]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.31/patches.drivers/staging-add-rt2870-wireless-driver.patch
Reenabled linux-xen, added patches for Xen Kernel Version 2.6.27.31,
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.drivers / staging-add-rt2870-wireless-driver.patch
1 From 0d43598686dd4b9c4ef8fe9027ac60b5335feaa8 Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@suse.de>
3 Date: Wed, 17 Dec 2008 17:04:23 -0800
4 Subject: [PATCH 1/4] Staging: add rt2870 wireless driver
5
6 From: Greg Kroah-Hartman <gregkh@suse.de>
7
8 This is the Ralink RT2870 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 and cleaned up a bit already by me.
19
20 Cc: Linux wireless <linux-wireless@vger.kernel.org>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
22 ---
23 drivers/staging/Kconfig | 2
24 drivers/staging/Makefile | 1
25 drivers/staging/rt2870/2870_main_dev.c | 1612 ++++
26 drivers/staging/rt2870/Kconfig | 6
27 drivers/staging/rt2870/Makefile | 47
28 drivers/staging/rt2870/TODO | 10
29 drivers/staging/rt2870/aironet.h | 210
30 drivers/staging/rt2870/ap.h | 562 +
31 drivers/staging/rt2870/chlist.h | 1296 +++
32 drivers/staging/rt2870/common/2870_rtmp_init.c | 1778 +++++
33 drivers/staging/rt2870/common/action.c | 1046 +++
34 drivers/staging/rt2870/common/action.h | 68
35 drivers/staging/rt2870/common/ba_action.c | 1798 +++++
36 drivers/staging/rt2870/common/cmm_data.c | 2734 +++++++
37 drivers/staging/rt2870/common/cmm_data_2870.c | 963 ++
38 drivers/staging/rt2870/common/cmm_info.c | 3712 ++++++++++
39 drivers/staging/rt2870/common/cmm_sanity.c | 1663 ++++
40 drivers/staging/rt2870/common/cmm_sync.c | 711 ++
41 drivers/staging/rt2870/common/cmm_wpa.c | 1654 ++++
42 drivers/staging/rt2870/common/dfs.c | 453 +
43 drivers/staging/rt2870/common/eeprom.c | 254
44 drivers/staging/rt2870/common/firmware.h | 558 +
45 drivers/staging/rt2870/common/md5.c | 1427 ++++
46 drivers/staging/rt2870/common/mlme.c | 8609 +++++++++++++++++++++++++
47 drivers/staging/rt2870/common/netif_block.c | 144
48 drivers/staging/rt2870/common/rtmp_init.c | 4132 +++++++++++
49 drivers/staging/rt2870/common/rtmp_tkip.c | 1613 ++++
50 drivers/staging/rt2870/common/rtmp_wep.c | 508 +
51 drivers/staging/rt2870/common/rtusb_bulk.c | 1981 +++++
52 drivers/staging/rt2870/common/rtusb_data.c | 229
53 drivers/staging/rt2870/common/rtusb_io.c | 2006 +++++
54 drivers/staging/rt2870/common/spectrum.c | 1876 +++++
55 drivers/staging/rt2870/dfs.h | 100
56 drivers/staging/rt2870/leap.h | 215
57 drivers/staging/rt2870/link_list.h | 134
58 drivers/staging/rt2870/md4.h | 42
59 drivers/staging/rt2870/md5.h | 107
60 drivers/staging/rt2870/mlme.h | 1471 ++++
61 drivers/staging/rt2870/netif_block.h | 58
62 drivers/staging/rt2870/oid.h | 1091 +++
63 drivers/staging/rt2870/rt2870.h | 761 ++
64 drivers/staging/rt2870/rt28xx.h | 2689 +++++++
65 drivers/staging/rt2870/rt_ate.c | 6452 ++++++++++++++++++
66 drivers/staging/rt2870/rt_ate.h | 315
67 drivers/staging/rt2870/rt_config.h | 104
68 drivers/staging/rt2870/rt_linux.c | 1095 +++
69 drivers/staging/rt2870/rt_linux.h | 908 ++
70 drivers/staging/rt2870/rt_main_dev.c | 1863 +++++
71 drivers/staging/rt2870/rt_profile.c | 2016 +++++
72 drivers/staging/rt2870/rtmp.h | 7586 ++++++++++++++++++++++
73 drivers/staging/rt2870/rtmp_ckipmic.h | 113
74 drivers/staging/rt2870/rtmp_def.h | 1622 ++++
75 drivers/staging/rt2870/rtmp_type.h | 94
76 drivers/staging/rt2870/spectrum.h | 322
77 drivers/staging/rt2870/spectrum_def.h | 95
78 drivers/staging/rt2870/sta/aironet.c | 1312 +++
79 drivers/staging/rt2870/sta/assoc.c | 2039 +++++
80 drivers/staging/rt2870/sta/auth.c | 474 +
81 drivers/staging/rt2870/sta/auth_rsp.c | 166
82 drivers/staging/rt2870/sta/connect.c | 2822 ++++++++
83 drivers/staging/rt2870/sta/dls.c | 2210 ++++++
84 drivers/staging/rt2870/sta/rtmp_data.c | 2619 +++++++
85 drivers/staging/rt2870/sta/sanity.c | 420 +
86 drivers/staging/rt2870/sta/sync.c | 1753 +++++
87 drivers/staging/rt2870/sta/wpa.c | 2107 ++++++
88 drivers/staging/rt2870/sta_ioctl.c | 7068 ++++++++++++++++++++
89 drivers/staging/rt2870/sta_ioctl.c.patch | 18
90 drivers/staging/rt2870/tmp60 | 7037 ++++++++++++++++++++
91 drivers/staging/rt2870/tmp61 | 7037 ++++++++++++++++++++
92 drivers/staging/rt2870/wpa.h | 357 +
93 70 files changed, 110355 insertions(+)
94 create mode 100644 drivers/staging/rt2870/2870_main_dev.c
95 create mode 100644 drivers/staging/rt2870/Kconfig
96 create mode 100644 drivers/staging/rt2870/Makefile
97 create mode 100644 drivers/staging/rt2870/TODO
98 create mode 100644 drivers/staging/rt2870/aironet.h
99 create mode 100644 drivers/staging/rt2870/ap.h
100 create mode 100644 drivers/staging/rt2870/chlist.h
101 create mode 100644 drivers/staging/rt2870/common/2870_rtmp_init.c
102 create mode 100644 drivers/staging/rt2870/common/action.c
103 create mode 100644 drivers/staging/rt2870/common/action.h
104 create mode 100644 drivers/staging/rt2870/common/ba_action.c
105 create mode 100644 drivers/staging/rt2870/common/cmm_data.c
106 create mode 100644 drivers/staging/rt2870/common/cmm_data_2870.c
107 create mode 100644 drivers/staging/rt2870/common/cmm_info.c
108 create mode 100644 drivers/staging/rt2870/common/cmm_sanity.c
109 create mode 100644 drivers/staging/rt2870/common/cmm_sync.c
110 create mode 100644 drivers/staging/rt2870/common/cmm_wpa.c
111 create mode 100644 drivers/staging/rt2870/common/dfs.c
112 create mode 100644 drivers/staging/rt2870/common/eeprom.c
113 create mode 100644 drivers/staging/rt2870/common/firmware.h
114 create mode 100644 drivers/staging/rt2870/common/md5.c
115 create mode 100644 drivers/staging/rt2870/common/mlme.c
116 create mode 100644 drivers/staging/rt2870/common/netif_block.c
117 create mode 100644 drivers/staging/rt2870/common/rtmp_init.c
118 create mode 100644 drivers/staging/rt2870/common/rtmp_tkip.c
119 create mode 100644 drivers/staging/rt2870/common/rtmp_wep.c
120 create mode 100644 drivers/staging/rt2870/common/rtusb_bulk.c
121 create mode 100644 drivers/staging/rt2870/common/rtusb_data.c
122 create mode 100644 drivers/staging/rt2870/common/rtusb_io.c
123 create mode 100644 drivers/staging/rt2870/common/spectrum.c
124 create mode 100644 drivers/staging/rt2870/dfs.h
125 create mode 100644 drivers/staging/rt2870/leap.h
126 create mode 100644 drivers/staging/rt2870/link_list.h
127 create mode 100644 drivers/staging/rt2870/md4.h
128 create mode 100644 drivers/staging/rt2870/md5.h
129 create mode 100644 drivers/staging/rt2870/mlme.h
130 create mode 100644 drivers/staging/rt2870/netif_block.h
131 create mode 100644 drivers/staging/rt2870/oid.h
132 create mode 100644 drivers/staging/rt2870/rt2870.h
133 create mode 100644 drivers/staging/rt2870/rt28xx.h
134 create mode 100644 drivers/staging/rt2870/rt_ate.c
135 create mode 100644 drivers/staging/rt2870/rt_ate.h
136 create mode 100644 drivers/staging/rt2870/rt_config.h
137 create mode 100644 drivers/staging/rt2870/rt_linux.c
138 create mode 100644 drivers/staging/rt2870/rt_linux.h
139 create mode 100644 drivers/staging/rt2870/rt_main_dev.c
140 create mode 100644 drivers/staging/rt2870/rt_profile.c
141 create mode 100644 drivers/staging/rt2870/rtmp.h
142 create mode 100644 drivers/staging/rt2870/rtmp_ckipmic.h
143 create mode 100644 drivers/staging/rt2870/rtmp_def.h
144 create mode 100644 drivers/staging/rt2870/rtmp_type.h
145 create mode 100644 drivers/staging/rt2870/spectrum.h
146 create mode 100644 drivers/staging/rt2870/spectrum_def.h
147 create mode 100644 drivers/staging/rt2870/sta/aironet.c
148 create mode 100644 drivers/staging/rt2870/sta/assoc.c
149 create mode 100644 drivers/staging/rt2870/sta/auth.c
150 create mode 100644 drivers/staging/rt2870/sta/auth_rsp.c
151 create mode 100644 drivers/staging/rt2870/sta/connect.c
152 create mode 100644 drivers/staging/rt2870/sta/dls.c
153 create mode 100644 drivers/staging/rt2870/sta/rtmp_data.c
154 create mode 100644 drivers/staging/rt2870/sta/sanity.c
155 create mode 100644 drivers/staging/rt2870/sta/sync.c
156 create mode 100644 drivers/staging/rt2870/sta/wpa.c
157 create mode 100644 drivers/staging/rt2870/sta_ioctl.c
158 create mode 100644 drivers/staging/rt2870/sta_ioctl.c.patch
159 create mode 100644 drivers/staging/rt2870/tmp60
160 create mode 100644 drivers/staging/rt2870/tmp61
161 create mode 100644 drivers/staging/rt2870/wpa.h
162
163 --- a/drivers/staging/Kconfig
164 +++ b/drivers/staging/Kconfig
165 @@ -49,6 +49,8 @@ source "drivers/staging/otus/Kconfig"
166
167 source "drivers/staging/rt2860/Kconfig"
168
169 +source "drivers/staging/rt2870/Kconfig"
170 +
171 source "drivers/staging/benet/Kconfig"
172
173 source "drivers/staging/rtl8187se/Kconfig"
174 --- a/drivers/staging/Makefile
175 +++ b/drivers/staging/Makefile
176 @@ -16,5 +16,6 @@ obj-$(CONFIG_USB_ATMEL) += at76_usb/
177 obj-$(CONFIG_AGNX) += agnx/
178 obj-$(CONFIG_OTUS) += otus/
179 obj-$(CONFIG_RT2860) += rt2860/
180 +obj-$(CONFIG_RT2870) += rt2870/
181 obj-$(CONFIG_BENET) += benet/
182 obj-$(CONFIG_RTL8187SE) += rtl8187se/
183 --- /dev/null
184 +++ b/drivers/staging/rt2870/2870_main_dev.c
185 @@ -0,0 +1,1612 @@
186 +/*
187 + *************************************************************************
188 + * Ralink Tech Inc.
189 + * 5F., No.36, Taiyuan St., Jhubei City,
190 + * Hsinchu County 302,
191 + * Taiwan, R.O.C.
192 + *
193 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
194 + *
195 + * This program is free software; you can redistribute it and/or modify *
196 + * it under the terms of the GNU General Public License as published by *
197 + * the Free Software Foundation; either version 2 of the License, or *
198 + * (at your option) any later version. *
199 + * *
200 + * This program is distributed in the hope that it will be useful, *
201 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
202 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
203 + * GNU General Public License for more details. *
204 + * *
205 + * You should have received a copy of the GNU General Public License *
206 + * along with this program; if not, write to the *
207 + * Free Software Foundation, Inc., *
208 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
209 + * *
210 + *************************************************************************
211 +
212 + Module Name:
213 + rtmp_main.c
214 +
215 + Abstract:
216 + main initialization routines
217 +
218 + Revision History:
219 + Who When What
220 + -------- ---------- ----------------------------------------------
221 + Name Date Modification logs
222 + Jan Lee 01-10-2005 modified
223 + Sample Jun/01/07 Merge RT2870 and RT2860 drivers.
224 +*/
225 +
226 +#include "rt_config.h"
227 +
228 +
229 +// Following information will be show when you run 'modinfo'
230 +// *** If you have a solution for the bug in current version of driver, please mail to me.
231 +// Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. ***
232 +MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
233 +MODULE_DESCRIPTION("RT2870 Wireless Lan Linux Driver");
234 +#ifdef CONFIG_STA_SUPPORT
235 +MODULE_LICENSE("GPL");
236 +#ifdef MODULE_VERSION
237 +MODULE_VERSION(STA_DRIVER_VERSION);
238 +#endif
239 +#endif // CONFIG_STA_SUPPORT //
240 +
241 +#ifdef MULTIPLE_CARD_SUPPORT
242 +// record whether the card in the card list is used in the card file
243 +extern UINT8 MC_CardUsed[];
244 +#endif // MULTIPLE_CARD_SUPPORT //
245 +
246 +/* Kernel thread and vars, which handles packets that are completed. Only
247 + * packets that have a "complete" function are sent here. This way, the
248 + * completion is run out of kernel context, and doesn't block the rest of
249 + * the stack. */
250 +
251 +extern INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
252 + IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
253 +
254 +
255 +/* module table */
256 +struct usb_device_id rtusb_usb_id[] = RT2870_USB_DEVICES;
257 +INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
258 +MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
259 +
260 +#ifndef PF_NOFREEZE
261 +#define PF_NOFREEZE 0
262 +#endif
263 +
264 +
265 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
266 +
267 +/**************************************************************************/
268 +/**************************************************************************/
269 +//tested for kernel 2.4 series
270 +/**************************************************************************/
271 +/**************************************************************************/
272 +static void *rtusb_probe(struct usb_device *dev, UINT interface,
273 + const struct usb_device_id *id_table);
274 +static void rtusb_disconnect(struct usb_device *dev, void *ptr);
275 +
276 +struct usb_driver rtusb_driver = {
277 + name:"rt2870",
278 + probe:rtusb_probe,
279 + disconnect:rtusb_disconnect,
280 + id_table:rtusb_usb_id,
281 + };
282 +
283 +#else
284 +
285 +#ifdef CONFIG_PM
286 +static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
287 +static int rt2870_resume(struct usb_interface *intf);
288 +#endif // CONFIG_PM //
289 +
290 +/**************************************************************************/
291 +/**************************************************************************/
292 +//tested for kernel 2.6series
293 +/**************************************************************************/
294 +/**************************************************************************/
295 +static int rtusb_probe (struct usb_interface *intf,
296 + const struct usb_device_id *id);
297 +static void rtusb_disconnect(struct usb_interface *intf);
298 +
299 +struct usb_driver rtusb_driver = {
300 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
301 + .owner = THIS_MODULE,
302 +#endif
303 + .name="rt2870",
304 + .probe=rtusb_probe,
305 + .disconnect=rtusb_disconnect,
306 + .id_table=rtusb_usb_id,
307 +
308 +#ifdef CONFIG_PM
309 + suspend: rt2870_suspend,
310 + resume: rt2870_resume,
311 +#endif
312 + };
313 +
314 +#ifdef CONFIG_PM
315 +
316 +VOID RT2860RejectPendingPackets(
317 + IN PRTMP_ADAPTER pAd)
318 +{
319 + // clear PS packets
320 + // clear TxSw packets
321 +}
322 +
323 +static int rt2870_suspend(
324 + struct usb_interface *intf,
325 + pm_message_t state)
326 +{
327 + struct net_device *net_dev;
328 + PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
329 +
330 +
331 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
332 + net_dev = pAd->net_dev;
333 + netif_device_detach (net_dev);
334 +
335 + pAd->PM_FlgSuspend = 1;
336 + if (netif_running(net_dev)) {
337 + RTUSBCancelPendingBulkInIRP(pAd);
338 + RTUSBCancelPendingBulkOutIRP(pAd);
339 + }
340 + DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
341 + return 0;
342 +}
343 +
344 +static int rt2870_resume(
345 + struct usb_interface *intf)
346 +{
347 + struct net_device *net_dev;
348 + PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
349 +
350 +
351 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
352 +
353 + pAd->PM_FlgSuspend = 0;
354 + net_dev = pAd->net_dev;
355 + netif_device_attach (net_dev);
356 + netif_start_queue(net_dev);
357 + netif_carrier_on(net_dev);
358 + netif_wake_queue(net_dev);
359 +
360 + DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
361 + return 0;
362 +}
363 +#endif // CONFIG_PM //
364 +#endif // LINUX_VERSION_CODE //
365 +
366 +
367 +// Init driver module
368 +INT __init rtusb_init(void)
369 +{
370 + printk("rtusb init --->\n");
371 + return usb_register(&rtusb_driver);
372 +}
373 +
374 +// Deinit driver module
375 +VOID __exit rtusb_exit(void)
376 +{
377 + usb_deregister(&rtusb_driver);
378 + printk("<--- rtusb exit\n");
379 +}
380 +
381 +module_init(rtusb_init);
382 +module_exit(rtusb_exit);
383 +
384 +
385 +
386 +
387 +/*--------------------------------------------------------------------- */
388 +/* function declarations */
389 +/*--------------------------------------------------------------------- */
390 +
391 +/*
392 +========================================================================
393 +Routine Description:
394 + MLME kernel thread.
395 +
396 +Arguments:
397 + *Context the pAd, driver control block pointer
398 +
399 +Return Value:
400 + 0 close the thread
401 +
402 +Note:
403 +========================================================================
404 +*/
405 +INT MlmeThread(
406 + IN void *Context)
407 +{
408 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
409 + POS_COOKIE pObj;
410 + int status;
411 +
412 + pObj = (POS_COOKIE)pAd->OS_Cookie;
413 +
414 + rtmp_os_thread_init("rt2870MlmeThread", (PVOID)&(pAd->mlmeComplete));
415 +
416 + while (pAd->mlme_kill == 0)
417 + {
418 + /* lock the device pointers */
419 + //down(&(pAd->mlme_semaphore));
420 + status = down_interruptible(&(pAd->mlme_semaphore));
421 +
422 + /* lock the device pointers , need to check if required*/
423 + //down(&(pAd->usbdev_semaphore));
424 +
425 + if (!pAd->PM_FlgSuspend)
426 + MlmeHandler(pAd);
427 +
428 + /* unlock the device pointers */
429 + //up(&(pAd->usbdev_semaphore));
430 + if (status != 0)
431 + {
432 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
433 + break;
434 + }
435 + }
436 +
437 + /* notify the exit routine that we're actually exiting now
438 + *
439 + * complete()/wait_for_completion() is similar to up()/down(),
440 + * except that complete() is safe in the case where the structure
441 + * is getting deleted in a parallel mode of execution (i.e. just
442 + * after the down() -- that's necessary for the thread-shutdown
443 + * case.
444 + *
445 + * complete_and_exit() goes even further than this -- it is safe in
446 + * the case that the thread of the caller is going away (not just
447 + * the structure) -- this is necessary for the module-remove case.
448 + * This is important in preemption kernels, which transfer the flow
449 + * of execution immediately upon a complete().
450 + */
451 + DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__FUNCTION__));
452 +
453 + pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
454 +
455 + complete_and_exit (&pAd->mlmeComplete, 0);
456 + return 0;
457 +
458 +}
459 +
460 +
461 +/*
462 +========================================================================
463 +Routine Description:
464 + USB command kernel thread.
465 +
466 +Arguments:
467 + *Context the pAd, driver control block pointer
468 +
469 +Return Value:
470 + 0 close the thread
471 +
472 +Note:
473 +========================================================================
474 +*/
475 +INT RTUSBCmdThread(
476 + IN void * Context)
477 +{
478 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
479 + POS_COOKIE pObj;
480 + int status;
481 +
482 + pObj = (POS_COOKIE)pAd->OS_Cookie;
483 +
484 + rtmp_os_thread_init("rt2870CmdThread", (PVOID)&(pAd->CmdQComplete));
485 +
486 + NdisAcquireSpinLock(&pAd->CmdQLock);
487 + pAd->CmdQ.CmdQState = RT2870_THREAD_RUNNING;
488 + NdisReleaseSpinLock(&pAd->CmdQLock);
489 +
490 + while (pAd->CmdQ.CmdQState == RT2870_THREAD_RUNNING)
491 + {
492 + /* lock the device pointers */
493 + //down(&(pAd->RTUSBCmd_semaphore));
494 + status = down_interruptible(&(pAd->RTUSBCmd_semaphore));
495 +
496 + if (pAd->CmdQ.CmdQState == RT2870_THREAD_STOPED)
497 + break;
498 +
499 + if (status != 0)
500 + {
501 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
502 + break;
503 + }
504 + /* lock the device pointers , need to check if required*/
505 + //down(&(pAd->usbdev_semaphore));
506 +
507 + if (!pAd->PM_FlgSuspend)
508 + CMDHandler(pAd);
509 +
510 + /* unlock the device pointers */
511 + //up(&(pAd->usbdev_semaphore));
512 + }
513 +
514 + if (!pAd->PM_FlgSuspend)
515 + { // Clear the CmdQElements.
516 + CmdQElmt *pCmdQElmt = NULL;
517 +
518 + NdisAcquireSpinLock(&pAd->CmdQLock);
519 + pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
520 + while(pAd->CmdQ.size)
521 + {
522 + RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
523 + if (pCmdQElmt)
524 + {
525 + if (pCmdQElmt->CmdFromNdis == TRUE)
526 + {
527 + if (pCmdQElmt->buffer != NULL)
528 + NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
529 +
530 + NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
531 + }
532 + else
533 + {
534 + if ((pCmdQElmt->buffer != NULL) && (pCmdQElmt->bufferlength != 0))
535 + NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
536 + {
537 + NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
538 + }
539 + }
540 + }
541 + }
542 +
543 + NdisReleaseSpinLock(&pAd->CmdQLock);
544 + }
545 + /* notify the exit routine that we're actually exiting now
546 + *
547 + * complete()/wait_for_completion() is similar to up()/down(),
548 + * except that complete() is safe in the case where the structure
549 + * is getting deleted in a parallel mode of execution (i.e. just
550 + * after the down() -- that's necessary for the thread-shutdown
551 + * case.
552 + *
553 + * complete_and_exit() goes even further than this -- it is safe in
554 + * the case that the thread of the caller is going away (not just
555 + * the structure) -- this is necessary for the module-remove case.
556 + * This is important in preemption kernels, which transfer the flow
557 + * of execution immediately upon a complete().
558 + */
559 + DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
560 +
561 + pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
562 +
563 + complete_and_exit (&pAd->CmdQComplete, 0);
564 + return 0;
565 +
566 +}
567 +
568 +
569 +static void RT2870_TimerQ_Handle(RTMP_ADAPTER *pAd)
570 +{
571 + int status;
572 + RALINK_TIMER_STRUCT *pTimer;
573 + RT2870_TIMER_ENTRY *pEntry;
574 + unsigned long irqFlag;
575 +
576 + while(!pAd->TimerFunc_kill)
577 + {
578 +// printk("waiting for event!\n");
579 + pTimer = NULL;
580 +
581 + status = down_interruptible(&(pAd->RTUSBTimer_semaphore));
582 +
583 + if (pAd->TimerQ.status == RT2870_THREAD_STOPED)
584 + break;
585 +
586 + // event happened.
587 + while(pAd->TimerQ.pQHead)
588 + {
589 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlag);
590 + pEntry = pAd->TimerQ.pQHead;
591 + if (pEntry)
592 + {
593 + pTimer = pEntry->pRaTimer;
594 +
595 + // update pQHead
596 + pAd->TimerQ.pQHead = pEntry->pNext;
597 + if (pEntry == pAd->TimerQ.pQTail)
598 + pAd->TimerQ.pQTail = NULL;
599 +
600 + // return this queue entry to timerQFreeList.
601 + pEntry->pNext = pAd->TimerQ.pQPollFreeList;
602 + pAd->TimerQ.pQPollFreeList = pEntry;
603 + }
604 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlag);
605 +
606 + if (pTimer)
607 + {
608 + if (pTimer->handle != NULL)
609 + if (!pAd->PM_FlgSuspend)
610 + pTimer->handle(NULL, (PVOID) pTimer->cookie, NULL, pTimer);
611 + if ((pTimer->Repeat) && (pTimer->State == FALSE))
612 + RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue);
613 + }
614 + }
615 +
616 + if (status != 0)
617 + {
618 + pAd->TimerQ.status = RT2870_THREAD_STOPED;
619 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
620 + break;
621 + }
622 + }
623 +}
624 +
625 +
626 +INT TimerQThread(
627 + IN OUT PVOID Context)
628 +{
629 + PRTMP_ADAPTER pAd;
630 + POS_COOKIE pObj;
631 +
632 + pAd = (PRTMP_ADAPTER)Context;
633 + pObj = (POS_COOKIE) pAd->OS_Cookie;
634 +
635 + rtmp_os_thread_init("rt2870TimerQHandle", (PVOID)&(pAd->TimerQComplete));
636 +
637 + RT2870_TimerQ_Handle(pAd);
638 +
639 + /* notify the exit routine that we're actually exiting now
640 + *
641 + * complete()/wait_for_completion() is similar to up()/down(),
642 + * except that complete() is safe in the case where the structure
643 + * is getting deleted in a parallel mode of execution (i.e. just
644 + * after the down() -- that's necessary for the thread-shutdown
645 + * case.
646 + *
647 + * complete_and_exit() goes even further than this -- it is safe in
648 + * the case that the thread of the caller is going away (not just
649 + * the structure) -- this is necessary for the module-remove case.
650 + * This is important in preemption kernels, which transfer the flow
651 + * of execution immediately upon a complete().
652 + */
653 + DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__FUNCTION__));
654 +
655 + pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
656 +
657 + complete_and_exit(&pAd->TimerQComplete, 0);
658 + return 0;
659 +
660 +}
661 +
662 +
663 +RT2870_TIMER_ENTRY *RT2870_TimerQ_Insert(
664 + IN RTMP_ADAPTER *pAd,
665 + IN RALINK_TIMER_STRUCT *pTimer)
666 +{
667 + RT2870_TIMER_ENTRY *pQNode = NULL, *pQTail;
668 + unsigned long irqFlags;
669 +
670 +
671 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
672 + if (pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)
673 + {
674 + if(pAd->TimerQ.pQPollFreeList)
675 + {
676 + pQNode = pAd->TimerQ.pQPollFreeList;
677 + pAd->TimerQ.pQPollFreeList = pQNode->pNext;
678 +
679 + pQNode->pRaTimer = pTimer;
680 + pQNode->pNext = NULL;
681 +
682 + pQTail = pAd->TimerQ.pQTail;
683 + if (pAd->TimerQ.pQTail != NULL)
684 + pQTail->pNext = pQNode;
685 + pAd->TimerQ.pQTail = pQNode;
686 + if (pAd->TimerQ.pQHead == NULL)
687 + pAd->TimerQ.pQHead = pQNode;
688 + }
689 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
690 +
691 + if (pQNode)
692 + up(&pAd->RTUSBTimer_semaphore);
693 + //wake_up(&timerWaitQ);
694 + }
695 + else
696 + {
697 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
698 + }
699 + return pQNode;
700 +}
701 +
702 +
703 +BOOLEAN RT2870_TimerQ_Remove(
704 + IN RTMP_ADAPTER *pAd,
705 + IN RALINK_TIMER_STRUCT *pTimer)
706 +{
707 + RT2870_TIMER_ENTRY *pNode, *pPrev = NULL;
708 + unsigned long irqFlags;
709 +
710 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
711 + if (pAd->TimerQ.status >= RT2870_THREAD_INITED)
712 + {
713 + pNode = pAd->TimerQ.pQHead;
714 + while (pNode)
715 + {
716 + if (pNode->pRaTimer == pTimer)
717 + break;
718 + pPrev = pNode;
719 + pNode = pNode->pNext;
720 + }
721 +
722 + // Now move it to freeList queue.
723 + if (pNode)
724 + {
725 + if (pNode == pAd->TimerQ.pQHead)
726 + pAd->TimerQ.pQHead = pNode->pNext;
727 + if (pNode == pAd->TimerQ.pQTail)
728 + pAd->TimerQ.pQTail = pPrev;
729 + if (pPrev != NULL)
730 + pPrev->pNext = pNode->pNext;
731 +
732 + // return this queue entry to timerQFreeList.
733 + pNode->pNext = pAd->TimerQ.pQPollFreeList;
734 + pAd->TimerQ.pQPollFreeList = pNode;
735 + }
736 + }
737 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
738 +
739 + return TRUE;
740 +}
741 +
742 +
743 +void RT2870_TimerQ_Exit(RTMP_ADAPTER *pAd)
744 +{
745 + RT2870_TIMER_ENTRY *pTimerQ;
746 + unsigned long irqFlags;
747 +
748 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
749 + while (pAd->TimerQ.pQHead)
750 + {
751 + pTimerQ = pAd->TimerQ.pQHead;
752 + pAd->TimerQ.pQHead = pTimerQ->pNext;
753 + // remove the timeQ
754 + }
755 + pAd->TimerQ.pQPollFreeList = NULL;
756 + os_free_mem(pAd, pAd->TimerQ.pTimerQPoll);
757 + pAd->TimerQ.pQTail = NULL;
758 + pAd->TimerQ.pQHead = NULL;
759 + pAd->TimerQ.status = RT2870_THREAD_STOPED;
760 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
761 +
762 +}
763 +
764 +
765 +void RT2870_TimerQ_Init(RTMP_ADAPTER *pAd)
766 +{
767 + int i;
768 + RT2870_TIMER_ENTRY *pQNode, *pEntry;
769 + unsigned long irqFlags;
770 +
771 + NdisAllocateSpinLock(&pAd->TimerQLock);
772 +
773 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
774 + NdisZeroMemory(&pAd->TimerQ, sizeof(pAd->TimerQ));
775 + //InterlockedExchange(&pAd->TimerQ.count, 0);
776 +
777 + /* Initialise the wait q head */
778 + //init_waitqueue_head(&timerWaitQ);
779 +
780 + os_alloc_mem(pAd, &pAd->TimerQ.pTimerQPoll, sizeof(RT2870_TIMER_ENTRY) * TIMER_QUEUE_SIZE_MAX);
781 + if (pAd->TimerQ.pTimerQPoll)
782 + {
783 + pEntry = NULL;
784 + pQNode = (RT2870_TIMER_ENTRY *)pAd->TimerQ.pTimerQPoll;
785 + for (i = 0 ;i <TIMER_QUEUE_SIZE_MAX; i++)
786 + {
787 + pQNode->pNext = pEntry;
788 + pEntry = pQNode;
789 + pQNode++;
790 + }
791 + pAd->TimerQ.pQPollFreeList = pEntry;
792 + pAd->TimerQ.pQHead = NULL;
793 + pAd->TimerQ.pQTail = NULL;
794 + pAd->TimerQ.status = RT2870_THREAD_INITED;
795 + }
796 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
797 +}
798 +
799 +
800 +VOID RT2870_WatchDog(IN RTMP_ADAPTER *pAd)
801 +{
802 + PHT_TX_CONTEXT pHTTXContext;
803 + int idx;
804 + ULONG irqFlags;
805 + PURB pUrb;
806 + BOOLEAN needDumpSeq = FALSE;
807 + UINT32 MACValue;
808 +
809 +
810 + idx = 0;
811 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
812 + if ((MACValue & 0xff) !=0 )
813 + {
814 + DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 0 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
815 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
816 + while((MACValue &0xff) != 0 && (idx++ < 10))
817 + {
818 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
819 + NdisMSleep(1);
820 + }
821 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
822 + }
823 +
824 + idx = 0;
825 + if ((MACValue & 0xff00) !=0 )
826 + {
827 + DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 1 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
828 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf4000a);
829 + while((MACValue &0xff00) != 0 && (idx++ < 10))
830 + {
831 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
832 + NdisMSleep(1);
833 + }
834 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
835 + }
836 +
837 +
838 + if (pAd->watchDogRxOverFlowCnt >= 2)
839 + {
840 + DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
841 + if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
842 + fRTMP_ADAPTER_BULKIN_RESET |
843 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
844 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
845 + {
846 + DBGPRINT(RT_DEBUG_TRACE, ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
847 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
848 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
849 + needDumpSeq = TRUE;
850 + }
851 + pAd->watchDogRxOverFlowCnt = 0;
852 + }
853 +
854 +
855 + for (idx = 0; idx < NUM_OF_TX_RING; idx++)
856 + {
857 + pUrb = NULL;
858 +
859 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
860 + if ((pAd->BulkOutPending[idx] == TRUE) && pAd->watchDogTxPendingCnt)
861 + {
862 + pAd->watchDogTxPendingCnt[idx]++;
863 +
864 + if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
865 + (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_BULKOUT_RESET)))
866 + )
867 + {
868 + // FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it!
869 + pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[idx]);
870 + if (pHTTXContext->IRPPending)
871 + { // Check TxContext.
872 + pUrb = pHTTXContext->pUrb;
873 + }
874 + else if (idx == MGMTPIPEIDX)
875 + {
876 + PTX_CONTEXT pMLMEContext, pNULLContext, pPsPollContext;
877 +
878 + //Check MgmtContext.
879 + pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
880 + pPsPollContext = (PTX_CONTEXT)(&pAd->PsPollContext);
881 + pNULLContext = (PTX_CONTEXT)(&pAd->NullContext);
882 +
883 + if (pMLMEContext->IRPPending)
884 + {
885 + ASSERT(pMLMEContext->IRPPending);
886 + pUrb = pMLMEContext->pUrb;
887 + }
888 + else if (pNULLContext->IRPPending)
889 + {
890 + ASSERT(pNULLContext->IRPPending);
891 + pUrb = pNULLContext->pUrb;
892 + }
893 + else if (pPsPollContext->IRPPending)
894 + {
895 + ASSERT(pPsPollContext->IRPPending);
896 + pUrb = pPsPollContext->pUrb;
897 + }
898 + }
899 +
900 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
901 +
902 + DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n", idx));
903 + if (pUrb)
904 + {
905 + DBGPRINT(RT_DEBUG_TRACE, ("Unlink the pending URB!\n"));
906 + // unlink it now
907 + RTUSB_UNLINK_URB(pUrb);
908 + // Sleep 200 microseconds to give cancellation time to work
909 + RTMPusecDelay(200);
910 + needDumpSeq = TRUE;
911 + }
912 + else
913 + {
914 + DBGPRINT(RT_DEBUG_ERROR, ("Unkonw bulkOut URB maybe hanged!!!!!!!!!!!!\n"));
915 + }
916 + }
917 + else
918 + {
919 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
920 + }
921 + }
922 + else
923 + {
924 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
925 + }
926 + }
927 +
928 +#ifdef DOT11_N_SUPPORT
929 + // For Sigma debug, dump the ba_reordering sequence.
930 + if((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0))
931 + {
932 + USHORT Idx;
933 + PBA_REC_ENTRY pBAEntry = NULL;
934 + UCHAR count = 0;
935 + struct reordering_mpdu *mpdu_blk;
936 +
937 + Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
938 +
939 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
940 + if((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL))
941 + {
942 + DBGPRINT(RT_DEBUG_TRACE, ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
943 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
944 + mpdu_blk = pBAEntry->list.next;
945 + while (mpdu_blk)
946 + {
947 + DBGPRINT(RT_DEBUG_TRACE, ("\t%d:Seq-%d, bAMSDU-%d!\n", count, mpdu_blk->Sequence, mpdu_blk->bAMSDU));
948 + mpdu_blk = mpdu_blk->next;
949 + count++;
950 + }
951 +
952 + DBGPRINT(RT_DEBUG_TRACE, ("\npBAEntry->LastIndSeq=%d!\n", pBAEntry->LastIndSeq));
953 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
954 + }
955 + }
956 +#endif // DOT11_N_SUPPORT //
957 +}
958 +
959 +/*
960 +========================================================================
961 +Routine Description:
962 + Release allocated resources.
963 +
964 +Arguments:
965 + *dev Point to the PCI or USB device
966 + pAd driver control block pointer
967 +
968 +Return Value:
969 + None
970 +
971 +Note:
972 +========================================================================
973 +*/
974 +static void _rtusb_disconnect(struct usb_device *dev, PRTMP_ADAPTER pAd)
975 +{
976 + struct net_device *net_dev = NULL;
977 +
978 +
979 + DBGPRINT(RT_DEBUG_ERROR, ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
980 + dev->bus->bus_name, dev->devpath));
981 + if (!pAd)
982 + {
983 +#ifdef MULTIPLE_CARD_SUPPORT
984 + if ((pAd->MC_RowID >= 0) && (pAd->MC_RowID <= MAX_NUM_OF_MULTIPLE_CARD))
985 + MC_CardUsed[pAd->MC_RowID] = 0; // not clear MAC address
986 +#endif // MULTIPLE_CARD_SUPPORT //
987 +
988 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
989 + while(MOD_IN_USE > 0)
990 + {
991 + MOD_DEC_USE_COUNT;
992 + }
993 +#else
994 + usb_put_dev(dev);
995 +#endif // LINUX_VERSION_CODE //
996 +
997 + printk("rtusb_disconnect: pAd == NULL!\n");
998 + return;
999 + }
1000 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
1001 +
1002 +
1003 +
1004 + // for debug, wait to show some messages to /proc system
1005 + udelay(1);
1006 +
1007 +
1008 +
1009 +
1010 + net_dev = pAd->net_dev;
1011 + if (pAd->net_dev != NULL)
1012 + {
1013 + printk("rtusb_disconnect: unregister_netdev(), dev->name=%s!\n", net_dev->name);
1014 + unregister_netdev (pAd->net_dev);
1015 + }
1016 + udelay(1);
1017 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1018 +#else
1019 + flush_scheduled_work();
1020 +#endif // LINUX_VERSION_CODE //
1021 + udelay(1);
1022 +
1023 + // free net_device memory
1024 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1025 + kfree(net_dev);
1026 +#else
1027 + free_netdev(net_dev);
1028 +#endif // LINUX_VERSION_CODE //
1029 +
1030 + // free adapter memory
1031 + RTMPFreeAdapter(pAd);
1032 +
1033 + // release a use of the usb device structure
1034 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1035 + while(MOD_IN_USE > 0)
1036 + {
1037 + MOD_DEC_USE_COUNT;
1038 + }
1039 +#else
1040 + usb_put_dev(dev);
1041 +#endif // LINUX_VERSION_CODE //
1042 + udelay(1);
1043 +
1044 + DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
1045 +}
1046 +
1047 +
1048 +/*
1049 +========================================================================
1050 +Routine Description:
1051 + Probe RT28XX chipset.
1052 +
1053 +Arguments:
1054 + *dev Point to the PCI or USB device
1055 + interface
1056 + *id_table Point to the PCI or USB device ID
1057 +
1058 +Return Value:
1059 + None
1060 +
1061 +Note:
1062 +========================================================================
1063 +*/
1064 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1065 +static void *rtusb_probe(struct usb_device *dev, UINT interface,
1066 + const struct usb_device_id *id)
1067 +{
1068 + PRTMP_ADAPTER pAd;
1069 + rt28xx_probe((void *)dev, (void *)id, interface, &pAd);
1070 + return (void *)pAd;
1071 +}
1072 +
1073 +//Disconnect function is called within exit routine
1074 +static void rtusb_disconnect(struct usb_device *dev, void *ptr)
1075 +{
1076 + _rtusb_disconnect(dev, ((PRTMP_ADAPTER)ptr));
1077 +}
1078 +
1079 +#else /* kernel 2.6 series */
1080 +static int rtusb_probe (struct usb_interface *intf,
1081 + const struct usb_device_id *id)
1082 +{
1083 + PRTMP_ADAPTER pAd;
1084 + return (int)rt28xx_probe((void *)intf, (void *)id, 0, &pAd);
1085 +}
1086 +
1087 +
1088 +static void rtusb_disconnect(struct usb_interface *intf)
1089 +{
1090 + struct usb_device *dev = interface_to_usbdev(intf);
1091 + PRTMP_ADAPTER pAd;
1092 +
1093 +
1094 + pAd = usb_get_intfdata(intf);
1095 + usb_set_intfdata(intf, NULL);
1096 +
1097 + _rtusb_disconnect(dev, pAd);
1098 +}
1099 +#endif // LINUX_VERSION_CODE //
1100 +
1101 +
1102 +/*
1103 +========================================================================
1104 +Routine Description:
1105 + Close kernel threads.
1106 +
1107 +Arguments:
1108 + *pAd the raxx interface data pointer
1109 +
1110 +Return Value:
1111 + NONE
1112 +
1113 +Note:
1114 +========================================================================
1115 +*/
1116 +VOID RT28xxThreadTerminate(
1117 + IN RTMP_ADAPTER *pAd)
1118 +{
1119 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
1120 + INT ret;
1121 +
1122 +
1123 + // Sleep 50 milliseconds so pending io might finish normally
1124 + RTMPusecDelay(50000);
1125 +
1126 + // We want to wait until all pending receives and sends to the
1127 + // device object. We cancel any
1128 + // irps. Wait until sends and receives have stopped.
1129 + RTUSBCancelPendingIRPs(pAd);
1130 +
1131 + // Terminate Threads
1132 + CHECK_PID_LEGALITY(pObj->TimerQThr_pid)
1133 + {
1134 + POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;
1135 +
1136 + printk("Terminate the TimerQThr_pid=%d!\n", GET_PID_NUMBER(pObj->TimerQThr_pid));
1137 + mb();
1138 + pAd->TimerFunc_kill = 1;
1139 + mb();
1140 + ret = KILL_THREAD_PID(pObj->TimerQThr_pid, SIGTERM, 1);
1141 + if (ret)
1142 + {
1143 + printk(KERN_WARNING "%s: unable to stop TimerQThread, pid=%d, ret=%d!\n",
1144 + pAd->net_dev->name, GET_PID_NUMBER(pObj->TimerQThr_pid), ret);
1145 + }
1146 + else
1147 + {
1148 + wait_for_completion(&pAd->TimerQComplete);
1149 + pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
1150 + }
1151 + }
1152 +
1153 + CHECK_PID_LEGALITY(pObj->MLMEThr_pid)
1154 + {
1155 + printk("Terminate the MLMEThr_pid=%d!\n", GET_PID_NUMBER(pObj->MLMEThr_pid));
1156 + mb();
1157 + pAd->mlme_kill = 1;
1158 + //RT28XX_MLME_HANDLER(pAd);
1159 + mb();
1160 + ret = KILL_THREAD_PID(pObj->MLMEThr_pid, SIGTERM, 1);
1161 + if (ret)
1162 + {
1163 + printk (KERN_WARNING "%s: unable to Mlme thread, pid=%d, ret=%d!\n",
1164 + pAd->net_dev->name, GET_PID_NUMBER(pObj->MLMEThr_pid), ret);
1165 + }
1166 + else
1167 + {
1168 + //wait_for_completion (&pAd->notify);
1169 + wait_for_completion (&pAd->mlmeComplete);
1170 + pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
1171 + }
1172 + }
1173 +
1174 + CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)
1175 + {
1176 + printk("Terminate the RTUSBCmdThr_pid=%d!\n", GET_PID_NUMBER(pObj->RTUSBCmdThr_pid));
1177 + mb();
1178 + NdisAcquireSpinLock(&pAd->CmdQLock);
1179 + pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
1180 + NdisReleaseSpinLock(&pAd->CmdQLock);
1181 + mb();
1182 + //RTUSBCMDUp(pAd);
1183 + ret = KILL_THREAD_PID(pObj->RTUSBCmdThr_pid, SIGTERM, 1);
1184 + if (ret)
1185 + {
1186 + printk(KERN_WARNING "%s: unable to RTUSBCmd thread, pid=%d, ret=%d!\n",
1187 + pAd->net_dev->name, GET_PID_NUMBER(pObj->RTUSBCmdThr_pid), ret);
1188 + }
1189 + else
1190 + {
1191 + //wait_for_completion (&pAd->notify);
1192 + wait_for_completion (&pAd->CmdQComplete);
1193 + pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
1194 + }
1195 + }
1196 +
1197 +
1198 + // Kill tasklets
1199 + pAd->mlme_kill = 0;
1200 + pAd->CmdQ.CmdQState = RT2870_THREAD_UNKNOWN;
1201 + pAd->TimerFunc_kill = 0;
1202 +}
1203 +
1204 +
1205 +void kill_thread_task(IN PRTMP_ADAPTER pAd)
1206 +{
1207 + POS_COOKIE pObj;
1208 +
1209 + pObj = (POS_COOKIE) pAd->OS_Cookie;
1210 +
1211 + tasklet_kill(&pObj->rx_done_task);
1212 + tasklet_kill(&pObj->mgmt_dma_done_task);
1213 + tasklet_kill(&pObj->ac0_dma_done_task);
1214 + tasklet_kill(&pObj->ac1_dma_done_task);
1215 + tasklet_kill(&pObj->ac2_dma_done_task);
1216 + tasklet_kill(&pObj->ac3_dma_done_task);
1217 + tasklet_kill(&pObj->hcca_dma_done_task);
1218 + tasklet_kill(&pObj->tbtt_task);
1219 +
1220 +}
1221 +
1222 +
1223 +/*
1224 +========================================================================
1225 +Routine Description:
1226 + Check the chipset vendor/product ID.
1227 +
1228 +Arguments:
1229 + _dev_p Point to the PCI or USB device
1230 +
1231 +Return Value:
1232 + TRUE Check ok
1233 + FALSE Check fail
1234 +
1235 +Note:
1236 +========================================================================
1237 +*/
1238 +BOOLEAN RT28XXChipsetCheck(
1239 + IN void *_dev_p)
1240 +{
1241 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1242 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1243 +#else
1244 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1245 + struct usb_device *dev_p = interface_to_usbdev(intf);
1246 +#endif // LINUX_VERSION_CODE //
1247 + UINT32 i;
1248 +
1249 +
1250 + for(i=0; i<rtusb_usb_id_len; i++)
1251 + {
1252 + if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
1253 + dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
1254 + {
1255 + printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
1256 + dev_p->descriptor.idVendor, dev_p->descriptor.idProduct);
1257 + break;
1258 + }
1259 + }
1260 +
1261 + if (i == rtusb_usb_id_len)
1262 + {
1263 + printk("rt2870: Error! Device Descriptor not matching!\n");
1264 + return FALSE;
1265 + }
1266 +
1267 + return TRUE;
1268 +}
1269 +
1270 +
1271 +/*
1272 +========================================================================
1273 +Routine Description:
1274 + Init net device structure.
1275 +
1276 +Arguments:
1277 + _dev_p Point to the PCI or USB device
1278 + *net_dev Point to the net device
1279 + *pAd the raxx interface data pointer
1280 +
1281 +Return Value:
1282 + TRUE Init ok
1283 + FALSE Init fail
1284 +
1285 +Note:
1286 +========================================================================
1287 +*/
1288 +BOOLEAN RT28XXNetDevInit(
1289 + IN void *_dev_p,
1290 + IN struct net_device *net_dev,
1291 + IN RTMP_ADAPTER *pAd)
1292 +{
1293 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1294 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1295 +#else
1296 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1297 + struct usb_device *dev_p = interface_to_usbdev(intf);
1298 +#endif // LINUX_VERSION_CODE //
1299 +
1300 +
1301 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1302 + pAd->config = dev_p->config;
1303 +#else
1304 + pAd->config = &dev_p->config->desc;
1305 +#endif // LINUX_VERSION_CODE //
1306 + return TRUE;
1307 +}
1308 +
1309 +
1310 +/*
1311 +========================================================================
1312 +Routine Description:
1313 + Init net device structure.
1314 +
1315 +Arguments:
1316 + _dev_p Point to the PCI or USB device
1317 + *pAd the raxx interface data pointer
1318 +
1319 +Return Value:
1320 + TRUE Config ok
1321 + FALSE Config fail
1322 +
1323 +Note:
1324 +========================================================================
1325 +*/
1326 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1327 +BOOLEAN RT28XXProbePostConfig(
1328 + IN void *_dev_p,
1329 + IN RTMP_ADAPTER *pAd,
1330 + IN INT32 interface)
1331 +{
1332 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1333 + struct usb_interface *intf;
1334 + struct usb_interface_descriptor *iface_desc;
1335 + struct usb_endpoint_descriptor *endpoint;
1336 + ULONG BulkOutIdx;
1337 + UINT32 i;
1338 +
1339 +
1340 + /* get the active interface descriptor */
1341 + intf = &dev_p->actconfig->interface[interface];
1342 + iface_desc = &intf->altsetting[0];
1343 +
1344 + /* get # of enpoints */
1345 + pAd->NumberOfPipes = iface_desc->bNumEndpoints;
1346 + DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->bNumEndpoints));
1347 +
1348 + /* Configure Pipes */
1349 + endpoint = &iface_desc->endpoint[0];
1350 + BulkOutIdx = 0;
1351 +
1352 + for(i=0; i<pAd->NumberOfPipes; i++)
1353 + {
1354 + if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) &&
1355 + ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
1356 + {
1357 + pAd->BulkInEpAddr = endpoint[i].bEndpointAddress;
1358 + pAd->BulkInMaxPacketSize = endpoint[i].wMaxPacketSize;
1359 +
1360 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1361 + ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));
1362 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1363 + ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress));
1364 + }
1365 + else if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) &&
1366 + ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
1367 + {
1368 + // There are 6 bulk out EP. EP6 highest priority.
1369 + // EP1-4 is EDCA. EP5 is HCCA.
1370 + pAd->BulkOutEpAddr[BulkOutIdx++] = endpoint[i].bEndpointAddress;
1371 + pAd->BulkOutMaxPacketSize = endpoint[i].wMaxPacketSize;
1372 +
1373 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1374 + ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
1375 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1376 + ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress));
1377 + }
1378 + }
1379 +
1380 + if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
1381 + {
1382 + printk("Could not find both bulk-in and bulk-out endpoints\n");
1383 + return FALSE;
1384 + }
1385 +
1386 + return TRUE;
1387 +}
1388 +
1389 +#else
1390 +BOOLEAN RT28XXProbePostConfig(
1391 + IN void *_dev_p,
1392 + IN RTMP_ADAPTER *pAd,
1393 + IN INT32 interface)
1394 +{
1395 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1396 + struct usb_host_interface *iface_desc;
1397 + ULONG BulkOutIdx;
1398 + UINT32 i;
1399 +
1400 +
1401 + /* get the active interface descriptor */
1402 + iface_desc = intf->cur_altsetting;
1403 +
1404 + /* get # of enpoints */
1405 + pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
1406 + DBGPRINT(RT_DEBUG_TRACE,
1407 + ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
1408 +
1409 + /* Configure Pipes */
1410 + BulkOutIdx = 0;
1411 +
1412 + for(i=0; i<pAd->NumberOfPipes; i++)
1413 + {
1414 + if ((iface_desc->endpoint[i].desc.bmAttributes ==
1415 + USB_ENDPOINT_XFER_BULK) &&
1416 + ((iface_desc->endpoint[i].desc.bEndpointAddress &
1417 + USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
1418 + {
1419 + pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress;
1420 + pAd->BulkInMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1421 +
1422 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1423 + ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));
1424 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1425 + ("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress));
1426 + }
1427 + else if ((iface_desc->endpoint[i].desc.bmAttributes ==
1428 + USB_ENDPOINT_XFER_BULK) &&
1429 + ((iface_desc->endpoint[i].desc.bEndpointAddress &
1430 + USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
1431 + {
1432 + // there are 6 bulk out EP. EP6 highest priority.
1433 + // EP1-4 is EDCA. EP5 is HCCA.
1434 + pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress;
1435 + pAd->BulkOutMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1436 +
1437 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1438 + ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
1439 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1440 + ("EP address = 0x%2x \n", iface_desc->endpoint[i].desc.bEndpointAddress));
1441 + }
1442 + }
1443 +
1444 + if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
1445 + {
1446 + printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __FUNCTION__);
1447 + return FALSE;
1448 + }
1449 +
1450 + return TRUE;
1451 +}
1452 +#endif // LINUX_VERSION_CODE //
1453 +
1454 +
1455 +/*
1456 +========================================================================
1457 +Routine Description:
1458 + Disable DMA.
1459 +
1460 +Arguments:
1461 + *pAd the raxx interface data pointer
1462 +
1463 +Return Value:
1464 + None
1465 +
1466 +Note:
1467 +========================================================================
1468 +*/
1469 +VOID RT28XXDMADisable(
1470 + IN RTMP_ADAPTER *pAd)
1471 +{
1472 + // no use
1473 +}
1474 +
1475 +
1476 +
1477 +/*
1478 +========================================================================
1479 +Routine Description:
1480 + Enable DMA.
1481 +
1482 +Arguments:
1483 + *pAd the raxx interface data pointer
1484 +
1485 +Return Value:
1486 + None
1487 +
1488 +Note:
1489 +========================================================================
1490 +*/
1491 +VOID RT28XXDMAEnable(
1492 + IN RTMP_ADAPTER *pAd)
1493 +{
1494 + WPDMA_GLO_CFG_STRUC GloCfg;
1495 + USB_DMA_CFG_STRUC UsbCfg;
1496 + int i = 0;
1497 +
1498 +
1499 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1500 + do
1501 + {
1502 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1503 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
1504 + break;
1505 +
1506 + DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
1507 + RTMPusecDelay(1000);
1508 + i++;
1509 + }while ( i <200);
1510 +
1511 +
1512 + RTMPusecDelay(50);
1513 + GloCfg.field.EnTXWriteBackDDONE = 1;
1514 + GloCfg.field.EnableRxDMA = 1;
1515 + GloCfg.field.EnableTxDMA = 1;
1516 + DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1517 + RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1518 +
1519 + UsbCfg.word = 0;
1520 + UsbCfg.field.phyclear = 0;
1521 + /* usb version is 1.1,do not use bulk in aggregation */
1522 + if (pAd->BulkInMaxPacketSize == 512)
1523 + UsbCfg.field.RxBulkAggEn = 1;
1524 + /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */
1525 + UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3;
1526 + UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */
1527 + UsbCfg.field.RxBulkEn = 1;
1528 + UsbCfg.field.TxBulkEn = 1;
1529 +
1530 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);
1531 +
1532 +}
1533 +
1534 +/*
1535 +========================================================================
1536 +Routine Description:
1537 + Write Beacon buffer to Asic.
1538 +
1539 +Arguments:
1540 + *pAd the raxx interface data pointer
1541 +
1542 +Return Value:
1543 + None
1544 +
1545 +Note:
1546 +========================================================================
1547 +*/
1548 +VOID RT28xx_UpdateBeaconToAsic(
1549 + IN RTMP_ADAPTER *pAd,
1550 + IN INT apidx,
1551 + IN ULONG FrameLen,
1552 + IN ULONG UpdatePos)
1553 +{
1554 + PUCHAR pBeaconFrame = NULL;
1555 + UCHAR *ptr;
1556 + UINT i, padding;
1557 + BEACON_SYNC_STRUCT *pBeaconSync = pAd->CommonCfg.pBeaconSync;
1558 + UINT32 longValue;
1559 + BOOLEAN bBcnReq = FALSE;
1560 + UCHAR bcn_idx = 0;
1561 +
1562 +
1563 + if (pBeaconFrame == NULL)
1564 + {
1565 + DBGPRINT(RT_DEBUG_ERROR,("pBeaconFrame is NULL!\n"));
1566 + return;
1567 + }
1568 +
1569 + if (pBeaconSync == NULL)
1570 + {
1571 + DBGPRINT(RT_DEBUG_ERROR,("pBeaconSync is NULL!\n"));
1572 + return;
1573 + }
1574 +
1575 + //if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) ||
1576 + // ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP))
1577 + // )
1578 + if (bBcnReq == FALSE)
1579 + {
1580 + /* when the ra interface is down, do not send its beacon frame */
1581 + /* clear all zero */
1582 + for(i=0; i<TXWI_SIZE; i+=4) {
1583 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1584 + }
1585 + pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1586 + NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE);
1587 + }
1588 + else
1589 + {
1590 + ptr = (PUCHAR)&pAd->BeaconTxWI;
1591 +#ifdef RT_BIG_ENDIAN
1592 + RTMPWIEndianChange(ptr, TYPE_TXWI);
1593 +#endif
1594 + if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE)
1595 + { // If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames.
1596 + pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1597 + NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE);
1598 + }
1599 +
1600 + if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) != (1 << bcn_idx))
1601 + {
1602 + for (i=0; i<TXWI_SIZE; i+=4) // 16-byte TXWI field
1603 + {
1604 + longValue = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1605 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longValue);
1606 + ptr += 4;
1607 + }
1608 + }
1609 +
1610 + ptr = pBeaconSync->BeaconBuf[bcn_idx];
1611 + padding = (FrameLen & 0x01);
1612 + NdisZeroMemory((PUCHAR)(pBeaconFrame + FrameLen), padding);
1613 + FrameLen += padding;
1614 + for (i = 0 ; i < FrameLen /*HW_BEACON_OFFSET*/; i += 2)
1615 + {
1616 + if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE)
1617 + {
1618 + NdisMoveMemory(ptr, pBeaconFrame, 2);
1619 + //shortValue = *ptr + (*(ptr+1)<<8);
1620 + //RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue);
1621 + RTUSBMultiWrite(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, ptr, 2);
1622 + }
1623 + ptr +=2;
1624 + pBeaconFrame += 2;
1625 + }
1626 +
1627 + pBeaconSync->BeaconBitMap |= (1 << bcn_idx);
1628 + }
1629 +
1630 +}
1631 +
1632 +
1633 +VOID RT2870_BssBeaconStop(
1634 + IN RTMP_ADAPTER *pAd)
1635 +{
1636 + BEACON_SYNC_STRUCT *pBeaconSync;
1637 + int i, offset;
1638 + BOOLEAN Cancelled = TRUE;
1639 +
1640 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1641 + if (pBeaconSync && pBeaconSync->EnableBeacon)
1642 + {
1643 + INT NumOfBcn;
1644 +
1645 +
1646 +#ifdef CONFIG_STA_SUPPORT
1647 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1648 + {
1649 + NumOfBcn = MAX_MESH_NUM;
1650 + }
1651 +#endif // CONFIG_STA_SUPPORT //
1652 +
1653 + RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1654 +
1655 + for(i=0; i<NumOfBcn; i++)
1656 + {
1657 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1658 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1659 +
1660 + for (offset=0; offset<HW_BEACON_OFFSET; offset+=4)
1661 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[i] + offset, 0x00);
1662 +
1663 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1664 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1665 + }
1666 + pBeaconSync->BeaconBitMap = 0;
1667 + pBeaconSync->DtimBitOn = 0;
1668 + }
1669 +}
1670 +
1671 +
1672 +VOID RT2870_BssBeaconStart(
1673 + IN RTMP_ADAPTER *pAd)
1674 +{
1675 + int apidx;
1676 + BEACON_SYNC_STRUCT *pBeaconSync;
1677 +// LARGE_INTEGER tsfTime, deltaTime;
1678 +
1679 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1680 + if (pBeaconSync && pBeaconSync->EnableBeacon)
1681 + {
1682 + INT NumOfBcn;
1683 +
1684 +
1685 +#ifdef CONFIG_STA_SUPPORT
1686 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1687 + {
1688 + NumOfBcn = MAX_MESH_NUM;
1689 + }
1690 +#endif // CONFIG_STA_SUPPORT //
1691 +
1692 + for(apidx=0; apidx<NumOfBcn; apidx++)
1693 + {
1694 + UCHAR CapabilityInfoLocationInBeacon = 0;
1695 + UCHAR TimIELocationInBeacon = 0;
1696 +
1697 + NdisZeroMemory(pBeaconSync->BeaconBuf[apidx], HW_BEACON_OFFSET);
1698 + pBeaconSync->CapabilityInfoLocationInBeacon[apidx] = CapabilityInfoLocationInBeacon;
1699 + pBeaconSync->TimIELocationInBeacon[apidx] = TimIELocationInBeacon;
1700 + NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx], TXWI_SIZE);
1701 + }
1702 + pBeaconSync->BeaconBitMap = 0;
1703 + pBeaconSync->DtimBitOn = 0;
1704 + pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE;
1705 +
1706 + pAd->CommonCfg.BeaconAdjust = 0;
1707 + pAd->CommonCfg.BeaconFactor = 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10);
1708 + pAd->CommonCfg.BeaconRemain = (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1;
1709 + printk("RT2870_BssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n", pAd->CommonCfg.BeaconFactor, pAd->CommonCfg.BeaconRemain);
1710 + RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer, pAd->CommonCfg.BeaconPeriod);
1711 +
1712 + }
1713 +}
1714 +
1715 +
1716 +VOID RT2870_BssBeaconInit(
1717 + IN RTMP_ADAPTER *pAd)
1718 +{
1719 + BEACON_SYNC_STRUCT *pBeaconSync;
1720 + int i;
1721 +
1722 + NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(BEACON_SYNC_STRUCT), MEM_ALLOC_FLAG);
1723 + if (pAd->CommonCfg.pBeaconSync)
1724 + {
1725 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1726 + NdisZeroMemory(pBeaconSync, sizeof(BEACON_SYNC_STRUCT));
1727 + for(i=0; i < HW_BEACON_MAX_COUNT; i++)
1728 + {
1729 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1730 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1731 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1732 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1733 + }
1734 + pBeaconSync->BeaconBitMap = 0;
1735 +
1736 + //RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE);
1737 + pBeaconSync->EnableBeacon = TRUE;
1738 + }
1739 +}
1740 +
1741 +
1742 +VOID RT2870_BssBeaconExit(
1743 + IN RTMP_ADAPTER *pAd)
1744 +{
1745 + BEACON_SYNC_STRUCT *pBeaconSync;
1746 + BOOLEAN Cancelled = TRUE;
1747 + int i;
1748 +
1749 + if (pAd->CommonCfg.pBeaconSync)
1750 + {
1751 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1752 + pBeaconSync->EnableBeacon = FALSE;
1753 + RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1754 + pBeaconSync->BeaconBitMap = 0;
1755 +
1756 + for(i=0; i<HW_BEACON_MAX_COUNT; i++)
1757 + {
1758 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1759 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1760 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1761 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1762 + }
1763 +
1764 + NdisFreeMemory(pAd->CommonCfg.pBeaconSync, HW_BEACON_OFFSET * HW_BEACON_MAX_COUNT, 0);
1765 + pAd->CommonCfg.pBeaconSync = NULL;
1766 + }
1767 +}
1768 +
1769 +VOID BeaconUpdateExec(
1770 + IN PVOID SystemSpecific1,
1771 + IN PVOID FunctionContext,
1772 + IN PVOID SystemSpecific2,
1773 + IN PVOID SystemSpecific3)
1774 +{
1775 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext;
1776 + LARGE_INTEGER tsfTime_a;//, tsfTime_b, deltaTime_exp, deltaTime_ab;
1777 + UINT32 delta, remain, remain_low, remain_high;
1778 +// BOOLEAN positive;
1779 +
1780 + ReSyncBeaconTime(pAd);
1781 +
1782 +
1783 +
1784 + RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart);
1785 + RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart);
1786 +
1787 +
1788 + //positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp);
1789 + remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart;
1790 + remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10);
1791 + remain = (remain_high + remain_low)%(pAd->CommonCfg.BeaconPeriod << 10);
1792 + delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain;
1793 +
1794 + pAd->CommonCfg.BeaconUpdateTimer.TimerValue = (delta >> 10) + 10;
1795 +
1796 +}
1797 +
1798 --- /dev/null
1799 +++ b/drivers/staging/rt2870/aironet.h
1800 @@ -0,0 +1,210 @@
1801 +/*
1802 + *************************************************************************
1803 + * Ralink Tech Inc.
1804 + * 5F., No.36, Taiyuan St., Jhubei City,
1805 + * Hsinchu County 302,
1806 + * Taiwan, R.O.C.
1807 + *
1808 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
1809 + *
1810 + * This program is free software; you can redistribute it and/or modify *
1811 + * it under the terms of the GNU General Public License as published by *
1812 + * the Free Software Foundation; either version 2 of the License, or *
1813 + * (at your option) any later version. *
1814 + * *
1815 + * This program is distributed in the hope that it will be useful, *
1816 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
1817 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
1818 + * GNU General Public License for more details. *
1819 + * *
1820 + * You should have received a copy of the GNU General Public License *
1821 + * along with this program; if not, write to the *
1822 + * Free Software Foundation, Inc., *
1823 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1824 + * *
1825 + *************************************************************************
1826 +
1827 + Module Name:
1828 + aironet.h
1829 +
1830 + Abstract:
1831 +
1832 + Revision History:
1833 + Who When What
1834 + -------- ---------- ----------------------------------------------
1835 + Name Date Modification logs
1836 + Paul Lin 04-06-15 Initial
1837 +*/
1838 +
1839 +#ifndef __AIRONET_H__
1840 +#define __AIRONET_H__
1841 +
1842 +// Measurement Type definition
1843 +#define MSRN_TYPE_UNUSED 0
1844 +#define MSRN_TYPE_CHANNEL_LOAD_REQ 1
1845 +#define MSRN_TYPE_NOISE_HIST_REQ 2
1846 +#define MSRN_TYPE_BEACON_REQ 3
1847 +#define MSRN_TYPE_FRAME_REQ 4
1848 +
1849 +// Scan Mode in Beacon Request
1850 +#define MSRN_SCAN_MODE_PASSIVE 0
1851 +#define MSRN_SCAN_MODE_ACTIVE 1
1852 +#define MSRN_SCAN_MODE_BEACON_TABLE 2
1853 +
1854 +// PHY type definition for Aironet beacon report, CCX 2 table 36-9
1855 +#define PHY_FH 1
1856 +#define PHY_DSS 2
1857 +#define PHY_UNUSED 3
1858 +#define PHY_OFDM 4
1859 +#define PHY_HR_DSS 5
1860 +#define PHY_ERP 6
1861 +
1862 +// RPI table in dBm
1863 +#define RPI_0 0 // Power <= -87
1864 +#define RPI_1 1 // -87 < Power <= -82
1865 +#define RPI_2 2 // -82 < Power <= -77
1866 +#define RPI_3 3 // -77 < Power <= -72
1867 +#define RPI_4 4 // -72 < Power <= -67
1868 +#define RPI_5 5 // -67 < Power <= -62
1869 +#define RPI_6 6 // -62 < Power <= -57
1870 +#define RPI_7 7 // -57 < Power
1871 +
1872 +// Cisco Aironet IAPP definetions
1873 +#define AIRONET_IAPP_TYPE 0x32
1874 +#define AIRONET_IAPP_SUBTYPE_REQUEST 0x01
1875 +#define AIRONET_IAPP_SUBTYPE_REPORT 0x81
1876 +
1877 +// Measurement Request detail format
1878 +typedef struct _MEASUREMENT_REQUEST {
1879 + UCHAR Channel;
1880 + UCHAR ScanMode; // Use only in beacon request, other requests did not use this field
1881 + USHORT Duration;
1882 +} MEASUREMENT_REQUEST, *PMEASUREMENT_REQUEST;
1883 +
1884 +// Beacon Measurement Report
1885 +// All these field might change to UCHAR, because we didn't do anything to these report.
1886 +// We copy all these beacons and report to CCX 2 AP.
1887 +typedef struct _BEACON_REPORT {
1888 + UCHAR Channel;
1889 + UCHAR Spare;
1890 + USHORT Duration;
1891 + UCHAR PhyType; // Definiation is listed above table 36-9
1892 + UCHAR RxPower;
1893 + UCHAR BSSID[6];
1894 + UCHAR ParentTSF[4];
1895 + UCHAR TargetTSF[8];
1896 + USHORT BeaconInterval;
1897 + USHORT CapabilityInfo;
1898 +} BEACON_REPORT, *PBEACON_REPORT;
1899 +
1900 +// Frame Measurement Report (Optional)
1901 +typedef struct _FRAME_REPORT {
1902 + UCHAR Channel;
1903 + UCHAR Spare;
1904 + USHORT Duration;
1905 + UCHAR TA;
1906 + UCHAR BSSID[6];
1907 + UCHAR RSSI;
1908 + UCHAR Count;
1909 +} FRAME_REPORT, *PFRAME_REPORT;
1910 +
1911 +#pragma pack(1)
1912 +// Channel Load Report
1913 +typedef struct _CHANNEL_LOAD_REPORT {
1914 + UCHAR Channel;
1915 + UCHAR Spare;
1916 + USHORT Duration;
1917 + UCHAR CCABusy;
1918 +} CHANNEL_LOAD_REPORT, *PCHANNEL_LOAD_REPORT;
1919 +#pragma pack()
1920 +
1921 +// Nosie Histogram Report
1922 +typedef struct _NOISE_HIST_REPORT {
1923 + UCHAR Channel;
1924 + UCHAR Spare;
1925 + USHORT Duration;
1926 + UCHAR Density[8];
1927 +} NOISE_HIST_REPORT, *PNOISE_HIST_REPORT;
1928 +
1929 +// Radio Management Capability element
1930 +typedef struct _RADIO_MANAGEMENT_CAPABILITY {
1931 + UCHAR Eid; // TODO: Why the Eid is 1 byte, not normal 2 bytes???
1932 + UCHAR Length;
1933 + UCHAR AironetOui[3]; // AIronet OUI (00 40 96)
1934 + UCHAR Type; // Type / Version
1935 + USHORT Status; // swap16 required
1936 +} RADIO_MANAGEMENT_CAPABILITY, *PRADIO_MANAGEMENT_CAPABILITY;
1937 +
1938 +// Measurement Mode Bit definition
1939 +typedef struct _MEASUREMENT_MODE {
1940 + UCHAR Rsvd:4;
1941 + UCHAR Report:1;
1942 + UCHAR NotUsed:1;
1943 + UCHAR Enable:1;
1944 + UCHAR Parallel:1;
1945 +} MEASUREMENT_MODE, *PMEASUREMENT_MODE;
1946 +
1947 +// Measurement Request element, This is little endian mode
1948 +typedef struct _MEASUREMENT_REQUEST_ELEMENT {
1949 + USHORT Eid;
1950 + USHORT Length; // swap16 required
1951 + USHORT Token; // non-zero unique token
1952 + UCHAR Mode; // Measurement Mode
1953 + UCHAR Type; // Measurement type
1954 +} MEASUREMENT_REQUEST_ELEMENT, *PMEASUREMENT_REQUEST_ELEMENT;
1955 +
1956 +// Measurement Report element, This is little endian mode
1957 +typedef struct _MEASUREMENT_REPORT_ELEMENT {
1958 + USHORT Eid;
1959 + USHORT Length; // swap16 required
1960 + USHORT Token; // non-zero unique token
1961 + UCHAR Mode; // Measurement Mode
1962 + UCHAR Type; // Measurement type
1963 +} MEASUREMENT_REPORT_ELEMENT, *PMEASUREMENT_REPORT_ELEMENT;
1964 +
1965 +// Cisco Aironet IAPP Frame Header, Network byte order used
1966 +typedef struct _AIRONET_IAPP_HEADER {
1967 + UCHAR CiscoSnapHeader[8]; // 8 bytes Cisco snap header
1968 + USHORT Length; // IAPP ID & length, remember to swap16 in LE system
1969 + UCHAR Type; // IAPP type
1970 + UCHAR SubType; // IAPP subtype
1971 + UCHAR DA[6]; // Destination MAC address
1972 + UCHAR SA[6]; // Source MAC address
1973 + USHORT Token; // Dialog token, no need to swap16 since it is for yoken usage only
1974 +} AIRONET_IAPP_HEADER, *PAIRONET_IAPP_HEADER;
1975 +
1976 +// Radio Measurement Request frame
1977 +typedef struct _AIRONET_RM_REQUEST_FRAME {
1978 + AIRONET_IAPP_HEADER IAPP; // Common header
1979 + UCHAR Delay; // Activation Delay
1980 + UCHAR Offset; // Measurement offset
1981 +} AIRONET_RM_REQUEST_FRAME, *PAIRONET_RM_REQUEST_FRAME;
1982 +
1983 +// Radio Measurement Report frame
1984 +typedef struct _AIRONET_RM_REPORT_FRAME {
1985 + AIRONET_IAPP_HEADER IAPP; // Common header
1986 +} AIRONET_RM_REPORT_FRAME, *PAIRONET_RM_REPORT_FRAME;
1987 +
1988 +// Saved element request actions which will saved in StaCfg.
1989 +typedef struct _RM_REQUEST_ACTION {
1990 + MEASUREMENT_REQUEST_ELEMENT ReqElem; // Saved request element
1991 + MEASUREMENT_REQUEST Measurement; // Saved measurement within the request element
1992 +} RM_REQUEST_ACTION, *PRM_REQUEST_ACTION;
1993 +
1994 +// CCX administration control
1995 +typedef union _CCX_CONTROL {
1996 + struct {
1997 + UINT32 Enable:1; // Enable CCX2
1998 + UINT32 LeapEnable:1; // Enable LEAP at CCX2
1999 + UINT32 RMEnable:1; // Radio Measurement Enable
2000 + UINT32 DCRMEnable:1; // Non serving channel Radio Measurement enable
2001 + UINT32 QOSEnable:1; // Enable QOS for CCX 2.0 support
2002 + UINT32 FastRoamEnable:1; // Enable fast roaming
2003 + UINT32 Rsvd:2; // Not used
2004 + UINT32 dBmToRoam:8; // the condition to roam when receiving Rssi less than this value. It's negative value.
2005 + UINT32 TuLimit:16; // Limit for different channel scan
2006 + } field;
2007 + UINT32 word;
2008 +} CCX_CONTROL, *PCCX_CONTROL;
2009 +
2010 +#endif // __AIRONET_H__
2011 --- /dev/null
2012 +++ b/drivers/staging/rt2870/ap.h
2013 @@ -0,0 +1,562 @@
2014 +/*
2015 + *************************************************************************
2016 + * Ralink Tech Inc.
2017 + * 5F., No.36, Taiyuan St., Jhubei City,
2018 + * Hsinchu County 302,
2019 + * Taiwan, R.O.C.
2020 + *
2021 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
2022 + *
2023 + * This program is free software; you can redistribute it and/or modify *
2024 + * it under the terms of the GNU General Public License as published by *
2025 + * the Free Software Foundation; either version 2 of the License, or *
2026 + * (at your option) any later version. *
2027 + * *
2028 + * This program is distributed in the hope that it will be useful, *
2029 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
2030 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
2031 + * GNU General Public License for more details. *
2032 + * *
2033 + * You should have received a copy of the GNU General Public License *
2034 + * along with this program; if not, write to the *
2035 + * Free Software Foundation, Inc., *
2036 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
2037 + * *
2038 + *************************************************************************
2039 +
2040 + Module Name:
2041 + ap.h
2042 +
2043 + Abstract:
2044 + Miniport generic portion header file
2045 +
2046 + Revision History:
2047 + Who When What
2048 + -------- ---------- ----------------------------------------------
2049 + Paul Lin 08-01-2002 created
2050 + James Tan 09-06-2002 modified (Revise NTCRegTable)
2051 + John Chang 12-22-2004 modified for RT2561/2661. merge with STA driver
2052 +*/
2053 +#ifndef __AP_H__
2054 +#define __AP_H__
2055 +
2056 +
2057 +
2058 +// ========================= AP RTMP.h ================================
2059 +
2060 +
2061 +
2062 +// =============================================================
2063 +// Function Prototypes
2064 +// =============================================================
2065 +
2066 +// ap_data.c
2067 +
2068 +BOOLEAN APBridgeToWirelessSta(
2069 + IN PRTMP_ADAPTER pAd,
2070 + IN PUCHAR pHeader,
2071 + IN UINT HdrLen,
2072 + IN PUCHAR pData,
2073 + IN UINT DataLen,
2074 + IN ULONG fromwdsidx);
2075 +
2076 +BOOLEAN APHandleRxDoneInterrupt(
2077 + IN PRTMP_ADAPTER pAd);
2078 +
2079 +VOID APSendPackets(
2080 + IN NDIS_HANDLE MiniportAdapterContext,
2081 + IN PPNDIS_PACKET ppPacketArray,
2082 + IN UINT NumberOfPackets);
2083 +
2084 +NDIS_STATUS APSendPacket(
2085 + IN PRTMP_ADAPTER pAd,
2086 + IN PNDIS_PACKET pPacket);
2087 +
2088 +
2089 +NDIS_STATUS APHardTransmit(
2090 + IN PRTMP_ADAPTER pAd,
2091 + IN TX_BLK *pTxBlk,
2092 + IN UCHAR QueIdx);
2093 +
2094 +VOID APRxEAPOLFrameIndicate(
2095 + IN PRTMP_ADAPTER pAd,
2096 + IN MAC_TABLE_ENTRY *pEntry,
2097 + IN RX_BLK *pRxBlk,
2098 + IN UCHAR FromWhichBSSID);
2099 +
2100 +NDIS_STATUS APCheckRxError(
2101 + IN PRTMP_ADAPTER pAd,
2102 + IN PRT28XX_RXD_STRUC pRxD,
2103 + IN UCHAR Wcid);
2104 +
2105 +BOOLEAN APCheckClass2Class3Error(
2106 + IN PRTMP_ADAPTER pAd,
2107 + IN ULONG Wcid,
2108 + IN PHEADER_802_11 pHeader);
2109 +
2110 +VOID APHandleRxPsPoll(
2111 + IN PRTMP_ADAPTER pAd,
2112 + IN PUCHAR pAddr,
2113 + IN USHORT Aid,
2114 + IN BOOLEAN isActive);
2115 +
2116 +VOID RTMPDescriptorEndianChange(
2117 + IN PUCHAR pData,
2118 + IN ULONG DescriptorType);
2119 +
2120 +VOID RTMPFrameEndianChange(
2121 + IN PRTMP_ADAPTER pAd,
2122 + IN PUCHAR pData,
2123 + IN ULONG Dir,
2124 + IN BOOLEAN FromRxDoneInt);
2125 +
2126 +// ap_assoc.c
2127 +
2128 +VOID APAssocStateMachineInit(
2129 + IN PRTMP_ADAPTER pAd,
2130 + IN STATE_MACHINE *S,
2131 + OUT STATE_MACHINE_FUNC Trans[]);
2132 +
2133 +VOID APPeerAssocReqAction(
2134 + IN PRTMP_ADAPTER pAd,
2135 + IN MLME_QUEUE_ELEM *Elem);
2136 +
2137 +VOID APPeerReassocReqAction(
2138 + IN PRTMP_ADAPTER pAd,
2139 + IN MLME_QUEUE_ELEM *Elem);
2140 +
2141 +VOID APPeerDisassocReqAction(
2142 + IN PRTMP_ADAPTER pAd,
2143 + IN MLME_QUEUE_ELEM *Elem);
2144 +
2145 +VOID MbssKickOutStas(
2146 + IN PRTMP_ADAPTER pAd,
2147 + IN INT apidx,
2148 + IN USHORT Reason);
2149 +
2150 +VOID APMlmeKickOutSta(
2151 + IN PRTMP_ADAPTER pAd,
2152 + IN PUCHAR pStaAddr,
2153 + IN UCHAR Wcid,
2154 + IN USHORT Reason);
2155 +
2156 +VOID APMlmeDisassocReqAction(
2157 + IN PRTMP_ADAPTER pAd,
2158 + IN MLME_QUEUE_ELEM *Elem);
2159 +
2160 +VOID APCls3errAction(
2161 + IN PRTMP_ADAPTER pAd,
2162 + IN ULONG Wcid,
2163 + IN PHEADER_802_11 pHeader);
2164 +
2165 +
2166 +USHORT APBuildAssociation(
2167 + IN PRTMP_ADAPTER pAd,
2168 + IN MAC_TABLE_ENTRY *pEntry,
2169 + IN USHORT CapabilityInfo,
2170 + IN UCHAR MaxSupportedRateIn500Kbps,
2171 + IN UCHAR *RSN,
2172 + IN UCHAR *pRSNLen,
2173 + IN BOOLEAN bWmmCapable,
2174 + IN ULONG RalinkIe,
2175 +#ifdef DOT11N_DRAFT3
2176 + IN EXT_CAP_INFO_ELEMENT ExtCapInfo,
2177 +#endif // DOT11N_DRAFT3 //
2178 + IN HT_CAPABILITY_IE *pHtCapability,
2179 + IN UCHAR HtCapabilityLen,
2180 + OUT USHORT *pAid);
2181 +
2182 +/*
2183 +VOID RTMPAddClientSec(
2184 + IN PRTMP_ADAPTER pAd,
2185 + IN UCHAR BssIdx,
2186 + IN UCHAR KeyIdx,
2187 + IN UCHAR CipherAlg,
2188 + IN PUCHAR pKey,
2189 + IN PUCHAR pTxMic,
2190 + IN PUCHAR pRxMic,
2191 + IN MAC_TABLE_ENTRY *pEntry);
2192 +*/
2193 +
2194 +// ap_auth.c
2195 +
2196 +void APAuthStateMachineInit(
2197 + IN PRTMP_ADAPTER pAd,
2198 + IN STATE_MACHINE *Sm,
2199 + OUT STATE_MACHINE_FUNC Trans[]);
2200 +
2201 +VOID APMlmeDeauthReqAction(
2202 + IN PRTMP_ADAPTER pAd,
2203 + IN MLME_QUEUE_ELEM *Elem);
2204 +
2205 +VOID APCls2errAction(
2206 + IN PRTMP_ADAPTER pAd,
2207 + IN ULONG Wcid,
2208 + IN PHEADER_802_11 pHeader);
2209 +
2210 +// ap_authrsp.c
2211 +
2212 +VOID APAuthRspStateMachineInit(
2213 + IN PRTMP_ADAPTER pAd,
2214 + IN PSTATE_MACHINE Sm,
2215 + IN STATE_MACHINE_FUNC Trans[]);
2216 +
2217 +VOID APPeerAuthAtAuthRspIdleAction(
2218 + IN PRTMP_ADAPTER pAd,
2219 + IN MLME_QUEUE_ELEM *Elem);
2220 +
2221 +VOID APPeerDeauthReqAction(
2222 + IN PRTMP_ADAPTER pAd,
2223 + IN MLME_QUEUE_ELEM *Elem);
2224 +
2225 +VOID APPeerAuthSimpleRspGenAndSend(
2226 + IN PRTMP_ADAPTER pAd,
2227 + IN PHEADER_802_11 pHdr80211,
2228 + IN USHORT Alg,
2229 + IN USHORT Seq,
2230 + IN USHORT StatusCode);
2231 +
2232 +// ap_connect.c
2233 +
2234 +BOOLEAN BeaconTransmitRequired(
2235 + IN PRTMP_ADAPTER pAd,
2236 + IN INT apidx);
2237 +
2238 +VOID APMakeBssBeacon(
2239 + IN PRTMP_ADAPTER pAd,
2240 + IN INT apidx);
2241 +
2242 +VOID APUpdateBeaconFrame(
2243 + IN PRTMP_ADAPTER pAd,
2244 + IN INT apidx);
2245 +
2246 +VOID APMakeAllBssBeacon(
2247 + IN PRTMP_ADAPTER pAd);
2248 +
2249 +VOID APUpdateAllBeaconFrame(
2250 + IN PRTMP_ADAPTER pAd);
2251 +
2252 +
2253 +// ap_sync.c
2254 +
2255 +VOID APSyncStateMachineInit(
2256 + IN PRTMP_ADAPTER pAd,
2257 + IN STATE_MACHINE *Sm,
2258 + OUT STATE_MACHINE_FUNC Trans[]);
2259 +
2260 +VOID APScanTimeout(
2261 + IN PVOID SystemSpecific1,
2262 + IN PVOID FunctionContext,
2263 + IN PVOID SystemSpecific2,
2264 + IN PVOID SystemSpecific3);
2265 +
2266 +VOID APInvalidStateWhenScan(
2267 + IN PRTMP_ADAPTER pAd,
2268 + IN MLME_QUEUE_ELEM *Elem);
2269 +
2270 +VOID APScanTimeoutAction(
2271 + IN PRTMP_ADAPTER pAd,
2272 + IN MLME_QUEUE_ELEM *Elem);
2273 +
2274 +VOID APPeerProbeReqAction(
2275 + IN PRTMP_ADAPTER pAd,
2276 + IN MLME_QUEUE_ELEM *Elem);
2277 +
2278 +VOID APPeerBeaconAction(
2279 + IN PRTMP_ADAPTER pAd,
2280 + IN MLME_QUEUE_ELEM *Elem);
2281 +
2282 +VOID APMlmeScanReqAction(
2283 + IN PRTMP_ADAPTER pAd,
2284 + IN MLME_QUEUE_ELEM *Elem);
2285 +
2286 +VOID APPeerBeaconAtScanAction(
2287 + IN PRTMP_ADAPTER pAd,
2288 + IN MLME_QUEUE_ELEM *Elem);
2289 +
2290 +VOID APScanCnclAction(
2291 + IN PRTMP_ADAPTER pAd,
2292 + IN MLME_QUEUE_ELEM *Elem);
2293 +
2294 +VOID ApSiteSurvey(
2295 + IN PRTMP_ADAPTER pAd);
2296 +
2297 +VOID SupportRate(
2298 + IN PUCHAR SupRate,
2299 + IN UCHAR SupRateLen,
2300 + IN PUCHAR ExtRate,
2301 + IN UCHAR ExtRateLen,
2302 + OUT PUCHAR *Rates,
2303 + OUT PUCHAR RatesLen,
2304 + OUT PUCHAR pMaxSupportRate);
2305 +
2306 +
2307 +BOOLEAN ApScanRunning(
2308 + IN PRTMP_ADAPTER pAd);
2309 +
2310 +#ifdef DOT11N_DRAFT3
2311 +VOID APOverlappingBSSScan(
2312 + IN RTMP_ADAPTER *pAd);
2313 +#endif // DOT11N_DRAFT3 //
2314 +
2315 +// ap_wpa.c
2316 +
2317 +VOID APWpaStateMachineInit(
2318 + IN PRTMP_ADAPTER pAd,
2319 + IN STATE_MACHINE *Sm,
2320 + OUT STATE_MACHINE_FUNC Trans[]);
2321 +
2322 +// ap_mlme.c
2323 +
2324 +VOID APMlmePeriodicExec(
2325 + IN PRTMP_ADAPTER pAd);
2326 +
2327 +VOID APMlmeSelectTxRateTable(
2328 + IN PRTMP_ADAPTER pAd,
2329 + IN PMAC_TABLE_ENTRY pEntry,
2330 + IN PUCHAR *ppTable,
2331 + IN PUCHAR pTableSize,
2332 + IN PUCHAR pInitTxRateIdx);
2333 +
2334 +VOID APMlmeSetTxRate(
2335 + IN PRTMP_ADAPTER pAd,
2336 + IN PMAC_TABLE_ENTRY pEntry,
2337 + IN PRTMP_TX_RATE_SWITCH pTxRate);
2338 +
2339 +VOID APMlmeDynamicTxRateSwitching(
2340 + IN PRTMP_ADAPTER pAd);
2341 +
2342 +VOID APQuickResponeForRateUpExec(
2343 + IN PVOID SystemSpecific1,
2344 + IN PVOID FunctionContext,
2345 + IN PVOID SystemSpecific2,
2346 + IN PVOID SystemSpecific3);
2347 +
2348 +BOOLEAN APMsgTypeSubst(
2349 + IN PRTMP_ADAPTER pAd,
2350 + IN PFRAME_802_11 pFrame,
2351 + OUT INT *Machine,
2352 + OUT INT *MsgType);
2353 +
2354 +VOID APQuickResponeForRateUpExec(
2355 + IN PVOID SystemSpecific1,
2356 + IN PVOID FunctionContext,
2357 + IN PVOID SystemSpecific2,
2358 + IN PVOID SystemSpecific3);
2359 +
2360 +#ifdef RT2870
2361 +VOID BeaconUpdateExec(
2362 + IN PVOID SystemSpecific1,
2363 + IN PVOID FunctionContext,
2364 + IN PVOID SystemSpecific2,
2365 + IN PVOID SystemSpecific3);
2366 +#endif // RT2870 //
2367 +
2368 +VOID RTMPSetPiggyBack(
2369 + IN PRTMP_ADAPTER pAd,
2370 + IN BOOLEAN bPiggyBack);
2371 +
2372 +VOID APAsicEvaluateRxAnt(
2373 + IN PRTMP_ADAPTER pAd);
2374 +
2375 +VOID APAsicRxAntEvalTimeout(
2376 + IN PRTMP_ADAPTER pAd);
2377 +
2378 +// ap.c
2379 +
2380 +VOID APSwitchChannel(
2381 + IN PRTMP_ADAPTER pAd,
2382 + IN INT Channel);
2383 +
2384 +NDIS_STATUS APInitialize(
2385 + IN PRTMP_ADAPTER pAd);
2386 +
2387 +VOID APShutdown(
2388 + IN PRTMP_ADAPTER pAd);
2389 +
2390 +VOID APStartUp(
2391 + IN PRTMP_ADAPTER pAd);
2392 +
2393 +VOID APStop(
2394 + IN PRTMP_ADAPTER pAd);
2395 +
2396 +VOID APCleanupPsQueue(
2397 + IN PRTMP_ADAPTER pAd,
2398 + IN PQUEUE_HEADER pQueue);
2399 +
2400 +VOID MacTableReset(
2401 + IN PRTMP_ADAPTER pAd);
2402 +
2403 +MAC_TABLE_ENTRY *MacTableInsertEntry(
2404 + IN PRTMP_ADAPTER pAd,
2405 + IN PUCHAR pAddr,
2406 + IN UCHAR apidx,
2407 + IN BOOLEAN CleanAll);
2408 +
2409 +BOOLEAN MacTableDeleteEntry(
2410 + IN PRTMP_ADAPTER pAd,
2411 + IN USHORT wcid,
2412 + IN PUCHAR pAddr);
2413 +
2414 +MAC_TABLE_ENTRY *MacTableLookup(
2415 + IN PRTMP_ADAPTER pAd,
2416 + IN PUCHAR pAddr);
2417 +
2418 +VOID MacTableMaintenance(
2419 + IN PRTMP_ADAPTER pAd);
2420 +
2421 +UINT32 MacTableAssocStaNumGet(
2422 + IN PRTMP_ADAPTER pAd);
2423 +
2424 +MAC_TABLE_ENTRY *APSsPsInquiry(
2425 + IN PRTMP_ADAPTER pAd,
2426 + IN PUCHAR pAddr,
2427 + OUT SST *Sst,
2428 + OUT USHORT *Aid,
2429 + OUT UCHAR *PsMode,
2430 + OUT UCHAR *Rate);
2431 +
2432 +BOOLEAN APPsIndicate(
2433 + IN PRTMP_ADAPTER pAd,
2434 + IN PUCHAR pAddr,
2435 + IN ULONG Wcid,
2436 + IN UCHAR Psm);
2437 +
2438 +VOID ApLogEvent(
2439 + IN PRTMP_ADAPTER pAd,
2440 + IN PUCHAR pAddr,
2441 + IN USHORT Event);
2442 +
2443 +#ifdef DOT11_N_SUPPORT
2444 +VOID APUpdateOperationMode(
2445 + IN PRTMP_ADAPTER pAd);
2446 +#endif // DOT11_N_SUPPORT //
2447 +
2448 +VOID APUpdateCapabilityAndErpIe(
2449 + IN PRTMP_ADAPTER pAd);
2450 +
2451 +BOOLEAN ApCheckAccessControlList(
2452 + IN PRTMP_ADAPTER pAd,
2453 + IN PUCHAR pAddr,
2454 + IN UCHAR Apidx);
2455 +
2456 +VOID ApUpdateAccessControlList(
2457 + IN PRTMP_ADAPTER pAd,
2458 + IN UCHAR Apidx);
2459 +
2460 +VOID ApEnqueueNullFrame(
2461 + IN PRTMP_ADAPTER pAd,
2462 + IN PUCHAR pAddr,
2463 + IN UCHAR TxRate,
2464 + IN UCHAR PID,
2465 + IN UCHAR apidx,
2466 + IN BOOLEAN bQosNull,
2467 + IN BOOLEAN bEOSP,
2468 + IN UCHAR OldUP);
2469 +
2470 +VOID ApSendFrame(
2471 + IN PRTMP_ADAPTER pAd,
2472 + IN PVOID pBuffer,
2473 + IN ULONG Length,
2474 + IN UCHAR TxRate,
2475 + IN UCHAR PID);
2476 +
2477 +VOID ApEnqueueAckFrame(
2478 + IN PRTMP_ADAPTER pAd,
2479 + IN PUCHAR pAddr,
2480 + IN UCHAR TxRate,
2481 + IN UCHAR apidx);
2482 +
2483 +UCHAR APAutoSelectChannel(
2484 + IN PRTMP_ADAPTER pAd,
2485 + IN BOOLEAN Optimal);
2486 +
2487 +// ap_sanity.c
2488 +
2489 +
2490 +BOOLEAN PeerAssocReqCmmSanity(
2491 + IN PRTMP_ADAPTER pAd,
2492 + IN BOOLEAN isRessoc,
2493 + IN VOID *Msg,
2494 + IN ULONG MsgLen,
2495 + OUT PUCHAR pAddr2,
2496 + OUT USHORT *pCapabilityInfo,
2497 + OUT USHORT *pListenInterval,
2498 + OUT PUCHAR pApAddr,
2499 + OUT UCHAR *pSsidLen,
2500 + OUT char *Ssid,
2501 + OUT UCHAR *pRatesLen,
2502 + OUT UCHAR Rates[],
2503 + OUT UCHAR *RSN,
2504 + OUT UCHAR *pRSNLen,
2505 + OUT BOOLEAN *pbWmmCapable,
2506 +#ifdef WSC_AP_SUPPORT
2507 + OUT BOOLEAN *pWscCapable,
2508 +#endif // WSC_AP_SUPPORT //
2509 + OUT ULONG *pRalinkIe,
2510 +#ifdef DOT11N_DRAFT3
2511 + OUT EXT_CAP_INFO_ELEMENT *pExtCapInfo,
2512 +#endif // DOT11N_DRAFT3 //
2513 + OUT UCHAR *pHtCapabilityLen,
2514 + OUT HT_CAPABILITY_IE *pHtCapability);
2515 +
2516 +BOOLEAN PeerDisassocReqSanity(
2517 + IN PRTMP_ADAPTER pAd,
2518 + IN VOID *Msg,
2519 + IN ULONG MsgLen,
2520 + OUT PUCHAR pAddr2,
2521 + OUT USHORT *Reason);
2522 +
2523 +BOOLEAN PeerDeauthReqSanity(
2524 + IN PRTMP_ADAPTER pAd,
2525 + IN VOID *Msg,
2526 + IN ULONG MsgLen,
2527 + OUT PUCHAR pAddr2,
2528 + OUT USHORT *Reason);
2529 +
2530 +BOOLEAN APPeerAuthSanity(
2531 + IN PRTMP_ADAPTER pAd,
2532 + IN VOID *Msg,
2533 + IN ULONG MsgLen,
2534 + OUT PUCHAR pAddr1,
2535 + OUT PUCHAR pAddr2,
2536 + OUT USHORT *Alg,
2537 + OUT USHORT *Seq,
2538 + OUT USHORT *Status,
2539 + CHAR *ChlgText);
2540 +
2541 +BOOLEAN APPeerProbeReqSanity(
2542 + IN PRTMP_ADAPTER pAd,
2543 + IN VOID *Msg,
2544 + IN ULONG MsgLen,
2545 + OUT PUCHAR pAddr2,
2546 + OUT CHAR Ssid[],
2547 + OUT UCHAR *SsidLen);
2548 +
2549 +BOOLEAN APPeerBeaconAndProbeRspSanity(
2550 + IN PRTMP_ADAPTER pAd,
2551 + IN VOID *Msg,
2552 + IN ULONG MsgLen,
2553 + OUT PUCHAR pAddr2,
2554 + OUT PUCHAR pBssid,
2555 + OUT CHAR Ssid[],
2556 + OUT UCHAR *SsidLen,
2557 + OUT UCHAR *BssType,
2558 + OUT USHORT *BeaconPeriod,
2559 + OUT UCHAR *Channel,
2560 + OUT LARGE_INTEGER *Timestamp,
2561 + OUT USHORT *CapabilityInfo,
2562 + OUT UCHAR Rate[],
2563 + OUT UCHAR *RateLen,
2564 + OUT BOOLEAN *ExtendedRateIeExist,
2565 + OUT UCHAR *Erp);
2566 +
2567 +// ap_info.c
2568 +
2569 +
2570 +
2571 +// ================== end of AP RTMP.h ========================
2572 +
2573 +
2574 +#endif // __AP_H__
2575 +
2576 --- /dev/null
2577 +++ b/drivers/staging/rt2870/chlist.h
2578 @@ -0,0 +1,1296 @@
2579 +/*
2580 + *************************************************************************
2581 + * Ralink Tech Inc.
2582 + * 5F., No.36, Taiyuan St., Jhubei City,
2583 + * Hsinchu County 302,
2584 + * Taiwan, R.O.C.
2585 + *
2586 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
2587 + *
2588 + * This program is free software; you can redistribute it and/or modify *
2589 + * it under the terms of the GNU General Public License as published by *
2590 + * the Free Software Foundation; either version 2 of the License, or *
2591 + * (at your option) any later version. *
2592 + * *
2593 + * This program is distributed in the hope that it will be useful, *
2594 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
2595 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
2596 + * GNU General Public License for more details. *
2597 + * *
2598 + * You should have received a copy of the GNU General Public License *
2599 + * along with this program; if not, write to the *
2600 + * Free Software Foundation, Inc., *
2601 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
2602 + * *
2603 + *************************************************************************
2604 +
2605 + Module Name:
2606 + chlist.c
2607 +
2608 + Abstract:
2609 +
2610 + Revision History:
2611 + Who When What
2612 + -------- ---------- ----------------------------------------------
2613 + Fonchi Wu 2007-12-19 created
2614 +*/
2615 +
2616 +#ifndef __CHLIST_H__
2617 +#define __CHLIST_H__
2618 +
2619 +#include "rtmp_type.h"
2620 +#include "rtmp_def.h"
2621 +
2622 +
2623 +#define ODOR 0
2624 +#define IDOR 1
2625 +#define BOTH 2
2626 +
2627 +#define BAND_5G 0
2628 +#define BAND_24G 1
2629 +#define BAND_BOTH 2
2630 +
2631 +typedef struct _CH_DESP {
2632 + UCHAR FirstChannel;
2633 + UCHAR NumOfCh;
2634 + CHAR MaxTxPwr; // dBm
2635 + UCHAR Geography; // 0:out door, 1:in door, 2:both
2636 + BOOLEAN DfsReq; // Dfs require, 0: No, 1: yes.
2637 +} CH_DESP, *PCH_DESP;
2638 +
2639 +typedef struct _CH_REGION {
2640 + UCHAR CountReg[3];
2641 + UCHAR DfsType; // 0: CE, 1: FCC, 2: JAP, 3:JAP_W53, JAP_W56
2642 + CH_DESP ChDesp[10];
2643 +} CH_REGION, *PCH_REGION;
2644 +
2645 +static CH_REGION ChRegion[] =
2646 +{
2647 + { // Antigua and Berbuda
2648 + "AG",
2649 + CE,
2650 + {
2651 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2652 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2653 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2654 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2655 + { 0}, // end
2656 + }
2657 + },
2658 +
2659 + { // Argentina
2660 + "AR",
2661 + CE,
2662 + {
2663 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2664 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2665 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2666 + { 0}, // end
2667 + }
2668 + },
2669 +
2670 + { // Aruba
2671 + "AW",
2672 + CE,
2673 + {
2674 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2675 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2676 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2677 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2678 + { 0}, // end
2679 + }
2680 + },
2681 +
2682 + { // Australia
2683 + "AU",
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, 24, BOTH, FALSE}, // 5G, ch 52~64
2689 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2690 + { 0}, // end
2691 + }
2692 + },
2693 +
2694 + { // Austria
2695 + "AT",
2696 + CE,
2697 + {
2698 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2699 + { 36, 4, 23, IDOR, TRUE}, // 5G, ch 36~48
2700 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2701 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2702 + { 0}, // end
2703 + }
2704 + },
2705 +
2706 + { // Bahamas
2707 + "BS",
2708 + CE,
2709 + {
2710 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2711 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2712 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2713 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2714 + { 0}, // end
2715 + }
2716 + },
2717 +
2718 + { // Barbados
2719 + "BB",
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 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2726 + { 0}, // end
2727 + }
2728 + },
2729 +
2730 + { // Bermuda
2731 + "BM",
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 + { // Brazil
2743 + "BR",
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, 24, BOTH, FALSE}, // 5G, ch 100~140
2750 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 100~140
2751 + { 0}, // end
2752 + }
2753 + },
2754 +
2755 + { // Belgium
2756 + "BE",
2757 + CE,
2758 + {
2759 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2760 + { 36, 4, 18, IDOR, FALSE}, // 5G, ch 36~48
2761 + { 52, 4, 18, IDOR, FALSE}, // 5G, ch 52~64
2762 + { 0}, // end
2763 + }
2764 + },
2765 +
2766 + { // Bulgaria
2767 + "BG",
2768 + CE,
2769 + {
2770 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2771 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2772 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2773 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
2774 + { 0}, // end
2775 + }
2776 + },
2777 +
2778 + { // Canada
2779 + "CA",
2780 + CE,
2781 + {
2782 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2783 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2784 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2785 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2786 + { 0}, // end
2787 + }
2788 + },
2789 +
2790 + { // Cayman IsLands
2791 + "KY",
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, 24, BOTH, FALSE}, // 5G, ch 52~64
2797 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2798 + { 0}, // end
2799 + }
2800 + },
2801 +
2802 + { // Chile
2803 + "CL",
2804 + CE,
2805 + {
2806 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2807 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 36~48
2808 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
2809 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
2810 + { 0}, // end
2811 + }
2812 + },
2813 +
2814 + { // China
2815 + "CN",
2816 + CE,
2817 + {
2818 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2819 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
2820 + { 0}, // end
2821 + }
2822 + },
2823 +
2824 + { // Colombia
2825 + "CO",
2826 + CE,
2827 + {
2828 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2829 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2830 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2831 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2832 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2833 + { 0}, // end
2834 + }
2835 + },
2836 +
2837 + { // Costa Rica
2838 + "CR",
2839 + CE,
2840 + {
2841 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2842 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2843 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2844 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2845 + { 0}, // end
2846 + }
2847 + },
2848 +
2849 + { // Cyprus
2850 + "CY",
2851 + CE,
2852 + {
2853 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2854 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2855 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
2856 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2857 + { 0}, // end
2858 + }
2859 + },
2860 +
2861 + { // Czech_Republic
2862 + "CZ",
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, 23, IDOR, TRUE}, // 5G, ch 52~64
2868 + { 0}, // end
2869 + }
2870 + },
2871 +
2872 + { // Denmark
2873 + "DK",
2874 + CE,
2875 + {
2876 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2877 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2878 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2879 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2880 + { 0}, // end
2881 + }
2882 + },
2883 +
2884 + { // Dominican Republic
2885 + "DO",
2886 + CE,
2887 + {
2888 + { 1, 0, 20, BOTH, FALSE}, // 2.4 G, ch 0
2889 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
2890 + { 0}, // end
2891 + }
2892 + },
2893 +
2894 + { // Equador
2895 + "EC",
2896 + CE,
2897 + {
2898 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2899 + { 100, 11, 27, BOTH, FALSE}, // 5G, ch 100~140
2900 + { 0}, // end
2901 + }
2902 + },
2903 +
2904 + { // El Salvador
2905 + "SV",
2906 + CE,
2907 + {
2908 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2909 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2910 + { 52, 4, 30, BOTH, TRUE}, // 5G, ch 52~64
2911 + { 149, 4, 36, BOTH, TRUE}, // 5G, ch 149~165
2912 + { 0}, // end
2913 + }
2914 + },
2915 +
2916 + { // Finland
2917 + "FI",
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, 23, IDOR, TRUE}, // 5G, ch 52~64
2923 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2924 + { 0}, // end
2925 + }
2926 + },
2927 +
2928 + { // France
2929 + "FR",
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 + { 0}, // end
2936 + }
2937 + },
2938 +
2939 + { // Germany
2940 + "DE",
2941 + CE,
2942 + {
2943 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2944 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2945 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2946 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2947 + { 0}, // end
2948 + }
2949 + },
2950 +
2951 + { // Greece
2952 + "GR",
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, ODOR, TRUE}, // 5G, ch 100~140
2959 + { 0}, // end
2960 + }
2961 + },
2962 +
2963 + { // Guam
2964 + "GU",
2965 + CE,
2966 + {
2967 + { 1, 11, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
2968 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2969 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2970 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2971 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2972 + { 0}, // end
2973 + }
2974 + },
2975 +
2976 + { // Guatemala
2977 + "GT",
2978 + CE,
2979 + {
2980 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2981 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2982 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2983 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2984 + { 0}, // end
2985 + }
2986 + },
2987 +
2988 + { // Haiti
2989 + "HT",
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 + { // Honduras
3001 + "HN",
3002 + CE,
3003 + {
3004 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3005 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3006 + { 0}, // end
3007 + }
3008 + },
3009 +
3010 + { // Hong Kong
3011 + "HK",
3012 + CE,
3013 + {
3014 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3015 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3016 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3017 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3018 + { 0}, // end
3019 + }
3020 + },
3021 +
3022 + { // Hungary
3023 + "HU",
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, TRUE}, // 5G, ch 52~64
3029 + { 0}, // end
3030 + }
3031 + },
3032 +
3033 + { // Iceland
3034 + "IS",
3035 + CE,
3036 + {
3037 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3038 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3039 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3040 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3041 + { 0}, // end
3042 + }
3043 + },
3044 +
3045 + { // India
3046 + "IN",
3047 + CE,
3048 + {
3049 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3050 + { 149, 4, 24, IDOR, FALSE}, // 5G, ch 149~161
3051 + { 0}, // end
3052 + }
3053 + },
3054 +
3055 + { // Indonesia
3056 + "ID",
3057 + CE,
3058 + {
3059 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3060 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3061 + { 0}, // end
3062 + }
3063 + },
3064 +
3065 + { // Ireland
3066 + "IE",
3067 + CE,
3068 + {
3069 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3070 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3071 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3072 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
3073 + { 0}, // end
3074 + }
3075 + },
3076 +
3077 + { // Israel
3078 + "IL",
3079 + CE,
3080 + {
3081 + { 1, 3, 20, IDOR, FALSE}, // 2.4 G, ch 1~3
3082 + { 4, 6, 20, BOTH, FALSE}, // 2.4 G, ch 4~9
3083 + { 10, 4, 20, IDOR, FALSE}, // 2.4 G, ch 10~13
3084 + { 0}, // end
3085 + }
3086 + },
3087 +
3088 + { // Italy
3089 + "IT",
3090 + CE,
3091 + {
3092 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3093 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3094 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3095 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
3096 + { 0}, // end
3097 + }
3098 + },
3099 +
3100 + { // Japan
3101 + "JP",
3102 + JAP,
3103 + {
3104 + { 1, 14, 20, BOTH, FALSE}, // 2.4 G, ch 1~14
3105 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3106 + { 0}, // end
3107 + }
3108 + },
3109 +
3110 + { // Jordan
3111 + "JO",
3112 + CE,
3113 + {
3114 + { 1, 13, 20, IDOR, FALSE}, // 2.4 G, ch 1~13
3115 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3116 + { 149, 4, 23, IDOR, FALSE}, // 5G, ch 149~161
3117 + { 0}, // end
3118 + }
3119 + },
3120 +
3121 + { // Latvia
3122 + "LV",
3123 + CE,
3124 + {
3125 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3126 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3127 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3128 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3129 + { 0}, // end
3130 + }
3131 + },
3132 +
3133 + { // Liechtenstein
3134 + "LI",
3135 + CE,
3136 + {
3137 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3138 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3139 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3140 + { 0}, // end
3141 + }
3142 + },
3143 +
3144 + { // Lithuania
3145 + "LT",
3146 + CE,
3147 + {
3148 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3149 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
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 + { // Luxemburg
3157 + "LU",
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 + { // Malaysia
3169 + "MY",
3170 + CE,
3171 + {
3172 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3173 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3174 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
3175 + { 0}, // end
3176 + }
3177 + },
3178 +
3179 + { // Malta
3180 + "MT",
3181 + CE,
3182 + {
3183 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3184 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3185 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3186 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3187 + { 0}, // end
3188 + }
3189 + },
3190 +
3191 + { // Marocco
3192 + "MA",
3193 + CE,
3194 + {
3195 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3196 + { 36, 4, 24, IDOR, FALSE}, // 5G, ch 36~48
3197 + { 0}, // end
3198 + }
3199 + },
3200 +
3201 + { // Mexico
3202 + "MX",
3203 + CE,
3204 + {
3205 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3206 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3207 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
3208 + { 149, 5, 30, IDOR, FALSE}, // 5G, ch 149~165
3209 + { 0}, // end
3210 + }
3211 + },
3212 +
3213 + { // Netherlands
3214 + "NL",
3215 + CE,
3216 + {
3217 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3218 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3219 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
3220 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3221 + { 0}, // end
3222 + }
3223 + },
3224 +
3225 + { // New Zealand
3226 + "NZ",
3227 + CE,
3228 + {
3229 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3230 + { 36, 4, 24, BOTH, FALSE}, // 5G, ch 36~48
3231 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
3232 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3233 + { 0}, // end
3234 + }
3235 + },
3236 +
3237 + { // Norway
3238 + "NO",
3239 + CE,
3240 + {
3241 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3242 + { 36, 4, 24, IDOR, FALSE}, // 5G, ch 36~48
3243 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
3244 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 149~161
3245 + { 0}, // end
3246 + }
3247 + },
3248 +
3249 + { // Peru
3250 + "PE",
3251 + CE,
3252 + {
3253 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3254 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3255 + { 0}, // end
3256 + }
3257 + },
3258 +
3259 + { // Portugal
3260 + "PT",
3261 + CE,
3262 + {
3263 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3264 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3265 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3266 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3267 + { 0}, // end
3268 + }
3269 + },
3270 +
3271 + { // Poland
3272 + "PL",
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 + { // Romania
3284 + "RO",
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 + { // Russia
3296 + "RU",
3297 + CE,
3298 + {
3299 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3300 + { 149, 4, 20, IDOR, FALSE}, // 5G, ch 149~161
3301 + { 0}, // end
3302 + }
3303 + },
3304 +
3305 + { // Saudi Arabia
3306 + "SA",
3307 + CE,
3308 + {
3309 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3310 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3311 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3312 + { 149, 4, 23, BOTH, FALSE}, // 5G, ch 149~161
3313 + { 0}, // end
3314 + }
3315 + },
3316 +
3317 + { // Serbia_and_Montenegro
3318 + "CS",
3319 + CE,
3320 + {
3321 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3322 + { 0}, // end
3323 + }
3324 + },
3325 +
3326 + { // Singapore
3327 + "SG",
3328 + CE,
3329 + {
3330 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3331 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3332 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3333 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
3334 + { 0}, // end
3335 + }
3336 + },
3337 +
3338 + { // Slovakia
3339 + "SK",
3340 + CE,
3341 + {
3342 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3343 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3344 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3345 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3346 + { 0}, // end
3347 + }
3348 + },
3349 +
3350 + { // Slovenia
3351 + "SI",
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 + { 0}, // end
3358 + }
3359 + },
3360 +
3361 + { // South Africa
3362 + "ZA",
3363 + CE,
3364 + {
3365 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3366 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3367 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3368 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3369 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3370 + { 0}, // end
3371 + }
3372 + },
3373 +
3374 + { // South Korea
3375 + "KR",
3376 + CE,
3377 + {
3378 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3379 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 36~48
3380 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3381 + { 100, 8, 20, BOTH, FALSE}, // 5G, ch 100~128
3382 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
3383 + { 0}, // end
3384 + }
3385 + },
3386 +
3387 + { // Spain
3388 + "ES",
3389 + CE,
3390 + {
3391 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3392 + { 36, 4, 17, IDOR, FALSE}, // 5G, ch 36~48
3393 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3394 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3395 + { 0}, // end
3396 + }
3397 + },
3398 +
3399 + { // Sweden
3400 + "SE",
3401 + CE,
3402 + {
3403 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3404 + { 36, 4, 23, 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 + { // Switzerland
3412 + "CH",
3413 + CE,
3414 + {
3415 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3416 + { 36, 4, 23, IDOR, TRUE}, // 5G, ch 36~48
3417 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3418 + { 0}, // end
3419 + }
3420 + },
3421 +
3422 + { // Taiwan
3423 + "TW",
3424 + CE,
3425 + {
3426 + { 1, 11, 30, BOTH, FALSE}, // 2.4 G, ch 1~11
3427 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3428 + { 0}, // end
3429 + }
3430 + },
3431 +
3432 + { // Turkey
3433 + "TR",
3434 + CE,
3435 + {
3436 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3437 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3438 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3439 + { 0}, // end
3440 + }
3441 + },
3442 +
3443 + { // UK
3444 + "GB",
3445 + CE,
3446 + {
3447 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3448 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3449 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3450 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3451 + { 0}, // end
3452 + }
3453 + },
3454 +
3455 + { // Ukraine
3456 + "UA",
3457 + CE,
3458 + {
3459 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3460 + { 0}, // end
3461 + }
3462 + },
3463 +
3464 + { // United_Arab_Emirates
3465 + "AE",
3466 + CE,
3467 + {
3468 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3469 + { 0}, // end
3470 + }
3471 + },
3472 +
3473 + { // United_States
3474 + "US",
3475 + CE,
3476 + {
3477 + { 1, 11, 30, BOTH, FALSE}, // 2.4 G, ch 1~11
3478 + { 36, 4, 17, IDOR, FALSE}, // 5G, ch 52~64
3479 + { 52, 4, 24, BOTH, TRUE}, // 5G, ch 52~64
3480 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3481 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
3482 + { 0}, // end
3483 + }
3484 + },
3485 +
3486 + { // Venezuela
3487 + "VE",
3488 + CE,
3489 + {
3490 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3491 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3492 + { 0}, // end
3493 + }
3494 + },
3495 +
3496 + { // Default
3497 + "",
3498 + CE,
3499 + {
3500 + { 1, 11, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3501 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3502 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3503 + { 100, 11, 20, BOTH, FALSE}, // 5G, ch 100~140
3504 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
3505 + { 0}, // end
3506 + }
3507 + },
3508 +};
3509 +
3510 +static inline PCH_REGION GetChRegion(
3511 + IN PUCHAR CntryCode)
3512 +{
3513 + INT loop = 0;
3514 + PCH_REGION pChRegion = NULL;
3515 +
3516 + while (strcmp(ChRegion[loop].CountReg, "") != 0)
3517 + {
3518 + if (strncmp(ChRegion[loop].CountReg, CntryCode, 2) == 0)
3519 + {
3520 + pChRegion = &ChRegion[loop];
3521 + break;
3522 + }
3523 + loop++;
3524 + }
3525 +
3526 + if (pChRegion == NULL)
3527 + pChRegion = &ChRegion[loop];
3528 + return pChRegion;
3529 +}
3530 +
3531 +static inline VOID ChBandCheck(
3532 + IN UCHAR PhyMode,
3533 + OUT PUCHAR pChType)
3534 +{
3535 + switch(PhyMode)
3536 + {
3537 + case PHY_11A:
3538 +#ifdef DOT11_N_SUPPORT
3539 + case PHY_11AN_MIXED:
3540 +#endif // DOT11_N_SUPPORT //
3541 + *pChType = BAND_5G;
3542 + break;
3543 + case PHY_11ABG_MIXED:
3544 +#ifdef DOT11_N_SUPPORT
3545 + case PHY_11AGN_MIXED:
3546 + case PHY_11ABGN_MIXED:
3547 +#endif // DOT11_N_SUPPORT //
3548 + *pChType = BAND_BOTH;
3549 + break;
3550 +
3551 + default:
3552 + *pChType = BAND_24G;
3553 + break;
3554 + }
3555 +}
3556 +
3557 +static inline UCHAR FillChList(
3558 + IN PRTMP_ADAPTER pAd,
3559 + IN PCH_DESP pChDesp,
3560 + IN UCHAR Offset,
3561 + IN UCHAR increment)
3562 +{
3563 + INT i, j, l;
3564 + UCHAR channel;
3565 +
3566 + j = Offset;
3567 + for (i = 0; i < pChDesp->NumOfCh; i++)
3568 + {
3569 + channel = pChDesp->FirstChannel + i * increment;
3570 + for (l=0; l<MAX_NUM_OF_CHANNELS; l++)
3571 + {
3572 + if (channel == pAd->TxPower[l].Channel)
3573 + {
3574 + pAd->ChannelList[j].Power = pAd->TxPower[l].Power;
3575 + pAd->ChannelList[j].Power2 = pAd->TxPower[l].Power2;
3576 + break;
3577 + }
3578 + }
3579 + if (l == MAX_NUM_OF_CHANNELS)
3580 + continue;
3581 +
3582 + pAd->ChannelList[j].Channel = pChDesp->FirstChannel + i * increment;
3583 + pAd->ChannelList[j].MaxTxPwr = pChDesp->MaxTxPwr;
3584 + pAd->ChannelList[j].DfsReq = pChDesp->DfsReq;
3585 + j++;
3586 + }
3587 + pAd->ChannelListNum = j;
3588 +
3589 + return j;
3590 +}
3591 +
3592 +static inline VOID CreateChList(
3593 + IN PRTMP_ADAPTER pAd,
3594 + IN PCH_REGION pChRegion,
3595 + IN UCHAR Geography)
3596 +{
3597 + INT i;
3598 + UCHAR offset = 0;
3599 + PCH_DESP pChDesp;
3600 + UCHAR ChType;
3601 + UCHAR increment;
3602 +
3603 + if (pChRegion == NULL)
3604 + return;
3605 +
3606 + ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
3607 +
3608 + for (i=0; i<10; i++)
3609 + {
3610 + pChDesp = &pChRegion->ChDesp[i];
3611 + if (pChDesp->FirstChannel == 0)
3612 + break;
3613 +
3614 + if (ChType == BAND_5G)
3615 + {
3616 + if (pChDesp->FirstChannel <= 14)
3617 + continue;
3618 + }
3619 + else if (ChType == BAND_24G)
3620 + {
3621 + if (pChDesp->FirstChannel > 14)
3622 + continue;
3623 + }
3624 +
3625 + if ((pChDesp->Geography == BOTH)
3626 + || (pChDesp->Geography == Geography))
3627 + {
3628 + if (pChDesp->FirstChannel > 14)
3629 + increment = 4;
3630 + else
3631 + increment = 1;
3632 + offset = FillChList(pAd, pChDesp, offset, increment);
3633 + }
3634 + }
3635 +}
3636 +
3637 +static inline VOID BuildChannelListEx(
3638 + IN PRTMP_ADAPTER pAd)
3639 +{
3640 + PCH_REGION pChReg;
3641 +
3642 + pChReg = GetChRegion(pAd->CommonCfg.CountryCode);
3643 + CreateChList(pAd, pChReg, pAd->CommonCfg.Geography);
3644 +}
3645 +
3646 +static inline VOID BuildBeaconChList(
3647 + IN PRTMP_ADAPTER pAd,
3648 + OUT PUCHAR pBuf,
3649 + OUT PULONG pBufLen)
3650 +{
3651 + INT i;
3652 + ULONG TmpLen;
3653 + PCH_REGION pChRegion;
3654 + PCH_DESP pChDesp;
3655 + UCHAR ChType;
3656 +
3657 + pChRegion = GetChRegion(pAd->CommonCfg.CountryCode);
3658 +
3659 + if (pChRegion == NULL)
3660 + return;
3661 +
3662 + ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
3663 + *pBufLen = 0;
3664 +
3665 + for (i=0; i<10; i++)
3666 + {
3667 + pChDesp = &pChRegion->ChDesp[i];
3668 + if (pChDesp->FirstChannel == 0)
3669 + break;
3670 +
3671 + if (ChType == BAND_5G)
3672 + {
3673 + if (pChDesp->FirstChannel <= 14)
3674 + continue;
3675 + }
3676 + else if (ChType == BAND_24G)
3677 + {
3678 + if (pChDesp->FirstChannel > 14)
3679 + continue;
3680 + }
3681 +
3682 + if ((pChDesp->Geography == BOTH)
3683 + || (pChDesp->Geography == pAd->CommonCfg.Geography))
3684 + {
3685 + MakeOutgoingFrame(pBuf + *pBufLen, &TmpLen,
3686 + 1, &pChDesp->FirstChannel,
3687 + 1, &pChDesp->NumOfCh,
3688 + 1, &pChDesp->MaxTxPwr,
3689 + END_OF_ARGS);
3690 + *pBufLen += TmpLen;
3691 + }
3692 + }
3693 +}
3694 +
3695 +
3696 +#ifdef DOT11_N_SUPPORT
3697 +static inline BOOLEAN IsValidChannel(
3698 + IN PRTMP_ADAPTER pAd,
3699 + IN UCHAR channel)
3700 +
3701 +{
3702 + INT i;
3703 +
3704 + for (i = 0; i < pAd->ChannelListNum; i++)
3705 + {
3706 + if (pAd->ChannelList[i].Channel == channel)
3707 + break;
3708 + }
3709 +
3710 + if (i == pAd->ChannelListNum)
3711 + return FALSE;
3712 + else
3713 + return TRUE;
3714 +}
3715 +
3716 +
3717 +static inline UCHAR GetExtCh(
3718 + IN UCHAR Channel,
3719 + IN UCHAR Direction)
3720 +{
3721 + CHAR ExtCh;
3722 +
3723 + if (Direction == EXTCHA_ABOVE)
3724 + ExtCh = Channel + 4;
3725 + else
3726 + ExtCh = (Channel - 4) > 0 ? (Channel - 4) : 0;
3727 +
3728 + return ExtCh;
3729 +}
3730 +
3731 +
3732 +static inline VOID N_ChannelCheck(
3733 + IN PRTMP_ADAPTER pAd)
3734 +{
3735 + //UCHAR ChannelNum = pAd->ChannelListNum;
3736 + UCHAR Channel = pAd->CommonCfg.Channel;
3737 +
3738 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
3739 + {
3740 + if (Channel > 14)
3741 + {
3742 + if ((Channel == 36) || (Channel == 44) || (Channel == 52) || (Channel == 60) || (Channel == 100) || (Channel == 108) ||
3743 + (Channel == 116) || (Channel == 124) || (Channel == 132) || (Channel == 149) || (Channel == 157))
3744 + {
3745 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
3746 + }
3747 + else if ((Channel == 40) || (Channel == 48) || (Channel == 56) || (Channel == 64) || (Channel == 104) || (Channel == 112) ||
3748 + (Channel == 120) || (Channel == 128) || (Channel == 136) || (Channel == 153) || (Channel == 161))
3749 + {
3750 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
3751 + }
3752 + else
3753 + {
3754 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3755 + }
3756 + }
3757 + else
3758 + {
3759 + do
3760 + {
3761 + UCHAR ExtCh;
3762 + UCHAR Dir = pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
3763 + ExtCh = GetExtCh(Channel, Dir);
3764 + if (IsValidChannel(pAd, ExtCh))
3765 + break;
3766 +
3767 + Dir = (Dir == EXTCHA_ABOVE) ? EXTCHA_BELOW : EXTCHA_ABOVE;
3768 + ExtCh = GetExtCh(Channel, Dir);
3769 + if (IsValidChannel(pAd, ExtCh))
3770 + {
3771 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = Dir;
3772 + break;
3773 + }
3774 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3775 + } while(FALSE);
3776 +
3777 + if (Channel == 14)
3778 + {
3779 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3780 + //pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_NONE; // We didn't set the ExtCh as NONE due to it'll set in RTMPSetHT()
3781 + }
3782 +#if 0
3783 + switch (pAd->CommonCfg.CountryRegion & 0x7f)
3784 + {
3785 + case REGION_0_BG_BAND: // 1 -11
3786 + case REGION_1_BG_BAND: // 1 - 13
3787 + case REGION_5_BG_BAND: // 1 - 14
3788 + if (Channel <= 4)
3789 + {
3790 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
3791 + }
3792 + else if (Channel >= 8)
3793 + {
3794 + if ((ChannelNum - Channel) < 4)
3795 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
3796 + }
3797 + break;
3798 +
3799 + case REGION_2_BG_BAND: // 10 - 11
3800 + case REGION_3_BG_BAND: // 10 - 13
3801 + case REGION_4_BG_BAND: // 14
3802 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3803 + break;
3804 +
3805 + case REGION_6_BG_BAND: // 3 - 9
3806 + if (Channel <= 5)
3807 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
3808 + else if (Channel == 6)
3809 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3810 + else if (Channel >= 7)
3811 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
3812 + break;
3813 +
3814 + case REGION_7_BG_BAND: // 5 - 13
3815 + if (Channel <= 8)
3816 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
3817 + else if (Channel >= 10)
3818 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
3819 + break;
3820 +
3821 + default: // Error. should never happen
3822 + break;
3823 + }
3824 +#endif
3825 + }
3826 + }
3827 +
3828 +
3829 +}
3830 +
3831 +
3832 +static inline VOID N_SetCenCh(
3833 + IN PRTMP_ADAPTER pAd)
3834 +{
3835 + if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
3836 + {
3837 + if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
3838 + {
3839 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
3840 + }
3841 + else
3842 + {
3843 + if (pAd->CommonCfg.Channel == 14)
3844 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 1;
3845 + else
3846 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
3847 + }
3848 + }
3849 + else
3850 + {
3851 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
3852 + }
3853 +}
3854 +#endif // DOT11_N_SUPPORT //
3855 +
3856 +
3857 +static inline UINT8 GetCuntryMaxTxPwr(
3858 + IN PRTMP_ADAPTER pAd,
3859 + IN UINT8 channel)
3860 +{
3861 + int i;
3862 + for (i = 0; i < pAd->ChannelListNum; i++)
3863 + {
3864 + if (pAd->ChannelList[i].Channel == channel)
3865 + break;
3866 + }
3867 +
3868 + if (i == pAd->ChannelListNum)
3869 + return 0xff;
3870 + else
3871 + return pAd->ChannelList[i].MaxTxPwr;
3872 +}
3873 +#endif // __CHLIST_H__
3874 +
3875 --- /dev/null
3876 +++ b/drivers/staging/rt2870/common/2870_rtmp_init.c
3877 @@ -0,0 +1,1778 @@
3878 +/*
3879 + *************************************************************************
3880 + * Ralink Tech Inc.
3881 + * 5F., No.36, Taiyuan St., Jhubei City,
3882 + * Hsinchu County 302,
3883 + * Taiwan, R.O.C.
3884 + *
3885 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
3886 + *
3887 + * This program is free software; you can redistribute it and/or modify *
3888 + * it under the terms of the GNU General Public License as published by *
3889 + * the Free Software Foundation; either version 2 of the License, or *
3890 + * (at your option) any later version. *
3891 + * *
3892 + * This program is distributed in the hope that it will be useful, *
3893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
3894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
3895 + * GNU General Public License for more details. *
3896 + * *
3897 + * You should have received a copy of the GNU General Public License *
3898 + * along with this program; if not, write to the *
3899 + * Free Software Foundation, Inc., *
3900 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
3901 + * *
3902 + *************************************************************************
3903 +
3904 + Module Name:
3905 + 2870_rtmp_init.c
3906 +
3907 + Abstract:
3908 + Miniport generic portion header file
3909 +
3910 + Revision History:
3911 + Who When What
3912 + -------- ---------- ----------------------------------------------
3913 + Paul Lin 2002-08-01 created
3914 + John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme
3915 + Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT.
3916 + Sample Lin 2007-05-31 Merge RT2860 and RT2870 drivers.
3917 +*/
3918 +
3919 +#include "../rt_config.h"
3920 +
3921 +
3922 +static void rx_done_tasklet(unsigned long data);
3923 +static void rt2870_hcca_dma_done_tasklet(unsigned long data);
3924 +static void rt2870_ac3_dma_done_tasklet(unsigned long data);
3925 +static void rt2870_ac2_dma_done_tasklet(unsigned long data);
3926 +static void rt2870_ac1_dma_done_tasklet(unsigned long data);
3927 +static void rt2870_ac0_dma_done_tasklet(unsigned long data);
3928 +static void rt2870_mgmt_dma_done_tasklet(unsigned long data);
3929 +static void rt2870_null_frame_complete_tasklet(unsigned long data);
3930 +static void rt2870_rts_frame_complete_tasklet(unsigned long data);
3931 +static void rt2870_pspoll_frame_complete_tasklet(unsigned long data);
3932 +static void rt2870_dataout_complete_tasklet(unsigned long data);
3933 +
3934 +
3935 +/*
3936 +========================================================================
3937 +Routine Description:
3938 + Initialize receive data structures.
3939 +
3940 +Arguments:
3941 + pAd Pointer to our adapter
3942 +
3943 +Return Value:
3944 + NDIS_STATUS_SUCCESS
3945 + NDIS_STATUS_RESOURCES
3946 +
3947 +Note:
3948 + Initialize all receive releated private buffer, include those define
3949 + in RTMP_ADAPTER structure and all private data structures. The mahor
3950 + work is to allocate buffer for each packet and chain buffer to
3951 + NDIS packet descriptor.
3952 +========================================================================
3953 +*/
3954 +NDIS_STATUS NICInitRecv(
3955 + IN PRTMP_ADAPTER pAd)
3956 +{
3957 + UCHAR i;
3958 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
3959 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
3960 +
3961 +
3962 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitRecv\n"));
3963 + pObj = pObj;
3964 +
3965 + //InterlockedExchange(&pAd->PendingRx, 0);
3966 + pAd->PendingRx = 0;
3967 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
3968 + pAd->NextRxBulkInIndex = 0 ; //RX_RING_SIZE -1; // Rx Bulk pointer
3969 + pAd->NextRxBulkInPosition = 0;
3970 +
3971 + for (i = 0; i < (RX_RING_SIZE); i++)
3972 + {
3973 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
3974 +
3975 + //Allocate URB
3976 + pRxContext->pUrb = RTUSB_ALLOC_URB(0);
3977 + if (pRxContext->pUrb == NULL)
3978 + {
3979 + Status = NDIS_STATUS_RESOURCES;
3980 + goto out1;
3981 + }
3982 +
3983 + // Allocate transfer buffer
3984 + pRxContext->TransferBuffer = RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE, &pRxContext->data_dma);
3985 + if (pRxContext->TransferBuffer == NULL)
3986 + {
3987 + Status = NDIS_STATUS_RESOURCES;
3988 + goto out1;
3989 + }
3990 +
3991 + NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
3992 +
3993 + pRxContext->pAd = pAd;
3994 + pRxContext->pIrp = NULL;
3995 + pRxContext->InUse = FALSE;
3996 + pRxContext->IRPPending = FALSE;
3997 + pRxContext->Readable = FALSE;
3998 + //pRxContext->ReorderInUse = FALSE;
3999 + pRxContext->bRxHandling = FALSE;
4000 + pRxContext->BulkInOffset = 0;
4001 + }
4002 +
4003 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitRecv\n"));
4004 + return Status;
4005 +
4006 +out1:
4007 + for (i = 0; i < (RX_RING_SIZE); i++)
4008 + {
4009 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
4010 +
4011 + if (NULL != pRxContext->TransferBuffer)
4012 + {
4013 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE,
4014 + pRxContext->TransferBuffer, pRxContext->data_dma);
4015 + pRxContext->TransferBuffer = NULL;
4016 + }
4017 +
4018 + if (NULL != pRxContext->pUrb)
4019 + {
4020 + RTUSB_UNLINK_URB(pRxContext->pUrb);
4021 + RTUSB_FREE_URB(pRxContext->pUrb);
4022 + pRxContext->pUrb = NULL;
4023 + }
4024 + }
4025 +
4026 + return Status;
4027 +}
4028 +
4029 +
4030 +/*
4031 +========================================================================
4032 +Routine Description:
4033 + Initialize transmit data structures.
4034 +
4035 +Arguments:
4036 + pAd Pointer to our adapter
4037 +
4038 +Return Value:
4039 + NDIS_STATUS_SUCCESS
4040 + NDIS_STATUS_RESOURCES
4041 +
4042 +Note:
4043 +========================================================================
4044 +*/
4045 +NDIS_STATUS NICInitTransmit(
4046 + IN PRTMP_ADAPTER pAd)
4047 +{
4048 +#define LM_USB_ALLOC(pObj, Context, TB_Type, BufferSize, Status, msg1, err1, msg2, err2) \
4049 + Context->pUrb = RTUSB_ALLOC_URB(0); \
4050 + if (Context->pUrb == NULL) { \
4051 + DBGPRINT(RT_DEBUG_ERROR, msg1); \
4052 + Status = NDIS_STATUS_RESOURCES; \
4053 + goto err1; } \
4054 + \
4055 + Context->TransferBuffer = \
4056 + (TB_Type)RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, BufferSize, &Context->data_dma); \
4057 + if (Context->TransferBuffer == NULL) { \
4058 + DBGPRINT(RT_DEBUG_ERROR, msg2); \
4059 + Status = NDIS_STATUS_RESOURCES; \
4060 + goto err2; }
4061 +
4062 +#define LM_URB_FREE(pObj, Context, BufferSize) \
4063 + if (NULL != Context->pUrb) { \
4064 + RTUSB_UNLINK_URB(Context->pUrb); \
4065 + RTUSB_FREE_URB(Context->pUrb); \
4066 + Context->pUrb = NULL; } \
4067 + if (NULL != Context->TransferBuffer) { \
4068 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
4069 + Context->TransferBuffer, \
4070 + Context->data_dma); \
4071 + Context->TransferBuffer = NULL; }
4072 +
4073 + UCHAR i, acidx;
4074 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
4075 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
4076 + PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext);
4077 + PTX_CONTEXT pRTSContext = &(pAd->RTSContext);
4078 + PTX_CONTEXT pMLMEContext = NULL;
4079 +// PHT_TX_CONTEXT pHTTXContext = NULL;
4080 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4081 + PVOID RingBaseVa;
4082 +// RTMP_TX_RING *pTxRing;
4083 + RTMP_MGMT_RING *pMgmtRing;
4084 +
4085 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitTransmit\n"));
4086 + pObj = pObj;
4087 +
4088 + // Init 4 set of Tx parameters
4089 + for(acidx = 0; acidx < NUM_OF_TX_RING; acidx++)
4090 + {
4091 + // Initialize all Transmit releated queues
4092 + InitializeQueueHeader(&pAd->TxSwQueue[acidx]);
4093 +
4094 + // Next Local tx ring pointer waiting for buck out
4095 + pAd->NextBulkOutIndex[acidx] = acidx;
4096 + pAd->BulkOutPending[acidx] = FALSE; // Buck Out control flag
4097 + //pAd->DataBulkDoneIdx[acidx] = 0;
4098 + }
4099 +
4100 + //pAd->NextMLMEIndex = 0;
4101 + //pAd->PushMgmtIndex = 0;
4102 + //pAd->PopMgmtIndex = 0;
4103 + //InterlockedExchange(&pAd->MgmtQueueSize, 0);
4104 + //InterlockedExchange(&pAd->TxCount, 0);
4105 +
4106 + //pAd->PrioRingFirstIndex = 0;
4107 + //pAd->PrioRingTxCnt = 0;
4108 +
4109 + do
4110 + {
4111 + //
4112 + // TX_RING_SIZE, 4 ACs
4113 + //
4114 + for(acidx=0; acidx<4; acidx++)
4115 + {
4116 + PHT_TX_CONTEXT pHTTXContext = &(pAd->TxContext[acidx]);
4117 +
4118 + NdisZeroMemory(pHTTXContext, sizeof(HT_TX_CONTEXT));
4119 + //Allocate URB
4120 + LM_USB_ALLOC(pObj, pHTTXContext, PHTTX_BUFFER, sizeof(HTTX_BUFFER), Status,
4121 + ("<-- ERROR in Alloc TX TxContext[%d] urb!! \n", acidx),
4122 + done,
4123 + ("<-- ERROR in Alloc TX TxContext[%d] HTTX_BUFFER !! \n", acidx),
4124 + out1);
4125 +
4126 + NdisZeroMemory(pHTTXContext->TransferBuffer->Aggregation, 4);
4127 + pHTTXContext->pAd = pAd;
4128 + pHTTXContext->pIrp = NULL;
4129 + pHTTXContext->IRPPending = FALSE;
4130 + pHTTXContext->NextBulkOutPosition = 0;
4131 + pHTTXContext->ENextBulkOutPosition = 0;
4132 + pHTTXContext->CurWritePosition = 0;
4133 + pHTTXContext->CurWriteRealPos = 0;
4134 + pHTTXContext->BulkOutSize = 0;
4135 + pHTTXContext->BulkOutPipeId = acidx;
4136 + pHTTXContext->bRingEmpty = TRUE;
4137 + pHTTXContext->bCopySavePad = FALSE;
4138 +
4139 + pAd->BulkOutPending[acidx] = FALSE;
4140 + }
4141 +
4142 +
4143 + //
4144 + // MGMT_RING_SIZE
4145 + //
4146 +#if 0
4147 + for(i=0; i<MGMT_RING_SIZE; i++) // 8
4148 + {
4149 + PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]);
4150 +
4151 +
4152 + NdisZeroMemory(pMLMEContext, sizeof(TX_CONTEXT));
4153 +
4154 + //Allocate URB
4155 + LM_USB_ALLOC(pObj, pMLMEContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4156 + ("<-- ERROR in Alloc TX MLMEContext[%d] urb!! \n", i),
4157 + out2,
4158 + ("<-- ERROR in Alloc TX MLMEContext[%d] TX_BUFFER !! \n", i),
4159 + out2);
4160 +
4161 + pMLMEContext->pAd = pAd;
4162 + pMLMEContext->pIrp = NULL;
4163 + pMLMEContext->InUse = FALSE;
4164 + pMLMEContext->IRPPending = FALSE;
4165 + }
4166 +#else
4167 + // Allocate MGMT ring descriptor's memory
4168 + pAd->MgmtDescRing.AllocSize = MGMT_RING_SIZE * sizeof(TX_CONTEXT);
4169 + RTMPAllocateMemory(&pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize);
4170 + if (pAd->MgmtDescRing.AllocVa == NULL)
4171 + {
4172 + DBGPRINT_ERR(("Failed to allocate a big buffer for MgmtDescRing!\n"));
4173 + Status = NDIS_STATUS_RESOURCES;
4174 + goto out1;
4175 + }
4176 + NdisZeroMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize);
4177 + RingBaseVa = pAd->MgmtDescRing.AllocVa;
4178 +
4179 + // Initialize MGMT Ring and associated buffer memory
4180 + pMgmtRing = &pAd->MgmtRing;
4181 + for (i = 0; i < MGMT_RING_SIZE; i++)
4182 + {
4183 + // link the pre-allocated Mgmt buffer to MgmtRing.Cell
4184 + pMgmtRing->Cell[i].AllocSize = sizeof(TX_CONTEXT);
4185 + pMgmtRing->Cell[i].AllocVa = RingBaseVa;
4186 + pMgmtRing->Cell[i].pNdisPacket = NULL;
4187 + pMgmtRing->Cell[i].pNextNdisPacket = NULL;
4188 +
4189 + //Allocate URB for MLMEContext
4190 + pMLMEContext = (PTX_CONTEXT) pAd->MgmtRing.Cell[i].AllocVa;
4191 + pMLMEContext->pUrb = RTUSB_ALLOC_URB(0);
4192 + if (pMLMEContext->pUrb == NULL)
4193 + {
4194 + DBGPRINT(RT_DEBUG_ERROR, ("<-- ERROR in Alloc TX MLMEContext[%d] urb!! \n", i));
4195 + Status = NDIS_STATUS_RESOURCES;
4196 + goto out2;
4197 + }
4198 + pMLMEContext->pAd = pAd;
4199 + pMLMEContext->pIrp = NULL;
4200 + pMLMEContext->TransferBuffer = NULL;
4201 + pMLMEContext->InUse = FALSE;
4202 + pMLMEContext->IRPPending = FALSE;
4203 + pMLMEContext->bWaitingBulkOut = FALSE;
4204 + pMLMEContext->BulkOutSize = 0;
4205 + pMLMEContext->SelfIdx = i;
4206 +
4207 + // Offset to next ring descriptor address
4208 + RingBaseVa = (PUCHAR) RingBaseVa + sizeof(TX_CONTEXT);
4209 + }
4210 + DBGPRINT(RT_DEBUG_TRACE, ("MGMT Ring: total %d entry allocated\n", i));
4211 +
4212 + //pAd->MgmtRing.TxSwFreeIdx = (MGMT_RING_SIZE - 1);
4213 + pAd->MgmtRing.TxSwFreeIdx = MGMT_RING_SIZE;
4214 + pAd->MgmtRing.TxCpuIdx = 0;
4215 + pAd->MgmtRing.TxDmaIdx = 0;
4216 +#endif
4217 +
4218 + //
4219 + // BEACON_RING_SIZE
4220 + //
4221 + for(i=0; i<BEACON_RING_SIZE; i++) // 2
4222 + {
4223 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4224 +
4225 +
4226 + NdisZeroMemory(pBeaconContext, sizeof(TX_CONTEXT));
4227 +
4228 + //Allocate URB
4229 + LM_USB_ALLOC(pObj, pBeaconContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4230 + ("<-- ERROR in Alloc TX BeaconContext[%d] urb!! \n", i),
4231 + out2,
4232 + ("<-- ERROR in Alloc TX BeaconContext[%d] TX_BUFFER !! \n", i),
4233 + out3);
4234 +
4235 + pBeaconContext->pAd = pAd;
4236 + pBeaconContext->pIrp = NULL;
4237 + pBeaconContext->InUse = FALSE;
4238 + pBeaconContext->IRPPending = FALSE;
4239 + }
4240 +
4241 + //
4242 + // NullContext
4243 + //
4244 + NdisZeroMemory(pNullContext, sizeof(TX_CONTEXT));
4245 +
4246 + //Allocate URB
4247 + LM_USB_ALLOC(pObj, pNullContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4248 + ("<-- ERROR in Alloc TX NullContext urb!! \n"),
4249 + out3,
4250 + ("<-- ERROR in Alloc TX NullContext TX_BUFFER !! \n"),
4251 + out4);
4252 +
4253 + pNullContext->pAd = pAd;
4254 + pNullContext->pIrp = NULL;
4255 + pNullContext->InUse = FALSE;
4256 + pNullContext->IRPPending = FALSE;
4257 +
4258 + //
4259 + // RTSContext
4260 + //
4261 + NdisZeroMemory(pRTSContext, sizeof(TX_CONTEXT));
4262 +
4263 + //Allocate URB
4264 + LM_USB_ALLOC(pObj, pRTSContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4265 + ("<-- ERROR in Alloc TX RTSContext urb!! \n"),
4266 + out4,
4267 + ("<-- ERROR in Alloc TX RTSContext TX_BUFFER !! \n"),
4268 + out5);
4269 +
4270 + pRTSContext->pAd = pAd;
4271 + pRTSContext->pIrp = NULL;
4272 + pRTSContext->InUse = FALSE;
4273 + pRTSContext->IRPPending = FALSE;
4274 +
4275 + //
4276 + // PsPollContext
4277 + //
4278 + //NdisZeroMemory(pPsPollContext, sizeof(TX_CONTEXT));
4279 + //Allocate URB
4280 + LM_USB_ALLOC(pObj, pPsPollContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4281 + ("<-- ERROR in Alloc TX PsPollContext urb!! \n"),
4282 + out5,
4283 + ("<-- ERROR in Alloc TX PsPollContext TX_BUFFER !! \n"),
4284 + out6);
4285 +
4286 + pPsPollContext->pAd = pAd;
4287 + pPsPollContext->pIrp = NULL;
4288 + pPsPollContext->InUse = FALSE;
4289 + pPsPollContext->IRPPending = FALSE;
4290 + pPsPollContext->bAggregatible = FALSE;
4291 + pPsPollContext->LastOne = TRUE;
4292 +
4293 + } while (FALSE);
4294 +
4295 +
4296 +done:
4297 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitTransmit\n"));
4298 +
4299 + return Status;
4300 +
4301 + /* --------------------------- ERROR HANDLE --------------------------- */
4302 +out6:
4303 + LM_URB_FREE(pObj, pPsPollContext, sizeof(TX_BUFFER));
4304 +
4305 +out5:
4306 + LM_URB_FREE(pObj, pRTSContext, sizeof(TX_BUFFER));
4307 +
4308 +out4:
4309 + LM_URB_FREE(pObj, pNullContext, sizeof(TX_BUFFER));
4310 +
4311 +out3:
4312 + for(i=0; i<BEACON_RING_SIZE; i++)
4313 + {
4314 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4315 + if (pBeaconContext)
4316 + LM_URB_FREE(pObj, pBeaconContext, sizeof(TX_BUFFER));
4317 + }
4318 +
4319 +out2:
4320 + if (pAd->MgmtDescRing.AllocVa)
4321 + {
4322 + pMgmtRing = &pAd->MgmtRing;
4323 + for(i=0; i<MGMT_RING_SIZE; i++)
4324 + {
4325 + pMLMEContext = (PTX_CONTEXT) pAd->MgmtRing.Cell[i].AllocVa;
4326 + if (pMLMEContext)
4327 + LM_URB_FREE(pObj, pMLMEContext, sizeof(TX_BUFFER));
4328 + }
4329 + NdisFreeMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize, 0);
4330 + pAd->MgmtDescRing.AllocVa = NULL;
4331 + }
4332 +
4333 +out1:
4334 + for (acidx = 0; acidx < 4; acidx++)
4335 + {
4336 + PHT_TX_CONTEXT pTxContext = &(pAd->TxContext[acidx]);
4337 + if (pTxContext)
4338 + LM_URB_FREE(pObj, pTxContext, sizeof(HTTX_BUFFER));
4339 + }
4340 +
4341 + // Here we didn't have any pre-allocated memory need to free.
4342 +
4343 + return Status;
4344 +}
4345 +
4346 +
4347 +/*
4348 +========================================================================
4349 +Routine Description:
4350 + Allocate DMA memory blocks for send, receive.
4351 +
4352 +Arguments:
4353 + pAd Pointer to our adapter
4354 +
4355 +Return Value:
4356 + NDIS_STATUS_SUCCESS
4357 + NDIS_STATUS_FAILURE
4358 + NDIS_STATUS_RESOURCES
4359 +
4360 +Note:
4361 +========================================================================
4362 +*/
4363 +NDIS_STATUS RTMPAllocTxRxRingMemory(
4364 + IN PRTMP_ADAPTER pAd)
4365 +{
4366 +// COUNTER_802_11 pCounter = &pAd->WlanCounters;
4367 + NDIS_STATUS Status;
4368 + INT num;
4369 +
4370 +
4371 + DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n"));
4372 +
4373 +
4374 + do
4375 + {
4376 + // Init the CmdQ and CmdQLock
4377 + NdisAllocateSpinLock(&pAd->CmdQLock);
4378 + NdisAcquireSpinLock(&pAd->CmdQLock);
4379 + RTUSBInitializeCmdQ(&pAd->CmdQ);
4380 + NdisReleaseSpinLock(&pAd->CmdQLock);
4381 +
4382 +
4383 + NdisAllocateSpinLock(&pAd->MLMEBulkOutLock);
4384 + //NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock);
4385 + NdisAllocateSpinLock(&pAd->BulkOutLock[0]);
4386 + NdisAllocateSpinLock(&pAd->BulkOutLock[1]);
4387 + NdisAllocateSpinLock(&pAd->BulkOutLock[2]);
4388 + NdisAllocateSpinLock(&pAd->BulkOutLock[3]);
4389 + NdisAllocateSpinLock(&pAd->BulkOutLock[4]);
4390 + NdisAllocateSpinLock(&pAd->BulkOutLock[5]);
4391 + NdisAllocateSpinLock(&pAd->BulkInLock);
4392 +
4393 + for (num = 0; num < NUM_OF_TX_RING; num++)
4394 + {
4395 + NdisAllocateSpinLock(&pAd->TxContextQueueLock[num]);
4396 + }
4397 +
4398 +#ifdef RALINK_ATE
4399 + NdisAllocateSpinLock(&pAd->GenericLock);
4400 +#endif // RALINK_ATE //
4401 +
4402 +// NdisAllocateSpinLock(&pAd->MemLock); // Not used in RT28XX
4403 +
4404 +// NdisAllocateSpinLock(&pAd->MacTabLock); // init it in UserCfgInit()
4405 +// NdisAllocateSpinLock(&pAd->BATabLock); // init it in BATableInit()
4406 +
4407 +// for(num=0; num<MAX_LEN_OF_BA_REC_TABLE; num++)
4408 +// {
4409 +// NdisAllocateSpinLock(&pAd->BATable.BARecEntry[num].RxReRingLock);
4410 +// }
4411 +
4412 + //
4413 + // Init Mac Table
4414 + //
4415 +// MacTableInitialize(pAd);
4416 +
4417 + //
4418 + // Init send data structures and related parameters
4419 + //
4420 + Status = NICInitTransmit(pAd);
4421 + if (Status != NDIS_STATUS_SUCCESS)
4422 + break;
4423 +
4424 + //
4425 + // Init receive data structures and related parameters
4426 + //
4427 + Status = NICInitRecv(pAd);
4428 + if (Status != NDIS_STATUS_SUCCESS)
4429 + break;
4430 +
4431 + pAd->PendingIoCount = 1;
4432 +
4433 + } while (FALSE);
4434 +
4435 + NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME));
4436 + pAd->FragFrame.pFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
4437 +
4438 + if (pAd->FragFrame.pFragPacket == NULL)
4439 + {
4440 + Status = NDIS_STATUS_RESOURCES;
4441 + }
4442 +
4443 + DBGPRINT_S(Status, ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status));
4444 + return Status;
4445 +}
4446 +
4447 +
4448 +/*
4449 +========================================================================
4450 +Routine Description:
4451 + Calls USB_InterfaceStop and frees memory allocated for the URBs
4452 + calls NdisMDeregisterDevice and frees the memory
4453 + allocated in VNetInitialize for the Adapter Object
4454 +
4455 +Arguments:
4456 + *pAd the raxx interface data pointer
4457 +
4458 +Return Value:
4459 + None
4460 +
4461 +Note:
4462 +========================================================================
4463 +*/
4464 +VOID RTMPFreeTxRxRingMemory(
4465 + IN PRTMP_ADAPTER pAd)
4466 +{
4467 +#define LM_URB_FREE(pObj, Context, BufferSize) \
4468 + if (NULL != Context->pUrb) { \
4469 + RTUSB_UNLINK_URB(Context->pUrb); \
4470 + RTUSB_FREE_URB(Context->pUrb); \
4471 + Context->pUrb = NULL; } \
4472 + if (NULL != Context->TransferBuffer) { \
4473 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
4474 + Context->TransferBuffer, \
4475 + Context->data_dma); \
4476 + Context->TransferBuffer = NULL; }
4477 +
4478 +
4479 + UINT i, acidx;
4480 + PTX_CONTEXT pNullContext = &pAd->NullContext;
4481 + PTX_CONTEXT pPsPollContext = &pAd->PsPollContext;
4482 + PTX_CONTEXT pRTSContext = &pAd->RTSContext;
4483 +// PHT_TX_CONTEXT pHTTXContext;
4484 + //PRTMP_REORDERBUF pReorderBuf;
4485 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4486 +// RTMP_TX_RING *pTxRing;
4487 +
4488 + DBGPRINT(RT_DEBUG_ERROR, ("---> RTMPFreeTxRxRingMemory\n"));
4489 + pObj = pObj;
4490 +
4491 + // Free all resources for the RECEIVE buffer queue.
4492 + for(i=0; i<(RX_RING_SIZE); i++)
4493 + {
4494 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
4495 + if (pRxContext)
4496 + LM_URB_FREE(pObj, pRxContext, MAX_RXBULK_SIZE);
4497 + }
4498 +
4499 + // Free PsPoll frame resource
4500 + LM_URB_FREE(pObj, pPsPollContext, sizeof(TX_BUFFER));
4501 +
4502 + // Free NULL frame resource
4503 + LM_URB_FREE(pObj, pNullContext, sizeof(TX_BUFFER));
4504 +
4505 + // Free RTS frame resource
4506 + LM_URB_FREE(pObj, pRTSContext, sizeof(TX_BUFFER));
4507 +
4508 +
4509 + // Free beacon frame resource
4510 + for(i=0; i<BEACON_RING_SIZE; i++)
4511 + {
4512 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4513 + if (pBeaconContext)
4514 + LM_URB_FREE(pObj, pBeaconContext, sizeof(TX_BUFFER));
4515 + }
4516 +
4517 +
4518 + // Free mgmt frame resource
4519 + for(i = 0; i < MGMT_RING_SIZE; i++)
4520 + {
4521 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[i].AllocVa;
4522 + //LM_URB_FREE(pObj, pMLMEContext, sizeof(TX_BUFFER));
4523 + if (NULL != pAd->MgmtRing.Cell[i].pNdisPacket)
4524 + {
4525 + RTMPFreeNdisPacket(pAd, pAd->MgmtRing.Cell[i].pNdisPacket);
4526 + pAd->MgmtRing.Cell[i].pNdisPacket = NULL;
4527 + pMLMEContext->TransferBuffer = NULL;
4528 + }
4529 +
4530 + if (pMLMEContext)
4531 + {
4532 + if (NULL != pMLMEContext->pUrb)
4533 + {
4534 + RTUSB_UNLINK_URB(pMLMEContext->pUrb);
4535 + RTUSB_FREE_URB(pMLMEContext->pUrb);
4536 + pMLMEContext->pUrb = NULL;
4537 + }
4538 + }
4539 + }
4540 + if (pAd->MgmtDescRing.AllocVa)
4541 + NdisFreeMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize, 0);
4542 +
4543 +
4544 + // Free Tx frame resource
4545 + for (acidx = 0; acidx < 4; acidx++)
4546 + {
4547 + PHT_TX_CONTEXT pHTTXContext = &(pAd->TxContext[acidx]);
4548 + if (pHTTXContext)
4549 + LM_URB_FREE(pObj, pHTTXContext, sizeof(HTTX_BUFFER));
4550 + }
4551 +
4552 + if (pAd->FragFrame.pFragPacket)
4553 + RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, NDIS_STATUS_SUCCESS);
4554 +
4555 + for(i=0; i<6; i++)
4556 + {
4557 + NdisFreeSpinLock(&pAd->BulkOutLock[i]);
4558 + }
4559 +
4560 + NdisFreeSpinLock(&pAd->BulkInLock);
4561 + NdisFreeSpinLock(&pAd->MLMEBulkOutLock);
4562 +
4563 + NdisFreeSpinLock(&pAd->CmdQLock);
4564 +#ifdef RALINK_ATE
4565 + NdisFreeSpinLock(&pAd->GenericLock);
4566 +#endif // RALINK_ATE //
4567 + // Clear all pending bulk-out request flags.
4568 + RTUSB_CLEAR_BULK_FLAG(pAd, 0xffffffff);
4569 +
4570 +// NdisFreeSpinLock(&pAd->MacTabLock);
4571 +
4572 +// for(i=0; i<MAX_LEN_OF_BA_REC_TABLE; i++)
4573 +// {
4574 +// NdisFreeSpinLock(&pAd->BATable.BARecEntry[i].RxReRingLock);
4575 +// }
4576 +
4577 + DBGPRINT(RT_DEBUG_ERROR, ("<--- ReleaseAdapter\n"));
4578 +}
4579 +
4580 +
4581 +/*
4582 +========================================================================
4583 +Routine Description:
4584 + Allocate memory for adapter control block.
4585 +
4586 +Arguments:
4587 + pAd Pointer to our adapter
4588 +
4589 +Return Value:
4590 + NDIS_STATUS_SUCCESS
4591 + NDIS_STATUS_FAILURE
4592 + NDIS_STATUS_RESOURCES
4593 +
4594 +Note:
4595 +========================================================================
4596 +*/
4597 +NDIS_STATUS AdapterBlockAllocateMemory(
4598 + IN PVOID handle,
4599 + OUT PVOID *ppAd)
4600 +{
4601 + PUSB_DEV usb_dev;
4602 + POS_COOKIE pObj = (POS_COOKIE) handle;
4603 +
4604 +
4605 + usb_dev = pObj->pUsb_Dev;
4606 +
4607 + pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
4608 + pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
4609 +
4610 + *ppAd = (PVOID)vmalloc(sizeof(RTMP_ADAPTER));
4611 +
4612 + if (*ppAd)
4613 + {
4614 + NdisZeroMemory(*ppAd, sizeof(RTMP_ADAPTER));
4615 + ((PRTMP_ADAPTER)*ppAd)->OS_Cookie = handle;
4616 + return (NDIS_STATUS_SUCCESS);
4617 + }
4618 + else
4619 + {
4620 + return (NDIS_STATUS_FAILURE);
4621 + }
4622 +}
4623 +
4624 +
4625 +/*
4626 +========================================================================
4627 +Routine Description:
4628 + Create kernel threads & tasklets.
4629 +
4630 +Arguments:
4631 + *net_dev Pointer to wireless net device interface
4632 +
4633 +Return Value:
4634 + NDIS_STATUS_SUCCESS
4635 + NDIS_STATUS_FAILURE
4636 +
4637 +Note:
4638 +========================================================================
4639 +*/
4640 +NDIS_STATUS CreateThreads(
4641 + IN struct net_device *net_dev)
4642 +{
4643 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv;
4644 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4645 + pid_t pid_number = -1;
4646 +
4647 + //init_MUTEX(&(pAd->usbdev_semaphore));
4648 +
4649 + init_MUTEX_LOCKED(&(pAd->mlme_semaphore));
4650 + init_completion (&pAd->mlmeComplete);
4651 +
4652 + init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore));
4653 + init_completion (&pAd->CmdQComplete);
4654 +
4655 + init_MUTEX_LOCKED(&(pAd->RTUSBTimer_semaphore));
4656 + init_completion (&pAd->TimerQComplete);
4657 +
4658 + // Creat MLME Thread
4659 + pObj->MLMEThr_pid= THREAD_PID_INIT_VALUE;
4660 + pid_number = kernel_thread(MlmeThread, pAd, CLONE_VM);
4661 + if (pid_number < 0)
4662 + {
4663 + printk (KERN_WARNING "%s: unable to start Mlme thread\n",pAd->net_dev->name);
4664 + return NDIS_STATUS_FAILURE;
4665 + }
4666 + pObj->MLMEThr_pid = GET_PID(pid_number);
4667 + // Wait for the thread to start
4668 + wait_for_completion(&(pAd->mlmeComplete));
4669 +
4670 + // Creat Command Thread
4671 + pObj->RTUSBCmdThr_pid= THREAD_PID_INIT_VALUE;
4672 + pid_number = kernel_thread(RTUSBCmdThread, pAd, CLONE_VM);
4673 + if (pid_number < 0)
4674 + {
4675 + printk (KERN_WARNING "%s: unable to start RTUSBCmd thread\n",pAd->net_dev->name);
4676 + return NDIS_STATUS_FAILURE;
4677 + }
4678 + pObj->RTUSBCmdThr_pid = GET_PID(pid_number);
4679 + wait_for_completion(&(pAd->CmdQComplete));
4680 +
4681 + pObj->TimerQThr_pid= THREAD_PID_INIT_VALUE;
4682 + pid_number = kernel_thread(TimerQThread, pAd, CLONE_VM);
4683 + if (pid_number < 0)
4684 + {
4685 + printk (KERN_WARNING "%s: unable to start TimerQThread\n",pAd->net_dev->name);
4686 + return NDIS_STATUS_FAILURE;
4687 + }
4688 + pObj->TimerQThr_pid = GET_PID(pid_number);
4689 + // Wait for the thread to start
4690 + wait_for_completion(&(pAd->TimerQComplete));
4691 +
4692 + // Create receive tasklet
4693 + tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (ULONG)pAd);
4694 + tasklet_init(&pObj->mgmt_dma_done_task, rt2870_mgmt_dma_done_tasklet, (unsigned long)pAd);
4695 + tasklet_init(&pObj->ac0_dma_done_task, rt2870_ac0_dma_done_tasklet, (unsigned long)pAd);
4696 + tasklet_init(&pObj->ac1_dma_done_task, rt2870_ac1_dma_done_tasklet, (unsigned long)pAd);
4697 + tasklet_init(&pObj->ac2_dma_done_task, rt2870_ac2_dma_done_tasklet, (unsigned long)pAd);
4698 + tasklet_init(&pObj->ac3_dma_done_task, rt2870_ac3_dma_done_tasklet, (unsigned long)pAd);
4699 + tasklet_init(&pObj->hcca_dma_done_task, rt2870_hcca_dma_done_tasklet, (unsigned long)pAd);
4700 + tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
4701 + tasklet_init(&pObj->null_frame_complete_task, rt2870_null_frame_complete_tasklet, (unsigned long)pAd);
4702 + tasklet_init(&pObj->rts_frame_complete_task, rt2870_rts_frame_complete_tasklet, (unsigned long)pAd);
4703 + tasklet_init(&pObj->pspoll_frame_complete_task, rt2870_pspoll_frame_complete_tasklet, (unsigned long)pAd);
4704 +
4705 + return NDIS_STATUS_SUCCESS;
4706 +}
4707 +
4708 +
4709 +#ifdef CONFIG_STA_SUPPORT
4710 +/*
4711 +========================================================================
4712 +Routine Description:
4713 + As STA's BSSID is a WC too, it uses shared key table.
4714 + This function write correct unicast TX key to ASIC WCID.
4715 + And we still make a copy in our MacTab.Content[BSSID_WCID].PairwiseKey.
4716 + Caller guarantee TKIP/AES always has keyidx = 0. (pairwise key)
4717 + Caller guarantee WEP calls this function when set Txkey, default key index=0~3.
4718 +
4719 +Arguments:
4720 + pAd Pointer to our adapter
4721 + pKey Pointer to the where the key stored
4722 +
4723 +Return Value:
4724 + NDIS_SUCCESS Add key successfully
4725 +
4726 +Note:
4727 +========================================================================
4728 +*/
4729 +VOID RTMPAddBSSIDCipher(
4730 + IN PRTMP_ADAPTER pAd,
4731 + IN UCHAR Aid,
4732 + IN PNDIS_802_11_KEY pKey,
4733 + IN UCHAR CipherAlg)
4734 +{
4735 + PUCHAR pTxMic, pRxMic;
4736 + BOOLEAN bKeyRSC, bAuthenticator; // indicate the receive SC set by KeyRSC value
4737 +// UCHAR CipherAlg;
4738 + UCHAR i;
4739 + ULONG WCIDAttri;
4740 + USHORT offset;
4741 + UCHAR KeyIdx, IVEIV[8];
4742 + UINT32 Value;
4743 +
4744 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddBSSIDCipher==> Aid = %d\n",Aid));
4745 +
4746 + // Bit 29 of Add-key KeyRSC
4747 + bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
4748 +
4749 + // Bit 28 of Add-key Authenticator
4750 + bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
4751 + KeyIdx = (UCHAR)pKey->KeyIndex&0xff;
4752 +
4753 + if (KeyIdx > 4)
4754 + return;
4755 +
4756 +
4757 + if (pAd->MacTab.Content[Aid].PairwiseKey.CipherAlg == CIPHER_TKIP)
4758 + { if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
4759 + {
4760 + // for WPA-None Tx, Rx MIC is the same
4761 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4762 + pRxMic = pTxMic;
4763 + }
4764 + else if (bAuthenticator == TRUE)
4765 + {
4766 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4767 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
4768 + }
4769 + else
4770 + {
4771 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4772 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
4773 + }
4774 +
4775 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE) + 0x10;
4776 + for (i=0; i<8; )
4777 + {
4778 + Value = *(pTxMic+i);
4779 + Value += (*(pTxMic+i+1)<<8);
4780 + Value += (*(pTxMic+i+2)<<16);
4781 + Value += (*(pTxMic+i+3)<<24);
4782 + RTUSBWriteMACRegister(pAd, offset+i, Value);
4783 + i+=4;
4784 + }
4785 +
4786 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE) + 0x18;
4787 + for (i=0; i<8; )
4788 + {
4789 + Value = *(pRxMic+i);
4790 + Value += (*(pRxMic+i+1)<<8);
4791 + Value += (*(pRxMic+i+2)<<16);
4792 + Value += (*(pRxMic+i+3)<<24);
4793 + RTUSBWriteMACRegister(pAd, offset+i, Value);
4794 + i+=4;
4795 + }
4796 +
4797 + // Only Key lenth equal to TKIP key have these
4798 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxMic, pRxMic, 8);
4799 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.TxMic, pTxMic, 8);
4800 +
4801 + DBGPRINT(RT_DEBUG_TRACE,
4802 + (" TxMIC = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n",
4803 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],
4804 + pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
4805 + DBGPRINT(RT_DEBUG_TRACE,
4806 + (" RxMIC = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n",
4807 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],
4808 + pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
4809 + }
4810 +
4811 + // 2. Record Security Key.
4812 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen= (UCHAR)pKey->KeyLength;
4813 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
4814 +
4815 + // 3. Check RxTsc. And used to init to ASIC IV.
4816 + if (bKeyRSC == TRUE)
4817 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxTsc, &pKey->KeyRSC, 6);
4818 + else
4819 + NdisZeroMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxTsc, 6);
4820 +
4821 + // 4. Init TxTsc to one based on WiFi WPA specs
4822 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[0] = 1;
4823 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[1] = 0;
4824 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[2] = 0;
4825 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[3] = 0;
4826 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[4] = 0;
4827 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[5] = 0;
4828 +
4829 + CipherAlg = pAd->MacTab.Content[Aid].PairwiseKey.CipherAlg;
4830 +
4831 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE);
4832 + RTUSBMultiWrite(pAd, (USHORT) offset, pKey->KeyMaterial,
4833 + ((pKey->KeyLength == LEN_TKIP_KEY) ? 16 : (USHORT)pKey->KeyLength));
4834 +
4835 + offset = SHARED_KEY_TABLE_BASE + (KeyIdx * HW_KEY_ENTRY_SIZE);
4836 + RTUSBMultiWrite(pAd, (USHORT) offset, pKey->KeyMaterial, (USHORT)pKey->KeyLength);
4837 +
4838 + offset = PAIRWISE_IVEIV_TABLE_BASE + (Aid * HW_IVEIV_ENTRY_SIZE);
4839 + NdisZeroMemory(IVEIV, 8);
4840 +
4841 + // IV/EIV
4842 + if ((CipherAlg == CIPHER_TKIP) ||
4843 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
4844 + (CipherAlg == CIPHER_AES))
4845 + {
4846 + IVEIV[3] = 0x20; // Eiv bit on. keyid always 0 for pairwise key
4847 + }
4848 + // default key idx needs to set.
4849 + // in TKIP/AES KeyIdx = 0 , WEP KeyIdx is default tx key.
4850 + else
4851 + {
4852 + IVEIV[3] |= (KeyIdx<< 6);
4853 + }
4854 + RTUSBMultiWrite(pAd, (USHORT) offset, IVEIV, 8);
4855 +
4856 + // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0
4857 + if ((CipherAlg == CIPHER_TKIP) ||
4858 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
4859 + (CipherAlg == CIPHER_AES))
4860 + {
4861 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
4862 + }
4863 + else
4864 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
4865 +
4866 + offset = MAC_WCID_ATTRIBUTE_BASE + (Aid* HW_WCID_ATTRI_SIZE);
4867 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
4868 + RTUSBReadMACRegister(pAd, offset, &Value);
4869 +
4870 + DBGPRINT(RT_DEBUG_TRACE, ("BSSID_WCID : offset = %x, WCIDAttri = %lx\n",
4871 + offset, WCIDAttri));
4872 +
4873 + // pAddr
4874 + // Add Bssid mac address at linkup. not here. check!
4875 + /*offset = MAC_WCID_BASE + (BSSID_WCID * HW_WCID_ENTRY_SIZE);
4876 + *for (i=0; i<MAC_ADDR_LEN; i++)
4877 + {
4878 + RTMP_IO_WRITE8(pAd, offset+i, pKey->BSSID[i]);
4879 + }
4880 + */
4881 +
4882 + DBGPRINT(RT_DEBUG_ERROR, ("AddBSSIDasWCIDEntry: Alg=%s, KeyLength = %d\n",
4883 + CipherName[CipherAlg], pKey->KeyLength));
4884 + DBGPRINT(RT_DEBUG_TRACE, ("Key [idx=%x] [KeyLen = %d]\n",
4885 + pKey->KeyIndex, pKey->KeyLength));
4886 + for(i=0; i<pKey->KeyLength; i++)
4887 + DBGPRINT_RAW(RT_DEBUG_TRACE,(" %x:", pKey->KeyMaterial[i]));
4888 + DBGPRINT(RT_DEBUG_TRACE,(" \n"));
4889 +}
4890 +#endif // CONFIG_STA_SUPPORT //
4891 +
4892 +/*
4893 +========================================================================
4894 +Routine Description:
4895 + Get a received packet.
4896 +
4897 +Arguments:
4898 + pAd device control block
4899 + pSaveRxD receive descriptor information
4900 + *pbReschedule need reschedule flag
4901 + *pRxPending pending received packet flag
4902 +
4903 +Return Value:
4904 + the recieved packet
4905 +
4906 +Note:
4907 +========================================================================
4908 +*/
4909 +#define RT2870_RXDMALEN_FIELD_SIZE 4
4910 +PNDIS_PACKET GetPacketFromRxRing(
4911 + IN PRTMP_ADAPTER pAd,
4912 + OUT PRT28XX_RXD_STRUC pSaveRxD,
4913 + OUT BOOLEAN *pbReschedule,
4914 + IN OUT UINT32 *pRxPending)
4915 +{
4916 + PRX_CONTEXT pRxContext;
4917 + PNDIS_PACKET pSkb;
4918 + PUCHAR pData;
4919 + ULONG ThisFrameLen;
4920 + ULONG RxBufferLength;
4921 + PRXWI_STRUC pRxWI;
4922 +
4923 + pRxContext = &pAd->RxContext[pAd->NextRxBulkInReadIndex];
4924 + if ((pRxContext->Readable == FALSE) || (pRxContext->InUse == TRUE))
4925 + return NULL;
4926 +
4927 + RxBufferLength = pRxContext->BulkInOffset - pAd->ReadPosition;
4928 + if (RxBufferLength < (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXWI_STRUC) + sizeof(RXINFO_STRUC)))
4929 + {
4930 + goto label_null;
4931 + }
4932 +
4933 + pData = &pRxContext->TransferBuffer[pAd->ReadPosition]; /* 4KB */
4934 + // The RXDMA field is 4 bytes, now just use the first 2 bytes. The Length including the (RXWI + MSDU + Padding)
4935 + ThisFrameLen = *pData + (*(pData+1)<<8);
4936 + if (ThisFrameLen == 0)
4937 + {
4938 + DBGPRINT(RT_DEBUG_TRACE, ("BIRIdx(%d): RXDMALen is zero.[%ld], BulkInBufLen = %ld)\n",
4939 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset));
4940 + goto label_null;
4941 + }
4942 + if ((ThisFrameLen&0x3) != 0)
4943 + {
4944 + DBGPRINT(RT_DEBUG_ERROR, ("BIRIdx(%d): RXDMALen not multiple of 4.[%ld], BulkInBufLen = %ld)\n",
4945 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset));
4946 + goto label_null;
4947 + }
4948 +
4949 + if ((ThisFrameLen + 8)> RxBufferLength) // 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXINFO_STRUC))
4950 + {
4951 + DBGPRINT(RT_DEBUG_TRACE,("BIRIdx(%d):FrameLen(0x%lx) outranges. BulkInLen=0x%lx, remaining RxBufLen=0x%lx, ReadPos=0x%lx\n",
4952 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset, RxBufferLength, pAd->ReadPosition));
4953 +
4954 + // error frame. finish this loop
4955 + goto label_null;
4956 + }
4957 +
4958 + // skip USB frame length field
4959 + pData += RT2870_RXDMALEN_FIELD_SIZE;
4960 + pRxWI = (PRXWI_STRUC)pData;
4961 +#ifdef RT_BIG_ENDIAN
4962 + RTMPWIEndianChange(pData, TYPE_RXWI);
4963 +#endif // RT_BIG_ENDIAN //
4964 + if (pRxWI->MPDUtotalByteCount > ThisFrameLen)
4965 + {
4966 + DBGPRINT(RT_DEBUG_ERROR, ("%s():pRxWIMPDUtotalByteCount(%d) large than RxDMALen(%ld)\n",
4967 + __FUNCTION__, pRxWI->MPDUtotalByteCount, ThisFrameLen));
4968 + goto label_null;
4969 + }
4970 +#ifdef RT_BIG_ENDIAN
4971 + RTMPWIEndianChange(pData, TYPE_RXWI);
4972 +#endif // RT_BIG_ENDIAN //
4973 +
4974 + // allocate a rx packet
4975 + pSkb = dev_alloc_skb(ThisFrameLen);
4976 + if (pSkb == NULL)
4977 + {
4978 + DBGPRINT(RT_DEBUG_ERROR,("%s():Cannot Allocate sk buffer for this Bulk-In buffer!\n", __FUNCTION__));
4979 + goto label_null;
4980 + }
4981 +
4982 + // copy the rx packet
4983 + memcpy(skb_put(pSkb, ThisFrameLen), pData, ThisFrameLen);
4984 + RTPKT_TO_OSPKT(pSkb)->dev = get_netdev_from_bssid(pAd, BSS0);
4985 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pSkb), PKTSRC_NDIS);
4986 +
4987 + // copy RxD
4988 + *pSaveRxD = *(PRXINFO_STRUC)(pData + ThisFrameLen);
4989 +#ifdef RT_BIG_ENDIAN
4990 + RTMPDescriptorEndianChange((PUCHAR)pSaveRxD, TYPE_RXINFO);
4991 +#endif // RT_BIG_ENDIAN //
4992 +
4993 + // update next packet read position.
4994 + pAd->ReadPosition += (ThisFrameLen + RT2870_RXDMALEN_FIELD_SIZE + RXINFO_SIZE); // 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXINFO_STRUC))
4995 +
4996 + return pSkb;
4997 +
4998 +label_null:
4999 +
5000 + return NULL;
5001 +}
5002 +
5003 +
5004 +/*
5005 +========================================================================
5006 +Routine Description:
5007 + Handle received packets.
5008 +
5009 +Arguments:
5010 + data - URB information pointer
5011 +
5012 +Return Value:
5013 + None
5014 +
5015 +Note:
5016 +========================================================================
5017 +*/
5018 +static void rx_done_tasklet(unsigned long data)
5019 +{
5020 + purbb_t pUrb;
5021 + PRX_CONTEXT pRxContext;
5022 + PRTMP_ADAPTER pAd;
5023 + NTSTATUS Status;
5024 + unsigned int IrqFlags;
5025 +
5026 + pUrb = (purbb_t)data;
5027 + pRxContext = (PRX_CONTEXT)pUrb->context;
5028 + pAd = pRxContext->pAd;
5029 + Status = pUrb->status;
5030 +
5031 +
5032 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
5033 + pRxContext->InUse = FALSE;
5034 + pRxContext->IRPPending = FALSE;
5035 + pRxContext->BulkInOffset += pUrb->actual_length;
5036 + //NdisInterlockedDecrement(&pAd->PendingRx);
5037 + pAd->PendingRx--;
5038 +
5039 + if (Status == USB_ST_NOERROR)
5040 + {
5041 + pAd->BulkInComplete++;
5042 + pAd->NextRxBulkInPosition = 0;
5043 + if (pRxContext->BulkInOffset) // As jan's comment, it may bulk-in success but size is zero.
5044 + {
5045 + pRxContext->Readable = TRUE;
5046 + INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE);
5047 + }
5048 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
5049 + }
5050 + else // STATUS_OTHER
5051 + {
5052 + pAd->BulkInCompleteFail++;
5053 + // Still read this packet although it may comtain wrong bytes.
5054 + pRxContext->Readable = FALSE;
5055 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
5056 +
5057 + // Parsing all packets. because after reset, the index will reset to all zero.
5058 + if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5059 + fRTMP_ADAPTER_BULKIN_RESET |
5060 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5061 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5062 + {
5063 +
5064 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk In Failed. Status=%d, BIIdx=0x%x, BIRIdx=0x%x, actual_length= 0x%x\n",
5065 + Status, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pRxContext->pUrb->actual_length));
5066 +
5067 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
5068 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
5069 + }
5070 + }
5071 +
5072 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
5073 +
5074 +#ifdef RALINK_ATE
5075 + if (ATE_ON(pAd))
5076 + {
5077 + // If the driver is in ATE mode and Rx frame is set into here.
5078 + if (pAd->ContinBulkIn == TRUE)
5079 + {
5080 + RTUSBBulkReceive(pAd);
5081 + }
5082 + }
5083 + else
5084 +#endif // RALINK_ATE //
5085 + RTUSBBulkReceive(pAd);
5086 +
5087 + return;
5088 +
5089 +}
5090 +
5091 +
5092 +static void rt2870_mgmt_dma_done_tasklet(unsigned long data)
5093 +{
5094 + PRTMP_ADAPTER pAd;
5095 + PTX_CONTEXT pMLMEContext;
5096 + int index;
5097 + PNDIS_PACKET pPacket;
5098 + purbb_t pUrb;
5099 + NTSTATUS Status;
5100 + unsigned long IrqFlags;
5101 +
5102 +
5103 + pUrb = (purbb_t)data;
5104 + pMLMEContext = (PTX_CONTEXT)pUrb->context;
5105 + pAd = pMLMEContext->pAd;
5106 + Status = pUrb->status;
5107 + index = pMLMEContext->SelfIdx;
5108 +
5109 + ASSERT((pAd->MgmtRing.TxDmaIdx == index));
5110 +
5111 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
5112 +
5113 +
5114 + if (Status != USB_ST_NOERROR)
5115 + {
5116 + //Bulk-Out fail status handle
5117 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5118 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5119 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5120 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5121 + {
5122 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out MLME Failed, Status=%d!\n", Status));
5123 + // TODO: How to handle about the MLMEBulkOut failed issue. Need to resend the mgmt pkt?
5124 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5125 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5126 + }
5127 + }
5128 +
5129 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
5130 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
5131 +
5132 + RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
5133 + // Reset MLME context flags
5134 + pMLMEContext->IRPPending = FALSE;
5135 + pMLMEContext->InUse = FALSE;
5136 + pMLMEContext->bWaitingBulkOut = FALSE;
5137 + pMLMEContext->BulkOutSize = 0;
5138 +
5139 + pPacket = pAd->MgmtRing.Cell[index].pNdisPacket;
5140 + pAd->MgmtRing.Cell[index].pNdisPacket = NULL;
5141 +
5142 + // Increase MgmtRing Index
5143 + INC_RING_INDEX(pAd->MgmtRing.TxDmaIdx, MGMT_RING_SIZE);
5144 + pAd->MgmtRing.TxSwFreeIdx++;
5145 + RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
5146 +
5147 + // No-matter success or fail, we free the mgmt packet.
5148 + if (pPacket)
5149 + RTMPFreeNdisPacket(pAd, pPacket);
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 + ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG))
5161 + { // For Mgmt Bulk-Out failed, ignore it now.
5162 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5163 + }
5164 + else
5165 + {
5166 +
5167 + // Always call Bulk routine, even reset bulk.
5168 + // The protectioon of rest bulk should be in BulkOut routine
5169 + if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */)
5170 + {
5171 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
5172 + }
5173 + RTUSBKickBulkOut(pAd);
5174 + }
5175 + }
5176 +
5177 +}
5178 +
5179 +
5180 +static void rt2870_hcca_dma_done_tasklet(unsigned long data)
5181 +{
5182 + PRTMP_ADAPTER pAd;
5183 + PHT_TX_CONTEXT pHTTXContext;
5184 + UCHAR BulkOutPipeId = 4;
5185 + purbb_t pUrb;
5186 +
5187 +
5188 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("--->hcca_dma_done_tasklet\n"));
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);
5220 + RTUSBKickBulkOut(pAd);
5221 + }
5222 + }
5223 +
5224 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("<---hcca_dma_done_tasklet\n"));
5225 +
5226 + return;
5227 +}
5228 +
5229 +
5230 +static void rt2870_ac3_dma_done_tasklet(unsigned long data)
5231 +{
5232 + PRTMP_ADAPTER pAd;
5233 + PHT_TX_CONTEXT pHTTXContext;
5234 + UCHAR BulkOutPipeId = 3;
5235 + purbb_t pUrb;
5236 +
5237 +
5238 + pUrb = (purbb_t)data;
5239 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5240 + pAd = pHTTXContext->pAd;
5241 +
5242 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5243 +
5244 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5245 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5246 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5247 + {
5248 + // do nothing and return directly.
5249 + }
5250 + else
5251 + {
5252 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5253 + {
5254 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5255 + }
5256 + else
5257 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5258 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5259 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5260 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5261 + (pHTTXContext->bCurWriting == FALSE))
5262 + {
5263 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5264 + }
5265 +
5266 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<3);
5267 + RTUSBKickBulkOut(pAd);
5268 + }
5269 + }
5270 +
5271 +
5272 + return;
5273 +}
5274 +
5275 +
5276 +static void rt2870_ac2_dma_done_tasklet(unsigned long data)
5277 +{
5278 + PRTMP_ADAPTER pAd;
5279 + PHT_TX_CONTEXT pHTTXContext;
5280 + UCHAR BulkOutPipeId = 2;
5281 + purbb_t pUrb;
5282 +
5283 +
5284 + pUrb = (purbb_t)data;
5285 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5286 + pAd = pHTTXContext->pAd;
5287 +
5288 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5289 +
5290 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5291 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5292 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5293 + {
5294 + // do nothing and return directly.
5295 + }
5296 + else
5297 + {
5298 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5299 + {
5300 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5301 + }
5302 + else
5303 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5304 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5305 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5306 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5307 + (pHTTXContext->bCurWriting == FALSE))
5308 + {
5309 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5310 + }
5311 +
5312 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<2);
5313 + RTUSBKickBulkOut(pAd);
5314 + }
5315 + }
5316 +
5317 + return;
5318 +}
5319 +
5320 +
5321 +static void rt2870_ac1_dma_done_tasklet(unsigned long data)
5322 +{
5323 + PRTMP_ADAPTER pAd;
5324 + PHT_TX_CONTEXT pHTTXContext;
5325 + UCHAR BulkOutPipeId = 1;
5326 + purbb_t pUrb;
5327 +
5328 +
5329 + pUrb = (purbb_t)data;
5330 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5331 + pAd = pHTTXContext->pAd;
5332 +
5333 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5334 +
5335 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5336 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5337 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5338 + {
5339 + // do nothing and return directly.
5340 + }
5341 + else
5342 + {
5343 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5344 + {
5345 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5346 + }
5347 + else
5348 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5349 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5350 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5351 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5352 + (pHTTXContext->bCurWriting == FALSE))
5353 + {
5354 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5355 + }
5356 +
5357 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<1);
5358 + RTUSBKickBulkOut(pAd);
5359 + }
5360 + }
5361 +
5362 +
5363 + return;
5364 +}
5365 +
5366 +
5367 +static void rt2870_ac0_dma_done_tasklet(unsigned long data)
5368 +{
5369 + PRTMP_ADAPTER pAd;
5370 + PHT_TX_CONTEXT pHTTXContext;
5371 + UCHAR BulkOutPipeId = 0;
5372 + purbb_t pUrb;
5373 +
5374 +
5375 + pUrb = (purbb_t)data;
5376 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5377 + pAd = pHTTXContext->pAd;
5378 +
5379 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5380 +
5381 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5382 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5383 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5384 + {
5385 + // do nothing and return directly.
5386 + }
5387 + else
5388 + {
5389 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5390 + {
5391 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5392 + }
5393 + else
5394 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5395 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5396 + /* ((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5397 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5398 + (pHTTXContext->bCurWriting == FALSE))
5399 + {
5400 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5401 + }
5402 +
5403 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL);
5404 + RTUSBKickBulkOut(pAd);
5405 + }
5406 + }
5407 +
5408 +
5409 + return;
5410 +
5411 +}
5412 +
5413 +
5414 +static void rt2870_null_frame_complete_tasklet(unsigned long data)
5415 +{
5416 + PRTMP_ADAPTER pAd;
5417 + PTX_CONTEXT pNullContext;
5418 + purbb_t pUrb;
5419 + NTSTATUS Status;
5420 + unsigned long irqFlag;
5421 +
5422 +
5423 + pUrb = (purbb_t)data;
5424 + pNullContext = (PTX_CONTEXT)pUrb->context;
5425 + pAd = pNullContext->pAd;
5426 + Status = pUrb->status;
5427 +
5428 + // Reset Null frame context flags
5429 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
5430 + pNullContext->IRPPending = FALSE;
5431 + pNullContext->InUse = FALSE;
5432 + pAd->BulkOutPending[0] = FALSE;
5433 + pAd->watchDogTxPendingCnt[0] = 0;
5434 +
5435 + if (Status == USB_ST_NOERROR)
5436 + {
5437 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5438 +
5439 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5440 + }
5441 + else // STATUS_OTHER
5442 + {
5443 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5444 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5445 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5446 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5447 + {
5448 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out Null Frame Failed, ReasonCode=%d!\n", Status));
5449 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5450 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5451 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5452 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5453 + }
5454 + else
5455 + {
5456 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5457 + }
5458 + }
5459 +
5460 + // Always call Bulk routine, even reset bulk.
5461 + // The protectioon of rest bulk should be in BulkOut routine
5462 + RTUSBKickBulkOut(pAd);
5463 +
5464 +}
5465 +
5466 +
5467 +static void rt2870_rts_frame_complete_tasklet(unsigned long data)
5468 +{
5469 + PRTMP_ADAPTER pAd;
5470 + PTX_CONTEXT pRTSContext;
5471 + purbb_t pUrb;
5472 + NTSTATUS Status;
5473 + unsigned long irqFlag;
5474 +
5475 +
5476 + pUrb = (purbb_t)data;
5477 + pRTSContext = (PTX_CONTEXT)pUrb->context;
5478 + pAd = pRTSContext->pAd;
5479 + Status = pUrb->status;
5480 +
5481 + // Reset RTS frame context flags
5482 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
5483 + pRTSContext->IRPPending = FALSE;
5484 + pRTSContext->InUse = FALSE;
5485 +
5486 + if (Status == USB_ST_NOERROR)
5487 + {
5488 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5489 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5490 + }
5491 + else // STATUS_OTHER
5492 + {
5493 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5494 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5495 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5496 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5497 + {
5498 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out RTS Frame Failed\n"));
5499 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5500 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5501 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5502 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5503 + }
5504 + else
5505 + {
5506 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5507 + }
5508 + }
5509 +
5510 + RTMP_SEM_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
5511 + pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE;
5512 + RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
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_pspoll_frame_complete_tasklet(unsigned long data)
5522 +{
5523 + PRTMP_ADAPTER pAd;
5524 + PTX_CONTEXT pPsPollContext;
5525 + purbb_t pUrb;
5526 + NTSTATUS Status;
5527 +
5528 +
5529 + pUrb = (purbb_t)data;
5530 + pPsPollContext = (PTX_CONTEXT)pUrb->context;
5531 + pAd = pPsPollContext->pAd;
5532 + Status = pUrb->status;
5533 +
5534 + // Reset PsPoll context flags
5535 + pPsPollContext->IRPPending = FALSE;
5536 + pPsPollContext->InUse = FALSE;
5537 + pAd->watchDogTxPendingCnt[0] = 0;
5538 +
5539 + if (Status == USB_ST_NOERROR)
5540 + {
5541 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5542 + }
5543 + else // STATUS_OTHER
5544 + {
5545 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5546 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5547 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5548 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5549 + {
5550 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out PSPoll Failed\n"));
5551 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5552 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5553 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5554 + }
5555 + }
5556 +
5557 + RTMP_SEM_LOCK(&pAd->BulkOutLock[0]);
5558 + pAd->BulkOutPending[0] = FALSE;
5559 + RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]);
5560 +
5561 + // Always call Bulk routine, even reset bulk.
5562 + // The protectioon of rest bulk should be in BulkOut routine
5563 + RTUSBKickBulkOut(pAd);
5564 +
5565 +}
5566 +
5567 +
5568 +static void rt2870_dataout_complete_tasklet(unsigned long data)
5569 +{
5570 + PRTMP_ADAPTER pAd;
5571 + purbb_t pUrb;
5572 + POS_COOKIE pObj;
5573 + PHT_TX_CONTEXT pHTTXContext;
5574 + UCHAR BulkOutPipeId;
5575 + NTSTATUS Status;
5576 + unsigned long IrqFlags;
5577 +
5578 +
5579 + pUrb = (purbb_t)data;
5580 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5581 + pAd = pHTTXContext->pAd;
5582 + pObj = (POS_COOKIE) pAd->OS_Cookie;
5583 + Status = pUrb->status;
5584 +
5585 + // Store BulkOut PipeId
5586 + BulkOutPipeId = pHTTXContext->BulkOutPipeId;
5587 + pAd->BulkOutDataOneSecCount++;
5588 +
5589 + //DBGPRINT(RT_DEBUG_LOUD, ("Done-B(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", BulkOutPipeId, in_interrupt(), pHTTXContext->CurWritePosition,
5590 + // pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
5591 +
5592 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5593 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
5594 + pHTTXContext->IRPPending = FALSE;
5595 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
5596 +
5597 + if (Status == USB_ST_NOERROR)
5598 + {
5599 + pAd->BulkOutComplete++;
5600 +
5601 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5602 +
5603 + pAd->Counters8023.GoodTransmits++;
5604 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5605 + FREE_HTTX_RING(pAd, BulkOutPipeId, pHTTXContext);
5606 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5607 +
5608 +
5609 + }
5610 + else // STATUS_OTHER
5611 + {
5612 + PUCHAR pBuf;
5613 +
5614 + pAd->BulkOutCompleteOther++;
5615 +
5616 + pBuf = &pHTTXContext->TransferBuffer->field.WirelessPacket[pHTTXContext->NextBulkOutPosition];
5617 +
5618 + if (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5619 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5620 + fRTMP_ADAPTER_NIC_NOT_EXIST |
5621 + fRTMP_ADAPTER_BULKOUT_RESET)))
5622 + {
5623 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5624 + pAd->bulkResetPipeid = BulkOutPipeId;
5625 + pAd->bulkResetReq[BulkOutPipeId] = pAd->BulkOutReq;
5626 + }
5627 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5628 +
5629 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkOutDataPacket failed: ReasonCode=%d!\n", Status));
5630 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("\t>>BulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther));
5631 + 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]));
5632 + //DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOutCompleteCancel=0x%x, BulkOutCompleteOther=0x%x\n", pAd->BulkOutCompleteCancel, pAd->BulkOutCompleteOther));
5633 +
5634 + }
5635 +
5636 + //
5637 + // bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut
5638 + // bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out.
5639 + //
5640 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5641 + if ((pHTTXContext->ENextBulkOutPosition != pHTTXContext->CurWritePosition) &&
5642 + (pHTTXContext->ENextBulkOutPosition != (pHTTXContext->CurWritePosition+8)) &&
5643 + !RTUSB_TEST_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId)))
5644 + {
5645 + // Indicate There is data avaliable
5646 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
5647 + }
5648 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5649 +
5650 + // Always call Bulk routine, even reset bulk.
5651 + // The protection of rest bulk should be in BulkOut routine
5652 + RTUSBKickBulkOut(pAd);
5653 +}
5654 +
5655 +/* End of 2870_rtmp_init.c */
5656 --- /dev/null
5657 +++ b/drivers/staging/rt2870/common/action.c
5658 @@ -0,0 +1,1046 @@
5659 +/*
5660 + *************************************************************************
5661 + * Ralink Tech Inc.
5662 + * 5F., No.36, Taiyuan St., Jhubei City,
5663 + * Hsinchu County 302,
5664 + * Taiwan, R.O.C.
5665 + *
5666 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
5667 + *
5668 + * This program is free software; you can redistribute it and/or modify *
5669 + * it under the terms of the GNU General Public License as published by *
5670 + * the Free Software Foundation; either version 2 of the License, or *
5671 + * (at your option) any later version. *
5672 + * *
5673 + * This program is distributed in the hope that it will be useful, *
5674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
5675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
5676 + * GNU General Public License for more details. *
5677 + * *
5678 + * You should have received a copy of the GNU General Public License *
5679 + * along with this program; if not, write to the *
5680 + * Free Software Foundation, Inc., *
5681 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
5682 + * *
5683 + *************************************************************************
5684 +
5685 + Module Name:
5686 + action.c
5687 +
5688 + Abstract:
5689 + Handle association related requests either from WSTA or from local MLME
5690 +
5691 + Revision History:
5692 + Who When What
5693 + -------- ---------- ----------------------------------------------
5694 + Jan Lee 2006 created for rt2860
5695 + */
5696 +
5697 +#include "../rt_config.h"
5698 +#include "action.h"
5699 +
5700 +
5701 +static VOID ReservedAction(
5702 + IN PRTMP_ADAPTER pAd,
5703 + IN MLME_QUEUE_ELEM *Elem);
5704 +
5705 +/*
5706 + ==========================================================================
5707 + Description:
5708 + association state machine init, including state transition and timer init
5709 + Parameters:
5710 + S - pointer to the association state machine
5711 + Note:
5712 + The state machine looks like the following
5713 +
5714 + ASSOC_IDLE
5715 + MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action
5716 + MT2_PEER_DISASSOC_REQ peer_disassoc_action
5717 + MT2_PEER_ASSOC_REQ drop
5718 + MT2_PEER_REASSOC_REQ drop
5719 + MT2_CLS3ERR cls3err_action
5720 + ==========================================================================
5721 + */
5722 +VOID ActionStateMachineInit(
5723 + IN PRTMP_ADAPTER pAd,
5724 + IN STATE_MACHINE *S,
5725 + OUT STATE_MACHINE_FUNC Trans[])
5726 +{
5727 + StateMachineInit(S, (STATE_MACHINE_FUNC *)Trans, MAX_ACT_STATE, MAX_ACT_MSG, (STATE_MACHINE_FUNC)Drop, ACT_IDLE, ACT_MACHINE_BASE);
5728 +
5729 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_SPECTRUM_CATE, (STATE_MACHINE_FUNC)PeerSpectrumAction);
5730 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_QOS_CATE, (STATE_MACHINE_FUNC)PeerQOSAction);
5731 +
5732 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, (STATE_MACHINE_FUNC)ReservedAction);
5733 +#ifdef QOS_DLS_SUPPORT
5734 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, (STATE_MACHINE_FUNC)PeerDLSAction);
5735 +#endif // QOS_DLS_SUPPORT //
5736 +
5737 +#ifdef DOT11_N_SUPPORT
5738 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_BA_CATE, (STATE_MACHINE_FUNC)PeerBAAction);
5739 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_HT_CATE, (STATE_MACHINE_FUNC)PeerHTAction);
5740 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ADD_BA_CATE, (STATE_MACHINE_FUNC)MlmeADDBAAction);
5741 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ORI_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction);
5742 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_REC_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction);
5743 +#endif // DOT11_N_SUPPORT //
5744 +
5745 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_PUBLIC_CATE, (STATE_MACHINE_FUNC)PeerPublicAction);
5746 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_RM_CATE, (STATE_MACHINE_FUNC)PeerRMAction);
5747 +
5748 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_QOS_CATE, (STATE_MACHINE_FUNC)MlmeQOSAction);
5749 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_DLS_CATE, (STATE_MACHINE_FUNC)MlmeDLSAction);
5750 + StateMachineSetAction(S, ACT_IDLE, MT2_ACT_INVALID, (STATE_MACHINE_FUNC)MlmeInvalidAction);
5751 +}
5752 +
5753 +#ifdef DOT11_N_SUPPORT
5754 +VOID MlmeADDBAAction(
5755 + IN PRTMP_ADAPTER pAd,
5756 + IN MLME_QUEUE_ELEM *Elem)
5757 +
5758 +{
5759 + MLME_ADDBA_REQ_STRUCT *pInfo;
5760 + UCHAR Addr[6];
5761 + PUCHAR pOutBuffer = NULL;
5762 + NDIS_STATUS NStatus;
5763 + ULONG Idx;
5764 + FRAME_ADDBA_REQ Frame;
5765 + ULONG FrameLen;
5766 + BA_ORI_ENTRY *pBAEntry = NULL;
5767 +
5768 + pInfo = (MLME_ADDBA_REQ_STRUCT *)Elem->Msg;
5769 + NdisZeroMemory(&Frame, sizeof(FRAME_ADDBA_REQ));
5770 +
5771 + if(MlmeAddBAReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr))
5772 + {
5773 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
5774 + if(NStatus != NDIS_STATUS_SUCCESS)
5775 + {
5776 + DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeADDBAAction() allocate memory failed \n"));
5777 + return;
5778 + }
5779 + // 1. find entry
5780 + Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
5781 + if (Idx == 0)
5782 + {
5783 + MlmeFreeMemory(pAd, pOutBuffer);
5784 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() can't find BAOriEntry \n"));
5785 + return;
5786 + }
5787 + else
5788 + {
5789 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
5790 + }
5791 +
5792 +#ifdef CONFIG_STA_SUPPORT
5793 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5794 + {
5795 + if (ADHOC_ON(pAd))
5796 + ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5797 + else
5798 +#ifdef QOS_DLS_SUPPORT
5799 + if (pAd->MacTab.Content[pInfo->Wcid].ValidAsDls)
5800 + ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5801 + else
5802 +#endif // QOS_DLS_SUPPORT //
5803 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pInfo->pAddr);
5804 +
5805 + }
5806 +#endif // CONFIG_STA_SUPPORT //
5807 +
5808 + Frame.Category = CATEGORY_BA;
5809 + Frame.Action = ADDBA_REQ;
5810 + Frame.BaParm.AMSDUSupported = 0;
5811 + Frame.BaParm.BAPolicy = IMMED_BA;
5812 + Frame.BaParm.TID = pInfo->TID;
5813 + Frame.BaParm.BufSize = pInfo->BaBufSize;
5814 + Frame.Token = pInfo->Token;
5815 + Frame.TimeOutValue = pInfo->TimeOutValue;
5816 + Frame.BaStartSeq.field.FragNum = 0;
5817 + Frame.BaStartSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID];
5818 +
5819 + *(USHORT *)(&Frame.BaParm) = cpu2le16(*(USHORT *)(&Frame.BaParm));
5820 + Frame.TimeOutValue = cpu2le16(Frame.TimeOutValue);
5821 + Frame.BaStartSeq.word = cpu2le16(Frame.BaStartSeq.word);
5822 +
5823 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
5824 + sizeof(FRAME_ADDBA_REQ), &Frame,
5825 + END_OF_ARGS);
5826 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
5827 + MlmeFreeMemory(pAd, pOutBuffer);
5828 +
5829 + DBGPRINT(RT_DEBUG_TRACE, ("BA - Send ADDBA request. StartSeq = %x, FrameLen = %ld. BufSize = %d\n", Frame.BaStartSeq.field.StartSeq, FrameLen, Frame.BaParm.BufSize));
5830 + }
5831 +}
5832 +
5833 +/*
5834 + ==========================================================================
5835 + Description:
5836 + send DELBA and delete BaEntry if any
5837 + Parametrs:
5838 + Elem - MLME message MLME_DELBA_REQ_STRUCT
5839 +
5840 + IRQL = DISPATCH_LEVEL
5841 +
5842 + ==========================================================================
5843 + */
5844 +VOID MlmeDELBAAction(
5845 + IN PRTMP_ADAPTER pAd,
5846 + IN MLME_QUEUE_ELEM *Elem)
5847 +{
5848 + MLME_DELBA_REQ_STRUCT *pInfo;
5849 + PUCHAR pOutBuffer = NULL;
5850 + PUCHAR pOutBuffer2 = NULL;
5851 + NDIS_STATUS NStatus;
5852 + ULONG Idx;
5853 + FRAME_DELBA_REQ Frame;
5854 + ULONG FrameLen;
5855 + FRAME_BAR FrameBar;
5856 +
5857 + pInfo = (MLME_DELBA_REQ_STRUCT *)Elem->Msg;
5858 + // must send back DELBA
5859 + NdisZeroMemory(&Frame, sizeof(FRAME_DELBA_REQ));
5860 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeDELBAAction(), Initiator(%d) \n", pInfo->Initiator));
5861 +
5862 + if(MlmeDelBAReqSanity(pAd, Elem->Msg, Elem->MsgLen))
5863 + {
5864 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
5865 + if(NStatus != NDIS_STATUS_SUCCESS)
5866 + {
5867 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeDELBAAction() allocate memory failed 1. \n"));
5868 + return;
5869 + }
5870 +
5871 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory
5872 + if(NStatus != NDIS_STATUS_SUCCESS)
5873 + {
5874 + MlmeFreeMemory(pAd, pOutBuffer);
5875 + DBGPRINT(RT_DEBUG_ERROR, ("BA - MlmeDELBAAction() allocate memory failed 2. \n"));
5876 + return;
5877 + }
5878 +
5879 + // SEND BAR (Send BAR to refresh peer reordering buffer.)
5880 + Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
5881 +
5882 +#ifdef CONFIG_STA_SUPPORT
5883 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5884 + BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress);
5885 +#endif // CONFIG_STA_SUPPORT //
5886 +
5887 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL funciton.
5888 + FrameBar.StartingSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; // make sure sequence not clear in DEL funciton.
5889 + FrameBar.BarControl.TID = pInfo->TID; // make sure sequence not clear in DEL funciton.
5890 + FrameBar.BarControl.ACKPolicy = IMMED_BA; // make sure sequence not clear in DEL funciton.
5891 + FrameBar.BarControl.Compressed = 1; // make sure sequence not clear in DEL funciton.
5892 + FrameBar.BarControl.MTID = 0; // make sure sequence not clear in DEL funciton.
5893 +
5894 + MakeOutgoingFrame(pOutBuffer2, &FrameLen,
5895 + sizeof(FRAME_BAR), &FrameBar,
5896 + END_OF_ARGS);
5897 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
5898 + MlmeFreeMemory(pAd, pOutBuffer2);
5899 + DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeDELBAAction() . Send BAR to refresh peer reordering buffer \n"));
5900 +
5901 + // SEND DELBA FRAME
5902 + FrameLen = 0;
5903 +#ifdef CONFIG_STA_SUPPORT
5904 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5905 + {
5906 + if (ADHOC_ON(pAd))
5907 + ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5908 + else
5909 +#ifdef QOS_DLS_SUPPORT
5910 + if (pAd->MacTab.Content[pInfo->Wcid].ValidAsDls)
5911 + ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5912 + else
5913 +#endif // QOS_DLS_SUPPORT //
5914 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[pInfo->Wcid].Addr);
5915 + }
5916 +#endif // CONFIG_STA_SUPPORT //
5917 + Frame.Category = CATEGORY_BA;
5918 + Frame.Action = DELBA;
5919 + Frame.DelbaParm.Initiator = pInfo->Initiator;
5920 + Frame.DelbaParm.TID = pInfo->TID;
5921 + Frame.ReasonCode = 39; // Time Out
5922 + *(USHORT *)(&Frame.DelbaParm) = cpu2le16(*(USHORT *)(&Frame.DelbaParm));
5923 + Frame.ReasonCode = cpu2le16(Frame.ReasonCode);
5924 +
5925 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
5926 + sizeof(FRAME_DELBA_REQ), &Frame,
5927 + END_OF_ARGS);
5928 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
5929 + MlmeFreeMemory(pAd, pOutBuffer);
5930 + DBGPRINT(RT_DEBUG_TRACE, ("BA - MlmeDELBAAction() . 3 DELBA sent. Initiator(%d)\n", pInfo->Initiator));
5931 + }
5932 +}
5933 +#endif // DOT11_N_SUPPORT //
5934 +
5935 +VOID MlmeQOSAction(
5936 + IN PRTMP_ADAPTER pAd,
5937 + IN MLME_QUEUE_ELEM *Elem)
5938 +{
5939 +}
5940 +
5941 +VOID MlmeDLSAction(
5942 + IN PRTMP_ADAPTER pAd,
5943 + IN MLME_QUEUE_ELEM *Elem)
5944 +{
5945 +}
5946 +
5947 +VOID MlmeInvalidAction(
5948 + IN PRTMP_ADAPTER pAd,
5949 + IN MLME_QUEUE_ELEM *Elem)
5950 +{
5951 + //PUCHAR pOutBuffer = NULL;
5952 + //Return the receiving frame except the MSB of category filed set to 1. 7.3.1.11
5953 +}
5954 +
5955 +VOID PeerQOSAction(
5956 + IN PRTMP_ADAPTER pAd,
5957 + IN MLME_QUEUE_ELEM *Elem)
5958 +{
5959 +}
5960 +
5961 +#ifdef QOS_DLS_SUPPORT
5962 +VOID PeerDLSAction(
5963 + IN PRTMP_ADAPTER pAd,
5964 + IN MLME_QUEUE_ELEM *Elem)
5965 +{
5966 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
5967 +
5968 + switch(Action)
5969 + {
5970 + case ACTION_DLS_REQUEST:
5971 +#ifdef CONFIG_STA_SUPPORT
5972 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5973 + PeerDlsReqAction(pAd, Elem);
5974 +#endif // CONFIG_STA_SUPPORT //
5975 + break;
5976 +
5977 + case ACTION_DLS_RESPONSE:
5978 +#ifdef CONFIG_STA_SUPPORT
5979 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5980 + PeerDlsRspAction(pAd, Elem);
5981 +#endif // CONFIG_STA_SUPPORT //
5982 + break;
5983 +
5984 + case ACTION_DLS_TEARDOWN:
5985 +#ifdef CONFIG_STA_SUPPORT
5986 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5987 + PeerDlsTearDownAction(pAd, Elem);
5988 +#endif // CONFIG_STA_SUPPORT //
5989 + break;
5990 + }
5991 +}
5992 +#endif // QOS_DLS_SUPPORT //
5993 +
5994 +#ifdef DOT11_N_SUPPORT
5995 +VOID PeerBAAction(
5996 + IN PRTMP_ADAPTER pAd,
5997 + IN MLME_QUEUE_ELEM *Elem)
5998 +{
5999 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
6000 +
6001 + switch(Action)
6002 + {
6003 + case ADDBA_REQ:
6004 + PeerAddBAReqAction(pAd,Elem);
6005 + break;
6006 + case ADDBA_RESP:
6007 + PeerAddBARspAction(pAd,Elem);
6008 + break;
6009 + case DELBA:
6010 + PeerDelBAAction(pAd,Elem);
6011 + break;
6012 + }
6013 +}
6014 +
6015 +
6016 +#ifdef DOT11N_DRAFT3
6017 +
6018 +#ifdef CONFIG_STA_SUPPORT
6019 +VOID StaPublicAction(
6020 + IN PRTMP_ADAPTER pAd,
6021 + IN UCHAR Bss2040Coexist)
6022 +{
6023 + BSS_2040_COEXIST_IE BssCoexist;
6024 + MLME_SCAN_REQ_STRUCT ScanReq;
6025 +
6026 + BssCoexist.word = Bss2040Coexist;
6027 + // 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
6028 + if ((BssCoexist.field.InfoReq == 1) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SCAN_2040)))
6029 + {
6030 + // Clear record first. After scan , will update those bit and send back to transmiter.
6031 + pAd->CommonCfg.BSSCoexist2040.field.InfoReq = 1;
6032 + pAd->CommonCfg.BSSCoexist2040.field.Intolerant40 = 0;
6033 + pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq = 0;
6034 + // Fill out stuff for scan request
6035 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_2040_BSS_COEXIST);
6036 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
6037 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
6038 + }
6039 +}
6040 +
6041 +
6042 +/*
6043 +Description : Build Intolerant Channel Rerpot from Trigger event table.
6044 +return : how many bytes copied.
6045 +*/
6046 +ULONG BuildIntolerantChannelRep(
6047 + IN PRTMP_ADAPTER pAd,
6048 + IN PUCHAR pDest)
6049 +{
6050 + ULONG FrameLen = 0;
6051 + ULONG ReadOffset = 0;
6052 + UCHAR i;
6053 + UCHAR LastRegClass = 0xff;
6054 + PUCHAR pLen;
6055 +
6056 + for ( i = 0;i < MAX_TRIGGER_EVENT;i++)
6057 + {
6058 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].bValid == TRUE)
6059 + {
6060 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].RegClass == LastRegClass)
6061 + {
6062 + *(pDest + ReadOffset) = (UCHAR)pAd->CommonCfg.TriggerEventTab.EventA[i].Channel;
6063 + *pLen++;
6064 + ReadOffset++;
6065 + FrameLen++;
6066 + }
6067 + else
6068 + {
6069 + *(pDest + ReadOffset) = IE_2040_BSS_INTOLERANT_REPORT; // IE
6070 + *(pDest + ReadOffset + 1) = 2; // Len = RegClass byte + channel byte.
6071 + pLen = pDest + ReadOffset + 1;
6072 + LastRegClass = pAd->CommonCfg.TriggerEventTab.EventA[i].RegClass;
6073 + *(pDest + ReadOffset + 2) = LastRegClass; // Len = RegClass byte + channel byte.
6074 + *(pDest + ReadOffset + 3) = (UCHAR)pAd->CommonCfg.TriggerEventTab.EventA[i].Channel;
6075 + FrameLen += 4;
6076 + ReadOffset += 4;
6077 + }
6078 +
6079 + }
6080 + }
6081 + return FrameLen;
6082 +}
6083 +
6084 +
6085 +/*
6086 +Description : Send 20/40 BSS Coexistence Action frame If one trigger event is triggered.
6087 +*/
6088 +VOID Send2040CoexistAction(
6089 + IN PRTMP_ADAPTER pAd,
6090 + IN UCHAR Wcid,
6091 + IN BOOLEAN bAddIntolerantCha)
6092 +{
6093 + PUCHAR pOutBuffer = NULL;
6094 + NDIS_STATUS NStatus;
6095 + FRAME_ACTION_HDR Frame;
6096 + ULONG FrameLen;
6097 + ULONG IntolerantChaRepLen;
6098 +
6099 + IntolerantChaRepLen = 0;
6100 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6101 + if(NStatus != NDIS_STATUS_SUCCESS)
6102 + {
6103 + DBGPRINT(RT_DEBUG_ERROR,("ACT - Send2040CoexistAction() allocate memory failed \n"));
6104 + return;
6105 + }
6106 + ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[Wcid].Addr, pAd->CommonCfg.Bssid);
6107 + Frame.Category = CATEGORY_PUBLIC;
6108 + Frame.Action = ACTION_BSS_2040_COEXIST;
6109 +
6110 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6111 + sizeof(FRAME_ACTION_HDR), &Frame,
6112 + END_OF_ARGS);
6113 +
6114 + *(pOutBuffer + FrameLen) = pAd->CommonCfg.BSSCoexist2040.word;
6115 + FrameLen++;
6116 +
6117 + if (bAddIntolerantCha == TRUE)
6118 + IntolerantChaRepLen = BuildIntolerantChannelRep(pAd, pOutBuffer + FrameLen);
6119 +
6120 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen + IntolerantChaRepLen);
6121 + DBGPRINT(RT_DEBUG_ERROR,("ACT - Send2040CoexistAction( BSSCoexist2040 = 0x%x ) \n", pAd->CommonCfg.BSSCoexist2040.word));
6122 +
6123 +}
6124 +
6125 +
6126 +/*
6127 + ==========================================================================
6128 + Description:
6129 + After scan, Update 20/40 BSS Coexistence IE and send out.
6130 + According to 802.11n D3.03 11.14.10
6131 +
6132 + Parameters:
6133 + ==========================================================================
6134 + */
6135 +VOID Update2040CoexistFrameAndNotify(
6136 + IN PRTMP_ADAPTER pAd,
6137 + IN UCHAR Wcid,
6138 + IN BOOLEAN bAddIntolerantCha)
6139 +{
6140 + BSS_2040_COEXIST_IE OldValue;
6141 +
6142 + OldValue.word = pAd->CommonCfg.BSSCoexist2040.word;
6143 + if ((pAd->CommonCfg.TriggerEventTab.EventANo > 0) || (pAd->CommonCfg.TriggerEventTab.EventBCountDown > 0))
6144 + pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq = 1;
6145 +
6146 + // Need to check !!!!
6147 + // How STA will set Intolerant40 if implementation dependent. Now we don't set this bit first.!!!!!
6148 + // So Only check BSS20WidthReq change.
6149 + if (OldValue.field.BSS20WidthReq != pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq)
6150 + {
6151 + Send2040CoexistAction(pAd, Wcid, bAddIntolerantCha);
6152 + }
6153 +}
6154 +#endif // CONFIG_STA_SUPPORT //
6155 +
6156 +
6157 +BOOLEAN ChannelSwitchSanityCheck(
6158 + IN PRTMP_ADAPTER pAd,
6159 + IN UCHAR Wcid,
6160 + IN UCHAR NewChannel,
6161 + IN UCHAR Secondary)
6162 +{
6163 + UCHAR i;
6164 +
6165 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
6166 + return FALSE;
6167 +
6168 + if ((NewChannel > 7) && (Secondary == 1))
6169 + return FALSE;
6170 +
6171 + if ((NewChannel < 5) && (Secondary == 3))
6172 + return FALSE;
6173 +
6174 + // 0. Check if new channel is in the channellist.
6175 + for (i = 0;i < pAd->ChannelListNum;i++)
6176 + {
6177 + if (pAd->ChannelList[i].Channel == NewChannel)
6178 + {
6179 + break;
6180 + }
6181 + }
6182 +
6183 + if (i == pAd->ChannelListNum)
6184 + return FALSE;
6185 +
6186 + return TRUE;
6187 +}
6188 +
6189 +
6190 +VOID ChannelSwitchAction(
6191 + IN PRTMP_ADAPTER pAd,
6192 + IN UCHAR Wcid,
6193 + IN UCHAR NewChannel,
6194 + IN UCHAR Secondary)
6195 +{
6196 + UCHAR BBPValue = 0;
6197 + ULONG MACValue;
6198 +
6199 + DBGPRINT(RT_DEBUG_TRACE,("SPECTRUM - ChannelSwitchAction(NewChannel = %d , Secondary = %d) \n", NewChannel, Secondary));
6200 +
6201 + if (ChannelSwitchSanityCheck(pAd, Wcid, NewChannel, Secondary) == FALSE)
6202 + return;
6203 +
6204 + // 1. Switches to BW = 20.
6205 + if (Secondary == 0)
6206 + {
6207 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6208 + BBPValue&= (~0x18);
6209 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6210 + if (pAd->MACVersion == 0x28600100)
6211 + {
6212 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
6213 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
6214 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
6215 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
6216 + }
6217 + pAd->CommonCfg.BBPCurrentBW = BW_20;
6218 + pAd->CommonCfg.Channel = NewChannel;
6219 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
6220 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel,FALSE);
6221 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
6222 + pAd->MacTab.Content[Wcid].HTPhyMode.field.BW = 0;
6223 + DBGPRINT(RT_DEBUG_TRACE, ("!!!20MHz !!! \n" ));
6224 + }
6225 + // 1. Switches to BW = 40 And Station supports BW = 40.
6226 + else if (((Secondary == 1) || (Secondary == 3)) && (pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == 1))
6227 + {
6228 + pAd->CommonCfg.Channel = NewChannel;
6229 +
6230 + if (Secondary == 1)
6231 + {
6232 + // Secondary above.
6233 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
6234 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &MACValue);
6235 + MACValue &= 0xfe;
6236 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, MACValue);
6237 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6238 + BBPValue&= (~0x18);
6239 + BBPValue|= (0x10);
6240 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6241 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPValue);
6242 + BBPValue&= (~0x20);
6243 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPValue);
6244 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
6245 + }
6246 + else
6247 + {
6248 + // Secondary below.
6249 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
6250 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &MACValue);
6251 + MACValue &= 0xfe;
6252 + MACValue |= 0x1;
6253 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, MACValue);
6254 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6255 + BBPValue&= (~0x18);
6256 + BBPValue|= (0x10);
6257 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6258 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPValue);
6259 + BBPValue&= (~0x20);
6260 + BBPValue|= (0x20);
6261 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPValue);
6262 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
6263 + }
6264 + pAd->CommonCfg.BBPCurrentBW = BW_40;
6265 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
6266 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
6267 + pAd->MacTab.Content[Wcid].HTPhyMode.field.BW = 1;
6268 + }
6269 +}
6270 +#endif // DOT11N_DRAFT3 //
6271 +#endif // DOT11_N_SUPPORT //
6272 +
6273 +VOID PeerPublicAction(
6274 + IN PRTMP_ADAPTER pAd,
6275 + IN MLME_QUEUE_ELEM *Elem)
6276 +{
6277 +#ifdef DOT11N_DRAFT3
6278 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
6279 +#endif // DOT11N_DRAFT3 //
6280 +
6281 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
6282 + return;
6283 +
6284 +#ifdef DOT11N_DRAFT3
6285 + switch(Action)
6286 + {
6287 + case ACTION_BSS_2040_COEXIST: // Format defined in IEEE 7.4.7a.1 in 11n Draf3.03
6288 + {
6289 + //UCHAR BssCoexist;
6290 + BSS_2040_COEXIST_ELEMENT *pCoexistInfo;
6291 + BSS_2040_COEXIST_IE *pBssCoexistIe;
6292 + BSS_2040_INTOLERANT_CH_REPORT *pIntolerantReport = NULL;
6293 +
6294 + if (Elem->MsgLen <= (LENGTH_802_11 + sizeof(BSS_2040_COEXIST_ELEMENT)) )
6295 + {
6296 + DBGPRINT(RT_DEBUG_ERROR, ("ACTION - 20/40 BSS Coexistence Management Frame length too short! len = %ld!\n", Elem->MsgLen));
6297 + break;
6298 + }
6299 + DBGPRINT(RT_DEBUG_TRACE, ("ACTION - 20/40 BSS Coexistence Management action----> \n"));
6300 + hex_dump("CoexistenceMgmtFrame", Elem->Msg, Elem->MsgLen);
6301 +
6302 +
6303 + pCoexistInfo = (BSS_2040_COEXIST_ELEMENT *) &Elem->Msg[LENGTH_802_11+2];
6304 + //hex_dump("CoexistInfo", (PUCHAR)pCoexistInfo, sizeof(BSS_2040_COEXIST_ELEMENT));
6305 + if (Elem->MsgLen >= (LENGTH_802_11 + sizeof(BSS_2040_COEXIST_ELEMENT) + sizeof(BSS_2040_INTOLERANT_CH_REPORT)))
6306 + {
6307 + pIntolerantReport = (BSS_2040_INTOLERANT_CH_REPORT *)((PUCHAR)pCoexistInfo + sizeof(BSS_2040_COEXIST_ELEMENT));
6308 + }
6309 + //hex_dump("IntolerantReport ", (PUCHAR)pIntolerantReport, sizeof(BSS_2040_INTOLERANT_CH_REPORT));
6310 +
6311 + pBssCoexistIe = (BSS_2040_COEXIST_IE *)(&pCoexistInfo->BssCoexistIe);
6312 +
6313 +#ifdef CONFIG_STA_SUPPORT
6314 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6315 + {
6316 + if (INFRA_ON(pAd))
6317 + {
6318 + StaPublicAction(pAd, pCoexistInfo);
6319 + }
6320 + }
6321 +#endif // CONFIG_STA_SUPPORT //
6322 +
6323 + }
6324 + break;
6325 + }
6326 +
6327 +#endif // DOT11N_DRAFT3 //
6328 +
6329 +}
6330 +
6331 +
6332 +static VOID ReservedAction(
6333 + IN PRTMP_ADAPTER pAd,
6334 + IN MLME_QUEUE_ELEM *Elem)
6335 +{
6336 + UCHAR Category;
6337 +
6338 + if (Elem->MsgLen <= LENGTH_802_11)
6339 + {
6340 + return;
6341 + }
6342 +
6343 + Category = Elem->Msg[LENGTH_802_11];
6344 + DBGPRINT(RT_DEBUG_TRACE,("Rcv reserved category(%d) Action Frame\n", Category));
6345 + hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen);
6346 +}
6347 +
6348 +VOID PeerRMAction(
6349 + IN PRTMP_ADAPTER pAd,
6350 + IN MLME_QUEUE_ELEM *Elem)
6351 +
6352 +{
6353 + return;
6354 +}
6355 +
6356 +#ifdef DOT11_N_SUPPORT
6357 +static VOID respond_ht_information_exchange_action(
6358 + IN PRTMP_ADAPTER pAd,
6359 + IN MLME_QUEUE_ELEM *Elem)
6360 +{
6361 + PUCHAR pOutBuffer = NULL;
6362 + NDIS_STATUS NStatus;
6363 + ULONG FrameLen;
6364 + FRAME_HT_INFO HTINFOframe, *pFrame;
6365 + UCHAR *pAddr;
6366 +
6367 +
6368 + // 2. Always send back ADDBA Response
6369 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6370 +
6371 + if (NStatus != NDIS_STATUS_SUCCESS)
6372 + {
6373 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - respond_ht_information_exchange_action() allocate memory failed \n"));
6374 + return;
6375 + }
6376 +
6377 + // get RA
6378 + pFrame = (FRAME_HT_INFO *) &Elem->Msg[0];
6379 + pAddr = pFrame->Hdr.Addr2;
6380 +
6381 + NdisZeroMemory(&HTINFOframe, sizeof(FRAME_HT_INFO));
6382 + // 2-1. Prepare ADDBA Response frame.
6383 +#ifdef CONFIG_STA_SUPPORT
6384 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6385 + {
6386 + if (ADHOC_ON(pAd))
6387 + ActHeaderInit(pAd, &HTINFOframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
6388 + else
6389 + ActHeaderInit(pAd, &HTINFOframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr);
6390 + }
6391 +#endif // CONFIG_STA_SUPPORT //
6392 +
6393 + HTINFOframe.Category = CATEGORY_HT;
6394 + HTINFOframe.Action = HT_INFO_EXCHANGE;
6395 + HTINFOframe.HT_Info.Request = 0;
6396 + HTINFOframe.HT_Info.Forty_MHz_Intolerant = pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant;
6397 + HTINFOframe.HT_Info.STA_Channel_Width = pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth;
6398 +
6399 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6400 + sizeof(FRAME_HT_INFO), &HTINFOframe,
6401 + END_OF_ARGS);
6402 +
6403 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
6404 + MlmeFreeMemory(pAd, pOutBuffer);
6405 +}
6406 +
6407 +
6408 +#ifdef DOT11N_DRAFT3
6409 +VOID SendNotifyBWActionFrame(
6410 + IN PRTMP_ADAPTER pAd,
6411 + IN UCHAR Wcid,
6412 + IN UCHAR apidx)
6413 +{
6414 + PUCHAR pOutBuffer = NULL;
6415 + NDIS_STATUS NStatus;
6416 + FRAME_ACTION_HDR Frame;
6417 + ULONG FrameLen;
6418 + PUCHAR pAddr1;
6419 +
6420 +
6421 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6422 + if(NStatus != NDIS_STATUS_SUCCESS)
6423 + {
6424 + DBGPRINT(RT_DEBUG_ERROR,("ACT - SendNotifyBWAction() allocate memory failed \n"));
6425 + return;
6426 + }
6427 +
6428 + if (Wcid == MCAST_WCID)
6429 + pAddr1 = &BROADCAST_ADDR[0];
6430 + else
6431 + pAddr1 = pAd->MacTab.Content[Wcid].Addr;
6432 + ActHeaderInit(pAd, &Frame.Hdr, pAddr1, pAd->ApCfg.MBSSID[apidx].Bssid, pAd->ApCfg.MBSSID[apidx].Bssid);
6433 +
6434 + Frame.Category = CATEGORY_HT;
6435 + Frame.Action = NOTIFY_BW_ACTION;
6436 +
6437 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6438 + sizeof(FRAME_ACTION_HDR), &Frame,
6439 + END_OF_ARGS);
6440 +
6441 + *(pOutBuffer + FrameLen) = pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth;
6442 + FrameLen++;
6443 +
6444 +
6445 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
6446 + DBGPRINT(RT_DEBUG_TRACE,("ACT - SendNotifyBWAction(NotifyBW= %d)!\n", pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth));
6447 +
6448 +}
6449 +#endif // DOT11N_DRAFT3 //
6450 +
6451 +
6452 +VOID PeerHTAction(
6453 + IN PRTMP_ADAPTER pAd,
6454 + IN MLME_QUEUE_ELEM *Elem)
6455 +{
6456 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
6457 +
6458 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
6459 + return;
6460 +
6461 + switch(Action)
6462 + {
6463 + case NOTIFY_BW_ACTION:
6464 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Notify Channel bandwidth action----> \n"));
6465 +#ifdef CONFIG_STA_SUPPORT
6466 + if(pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
6467 + {
6468 + // Note, this is to patch DIR-1353 AP. When the AP set to Wep, it will use legacy mode. But AP still keeps
6469 + // sending BW_Notify Action frame, and cause us to linkup and linkdown.
6470 + // In legacy mode, don't need to parse HT action frame.
6471 + DBGPRINT(RT_DEBUG_TRACE,("ACTION -Ignore HT Notify Channel BW when link as legacy mode. BW = %d---> \n",
6472 + Elem->Msg[LENGTH_802_11+2] ));
6473 + break;
6474 + }
6475 +#endif // CONFIG_STA_SUPPORT //
6476 +
6477 + if (Elem->Msg[LENGTH_802_11+2] == 0) // 7.4.8.2. if value is 1, keep the same as supported channel bandwidth.
6478 + pAd->MacTab.Content[Elem->Wcid].HTPhyMode.field.BW = 0;
6479 +
6480 + break;
6481 +
6482 + case SMPS_ACTION:
6483 + // 7.3.1.25
6484 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - SMPS action----> \n"));
6485 + if (((Elem->Msg[LENGTH_802_11+2]&0x1) == 0))
6486 + {
6487 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_ENABLE;
6488 + }
6489 + else if (((Elem->Msg[LENGTH_802_11+2]&0x2) == 0))
6490 + {
6491 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_STATIC;
6492 + }
6493 + else
6494 + {
6495 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_DYNAMIC;
6496 + }
6497 +
6498 + DBGPRINT(RT_DEBUG_TRACE,("Aid(%d) MIMO PS = %d\n", Elem->Wcid, pAd->MacTab.Content[Elem->Wcid].MmpsMode));
6499 + // rt2860c : add something for smps change.
6500 + break;
6501 +
6502 + case SETPCO_ACTION:
6503 + break;
6504 +
6505 + case MIMO_CHA_MEASURE_ACTION:
6506 + break;
6507 +
6508 + case HT_INFO_EXCHANGE:
6509 + {
6510 + HT_INFORMATION_OCTET *pHT_info;
6511 +
6512 + pHT_info = (HT_INFORMATION_OCTET *) &Elem->Msg[LENGTH_802_11+2];
6513 + // 7.4.8.10
6514 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Information Exchange action----> \n"));
6515 + if (pHT_info->Request)
6516 + {
6517 + respond_ht_information_exchange_action(pAd, Elem);
6518 + }
6519 + }
6520 + break;
6521 + }
6522 +}
6523 +
6524 +
6525 +/*
6526 + ==========================================================================
6527 + Description:
6528 + Retry sending ADDBA Reqest.
6529 +
6530 + IRQL = DISPATCH_LEVEL
6531 +
6532 + Parametrs:
6533 + p8023Header: if this is already 802.3 format, p8023Header is NULL
6534 +
6535 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
6536 + FALSE , then continue indicaterx at this moment.
6537 + ==========================================================================
6538 + */
6539 +VOID ORIBATimerTimeout(
6540 + IN PRTMP_ADAPTER pAd)
6541 +{
6542 + MAC_TABLE_ENTRY *pEntry;
6543 + INT i, total;
6544 +// FRAME_BAR FrameBar;
6545 +// ULONG FrameLen;
6546 +// NDIS_STATUS NStatus;
6547 +// PUCHAR pOutBuffer = NULL;
6548 +// USHORT Sequence;
6549 + UCHAR TID;
6550 +
6551 +#ifdef RALINK_ATE
6552 + if (ATE_ON(pAd))
6553 + return;
6554 +#endif // RALINK_ATE //
6555 +
6556 + total = pAd->MacTab.Size * NUM_OF_TID;
6557 +
6558 + for (i = 1; ((i <MAX_LEN_OF_BA_ORI_TABLE) && (total > 0)) ; i++)
6559 + {
6560 + if (pAd->BATable.BAOriEntry[i].ORI_BA_Status == Originator_Done)
6561 + {
6562 + pEntry = &pAd->MacTab.Content[pAd->BATable.BAOriEntry[i].Wcid];
6563 + TID = pAd->BATable.BAOriEntry[i].TID;
6564 +
6565 + ASSERT(pAd->BATable.BAOriEntry[i].Wcid < MAX_LEN_OF_MAC_TABLE);
6566 + }
6567 + total --;
6568 + }
6569 +}
6570 +
6571 +
6572 +VOID SendRefreshBAR(
6573 + IN PRTMP_ADAPTER pAd,
6574 + IN MAC_TABLE_ENTRY *pEntry)
6575 +{
6576 + FRAME_BAR FrameBar;
6577 + ULONG FrameLen;
6578 + NDIS_STATUS NStatus;
6579 + PUCHAR pOutBuffer = NULL;
6580 + USHORT Sequence;
6581 + UCHAR i, TID;
6582 + USHORT idx;
6583 + BA_ORI_ENTRY *pBAEntry;
6584 +
6585 + for (i = 0; i <NUM_OF_TID; i++)
6586 + {
6587 + idx = pEntry->BAOriWcidArray[i];
6588 + if (idx == 0)
6589 + {
6590 + continue;
6591 + }
6592 + pBAEntry = &pAd->BATable.BAOriEntry[idx];
6593 +
6594 + if (pBAEntry->ORI_BA_Status == Originator_Done)
6595 + {
6596 + TID = pBAEntry->TID;
6597 +
6598 + ASSERT(pBAEntry->Wcid < MAX_LEN_OF_MAC_TABLE);
6599 +
6600 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6601 + if(NStatus != NDIS_STATUS_SUCCESS)
6602 + {
6603 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n"));
6604 + return;
6605 + }
6606 +
6607 + Sequence = pEntry->TxSeq[TID];
6608 +
6609 +
6610 +#ifdef CONFIG_STA_SUPPORT
6611 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6612 + BarHeaderInit(pAd, &FrameBar, pEntry->Addr, pAd->CurrentAddress);
6613 +#endif // CONFIG_STA_SUPPORT //
6614 +
6615 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function.
6616 + FrameBar.StartingSeq.field.StartSeq = Sequence; // make sure sequence not clear in DEL funciton.
6617 + FrameBar.BarControl.TID = TID; // make sure sequence not clear in DEL funciton.
6618 +
6619 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6620 + sizeof(FRAME_BAR), &FrameBar,
6621 + END_OF_ARGS);
6622 + //if (!(CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_RALINK_CHIPSET)))
6623 + if (1) // Now we always send BAR.
6624 + {
6625 + //MiniportMMRequestUnlock(pAd, 0, pOutBuffer, FrameLen);
6626 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
6627 + }
6628 + MlmeFreeMemory(pAd, pOutBuffer);
6629 + }
6630 + }
6631 +}
6632 +#endif // DOT11_N_SUPPORT //
6633 +
6634 +VOID ActHeaderInit(
6635 + IN PRTMP_ADAPTER pAd,
6636 + IN OUT PHEADER_802_11 pHdr80211,
6637 + IN PUCHAR Addr1,
6638 + IN PUCHAR Addr2,
6639 + IN PUCHAR Addr3)
6640 +{
6641 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
6642 + pHdr80211->FC.Type = BTYPE_MGMT;
6643 + pHdr80211->FC.SubType = SUBTYPE_ACTION;
6644 +
6645 + COPY_MAC_ADDR(pHdr80211->Addr1, Addr1);
6646 + COPY_MAC_ADDR(pHdr80211->Addr2, Addr2);
6647 + COPY_MAC_ADDR(pHdr80211->Addr3, Addr3);
6648 +}
6649 +
6650 +VOID BarHeaderInit(
6651 + IN PRTMP_ADAPTER pAd,
6652 + IN OUT PFRAME_BAR pCntlBar,
6653 + IN PUCHAR pDA,
6654 + IN PUCHAR pSA)
6655 +{
6656 +// USHORT Duration;
6657 +
6658 + NdisZeroMemory(pCntlBar, sizeof(FRAME_BAR));
6659 + pCntlBar->FC.Type = BTYPE_CNTL;
6660 + pCntlBar->FC.SubType = SUBTYPE_BLOCK_ACK_REQ;
6661 + pCntlBar->BarControl.MTID = 0;
6662 + pCntlBar->BarControl.Compressed = 1;
6663 + pCntlBar->BarControl.ACKPolicy = 0;
6664 +
6665 +
6666 + pCntlBar->Duration = 16 + RTMPCalcDuration(pAd, RATE_1, sizeof(FRAME_BA));
6667 +
6668 + COPY_MAC_ADDR(pCntlBar->Addr1, pDA);
6669 + COPY_MAC_ADDR(pCntlBar->Addr2, pSA);
6670 +}
6671 +
6672 +
6673 +/*
6674 + ==========================================================================
6675 + Description:
6676 + Insert Category and action code into the action frame.
6677 +
6678 + Parametrs:
6679 + 1. frame buffer pointer.
6680 + 2. frame length.
6681 + 3. category code of the frame.
6682 + 4. action code of the frame.
6683 +
6684 + Return : None.
6685 + ==========================================================================
6686 + */
6687 +VOID InsertActField(
6688 + IN PRTMP_ADAPTER pAd,
6689 + OUT PUCHAR pFrameBuf,
6690 + OUT PULONG pFrameLen,
6691 + IN UINT8 Category,
6692 + IN UINT8 ActCode)
6693 +{
6694 + ULONG TempLen;
6695 +
6696 + MakeOutgoingFrame( pFrameBuf, &TempLen,
6697 + 1, &Category,
6698 + 1, &ActCode,
6699 + END_OF_ARGS);
6700 +
6701 + *pFrameLen = *pFrameLen + TempLen;
6702 +
6703 + return;
6704 +}
6705 --- /dev/null
6706 +++ b/drivers/staging/rt2870/common/action.h
6707 @@ -0,0 +1,68 @@
6708 +/*
6709 + *************************************************************************
6710 + * Ralink Tech Inc.
6711 + * 5F., No.36, Taiyuan St., Jhubei City,
6712 + * Hsinchu County 302,
6713 + * Taiwan, R.O.C.
6714 + *
6715 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
6716 + *
6717 + * This program is free software; you can redistribute it and/or modify *
6718 + * it under the terms of the GNU General Public License as published by *
6719 + * the Free Software Foundation; either version 2 of the License, or *
6720 + * (at your option) any later version. *
6721 + * *
6722 + * This program is distributed in the hope that it will be useful, *
6723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
6724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
6725 + * GNU General Public License for more details. *
6726 + * *
6727 + * You should have received a copy of the GNU General Public License *
6728 + * along with this program; if not, write to the *
6729 + * Free Software Foundation, Inc., *
6730 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
6731 + * *
6732 + *************************************************************************
6733 +
6734 + Module Name:
6735 + aironet.h
6736 +
6737 + Abstract:
6738 +
6739 + Revision History:
6740 + Who When What
6741 + -------- ---------- ----------------------------------------------
6742 + Name Date Modification logs
6743 + Paul Lin 04-06-15 Initial
6744 +*/
6745 +
6746 +#ifndef __ACTION_H__
6747 +#define __ACTION_H__
6748 +
6749 +typedef struct PACKED __HT_INFO_OCTET
6750 +{
6751 +#ifdef RT_BIG_ENDIAN
6752 + UCHAR Reserved:5;
6753 + UCHAR STA_Channel_Width:1;
6754 + UCHAR Forty_MHz_Intolerant:1;
6755 + UCHAR Request:1;
6756 +#else
6757 + UCHAR Request:1;
6758 + UCHAR Forty_MHz_Intolerant:1;
6759 + UCHAR STA_Channel_Width:1;
6760 + UCHAR Reserved:5;
6761 +#endif
6762 +} HT_INFORMATION_OCTET;
6763 +
6764 +
6765 +typedef struct PACKED __FRAME_HT_INFO
6766 +{
6767 + HEADER_802_11 Hdr;
6768 + UCHAR Category;
6769 + UCHAR Action;
6770 + HT_INFORMATION_OCTET HT_Info;
6771 +} FRAME_HT_INFO, *PFRAME_HT_INFO;
6772 +
6773 +#endif /* __ACTION_H__ */
6774 +
6775 +
6776 --- /dev/null
6777 +++ b/drivers/staging/rt2870/common/ba_action.c
6778 @@ -0,0 +1,1798 @@
6779 +/*
6780 + *************************************************************************
6781 + * Ralink Tech Inc.
6782 + * 5F., No.36, Taiyuan St., Jhubei City,
6783 + * Hsinchu County 302,
6784 + * Taiwan, R.O.C.
6785 + *
6786 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
6787 + *
6788 + * This program is free software; you can redistribute it and/or modify *
6789 + * it under the terms of the GNU General Public License as published by *
6790 + * the Free Software Foundation; either version 2 of the License, or *
6791 + * (at your option) any later version. *
6792 + * *
6793 + * This program is distributed in the hope that it will be useful, *
6794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
6795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
6796 + * GNU General Public License for more details. *
6797 + * *
6798 + * You should have received a copy of the GNU General Public License *
6799 + * along with this program; if not, write to the *
6800 + * Free Software Foundation, Inc., *
6801 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
6802 + * *
6803 + *************************************************************************
6804 + */
6805 +
6806 +
6807 +#ifdef DOT11_N_SUPPORT
6808 +
6809 +#include "../rt_config.h"
6810 +
6811 +
6812 +
6813 +#define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) //1 // inital sequence number of BA session
6814 +
6815 +#define ORI_SESSION_MAX_RETRY 8
6816 +#define ORI_BA_SESSION_TIMEOUT (2000) // ms
6817 +#define REC_BA_SESSION_IDLE_TIMEOUT (1000) // ms
6818 +
6819 +#define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms
6820 +#define MAX_REORDERING_PACKET_TIMEOUT ((3000 * HZ)/1000) // system ticks -- 100 ms
6821 +
6822 +#define RESET_RCV_SEQ (0xFFFF)
6823 +
6824 +static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk);
6825 +
6826 +
6827 +BA_ORI_ENTRY *BATableAllocOriEntry(
6828 + IN PRTMP_ADAPTER pAd,
6829 + OUT USHORT *Idx);
6830 +
6831 +BA_REC_ENTRY *BATableAllocRecEntry(
6832 + IN PRTMP_ADAPTER pAd,
6833 + OUT USHORT *Idx);
6834 +
6835 +VOID BAOriSessionSetupTimeout(
6836 + IN PVOID SystemSpecific1,
6837 + IN PVOID FunctionContext,
6838 + IN PVOID SystemSpecific2,
6839 + IN PVOID SystemSpecific3);
6840 +
6841 +VOID BARecSessionIdleTimeout(
6842 + IN PVOID SystemSpecific1,
6843 + IN PVOID FunctionContext,
6844 + IN PVOID SystemSpecific2,
6845 + IN PVOID SystemSpecific3);
6846 +
6847 +
6848 +BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout);
6849 +BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout);
6850 +
6851 +#define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \
6852 + Announce_Reordering_Packet(_pAd, _mpdu_blk);
6853 +
6854 +VOID BA_MaxWinSizeReasign(
6855 + IN PRTMP_ADAPTER pAd,
6856 + IN MAC_TABLE_ENTRY *pEntryPeer,
6857 + OUT UCHAR *pWinSize)
6858 +{
6859 + UCHAR MaxSize;
6860 +
6861 +
6862 + if (pAd->MACVersion >= RALINK_2883_VERSION) // 3*3
6863 + {
6864 + if (pAd->MACVersion >= RALINK_3070_VERSION)
6865 + {
6866 + if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled)
6867 + MaxSize = 7; // for non-open mode
6868 + else
6869 + MaxSize = 13;
6870 + }
6871 + else
6872 + MaxSize = 31;
6873 + }
6874 + else if (pAd->MACVersion >= RALINK_2880E_VERSION) // 2880 e
6875 + {
6876 + if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled)
6877 + MaxSize = 7; // for non-open mode
6878 + else
6879 + MaxSize = 13;
6880 + }
6881 + else
6882 + MaxSize = 7;
6883 +
6884 + DBGPRINT(RT_DEBUG_TRACE, ("ba> Win Size = %d, Max Size = %d\n",
6885 + *pWinSize, MaxSize));
6886 +
6887 + if ((*pWinSize) > MaxSize)
6888 + {
6889 + DBGPRINT(RT_DEBUG_TRACE, ("ba> reassign max win size from %d to %d\n",
6890 + *pWinSize, MaxSize));
6891 +
6892 + *pWinSize = MaxSize;
6893 + }
6894 +}
6895 +
6896 +void Announce_Reordering_Packet(IN PRTMP_ADAPTER pAd,
6897 + IN struct reordering_mpdu *mpdu)
6898 +{
6899 + PNDIS_PACKET pPacket;
6900 +
6901 + pPacket = mpdu->pPacket;
6902 +
6903 + if (mpdu->bAMSDU)
6904 + {
6905 + ASSERT(0);
6906 + BA_Reorder_AMSDU_Annnounce(pAd, pPacket);
6907 + }
6908 + else
6909 + {
6910 + //
6911 + // pass this 802.3 packet to upper layer or forward this packet to WM directly
6912 + //
6913 +
6914 +#ifdef CONFIG_STA_SUPPORT
6915 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6916 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket, RTMP_GET_PACKET_IF(pPacket));
6917 +#endif // CONFIG_STA_SUPPORT //
6918 + }
6919 +}
6920 +
6921 +/*
6922 + * Insert a reordering mpdu into sorted linked list by sequence no.
6923 + */
6924 +BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list, struct reordering_mpdu *mpdu)
6925 +{
6926 +
6927 + struct reordering_mpdu **ppScan = &list->next;
6928 +
6929 + while (*ppScan != NULL)
6930 + {
6931 + if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ))
6932 + {
6933 + ppScan = &(*ppScan)->next;
6934 + }
6935 + else if ((*ppScan)->Sequence == mpdu->Sequence)
6936 + {
6937 + /* give up this duplicated frame */
6938 + return(FALSE);
6939 + }
6940 + else
6941 + {
6942 + /* find position */
6943 + break;
6944 + }
6945 + }
6946 +
6947 + mpdu->next = *ppScan;
6948 + *ppScan = mpdu;
6949 + list->qlen++;
6950 + return TRUE;
6951 +}
6952 +
6953 +
6954 +/*
6955 + * caller lock critical section if necessary
6956 + */
6957 +static inline void ba_enqueue(struct reordering_list *list, struct reordering_mpdu *mpdu_blk)
6958 +{
6959 + list->qlen++;
6960 + mpdu_blk->next = list->next;
6961 + list->next = mpdu_blk;
6962 +}
6963 +
6964 +/*
6965 + * caller lock critical section if necessary
6966 + */
6967 +static inline struct reordering_mpdu * ba_dequeue(struct reordering_list *list)
6968 +{
6969 + struct reordering_mpdu *mpdu_blk = NULL;
6970 +
6971 + ASSERT(list);
6972 +
6973 + if (list->qlen)
6974 + {
6975 + list->qlen--;
6976 + mpdu_blk = list->next;
6977 + if (mpdu_blk)
6978 + {
6979 + list->next = mpdu_blk->next;
6980 + mpdu_blk->next = NULL;
6981 + }
6982 + }
6983 + return mpdu_blk;
6984 +}
6985 +
6986 +
6987 +static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct reordering_list *list)
6988 +{
6989 + return(ba_dequeue(list));
6990 +}
6991 +
6992 +
6993 +static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct reordering_list *list)
6994 + {
6995 + ASSERT(list);
6996 +
6997 + return(list->next);
6998 + }
6999 +
7000 +
7001 +/*
7002 + * free all resource for reordering mechanism
7003 + */
7004 +void ba_reordering_resource_release(PRTMP_ADAPTER pAd)
7005 +{
7006 + BA_TABLE *Tab;
7007 + PBA_REC_ENTRY pBAEntry;
7008 + struct reordering_mpdu *mpdu_blk;
7009 + int i;
7010 +
7011 + Tab = &pAd->BATable;
7012 +
7013 + /* I. release all pending reordering packet */
7014 + NdisAcquireSpinLock(&pAd->BATabLock);
7015 + for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++)
7016 + {
7017 + pBAEntry = &Tab->BARecEntry[i];
7018 + if (pBAEntry->REC_BA_Status != Recipient_NONE)
7019 + {
7020 + while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list)))
7021 + {
7022 + ASSERT(mpdu_blk->pPacket);
7023 + RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket, NDIS_STATUS_FAILURE);
7024 + ba_mpdu_blk_free(pAd, mpdu_blk);
7025 + }
7026 + }
7027 + }
7028 + NdisReleaseSpinLock(&pAd->BATabLock);
7029 +
7030 + ASSERT(pBAEntry->list.qlen == 0);
7031 + /* II. free memory of reordering mpdu table */
7032 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
7033 + os_free_mem(pAd, pAd->mpdu_blk_pool.mem);
7034 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
7035 +}
7036 +
7037 +
7038 +
7039 +/*
7040 + * Allocate all resource for reordering mechanism
7041 + */
7042 +BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num)
7043 +{
7044 + int i;
7045 + PUCHAR mem;
7046 + struct reordering_mpdu *mpdu_blk;
7047 + struct reordering_list *freelist;
7048 +
7049 + /* allocate spinlock */
7050 + NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock);
7051 +
7052 + /* initialize freelist */
7053 + freelist = &pAd->mpdu_blk_pool.freelist;
7054 + freelist->next = NULL;
7055 + freelist->qlen = 0;
7056 +
7057 + DBGPRINT(RT_DEBUG_TRACE, ("Allocate %d memory for BA reordering\n", (UINT32)(num*sizeof(struct reordering_mpdu))));
7058 +
7059 + /* allocate number of mpdu_blk memory */
7060 + os_alloc_mem(pAd, (PUCHAR *)&mem, (num*sizeof(struct reordering_mpdu)));
7061 +
7062 + pAd->mpdu_blk_pool.mem = mem;
7063 +
7064 + if (mem == NULL)
7065 + {
7066 + DBGPRINT(RT_DEBUG_ERROR, ("Can't Allocate Memory for BA Reordering\n"));
7067 + return(FALSE);
7068 + }
7069 +
7070 + /* build mpdu_blk free list */
7071 + for (i=0; i<num; i++)
7072 + {
7073 + /* get mpdu_blk */
7074 + mpdu_blk = (struct reordering_mpdu *) mem;
7075 + /* initial mpdu_blk */
7076 + NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
7077 + /* next mpdu_blk */
7078 + mem += sizeof(struct reordering_mpdu);
7079 + /* insert mpdu_blk into freelist */
7080 + ba_enqueue(freelist, mpdu_blk);
7081 + }
7082 +
7083 + return(TRUE);
7084 +}
7085 +
7086 +//static int blk_count=0; // sample take off, no use
7087 +
7088 +static struct reordering_mpdu *ba_mpdu_blk_alloc(PRTMP_ADAPTER pAd)
7089 +{
7090 + struct reordering_mpdu *mpdu_blk;
7091 +
7092 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
7093 + mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist);
7094 + if (mpdu_blk)
7095 + {
7096 +// blk_count++;
7097 + /* reset mpdu_blk */
7098 + NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
7099 + }
7100 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
7101 + return mpdu_blk;
7102 +}
7103 +
7104 +static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk)
7105 +{
7106 + ASSERT(mpdu_blk);
7107 +
7108 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
7109 +// blk_count--;
7110 + ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk);
7111 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
7112 +}
7113 +
7114 +
7115 +static USHORT ba_indicate_reordering_mpdus_in_order(
7116 + IN PRTMP_ADAPTER pAd,
7117 + IN PBA_REC_ENTRY pBAEntry,
7118 + IN USHORT StartSeq)
7119 +{
7120 + struct reordering_mpdu *mpdu_blk;
7121 + USHORT LastIndSeq = RESET_RCV_SEQ;
7122 +
7123 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
7124 +
7125 + while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list)))
7126 + {
7127 + /* find in-order frame */
7128 + if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ))
7129 + {
7130 + break;
7131 + }
7132 + /* dequeue in-order frame from reodering list */
7133 + mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
7134 + /* pass this frame up */
7135 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7136 + /* move to next sequence */
7137 + StartSeq = mpdu_blk->Sequence;
7138 + LastIndSeq = StartSeq;
7139 + /* free mpdu_blk */
7140 + ba_mpdu_blk_free(pAd, mpdu_blk);
7141 + }
7142 +
7143 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7144 +
7145 + /* update last indicated sequence */
7146 + return LastIndSeq;
7147 +}
7148 +
7149 +static void ba_indicate_reordering_mpdus_le_seq(
7150 + IN PRTMP_ADAPTER pAd,
7151 + IN PBA_REC_ENTRY pBAEntry,
7152 + IN USHORT Sequence)
7153 +{
7154 + struct reordering_mpdu *mpdu_blk;
7155 +
7156 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
7157 + while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list)))
7158 + {
7159 + /* find in-order frame */
7160 + if ((mpdu_blk->Sequence == Sequence) || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ))
7161 + {
7162 + /* dequeue in-order frame from reodering list */
7163 + mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
7164 + /* pass this frame up */
7165 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7166 + /* free mpdu_blk */
7167 + ba_mpdu_blk_free(pAd, mpdu_blk);
7168 + }
7169 + else
7170 + {
7171 + break;
7172 + }
7173 + }
7174 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7175 +}
7176 +
7177 +
7178 +static void ba_refresh_reordering_mpdus(
7179 + IN PRTMP_ADAPTER pAd,
7180 + PBA_REC_ENTRY pBAEntry)
7181 +{
7182 + struct reordering_mpdu *mpdu_blk;
7183 +
7184 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
7185 +
7186 + /* dequeue in-order frame from reodering list */
7187 + while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list)))
7188 + {
7189 + /* pass this frame up */
7190 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7191 +
7192 + pBAEntry->LastIndSeq = mpdu_blk->Sequence;
7193 + ba_mpdu_blk_free(pAd, mpdu_blk);
7194 +
7195 + /* update last indicated sequence */
7196 + }
7197 + ASSERT(pBAEntry->list.qlen == 0);
7198 + pBAEntry->LastIndSeq = RESET_RCV_SEQ;
7199 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7200 +}
7201 +
7202 +
7203 +//static
7204 +void ba_flush_reordering_timeout_mpdus(
7205 + IN PRTMP_ADAPTER pAd,
7206 + IN PBA_REC_ENTRY pBAEntry,
7207 + IN ULONG Now32)
7208 +
7209 +{
7210 + USHORT Sequence;
7211 +
7212 +// if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) &&
7213 +// (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //||
7214 +// (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) &&
7215 +// (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8)))
7216 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(MAX_REORDERING_PACKET_TIMEOUT/6)))
7217 + &&(pBAEntry->list.qlen > 1)
7218 + )
7219 + {
7220 + DBGPRINT(RT_DEBUG_TRACE,("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer),
7221 + (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), MAX_REORDERING_PACKET_TIMEOUT,
7222 + pBAEntry->LastIndSeq));
7223 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7224 + pBAEntry->LastIndSeqAtTimer = Now32;
7225 + }
7226 + else
7227 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT)))
7228 + && (pBAEntry->list.qlen > 0)
7229 + )
7230 + {
7231 + //
7232 + // force LastIndSeq to shift to LastIndSeq+1
7233 + //
7234 + Sequence = (pBAEntry->LastIndSeq+1) & MAXSEQ;
7235 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
7236 + pBAEntry->LastIndSeqAtTimer = Now32;
7237 + pBAEntry->LastIndSeq = Sequence;
7238 + //
7239 + // indicate in-order mpdus
7240 + //
7241 + Sequence = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, Sequence);
7242 + if (Sequence != RESET_RCV_SEQ)
7243 + {
7244 + pBAEntry->LastIndSeq = Sequence;
7245 + }
7246 +
7247 + }
7248 +#if 0
7249 + else if (
7250 + (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(MAX_REORDERING_PACKET_TIMEOUT))) &&
7251 + (pBAEntry->list.qlen > 1))
7252 + )
7253 + {
7254 + DBGPRINT(RT_DEBUG_TRACE,("timeout[%d] (%lx-%lx = %d > %d): %x\n ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer),
7255 + (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), MAX_REORDERING_PACKET_TIMEOUT,
7256 + pBAEntry->LastIndSeq));
7257 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7258 + pBAEntry->LastIndSeqAtTimer = Now32;
7259 + }
7260 +#endif
7261 +}
7262 +
7263 +
7264 +/*
7265 + * generate ADDBA request to
7266 + * set up BA agreement
7267 + */
7268 +VOID BAOriSessionSetUp(
7269 + IN PRTMP_ADAPTER pAd,
7270 + IN MAC_TABLE_ENTRY *pEntry,
7271 + IN UCHAR TID,
7272 + IN USHORT TimeOut,
7273 + IN ULONG DelayTime,
7274 + IN BOOLEAN isForced)
7275 +
7276 +{
7277 + //MLME_ADDBA_REQ_STRUCT AddbaReq;
7278 + BA_ORI_ENTRY *pBAEntry = NULL;
7279 + USHORT Idx;
7280 + BOOLEAN Cancelled;
7281 +
7282 + if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE) && (isForced == FALSE))
7283 + return;
7284 +
7285 + // if this entry is limited to use legacy tx mode, it doesn't generate BA.
7286 + if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT)
7287 + return;
7288 +
7289 + if ((pEntry->BADeclineBitmap & (1<<TID)) && (isForced == FALSE))
7290 + {
7291 + // try again after 3 secs
7292 + DelayTime = 3000;
7293 +// printk("DeCline BA from Peer\n");
7294 +// return;
7295 + }
7296 +
7297 +
7298 + Idx = pEntry->BAOriWcidArray[TID];
7299 + if (Idx == 0)
7300 + {
7301 + // allocate a BA session
7302 + pBAEntry = BATableAllocOriEntry(pAd, &Idx);
7303 + if (pBAEntry == NULL)
7304 + {
7305 + DBGPRINT(RT_DEBUG_TRACE,("ADDBA - MlmeADDBAAction() allocate BA session failed \n"));
7306 + return;
7307 + }
7308 + }
7309 + else
7310 + {
7311 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7312 + }
7313 +
7314 + if (pBAEntry->ORI_BA_Status >= Originator_WaitRes)
7315 + {
7316 + return;
7317 + }
7318 +
7319 + pEntry->BAOriWcidArray[TID] = Idx;
7320 +
7321 + // Initialize BA session
7322 + pBAEntry->ORI_BA_Status = Originator_WaitRes;
7323 + pBAEntry->Wcid = pEntry->Aid;
7324 + pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit;
7325 + pBAEntry->Sequence = BA_ORI_INIT_SEQ;
7326 + pBAEntry->Token = 1; // (2008-01-21) Jan Lee recommends it - this token can't be 0
7327 + pBAEntry->TID = TID;
7328 + pBAEntry->TimeOutValue = TimeOut;
7329 + pBAEntry->pAdapter = pAd;
7330 +
7331 + if (!(pEntry->TXBAbitmap & (1<<TID)))
7332 + {
7333 + RTMPInitTimer(pAd, &pBAEntry->ORIBATimer, GET_TIMER_FUNCTION(BAOriSessionSetupTimeout), pBAEntry, FALSE);
7334 + }
7335 + else
7336 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7337 +
7338 + // set timer to send ADDBA request
7339 + RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime);
7340 +}
7341 +
7342 +VOID BAOriSessionAdd(
7343 + IN PRTMP_ADAPTER pAd,
7344 + IN MAC_TABLE_ENTRY *pEntry,
7345 + IN PFRAME_ADDBA_RSP pFrame)
7346 +{
7347 + BA_ORI_ENTRY *pBAEntry = NULL;
7348 + BOOLEAN Cancelled;
7349 + UCHAR TID;
7350 + USHORT Idx;
7351 + PUCHAR pOutBuffer2 = NULL;
7352 + NDIS_STATUS NStatus;
7353 + ULONG FrameLen;
7354 + FRAME_BAR FrameBar;
7355 +
7356 + TID = pFrame->BaParm.TID;
7357 + Idx = pEntry->BAOriWcidArray[TID];
7358 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7359 +
7360 + // Start fill in parameters.
7361 + if ((Idx !=0) && (pBAEntry->TID == TID) && (pBAEntry->ORI_BA_Status == Originator_WaitRes))
7362 + {
7363 + pBAEntry->BAWinSize = min(pBAEntry->BAWinSize, ((UCHAR)pFrame->BaParm.BufSize));
7364 + BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize);
7365 +
7366 + pBAEntry->TimeOutValue = pFrame->TimeOutValue;
7367 + pBAEntry->ORI_BA_Status = Originator_Done;
7368 + // reset sequence number
7369 + pBAEntry->Sequence = BA_ORI_INIT_SEQ;
7370 + // Set Bitmap flag.
7371 + pEntry->TXBAbitmap |= (1<<TID);
7372 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7373 +
7374 + pBAEntry->ORIBATimer.TimerValue = 0; //pFrame->TimeOutValue;
7375 +
7376 + DBGPRINT(RT_DEBUG_TRACE,("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n", __FUNCTION__, pEntry->TXBAbitmap,
7377 + pBAEntry->BAWinSize, pBAEntry->ORIBATimer.TimerValue));
7378 +
7379 + // SEND BAR ;
7380 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory
7381 + if (NStatus != NDIS_STATUS_SUCCESS)
7382 + {
7383 + DBGPRINT(RT_DEBUG_TRACE,("BA - BAOriSessionAdd() allocate memory failed \n"));
7384 + return;
7385 + }
7386 +
7387 +
7388 +#ifdef CONFIG_STA_SUPPORT
7389 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
7390 + BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pBAEntry->Wcid].Addr, pAd->CurrentAddress);
7391 +#endif // CONFIG_STA_SUPPORT //
7392 +
7393 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function.
7394 + FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; // make sure sequence not clear in DEL funciton.
7395 + FrameBar.BarControl.TID = pBAEntry->TID; // make sure sequence not clear in DEL funciton.
7396 + MakeOutgoingFrame(pOutBuffer2, &FrameLen,
7397 + sizeof(FRAME_BAR), &FrameBar,
7398 + END_OF_ARGS);
7399 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
7400 + MlmeFreeMemory(pAd, pOutBuffer2);
7401 +
7402 +
7403 + if (pBAEntry->ORIBATimer.TimerValue)
7404 + RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); // in mSec
7405 + }
7406 +}
7407 +
7408 +BOOLEAN BARecSessionAdd(
7409 + IN PRTMP_ADAPTER pAd,
7410 + IN MAC_TABLE_ENTRY *pEntry,
7411 + IN PFRAME_ADDBA_REQ pFrame)
7412 +{
7413 + BA_REC_ENTRY *pBAEntry = NULL;
7414 + BOOLEAN Status = TRUE;
7415 + BOOLEAN Cancelled;
7416 + USHORT Idx;
7417 + UCHAR TID;
7418 + UCHAR BAWinSize;
7419 + //UINT32 Value;
7420 + //UINT offset;
7421 +
7422 +
7423 + ASSERT(pEntry);
7424 +
7425 + // find TID
7426 + TID = pFrame->BaParm.TID;
7427 +
7428 + BAWinSize = min(((UCHAR)pFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
7429 +
7430 + // Intel patch
7431 + if (BAWinSize == 0)
7432 + {
7433 + BAWinSize = 64;
7434 + }
7435 +
7436 + Idx = pEntry->BARecWcidArray[TID];
7437 +
7438 +
7439 + if (Idx == 0)
7440 + {
7441 + pBAEntry = BATableAllocRecEntry(pAd, &Idx);
7442 + }
7443 + else
7444 + {
7445 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
7446 + // flush all pending reordering mpdus
7447 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7448 + }
7449 +
7450 + DBGPRINT(RT_DEBUG_TRACE,("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __FUNCTION__, pAd->BATable.numAsRecipient, Idx,
7451 + pFrame->BaParm.BufSize, BAWinSize));
7452 +
7453 + // Start fill in parameters.
7454 + if (pBAEntry != NULL)
7455 + {
7456 + ASSERT(pBAEntry->list.qlen == 0);
7457 +
7458 + pBAEntry->REC_BA_Status = Recipient_HandleRes;
7459 + pBAEntry->BAWinSize = BAWinSize;
7460 + pBAEntry->Wcid = pEntry->Aid;
7461 + pBAEntry->TID = TID;
7462 + pBAEntry->TimeOutValue = pFrame->TimeOutValue;
7463 + pBAEntry->REC_BA_Status = Recipient_Accept;
7464 + // initial sequence number
7465 + pBAEntry->LastIndSeq = RESET_RCV_SEQ; //pFrame->BaStartSeq.field.StartSeq;
7466 +
7467 + printk("Start Seq = %08x\n", pFrame->BaStartSeq.field.StartSeq);
7468 +
7469 + if (pEntry->RXBAbitmap & (1<<TID))
7470 + {
7471 + RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
7472 + }
7473 + else
7474 + {
7475 + RTMPInitTimer(pAd, &pBAEntry->RECBATimer, GET_TIMER_FUNCTION(BARecSessionIdleTimeout), pBAEntry, TRUE);
7476 + }
7477 +
7478 +#if 0 // for debugging
7479 + RTMPSetTimer(&pBAEntry->RECBATimer, REC_BA_SESSION_IDLE_TIMEOUT);
7480 +#endif
7481 +
7482 + // Set Bitmap flag.
7483 + pEntry->RXBAbitmap |= (1<<TID);
7484 + pEntry->BARecWcidArray[TID] = Idx;
7485 +
7486 + pEntry->BADeclineBitmap &= ~(1<<TID);
7487 +
7488 + // Set BA session mask in WCID table.
7489 + RT28XX_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID);
7490 +
7491 + DBGPRINT(RT_DEBUG_TRACE,("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n",
7492 + pEntry->Aid, pEntry->RXBAbitmap, pEntry->BARecWcidArray[TID]));
7493 + }
7494 + else
7495 + {
7496 + Status = FALSE;
7497 + DBGPRINT(RT_DEBUG_TRACE,("Can't Accept ADDBA for %02x:%02x:%02x:%02x:%02x:%02x TID = %d\n",
7498 + PRINT_MAC(pEntry->Addr), TID));
7499 + }
7500 + return(Status);
7501 +}
7502 +
7503 +
7504 +BA_REC_ENTRY *BATableAllocRecEntry(
7505 + IN PRTMP_ADAPTER pAd,
7506 + OUT USHORT *Idx)
7507 +{
7508 + int i;
7509 + BA_REC_ENTRY *pBAEntry = NULL;
7510 +
7511 +
7512 + NdisAcquireSpinLock(&pAd->BATabLock);
7513 +
7514 + if (pAd->BATable.numAsRecipient >= MAX_BARECI_SESSION)
7515 + {
7516 + printk("BA Recipeint Session (%ld) > %d\n", pAd->BATable.numAsRecipient,
7517 + MAX_BARECI_SESSION);
7518 + goto done;
7519 + }
7520 +
7521 + // reserve idx 0 to identify BAWcidArray[TID] as empty
7522 + for (i=1; i < MAX_LEN_OF_BA_REC_TABLE; i++)
7523 + {
7524 + pBAEntry =&pAd->BATable.BARecEntry[i];
7525 + if ((pBAEntry->REC_BA_Status == Recipient_NONE))
7526 + {
7527 + // get one
7528 + pAd->BATable.numAsRecipient++;
7529 + pBAEntry->REC_BA_Status = Recipient_USED;
7530 + *Idx = i;
7531 + break;
7532 + }
7533 + }
7534 +
7535 +done:
7536 + NdisReleaseSpinLock(&pAd->BATabLock);
7537 + return pBAEntry;
7538 +}
7539 +
7540 +BA_ORI_ENTRY *BATableAllocOriEntry(
7541 + IN PRTMP_ADAPTER pAd,
7542 + OUT USHORT *Idx)
7543 +{
7544 + int i;
7545 + BA_ORI_ENTRY *pBAEntry = NULL;
7546 +
7547 + NdisAcquireSpinLock(&pAd->BATabLock);
7548 +
7549 + if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE))
7550 + {
7551 + goto done;
7552 + }
7553 +
7554 + // reserve idx 0 to identify BAWcidArray[TID] as empty
7555 + for (i=1; i<MAX_LEN_OF_BA_ORI_TABLE; i++)
7556 + {
7557 + pBAEntry =&pAd->BATable.BAOriEntry[i];
7558 + if ((pBAEntry->ORI_BA_Status == Originator_NONE))
7559 + {
7560 + // get one
7561 + pAd->BATable.numAsOriginator++;
7562 + pBAEntry->ORI_BA_Status = Originator_USED;
7563 + pBAEntry->pAdapter = pAd;
7564 + *Idx = i;
7565 + break;
7566 + }
7567 + }
7568 +
7569 +done:
7570 + NdisReleaseSpinLock(&pAd->BATabLock);
7571 + return pBAEntry;
7572 +}
7573 +
7574 +
7575 +VOID BATableFreeOriEntry(
7576 + IN PRTMP_ADAPTER pAd,
7577 + IN ULONG Idx)
7578 +{
7579 + BA_ORI_ENTRY *pBAEntry = NULL;
7580 + MAC_TABLE_ENTRY *pEntry;
7581 +
7582 +
7583 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE))
7584 + return;
7585 +
7586 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7587 +
7588 + if (pBAEntry->ORI_BA_Status != Originator_NONE)
7589 + {
7590 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7591 + pEntry->BAOriWcidArray[pBAEntry->TID] = 0;
7592 +
7593 +
7594 + NdisAcquireSpinLock(&pAd->BATabLock);
7595 + if (pBAEntry->ORI_BA_Status == Originator_Done)
7596 + {
7597 + pEntry->TXBAbitmap &= (~(1<<(pBAEntry->TID) ));
7598 + DBGPRINT(RT_DEBUG_TRACE, ("BATableFreeOriEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient));
7599 + // Erase Bitmap flag.
7600 + }
7601 +
7602 + ASSERT(pAd->BATable.numAsOriginator != 0);
7603 +
7604 + pAd->BATable.numAsOriginator -= 1;
7605 +
7606 + pBAEntry->ORI_BA_Status = Originator_NONE;
7607 + pBAEntry->Token = 0;
7608 + NdisReleaseSpinLock(&pAd->BATabLock);
7609 + }
7610 +}
7611 +
7612 +
7613 +VOID BATableFreeRecEntry(
7614 + IN PRTMP_ADAPTER pAd,
7615 + IN ULONG Idx)
7616 +{
7617 + BA_REC_ENTRY *pBAEntry = NULL;
7618 + MAC_TABLE_ENTRY *pEntry;
7619 +
7620 +
7621 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE))
7622 + return;
7623 +
7624 + pBAEntry =&pAd->BATable.BARecEntry[Idx];
7625 +
7626 + if (pBAEntry->REC_BA_Status != Recipient_NONE)
7627 + {
7628 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7629 + pEntry->BARecWcidArray[pBAEntry->TID] = 0;
7630 +
7631 + NdisAcquireSpinLock(&pAd->BATabLock);
7632 +
7633 + ASSERT(pAd->BATable.numAsRecipient != 0);
7634 +
7635 + pAd->BATable.numAsRecipient -= 1;
7636 +
7637 + pBAEntry->REC_BA_Status = Recipient_NONE;
7638 + NdisReleaseSpinLock(&pAd->BATabLock);
7639 + }
7640 +}
7641 +
7642 +
7643 +VOID BAOriSessionTearDown(
7644 + IN OUT PRTMP_ADAPTER pAd,
7645 + IN UCHAR Wcid,
7646 + IN UCHAR TID,
7647 + IN BOOLEAN bPassive,
7648 + IN BOOLEAN bForceSend)
7649 +{
7650 + ULONG Idx = 0;
7651 + BA_ORI_ENTRY *pBAEntry;
7652 + BOOLEAN Cancelled;
7653 +
7654 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
7655 + {
7656 + return;
7657 + }
7658 +
7659 + //
7660 + // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID).
7661 + //
7662 + Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID];
7663 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE))
7664 + {
7665 + if (bForceSend == TRUE)
7666 + {
7667 + // force send specified TID DelBA
7668 + MLME_DELBA_REQ_STRUCT DelbaReq;
7669 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7670 +
7671 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7672 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7673 +
7674 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7675 + DelbaReq.Wcid = Wcid;
7676 + DelbaReq.TID = TID;
7677 + DelbaReq.Initiator = ORIGINATOR;
7678 +#if 1
7679 + Elem->MsgLen = sizeof(DelbaReq);
7680 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7681 + MlmeDELBAAction(pAd, Elem);
7682 + kfree(Elem);
7683 +#else
7684 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7685 + RT28XX_MLME_HANDLER(pAd);
7686 +#endif
7687 + }
7688 +
7689 + return;
7690 + }
7691 +
7692 + DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID));
7693 +
7694 + pBAEntry = &pAd->BATable.BAOriEntry[Idx];
7695 + DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->ORI_BA_Status));
7696 + //
7697 + // Prepare DelBA action frame and send to the peer.
7698 + //
7699 + if ((bPassive == FALSE) && (TID == pBAEntry->TID) && (pBAEntry->ORI_BA_Status == Originator_Done))
7700 + {
7701 + MLME_DELBA_REQ_STRUCT DelbaReq;
7702 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7703 +
7704 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7705 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7706 +
7707 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7708 + DelbaReq.Wcid = Wcid;
7709 + DelbaReq.TID = pBAEntry->TID;
7710 + DelbaReq.Initiator = ORIGINATOR;
7711 +#if 1
7712 + Elem->MsgLen = sizeof(DelbaReq);
7713 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7714 + MlmeDELBAAction(pAd, Elem);
7715 + kfree(Elem);
7716 +#else
7717 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7718 + RT28XX_MLME_HANDLER(pAd);
7719 +#endif
7720 + }
7721 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7722 + BATableFreeOriEntry(pAd, Idx);
7723 +
7724 + if (bPassive)
7725 + {
7726 + //BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE);
7727 + }
7728 +}
7729 +
7730 +VOID BARecSessionTearDown(
7731 + IN OUT PRTMP_ADAPTER pAd,
7732 + IN UCHAR Wcid,
7733 + IN UCHAR TID,
7734 + IN BOOLEAN bPassive)
7735 +{
7736 + ULONG Idx = 0;
7737 + BA_REC_ENTRY *pBAEntry;
7738 +
7739 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
7740 + {
7741 + return;
7742 + }
7743 +
7744 + //
7745 + // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID).
7746 + //
7747 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
7748 + if (Idx == 0)
7749 + return;
7750 +
7751 + DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID));
7752 +
7753 +
7754 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
7755 + DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->REC_BA_Status));
7756 + //
7757 + // Prepare DelBA action frame and send to the peer.
7758 + //
7759 + if ((TID == pBAEntry->TID) && (pBAEntry->REC_BA_Status == Recipient_Accept))
7760 + {
7761 + MLME_DELBA_REQ_STRUCT DelbaReq;
7762 + BOOLEAN Cancelled;
7763 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7764 + //ULONG offset;
7765 + //UINT32 VALUE;
7766 +
7767 + RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
7768 +
7769 + //
7770 + // 1. Send DELBA Action Frame
7771 + //
7772 + if (bPassive == FALSE)
7773 + {
7774 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7775 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7776 +
7777 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7778 + DelbaReq.Wcid = Wcid;
7779 + DelbaReq.TID = TID;
7780 + DelbaReq.Initiator = RECIPIENT;
7781 +#if 1
7782 + Elem->MsgLen = sizeof(DelbaReq);
7783 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7784 + MlmeDELBAAction(pAd, Elem);
7785 + kfree(Elem);
7786 +#else
7787 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7788 + RT28XX_MLME_HANDLER(pAd);
7789 +#endif
7790 + }
7791 +
7792 +
7793 + //
7794 + // 2. Free resource of BA session
7795 + //
7796 + // flush all pending reordering mpdus
7797 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7798 +
7799 + NdisAcquireSpinLock(&pAd->BATabLock);
7800 +
7801 + // Erase Bitmap flag.
7802 + pBAEntry->LastIndSeq = RESET_RCV_SEQ;
7803 + pBAEntry->BAWinSize = 0;
7804 + // Erase Bitmap flag at software mactable
7805 + pAd->MacTab.Content[Wcid].RXBAbitmap &= (~(1<<(pBAEntry->TID)));
7806 + pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0;
7807 +
7808 + RT28XX_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID);
7809 +
7810 + NdisReleaseSpinLock(&pAd->BATabLock);
7811 +
7812 + }
7813 +
7814 + BATableFreeRecEntry(pAd, Idx);
7815 +}
7816 +
7817 +VOID BASessionTearDownALL(
7818 + IN OUT PRTMP_ADAPTER pAd,
7819 + IN UCHAR Wcid)
7820 +{
7821 + int i;
7822 +
7823 + for (i=0; i<NUM_OF_TID; i++)
7824 + {
7825 + BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE);
7826 + BARecSessionTearDown(pAd, Wcid, i, FALSE);
7827 + }
7828 +}
7829 +
7830 +
7831 +/*
7832 + ==========================================================================
7833 + Description:
7834 + Retry sending ADDBA Reqest.
7835 +
7836 + IRQL = DISPATCH_LEVEL
7837 +
7838 + Parametrs:
7839 + p8023Header: if this is already 802.3 format, p8023Header is NULL
7840 +
7841 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
7842 + FALSE , then continue indicaterx at this moment.
7843 + ==========================================================================
7844 + */
7845 +VOID BAOriSessionSetupTimeout(
7846 + IN PVOID SystemSpecific1,
7847 + IN PVOID FunctionContext,
7848 + IN PVOID SystemSpecific2,
7849 + IN PVOID SystemSpecific3)
7850 +{
7851 + BA_ORI_ENTRY *pBAEntry = (BA_ORI_ENTRY *)FunctionContext;
7852 + MAC_TABLE_ENTRY *pEntry;
7853 + PRTMP_ADAPTER pAd;
7854 +
7855 + if (pBAEntry == NULL)
7856 + return;
7857 +
7858 + pAd = pBAEntry->pAdapter;
7859 +
7860 +#ifdef CONFIG_STA_SUPPORT
7861 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
7862 + {
7863 + // Do nothing if monitor mode is on
7864 + if (MONITOR_ON(pAd))
7865 + return;
7866 + }
7867 +#endif // CONFIG_STA_SUPPORT //
7868 +
7869 +#ifdef RALINK_ATE
7870 + // Nothing to do in ATE mode.
7871 + if (ATE_ON(pAd))
7872 + return;
7873 +#endif // RALINK_ATE //
7874 +
7875 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7876 +
7877 + if ((pBAEntry->ORI_BA_Status == Originator_WaitRes) && (pBAEntry->Token < ORI_SESSION_MAX_RETRY))
7878 + {
7879 + MLME_ADDBA_REQ_STRUCT AddbaReq;
7880 +
7881 + NdisZeroMemory(&AddbaReq, sizeof(AddbaReq));
7882 + COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr);
7883 + AddbaReq.Wcid = (UCHAR)(pEntry->Aid);
7884 + AddbaReq.TID = pBAEntry->TID;
7885 + AddbaReq.BaBufSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit;
7886 + AddbaReq.TimeOutValue = 0;
7887 + AddbaReq.Token = pBAEntry->Token;
7888 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE, sizeof(MLME_ADDBA_REQ_STRUCT), (PVOID)&AddbaReq);
7889 + RT28XX_MLME_HANDLER(pAd);
7890 + DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) : Send ADD BA again\n", pBAEntry->Token));
7891 +
7892 + pBAEntry->Token++;
7893 + RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT);
7894 + }
7895 + else
7896 + {
7897 + BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]);
7898 + }
7899 +}
7900 +
7901 +/*
7902 + ==========================================================================
7903 + Description:
7904 + Retry sending ADDBA Reqest.
7905 +
7906 + IRQL = DISPATCH_LEVEL
7907 +
7908 + Parametrs:
7909 + p8023Header: if this is already 802.3 format, p8023Header is NULL
7910 +
7911 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
7912 + FALSE , then continue indicaterx at this moment.
7913 + ==========================================================================
7914 + */
7915 +VOID BARecSessionIdleTimeout(
7916 + IN PVOID SystemSpecific1,
7917 + IN PVOID FunctionContext,
7918 + IN PVOID SystemSpecific2,
7919 + IN PVOID SystemSpecific3)
7920 +{
7921 +
7922 + BA_REC_ENTRY *pBAEntry = (BA_REC_ENTRY *)FunctionContext;
7923 + PRTMP_ADAPTER pAd;
7924 + ULONG Now32;
7925 +
7926 + if (pBAEntry == NULL)
7927 + return;
7928 +
7929 + if ((pBAEntry->REC_BA_Status == Recipient_Accept))
7930 + {
7931 + NdisGetSystemUpTime(&Now32);
7932 +
7933 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer + REC_BA_SESSION_IDLE_TIMEOUT)))
7934 + {
7935 + pAd = pBAEntry->pAdapter;
7936 + // flush all pending reordering mpdus
7937 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7938 + printk("%ld: REC BA session Timeout\n", Now32);
7939 + }
7940 + }
7941 +}
7942 +
7943 +
7944 +VOID PeerAddBAReqAction(
7945 + IN PRTMP_ADAPTER pAd,
7946 + IN MLME_QUEUE_ELEM *Elem)
7947 +
7948 +{
7949 + // 7.4.4.1
7950 + //ULONG Idx;
7951 + UCHAR Status = 1;
7952 + UCHAR pAddr[6];
7953 + FRAME_ADDBA_RSP ADDframe;
7954 + PUCHAR pOutBuffer = NULL;
7955 + NDIS_STATUS NStatus;
7956 + PFRAME_ADDBA_REQ pAddreqFrame = NULL;
7957 + //UCHAR BufSize;
7958 + ULONG FrameLen;
7959 + PULONG ptemp;
7960 + PMAC_TABLE_ENTRY pMacEntry;
7961 +
7962 + DBGPRINT(RT_DEBUG_TRACE, ("%s ==> (Wcid = %d)\n", __FUNCTION__, Elem->Wcid));
7963 +
7964 + //hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen);
7965 +
7966 + //ADDBA Request from unknown peer, ignore this.
7967 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
7968 + return;
7969 +
7970 + pMacEntry = &pAd->MacTab.Content[Elem->Wcid];
7971 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerAddBAReqAction----> \n"));
7972 + ptemp = (PULONG)Elem->Msg;
7973 + //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)));
7974 +
7975 + if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr))
7976 + {
7977 +
7978 + if ((pAd->CommonCfg.bBADecline == FALSE) && IS_HT_STA(pMacEntry))
7979 + {
7980 + pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]);
7981 + printk("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid);
7982 + if (BARecSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pAddreqFrame))
7983 + Status = 0;
7984 + else
7985 + Status = 38; // more parameters have invalid values
7986 + }
7987 + else
7988 + {
7989 + Status = 37; // the request has been declined.
7990 + }
7991 + }
7992 +
7993 + if (pAd->MacTab.Content[Elem->Wcid].ValidAsCLI)
7994 + ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC);
7995 +
7996 + pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]);
7997 + // 2. Always send back ADDBA Response
7998 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
7999 + if (NStatus != NDIS_STATUS_SUCCESS)
8000 + {
8001 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - PeerBAAction() allocate memory failed \n"));
8002 + return;
8003 + }
8004 +
8005 + NdisZeroMemory(&ADDframe, sizeof(FRAME_ADDBA_RSP));
8006 + // 2-1. Prepare ADDBA Response frame.
8007 +#ifdef CONFIG_STA_SUPPORT
8008 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8009 + {
8010 + if (ADHOC_ON(pAd))
8011 + ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
8012 + else
8013 +#ifdef QOS_DLS_SUPPORT
8014 + if (pAd->MacTab.Content[Elem->Wcid].ValidAsDls)
8015 + ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
8016 + else
8017 +#endif // QOS_DLS_SUPPORT //
8018 + ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr);
8019 + }
8020 +#endif // CONFIG_STA_SUPPORT //
8021 + ADDframe.Category = CATEGORY_BA;
8022 + ADDframe.Action = ADDBA_RESP;
8023 + ADDframe.Token = pAddreqFrame->Token;
8024 + // What is the Status code?? need to check.
8025 + ADDframe.StatusCode = Status;
8026 + ADDframe.BaParm.BAPolicy = IMMED_BA;
8027 + ADDframe.BaParm.AMSDUSupported = 0;
8028 + ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID;
8029 + ADDframe.BaParm.BufSize = min(((UCHAR)pAddreqFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
8030 + if (ADDframe.BaParm.BufSize == 0)
8031 + {
8032 + ADDframe.BaParm.BufSize = 64;
8033 + }
8034 + ADDframe.TimeOutValue = 0; //pAddreqFrame->TimeOutValue;
8035 +
8036 + *(USHORT *)(&ADDframe.BaParm) = cpu2le16(*(USHORT *)(&ADDframe.BaParm));
8037 + ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode);
8038 + ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue);
8039 +
8040 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
8041 + sizeof(FRAME_ADDBA_RSP), &ADDframe,
8042 + END_OF_ARGS);
8043 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
8044 + MlmeFreeMemory(pAd, pOutBuffer);
8045 +
8046 + DBGPRINT(RT_DEBUG_TRACE, ("%s(%d): TID(%d), BufSize(%d) <== \n", __FUNCTION__, Elem->Wcid, ADDframe.BaParm.TID,
8047 + ADDframe.BaParm.BufSize));
8048 +}
8049 +
8050 +
8051 +VOID PeerAddBARspAction(
8052 + IN PRTMP_ADAPTER pAd,
8053 + IN MLME_QUEUE_ELEM *Elem)
8054 +
8055 +{
8056 + //UCHAR Idx, i;
8057 + //PUCHAR pOutBuffer = NULL;
8058 + PFRAME_ADDBA_RSP pFrame = NULL;
8059 + //PBA_ORI_ENTRY pBAEntry;
8060 +
8061 + //ADDBA Response from unknown peer, ignore this.
8062 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
8063 + return;
8064 +
8065 + DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __FUNCTION__, Elem->Wcid));
8066 +
8067 + //hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen);
8068 +
8069 + if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen))
8070 + {
8071 + pFrame = (PFRAME_ADDBA_RSP)(&Elem->Msg[0]);
8072 +
8073 + DBGPRINT(RT_DEBUG_TRACE, ("\t\t StatusCode = %d\n", pFrame->StatusCode));
8074 + switch (pFrame->StatusCode)
8075 + {
8076 + case 0:
8077 + // I want a BAsession with this peer as an originator.
8078 + BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pFrame);
8079 + break;
8080 + default:
8081 + // check status == USED ???
8082 + BAOriSessionTearDown(pAd, Elem->Wcid, pFrame->BaParm.TID, TRUE, FALSE);
8083 + break;
8084 + }
8085 + // Rcv Decline StatusCode
8086 + if ((pFrame->StatusCode == 37)
8087 +#ifdef CONFIG_STA_SUPPORT
8088 + || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd) && (pFrame->StatusCode != 0))
8089 +#endif // CONFIG_STA_SUPPORT //
8090 + )
8091 + {
8092 + pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |= 1<<pFrame->BaParm.TID;
8093 + }
8094 + }
8095 +}
8096 +
8097 +VOID PeerDelBAAction(
8098 + IN PRTMP_ADAPTER pAd,
8099 + IN MLME_QUEUE_ELEM *Elem)
8100 +
8101 +{
8102 + //UCHAR Idx;
8103 + //PUCHAR pOutBuffer = NULL;
8104 + PFRAME_DELBA_REQ pDelFrame = NULL;
8105 +
8106 + DBGPRINT(RT_DEBUG_TRACE,("%s ==>\n", __FUNCTION__));
8107 + //DELBA Request from unknown peer, ignore this.
8108 + if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen))
8109 + {
8110 + pDelFrame = (PFRAME_DELBA_REQ)(&Elem->Msg[0]);
8111 + if (pDelFrame->DelbaParm.Initiator == ORIGINATOR)
8112 + {
8113 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> ORIGINATOR\n"));
8114 + BARecSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE);
8115 + }
8116 + else
8117 + {
8118 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n", pDelFrame->ReasonCode));
8119 + //hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen);
8120 + BAOriSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE, FALSE);
8121 + }
8122 + }
8123 +}
8124 +
8125 +
8126 +BOOLEAN CntlEnqueueForRecv(
8127 + IN PRTMP_ADAPTER pAd,
8128 + IN ULONG Wcid,
8129 + IN ULONG MsgLen,
8130 + IN PFRAME_BA_REQ pMsg)
8131 +{
8132 + PFRAME_BA_REQ pFrame = pMsg;
8133 + //PRTMP_REORDERBUF pBuffer;
8134 + //PRTMP_REORDERBUF pDmaBuf;
8135 + PBA_REC_ENTRY pBAEntry;
8136 + //BOOLEAN Result;
8137 + ULONG Idx;
8138 + //UCHAR NumRxPkt;
8139 + UCHAR TID;//, i;
8140 +
8141 + TID = (UCHAR)pFrame->BARControl.TID;
8142 +
8143 + DBGPRINT(RT_DEBUG_TRACE, ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __FUNCTION__, Wcid, TID));
8144 + //hex_dump("BAR", (PCHAR) pFrame, MsgLen);
8145 + // Do nothing if the driver is starting halt state.
8146 + // This might happen when timer already been fired before cancel timer with mlmehalt
8147 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
8148 + return FALSE;
8149 +
8150 + // First check the size, it MUST not exceed the mlme queue size
8151 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
8152 + {
8153 + DBGPRINT_ERR(("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen));
8154 + return FALSE;
8155 + }
8156 + else if (MsgLen != sizeof(FRAME_BA_REQ))
8157 + {
8158 + DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen));
8159 + return FALSE;
8160 + }
8161 + else if (MsgLen != sizeof(FRAME_BA_REQ))
8162 + {
8163 + DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen));
8164 + return FALSE;
8165 + }
8166 +
8167 + if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8))
8168 + {
8169 + // if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search.
8170 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
8171 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
8172 + }
8173 + else
8174 + {
8175 + return FALSE;
8176 + }
8177 +
8178 + DBGPRINT(RT_DEBUG_TRACE, ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID, pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq ));
8179 +
8180 + if (SEQ_SMALLER(pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq, MAXSEQ))
8181 + {
8182 + //printk("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq);
8183 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, pFrame->BAStartingSeq.field.StartSeq);
8184 + pBAEntry->LastIndSeq = (pFrame->BAStartingSeq.field.StartSeq == 0) ? MAXSEQ :(pFrame->BAStartingSeq.field.StartSeq -1);
8185 + }
8186 + //ba_refresh_reordering_mpdus(pAd, pBAEntry);
8187 + return TRUE;
8188 +}
8189 +
8190 +/*
8191 +Description : Send PSMP Action frame If PSMP mode switches.
8192 +*/
8193 +VOID SendPSMPAction(
8194 + IN PRTMP_ADAPTER pAd,
8195 + IN UCHAR Wcid,
8196 + IN UCHAR Psmp)
8197 +{
8198 + PUCHAR pOutBuffer = NULL;
8199 + NDIS_STATUS NStatus;
8200 + //ULONG Idx;
8201 + FRAME_PSMP_ACTION Frame;
8202 + ULONG FrameLen;
8203 +
8204 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
8205 + if (NStatus != NDIS_STATUS_SUCCESS)
8206 + {
8207 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n"));
8208 + return;
8209 + }
8210 +#ifdef CONFIG_STA_SUPPORT
8211 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8212 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr);
8213 +#endif // CONFIG_STA_SUPPORT //
8214 +
8215 + Frame.Category = CATEGORY_HT;
8216 + Frame.Action = SMPS_ACTION;
8217 + switch (Psmp)
8218 + {
8219 + case MMPS_ENABLE:
8220 + Frame.Psmp = 0;
8221 + break;
8222 + case MMPS_DYNAMIC:
8223 + Frame.Psmp = 3;
8224 + break;
8225 + case MMPS_STATIC:
8226 + Frame.Psmp = 1;
8227 + break;
8228 + }
8229 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
8230 + sizeof(FRAME_PSMP_ACTION), &Frame,
8231 + END_OF_ARGS);
8232 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
8233 + MlmeFreeMemory(pAd, pOutBuffer);
8234 + DBGPRINT(RT_DEBUG_ERROR,("HT - SendPSMPAction( %d ) \n", Frame.Psmp));
8235 +}
8236 +
8237 +
8238 +#define RADIO_MEASUREMENT_REQUEST_ACTION 0
8239 +
8240 +typedef struct PACKED
8241 +{
8242 + UCHAR RegulatoryClass;
8243 + UCHAR ChannelNumber;
8244 + USHORT RandomInterval;
8245 + USHORT MeasurementDuration;
8246 + UCHAR MeasurementMode;
8247 + UCHAR BSSID[MAC_ADDR_LEN];
8248 + UCHAR ReportingCondition;
8249 + UCHAR Threshold;
8250 + UCHAR SSIDIE[2]; // 2 byte
8251 +} BEACON_REQUEST;
8252 +
8253 +typedef struct PACKED
8254 +{
8255 + UCHAR ID;
8256 + UCHAR Length;
8257 + UCHAR Token;
8258 + UCHAR RequestMode;
8259 + UCHAR Type;
8260 +} MEASUREMENT_REQ;
8261 +
8262 +
8263 +
8264 +
8265 +void convert_reordering_packet_to_preAMSDU_or_802_3_packet(
8266 + IN PRTMP_ADAPTER pAd,
8267 + IN RX_BLK *pRxBlk,
8268 + IN UCHAR FromWhichBSSID)
8269 +{
8270 + PNDIS_PACKET pRxPkt;
8271 + UCHAR Header802_3[LENGTH_802_3];
8272 +
8273 + // 1. get 802.3 Header
8274 + // 2. remove LLC
8275 + // a. pointer pRxBlk->pData to payload
8276 + // b. modify pRxBlk->DataSize
8277 +
8278 +#ifdef CONFIG_STA_SUPPORT
8279 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8280 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
8281 +#endif // CONFIG_STA_SUPPORT //
8282 +
8283 + ASSERT(pRxBlk->pRxPacket);
8284 + pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
8285 +
8286 + RTPKT_TO_OSPKT(pRxPkt)->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
8287 + RTPKT_TO_OSPKT(pRxPkt)->data = pRxBlk->pData;
8288 + RTPKT_TO_OSPKT(pRxPkt)->len = pRxBlk->DataSize;
8289 + RTPKT_TO_OSPKT(pRxPkt)->tail = RTPKT_TO_OSPKT(pRxPkt)->data + RTPKT_TO_OSPKT(pRxPkt)->len;
8290 +
8291 + //
8292 + // copy 802.3 header, if necessary
8293 + //
8294 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU))
8295 + {
8296 +
8297 +#ifdef CONFIG_STA_SUPPORT
8298 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8299 + {
8300 +#ifdef LINUX
8301 + NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3);
8302 +#endif
8303 +#ifdef UCOS
8304 + NdisMoveMemory(net_pkt_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3);
8305 +#endif
8306 + }
8307 +#endif // CONFIG_STA_SUPPORT //
8308 + }
8309 +}
8310 +
8311 +
8312 +#define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \
8313 + do \
8314 + { \
8315 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \
8316 + { \
8317 + Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8318 + } \
8319 + else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \
8320 + { \
8321 + Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8322 + } \
8323 + else \
8324 + { \
8325 + Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8326 + } \
8327 + } while (0);
8328 +
8329 +
8330 +
8331 +static VOID ba_enqueue_reordering_packet(
8332 + IN PRTMP_ADAPTER pAd,
8333 + IN PBA_REC_ENTRY pBAEntry,
8334 + IN RX_BLK *pRxBlk,
8335 + IN UCHAR FromWhichBSSID)
8336 +{
8337 + struct reordering_mpdu *mpdu_blk;
8338 + UINT16 Sequence = (UINT16) pRxBlk->pHeader->Sequence;
8339 +
8340 + mpdu_blk = ba_mpdu_blk_alloc(pAd);
8341 + if (mpdu_blk != NULL)
8342 + {
8343 + // Write RxD buffer address & allocated buffer length
8344 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
8345 +
8346 + mpdu_blk->Sequence = Sequence;
8347 +
8348 + mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU);
8349 +
8350 + convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd, pRxBlk, FromWhichBSSID);
8351 +
8352 + STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
8353 +
8354 + //
8355 + // it is necessary for reordering packet to record
8356 + // which BSS it come from
8357 + //
8358 + RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
8359 +
8360 + mpdu_blk->pPacket = pRxBlk->pRxPacket;
8361 +
8362 + if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk) == FALSE)
8363 + {
8364 + // had been already within reordering list
8365 + // don't indicate
8366 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_SUCCESS);
8367 + ba_mpdu_blk_free(pAd, mpdu_blk);
8368 + }
8369 +
8370 + ASSERT((0<= pBAEntry->list.qlen) && (pBAEntry->list.qlen <= pBAEntry->BAWinSize));
8371 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
8372 + }
8373 + else
8374 + {
8375 +#if 0
8376 + DBGPRINT(RT_DEBUG_ERROR, ("!!! (%d:%d) Can't allocate reordering mpdu blk\n",
8377 + blk_count, pBAEntry->list.qlen));
8378 +#else
8379 + DBGPRINT(RT_DEBUG_ERROR, ("!!! (%d) Can't allocate reordering mpdu blk\n",
8380 + pBAEntry->list.qlen));
8381 +#endif
8382 + /*
8383 + * flush all pending reordering mpdus
8384 + * and receving mpdu to upper layer
8385 + * make tcp/ip to take care reordering mechanism
8386 + */
8387 + //ba_refresh_reordering_mpdus(pAd, pBAEntry);
8388 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
8389 +
8390 + pBAEntry->LastIndSeq = Sequence;
8391 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8392 + }
8393 +}
8394 +
8395 +
8396 +/*
8397 + ==========================================================================
8398 + Description:
8399 + Indicate this packet to upper layer or put it into reordering buffer
8400 +
8401 + Parametrs:
8402 + pRxBlk : carry necessary packet info 802.11 format
8403 + FromWhichBSSID : the packet received from which BSS
8404 +
8405 + Return :
8406 + none
8407 +
8408 + Note :
8409 + the packet queued into reordering buffer need to cover to 802.3 format
8410 + or pre_AMSDU format
8411 + ==========================================================================
8412 + */
8413 +
8414 +VOID Indicate_AMPDU_Packet(
8415 + IN PRTMP_ADAPTER pAd,
8416 + IN RX_BLK *pRxBlk,
8417 + IN UCHAR FromWhichBSSID)
8418 +{
8419 + USHORT Idx;
8420 + PBA_REC_ENTRY pBAEntry = NULL;
8421 + UINT16 Sequence = pRxBlk->pHeader->Sequence;
8422 + ULONG Now32;
8423 + UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID;
8424 + UCHAR TID = pRxBlk->pRxWI->TID;
8425 +
8426 +
8427 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU) && (pRxBlk->DataSize > MAX_RX_PKT_LEN))
8428 + {
8429 +#if 0 // sample take off, no use
8430 + static int err_size;
8431 +
8432 + err_size++;
8433 + if (err_size > 20) {
8434 + printk("AMPDU DataSize = %d\n", pRxBlk->DataSize);
8435 + hex_dump("802.11 Header", (UCHAR *)pRxBlk->pHeader, 24);
8436 + hex_dump("Payload", pRxBlk->pData, 64);
8437 + err_size = 0;
8438 + }
8439 +#endif
8440 + // release packet
8441 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8442 + return;
8443 + }
8444 +
8445 +
8446 +#if 0 // test
8447 + /* Rec BA Session had been torn down */
8448 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8449 + return;
8450 +#endif
8451 +
8452 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
8453 + {
8454 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
8455 + if (Idx == 0)
8456 + {
8457 + /* Rec BA Session had been torn down */
8458 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8459 + return;
8460 + }
8461 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
8462 + }
8463 + else
8464 + {
8465 + // impossible !!!
8466 + ASSERT(0);
8467 + // release packet
8468 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8469 + return;
8470 + }
8471 +
8472 + ASSERT(pBAEntry);
8473 +
8474 + // update last rx time
8475 + NdisGetSystemUpTime(&Now32);
8476 +
8477 + pBAEntry->rcvSeq = Sequence;
8478 +
8479 +
8480 + ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32);
8481 + pBAEntry->LastIndSeqAtTimer = Now32;
8482 +
8483 + //
8484 + // Reset Last Indicate Sequence
8485 + //
8486 + if (pBAEntry->LastIndSeq == RESET_RCV_SEQ)
8487 + {
8488 + ASSERT((pBAEntry->list.qlen == 0) && (pBAEntry->list.next == NULL));
8489 +
8490 + // reset rcv sequence of BA session
8491 + pBAEntry->LastIndSeq = Sequence;
8492 + pBAEntry->LastIndSeqAtTimer = Now32;
8493 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8494 + return;
8495 + }
8496 +
8497 +
8498 + //
8499 + // I. Check if in order.
8500 + //
8501 + if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ))
8502 + {
8503 + USHORT LastIndSeq;
8504 +
8505 + pBAEntry->LastIndSeq = Sequence;
8506 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8507 + LastIndSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq);
8508 + if (LastIndSeq != RESET_RCV_SEQ)
8509 + {
8510 + pBAEntry->LastIndSeq = LastIndSeq;
8511 + }
8512 + pBAEntry->LastIndSeqAtTimer = Now32;
8513 + }
8514 + //
8515 + // II. Drop Duplicated Packet
8516 + //
8517 + else if (Sequence == pBAEntry->LastIndSeq)
8518 + {
8519 +
8520 + // drop and release packet
8521 + pBAEntry->nDropPacket++;
8522 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8523 + }
8524 + //
8525 + // III. Drop Old Received Packet
8526 + //
8527 + else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ))
8528 + {
8529 +
8530 + // drop and release packet
8531 + pBAEntry->nDropPacket++;
8532 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8533 + }
8534 + //
8535 + // IV. Receive Sequence within Window Size
8536 + //
8537 + else if (SEQ_SMALLER(Sequence, (((pBAEntry->LastIndSeq+pBAEntry->BAWinSize+1)) & MAXSEQ), MAXSEQ))
8538 + {
8539 + ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID);
8540 + }
8541 + //
8542 + // V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer
8543 + //
8544 + else
8545 + {
8546 +#if 0
8547 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
8548 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8549 +#else
8550 + LONG WinStartSeq, TmpSeq;
8551 +
8552 +
8553 + TmpSeq = Sequence - (pBAEntry->BAWinSize) -1;
8554 + if (TmpSeq < 0)
8555 + {
8556 + TmpSeq = (MAXSEQ+1) + TmpSeq;
8557 + }
8558 + WinStartSeq = (TmpSeq+1) & MAXSEQ;
8559 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq);
8560 + pBAEntry->LastIndSeq = WinStartSeq; //TmpSeq;
8561 +
8562 + pBAEntry->LastIndSeqAtTimer = Now32;
8563 +
8564 + ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID);
8565 +
8566 + TmpSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq);
8567 + if (TmpSeq != RESET_RCV_SEQ)
8568 + {
8569 + pBAEntry->LastIndSeq = TmpSeq;
8570 + }
8571 +#endif
8572 + }
8573 +}
8574 +
8575 +#endif // DOT11_N_SUPPORT //
8576 +
8577 --- /dev/null
8578 +++ b/drivers/staging/rt2870/common/cmm_data_2870.c
8579 @@ -0,0 +1,963 @@
8580 +/*
8581 + *************************************************************************
8582 + * Ralink Tech Inc.
8583 + * 5F., No.36, Taiyuan St., Jhubei City,
8584 + * Hsinchu County 302,
8585 + * Taiwan, R.O.C.
8586 + *
8587 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
8588 + *
8589 + * This program is free software; you can redistribute it and/or modify *
8590 + * it under the terms of the GNU General Public License as published by *
8591 + * the Free Software Foundation; either version 2 of the License, or *
8592 + * (at your option) any later version. *
8593 + * *
8594 + * This program is distributed in the hope that it will be useful, *
8595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
8596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
8597 + * GNU General Public License for more details. *
8598 + * *
8599 + * You should have received a copy of the GNU General Public License *
8600 + * along with this program; if not, write to the *
8601 + * Free Software Foundation, Inc., *
8602 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
8603 + * *
8604 + *************************************************************************
8605 +*/
8606 +/*
8607 + All functions in this file must be USB-depended, or you should out your function
8608 + in other files.
8609 +
8610 +*/
8611 +#include "../rt_config.h"
8612 +
8613 +
8614 +/*
8615 + We can do copy the frame into pTxContext when match following conditions.
8616 + =>
8617 + =>
8618 + =>
8619 +*/
8620 +static inline NDIS_STATUS RtmpUSBCanDoWrite(
8621 + IN RTMP_ADAPTER *pAd,
8622 + IN UCHAR QueIdx,
8623 + IN HT_TX_CONTEXT *pHTTXContext)
8624 +{
8625 + NDIS_STATUS canWrite = NDIS_STATUS_RESOURCES;
8626 +
8627 + if (((pHTTXContext->CurWritePosition) < pHTTXContext->NextBulkOutPosition) && (pHTTXContext->CurWritePosition + LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition)
8628 + {
8629 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c1!\n"));
8630 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
8631 + }
8632 + else if ((pHTTXContext->CurWritePosition == 8) && (pHTTXContext->NextBulkOutPosition < LOCAL_TXBUF_SIZE))
8633 + {
8634 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c2!\n"));
8635 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
8636 + }
8637 + else if (pHTTXContext->bCurWriting == TRUE)
8638 + {
8639 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c3!\n"));
8640 + }
8641 + else
8642 + {
8643 + canWrite = NDIS_STATUS_SUCCESS;
8644 + }
8645 +
8646 +
8647 + return canWrite;
8648 +}
8649 +
8650 +
8651 +USHORT RtmpUSB_WriteSubTxResource(
8652 + IN PRTMP_ADAPTER pAd,
8653 + IN TX_BLK *pTxBlk,
8654 + IN BOOLEAN bIsLast,
8655 + OUT USHORT *FreeNumber)
8656 +{
8657 +
8658 + // Dummy function. Should be removed in the future.
8659 + return 0;
8660 +
8661 +}
8662 +
8663 +USHORT RtmpUSB_WriteFragTxResource(
8664 + IN PRTMP_ADAPTER pAd,
8665 + IN TX_BLK *pTxBlk,
8666 + IN UCHAR fragNum,
8667 + OUT USHORT *FreeNumber)
8668 +{
8669 + HT_TX_CONTEXT *pHTTXContext;
8670 + USHORT hwHdrLen; // The hwHdrLen consist of 802.11 header length plus the header padding length.
8671 + UINT32 fillOffset;
8672 + TXINFO_STRUC *pTxInfo;
8673 + TXWI_STRUC *pTxWI;
8674 + PUCHAR pWirelessPacket = NULL;
8675 + UCHAR QueIdx;
8676 + NDIS_STATUS Status;
8677 + unsigned long IrqFlags;
8678 + UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8679 + BOOLEAN TxQLastRound = FALSE;
8680 +
8681 + //
8682 + // get Tx Ring Resource & Dma Buffer address
8683 + //
8684 + QueIdx = pTxBlk->QueIdx;
8685 + pHTTXContext = &pAd->TxContext[QueIdx];
8686 +
8687 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8688 +
8689 + pHTTXContext = &pAd->TxContext[QueIdx];
8690 + fillOffset = pHTTXContext->CurWritePosition;
8691 +
8692 + if(fragNum == 0)
8693 + {
8694 + // Check if we have enough space for this bulk-out batch.
8695 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8696 + if (Status == NDIS_STATUS_SUCCESS)
8697 + {
8698 + pHTTXContext->bCurWriting = TRUE;
8699 +
8700 + // Reserve space for 8 bytes padding.
8701 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8702 + {
8703 + pHTTXContext->ENextBulkOutPosition += 8;
8704 + pHTTXContext->CurWritePosition += 8;
8705 + fillOffset += 8;
8706 + }
8707 + pTxBlk->Priv = 0;
8708 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8709 + }
8710 + else
8711 + {
8712 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8713 +
8714 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
8715 + return(Status);
8716 + }
8717 + }
8718 + else
8719 + {
8720 + // For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer.
8721 + Status = ((pHTTXContext->bCurWriting == TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
8722 + if (Status == NDIS_STATUS_SUCCESS)
8723 + {
8724 + fillOffset += pTxBlk->Priv;
8725 + }
8726 + else
8727 + {
8728 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8729 +
8730 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
8731 + return(Status);
8732 + }
8733 + }
8734 +
8735 + NdisZeroMemory((PUCHAR)(&pTxBlk->HeaderBuf[0]), TXINFO_SIZE);
8736 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8737 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8738 +
8739 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8740 +
8741 + // copy TXWI + WLAN Header + LLC into DMA Header Buffer
8742 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8743 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8744 +
8745 + // Build our URB for USBD
8746 + DMAHdrLen = TXWI_SIZE + hwHdrLen;
8747 + USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
8748 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
8749 + USBDMApktLen += padding;
8750 +
8751 + pTxBlk->Priv += (TXINFO_SIZE + USBDMApktLen);
8752 +
8753 + // For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload
8754 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(USBDMApktLen), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8755 +
8756 + if (fragNum == pTxBlk->TotalFragNum)
8757 + {
8758 + pTxInfo->USBDMATxburst = 0;
8759 + if ((pHTTXContext->CurWritePosition + pTxBlk->Priv + 3906)> MAX_TXBULK_LIMIT)
8760 + {
8761 + pTxInfo->SwUseLastRound = 1;
8762 + TxQLastRound = TRUE;
8763 + }
8764 + }
8765 + else
8766 + {
8767 + pTxInfo->USBDMATxburst = 1;
8768 + }
8769 +
8770 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8771 +#ifdef RT_BIG_ENDIAN
8772 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket + TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
8773 +#endif // RT_BIG_ENDIAN //
8774 + pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8775 + pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8776 +
8777 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8778 +
8779 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
8780 +
8781 + // Zero the last padding.
8782 + pWirelessPacket += pTxBlk->SrcBufLen;
8783 + NdisZeroMemory(pWirelessPacket, padding + 8);
8784 +
8785 + if (fragNum == pTxBlk->TotalFragNum)
8786 + {
8787 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8788 +
8789 + // Update the pHTTXContext->CurWritePosition. 3906 used to prevent the NextBulkOut is a A-RALINK/A-MSDU Frame.
8790 + pHTTXContext->CurWritePosition += pTxBlk->Priv;
8791 + if (TxQLastRound == TRUE)
8792 + pHTTXContext->CurWritePosition = 8;
8793 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8794 +
8795 +
8796 + // Finally, set bCurWriting as FALSE
8797 + pHTTXContext->bCurWriting = FALSE;
8798 +
8799 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8800 +
8801 + // succeed and release the skb buffer
8802 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
8803 + }
8804 +
8805 +
8806 + return(Status);
8807 +
8808 +}
8809 +
8810 +
8811 +USHORT RtmpUSB_WriteSingleTxResource(
8812 + IN PRTMP_ADAPTER pAd,
8813 + IN TX_BLK *pTxBlk,
8814 + IN BOOLEAN bIsLast,
8815 + OUT USHORT *FreeNumber)
8816 +{
8817 + HT_TX_CONTEXT *pHTTXContext;
8818 + USHORT hwHdrLen;
8819 + UINT32 fillOffset;
8820 + TXINFO_STRUC *pTxInfo;
8821 + TXWI_STRUC *pTxWI;
8822 + PUCHAR pWirelessPacket;
8823 + UCHAR QueIdx;
8824 + unsigned long IrqFlags;
8825 + NDIS_STATUS Status;
8826 + UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8827 + BOOLEAN bTxQLastRound = FALSE;
8828 +
8829 + // For USB, didn't need PCI_MAP_SINGLE()
8830 + //SrcBufPA = PCI_MAP_SINGLE(pAd, (char *) pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, PCI_DMA_TODEVICE);
8831 +
8832 +
8833 + //
8834 + // get Tx Ring Resource & Dma Buffer address
8835 + //
8836 + QueIdx = pTxBlk->QueIdx;
8837 +
8838 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8839 + pHTTXContext = &pAd->TxContext[QueIdx];
8840 + fillOffset = pHTTXContext->CurWritePosition;
8841 +
8842 +
8843 +
8844 + // Check ring full.
8845 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8846 + if(Status == NDIS_STATUS_SUCCESS)
8847 + {
8848 + pHTTXContext->bCurWriting = TRUE;
8849 +
8850 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8851 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8852 +
8853 + // Reserve space for 8 bytes padding.
8854 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8855 + {
8856 + pHTTXContext->ENextBulkOutPosition += 8;
8857 + pHTTXContext->CurWritePosition += 8;
8858 + fillOffset += 8;
8859 + }
8860 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8861 +
8862 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8863 +
8864 + // copy TXWI + WLAN Header + LLC into DMA Header Buffer
8865 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8866 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8867 +
8868 + // Build our URB for USBD
8869 + DMAHdrLen = TXWI_SIZE + hwHdrLen;
8870 + USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
8871 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
8872 + USBDMApktLen += padding;
8873 +
8874 + pTxBlk->Priv = (TXINFO_SIZE + USBDMApktLen);
8875 +
8876 + // For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload
8877 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(USBDMApktLen), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8878 +
8879 + if ((pHTTXContext->CurWritePosition + 3906 + pTxBlk->Priv) > MAX_TXBULK_LIMIT)
8880 + {
8881 + pTxInfo->SwUseLastRound = 1;
8882 + bTxQLastRound = TRUE;
8883 + }
8884 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8885 +#ifdef RT_BIG_ENDIAN
8886 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket + TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
8887 +#endif // RT_BIG_ENDIAN //
8888 + pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8889 +
8890 + // We unlock it here to prevent the first 8 bytes maybe over-writed issue.
8891 + // 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxcontext.
8892 + // 2. An interrupt break our routine and handle bulk-out complete.
8893 + // 3. In the bulk-out compllete, it need to do another bulk-out,
8894 + // if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition,
8895 + // but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE.
8896 + // 4. Interrupt complete.
8897 + // 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext.
8898 + // 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition.
8899 + // and the packet will wrong.
8900 + pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8901 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8902 +
8903 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
8904 + pWirelessPacket += pTxBlk->SrcBufLen;
8905 + NdisZeroMemory(pWirelessPacket, padding + 8);
8906 +
8907 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8908 +
8909 + pHTTXContext->CurWritePosition += pTxBlk->Priv;
8910 + if (bTxQLastRound)
8911 + pHTTXContext->CurWritePosition = 8;
8912 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8913 +
8914 + pHTTXContext->bCurWriting = FALSE;
8915 + }
8916 +
8917 +
8918 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8919 +
8920 +
8921 + // succeed and release the skb buffer
8922 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
8923 +
8924 + return(Status);
8925 +
8926 +}
8927 +
8928 +
8929 +USHORT RtmpUSB_WriteMultiTxResource(
8930 + IN PRTMP_ADAPTER pAd,
8931 + IN TX_BLK *pTxBlk,
8932 + IN UCHAR frameNum,
8933 + OUT USHORT *FreeNumber)
8934 +{
8935 + HT_TX_CONTEXT *pHTTXContext;
8936 + USHORT hwHdrLen; // The hwHdrLen consist of 802.11 header length plus the header padding length.
8937 + UINT32 fillOffset;
8938 + TXINFO_STRUC *pTxInfo;
8939 + TXWI_STRUC *pTxWI;
8940 + PUCHAR pWirelessPacket = NULL;
8941 + UCHAR QueIdx;
8942 + NDIS_STATUS Status;
8943 + unsigned long IrqFlags;
8944 + //UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8945 +
8946 + //
8947 + // get Tx Ring Resource & Dma Buffer address
8948 + //
8949 + QueIdx = pTxBlk->QueIdx;
8950 + pHTTXContext = &pAd->TxContext[QueIdx];
8951 +
8952 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8953 +
8954 + if(frameNum == 0)
8955 + {
8956 + // Check if we have enough space for this bulk-out batch.
8957 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8958 + if (Status == NDIS_STATUS_SUCCESS)
8959 + {
8960 + pHTTXContext->bCurWriting = TRUE;
8961 +
8962 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8963 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8964 +
8965 +
8966 + // Reserve space for 8 bytes padding.
8967 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8968 + {
8969 +
8970 + pHTTXContext->CurWritePosition += 8;
8971 + pHTTXContext->ENextBulkOutPosition += 8;
8972 + }
8973 + fillOffset = pHTTXContext->CurWritePosition;
8974 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8975 +
8976 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8977 +
8978 + //
8979 + // Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer
8980 + //
8981 + if (pTxBlk->TxFrameType == TX_AMSDU_FRAME)
8982 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD;
8983 + hwHdrLen = pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD + pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD;
8984 + else if (pTxBlk->TxFrameType == TX_RALINK_FRAME)
8985 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD;
8986 + hwHdrLen = pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD + pTxBlk->HdrPadLen + LENGTH_ARALINK_HEADER_FIELD;
8987 + else
8988 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8989 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8990 +
8991 + // Update the pTxBlk->Priv.
8992 + pTxBlk->Priv = TXINFO_SIZE + TXWI_SIZE + hwHdrLen;
8993 +
8994 + // pTxInfo->USBDMApktLen now just a temp value and will to correct latter.
8995 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(pTxBlk->Priv), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8996 +
8997 + // Copy it.
8998 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, pTxBlk->Priv);
8999 +#ifdef RT_BIG_ENDIAN
9000 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket+ TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
9001 +#endif // RT_BIG_ENDIAN //
9002 + pHTTXContext->CurWriteRealPos += pTxBlk->Priv;
9003 + pWirelessPacket += pTxBlk->Priv;
9004 + }
9005 + }
9006 + else
9007 + { // For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer.
9008 +
9009 + Status = ((pHTTXContext->bCurWriting == TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
9010 + if (Status == NDIS_STATUS_SUCCESS)
9011 + {
9012 + fillOffset = (pHTTXContext->CurWritePosition + pTxBlk->Priv);
9013 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
9014 +
9015 + //hwHdrLen = pTxBlk->MpduHeaderLen;
9016 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, pTxBlk->MpduHeaderLen);
9017 + pWirelessPacket += (pTxBlk->MpduHeaderLen);
9018 + pTxBlk->Priv += pTxBlk->MpduHeaderLen;
9019 + }
9020 + else
9021 + { // It should not happened now unless we are going to shutdown.
9022 + DBGPRINT(RT_DEBUG_ERROR, ("WriteMultiTxResource():bCurWriting is FALSE when handle sub-sequent frames.\n"));
9023 + Status = NDIS_STATUS_FAILURE;
9024 + }
9025 + }
9026 +
9027 +
9028 + // We unlock it here to prevent the first 8 bytes maybe over-write issue.
9029 + // 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxContext.
9030 + // 2. An interrupt break our routine and handle bulk-out complete.
9031 + // 3. In the bulk-out compllete, it need to do another bulk-out,
9032 + // if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition,
9033 + // but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE.
9034 + // 4. Interrupt complete.
9035 + // 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext.
9036 + // 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition.
9037 + // and the packet will wrong.
9038 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
9039 +
9040 + if (Status != NDIS_STATUS_SUCCESS)
9041 + {
9042 + DBGPRINT(RT_DEBUG_ERROR,("WriteMultiTxResource: CWPos = %ld, NBOutPos = %ld.\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition));
9043 + goto done;
9044 + }
9045 +
9046 + // Copy the frame content into DMA buffer and update the pTxBlk->Priv
9047 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
9048 + pWirelessPacket += pTxBlk->SrcBufLen;
9049 + pTxBlk->Priv += pTxBlk->SrcBufLen;
9050 +
9051 +done:
9052 + // Release the skb buffer here
9053 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
9054 +
9055 + return(Status);
9056 +
9057 +}
9058 +
9059 +
9060 +VOID RtmpUSB_FinalWriteTxResource(
9061 + IN PRTMP_ADAPTER pAd,
9062 + IN TX_BLK *pTxBlk,
9063 + IN USHORT totalMPDUSize,
9064 + IN USHORT TxIdx)
9065 +{
9066 + UCHAR QueIdx;
9067 + HT_TX_CONTEXT *pHTTXContext;
9068 + UINT32 fillOffset;
9069 + TXINFO_STRUC *pTxInfo;
9070 + TXWI_STRUC *pTxWI;
9071 + UINT32 USBDMApktLen, padding;
9072 + unsigned long IrqFlags;
9073 + PUCHAR pWirelessPacket;
9074 +
9075 + QueIdx = pTxBlk->QueIdx;
9076 + pHTTXContext = &pAd->TxContext[QueIdx];
9077 +
9078 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
9079 +
9080 + if (pHTTXContext->bCurWriting == TRUE)
9081 + {
9082 + fillOffset = pHTTXContext->CurWritePosition;
9083 + if (((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition) || ((pHTTXContext->ENextBulkOutPosition-8) == pHTTXContext->CurWritePosition))
9084 + && (pHTTXContext->bCopySavePad == TRUE))
9085 + pWirelessPacket = (PUCHAR)(&pHTTXContext->SavedPad[0]);
9086 + else
9087 + pWirelessPacket = (PUCHAR)(&pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset]);
9088 +
9089 + //
9090 + // Update TxInfo->USBDMApktLen ,
9091 + // the length = TXWI_SIZE + 802.11_hdr + 802.11_hdr_pad + payload_of_all_batch_frames + Bulk-Out-padding
9092 + //
9093 + pTxInfo = (PTXINFO_STRUC)(pWirelessPacket);
9094 +
9095 + // Calculate the bulk-out padding
9096 + USBDMApktLen = pTxBlk->Priv - TXINFO_SIZE;
9097 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
9098 + USBDMApktLen += padding;
9099 +
9100 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
9101 +
9102 + //
9103 + // Update TXWI->MPDUtotalByteCount ,
9104 + // the length = 802.11 header + payload_of_all_batch_frames
9105 + pTxWI= (PTXWI_STRUC)(pWirelessPacket + TXINFO_SIZE);
9106 + pTxWI->MPDUtotalByteCount = totalMPDUSize;
9107 +
9108 + //
9109 + // Update the pHTTXContext->CurWritePosition
9110 + //
9111 + pHTTXContext->CurWritePosition += (TXINFO_SIZE + USBDMApktLen);
9112 + if ((pHTTXContext->CurWritePosition + 3906)> MAX_TXBULK_LIMIT)
9113 + { // Add 3906 for prevent the NextBulkOut packet size is a A-RALINK/A-MSDU Frame.
9114 + pHTTXContext->CurWritePosition = 8;
9115 + pTxInfo->SwUseLastRound = 1;
9116 + }
9117 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
9118 +
9119 +
9120 + //
9121 + // Zero the last padding.
9122 + //
9123 + pWirelessPacket = (&pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset + pTxBlk->Priv]);
9124 + NdisZeroMemory(pWirelessPacket, padding + 8);
9125 +
9126 + // Finally, set bCurWriting as FALSE
9127 + pHTTXContext->bCurWriting = FALSE;
9128 +
9129 + }
9130 + else
9131 + { // It should not happened now unless we are going to shutdown.
9132 + DBGPRINT(RT_DEBUG_ERROR, ("FinalWriteTxResource():bCurWriting is FALSE when handle last frames.\n"));
9133 + }
9134 +
9135 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
9136 +
9137 +}
9138 +
9139 +
9140 +VOID RtmpUSBDataLastTxIdx(
9141 + IN PRTMP_ADAPTER pAd,
9142 + IN UCHAR QueIdx,
9143 + IN USHORT TxIdx)
9144 +{
9145 + // DO nothing for USB.
9146 +}
9147 +
9148 +
9149 +/*
9150 + When can do bulk-out:
9151 + 1. TxSwFreeIdx < TX_RING_SIZE;
9152 + It means has at least one Ring entity is ready for bulk-out, kick it out.
9153 + 2. If TxSwFreeIdx == TX_RING_SIZE
9154 + Check if the CurWriting flag is FALSE, if it's FALSE, we can do kick out.
9155 +
9156 +*/
9157 +VOID RtmpUSBDataKickOut(
9158 + IN PRTMP_ADAPTER pAd,
9159 + IN TX_BLK *pTxBlk,
9160 + IN UCHAR QueIdx)
9161 +{
9162 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
9163 + RTUSBKickBulkOut(pAd);
9164 +
9165 +}
9166 +
9167 +
9168 +/*
9169 + Must be run in Interrupt context
9170 + This function handle RT2870 specific TxDesc and cpu index update and kick the packet out.
9171 + */
9172 +int RtmpUSBMgmtKickOut(
9173 + IN RTMP_ADAPTER *pAd,
9174 + IN UCHAR QueIdx,
9175 + IN PNDIS_PACKET pPacket,
9176 + IN PUCHAR pSrcBufVA,
9177 + IN UINT SrcBufLen)
9178 +{
9179 + PTXINFO_STRUC pTxInfo;
9180 + ULONG BulkOutSize;
9181 + UCHAR padLen;
9182 + PUCHAR pDest;
9183 + ULONG SwIdx = pAd->MgmtRing.TxCpuIdx;
9184 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[SwIdx].AllocVa;
9185 + unsigned long IrqFlags;
9186 +
9187 +
9188 + pTxInfo = (PTXINFO_STRUC)(pSrcBufVA);
9189 +
9190 + // Build our URB for USBD
9191 + BulkOutSize = SrcBufLen;
9192 + BulkOutSize = (BulkOutSize + 3) & (~3);
9193 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(BulkOutSize - TXINFO_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
9194 +
9195 + BulkOutSize += 4; // Always add 4 extra bytes at every packet.
9196 +
9197 + // If BulkOutSize is multiple of BulkOutMaxPacketSize, add extra 4 bytes again.
9198 + if ((BulkOutSize % pAd->BulkOutMaxPacketSize) == 0)
9199 + BulkOutSize += 4;
9200 +
9201 + padLen = BulkOutSize - SrcBufLen;
9202 + ASSERT((padLen <= RTMP_PKT_TAIL_PADDING));
9203 +
9204 + // Now memzero all extra padding bytes.
9205 + pDest = (PUCHAR)(pSrcBufVA + SrcBufLen);
9206 + skb_put(GET_OS_PKT_TYPE(pPacket), padLen);
9207 + NdisZeroMemory(pDest, padLen);
9208 +
9209 + RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
9210 +
9211 + pAd->MgmtRing.Cell[pAd->MgmtRing.TxCpuIdx].pNdisPacket = pPacket;
9212 + pMLMEContext->TransferBuffer = (PTX_BUFFER)(GET_OS_PKT_DATAPTR(pPacket));
9213 +
9214 + // Length in TxInfo should be 8 less than bulkout size.
9215 + pMLMEContext->BulkOutSize = BulkOutSize;
9216 + pMLMEContext->InUse = TRUE;
9217 + pMLMEContext->bWaitingBulkOut = TRUE;
9218 +
9219 +
9220 + //for debug
9221 + //hex_dump("RtmpUSBMgmtKickOut", &pMLMEContext->TransferBuffer->field.WirelessPacket[0], (pMLMEContext->BulkOutSize > 16 ? 16 : pMLMEContext->BulkOutSize));
9222 +
9223 + //pAd->RalinkCounters.KickTxCount++;
9224 + //pAd->RalinkCounters.OneSecTxDoneCount++;
9225 +
9226 + //if (pAd->MgmtRing.TxSwFreeIdx == MGMT_RING_SIZE)
9227 + // needKickOut = TRUE;
9228 +
9229 + // Decrease the TxSwFreeIdx and Increase the TX_CTX_IDX
9230 + pAd->MgmtRing.TxSwFreeIdx--;
9231 + INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE);
9232 +
9233 + RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
9234 +
9235 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
9236 + //if (needKickOut)
9237 + RTUSBKickBulkOut(pAd);
9238 +
9239 + return 0;
9240 +}
9241 +
9242 +
9243 +VOID RtmpUSBNullFrameKickOut(
9244 + IN RTMP_ADAPTER *pAd,
9245 + IN UCHAR QueIdx,
9246 + IN UCHAR *pNullFrame,
9247 + IN UINT32 frameLen)
9248 +{
9249 + if (pAd->NullContext.InUse == FALSE)
9250 + {
9251 + PTX_CONTEXT pNullContext;
9252 + PTXINFO_STRUC pTxInfo;
9253 + PTXWI_STRUC pTxWI;
9254 + PUCHAR pWirelessPkt;
9255 +
9256 + pNullContext = &(pAd->NullContext);
9257 +
9258 + // Set the in use bit
9259 + pNullContext->InUse = TRUE;
9260 + pWirelessPkt = (PUCHAR)&pNullContext->TransferBuffer->field.WirelessPacket[0];
9261 +
9262 + RTMPZeroMemory(&pWirelessPkt[0], 100);
9263 + pTxInfo = (PTXINFO_STRUC)&pWirelessPkt[0];
9264 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
9265 + pTxInfo->QSEL = FIFO_EDCA;
9266 + pTxWI = (PTXWI_STRUC)&pWirelessPkt[TXINFO_SIZE];
9267 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
9268 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
9269 +#ifdef RT_BIG_ENDIAN
9270 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
9271 +#endif // RT_BIG_ENDIAN //
9272 +
9273 + RTMPMoveMemory(&pWirelessPkt[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
9274 +#ifdef RT_BIG_ENDIAN
9275 + RTMPFrameEndianChange(pAd, (PUCHAR)&pWirelessPkt[TXINFO_SIZE + TXWI_SIZE], DIR_WRITE, FALSE);
9276 +#endif // RT_BIG_ENDIAN //
9277 + pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
9278 +
9279 + // Fill out frame length information for global Bulk out arbitor
9280 + //pNullContext->BulkOutSize = TransferBufferLength;
9281 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - send NULL Frame @%d Mbps...\n", RateIdToMbps[pAd->CommonCfg.TxRate]));
9282 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
9283 +
9284 + // Kick bulk out
9285 + RTUSBKickBulkOut(pAd);
9286 + }
9287 +
9288 +}
9289 +
9290 +#ifdef CONFIG_STA_SUPPORT
9291 +/*
9292 + ========================================================================
9293 +
9294 + Routine Description:
9295 + Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound
9296 +
9297 + Arguments:
9298 + pRxD Pointer to the Rx descriptor
9299 +
9300 + Return Value:
9301 + NDIS_STATUS_SUCCESS No err
9302 + NDIS_STATUS_FAILURE Error
9303 +
9304 + Note:
9305 +
9306 + ========================================================================
9307 +*/
9308 +NDIS_STATUS RTMPCheckRxError(
9309 + IN PRTMP_ADAPTER pAd,
9310 + IN PHEADER_802_11 pHeader,
9311 + IN PRXWI_STRUC pRxWI,
9312 + IN PRT28XX_RXD_STRUC pRxINFO)
9313 +{
9314 + PCIPHER_KEY pWpaKey;
9315 + INT dBm;
9316 +
9317 + if (pAd->bPromiscuous == TRUE)
9318 + return(NDIS_STATUS_SUCCESS);
9319 + if(pRxINFO == NULL)
9320 + return(NDIS_STATUS_FAILURE);
9321 +
9322 + // Phy errors & CRC errors
9323 + if (pRxINFO->Crc)
9324 + {
9325 + // Check RSSI for Noise Hist statistic collection.
9326 + dBm = (INT) (pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta;
9327 + if (dBm <= -87)
9328 + pAd->StaCfg.RPIDensity[0] += 1;
9329 + else if (dBm <= -82)
9330 + pAd->StaCfg.RPIDensity[1] += 1;
9331 + else if (dBm <= -77)
9332 + pAd->StaCfg.RPIDensity[2] += 1;
9333 + else if (dBm <= -72)
9334 + pAd->StaCfg.RPIDensity[3] += 1;
9335 + else if (dBm <= -67)
9336 + pAd->StaCfg.RPIDensity[4] += 1;
9337 + else if (dBm <= -62)
9338 + pAd->StaCfg.RPIDensity[5] += 1;
9339 + else if (dBm <= -57)
9340 + pAd->StaCfg.RPIDensity[6] += 1;
9341 + else if (dBm > -57)
9342 + pAd->StaCfg.RPIDensity[7] += 1;
9343 +
9344 + return(NDIS_STATUS_FAILURE);
9345 + }
9346 +
9347 + // Add Rx size to channel load counter, we should ignore error counts
9348 + pAd->StaCfg.CLBusyBytes += (pRxWI->MPDUtotalByteCount+ 14);
9349 +
9350 + // Drop ToDs promiscous frame, it is opened due to CCX 2 channel load statistics
9351 + if (pHeader->FC.ToDs)
9352 + {
9353 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Err;FC.ToDs\n"));
9354 + return NDIS_STATUS_FAILURE;
9355 + }
9356 +
9357 + // Paul 04-03 for OFDM Rx length issue
9358 + if (pRxWI->MPDUtotalByteCount > MAX_AGGREGATION_SIZE)
9359 + {
9360 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("received packet too long\n"));
9361 + return NDIS_STATUS_FAILURE;
9362 + }
9363 +
9364 + // Drop not U2M frames, cant's drop here because we will drop beacon in this case
9365 + // I am kind of doubting the U2M bit operation
9366 + // if (pRxD->U2M == 0)
9367 + // return(NDIS_STATUS_FAILURE);
9368 +
9369 + // drop decyption fail frame
9370 + if (pRxINFO->Decrypted && pRxINFO->CipherErr)
9371 + {
9372 +
9373 + //
9374 + // MIC Error
9375 + //
9376 + if ((pRxINFO->CipherErr == 2) && pRxINFO->MyBss)
9377 + {
9378 + pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex];
9379 + RTMPReportMicError(pAd, pWpaKey);
9380 + DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error\n"));
9381 + }
9382 +
9383 + if (pRxINFO->Decrypted &&
9384 + (pAd->SharedKey[BSS0][pRxWI->KeyIndex].CipherAlg == CIPHER_AES) &&
9385 + (pHeader->Sequence == pAd->FragFrame.Sequence))
9386 + {
9387 + //
9388 + // Acceptable since the First FragFrame no CipherErr problem.
9389 + //
9390 + return(NDIS_STATUS_SUCCESS);
9391 + }
9392 +
9393 + return(NDIS_STATUS_FAILURE);
9394 + }
9395 +
9396 + return(NDIS_STATUS_SUCCESS);
9397 +}
9398 +
9399 +VOID RT28xxUsbStaAsicForceWakeup(
9400 + IN PRTMP_ADAPTER pAd,
9401 + IN BOOLEAN bFromTx)
9402 +{
9403 + AUTO_WAKEUP_STRUC AutoWakeupCfg;
9404 +
9405 + AutoWakeupCfg.word = 0;
9406 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9407 +
9408 + AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x00);
9409 +
9410 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
9411 +}
9412 +
9413 +VOID RT28xxUsbStaAsicSleepThenAutoWakeup(
9414 + IN PRTMP_ADAPTER pAd,
9415 + IN USHORT TbttNumToNextWakeUp)
9416 +{
9417 + AUTO_WAKEUP_STRUC AutoWakeupCfg;
9418 +
9419 + // we have decided to SLEEP, so at least do it for a BEACON period.
9420 + if (TbttNumToNextWakeUp == 0)
9421 + TbttNumToNextWakeUp = 1;
9422 +
9423 + AutoWakeupCfg.word = 0;
9424 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9425 +
9426 + AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1;
9427 + AutoWakeupCfg.field.EnableAutoWakeup = 1;
9428 + AutoWakeupCfg.field.AutoLeadTime = 5;
9429 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9430 +
9431 + AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); // send POWER-SAVE command to MCU. Timeout 40us.
9432 +
9433 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE);
9434 +
9435 +}
9436 +#endif // CONFIG_STA_SUPPORT //
9437 +
9438 +VOID RT28xxUsbMlmeRadioOn(
9439 + IN PRTMP_ADAPTER pAd)
9440 +{
9441 + DBGPRINT(RT_DEBUG_TRACE,("RT28xxUsbMlmeRadioOn()\n"));
9442 +
9443 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
9444 + return;
9445 +
9446 +#ifdef CONFIG_STA_SUPPORT
9447 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9448 + {
9449 + AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x00);
9450 + RTMPusecDelay(10000);
9451 + }
9452 +#endif // CONFIG_STA_SUPPORT //
9453 + NICResetFromError(pAd);
9454 +
9455 + // Enable Tx/Rx
9456 + RTMPEnableRxTx(pAd);
9457 +
9458 + // Clear Radio off flag
9459 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
9460 +
9461 +#ifdef CONFIG_STA_SUPPORT
9462 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9463 + RTUSBBulkReceive(pAd);
9464 +#endif // CONFIG_STA_SUPPORT //
9465 +
9466 + // Set LED
9467 + RTMPSetLED(pAd, LED_RADIO_ON);
9468 +}
9469 +
9470 +VOID RT28xxUsbMlmeRadioOFF(
9471 + IN PRTMP_ADAPTER pAd)
9472 +{
9473 + WPDMA_GLO_CFG_STRUC GloCfg;
9474 + UINT32 Value, i;
9475 +
9476 + DBGPRINT(RT_DEBUG_TRACE,("RT28xxUsbMlmeRadioOFF()\n"));
9477 +
9478 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
9479 + return;
9480 +
9481 + // Set LED
9482 + RTMPSetLED(pAd, LED_RADIO_OFF);
9483 + // Set Radio off flag
9484 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
9485 +
9486 +#ifdef CONFIG_STA_SUPPORT
9487 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9488 + {
9489 + // Link down first if any association exists
9490 + if (INFRA_ON(pAd) || ADHOC_ON(pAd))
9491 + LinkDown(pAd, FALSE);
9492 + RTMPusecDelay(10000);
9493 +
9494 + //==========================================
9495 + // Clean up old bss table
9496 + BssTableInit(&pAd->ScanTab);
9497 + }
9498 +#endif // CONFIG_STA_SUPPORT //
9499 +
9500 +
9501 + // Disable MAC Tx/Rx
9502 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
9503 + Value &= (0xfffffff3);
9504 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
9505 +
9506 + // MAC_SYS_CTRL => value = 0x0 => 40mA
9507 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0);
9508 +
9509 + // PWR_PIN_CFG => value = 0x0 => 40mA
9510 + RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0);
9511 +
9512 + // TX_PIN_CFG => value = 0x0 => 20mA
9513 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, 0);
9514 +
9515 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
9516 + {
9517 + // Must using 40MHz.
9518 + AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel);
9519 + }
9520 + else
9521 + {
9522 + // Must using 20MHz.
9523 + AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel);
9524 + }
9525 +
9526 + // Waiting for DMA idle
9527 + i = 0;
9528 + do
9529 + {
9530 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
9531 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
9532 + break;
9533 +
9534 + RTMPusecDelay(1000);
9535 + }while (i++ < 100);
9536 +
9537 +#ifdef CONFIG_STA_SUPPORT
9538 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9539 + AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02);
9540 +#endif // CONFIG_STA_SUPPORT //
9541 +}
9542 +
9543 --- /dev/null
9544 +++ b/drivers/staging/rt2870/common/cmm_data.c
9545 @@ -0,0 +1,2734 @@
9546 +/*
9547 + *************************************************************************
9548 + * Ralink Tech Inc.
9549 + * 5F., No.36, Taiyuan St., Jhubei City,
9550 + * Hsinchu County 302,
9551 + * Taiwan, R.O.C.
9552 + *
9553 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
9554 + *
9555 + * This program is free software; you can redistribute it and/or modify *
9556 + * it under the terms of the GNU General Public License as published by *
9557 + * the Free Software Foundation; either version 2 of the License, or *
9558 + * (at your option) any later version. *
9559 + * *
9560 + * This program is distributed in the hope that it will be useful, *
9561 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9562 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
9563 + * GNU General Public License for more details. *
9564 + * *
9565 + * You should have received a copy of the GNU General Public License *
9566 + * along with this program; if not, write to the *
9567 + * Free Software Foundation, Inc., *
9568 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
9569 + * *
9570 + *************************************************************************
9571 +*/
9572 +
9573 +#include "../rt_config.h"
9574 +
9575 +#define MAX_TX_IN_TBTT (16)
9576 +
9577 +
9578 +UCHAR SNAP_802_1H[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
9579 +UCHAR SNAP_BRIDGE_TUNNEL[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
9580 +// Add Cisco Aironet SNAP heade for CCX2 support
9581 +UCHAR SNAP_AIRONET[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00};
9582 +UCHAR CKIP_LLC_SNAP[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02};
9583 +UCHAR EAPOL_LLC_SNAP[]= {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e};
9584 +UCHAR EAPOL[] = {0x88, 0x8e};
9585 +UCHAR TPID[] = {0x81, 0x00}; /* VLAN related */
9586 +
9587 +UCHAR IPX[] = {0x81, 0x37};
9588 +UCHAR APPLE_TALK[] = {0x80, 0xf3};
9589 +UCHAR RateIdToPlcpSignal[12] = {
9590 + 0, /* RATE_1 */ 1, /* RATE_2 */ 2, /* RATE_5_5 */ 3, /* RATE_11 */ // see BBP spec
9591 + 11, /* RATE_6 */ 15, /* RATE_9 */ 10, /* RATE_12 */ 14, /* RATE_18 */ // see IEEE802.11a-1999 p.14
9592 + 9, /* RATE_24 */ 13, /* RATE_36 */ 8, /* RATE_48 */ 12 /* RATE_54 */ }; // see IEEE802.11a-1999 p.14
9593 +
9594 +UCHAR OfdmSignalToRateId[16] = {
9595 + RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 0, 1, 2, 3 respectively
9596 + RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 4, 5, 6, 7 respectively
9597 + RATE_48, RATE_24, RATE_12, RATE_6, // OFDM PLCP Signal = 8, 9, 10, 11 respectively
9598 + RATE_54, RATE_36, RATE_18, RATE_9, // OFDM PLCP Signal = 12, 13, 14, 15 respectively
9599 +};
9600 +
9601 +UCHAR OfdmRateToRxwiMCS[12] = {
9602 + 0, 0, 0, 0,
9603 + 0, 1, 2, 3, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3
9604 + 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7
9605 +};
9606 +UCHAR RxwiMCSToOfdmRate[12] = {
9607 + RATE_6, RATE_9, RATE_12, RATE_18,
9608 + RATE_24, RATE_36, RATE_48, RATE_54, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3
9609 + 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7
9610 +};
9611 +
9612 +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"};
9613 +
9614 +UCHAR default_cwmin[]={CW_MIN_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1, CW_MIN_IN_BITS-2};
9615 +//UCHAR default_cwmax[]={CW_MAX_IN_BITS, CW_MAX_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1};
9616 +UCHAR default_sta_aifsn[]={3,7,2,2};
9617 +
9618 +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};
9619 +
9620 +
9621 +/*
9622 + ========================================================================
9623 +
9624 + Routine Description:
9625 + API for MLME to transmit management frame to AP (BSS Mode)
9626 + or station (IBSS Mode)
9627 +
9628 + Arguments:
9629 + pAd Pointer to our adapter
9630 + pData Pointer to the outgoing 802.11 frame
9631 + Length Size of outgoing management frame
9632 +
9633 + Return Value:
9634 + NDIS_STATUS_FAILURE
9635 + NDIS_STATUS_PENDING
9636 + NDIS_STATUS_SUCCESS
9637 +
9638 + IRQL = PASSIVE_LEVEL
9639 + IRQL = DISPATCH_LEVEL
9640 +
9641 + Note:
9642 +
9643 + ========================================================================
9644 +*/
9645 +NDIS_STATUS MiniportMMRequest(
9646 + IN PRTMP_ADAPTER pAd,
9647 + IN UCHAR QueIdx,
9648 + IN PUCHAR pData,
9649 + IN UINT Length)
9650 +{
9651 + PNDIS_PACKET pPacket;
9652 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
9653 + ULONG FreeNum;
9654 + UCHAR IrqState;
9655 + UCHAR rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; //RTMP_HW_HDR_LEN];
9656 +
9657 + ASSERT(Length <= MGMT_DMA_BUFFER_SIZE);
9658 +
9659 + QueIdx=3;
9660 +
9661 + // 2860C use Tx Ring
9662 +
9663 + IrqState = pAd->irq_disabled;
9664 +
9665 + do
9666 + {
9667 + // Reset is in progress, stop immediately
9668 + if ( RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
9669 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)||
9670 + !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
9671 + {
9672 + Status = NDIS_STATUS_FAILURE;
9673 + break;
9674 + }
9675 +
9676 + // Check Free priority queue
9677 + // Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing.
9678 +
9679 + // 2860C use Tx Ring
9680 + if (pAd->MACVersion == 0x28600100)
9681 + {
9682 + FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
9683 + }
9684 + else
9685 + {
9686 + FreeNum = GET_MGMTRING_FREENO(pAd);
9687 + }
9688 +
9689 + if ((FreeNum > 0))
9690 + {
9691 + // We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870
9692 + NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE));
9693 + Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE), pData, Length);
9694 + if (Status != NDIS_STATUS_SUCCESS)
9695 + {
9696 + DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n"));
9697 + break;
9698 + }
9699 +
9700 + //pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
9701 + //pAd->CommonCfg.MlmeRate = RATE_2;
9702 +
9703 +
9704 + Status = MlmeHardTransmit(pAd, QueIdx, pPacket);
9705 + if (Status != NDIS_STATUS_SUCCESS)
9706 + RTMPFreeNdisPacket(pAd, pPacket);
9707 + }
9708 + else
9709 + {
9710 + pAd->RalinkCounters.MgmtRingFullCount++;
9711 + DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n",
9712 + QueIdx, pAd->RalinkCounters.MgmtRingFullCount));
9713 + }
9714 +
9715 + } while (FALSE);
9716 +
9717 +
9718 + return Status;
9719 +}
9720 +
9721 +
9722 +
9723 +
9724 +/*
9725 + ========================================================================
9726 +
9727 + Routine Description:
9728 + Copy frame from waiting queue into relative ring buffer and set
9729 + appropriate ASIC register to kick hardware transmit function
9730 +
9731 + Arguments:
9732 + pAd Pointer to our adapter
9733 + pBuffer Pointer to memory of outgoing frame
9734 + Length Size of outgoing management frame
9735 +
9736 + Return Value:
9737 + NDIS_STATUS_FAILURE
9738 + NDIS_STATUS_PENDING
9739 + NDIS_STATUS_SUCCESS
9740 +
9741 + IRQL = PASSIVE_LEVEL
9742 + IRQL = DISPATCH_LEVEL
9743 +
9744 + Note:
9745 +
9746 + ========================================================================
9747 +*/
9748 +NDIS_STATUS MlmeHardTransmit(
9749 + IN PRTMP_ADAPTER pAd,
9750 + IN UCHAR QueIdx,
9751 + IN PNDIS_PACKET pPacket)
9752 +{
9753 + if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
9754 +#ifdef CARRIER_DETECTION_SUPPORT
9755 +#endif // CARRIER_DETECTION_SUPPORT //
9756 + )
9757 + {
9758 + return NDIS_STATUS_FAILURE;
9759 + }
9760 +
9761 + return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket);
9762 +
9763 +}
9764 +
9765 +
9766 +
9767 +NDIS_STATUS MlmeHardTransmitMgmtRing(
9768 + IN PRTMP_ADAPTER pAd,
9769 + IN UCHAR QueIdx,
9770 + IN PNDIS_PACKET pPacket)
9771 +{
9772 + PACKET_INFO PacketInfo;
9773 + PUCHAR pSrcBufVA;
9774 + UINT SrcBufLen;
9775 + PHEADER_802_11 pHeader_802_11;
9776 + BOOLEAN bAckRequired, bInsertTimestamp;
9777 + UCHAR MlmeRate;
9778 + PTXWI_STRUC pFirstTxWI;
9779 + MAC_TABLE_ENTRY *pMacEntry = NULL;
9780 +
9781 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
9782 +
9783 + // Make sure MGMT ring resource won't be used by other threads
9784 +// sample, for IRQ LOCK -> SEM LOCK
9785 +// IrqState = pAd->irq_disabled;
9786 +// if (!IrqState)
9787 + RTMP_SEM_LOCK(&pAd->MgmtRingLock);
9788 +
9789 +
9790 + if (pSrcBufVA == NULL)
9791 + {
9792 + // The buffer shouldn't be NULL
9793 +// if (!IrqState)
9794 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9795 + return NDIS_STATUS_FAILURE;
9796 + }
9797 +
9798 +#ifdef CONFIG_STA_SUPPORT
9799 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9800 + {
9801 + // outgoing frame always wakeup PHY to prevent frame lost
9802 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
9803 + AsicForceWakeup(pAd, TRUE);
9804 + }
9805 +#endif // CONFIG_STA_SUPPORT //
9806 +
9807 + pFirstTxWI = (PTXWI_STRUC)(pSrcBufVA + TXINFO_SIZE);
9808 + pHeader_802_11 = (PHEADER_802_11) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); //TXWI_SIZE);
9809 +
9810 + if (pHeader_802_11->Addr1[0] & 0x01)
9811 + {
9812 + MlmeRate = pAd->CommonCfg.BasicMlmeRate;
9813 + }
9814 + else
9815 + {
9816 + MlmeRate = pAd->CommonCfg.MlmeRate;
9817 + }
9818 +
9819 + // Verify Mlme rate for a / g bands.
9820 + if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) // 11A band
9821 + MlmeRate = RATE_6;
9822 +
9823 + if ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
9824 + (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL))
9825 + {
9826 + pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1);
9827 + }
9828 +
9829 +#ifdef CONFIG_STA_SUPPORT
9830 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9831 + {
9832 + // Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode.
9833 + if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED
9834 +#ifdef DOT11_N_SUPPORT
9835 + || pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED
9836 +#endif // DOT11_N_SUPPORT //
9837 + )
9838 + {
9839 + if (pAd->LatchRfRegs.Channel > 14)
9840 + pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
9841 + else
9842 + pAd->CommonCfg.MlmeTransmit.field.MODE = 0;
9843 + }
9844 + }
9845 +#endif // CONFIG_STA_SUPPORT //
9846 +
9847 + //
9848 + // Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE)
9849 + // Snice it's been set to 0 while on MgtMacHeaderInit
9850 + // By the way this will cause frame to be send on PWR_SAVE failed.
9851 + //
9852 + // pHeader_802_11->FC.PwrMgmt = 0; // (pAd->StaCfg.Psm == PWR_SAVE);
9853 + //
9854 + // In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame
9855 +#ifdef CONFIG_STA_SUPPORT
9856 + // Data-Null packets alse pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD
9857 + if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL))
9858 + {
9859 + if ((pAd->StaCfg.Psm == PWR_SAVE) &&
9860 + (pHeader_802_11->FC.SubType == SUBTYPE_ACTION))
9861 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
9862 + else
9863 + pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE;
9864 + }
9865 +#endif // CONFIG_STA_SUPPORT //
9866 +
9867 + bInsertTimestamp = FALSE;
9868 + if (pHeader_802_11->FC.Type == BTYPE_CNTL) // must be PS-POLL
9869 + {
9870 +#ifdef CONFIG_STA_SUPPORT
9871 + //Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue.
9872 + if ((pAd->OpMode == OPMODE_STA) && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL))
9873 + {
9874 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
9875 + }
9876 +#endif // CONFIG_STA_SUPPORT //
9877 + bAckRequired = FALSE;
9878 + }
9879 + else // BTYPE_MGMT or BTYPE_DATA(must be NULL frame)
9880 + {
9881 + //pAd->Sequence++;
9882 + //pHeader_802_11->Sequence = pAd->Sequence;
9883 +
9884 + if (pHeader_802_11->Addr1[0] & 0x01) // MULTICAST, BROADCAST
9885 + {
9886 + bAckRequired = FALSE;
9887 + pHeader_802_11->Duration = 0;
9888 + }
9889 + else
9890 + {
9891 + bAckRequired = TRUE;
9892 + pHeader_802_11->Duration = RTMPCalcDuration(pAd, MlmeRate, 14);
9893 + if (pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP)
9894 + {
9895 + bInsertTimestamp = TRUE;
9896 + }
9897 + }
9898 + }
9899 +
9900 + pHeader_802_11->Sequence = pAd->Sequence++;
9901 + if (pAd->Sequence >0xfff)
9902 + pAd->Sequence = 0;
9903 +
9904 + // Before radar detection done, mgmt frame can not be sent but probe req
9905 + // Because we need to use probe req to trigger driver to send probe req in passive scan
9906 + if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ)
9907 + && (pAd->CommonCfg.bIEEE80211H == 1)
9908 + && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE))
9909 + {
9910 + DBGPRINT(RT_DEBUG_ERROR,("MlmeHardTransmit --> radar detect not in normal mode !!!\n"));
9911 +// if (!IrqState)
9912 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9913 + return (NDIS_STATUS_FAILURE);
9914 + }
9915 +
9916 +#ifdef RT_BIG_ENDIAN
9917 + RTMPFrameEndianChange(pAd, (PUCHAR)pHeader_802_11, DIR_WRITE, FALSE);
9918 +#endif
9919 +
9920 + //
9921 + // fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET
9922 + // should always has only one ohysical buffer, and the whole frame size equals
9923 + // to the first scatter buffer size
9924 + //
9925 +
9926 + // Initialize TX Descriptor
9927 + // For inter-frame gap, the number is for this frame and next frame
9928 + // For MLME rate, we will fix as 2Mb to match other vendor's implement
9929 +// pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
9930 +
9931 +// management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not.
9932 + if (pMacEntry == NULL)
9933 + {
9934 + RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, FALSE, bAckRequired, FALSE,
9935 + 0, RESERVED_WCID, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), PID_MGMT, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
9936 + }
9937 + else
9938 + {
9939 + RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE,
9940 + bInsertTimestamp, FALSE, bAckRequired, FALSE,
9941 + 0, pMacEntry->Aid, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE),
9942 + pMacEntry->MaxHTPhyMode.field.MCS, 0,
9943 + (UCHAR)pMacEntry->MaxHTPhyMode.field.MCS,
9944 + IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode);
9945 + }
9946 +
9947 +#ifdef RT_BIG_ENDIAN
9948 + RTMPWIEndianChange((PUCHAR)pFirstTxWI, TYPE_TXWI);
9949 +#endif
9950 +
9951 + // Now do hardware-depened kick out.
9952 + HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen);
9953 +
9954 + // Make sure to release MGMT ring resource
9955 +// if (!IrqState)
9956 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9957 + return NDIS_STATUS_SUCCESS;
9958 +}
9959 +
9960 +
9961 +/********************************************************************************
9962 +
9963 + New DeQueue Procedures.
9964 +
9965 + ********************************************************************************/
9966 +
9967 +#define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \
9968 + do{ \
9969 + if (bIntContext == FALSE) \
9970 + RTMP_IRQ_LOCK((lock), IrqFlags); \
9971 + }while(0)
9972 +
9973 +#define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \
9974 + do{ \
9975 + if (bIntContext == FALSE) \
9976 + RTMP_IRQ_UNLOCK((lock), IrqFlags); \
9977 + }while(0)
9978 +
9979 +
9980 +#if 0
9981 +static VOID dumpTxBlk(TX_BLK *pTxBlk)
9982 +{
9983 + NDIS_PACKET *pPacket;
9984 + int i, frameNum;
9985 + PQUEUE_ENTRY pQEntry;
9986 +
9987 + printk("Dump TX_BLK Structure:\n");
9988 + printk("\tTxFrameType=%d!\n", pTxBlk->TxFrameType);
9989 + printk("\tTotalFrameLen=%d\n", pTxBlk->TotalFrameLen);
9990 + printk("\tTotalFrameNum=%ld!\n", pTxBlk->TxPacketList.Number);
9991 + printk("\tTotalFragNum=%d!\n", pTxBlk->TotalFragNum);
9992 + printk("\tpPacketList=\n");
9993 +
9994 + frameNum = pTxBlk->TxPacketList.Number;
9995 +
9996 + for(i=0; i < frameNum; i++)
9997 + { int j;
9998 + UCHAR *pBuf;
9999 +
10000 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
10001 + pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
10002 + if (pPacket)
10003 + {
10004 + pBuf = GET_OS_PKT_DATAPTR(pPacket);
10005 + printk("\t\t[%d]:ptr=0x%x, Len=%d!\n", i, (UINT32)(GET_OS_PKT_DATAPTR(pPacket)), GET_OS_PKT_LEN(pPacket));
10006 + printk("\t\t");
10007 + for (j =0 ; j < GET_OS_PKT_LEN(pPacket); j++)
10008 + {
10009 + printk("%02x ", (pBuf[j] & 0xff));
10010 + if (j == 16)
10011 + break;
10012 + }
10013 + InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
10014 + }
10015 + }
10016 + printk("\tWcid=%d!\n", pTxBlk->Wcid);
10017 + printk("\tapidx=%d!\n", pTxBlk->apidx);
10018 + printk("----EndOfDump\n");
10019 +
10020 +}
10021 +#endif
10022 +
10023 +
10024 +/*
10025 + ========================================================================
10026 + Tx Path design algorithm:
10027 + Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal),
10028 + Specific Packet Type. Following show the classification rule and policy for each kinds of packets.
10029 + Classification Rule=>
10030 + Multicast: (*addr1 & 0x01) == 0x01
10031 + Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc.
10032 + 11N Rate : If peer support HT
10033 + (1).AMPDU -- If TXBA is negotiated.
10034 + (2).AMSDU -- If AMSDU is capable for both peer and ourself.
10035 + *). AMSDU can embedded in a AMPDU, but now we didn't support it.
10036 + (3).Normal -- Other packets which send as 11n rate.
10037 +
10038 + B/G Rate : If peer is b/g only.
10039 + (1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6
10040 + (2).Normal -- Other packets which send as b/g rate.
10041 + Fragment:
10042 + The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment.
10043 +
10044 + Classified Packet Handle Rule=>
10045 + Multicast:
10046 + No ACK, //pTxBlk->bAckRequired = FALSE;
10047 + No WMM, //pTxBlk->bWMM = FALSE;
10048 + No piggyback, //pTxBlk->bPiggyBack = FALSE;
10049 + Force LowRate, //pTxBlk->bForceLowRate = TRUE;
10050 + Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use
10051 + the same policy to handle it.
10052 + Force LowRate, //pTxBlk->bForceLowRate = TRUE;
10053 +
10054 + 11N Rate :
10055 + No piggyback, //pTxBlk->bPiggyBack = FALSE;
10056 +
10057 + (1).AMSDU
10058 + pTxBlk->bWMM = TRUE;
10059 + (2).AMPDU
10060 + pTxBlk->bWMM = TRUE;
10061 + (3).Normal
10062 +
10063 + B/G Rate :
10064 + (1).ARALINK
10065 +
10066 + (2).Normal
10067 + ========================================================================
10068 +*/
10069 +static UCHAR TxPktClassification(
10070 + IN RTMP_ADAPTER *pAd,
10071 + IN PNDIS_PACKET pPacket)
10072 +{
10073 + UCHAR TxFrameType = TX_UNKOWN_FRAME;
10074 + UCHAR Wcid;
10075 + MAC_TABLE_ENTRY *pMacEntry = NULL;
10076 +#ifdef DOT11_N_SUPPORT
10077 + BOOLEAN bHTRate = FALSE;
10078 +#endif // DOT11_N_SUPPORT //
10079 +
10080 + Wcid = RTMP_GET_PACKET_WCID(pPacket);
10081 + if (Wcid == MCAST_WCID)
10082 + { // Handle for RA is Broadcast/Multicast Address.
10083 + return TX_MCAST_FRAME;
10084 + }
10085 +
10086 + // Handle for unicast packets
10087 + pMacEntry = &pAd->MacTab.Content[Wcid];
10088 + if (RTMP_GET_PACKET_LOWRATE(pPacket))
10089 + { // It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame
10090 + TxFrameType = TX_LEGACY_FRAME;
10091 + }
10092 +#ifdef DOT11_N_SUPPORT
10093 + else if (IS_HT_RATE(pMacEntry))
10094 + { // it's a 11n capable packet
10095 +
10096 + // Depends on HTPhyMode to check if the peer support the HTRate transmission.
10097 + // Currently didn't support A-MSDU embedded in A-MPDU
10098 + bHTRate = TRUE;
10099 + if (RTMP_GET_PACKET_MOREDATA(pPacket) || (pMacEntry->PsMode == PWR_SAVE))
10100 + TxFrameType = TX_LEGACY_FRAME;
10101 +#ifdef UAPSD_AP_SUPPORT
10102 + else if (RTMP_GET_PACKET_EOSP(pPacket))
10103 + TxFrameType = TX_LEGACY_FRAME;
10104 +#endif // UAPSD_AP_SUPPORT //
10105 + else if((pMacEntry->TXBAbitmap & (1<<(RTMP_GET_PACKET_UP(pPacket)))) != 0)
10106 + return TX_AMPDU_FRAME;
10107 + else if(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AMSDU_INUSED))
10108 + return TX_AMSDU_FRAME;
10109 + else
10110 + TxFrameType = TX_LEGACY_FRAME;
10111 + }
10112 +#endif // DOT11_N_SUPPORT //
10113 + else
10114 + { // it's a legacy b/g packet.
10115 + if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) &&
10116 + (RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) &&
10117 + (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))))
10118 + { // if peer support Ralink Aggregation, we use it.
10119 + TxFrameType = TX_RALINK_FRAME;
10120 + }
10121 + else
10122 + {
10123 + TxFrameType = TX_LEGACY_FRAME;
10124 + }
10125 + }
10126 +
10127 + // Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU.
10128 + if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1) && (TxFrameType == TX_LEGACY_FRAME))
10129 + TxFrameType = TX_FRAG_FRAME;
10130 +
10131 + return TxFrameType;
10132 +}
10133 +
10134 +
10135 +BOOLEAN RTMP_FillTxBlkInfo(
10136 + IN RTMP_ADAPTER *pAd,
10137 + IN TX_BLK *pTxBlk)
10138 +{
10139 + PACKET_INFO PacketInfo;
10140 + PNDIS_PACKET pPacket;
10141 + PMAC_TABLE_ENTRY pMacEntry = NULL;
10142 +
10143 + pPacket = pTxBlk->pPacket;
10144 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
10145 +
10146 + pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket);
10147 + pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket);
10148 + pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket);
10149 + pTxBlk->FrameGap = IFS_HTTXOP; // ASIC determine Frame Gap
10150 +
10151 + if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket))
10152 + TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame);
10153 + else
10154 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame);
10155 +
10156 + // Default to clear this flag
10157 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS);
10158 +
10159 +
10160 + if (pTxBlk->Wcid == MCAST_WCID)
10161 + {
10162 + pTxBlk->pMacEntry = NULL;
10163 + {
10164 +#ifdef MCAST_RATE_SPECIFIC
10165 + PUCHAR pDA = GET_OS_PKT_DATAPTR(pPacket);
10166 + if (((*pDA & 0x01) == 0x01) && (*pDA != 0xff))
10167 + pTxBlk->pTransmit = &pAd->CommonCfg.MCastPhyMode;
10168 + else
10169 +#endif // MCAST_RATE_SPECIFIC //
10170 + pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
10171 + }
10172 +
10173 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); // AckRequired = FALSE, when broadcast packet in Adhoc mode.
10174 + //TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate);
10175 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag);
10176 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
10177 + if (RTMP_GET_PACKET_MOREDATA(pPacket))
10178 + {
10179 + TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
10180 + }
10181 +
10182 + }
10183 + else
10184 + {
10185 + pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid];
10186 + pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode;
10187 +
10188 + pMacEntry = pTxBlk->pMacEntry;
10189 +
10190 +
10191 + // For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK.
10192 + if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK)
10193 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
10194 + else
10195 + TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired);
10196 +
10197 + {
10198 +
10199 +#ifdef CONFIG_STA_SUPPORT
10200 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
10201 + {
10202 +
10203 + // If support WMM, enable it.
10204 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
10205 + CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))
10206 + TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM);
10207 + }
10208 +#endif // CONFIG_STA_SUPPORT //
10209 + }
10210 +
10211 + if (pTxBlk->TxFrameType == TX_LEGACY_FRAME)
10212 + {
10213 + if ( (RTMP_GET_PACKET_LOWRATE(pPacket)) ||
10214 + ((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1)))
10215 + { // Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate.
10216 + pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
10217 +#ifdef DOT11_N_SUPPORT
10218 + // Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it???
10219 + if (IS_HT_STA(pTxBlk->pMacEntry) &&
10220 + (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET)) &&
10221 + ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RDG_CAPABLE)))
10222 + {
10223 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
10224 + TX_BLK_SET_FLAG(pTxBlk, fTX_bForceNonQoS);
10225 + }
10226 +#endif // DOT11_N_SUPPORT //
10227 + }
10228 +
10229 +#ifdef DOT11_N_SUPPORT
10230 + if ( (IS_HT_RATE(pMacEntry) == FALSE) &&
10231 + (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE)))
10232 + { // Currently piggy-back only support when peer is operate in b/g mode.
10233 + TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack);
10234 + }
10235 +#endif // DOT11_N_SUPPORT //
10236 +
10237 + if (RTMP_GET_PACKET_MOREDATA(pPacket))
10238 + {
10239 + TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
10240 + }
10241 +#ifdef UAPSD_AP_SUPPORT
10242 + if (RTMP_GET_PACKET_EOSP(pPacket))
10243 + {
10244 + TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM_UAPSD_EOSP);
10245 + }
10246 +#endif // UAPSD_AP_SUPPORT //
10247 + }
10248 + else if (pTxBlk->TxFrameType == TX_FRAG_FRAME)
10249 + {
10250 + TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag);
10251 + }
10252 +
10253 + pMacEntry->DebugTxCount++;
10254 + }
10255 +
10256 + return TRUE;
10257 +
10258 +FillTxBlkErr:
10259 + return FALSE;
10260 +}
10261 +
10262 +
10263 +BOOLEAN CanDoAggregateTransmit(
10264 + IN RTMP_ADAPTER *pAd,
10265 + IN NDIS_PACKET *pPacket,
10266 + IN TX_BLK *pTxBlk)
10267 +{
10268 +
10269 + //printk("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType);
10270 +
10271 + if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID)
10272 + return FALSE;
10273 +
10274 + if (RTMP_GET_PACKET_DHCP(pPacket) ||
10275 + RTMP_GET_PACKET_EAPOL(pPacket) ||
10276 + RTMP_GET_PACKET_WAI(pPacket))
10277 + return FALSE;
10278 +
10279 + if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) &&
10280 + ((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))> (RX_BUFFER_AGGRESIZE - 100)))
10281 + { // For AMSDU, allow the packets with total length < max-amsdu size
10282 + return FALSE;
10283 + }
10284 +
10285 + if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) &&
10286 + (pTxBlk->TxPacketList.Number == 2))
10287 + { // For RALINK-Aggregation, allow two frames in one batch.
10288 + return FALSE;
10289 + }
10290 +
10291 +#ifdef CONFIG_STA_SUPPORT
10292 + if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) // must be unicast to AP
10293 + return TRUE;
10294 + else
10295 +#endif // CONFIG_STA_SUPPORT //
10296 + return FALSE;
10297 +
10298 +}
10299 +
10300 +
10301 +/*
10302 + ========================================================================
10303 +
10304 + Routine Description:
10305 + To do the enqueue operation and extract the first item of waiting
10306 + list. If a number of available shared memory segments could meet
10307 + the request of extracted item, the extracted item will be fragmented
10308 + into shared memory segments.
10309 +
10310 + Arguments:
10311 + pAd Pointer to our adapter
10312 + pQueue Pointer to Waiting Queue
10313 +
10314 + Return Value:
10315 + None
10316 +
10317 + IRQL = DISPATCH_LEVEL
10318 +
10319 + Note:
10320 +
10321 + ========================================================================
10322 +*/
10323 +VOID RTMPDeQueuePacket(
10324 + IN PRTMP_ADAPTER pAd,
10325 + IN BOOLEAN bIntContext,
10326 + IN UCHAR QIdx, /* BulkOutPipeId */
10327 + IN UCHAR Max_Tx_Packets)
10328 +{
10329 + PQUEUE_ENTRY pEntry = NULL;
10330 + PNDIS_PACKET pPacket;
10331 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
10332 + UCHAR Count=0;
10333 + PQUEUE_HEADER pQueue;
10334 + ULONG FreeNumber[NUM_OF_TX_RING];
10335 + UCHAR QueIdx, sQIdx, eQIdx;
10336 + unsigned long IrqFlags = 0;
10337 + BOOLEAN hasTxDesc = FALSE;
10338 + TX_BLK TxBlk;
10339 + TX_BLK *pTxBlk;
10340 +
10341 +#ifdef DBG_DIAGNOSE
10342 + BOOLEAN firstRound;
10343 + RtmpDiagStruct *pDiagStruct = &pAd->DiagStruct;
10344 +#endif
10345 +
10346 +
10347 + if (QIdx == NUM_OF_TX_RING)
10348 + {
10349 + sQIdx = 0;
10350 + eQIdx = 3; // 4 ACs, start from 0.
10351 + }
10352 + else
10353 + {
10354 + sQIdx = eQIdx = QIdx;
10355 + }
10356 +
10357 + for (QueIdx=sQIdx; QueIdx <= eQIdx; QueIdx++)
10358 + {
10359 + Count=0;
10360 +
10361 + RT28XX_START_DEQUEUE(pAd, QueIdx, IrqFlags);
10362 +
10363 +#ifdef DBG_DIAGNOSE
10364 + firstRound = ((QueIdx == 0) ? TRUE : FALSE);
10365 +#endif // DBG_DIAGNOSE //
10366 +
10367 + while (1)
10368 + {
10369 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS |
10370 + fRTMP_ADAPTER_RADIO_OFF |
10371 + fRTMP_ADAPTER_RESET_IN_PROGRESS |
10372 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
10373 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
10374 + {
10375 + RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
10376 + return;
10377 + }
10378 +
10379 + if (Count >= Max_Tx_Packets)
10380 + break;
10381 +
10382 + DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10383 + if (&pAd->TxSwQueue[QueIdx] == NULL)
10384 + {
10385 +#ifdef DBG_DIAGNOSE
10386 + if (firstRound == TRUE)
10387 + pDiagStruct->TxSWQueCnt[pDiagStruct->ArrayCurIdx][0]++;
10388 +#endif // DBG_DIAGNOSE //
10389 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10390 + break;
10391 + }
10392 +
10393 +
10394 + // probe the Queue Head
10395 + pQueue = &pAd->TxSwQueue[QueIdx];
10396 + if ((pEntry = pQueue->Head) == NULL)
10397 + {
10398 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10399 + break;
10400 + }
10401 +
10402 + pTxBlk = &TxBlk;
10403 + NdisZeroMemory((PUCHAR)pTxBlk, sizeof(TX_BLK));
10404 + //InitializeQueueHeader(&pTxBlk->TxPacketList); // Didn't need it because we already memzero it.
10405 + pTxBlk->QueIdx = QueIdx;
10406 +
10407 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10408 +
10409 + // Early check to make sure we have enoguh Tx Resource.
10410 + hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket);
10411 + if (!hasTxDesc)
10412 + {
10413 + pAd->PrivateInfo.TxRingFullCnt++;
10414 +
10415 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10416 +
10417 + break;
10418 + }
10419 +
10420 + pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket);
10421 + pEntry = RemoveHeadQueue(pQueue);
10422 + pTxBlk->TotalFrameNum++;
10423 + pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary
10424 + pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
10425 + pTxBlk->pPacket = pPacket;
10426 + InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
10427 +
10428 + if (pTxBlk->TxFrameType == TX_RALINK_FRAME || pTxBlk->TxFrameType == TX_AMSDU_FRAME)
10429 + {
10430 + // Enhance SW Aggregation Mechanism
10431 + if (NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, FreeNumber[QueIdx], pTxBlk->TxFrameType))
10432 + {
10433 + InsertHeadQueue(pQueue, PACKET_TO_QUEUE_ENTRY(pPacket));
10434 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10435 + break;
10436 + }
10437 +
10438 + do{
10439 + if((pEntry = pQueue->Head) == NULL)
10440 + break;
10441 +
10442 + // For TX_AMSDU_FRAME/TX_RALINK_FRAME, Need to check if next pakcet can do aggregation.
10443 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10444 + FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx);
10445 + hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket);
10446 + if ((hasTxDesc == FALSE) || (CanDoAggregateTransmit(pAd, pPacket, pTxBlk) == FALSE))
10447 + break;
10448 +
10449 + //Remove the packet from the TxSwQueue and insert into pTxBlk
10450 + pEntry = RemoveHeadQueue(pQueue);
10451 + ASSERT(pEntry);
10452 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10453 + pTxBlk->TotalFrameNum++;
10454 + pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary
10455 + pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
10456 + InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
10457 + }while(1);
10458 +
10459 + if (pTxBlk->TxPacketList.Number == 1)
10460 + pTxBlk->TxFrameType = TX_LEGACY_FRAME;
10461 + }
10462 +
10463 +#ifdef RT2870
10464 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10465 +#endif // RT2870 //
10466 +
10467 + Count += pTxBlk->TxPacketList.Number;
10468 +
10469 + // Do HardTransmit now.
10470 +#ifdef CONFIG_STA_SUPPORT
10471 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
10472 + Status = STAHardTransmit(pAd, pTxBlk, QueIdx);
10473 +#endif // CONFIG_STA_SUPPORT //
10474 +
10475 +
10476 +#if 0 // We should not break if HardTransmit failed. Well, at least now we should not!
10477 + if (Status != NDIS_STATUS_SUCCESS)
10478 + {
10479 + DBGPRINT(RT_DEBUG_TRACE /*RT_DEBUG_INFO*/,("RTMPHardTransmit return failed!!!\n"));
10480 + break;
10481 + }
10482 +#endif
10483 + }
10484 +
10485 + RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
10486 +
10487 +#ifdef RT2870
10488 + if (!hasTxDesc)
10489 + RTUSBKickBulkOut(pAd);
10490 +#endif // RT2870 //
10491 +
10492 +#ifdef BLOCK_NET_IF
10493 + if ((pAd->blockQueueTab[QueIdx].SwTxQueueBlockFlag == TRUE)
10494 + && (pAd->TxSwQueue[QueIdx].Number < 1))
10495 + {
10496 + releaseNetIf(&pAd->blockQueueTab[QueIdx]);
10497 + }
10498 +#endif // BLOCK_NET_IF //
10499 +
10500 + }
10501 +
10502 +}
10503 +
10504 +
10505 +/*
10506 + ========================================================================
10507 +
10508 + Routine Description:
10509 + Calculates the duration which is required to transmit out frames
10510 + with given size and specified rate.
10511 +
10512 + Arguments:
10513 + pAd Pointer to our adapter
10514 + Rate Transmit rate
10515 + Size Frame size in units of byte
10516 +
10517 + Return Value:
10518 + Duration number in units of usec
10519 +
10520 + IRQL = PASSIVE_LEVEL
10521 + IRQL = DISPATCH_LEVEL
10522 +
10523 + Note:
10524 +
10525 + ========================================================================
10526 +*/
10527 +USHORT RTMPCalcDuration(
10528 + IN PRTMP_ADAPTER pAd,
10529 + IN UCHAR Rate,
10530 + IN ULONG Size)
10531 +{
10532 + ULONG Duration = 0;
10533 +
10534 + if (Rate < RATE_FIRST_OFDM_RATE) // CCK
10535 + {
10536 + if ((Rate > RATE_1) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED))
10537 + Duration = 96; // 72+24 preamble+plcp
10538 + else
10539 + Duration = 192; // 144+48 preamble+plcp
10540 +
10541 + Duration += (USHORT)((Size << 4) / RateIdTo500Kbps[Rate]);
10542 + if ((Size << 4) % RateIdTo500Kbps[Rate])
10543 + Duration ++;
10544 + }
10545 + else if (Rate <= RATE_LAST_OFDM_RATE)// OFDM rates
10546 + {
10547 + Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension
10548 + Duration += 4 * (USHORT)((11 + Size * 4) / RateIdTo500Kbps[Rate]);
10549 + if ((11 + Size * 4) % RateIdTo500Kbps[Rate])
10550 + Duration += 4;
10551 + }
10552 + else //mimo rate
10553 + {
10554 + Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension
10555 + }
10556 +
10557 + return (USHORT)Duration;
10558 +}
10559 +
10560 +
10561 +/*
10562 + ========================================================================
10563 +
10564 + Routine Description:
10565 + Calculates the duration which is required to transmit out frames
10566 + with given size and specified rate.
10567 +
10568 + Arguments:
10569 + pTxWI Pointer to head of each MPDU to HW.
10570 + Ack Setting for Ack requirement bit
10571 + Fragment Setting for Fragment bit
10572 + RetryMode Setting for retry mode
10573 + Ifs Setting for IFS gap
10574 + Rate Setting for transmit rate
10575 + Service Setting for service
10576 + Length Frame length
10577 + TxPreamble Short or Long preamble when using CCK rates
10578 + QueIdx - 0-3, according to 802.11e/d4.4 June/2003
10579 +
10580 + Return Value:
10581 + None
10582 +
10583 + IRQL = PASSIVE_LEVEL
10584 + IRQL = DISPATCH_LEVEL
10585 +
10586 + See also : BASmartHardTransmit() !!!
10587 +
10588 + ========================================================================
10589 +*/
10590 +VOID RTMPWriteTxWI(
10591 + IN PRTMP_ADAPTER pAd,
10592 + IN PTXWI_STRUC pOutTxWI,
10593 + IN BOOLEAN FRAG,
10594 + IN BOOLEAN CFACK,
10595 + IN BOOLEAN InsTimestamp,
10596 + IN BOOLEAN AMPDU,
10597 + IN BOOLEAN Ack,
10598 + IN BOOLEAN NSeq, // HW new a sequence.
10599 + IN UCHAR BASize,
10600 + IN UCHAR WCID,
10601 + IN ULONG Length,
10602 + IN UCHAR PID,
10603 + IN UCHAR TID,
10604 + IN UCHAR TxRate,
10605 + IN UCHAR Txopmode,
10606 + IN BOOLEAN CfAck,
10607 + IN HTTRANSMIT_SETTING *pTransmit)
10608 +{
10609 + PMAC_TABLE_ENTRY pMac = NULL;
10610 + TXWI_STRUC TxWI;
10611 + PTXWI_STRUC pTxWI;
10612 +
10613 + if (WCID < MAX_LEN_OF_MAC_TABLE)
10614 + pMac = &pAd->MacTab.Content[WCID];
10615 +
10616 + //
10617 + // Always use Long preamble before verifiation short preamble functionality works well.
10618 + // Todo: remove the following line if short preamble functionality works
10619 + //
10620 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10621 + NdisZeroMemory(&TxWI, TXWI_SIZE);
10622 + pTxWI = &TxWI;
10623 +
10624 + pTxWI->FRAG= FRAG;
10625 +
10626 + pTxWI->CFACK = CFACK;
10627 + pTxWI->TS= InsTimestamp;
10628 + pTxWI->AMPDU = AMPDU;
10629 + pTxWI->ACK = Ack;
10630 + pTxWI->txop= Txopmode;
10631 +
10632 + pTxWI->NSEQ = NSeq;
10633 + // John tune the performace with Intel Client in 20 MHz performance
10634 +#ifdef DOT11_N_SUPPORT
10635 + BASize = pAd->CommonCfg.TxBASize;
10636 +
10637 + if( BASize >7 )
10638 + BASize =7;
10639 + pTxWI->BAWinSize = BASize;
10640 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10641 + pTxWI->STBC = pTransmit->field.STBC;
10642 +#endif // DOT11_N_SUPPORT //
10643 +
10644 + pTxWI->WirelessCliID = WCID;
10645 + pTxWI->MPDUtotalByteCount = Length;
10646 + pTxWI->PacketId = PID;
10647 +
10648 + // If CCK or OFDM, BW must be 20
10649 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10650 +#ifdef DOT11N_DRAFT3
10651 + if (pTxWI->BW)
10652 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10653 +#endif // DOT11N_DRAFT3 //
10654 +
10655 + pTxWI->MCS = pTransmit->field.MCS;
10656 + pTxWI->PHYMODE = pTransmit->field.MODE;
10657 + pTxWI->CFACK = CfAck;
10658 +
10659 +#ifdef DOT11_N_SUPPORT
10660 + if (pMac)
10661 + {
10662 + if (pAd->CommonCfg.bMIMOPSEnable)
10663 + {
10664 + if ((pMac->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10665 + {
10666 + // Dynamic MIMO Power Save Mode
10667 + pTxWI->MIMOps = 1;
10668 + }
10669 + else if (pMac->MmpsMode == MMPS_STATIC)
10670 + {
10671 + // Static MIMO Power Save Mode
10672 + if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7)
10673 + {
10674 + pTxWI->MCS = 7;
10675 + pTxWI->MIMOps = 0;
10676 + }
10677 + }
10678 + }
10679 + //pTxWI->MIMOps = (pMac->PsMode == PWR_MMPS)? 1:0;
10680 + if (pMac->bIAmBadAtheros && (pMac->WepStatus != Ndis802_11WEPDisabled))
10681 + {
10682 + pTxWI->MpduDensity = 7;
10683 + }
10684 + else
10685 + {
10686 + pTxWI->MpduDensity = pMac->MpduDensity;
10687 + }
10688 + }
10689 +#endif // DOT11_N_SUPPORT //
10690 +
10691 + pTxWI->PacketId = pTxWI->MCS;
10692 + NdisMoveMemory(pOutTxWI, &TxWI, sizeof(TXWI_STRUC));
10693 +}
10694 +
10695 +
10696 +VOID RTMPWriteTxWI_Data(
10697 + IN PRTMP_ADAPTER pAd,
10698 + IN OUT PTXWI_STRUC pTxWI,
10699 + IN TX_BLK *pTxBlk)
10700 +{
10701 + HTTRANSMIT_SETTING *pTransmit;
10702 + PMAC_TABLE_ENTRY pMacEntry;
10703 +#ifdef DOT11_N_SUPPORT
10704 + UCHAR BASize;
10705 +#endif // DOT11_N_SUPPORT //
10706 +
10707 +
10708 + ASSERT(pTxWI);
10709 +
10710 + pTransmit = pTxBlk->pTransmit;
10711 + pMacEntry = pTxBlk->pMacEntry;
10712 +
10713 +
10714 + //
10715 + // Always use Long preamble before verifiation short preamble functionality works well.
10716 + // Todo: remove the following line if short preamble functionality works
10717 + //
10718 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10719 + NdisZeroMemory(pTxWI, TXWI_SIZE);
10720 +
10721 + pTxWI->FRAG = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag);
10722 + pTxWI->ACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAckRequired);
10723 + pTxWI->txop = pTxBlk->FrameGap;
10724 +
10725 +#ifdef CONFIG_STA_SUPPORT
10726 +#ifdef QOS_DLS_SUPPORT
10727 + if (pMacEntry &&
10728 + (pAd->StaCfg.BssType == BSS_INFRA) &&
10729 + (pMacEntry->ValidAsDls == TRUE))
10730 + pTxWI->WirelessCliID = BSSID_WCID;
10731 + else
10732 +#endif // QOS_DLS_SUPPORT //
10733 +#endif // CONFIG_STA_SUPPORT //
10734 + pTxWI->WirelessCliID = pTxBlk->Wcid;
10735 +
10736 + pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
10737 + pTxWI->CFACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bPiggyBack);
10738 +
10739 + // If CCK or OFDM, BW must be 20
10740 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10741 +#ifdef DOT11_N_SUPPORT
10742 +#ifdef DOT11N_DRAFT3
10743 + if (pTxWI->BW)
10744 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10745 +#endif // DOT11N_DRAFT3 //
10746 + pTxWI->AMPDU = ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) ? TRUE : FALSE);
10747 +
10748 + // John tune the performace with Intel Client in 20 MHz performance
10749 + BASize = pAd->CommonCfg.TxBASize;
10750 + if((pTxBlk->TxFrameType == TX_AMPDU_FRAME) && (pMacEntry))
10751 + {
10752 + UCHAR RABAOriIdx = 0; //The RA's BA Originator table index.
10753 +
10754 + RABAOriIdx = pTxBlk->pMacEntry->BAOriWcidArray[pTxBlk->UserPriority];
10755 + BASize = pAd->BATable.BAOriEntry[RABAOriIdx].BAWinSize;
10756 + }
10757 +
10758 +#if 0 // 3*3
10759 + if (BASize > 7)
10760 + BASize = 7;
10761 +#endif
10762 +
10763 + pTxWI->TxBF = pTransmit->field.TxBF;
10764 + pTxWI->BAWinSize = BASize;
10765 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10766 + pTxWI->STBC = pTransmit->field.STBC;
10767 +#endif // DOT11_N_SUPPORT //
10768 +
10769 + pTxWI->MCS = pTransmit->field.MCS;
10770 + pTxWI->PHYMODE = pTransmit->field.MODE;
10771 +
10772 +#ifdef DOT11_N_SUPPORT
10773 + if (pMacEntry)
10774 + {
10775 + if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10776 + {
10777 + // Dynamic MIMO Power Save Mode
10778 + pTxWI->MIMOps = 1;
10779 + }
10780 + else if (pMacEntry->MmpsMode == MMPS_STATIC)
10781 + {
10782 + // Static MIMO Power Save Mode
10783 + if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7)
10784 + {
10785 + pTxWI->MCS = 7;
10786 + pTxWI->MIMOps = 0;
10787 + }
10788 + }
10789 +
10790 + if (pMacEntry->bIAmBadAtheros && (pMacEntry->WepStatus != Ndis802_11WEPDisabled))
10791 + {
10792 + pTxWI->MpduDensity = 7;
10793 + }
10794 + else
10795 + {
10796 + pTxWI->MpduDensity = pMacEntry->MpduDensity;
10797 + }
10798 + }
10799 +#endif // DOT11_N_SUPPORT //
10800 +
10801 +#ifdef DBG_DIAGNOSE
10802 + if (pTxBlk->QueIdx== 0)
10803 + {
10804 + pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++;
10805 + pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++;
10806 + }
10807 +#endif // DBG_DIAGNOSE //
10808 +
10809 + // for rate adapation
10810 + pTxWI->PacketId = pTxWI->MCS;
10811 +}
10812 +
10813 +
10814 +VOID RTMPWriteTxWI_Cache(
10815 + IN PRTMP_ADAPTER pAd,
10816 + IN OUT PTXWI_STRUC pTxWI,
10817 + IN TX_BLK *pTxBlk)
10818 +{
10819 + PHTTRANSMIT_SETTING /*pTxHTPhyMode,*/ pTransmit;
10820 + PMAC_TABLE_ENTRY pMacEntry;
10821 +
10822 + //
10823 + // update TXWI
10824 + //
10825 + pMacEntry = pTxBlk->pMacEntry;
10826 + pTransmit = pTxBlk->pTransmit;
10827 +
10828 + if (pMacEntry->bAutoTxRateSwitch)
10829 + {
10830 + pTxWI->txop = IFS_HTTXOP;
10831 +
10832 + // If CCK or OFDM, BW must be 20
10833 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10834 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10835 + pTxWI->STBC = pTransmit->field.STBC;
10836 +
10837 + pTxWI->MCS = pTransmit->field.MCS;
10838 + pTxWI->PHYMODE = pTransmit->field.MODE;
10839 +
10840 + // set PID for TxRateSwitching
10841 + pTxWI->PacketId = pTransmit->field.MCS;
10842 + }
10843 +
10844 +#ifdef DOT11_N_SUPPORT
10845 + pTxWI->AMPDU = ((pMacEntry->NoBADataCountDown == 0) ? TRUE: FALSE);
10846 + pTxWI->MIMOps = 0;
10847 +
10848 +#ifdef DOT11N_DRAFT3
10849 + if (pTxWI->BW)
10850 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10851 +#endif // DOT11N_DRAFT3 //
10852 +
10853 + if (pAd->CommonCfg.bMIMOPSEnable)
10854 + {
10855 + // MIMO Power Save Mode
10856 + if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10857 + {
10858 + // Dynamic MIMO Power Save Mode
10859 + pTxWI->MIMOps = 1;
10860 + }
10861 + else if (pMacEntry->MmpsMode == MMPS_STATIC)
10862 + {
10863 + // Static MIMO Power Save Mode
10864 + if ((pTransmit->field.MODE >= MODE_HTMIX) && (pTransmit->field.MCS > 7))
10865 + {
10866 + pTxWI->MCS = 7;
10867 + pTxWI->MIMOps = 0;
10868 + }
10869 + }
10870 + }
10871 +#endif // DOT11_N_SUPPORT //
10872 +
10873 +#ifdef DBG_DIAGNOSE
10874 + if (pTxBlk->QueIdx== 0)
10875 + {
10876 + pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++;
10877 + pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++;
10878 + }
10879 +#endif // DBG_DIAGNOSE //
10880 +
10881 + pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
10882 +
10883 +}
10884 +
10885 +
10886 +/*
10887 + ========================================================================
10888 +
10889 + Routine Description:
10890 + Calculates the duration which is required to transmit out frames
10891 + with given size and specified rate.
10892 +
10893 + Arguments:
10894 + pTxD Pointer to transmit descriptor
10895 + Ack Setting for Ack requirement bit
10896 + Fragment Setting for Fragment bit
10897 + RetryMode Setting for retry mode
10898 + Ifs Setting for IFS gap
10899 + Rate Setting for transmit rate
10900 + Service Setting for service
10901 + Length Frame length
10902 + TxPreamble Short or Long preamble when using CCK rates
10903 + QueIdx - 0-3, according to 802.11e/d4.4 June/2003
10904 +
10905 + Return Value:
10906 + None
10907 +
10908 + IRQL = PASSIVE_LEVEL
10909 + IRQL = DISPATCH_LEVEL
10910 +
10911 + ========================================================================
10912 +*/
10913 +VOID RTMPWriteTxDescriptor(
10914 + IN PRTMP_ADAPTER pAd,
10915 + IN PTXD_STRUC pTxD,
10916 + IN BOOLEAN bWIV,
10917 + IN UCHAR QueueSEL)
10918 +{
10919 + //
10920 + // Always use Long preamble before verifiation short preamble functionality works well.
10921 + // Todo: remove the following line if short preamble functionality works
10922 + //
10923 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10924 +
10925 + pTxD->WIV = (bWIV) ? 1: 0;
10926 + pTxD->QSEL= (QueueSEL);
10927 + //RT2860c?? fixed using EDCA queue for test... We doubt Queue1 has problem. 2006-09-26 Jan
10928 + //pTxD->QSEL= FIFO_EDCA;
10929 + if (pAd->bGenOneHCCA == TRUE)
10930 + pTxD->QSEL= FIFO_HCCA;
10931 + pTxD->DMADONE = 0;
10932 +}
10933 +
10934 +
10935 +// should be called only when -
10936 +// 1. MEADIA_CONNECTED
10937 +// 2. AGGREGATION_IN_USED
10938 +// 3. Fragmentation not in used
10939 +// 4. either no previous frame (pPrevAddr1=NULL) .OR. previoud frame is aggregatible
10940 +BOOLEAN TxFrameIsAggregatible(
10941 + IN PRTMP_ADAPTER pAd,
10942 + IN PUCHAR pPrevAddr1,
10943 + IN PUCHAR p8023hdr)
10944 +{
10945 +
10946 + // can't aggregate EAPOL (802.1x) frame
10947 + if ((p8023hdr[12] == 0x88) && (p8023hdr[13] == 0x8e))
10948 + return FALSE;
10949 +
10950 + // can't aggregate multicast/broadcast frame
10951 + if (p8023hdr[0] & 0x01)
10952 + return FALSE;
10953 +
10954 + if (INFRA_ON(pAd)) // must be unicast to AP
10955 + return TRUE;
10956 + else if ((pPrevAddr1 == NULL) || MAC_ADDR_EQUAL(pPrevAddr1, p8023hdr)) // unicast to same STA
10957 + return TRUE;
10958 + else
10959 + return FALSE;
10960 +}
10961 +
10962 +
10963 +/*
10964 + ========================================================================
10965 +
10966 + Routine Description:
10967 + Check the MSDU Aggregation policy
10968 + 1.HT aggregation is A-MSDU
10969 + 2.legaacy rate aggregation is software aggregation by Ralink.
10970 +
10971 + Arguments:
10972 +
10973 + Return Value:
10974 +
10975 + Note:
10976 +
10977 + ========================================================================
10978 +*/
10979 +BOOLEAN PeerIsAggreOn(
10980 + IN PRTMP_ADAPTER pAd,
10981 + IN ULONG TxRate,
10982 + IN PMAC_TABLE_ENTRY pMacEntry)
10983 +{
10984 + ULONG AFlags = (fCLIENT_STATUS_AMSDU_INUSED | fCLIENT_STATUS_AGGREGATION_CAPABLE);
10985 +
10986 + if (pMacEntry != NULL && CLIENT_STATUS_TEST_FLAG(pMacEntry, AFlags))
10987 + {
10988 +#ifdef DOT11_N_SUPPORT
10989 + if (pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
10990 + {
10991 + return TRUE;
10992 + }
10993 +#endif // DOT11_N_SUPPORT //
10994 +
10995 +#ifdef AGGREGATION_SUPPORT
10996 + if (TxRate >= RATE_6 && pAd->CommonCfg.bAggregationCapable && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))))
10997 + { // legacy Ralink Aggregation support
10998 + return TRUE;
10999 + }
11000 +#endif // AGGREGATION_SUPPORT //
11001 + }
11002 +
11003 + return FALSE;
11004 +
11005 +}
11006 +
11007 +/*
11008 + ========================================================================
11009 +
11010 + Routine Description:
11011 + Check and fine the packet waiting in SW queue with highest priority
11012 +
11013 + Arguments:
11014 + pAd Pointer to our adapter
11015 +
11016 + Return Value:
11017 + pQueue Pointer to Waiting Queue
11018 +
11019 + IRQL = DISPATCH_LEVEL
11020 +
11021 + Note:
11022 +
11023 + ========================================================================
11024 +*/
11025 +PQUEUE_HEADER RTMPCheckTxSwQueue(
11026 + IN PRTMP_ADAPTER pAd,
11027 + OUT PUCHAR pQueIdx)
11028 +{
11029 +
11030 + ULONG Number;
11031 + // 2004-11-15 to be removed. test aggregation only
11032 +// if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) && (*pNumber < 2))
11033 +// return NULL;
11034 +
11035 + Number = pAd->TxSwQueue[QID_AC_BK].Number
11036 + + pAd->TxSwQueue[QID_AC_BE].Number
11037 + + pAd->TxSwQueue[QID_AC_VI].Number
11038 + + pAd->TxSwQueue[QID_AC_VO].Number
11039 + + pAd->TxSwQueue[QID_HCCA].Number;
11040 +
11041 + if (pAd->TxSwQueue[QID_AC_VO].Head != NULL)
11042 + {
11043 + *pQueIdx = QID_AC_VO;
11044 + return (&pAd->TxSwQueue[QID_AC_VO]);
11045 + }
11046 + else if (pAd->TxSwQueue[QID_AC_VI].Head != NULL)
11047 + {
11048 + *pQueIdx = QID_AC_VI;
11049 + return (&pAd->TxSwQueue[QID_AC_VI]);
11050 + }
11051 + else if (pAd->TxSwQueue[QID_AC_BE].Head != NULL)
11052 + {
11053 + *pQueIdx = QID_AC_BE;
11054 + return (&pAd->TxSwQueue[QID_AC_BE]);
11055 + }
11056 + else if (pAd->TxSwQueue[QID_AC_BK].Head != NULL)
11057 + {
11058 + *pQueIdx = QID_AC_BK;
11059 + return (&pAd->TxSwQueue[QID_AC_BK]);
11060 + }
11061 + else if (pAd->TxSwQueue[QID_HCCA].Head != NULL)
11062 + {
11063 + *pQueIdx = QID_HCCA;
11064 + return (&pAd->TxSwQueue[QID_HCCA]);
11065 + }
11066 +
11067 + // No packet pending in Tx Sw queue
11068 + *pQueIdx = QID_AC_BK;
11069 +
11070 + return (NULL);
11071 +}
11072 +
11073 +
11074 +
11075 +/*
11076 + ========================================================================
11077 +
11078 + Routine Description:
11079 + Suspend MSDU transmission
11080 +
11081 + Arguments:
11082 + pAd Pointer to our adapter
11083 +
11084 + Return Value:
11085 + None
11086 +
11087 + Note:
11088 +
11089 + ========================================================================
11090 +*/
11091 +VOID RTMPSuspendMsduTransmission(
11092 + IN PRTMP_ADAPTER pAd)
11093 +{
11094 + DBGPRINT(RT_DEBUG_TRACE,("SCANNING, suspend MSDU transmission ...\n"));
11095 +
11096 +
11097 + //
11098 + // Before BSS_SCAN_IN_PROGRESS, we need to keep Current R66 value and
11099 + // use Lowbound as R66 value on ScanNextChannel(...)
11100 + //
11101 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
11102 +
11103 + // set BBP_R66 to 0x30/0x40 when scanning (AsicSwitchChannel will set R66 according to channel when scanning)
11104 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x26 + GET_LNA_GAIN(pAd)));
11105 + RTMPSetAGCInitValue(pAd, BW_20);
11106 +
11107 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
11108 + //RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x000f0000); // abort all TX rings
11109 +}
11110 +
11111 +
11112 +/*
11113 + ========================================================================
11114 +
11115 + Routine Description:
11116 + Resume MSDU transmission
11117 +
11118 + Arguments:
11119 + pAd Pointer to our adapter
11120 +
11121 + Return Value:
11122 + None
11123 +
11124 + IRQL = DISPATCH_LEVEL
11125 +
11126 + Note:
11127 +
11128 + ========================================================================
11129 +*/
11130 +VOID RTMPResumeMsduTransmission(
11131 + IN PRTMP_ADAPTER pAd)
11132 +{
11133 +// UCHAR IrqState;
11134 +
11135 + DBGPRINT(RT_DEBUG_TRACE,("SCAN done, resume MSDU transmission ...\n"));
11136 +
11137 +
11138 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, pAd->BbpTuning.R66CurrentValue);
11139 +
11140 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
11141 +// sample, for IRQ LOCK to SEM LOCK
11142 +// IrqState = pAd->irq_disabled;
11143 +// if (IrqState)
11144 +// RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS);
11145 +// else
11146 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
11147 +}
11148 +
11149 +
11150 +UINT deaggregate_AMSDU_announce(
11151 + IN PRTMP_ADAPTER pAd,
11152 + PNDIS_PACKET pPacket,
11153 + IN PUCHAR pData,
11154 + IN ULONG DataSize)
11155 +{
11156 + USHORT PayloadSize;
11157 + USHORT SubFrameSize;
11158 + PHEADER_802_3 pAMSDUsubheader;
11159 + UINT nMSDU;
11160 + UCHAR Header802_3[14];
11161 +
11162 + PUCHAR pPayload, pDA, pSA, pRemovedLLCSNAP;
11163 + PNDIS_PACKET pClonePacket;
11164 +
11165 +
11166 +
11167 + nMSDU = 0;
11168 +
11169 + while (DataSize > LENGTH_802_3)
11170 + {
11171 +
11172 + nMSDU++;
11173 +
11174 + //hex_dump("subheader", pData, 64);
11175 + pAMSDUsubheader = (PHEADER_802_3)pData;
11176 + //pData += LENGTH_802_3;
11177 + PayloadSize = pAMSDUsubheader->Octet[1] + (pAMSDUsubheader->Octet[0]<<8);
11178 + SubFrameSize = PayloadSize + LENGTH_802_3;
11179 +
11180 +
11181 + if ((DataSize < SubFrameSize) || (PayloadSize > 1518 ))
11182 + {
11183 + break;
11184 + }
11185 +
11186 + //printk("%d subframe: Size = %d\n", nMSDU, PayloadSize);
11187 +
11188 + pPayload = pData + LENGTH_802_3;
11189 + pDA = pData;
11190 + pSA = pData + MAC_ADDR_LEN;
11191 +
11192 + // convert to 802.3 header
11193 + CONVERT_TO_802_3(Header802_3, pDA, pSA, pPayload, PayloadSize, pRemovedLLCSNAP);
11194 +
11195 +#ifdef CONFIG_STA_SUPPORT
11196 + if ((Header802_3[12] == 0x88) && (Header802_3[13] == 0x8E) )
11197 + {
11198 + // avoid local heap overflow, use dyanamic allocation
11199 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
11200 + memmove(Elem->Msg+(LENGTH_802_11 + LENGTH_802_1_H), pPayload, PayloadSize);
11201 + Elem->MsgLen = LENGTH_802_11 + LENGTH_802_1_H + PayloadSize;
11202 + WpaEAPOLKeyAction(pAd, Elem);
11203 + kfree(Elem);
11204 + }
11205 +#endif // CONFIG_STA_SUPPORT //
11206 +
11207 +#ifdef CONFIG_STA_SUPPORT
11208 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11209 + {
11210 + if (pRemovedLLCSNAP)
11211 + {
11212 + pPayload -= LENGTH_802_3;
11213 + PayloadSize += LENGTH_802_3;
11214 + NdisMoveMemory(pPayload, &Header802_3[0], LENGTH_802_3);
11215 + }
11216 + }
11217 +#endif // CONFIG_STA_SUPPORT //
11218 +
11219 + pClonePacket = ClonePacket(pAd, pPacket, pPayload, PayloadSize);
11220 + if (pClonePacket)
11221 + {
11222 +#ifdef CONFIG_STA_SUPPORT
11223 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11224 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pClonePacket, RTMP_GET_PACKET_IF(pPacket));
11225 +#endif // CONFIG_STA_SUPPORT //
11226 + }
11227 +
11228 +
11229 + // A-MSDU has padding to multiple of 4 including subframe header.
11230 + // align SubFrameSize up to multiple of 4
11231 + SubFrameSize = (SubFrameSize+3)&(~0x3);
11232 +
11233 +
11234 + if (SubFrameSize > 1528 || SubFrameSize < 32)
11235 + {
11236 + break;
11237 + }
11238 +
11239 + if (DataSize > SubFrameSize)
11240 + {
11241 + pData += SubFrameSize;
11242 + DataSize -= SubFrameSize;
11243 + }
11244 + else
11245 + {
11246 + // end of A-MSDU
11247 + DataSize = 0;
11248 + }
11249 + }
11250 +
11251 + // finally release original rx packet
11252 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
11253 +
11254 + return nMSDU;
11255 +}
11256 +
11257 +
11258 +UINT BA_Reorder_AMSDU_Annnounce(
11259 + IN PRTMP_ADAPTER pAd,
11260 + IN PNDIS_PACKET pPacket)
11261 +{
11262 + PUCHAR pData;
11263 + USHORT DataSize;
11264 + UINT nMSDU = 0;
11265 +
11266 + pData = (PUCHAR) GET_OS_PKT_DATAPTR(pPacket);
11267 + DataSize = (USHORT) GET_OS_PKT_LEN(pPacket);
11268 +
11269 + nMSDU = deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
11270 +
11271 + return nMSDU;
11272 +}
11273 +
11274 +
11275 +/*
11276 + ==========================================================================
11277 + Description:
11278 + Look up the MAC address in the MAC table. Return NULL if not found.
11279 + Return:
11280 + pEntry - pointer to the MAC entry; NULL is not found
11281 + ==========================================================================
11282 +*/
11283 +MAC_TABLE_ENTRY *MacTableLookup(
11284 + IN PRTMP_ADAPTER pAd,
11285 + PUCHAR pAddr)
11286 +{
11287 + ULONG HashIdx;
11288 + MAC_TABLE_ENTRY *pEntry = NULL;
11289 +
11290 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11291 + pEntry = pAd->MacTab.Hash[HashIdx];
11292 +
11293 + while (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsWDS || pEntry->ValidAsApCli || pEntry->ValidAsMesh))
11294 + {
11295 + if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
11296 + {
11297 + break;
11298 + }
11299 + else
11300 + pEntry = pEntry->pNext;
11301 + }
11302 +
11303 + return pEntry;
11304 +}
11305 +
11306 +MAC_TABLE_ENTRY *MacTableInsertEntry(
11307 + IN PRTMP_ADAPTER pAd,
11308 + IN PUCHAR pAddr,
11309 + IN UCHAR apidx,
11310 + IN BOOLEAN CleanAll)
11311 +{
11312 + UCHAR HashIdx;
11313 + int i, FirstWcid;
11314 + MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
11315 +
11316 + // if FULL, return
11317 + if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE)
11318 + return NULL;
11319 +
11320 + FirstWcid = 1;
11321 +#ifdef CONFIG_STA_SUPPORT
11322 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11323 + if (pAd->StaCfg.BssType == BSS_INFRA)
11324 + FirstWcid = 2;
11325 +#endif // CONFIG_STA_SUPPORT //
11326 +
11327 + // allocate one MAC entry
11328 + NdisAcquireSpinLock(&pAd->MacTabLock);
11329 + for (i = FirstWcid; i< MAX_LEN_OF_MAC_TABLE; i++) // skip entry#0 so that "entry index == AID" for fast lookup
11330 + {
11331 + // pick up the first available vacancy
11332 + if ((pAd->MacTab.Content[i].ValidAsCLI == FALSE) &&
11333 + (pAd->MacTab.Content[i].ValidAsWDS == FALSE) &&
11334 + (pAd->MacTab.Content[i].ValidAsApCli== FALSE) &&
11335 + (pAd->MacTab.Content[i].ValidAsMesh == FALSE)
11336 +#ifdef CONFIG_STA_SUPPORT
11337 +#ifdef QOS_DLS_SUPPORT
11338 + && (pAd->MacTab.Content[i].ValidAsDls == FALSE)
11339 +#endif // QOS_DLS_SUPPORT //
11340 +#endif // CONFIG_STA_SUPPORT //
11341 + )
11342 + {
11343 + pEntry = &pAd->MacTab.Content[i];
11344 + if (CleanAll == TRUE)
11345 + {
11346 + pEntry->MaxSupportedRate = RATE_11;
11347 + pEntry->CurrTxRate = RATE_11;
11348 + NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY));
11349 + pEntry->PairwiseKey.KeyLen = 0;
11350 + pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
11351 + }
11352 +#ifdef CONFIG_STA_SUPPORT
11353 +#ifdef QOS_DLS_SUPPORT
11354 + if (apidx >= MIN_NET_DEVICE_FOR_DLS)
11355 + {
11356 + pEntry->ValidAsCLI = FALSE;
11357 + pEntry->ValidAsWDS = FALSE;
11358 + pEntry->ValidAsApCli = FALSE;
11359 + pEntry->ValidAsMesh = FALSE;
11360 + pEntry->ValidAsDls = TRUE;
11361 + pEntry->isCached = FALSE;
11362 + }
11363 + else
11364 +#endif // QOS_DLS_SUPPORT //
11365 +#endif // CONFIG_STA_SUPPORT //
11366 + {
11367 +
11368 +#ifdef CONFIG_STA_SUPPORT
11369 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11370 + {
11371 + pEntry->ValidAsCLI = TRUE;
11372 + pEntry->ValidAsWDS = FALSE;
11373 + pEntry->ValidAsApCli = FALSE;
11374 + pEntry->ValidAsMesh = FALSE;
11375 + pEntry->ValidAsDls = FALSE;
11376 + }
11377 +#endif // CONFIG_STA_SUPPORT //
11378 + }
11379 +
11380 + pEntry->bIAmBadAtheros = FALSE;
11381 + pEntry->pAd = pAd;
11382 + pEntry->CMTimerRunning = FALSE;
11383 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
11384 + pEntry->RSNIE_Len = 0;
11385 + NdisZeroMemory(pEntry->R_Counter, sizeof(pEntry->R_Counter));
11386 + pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR;
11387 +
11388 + if (pEntry->ValidAsMesh)
11389 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_MESH);
11390 + else if (pEntry->ValidAsApCli)
11391 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_APCLI);
11392 + else if (pEntry->ValidAsWDS)
11393 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_WDS);
11394 +#ifdef CONFIG_STA_SUPPORT
11395 +#ifdef QOS_DLS_SUPPORT
11396 + else if (pEntry->ValidAsDls)
11397 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_DLS);
11398 +#endif // QOS_DLS_SUPPORT //
11399 +#endif // CONFIG_STA_SUPPORT //
11400 + else
11401 + pEntry->apidx = apidx;
11402 +
11403 + {
11404 +
11405 +#ifdef CONFIG_STA_SUPPORT
11406 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11407 + {
11408 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
11409 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
11410 + pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
11411 + }
11412 +#endif // CONFIG_STA_SUPPORT //
11413 + }
11414 +
11415 + pEntry->GTKState = REKEY_NEGOTIATING;
11416 + pEntry->PairwiseKey.KeyLen = 0;
11417 + pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
11418 +#ifdef CONFIG_STA_SUPPORT
11419 +#ifdef QOS_DLS_SUPPORT
11420 + if (pEntry->ValidAsDls == TRUE)
11421 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
11422 +#endif //QOS_DLS_SUPPORT
11423 +#endif // CONFIG_STA_SUPPORT //
11424 + pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED;
11425 + pEntry->PMKID_CacheIdx = ENTRY_NOT_FOUND;
11426 + COPY_MAC_ADDR(pEntry->Addr, pAddr);
11427 + pEntry->Sst = SST_NOT_AUTH;
11428 + pEntry->AuthState = AS_NOT_AUTH;
11429 + pEntry->Aid = (USHORT)i; //0;
11430 + pEntry->CapabilityInfo = 0;
11431 + pEntry->PsMode = PWR_ACTIVE;
11432 + pEntry->PsQIdleCount = 0;
11433 + pEntry->NoDataIdleCount = 0;
11434 + pEntry->ContinueTxFailCnt = 0;
11435 + InitializeQueueHeader(&pEntry->PsQueue);
11436 +
11437 +
11438 + pAd->MacTab.Size ++;
11439 + // Add this entry into ASIC RX WCID search table
11440 + RT28XX_STA_ENTRY_ADD(pAd, pEntry);
11441 +
11442 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableInsertEntry - allocate entry #%d, Total= %d\n",i, pAd->MacTab.Size));
11443 + break;
11444 + }
11445 + }
11446 +
11447 + // add this MAC entry into HASH table
11448 + if (pEntry)
11449 + {
11450 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11451 + if (pAd->MacTab.Hash[HashIdx] == NULL)
11452 + {
11453 + pAd->MacTab.Hash[HashIdx] = pEntry;
11454 + }
11455 + else
11456 + {
11457 + pCurrEntry = pAd->MacTab.Hash[HashIdx];
11458 + while (pCurrEntry->pNext != NULL)
11459 + pCurrEntry = pCurrEntry->pNext;
11460 + pCurrEntry->pNext = pEntry;
11461 + }
11462 + }
11463 +
11464 + NdisReleaseSpinLock(&pAd->MacTabLock);
11465 + return pEntry;
11466 +}
11467 +
11468 +/*
11469 + ==========================================================================
11470 + Description:
11471 + Delete a specified client from MAC table
11472 + ==========================================================================
11473 + */
11474 +BOOLEAN MacTableDeleteEntry(
11475 + IN PRTMP_ADAPTER pAd,
11476 + IN USHORT wcid,
11477 + IN PUCHAR pAddr)
11478 +{
11479 + USHORT HashIdx;
11480 + MAC_TABLE_ENTRY *pEntry, *pPrevEntry, *pProbeEntry;
11481 + BOOLEAN Cancelled;
11482 + //USHORT offset; // unused variable
11483 + //UCHAR j; // unused variable
11484 +
11485 + if (wcid >= MAX_LEN_OF_MAC_TABLE)
11486 + return FALSE;
11487 +
11488 + NdisAcquireSpinLock(&pAd->MacTabLock);
11489 +
11490 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11491 + //pEntry = pAd->MacTab.Hash[HashIdx];
11492 + pEntry = &pAd->MacTab.Content[wcid];
11493 +
11494 + if (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsApCli || pEntry->ValidAsWDS || pEntry->ValidAsMesh
11495 +#ifdef CONFIG_STA_SUPPORT
11496 +#ifdef QOS_DLS_SUPPORT
11497 + || pEntry->ValidAsDls
11498 +#endif // QOS_DLS_SUPPORT //
11499 +#endif // CONFIG_STA_SUPPORT //
11500 + ))
11501 + {
11502 + if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
11503 + {
11504 +
11505 + // Delete this entry from ASIC on-chip WCID Table
11506 + RT28XX_STA_ENTRY_MAC_RESET(pAd, wcid);
11507 +
11508 +#ifdef DOT11_N_SUPPORT
11509 + // free resources of BA
11510 + BASessionTearDownALL(pAd, pEntry->Aid);
11511 +#endif // DOT11_N_SUPPORT //
11512 +
11513 +
11514 + pPrevEntry = NULL;
11515 + pProbeEntry = pAd->MacTab.Hash[HashIdx];
11516 + ASSERT(pProbeEntry);
11517 +
11518 + // update Hash list
11519 + do
11520 + {
11521 + if (pProbeEntry == pEntry)
11522 + {
11523 + if (pPrevEntry == NULL)
11524 + {
11525 + pAd->MacTab.Hash[HashIdx] = pEntry->pNext;
11526 + }
11527 + else
11528 + {
11529 + pPrevEntry->pNext = pEntry->pNext;
11530 + }
11531 + break;
11532 + }
11533 +
11534 + pPrevEntry = pProbeEntry;
11535 + pProbeEntry = pProbeEntry->pNext;
11536 + } while (pProbeEntry);
11537 +
11538 + // not found !!!
11539 + ASSERT(pProbeEntry != NULL);
11540 +
11541 + RT28XX_STA_ENTRY_KEY_DEL(pAd, BSS0, wcid);
11542 +
11543 +
11544 + if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
11545 + {
11546 + RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
11547 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
11548 + }
11549 +
11550 +
11551 + NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY));
11552 + pAd->MacTab.Size --;
11553 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableDeleteEntry1 - Total= %d\n", pAd->MacTab.Size));
11554 + }
11555 + else
11556 + {
11557 + printk("\n%s: Impossible Wcid = %d !!!!!\n", __FUNCTION__, wcid);
11558 + }
11559 + }
11560 +
11561 + NdisReleaseSpinLock(&pAd->MacTabLock);
11562 +
11563 + //Reset operating mode when no Sta.
11564 + if (pAd->MacTab.Size == 0)
11565 + {
11566 +#ifdef DOT11_N_SUPPORT
11567 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode = 0;
11568 +#endif // DOT11_N_SUPPORT //
11569 + AsicUpdateProtect(pAd, 0 /*pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode*/, (ALLN_SETPROTECT), TRUE, 0 /*pAd->MacTab.fAnyStationNonGF*/);
11570 + }
11571 +
11572 + return TRUE;
11573 +}
11574 +
11575 +
11576 +/*
11577 + ==========================================================================
11578 + Description:
11579 + This routine reset the entire MAC table. All packets pending in
11580 + the power-saving queues are freed here.
11581 + ==========================================================================
11582 + */
11583 +VOID MacTableReset(
11584 + IN PRTMP_ADAPTER pAd)
11585 +{
11586 + int i;
11587 +
11588 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableReset\n"));
11589 + //NdisAcquireSpinLock(&pAd->MacTabLock);
11590 +
11591 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
11592 + {
11593 + if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
11594 + {
11595 +
11596 +#ifdef DOT11_N_SUPPORT
11597 + // free resources of BA
11598 + BASessionTearDownALL(pAd, i);
11599 +#endif // DOT11_N_SUPPORT //
11600 +
11601 + pAd->MacTab.Content[i].ValidAsCLI = FALSE;
11602 +
11603 +
11604 +
11605 +#ifdef RT2870
11606 + NdisZeroMemory(pAd->MacTab.Content[i].Addr, 6);
11607 + RT28XX_STA_ENTRY_MAC_RESET(pAd, i);
11608 +#endif // RT2870 //
11609 +
11610 + //AsicDelWcidTab(pAd, i);
11611 + }
11612 + }
11613 +
11614 + return;
11615 +}
11616 +
11617 +/*
11618 + ==========================================================================
11619 + Description:
11620 +
11621 + IRQL = DISPATCH_LEVEL
11622 +
11623 + ==========================================================================
11624 +*/
11625 +VOID AssocParmFill(
11626 + IN PRTMP_ADAPTER pAd,
11627 + IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
11628 + IN PUCHAR pAddr,
11629 + IN USHORT CapabilityInfo,
11630 + IN ULONG Timeout,
11631 + IN USHORT ListenIntv)
11632 +{
11633 + COPY_MAC_ADDR(AssocReq->Addr, pAddr);
11634 + // Add mask to support 802.11b mode only
11635 + AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; // not cf-pollable, not cf-poll-request
11636 + AssocReq->Timeout = Timeout;
11637 + AssocReq->ListenIntv = ListenIntv;
11638 +}
11639 +
11640 +
11641 +/*
11642 + ==========================================================================
11643 + Description:
11644 +
11645 + IRQL = DISPATCH_LEVEL
11646 +
11647 + ==========================================================================
11648 +*/
11649 +VOID DisassocParmFill(
11650 + IN PRTMP_ADAPTER pAd,
11651 + IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
11652 + IN PUCHAR pAddr,
11653 + IN USHORT Reason)
11654 +{
11655 + COPY_MAC_ADDR(DisassocReq->Addr, pAddr);
11656 + DisassocReq->Reason = Reason;
11657 +}
11658 +
11659 +
11660 +/*
11661 + ========================================================================
11662 +
11663 + Routine Description:
11664 + Check the out going frame, if this is an DHCP or ARP datagram
11665 + will be duplicate another frame at low data rate transmit.
11666 +
11667 + Arguments:
11668 + pAd Pointer to our adapter
11669 + pPacket Pointer to outgoing Ndis frame
11670 +
11671 + Return Value:
11672 + TRUE To be duplicate at Low data rate transmit. (1mb)
11673 + FALSE Do nothing.
11674 +
11675 + IRQL = DISPATCH_LEVEL
11676 +
11677 + Note:
11678 +
11679 + MAC header + IP Header + UDP Header
11680 + 14 Bytes 20 Bytes
11681 +
11682 + UDP Header
11683 + 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|
11684 + Source Port
11685 + 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|
11686 + Destination Port
11687 +
11688 + port 0x43 means Bootstrap Protocol, server.
11689 + Port 0x44 means Bootstrap Protocol, client.
11690 +
11691 + ========================================================================
11692 +*/
11693 +
11694 +BOOLEAN RTMPCheckDHCPFrame(
11695 + IN PRTMP_ADAPTER pAd,
11696 + IN PNDIS_PACKET pPacket)
11697 +{
11698 + PACKET_INFO PacketInfo;
11699 + ULONG NumberOfBytesRead = 0;
11700 + ULONG CurrentOffset = 0;
11701 + PVOID pVirtualAddress = NULL;
11702 + UINT NdisBufferLength;
11703 + PUCHAR pSrc;
11704 + USHORT Protocol;
11705 + UCHAR ByteOffset36 = 0;
11706 + UCHAR ByteOffset38 = 0;
11707 + BOOLEAN ReadFirstParm = TRUE;
11708 +
11709 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, (PUCHAR *)&pVirtualAddress, &NdisBufferLength);
11710 +
11711 + NumberOfBytesRead += NdisBufferLength;
11712 + pSrc = (PUCHAR) pVirtualAddress;
11713 + Protocol = *(pSrc + 12) * 256 + *(pSrc + 13);
11714 +
11715 + //
11716 + // Check DHCP & BOOTP protocol
11717 + //
11718 + while (NumberOfBytesRead <= PacketInfo.TotalPacketLength)
11719 + {
11720 + if ((NumberOfBytesRead >= 35) && (ReadFirstParm == TRUE))
11721 + {
11722 + CurrentOffset = 35 - (NumberOfBytesRead - NdisBufferLength);
11723 + ByteOffset36 = *(pSrc + CurrentOffset);
11724 + ReadFirstParm = FALSE;
11725 + }
11726 +
11727 + if (NumberOfBytesRead >= 37)
11728 + {
11729 + CurrentOffset = 37 - (NumberOfBytesRead - NdisBufferLength);
11730 + ByteOffset38 = *(pSrc + CurrentOffset);
11731 + //End of Read
11732 + break;
11733 + }
11734 + return FALSE;
11735 + }
11736 +
11737 + // Check for DHCP & BOOTP protocol
11738 + if ((ByteOffset36 != 0x44) || (ByteOffset38 != 0x43))
11739 + {
11740 + //
11741 + // 2054 (hex 0806) for ARP datagrams
11742 + // if this packet is not ARP datagrams, then do nothing
11743 + // ARP datagrams will also be duplicate at 1mb broadcast frames
11744 + //
11745 + if (Protocol != 0x0806 )
11746 + return FALSE;
11747 + }
11748 +
11749 + return TRUE;
11750 +}
11751 +
11752 +
11753 +BOOLEAN RTMPCheckEtherType(
11754 + IN PRTMP_ADAPTER pAd,
11755 + IN PNDIS_PACKET pPacket)
11756 +{
11757 + USHORT TypeLen;
11758 + UCHAR Byte0, Byte1;
11759 + PUCHAR pSrcBuf;
11760 + UINT32 pktLen;
11761 + UINT16 srcPort, dstPort;
11762 + BOOLEAN status = TRUE;
11763 +
11764 +
11765 + pSrcBuf = GET_OS_PKT_DATAPTR(pPacket);
11766 + pktLen = GET_OS_PKT_LEN(pPacket);
11767 +
11768 + ASSERT(pSrcBuf);
11769 +
11770 + RTMP_SET_PACKET_SPECIFIC(pPacket, 0);
11771 +
11772 + // get Ethernet protocol field
11773 + TypeLen = (pSrcBuf[12] << 8) + pSrcBuf[13];
11774 +
11775 + pSrcBuf += LENGTH_802_3; // Skip the Ethernet Header.
11776 +
11777 + if (TypeLen <= 1500)
11778 + { // 802.3, 802.3 LLC
11779 + /*
11780 + DestMAC(6) + SrcMAC(6) + Lenght(2) +
11781 + DSAP(1) + SSAP(1) + Control(1) +
11782 + if the DSAP = 0xAA, SSAP=0xAA, Contorl = 0x03, it has a 5-bytes SNAP header.
11783 + => + SNAP (5, OriginationID(3) + etherType(2))
11784 + */
11785 + if (pSrcBuf[0] == 0xAA && pSrcBuf[1] == 0xAA && pSrcBuf[2] == 0x03)
11786 + {
11787 + Sniff2BytesFromNdisBuffer(pSrcBuf, 6, &Byte0, &Byte1);
11788 + RTMP_SET_PACKET_LLCSNAP(pPacket, 1);
11789 + TypeLen = (USHORT)((Byte0 << 8) + Byte1);
11790 + pSrcBuf += 8; // Skip this LLC/SNAP header
11791 + }
11792 + else
11793 + {
11794 + //It just has 3-byte LLC header, maybe a legacy ether type frame. we didn't handle it.
11795 + }
11796 + }
11797 +
11798 + // If it's a VLAN packet, get the real Type/Length field.
11799 + if (TypeLen == 0x8100)
11800 + {
11801 + /* 0x8100 means VLAN packets */
11802 +
11803 + /* Dest. MAC Address (6-bytes) +
11804 + Source MAC Address (6-bytes) +
11805 + Length/Type = 802.1Q Tag Type (2-byte) +
11806 + Tag Control Information (2-bytes) +
11807 + Length / Type (2-bytes) +
11808 + data payload (0-n bytes) +
11809 + Pad (0-p bytes) +
11810 + Frame Check Sequence (4-bytes) */
11811 +
11812 + RTMP_SET_PACKET_VLAN(pPacket, 1);
11813 + Sniff2BytesFromNdisBuffer(pSrcBuf, 2, &Byte0, &Byte1);
11814 + TypeLen = (USHORT)((Byte0 << 8) + Byte1);
11815 +
11816 + pSrcBuf += 4; // Skip the VLAN Header.
11817 + }
11818 +
11819 + switch (TypeLen)
11820 + {
11821 + case 0x0800:
11822 + {
11823 + ASSERT((pktLen > 34));
11824 + if (*(pSrcBuf + 9) == 0x11)
11825 + { // udp packet
11826 + ASSERT((pktLen > 34)); // 14 for ethernet header, 20 for IP header
11827 +
11828 + pSrcBuf += 20; // Skip the IP header
11829 + srcPort = OS_NTOHS(*((UINT16 *)pSrcBuf));
11830 + dstPort = OS_NTOHS(*((UINT16 *)(pSrcBuf +2)));
11831 +
11832 + if ((srcPort==0x44 && dstPort==0x43) || (srcPort==0x43 && dstPort==0x44))
11833 + { //It's a BOOTP/DHCP packet
11834 + RTMP_SET_PACKET_DHCP(pPacket, 1);
11835 + }
11836 + }
11837 + }
11838 + break;
11839 + case 0x0806:
11840 + {
11841 + //ARP Packet.
11842 + RTMP_SET_PACKET_DHCP(pPacket, 1);
11843 + }
11844 + break;
11845 + case 0x888e:
11846 + {
11847 + // EAPOL Packet.
11848 + RTMP_SET_PACKET_EAPOL(pPacket, 1);
11849 + }
11850 + break;
11851 + default:
11852 + status = FALSE;
11853 + break;
11854 + }
11855 +
11856 + return status;
11857 +
11858 +}
11859 +
11860 +
11861 +
11862 +VOID Update_Rssi_Sample(
11863 + IN PRTMP_ADAPTER pAd,
11864 + IN RSSI_SAMPLE *pRssi,
11865 + IN PRXWI_STRUC pRxWI)
11866 + {
11867 + CHAR rssi0 = pRxWI->RSSI0;
11868 + CHAR rssi1 = pRxWI->RSSI1;
11869 + CHAR rssi2 = pRxWI->RSSI2;
11870 +
11871 + if (rssi0 != 0)
11872 + {
11873 + pRssi->LastRssi0 = ConvertToRssi(pAd, (CHAR)rssi0, RSSI_0);
11874 + pRssi->AvgRssi0X8 = (pRssi->AvgRssi0X8 - pRssi->AvgRssi0) + pRssi->LastRssi0;
11875 + pRssi->AvgRssi0 = pRssi->AvgRssi0X8 >> 3;
11876 + }
11877 +
11878 + if (rssi1 != 0)
11879 + {
11880 + pRssi->LastRssi1 = ConvertToRssi(pAd, (CHAR)rssi1, RSSI_1);
11881 + pRssi->AvgRssi1X8 = (pRssi->AvgRssi1X8 - pRssi->AvgRssi1) + pRssi->LastRssi1;
11882 + pRssi->AvgRssi1 = pRssi->AvgRssi1X8 >> 3;
11883 + }
11884 +
11885 + if (rssi2 != 0)
11886 + {
11887 + pRssi->LastRssi2 = ConvertToRssi(pAd, (CHAR)rssi2, RSSI_2);
11888 + pRssi->AvgRssi2X8 = (pRssi->AvgRssi2X8 - pRssi->AvgRssi2) + pRssi->LastRssi2;
11889 + pRssi->AvgRssi2 = pRssi->AvgRssi2X8 >> 3;
11890 + }
11891 +}
11892 +
11893 +
11894 +
11895 +// Normal legacy Rx packet indication
11896 +VOID Indicate_Legacy_Packet(
11897 + IN PRTMP_ADAPTER pAd,
11898 + IN RX_BLK *pRxBlk,
11899 + IN UCHAR FromWhichBSSID)
11900 +{
11901 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
11902 + UCHAR Header802_3[LENGTH_802_3];
11903 +
11904 + // 1. get 802.3 Header
11905 + // 2. remove LLC
11906 + // a. pointer pRxBlk->pData to payload
11907 + // b. modify pRxBlk->DataSize
11908 +#ifdef CONFIG_STA_SUPPORT
11909 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11910 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
11911 +#endif // CONFIG_STA_SUPPORT //
11912 +
11913 + if (pRxBlk->DataSize > MAX_RX_PKT_LEN)
11914 + {
11915 +#if 0 // sample take off, for multiple card design
11916 + static int err_size;
11917 +
11918 + err_size++;
11919 + if (err_size > 20)
11920 + {
11921 + printk("Legacy DataSize = %d\n", pRxBlk->DataSize);
11922 + hex_dump("802.3 Header", Header802_3, LENGTH_802_3);
11923 + hex_dump("Payload", pRxBlk->pData, 64);
11924 + err_size = 0;
11925 + }
11926 +#endif
11927 +
11928 + // release packet
11929 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
11930 + return;
11931 + }
11932 +
11933 +
11934 + STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
11935 +
11936 +#ifdef RT2870
11937 +#ifdef DOT11_N_SUPPORT
11938 + if (pAd->CommonCfg.bDisableReordering == 0)
11939 + {
11940 + PBA_REC_ENTRY pBAEntry;
11941 + ULONG Now32;
11942 + UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID;
11943 + UCHAR TID = pRxBlk->pRxWI->TID;
11944 + USHORT Idx;
11945 +
11946 +#define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms
11947 +
11948 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
11949 + {
11950 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
11951 + if (Idx != 0)
11952 + {
11953 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
11954 + // update last rx time
11955 + NdisGetSystemUpTime(&Now32);
11956 + if ((pBAEntry->list.qlen > 0) &&
11957 + RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT)))
11958 + )
11959 + {
11960 + 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);
11961 + hex_dump("Dump the legacy Packet:", GET_OS_PKT_DATAPTR(pRxBlk->pRxPacket), 64);
11962 + ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32);
11963 + }
11964 + }
11965 + }
11966 + }
11967 +#endif // DOT11_N_SUPPORT //
11968 +#endif // RT2870 //
11969 +
11970 + wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
11971 +
11972 + //
11973 + // pass this 802.3 packet to upper layer or forward this packet to WM directly
11974 + //
11975 +#ifdef CONFIG_STA_SUPPORT
11976 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11977 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxPacket, FromWhichBSSID);
11978 +#endif // CONFIG_STA_SUPPORT //
11979 +
11980 +}
11981 +
11982 +
11983 +// Normal, AMPDU or AMSDU
11984 +VOID CmmRxnonRalinkFrameIndicate(
11985 + IN PRTMP_ADAPTER pAd,
11986 + IN RX_BLK *pRxBlk,
11987 + IN UCHAR FromWhichBSSID)
11988 +{
11989 +#ifdef DOT11_N_SUPPORT
11990 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))
11991 + {
11992 + Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
11993 + }
11994 + else
11995 +#endif // DOT11_N_SUPPORT //
11996 + {
11997 +#ifdef DOT11_N_SUPPORT
11998 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU))
11999 + {
12000 + // handle A-MSDU
12001 + Indicate_AMSDU_Packet(pAd, pRxBlk, FromWhichBSSID);
12002 + }
12003 + else
12004 +#endif // DOT11_N_SUPPORT //
12005 + {
12006 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
12007 + }
12008 + }
12009 +}
12010 +
12011 +
12012 +VOID CmmRxRalinkFrameIndicate(
12013 + IN PRTMP_ADAPTER pAd,
12014 + IN MAC_TABLE_ENTRY *pEntry,
12015 + IN RX_BLK *pRxBlk,
12016 + IN UCHAR FromWhichBSSID)
12017 +{
12018 + UCHAR Header802_3[LENGTH_802_3];
12019 + UINT16 Msdu2Size;
12020 + UINT16 Payload1Size, Payload2Size;
12021 + PUCHAR pData2;
12022 + PNDIS_PACKET pPacket2 = NULL;
12023 +
12024 +
12025 +
12026 + Msdu2Size = *(pRxBlk->pData) + (*(pRxBlk->pData+1) << 8);
12027 +
12028 + if ((Msdu2Size <= 1536) && (Msdu2Size < pRxBlk->DataSize))
12029 + {
12030 + /* skip two byte MSDU2 len */
12031 + pRxBlk->pData += 2;
12032 + pRxBlk->DataSize -= 2;
12033 + }
12034 + else
12035 + {
12036 + // release packet
12037 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12038 + return;
12039 + }
12040 +
12041 + // get 802.3 Header and remove LLC
12042 +#ifdef CONFIG_STA_SUPPORT
12043 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12044 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
12045 +#endif // CONFIG_STA_SUPPORT //
12046 +
12047 +
12048 + ASSERT(pRxBlk->pRxPacket);
12049 +
12050 + // Ralink Aggregation frame
12051 + pAd->RalinkCounters.OneSecRxAggregationCount ++;
12052 + Payload1Size = pRxBlk->DataSize - Msdu2Size;
12053 + Payload2Size = Msdu2Size - LENGTH_802_3;
12054 +
12055 + pData2 = pRxBlk->pData + Payload1Size + LENGTH_802_3;
12056 +#ifdef CONFIG_STA_SUPPORT
12057 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12058 + pPacket2 = duplicate_pkt(pAd, (pData2-LENGTH_802_3), LENGTH_802_3, pData2, Payload2Size, FromWhichBSSID);
12059 +#endif // CONFIG_STA_SUPPORT //
12060 +
12061 + if (!pPacket2)
12062 + {
12063 + // release packet
12064 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12065 + return;
12066 + }
12067 +
12068 + // update payload size of 1st packet
12069 + pRxBlk->DataSize = Payload1Size;
12070 + wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
12071 +
12072 +#ifdef CONFIG_STA_SUPPORT
12073 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12074 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxBlk->pRxPacket, FromWhichBSSID);
12075 +#endif // CONFIG_STA_SUPPORT //
12076 +
12077 + if (pPacket2)
12078 + {
12079 +#ifdef CONFIG_STA_SUPPORT
12080 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12081 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket2, FromWhichBSSID);
12082 +#endif // CONFIG_STA_SUPPORT //
12083 + }
12084 +}
12085 +
12086 +
12087 +#define RESET_FRAGFRAME(_fragFrame) \
12088 + { \
12089 + _fragFrame.RxSize = 0; \
12090 + _fragFrame.Sequence = 0; \
12091 + _fragFrame.LastFrag = 0; \
12092 + _fragFrame.Flags = 0; \
12093 + }
12094 +
12095 +
12096 +PNDIS_PACKET RTMPDeFragmentDataFrame(
12097 + IN PRTMP_ADAPTER pAd,
12098 + IN RX_BLK *pRxBlk)
12099 +{
12100 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
12101 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
12102 + UCHAR *pData = pRxBlk->pData;
12103 + USHORT DataSize = pRxBlk->DataSize;
12104 + PNDIS_PACKET pRetPacket = NULL;
12105 + UCHAR *pFragBuffer = NULL;
12106 + BOOLEAN bReassDone = FALSE;
12107 + UCHAR HeaderRoom = 0;
12108 +
12109 +
12110 + ASSERT(pHeader);
12111 +
12112 + HeaderRoom = pData - (UCHAR *)pHeader;
12113 +
12114 + // Re-assemble the fragmented packets
12115 + if (pHeader->Frag == 0) // Frag. Number is 0 : First frag or only one pkt
12116 + {
12117 + // the first pkt of fragment, record it.
12118 + if (pHeader->FC.MoreFrag)
12119 + {
12120 + ASSERT(pAd->FragFrame.pFragPacket);
12121 + pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
12122 + pAd->FragFrame.RxSize = DataSize + HeaderRoom;
12123 + NdisMoveMemory(pFragBuffer, pHeader, pAd->FragFrame.RxSize);
12124 + pAd->FragFrame.Sequence = pHeader->Sequence;
12125 + pAd->FragFrame.LastFrag = pHeader->Frag; // Should be 0
12126 + ASSERT(pAd->FragFrame.LastFrag == 0);
12127 + goto done; // end of processing this frame
12128 + }
12129 + }
12130 + else //Middle & End of fragment
12131 + {
12132 + if ((pHeader->Sequence != pAd->FragFrame.Sequence) ||
12133 + (pHeader->Frag != (pAd->FragFrame.LastFrag + 1)))
12134 + {
12135 + // Fragment is not the same sequence or out of fragment number order
12136 + // Reset Fragment control blk
12137 + RESET_FRAGFRAME(pAd->FragFrame);
12138 + DBGPRINT(RT_DEBUG_ERROR, ("Fragment is not the same sequence or out of fragment number order.\n"));
12139 + goto done; // give up this frame
12140 + }
12141 + else if ((pAd->FragFrame.RxSize + DataSize) > MAX_FRAME_SIZE)
12142 + {
12143 + // Fragment frame is too large, it exeeds the maximum frame size.
12144 + // Reset Fragment control blk
12145 + RESET_FRAGFRAME(pAd->FragFrame);
12146 + DBGPRINT(RT_DEBUG_ERROR, ("Fragment frame is too large, it exeeds the maximum frame size.\n"));
12147 + goto done; // give up this frame
12148 + }
12149 +
12150 + //
12151 + // Broadcom AP(BCM94704AGR) will send out LLC in fragment's packet, LLC only can accpet at first fragment.
12152 + // In this case, we will dropt it.
12153 + //
12154 + if (NdisEqualMemory(pData, SNAP_802_1H, sizeof(SNAP_802_1H)))
12155 + {
12156 + DBGPRINT(RT_DEBUG_ERROR, ("Find another LLC at Middle or End fragment(SN=%d, Frag=%d)\n", pHeader->Sequence, pHeader->Frag));
12157 + goto done; // give up this frame
12158 + }
12159 +
12160 + pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
12161 +
12162 + // concatenate this fragment into the re-assembly buffer
12163 + NdisMoveMemory((pFragBuffer + pAd->FragFrame.RxSize), pData, DataSize);
12164 + pAd->FragFrame.RxSize += DataSize;
12165 + pAd->FragFrame.LastFrag = pHeader->Frag; // Update fragment number
12166 +
12167 + // Last fragment
12168 + if (pHeader->FC.MoreFrag == FALSE)
12169 + {
12170 + bReassDone = TRUE;
12171 + }
12172 + }
12173 +
12174 +done:
12175 + // always release rx fragmented packet
12176 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
12177 +
12178 + // return defragmented packet if packet is reassembled completely
12179 + // otherwise return NULL
12180 + if (bReassDone)
12181 + {
12182 + PNDIS_PACKET pNewFragPacket;
12183 +
12184 + // allocate a new packet buffer for fragment
12185 + pNewFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
12186 + if (pNewFragPacket)
12187 + {
12188 + // update RxBlk
12189 + pRetPacket = pAd->FragFrame.pFragPacket;
12190 + pAd->FragFrame.pFragPacket = pNewFragPacket;
12191 + pRxBlk->pHeader = (PHEADER_802_11) GET_OS_PKT_DATAPTR(pRetPacket);
12192 + pRxBlk->pData = (UCHAR *)pRxBlk->pHeader + HeaderRoom;
12193 + pRxBlk->DataSize = pAd->FragFrame.RxSize - HeaderRoom;
12194 + pRxBlk->pRxPacket = pRetPacket;
12195 + }
12196 + else
12197 + {
12198 + RESET_FRAGFRAME(pAd->FragFrame);
12199 + }
12200 + }
12201 +
12202 + return pRetPacket;
12203 +}
12204 +
12205 +
12206 +VOID Indicate_AMSDU_Packet(
12207 + IN PRTMP_ADAPTER pAd,
12208 + IN RX_BLK *pRxBlk,
12209 + IN UCHAR FromWhichBSSID)
12210 +{
12211 + UINT nMSDU;
12212 +
12213 + update_os_packet_info(pAd, pRxBlk, FromWhichBSSID);
12214 + RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
12215 + nMSDU = deaggregate_AMSDU_announce(pAd, pRxBlk->pRxPacket, pRxBlk->pData, pRxBlk->DataSize);
12216 +}
12217 +
12218 +VOID Indicate_EAPOL_Packet(
12219 + IN PRTMP_ADAPTER pAd,
12220 + IN RX_BLK *pRxBlk,
12221 + IN UCHAR FromWhichBSSID)
12222 +{
12223 + MAC_TABLE_ENTRY *pEntry = NULL;
12224 +
12225 +
12226 +#ifdef CONFIG_STA_SUPPORT
12227 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12228 + {
12229 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
12230 + STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
12231 + return;
12232 + }
12233 +#endif // CONFIG_STA_SUPPORT //
12234 +
12235 + if (pEntry == NULL)
12236 + {
12237 + DBGPRINT(RT_DEBUG_WARN, ("Indicate_EAPOL_Packet: drop and release the invalid packet.\n"));
12238 + // release packet
12239 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12240 + return;
12241 + }
12242 +}
12243 +
12244 +#define BCN_TBTT_OFFSET 64 //defer 64 us
12245 +VOID ReSyncBeaconTime(
12246 + IN PRTMP_ADAPTER pAd)
12247 +{
12248 +
12249 + UINT32 Offset;
12250 +
12251 +
12252 + Offset = (pAd->TbttTickCount) % (BCN_TBTT_OFFSET);
12253 +
12254 + pAd->TbttTickCount++;
12255 +
12256 + //
12257 + // The updated BeaconInterval Value will affect Beacon Interval after two TBTT
12258 + // beacasue the original BeaconInterval had been loaded into next TBTT_TIMER
12259 + //
12260 + if (Offset == (BCN_TBTT_OFFSET-2))
12261 + {
12262 + BCN_TIME_CFG_STRUC csr;
12263 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
12264 + csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod << 4) - 1 ; // ASIC register in units of 1/16 TU = 64us
12265 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
12266 + }
12267 + else
12268 + {
12269 + if (Offset == (BCN_TBTT_OFFSET-1))
12270 + {
12271 + BCN_TIME_CFG_STRUC csr;
12272 +
12273 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
12274 + csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod) << 4; // ASIC register in units of 1/16 TU
12275 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
12276 + }
12277 + }
12278 +}
12279 +
12280 --- /dev/null
12281 +++ b/drivers/staging/rt2870/common/cmm_info.c
12282 @@ -0,0 +1,3712 @@
12283 +/*
12284 + *************************************************************************
12285 + * Ralink Tech Inc.
12286 + * 5F., No.36, Taiyuan St., Jhubei City,
12287 + * Hsinchu County 302,
12288 + * Taiwan, R.O.C.
12289 + *
12290 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
12291 + *
12292 + * This program is free software; you can redistribute it and/or modify *
12293 + * it under the terms of the GNU General Public License as published by *
12294 + * the Free Software Foundation; either version 2 of the License, or *
12295 + * (at your option) any later version. *
12296 + * *
12297 + * This program is distributed in the hope that it will be useful, *
12298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12300 + * GNU General Public License for more details. *
12301 + * *
12302 + * You should have received a copy of the GNU General Public License *
12303 + * along with this program; if not, write to the *
12304 + * Free Software Foundation, Inc., *
12305 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
12306 + * *
12307 + *************************************************************************
12308 +*/
12309 +
12310 +#include "../rt_config.h"
12311 +
12312 +INT Show_SSID_Proc(
12313 + IN PRTMP_ADAPTER pAd,
12314 + OUT PUCHAR pBuf);
12315 +
12316 +INT Show_WirelessMode_Proc(
12317 + IN PRTMP_ADAPTER pAd,
12318 + OUT PUCHAR pBuf);
12319 +
12320 +INT Show_TxBurst_Proc(
12321 + IN PRTMP_ADAPTER pAd,
12322 + OUT PUCHAR pBuf);
12323 +
12324 +INT Show_TxPreamble_Proc(
12325 + IN PRTMP_ADAPTER pAd,
12326 + OUT PUCHAR pBuf);
12327 +
12328 +INT Show_TxPower_Proc(
12329 + IN PRTMP_ADAPTER pAd,
12330 + OUT PUCHAR pBuf);
12331 +
12332 +INT Show_Channel_Proc(
12333 + IN PRTMP_ADAPTER pAd,
12334 + OUT PUCHAR pBuf);
12335 +
12336 +INT Show_BGProtection_Proc(
12337 + IN PRTMP_ADAPTER pAd,
12338 + OUT PUCHAR pBuf);
12339 +
12340 +INT Show_RTSThreshold_Proc(
12341 + IN PRTMP_ADAPTER pAd,
12342 + OUT PUCHAR pBuf);
12343 +
12344 +INT Show_FragThreshold_Proc(
12345 + IN PRTMP_ADAPTER pAd,
12346 + OUT PUCHAR pBuf);
12347 +
12348 +#ifdef DOT11_N_SUPPORT
12349 +INT Show_HtBw_Proc(
12350 + IN PRTMP_ADAPTER pAd,
12351 + OUT PUCHAR pBuf);
12352 +
12353 +INT Show_HtMcs_Proc(
12354 + IN PRTMP_ADAPTER pAd,
12355 + OUT PUCHAR pBuf);
12356 +
12357 +INT Show_HtGi_Proc(
12358 + IN PRTMP_ADAPTER pAd,
12359 + OUT PUCHAR pBuf);
12360 +
12361 +INT Show_HtOpMode_Proc(
12362 + IN PRTMP_ADAPTER pAd,
12363 + OUT PUCHAR pBuf);
12364 +
12365 +INT Show_HtExtcha_Proc(
12366 + IN PRTMP_ADAPTER pAd,
12367 + OUT PUCHAR pBuf);
12368 +
12369 +INT Show_HtMpduDensity_Proc(
12370 + IN PRTMP_ADAPTER pAd,
12371 + OUT PUCHAR pBuf);
12372 +
12373 +INT Show_HtBaWinSize_Proc(
12374 + IN PRTMP_ADAPTER pAd,
12375 + OUT PUCHAR pBuf);
12376 +
12377 +INT Show_HtRdg_Proc(
12378 + IN PRTMP_ADAPTER pAd,
12379 + OUT PUCHAR pBuf);
12380 +
12381 +INT Show_HtAmsdu_Proc(
12382 + IN PRTMP_ADAPTER pAd,
12383 + OUT PUCHAR pBuf);
12384 +
12385 +INT Show_HtAutoBa_Proc(
12386 + IN PRTMP_ADAPTER pAd,
12387 + OUT PUCHAR pBuf);
12388 +#endif // DOT11_N_SUPPORT //
12389 +
12390 +INT Show_CountryRegion_Proc(
12391 + IN PRTMP_ADAPTER pAd,
12392 + OUT PUCHAR pBuf);
12393 +
12394 +INT Show_CountryRegionABand_Proc(
12395 + IN PRTMP_ADAPTER pAd,
12396 + OUT PUCHAR pBuf);
12397 +
12398 +INT Show_CountryCode_Proc(
12399 + IN PRTMP_ADAPTER pAd,
12400 + OUT PUCHAR pBuf);
12401 +
12402 +#ifdef AGGREGATION_SUPPORT
12403 +INT Show_PktAggregate_Proc(
12404 + IN PRTMP_ADAPTER pAd,
12405 + OUT PUCHAR pBuf);
12406 +#endif // AGGREGATION_SUPPORT //
12407 +
12408 +#ifdef WMM_SUPPORT
12409 +INT Show_WmmCapable_Proc(
12410 + IN PRTMP_ADAPTER pAd,
12411 + OUT PUCHAR pBuf);
12412 +#endif // WMM_SUPPORT //
12413 +
12414 +INT Show_IEEE80211H_Proc(
12415 + IN PRTMP_ADAPTER pAd,
12416 + OUT PUCHAR pBuf);
12417 +
12418 +#ifdef CONFIG_STA_SUPPORT
12419 +INT Show_NetworkType_Proc(
12420 + IN PRTMP_ADAPTER pAd,
12421 + OUT PUCHAR pBuf);
12422 +#endif // CONFIG_STA_SUPPORT //
12423 +
12424 +INT Show_AuthMode_Proc(
12425 + IN PRTMP_ADAPTER pAd,
12426 + OUT PUCHAR pBuf);
12427 +
12428 +INT Show_EncrypType_Proc(
12429 + IN PRTMP_ADAPTER pAd,
12430 + OUT PUCHAR pBuf);
12431 +
12432 +INT Show_DefaultKeyID_Proc(
12433 + IN PRTMP_ADAPTER pAd,
12434 + OUT PUCHAR pBuf);
12435 +
12436 +INT Show_Key1_Proc(
12437 + IN PRTMP_ADAPTER pAd,
12438 + OUT PUCHAR pBuf);
12439 +
12440 +INT Show_Key2_Proc(
12441 + IN PRTMP_ADAPTER pAd,
12442 + OUT PUCHAR pBuf);
12443 +
12444 +INT Show_Key3_Proc(
12445 + IN PRTMP_ADAPTER pAd,
12446 + OUT PUCHAR pBuf);
12447 +
12448 +INT Show_Key4_Proc(
12449 + IN PRTMP_ADAPTER pAd,
12450 + OUT PUCHAR pBuf);
12451 +
12452 +INT Show_WPAPSK_Proc(
12453 + IN PRTMP_ADAPTER pAd,
12454 + OUT PUCHAR pBuf);
12455 +
12456 +static struct {
12457 + CHAR *name;
12458 + INT (*show_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
12459 +} *PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC, RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC[] = {
12460 + {"SSID", Show_SSID_Proc},
12461 + {"WirelessMode", Show_WirelessMode_Proc},
12462 + {"TxBurst", Show_TxBurst_Proc},
12463 + {"TxPreamble", Show_TxPreamble_Proc},
12464 + {"TxPower", Show_TxPower_Proc},
12465 + {"Channel", Show_Channel_Proc},
12466 + {"BGProtection", Show_BGProtection_Proc},
12467 + {"RTSThreshold", Show_RTSThreshold_Proc},
12468 + {"FragThreshold", Show_FragThreshold_Proc},
12469 +#ifdef DOT11_N_SUPPORT
12470 + {"HtBw", Show_HtBw_Proc},
12471 + {"HtMcs", Show_HtMcs_Proc},
12472 + {"HtGi", Show_HtGi_Proc},
12473 + {"HtOpMode", Show_HtOpMode_Proc},
12474 + {"HtExtcha", Show_HtExtcha_Proc},
12475 + {"HtMpduDensity", Show_HtMpduDensity_Proc},
12476 + {"HtBaWinSize", Show_HtBaWinSize_Proc},
12477 + {"HtRdg", Show_HtRdg_Proc},
12478 + {"HtAmsdu", Show_HtAmsdu_Proc},
12479 + {"HtAutoBa", Show_HtAutoBa_Proc},
12480 +#endif // DOT11_N_SUPPORT //
12481 + {"CountryRegion", Show_CountryRegion_Proc},
12482 + {"CountryRegionABand", Show_CountryRegionABand_Proc},
12483 + {"CountryCode", Show_CountryCode_Proc},
12484 +#ifdef AGGREGATION_SUPPORT
12485 + {"PktAggregate", Show_PktAggregate_Proc},
12486 +#endif
12487 +
12488 +#ifdef WMM_SUPPORT
12489 + {"WmmCapable", Show_WmmCapable_Proc},
12490 +#endif
12491 + {"IEEE80211H", Show_IEEE80211H_Proc},
12492 +#ifdef CONFIG_STA_SUPPORT
12493 + {"NetworkType", Show_NetworkType_Proc},
12494 +#endif // CONFIG_STA_SUPPORT //
12495 + {"AuthMode", Show_AuthMode_Proc},
12496 + {"EncrypType", Show_EncrypType_Proc},
12497 + {"DefaultKeyID", Show_DefaultKeyID_Proc},
12498 + {"Key1", Show_Key1_Proc},
12499 + {"Key2", Show_Key2_Proc},
12500 + {"Key3", Show_Key3_Proc},
12501 + {"Key4", Show_Key4_Proc},
12502 + {"WPAPSK", Show_WPAPSK_Proc},
12503 + {NULL, NULL}
12504 +};
12505 +
12506 +/*
12507 + ==========================================================================
12508 + Description:
12509 + Get Driver version.
12510 +
12511 + Return:
12512 + ==========================================================================
12513 +*/
12514 +INT Set_DriverVersion_Proc(
12515 + IN PRTMP_ADAPTER pAd,
12516 + IN PUCHAR arg)
12517 +{
12518 +
12519 +#ifdef CONFIG_STA_SUPPORT
12520 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12521 + DBGPRINT(RT_DEBUG_TRACE, ("Driver version-%s\n", STA_DRIVER_VERSION));
12522 +#endif // CONFIG_STA_SUPPORT //
12523 +
12524 + return TRUE;
12525 +}
12526 +
12527 +/*
12528 + ==========================================================================
12529 + Description:
12530 + Set Country Region.
12531 + This command will not work, if the field of CountryRegion in eeprom is programmed.
12532 + Return:
12533 + TRUE if all parameters are OK, FALSE otherwise
12534 + ==========================================================================
12535 +*/
12536 +INT Set_CountryRegion_Proc(
12537 + IN PRTMP_ADAPTER pAd,
12538 + IN PUCHAR arg)
12539 +{
12540 + ULONG region;
12541 +
12542 + region = simple_strtol(arg, 0, 10);
12543 +
12544 +#ifdef EXT_BUILD_CHANNEL_LIST
12545 + return -EOPNOTSUPP;
12546 +#endif // EXT_BUILD_CHANNEL_LIST //
12547 +
12548 + // Country can be set only when EEPROM not programmed
12549 + if (pAd->CommonCfg.CountryRegion & 0x80)
12550 + {
12551 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n"));
12552 + return FALSE;
12553 + }
12554 +
12555 + if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND))
12556 + {
12557 + pAd->CommonCfg.CountryRegion = (UCHAR) region;
12558 + }
12559 + else if (region == REGION_31_BG_BAND)
12560 + {
12561 + pAd->CommonCfg.CountryRegion = (UCHAR) region;
12562 + }
12563 + else
12564 + {
12565 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n"));
12566 + return FALSE;
12567 + }
12568 +
12569 + // if set country region, driver needs to be reset
12570 + BuildChannelList(pAd);
12571 +
12572 + DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegion));
12573 +
12574 + return TRUE;
12575 +}
12576 +
12577 +/*
12578 + ==========================================================================
12579 + Description:
12580 + Set Country Region for A band.
12581 + This command will not work, if the field of CountryRegion in eeprom is programmed.
12582 + Return:
12583 + TRUE if all parameters are OK, FALSE otherwise
12584 + ==========================================================================
12585 +*/
12586 +INT Set_CountryRegionABand_Proc(
12587 + IN PRTMP_ADAPTER pAd,
12588 + IN PUCHAR arg)
12589 +{
12590 + ULONG region;
12591 +
12592 + region = simple_strtol(arg, 0, 10);
12593 +
12594 +#ifdef EXT_BUILD_CHANNEL_LIST
12595 + return -EOPNOTSUPP;
12596 +#endif // EXT_BUILD_CHANNEL_LIST //
12597 +
12598 + // Country can be set only when EEPROM not programmed
12599 + if (pAd->CommonCfg.CountryRegionForABand & 0x80)
12600 + {
12601 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n"));
12602 + return FALSE;
12603 + }
12604 +
12605 + if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND))
12606 + {
12607 + pAd->CommonCfg.CountryRegionForABand = (UCHAR) region;
12608 + }
12609 + else
12610 + {
12611 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n"));
12612 + return FALSE;
12613 + }
12614 +
12615 + // if set country region, driver needs to be reset
12616 + BuildChannelList(pAd);
12617 +
12618 + DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegionABand_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegionForABand));
12619 +
12620 + return TRUE;
12621 +}
12622 +
12623 +/*
12624 + ==========================================================================
12625 + Description:
12626 + Set Wireless Mode
12627 + Return:
12628 + TRUE if all parameters are OK, FALSE otherwise
12629 + ==========================================================================
12630 +*/
12631 +INT Set_WirelessMode_Proc(
12632 + IN PRTMP_ADAPTER pAd,
12633 + IN PUCHAR arg)
12634 +{
12635 + ULONG WirelessMode;
12636 + INT success = TRUE;
12637 +
12638 + WirelessMode = simple_strtol(arg, 0, 10);
12639 +
12640 +
12641 +#ifdef CONFIG_STA_SUPPORT
12642 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12643 + {
12644 + INT MaxPhyMode = PHY_11G;
12645 +
12646 +#ifdef DOT11_N_SUPPORT
12647 + MaxPhyMode = PHY_11N_5G;
12648 +#endif // DOT11_N_SUPPORT //
12649 +
12650 + if (WirelessMode <= MaxPhyMode)
12651 + {
12652 + RTMPSetPhyMode(pAd, WirelessMode);
12653 +#ifdef DOT11_N_SUPPORT
12654 + if (WirelessMode >= PHY_11ABGN_MIXED)
12655 + {
12656 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
12657 + pAd->CommonCfg.REGBACapability.field.AutoBA = TRUE;
12658 + }
12659 + else
12660 + {
12661 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
12662 + pAd->CommonCfg.REGBACapability.field.AutoBA = FALSE;
12663 + }
12664 +#endif // DOT11_N_SUPPORT //
12665 + // Set AdhocMode rates
12666 + if (pAd->StaCfg.BssType == BSS_ADHOC)
12667 + {
12668 + MlmeUpdateTxRates(pAd, FALSE, 0);
12669 + MakeIbssBeacon(pAd); // re-build BEACON frame
12670 + AsicEnableIbssSync(pAd); // copy to on-chip memory
12671 + }
12672 + }
12673 + else
12674 + {
12675 + success = FALSE;
12676 + }
12677 + }
12678 +#endif // CONFIG_STA_SUPPORT //
12679 +
12680 + // it is needed to set SSID to take effect
12681 + if (success == TRUE)
12682 + {
12683 +#ifdef DOT11_N_SUPPORT
12684 + SetCommonHT(pAd);
12685 +#endif // DOT11_N_SUPPORT //
12686 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WirelessMode_Proc::(=%ld)\n", WirelessMode));
12687 + }
12688 + else
12689 + {
12690 + DBGPRINT(RT_DEBUG_ERROR, ("Set_WirelessMode_Proc::parameters out of range\n"));
12691 + }
12692 +
12693 + return success;
12694 +}
12695 +
12696 +/*
12697 + ==========================================================================
12698 + Description:
12699 + Set Channel
12700 + Return:
12701 + TRUE if all parameters are OK, FALSE otherwise
12702 + ==========================================================================
12703 +*/
12704 +INT Set_Channel_Proc(
12705 + IN PRTMP_ADAPTER pAd,
12706 + IN PUCHAR arg)
12707 +{
12708 + INT success = TRUE;
12709 + UCHAR Channel;
12710 +
12711 + Channel = (UCHAR) simple_strtol(arg, 0, 10);
12712 +
12713 + // check if this channel is valid
12714 + if (ChannelSanity(pAd, Channel) == TRUE)
12715 + {
12716 +#ifdef CONFIG_STA_SUPPORT
12717 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12718 + {
12719 + pAd->CommonCfg.Channel = Channel;
12720 +
12721 + if (MONITOR_ON(pAd))
12722 + {
12723 +#ifdef DOT11_N_SUPPORT
12724 + N_ChannelCheck(pAd);
12725 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
12726 + pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
12727 + {
12728 + N_SetCenCh(pAd);
12729 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
12730 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
12731 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40, control_channel(%d), CentralChannel(%d) \n",
12732 + pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
12733 + }
12734 + else
12735 +#endif // DOT11_N_SUPPORT //
12736 + {
12737 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
12738 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
12739 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAd->CommonCfg.Channel));
12740 + }
12741 + }
12742 + }
12743 +#endif // CONFIG_STA_SUPPORT //
12744 + success = TRUE;
12745 + }
12746 + else
12747 + {
12748 +
12749 +#ifdef CONFIG_STA_SUPPORT
12750 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12751 + success = FALSE;
12752 +#endif // CONFIG_STA_SUPPORT //
12753 + }
12754 +
12755 +
12756 + if (success == TRUE)
12757 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Channel_Proc::(Channel=%d)\n", pAd->CommonCfg.Channel));
12758 +
12759 + return success;
12760 +}
12761 +
12762 +/*
12763 + ==========================================================================
12764 + Description:
12765 + Set Short Slot Time Enable or Disable
12766 + Return:
12767 + TRUE if all parameters are OK, FALSE otherwise
12768 + ==========================================================================
12769 +*/
12770 +INT Set_ShortSlot_Proc(
12771 + IN PRTMP_ADAPTER pAd,
12772 + IN PUCHAR arg)
12773 +{
12774 + ULONG ShortSlot;
12775 +
12776 + ShortSlot = simple_strtol(arg, 0, 10);
12777 +
12778 + if (ShortSlot == 1)
12779 + pAd->CommonCfg.bUseShortSlotTime = TRUE;
12780 + else if (ShortSlot == 0)
12781 + pAd->CommonCfg.bUseShortSlotTime = FALSE;
12782 + else
12783 + return FALSE; //Invalid argument
12784 +
12785 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAd->CommonCfg.bUseShortSlotTime));
12786 +
12787 + return TRUE;
12788 +}
12789 +
12790 +/*
12791 + ==========================================================================
12792 + Description:
12793 + Set Tx power
12794 + Return:
12795 + TRUE if all parameters are OK, FALSE otherwise
12796 + ==========================================================================
12797 +*/
12798 +INT Set_TxPower_Proc(
12799 + IN PRTMP_ADAPTER pAd,
12800 + IN PUCHAR arg)
12801 +{
12802 + ULONG TxPower;
12803 + INT success = FALSE;
12804 +
12805 + TxPower = (ULONG) simple_strtol(arg, 0, 10);
12806 + if (TxPower <= 100)
12807 + {
12808 +
12809 +#ifdef CONFIG_STA_SUPPORT
12810 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12811 + {
12812 + pAd->CommonCfg.TxPowerDefault = TxPower;
12813 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
12814 + }
12815 +#endif // CONFIG_STA_SUPPORT //
12816 + success = TRUE;
12817 + }
12818 + else
12819 + success = FALSE;
12820 +
12821 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPower_Proc::(TxPowerPercentage=%ld)\n", pAd->CommonCfg.TxPowerPercentage));
12822 +
12823 + return success;
12824 +}
12825 +
12826 +/*
12827 + ==========================================================================
12828 + Description:
12829 + Set 11B/11G Protection
12830 + Return:
12831 + TRUE if all parameters are OK, FALSE otherwise
12832 + ==========================================================================
12833 +*/
12834 +INT Set_BGProtection_Proc(
12835 + IN PRTMP_ADAPTER pAd,
12836 + IN PUCHAR arg)
12837 +{
12838 + switch (simple_strtol(arg, 0, 10))
12839 + {
12840 + case 0: //AUTO
12841 + pAd->CommonCfg.UseBGProtection = 0;
12842 + break;
12843 + case 1: //Always On
12844 + pAd->CommonCfg.UseBGProtection = 1;
12845 + break;
12846 + case 2: //Always OFF
12847 + pAd->CommonCfg.UseBGProtection = 2;
12848 + break;
12849 + default: //Invalid argument
12850 + return FALSE;
12851 + }
12852 +
12853 +
12854 + DBGPRINT(RT_DEBUG_TRACE, ("Set_BGProtection_Proc::(BGProtection=%ld)\n", pAd->CommonCfg.UseBGProtection));
12855 +
12856 + return TRUE;
12857 +}
12858 +
12859 +/*
12860 + ==========================================================================
12861 + Description:
12862 + Set TxPreamble
12863 + Return:
12864 + TRUE if all parameters are OK, FALSE otherwise
12865 + ==========================================================================
12866 +*/
12867 +INT Set_TxPreamble_Proc(
12868 + IN PRTMP_ADAPTER pAd,
12869 + IN PUCHAR arg)
12870 +{
12871 + RT_802_11_PREAMBLE Preamble;
12872 +
12873 + Preamble = simple_strtol(arg, 0, 10);
12874 +
12875 +
12876 + switch (Preamble)
12877 + {
12878 + case Rt802_11PreambleShort:
12879 + pAd->CommonCfg.TxPreamble = Preamble;
12880 +#ifdef CONFIG_STA_SUPPORT
12881 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12882 + MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
12883 +#endif // CONFIG_STA_SUPPORT //
12884 + break;
12885 + case Rt802_11PreambleLong:
12886 +#ifdef CONFIG_STA_SUPPORT
12887 + case Rt802_11PreambleAuto:
12888 + // if user wants AUTO, initialize to LONG here, then change according to AP's
12889 + // capability upon association.
12890 +#endif // CONFIG_STA_SUPPORT //
12891 + pAd->CommonCfg.TxPreamble = Preamble;
12892 +#ifdef CONFIG_STA_SUPPORT
12893 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12894 + MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
12895 +#endif // CONFIG_STA_SUPPORT //
12896 + break;
12897 + default: //Invalid argument
12898 + return FALSE;
12899 + }
12900 +
12901 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPreamble_Proc::(TxPreamble=%ld)\n", pAd->CommonCfg.TxPreamble));
12902 +
12903 + return TRUE;
12904 +}
12905 +
12906 +/*
12907 + ==========================================================================
12908 + Description:
12909 + Set RTS Threshold
12910 + Return:
12911 + TRUE if all parameters are OK, FALSE otherwise
12912 + ==========================================================================
12913 +*/
12914 +INT Set_RTSThreshold_Proc(
12915 + IN PRTMP_ADAPTER pAd,
12916 + IN PUCHAR arg)
12917 +{
12918 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
12919 +
12920 + RtsThresh = simple_strtol(arg, 0, 10);
12921 +
12922 + if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
12923 + pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
12924 +#ifdef CONFIG_STA_SUPPORT
12925 + else if (RtsThresh == 0)
12926 + pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
12927 +#endif // CONFIG_STA_SUPPORT //
12928 + else
12929 + return FALSE; //Invalid argument
12930 +
12931 + DBGPRINT(RT_DEBUG_TRACE, ("Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAd->CommonCfg.RtsThreshold));
12932 +
12933 + return TRUE;
12934 +}
12935 +
12936 +/*
12937 + ==========================================================================
12938 + Description:
12939 + Set Fragment Threshold
12940 + Return:
12941 + TRUE if all parameters are OK, FALSE otherwise
12942 + ==========================================================================
12943 +*/
12944 +INT Set_FragThreshold_Proc(
12945 + IN PRTMP_ADAPTER pAd,
12946 + IN PUCHAR arg)
12947 +{
12948 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
12949 +
12950 + FragThresh = simple_strtol(arg, 0, 10);
12951 +
12952 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
12953 + {
12954 + //Illegal FragThresh so we set it to default
12955 + pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
12956 + }
12957 + else if (FragThresh % 2 == 1)
12958 + {
12959 + // The length of each fragment shall always be an even number of octets, except for the last fragment
12960 + // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
12961 + pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
12962 + }
12963 + else
12964 + {
12965 + pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
12966 + }
12967 +
12968 +#ifdef CONFIG_STA_SUPPORT
12969 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12970 + {
12971 + if (pAd->CommonCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
12972 + pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
12973 + else
12974 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
12975 + }
12976 +#endif // CONFIG_STA_SUPPORT //
12977 +
12978 + DBGPRINT(RT_DEBUG_TRACE, ("Set_FragThreshold_Proc::(FragThreshold=%d)\n", pAd->CommonCfg.FragmentThreshold));
12979 +
12980 + return TRUE;
12981 +}
12982 +
12983 +/*
12984 + ==========================================================================
12985 + Description:
12986 + Set TxBurst
12987 + Return:
12988 + TRUE if all parameters are OK, FALSE otherwise
12989 + ==========================================================================
12990 +*/
12991 +INT Set_TxBurst_Proc(
12992 + IN PRTMP_ADAPTER pAd,
12993 + IN PUCHAR arg)
12994 +{
12995 + ULONG TxBurst;
12996 +
12997 + TxBurst = simple_strtol(arg, 0, 10);
12998 + if (TxBurst == 1)
12999 + pAd->CommonCfg.bEnableTxBurst = TRUE;
13000 + else if (TxBurst == 0)
13001 + pAd->CommonCfg.bEnableTxBurst = FALSE;
13002 + else
13003 + return FALSE; //Invalid argument
13004 +
13005 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxBurst_Proc::(TxBurst=%d)\n", pAd->CommonCfg.bEnableTxBurst));
13006 +
13007 + return TRUE;
13008 +}
13009 +
13010 +#ifdef AGGREGATION_SUPPORT
13011 +/*
13012 + ==========================================================================
13013 + Description:
13014 + Set TxBurst
13015 + Return:
13016 + TRUE if all parameters are OK, FALSE otherwise
13017 + ==========================================================================
13018 +*/
13019 +INT Set_PktAggregate_Proc(
13020 + IN PRTMP_ADAPTER pAd,
13021 + IN PUCHAR arg)
13022 +{
13023 + ULONG aggre;
13024 +
13025 + aggre = simple_strtol(arg, 0, 10);
13026 +
13027 + if (aggre == 1)
13028 + pAd->CommonCfg.bAggregationCapable = TRUE;
13029 + else if (aggre == 0)
13030 + pAd->CommonCfg.bAggregationCapable = FALSE;
13031 + else
13032 + return FALSE; //Invalid argument
13033 +
13034 +
13035 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PktAggregate_Proc::(AGGRE=%d)\n", pAd->CommonCfg.bAggregationCapable));
13036 +
13037 + return TRUE;
13038 +}
13039 +#endif
13040 +
13041 +/*
13042 + ==========================================================================
13043 + Description:
13044 + Set IEEE80211H.
13045 + This parameter is 1 when needs radar detection, otherwise 0
13046 + Return:
13047 + TRUE if all parameters are OK, FALSE otherwise
13048 + ==========================================================================
13049 +*/
13050 +INT Set_IEEE80211H_Proc(
13051 + IN PRTMP_ADAPTER pAd,
13052 + IN PUCHAR arg)
13053 +{
13054 + ULONG ieee80211h;
13055 +
13056 + ieee80211h = simple_strtol(arg, 0, 10);
13057 +
13058 + if (ieee80211h == 1)
13059 + pAd->CommonCfg.bIEEE80211H = TRUE;
13060 + else if (ieee80211h == 0)
13061 + pAd->CommonCfg.bIEEE80211H = FALSE;
13062 + else
13063 + return FALSE; //Invalid argument
13064 +
13065 + DBGPRINT(RT_DEBUG_TRACE, ("Set_IEEE80211H_Proc::(IEEE80211H=%d)\n", pAd->CommonCfg.bIEEE80211H));
13066 +
13067 + return TRUE;
13068 +}
13069 +
13070 +
13071 +#ifdef DBG
13072 +/*
13073 + ==========================================================================
13074 + Description:
13075 + For Debug information
13076 + Return:
13077 + TRUE if all parameters are OK, FALSE otherwise
13078 + ==========================================================================
13079 +*/
13080 +INT Set_Debug_Proc(
13081 + IN PRTMP_ADAPTER pAd,
13082 + IN PUCHAR arg)
13083 +{
13084 + DBGPRINT(RT_DEBUG_TRACE, ("==> Set_Debug_Proc *******************\n"));
13085 +
13086 + if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
13087 + RTDebugLevel = simple_strtol(arg, 0, 10);
13088 +
13089 + DBGPRINT(RT_DEBUG_TRACE, ("<== Set_Debug_Proc(RTDebugLevel = %ld)\n", RTDebugLevel));
13090 +
13091 + return TRUE;
13092 +}
13093 +#endif
13094 +
13095 +INT Show_DescInfo_Proc(
13096 + IN PRTMP_ADAPTER pAd,
13097 + IN PUCHAR arg)
13098 +{
13099 +
13100 + return TRUE;
13101 +}
13102 +
13103 +/*
13104 + ==========================================================================
13105 + Description:
13106 + Reset statistics counter
13107 +
13108 + Arguments:
13109 + pAdapter Pointer to our adapter
13110 + arg
13111 +
13112 + Return:
13113 + TRUE if all parameters are OK, FALSE otherwise
13114 + ==========================================================================
13115 +*/
13116 +INT Set_ResetStatCounter_Proc(
13117 + IN PRTMP_ADAPTER pAd,
13118 + IN PUCHAR arg)
13119 +{
13120 + //UCHAR i;
13121 + //MAC_TABLE_ENTRY *pEntry;
13122 +
13123 + DBGPRINT(RT_DEBUG_TRACE, ("==>Set_ResetStatCounter_Proc\n"));
13124 +
13125 + // add the most up-to-date h/w raw counters into software counters
13126 + NICUpdateRawCounters(pAd);
13127 +
13128 + NdisZeroMemory(&pAd->WlanCounters, sizeof(COUNTER_802_11));
13129 + NdisZeroMemory(&pAd->Counters8023, sizeof(COUNTER_802_3));
13130 + NdisZeroMemory(&pAd->RalinkCounters, sizeof(COUNTER_RALINK));
13131 +
13132 + // Reset HotSpot counter
13133 +#if 0 // ToDo.
13134 + for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++)
13135 + {
13136 + pEntry = &pAd->MacTab.Content[i];
13137 +
13138 + if ((pEntry->Valid == FALSE) || (pEntry->Sst != SST_ASSOC))
13139 + continue;
13140 +
13141 + pEntry->HSCounter.LastDataPacketTime = 0;
13142 + pEntry->HSCounter.TotalRxByteCount= 0;
13143 + pEntry->HSCounter.TotalTxByteCount= 0;
13144 + }
13145 +#endif
13146 +
13147 +
13148 + return TRUE;
13149 +}
13150 +
13151 +/*
13152 + ========================================================================
13153 +
13154 + Routine Description:
13155 + Add WPA key process.
13156 + In Adhoc WPANONE, bPairwise = 0; KeyIdx = 0;
13157 +
13158 + Arguments:
13159 + pAd Pointer to our adapter
13160 + pBuf Pointer to the where the key stored
13161 +
13162 + Return Value:
13163 + NDIS_SUCCESS Add key successfully
13164 +
13165 + IRQL = DISPATCH_LEVEL
13166 +
13167 + Note:
13168 +
13169 + ========================================================================
13170 +*/
13171 +#if 0 // remove by AlbertY
13172 +NDIS_STATUS RTMPWPAAddKeyProc(
13173 + IN PRTMP_ADAPTER pAd,
13174 + IN PVOID pBuf)
13175 +{
13176 + PNDIS_802_11_KEY pKey;
13177 + ULONG KeyIdx;
13178 +// NDIS_STATUS Status;
13179 +// ULONG offset; // unused variable, snowpin 2006.07.13
13180 +
13181 + PUCHAR pTxMic, pRxMic;
13182 + BOOLEAN bTxKey; // Set the key as transmit key
13183 + BOOLEAN bPairwise; // Indicate the key is pairwise key
13184 + BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
13185 + // Otherwise, it will set by the NIC.
13186 + BOOLEAN bAuthenticator; // indicate key is set by authenticator.
13187 + UCHAR apidx = BSS0;
13188 +
13189 + pKey = (PNDIS_802_11_KEY) pBuf;
13190 + KeyIdx = pKey->KeyIndex & 0xff;
13191 + // Bit 31 of Add-key, Tx Key
13192 + bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
13193 + // Bit 30 of Add-key PairwiseKey
13194 + bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
13195 + // Bit 29 of Add-key KeyRSC
13196 + bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
13197 + // Bit 28 of Add-key Authenticator
13198 + bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
13199 +
13200 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc==>pKey->KeyIndex = %x. bPairwise= %d\n", pKey->KeyIndex, bPairwise));
13201 + // 1. Check Group / Pairwise Key
13202 + if (bPairwise) // Pairwise Key
13203 + {
13204 + // 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
13205 + if (KeyIdx != 0)
13206 + return(NDIS_STATUS_INVALID_DATA);
13207 +
13208 + // 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
13209 + if (bTxKey == FALSE)
13210 + return(NDIS_STATUS_INVALID_DATA);
13211 +
13212 + // 3. If BSSID is all 0xff, return NDIS_STATUS_INVALID_DATA
13213 + if (MAC_ADDR_EQUAL(pKey->BSSID, BROADCAST_ADDR))
13214 + return(NDIS_STATUS_INVALID_DATA);
13215 +
13216 + // 3.1 Check Pairwise key length for TKIP key. For AES, it's always 128 bits
13217 + //if ((pAdapter->PortCfg.WepStatus == Ndis802_11Encryption2Enabled) && (pKey->KeyLength != LEN_TKIP_KEY))
13218 + if ((pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled) && (pKey->KeyLength != LEN_TKIP_KEY))
13219 + return(NDIS_STATUS_INVALID_DATA);
13220 +
13221 + pAd->SharedKey[apidx][KeyIdx].Type = PAIRWISE_KEY;
13222 +
13223 + if (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2)
13224 + {
13225 + // Send media specific event to start PMKID caching
13226 + RTMPIndicateWPA2Status(pAd);
13227 + }
13228 + }
13229 + else
13230 + {
13231 + // 1. Check BSSID, if not current BSSID or Bcast, return NDIS_STATUS_INVALID_DATA
13232 + if ((! MAC_ADDR_EQUAL(pKey->BSSID, BROADCAST_ADDR)) &&
13233 + (! MAC_ADDR_EQUAL(pKey->BSSID, pAd->ApCfg.MBSSID[apidx].Bssid)))
13234 + return(NDIS_STATUS_INVALID_DATA);
13235 +
13236 + // 2. Check Key index for supported Group Key
13237 + if (KeyIdx >= GROUP_KEY_NUM)
13238 + return(NDIS_STATUS_INVALID_DATA);
13239 +
13240 + // 3. Set as default Tx Key if bTxKey is TRUE
13241 + if (bTxKey == TRUE)
13242 + pAd->ApCfg.MBSSID[apidx].DefaultKeyId = (UCHAR) KeyIdx;
13243 +
13244 + pAd->SharedKey[apidx][KeyIdx].Type = GROUP_KEY;
13245 + }
13246 +
13247 + // 4. Select RxMic / TxMic based on Supp / Authenticator
13248 + if (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPANone)
13249 + {
13250 + // for WPA-None Tx, Rx MIC is the same
13251 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
13252 + pRxMic = pTxMic;
13253 + }
13254 + else if (bAuthenticator == TRUE)
13255 + {
13256 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
13257 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
13258 + }
13259 + else
13260 + {
13261 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
13262 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
13263 + }
13264 +
13265 + // 6. Check RxTsc
13266 + if (bKeyRSC == TRUE)
13267 + {
13268 + NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].RxTsc, &pKey->KeyRSC, 6);
13269 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.RxTsc, &pKey->KeyRSC, 6);
13270 + }
13271 + else
13272 + {
13273 + NdisZeroMemory(pAd->SharedKey[apidx][KeyIdx].RxTsc, 6);
13274 + }
13275 +
13276 + // 7. Copy information into Pairwise Key structure.
13277 + // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
13278 + pAd->SharedKey[apidx][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
13279 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
13280 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, 16);
13281 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.Key, &pKey->KeyMaterial, 16);
13282 + if (pKey->KeyLength == LEN_TKIP_KEY)
13283 + {
13284 + // Only Key lenth equal to TKIP key have these
13285 + NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].RxMic, pRxMic, 8);
13286 + NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].TxMic, pTxMic, 8);
13287 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.RxMic, pRxMic, 8);
13288 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxMic, pTxMic, 8);
13289 + }
13290 +
13291 + COPY_MAC_ADDR(pAd->SharedKey[BSS0][KeyIdx].BssId, pKey->BSSID);
13292 +
13293 + // Init TxTsc to one based on WiFi WPA specs
13294 + pAd->SharedKey[apidx][KeyIdx].TxTsc[0] = 1;
13295 + pAd->SharedKey[apidx][KeyIdx].TxTsc[1] = 0;
13296 + pAd->SharedKey[apidx][KeyIdx].TxTsc[2] = 0;
13297 + pAd->SharedKey[apidx][KeyIdx].TxTsc[3] = 0;
13298 + pAd->SharedKey[apidx][KeyIdx].TxTsc[4] = 0;
13299 + pAd->SharedKey[apidx][KeyIdx].TxTsc[5] = 0;
13300 + // 4. Init TxTsc to one based on WiFi WPA specs
13301 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[0] = 1;
13302 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[1] = 0;
13303 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[2] = 0;
13304 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[3] = 0;
13305 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[4] = 0;
13306 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[5] = 0;
13307 +
13308 + if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption3Enabled)
13309 + {
13310 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_AES;
13311 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_AES;
13312 + }
13313 + else if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption2Enabled)
13314 + {
13315 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_TKIP;
13316 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_TKIP;
13317 + }
13318 + else if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption1Enabled)
13319 + {
13320 + if (pAd->SharedKey[apidx][KeyIdx].KeyLen == 5)
13321 + {
13322 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_WEP64;
13323 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_WEP64;
13324 + }
13325 + else if (pAd->SharedKey[apidx][KeyIdx].KeyLen == 13)
13326 + {
13327 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_WEP128;
13328 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_WEP128;
13329 + }
13330 + else
13331 + {
13332 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_NONE;
13333 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_NONE;
13334 + }
13335 + }
13336 + else
13337 + {
13338 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_NONE;
13339 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_NONE;
13340 + }
13341 +
13342 + if ((pAd->OpMode == OPMODE_STA)) // Pairwise Key. Add BSSID to WCTable
13343 + {
13344 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
13345 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = pAd->SharedKey[BSS0][KeyIdx].KeyLen;
13346 + }
13347 +
13348 + if ((pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2) ||
13349 + (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2PSK))
13350 + {
13351 + //
13352 + // On WPA2, Update Group Key Cipher.
13353 + //
13354 + if (!bPairwise)
13355 + {
13356 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
13357 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_AES;
13358 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
13359 + pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_TKIP;
13360 + }
13361 + }
13362 +
13363 + DBGPRINT(RT_DEBUG_TRACE, ("pAd->SharedKey[%d][%d].CipherAlg = %d\n", apidx, KeyIdx, pAd->SharedKey[apidx][KeyIdx].CipherAlg));
13364 +
13365 +#if 0
13366 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("%s Key #%d", CipherName[pAd->SharedKey[apidx][KeyIdx].CipherAlg],KeyIdx));
13367 + for (i = 0; i < 16; i++)
13368 + {
13369 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].Key[i]));
13370 + }
13371 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n Rx MIC Key = "));
13372 + for (i = 0; i < 8; i++)
13373 + {
13374 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].RxMic[i]));
13375 + }
13376 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n Tx MIC Key = "));
13377 + for (i = 0; i < 8; i++)
13378 + {
13379 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].TxMic[i]));
13380 + }
13381 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n RxTSC = "));
13382 + for (i = 0; i < 6; i++)
13383 + {
13384 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].RxTsc[i]));
13385 + }
13386 +#endif
13387 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n pKey-> BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
13388 + pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]));
13389 +
13390 + if ((bTxKey) && (pAd->OpMode == OPMODE_STA)) // Pairwise Key. Add BSSID to WCTable
13391 + RTMPAddBSSIDCipher(pAd, BSSID_WCID, pKey, pAd->SharedKey[BSS0][KeyIdx].CipherAlg);
13392 +
13393 +
13394 + // No matter pairwise key or what leyidx is, always has a copy at on-chip SharedKeytable.
13395 + AsicAddSharedKeyEntry(pAd,
13396 + apidx,
13397 + (UCHAR)KeyIdx,
13398 + pAd->SharedKey[apidx][KeyIdx].CipherAlg,
13399 + pAd->SharedKey[apidx][KeyIdx].Key,
13400 + pAd->SharedKey[apidx][KeyIdx].TxMic,
13401 + pAd->SharedKey[apidx][KeyIdx].RxMic);
13402 +
13403 + // The WCID key specified in used at Tx. For STA, always use pairwise key.
13404 +
13405 + // ad-hoc mode need to specify WAP Group key with WCID index=BSS0Mcast_WCID. Let's always set this key here.
13406 +/* if (bPairwise == FALSE)
13407 + {
13408 + offset = MAC_IVEIV_TABLE_BASE + (BSS0Mcast_WCID * HW_IVEIV_ENTRY_SIZE);
13409 + NdisZeroMemory(IVEIV, 8);
13410 + // 1. IV/EIV
13411 + // Specify key index to find shared key.
13412 + if ((pAd->SharedKey[BSS0][KeyIdx].CipherAlg==CIPHER_TKIP) ||
13413 + (pAd->SharedKey[BSS0][KeyIdx].CipherAlg==CIPHER_AES))
13414 + IVEIV[3] = 0x20; // Eiv bit on. keyid always 0 for pairwise key
13415 + IVEIV[3] |= (KeyIdx<< 6); // groupkey index is not 0
13416 + for (i=0; i<8; i++)
13417 + {
13418 + RTMP_IO_WRITE8(pAd, offset+i, IVEIV[i]);
13419 + }
13420 +
13421 + // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0
13422 + WCIDAttri = (pAd->SharedKey[BSS0][KeyIdx].CipherAlg<<1)|PAIRWISEKEYTABLE;
13423 + offset = MAC_WCID_ATTRIBUTE_BASE + (BSS0Mcast_WCID* HW_WCID_ATTRI_SIZE);
13424 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
13425 +
13426 + }
13427 +
13428 +*/
13429 +
13430 + if (pAd->SharedKey[apidx][KeyIdx].Type == GROUP_KEY)
13431 + {
13432 + // 802.1x port control
13433 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
13434 + DBGPRINT(RT_DEBUG_TRACE,("!!WPA_802_1X_PORT_SECURED!!\n"));
13435 +
13436 + }
13437 +
13438 + return (NDIS_STATUS_SUCCESS);
13439 +}
13440 +#endif
13441 +
13442 +BOOLEAN RTMPCheckStrPrintAble(
13443 + IN CHAR *pInPutStr,
13444 + IN UCHAR strLen)
13445 +{
13446 + UCHAR i=0;
13447 +
13448 + for (i=0; i<strLen; i++)
13449 + {
13450 + if ((pInPutStr[i] < 0x21) ||
13451 + (pInPutStr[i] > 0x7E))
13452 + return FALSE;
13453 + }
13454 +
13455 + return TRUE;
13456 +}
13457 +
13458 +/*
13459 + ========================================================================
13460 +
13461 + Routine Description:
13462 + Remove WPA Key process
13463 +
13464 + Arguments:
13465 + pAd Pointer to our adapter
13466 + pBuf Pointer to the where the key stored
13467 +
13468 + Return Value:
13469 + NDIS_SUCCESS Add key successfully
13470 +
13471 + IRQL = DISPATCH_LEVEL
13472 +
13473 + Note:
13474 +
13475 + ========================================================================
13476 +*/
13477 +#ifdef CONFIG_STA_SUPPORT
13478 +VOID RTMPSetDesiredRates(
13479 + IN PRTMP_ADAPTER pAdapter,
13480 + IN LONG Rates)
13481 +{
13482 + NDIS_802_11_RATES aryRates;
13483 +
13484 + memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
13485 + switch (pAdapter->CommonCfg.PhyMode)
13486 + {
13487 + case PHY_11A: // A only
13488 + switch (Rates)
13489 + {
13490 + case 6000000: //6M
13491 + aryRates[0] = 0x0c; // 6M
13492 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13493 + break;
13494 + case 9000000: //9M
13495 + aryRates[0] = 0x12; // 9M
13496 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13497 + break;
13498 + case 12000000: //12M
13499 + aryRates[0] = 0x18; // 12M
13500 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13501 + break;
13502 + case 18000000: //18M
13503 + aryRates[0] = 0x24; // 18M
13504 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13505 + break;
13506 + case 24000000: //24M
13507 + aryRates[0] = 0x30; // 24M
13508 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
13509 + break;
13510 + case 36000000: //36M
13511 + aryRates[0] = 0x48; // 36M
13512 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
13513 + break;
13514 + case 48000000: //48M
13515 + aryRates[0] = 0x60; // 48M
13516 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
13517 + break;
13518 + case 54000000: //54M
13519 + aryRates[0] = 0x6c; // 54M
13520 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
13521 + break;
13522 + case -1: //Auto
13523 + default:
13524 + aryRates[0] = 0x6c; // 54Mbps
13525 + aryRates[1] = 0x60; // 48Mbps
13526 + aryRates[2] = 0x48; // 36Mbps
13527 + aryRates[3] = 0x30; // 24Mbps
13528 + aryRates[4] = 0x24; // 18M
13529 + aryRates[5] = 0x18; // 12M
13530 + aryRates[6] = 0x12; // 9M
13531 + aryRates[7] = 0x0c; // 6M
13532 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
13533 + break;
13534 + }
13535 + break;
13536 + case PHY_11BG_MIXED: // B/G Mixed
13537 + case PHY_11B: // B only
13538 + case PHY_11ABG_MIXED: // A/B/G Mixed
13539 + default:
13540 + switch (Rates)
13541 + {
13542 + case 1000000: //1M
13543 + aryRates[0] = 0x02;
13544 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13545 + break;
13546 + case 2000000: //2M
13547 + aryRates[0] = 0x04;
13548 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13549 + break;
13550 + case 5000000: //5.5M
13551 + aryRates[0] = 0x0b; // 5.5M
13552 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13553 + break;
13554 + case 11000000: //11M
13555 + aryRates[0] = 0x16; // 11M
13556 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13557 + break;
13558 + case 6000000: //6M
13559 + aryRates[0] = 0x0c; // 6M
13560 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13561 + break;
13562 + case 9000000: //9M
13563 + aryRates[0] = 0x12; // 9M
13564 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13565 + break;
13566 + case 12000000: //12M
13567 + aryRates[0] = 0x18; // 12M
13568 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13569 + break;
13570 + case 18000000: //18M
13571 + aryRates[0] = 0x24; // 18M
13572 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13573 + break;
13574 + case 24000000: //24M
13575 + aryRates[0] = 0x30; // 24M
13576 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
13577 + break;
13578 + case 36000000: //36M
13579 + aryRates[0] = 0x48; // 36M
13580 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
13581 + break;
13582 + case 48000000: //48M
13583 + aryRates[0] = 0x60; // 48M
13584 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
13585 + break;
13586 + case 54000000: //54M
13587 + aryRates[0] = 0x6c; // 54M
13588 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
13589 + break;
13590 + case -1: //Auto
13591 + default:
13592 + if (pAdapter->CommonCfg.PhyMode == PHY_11B)
13593 + { //B Only
13594 + aryRates[0] = 0x16; // 11Mbps
13595 + aryRates[1] = 0x0b; // 5.5Mbps
13596 + aryRates[2] = 0x04; // 2Mbps
13597 + aryRates[3] = 0x02; // 1Mbps
13598 + }
13599 + else
13600 + { //(B/G) Mixed or (A/B/G) Mixed
13601 + aryRates[0] = 0x6c; // 54Mbps
13602 + aryRates[1] = 0x60; // 48Mbps
13603 + aryRates[2] = 0x48; // 36Mbps
13604 + aryRates[3] = 0x30; // 24Mbps
13605 + aryRates[4] = 0x16; // 11Mbps
13606 + aryRates[5] = 0x0b; // 5.5Mbps
13607 + aryRates[6] = 0x04; // 2Mbps
13608 + aryRates[7] = 0x02; // 1Mbps
13609 + }
13610 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
13611 + break;
13612 + }
13613 + break;
13614 + }
13615 +
13616 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
13617 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
13618 + DBGPRINT(RT_DEBUG_TRACE, (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
13619 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
13620 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
13621 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
13622 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
13623 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
13624 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
13625 +}
13626 +
13627 +NDIS_STATUS RTMPWPARemoveKeyProc(
13628 + IN PRTMP_ADAPTER pAd,
13629 + IN PVOID pBuf)
13630 +{
13631 + PNDIS_802_11_REMOVE_KEY pKey;
13632 + ULONG KeyIdx;
13633 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
13634 + BOOLEAN bTxKey; // Set the key as transmit key
13635 + BOOLEAN bPairwise; // Indicate the key is pairwise key
13636 + BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
13637 + // Otherwise, it will set by the NIC.
13638 + BOOLEAN bAuthenticator; // indicate key is set by authenticator.
13639 + INT i;
13640 +
13641 + DBGPRINT(RT_DEBUG_TRACE,("---> RTMPWPARemoveKeyProc\n"));
13642 +
13643 + pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
13644 + KeyIdx = pKey->KeyIndex & 0xff;
13645 + // Bit 31 of Add-key, Tx Key
13646 + bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
13647 + // Bit 30 of Add-key PairwiseKey
13648 + bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
13649 + // Bit 29 of Add-key KeyRSC
13650 + bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
13651 + // Bit 28 of Add-key Authenticator
13652 + bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
13653 +
13654 + // 1. If bTx is TRUE, return failure information
13655 + if (bTxKey == TRUE)
13656 + return(NDIS_STATUS_INVALID_DATA);
13657 +
13658 + // 2. Check Pairwise Key
13659 + if (bPairwise)
13660 + {
13661 + // a. If BSSID is broadcast, remove all pairwise keys.
13662 + // b. If not broadcast, remove the pairwise specified by BSSID
13663 + for (i = 0; i < SHARE_KEY_NUM; i++)
13664 + {
13665 + if (MAC_ADDR_EQUAL(pAd->SharedKey[BSS0][i].BssId, pKey->BSSID))
13666 + {
13667 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%d)\n", i));
13668 + pAd->SharedKey[BSS0][i].KeyLen = 0;
13669 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
13670 + AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)i);
13671 + Status = NDIS_STATUS_SUCCESS;
13672 + break;
13673 + }
13674 + }
13675 + }
13676 + // 3. Group Key
13677 + else
13678 + {
13679 + // a. If BSSID is broadcast, remove all group keys indexed
13680 + // b. If BSSID matched, delete the group key indexed.
13681 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%ld)\n", KeyIdx));
13682 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = 0;
13683 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
13684 + AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx);
13685 + Status = NDIS_STATUS_SUCCESS;
13686 + }
13687 +
13688 + return (Status);
13689 +}
13690 +#endif // CONFIG_STA_SUPPORT //
13691 +
13692 +
13693 +#ifdef CONFIG_STA_SUPPORT
13694 +/*
13695 + ========================================================================
13696 +
13697 + Routine Description:
13698 + Remove All WPA Keys
13699 +
13700 + Arguments:
13701 + pAd Pointer to our adapter
13702 +
13703 + Return Value:
13704 + None
13705 +
13706 + IRQL = DISPATCH_LEVEL
13707 +
13708 + Note:
13709 +
13710 + ========================================================================
13711 +*/
13712 +VOID RTMPWPARemoveAllKeys(
13713 + IN PRTMP_ADAPTER pAd)
13714 +{
13715 +
13716 + UCHAR i;
13717 +
13718 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
13719 +
13720 + // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after
13721 + // Link up. And it will be replaced if user changed it.
13722 + if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
13723 + return;
13724 +
13725 + // For WPA-None, there is no need to remove it, since WinXP won't set it again after
13726 + // Link up. And it will be replaced if user changed it.
13727 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
13728 + return;
13729 +
13730 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
13731 + AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
13732 +
13733 + // set all shared key mode as no-security.
13734 + for (i = 0; i < SHARE_KEY_NUM; i++)
13735 + {
13736 + DBGPRINT(RT_DEBUG_TRACE,("remove %s key #%d\n", CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
13737 + NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY));
13738 +
13739 + AsicRemoveSharedKeyEntry(pAd, BSS0, i);
13740 + }
13741 +
13742 +}
13743 +#endif // CONFIG_STA_SUPPORT //
13744 +
13745 +/*
13746 + ========================================================================
13747 + Routine Description:
13748 + Change NIC PHY mode. Re-association may be necessary. possible settings
13749 + include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
13750 +
13751 + Arguments:
13752 + pAd - Pointer to our adapter
13753 + phymode -
13754 +
13755 + IRQL = PASSIVE_LEVEL
13756 + IRQL = DISPATCH_LEVEL
13757 +
13758 + ========================================================================
13759 +*/
13760 +VOID RTMPSetPhyMode(
13761 + IN PRTMP_ADAPTER pAd,
13762 + IN ULONG phymode)
13763 +{
13764 + INT i;
13765 + // the selected phymode must be supported by the RF IC encoded in E2PROM
13766 +
13767 + // if no change, do nothing
13768 + /* bug fix
13769 + if (pAd->CommonCfg.PhyMode == phymode)
13770 + return;
13771 + */
13772 + pAd->CommonCfg.PhyMode = (UCHAR)phymode;
13773 +
13774 + DBGPRINT(RT_DEBUG_TRACE,("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
13775 +#ifdef EXT_BUILD_CHANNEL_LIST
13776 + BuildChannelListEx(pAd);
13777 +#else
13778 + BuildChannelList(pAd);
13779 +#endif // EXT_BUILD_CHANNEL_LIST //
13780 +
13781 + // sanity check user setting
13782 + for (i = 0; i < pAd->ChannelListNum; i++)
13783 + {
13784 + if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
13785 + break;
13786 + }
13787 +
13788 + if (i == pAd->ChannelListNum)
13789 + {
13790 +#ifdef CONFIG_STA_SUPPORT
13791 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
13792 + pAd->CommonCfg.Channel = FirstChannel(pAd);
13793 +#endif // CONFIG_STA_SUPPORT //
13794 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", pAd->CommonCfg.Channel));
13795 + }
13796 +
13797 + NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
13798 + NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
13799 + NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
13800 + switch (phymode) {
13801 + case PHY_11B:
13802 + pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
13803 + pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
13804 + pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
13805 + pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
13806 + pAd->CommonCfg.SupRateLen = 4;
13807 + pAd->CommonCfg.ExtRateLen = 0;
13808 + pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
13809 + pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
13810 + pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
13811 + pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
13812 + //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use
13813 + break;
13814 +
13815 + case PHY_11G:
13816 + case PHY_11BG_MIXED:
13817 + case PHY_11ABG_MIXED:
13818 +#ifdef DOT11_N_SUPPORT
13819 + case PHY_11N_2_4G:
13820 + case PHY_11ABGN_MIXED:
13821 + case PHY_11BGN_MIXED:
13822 + case PHY_11GN_MIXED:
13823 +#endif // DOT11_N_SUPPORT //
13824 + pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
13825 + pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
13826 + pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
13827 + pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
13828 + pAd->CommonCfg.SupRate[4] = 0x12; // 9 mbps, in units of 0.5 Mbps
13829 + pAd->CommonCfg.SupRate[5] = 0x24; // 18 mbps, in units of 0.5 Mbps
13830 + pAd->CommonCfg.SupRate[6] = 0x48; // 36 mbps, in units of 0.5 Mbps
13831 + pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
13832 + pAd->CommonCfg.SupRateLen = 8;
13833 + pAd->CommonCfg.ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps
13834 + pAd->CommonCfg.ExtRate[1] = 0x18; // 12 mbps, in units of 0.5 Mbps
13835 + pAd->CommonCfg.ExtRate[2] = 0x30; // 24 mbps, in units of 0.5 Mbps
13836 + pAd->CommonCfg.ExtRate[3] = 0x60; // 48 mbps, in units of 0.5 Mbps
13837 + pAd->CommonCfg.ExtRateLen = 4;
13838 + pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
13839 + pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
13840 + pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
13841 + pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
13842 + pAd->CommonCfg.DesireRate[4] = 12; // 6 mbps, in units of 0.5 Mbps
13843 + pAd->CommonCfg.DesireRate[5] = 18; // 9 mbps, in units of 0.5 Mbps
13844 + pAd->CommonCfg.DesireRate[6] = 24; // 12 mbps, in units of 0.5 Mbps
13845 + pAd->CommonCfg.DesireRate[7] = 36; // 18 mbps, in units of 0.5 Mbps
13846 + pAd->CommonCfg.DesireRate[8] = 48; // 24 mbps, in units of 0.5 Mbps
13847 + pAd->CommonCfg.DesireRate[9] = 72; // 36 mbps, in units of 0.5 Mbps
13848 + pAd->CommonCfg.DesireRate[10] = 96; // 48 mbps, in units of 0.5 Mbps
13849 + pAd->CommonCfg.DesireRate[11] = 108; // 54 mbps, in units of 0.5 Mbps
13850 + break;
13851 +
13852 + case PHY_11A:
13853 +#ifdef DOT11_N_SUPPORT
13854 + case PHY_11AN_MIXED:
13855 + case PHY_11AGN_MIXED:
13856 + case PHY_11N_5G:
13857 +#endif // DOT11_N_SUPPORT //
13858 + pAd->CommonCfg.SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
13859 + pAd->CommonCfg.SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
13860 + pAd->CommonCfg.SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
13861 + pAd->CommonCfg.SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
13862 + pAd->CommonCfg.SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
13863 + pAd->CommonCfg.SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
13864 + pAd->CommonCfg.SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
13865 + pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
13866 + pAd->CommonCfg.SupRateLen = 8;
13867 + pAd->CommonCfg.ExtRateLen = 0;
13868 + pAd->CommonCfg.DesireRate[0] = 12; // 6 mbps, in units of 0.5 Mbps
13869 + pAd->CommonCfg.DesireRate[1] = 18; // 9 mbps, in units of 0.5 Mbps
13870 + pAd->CommonCfg.DesireRate[2] = 24; // 12 mbps, in units of 0.5 Mbps
13871 + pAd->CommonCfg.DesireRate[3] = 36; // 18 mbps, in units of 0.5 Mbps
13872 + pAd->CommonCfg.DesireRate[4] = 48; // 24 mbps, in units of 0.5 Mbps
13873 + pAd->CommonCfg.DesireRate[5] = 72; // 36 mbps, in units of 0.5 Mbps
13874 + pAd->CommonCfg.DesireRate[6] = 96; // 48 mbps, in units of 0.5 Mbps
13875 + pAd->CommonCfg.DesireRate[7] = 108; // 54 mbps, in units of 0.5 Mbps
13876 + //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use
13877 + break;
13878 +
13879 + default:
13880 + break;
13881 + }
13882 +
13883 +
13884 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
13885 +}
13886 +
13887 +
13888 +#ifdef DOT11_N_SUPPORT
13889 +/*
13890 + ========================================================================
13891 + Routine Description:
13892 + Caller ensures we has 802.11n support.
13893 + Calls at setting HT from AP/STASetinformation
13894 +
13895 + Arguments:
13896 + pAd - Pointer to our adapter
13897 + phymode -
13898 +
13899 + ========================================================================
13900 +*/
13901 +VOID RTMPSetHT(
13902 + IN PRTMP_ADAPTER pAd,
13903 + IN OID_SET_HT_PHYMODE *pHTPhyMode)
13904 +{
13905 + //ULONG *pmcs;
13906 + UINT32 Value = 0;
13907 + UCHAR BBPValue = 0;
13908 + UCHAR BBP3Value = 0;
13909 + UCHAR RxStream = pAd->CommonCfg.RxStream;
13910 +
13911 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
13912 + pHTPhyMode->HtMode, pHTPhyMode->ExtOffset,
13913 + pHTPhyMode->MCS, pHTPhyMode->BW,
13914 + pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
13915 +
13916 + // Don't zero supportedHyPhy structure.
13917 + RTMPZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
13918 + RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
13919 + RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, sizeof(pAd->CommonCfg.NewExtChanOffset));
13920 + RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, sizeof(pAd->CommonCfg.DesiredHtPhy));
13921 +
13922 + if (pAd->CommonCfg.bRdg)
13923 + {
13924 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
13925 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
13926 + }
13927 + else
13928 + {
13929 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
13930 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
13931 + }
13932 +
13933 + pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
13934 + pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
13935 +
13936 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : RxBAWinLimit = %d\n", pAd->CommonCfg.BACapability.field.RxBAWinLimit));
13937 +
13938 + // Mimo power save, A-MSDU size,
13939 + pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
13940 + pAd->CommonCfg.DesiredHtPhy.AmsduSize = (UCHAR)pAd->CommonCfg.BACapability.field.AmsduSize;
13941 + pAd->CommonCfg.DesiredHtPhy.MimoPs = (UCHAR)pAd->CommonCfg.BACapability.field.MMPSmode;
13942 + pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
13943 +
13944 + pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
13945 + pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
13946 + pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
13947 +
13948 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
13949 + pAd->CommonCfg.DesiredHtPhy.AmsduSize,
13950 + pAd->CommonCfg.DesiredHtPhy.MimoPs,
13951 + pAd->CommonCfg.DesiredHtPhy.MpduDensity,
13952 + pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
13953 +
13954 + if(pHTPhyMode->HtMode == HTMODE_GF)
13955 + {
13956 + pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
13957 + pAd->CommonCfg.DesiredHtPhy.GF = 1;
13958 + }
13959 + else
13960 + pAd->CommonCfg.DesiredHtPhy.GF = 0;
13961 +
13962 + // Decide Rx MCSSet
13963 + switch (RxStream)
13964 + {
13965 + case 1:
13966 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13967 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00;
13968 + break;
13969 +
13970 + case 2:
13971 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13972 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
13973 + break;
13974 +
13975 + case 3: // 3*3
13976 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13977 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
13978 + pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff;
13979 + break;
13980 + }
13981 +
13982 + if (pAd->CommonCfg.bForty_Mhz_Intolerant && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40) )
13983 + {
13984 + pHTPhyMode->BW = BW_20;
13985 + pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
13986 + }
13987 +
13988 + if(pHTPhyMode->BW == BW_40)
13989 + {
13990 + pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32
13991 + pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
13992 + if (pAd->CommonCfg.Channel <= 14)
13993 + pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
13994 +
13995 + pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
13996 + pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
13997 + pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = (pHTPhyMode->ExtOffset == EXTCHA_BELOW)? (EXTCHA_BELOW): EXTCHA_ABOVE;
13998 + // Set Regsiter for extension channel position.
13999 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
14000 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
14001 + if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW))
14002 + {
14003 + Value |= 0x1;
14004 + BBP3Value |= (0x20);
14005 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
14006 + }
14007 + else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE))
14008 + {
14009 + Value &= 0xfe;
14010 + BBP3Value &= (~0x20);
14011 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
14012 + }
14013 +
14014 + // Turn on BBP 40MHz mode now only as AP .
14015 + // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection.
14016 + if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
14017 + )
14018 + {
14019 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
14020 + BBPValue &= (~0x18);
14021 + BBPValue |= 0x10;
14022 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
14023 +
14024 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
14025 + pAd->CommonCfg.BBPCurrentBW = BW_40;
14026 + }
14027 + }
14028 + else
14029 + {
14030 + pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
14031 + pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
14032 + pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
14033 + pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
14034 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
14035 + // Turn on BBP 20MHz mode by request here.
14036 + {
14037 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
14038 + BBPValue &= (~0x18);
14039 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
14040 + pAd->CommonCfg.BBPCurrentBW = BW_20;
14041 + }
14042 + }
14043 +
14044 + if(pHTPhyMode->STBC == STBC_USE)
14045 + {
14046 + pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
14047 + pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
14048 + pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
14049 + pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
14050 + }
14051 + else
14052 + {
14053 + pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
14054 + pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
14055 + }
14056 +
14057 +#ifdef RT2870
14058 + /* Frank recommend ,If not, Tx maybe block in high power. Rx has no problem*/
14059 + if(IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020)))
14060 + {
14061 + pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 0;
14062 + pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
14063 + }
14064 +#endif // RT2870 //
14065 +
14066 + if(pHTPhyMode->SHORTGI == GI_400)
14067 + {
14068 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
14069 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
14070 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
14071 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
14072 + }
14073 + else
14074 + {
14075 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
14076 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
14077 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
14078 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
14079 + }
14080 +
14081 + // We support link adaptation for unsolicit MCS feedback, set to 2.
14082 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT;
14083 + pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
14084 + // 1, the extension channel above the control channel.
14085 +
14086 + // EDCA parameters used for AP's own transmission
14087 + if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
14088 + {
14089 + pAd->CommonCfg.APEdcaParm.bValid = TRUE;
14090 + pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
14091 + pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
14092 + pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
14093 + pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
14094 +
14095 + pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
14096 + pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
14097 + pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
14098 + pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
14099 +
14100 + pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
14101 + pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
14102 + pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
14103 + pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
14104 +
14105 + pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
14106 + pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
14107 + pAd->CommonCfg.APEdcaParm.Txop[2] = 94;
14108 + pAd->CommonCfg.APEdcaParm.Txop[3] = 47;
14109 + }
14110 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
14111 +
14112 +
14113 +#ifdef CONFIG_STA_SUPPORT
14114 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14115 + {
14116 + RTMPSetIndividualHT(pAd, 0);
14117 + }
14118 +#endif // CONFIG_STA_SUPPORT //
14119 +
14120 +}
14121 +
14122 +/*
14123 + ========================================================================
14124 + Routine Description:
14125 + Caller ensures we has 802.11n support.
14126 + Calls at setting HT from AP/STASetinformation
14127 +
14128 + Arguments:
14129 + pAd - Pointer to our adapter
14130 + phymode -
14131 +
14132 + ========================================================================
14133 +*/
14134 +VOID RTMPSetIndividualHT(
14135 + IN PRTMP_ADAPTER pAd,
14136 + IN UCHAR apidx)
14137 +{
14138 + PRT_HT_PHY_INFO pDesired_ht_phy = NULL;
14139 + UCHAR TxStream = pAd->CommonCfg.TxStream;
14140 + UCHAR DesiredMcs = MCS_AUTO;
14141 +
14142 + do
14143 + {
14144 +
14145 +#ifdef CONFIG_STA_SUPPORT
14146 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14147 + {
14148 + pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
14149 + DesiredMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
14150 + //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE;
14151 + break;
14152 + }
14153 +#endif // CONFIG_STA_SUPPORT //
14154 + } while (FALSE);
14155 +
14156 + if (pDesired_ht_phy == NULL)
14157 + {
14158 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
14159 + return;
14160 + }
14161 + RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO));
14162 +
14163 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
14164 + // Check the validity of MCS
14165 + if ((TxStream == 1) && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15)))
14166 + {
14167 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", DesiredMcs));
14168 + DesiredMcs = MCS_7;
14169 + }
14170 +
14171 + if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) && (DesiredMcs == MCS_32))
14172 + {
14173 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
14174 + DesiredMcs = MCS_0;
14175 + }
14176 +
14177 + pDesired_ht_phy->bHtEnable = TRUE;
14178 +
14179 + // Decide desired Tx MCS
14180 + switch (TxStream)
14181 + {
14182 + case 1:
14183 + if (DesiredMcs == MCS_AUTO)
14184 + {
14185 + pDesired_ht_phy->MCSSet[0]= 0xff;
14186 + pDesired_ht_phy->MCSSet[1]= 0x00;
14187 + }
14188 + else if (DesiredMcs <= MCS_7)
14189 + {
14190 + pDesired_ht_phy->MCSSet[0]= 1<<DesiredMcs;
14191 + pDesired_ht_phy->MCSSet[1]= 0x00;
14192 + }
14193 + break;
14194 +
14195 + case 2:
14196 + if (DesiredMcs == MCS_AUTO)
14197 + {
14198 + pDesired_ht_phy->MCSSet[0]= 0xff;
14199 + pDesired_ht_phy->MCSSet[1]= 0xff;
14200 + }
14201 + else if (DesiredMcs <= MCS_15)
14202 + {
14203 + ULONG mode;
14204 +
14205 + mode = DesiredMcs / 8;
14206 + if (mode < 2)
14207 + pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
14208 + }
14209 + break;
14210 +
14211 + case 3: // 3*3
14212 + if (DesiredMcs == MCS_AUTO)
14213 + {
14214 + /* MCS0 ~ MCS23, 3 bytes */
14215 + pDesired_ht_phy->MCSSet[0]= 0xff;
14216 + pDesired_ht_phy->MCSSet[1]= 0xff;
14217 + pDesired_ht_phy->MCSSet[2]= 0xff;
14218 + }
14219 + else if (DesiredMcs <= MCS_23)
14220 + {
14221 + ULONG mode;
14222 +
14223 + mode = DesiredMcs / 8;
14224 + if (mode < 3)
14225 + pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
14226 + }
14227 + break;
14228 + }
14229 +
14230 + if(pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40)
14231 + {
14232 + if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
14233 + pDesired_ht_phy->MCSSet[4] = 0x1;
14234 + }
14235 +
14236 + // update HT Rate setting
14237 + if (pAd->OpMode == OPMODE_STA)
14238 + MlmeUpdateHtTxRates(pAd, BSS0);
14239 + else
14240 + MlmeUpdateHtTxRates(pAd, apidx);
14241 +}
14242 +
14243 +
14244 +/*
14245 + ========================================================================
14246 + Routine Description:
14247 + Update HT IE from our capability.
14248 +
14249 + Arguments:
14250 + Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
14251 +
14252 +
14253 + ========================================================================
14254 +*/
14255 +VOID RTMPUpdateHTIE(
14256 + IN RT_HT_CAPABILITY *pRtHt,
14257 + IN UCHAR *pMcsSet,
14258 + OUT HT_CAPABILITY_IE *pHtCapability,
14259 + OUT ADD_HT_INFO_IE *pAddHtInfo)
14260 +{
14261 + RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE));
14262 + RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE));
14263 +
14264 + pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
14265 + pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
14266 + pHtCapability->HtCapInfo.GF = pRtHt->GF;
14267 + pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
14268 + pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
14269 + pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
14270 + pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
14271 + pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
14272 + pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
14273 + pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
14274 +
14275 + pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset ;
14276 + pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
14277 + pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
14278 + pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
14279 + RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet*/pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar.
14280 +
14281 + DBGPRINT(RT_DEBUG_TRACE,("RTMPUpdateHTIE <== \n"));
14282 +}
14283 +#endif // DOT11_N_SUPPORT //
14284 +
14285 +/*
14286 + ========================================================================
14287 + Description:
14288 + Add Client security information into ASIC WCID table and IVEIV table.
14289 + Return:
14290 + ========================================================================
14291 +*/
14292 +VOID RTMPAddWcidAttributeEntry(
14293 + IN PRTMP_ADAPTER pAd,
14294 + IN UCHAR BssIdx,
14295 + IN UCHAR KeyIdx,
14296 + IN UCHAR CipherAlg,
14297 + IN MAC_TABLE_ENTRY *pEntry)
14298 +{
14299 + UINT32 WCIDAttri = 0;
14300 + USHORT offset;
14301 + UCHAR IVEIV = 0;
14302 + USHORT Wcid = 0;
14303 +
14304 + {
14305 +#ifdef CONFIG_STA_SUPPORT
14306 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14307 + {
14308 + if (BssIdx > BSS0)
14309 + {
14310 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", BssIdx));
14311 + return;
14312 + }
14313 +
14314 + // 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists.
14315 + // 2. In Infra mode, the AID:1 MUST be wcid of infra STA.
14316 + // the AID:2~ assign to mesh link entry.
14317 + if (pEntry && ADHOC_ON(pAd))
14318 + Wcid = pEntry->Aid;
14319 + else if (pEntry && INFRA_ON(pAd))
14320 + {
14321 +#ifdef QOS_DLS_SUPPORT
14322 + if (pEntry->ValidAsDls == TRUE)
14323 + Wcid = pEntry->Aid;
14324 + else
14325 +#endif // QOS_DLS_SUPPORT //
14326 + Wcid = BSSID_WCID;
14327 + }
14328 + else
14329 + Wcid = MCAST_WCID;
14330 + }
14331 +#endif // CONFIG_STA_SUPPORT //
14332 + }
14333 +
14334 + // Update WCID attribute table
14335 + offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
14336 +
14337 +#ifdef CONFIG_STA_SUPPORT
14338 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14339 + {
14340 + if (pEntry && pEntry->ValidAsMesh)
14341 + WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
14342 +#ifdef QOS_DLS_SUPPORT
14343 + else if ((pEntry) && (pEntry->ValidAsDls) &&
14344 + ((CipherAlg == CIPHER_TKIP) ||
14345 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
14346 + (CipherAlg == CIPHER_AES) ||
14347 + (CipherAlg == CIPHER_NONE)))
14348 + WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
14349 +#endif // QOS_DLS_SUPPORT //
14350 + else
14351 + WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE;
14352 + }
14353 +#endif // CONFIG_STA_SUPPORT //
14354 +
14355 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
14356 +
14357 +
14358 + // Update IV/EIV table
14359 + offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
14360 +
14361 + // WPA mode
14362 + if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES))
14363 + {
14364 + // Eiv bit on. keyid always is 0 for pairwise key
14365 + IVEIV = (KeyIdx <<6) | 0x20;
14366 + }
14367 + else
14368 + {
14369 + // WEP KeyIdx is default tx key.
14370 + IVEIV = (KeyIdx << 6);
14371 + }
14372 +
14373 + // For key index and ext IV bit, so only need to update the position(offset+3).
14374 +#ifdef RT2870
14375 + RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV);
14376 +#endif // RT2870 //
14377 +
14378 + DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg]));
14379 + DBGPRINT(RT_DEBUG_TRACE,(" WCIDAttri = 0x%x \n", WCIDAttri));
14380 +
14381 +}
14382 +
14383 +/*
14384 + ==========================================================================
14385 + Description:
14386 + Parse encryption type
14387 +Arguments:
14388 + pAdapter Pointer to our adapter
14389 + wrq Pointer to the ioctl argument
14390 +
14391 + Return Value:
14392 + None
14393 +
14394 + Note:
14395 + ==========================================================================
14396 +*/
14397 +CHAR *GetEncryptType(CHAR enc)
14398 +{
14399 + if(enc == Ndis802_11WEPDisabled)
14400 + return "NONE";
14401 + if(enc == Ndis802_11WEPEnabled)
14402 + return "WEP";
14403 + if(enc == Ndis802_11Encryption2Enabled)
14404 + return "TKIP";
14405 + if(enc == Ndis802_11Encryption3Enabled)
14406 + return "AES";
14407 + if(enc == Ndis802_11Encryption4Enabled)
14408 + return "TKIPAES";
14409 + else
14410 + return "UNKNOW";
14411 +}
14412 +
14413 +CHAR *GetAuthMode(CHAR auth)
14414 +{
14415 + if(auth == Ndis802_11AuthModeOpen)
14416 + return "OPEN";
14417 + if(auth == Ndis802_11AuthModeShared)
14418 + return "SHARED";
14419 + if(auth == Ndis802_11AuthModeAutoSwitch)
14420 + return "AUTOWEP";
14421 + if(auth == Ndis802_11AuthModeWPA)
14422 + return "WPA";
14423 + if(auth == Ndis802_11AuthModeWPAPSK)
14424 + return "WPAPSK";
14425 + if(auth == Ndis802_11AuthModeWPANone)
14426 + return "WPANONE";
14427 + if(auth == Ndis802_11AuthModeWPA2)
14428 + return "WPA2";
14429 + if(auth == Ndis802_11AuthModeWPA2PSK)
14430 + return "WPA2PSK";
14431 + if(auth == Ndis802_11AuthModeWPA1WPA2)
14432 + return "WPA1WPA2";
14433 + if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
14434 + return "WPA1PSKWPA2PSK";
14435 +
14436 + return "UNKNOW";
14437 +}
14438 +
14439 +#if 1 //#ifndef UCOS
14440 +/*
14441 + ==========================================================================
14442 + Description:
14443 + Get site survey results
14444 + Arguments:
14445 + pAdapter Pointer to our adapter
14446 + wrq Pointer to the ioctl argument
14447 +
14448 + Return Value:
14449 + None
14450 +
14451 + Note:
14452 + Usage:
14453 + 1.) UI needs to wait 4 seconds after issue a site survey command
14454 + 2.) iwpriv ra0 get_site_survey
14455 + 3.) UI needs to prepare at least 4096bytes to get the results
14456 + ==========================================================================
14457 +*/
14458 +#define LINE_LEN (4+33+20+8+10+9+7+3) // Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType
14459 +VOID RTMPIoctlGetSiteSurvey(
14460 + IN PRTMP_ADAPTER pAdapter,
14461 + IN struct iwreq *wrq)
14462 +{
14463 + CHAR *msg;
14464 + INT i=0;
14465 + INT WaitCnt;
14466 + INT Status=0;
14467 + CHAR Ssid[MAX_LEN_OF_SSID +1];
14468 + INT Rssi = 0, max_len = LINE_LEN;
14469 + UINT Rssi_Quality = 0;
14470 + NDIS_802_11_NETWORK_TYPE wireless_mode;
14471 +
14472 + os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len));
14473 +
14474 + if (msg == NULL)
14475 + {
14476 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n"));
14477 + return;
14478 + }
14479 +
14480 + memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len );
14481 + memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1));
14482 + sprintf(msg,"%s","\n");
14483 + sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n",
14484 + "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT");
14485 +
14486 +
14487 + WaitCnt = 0;
14488 +#ifdef CONFIG_STA_SUPPORT
14489 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
14490 + while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200))
14491 + OS_WAIT(500);
14492 +#endif // CONFIG_STA_SUPPORT //
14493 +
14494 + for(i=0; i<pAdapter->ScanTab.BssNr ;i++)
14495 + {
14496 + if( pAdapter->ScanTab.BssEntry[i].Channel==0)
14497 + break;
14498 +
14499 + if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA)
14500 + break;
14501 +
14502 + //Channel
14503 + sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel);
14504 + //SSID
14505 + memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
14506 + Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0';
14507 + sprintf(msg+strlen(msg),"%-33s", Ssid);
14508 + //BSSID
14509 + sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x ",
14510 + pAdapter->ScanTab.BssEntry[i].Bssid[0],
14511 + pAdapter->ScanTab.BssEntry[i].Bssid[1],
14512 + pAdapter->ScanTab.BssEntry[i].Bssid[2],
14513 + pAdapter->ScanTab.BssEntry[i].Bssid[3],
14514 + pAdapter->ScanTab.BssEntry[i].Bssid[4],
14515 + pAdapter->ScanTab.BssEntry[i].Bssid[5]);
14516 + //Encryption Type
14517 + sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus));
14518 + //Authentication Mode
14519 + if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled)
14520 + sprintf(msg+strlen(msg),"%-10s", "UNKNOW");
14521 + else
14522 + sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode));
14523 + // Rssi
14524 + Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi;
14525 + if (Rssi >= -50)
14526 + Rssi_Quality = 100;
14527 + else if (Rssi >= -80) // between -50 ~ -80dbm
14528 + Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10);
14529 + else if (Rssi >= -90) // between -80 ~ -90dbm
14530 + Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10);
14531 + else // < -84 dbm
14532 + Rssi_Quality = 0;
14533 + sprintf(msg+strlen(msg),"%-9d", Rssi_Quality);
14534 + // Wireless Mode
14535 + wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
14536 + if (wireless_mode == Ndis802_11FH ||
14537 + wireless_mode == Ndis802_11DS)
14538 + sprintf(msg+strlen(msg),"%-7s", "11b");
14539 + else if (wireless_mode == Ndis802_11OFDM5)
14540 + sprintf(msg+strlen(msg),"%-7s", "11a");
14541 + else if (wireless_mode == Ndis802_11OFDM5_N)
14542 + sprintf(msg+strlen(msg),"%-7s", "11a/n");
14543 + else if (wireless_mode == Ndis802_11OFDM24)
14544 + sprintf(msg+strlen(msg),"%-7s", "11b/g");
14545 + else if (wireless_mode == Ndis802_11OFDM24_N)
14546 + sprintf(msg+strlen(msg),"%-7s", "11b/g/n");
14547 + else
14548 + sprintf(msg+strlen(msg),"%-7s", "unknow");
14549 + //Network Type
14550 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC)
14551 + sprintf(msg+strlen(msg),"%-3s", " Ad");
14552 + else
14553 + sprintf(msg+strlen(msg),"%-3s", " In");
14554 +
14555 + sprintf(msg+strlen(msg),"\n");
14556 + }
14557 +
14558 +#ifdef CONFIG_STA_SUPPORT
14559 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
14560 +#endif // CONFIG_STA_SUPPORT //
14561 + wrq->u.data.length = strlen(msg);
14562 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
14563 +
14564 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length));
14565 + os_free_mem(NULL, (PUCHAR)msg);
14566 +}
14567 +
14568 +
14569 +#define MAC_LINE_LEN (14+4+4+10+10+10+6+6) // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate
14570 +VOID RTMPIoctlGetMacTable(
14571 + IN PRTMP_ADAPTER pAd,
14572 + IN struct iwreq *wrq)
14573 +{
14574 + INT i;
14575 + RT_802_11_MAC_TABLE MacTab;
14576 + char *msg;
14577 +
14578 + MacTab.Num = 0;
14579 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
14580 + {
14581 + if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))
14582 + {
14583 + COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);
14584 + MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;
14585 + MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;
14586 +#ifdef DOT11_N_SUPPORT
14587 + MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;
14588 +#endif // DOT11_N_SUPPORT //
14589 +
14590 + // Fill in RSSI per entry
14591 + MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;
14592 + MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;
14593 + MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;
14594 +
14595 + // the connected time per entry
14596 + MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;
14597 +#if 0 // ToDo
14598 + MacTab.Entry[MacTab.Num].HSCounter.LastDataPacketTime = pAd->MacTab.Content[i].HSCounter.LastDataPacketTime;
14599 + MacTab.Entry[MacTab.Num].HSCounter.TotalRxByteCount = pAd->MacTab.Content[i].HSCounter.TotalRxByteCount;
14600 + MacTab.Entry[MacTab.Num].HSCounter.TotalTxByteCount = pAd->MacTab.Content[i].HSCounter.TotalTxByteCount;
14601 +#endif
14602 + MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;
14603 + MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;
14604 + MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;
14605 + MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;
14606 + MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;
14607 + MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;
14608 + MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;
14609 +
14610 + MacTab.Num += 1;
14611 + }
14612 + }
14613 + wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);
14614 + if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))
14615 + {
14616 + DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __FUNCTION__));
14617 + }
14618 +
14619 + msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);
14620 + memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );
14621 + sprintf(msg,"%s","\n");
14622 + sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",
14623 + "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");
14624 +
14625 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
14626 + {
14627 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
14628 + if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))
14629 + {
14630 + if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )
14631 + break;
14632 + sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x ",
14633 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
14634 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
14635 + sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);
14636 + sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);
14637 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo
14638 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo
14639 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo
14640 + sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);
14641 + sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo
14642 + }
14643 + }
14644 + // for compatible with old API just do the printk to console
14645 + //wrq->u.data.length = strlen(msg);
14646 + //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
14647 + {
14648 + DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));
14649 + }
14650 +
14651 + kfree(msg);
14652 +}
14653 +#endif // UCOS //
14654 +
14655 +#ifdef DOT11_N_SUPPORT
14656 +INT Set_BASetup_Proc(
14657 + IN PRTMP_ADAPTER pAd,
14658 + IN PUCHAR arg)
14659 +{
14660 + UCHAR mac[6], tid;
14661 + char *token, sepValue[] = ":", DASH = '-';
14662 + INT i;
14663 + MAC_TABLE_ENTRY *pEntry;
14664 +
14665 +/*
14666 + The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d,
14667 + =>The six 2 digit hex-decimal number previous are the Mac address,
14668 + =>The seventh decimal number is the tid value.
14669 +*/
14670 + //printk("\n%s\n", arg);
14671 +
14672 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14673 + return FALSE;
14674 +
14675 + token = strchr(arg, DASH);
14676 + if ((token != NULL) && (strlen(token)>1))
14677 + {
14678 + tid = simple_strtol((token+1), 0, 10);
14679 + if (tid > 15)
14680 + return FALSE;
14681 +
14682 + *token = '\0';
14683 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14684 + {
14685 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14686 + return FALSE;
14687 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14688 + }
14689 + if(i != 6)
14690 + return FALSE;
14691 +
14692 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1],
14693 + mac[2], mac[3], mac[4], mac[5], tid);
14694 +
14695 + pEntry = MacTableLookup(pAd, mac);
14696 +
14697 + if (pEntry) {
14698 + printk("\nSetup BA Session: Tid = %d\n", tid);
14699 + BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);
14700 + }
14701 +
14702 + return TRUE;
14703 + }
14704 +
14705 + return FALSE;
14706 +
14707 +}
14708 +
14709 +INT Set_BADecline_Proc(
14710 + IN PRTMP_ADAPTER pAd,
14711 + IN PUCHAR arg)
14712 +{
14713 + ULONG bBADecline;
14714 +
14715 + bBADecline = simple_strtol(arg, 0, 10);
14716 +
14717 + if (bBADecline == 0)
14718 + {
14719 + pAd->CommonCfg.bBADecline = FALSE;
14720 + }
14721 + else if (bBADecline == 1)
14722 + {
14723 + pAd->CommonCfg.bBADecline = TRUE;
14724 + }
14725 + else
14726 + {
14727 + return FALSE; //Invalid argument
14728 + }
14729 +
14730 + DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));
14731 +
14732 + return TRUE;
14733 +}
14734 +
14735 +INT Set_BAOriTearDown_Proc(
14736 + IN PRTMP_ADAPTER pAd,
14737 + IN PUCHAR arg)
14738 +{
14739 + UCHAR mac[6], tid;
14740 + char *token, sepValue[] = ":", DASH = '-';
14741 + INT i;
14742 + MAC_TABLE_ENTRY *pEntry;
14743 +
14744 + //printk("\n%s\n", arg);
14745 +/*
14746 + The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
14747 + =>The six 2 digit hex-decimal number previous are the Mac address,
14748 + =>The seventh decimal number is the tid value.
14749 +*/
14750 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14751 + return FALSE;
14752 +
14753 + token = strchr(arg, DASH);
14754 + if ((token != NULL) && (strlen(token)>1))
14755 + {
14756 + tid = simple_strtol((token+1), 0, 10);
14757 + if (tid > NUM_OF_TID)
14758 + return FALSE;
14759 +
14760 + *token = '\0';
14761 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14762 + {
14763 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14764 + return FALSE;
14765 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14766 + }
14767 + if(i != 6)
14768 + return FALSE;
14769 +
14770 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
14771 + mac[2], mac[3], mac[4], mac[5], tid);
14772 +
14773 + pEntry = MacTableLookup(pAd, mac);
14774 +
14775 + if (pEntry) {
14776 + printk("\nTear down Ori BA Session: Tid = %d\n", tid);
14777 + BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE);
14778 + }
14779 +
14780 + return TRUE;
14781 + }
14782 +
14783 + return FALSE;
14784 +
14785 +}
14786 +
14787 +INT Set_BARecTearDown_Proc(
14788 + IN PRTMP_ADAPTER pAd,
14789 + IN PUCHAR arg)
14790 +{
14791 + UCHAR mac[6], tid;
14792 + char *token, sepValue[] = ":", DASH = '-';
14793 + INT i;
14794 + MAC_TABLE_ENTRY *pEntry;
14795 +
14796 + //printk("\n%s\n", arg);
14797 +/*
14798 + The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
14799 + =>The six 2 digit hex-decimal number previous are the Mac address,
14800 + =>The seventh decimal number is the tid value.
14801 +*/
14802 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14803 + return FALSE;
14804 +
14805 + token = strchr(arg, DASH);
14806 + if ((token != NULL) && (strlen(token)>1))
14807 + {
14808 + tid = simple_strtol((token+1), 0, 10);
14809 + if (tid > NUM_OF_TID)
14810 + return FALSE;
14811 +
14812 + *token = '\0';
14813 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14814 + {
14815 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14816 + return FALSE;
14817 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14818 + }
14819 + if(i != 6)
14820 + return FALSE;
14821 +
14822 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
14823 + mac[2], mac[3], mac[4], mac[5], tid);
14824 +
14825 + pEntry = MacTableLookup(pAd, mac);
14826 +
14827 + if (pEntry) {
14828 + printk("\nTear down Rec BA Session: Tid = %d\n", tid);
14829 + BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE);
14830 + }
14831 +
14832 + return TRUE;
14833 + }
14834 +
14835 + return FALSE;
14836 +
14837 +}
14838 +
14839 +INT Set_HtBw_Proc(
14840 + IN PRTMP_ADAPTER pAd,
14841 + IN PUCHAR arg)
14842 +{
14843 + ULONG HtBw;
14844 +
14845 + HtBw = simple_strtol(arg, 0, 10);
14846 + if (HtBw == BW_40)
14847 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
14848 + else if (HtBw == BW_20)
14849 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
14850 + else
14851 + return FALSE; //Invalid argument
14852 +
14853 + SetCommonHT(pAd);
14854 +
14855 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW));
14856 +
14857 + return TRUE;
14858 +}
14859 +
14860 +INT Set_HtMcs_Proc(
14861 + IN PRTMP_ADAPTER pAd,
14862 + IN PUCHAR arg)
14863 +{
14864 + ULONG HtMcs, Mcs_tmp;
14865 +#ifdef CONFIG_STA_SUPPORT
14866 + BOOLEAN bAutoRate = FALSE;
14867 +#endif // CONFIG_STA_SUPPORT //
14868 +
14869 + Mcs_tmp = simple_strtol(arg, 0, 10);
14870 +
14871 + if (Mcs_tmp <= 15 || Mcs_tmp == 32)
14872 + HtMcs = Mcs_tmp;
14873 + else
14874 + HtMcs = MCS_AUTO;
14875 +
14876 +#ifdef CONFIG_STA_SUPPORT
14877 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14878 + {
14879 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs;
14880 + pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE;
14881 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n",
14882 + pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch));
14883 +
14884 + if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) ||
14885 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
14886 + {
14887 + if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
14888 + (HtMcs >= 0 && HtMcs <= 3) &&
14889 + (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
14890 + {
14891 + RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
14892 + }
14893 + else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
14894 + (HtMcs >= 0 && HtMcs <= 7) &&
14895 + (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
14896 + {
14897 + RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
14898 + }
14899 + else
14900 + bAutoRate = TRUE;
14901 +
14902 + if (bAutoRate)
14903 + {
14904 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
14905 + RTMPSetDesiredRates(pAd, -1);
14906 + }
14907 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode));
14908 + }
14909 + if (ADHOC_ON(pAd))
14910 + return TRUE;
14911 + }
14912 +#endif // CONFIG_STA_SUPPORT //
14913 +
14914 + SetCommonHT(pAd);
14915 +
14916 + return TRUE;
14917 +}
14918 +
14919 +INT Set_HtGi_Proc(
14920 + IN PRTMP_ADAPTER pAd,
14921 + IN PUCHAR arg)
14922 +{
14923 + ULONG HtGi;
14924 +
14925 + HtGi = simple_strtol(arg, 0, 10);
14926 +
14927 + if ( HtGi == GI_400)
14928 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
14929 + else if ( HtGi == GI_800 )
14930 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
14931 + else
14932 + return FALSE; //Invalid argument
14933 +
14934 + SetCommonHT(pAd);
14935 +
14936 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI));
14937 +
14938 + return TRUE;
14939 +}
14940 +
14941 +
14942 +INT Set_HtTxBASize_Proc(
14943 + IN PRTMP_ADAPTER pAd,
14944 + IN PUCHAR arg)
14945 +{
14946 + UCHAR Size;
14947 +
14948 + Size = simple_strtol(arg, 0, 10);
14949 +
14950 + if (Size <=0 || Size >=64)
14951 + {
14952 + Size = 8;
14953 + }
14954 + pAd->CommonCfg.TxBASize = Size-1;
14955 + DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
14956 +
14957 + return TRUE;
14958 +}
14959 +
14960 +
14961 +INT Set_HtOpMode_Proc(
14962 + IN PRTMP_ADAPTER pAd,
14963 + IN PUCHAR arg)
14964 +{
14965 +
14966 + ULONG Value;
14967 +
14968 + Value = simple_strtol(arg, 0, 10);
14969 +
14970 + if (Value == HTMODE_GF)
14971 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
14972 + else if ( Value == HTMODE_MM )
14973 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
14974 + else
14975 + return FALSE; //Invalid argument
14976 +
14977 + SetCommonHT(pAd);
14978 +
14979 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE));
14980 +
14981 + return TRUE;
14982 +
14983 +}
14984 +
14985 +INT Set_HtStbc_Proc(
14986 + IN PRTMP_ADAPTER pAd,
14987 + IN PUCHAR arg)
14988 +{
14989 +
14990 + ULONG Value;
14991 +
14992 + Value = simple_strtol(arg, 0, 10);
14993 +
14994 + if (Value == STBC_USE)
14995 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
14996 + else if ( Value == STBC_NONE )
14997 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
14998 + else
14999 + return FALSE; //Invalid argument
15000 +
15001 + SetCommonHT(pAd);
15002 +
15003 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC));
15004 +
15005 + return TRUE;
15006 +}
15007 +
15008 +INT Set_HtHtc_Proc(
15009 + IN PRTMP_ADAPTER pAd,
15010 + IN PUCHAR arg)
15011 +{
15012 +
15013 + ULONG Value;
15014 +
15015 + Value = simple_strtol(arg, 0, 10);
15016 + if (Value == 0)
15017 + pAd->HTCEnable = FALSE;
15018 + else if ( Value ==1 )
15019 + pAd->HTCEnable = TRUE;
15020 + else
15021 + return FALSE; //Invalid argument
15022 +
15023 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable));
15024 +
15025 + return TRUE;
15026 +}
15027 +
15028 +INT Set_HtExtcha_Proc(
15029 + IN PRTMP_ADAPTER pAd,
15030 + IN PUCHAR arg)
15031 +{
15032 +
15033 + ULONG Value;
15034 +
15035 + Value = simple_strtol(arg, 0, 10);
15036 +
15037 + if (Value == 0)
15038 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
15039 + else if ( Value ==1 )
15040 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
15041 + else
15042 + return FALSE; //Invalid argument
15043 +
15044 + SetCommonHT(pAd);
15045 +
15046 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA));
15047 +
15048 + return TRUE;
15049 +}
15050 +
15051 +INT Set_HtMpduDensity_Proc(
15052 + IN PRTMP_ADAPTER pAd,
15053 + IN PUCHAR arg)
15054 +{
15055 + ULONG Value;
15056 +
15057 + Value = simple_strtol(arg, 0, 10);
15058 +
15059 + if (Value <=7 && Value >= 0)
15060 + pAd->CommonCfg.BACapability.field.MpduDensity = Value;
15061 + else
15062 + pAd->CommonCfg.BACapability.field.MpduDensity = 4;
15063 +
15064 + SetCommonHT(pAd);
15065 +
15066 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity));
15067 +
15068 + return TRUE;
15069 +}
15070 +
15071 +INT Set_HtBaWinSize_Proc(
15072 + IN PRTMP_ADAPTER pAd,
15073 + IN PUCHAR arg)
15074 +{
15075 + ULONG Value;
15076 +
15077 + Value = simple_strtol(arg, 0, 10);
15078 +
15079 +
15080 + if (Value >=1 && Value <= 64)
15081 + {
15082 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
15083 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
15084 + }
15085 + else
15086 + {
15087 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
15088 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
15089 + }
15090 +
15091 + SetCommonHT(pAd);
15092 +
15093 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit));
15094 +
15095 + return TRUE;
15096 +}
15097 +
15098 +INT Set_HtRdg_Proc(
15099 + IN PRTMP_ADAPTER pAd,
15100 + IN PUCHAR arg)
15101 +{
15102 + ULONG Value;
15103 +
15104 + Value = simple_strtol(arg, 0, 10);
15105 +
15106 + if (Value == 0)
15107 + pAd->CommonCfg.bRdg = FALSE;
15108 + else if ( Value ==1 )
15109 + {
15110 + pAd->HTCEnable = TRUE;
15111 + pAd->CommonCfg.bRdg = TRUE;
15112 + }
15113 + else
15114 + return FALSE; //Invalid argument
15115 +
15116 + SetCommonHT(pAd);
15117 +
15118 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg));
15119 +
15120 + return TRUE;
15121 +}
15122 +
15123 +INT Set_HtLinkAdapt_Proc(
15124 + IN PRTMP_ADAPTER pAd,
15125 + IN PUCHAR arg)
15126 +{
15127 + ULONG Value;
15128 +
15129 + Value = simple_strtol(arg, 0, 10);
15130 + if (Value == 0)
15131 + pAd->bLinkAdapt = FALSE;
15132 + else if ( Value ==1 )
15133 + {
15134 + pAd->HTCEnable = TRUE;
15135 + pAd->bLinkAdapt = TRUE;
15136 + }
15137 + else
15138 + return FALSE; //Invalid argument
15139 +
15140 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt));
15141 +
15142 + return TRUE;
15143 +}
15144 +
15145 +INT Set_HtAmsdu_Proc(
15146 + IN PRTMP_ADAPTER pAd,
15147 + IN PUCHAR arg)
15148 +{
15149 + ULONG Value;
15150 +
15151 + Value = simple_strtol(arg, 0, 10);
15152 + if (Value == 0)
15153 + pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
15154 + else if ( Value == 1 )
15155 + pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
15156 + else
15157 + return FALSE; //Invalid argument
15158 +
15159 + SetCommonHT(pAd);
15160 +
15161 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable));
15162 +
15163 + return TRUE;
15164 +}
15165 +
15166 +INT Set_HtAutoBa_Proc(
15167 + IN PRTMP_ADAPTER pAd,
15168 + IN PUCHAR arg)
15169 +{
15170 + ULONG Value;
15171 +
15172 + Value = simple_strtol(arg, 0, 10);
15173 + if (Value == 0)
15174 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
15175 + else if (Value == 1)
15176 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
15177 + else
15178 + return FALSE; //Invalid argument
15179 +
15180 + pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
15181 + SetCommonHT(pAd);
15182 +
15183 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA));
15184 +
15185 + return TRUE;
15186 +
15187 +}
15188 +
15189 +INT Set_HtProtect_Proc(
15190 + IN PRTMP_ADAPTER pAd,
15191 + IN PUCHAR arg)
15192 +{
15193 + ULONG Value;
15194 +
15195 + Value = simple_strtol(arg, 0, 10);
15196 + if (Value == 0)
15197 + pAd->CommonCfg.bHTProtect = FALSE;
15198 + else if (Value == 1)
15199 + pAd->CommonCfg.bHTProtect = TRUE;
15200 + else
15201 + return FALSE; //Invalid argument
15202 +
15203 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect));
15204 +
15205 + return TRUE;
15206 +}
15207 +
15208 +INT Set_SendPSMPAction_Proc(
15209 + IN PRTMP_ADAPTER pAd,
15210 + IN PUCHAR arg)
15211 +{
15212 + UCHAR mac[6], mode;
15213 + char *token, sepValue[] = ":", DASH = '-';
15214 + INT i;
15215 + MAC_TABLE_ENTRY *pEntry;
15216 +
15217 + //printk("\n%s\n", arg);
15218 +/*
15219 + The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
15220 + =>The six 2 digit hex-decimal number previous are the Mac address,
15221 + =>The seventh decimal number is the mode value.
15222 +*/
15223 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format.
15224 + return FALSE;
15225 +
15226 + token = strchr(arg, DASH);
15227 + if ((token != NULL) && (strlen(token)>1))
15228 + {
15229 + mode = simple_strtol((token+1), 0, 10);
15230 + if (mode > MMPS_ENABLE)
15231 + return FALSE;
15232 +
15233 + *token = '\0';
15234 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
15235 + {
15236 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
15237 + return FALSE;
15238 + AtoH(token, (PUCHAR)(&mac[i]), 1);
15239 + }
15240 + if(i != 6)
15241 + return FALSE;
15242 +
15243 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
15244 + mac[2], mac[3], mac[4], mac[5], mode);
15245 +
15246 + pEntry = MacTableLookup(pAd, mac);
15247 +
15248 + if (pEntry) {
15249 + printk("\nSendPSMPAction MIPS mode = %d\n", mode);
15250 + SendPSMPAction(pAd, pEntry->Aid, mode);
15251 + }
15252 +
15253 + return TRUE;
15254 + }
15255 +
15256 + return FALSE;
15257 +
15258 +
15259 +}
15260 +
15261 +INT Set_HtMIMOPSmode_Proc(
15262 + IN PRTMP_ADAPTER pAd,
15263 + IN PUCHAR arg)
15264 +{
15265 + ULONG Value;
15266 +
15267 + Value = simple_strtol(arg, 0, 10);
15268 +
15269 + if (Value <=3 && Value >= 0)
15270 + pAd->CommonCfg.BACapability.field.MMPSmode = Value;
15271 + else
15272 + pAd->CommonCfg.BACapability.field.MMPSmode = 3;
15273 +
15274 + SetCommonHT(pAd);
15275 +
15276 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode));
15277 +
15278 + return TRUE;
15279 +}
15280 +
15281 +
15282 +INT Set_ForceShortGI_Proc(
15283 + IN PRTMP_ADAPTER pAd,
15284 + IN PUCHAR arg)
15285 +{
15286 + ULONG Value;
15287 +
15288 + Value = simple_strtol(arg, 0, 10);
15289 + if (Value == 0)
15290 + pAd->WIFItestbed.bShortGI = FALSE;
15291 + else if (Value == 1)
15292 + pAd->WIFItestbed.bShortGI = TRUE;
15293 + else
15294 + return FALSE; //Invalid argument
15295 +
15296 + SetCommonHT(pAd);
15297 +
15298 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI));
15299 +
15300 + return TRUE;
15301 +}
15302 +
15303 +
15304 +
15305 +INT Set_ForceGF_Proc(
15306 + IN PRTMP_ADAPTER pAd,
15307 + IN PUCHAR arg)
15308 +{
15309 + ULONG Value;
15310 +
15311 + Value = simple_strtol(arg, 0, 10);
15312 + if (Value == 0)
15313 + pAd->WIFItestbed.bGreenField = FALSE;
15314 + else if (Value == 1)
15315 + pAd->WIFItestbed.bGreenField = TRUE;
15316 + else
15317 + return FALSE; //Invalid argument
15318 +
15319 + SetCommonHT(pAd);
15320 +
15321 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField));
15322 +
15323 + return TRUE;
15324 +}
15325 +
15326 +INT Set_HtMimoPs_Proc(
15327 + IN PRTMP_ADAPTER pAd,
15328 + IN PUCHAR arg)
15329 +{
15330 + ULONG Value;
15331 +
15332 + Value = simple_strtol(arg, 0, 10);
15333 + if (Value == 0)
15334 + pAd->CommonCfg.bMIMOPSEnable = FALSE;
15335 + else if (Value == 1)
15336 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
15337 + else
15338 + return FALSE; //Invalid argument
15339 +
15340 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable));
15341 +
15342 + return TRUE;
15343 +}
15344 +#endif // DOT11_N_SUPPORT //
15345 +
15346 +
15347 +#ifdef DOT11_N_SUPPORT
15348 +INT SetCommonHT(
15349 + IN PRTMP_ADAPTER pAd)
15350 +{
15351 + OID_SET_HT_PHYMODE SetHT;
15352 +
15353 + if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
15354 + return FALSE;
15355 +
15356 + SetHT.PhyMode = pAd->CommonCfg.PhyMode;
15357 + SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath);
15358 + SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
15359 + SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
15360 + SetHT.MCS = MCS_AUTO;
15361 + SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW;
15362 + SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC;
15363 + SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
15364 +
15365 + RTMPSetHT(pAd, &SetHT);
15366 +
15367 + return TRUE;
15368 +}
15369 +#endif // DOT11_N_SUPPORT //
15370 +
15371 +INT Set_FixedTxMode_Proc(
15372 + IN PRTMP_ADAPTER pAd,
15373 + IN PUCHAR arg)
15374 +{
15375 + UCHAR fix_tx_mode = FIXED_TXMODE_HT;
15376 +
15377 + if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0)
15378 + {
15379 + fix_tx_mode = FIXED_TXMODE_OFDM;
15380 + }
15381 + else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0)
15382 + {
15383 + fix_tx_mode = FIXED_TXMODE_CCK;
15384 + }
15385 +
15386 +#ifdef CONFIG_STA_SUPPORT
15387 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15388 + pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
15389 +#endif // CONFIG_STA_SUPPORT //
15390 +
15391 + DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode));
15392 +
15393 + return TRUE;
15394 +}
15395 +
15396 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
15397 +INT Set_OpMode_Proc(
15398 + IN PRTMP_ADAPTER pAd,
15399 + IN PUCHAR arg)
15400 +{
15401 + ULONG Value;
15402 +
15403 + Value = simple_strtol(arg, 0, 10);
15404 +
15405 +#ifdef RT2870
15406 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
15407 +#endif // RT2870 //
15408 + {
15409 + DBGPRINT(RT_DEBUG_ERROR, ("Can not switch operate mode on interface up !! \n"));
15410 + return FALSE;
15411 + }
15412 +
15413 + if (Value == 0)
15414 + pAd->OpMode = OPMODE_STA;
15415 + else if (Value == 1)
15416 + pAd->OpMode = OPMODE_AP;
15417 + else
15418 + return FALSE; //Invalid argument
15419 +
15420 + DBGPRINT(RT_DEBUG_TRACE, ("Set_OpMode_Proc::(OpMode=%s)\n", pAd->OpMode == 1 ? "AP Mode" : "STA Mode"));
15421 +
15422 + return TRUE;
15423 +}
15424 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
15425 +
15426 +
15427 +/////////////////////////////////////////////////////////////////////////
15428 +PCHAR RTMPGetRalinkAuthModeStr(
15429 + IN NDIS_802_11_AUTHENTICATION_MODE authMode)
15430 +{
15431 + switch(authMode)
15432 + {
15433 + case Ndis802_11AuthModeOpen:
15434 + return "OPEN";
15435 + case Ndis802_11AuthModeWPAPSK:
15436 + return "WPAPSK";
15437 + case Ndis802_11AuthModeShared:
15438 + return "SHARED";
15439 + case Ndis802_11AuthModeWPA:
15440 + return "WPA";
15441 + case Ndis802_11AuthModeWPA2:
15442 + return "WPA2";
15443 + case Ndis802_11AuthModeWPA2PSK:
15444 + return "WPA2PSK";
15445 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
15446 + return "WPAPSKWPA2PSK";
15447 + case Ndis802_11AuthModeWPA1WPA2:
15448 + return "WPA1WPA2";
15449 + case Ndis802_11AuthModeWPANone:
15450 + return "WPANONE";
15451 + default:
15452 + return "UNKNOW";
15453 + }
15454 +}
15455 +
15456 +PCHAR RTMPGetRalinkEncryModeStr(
15457 + IN USHORT encryMode)
15458 +{
15459 + switch(encryMode)
15460 + {
15461 + case Ndis802_11WEPDisabled:
15462 + return "NONE";
15463 + case Ndis802_11WEPEnabled:
15464 + return "WEP";
15465 + case Ndis802_11Encryption2Enabled:
15466 + return "TKIP";
15467 + case Ndis802_11Encryption3Enabled:
15468 + return "AES";
15469 + case Ndis802_11Encryption4Enabled:
15470 + return "TKIPAES";
15471 + default:
15472 + return "UNKNOW";
15473 + }
15474 +}
15475 +
15476 +INT RTMPShowCfgValue(
15477 + IN PRTMP_ADAPTER pAd,
15478 + IN PUCHAR pName,
15479 + IN PUCHAR pBuf)
15480 +{
15481 + INT Status = 0;
15482 +
15483 + 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++)
15484 + {
15485 + if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name))
15486 + {
15487 + if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf))
15488 + Status = -EINVAL;
15489 + break; //Exit for loop.
15490 + }
15491 + }
15492 +
15493 + if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL)
15494 + {
15495 + sprintf(pBuf, "\n");
15496 + 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++)
15497 + sprintf(pBuf, "%s%s\n", pBuf, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
15498 + }
15499 +
15500 + return Status;
15501 +}
15502 +
15503 +INT Show_SSID_Proc(
15504 + IN PRTMP_ADAPTER pAd,
15505 + OUT PUCHAR pBuf)
15506 +{
15507 +
15508 +#ifdef CONFIG_STA_SUPPORT
15509 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15510 + sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid);
15511 +#endif // CONFIG_STA_SUPPORT //
15512 + return 0;
15513 +}
15514 +
15515 +INT Show_WirelessMode_Proc(
15516 + IN PRTMP_ADAPTER pAd,
15517 + OUT PUCHAR pBuf)
15518 +{
15519 + switch(pAd->CommonCfg.PhyMode)
15520 + {
15521 + case PHY_11BG_MIXED:
15522 + sprintf(pBuf, "\t11B/G");
15523 + break;
15524 + case PHY_11B:
15525 + sprintf(pBuf, "\t11B");
15526 + break;
15527 + case PHY_11A:
15528 + sprintf(pBuf, "\t11A");
15529 + break;
15530 + case PHY_11ABG_MIXED:
15531 + sprintf(pBuf, "\t11A/B/G");
15532 + break;
15533 + case PHY_11G:
15534 + sprintf(pBuf, "\t11G");
15535 + break;
15536 +#ifdef DOT11_N_SUPPORT
15537 + case PHY_11ABGN_MIXED:
15538 + sprintf(pBuf, "\t11A/B/G/N");
15539 + break;
15540 + case PHY_11N_2_4G:
15541 + sprintf(pBuf, "\t11N only with 2.4G");
15542 + break;
15543 + case PHY_11GN_MIXED:
15544 + sprintf(pBuf, "\t11G/N");
15545 + break;
15546 + case PHY_11AN_MIXED:
15547 + sprintf(pBuf, "\t11A/N");
15548 + break;
15549 + case PHY_11BGN_MIXED:
15550 + sprintf(pBuf, "\t11B/G/N");
15551 + break;
15552 + case PHY_11AGN_MIXED:
15553 + sprintf(pBuf, "\t11A/G/N");
15554 + break;
15555 + case PHY_11N_5G:
15556 + sprintf(pBuf, "\t11N only with 5G");
15557 + break;
15558 +#endif // DOT11_N_SUPPORT //
15559 + default:
15560 + sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode);
15561 + break;
15562 + }
15563 + return 0;
15564 +}
15565 +
15566 +
15567 +INT Show_TxBurst_Proc(
15568 + IN PRTMP_ADAPTER pAd,
15569 + OUT PUCHAR pBuf)
15570 +{
15571 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE");
15572 + return 0;
15573 +}
15574 +
15575 +INT Show_TxPreamble_Proc(
15576 + IN PRTMP_ADAPTER pAd,
15577 + OUT PUCHAR pBuf)
15578 +{
15579 + switch(pAd->CommonCfg.TxPreamble)
15580 + {
15581 + case Rt802_11PreambleShort:
15582 + sprintf(pBuf, "\tShort");
15583 + break;
15584 + case Rt802_11PreambleLong:
15585 + sprintf(pBuf, "\tLong");
15586 + break;
15587 + case Rt802_11PreambleAuto:
15588 + sprintf(pBuf, "\tAuto");
15589 + break;
15590 + default:
15591 + sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble);
15592 + break;
15593 + }
15594 +
15595 + return 0;
15596 +}
15597 +
15598 +INT Show_TxPower_Proc(
15599 + IN PRTMP_ADAPTER pAd,
15600 + OUT PUCHAR pBuf)
15601 +{
15602 + sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage);
15603 + return 0;
15604 +}
15605 +
15606 +INT Show_Channel_Proc(
15607 + IN PRTMP_ADAPTER pAd,
15608 + OUT PUCHAR pBuf)
15609 +{
15610 + sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel);
15611 + return 0;
15612 +}
15613 +
15614 +INT Show_BGProtection_Proc(
15615 + IN PRTMP_ADAPTER pAd,
15616 + OUT PUCHAR pBuf)
15617 +{
15618 + switch(pAd->CommonCfg.UseBGProtection)
15619 + {
15620 + case 1: //Always On
15621 + sprintf(pBuf, "\tON");
15622 + break;
15623 + case 2: //Always OFF
15624 + sprintf(pBuf, "\tOFF");
15625 + break;
15626 + case 0: //AUTO
15627 + sprintf(pBuf, "\tAuto");
15628 + break;
15629 + default:
15630 + sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection);
15631 + break;
15632 + }
15633 + return 0;
15634 +}
15635 +
15636 +INT Show_RTSThreshold_Proc(
15637 + IN PRTMP_ADAPTER pAd,
15638 + OUT PUCHAR pBuf)
15639 +{
15640 + sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold);
15641 + return 0;
15642 +}
15643 +
15644 +INT Show_FragThreshold_Proc(
15645 + IN PRTMP_ADAPTER pAd,
15646 + OUT PUCHAR pBuf)
15647 +{
15648 + sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold);
15649 + return 0;
15650 +}
15651 +
15652 +#ifdef DOT11_N_SUPPORT
15653 +INT Show_HtBw_Proc(
15654 + IN PRTMP_ADAPTER pAd,
15655 + OUT PUCHAR pBuf)
15656 +{
15657 + if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
15658 + {
15659 + sprintf(pBuf, "\t40 MHz");
15660 + }
15661 + else
15662 + {
15663 + sprintf(pBuf, "\t20 MHz");
15664 + }
15665 + return 0;
15666 +}
15667 +
15668 +INT Show_HtMcs_Proc(
15669 + IN PRTMP_ADAPTER pAd,
15670 + OUT PUCHAR pBuf)
15671 +{
15672 +
15673 +#ifdef CONFIG_STA_SUPPORT
15674 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15675 + sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS);
15676 +#endif // CONFIG_STA_SUPPORT //
15677 + return 0;
15678 +}
15679 +
15680 +INT Show_HtGi_Proc(
15681 + IN PRTMP_ADAPTER pAd,
15682 + OUT PUCHAR pBuf)
15683 +{
15684 + switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI)
15685 + {
15686 + case GI_400:
15687 + sprintf(pBuf, "\tGI_400");
15688 + break;
15689 + case GI_800:
15690 + sprintf(pBuf, "\tGI_800");
15691 + break;
15692 + default:
15693 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI);
15694 + break;
15695 + }
15696 + return 0;
15697 +}
15698 +
15699 +INT Show_HtOpMode_Proc(
15700 + IN PRTMP_ADAPTER pAd,
15701 + OUT PUCHAR pBuf)
15702 +{
15703 + switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE)
15704 + {
15705 + case HTMODE_GF:
15706 + sprintf(pBuf, "\tGF");
15707 + break;
15708 + case HTMODE_MM:
15709 + sprintf(pBuf, "\tMM");
15710 + break;
15711 + default:
15712 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE);
15713 + break;
15714 + }
15715 + return 0;
15716 +}
15717 +
15718 +INT Show_HtExtcha_Proc(
15719 + IN PRTMP_ADAPTER pAd,
15720 + OUT PUCHAR pBuf)
15721 +{
15722 + switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)
15723 + {
15724 + case EXTCHA_BELOW:
15725 + sprintf(pBuf, "\tBelow");
15726 + break;
15727 + case EXTCHA_ABOVE:
15728 + sprintf(pBuf, "\tAbove");
15729 + break;
15730 + default:
15731 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA);
15732 + break;
15733 + }
15734 + return 0;
15735 +}
15736 +
15737 +
15738 +INT Show_HtMpduDensity_Proc(
15739 + IN PRTMP_ADAPTER pAd,
15740 + OUT PUCHAR pBuf)
15741 +{
15742 + sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity);
15743 + return 0;
15744 +}
15745 +
15746 +INT Show_HtBaWinSize_Proc(
15747 + IN PRTMP_ADAPTER pAd,
15748 + OUT PUCHAR pBuf)
15749 +{
15750 + sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit);
15751 + return 0;
15752 +}
15753 +
15754 +INT Show_HtRdg_Proc(
15755 + IN PRTMP_ADAPTER pAd,
15756 + OUT PUCHAR pBuf)
15757 +{
15758 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE");
15759 + return 0;
15760 +}
15761 +
15762 +INT Show_HtAmsdu_Proc(
15763 + IN PRTMP_ADAPTER pAd,
15764 + OUT PUCHAR pBuf)
15765 +{
15766 + sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE");
15767 + return 0;
15768 +}
15769 +
15770 +INT Show_HtAutoBa_Proc(
15771 + IN PRTMP_ADAPTER pAd,
15772 + OUT PUCHAR pBuf)
15773 +{
15774 + sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE");
15775 + return 0;
15776 +}
15777 +#endif // DOT11_N_SUPPORT //
15778 +
15779 +INT Show_CountryRegion_Proc(
15780 + IN PRTMP_ADAPTER pAd,
15781 + OUT PUCHAR pBuf)
15782 +{
15783 + sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion);
15784 + return 0;
15785 +}
15786 +
15787 +INT Show_CountryRegionABand_Proc(
15788 + IN PRTMP_ADAPTER pAd,
15789 + OUT PUCHAR pBuf)
15790 +{
15791 + sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand);
15792 + return 0;
15793 +}
15794 +
15795 +INT Show_CountryCode_Proc(
15796 + IN PRTMP_ADAPTER pAd,
15797 + OUT PUCHAR pBuf)
15798 +{
15799 + sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode);
15800 + return 0;
15801 +}
15802 +
15803 +#ifdef AGGREGATION_SUPPORT
15804 +INT Show_PktAggregate_Proc(
15805 + IN PRTMP_ADAPTER pAd,
15806 + OUT PUCHAR pBuf)
15807 +{
15808 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE");
15809 + return 0;
15810 +}
15811 +#endif // AGGREGATION_SUPPORT //
15812 +
15813 +#ifdef WMM_SUPPORT
15814 +INT Show_WmmCapable_Proc(
15815 + IN PRTMP_ADAPTER pAd,
15816 + OUT PUCHAR pBuf)
15817 +{
15818 +
15819 +#ifdef CONFIG_STA_SUPPORT
15820 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15821 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE");
15822 +#endif // CONFIG_STA_SUPPORT //
15823 +
15824 + return 0;
15825 +}
15826 +#endif // WMM_SUPPORT //
15827 +
15828 +INT Show_IEEE80211H_Proc(
15829 + IN PRTMP_ADAPTER pAd,
15830 + OUT PUCHAR pBuf)
15831 +{
15832 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE");
15833 + return 0;
15834 +}
15835 +
15836 +#ifdef CONFIG_STA_SUPPORT
15837 +INT Show_NetworkType_Proc(
15838 + IN PRTMP_ADAPTER pAd,
15839 + OUT PUCHAR pBuf)
15840 +{
15841 + switch(pAd->StaCfg.BssType)
15842 + {
15843 + case BSS_ADHOC:
15844 + sprintf(pBuf, "\tAdhoc");
15845 + break;
15846 + case BSS_INFRA:
15847 + sprintf(pBuf, "\tInfra");
15848 + break;
15849 + case BSS_ANY:
15850 + sprintf(pBuf, "\tAny");
15851 + break;
15852 + case BSS_MONITOR:
15853 + sprintf(pBuf, "\tMonitor");
15854 + break;
15855 + default:
15856 + sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType);
15857 + break;
15858 + }
15859 + return 0;
15860 +}
15861 +#endif // CONFIG_STA_SUPPORT //
15862 +
15863 +INT Show_AuthMode_Proc(
15864 + IN PRTMP_ADAPTER pAd,
15865 + OUT PUCHAR pBuf)
15866 +{
15867 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen;
15868 +
15869 +#ifdef CONFIG_STA_SUPPORT
15870 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15871 + AuthMode = pAd->StaCfg.AuthMode;
15872 +#endif // CONFIG_STA_SUPPORT //
15873 +
15874 + if ((AuthMode >= Ndis802_11AuthModeOpen) &&
15875 + (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
15876 + sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode));
15877 + else
15878 + sprintf(pBuf, "\tUnknow Value(%d)", AuthMode);
15879 +
15880 + return 0;
15881 +}
15882 +
15883 +INT Show_EncrypType_Proc(
15884 + IN PRTMP_ADAPTER pAd,
15885 + OUT PUCHAR pBuf)
15886 +{
15887 + NDIS_802_11_WEP_STATUS WepStatus = Ndis802_11WEPDisabled;
15888 +
15889 +#ifdef CONFIG_STA_SUPPORT
15890 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15891 + WepStatus = pAd->StaCfg.WepStatus;
15892 +#endif // CONFIG_STA_SUPPORT //
15893 +
15894 + if ((WepStatus >= Ndis802_11WEPEnabled) &&
15895 + (WepStatus <= Ndis802_11Encryption4KeyAbsent))
15896 + sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus));
15897 + else
15898 + sprintf(pBuf, "\tUnknow Value(%d)", WepStatus);
15899 +
15900 + return 0;
15901 +}
15902 +
15903 +INT Show_DefaultKeyID_Proc(
15904 + IN PRTMP_ADAPTER pAd,
15905 + OUT PUCHAR pBuf)
15906 +{
15907 + UCHAR DefaultKeyId = 0;
15908 +
15909 +#ifdef CONFIG_STA_SUPPORT
15910 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15911 + DefaultKeyId = pAd->StaCfg.DefaultKeyId;
15912 +#endif // CONFIG_STA_SUPPORT //
15913 +
15914 + sprintf(pBuf, "\t%d", DefaultKeyId);
15915 +
15916 + return 0;
15917 +}
15918 +
15919 +INT Show_WepKey_Proc(
15920 + IN PRTMP_ADAPTER pAd,
15921 + IN INT KeyIdx,
15922 + OUT PUCHAR pBuf)
15923 +{
15924 + UCHAR Key[16] = {0}, KeyLength = 0;
15925 + INT index = BSS0;
15926 +
15927 + KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen;
15928 + NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength);
15929 +
15930 + //check key string is ASCII or not
15931 + if (RTMPCheckStrPrintAble(Key, KeyLength))
15932 + sprintf(pBuf, "\t%s", Key);
15933 + else
15934 + {
15935 + int idx;
15936 + sprintf(pBuf, "\t");
15937 + for (idx = 0; idx < KeyLength; idx++)
15938 + sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]);
15939 + }
15940 + return 0;
15941 +}
15942 +
15943 +INT Show_Key1_Proc(
15944 + IN PRTMP_ADAPTER pAd,
15945 + OUT PUCHAR pBuf)
15946 +{
15947 + Show_WepKey_Proc(pAd, 0, pBuf);
15948 + return 0;
15949 +}
15950 +
15951 +INT Show_Key2_Proc(
15952 + IN PRTMP_ADAPTER pAd,
15953 + OUT PUCHAR pBuf)
15954 +{
15955 + Show_WepKey_Proc(pAd, 1, pBuf);
15956 + return 0;
15957 +}
15958 +
15959 +INT Show_Key3_Proc(
15960 + IN PRTMP_ADAPTER pAd,
15961 + OUT PUCHAR pBuf)
15962 +{
15963 + Show_WepKey_Proc(pAd, 2, pBuf);
15964 + return 0;
15965 +}
15966 +
15967 +INT Show_Key4_Proc(
15968 + IN PRTMP_ADAPTER pAd,
15969 + OUT PUCHAR pBuf)
15970 +{
15971 + Show_WepKey_Proc(pAd, 3, pBuf);
15972 + return 0;
15973 +}
15974 +
15975 +INT Show_WPAPSK_Proc(
15976 + IN PRTMP_ADAPTER pAd,
15977 + OUT PUCHAR pBuf)
15978 +{
15979 + INT idx;
15980 + UCHAR PMK[32] = {0};
15981 +
15982 +
15983 +#ifdef CONFIG_STA_SUPPORT
15984 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15985 + NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32);
15986 +#endif // CONFIG_STA_SUPPORT //
15987 +
15988 + sprintf(pBuf, "\tPMK = ");
15989 + for (idx = 0; idx < 32; idx++)
15990 + sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]);
15991 +
15992 + return 0;
15993 +}
15994 +
15995 --- /dev/null
15996 +++ b/drivers/staging/rt2870/common/cmm_sanity.c
15997 @@ -0,0 +1,1663 @@
15998 +/*
15999 + *************************************************************************
16000 + * Ralink Tech Inc.
16001 + * 5F., No.36, Taiyuan St., Jhubei City,
16002 + * Hsinchu County 302,
16003 + * Taiwan, R.O.C.
16004 + *
16005 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
16006 + *
16007 + * This program is free software; you can redistribute it and/or modify *
16008 + * it under the terms of the GNU General Public License as published by *
16009 + * the Free Software Foundation; either version 2 of the License, or *
16010 + * (at your option) any later version. *
16011 + * *
16012 + * This program is distributed in the hope that it will be useful, *
16013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16015 + * GNU General Public License for more details. *
16016 + * *
16017 + * You should have received a copy of the GNU General Public License *
16018 + * along with this program; if not, write to the *
16019 + * Free Software Foundation, Inc., *
16020 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
16021 + * *
16022 + *************************************************************************
16023 +
16024 + Module Name:
16025 + sanity.c
16026 +
16027 + Abstract:
16028 +
16029 + Revision History:
16030 + Who When What
16031 + -------- ---------- ----------------------------------------------
16032 + John Chang 2004-09-01 add WMM support
16033 +*/
16034 +#include "../rt_config.h"
16035 +
16036 +
16037 +extern UCHAR CISCO_OUI[];
16038 +
16039 +extern UCHAR WPA_OUI[];
16040 +extern UCHAR RSN_OUI[];
16041 +extern UCHAR WME_INFO_ELEM[];
16042 +extern UCHAR WME_PARM_ELEM[];
16043 +extern UCHAR Ccx2QosInfo[];
16044 +extern UCHAR RALINK_OUI[];
16045 +extern UCHAR BROADCOM_OUI[];
16046 +extern UCHAR WPS_OUI[];
16047 +
16048 +/*
16049 + ==========================================================================
16050 + Description:
16051 + MLME message sanity check
16052 + Return:
16053 + TRUE if all parameters are OK, FALSE otherwise
16054 +
16055 + IRQL = DISPATCH_LEVEL
16056 +
16057 + ==========================================================================
16058 + */
16059 +BOOLEAN MlmeAddBAReqSanity(
16060 + IN PRTMP_ADAPTER pAd,
16061 + IN VOID *Msg,
16062 + IN ULONG MsgLen,
16063 + OUT PUCHAR pAddr2)
16064 +{
16065 + PMLME_ADDBA_REQ_STRUCT pInfo;
16066 +
16067 + pInfo = (MLME_ADDBA_REQ_STRUCT *)Msg;
16068 +
16069 + if ((MsgLen != sizeof(MLME_ADDBA_REQ_STRUCT)))
16070 + {
16071 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - message lenght not correct.\n"));
16072 + return FALSE;
16073 + }
16074 +
16075 + if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))
16076 + {
16077 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n"));
16078 + return FALSE;
16079 + }
16080 +
16081 + /*
16082 + if ((pInfo->BaBufSize > MAX_RX_REORDERBUF) || (pInfo->BaBufSize < 2))
16083 + {
16084 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - Rx Reordering buffer too big or too small\n"));
16085 + return FALSE;
16086 + }
16087 + */
16088 +
16089 + if ((pInfo->pAddr[0]&0x01) == 0x01)
16090 + {
16091 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - broadcast address not support BA\n"));
16092 + return FALSE;
16093 + }
16094 +
16095 + return TRUE;
16096 +}
16097 +
16098 +/*
16099 + ==========================================================================
16100 + Description:
16101 + MLME message sanity check
16102 + Return:
16103 + TRUE if all parameters are OK, FALSE otherwise
16104 +
16105 + IRQL = DISPATCH_LEVEL
16106 +
16107 + ==========================================================================
16108 + */
16109 +BOOLEAN MlmeDelBAReqSanity(
16110 + IN PRTMP_ADAPTER pAd,
16111 + IN VOID *Msg,
16112 + IN ULONG MsgLen)
16113 +{
16114 + MLME_DELBA_REQ_STRUCT *pInfo;
16115 + pInfo = (MLME_DELBA_REQ_STRUCT *)Msg;
16116 +
16117 + if ((MsgLen != sizeof(MLME_DELBA_REQ_STRUCT)))
16118 + {
16119 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - message lenght not correct.\n"));
16120 + return FALSE;
16121 + }
16122 +
16123 + if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))
16124 + {
16125 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n"));
16126 + return FALSE;
16127 + }
16128 +
16129 + if ((pInfo->TID & 0xf0))
16130 + {
16131 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n"));
16132 + return FALSE;
16133 + }
16134 +
16135 + if (NdisEqualMemory(pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr, MAC_ADDR_LEN) == 0)
16136 + {
16137 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n"));
16138 + return FALSE;
16139 + }
16140 +
16141 + return TRUE;
16142 +}
16143 +
16144 +BOOLEAN PeerAddBAReqActionSanity(
16145 + IN PRTMP_ADAPTER pAd,
16146 + IN VOID *pMsg,
16147 + IN ULONG MsgLen,
16148 + OUT PUCHAR pAddr2)
16149 +{
16150 + PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
16151 + PFRAME_ADDBA_REQ pAddFrame;
16152 + pAddFrame = (PFRAME_ADDBA_REQ)(pMsg);
16153 + if (MsgLen < (sizeof(FRAME_ADDBA_REQ)))
16154 + {
16155 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", MsgLen));
16156 + return FALSE;
16157 + }
16158 + // we support immediate BA.
16159 + *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm));
16160 + pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
16161 + pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word);
16162 +
16163 + if (pAddFrame->BaParm.BAPolicy != IMMED_BA)
16164 + {
16165 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));
16166 + DBGPRINT(RT_DEBUG_ERROR,("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, pAddFrame->BaParm.AMSDUSupported));
16167 + return FALSE;
16168 + }
16169 +
16170 + // we support immediate BA.
16171 + if (pAddFrame->BaParm.TID &0xfff0)
16172 + {
16173 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", pAddFrame->BaParm.TID));
16174 + return FALSE;
16175 + }
16176 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16177 + return TRUE;
16178 +}
16179 +
16180 +BOOLEAN PeerAddBARspActionSanity(
16181 + IN PRTMP_ADAPTER pAd,
16182 + IN VOID *pMsg,
16183 + IN ULONG MsgLen)
16184 +{
16185 + //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
16186 + PFRAME_ADDBA_RSP pAddFrame;
16187 +
16188 + pAddFrame = (PFRAME_ADDBA_RSP)(pMsg);
16189 + if (MsgLen < (sizeof(FRAME_ADDBA_RSP)))
16190 + {
16191 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", MsgLen));
16192 + return FALSE;
16193 + }
16194 + // we support immediate BA.
16195 + *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm));
16196 + pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode);
16197 + pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
16198 +
16199 + if (pAddFrame->BaParm.BAPolicy != IMMED_BA)
16200 + {
16201 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));
16202 + return FALSE;
16203 + }
16204 +
16205 + // we support immediate BA.
16206 + if (pAddFrame->BaParm.TID &0xfff0)
16207 + {
16208 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", pAddFrame->BaParm.TID));
16209 + return FALSE;
16210 + }
16211 + return TRUE;
16212 +
16213 +}
16214 +
16215 +BOOLEAN PeerDelBAActionSanity(
16216 + IN PRTMP_ADAPTER pAd,
16217 + IN UCHAR Wcid,
16218 + IN VOID *pMsg,
16219 + IN ULONG MsgLen )
16220 +{
16221 + //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
16222 + PFRAME_DELBA_REQ pDelFrame;
16223 + if (MsgLen != (sizeof(FRAME_DELBA_REQ)))
16224 + return FALSE;
16225 +
16226 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
16227 + return FALSE;
16228 +
16229 + pDelFrame = (PFRAME_DELBA_REQ)(pMsg);
16230 +
16231 + *(USHORT *)(&pDelFrame->DelbaParm) = cpu2le16(*(USHORT *)(&pDelFrame->DelbaParm));
16232 + pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode);
16233 +
16234 + if (pDelFrame->DelbaParm.TID &0xfff0)
16235 + return FALSE;
16236 +
16237 + return TRUE;
16238 +}
16239 +
16240 +/*
16241 + ==========================================================================
16242 + Description:
16243 + MLME message sanity check
16244 + Return:
16245 + TRUE if all parameters are OK, FALSE otherwise
16246 +
16247 + IRQL = DISPATCH_LEVEL
16248 +
16249 + ==========================================================================
16250 + */
16251 +BOOLEAN PeerBeaconAndProbeRspSanity(
16252 + IN PRTMP_ADAPTER pAd,
16253 + IN VOID *Msg,
16254 + IN ULONG MsgLen,
16255 + IN UCHAR MsgChannel,
16256 + OUT PUCHAR pAddr2,
16257 + OUT PUCHAR pBssid,
16258 + OUT CHAR Ssid[],
16259 + OUT UCHAR *pSsidLen,
16260 + OUT UCHAR *pBssType,
16261 + OUT USHORT *pBeaconPeriod,
16262 + OUT UCHAR *pChannel,
16263 + OUT UCHAR *pNewChannel,
16264 + OUT LARGE_INTEGER *pTimestamp,
16265 + OUT CF_PARM *pCfParm,
16266 + OUT USHORT *pAtimWin,
16267 + OUT USHORT *pCapabilityInfo,
16268 + OUT UCHAR *pErp,
16269 + OUT UCHAR *pDtimCount,
16270 + OUT UCHAR *pDtimPeriod,
16271 + OUT UCHAR *pBcastFlag,
16272 + OUT UCHAR *pMessageToMe,
16273 + OUT UCHAR SupRate[],
16274 + OUT UCHAR *pSupRateLen,
16275 + OUT UCHAR ExtRate[],
16276 + OUT UCHAR *pExtRateLen,
16277 + OUT UCHAR *pCkipFlag,
16278 + OUT UCHAR *pAironetCellPowerLimit,
16279 + OUT PEDCA_PARM pEdcaParm,
16280 + OUT PQBSS_LOAD_PARM pQbssLoad,
16281 + OUT PQOS_CAPABILITY_PARM pQosCapability,
16282 + OUT ULONG *pRalinkIe,
16283 + OUT UCHAR *pHtCapabilityLen,
16284 +#ifdef CONFIG_STA_SUPPORT
16285 + OUT UCHAR *pPreNHtCapabilityLen,
16286 +#endif // CONFIG_STA_SUPPORT //
16287 + OUT HT_CAPABILITY_IE *pHtCapability,
16288 + OUT UCHAR *AddHtInfoLen,
16289 + OUT ADD_HT_INFO_IE *AddHtInfo,
16290 + OUT UCHAR *NewExtChannelOffset, // Ht extension channel offset(above or below)
16291 + OUT USHORT *LengthVIE,
16292 + OUT PNDIS_802_11_VARIABLE_IEs pVIE)
16293 +{
16294 + CHAR *Ptr;
16295 +#ifdef CONFIG_STA_SUPPORT
16296 + CHAR TimLen;
16297 +#endif // CONFIG_STA_SUPPORT //
16298 + PFRAME_802_11 pFrame;
16299 + PEID_STRUCT pEid;
16300 + UCHAR SubType;
16301 + UCHAR Sanity;
16302 + //UCHAR ECWMin, ECWMax;
16303 + //MAC_CSR9_STRUC Csr9;
16304 + ULONG Length = 0;
16305 +
16306 + // For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel
16307 + // 1. If the AP is 11n enabled, then check the control channel.
16308 + // 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!!)
16309 + UCHAR CtrlChannel = 0;
16310 +
16311 + // Add for 3 necessary EID field check
16312 + Sanity = 0;
16313 +
16314 + *pAtimWin = 0;
16315 + *pErp = 0;
16316 + *pDtimCount = 0;
16317 + *pDtimPeriod = 0;
16318 + *pBcastFlag = 0;
16319 + *pMessageToMe = 0;
16320 + *pExtRateLen = 0;
16321 + *pCkipFlag = 0; // Default of CkipFlag is 0
16322 + *pAironetCellPowerLimit = 0xFF; // Default of AironetCellPowerLimit is 0xFF
16323 + *LengthVIE = 0; // Set the length of VIE to init value 0
16324 + *pHtCapabilityLen = 0; // Set the length of VIE to init value 0
16325 +#ifdef CONFIG_STA_SUPPORT
16326 + if (pAd->OpMode == OPMODE_STA)
16327 + *pPreNHtCapabilityLen = 0; // Set the length of VIE to init value 0
16328 +#endif // CONFIG_STA_SUPPORT //
16329 + *AddHtInfoLen = 0; // Set the length of VIE to init value 0
16330 + *pRalinkIe = 0;
16331 + *pNewChannel = 0;
16332 + *NewExtChannelOffset = 0xff; //Default 0xff means no such IE
16333 + pCfParm->bValid = FALSE; // default: no IE_CF found
16334 + pQbssLoad->bValid = FALSE; // default: no IE_QBSS_LOAD found
16335 + pEdcaParm->bValid = FALSE; // default: no IE_EDCA_PARAMETER found
16336 + pQosCapability->bValid = FALSE; // default: no IE_QOS_CAPABILITY found
16337 +
16338 + pFrame = (PFRAME_802_11)Msg;
16339 +
16340 + // get subtype from header
16341 + SubType = (UCHAR)pFrame->Hdr.FC.SubType;
16342 +
16343 + // get Addr2 and BSSID from header
16344 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16345 + COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3);
16346 +
16347 +// hex_dump("Beacon", Msg, MsgLen);
16348 +
16349 + Ptr = pFrame->Octet;
16350 + Length += LENGTH_802_11;
16351 +
16352 + // get timestamp from payload and advance the pointer
16353 + NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN);
16354 +
16355 + pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart);
16356 + pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart);
16357 +
16358 + Ptr += TIMESTAMP_LEN;
16359 + Length += TIMESTAMP_LEN;
16360 +
16361 + // get beacon interval from payload and advance the pointer
16362 + NdisMoveMemory(pBeaconPeriod, Ptr, 2);
16363 + Ptr += 2;
16364 + Length += 2;
16365 +
16366 + // get capability info from payload and advance the pointer
16367 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
16368 + Ptr += 2;
16369 + Length += 2;
16370 +
16371 + if (CAP_IS_ESS_ON(*pCapabilityInfo))
16372 + *pBssType = BSS_INFRA;
16373 + else
16374 + *pBssType = BSS_ADHOC;
16375 +
16376 + pEid = (PEID_STRUCT) Ptr;
16377 +
16378 + // get variable fields from payload and advance the pointer
16379 + while ((Length + 2 + pEid->Len) <= MsgLen)
16380 + {
16381 + //
16382 + // Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow.
16383 + //
16384 + if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN)
16385 + {
16386 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n",
16387 + (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN));
16388 + break;
16389 + }
16390 +
16391 + switch(pEid->Eid)
16392 + {
16393 + case IE_SSID:
16394 + // Already has one SSID EID in this beacon, ignore the second one
16395 + if (Sanity & 0x1)
16396 + break;
16397 + if(pEid->Len <= MAX_LEN_OF_SSID)
16398 + {
16399 + NdisMoveMemory(Ssid, pEid->Octet, pEid->Len);
16400 + *pSsidLen = pEid->Len;
16401 + Sanity |= 0x1;
16402 + }
16403 + else
16404 + {
16405 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len));
16406 + return FALSE;
16407 + }
16408 + break;
16409 +
16410 + case IE_SUPP_RATES:
16411 + if(pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
16412 + {
16413 + Sanity |= 0x2;
16414 + NdisMoveMemory(SupRate, pEid->Octet, pEid->Len);
16415 + *pSupRateLen = pEid->Len;
16416 +
16417 + // TODO: 2004-09-14 not a good design here, cause it exclude extra rates
16418 + // from ScanTab. We should report as is. And filter out unsupported
16419 + // rates in MlmeAux.
16420 + // Check against the supported rates
16421 + // RTMPCheckRates(pAd, SupRate, pSupRateLen);
16422 + }
16423 + else
16424 + {
16425 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",pEid->Len));
16426 + return FALSE;
16427 + }
16428 + break;
16429 +
16430 + case IE_HT_CAP:
16431 + if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!
16432 + {
16433 + NdisMoveMemory(pHtCapability, pEid->Octet, sizeof(HT_CAPABILITY_IE));
16434 + *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes.
16435 +
16436 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
16437 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
16438 +
16439 +#ifdef CONFIG_STA_SUPPORT
16440 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16441 + {
16442 + *pPreNHtCapabilityLen = 0; // Nnow we only support 26 bytes.
16443 +
16444 + Ptr = (PUCHAR) pVIE;
16445 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16446 + *LengthVIE += (pEid->Len + 2);
16447 + }
16448 +#endif // CONFIG_STA_SUPPORT //
16449 + }
16450 + else
16451 + {
16452 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n", pEid->Len));
16453 + }
16454 +
16455 + break;
16456 + case IE_ADD_HT:
16457 + if (pEid->Len >= sizeof(ADD_HT_INFO_IE))
16458 + {
16459 + // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only
16460 + // copy first sizeof(ADD_HT_INFO_IE)
16461 + NdisMoveMemory(AddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));
16462 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
16463 +
16464 + CtrlChannel = AddHtInfo->ControlChan;
16465 +
16466 + *(USHORT *)(&AddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo2));
16467 + *(USHORT *)(&AddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo3));
16468 +
16469 +#ifdef CONFIG_STA_SUPPORT
16470 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16471 + {
16472 + Ptr = (PUCHAR) pVIE;
16473 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16474 + *LengthVIE += (pEid->Len + 2);
16475 + }
16476 +#endif // CONFIG_STA_SUPPORT //
16477 + }
16478 + else
16479 + {
16480 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n"));
16481 + }
16482 +
16483 + break;
16484 + case IE_SECONDARY_CH_OFFSET:
16485 + if (pEid->Len == 1)
16486 + {
16487 + *NewExtChannelOffset = pEid->Octet[0];
16488 + }
16489 + else
16490 + {
16491 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
16492 + }
16493 +
16494 + break;
16495 + case IE_FH_PARM:
16496 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n"));
16497 + break;
16498 +
16499 + case IE_DS_PARM:
16500 + if(pEid->Len == 1)
16501 + {
16502 + *pChannel = *pEid->Octet;
16503 +#ifdef CONFIG_STA_SUPPORT
16504 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16505 + {
16506 + if (ChannelSanity(pAd, *pChannel) == 0)
16507 + {
16508 +
16509 + return FALSE;
16510 + }
16511 + }
16512 +#endif // CONFIG_STA_SUPPORT //
16513 + Sanity |= 0x4;
16514 + }
16515 + else
16516 + {
16517 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n",pEid->Len));
16518 + return FALSE;
16519 + }
16520 + break;
16521 +
16522 + case IE_CF_PARM:
16523 + if(pEid->Len == 6)
16524 + {
16525 + pCfParm->bValid = TRUE;
16526 + pCfParm->CfpCount = pEid->Octet[0];
16527 + pCfParm->CfpPeriod = pEid->Octet[1];
16528 + pCfParm->CfpMaxDuration = pEid->Octet[2] + 256 * pEid->Octet[3];
16529 + pCfParm->CfpDurRemaining = pEid->Octet[4] + 256 * pEid->Octet[5];
16530 + }
16531 + else
16532 + {
16533 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n"));
16534 + return FALSE;
16535 + }
16536 + break;
16537 +
16538 + case IE_IBSS_PARM:
16539 + if(pEid->Len == 2)
16540 + {
16541 + NdisMoveMemory(pAtimWin, pEid->Octet, pEid->Len);
16542 + }
16543 + else
16544 + {
16545 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n"));
16546 + return FALSE;
16547 + }
16548 + break;
16549 +
16550 +#ifdef CONFIG_STA_SUPPORT
16551 + case IE_TIM:
16552 + if(INFRA_ON(pAd) && SubType == SUBTYPE_BEACON)
16553 + {
16554 + GetTimBit((PUCHAR)pEid, pAd->StaActive.Aid, &TimLen, pBcastFlag, pDtimCount, pDtimPeriod, pMessageToMe);
16555 + }
16556 + break;
16557 +#endif // CONFIG_STA_SUPPORT //
16558 + case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
16559 + if(pEid->Len == 3)
16560 + {
16561 + *pNewChannel = pEid->Octet[1]; //extract new channel number
16562 + }
16563 + break;
16564 +
16565 + // New for WPA
16566 + // CCX v2 has the same IE, we need to parse that too
16567 + // Wifi WMM use the same IE vale, need to parse that too
16568 + // case IE_WPA:
16569 + case IE_VENDOR_SPECIFIC:
16570 + // Check Broadcom/Atheros 802.11n OUI version, for HT Capability IE.
16571 + // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan.
16572 + /*if (NdisEqualMemory(pEid->Octet, BROADCOM_OUI, 3) && (pEid->Len >= 4))
16573 + {
16574 + if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 30))
16575 + {
16576 + {
16577 + NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE));
16578 + *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes.
16579 + }
16580 + }
16581 + if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 26))
16582 + {
16583 + {
16584 + NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE));
16585 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; // Nnow we only support 26 bytes.
16586 + }
16587 + }
16588 + }
16589 + */
16590 + // Check the OUI version, filter out non-standard usage
16591 + if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3) && (pEid->Len == 7))
16592 + {
16593 + //*pRalinkIe = pEid->Octet[3];
16594 + if (pEid->Octet[3] != 0)
16595 + *pRalinkIe = pEid->Octet[3];
16596 + else
16597 + *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.
16598 + }
16599 +#ifdef CONFIG_STA_SUPPORT
16600 +#ifdef DOT11_N_SUPPORT
16601 + // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan.
16602 +
16603 + // Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP,
16604 + // Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE
16605 + else if ((*pHtCapabilityLen == 0) && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI, 3) && (pEid->Len >= 4) && (pAd->OpMode == OPMODE_STA))
16606 + {
16607 + if ((pEid->Octet[3] == OUI_PREN_HT_CAP) && (pEid->Len >= 30) && (*pHtCapabilityLen == 0))
16608 + {
16609 + NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE));
16610 + *pPreNHtCapabilityLen = SIZE_HT_CAP_IE;
16611 + }
16612 +
16613 + if ((pEid->Octet[3] == OUI_PREN_ADD_HT) && (pEid->Len >= 26))
16614 + {
16615 + NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE));
16616 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
16617 + }
16618 + }
16619 +#endif // DOT11_N_SUPPORT //
16620 +#endif // CONFIG_STA_SUPPORT //
16621 + else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
16622 + {
16623 + // Copy to pVIE which will report to microsoft bssid list.
16624 + Ptr = (PUCHAR) pVIE;
16625 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16626 + *LengthVIE += (pEid->Len + 2);
16627 + }
16628 + else if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))
16629 + {
16630 + PUCHAR ptr;
16631 + int i;
16632 +
16633 + // parsing EDCA parameters
16634 + pEdcaParm->bValid = TRUE;
16635 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
16636 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
16637 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
16638 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
16639 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
16640 + ptr = &pEid->Octet[8];
16641 + for (i=0; i<4; i++)
16642 + {
16643 + UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX
16644 + pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM
16645 + pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN
16646 + pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin
16647 + pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax
16648 + pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us
16649 + ptr += 4; // point to next AC
16650 + }
16651 + }
16652 + else if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6) && (pEid->Len == 7))
16653 + {
16654 + // parsing EDCA parameters
16655 + pEdcaParm->bValid = TRUE;
16656 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
16657 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
16658 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
16659 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
16660 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
16661 +
16662 + // use default EDCA parameter
16663 + pEdcaParm->bACM[QID_AC_BE] = 0;
16664 + pEdcaParm->Aifsn[QID_AC_BE] = 3;
16665 + pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS;
16666 + pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS;
16667 + pEdcaParm->Txop[QID_AC_BE] = 0;
16668 +
16669 + pEdcaParm->bACM[QID_AC_BK] = 0;
16670 + pEdcaParm->Aifsn[QID_AC_BK] = 7;
16671 + pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS;
16672 + pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS;
16673 + pEdcaParm->Txop[QID_AC_BK] = 0;
16674 +
16675 + pEdcaParm->bACM[QID_AC_VI] = 0;
16676 + pEdcaParm->Aifsn[QID_AC_VI] = 2;
16677 + pEdcaParm->Cwmin[QID_AC_VI] = CW_MIN_IN_BITS-1;
16678 + pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS;
16679 + pEdcaParm->Txop[QID_AC_VI] = 96; // AC_VI: 96*32us ~= 3ms
16680 +
16681 + pEdcaParm->bACM[QID_AC_VO] = 0;
16682 + pEdcaParm->Aifsn[QID_AC_VO] = 2;
16683 + pEdcaParm->Cwmin[QID_AC_VO] = CW_MIN_IN_BITS-2;
16684 + pEdcaParm->Cwmax[QID_AC_VO] = CW_MAX_IN_BITS-1;
16685 + pEdcaParm->Txop[QID_AC_VO] = 48; // AC_VO: 48*32us ~= 1.5ms
16686 + }
16687 + break;
16688 +
16689 + case IE_EXT_SUPP_RATES:
16690 + if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
16691 + {
16692 + NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
16693 + *pExtRateLen = pEid->Len;
16694 +
16695 + // TODO: 2004-09-14 not a good design here, cause it exclude extra rates
16696 + // from ScanTab. We should report as is. And filter out unsupported
16697 + // rates in MlmeAux.
16698 + // Check against the supported rates
16699 + // RTMPCheckRates(pAd, ExtRate, pExtRateLen);
16700 + }
16701 + break;
16702 +
16703 + case IE_ERP:
16704 + if (pEid->Len == 1)
16705 + {
16706 + *pErp = (UCHAR)pEid->Octet[0];
16707 + }
16708 + break;
16709 +
16710 + case IE_AIRONET_CKIP:
16711 + // 0. Check Aironet IE length, it must be larger or equal to 28
16712 + // Cisco AP350 used length as 28
16713 + // Cisco AP12XX used length as 30
16714 + if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
16715 + break;
16716 +
16717 + // 1. Copy CKIP flag byte to buffer for process
16718 + *pCkipFlag = *(pEid->Octet + 8);
16719 + break;
16720 +
16721 + case IE_AP_TX_POWER:
16722 + // AP Control of Client Transmit Power
16723 + //0. Check Aironet IE length, it must be 6
16724 + if (pEid->Len != 0x06)
16725 + break;
16726 +
16727 + // Get cell power limit in dBm
16728 + if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
16729 + *pAironetCellPowerLimit = *(pEid->Octet + 4);
16730 + break;
16731 +
16732 + // WPA2 & 802.11i RSN
16733 + case IE_RSN:
16734 + // There is no OUI for version anymore, check the group cipher OUI before copying
16735 + if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
16736 + {
16737 + // Copy to pVIE which will report to microsoft bssid list.
16738 + Ptr = (PUCHAR) pVIE;
16739 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16740 + *LengthVIE += (pEid->Len + 2);
16741 + }
16742 + break;
16743 +#ifdef CONFIG_STA_SUPPORT
16744 +#ifdef EXT_BUILD_CHANNEL_LIST
16745 + case IE_COUNTRY:
16746 + Ptr = (PUCHAR) pVIE;
16747 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16748 + *LengthVIE += (pEid->Len + 2);
16749 + break;
16750 +#endif // EXT_BUILD_CHANNEL_LIST //
16751 +#endif // CONFIG_STA_SUPPORT //
16752 + default:
16753 + break;
16754 + }
16755 +
16756 + Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len]
16757 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
16758 + }
16759 +
16760 + // For some 11a AP. it did not have the channel EID, patch here
16761 +#ifdef CONFIG_STA_SUPPORT
16762 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16763 + {
16764 + UCHAR LatchRfChannel = MsgChannel;
16765 + if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0))
16766 + {
16767 + if (CtrlChannel != 0)
16768 + *pChannel = CtrlChannel;
16769 + else
16770 + *pChannel = LatchRfChannel;
16771 + Sanity |= 0x4;
16772 + }
16773 + }
16774 +#endif // CONFIG_STA_SUPPORT //
16775 +
16776 + if (Sanity != 0x7)
16777 + {
16778 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n", Sanity));
16779 + return FALSE;
16780 + }
16781 + else
16782 + {
16783 + return TRUE;
16784 + }
16785 +
16786 +}
16787 +
16788 +#ifdef DOT11N_DRAFT3
16789 +/*
16790 + ==========================================================================
16791 + Description:
16792 + MLME message sanity check for some IE addressed in 802.11n d3.03.
16793 + Return:
16794 + TRUE if all parameters are OK, FALSE otherwise
16795 +
16796 + IRQL = DISPATCH_LEVEL
16797 +
16798 + ==========================================================================
16799 + */
16800 +BOOLEAN PeerBeaconAndProbeRspSanity2(
16801 + IN PRTMP_ADAPTER pAd,
16802 + IN VOID *Msg,
16803 + IN ULONG MsgLen,
16804 + OUT UCHAR *RegClass)
16805 +{
16806 + CHAR *Ptr;
16807 + PFRAME_802_11 pFrame;
16808 + PEID_STRUCT pEid;
16809 + ULONG Length = 0;
16810 +
16811 + pFrame = (PFRAME_802_11)Msg;
16812 +
16813 + *RegClass = 0;
16814 + Ptr = pFrame->Octet;
16815 + Length += LENGTH_802_11;
16816 +
16817 + // get timestamp from payload and advance the pointer
16818 + Ptr += TIMESTAMP_LEN;
16819 + Length += TIMESTAMP_LEN;
16820 +
16821 + // get beacon interval from payload and advance the pointer
16822 + Ptr += 2;
16823 + Length += 2;
16824 +
16825 + // get capability info from payload and advance the pointer
16826 + Ptr += 2;
16827 + Length += 2;
16828 +
16829 + pEid = (PEID_STRUCT) Ptr;
16830 +
16831 + // get variable fields from payload and advance the pointer
16832 + while ((Length + 2 + pEid->Len) <= MsgLen)
16833 + {
16834 + switch(pEid->Eid)
16835 + {
16836 + case IE_SUPP_REG_CLASS:
16837 + if(pEid->Len > 0)
16838 + {
16839 + *RegClass = *pEid->Octet;
16840 + }
16841 + else
16842 + {
16843 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len));
16844 + return FALSE;
16845 + }
16846 + break;
16847 + }
16848 +
16849 + Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len]
16850 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
16851 + }
16852 +
16853 + return TRUE;
16854 +
16855 +}
16856 +#endif // DOT11N_DRAFT3 //
16857 +
16858 +/*
16859 + ==========================================================================
16860 + Description:
16861 + MLME message sanity check
16862 + Return:
16863 + TRUE if all parameters are OK, FALSE otherwise
16864 + ==========================================================================
16865 + */
16866 +BOOLEAN MlmeScanReqSanity(
16867 + IN PRTMP_ADAPTER pAd,
16868 + IN VOID *Msg,
16869 + IN ULONG MsgLen,
16870 + OUT UCHAR *pBssType,
16871 + OUT CHAR Ssid[],
16872 + OUT UCHAR *pSsidLen,
16873 + OUT UCHAR *pScanType)
16874 +{
16875 + MLME_SCAN_REQ_STRUCT *Info;
16876 +
16877 + Info = (MLME_SCAN_REQ_STRUCT *)(Msg);
16878 + *pBssType = Info->BssType;
16879 + *pSsidLen = Info->SsidLen;
16880 + NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
16881 + *pScanType = Info->ScanType;
16882 +
16883 + if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC || *pBssType == BSS_ANY)
16884 + && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE
16885 +#ifdef CONFIG_STA_SUPPORT
16886 + || *pScanType == SCAN_CISCO_PASSIVE || *pScanType == SCAN_CISCO_ACTIVE
16887 + || *pScanType == SCAN_CISCO_CHANNEL_LOAD || *pScanType == SCAN_CISCO_NOISE
16888 +#endif // CONFIG_STA_SUPPORT //
16889 + ))
16890 + {
16891 + return TRUE;
16892 + }
16893 + else
16894 + {
16895 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqSanity fail - wrong BssType or ScanType\n"));
16896 + return FALSE;
16897 + }
16898 +}
16899 +
16900 +// IRQL = DISPATCH_LEVEL
16901 +UCHAR ChannelSanity(
16902 + IN PRTMP_ADAPTER pAd,
16903 + IN UCHAR channel)
16904 +{
16905 + int i;
16906 +
16907 + for (i = 0; i < pAd->ChannelListNum; i ++)
16908 + {
16909 + if (channel == pAd->ChannelList[i].Channel)
16910 + return 1;
16911 + }
16912 + return 0;
16913 +}
16914 +
16915 +/*
16916 + ==========================================================================
16917 + Description:
16918 + MLME message sanity check
16919 + Return:
16920 + TRUE if all parameters are OK, FALSE otherwise
16921 +
16922 + IRQL = DISPATCH_LEVEL
16923 +
16924 + ==========================================================================
16925 + */
16926 +BOOLEAN PeerDeauthSanity(
16927 + IN PRTMP_ADAPTER pAd,
16928 + IN VOID *Msg,
16929 + IN ULONG MsgLen,
16930 + OUT PUCHAR pAddr2,
16931 + OUT USHORT *pReason)
16932 +{
16933 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
16934 +
16935 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16936 + NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
16937 +
16938 + return TRUE;
16939 +}
16940 +
16941 +/*
16942 + ==========================================================================
16943 + Description:
16944 + MLME message sanity check
16945 + Return:
16946 + TRUE if all parameters are OK, FALSE otherwise
16947 +
16948 + IRQL = DISPATCH_LEVEL
16949 +
16950 + ==========================================================================
16951 + */
16952 +BOOLEAN PeerAuthSanity(
16953 + IN PRTMP_ADAPTER pAd,
16954 + IN VOID *Msg,
16955 + IN ULONG MsgLen,
16956 + OUT PUCHAR pAddr,
16957 + OUT USHORT *pAlg,
16958 + OUT USHORT *pSeq,
16959 + OUT USHORT *pStatus,
16960 + CHAR *pChlgText)
16961 +{
16962 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
16963 +
16964 + COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2);
16965 + NdisMoveMemory(pAlg, &pFrame->Octet[0], 2);
16966 + NdisMoveMemory(pSeq, &pFrame->Octet[2], 2);
16967 + NdisMoveMemory(pStatus, &pFrame->Octet[4], 2);
16968 +
16969 + if ((*pAlg == Ndis802_11AuthModeOpen)
16970 +#ifdef LEAP_SUPPORT
16971 + || (*pAlg == CISCO_AuthModeLEAP)
16972 +#endif // LEAP_SUPPORT //
16973 + )
16974 + {
16975 + if (*pSeq == 1 || *pSeq == 2)
16976 + {
16977 + return TRUE;
16978 + }
16979 + else
16980 + {
16981 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n"));
16982 + return FALSE;
16983 + }
16984 + }
16985 + else if (*pAlg == Ndis802_11AuthModeShared)
16986 + {
16987 + if (*pSeq == 1 || *pSeq == 4)
16988 + {
16989 + return TRUE;
16990 + }
16991 + else if (*pSeq == 2 || *pSeq == 3)
16992 + {
16993 + NdisMoveMemory(pChlgText, &pFrame->Octet[8], CIPHER_TEXT_LEN);
16994 + return TRUE;
16995 + }
16996 + else
16997 + {
16998 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n"));
16999 + return FALSE;
17000 + }
17001 + }
17002 + else
17003 + {
17004 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong algorithm\n"));
17005 + return FALSE;
17006 + }
17007 +}
17008 +
17009 +/*
17010 + ==========================================================================
17011 + Description:
17012 + MLME message sanity check
17013 + Return:
17014 + TRUE if all parameters are OK, FALSE otherwise
17015 + ==========================================================================
17016 + */
17017 +BOOLEAN MlmeAuthReqSanity(
17018 + IN PRTMP_ADAPTER pAd,
17019 + IN VOID *Msg,
17020 + IN ULONG MsgLen,
17021 + OUT PUCHAR pAddr,
17022 + OUT ULONG *pTimeout,
17023 + OUT USHORT *pAlg)
17024 +{
17025 + MLME_AUTH_REQ_STRUCT *pInfo;
17026 +
17027 + pInfo = (MLME_AUTH_REQ_STRUCT *)Msg;
17028 + COPY_MAC_ADDR(pAddr, pInfo->Addr);
17029 + *pTimeout = pInfo->Timeout;
17030 + *pAlg = pInfo->Alg;
17031 +
17032 + if (((*pAlg == Ndis802_11AuthModeShared) ||(*pAlg == Ndis802_11AuthModeOpen)
17033 +#ifdef LEAP_SUPPORT
17034 + || (*pAlg == CISCO_AuthModeLEAP)
17035 +#endif // LEAP_SUPPORT //
17036 + ) &&
17037 + ((*pAddr & 0x01) == 0))
17038 + {
17039 + return TRUE;
17040 + }
17041 + else
17042 + {
17043 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAuthReqSanity fail - wrong algorithm\n"));
17044 + return FALSE;
17045 + }
17046 +}
17047 +
17048 +/*
17049 + ==========================================================================
17050 + Description:
17051 + MLME message sanity check
17052 + Return:
17053 + TRUE if all parameters are OK, FALSE otherwise
17054 +
17055 + IRQL = DISPATCH_LEVEL
17056 +
17057 + ==========================================================================
17058 + */
17059 +BOOLEAN MlmeAssocReqSanity(
17060 + IN PRTMP_ADAPTER pAd,
17061 + IN VOID *Msg,
17062 + IN ULONG MsgLen,
17063 + OUT PUCHAR pApAddr,
17064 + OUT USHORT *pCapabilityInfo,
17065 + OUT ULONG *pTimeout,
17066 + OUT USHORT *pListenIntv)
17067 +{
17068 + MLME_ASSOC_REQ_STRUCT *pInfo;
17069 +
17070 + pInfo = (MLME_ASSOC_REQ_STRUCT *)Msg;
17071 + *pTimeout = pInfo->Timeout; // timeout
17072 + COPY_MAC_ADDR(pApAddr, pInfo->Addr); // AP address
17073 + *pCapabilityInfo = pInfo->CapabilityInfo; // capability info
17074 + *pListenIntv = pInfo->ListenIntv;
17075 +
17076 + return TRUE;
17077 +}
17078 +
17079 +/*
17080 + ==========================================================================
17081 + Description:
17082 + MLME message sanity check
17083 + Return:
17084 + TRUE if all parameters are OK, FALSE otherwise
17085 +
17086 + IRQL = DISPATCH_LEVEL
17087 +
17088 + ==========================================================================
17089 + */
17090 +BOOLEAN PeerDisassocSanity(
17091 + IN PRTMP_ADAPTER pAd,
17092 + IN VOID *Msg,
17093 + IN ULONG MsgLen,
17094 + OUT PUCHAR pAddr2,
17095 + OUT USHORT *pReason)
17096 +{
17097 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
17098 +
17099 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
17100 + NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
17101 +
17102 + return TRUE;
17103 +}
17104 +
17105 +/*
17106 + ========================================================================
17107 + Routine Description:
17108 + Sanity check NetworkType (11b, 11g or 11a)
17109 +
17110 + Arguments:
17111 + pBss - Pointer to BSS table.
17112 +
17113 + Return Value:
17114 + Ndis802_11DS .......(11b)
17115 + Ndis802_11OFDM24....(11g)
17116 + Ndis802_11OFDM5.....(11a)
17117 +
17118 + IRQL = DISPATCH_LEVEL
17119 +
17120 + ========================================================================
17121 +*/
17122 +NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(
17123 + IN PBSS_ENTRY pBss)
17124 +{
17125 + NDIS_802_11_NETWORK_TYPE NetWorkType;
17126 + UCHAR rate, i;
17127 +
17128 + NetWorkType = Ndis802_11DS;
17129 +
17130 + if (pBss->Channel <= 14)
17131 + {
17132 + //
17133 + // First check support Rate.
17134 + //
17135 + for (i = 0; i < pBss->SupRateLen; i++)
17136 + {
17137 + rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit
17138 + if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22))
17139 + {
17140 + continue;
17141 + }
17142 + else
17143 + {
17144 + //
17145 + // Otherwise (even rate > 108) means Ndis802_11OFDM24
17146 + //
17147 + NetWorkType = Ndis802_11OFDM24;
17148 + break;
17149 + }
17150 + }
17151 +
17152 + //
17153 + // Second check Extend Rate.
17154 + //
17155 + if (NetWorkType != Ndis802_11OFDM24)
17156 + {
17157 + for (i = 0; i < pBss->ExtRateLen; i++)
17158 + {
17159 + rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit
17160 + if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22))
17161 + {
17162 + continue;
17163 + }
17164 + else
17165 + {
17166 + //
17167 + // Otherwise (even rate > 108) means Ndis802_11OFDM24
17168 + //
17169 + NetWorkType = Ndis802_11OFDM24;
17170 + break;
17171 + }
17172 + }
17173 + }
17174 + }
17175 + else
17176 + {
17177 + NetWorkType = Ndis802_11OFDM5;
17178 + }
17179 +
17180 + if (pBss->HtCapabilityLen != 0)
17181 + {
17182 + if (NetWorkType == Ndis802_11OFDM5)
17183 + NetWorkType = Ndis802_11OFDM5_N;
17184 + else
17185 + NetWorkType = Ndis802_11OFDM24_N;
17186 + }
17187 +
17188 + return NetWorkType;
17189 +}
17190 +
17191 +/*
17192 + ==========================================================================
17193 + Description:
17194 + WPA message sanity check
17195 + Return:
17196 + TRUE if all parameters are OK, FALSE otherwise
17197 + ==========================================================================
17198 + */
17199 +BOOLEAN PeerWpaMessageSanity(
17200 + IN PRTMP_ADAPTER pAd,
17201 + IN PEAPOL_PACKET pMsg,
17202 + IN ULONG MsgLen,
17203 + IN UCHAR MsgType,
17204 + IN MAC_TABLE_ENTRY *pEntry)
17205 +{
17206 + UCHAR mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE];
17207 + BOOLEAN bReplayDiff = FALSE;
17208 + BOOLEAN bWPA2 = FALSE;
17209 + KEY_INFO EapolKeyInfo;
17210 + UCHAR GroupKeyIndex = 0;
17211 +
17212 +
17213 + NdisZeroMemory(mic, sizeof(mic));
17214 + NdisZeroMemory(digest, sizeof(digest));
17215 + NdisZeroMemory(KEYDATA, sizeof(KEYDATA));
17216 + NdisZeroMemory((PUCHAR)&EapolKeyInfo, sizeof(EapolKeyInfo));
17217 +
17218 + NdisMoveMemory((PUCHAR)&EapolKeyInfo, (PUCHAR)&pMsg->KeyDesc.KeyInfo, sizeof(KEY_INFO));
17219 +
17220 + *((USHORT *)&EapolKeyInfo) = cpu2le16(*((USHORT *)&EapolKeyInfo));
17221 +
17222 + // Choose WPA2 or not
17223 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK))
17224 + bWPA2 = TRUE;
17225 +
17226 + // 0. Check MsgType
17227 + if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1))
17228 + {
17229 + DBGPRINT(RT_DEBUG_ERROR, ("The message type is invalid(%d)! \n", MsgType));
17230 + return FALSE;
17231 + }
17232 +
17233 + // 1. Replay counter check
17234 + if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) // For supplicant
17235 + {
17236 + // First validate replay counter, only accept message with larger replay counter.
17237 + // Let equal pass, some AP start with all zero replay counter
17238 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
17239 +
17240 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
17241 + if ((RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY) != 1) &&
17242 + (RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
17243 + {
17244 + bReplayDiff = TRUE;
17245 + }
17246 + }
17247 + else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) // For authenticator
17248 + {
17249 + // check Replay Counter coresponds to MSG from authenticator, otherwise discard
17250 + if (!NdisEqualMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY))
17251 + {
17252 + bReplayDiff = TRUE;
17253 + }
17254 + }
17255 +
17256 + // Replay Counter different condition
17257 + if (bReplayDiff)
17258 + {
17259 + // send wireless event - for replay counter different
17260 + if (pAd->CommonCfg.bWirelessEvent)
17261 + RTMPSendWirelessEvent(pAd, IW_REPLAY_COUNTER_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
17262 +
17263 + if (MsgType < EAPOL_GROUP_MSG_1)
17264 + {
17265 + DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n", MsgType));
17266 + }
17267 + else
17268 + {
17269 + DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4)));
17270 + }
17271 +
17272 + hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
17273 + hex_dump("Current replay counter ", pEntry->R_Counter, LEN_KEY_DESC_REPLAY);
17274 + return FALSE;
17275 + }
17276 +
17277 + // 2. Verify MIC except Pairwise Msg1
17278 + if (MsgType != EAPOL_PAIR_MSG_1)
17279 + {
17280 + UCHAR rcvd_mic[LEN_KEY_DESC_MIC];
17281 +
17282 + // Record the received MIC for check later
17283 + NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
17284 + NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
17285 +
17286 + if (pEntry->WepStatus == Ndis802_11Encryption2Enabled) // TKIP
17287 + {
17288 + hmac_md5(pEntry->PTK, LEN_EAP_MICK, (PUCHAR)pMsg, MsgLen, mic);
17289 + }
17290 + else if (pEntry->WepStatus == Ndis802_11Encryption3Enabled) // AES
17291 + {
17292 + HMAC_SHA1((PUCHAR)pMsg, MsgLen, pEntry->PTK, LEN_EAP_MICK, digest);
17293 + NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
17294 + }
17295 +
17296 + if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC))
17297 + {
17298 + // send wireless event - for MIC different
17299 + if (pAd->CommonCfg.bWirelessEvent)
17300 + RTMPSendWirelessEvent(pAd, IW_MIC_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
17301 +
17302 + if (MsgType < EAPOL_GROUP_MSG_1)
17303 + {
17304 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in pairwise msg %d of 4-way handshake!\n", MsgType));
17305 + }
17306 + else
17307 + {
17308 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4)));
17309 + }
17310 +
17311 + hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC);
17312 + hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC);
17313 +
17314 + return FALSE;
17315 + }
17316 + }
17317 +
17318 + // Extract the context of the Key Data field if it exist
17319 + // The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is un-encrypted.
17320 + // The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted.
17321 + if (pMsg->KeyDesc.KeyDataLen[1] > 0)
17322 + {
17323 + // Decrypt this field
17324 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
17325 + {
17326 + if(pEntry->WepStatus == Ndis802_11Encryption3Enabled)
17327 + {
17328 + // AES
17329 + AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA, pMsg->KeyDesc.KeyDataLen[1],pMsg->KeyDesc.KeyData);
17330 + }
17331 + else
17332 + {
17333 + INT i;
17334 + UCHAR Key[32];
17335 + // Decrypt TKIP GTK
17336 + // Construct 32 bytes RC4 Key
17337 + NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16);
17338 + NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16);
17339 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
17340 + //discard first 256 bytes
17341 + for(i = 0; i < 256; i++)
17342 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
17343 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
17344 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]);
17345 + }
17346 +
17347 + if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
17348 + GroupKeyIndex = EapolKeyInfo.KeyIndex;
17349 +
17350 + }
17351 + else if ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2))
17352 + {
17353 + NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]);
17354 + }
17355 + else
17356 + {
17357 +
17358 + return TRUE;
17359 + }
17360 +
17361 + // Parse Key Data field to
17362 + // 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2)
17363 + // 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2
17364 + // 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2)
17365 + if (!RTMPParseEapolKeyData(pAd, KEYDATA, pMsg->KeyDesc.KeyDataLen[1], GroupKeyIndex, MsgType, bWPA2, pEntry))
17366 + {
17367 + return FALSE;
17368 + }
17369 + }
17370 +
17371 + return TRUE;
17372 +
17373 +}
17374 +
17375 +#ifdef CONFIG_STA_SUPPORT
17376 +#ifdef QOS_DLS_SUPPORT
17377 +BOOLEAN MlmeDlsReqSanity(
17378 + IN PRTMP_ADAPTER pAd,
17379 + IN VOID *Msg,
17380 + IN ULONG MsgLen,
17381 + OUT PRT_802_11_DLS *pDLS,
17382 + OUT PUSHORT pReason)
17383 +{
17384 + MLME_DLS_REQ_STRUCT *pInfo;
17385 +
17386 + pInfo = (MLME_DLS_REQ_STRUCT *)Msg;
17387 +
17388 + *pDLS = pInfo->pDLS;
17389 + *pReason = pInfo->Reason;
17390 +
17391 + return TRUE;
17392 +}
17393 +#endif // QOS_DLS_SUPPORT //
17394 +#endif // CONFIG_STA_SUPPORT //
17395 +
17396 +#ifdef QOS_DLS_SUPPORT
17397 +BOOLEAN PeerDlsReqSanity(
17398 + IN PRTMP_ADAPTER pAd,
17399 + IN VOID *Msg,
17400 + IN ULONG MsgLen,
17401 + OUT PUCHAR pDA,
17402 + OUT PUCHAR pSA,
17403 + OUT USHORT *pCapabilityInfo,
17404 + OUT USHORT *pDlsTimeout,
17405 + OUT UCHAR *pRatesLen,
17406 + OUT UCHAR Rates[],
17407 + OUT UCHAR *pHtCapabilityLen,
17408 + OUT HT_CAPABILITY_IE *pHtCapability)
17409 +{
17410 + CHAR *Ptr;
17411 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17412 + PEID_STRUCT eid_ptr;
17413 +
17414 + // to prevent caller from using garbage output value
17415 + *pCapabilityInfo = 0;
17416 + *pDlsTimeout = 0;
17417 + *pHtCapabilityLen = 0;
17418 +
17419 + Ptr = Fr->Octet;
17420 +
17421 + // offset to destination MAC address (Category and Action field)
17422 + Ptr += 2;
17423 +
17424 + // get DA from payload and advance the pointer
17425 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17426 + Ptr += MAC_ADDR_LEN;
17427 +
17428 + // get SA from payload and advance the pointer
17429 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17430 + Ptr += MAC_ADDR_LEN;
17431 +
17432 + // get capability info from payload and advance the pointer
17433 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
17434 + Ptr += 2;
17435 +
17436 + // get capability info from payload and advance the pointer
17437 + NdisMoveMemory(pDlsTimeout, Ptr, 2);
17438 + Ptr += 2;
17439 +
17440 + // Category and Action field + DA + SA + capability + Timeout
17441 + eid_ptr = (PEID_STRUCT) &Fr->Octet[18];
17442 +
17443 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((UCHAR*)Fr + MsgLen))
17444 + {
17445 + switch(eid_ptr->Eid)
17446 + {
17447 + case IE_SUPP_RATES:
17448 + if ((eid_ptr->Len <= MAX_LEN_OF_SUPPORTED_RATES) && (eid_ptr->Len > 0))
17449 + {
17450 + NdisMoveMemory(Rates, eid_ptr->Octet, eid_ptr->Len);
17451 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - IE_SUPP_RATES., Len=%d. Rates[0]=%x\n",eid_ptr->Len, Rates[0]));
17452 + 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]));
17453 + *pRatesLen = eid_ptr->Len;
17454 + }
17455 + else
17456 + {
17457 + *pRatesLen = 8;
17458 + Rates[0] = 0x82;
17459 + Rates[1] = 0x84;
17460 + Rates[2] = 0x8b;
17461 + Rates[3] = 0x96;
17462 + Rates[4] = 0x12;
17463 + Rates[5] = 0x24;
17464 + Rates[6] = 0x48;
17465 + Rates[7] = 0x6c;
17466 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - wrong IE_SUPP_RATES., Len=%d\n",eid_ptr->Len));
17467 + }
17468 + break;
17469 +
17470 + case IE_EXT_SUPP_RATES:
17471 + if (eid_ptr->Len + *pRatesLen <= MAX_LEN_OF_SUPPORTED_RATES)
17472 + {
17473 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, eid_ptr->Len);
17474 + *pRatesLen = (*pRatesLen) + eid_ptr->Len;
17475 + }
17476 + else
17477 + {
17478 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, MAX_LEN_OF_SUPPORTED_RATES - (*pRatesLen));
17479 + *pRatesLen = MAX_LEN_OF_SUPPORTED_RATES;
17480 + }
17481 + break;
17482 +
17483 + case IE_HT_CAP:
17484 + if (eid_ptr->Len >= sizeof(HT_CAPABILITY_IE))
17485 + {
17486 + NdisMoveMemory(pHtCapability, eid_ptr->Octet, sizeof(HT_CAPABILITY_IE));
17487 +
17488 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
17489 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
17490 + *pHtCapabilityLen = sizeof(HT_CAPABILITY_IE);
17491 +
17492 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - IE_HT_CAP\n"));
17493 + }
17494 + else
17495 + {
17496 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - wrong IE_HT_CAP.eid_ptr->Len = %d\n", eid_ptr->Len));
17497 + }
17498 + break;
17499 +
17500 + default:
17501 + break;
17502 + }
17503 +
17504 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
17505 + }
17506 +
17507 + return TRUE;
17508 +}
17509 +
17510 +BOOLEAN PeerDlsRspSanity(
17511 + IN PRTMP_ADAPTER pAd,
17512 + IN VOID *Msg,
17513 + IN ULONG MsgLen,
17514 + OUT PUCHAR pDA,
17515 + OUT PUCHAR pSA,
17516 + OUT USHORT *pCapabilityInfo,
17517 + OUT USHORT *pStatus,
17518 + OUT UCHAR *pRatesLen,
17519 + OUT UCHAR Rates[],
17520 + OUT UCHAR *pHtCapabilityLen,
17521 + OUT HT_CAPABILITY_IE *pHtCapability)
17522 +{
17523 + CHAR *Ptr;
17524 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17525 + PEID_STRUCT eid_ptr;
17526 +
17527 + // to prevent caller from using garbage output value
17528 + *pStatus = 0;
17529 + *pCapabilityInfo = 0;
17530 + *pHtCapabilityLen = 0;
17531 +
17532 + Ptr = Fr->Octet;
17533 +
17534 + // offset to destination MAC address (Category and Action field)
17535 + Ptr += 2;
17536 +
17537 + // get status code from payload and advance the pointer
17538 + NdisMoveMemory(pStatus, Ptr, 2);
17539 + Ptr += 2;
17540 +
17541 + // get DA from payload and advance the pointer
17542 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17543 + Ptr += MAC_ADDR_LEN;
17544 +
17545 + // get SA from payload and advance the pointer
17546 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17547 + Ptr += MAC_ADDR_LEN;
17548 +
17549 + if (pStatus == 0)
17550 + {
17551 + // get capability info from payload and advance the pointer
17552 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
17553 + Ptr += 2;
17554 + }
17555 +
17556 + // Category and Action field + status code + DA + SA + capability
17557 + eid_ptr = (PEID_STRUCT) &Fr->Octet[18];
17558 +
17559 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((UCHAR*)Fr + MsgLen))
17560 + {
17561 + switch(eid_ptr->Eid)
17562 + {
17563 + case IE_SUPP_RATES:
17564 + if ((eid_ptr->Len <= MAX_LEN_OF_SUPPORTED_RATES) && (eid_ptr->Len > 0))
17565 + {
17566 + NdisMoveMemory(Rates, eid_ptr->Octet, eid_ptr->Len);
17567 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - IE_SUPP_RATES., Len=%d. Rates[0]=%x\n",eid_ptr->Len, Rates[0]));
17568 + 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]));
17569 + *pRatesLen = eid_ptr->Len;
17570 + }
17571 + else
17572 + {
17573 + *pRatesLen = 8;
17574 + Rates[0] = 0x82;
17575 + Rates[1] = 0x84;
17576 + Rates[2] = 0x8b;
17577 + Rates[3] = 0x96;
17578 + Rates[4] = 0x12;
17579 + Rates[5] = 0x24;
17580 + Rates[6] = 0x48;
17581 + Rates[7] = 0x6c;
17582 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - wrong IE_SUPP_RATES., Len=%d\n",eid_ptr->Len));
17583 + }
17584 + break;
17585 +
17586 + case IE_EXT_SUPP_RATES:
17587 + if (eid_ptr->Len + *pRatesLen <= MAX_LEN_OF_SUPPORTED_RATES)
17588 + {
17589 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, eid_ptr->Len);
17590 + *pRatesLen = (*pRatesLen) + eid_ptr->Len;
17591 + }
17592 + else
17593 + {
17594 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, MAX_LEN_OF_SUPPORTED_RATES - (*pRatesLen));
17595 + *pRatesLen = MAX_LEN_OF_SUPPORTED_RATES;
17596 + }
17597 + break;
17598 +
17599 + case IE_HT_CAP:
17600 + if (eid_ptr->Len >= sizeof(HT_CAPABILITY_IE))
17601 + {
17602 + NdisMoveMemory(pHtCapability, eid_ptr->Octet, sizeof(HT_CAPABILITY_IE));
17603 +
17604 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
17605 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
17606 + *pHtCapabilityLen = sizeof(HT_CAPABILITY_IE);
17607 +
17608 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - IE_HT_CAP\n"));
17609 + }
17610 + else
17611 + {
17612 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - wrong IE_HT_CAP.eid_ptr->Len = %d\n", eid_ptr->Len));
17613 + }
17614 + break;
17615 +
17616 + default:
17617 + break;
17618 + }
17619 +
17620 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
17621 + }
17622 +
17623 + return TRUE;
17624 +}
17625 +
17626 +BOOLEAN PeerDlsTearDownSanity(
17627 + IN PRTMP_ADAPTER pAd,
17628 + IN VOID *Msg,
17629 + IN ULONG MsgLen,
17630 + OUT PUCHAR pDA,
17631 + OUT PUCHAR pSA,
17632 + OUT USHORT *pReason)
17633 +{
17634 + CHAR *Ptr;
17635 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17636 +
17637 + // to prevent caller from using garbage output value
17638 + *pReason = 0;
17639 +
17640 + Ptr = Fr->Octet;
17641 +
17642 + // offset to destination MAC address (Category and Action field)
17643 + Ptr += 2;
17644 +
17645 + // get DA from payload and advance the pointer
17646 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17647 + Ptr += MAC_ADDR_LEN;
17648 +
17649 + // get SA from payload and advance the pointer
17650 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17651 + Ptr += MAC_ADDR_LEN;
17652 +
17653 + // get reason code from payload and advance the pointer
17654 + NdisMoveMemory(pReason, Ptr, 2);
17655 + Ptr += 2;
17656 +
17657 + return TRUE;
17658 +}
17659 +#endif // QOS_DLS_SUPPORT //
17660 +
17661 --- /dev/null
17662 +++ b/drivers/staging/rt2870/common/cmm_sync.c
17663 @@ -0,0 +1,711 @@
17664 +/*
17665 + *************************************************************************
17666 + * Ralink Tech Inc.
17667 + * 5F., No.36, Taiyuan St., Jhubei City,
17668 + * Hsinchu County 302,
17669 + * Taiwan, R.O.C.
17670 + *
17671 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
17672 + *
17673 + * This program is free software; you can redistribute it and/or modify *
17674 + * it under the terms of the GNU General Public License as published by *
17675 + * the Free Software Foundation; either version 2 of the License, or *
17676 + * (at your option) any later version. *
17677 + * *
17678 + * This program is distributed in the hope that it will be useful, *
17679 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17680 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17681 + * GNU General Public License for more details. *
17682 + * *
17683 + * You should have received a copy of the GNU General Public License *
17684 + * along with this program; if not, write to the *
17685 + * Free Software Foundation, Inc., *
17686 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17687 + * *
17688 + *************************************************************************
17689 +
17690 + Module Name:
17691 + sync.c
17692 +
17693 + Abstract:
17694 +
17695 + Revision History:
17696 + Who When What
17697 + -------- ---------- ----------------------------------------------
17698 + John Chang 2004-09-01 modified for rt2561/2661
17699 +*/
17700 +#include "../rt_config.h"
17701 +
17702 +// 2.4 Ghz channel plan index in the TxPower arrays.
17703 +#define BG_BAND_REGION_0_START 0 // 1,2,3,4,5,6,7,8,9,10,11
17704 +#define BG_BAND_REGION_0_SIZE 11
17705 +#define BG_BAND_REGION_1_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13
17706 +#define BG_BAND_REGION_1_SIZE 13
17707 +#define BG_BAND_REGION_2_START 9 // 10,11
17708 +#define BG_BAND_REGION_2_SIZE 2
17709 +#define BG_BAND_REGION_3_START 9 // 10,11,12,13
17710 +#define BG_BAND_REGION_3_SIZE 4
17711 +#define BG_BAND_REGION_4_START 13 // 14
17712 +#define BG_BAND_REGION_4_SIZE 1
17713 +#define BG_BAND_REGION_5_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14
17714 +#define BG_BAND_REGION_5_SIZE 14
17715 +#define BG_BAND_REGION_6_START 2 // 3,4,5,6,7,8,9
17716 +#define BG_BAND_REGION_6_SIZE 7
17717 +#define BG_BAND_REGION_7_START 4 // 5,6,7,8,9,10,11,12,13
17718 +#define BG_BAND_REGION_7_SIZE 9
17719 +#define BG_BAND_REGION_31_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14
17720 +#define BG_BAND_REGION_31_SIZE 14
17721 +
17722 +// 5 Ghz channel plan index in the TxPower arrays.
17723 +UCHAR A_BAND_REGION_0_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165};
17724 +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};
17725 +UCHAR A_BAND_REGION_2_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64};
17726 +UCHAR A_BAND_REGION_3_CHANNEL_LIST[]={52, 56, 60, 64, 149, 153, 157, 161};
17727 +UCHAR A_BAND_REGION_4_CHANNEL_LIST[]={149, 153, 157, 161, 165};
17728 +UCHAR A_BAND_REGION_5_CHANNEL_LIST[]={149, 153, 157, 161};
17729 +UCHAR A_BAND_REGION_6_CHANNEL_LIST[]={36, 40, 44, 48};
17730 +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};
17731 +UCHAR A_BAND_REGION_8_CHANNEL_LIST[]={52, 56, 60, 64};
17732 +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};
17733 +UCHAR A_BAND_REGION_10_CHANNEL_LIST[]={36, 40, 44, 48, 149, 153, 157, 161, 165};
17734 +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};
17735 +
17736 +//BaSizeArray follows the 802.11n definition as MaxRxFactor. 2^(13+factor) bytes. When factor =0, it's about Ba buffer size =8.
17737 +UCHAR BaSizeArray[4] = {8,16,32,64};
17738 +
17739 +/*
17740 + ==========================================================================
17741 + Description:
17742 + Update StaCfg->ChannelList[] according to 1) Country Region 2) RF IC type,
17743 + and 3) PHY-mode user selected.
17744 + The outcome is used by driver when doing site survey.
17745 +
17746 + IRQL = PASSIVE_LEVEL
17747 + IRQL = DISPATCH_LEVEL
17748 +
17749 + ==========================================================================
17750 + */
17751 +VOID BuildChannelList(
17752 + IN PRTMP_ADAPTER pAd)
17753 +{
17754 + UCHAR i, j, index=0, num=0;
17755 + PUCHAR pChannelList = NULL;
17756 +
17757 + NdisZeroMemory(pAd->ChannelList, MAX_NUM_OF_CHANNELS * sizeof(CHANNEL_TX_POWER));
17758 +
17759 + // if not 11a-only mode, channel list starts from 2.4Ghz band
17760 + if ((pAd->CommonCfg.PhyMode != PHY_11A)
17761 +#ifdef DOT11_N_SUPPORT
17762 + && (pAd->CommonCfg.PhyMode != PHY_11AN_MIXED) && (pAd->CommonCfg.PhyMode != PHY_11N_5G)
17763 +#endif // DOT11_N_SUPPORT //
17764 + )
17765 + {
17766 + switch (pAd->CommonCfg.CountryRegion & 0x7f)
17767 + {
17768 + case REGION_0_BG_BAND: // 1 -11
17769 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_0_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_0_SIZE);
17770 + index += BG_BAND_REGION_0_SIZE;
17771 + break;
17772 + case REGION_1_BG_BAND: // 1 - 13
17773 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_1_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_1_SIZE);
17774 + index += BG_BAND_REGION_1_SIZE;
17775 + break;
17776 + case REGION_2_BG_BAND: // 10 - 11
17777 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_2_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_2_SIZE);
17778 + index += BG_BAND_REGION_2_SIZE;
17779 + break;
17780 + case REGION_3_BG_BAND: // 10 - 13
17781 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_3_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_3_SIZE);
17782 + index += BG_BAND_REGION_3_SIZE;
17783 + break;
17784 + case REGION_4_BG_BAND: // 14
17785 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_4_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_4_SIZE);
17786 + index += BG_BAND_REGION_4_SIZE;
17787 + break;
17788 + case REGION_5_BG_BAND: // 1 - 14
17789 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_5_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_5_SIZE);
17790 + index += BG_BAND_REGION_5_SIZE;
17791 + break;
17792 + case REGION_6_BG_BAND: // 3 - 9
17793 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_6_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_6_SIZE);
17794 + index += BG_BAND_REGION_6_SIZE;
17795 + break;
17796 + case REGION_7_BG_BAND: // 5 - 13
17797 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_7_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_7_SIZE);
17798 + index += BG_BAND_REGION_7_SIZE;
17799 + break;
17800 + case REGION_31_BG_BAND: // 1 - 14
17801 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_31_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_31_SIZE);
17802 + index += BG_BAND_REGION_31_SIZE;
17803 + break;
17804 + default: // Error. should never happen
17805 + break;
17806 + }
17807 + for (i=0; i<index; i++)
17808 + pAd->ChannelList[i].MaxTxPwr = 20;
17809 + }
17810 +
17811 + if ((pAd->CommonCfg.PhyMode == PHY_11A) || (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
17812 +#ifdef DOT11_N_SUPPORT
17813 + || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED)
17814 + || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)
17815 +#endif // DOT11_N_SUPPORT //
17816 + )
17817 + {
17818 + switch (pAd->CommonCfg.CountryRegionForABand & 0x7f)
17819 + {
17820 + case REGION_0_A_BAND:
17821 + num = sizeof(A_BAND_REGION_0_CHANNEL_LIST)/sizeof(UCHAR);
17822 + pChannelList = A_BAND_REGION_0_CHANNEL_LIST;
17823 + break;
17824 + case REGION_1_A_BAND:
17825 + num = sizeof(A_BAND_REGION_1_CHANNEL_LIST)/sizeof(UCHAR);
17826 + pChannelList = A_BAND_REGION_1_CHANNEL_LIST;
17827 + break;
17828 + case REGION_2_A_BAND:
17829 + num = sizeof(A_BAND_REGION_2_CHANNEL_LIST)/sizeof(UCHAR);
17830 + pChannelList = A_BAND_REGION_2_CHANNEL_LIST;
17831 + break;
17832 + case REGION_3_A_BAND:
17833 + num = sizeof(A_BAND_REGION_3_CHANNEL_LIST)/sizeof(UCHAR);
17834 + pChannelList = A_BAND_REGION_3_CHANNEL_LIST;
17835 + break;
17836 + case REGION_4_A_BAND:
17837 + num = sizeof(A_BAND_REGION_4_CHANNEL_LIST)/sizeof(UCHAR);
17838 + pChannelList = A_BAND_REGION_4_CHANNEL_LIST;
17839 + break;
17840 + case REGION_5_A_BAND:
17841 + num = sizeof(A_BAND_REGION_5_CHANNEL_LIST)/sizeof(UCHAR);
17842 + pChannelList = A_BAND_REGION_5_CHANNEL_LIST;
17843 + break;
17844 + case REGION_6_A_BAND:
17845 + num = sizeof(A_BAND_REGION_6_CHANNEL_LIST)/sizeof(UCHAR);
17846 + pChannelList = A_BAND_REGION_6_CHANNEL_LIST;
17847 + break;
17848 + case REGION_7_A_BAND:
17849 + num = sizeof(A_BAND_REGION_7_CHANNEL_LIST)/sizeof(UCHAR);
17850 + pChannelList = A_BAND_REGION_7_CHANNEL_LIST;
17851 + break;
17852 + case REGION_8_A_BAND:
17853 + num = sizeof(A_BAND_REGION_8_CHANNEL_LIST)/sizeof(UCHAR);
17854 + pChannelList = A_BAND_REGION_8_CHANNEL_LIST;
17855 + break;
17856 + case REGION_9_A_BAND:
17857 + num = sizeof(A_BAND_REGION_9_CHANNEL_LIST)/sizeof(UCHAR);
17858 + pChannelList = A_BAND_REGION_9_CHANNEL_LIST;
17859 + break;
17860 +
17861 + case REGION_10_A_BAND:
17862 + num = sizeof(A_BAND_REGION_10_CHANNEL_LIST)/sizeof(UCHAR);
17863 + pChannelList = A_BAND_REGION_10_CHANNEL_LIST;
17864 + break;
17865 +
17866 + case REGION_11_A_BAND:
17867 + num = sizeof(A_BAND_REGION_11_CHANNEL_LIST)/sizeof(UCHAR);
17868 + pChannelList = A_BAND_REGION_11_CHANNEL_LIST;
17869 + break;
17870 +
17871 + default: // Error. should never happen
17872 + DBGPRINT(RT_DEBUG_WARN,("countryregion=%d not support", pAd->CommonCfg.CountryRegionForABand));
17873 + break;
17874 + }
17875 +
17876 + if (num != 0)
17877 + {
17878 + UCHAR RadarCh[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
17879 + for (i=0; i<num; i++)
17880 + {
17881 + for (j=0; j<MAX_NUM_OF_CHANNELS; j++)
17882 + {
17883 + if (pChannelList[i] == pAd->TxPower[j].Channel)
17884 + NdisMoveMemory(&pAd->ChannelList[index+i], &pAd->TxPower[j], sizeof(CHANNEL_TX_POWER));
17885 + }
17886 + for (j=0; j<15; j++)
17887 + {
17888 + if (pChannelList[i] == RadarCh[j])
17889 + pAd->ChannelList[index+i].DfsReq = TRUE;
17890 + }
17891 + pAd->ChannelList[index+i].MaxTxPwr = 20;
17892 + }
17893 + index += num;
17894 + }
17895 + }
17896 +
17897 + pAd->ChannelListNum = index;
17898 + DBGPRINT(RT_DEBUG_TRACE,("country code=%d/%d, RFIC=%d, PHY mode=%d, support %d channels\n",
17899 + pAd->CommonCfg.CountryRegion, pAd->CommonCfg.CountryRegionForABand, pAd->RfIcType, pAd->CommonCfg.PhyMode, pAd->ChannelListNum));
17900 +#ifdef DBG
17901 + for (i=0;i<pAd->ChannelListNum;i++)
17902 + {
17903 + DBGPRINT_RAW(RT_DEBUG_TRACE,("BuildChannel # %d :: Pwr0 = %d, Pwr1 =%d, \n ", pAd->ChannelList[i].Channel, pAd->ChannelList[i].Power, pAd->ChannelList[i].Power2));
17904 + }
17905 +#endif
17906 +}
17907 +
17908 +/*
17909 + ==========================================================================
17910 + Description:
17911 + This routine return the first channel number according to the country
17912 + code selection and RF IC selection (signal band or dual band). It is called
17913 + whenever driver need to start a site survey of all supported channels.
17914 + Return:
17915 + ch - the first channel number of current country code setting
17916 +
17917 + IRQL = PASSIVE_LEVEL
17918 +
17919 + ==========================================================================
17920 + */
17921 +UCHAR FirstChannel(
17922 + IN PRTMP_ADAPTER pAd)
17923 +{
17924 + return pAd->ChannelList[0].Channel;
17925 +}
17926 +
17927 +/*
17928 + ==========================================================================
17929 + Description:
17930 + This routine returns the next channel number. This routine is called
17931 + during driver need to start a site survey of all supported channels.
17932 + Return:
17933 + next_channel - the next channel number valid in current country code setting.
17934 + Note:
17935 + return 0 if no more next channel
17936 + ==========================================================================
17937 + */
17938 +UCHAR NextChannel(
17939 + IN PRTMP_ADAPTER pAd,
17940 + IN UCHAR channel)
17941 +{
17942 + int i;
17943 + UCHAR next_channel = 0;
17944 +
17945 + for (i = 0; i < (pAd->ChannelListNum - 1); i++)
17946 + if (channel == pAd->ChannelList[i].Channel)
17947 + {
17948 + next_channel = pAd->ChannelList[i+1].Channel;
17949 + break;
17950 + }
17951 + return next_channel;
17952 +}
17953 +
17954 +/*
17955 + ==========================================================================
17956 + Description:
17957 + This routine is for Cisco Compatible Extensions 2.X
17958 + Spec31. AP Control of Client Transmit Power
17959 + Return:
17960 + None
17961 + Note:
17962 + Required by Aironet dBm(mW)
17963 + 0dBm(1mW), 1dBm(5mW), 13dBm(20mW), 15dBm(30mW),
17964 + 17dBm(50mw), 20dBm(100mW)
17965 +
17966 + We supported
17967 + 3dBm(Lowest), 6dBm(10%), 9dBm(25%), 12dBm(50%),
17968 + 14dBm(75%), 15dBm(100%)
17969 +
17970 + The client station's actual transmit power shall be within +/- 5dB of
17971 + the minimum value or next lower value.
17972 + ==========================================================================
17973 + */
17974 +VOID ChangeToCellPowerLimit(
17975 + IN PRTMP_ADAPTER pAd,
17976 + IN UCHAR AironetCellPowerLimit)
17977 +{
17978 + //valud 0xFF means that hasn't found power limit information
17979 + //from the AP's Beacon/Probe response.
17980 + if (AironetCellPowerLimit == 0xFF)
17981 + return;
17982 +
17983 + if (AironetCellPowerLimit < 6) //Used Lowest Power Percentage.
17984 + pAd->CommonCfg.TxPowerPercentage = 6;
17985 + else if (AironetCellPowerLimit < 9)
17986 + pAd->CommonCfg.TxPowerPercentage = 10;
17987 + else if (AironetCellPowerLimit < 12)
17988 + pAd->CommonCfg.TxPowerPercentage = 25;
17989 + else if (AironetCellPowerLimit < 14)
17990 + pAd->CommonCfg.TxPowerPercentage = 50;
17991 + else if (AironetCellPowerLimit < 15)
17992 + pAd->CommonCfg.TxPowerPercentage = 75;
17993 + else
17994 + pAd->CommonCfg.TxPowerPercentage = 100; //else used maximum
17995 +
17996 + if (pAd->CommonCfg.TxPowerPercentage > pAd->CommonCfg.TxPowerDefault)
17997 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
17998 +
17999 +}
18000 +
18001 +CHAR ConvertToRssi(
18002 + IN PRTMP_ADAPTER pAd,
18003 + IN CHAR Rssi,
18004 + IN UCHAR RssiNumber)
18005 +{
18006 + UCHAR RssiOffset, LNAGain;
18007 +
18008 + // Rssi equals to zero should be an invalid value
18009 + if (Rssi == 0)
18010 + return -99;
18011 +
18012 + LNAGain = GET_LNA_GAIN(pAd);
18013 + if (pAd->LatchRfRegs.Channel > 14)
18014 + {
18015 + if (RssiNumber == 0)
18016 + RssiOffset = pAd->ARssiOffset0;
18017 + else if (RssiNumber == 1)
18018 + RssiOffset = pAd->ARssiOffset1;
18019 + else
18020 + RssiOffset = pAd->ARssiOffset2;
18021 + }
18022 + else
18023 + {
18024 + if (RssiNumber == 0)
18025 + RssiOffset = pAd->BGRssiOffset0;
18026 + else if (RssiNumber == 1)
18027 + RssiOffset = pAd->BGRssiOffset1;
18028 + else
18029 + RssiOffset = pAd->BGRssiOffset2;
18030 + }
18031 +
18032 + return (-12 - RssiOffset - LNAGain - Rssi);
18033 +}
18034 +
18035 +/*
18036 + ==========================================================================
18037 + Description:
18038 + Scan next channel
18039 + ==========================================================================
18040 + */
18041 +VOID ScanNextChannel(
18042 + IN PRTMP_ADAPTER pAd)
18043 +{
18044 + HEADER_802_11 Hdr80211;
18045 + PUCHAR pOutBuffer = NULL;
18046 + NDIS_STATUS NStatus;
18047 + ULONG FrameLen = 0;
18048 + UCHAR SsidLen = 0, ScanType = pAd->MlmeAux.ScanType, BBPValue = 0;
18049 +#ifdef CONFIG_STA_SUPPORT
18050 + USHORT Status;
18051 + PHEADER_802_11 pHdr80211;
18052 +#endif // CONFIG_STA_SUPPORT //
18053 + UINT ScanTimeIn5gChannel = SHORT_CHANNEL_TIME;
18054 +
18055 +#ifdef CONFIG_STA_SUPPORT
18056 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18057 + {
18058 + if (MONITOR_ON(pAd))
18059 + return;
18060 + }
18061 +#endif // CONFIG_STA_SUPPORT //
18062 +
18063 +#ifdef RALINK_ATE
18064 + // Nothing to do in ATE mode.
18065 + if (ATE_ON(pAd))
18066 + return;
18067 +#endif // RALINK_ATE //
18068 +
18069 + if (pAd->MlmeAux.Channel == 0)
18070 + {
18071 + if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
18072 +#ifdef CONFIG_STA_SUPPORT
18073 + && (INFRA_ON(pAd)
18074 + || (pAd->OpMode == OPMODE_AP))
18075 +#endif // CONFIG_STA_SUPPORT //
18076 + )
18077 + {
18078 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
18079 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
18080 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
18081 + BBPValue &= (~0x18);
18082 + BBPValue |= 0x10;
18083 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
18084 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
18085 + }
18086 + else
18087 + {
18088 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
18089 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
18090 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to channel %d, Total BSS[%02d]\n",pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
18091 + }
18092 +
18093 +#ifdef CONFIG_STA_SUPPORT
18094 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18095 + {
18096 + //
18097 + // To prevent data lost.
18098 + // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.
18099 + // Now, we need to send an NULL data with turned PSM bit off to AP, when scan progress done
18100 + //
18101 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))
18102 + {
18103 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);
18104 + if (NStatus == NDIS_STATUS_SUCCESS)
18105 + {
18106 + pHdr80211 = (PHEADER_802_11) pOutBuffer;
18107 + MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
18108 + pHdr80211->Duration = 0;
18109 + pHdr80211->FC.Type = BTYPE_DATA;
18110 + pHdr80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
18111 +
18112 + // Send using priority queue
18113 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
18114 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame\n"));
18115 + MlmeFreeMemory(pAd, pOutBuffer);
18116 + RTMPusecDelay(5000);
18117 + }
18118 + }
18119 +
18120 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
18121 + Status = MLME_SUCCESS;
18122 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
18123 + }
18124 +#endif // CONFIG_STA_SUPPORT //
18125 +
18126 +
18127 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
18128 + }
18129 +#ifdef RT2870
18130 +#ifdef CONFIG_STA_SUPPORT
18131 + else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) && (pAd->OpMode == OPMODE_STA))
18132 + {
18133 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
18134 + MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE);
18135 + }
18136 +#endif // CONFIG_STA_SUPPORT //
18137 +#endif // RT2870 //
18138 + else
18139 + {
18140 +#ifdef CONFIG_STA_SUPPORT
18141 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18142 + {
18143 + // BBP and RF are not accessible in PS mode, we has to wake them up first
18144 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
18145 + AsicForceWakeup(pAd, TRUE);
18146 +
18147 + // leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON
18148 + if (pAd->StaCfg.Psm == PWR_SAVE)
18149 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
18150 + }
18151 +#endif // CONFIG_STA_SUPPORT //
18152 +
18153 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, TRUE);
18154 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
18155 +
18156 +#ifdef CONFIG_STA_SUPPORT
18157 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18158 + {
18159 + if (pAd->MlmeAux.Channel > 14)
18160 + {
18161 + if ((pAd->CommonCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
18162 + {
18163 + ScanType = SCAN_PASSIVE;
18164 + ScanTimeIn5gChannel = MIN_CHANNEL_TIME;
18165 + }
18166 + }
18167 +
18168 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
18169 + // carrier detection
18170 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
18171 + {
18172 + ScanType = SCAN_PASSIVE;
18173 + ScanTimeIn5gChannel = MIN_CHANNEL_TIME;
18174 + }
18175 +#endif // CARRIER_DETECTION_SUPPORT //
18176 + }
18177 +
18178 +#endif // CONFIG_STA_SUPPORT //
18179 +
18180 + //Global country domain(ch1-11:active scan, ch12-14 passive scan)
18181 + if ((pAd->MlmeAux.Channel <= 14) && (pAd->MlmeAux.Channel >= 12) && ((pAd->CommonCfg.CountryRegion & 0x7f) == REGION_31_BG_BAND))
18182 + {
18183 + ScanType = SCAN_PASSIVE;
18184 + }
18185 +
18186 + // We need to shorten active scan time in order for WZC connect issue
18187 + // Chnage the channel scan time for CISCO stuff based on its IAPP announcement
18188 + if (ScanType == FAST_SCAN_ACTIVE)
18189 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, FAST_ACTIVE_SCAN_TIME);
18190 +#ifdef CONFIG_STA_SUPPORT
18191 + else if (((ScanType == SCAN_CISCO_ACTIVE) ||
18192 + (ScanType == SCAN_CISCO_PASSIVE) ||
18193 + (ScanType == SCAN_CISCO_CHANNEL_LOAD) ||
18194 + (ScanType == SCAN_CISCO_NOISE)) && (pAd->OpMode == OPMODE_STA))
18195 + {
18196 + if (pAd->StaCfg.CCXScanTime < 25)
18197 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime * 2);
18198 + else
18199 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime);
18200 + }
18201 +#endif // CONFIG_STA_SUPPORT //
18202 + else // must be SCAN_PASSIVE or SCAN_ACTIVE
18203 + {
18204 + if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
18205 +#ifdef DOT11_N_SUPPORT
18206 + || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED)
18207 +#endif // DOT11_N_SUPPORT //
18208 + )
18209 + {
18210 + if (pAd->MlmeAux.Channel > 14)
18211 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, ScanTimeIn5gChannel);
18212 + else
18213 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MIN_CHANNEL_TIME);
18214 + }
18215 + else
18216 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MAX_CHANNEL_TIME);
18217 + }
18218 +
18219 + if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE) ||
18220 + (ScanType == SCAN_CISCO_ACTIVE))
18221 + {
18222 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
18223 + if (NStatus != NDIS_STATUS_SUCCESS)
18224 + {
18225 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - ScanNextChannel() allocate memory fail\n"));
18226 +#ifdef CONFIG_STA_SUPPORT
18227 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18228 + {
18229 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
18230 + Status = MLME_FAIL_NO_RESOURCE;
18231 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
18232 + }
18233 +#endif // CONFIG_STA_SUPPORT //
18234 +
18235 + return;
18236 + }
18237 +
18238 + // There is no need to send broadcast probe request if active scan is in effect.
18239 + if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE)
18240 + )
18241 + SsidLen = pAd->MlmeAux.SsidLen;
18242 + else
18243 + SsidLen = 0;
18244 +
18245 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
18246 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
18247 + sizeof(HEADER_802_11), &Hdr80211,
18248 + 1, &SsidIe,
18249 + 1, &SsidLen,
18250 + SsidLen, pAd->MlmeAux.Ssid,
18251 + 1, &SupRateIe,
18252 + 1, &pAd->CommonCfg.SupRateLen,
18253 + pAd->CommonCfg.SupRateLen, pAd->CommonCfg.SupRate,
18254 + END_OF_ARGS);
18255 +
18256 + if (pAd->CommonCfg.ExtRateLen)
18257 + {
18258 + ULONG Tmp;
18259 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18260 + 1, &ExtRateIe,
18261 + 1, &pAd->CommonCfg.ExtRateLen,
18262 + pAd->CommonCfg.ExtRateLen, pAd->CommonCfg.ExtRate,
18263 + END_OF_ARGS);
18264 + FrameLen += Tmp;
18265 + }
18266 +
18267 +#ifdef DOT11_N_SUPPORT
18268 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
18269 + {
18270 + ULONG Tmp;
18271 + UCHAR HtLen;
18272 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
18273 +#ifdef RT_BIG_ENDIAN
18274 + HT_CAPABILITY_IE HtCapabilityTmp;
18275 +#endif
18276 + if (pAd->bBroadComHT == TRUE)
18277 + {
18278 + HtLen = pAd->MlmeAux.HtCapabilityLen + 4;
18279 +#ifdef RT_BIG_ENDIAN
18280 + NdisMoveMemory(&HtCapabilityTmp, &pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
18281 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
18282 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
18283 +
18284 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18285 + 1, &WpaIe,
18286 + 1, &HtLen,
18287 + 4, &BROADCOM[0],
18288 + pAd->MlmeAux.HtCapabilityLen, &HtCapabilityTmp,
18289 + END_OF_ARGS);
18290 +#else
18291 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18292 + 1, &WpaIe,
18293 + 1, &HtLen,
18294 + 4, &BROADCOM[0],
18295 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
18296 + END_OF_ARGS);
18297 +#endif // RT_BIG_ENDIAN //
18298 + }
18299 + else
18300 + {
18301 + HtLen = pAd->MlmeAux.HtCapabilityLen;
18302 +#ifdef RT_BIG_ENDIAN
18303 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, SIZE_HT_CAP_IE);
18304 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
18305 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
18306 +
18307 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18308 + 1, &HtCapIe,
18309 + 1, &HtLen,
18310 + HtLen, &HtCapabilityTmp,
18311 + END_OF_ARGS);
18312 +#else
18313 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18314 + 1, &HtCapIe,
18315 + 1, &HtLen,
18316 + HtLen, &pAd->CommonCfg.HtCapability,
18317 + END_OF_ARGS);
18318 +#endif // RT_BIG_ENDIAN //
18319 + }
18320 + FrameLen += Tmp;
18321 +
18322 +#ifdef DOT11N_DRAFT3
18323 + if (pAd->CommonCfg.BACapability.field.b2040CoexistScanSup == 1)
18324 + {
18325 + ULONG Tmp;
18326 + HtLen = 1;
18327 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18328 + 1, &ExtHtCapIe,
18329 + 1, &HtLen,
18330 + 1, &pAd->CommonCfg.BSSCoexist2040.word,
18331 + END_OF_ARGS);
18332 +
18333 + FrameLen += Tmp;
18334 + }
18335 +#endif // DOT11N_DRAFT3 //
18336 + }
18337 +#endif // DOT11_N_SUPPORT //
18338 +
18339 +
18340 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
18341 + MlmeFreeMemory(pAd, pOutBuffer);
18342 + }
18343 +
18344 + // For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe reponse
18345 +
18346 +#ifdef CONFIG_STA_SUPPORT
18347 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18348 + pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN;
18349 +#endif // CONFIG_STA_SUPPORT //
18350 +
18351 + }
18352 +}
18353 +
18354 +VOID MgtProbReqMacHeaderInit(
18355 + IN PRTMP_ADAPTER pAd,
18356 + IN OUT PHEADER_802_11 pHdr80211,
18357 + IN UCHAR SubType,
18358 + IN UCHAR ToDs,
18359 + IN PUCHAR pDA,
18360 + IN PUCHAR pBssid)
18361 +{
18362 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
18363 +
18364 + pHdr80211->FC.Type = BTYPE_MGMT;
18365 + pHdr80211->FC.SubType = SubType;
18366 + if (SubType == SUBTYPE_ACK)
18367 + pHdr80211->FC.Type = BTYPE_CNTL;
18368 + pHdr80211->FC.ToDs = ToDs;
18369 + COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
18370 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
18371 + COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
18372 +}
18373 +
18374 +
18375 --- /dev/null
18376 +++ b/drivers/staging/rt2870/common/cmm_wpa.c
18377 @@ -0,0 +1,1654 @@
18378 +/*
18379 + *************************************************************************
18380 + * Ralink Tech Inc.
18381 + * 5F., No.36, Taiyuan St., Jhubei City,
18382 + * Hsinchu County 302,
18383 + * Taiwan, R.O.C.
18384 + *
18385 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
18386 + *
18387 + * This program is free software; you can redistribute it and/or modify *
18388 + * it under the terms of the GNU General Public License as published by *
18389 + * the Free Software Foundation; either version 2 of the License, or *
18390 + * (at your option) any later version. *
18391 + * *
18392 + * This program is distributed in the hope that it will be useful, *
18393 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18394 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18395 + * GNU General Public License for more details. *
18396 + * *
18397 + * You should have received a copy of the GNU General Public License *
18398 + * along with this program; if not, write to the *
18399 + * Free Software Foundation, Inc., *
18400 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18401 + * *
18402 + *************************************************************************
18403 +
18404 + Module Name:
18405 + wpa.c
18406 +
18407 + Abstract:
18408 +
18409 + Revision History:
18410 + Who When What
18411 + -------- ---------- ----------------------------------------------
18412 + Jan Lee 03-07-22 Initial
18413 + Paul Lin 03-11-28 Modify for supplicant
18414 +*/
18415 +#include "../rt_config.h"
18416 +// WPA OUI
18417 +UCHAR OUI_WPA_NONE_AKM[4] = {0x00, 0x50, 0xF2, 0x00};
18418 +UCHAR OUI_WPA_VERSION[4] = {0x00, 0x50, 0xF2, 0x01};
18419 +UCHAR OUI_WPA_WEP40[4] = {0x00, 0x50, 0xF2, 0x01};
18420 +UCHAR OUI_WPA_TKIP[4] = {0x00, 0x50, 0xF2, 0x02};
18421 +UCHAR OUI_WPA_CCMP[4] = {0x00, 0x50, 0xF2, 0x04};
18422 +UCHAR OUI_WPA_WEP104[4] = {0x00, 0x50, 0xF2, 0x05};
18423 +UCHAR OUI_WPA_8021X_AKM[4] = {0x00, 0x50, 0xF2, 0x01};
18424 +UCHAR OUI_WPA_PSK_AKM[4] = {0x00, 0x50, 0xF2, 0x02};
18425 +// WPA2 OUI
18426 +UCHAR OUI_WPA2_WEP40[4] = {0x00, 0x0F, 0xAC, 0x01};
18427 +UCHAR OUI_WPA2_TKIP[4] = {0x00, 0x0F, 0xAC, 0x02};
18428 +UCHAR OUI_WPA2_CCMP[4] = {0x00, 0x0F, 0xAC, 0x04};
18429 +UCHAR OUI_WPA2_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x01};
18430 +UCHAR OUI_WPA2_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x02};
18431 +UCHAR OUI_WPA2_WEP104[4] = {0x00, 0x0F, 0xAC, 0x05};
18432 +// MSA OUI
18433 +UCHAR OUI_MSA_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x05}; // Not yet final - IEEE 802.11s-D1.06
18434 +UCHAR OUI_MSA_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x06}; // Not yet final - IEEE 802.11s-D1.06
18435 +
18436 +/*
18437 + ========================================================================
18438 +
18439 + Routine Description:
18440 + The pseudo-random function(PRF) that hashes various inputs to
18441 + derive a pseudo-random value. To add liveness to the pseudo-random
18442 + value, a nonce should be one of the inputs.
18443 +
18444 + It is used to generate PTK, GTK or some specific random value.
18445 +
18446 + Arguments:
18447 + UCHAR *key, - the key material for HMAC_SHA1 use
18448 + INT key_len - the length of key
18449 + UCHAR *prefix - a prefix label
18450 + INT prefix_len - the length of the label
18451 + UCHAR *data - a specific data with variable length
18452 + INT data_len - the length of a specific data
18453 + INT len - the output lenght
18454 +
18455 + Return Value:
18456 + UCHAR *output - the calculated result
18457 +
18458 + Note:
18459 + 802.11i-2004 Annex H.3
18460 +
18461 + ========================================================================
18462 +*/
18463 +VOID PRF(
18464 + IN UCHAR *key,
18465 + IN INT key_len,
18466 + IN UCHAR *prefix,
18467 + IN INT prefix_len,
18468 + IN UCHAR *data,
18469 + IN INT data_len,
18470 + OUT UCHAR *output,
18471 + IN INT len)
18472 +{
18473 + INT i;
18474 + UCHAR *input;
18475 + INT currentindex = 0;
18476 + INT total_len;
18477 +
18478 + // Allocate memory for input
18479 + os_alloc_mem(NULL, (PUCHAR *)&input, 1024);
18480 +
18481 + if (input == NULL)
18482 + {
18483 + DBGPRINT(RT_DEBUG_ERROR, ("!!!PRF: no memory!!!\n"));
18484 + return;
18485 + }
18486 +
18487 + // Generate concatenation input
18488 + NdisMoveMemory(input, prefix, prefix_len);
18489 +
18490 + // Concatenate a single octet containing 0
18491 + input[prefix_len] = 0;
18492 +
18493 + // Concatenate specific data
18494 + NdisMoveMemory(&input[prefix_len + 1], data, data_len);
18495 + total_len = prefix_len + 1 + data_len;
18496 +
18497 + // Concatenate a single octet containing 0
18498 + // This octet shall be update later
18499 + input[total_len] = 0;
18500 + total_len++;
18501 +
18502 + // Iterate to calculate the result by hmac-sha-1
18503 + // Then concatenate to last result
18504 + for (i = 0; i < (len + 19) / 20; i++)
18505 + {
18506 + HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
18507 + currentindex += 20;
18508 +
18509 + // update the last octet
18510 + input[total_len - 1]++;
18511 + }
18512 + os_free_mem(NULL, input);
18513 +}
18514 +
18515 +/*
18516 + ========================================================================
18517 +
18518 + Routine Description:
18519 + It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK.
18520 + It shall be called by 4-way handshake processing.
18521 +
18522 + Arguments:
18523 + pAd - pointer to our pAdapter context
18524 + PMK - pointer to PMK
18525 + ANonce - pointer to ANonce
18526 + AA - pointer to Authenticator Address
18527 + SNonce - pointer to SNonce
18528 + SA - pointer to Supplicant Address
18529 + len - indicate the length of PTK (octet)
18530 +
18531 + Return Value:
18532 + Output pointer to the PTK
18533 +
18534 + Note:
18535 + Refer to IEEE 802.11i-2004 8.5.1.2
18536 +
18537 + ========================================================================
18538 +*/
18539 +VOID WpaCountPTK(
18540 + IN PRTMP_ADAPTER pAd,
18541 + IN UCHAR *PMK,
18542 + IN UCHAR *ANonce,
18543 + IN UCHAR *AA,
18544 + IN UCHAR *SNonce,
18545 + IN UCHAR *SA,
18546 + OUT UCHAR *output,
18547 + IN UINT len)
18548 +{
18549 + UCHAR concatenation[76];
18550 + UINT CurrPos = 0;
18551 + UCHAR temp[32];
18552 + UCHAR Prefix[] = {'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ',
18553 + 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'};
18554 +
18555 + // initiate the concatenation input
18556 + NdisZeroMemory(temp, sizeof(temp));
18557 + NdisZeroMemory(concatenation, 76);
18558 +
18559 + // Get smaller address
18560 + if (RTMPCompareMemory(SA, AA, 6) == 1)
18561 + NdisMoveMemory(concatenation, AA, 6);
18562 + else
18563 + NdisMoveMemory(concatenation, SA, 6);
18564 + CurrPos += 6;
18565 +
18566 + // Get larger address
18567 + if (RTMPCompareMemory(SA, AA, 6) == 1)
18568 + NdisMoveMemory(&concatenation[CurrPos], SA, 6);
18569 + else
18570 + NdisMoveMemory(&concatenation[CurrPos], AA, 6);
18571 +
18572 + // store the larger mac address for backward compatible of
18573 + // ralink proprietary STA-key issue
18574 + NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN);
18575 + CurrPos += 6;
18576 +
18577 + // Get smaller Nonce
18578 + if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
18579 + NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
18580 + else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
18581 + NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
18582 + else
18583 + NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
18584 + CurrPos += 32;
18585 +
18586 + // Get larger Nonce
18587 + if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
18588 + NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
18589 + else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
18590 + NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
18591 + else
18592 + NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
18593 + CurrPos += 32;
18594 +
18595 + hex_dump("concatenation=", concatenation, 76);
18596 +
18597 + // Use PRF to generate PTK
18598 + PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len);
18599 +
18600 +}
18601 +
18602 +/*
18603 + ========================================================================
18604 +
18605 + Routine Description:
18606 + Generate random number by software.
18607 +
18608 + Arguments:
18609 + pAd - pointer to our pAdapter context
18610 + macAddr - pointer to local MAC address
18611 +
18612 + Return Value:
18613 +
18614 + Note:
18615 + 802.1ii-2004 Annex H.5
18616 +
18617 + ========================================================================
18618 +*/
18619 +VOID GenRandom(
18620 + IN PRTMP_ADAPTER pAd,
18621 + IN UCHAR *macAddr,
18622 + OUT UCHAR *random)
18623 +{
18624 + INT i, curr;
18625 + UCHAR local[80], KeyCounter[32];
18626 + UCHAR result[80];
18627 + ULONG CurrentTime;
18628 + UCHAR prefix[] = {'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r'};
18629 +
18630 + // Zero the related information
18631 + NdisZeroMemory(result, 80);
18632 + NdisZeroMemory(local, 80);
18633 + NdisZeroMemory(KeyCounter, 32);
18634 +
18635 + for (i = 0; i < 32; i++)
18636 + {
18637 + // copy the local MAC address
18638 + COPY_MAC_ADDR(local, macAddr);
18639 + curr = MAC_ADDR_LEN;
18640 +
18641 + // concatenate the current time
18642 + NdisGetSystemUpTime(&CurrentTime);
18643 + NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime));
18644 + curr += sizeof(CurrentTime);
18645 +
18646 + // concatenate the last result
18647 + NdisMoveMemory(&local[curr], result, 32);
18648 + curr += 32;
18649 +
18650 + // concatenate a variable
18651 + NdisMoveMemory(&local[curr], &i, 2);
18652 + curr += 2;
18653 +
18654 + // calculate the result
18655 + PRF(KeyCounter, 32, prefix,12, local, curr, result, 32);
18656 + }
18657 +
18658 + NdisMoveMemory(random, result, 32);
18659 +}
18660 +
18661 +/*
18662 + ========================================================================
18663 +
18664 + Routine Description:
18665 + Build cipher suite in RSN-IE.
18666 + It only shall be called by RTMPMakeRSNIE.
18667 +
18668 + Arguments:
18669 + pAd - pointer to our pAdapter context
18670 + ElementID - indicate the WPA1 or WPA2
18671 + WepStatus - indicate the encryption type
18672 + bMixCipher - a boolean to indicate the pairwise cipher and group
18673 + cipher are the same or not
18674 +
18675 + Return Value:
18676 +
18677 + Note:
18678 +
18679 + ========================================================================
18680 +*/
18681 +static VOID RTMPInsertRsnIeCipher(
18682 + IN PRTMP_ADAPTER pAd,
18683 + IN UCHAR ElementID,
18684 + IN UINT WepStatus,
18685 + IN BOOLEAN bMixCipher,
18686 + IN UCHAR FlexibleCipher,
18687 + OUT PUCHAR pRsnIe,
18688 + OUT UCHAR *rsn_len)
18689 +{
18690 + UCHAR PairwiseCnt;
18691 +
18692 + *rsn_len = 0;
18693 +
18694 + // decide WPA2 or WPA1
18695 + if (ElementID == Wpa2Ie)
18696 + {
18697 + RSNIE2 *pRsnie_cipher = (RSNIE2*)pRsnIe;
18698 +
18699 + // Assign the verson as 1
18700 + pRsnie_cipher->version = 1;
18701 +
18702 + switch (WepStatus)
18703 + {
18704 + // TKIP mode
18705 + case Ndis802_11Encryption2Enabled:
18706 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18707 + pRsnie_cipher->ucount = 1;
18708 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
18709 + *rsn_len = sizeof(RSNIE2);
18710 + break;
18711 +
18712 + // AES mode
18713 + case Ndis802_11Encryption3Enabled:
18714 + if (bMixCipher)
18715 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18716 + else
18717 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_CCMP, 4);
18718 + pRsnie_cipher->ucount = 1;
18719 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
18720 + *rsn_len = sizeof(RSNIE2);
18721 + break;
18722 +
18723 + // TKIP-AES mix mode
18724 + case Ndis802_11Encryption4Enabled:
18725 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18726 +
18727 + PairwiseCnt = 1;
18728 + // Insert WPA2 TKIP as the first pairwise cipher
18729 + if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher))
18730 + {
18731 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
18732 + // Insert WPA2 AES as the secondary pairwise cipher
18733 + if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher))
18734 + {
18735 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA2_CCMP, 4);
18736 + PairwiseCnt = 2;
18737 + }
18738 + }
18739 + else
18740 + {
18741 + // Insert WPA2 AES as the first pairwise cipher
18742 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
18743 + }
18744 +
18745 + pRsnie_cipher->ucount = PairwiseCnt;
18746 + *rsn_len = sizeof(RSNIE2) + (4 * (PairwiseCnt - 1));
18747 + break;
18748 + }
18749 +
18750 +#ifdef CONFIG_STA_SUPPORT
18751 + if ((pAd->OpMode == OPMODE_STA) &&
18752 + (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
18753 + (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
18754 + {
18755 + UINT GroupCipher = pAd->StaCfg.GroupCipher;
18756 + switch(GroupCipher)
18757 + {
18758 + case Ndis802_11GroupWEP40Enabled:
18759 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP40, 4);
18760 + break;
18761 + case Ndis802_11GroupWEP104Enabled:
18762 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP104, 4);
18763 + break;
18764 + }
18765 + }
18766 +#endif // CONFIG_STA_SUPPORT //
18767 +
18768 + // swap for big-endian platform
18769 + pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
18770 + pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
18771 + }
18772 + else
18773 + {
18774 + RSNIE *pRsnie_cipher = (RSNIE*)pRsnIe;
18775 +
18776 + // Assign OUI and version
18777 + NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4);
18778 + pRsnie_cipher->version = 1;
18779 +
18780 + switch (WepStatus)
18781 + {
18782 + // TKIP mode
18783 + case Ndis802_11Encryption2Enabled:
18784 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18785 + pRsnie_cipher->ucount = 1;
18786 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
18787 + *rsn_len = sizeof(RSNIE);
18788 + break;
18789 +
18790 + // AES mode
18791 + case Ndis802_11Encryption3Enabled:
18792 + if (bMixCipher)
18793 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18794 + else
18795 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_CCMP, 4);
18796 + pRsnie_cipher->ucount = 1;
18797 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
18798 + *rsn_len = sizeof(RSNIE);
18799 + break;
18800 +
18801 + // TKIP-AES mix mode
18802 + case Ndis802_11Encryption4Enabled:
18803 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18804 +
18805 + PairwiseCnt = 1;
18806 + // Insert WPA TKIP as the first pairwise cipher
18807 + if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher))
18808 + {
18809 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
18810 + // Insert WPA AES as the secondary pairwise cipher
18811 + if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher))
18812 + {
18813 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA_CCMP, 4);
18814 + PairwiseCnt = 2;
18815 + }
18816 + }
18817 + else
18818 + {
18819 + // Insert WPA AES as the first pairwise cipher
18820 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
18821 + }
18822 +
18823 + pRsnie_cipher->ucount = PairwiseCnt;
18824 + *rsn_len = sizeof(RSNIE) + (4 * (PairwiseCnt - 1));
18825 + break;
18826 + }
18827 +
18828 +#ifdef CONFIG_STA_SUPPORT
18829 + if ((pAd->OpMode == OPMODE_STA) &&
18830 + (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
18831 + (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
18832 + {
18833 + UINT GroupCipher = pAd->StaCfg.GroupCipher;
18834 + switch(GroupCipher)
18835 + {
18836 + case Ndis802_11GroupWEP40Enabled:
18837 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP40, 4);
18838 + break;
18839 + case Ndis802_11GroupWEP104Enabled:
18840 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP104, 4);
18841 + break;
18842 + }
18843 + }
18844 +#endif // CONFIG_STA_SUPPORT //
18845 +
18846 + // swap for big-endian platform
18847 + pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
18848 + pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
18849 + }
18850 +}
18851 +
18852 +/*
18853 + ========================================================================
18854 +
18855 + Routine Description:
18856 + Build AKM suite in RSN-IE.
18857 + It only shall be called by RTMPMakeRSNIE.
18858 +
18859 + Arguments:
18860 + pAd - pointer to our pAdapter context
18861 + ElementID - indicate the WPA1 or WPA2
18862 + AuthMode - indicate the authentication mode
18863 + apidx - indicate the interface index
18864 +
18865 + Return Value:
18866 +
18867 + Note:
18868 +
18869 + ========================================================================
18870 +*/
18871 +static VOID RTMPInsertRsnIeAKM(
18872 + IN PRTMP_ADAPTER pAd,
18873 + IN UCHAR ElementID,
18874 + IN UINT AuthMode,
18875 + IN UCHAR apidx,
18876 + OUT PUCHAR pRsnIe,
18877 + OUT UCHAR *rsn_len)
18878 +{
18879 + RSNIE_AUTH *pRsnie_auth;
18880 +
18881 + pRsnie_auth = (RSNIE_AUTH*)(pRsnIe + (*rsn_len));
18882 +
18883 + // decide WPA2 or WPA1
18884 + if (ElementID == Wpa2Ie)
18885 + {
18886 + switch (AuthMode)
18887 + {
18888 + case Ndis802_11AuthModeWPA2:
18889 + case Ndis802_11AuthModeWPA1WPA2:
18890 + pRsnie_auth->acount = 1;
18891 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_8021X_AKM, 4);
18892 + break;
18893 +
18894 + case Ndis802_11AuthModeWPA2PSK:
18895 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
18896 + pRsnie_auth->acount = 1;
18897 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_PSK_AKM, 4);
18898 + break;
18899 + }
18900 + }
18901 + else
18902 + {
18903 + switch (AuthMode)
18904 + {
18905 + case Ndis802_11AuthModeWPA:
18906 + case Ndis802_11AuthModeWPA1WPA2:
18907 + pRsnie_auth->acount = 1;
18908 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_8021X_AKM, 4);
18909 + break;
18910 +
18911 + case Ndis802_11AuthModeWPAPSK:
18912 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
18913 + pRsnie_auth->acount = 1;
18914 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_PSK_AKM, 4);
18915 + break;
18916 +
18917 + case Ndis802_11AuthModeWPANone:
18918 + pRsnie_auth->acount = 1;
18919 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_NONE_AKM, 4);
18920 + break;
18921 + }
18922 + }
18923 +
18924 + pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount);
18925 +
18926 + (*rsn_len) += sizeof(RSNIE_AUTH); // update current RSNIE length
18927 +
18928 +}
18929 +
18930 +/*
18931 + ========================================================================
18932 +
18933 + Routine Description:
18934 + Build capability in RSN-IE.
18935 + It only shall be called by RTMPMakeRSNIE.
18936 +
18937 + Arguments:
18938 + pAd - pointer to our pAdapter context
18939 + ElementID - indicate the WPA1 or WPA2
18940 + apidx - indicate the interface index
18941 +
18942 + Return Value:
18943 +
18944 + Note:
18945 +
18946 + ========================================================================
18947 +*/
18948 +static VOID RTMPInsertRsnIeCap(
18949 + IN PRTMP_ADAPTER pAd,
18950 + IN UCHAR ElementID,
18951 + IN UCHAR apidx,
18952 + OUT PUCHAR pRsnIe,
18953 + OUT UCHAR *rsn_len)
18954 +{
18955 + RSN_CAPABILITIES *pRSN_Cap;
18956 +
18957 + // it could be ignored in WPA1 mode
18958 + if (ElementID == WpaIe)
18959 + return;
18960 +
18961 + pRSN_Cap = (RSN_CAPABILITIES*)(pRsnIe + (*rsn_len));
18962 +
18963 +
18964 + pRSN_Cap->word = cpu2le16(pRSN_Cap->word);
18965 +
18966 + (*rsn_len) += sizeof(RSN_CAPABILITIES); // update current RSNIE length
18967 +
18968 +}
18969 +
18970 +
18971 +/*
18972 + ========================================================================
18973 +
18974 + Routine Description:
18975 + Build RSN IE context. It is not included element-ID and length.
18976 +
18977 + Arguments:
18978 + pAd - pointer to our pAdapter context
18979 + AuthMode - indicate the authentication mode
18980 + WepStatus - indicate the encryption type
18981 + apidx - indicate the interface index
18982 +
18983 + Return Value:
18984 +
18985 + Note:
18986 +
18987 + ========================================================================
18988 +*/
18989 +VOID RTMPMakeRSNIE(
18990 + IN PRTMP_ADAPTER pAd,
18991 + IN UINT AuthMode,
18992 + IN UINT WepStatus,
18993 + IN UCHAR apidx)
18994 +{
18995 + PUCHAR pRsnIe = NULL; // primary RSNIE
18996 + UCHAR *rsnielen_cur_p = 0; // the length of the primary RSNIE
18997 + UCHAR *rsnielen_ex_cur_p = 0; // the length of the secondary RSNIE
18998 + UCHAR PrimaryRsnie;
18999 + BOOLEAN bMixCipher = FALSE; // indicate the pairwise and group cipher are different
19000 + UCHAR p_offset;
19001 + WPA_MIX_PAIR_CIPHER FlexibleCipher = MIX_CIPHER_NOTUSE; // it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode
19002 +
19003 + rsnielen_cur_p = NULL;
19004 + rsnielen_ex_cur_p = NULL;
19005 +
19006 + {
19007 +#ifdef CONFIG_STA_SUPPORT
19008 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
19009 + {
19010 +#ifdef WPA_SUPPLICANT_SUPPORT
19011 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
19012 + {
19013 + if (AuthMode < Ndis802_11AuthModeWPA)
19014 + return;
19015 + }
19016 + else
19017 +#endif // WPA_SUPPLICANT_SUPPORT //
19018 + {
19019 + // Support WPAPSK or WPA2PSK in STA-Infra mode
19020 + // Support WPANone in STA-Adhoc mode
19021 + if ((AuthMode != Ndis802_11AuthModeWPAPSK) &&
19022 + (AuthMode != Ndis802_11AuthModeWPA2PSK) &&
19023 + (AuthMode != Ndis802_11AuthModeWPANone)
19024 + )
19025 + return;
19026 + }
19027 +
19028 + DBGPRINT(RT_DEBUG_TRACE,("==> RTMPMakeRSNIE(STA)\n"));
19029 +
19030 + // Zero RSNIE context
19031 + pAd->StaCfg.RSNIE_Len = 0;
19032 + NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE);
19033 +
19034 + // Pointer to RSNIE
19035 + rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len;
19036 + pRsnIe = pAd->StaCfg.RSN_IE;
19037 +
19038 + bMixCipher = pAd->StaCfg.bMixCipher;
19039 + }
19040 +#endif // CONFIG_STA_SUPPORT //
19041 + }
19042 +
19043 + // indicate primary RSNIE as WPA or WPA2
19044 + if ((AuthMode == Ndis802_11AuthModeWPA) ||
19045 + (AuthMode == Ndis802_11AuthModeWPAPSK) ||
19046 + (AuthMode == Ndis802_11AuthModeWPANone) ||
19047 + (AuthMode == Ndis802_11AuthModeWPA1WPA2) ||
19048 + (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK))
19049 + PrimaryRsnie = WpaIe;
19050 + else
19051 + PrimaryRsnie = Wpa2Ie;
19052 +
19053 + {
19054 + // Build the primary RSNIE
19055 + // 1. insert cipher suite
19056 + RTMPInsertRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, FlexibleCipher, pRsnIe, &p_offset);
19057 +
19058 + // 2. insert AKM
19059 + RTMPInsertRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, &p_offset);
19060 +
19061 + // 3. insert capability
19062 + RTMPInsertRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset);
19063 + }
19064 +
19065 + // 4. update the RSNIE length
19066 + *rsnielen_cur_p = p_offset;
19067 +
19068 + hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p));
19069 +
19070 +
19071 +}
19072 +
19073 +/*
19074 + ==========================================================================
19075 + Description:
19076 + Check whether the received frame is EAP frame.
19077 +
19078 + Arguments:
19079 + pAd - pointer to our pAdapter context
19080 + pEntry - pointer to active entry
19081 + pData - the received frame
19082 + DataByteCount - the received frame's length
19083 + FromWhichBSSID - indicate the interface index
19084 +
19085 + Return:
19086 + TRUE - This frame is EAP frame
19087 + FALSE - otherwise
19088 + ==========================================================================
19089 +*/
19090 +BOOLEAN RTMPCheckWPAframe(
19091 + IN PRTMP_ADAPTER pAd,
19092 + IN PMAC_TABLE_ENTRY pEntry,
19093 + IN PUCHAR pData,
19094 + IN ULONG DataByteCount,
19095 + IN UCHAR FromWhichBSSID)
19096 +{
19097 + ULONG Body_len;
19098 + BOOLEAN Cancelled;
19099 +
19100 +
19101 + if(DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H))
19102 + return FALSE;
19103 +
19104 +
19105 + // Skip LLC header
19106 + if (NdisEqualMemory(SNAP_802_1H, pData, 6) ||
19107 + // Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL
19108 + NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6))
19109 + {
19110 + pData += 6;
19111 + }
19112 + // Skip 2-bytes EAPoL type
19113 + if (NdisEqualMemory(EAPOL, pData, 2))
19114 + {
19115 + pData += 2;
19116 + }
19117 + else
19118 + return FALSE;
19119 +
19120 + switch (*(pData+1))
19121 + {
19122 + case EAPPacket:
19123 + Body_len = (*(pData+2)<<8) | (*(pData+3));
19124 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", Body_len));
19125 + break;
19126 + case EAPOLStart:
19127 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Start frame, TYPE = 1 \n"));
19128 + if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
19129 + {
19130 + DBGPRINT(RT_DEBUG_TRACE, ("Cancel the EnqueueEapolStartTimerRunning \n"));
19131 + RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
19132 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
19133 + }
19134 + break;
19135 + case EAPOLLogoff:
19136 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLLogoff frame, TYPE = 2 \n"));
19137 + break;
19138 + case EAPOLKey:
19139 + Body_len = (*(pData+2)<<8) | (*(pData+3));
19140 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", Body_len));
19141 + break;
19142 + case EAPOLASFAlert:
19143 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLASFAlert frame, TYPE = 4 \n"));
19144 + break;
19145 + default:
19146 + return FALSE;
19147 +
19148 + }
19149 + return TRUE;
19150 +}
19151 +
19152 +
19153 +/*
19154 + ==========================================================================
19155 + Description:
19156 + ENCRYPT AES GTK before sending in EAPOL frame.
19157 + AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function.
19158 + This function references to RFC 3394 for aes key wrap algorithm.
19159 + Return:
19160 + ==========================================================================
19161 +*/
19162 +VOID AES_GTK_KEY_WRAP(
19163 + IN UCHAR *key,
19164 + IN UCHAR *plaintext,
19165 + IN UCHAR p_len,
19166 + OUT UCHAR *ciphertext)
19167 +{
19168 + UCHAR A[8], BIN[16], BOUT[16];
19169 + UCHAR R[512];
19170 + INT num_blocks = p_len/8; // unit:64bits
19171 + INT i, j;
19172 + aes_context aesctx;
19173 + UCHAR xor;
19174 +
19175 + rtmp_aes_set_key(&aesctx, key, 128);
19176 +
19177 + // Init IA
19178 + for (i = 0; i < 8; i++)
19179 + A[i] = 0xa6;
19180 +
19181 + //Input plaintext
19182 + for (i = 0; i < num_blocks; i++)
19183 + {
19184 + for (j = 0 ; j < 8; j++)
19185 + R[8 * (i + 1) + j] = plaintext[8 * i + j];
19186 + }
19187 +
19188 + // Key Mix
19189 + for (j = 0; j < 6; j++)
19190 + {
19191 + for(i = 1; i <= num_blocks; i++)
19192 + {
19193 + //phase 1
19194 + NdisMoveMemory(BIN, A, 8);
19195 + NdisMoveMemory(&BIN[8], &R[8 * i], 8);
19196 + rtmp_aes_encrypt(&aesctx, BIN, BOUT);
19197 +
19198 + NdisMoveMemory(A, &BOUT[0], 8);
19199 + xor = num_blocks * j + i;
19200 + A[7] = BOUT[7] ^ xor;
19201 + NdisMoveMemory(&R[8 * i], &BOUT[8], 8);
19202 + }
19203 + }
19204 +
19205 + // Output ciphertext
19206 + NdisMoveMemory(ciphertext, A, 8);
19207 +
19208 + for (i = 1; i <= num_blocks; i++)
19209 + {
19210 + for (j = 0 ; j < 8; j++)
19211 + ciphertext[8 * i + j] = R[8 * i + j];
19212 + }
19213 +}
19214 +
19215 +
19216 +/*
19217 + ========================================================================
19218 +
19219 + Routine Description:
19220 + Misc function to decrypt AES body
19221 +
19222 + Arguments:
19223 +
19224 + Return Value:
19225 +
19226 + Note:
19227 + This function references to RFC 3394 for aes key unwrap algorithm.
19228 +
19229 + ========================================================================
19230 +*/
19231 +VOID AES_GTK_KEY_UNWRAP(
19232 + IN UCHAR *key,
19233 + OUT UCHAR *plaintext,
19234 + IN UCHAR c_len,
19235 + IN UCHAR *ciphertext)
19236 +
19237 +{
19238 + UCHAR A[8], BIN[16], BOUT[16];
19239 + UCHAR xor;
19240 + INT i, j;
19241 + aes_context aesctx;
19242 + UCHAR *R;
19243 + INT num_blocks = c_len/8; // unit:64bits
19244 +
19245 +
19246 + os_alloc_mem(NULL, (PUCHAR *)&R, 512);
19247 +
19248 + if (R == NULL)
19249 + {
19250 + DBGPRINT(RT_DEBUG_ERROR, ("!!!AES_GTK_KEY_UNWRAP: no memory!!!\n"));
19251 + return;
19252 + } /* End of if */
19253 +
19254 + // Initialize
19255 + NdisMoveMemory(A, ciphertext, 8);
19256 + //Input plaintext
19257 + for(i = 0; i < (c_len-8); i++)
19258 + {
19259 + R[ i] = ciphertext[i + 8];
19260 + }
19261 +
19262 + rtmp_aes_set_key(&aesctx, key, 128);
19263 +
19264 + for(j = 5; j >= 0; j--)
19265 + {
19266 + for(i = (num_blocks-1); i > 0; i--)
19267 + {
19268 + xor = (num_blocks -1 )* j + i;
19269 + NdisMoveMemory(BIN, A, 8);
19270 + BIN[7] = A[7] ^ xor;
19271 + NdisMoveMemory(&BIN[8], &R[(i-1)*8], 8);
19272 + rtmp_aes_decrypt(&aesctx, BIN, BOUT);
19273 + NdisMoveMemory(A, &BOUT[0], 8);
19274 + NdisMoveMemory(&R[(i-1)*8], &BOUT[8], 8);
19275 + }
19276 + }
19277 +
19278 + // OUTPUT
19279 + for(i = 0; i < c_len; i++)
19280 + {
19281 + plaintext[i] = R[i];
19282 + }
19283 +
19284 +
19285 + os_free_mem(NULL, R);
19286 +}
19287 +
19288 +/*
19289 + ==========================================================================
19290 + Description:
19291 + Report the EAP message type
19292 +
19293 + Arguments:
19294 + msg - EAPOL_PAIR_MSG_1
19295 + EAPOL_PAIR_MSG_2
19296 + EAPOL_PAIR_MSG_3
19297 + EAPOL_PAIR_MSG_4
19298 + EAPOL_GROUP_MSG_1
19299 + EAPOL_GROUP_MSG_2
19300 +
19301 + Return:
19302 + message type string
19303 +
19304 + ==========================================================================
19305 +*/
19306 +CHAR *GetEapolMsgType(CHAR msg)
19307 +{
19308 + if(msg == EAPOL_PAIR_MSG_1)
19309 + return "Pairwise Message 1";
19310 + else if(msg == EAPOL_PAIR_MSG_2)
19311 + return "Pairwise Message 2";
19312 + else if(msg == EAPOL_PAIR_MSG_3)
19313 + return "Pairwise Message 3";
19314 + else if(msg == EAPOL_PAIR_MSG_4)
19315 + return "Pairwise Message 4";
19316 + else if(msg == EAPOL_GROUP_MSG_1)
19317 + return "Group Message 1";
19318 + else if(msg == EAPOL_GROUP_MSG_2)
19319 + return "Group Message 2";
19320 + else
19321 + return "Invalid Message";
19322 +}
19323 +
19324 +
19325 +/*
19326 + ========================================================================
19327 +
19328 + Routine Description:
19329 + Check Sanity RSN IE of EAPoL message
19330 +
19331 + Arguments:
19332 +
19333 + Return Value:
19334 +
19335 +
19336 + ========================================================================
19337 +*/
19338 +BOOLEAN RTMPCheckRSNIE(
19339 + IN PRTMP_ADAPTER pAd,
19340 + IN PUCHAR pData,
19341 + IN UCHAR DataLen,
19342 + IN MAC_TABLE_ENTRY *pEntry,
19343 + OUT UCHAR *Offset)
19344 +{
19345 + PUCHAR pVIE;
19346 + UCHAR len;
19347 + PEID_STRUCT pEid;
19348 + BOOLEAN result = FALSE;
19349 +
19350 + pVIE = pData;
19351 + len = DataLen;
19352 + *Offset = 0;
19353 +
19354 + while (len > sizeof(RSNIE2))
19355 + {
19356 + pEid = (PEID_STRUCT) pVIE;
19357 + // WPA RSN IE
19358 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
19359 + {
19360 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) &&
19361 + (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
19362 + (pEntry->RSNIE_Len == (pEid->Len + 2)))
19363 + {
19364 + result = TRUE;
19365 + }
19366 +
19367 + *Offset += (pEid->Len + 2);
19368 + }
19369 + // WPA2 RSN IE
19370 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
19371 + {
19372 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) &&
19373 + (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
19374 + (pEntry->RSNIE_Len == (pEid->Len + 2))/* ToDo-AlbertY for mesh*/)
19375 + {
19376 + result = TRUE;
19377 + }
19378 +
19379 + *Offset += (pEid->Len + 2);
19380 + }
19381 + else
19382 + {
19383 + break;
19384 + }
19385 +
19386 + pVIE += (pEid->Len + 2);
19387 + len -= (pEid->Len + 2);
19388 + }
19389 +
19390 +
19391 + return result;
19392 +
19393 +}
19394 +
19395 +
19396 +/*
19397 + ========================================================================
19398 +
19399 + Routine Description:
19400 + Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
19401 + GTK is encaptulated in KDE format at p.83 802.11i D10
19402 +
19403 + Arguments:
19404 +
19405 + Return Value:
19406 +
19407 + Note:
19408 + 802.11i D10
19409 +
19410 + ========================================================================
19411 +*/
19412 +BOOLEAN RTMPParseEapolKeyData(
19413 + IN PRTMP_ADAPTER pAd,
19414 + IN PUCHAR pKeyData,
19415 + IN UCHAR KeyDataLen,
19416 + IN UCHAR GroupKeyIndex,
19417 + IN UCHAR MsgType,
19418 + IN BOOLEAN bWPA2,
19419 + IN MAC_TABLE_ENTRY *pEntry)
19420 +{
19421 + PKDE_ENCAP pKDE = NULL;
19422 + PUCHAR pMyKeyData = pKeyData;
19423 + UCHAR KeyDataLength = KeyDataLen;
19424 + UCHAR GTKLEN = 0;
19425 + UCHAR DefaultIdx = 0;
19426 + UCHAR skip_offset;
19427 +
19428 + // Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it
19429 + if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3)
19430 + {
19431 + // Check RSN IE whether it is WPA2/WPA2PSK
19432 + if (!RTMPCheckRSNIE(pAd, pKeyData, KeyDataLen, pEntry, &skip_offset))
19433 + {
19434 + // send wireless event - for RSN IE different
19435 + if (pAd->CommonCfg.bWirelessEvent)
19436 + RTMPSendWirelessEvent(pAd, IW_RSNIE_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
19437 +
19438 + DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in msg %d of 4-way handshake!\n", MsgType));
19439 + hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen);
19440 + hex_dump("Desired RSN_IE ", pEntry->RSN_IE, pEntry->RSNIE_Len);
19441 +
19442 + return FALSE;
19443 + }
19444 + else
19445 + {
19446 + if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3)
19447 + {
19448 + // skip RSN IE
19449 + pMyKeyData += skip_offset;
19450 + KeyDataLength -= skip_offset;
19451 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
19452 + }
19453 + else
19454 + return TRUE;
19455 + }
19456 + }
19457 +
19458 + DBGPRINT(RT_DEBUG_TRACE,("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
19459 +
19460 + // Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2
19461 + if (bWPA2 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1))
19462 + {
19463 + if (KeyDataLength >= 8) // KDE format exclude GTK length
19464 + {
19465 + pKDE = (PKDE_ENCAP) pMyKeyData;
19466 +
19467 +
19468 + DefaultIdx = pKDE->GTKEncap.Kid;
19469 +
19470 + // Sanity check - KED length
19471 + if (KeyDataLength < (pKDE->Len + 2))
19472 + {
19473 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
19474 + return FALSE;
19475 + }
19476 +
19477 + // Get GTK length - refer to IEEE 802.11i-2004 p.82
19478 + GTKLEN = pKDE->Len -6;
19479 + if (GTKLEN < LEN_AES_KEY)
19480 + {
19481 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
19482 + return FALSE;
19483 + }
19484 +
19485 + }
19486 + else
19487 + {
19488 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KDE format length is too short \n"));
19489 + return FALSE;
19490 + }
19491 +
19492 + DBGPRINT(RT_DEBUG_TRACE, ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", DefaultIdx, GTKLEN));
19493 + // skip it
19494 + pMyKeyData += 8;
19495 + KeyDataLength -= 8;
19496 +
19497 + }
19498 + else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1)
19499 + {
19500 + DefaultIdx = GroupKeyIndex;
19501 + DBGPRINT(RT_DEBUG_TRACE, ("GTK DefaultKeyID=%d \n", DefaultIdx));
19502 + }
19503 +
19504 + // Sanity check - shared key index must be 1 ~ 3
19505 + if (DefaultIdx < 1 || DefaultIdx > 3)
19506 + {
19507 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index(%d) is invalid in %s %s \n", DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
19508 + return FALSE;
19509 + }
19510 +
19511 +
19512 +#ifdef CONFIG_STA_SUPPORT
19513 + // Todo
19514 +#endif // CONFIG_STA_SUPPORT //
19515 +
19516 + return TRUE;
19517 +
19518 +}
19519 +
19520 +
19521 +/*
19522 + ========================================================================
19523 +
19524 + Routine Description:
19525 + Construct EAPoL message for WPA handshaking
19526 + Its format is below,
19527 +
19528 + +--------------------+
19529 + | Protocol Version | 1 octet
19530 + +--------------------+
19531 + | Protocol Type | 1 octet
19532 + +--------------------+
19533 + | Body Length | 2 octets
19534 + +--------------------+
19535 + | Descriptor Type | 1 octet
19536 + +--------------------+
19537 + | Key Information | 2 octets
19538 + +--------------------+
19539 + | Key Length | 1 octet
19540 + +--------------------+
19541 + | Key Repaly Counter | 8 octets
19542 + +--------------------+
19543 + | Key Nonce | 32 octets
19544 + +--------------------+
19545 + | Key IV | 16 octets
19546 + +--------------------+
19547 + | Key RSC | 8 octets
19548 + +--------------------+
19549 + | Key ID or Reserved | 8 octets
19550 + +--------------------+
19551 + | Key MIC | 16 octets
19552 + +--------------------+
19553 + | Key Data Length | 2 octets
19554 + +--------------------+
19555 + | Key Data | n octets
19556 + +--------------------+
19557 +
19558 +
19559 + Arguments:
19560 + pAd Pointer to our adapter
19561 +
19562 + Return Value:
19563 + None
19564 +
19565 + Note:
19566 +
19567 + ========================================================================
19568 +*/
19569 +VOID ConstructEapolMsg(
19570 + IN PRTMP_ADAPTER pAd,
19571 + IN UCHAR AuthMode,
19572 + IN UCHAR WepStatus,
19573 + IN UCHAR GroupKeyWepStatus,
19574 + IN UCHAR MsgType,
19575 + IN UCHAR DefaultKeyIdx,
19576 + IN UCHAR *ReplayCounter,
19577 + IN UCHAR *KeyNonce,
19578 + IN UCHAR *TxRSC,
19579 + IN UCHAR *PTK,
19580 + IN UCHAR *GTK,
19581 + IN UCHAR *RSNIE,
19582 + IN UCHAR RSNIE_Len,
19583 + OUT PEAPOL_PACKET pMsg)
19584 +{
19585 + BOOLEAN bWPA2 = FALSE;
19586 +
19587 + // Choose WPA2 or not
19588 + if ((AuthMode == Ndis802_11AuthModeWPA2) || (AuthMode == Ndis802_11AuthModeWPA2PSK))
19589 + bWPA2 = TRUE;
19590 +
19591 + // Init Packet and Fill header
19592 + pMsg->ProVer = EAPOL_VER;
19593 + pMsg->ProType = EAPOLKey;
19594 +
19595 + // Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field
19596 + pMsg->Body_Len[1] = LEN_EAPOL_KEY_MSG;
19597 +
19598 + // Fill in EAPoL descriptor
19599 + if (bWPA2)
19600 + pMsg->KeyDesc.Type = WPA2_KEY_DESC;
19601 + else
19602 + pMsg->KeyDesc.Type = WPA1_KEY_DESC;
19603 +
19604 + // Fill in Key information, refer to IEEE Std 802.11i-2004 page 78
19605 + // When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used.
19606 + pMsg->KeyDesc.KeyInfo.KeyDescVer =
19607 + (((WepStatus == Ndis802_11Encryption3Enabled) || (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
19608 +
19609 + // Specify Key Type as Group(0) or Pairwise(1)
19610 + if (MsgType >= EAPOL_GROUP_MSG_1)
19611 + pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY;
19612 + else
19613 + pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
19614 +
19615 + // Specify Key Index, only group_msg1_WPA1
19616 + if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))
19617 + pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx;
19618 +
19619 + if (MsgType == EAPOL_PAIR_MSG_3)
19620 + pMsg->KeyDesc.KeyInfo.Install = 1;
19621 +
19622 + if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))
19623 + pMsg->KeyDesc.KeyInfo.KeyAck = 1;
19624 +
19625 + if (MsgType != EAPOL_PAIR_MSG_1)
19626 + pMsg->KeyDesc.KeyInfo.KeyMic = 1;
19627 +
19628 + if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)))
19629 + {
19630 + pMsg->KeyDesc.KeyInfo.Secure = 1;
19631 + }
19632 +
19633 + if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
19634 + {
19635 + pMsg->KeyDesc.KeyInfo.EKD_DL = 1;
19636 + }
19637 +
19638 + // key Information element has done.
19639 + *(USHORT *)(&pMsg->KeyDesc.KeyInfo) = cpu2le16(*(USHORT *)(&pMsg->KeyDesc.KeyInfo));
19640 +
19641 + // Fill in Key Length
19642 +#if 0
19643 + if (bWPA2)
19644 + {
19645 + // In WPA2 mode, the field indicates the length of pairwise key cipher,
19646 + // so only pairwise_msg_1 and pairwise_msg_3 need to fill.
19647 + if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3))
19648 + pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
19649 + }
19650 + else if (!bWPA2)
19651 +#endif
19652 + {
19653 + if (MsgType >= EAPOL_GROUP_MSG_1)
19654 + {
19655 + // the length of group key cipher
19656 + pMsg->KeyDesc.KeyLength[1] = ((GroupKeyWepStatus == Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : LEN_AES_KEY);
19657 + }
19658 + else
19659 + {
19660 + // the length of pairwise key cipher
19661 + pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
19662 + }
19663 + }
19664 +
19665 + // Fill in replay counter
19666 + NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, ReplayCounter, LEN_KEY_DESC_REPLAY);
19667 +
19668 + // Fill Key Nonce field
19669 + // ANonce : pairwise_msg1 & pairwise_msg3
19670 + // SNonce : pairwise_msg2
19671 + // GNonce : group_msg1_wpa1
19672 + if ((MsgType <= EAPOL_PAIR_MSG_3) || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))))
19673 + NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, LEN_KEY_DESC_NONCE);
19674 +
19675 + // Fill key IV - WPA2 as 0, WPA1 as random
19676 + if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
19677 + {
19678 + // Suggest IV be random number plus some number,
19679 + NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], LEN_KEY_DESC_IV);
19680 + pMsg->KeyDesc.KeyIv[15] += 2;
19681 + }
19682 +
19683 + // Fill Key RSC field
19684 + // It contains the RSC for the GTK being installed.
19685 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
19686 + {
19687 + NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6);
19688 + }
19689 +
19690 + // Clear Key MIC field for MIC calculation later
19691 + NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
19692 +
19693 + ConstructEapolKeyData(pAd,
19694 + AuthMode,
19695 + WepStatus,
19696 + GroupKeyWepStatus,
19697 + MsgType,
19698 + DefaultKeyIdx,
19699 + bWPA2,
19700 + PTK,
19701 + GTK,
19702 + RSNIE,
19703 + RSNIE_Len,
19704 + pMsg);
19705 +
19706 + // Calculate MIC and fill in KeyMic Field except Pairwise Msg 1.
19707 + if (MsgType != EAPOL_PAIR_MSG_1)
19708 + {
19709 + CalculateMIC(pAd, WepStatus, PTK, pMsg);
19710 + }
19711 +
19712 + DBGPRINT(RT_DEBUG_TRACE, ("===> ConstructEapolMsg for %s %s\n", ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
19713 + DBGPRINT(RT_DEBUG_TRACE, (" Body length = %d \n", pMsg->Body_Len[1]));
19714 + DBGPRINT(RT_DEBUG_TRACE, (" Key length = %d \n", pMsg->KeyDesc.KeyLength[1]));
19715 +
19716 +
19717 +}
19718 +
19719 +/*
19720 + ========================================================================
19721 +
19722 + Routine Description:
19723 + Construct the Key Data field of EAPoL message
19724 +
19725 + Arguments:
19726 + pAd Pointer to our adapter
19727 + Elem Message body
19728 +
19729 + Return Value:
19730 + None
19731 +
19732 + Note:
19733 +
19734 + ========================================================================
19735 +*/
19736 +VOID ConstructEapolKeyData(
19737 + IN PRTMP_ADAPTER pAd,
19738 + IN UCHAR AuthMode,
19739 + IN UCHAR WepStatus,
19740 + IN UCHAR GroupKeyWepStatus,
19741 + IN UCHAR MsgType,
19742 + IN UCHAR DefaultKeyIdx,
19743 + IN BOOLEAN bWPA2Capable,
19744 + IN UCHAR *PTK,
19745 + IN UCHAR *GTK,
19746 + IN UCHAR *RSNIE,
19747 + IN UCHAR RSNIE_LEN,
19748 + OUT PEAPOL_PACKET pMsg)
19749 +{
19750 + UCHAR *mpool, *Key_Data, *Rc4GTK;
19751 + UCHAR ekey[(LEN_KEY_DESC_IV+LEN_EAP_EK)];
19752 + UCHAR data_offset;
19753 +
19754 +
19755 + if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2)
19756 + return;
19757 +
19758 + // allocate memory pool
19759 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1500);
19760 +
19761 + if (mpool == NULL)
19762 + return;
19763 +
19764 + /* Rc4GTK Len = 512 */
19765 + Rc4GTK = (UCHAR *) ROUND_UP(mpool, 4);
19766 + /* Key_Data Len = 512 */
19767 + Key_Data = (UCHAR *) ROUND_UP(Rc4GTK + 512, 4);
19768 +
19769 + NdisZeroMemory(Key_Data, 512);
19770 + pMsg->KeyDesc.KeyDataLen[1] = 0;
19771 + data_offset = 0;
19772 +
19773 + // Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3
19774 + if (RSNIE_LEN && ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3)))
19775 + {
19776 + if (bWPA2Capable)
19777 + Key_Data[data_offset + 0] = IE_WPA2;
19778 + else
19779 + Key_Data[data_offset + 0] = IE_WPA;
19780 +
19781 + Key_Data[data_offset + 1] = RSNIE_LEN;
19782 + NdisMoveMemory(&Key_Data[data_offset + 2], RSNIE, RSNIE_LEN);
19783 + data_offset += (2 + RSNIE_LEN);
19784 + }
19785 +
19786 + // Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2
19787 + if (bWPA2Capable && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
19788 + {
19789 + // Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h
19790 + Key_Data[data_offset + 0] = 0xDD;
19791 +
19792 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19793 + {
19794 + Key_Data[data_offset + 1] = 0x16;// 4+2+16(OUI+DataType+DataField)
19795 + }
19796 + else
19797 + {
19798 + Key_Data[data_offset + 1] = 0x26;// 4+2+32(OUI+DataType+DataField)
19799 + }
19800 +
19801 + Key_Data[data_offset + 2] = 0x00;
19802 + Key_Data[data_offset + 3] = 0x0F;
19803 + Key_Data[data_offset + 4] = 0xAC;
19804 + Key_Data[data_offset + 5] = 0x01;
19805 +
19806 + // GTK KDE format - 802.11i-2004 Figure-43x
19807 + Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03);
19808 + Key_Data[data_offset + 7] = 0x00; // Reserved Byte
19809 +
19810 + data_offset += 8;
19811 + }
19812 +
19813 +
19814 + // Encapsulate GTK and encrypt the key-data field with KEK.
19815 + // Only for pairwise_msg3_WPA2 and group_msg1
19816 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) || (MsgType == EAPOL_GROUP_MSG_1))
19817 + {
19818 + // Fill in GTK
19819 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19820 + {
19821 + NdisMoveMemory(&Key_Data[data_offset], GTK, LEN_AES_KEY);
19822 + data_offset += LEN_AES_KEY;
19823 + }
19824 + else
19825 + {
19826 + NdisMoveMemory(&Key_Data[data_offset], GTK, TKIP_GTK_LENGTH);
19827 + data_offset += TKIP_GTK_LENGTH;
19828 + }
19829 +
19830 + // Still dont know why, but if not append will occur "GTK not include in MSG3"
19831 + // Patch for compatibility between zero config and funk
19832 + if (MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable)
19833 + {
19834 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19835 + {
19836 + Key_Data[data_offset + 0] = 0xDD;
19837 + Key_Data[data_offset + 1] = 0;
19838 + data_offset += 2;
19839 + }
19840 + else
19841 + {
19842 + Key_Data[data_offset + 0] = 0xDD;
19843 + Key_Data[data_offset + 1] = 0;
19844 + Key_Data[data_offset + 2] = 0;
19845 + Key_Data[data_offset + 3] = 0;
19846 + Key_Data[data_offset + 4] = 0;
19847 + Key_Data[data_offset + 5] = 0;
19848 + data_offset += 6;
19849 + }
19850 + }
19851 +
19852 + // Encrypt the data material in key data field
19853 + if (WepStatus == Ndis802_11Encryption3Enabled)
19854 + {
19855 + AES_GTK_KEY_WRAP(&PTK[16], Key_Data, data_offset, Rc4GTK);
19856 + // AES wrap function will grow 8 bytes in length
19857 + data_offset += 8;
19858 + }
19859 + else
19860 + {
19861 + // PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV)
19862 + // put TxTsc in Key RSC field
19863 + pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32.
19864 +
19865 + // ekey is the contanetion of IV-field, and PTK[16]->PTK[31]
19866 + NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, LEN_KEY_DESC_IV);
19867 + NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &PTK[16], LEN_EAP_EK);
19868 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); //INIT SBOX, KEYLEN+3(IV)
19869 + pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, data_offset);
19870 + WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, Key_Data, data_offset);
19871 + }
19872 +
19873 + NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset);
19874 + }
19875 + else
19876 + {
19877 + NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset);
19878 + }
19879 +
19880 + // set key data length field and total length
19881 + pMsg->KeyDesc.KeyDataLen[1] = data_offset;
19882 + pMsg->Body_Len[1] += data_offset;
19883 +
19884 + os_free_mem(pAd, mpool);
19885 +
19886 +}
19887 +
19888 +/*
19889 + ========================================================================
19890 +
19891 + Routine Description:
19892 + Calcaulate MIC. It is used during 4-ways handsharking.
19893 +
19894 + Arguments:
19895 + pAd - pointer to our pAdapter context
19896 + PeerWepStatus - indicate the encryption type
19897 +
19898 + Return Value:
19899 +
19900 + Note:
19901 +
19902 + ========================================================================
19903 +*/
19904 +VOID CalculateMIC(
19905 + IN PRTMP_ADAPTER pAd,
19906 + IN UCHAR PeerWepStatus,
19907 + IN UCHAR *PTK,
19908 + OUT PEAPOL_PACKET pMsg)
19909 +{
19910 + UCHAR *OutBuffer;
19911 + ULONG FrameLen = 0;
19912 + UCHAR mic[LEN_KEY_DESC_MIC];
19913 + UCHAR digest[80];
19914 +
19915 + // allocate memory for MIC calculation
19916 + os_alloc_mem(pAd, (PUCHAR *)&OutBuffer, 512);
19917 +
19918 + if (OutBuffer == NULL)
19919 + {
19920 + DBGPRINT(RT_DEBUG_ERROR, ("!!!CalculateMIC: no memory!!!\n"));
19921 + return;
19922 + }
19923 +
19924 + // make a frame for calculating MIC.
19925 + MakeOutgoingFrame(OutBuffer, &FrameLen,
19926 + pMsg->Body_Len[1] + 4, pMsg,
19927 + END_OF_ARGS);
19928 +
19929 + NdisZeroMemory(mic, sizeof(mic));
19930 +
19931 + // Calculate MIC
19932 + if (PeerWepStatus == Ndis802_11Encryption3Enabled)
19933 + {
19934 + HMAC_SHA1(OutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
19935 + NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
19936 + }
19937 + else
19938 + {
19939 + hmac_md5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic);
19940 + }
19941 +
19942 + // store the calculated MIC
19943 + NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC);
19944 +
19945 + os_free_mem(pAd, OutBuffer);
19946 +}
19947 +
19948 +/*
19949 + ========================================================================
19950 +
19951 + Routine Description:
19952 + Some received frames can't decrypt by Asic, so decrypt them by software.
19953 +
19954 + Arguments:
19955 + pAd - pointer to our pAdapter context
19956 + PeerWepStatus - indicate the encryption type
19957 +
19958 + Return Value:
19959 + NDIS_STATUS_SUCCESS - decryption successful
19960 + NDIS_STATUS_FAILURE - decryption failure
19961 +
19962 + ========================================================================
19963 +*/
19964 +NDIS_STATUS RTMPSoftDecryptBroadCastData(
19965 + IN PRTMP_ADAPTER pAd,
19966 + IN RX_BLK *pRxBlk,
19967 + IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
19968 + IN PCIPHER_KEY pShard_key)
19969 +{
19970 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
19971 +
19972 +
19973 +
19974 + // handle WEP decryption
19975 + if (GroupCipher == Ndis802_11Encryption1Enabled)
19976 + {
19977 + if (RTMPSoftDecryptWEP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, pShard_key))
19978 + {
19979 +
19980 + //Minus IV[4] & ICV[4]
19981 + pRxWI->MPDUtotalByteCount -= 8;
19982 + }
19983 + else
19984 + {
19985 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : Software decrypt WEP data fails.\n"));
19986 + // give up this frame
19987 + return NDIS_STATUS_FAILURE;
19988 + }
19989 + }
19990 + // handle TKIP decryption
19991 + else if (GroupCipher == Ndis802_11Encryption2Enabled)
19992 + {
19993 + if (RTMPSoftDecryptTKIP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, pShard_key))
19994 + {
19995 +
19996 + //Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV
19997 + pRxWI->MPDUtotalByteCount -= 20;
19998 + }
19999 + else
20000 + {
20001 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptTKIP Failed\n"));
20002 + // give up this frame
20003 + return NDIS_STATUS_FAILURE;
20004 + }
20005 + }
20006 + // handle AES decryption
20007 + else if (GroupCipher == Ndis802_11Encryption3Enabled)
20008 + {
20009 + if (RTMPSoftDecryptAES(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount , pShard_key))
20010 + {
20011 +
20012 + //8 bytes MIC, 8 bytes IV/EIV (CCMP Header)
20013 + pRxWI->MPDUtotalByteCount -= 16;
20014 + }
20015 + else
20016 + {
20017 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptAES Failed\n"));
20018 + // give up this frame
20019 + return NDIS_STATUS_FAILURE;
20020 + }
20021 + }
20022 + else
20023 + {
20024 + // give up this frame
20025 + return NDIS_STATUS_FAILURE;
20026 + }
20027 +
20028 + return NDIS_STATUS_SUCCESS;
20029 +
20030 +}
20031 +
20032 --- /dev/null
20033 +++ b/drivers/staging/rt2870/common/dfs.c
20034 @@ -0,0 +1,453 @@
20035 +/*
20036 + *************************************************************************
20037 + * Ralink Tech Inc.
20038 + * 5F., No.36, Taiyuan St., Jhubei City,
20039 + * Hsinchu County 302,
20040 + * Taiwan, R.O.C.
20041 + *
20042 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
20043 + *
20044 + * This program is free software; you can redistribute it and/or modify *
20045 + * it under the terms of the GNU General Public License as published by *
20046 + * the Free Software Foundation; either version 2 of the License, or *
20047 + * (at your option) any later version. *
20048 + * *
20049 + * This program is distributed in the hope that it will be useful, *
20050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20052 + * GNU General Public License for more details. *
20053 + * *
20054 + * You should have received a copy of the GNU General Public License *
20055 + * along with this program; if not, write to the *
20056 + * Free Software Foundation, Inc., *
20057 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20058 + * *
20059 + *************************************************************************
20060 +
20061 + Module Name:
20062 + ap_dfs.c
20063 +
20064 + Abstract:
20065 + Support DFS function.
20066 +
20067 + Revision History:
20068 + Who When What
20069 + -------- ---------- ----------------------------------------------
20070 + Fonchi 03-12-2007 created
20071 +*/
20072 +
20073 +#include "../rt_config.h"
20074 +
20075 +typedef struct _RADAR_DURATION_TABLE
20076 +{
20077 + ULONG RDDurRegion;
20078 + ULONG RadarSignalDuration;
20079 + ULONG Tolerance;
20080 +} RADAR_DURATION_TABLE, *PRADAR_DURATION_TABLE;
20081 +
20082 +
20083 +static UCHAR RdIdleTimeTable[MAX_RD_REGION][4] =
20084 +{
20085 + {9, 250, 250, 250}, // CE
20086 + {4, 250, 250, 250}, // FCC
20087 + {4, 250, 250, 250}, // JAP
20088 + {15, 250, 250, 250}, // JAP_W53
20089 + {4, 250, 250, 250} // JAP_W56
20090 +};
20091 +
20092 +/*
20093 + ========================================================================
20094 +
20095 + Routine Description:
20096 + Bbp Radar detection routine
20097 +
20098 + Arguments:
20099 + pAd Pointer to our adapter
20100 +
20101 + Return Value:
20102 +
20103 + ========================================================================
20104 +*/
20105 +VOID BbpRadarDetectionStart(
20106 + IN PRTMP_ADAPTER pAd)
20107 +{
20108 + UINT8 RadarPeriod;
20109 +
20110 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 114, 0x02);
20111 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 121, 0x20);
20112 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 122, 0x00);
20113 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 123, 0x08/*0x80*/);
20114 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 124, 0x28);
20115 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 125, 0xff);
20116 +
20117 +#if 0
20118 + // toggle Rx enable bit for radar detection.
20119 + // it's Andy's recommand.
20120 + {
20121 + UINT32 Value;
20122 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
20123 + Value |= (0x1 << 3);
20124 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
20125 + Value &= ~(0x1 << 3);
20126 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
20127 + }
20128 +#endif
20129 + RadarPeriod = ((UINT)RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + (UINT)pAd->CommonCfg.RadarDetect.DfsSessionTime) < 250 ?
20130 + (RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + pAd->CommonCfg.RadarDetect.DfsSessionTime) : 250;
20131 +
20132 + RTMP_IO_WRITE8(pAd, 0x7020, 0x1d);
20133 + RTMP_IO_WRITE8(pAd, 0x7021, 0x40);
20134 +
20135 + RadarDetectionStart(pAd, 0, RadarPeriod);
20136 + return;
20137 +}
20138 +
20139 +/*
20140 + ========================================================================
20141 +
20142 + Routine Description:
20143 + Bbp Radar detection routine
20144 +
20145 + Arguments:
20146 + pAd Pointer to our adapter
20147 +
20148 + Return Value:
20149 +
20150 + ========================================================================
20151 +*/
20152 +VOID BbpRadarDetectionStop(
20153 + IN PRTMP_ADAPTER pAd)
20154 +{
20155 + RTMP_IO_WRITE8(pAd, 0x7020, 0x1d);
20156 + RTMP_IO_WRITE8(pAd, 0x7021, 0x60);
20157 +
20158 + RadarDetectionStop(pAd);
20159 + return;
20160 +}
20161 +
20162 +/*
20163 + ========================================================================
20164 +
20165 + Routine Description:
20166 + Radar detection routine
20167 +
20168 + Arguments:
20169 + pAd Pointer to our adapter
20170 +
20171 + Return Value:
20172 +
20173 + ========================================================================
20174 +*/
20175 +VOID RadarDetectionStart(
20176 + IN PRTMP_ADAPTER pAd,
20177 + IN BOOLEAN CTSProtect,
20178 + IN UINT8 CTSPeriod)
20179 +{
20180 + UINT8 DfsActiveTime = (pAd->CommonCfg.RadarDetect.DfsSessionTime & 0x1f);
20181 + UINT8 CtsProtect = (CTSProtect == 1) ? 0x02 : 0x01; // CTS protect.
20182 +
20183 + if (CTSProtect != 0)
20184 + {
20185 + switch(pAd->CommonCfg.RadarDetect.RDDurRegion)
20186 + {
20187 + case FCC:
20188 + case JAP_W56:
20189 + CtsProtect = 0x03;
20190 + break;
20191 +
20192 + case CE:
20193 + case JAP_W53:
20194 + default:
20195 + CtsProtect = 0x02;
20196 + break;
20197 + }
20198 + }
20199 + else
20200 + CtsProtect = 0x01;
20201 +
20202 +
20203 + // send start-RD with CTS protection command to MCU
20204 + // highbyte [7] reserve
20205 + // highbyte [6:5] 0x: stop Carrier/Radar detection
20206 + // highbyte [10]: Start Carrier/Radar detection without CTS protection, 11: Start Carrier/Radar detection with CTS protection
20207 + // highbyte [4:0] Radar/carrier detection duration. In 1ms.
20208 +
20209 + // lowbyte [7:0] Radar/carrier detection period, in 1ms.
20210 + AsicSendCommandToMcu(pAd, 0x60, 0xff, CTSPeriod, DfsActiveTime | (CtsProtect << 5));
20211 + //AsicSendCommandToMcu(pAd, 0x63, 0xff, 10, 0);
20212 +
20213 + return;
20214 +}
20215 +
20216 +/*
20217 + ========================================================================
20218 +
20219 + Routine Description:
20220 + Radar detection routine
20221 +
20222 + Arguments:
20223 + pAd Pointer to our adapter
20224 +
20225 + Return Value:
20226 + TRUE Found radar signal
20227 + FALSE Not found radar signal
20228 +
20229 + ========================================================================
20230 +*/
20231 +VOID RadarDetectionStop(
20232 + IN PRTMP_ADAPTER pAd)
20233 +{
20234 + DBGPRINT(RT_DEBUG_TRACE,("RadarDetectionStop.\n"));
20235 + AsicSendCommandToMcu(pAd, 0x60, 0xff, 0x00, 0x00); // send start-RD with CTS protection command to MCU
20236 +
20237 + return;
20238 +}
20239 +
20240 +/*
20241 + ========================================================================
20242 +
20243 + Routine Description:
20244 + Radar channel check routine
20245 +
20246 + Arguments:
20247 + pAd Pointer to our adapter
20248 +
20249 + Return Value:
20250 + TRUE need to do radar detect
20251 + FALSE need not to do radar detect
20252 +
20253 + ========================================================================
20254 +*/
20255 +BOOLEAN RadarChannelCheck(
20256 + IN PRTMP_ADAPTER pAd,
20257 + IN UCHAR Ch)
20258 +{
20259 +#if 1
20260 + INT i;
20261 + BOOLEAN result = FALSE;
20262 +
20263 + for (i=0; i<pAd->ChannelListNum; i++)
20264 + {
20265 + if (Ch == pAd->ChannelList[i].Channel)
20266 + {
20267 + result = pAd->ChannelList[i].DfsReq;
20268 + break;
20269 + }
20270 + }
20271 +
20272 + return result;
20273 +#else
20274 + INT i;
20275 + UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
20276 +
20277 + for (i=0; i<15; i++)
20278 + {
20279 + if (Ch == Channel[i])
20280 + {
20281 + break;
20282 + }
20283 + }
20284 +
20285 + if (i != 15)
20286 + return TRUE;
20287 + else
20288 + return FALSE;
20289 +#endif
20290 +}
20291 +
20292 +ULONG JapRadarType(
20293 + IN PRTMP_ADAPTER pAd)
20294 +{
20295 + ULONG i;
20296 + const UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
20297 +
20298 + if (pAd->CommonCfg.RadarDetect.RDDurRegion != JAP)
20299 + {
20300 + return pAd->CommonCfg.RadarDetect.RDDurRegion;
20301 + }
20302 +
20303 + for (i=0; i<15; i++)
20304 + {
20305 + if (pAd->CommonCfg.Channel == Channel[i])
20306 + {
20307 + break;
20308 + }
20309 + }
20310 +
20311 + if (i < 4)
20312 + return JAP_W53;
20313 + else if (i < 15)
20314 + return JAP_W56;
20315 + else
20316 + return JAP; // W52
20317 +
20318 +}
20319 +
20320 +ULONG RTMPBbpReadRadarDuration(
20321 + IN PRTMP_ADAPTER pAd)
20322 +{
20323 + UINT8 byteValue = 0;
20324 + ULONG result;
20325 +
20326 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R115, &byteValue);
20327 +
20328 + result = 0;
20329 + switch (byteValue)
20330 + {
20331 + case 1: // radar signal detected by pulse mode.
20332 + case 2: // radar signal detected by width mode.
20333 + result = RTMPReadRadarDuration(pAd);
20334 + break;
20335 +
20336 + case 0: // No radar signal.
20337 + default:
20338 +
20339 + result = 0;
20340 + break;
20341 + }
20342 +
20343 + return result;
20344 +}
20345 +
20346 +ULONG RTMPReadRadarDuration(
20347 + IN PRTMP_ADAPTER pAd)
20348 +{
20349 + ULONG result = 0;
20350 +
20351 +#ifdef DFS_SUPPORT
20352 + UINT8 duration1 = 0, duration2 = 0, duration3 = 0;
20353 +
20354 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R116, &duration1);
20355 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R117, &duration2);
20356 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R118, &duration3);
20357 + result = (duration1 << 16) + (duration2 << 8) + duration3;
20358 +#endif // DFS_SUPPORT //
20359 +
20360 + return result;
20361 +
20362 +}
20363 +
20364 +VOID RTMPCleanRadarDuration(
20365 + IN PRTMP_ADAPTER pAd)
20366 +{
20367 + return;
20368 +}
20369 +
20370 +/*
20371 + ========================================================================
20372 + Routine Description:
20373 + Radar wave detection. The API should be invoke each second.
20374 +
20375 + Arguments:
20376 + pAd - Adapter pointer
20377 +
20378 + Return Value:
20379 + None
20380 +
20381 + ========================================================================
20382 +*/
20383 +VOID ApRadarDetectPeriodic(
20384 + IN PRTMP_ADAPTER pAd)
20385 +{
20386 + INT i;
20387 +
20388 + pAd->CommonCfg.RadarDetect.InServiceMonitorCount++;
20389 +
20390 + for (i=0; i<pAd->ChannelListNum; i++)
20391 + {
20392 + if (pAd->ChannelList[i].RemainingTimeForUse > 0)
20393 + {
20394 + pAd->ChannelList[i].RemainingTimeForUse --;
20395 + if ((pAd->Mlme.PeriodicRound%5) == 0)
20396 + {
20397 + DBGPRINT(RT_DEBUG_TRACE, ("RadarDetectPeriodic - ch=%d, RemainingTimeForUse=%d\n", pAd->ChannelList[i].Channel, pAd->ChannelList[i].RemainingTimeForUse));
20398 + }
20399 + }
20400 + }
20401 +
20402 + //radar detect
20403 + if ((pAd->CommonCfg.Channel > 14)
20404 + && (pAd->CommonCfg.bIEEE80211H == 1)
20405 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
20406 + {
20407 + RadarDetectPeriodic(pAd);
20408 + }
20409 +
20410 + return;
20411 +}
20412 +
20413 +// Periodic Radar detection, switch channel will occur in RTMPHandleTBTTInterrupt()
20414 +// Before switch channel, driver needs doing channel switch announcement.
20415 +VOID RadarDetectPeriodic(
20416 + IN PRTMP_ADAPTER pAd)
20417 +{
20418 + // need to check channel availability, after switch channel
20419 + if (pAd->CommonCfg.RadarDetect.RDMode != RD_SILENCE_MODE)
20420 + return;
20421 +
20422 + // channel availability check time is 60sec, use 65 for assurance
20423 + if (pAd->CommonCfg.RadarDetect.RDCount++ > pAd->CommonCfg.RadarDetect.ChMovingTime)
20424 + {
20425 + DBGPRINT(RT_DEBUG_TRACE, ("Not found radar signal, start send beacon and radar detection in service monitor\n\n"));
20426 + BbpRadarDetectionStop(pAd);
20427 + AsicEnableBssSync(pAd);
20428 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
20429 +
20430 +
20431 + return;
20432 + }
20433 +
20434 + return;
20435 +}
20436 +
20437 +
20438 +/*
20439 + ==========================================================================
20440 + Description:
20441 + change channel moving time for DFS testing.
20442 +
20443 + Arguments:
20444 + pAdapter Pointer to our adapter
20445 + wrq Pointer to the ioctl argument
20446 +
20447 + Return Value:
20448 + None
20449 +
20450 + Note:
20451 + Usage:
20452 + 1.) iwpriv ra0 set ChMovTime=[value]
20453 + ==========================================================================
20454 +*/
20455 +INT Set_ChMovingTime_Proc(
20456 + IN PRTMP_ADAPTER pAd,
20457 + IN PUCHAR arg)
20458 +{
20459 + UINT8 Value;
20460 +
20461 + Value = simple_strtol(arg, 0, 10);
20462 +
20463 + pAd->CommonCfg.RadarDetect.ChMovingTime = Value;
20464 +
20465 + DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __FUNCTION__,
20466 + pAd->CommonCfg.RadarDetect.ChMovingTime));
20467 +
20468 + return TRUE;
20469 +}
20470 +
20471 +INT Set_LongPulseRadarTh_Proc(
20472 + IN PRTMP_ADAPTER pAd,
20473 + IN PUCHAR arg)
20474 +{
20475 + UINT8 Value;
20476 +
20477 + Value = simple_strtol(arg, 0, 10) > 10 ? 10 : simple_strtol(arg, 0, 10);
20478 +
20479 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh = Value;
20480 +
20481 + DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __FUNCTION__,
20482 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh));
20483 +
20484 + return TRUE;
20485 +}
20486 +
20487 +
20488 --- /dev/null
20489 +++ b/drivers/staging/rt2870/common/eeprom.c
20490 @@ -0,0 +1,254 @@
20491 +/*
20492 + *************************************************************************
20493 + * Ralink Tech Inc.
20494 + * 5F., No.36, Taiyuan St., Jhubei City,
20495 + * Hsinchu County 302,
20496 + * Taiwan, R.O.C.
20497 + *
20498 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
20499 + *
20500 + * This program is free software; you can redistribute it and/or modify *
20501 + * it under the terms of the GNU General Public License as published by *
20502 + * the Free Software Foundation; either version 2 of the License, or *
20503 + * (at your option) any later version. *
20504 + * *
20505 + * This program is distributed in the hope that it will be useful, *
20506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20508 + * GNU General Public License for more details. *
20509 + * *
20510 + * You should have received a copy of the GNU General Public License *
20511 + * along with this program; if not, write to the *
20512 + * Free Software Foundation, Inc., *
20513 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20514 + * *
20515 + *************************************************************************
20516 +
20517 + Module Name:
20518 + eeprom.c
20519 +
20520 + Abstract:
20521 +
20522 + Revision History:
20523 + Who When What
20524 + -------- ---------- ----------------------------------------------
20525 + Name Date Modification logs
20526 +*/
20527 +#include "../rt_config.h"
20528 +
20529 +#if 0
20530 +#define EEPROM_SIZE 0x200
20531 +#define NVRAM_OFFSET 0x30000
20532 +#define RF_OFFSET 0x40000
20533 +
20534 +static UCHAR init_flag = 0;
20535 +static PUCHAR nv_ee_start = 0;
20536 +
20537 +static UCHAR EeBuffer[EEPROM_SIZE];
20538 +#endif
20539 +// IRQL = PASSIVE_LEVEL
20540 +VOID RaiseClock(
20541 + IN PRTMP_ADAPTER pAd,
20542 + IN UINT32 *x)
20543 +{
20544 + *x = *x | EESK;
20545 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
20546 + RTMPusecDelay(1); // Max frequency = 1MHz in Spec. definition
20547 +}
20548 +
20549 +// IRQL = PASSIVE_LEVEL
20550 +VOID LowerClock(
20551 + IN PRTMP_ADAPTER pAd,
20552 + IN UINT32 *x)
20553 +{
20554 + *x = *x & ~EESK;
20555 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
20556 + RTMPusecDelay(1);
20557 +}
20558 +
20559 +// IRQL = PASSIVE_LEVEL
20560 +USHORT ShiftInBits(
20561 + IN PRTMP_ADAPTER pAd)
20562 +{
20563 + UINT32 x,i;
20564 + USHORT data=0;
20565 +
20566 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20567 +
20568 + x &= ~( EEDO | EEDI);
20569 +
20570 + for(i=0; i<16; i++)
20571 + {
20572 + data = data << 1;
20573 + RaiseClock(pAd, &x);
20574 +
20575 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20576 +
20577 + x &= ~(EEDI);
20578 + if(x & EEDO)
20579 + data |= 1;
20580 +
20581 + LowerClock(pAd, &x);
20582 + }
20583 +
20584 + return data;
20585 +}
20586 +
20587 +// IRQL = PASSIVE_LEVEL
20588 +VOID ShiftOutBits(
20589 + IN PRTMP_ADAPTER pAd,
20590 + IN USHORT data,
20591 + IN USHORT count)
20592 +{
20593 + UINT32 x,mask;
20594 +
20595 + mask = 0x01 << (count - 1);
20596 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20597 +
20598 + x &= ~(EEDO | EEDI);
20599 +
20600 + do
20601 + {
20602 + x &= ~EEDI;
20603 + if(data & mask) x |= EEDI;
20604 +
20605 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20606 +
20607 + RaiseClock(pAd, &x);
20608 + LowerClock(pAd, &x);
20609 +
20610 + mask = mask >> 1;
20611 + } while(mask);
20612 +
20613 + x &= ~EEDI;
20614 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20615 +}
20616 +
20617 +// IRQL = PASSIVE_LEVEL
20618 +VOID EEpromCleanup(
20619 + IN PRTMP_ADAPTER pAd)
20620 +{
20621 + UINT32 x;
20622 +
20623 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20624 +
20625 + x &= ~(EECS | EEDI);
20626 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20627 +
20628 + RaiseClock(pAd, &x);
20629 + LowerClock(pAd, &x);
20630 +}
20631 +
20632 +VOID EWEN(
20633 + IN PRTMP_ADAPTER pAd)
20634 +{
20635 + UINT32 x;
20636 +
20637 + // reset bits and set EECS
20638 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20639 + x &= ~(EEDI | EEDO | EESK);
20640 + x |= EECS;
20641 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20642 +
20643 + // kick a pulse
20644 + RaiseClock(pAd, &x);
20645 + LowerClock(pAd, &x);
20646 +
20647 + // output the read_opcode and six pulse in that order
20648 + ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
20649 + ShiftOutBits(pAd, 0, 6);
20650 +
20651 + EEpromCleanup(pAd);
20652 +}
20653 +
20654 +VOID EWDS(
20655 + IN PRTMP_ADAPTER pAd)
20656 +{
20657 + UINT32 x;
20658 +
20659 + // reset bits and set EECS
20660 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20661 + x &= ~(EEDI | EEDO | EESK);
20662 + x |= EECS;
20663 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20664 +
20665 + // kick a pulse
20666 + RaiseClock(pAd, &x);
20667 + LowerClock(pAd, &x);
20668 +
20669 + // output the read_opcode and six pulse in that order
20670 + ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
20671 + ShiftOutBits(pAd, 0, 6);
20672 +
20673 + EEpromCleanup(pAd);
20674 +}
20675 +
20676 +// IRQL = PASSIVE_LEVEL
20677 +USHORT RTMP_EEPROM_READ16(
20678 + IN PRTMP_ADAPTER pAd,
20679 + IN USHORT Offset)
20680 +{
20681 + UINT32 x;
20682 + USHORT data;
20683 +
20684 + Offset /= 2;
20685 + // reset bits and set EECS
20686 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20687 + x &= ~(EEDI | EEDO | EESK);
20688 + x |= EECS;
20689 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20690 +
20691 + // kick a pulse
20692 + RaiseClock(pAd, &x);
20693 + LowerClock(pAd, &x);
20694 +
20695 + // output the read_opcode and register number in that order
20696 + ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
20697 + ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
20698 +
20699 + // Now read the data (16 bits) in from the selected EEPROM word
20700 + data = ShiftInBits(pAd);
20701 +
20702 + EEpromCleanup(pAd);
20703 +
20704 + return data;
20705 +} //ReadEEprom
20706 +
20707 +VOID RTMP_EEPROM_WRITE16(
20708 + IN PRTMP_ADAPTER pAd,
20709 + IN USHORT Offset,
20710 + IN USHORT Data)
20711 +{
20712 + UINT32 x;
20713 +
20714 + Offset /= 2;
20715 +
20716 + EWEN(pAd);
20717 +
20718 + // reset bits and set EECS
20719 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20720 + x &= ~(EEDI | EEDO | EESK);
20721 + x |= EECS;
20722 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20723 +
20724 + // kick a pulse
20725 + RaiseClock(pAd, &x);
20726 + LowerClock(pAd, &x);
20727 +
20728 + // output the read_opcode ,register number and data in that order
20729 + ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3);
20730 + ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
20731 + ShiftOutBits(pAd, Data, 16); // 16-bit access
20732 +
20733 + // read DO status
20734 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20735 +
20736 + EEpromCleanup(pAd);
20737 +
20738 + RTMPusecDelay(10000); //delay for twp(MAX)=10ms
20739 +
20740 + EWDS(pAd);
20741 +
20742 + EEpromCleanup(pAd);
20743 +}
20744 +
20745 --- /dev/null
20746 +++ b/drivers/staging/rt2870/common/firmware.h
20747 @@ -0,0 +1,558 @@
20748 +/*
20749 + Copyright (c) 2007, Ralink Technology Corporation
20750 + All rights reserved.
20751 +
20752 + Redistribution. Redistribution and use in binary form, without
20753 + modification, are permitted provided that the following conditions are
20754 + met:
20755 +
20756 + * Redistributions must reproduce the above copyright notice and the
20757 + following disclaimer in the documentation and/or other materials
20758 + provided with the distribution.
20759 + * Neither the name of Ralink Technology Corporation nor the names of its
20760 + suppliers may be used to endorse or promote products derived from this
20761 + software without specific prior written permission.
20762 + * No reverse engineering, decompilation, or disassembly of this software
20763 + is permitted.
20764 +
20765 + Limited patent license. Ralink Technology Corporation grants a world-wide,
20766 + royalty-free, non-exclusive license under patents it now or hereafter
20767 + owns or controls to make, have made, use, import, offer to sell and
20768 + sell ("Utilize") this software, but solely to the extent that any
20769 + such patent is necessary to Utilize the software alone, or in
20770 + combination with an operating system licensed under an approved Open
20771 + Source license as listed by the Open Source Initiative at
20772 + http://opensource.org/licenses. The patent license shall not apply to
20773 + any other combinations which include this software. No hardware per
20774 + se is licensed hereunder.
20775 +
20776 + DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20777 + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
20778 + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20779 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20780 + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20781 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20782 + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
20783 + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20784 + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
20785 + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
20786 + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
20787 + DAMAGE.
20788 +*/
20789 +/* AUTO GEN PLEASE DO NOT MODIFY IT */
20790 +/* AUTO GEN PLEASE DO NOT MODIFY IT */
20791 +
20792 +
20793 +UCHAR FirmwareImage [] = {
20794 +0xff, 0xff, 0xff, 0x02, 0x10, 0x28, 0x02, 0x10, 0x32, 0x02, 0x10, 0x78, 0x02, 0x12, 0x79, 0x02,
20795 +0x12, 0x7a, 0x02, 0x12, 0x99, 0x02, 0x12, 0x9e, 0x12, 0x12, 0x9a, 0x22, 0x02, 0x16, 0x36, 0x02,
20796 +0x17, 0x0c, 0x02, 0x13, 0x89, 0x02, 0x12, 0x9f, 0x30, 0x05, 0x06, 0x20, 0x0d, 0x03, 0x12, 0x17,
20797 +0xae, 0x22, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe3, 0x1b, 0xe5, 0x4c, 0x30, 0xe0, 0x04, 0x7f, 0x40,
20798 +0x80, 0x02, 0x7f, 0x00, 0x90, 0x10, 0x2f, 0xef, 0xf0, 0x90, 0x01, 0x8c, 0x74, 0x08, 0xf0, 0xe4,
20799 +0x90, 0x01, 0xa7, 0xf0, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe0, 0x1c, 0x90, 0x01, 0x80, 0xe0, 0xb4,
20800 +0x02, 0x15, 0xa3, 0xe0, 0xb4, 0x01, 0x10, 0x90, 0x01, 0x84, 0xe0, 0xb4, 0x81, 0x09, 0x90, 0x01,
20801 +0x8c, 0x74, 0x01, 0xf0, 0x12, 0x0d, 0xc8, 0x22, 0x90, 0x04, 0x14, 0xe0, 0x20, 0xe7, 0x03, 0x02,
20802 +0x12, 0x6e, 0x90, 0x70, 0x12, 0xe0, 0xf5, 0x56, 0x90, 0x04, 0x04, 0xe0, 0x12, 0x0a, 0x9d, 0x10,
20803 +0xb7, 0x31, 0x10, 0xe2, 0x50, 0x11, 0x08, 0x51, 0x11, 0x13, 0x52, 0x11, 0x13, 0x53, 0x11, 0x13,
20804 +0x54, 0x11, 0x54, 0x55, 0x11, 0x79, 0x70, 0x11, 0xa4, 0x71, 0x11, 0xd2, 0x72, 0x12, 0x25, 0x73,
20805 +0x12, 0x46, 0x80, 0x00, 0x00, 0x12, 0x6e, 0x20, 0x02, 0x03, 0x30, 0x03, 0x1d, 0x7d, 0x02, 0xaf,
20806 +0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5,
20807 +0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x6e, 0x02, 0x12, 0x67, 0x85, 0x56, 0x41, 0xd2, 0x02, 0x02,
20808 +0x12, 0x6e, 0x90, 0x70, 0x10, 0xe0, 0x54, 0x7f, 0x64, 0x02, 0x60, 0x03, 0x02, 0x12, 0x6e, 0x90,
20809 +0x70, 0x11, 0xe0, 0x64, 0x08, 0x60, 0x08, 0xe0, 0x64, 0x20, 0x60, 0x03, 0x02, 0x12, 0x6e, 0x75,
20810 +0x4e, 0x03, 0x75, 0x4f, 0x20, 0x02, 0x12, 0x6e, 0x90, 0x70, 0x11, 0xe0, 0x24, 0xff, 0x92, 0x47,
20811 +0x02, 0x12, 0x6e, 0x90, 0x04, 0x04, 0xe0, 0x25, 0xe0, 0x24, 0x5d, 0xf5, 0x57, 0x90, 0x70, 0x10,
20812 +0xe0, 0xff, 0x74, 0x47, 0x25, 0x57, 0xf8, 0xc6, 0xef, 0xc6, 0x90, 0x70, 0x11, 0xe0, 0xff, 0x74,
20813 +0x48, 0x25, 0x57, 0xf8, 0xc6, 0xef, 0xc6, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04,
20814 +0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12,
20815 +0x6e, 0x02, 0x12, 0x67, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x0b, 0xe5, 0x47, 0x64, 0x08, 0x60, 0x05,
20816 +0xe5, 0x47, 0xb4, 0x09, 0x08, 0x90, 0x70, 0x11, 0xe0, 0x54, 0x0f, 0xf5, 0x3a, 0xe4, 0xfd, 0xaf,
20817 +0x56, 0x12, 0x0b, 0x91, 0xd2, 0x04, 0x02, 0x12, 0x6e, 0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90, 0x70,
20818 +0x11, 0xe0, 0xfd, 0xed, 0xf8, 0xe6, 0xf5, 0x57, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04,
20819 +0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12,
20820 +0x6e, 0x02, 0x12, 0x67, 0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90, 0x70, 0x11, 0xe0, 0xfd, 0xed, 0xf5,
20821 +0x82, 0x8e, 0x83, 0xe0, 0xf5, 0x57, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74,
20822 +0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x6e, 0x02,
20823 +0x12, 0x67, 0x90, 0x10, 0x02, 0xe0, 0xb4, 0x70, 0x1e, 0xa3, 0xe0, 0xb4, 0x30, 0x19, 0x90, 0x05,
20824 +0x08, 0xe0, 0x44, 0x01, 0xf0, 0xfd, 0x90, 0x05, 0x05, 0xe0, 0x54, 0xfb, 0xf0, 0x44, 0x04, 0xf0,
20825 +0xed, 0x54, 0xfe, 0x90, 0x05, 0x08, 0xf0, 0xe4, 0xf5, 0x4e, 0xf5, 0x4f, 0x75, 0x3a, 0xff, 0xad,
20826 +0x57, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13,
20827 +0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x07, 0x90, 0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x90, 0x70, 0x40,
20828 +0xe5, 0x3a, 0xf0, 0x80, 0x49, 0x90, 0x70, 0x10, 0xe0, 0x24, 0xff, 0x92, 0x93, 0xe4, 0xfd, 0xaf,
20829 +0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5,
20830 +0x56, 0xf4, 0x60, 0x2a, 0x80, 0x21, 0x90, 0x70, 0x10, 0xe0, 0x24, 0xff, 0x92, 0x4a, 0xd2, 0x05,
20831 +0xad, 0x57, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70,
20832 +0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x07, 0x90, 0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x90, 0x70,
20833 +0x42, 0xe5, 0x3a, 0xf0, 0xa3, 0x74, 0xab, 0xf0, 0x22, 0x22, 0xe5, 0x53, 0x70, 0x1a, 0x30, 0x60,
20834 +0x09, 0xb2, 0x4d, 0x30, 0x4d, 0x04, 0x05, 0x46, 0xc2, 0x04, 0xe5, 0x4f, 0x45, 0x4e, 0x60, 0x08,
20835 +0xe5, 0x4f, 0x15, 0x4f, 0x70, 0x02, 0x15, 0x4e, 0x22, 0x22, 0xc2, 0x42, 0xd3, 0x22, 0x22, 0xc2,
20836 +0x4b, 0xc2, 0x4c, 0xe5, 0x44, 0x12, 0x0a, 0x9d, 0x12, 0xc1, 0x00, 0x13, 0x54, 0x04, 0x13, 0x50,
20837 +0x08, 0x13, 0x2b, 0x10, 0x12, 0xd5, 0x20, 0x12, 0xf5, 0x60, 0x13, 0x06, 0xa0, 0x00, 0x00, 0x13,
20838 +0x56, 0x85, 0x48, 0x43, 0x85, 0x4a, 0x42, 0x85, 0x4c, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x60, 0x03,
20839 +0x02, 0x13, 0x56, 0x80, 0x1b, 0xe5, 0x48, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4a, 0xc4, 0x54,
20840 +0x0f, 0xf5, 0x42, 0xe5, 0x4c, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x66,
20841 +0x53, 0x43, 0x0f, 0x80, 0x61, 0x85, 0x49, 0x43, 0x85, 0x4b, 0x42, 0x85, 0x4d, 0x5e, 0xe5, 0x47,
20842 +0x64, 0x06, 0x70, 0x52, 0x80, 0x1b, 0xe5, 0x49, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4b, 0xc4,
20843 +0x54, 0x0f, 0xf5, 0x42, 0xe5, 0x4d, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70,
20844 +0x35, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x10, 0xf5, 0x43, 0x80, 0x2b, 0xe5, 0x47, 0xb4, 0x04, 0x06,
20845 +0x53, 0x5e, 0xfb, 0x75, 0x42, 0x09, 0xe5, 0x47, 0xb4, 0x05, 0x06, 0x43, 0x5e, 0x04, 0x75, 0x42,
20846 +0x09, 0xe5, 0x47, 0xb4, 0x06, 0x10, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x30, 0xf5, 0x43, 0x80, 0x06,
20847 +0xd2, 0x4b, 0x80, 0x02, 0xd2, 0x4c, 0xe4, 0xf5, 0x25, 0xe5, 0x42, 0xc4, 0x54, 0xf0, 0xff, 0xe5,
20848 +0x43, 0x54, 0x0f, 0x4f, 0xf5, 0x5f, 0x90, 0x70, 0x44, 0xf0, 0xa3, 0xe5, 0x5e, 0xf0, 0xa3, 0xe5,
20849 +0x4a, 0xf0, 0xa3, 0xe5, 0x48, 0xf0, 0xa3, 0xe5, 0x4c, 0xf0, 0xa3, 0xe5, 0x44, 0xf0, 0xa3, 0xe5,
20850 +0x42, 0xf0, 0xa3, 0xe5, 0x43, 0xf0, 0xd2, 0x60, 0x22, 0xe5, 0x47, 0x60, 0x10, 0x24, 0xc0, 0x70,
20851 +0x03, 0x12, 0x16, 0x16, 0x12, 0x13, 0x9e, 0xc2, 0xaf, 0xc2, 0x04, 0xd2, 0xaf, 0x22, 0xc2, 0xaf,
20852 +0x90, 0x04, 0x14, 0xe0, 0x54, 0x0e, 0x60, 0x04, 0xd2, 0x18, 0x80, 0x08, 0xe5, 0x4e, 0x45, 0x4f,
20853 +0x24, 0xff, 0x92, 0x18, 0xd2, 0xaf, 0x90, 0x04, 0x14, 0xe0, 0xa2, 0xe4, 0x92, 0x19, 0x74, 0x1e,
20854 +0xf0, 0xe5, 0x5f, 0x54, 0x0f, 0xf5, 0x2d, 0xe5, 0x25, 0x70, 0x13, 0x30, 0x18, 0x05, 0xe5, 0x5f,
20855 +0x20, 0xe5, 0x0b, 0x30, 0x19, 0x19, 0xe5, 0x5f, 0x54, 0x30, 0xff, 0xbf, 0x30, 0x11, 0xe5, 0x25,
20856 +0x70, 0x05, 0x75, 0x25, 0x0c, 0x80, 0x02, 0x15, 0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0x80, 0x0f, 0xe5,
20857 +0x5f, 0x30, 0xe6, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x04, 0xd2, 0x6c, 0xc2, 0x6d, 0xe5, 0x47,
20858 +0x64, 0x03, 0x70, 0x21, 0x30, 0x4b, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x18, 0xe5, 0x25, 0x70,
20859 +0x03, 0x30, 0x4c, 0x11, 0xc2, 0x4c, 0xe5, 0x25, 0x70, 0x05, 0x75, 0x25, 0x07, 0x80, 0x02, 0x15,
20860 +0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0xe5, 0x47, 0xb4, 0x09, 0x14, 0xe5, 0x44, 0x20, 0xe3, 0x0b, 0xe5,
20861 +0x3a, 0x64, 0x02, 0x60, 0x05, 0xe5, 0x3a, 0xb4, 0x03, 0x04, 0xc2, 0x6c, 0xd2, 0x6d, 0x90, 0x70,
20862 +0x46, 0xe5, 0x2d, 0xf0, 0x20, 0x69, 0x07, 0xe5, 0x5e, 0x20, 0xe0, 0x02, 0xb2, 0x68, 0x20, 0x6b,
20863 +0x07, 0xe5, 0x5e, 0x20, 0xe1, 0x02, 0xb2, 0x6a, 0x20, 0x6d, 0x07, 0xe5, 0x5e, 0x20, 0xe2, 0x02,
20864 +0xb2, 0x6c, 0x90, 0x70, 0x47, 0xe5, 0x2d, 0xf0, 0x75, 0x2e, 0x40, 0x20, 0x69, 0x04, 0xa2, 0x68,
20865 +0x80, 0x26, 0x30, 0x68, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe2, 0x04,
20866 +0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01,
20867 +0x80, 0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x73, 0x92, 0x72, 0x20, 0x6b, 0x04, 0xa2,
20868 +0x6a, 0x80, 0x26, 0x30, 0x6a, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe0,
20869 +0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e,
20870 +0x01, 0x80, 0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x75, 0x92, 0x74, 0x20, 0x6d, 0x04,
20871 +0xa2, 0x6c, 0x80, 0x26, 0x30, 0x6c, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20,
20872 +0xe1, 0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04,
20873 +0x7e, 0x01, 0x80, 0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x71, 0x92, 0x70, 0x90, 0x10,
20874 +0x2f, 0xe5, 0x2e, 0xf0, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x4c, 0x90, 0x02, 0x29, 0xe0, 0x54, 0xfe,
20875 +0xf0, 0xe5, 0x43, 0xc4, 0x54, 0x0f, 0x14, 0x60, 0x14, 0x24, 0xfe, 0x60, 0x23, 0x24, 0x03, 0x60,
20876 +0x03, 0x02, 0x16, 0x05, 0x90, 0x02, 0x28, 0xe0, 0x30, 0x47, 0x0f, 0x80, 0x07, 0x90, 0x02, 0x28,
20877 +0xe0, 0x20, 0x47, 0x06, 0x54, 0xfe, 0xf0, 0x02, 0x16, 0x05, 0x44, 0x01, 0xf0, 0x02, 0x16, 0x05,
20878 +0xe5, 0x46, 0x30, 0xe2, 0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0x90, 0x02, 0x28, 0xe0, 0x54,
20879 +0xfe, 0x4f, 0xf0, 0x02, 0x16, 0x05, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x0f, 0xe5, 0x47, 0x64, 0x08,
20880 +0x60, 0x09, 0xe5, 0x47, 0x64, 0x09, 0x60, 0x03, 0x02, 0x16, 0x05, 0xe4, 0xf5, 0x27, 0x90, 0x02,
20881 +0x29, 0xe0, 0x54, 0xfc, 0xf0, 0xe5, 0x3a, 0x14, 0x60, 0x2d, 0x14, 0x60, 0x2e, 0x14, 0x60, 0x36,
20882 +0x24, 0xfc, 0x60, 0x5f, 0x24, 0xf9, 0x60, 0x1f, 0x24, 0x0e, 0x70, 0x69, 0xe5, 0x46, 0x13, 0x13,
20883 +0x54, 0x3f, 0x75, 0xf0, 0x01, 0x84, 0xaf, 0xf0, 0x20, 0x47, 0x04, 0x7e, 0x01, 0x80, 0x02, 0x7e,
20884 +0x00, 0xef, 0x6e, 0x24, 0xff, 0x80, 0x45, 0xa2, 0x47, 0x80, 0x41, 0xe5, 0x46, 0x30, 0xe2, 0x03,
20885 +0xd3, 0x80, 0x27, 0xc3, 0x80, 0x24, 0xe5, 0x46, 0x30, 0xe2, 0x0d, 0x54, 0x38, 0xc3, 0x94, 0x30,
20886 +0x50, 0x06, 0x7e, 0x00, 0x7f, 0x01, 0x80, 0x04, 0x7e, 0x00, 0x7f, 0x00, 0x20, 0x47, 0x04, 0x7d,
20887 +0x01, 0x80, 0x02, 0x7d, 0x00, 0xef, 0x6d, 0x4e, 0x24, 0xff, 0x92, 0x38, 0xa2, 0x47, 0xb3, 0x92,
20888 +0x39, 0x80, 0x19, 0xe5, 0x46, 0x30, 0xe2, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92, 0x39, 0xa2, 0x47,
20889 +0xb3, 0x92, 0x38, 0x80, 0x07, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x92, 0x39, 0x90, 0x02, 0x28, 0xe0,
20890 +0x54, 0xfc, 0x45, 0x27, 0xf0, 0x90, 0x70, 0x9c, 0xe5, 0x3a, 0xf0, 0xa3, 0xe5, 0x47, 0xf0, 0x90,
20891 +0x70, 0x41, 0xe5, 0x3a, 0xf0, 0x22, 0xe4, 0x90, 0x02, 0x29, 0xf0, 0x30, 0x47, 0x04, 0xaf, 0x45,
20892 +0x80, 0x04, 0xe5, 0x45, 0xf4, 0xff, 0x90, 0x02, 0x28, 0xef, 0xf0, 0x22, 0x8f, 0x50, 0xd2, 0x59,
20893 +0x22, 0x8f, 0x54, 0xd2, 0x58, 0x22, 0xe4, 0xf5, 0x62, 0xc2, 0xaf, 0xe5, 0x51, 0x14, 0x60, 0x46,
20894 +0x14, 0x60, 0x62, 0x24, 0x02, 0x60, 0x03, 0x02, 0x16, 0xf0, 0xd2, 0x59, 0x75, 0x55, 0x01, 0x90,
20895 +0x02, 0xa2, 0xe0, 0x54, 0x7f, 0xf0, 0xa3, 0xe0, 0x20, 0xe7, 0x22, 0x90, 0x04, 0x34, 0xe0, 0xb4,
20896 +0x02, 0x1b, 0xa3, 0xe0, 0xb4, 0x02, 0x16, 0xa3, 0xe0, 0xb4, 0x02, 0x11, 0x7f, 0x20, 0x12, 0x16,
20897 +0x2c, 0x90, 0x10, 0x04, 0xe0, 0x54, 0xf3, 0xf0, 0x75, 0x51, 0x01, 0x80, 0x73, 0xe5, 0x50, 0x70,
20898 +0x05, 0x75, 0x62, 0x03, 0x80, 0x6a, 0x90, 0x12, 0x00, 0xe0, 0x54, 0x03, 0x70, 0x11, 0x7f, 0x20,
20899 +0x12, 0x16, 0x2c, 0x90, 0x02, 0xa2, 0xe0, 0x54, 0xbf, 0xf0, 0x75, 0x51, 0x02, 0x80, 0x51, 0xe5,
20900 +0x50, 0x70, 0x02, 0x80, 0x46, 0x90, 0x02, 0xa3, 0xe0, 0x20, 0xe6, 0x3b, 0x90, 0x04, 0x37, 0xe0,
20901 +0x64, 0x22, 0x70, 0x33, 0x90, 0x01, 0x8a, 0x74, 0x7e, 0xf0, 0x90, 0x01, 0x96, 0xf0, 0x90, 0x12,
20902 +0x04, 0x74, 0x0a, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x54, 0xf0, 0xf0, 0xa3, 0xe0, 0x54, 0xf0, 0xf0,
20903 +0xa3, 0xe0, 0x54, 0xfa, 0xf0, 0x90, 0x04, 0x01, 0xe0, 0x54, 0xf9, 0xf0, 0x75, 0x62, 0x01, 0x75,
20904 +0x55, 0x02, 0xe4, 0xf5, 0x51, 0x80, 0x09, 0xe5, 0x50, 0x70, 0x05, 0x75, 0x62, 0x03, 0xf5, 0x51,
20905 +0xe5, 0x62, 0x60, 0x15, 0xc2, 0x01, 0xe4, 0xf5, 0x51, 0xc2, 0x59, 0xad, 0x62, 0xaf, 0x40, 0x12,
20906 +0x17, 0x7a, 0xe5, 0x62, 0xb4, 0x03, 0x02, 0xd2, 0x03, 0xd2, 0xaf, 0x22, 0xc2, 0xaf, 0x30, 0x01,
20907 +0x12, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xf5, 0x51, 0xc2, 0x59, 0xc2, 0x01, 0x7d, 0x02, 0xaf, 0x40,
20908 +0x12, 0x17, 0x7a, 0xe5, 0x52, 0x14, 0x60, 0x09, 0x04, 0x70, 0x4c, 0x75, 0x52, 0x01, 0x75, 0x55,
20909 +0x03, 0x90, 0x04, 0x01, 0xe0, 0x44, 0x0e, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x44, 0x0f, 0xf0, 0xa3,
20910 +0xe0, 0x44, 0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x05, 0xf0, 0x90, 0x12, 0x04, 0x74, 0x03, 0xf0, 0x90,
20911 +0x02, 0xa2, 0xe0, 0x44, 0xc0, 0xf0, 0x90, 0x10, 0x04, 0xe0, 0x44, 0x0c, 0xf0, 0xe4, 0xf5, 0x52,
20912 +0xf5, 0x55, 0x30, 0x02, 0x0b, 0xc2, 0x02, 0x7d, 0x01, 0xaf, 0x41, 0x12, 0x17, 0x7a, 0x80, 0x02,
20913 +0xc2, 0x03, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xd2, 0xaf, 0x22, 0xef, 0xf4, 0x60, 0x2d, 0xe4, 0xfe,
20914 +0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xe0, 0xb4, 0xff, 0x19, 0x74, 0x14,
20915 +0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xef, 0xf0, 0x74, 0x1c, 0x2e, 0xf5, 0x82, 0xe4,
20916 +0x34, 0x70, 0xf5, 0x83, 0xed, 0xf0, 0x22, 0x0e, 0xbe, 0x04, 0xd5, 0x22, 0x22, 0x22, 0x90, 0x70,
20917 +0x2a, 0xe0, 0x30, 0xe1, 0x4d, 0xc2, 0xaf, 0x90, 0x70, 0x28, 0xe0, 0x90, 0x10, 0x1c, 0xf0, 0x90,
20918 +0x70, 0x29, 0xe0, 0x90, 0x10, 0x1d, 0xf0, 0x90, 0x70, 0x2a, 0xe0, 0x90, 0x10, 0x1e, 0xf0, 0x90,
20919 +0x10, 0x1c, 0xe0, 0xf5, 0x62, 0x90, 0x10, 0x1e, 0xe0, 0x20, 0xe1, 0xf3, 0x90, 0x10, 0x1c, 0xe0,
20920 +0x90, 0x70, 0x28, 0xf0, 0x90, 0x10, 0x1d, 0xe0, 0x90, 0x70, 0x29, 0xf0, 0x90, 0x10, 0x1e, 0xe0,
20921 +0x90, 0x70, 0x2a, 0xf0, 0x30, 0x4a, 0x07, 0x90, 0x70, 0x24, 0xe0, 0x44, 0x01, 0xf0, 0xc2, 0x05,
20922 +0xd2, 0xaf, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20923 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20924 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20925 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20926 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20927 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20928 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20929 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20930 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20931 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20932 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20933 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20934 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20935 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20936 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20937 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20938 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20939 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20940 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20941 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20942 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20943 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20944 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20945 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20946 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20947 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20948 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20949 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20950 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20951 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20952 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20953 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20954 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20955 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20956 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20957 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20958 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20959 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20960 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20961 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20962 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20963 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20964 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20965 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20966 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20967 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20968 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20969 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20970 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20971 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20972 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20973 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20974 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20975 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20976 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20977 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20978 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20979 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20980 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20981 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20982 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20983 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20984 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20985 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20986 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20987 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20988 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20989 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20990 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20991 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20992 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20993 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20994 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20995 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20996 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20997 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20998 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20999 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21000 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21001 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21002 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21003 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21004 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21005 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21006 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21007 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21008 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21009 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21010 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21011 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21012 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21013 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21014 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21015 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21016 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21017 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21018 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21019 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21020 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21021 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21022 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21023 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21024 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21025 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21026 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21027 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21028 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21029 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21030 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21031 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21032 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21033 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21034 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21035 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21036 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21037 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21038 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21039 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21040 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21041 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21042 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21043 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21044 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21045 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21046 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21047 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21048 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21049 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x69, 0x77,
21050 +0xff, 0xff, 0xff, 0x02, 0x10, 0x28, 0x02, 0x10, 0x32, 0x02, 0x10, 0x78, 0x02, 0x12, 0x25, 0x02,
21051 +0x12, 0x26, 0x02, 0x12, 0x39, 0x02, 0x12, 0x3e, 0x12, 0x12, 0x3a, 0x22, 0x02, 0x15, 0x72, 0x02,
21052 +0x16, 0x48, 0x02, 0x13, 0x29, 0x02, 0x12, 0x3f, 0x30, 0x05, 0x06, 0x20, 0x0d, 0x03, 0x12, 0x16,
21053 +0xea, 0x22, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe3, 0x1b, 0xe5, 0x4c, 0x30, 0xe0, 0x04, 0x7f, 0x40,
21054 +0x80, 0x02, 0x7f, 0x00, 0x90, 0x10, 0x2f, 0xef, 0xf0, 0x90, 0x01, 0x8c, 0x74, 0x08, 0xf0, 0xe4,
21055 +0x90, 0x01, 0xa7, 0xf0, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe0, 0x1c, 0x90, 0x01, 0x80, 0xe0, 0xb4,
21056 +0x02, 0x15, 0xa3, 0xe0, 0xb4, 0x01, 0x10, 0x90, 0x01, 0x84, 0xe0, 0xb4, 0x81, 0x09, 0x90, 0x01,
21057 +0x8c, 0x74, 0x01, 0xf0, 0x12, 0x0d, 0xdd, 0x22, 0x90, 0x04, 0x14, 0xe0, 0x20, 0xe7, 0x03, 0x02,
21058 +0x12, 0x1a, 0x90, 0x70, 0x12, 0xe0, 0xf5, 0x56, 0x90, 0x04, 0x04, 0xe0, 0x12, 0x0a, 0xb6, 0x10,
21059 +0xb4, 0x31, 0x10, 0xdf, 0x50, 0x11, 0x05, 0x51, 0x11, 0x10, 0x52, 0x11, 0x10, 0x53, 0x11, 0x10,
21060 +0x54, 0x11, 0x51, 0x55, 0x11, 0x70, 0x70, 0x11, 0x9a, 0x71, 0x11, 0xc4, 0x72, 0x11, 0xf2, 0x80,
21061 +0x00, 0x00, 0x12, 0x1a, 0x20, 0x02, 0x03, 0x30, 0x03, 0x1d, 0x7d, 0x02, 0xaf, 0x56, 0x12, 0x0b,
21062 +0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70,
21063 +0x03, 0x02, 0x12, 0x1a, 0x02, 0x12, 0x13, 0x85, 0x56, 0x41, 0xd2, 0x02, 0x02, 0x12, 0x1a, 0x90,
21064 +0x70, 0x10, 0xe0, 0x54, 0x7f, 0x64, 0x02, 0x60, 0x03, 0x02, 0x12, 0x1a, 0x90, 0x70, 0x11, 0xe0,
21065 +0x64, 0x08, 0x60, 0x08, 0xe0, 0x64, 0x20, 0x60, 0x03, 0x02, 0x12, 0x1a, 0x75, 0x4e, 0x03, 0x75,
21066 +0x4f, 0x20, 0x02, 0x12, 0x1a, 0x90, 0x70, 0x11, 0xe0, 0x24, 0xff, 0x92, 0x47, 0x02, 0x12, 0x1a,
21067 +0x90, 0x04, 0x04, 0xe0, 0x25, 0xe0, 0x24, 0x5d, 0xf5, 0x57, 0x90, 0x70, 0x10, 0xe0, 0xff, 0x74,
21068 +0x47, 0x25, 0x57, 0xf8, 0xc6, 0xef, 0xc6, 0x90, 0x70, 0x11, 0xe0, 0xff, 0x74, 0x48, 0x25, 0x57,
21069 +0xf8, 0xc6, 0xef, 0xc6, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80,
21070 +0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x1a, 0x02, 0x12,
21071 +0x13, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x05, 0xe5, 0x47, 0xb4, 0x08, 0x08, 0x90, 0x70, 0x11, 0xe0,
21072 +0x54, 0x07, 0xf5, 0x3a, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0xd2, 0x04, 0x02, 0x12, 0x1a,
21073 +0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90, 0x70, 0x11, 0xe0, 0xfd, 0xed, 0xf8, 0xe6, 0xf5, 0x57, 0xfd,
21074 +0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0,
21075 +0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x1a, 0x80, 0x79, 0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90,
21076 +0x70, 0x11, 0xe0, 0xfd, 0xed, 0xf5, 0x82, 0x8e, 0x83, 0xe0, 0xf5, 0x57, 0xfd, 0xaf, 0x56, 0x12,
21077 +0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4,
21078 +0x60, 0x58, 0x80, 0x4f, 0xe4, 0xf5, 0x4e, 0xf5, 0x4f, 0x75, 0x3a, 0xff, 0xad, 0x57, 0xaf, 0x56,
21079 +0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56,
21080 +0xf4, 0x60, 0x07, 0x90, 0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x90, 0x70, 0x40, 0xe5, 0x3a, 0xf0,
21081 +0x80, 0x28, 0x90, 0x70, 0x10, 0xe0, 0x24, 0xff, 0x92, 0x4a, 0xd2, 0x05, 0xad, 0x57, 0xaf, 0x56,
21082 +0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56,
21083 +0xf4, 0x60, 0x07, 0x90, 0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x90, 0x70, 0x42, 0xe5, 0x3a, 0xf0,
21084 +0xa3, 0x74, 0xab, 0xf0, 0x22, 0x22, 0xe5, 0x53, 0x70, 0x0e, 0xe5, 0x4f, 0x45, 0x4e, 0x60, 0x08,
21085 +0xe5, 0x4f, 0x15, 0x4f, 0x70, 0x02, 0x15, 0x4e, 0x22, 0x22, 0xc2, 0x42, 0xd3, 0x22, 0x22, 0xc2,
21086 +0x4b, 0xc2, 0x4c, 0xe5, 0x44, 0x12, 0x0a, 0xb6, 0x12, 0x61, 0x00, 0x12, 0xf4, 0x04, 0x12, 0xf0,
21087 +0x08, 0x12, 0xcb, 0x10, 0x12, 0x75, 0x20, 0x12, 0x95, 0x60, 0x12, 0xa6, 0xa0, 0x00, 0x00, 0x12,
21088 +0xf6, 0x85, 0x48, 0x43, 0x85, 0x4a, 0x42, 0x85, 0x4c, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x60, 0x03,
21089 +0x02, 0x12, 0xf6, 0x80, 0x1b, 0xe5, 0x48, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4a, 0xc4, 0x54,
21090 +0x0f, 0xf5, 0x42, 0xe5, 0x4c, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x66,
21091 +0x53, 0x43, 0x0f, 0x80, 0x61, 0x85, 0x49, 0x43, 0x85, 0x4b, 0x42, 0x85, 0x4d, 0x5e, 0xe5, 0x47,
21092 +0x64, 0x06, 0x70, 0x52, 0x80, 0x1b, 0xe5, 0x49, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4b, 0xc4,
21093 +0x54, 0x0f, 0xf5, 0x42, 0xe5, 0x4d, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70,
21094 +0x35, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x10, 0xf5, 0x43, 0x80, 0x2b, 0xe5, 0x47, 0xb4, 0x04, 0x06,
21095 +0x53, 0x5e, 0xfb, 0x75, 0x42, 0x09, 0xe5, 0x47, 0xb4, 0x05, 0x06, 0x43, 0x5e, 0x04, 0x75, 0x42,
21096 +0x09, 0xe5, 0x47, 0xb4, 0x06, 0x10, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x30, 0xf5, 0x43, 0x80, 0x06,
21097 +0xd2, 0x4b, 0x80, 0x02, 0xd2, 0x4c, 0xe4, 0xf5, 0x25, 0xe5, 0x42, 0xc4, 0x54, 0xf0, 0xff, 0xe5,
21098 +0x43, 0x54, 0x0f, 0x4f, 0xf5, 0x5f, 0x90, 0x70, 0x44, 0xf0, 0xa3, 0xe5, 0x5e, 0xf0, 0xa3, 0xe5,
21099 +0x4a, 0xf0, 0xa3, 0xe5, 0x48, 0xf0, 0xa3, 0xe5, 0x4c, 0xf0, 0xa3, 0xe5, 0x44, 0xf0, 0xa3, 0xe5,
21100 +0x42, 0xf0, 0xa3, 0xe5, 0x43, 0xf0, 0xd2, 0x60, 0x22, 0xe5, 0x47, 0x60, 0x10, 0x24, 0xc0, 0x70,
21101 +0x03, 0x12, 0x15, 0x52, 0x12, 0x13, 0x3e, 0xc2, 0xaf, 0xc2, 0x04, 0xd2, 0xaf, 0x22, 0xc2, 0xaf,
21102 +0x90, 0x04, 0x14, 0xe0, 0x54, 0x0e, 0x60, 0x04, 0xd2, 0x18, 0x80, 0x08, 0xe5, 0x4e, 0x45, 0x4f,
21103 +0x24, 0xff, 0x92, 0x18, 0xd2, 0xaf, 0x90, 0x04, 0x14, 0xe0, 0xa2, 0xe4, 0x92, 0x19, 0x74, 0x1e,
21104 +0xf0, 0xe5, 0x5f, 0x54, 0x0f, 0xf5, 0x2d, 0xe5, 0x25, 0x70, 0x13, 0x30, 0x18, 0x05, 0xe5, 0x5f,
21105 +0x20, 0xe5, 0x0b, 0x30, 0x19, 0x19, 0xe5, 0x5f, 0x54, 0x30, 0xff, 0xbf, 0x30, 0x11, 0xe5, 0x25,
21106 +0x70, 0x05, 0x75, 0x25, 0x0c, 0x80, 0x02, 0x15, 0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0x80, 0x0f, 0xe5,
21107 +0x5f, 0x30, 0xe6, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x04, 0xd2, 0x6c, 0xc2, 0x6d, 0xe5, 0x47,
21108 +0x64, 0x03, 0x70, 0x21, 0x30, 0x4b, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x18, 0xe5, 0x25, 0x70,
21109 +0x03, 0x30, 0x4c, 0x11, 0xc2, 0x4c, 0xe5, 0x25, 0x70, 0x05, 0x75, 0x25, 0x07, 0x80, 0x02, 0x15,
21110 +0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0x90, 0x70, 0x46, 0xe5, 0x2d, 0xf0, 0x20, 0x69, 0x07, 0xe5, 0x5e,
21111 +0x20, 0xe0, 0x02, 0xb2, 0x68, 0x20, 0x6b, 0x07, 0xe5, 0x5e, 0x20, 0xe1, 0x02, 0xb2, 0x6a, 0x20,
21112 +0x6d, 0x07, 0xe5, 0x5e, 0x20, 0xe2, 0x02, 0xb2, 0x6c, 0x90, 0x70, 0x47, 0xe5, 0x2d, 0xf0, 0x75,
21113 +0x2e, 0x40, 0x20, 0x69, 0x04, 0xa2, 0x68, 0x80, 0x15, 0x30, 0x68, 0x06, 0xe5, 0x46, 0xa2, 0xe3,
21114 +0x80, 0x0c, 0xe5, 0x46, 0x54, 0xf0, 0xff, 0xbf, 0xf0, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92, 0x73,
21115 +0x92, 0x72, 0x20, 0x6b, 0x04, 0xa2, 0x6a, 0x80, 0x15, 0x30, 0x6a, 0x06, 0xe5, 0x46, 0xa2, 0xe3,
21116 +0x80, 0x0c, 0xe5, 0x46, 0x54, 0xf0, 0xff, 0xbf, 0xf0, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92, 0x75,
21117 +0x92, 0x74, 0x20, 0x6d, 0x04, 0xa2, 0x6c, 0x80, 0x15, 0x30, 0x6c, 0x06, 0xe5, 0x46, 0xa2, 0xe3,
21118 +0x80, 0x0c, 0xe5, 0x46, 0x54, 0xf0, 0xff, 0xbf, 0xf0, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92, 0x71,
21119 +0x92, 0x70, 0x90, 0x10, 0x2f, 0xe5, 0x2e, 0xf0, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x4c, 0x90, 0x02,
21120 +0x29, 0xe0, 0x54, 0xfe, 0xf0, 0xe5, 0x43, 0xc4, 0x54, 0x0f, 0x14, 0x60, 0x14, 0x24, 0xfe, 0x60,
21121 +0x23, 0x24, 0x03, 0x60, 0x03, 0x02, 0x15, 0x41, 0x90, 0x02, 0x28, 0xe0, 0x30, 0x47, 0x0f, 0x80,
21122 +0x07, 0x90, 0x02, 0x28, 0xe0, 0x20, 0x47, 0x06, 0x54, 0xfe, 0xf0, 0x02, 0x15, 0x41, 0x44, 0x01,
21123 +0xf0, 0x02, 0x15, 0x41, 0xe5, 0x46, 0x30, 0xe3, 0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0x90,
21124 +0x02, 0x28, 0xe0, 0x54, 0xfe, 0x4f, 0xf0, 0x02, 0x15, 0x41, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x09,
21125 +0xe5, 0x47, 0x64, 0x08, 0x60, 0x03, 0x02, 0x15, 0x41, 0xe4, 0xf5, 0x27, 0x90, 0x02, 0x29, 0xe0,
21126 +0x54, 0xfc, 0xf0, 0xe5, 0x3a, 0x14, 0x60, 0x26, 0x14, 0x60, 0x2e, 0x14, 0x60, 0x36, 0x24, 0x03,
21127 +0x70, 0x5f, 0xe5, 0x46, 0x13, 0x13, 0x13, 0x54, 0x1f, 0x75, 0xf0, 0x03, 0x84, 0xaf, 0xf0, 0x20,
21128 +0x47, 0x04, 0x7e, 0x01, 0x80, 0x02, 0x7e, 0x00, 0xef, 0x6e, 0x24, 0xff, 0x80, 0x02, 0xa2, 0x47,
21129 +0x92, 0x39, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x80, 0x3f, 0xe5, 0x46, 0x30, 0xe3, 0x03, 0xd3, 0x80,
21130 +0x27, 0xc3, 0x80, 0x24, 0xe5, 0x46, 0x30, 0xe3, 0x0d, 0x54, 0x70, 0xc3, 0x94, 0x60, 0x50, 0x06,
21131 +0x7e, 0x00, 0x7f, 0x01, 0x80, 0x04, 0x7e, 0x00, 0x7f, 0x00, 0x20, 0x47, 0x04, 0x7d, 0x01, 0x80,
21132 +0x02, 0x7d, 0x00, 0xef, 0x6d, 0x4e, 0x24, 0xff, 0x92, 0x38, 0xa2, 0x47, 0xb3, 0x92, 0x39, 0x80,
21133 +0x07, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x92, 0x39, 0x90, 0x02, 0x28, 0xe0, 0x54, 0xfc, 0x45, 0x27,
21134 +0xf0, 0x90, 0x70, 0x9c, 0xe5, 0x3a, 0xf0, 0xa3, 0xe5, 0x47, 0xf0, 0x90, 0x70, 0x41, 0xe5, 0x3a,
21135 +0xf0, 0x22, 0xe4, 0x90, 0x02, 0x29, 0xf0, 0x30, 0x47, 0x04, 0xaf, 0x45, 0x80, 0x04, 0xe5, 0x45,
21136 +0xf4, 0xff, 0x90, 0x02, 0x28, 0xef, 0xf0, 0x22, 0x8f, 0x50, 0xd2, 0x59, 0x22, 0x8f, 0x54, 0xd2,
21137 +0x58, 0x22, 0xe4, 0xf5, 0x62, 0xc2, 0xaf, 0xe5, 0x51, 0x14, 0x60, 0x46, 0x14, 0x60, 0x62, 0x24,
21138 +0x02, 0x60, 0x03, 0x02, 0x16, 0x2c, 0xd2, 0x59, 0x75, 0x55, 0x01, 0x90, 0x02, 0xa2, 0xe0, 0x54,
21139 +0x7f, 0xf0, 0xa3, 0xe0, 0x20, 0xe7, 0x22, 0x90, 0x04, 0x34, 0xe0, 0xb4, 0x02, 0x1b, 0xa3, 0xe0,
21140 +0xb4, 0x02, 0x16, 0xa3, 0xe0, 0xb4, 0x02, 0x11, 0x7f, 0x20, 0x12, 0x15, 0x68, 0x90, 0x10, 0x04,
21141 +0xe0, 0x54, 0xf3, 0xf0, 0x75, 0x51, 0x01, 0x80, 0x73, 0xe5, 0x50, 0x70, 0x05, 0x75, 0x62, 0x03,
21142 +0x80, 0x6a, 0x90, 0x12, 0x00, 0xe0, 0x54, 0x03, 0x70, 0x11, 0x7f, 0x20, 0x12, 0x15, 0x68, 0x90,
21143 +0x02, 0xa2, 0xe0, 0x54, 0xbf, 0xf0, 0x75, 0x51, 0x02, 0x80, 0x51, 0xe5, 0x50, 0x70, 0x02, 0x80,
21144 +0x46, 0x90, 0x02, 0xa3, 0xe0, 0x20, 0xe6, 0x3b, 0x90, 0x04, 0x37, 0xe0, 0x64, 0x22, 0x70, 0x33,
21145 +0x90, 0x01, 0x8a, 0x74, 0x7e, 0xf0, 0x90, 0x01, 0x96, 0xf0, 0x90, 0x12, 0x04, 0x74, 0x0a, 0xf0,
21146 +0x90, 0x13, 0x28, 0xe0, 0x54, 0xf0, 0xf0, 0xa3, 0xe0, 0x54, 0xf0, 0xf0, 0xa3, 0xe0, 0x54, 0xfa,
21147 +0xf0, 0x90, 0x04, 0x01, 0xe0, 0x54, 0xf9, 0xf0, 0x75, 0x62, 0x01, 0x75, 0x55, 0x02, 0xe4, 0xf5,
21148 +0x51, 0x80, 0x09, 0xe5, 0x50, 0x70, 0x05, 0x75, 0x62, 0x03, 0xf5, 0x51, 0xe5, 0x62, 0x60, 0x15,
21149 +0xc2, 0x01, 0xe4, 0xf5, 0x51, 0xc2, 0x59, 0xad, 0x62, 0xaf, 0x40, 0x12, 0x16, 0xb6, 0xe5, 0x62,
21150 +0xb4, 0x03, 0x02, 0xd2, 0x03, 0xd2, 0xaf, 0x22, 0xc2, 0xaf, 0x30, 0x01, 0x12, 0xe4, 0x90, 0x01,
21151 +0x96, 0xf0, 0xf5, 0x51, 0xc2, 0x59, 0xc2, 0x01, 0x7d, 0x02, 0xaf, 0x40, 0x12, 0x16, 0xb6, 0xe5,
21152 +0x52, 0x14, 0x60, 0x09, 0x04, 0x70, 0x4c, 0x75, 0x52, 0x01, 0x75, 0x55, 0x03, 0x90, 0x04, 0x01,
21153 +0xe0, 0x44, 0x0e, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x44, 0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x0f, 0xf0,
21154 +0xa3, 0xe0, 0x44, 0x05, 0xf0, 0x90, 0x12, 0x04, 0x74, 0x03, 0xf0, 0x90, 0x02, 0xa2, 0xe0, 0x44,
21155 +0xc0, 0xf0, 0x90, 0x10, 0x04, 0xe0, 0x44, 0x0c, 0xf0, 0xe4, 0xf5, 0x52, 0xf5, 0x55, 0x30, 0x02,
21156 +0x0b, 0xc2, 0x02, 0x7d, 0x01, 0xaf, 0x41, 0x12, 0x16, 0xb6, 0x80, 0x02, 0xc2, 0x03, 0xe4, 0x90,
21157 +0x01, 0x96, 0xf0, 0xd2, 0xaf, 0x22, 0xef, 0xf4, 0x60, 0x2d, 0xe4, 0xfe, 0x74, 0x14, 0x2e, 0xf5,
21158 +0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xe0, 0xb4, 0xff, 0x19, 0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4,
21159 +0x34, 0x70, 0xf5, 0x83, 0xef, 0xf0, 0x74, 0x1c, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83,
21160 +0xed, 0xf0, 0x22, 0x0e, 0xbe, 0x04, 0xd5, 0x22, 0x22, 0x22, 0x90, 0x70, 0x2a, 0xe0, 0x30, 0xe1,
21161 +0x4d, 0xc2, 0xaf, 0x90, 0x70, 0x28, 0xe0, 0x90, 0x10, 0x1c, 0xf0, 0x90, 0x70, 0x29, 0xe0, 0x90,
21162 +0x10, 0x1d, 0xf0, 0x90, 0x70, 0x2a, 0xe0, 0x90, 0x10, 0x1e, 0xf0, 0x90, 0x10, 0x1c, 0xe0, 0xf5,
21163 +0x62, 0x90, 0x10, 0x1e, 0xe0, 0x20, 0xe1, 0xf3, 0x90, 0x10, 0x1c, 0xe0, 0x90, 0x70, 0x28, 0xf0,
21164 +0x90, 0x10, 0x1d, 0xe0, 0x90, 0x70, 0x29, 0xf0, 0x90, 0x10, 0x1e, 0xe0, 0x90, 0x70, 0x2a, 0xf0,
21165 +0x30, 0x4a, 0x07, 0x90, 0x70, 0x24, 0xe0, 0x44, 0x01, 0xf0, 0xc2, 0x05, 0xd2, 0xaf, 0x22, 0x22,
21166 +0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21167 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21168 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21169 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21170 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21171 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21172 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21173 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21174 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21175 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21176 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21177 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21178 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21179 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21180 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21181 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21182 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21183 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21184 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21185 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21186 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21187 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21188 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21189 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21190 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21191 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21192 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21193 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21194 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21195 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21196 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21197 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21198 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21199 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21200 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21201 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21202 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21203 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21204 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21205 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21206 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21207 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21208 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21209 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21210 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21211 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21212 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21213 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21214 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21215 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21216 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21217 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21218 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21219 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21220 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21221 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21222 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21223 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21224 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21225 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21226 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21227 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21228 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21229 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21230 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21231 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21232 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21233 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21234 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21235 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21236 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21237 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21238 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21239 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21240 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21241 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21242 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21243 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21244 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21245 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21246 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21247 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21248 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21249 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21250 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21251 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21252 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21253 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21254 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21255 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21256 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21257 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21258 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21259 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21260 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21261 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21262 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21263 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21264 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21265 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21266 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21267 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21268 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21269 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21270 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21271 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21272 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21273 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21274 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21275 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21276 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21277 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21278 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21279 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21280 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21281 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21282 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21283 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21284 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21285 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21286 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21287 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21288 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21289 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21290 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21291 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21292 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21293 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21294 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21295 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21296 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21297 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21298 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21299 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21300 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21301 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21302 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21303 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21304 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21305 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe9, 0x00, } ;
21306 --- /dev/null
21307 +++ b/drivers/staging/rt2870/common/md5.c
21308 @@ -0,0 +1,1427 @@
21309 +/*
21310 + *************************************************************************
21311 + * Ralink Tech Inc.
21312 + * 5F., No.36, Taiyuan St., Jhubei City,
21313 + * Hsinchu County 302,
21314 + * Taiwan, R.O.C.
21315 + *
21316 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
21317 + *
21318 + * This program is free software; you can redistribute it and/or modify *
21319 + * it under the terms of the GNU General Public License as published by *
21320 + * the Free Software Foundation; either version 2 of the License, or *
21321 + * (at your option) any later version. *
21322 + * *
21323 + * This program is distributed in the hope that it will be useful, *
21324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21326 + * GNU General Public License for more details. *
21327 + * *
21328 + * You should have received a copy of the GNU General Public License *
21329 + * along with this program; if not, write to the *
21330 + * Free Software Foundation, Inc., *
21331 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21332 + * *
21333 + *************************************************************************
21334 +
21335 + Module Name:
21336 + md5.c
21337 +
21338 + Abstract:
21339 +
21340 + Revision History:
21341 + Who When What
21342 + -------- ---------- ----------------------------------------------
21343 + Name Date Modification logs
21344 + jan 10-28-03 Initial
21345 + Rita 11-23-04 Modify MD5 and SHA-1
21346 + Rita 10-14-05 Modify SHA-1 in big-endian platform
21347 + */
21348 +#include "../rt_config.h"
21349 +
21350 +/**
21351 + * md5_mac:
21352 + * @key: pointer to the key used for MAC generation
21353 + * @key_len: length of the key in bytes
21354 + * @data: pointer to the data area for which the MAC is generated
21355 + * @data_len: length of the data in bytes
21356 + * @mac: pointer to the buffer holding space for the MAC; the buffer should
21357 + * have space for 128-bit (16 bytes) MD5 hash value
21358 + *
21359 + * md5_mac() determines the message authentication code by using secure hash
21360 + * MD5(key | data | key).
21361 + */
21362 +void md5_mac(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac)
21363 +{
21364 + MD5_CTX context;
21365 +
21366 + MD5Init(&context);
21367 + MD5Update(&context, key, key_len);
21368 + MD5Update(&context, data, data_len);
21369 + MD5Update(&context, key, key_len);
21370 + MD5Final(mac, &context);
21371 +}
21372 +
21373 +/**
21374 + * hmac_md5:
21375 + * @key: pointer to the key used for MAC generation
21376 + * @key_len: length of the key in bytes
21377 + * @data: pointer to the data area for which the MAC is generated
21378 + * @data_len: length of the data in bytes
21379 + * @mac: pointer to the buffer holding space for the MAC; the buffer should
21380 + * have space for 128-bit (16 bytes) MD5 hash value
21381 + *
21382 + * hmac_md5() determines the message authentication code using HMAC-MD5.
21383 + * This implementation is based on the sample code presented in RFC 2104.
21384 + */
21385 +void hmac_md5(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac)
21386 +{
21387 + MD5_CTX context;
21388 + u8 k_ipad[65]; /* inner padding - key XORd with ipad */
21389 + u8 k_opad[65]; /* outer padding - key XORd with opad */
21390 + u8 tk[16];
21391 + int i;
21392 +
21393 + //assert(key != NULL && data != NULL && mac != NULL);
21394 +
21395 + /* if key is longer than 64 bytes reset it to key = MD5(key) */
21396 + if (key_len > 64) {
21397 + MD5_CTX ttcontext;
21398 +
21399 + MD5Init(&ttcontext);
21400 + MD5Update(&ttcontext, key, key_len);
21401 + MD5Final(tk, &ttcontext);
21402 + //key=(PUCHAR)ttcontext.buf;
21403 + key = tk;
21404 + key_len = 16;
21405 + }
21406 +
21407 + /* the HMAC_MD5 transform looks like:
21408 + *
21409 + * MD5(K XOR opad, MD5(K XOR ipad, text))
21410 + *
21411 + * where K is an n byte key
21412 + * ipad is the byte 0x36 repeated 64 times
21413 + * opad is the byte 0x5c repeated 64 times
21414 + * and text is the data being protected */
21415 +
21416 + /* start out by storing key in pads */
21417 + NdisZeroMemory(k_ipad, sizeof(k_ipad));
21418 + NdisZeroMemory(k_opad, sizeof(k_opad));
21419 + //assert(key_len < sizeof(k_ipad));
21420 + NdisMoveMemory(k_ipad, key, key_len);
21421 + NdisMoveMemory(k_opad, key, key_len);
21422 +
21423 + /* XOR key with ipad and opad values */
21424 + for (i = 0; i < 64; i++) {
21425 + k_ipad[i] ^= 0x36;
21426 + k_opad[i] ^= 0x5c;
21427 + }
21428 +
21429 + /* perform inner MD5 */
21430 + MD5Init(&context); /* init context for 1st pass */
21431 + MD5Update(&context, k_ipad, 64); /* start with inner pad */
21432 + MD5Update(&context, data, data_len); /* then text of datagram */
21433 + MD5Final(mac, &context); /* finish up 1st pass */
21434 +
21435 + /* perform outer MD5 */
21436 + MD5Init(&context); /* init context for 2nd pass */
21437 + MD5Update(&context, k_opad, 64); /* start with outer pad */
21438 + MD5Update(&context, mac, 16); /* then results of 1st hash */
21439 + MD5Final(mac, &context); /* finish up 2nd pass */
21440 +}
21441 +
21442 +#ifndef RT_BIG_ENDIAN
21443 +#define byteReverse(buf, len) /* Nothing */
21444 +#else
21445 +void byteReverse(unsigned char *buf, unsigned longs);
21446 +void byteReverse(unsigned char *buf, unsigned longs)
21447 +{
21448 + do {
21449 + *(UINT32 *)buf = SWAP32(*(UINT32 *)buf);
21450 + buf += 4;
21451 + } while (--longs);
21452 +}
21453 +#endif
21454 +
21455 +
21456 +/* ========================== MD5 implementation =========================== */
21457 +// four base functions for MD5
21458 +#define MD5_F1(x, y, z) (((x) & (y)) | ((~x) & (z)))
21459 +#define MD5_F2(x, y, z) (((x) & (z)) | ((y) & (~z)))
21460 +#define MD5_F3(x, y, z) ((x) ^ (y) ^ (z))
21461 +#define MD5_F4(x, y, z) ((y) ^ ((x) | (~z)))
21462 +#define CYCLIC_LEFT_SHIFT(w, s) (((w) << (s)) | ((w) >> (32-(s))))
21463 +
21464 +#define MD5Step(f, w, x, y, z, data, t, s) \
21465 + ( w += f(x, y, z) + data + t, w = (CYCLIC_LEFT_SHIFT(w, s)) & 0xffffffff, w += x )
21466 +
21467 +
21468 +/*
21469 + * Function Description:
21470 + * Initiate MD5 Context satisfied in RFC 1321
21471 + *
21472 + * Arguments:
21473 + * pCtx Pointer to MD5 context
21474 + *
21475 + * Return Value:
21476 + * None
21477 + */
21478 +VOID MD5Init(MD5_CTX *pCtx)
21479 +{
21480 + pCtx->Buf[0]=0x67452301;
21481 + pCtx->Buf[1]=0xefcdab89;
21482 + pCtx->Buf[2]=0x98badcfe;
21483 + pCtx->Buf[3]=0x10325476;
21484 +
21485 + pCtx->LenInBitCount[0]=0;
21486 + pCtx->LenInBitCount[1]=0;
21487 +}
21488 +
21489 +
21490 +/*
21491 + * Function Description:
21492 + * Update MD5 Context, allow of an arrary of octets as the next portion
21493 + * of the message
21494 + *
21495 + * Arguments:
21496 + * pCtx Pointer to MD5 context
21497 + * pData Pointer to input data
21498 + * LenInBytes The length of input data (unit: byte)
21499 + *
21500 + * Return Value:
21501 + * None
21502 + *
21503 + * Note:
21504 + * Called after MD5Init or MD5Update(itself)
21505 + */
21506 +VOID MD5Update(MD5_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes)
21507 +{
21508 +
21509 + UINT32 TfTimes;
21510 + UINT32 temp;
21511 + unsigned int i;
21512 +
21513 + temp = pCtx->LenInBitCount[0];
21514 +
21515 + pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3));
21516 +
21517 + if (pCtx->LenInBitCount[0] < temp)
21518 + pCtx->LenInBitCount[1]++; //carry in
21519 +
21520 + pCtx->LenInBitCount[1] += LenInBytes >> 29;
21521 +
21522 + // mod 64 bytes
21523 + temp = (temp >> 3) & 0x3f;
21524 +
21525 + // process lacks of 64-byte data
21526 + if (temp)
21527 + {
21528 + UCHAR *pAds = (UCHAR *) pCtx->Input + temp;
21529 +
21530 + if ((temp+LenInBytes) < 64)
21531 + {
21532 + NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes);
21533 + return;
21534 + }
21535 +
21536 + NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp);
21537 + byteReverse(pCtx->Input, 16);
21538 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21539 +
21540 + pData += 64-temp;
21541 + LenInBytes -= 64-temp;
21542 + } // end of if (temp)
21543 +
21544 +
21545 + TfTimes = (LenInBytes >> 6);
21546 +
21547 + for (i=TfTimes; i>0; i--)
21548 + {
21549 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64);
21550 + byteReverse(pCtx->Input, 16);
21551 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21552 + pData += 64;
21553 + LenInBytes -= 64;
21554 + } // end of for
21555 +
21556 + // buffering lacks of 64-byte data
21557 + if(LenInBytes)
21558 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes);
21559 +
21560 +}
21561 +
21562 +
21563 +/*
21564 + * Function Description:
21565 + * Append padding bits and length of original message in the tail
21566 + * The message digest has to be completed in the end
21567 + *
21568 + * Arguments:
21569 + * Digest Output of Digest-Message for MD5
21570 + * pCtx Pointer to MD5 context
21571 + *
21572 + * Return Value:
21573 + * None
21574 + *
21575 + * Note:
21576 + * Called after MD5Update
21577 + */
21578 +VOID MD5Final(UCHAR Digest[16], MD5_CTX *pCtx)
21579 +{
21580 + UCHAR Remainder;
21581 + UCHAR PadLenInBytes;
21582 + UCHAR *pAppend=0;
21583 + unsigned int i;
21584 +
21585 + Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f);
21586 +
21587 + PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder);
21588 +
21589 + pAppend = (UCHAR *)pCtx->Input + Remainder;
21590 +
21591 + // padding bits without crossing block(64-byte based) boundary
21592 + if (Remainder < 56)
21593 + {
21594 + *pAppend = 0x80;
21595 + PadLenInBytes --;
21596 +
21597 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes);
21598 +
21599 + // add data-length field, from low to high
21600 + for (i=0; i<4; i++)
21601 + {
21602 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff);
21603 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff);
21604 + }
21605 +
21606 + byteReverse(pCtx->Input, 16);
21607 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21608 + } // end of if
21609 +
21610 + // padding bits with crossing block(64-byte based) boundary
21611 + else
21612 + {
21613 + // the first block ===
21614 + *pAppend = 0x80;
21615 + PadLenInBytes --;
21616 +
21617 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1));
21618 + PadLenInBytes -= (64 - Remainder - 1);
21619 +
21620 + byteReverse(pCtx->Input, 16);
21621 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21622 +
21623 +
21624 + // the second block ===
21625 + NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes);
21626 +
21627 + // add data-length field
21628 + for (i=0; i<4; i++)
21629 + {
21630 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff);
21631 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff);
21632 + }
21633 +
21634 + byteReverse(pCtx->Input, 16);
21635 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21636 + } // end of else
21637 +
21638 +
21639 + NdisMoveMemory((UCHAR *)Digest, (UINT32 *)pCtx->Buf, 16); // output
21640 + byteReverse((UCHAR *)Digest, 4);
21641 + NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free
21642 +}
21643 +
21644 +
21645 +/*
21646 + * Function Description:
21647 + * The central algorithm of MD5, consists of four rounds and sixteen
21648 + * steps per round
21649 + *
21650 + * Arguments:
21651 + * Buf Buffers of four states (output: 16 bytes)
21652 + * Mes Input data (input: 64 bytes)
21653 + *
21654 + * Return Value:
21655 + * None
21656 + *
21657 + * Note:
21658 + * Called by MD5Update or MD5Final
21659 + */
21660 +VOID MD5Transform(UINT32 Buf[4], UINT32 Mes[16])
21661 +{
21662 + UINT32 Reg[4], Temp;
21663 + unsigned int i;
21664 +
21665 + static UCHAR LShiftVal[16] =
21666 + {
21667 + 7, 12, 17, 22,
21668 + 5, 9 , 14, 20,
21669 + 4, 11, 16, 23,
21670 + 6, 10, 15, 21,
21671 + };
21672 +
21673 +
21674 + // [equal to 4294967296*abs(sin(index))]
21675 + static UINT32 MD5Table[64] =
21676 + {
21677 + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
21678 + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
21679 + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
21680 + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
21681 +
21682 + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
21683 + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
21684 + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
21685 + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
21686 +
21687 + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
21688 + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
21689 + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
21690 + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
21691 +
21692 + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
21693 + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
21694 + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
21695 + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
21696 + };
21697 +
21698 +
21699 + for (i=0; i<4; i++)
21700 + Reg[i]=Buf[i];
21701 +
21702 +
21703 + // 64 steps in MD5 algorithm
21704 + for (i=0; i<16; i++)
21705 + {
21706 + MD5Step(MD5_F1, Reg[0], Reg[1], Reg[2], Reg[3], Mes[i],
21707 + MD5Table[i], LShiftVal[i & 0x3]);
21708 +
21709 + // one-word right shift
21710 + Temp = Reg[3];
21711 + Reg[3] = Reg[2];
21712 + Reg[2] = Reg[1];
21713 + Reg[1] = Reg[0];
21714 + Reg[0] = Temp;
21715 + }
21716 + for (i=16; i<32; i++)
21717 + {
21718 + MD5Step(MD5_F2, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(5*(i & 0xf)+1) & 0xf],
21719 + MD5Table[i], LShiftVal[(0x1 << 2)+(i & 0x3)]);
21720 +
21721 + // one-word right shift
21722 + Temp = Reg[3];
21723 + Reg[3] = Reg[2];
21724 + Reg[2] = Reg[1];
21725 + Reg[1] = Reg[0];
21726 + Reg[0] = Temp;
21727 + }
21728 + for (i=32; i<48; i++)
21729 + {
21730 + MD5Step(MD5_F3, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(3*(i & 0xf)+5) & 0xf],
21731 + MD5Table[i], LShiftVal[(0x1 << 3)+(i & 0x3)]);
21732 +
21733 + // one-word right shift
21734 + Temp = Reg[3];
21735 + Reg[3] = Reg[2];
21736 + Reg[2] = Reg[1];
21737 + Reg[1] = Reg[0];
21738 + Reg[0] = Temp;
21739 + }
21740 + for (i=48; i<64; i++)
21741 + {
21742 + MD5Step(MD5_F4, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(7*(i & 0xf)) & 0xf],
21743 + MD5Table[i], LShiftVal[(0x3 << 2)+(i & 0x3)]);
21744 +
21745 + // one-word right shift
21746 + Temp = Reg[3];
21747 + Reg[3] = Reg[2];
21748 + Reg[2] = Reg[1];
21749 + Reg[1] = Reg[0];
21750 + Reg[0] = Temp;
21751 + }
21752 +
21753 +
21754 + // (temporary)output
21755 + for (i=0; i<4; i++)
21756 + Buf[i] += Reg[i];
21757 +
21758 +}
21759 +
21760 +
21761 +
21762 +/* ========================= SHA-1 implementation ========================== */
21763 +// four base functions for SHA-1
21764 +#define SHA1_F1(b, c, d) (((b) & (c)) | ((~b) & (d)))
21765 +#define SHA1_F2(b, c, d) ((b) ^ (c) ^ (d))
21766 +#define SHA1_F3(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
21767 +
21768 +
21769 +#define SHA1Step(f, a, b, c, d, e, w, k) \
21770 + ( e += ( f(b, c, d) + w + k + CYCLIC_LEFT_SHIFT(a, 5)) & 0xffffffff, \
21771 + b = CYCLIC_LEFT_SHIFT(b, 30) )
21772 +
21773 +//Initiate SHA-1 Context satisfied in RFC 3174
21774 +VOID SHAInit(SHA_CTX *pCtx)
21775 +{
21776 + pCtx->Buf[0]=0x67452301;
21777 + pCtx->Buf[1]=0xefcdab89;
21778 + pCtx->Buf[2]=0x98badcfe;
21779 + pCtx->Buf[3]=0x10325476;
21780 + pCtx->Buf[4]=0xc3d2e1f0;
21781 +
21782 + pCtx->LenInBitCount[0]=0;
21783 + pCtx->LenInBitCount[1]=0;
21784 +}
21785 +
21786 +/*
21787 + * Function Description:
21788 + * Update SHA-1 Context, allow of an arrary of octets as the next
21789 + * portion of the message
21790 + *
21791 + * Arguments:
21792 + * pCtx Pointer to SHA-1 context
21793 + * pData Pointer to input data
21794 + * LenInBytes The length of input data (unit: byte)
21795 + *
21796 + * Return Value:
21797 + * error indicate more than pow(2,64) bits of data
21798 + *
21799 + * Note:
21800 + * Called after SHAInit or SHAUpdate(itself)
21801 + */
21802 +UCHAR SHAUpdate(SHA_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes)
21803 +{
21804 + UINT32 TfTimes;
21805 + UINT32 temp1,temp2;
21806 + unsigned int i;
21807 + UCHAR err=1;
21808 +
21809 + temp1 = pCtx->LenInBitCount[0];
21810 + temp2 = pCtx->LenInBitCount[1];
21811 +
21812 + pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3));
21813 + if (pCtx->LenInBitCount[0] < temp1)
21814 + pCtx->LenInBitCount[1]++; //carry in
21815 +
21816 +
21817 + pCtx->LenInBitCount[1] = (UINT32) (pCtx->LenInBitCount[1] +(LenInBytes >> 29));
21818 + if (pCtx->LenInBitCount[1] < temp2)
21819 + return (err); //check total length of original data
21820 +
21821 +
21822 + // mod 64 bytes
21823 + temp1 = (temp1 >> 3) & 0x3f;
21824 +
21825 + // process lacks of 64-byte data
21826 + if (temp1)
21827 + {
21828 + UCHAR *pAds = (UCHAR *) pCtx->Input + temp1;
21829 +
21830 + if ((temp1+LenInBytes) < 64)
21831 + {
21832 + NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes);
21833 + return (0);
21834 + }
21835 +
21836 + NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp1);
21837 + byteReverse((UCHAR *)pCtx->Input, 16);
21838 +
21839 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
21840 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
21841 +
21842 + pData += 64-temp1;
21843 + LenInBytes -= 64-temp1;
21844 + } // end of if (temp1)
21845 +
21846 +
21847 + TfTimes = (LenInBytes >> 6);
21848 +
21849 + for (i=TfTimes; i>0; i--)
21850 + {
21851 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64);
21852 + byteReverse((UCHAR *)pCtx->Input, 16);
21853 +
21854 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
21855 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
21856 + pData += 64;
21857 + LenInBytes -= 64;
21858 + } // end of for
21859 +
21860 + // buffering lacks of 64-byte data
21861 + if(LenInBytes)
21862 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes);
21863 +
21864 + return (0);
21865 +
21866 +}
21867 +
21868 +// Append padding bits and length of original message in the tail
21869 +// The message digest has to be completed in the end
21870 +VOID SHAFinal(SHA_CTX *pCtx, UCHAR Digest[20])
21871 +{
21872 + UCHAR Remainder;
21873 + UCHAR PadLenInBytes;
21874 + UCHAR *pAppend=0;
21875 + unsigned int i;
21876 +
21877 + Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f);
21878 +
21879 + pAppend = (UCHAR *)pCtx->Input + Remainder;
21880 +
21881 + PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder);
21882 +
21883 + // padding bits without crossing block(64-byte based) boundary
21884 + if (Remainder < 56)
21885 + {
21886 + *pAppend = 0x80;
21887 + PadLenInBytes --;
21888 +
21889 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes);
21890 +
21891 + // add data-length field, from high to low
21892 + for (i=0; i<4; i++)
21893 + {
21894 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff);
21895 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff);
21896 + }
21897 +
21898 + byteReverse((UCHAR *)pCtx->Input, 16);
21899 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 14);
21900 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
21901 + } // end of if
21902 +
21903 + // padding bits with crossing block(64-byte based) boundary
21904 + else
21905 + {
21906 + // the first block ===
21907 + *pAppend = 0x80;
21908 + PadLenInBytes --;
21909 +
21910 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1));
21911 + PadLenInBytes -= (64 - Remainder - 1);
21912 +
21913 + byteReverse((UCHAR *)pCtx->Input, 16);
21914 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
21915 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
21916 +
21917 +
21918 + // the second block ===
21919 + NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes);
21920 +
21921 + // add data-length field
21922 + for (i=0; i<4; i++)
21923 + {
21924 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff);
21925 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff);
21926 + }
21927 +
21928 + byteReverse((UCHAR *)pCtx->Input, 16);
21929 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
21930 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
21931 + } // end of else
21932 +
21933 +
21934 + //Output, bytereverse
21935 + for (i=0; i<20; i++)
21936 + {
21937 + Digest [i] = (UCHAR)(pCtx->Buf[i>>2] >> 8*(3-(i & 0x3)));
21938 + }
21939 +
21940 + NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free
21941 +}
21942 +
21943 +
21944 +// The central algorithm of SHA-1, consists of four rounds and
21945 +// twenty steps per round
21946 +VOID SHATransform(UINT32 Buf[5], UINT32 Mes[20])
21947 +{
21948 + UINT32 Reg[5],Temp;
21949 + unsigned int i;
21950 + UINT32 W[80];
21951 +
21952 + static UINT32 SHA1Table[4] = { 0x5a827999, 0x6ed9eba1,
21953 + 0x8f1bbcdc, 0xca62c1d6 };
21954 +
21955 + Reg[0]=Buf[0];
21956 + Reg[1]=Buf[1];
21957 + Reg[2]=Buf[2];
21958 + Reg[3]=Buf[3];
21959 + Reg[4]=Buf[4];
21960 +
21961 + //the first octet of a word is stored in the 0th element, bytereverse
21962 + for(i = 0; i < 16; i++)
21963 + {
21964 + W[i] = (Mes[i] >> 24) & 0xff;
21965 + W[i] |= (Mes[i] >> 8 ) & 0xff00;
21966 + W[i] |= (Mes[i] << 8 ) & 0xff0000;
21967 + W[i] |= (Mes[i] << 24) & 0xff000000;
21968 + }
21969 +
21970 +
21971 + for (i = 0; i < 64; i++)
21972 + W[16+i] = CYCLIC_LEFT_SHIFT(W[i] ^ W[2+i] ^ W[8+i] ^ W[13+i], 1);
21973 +
21974 +
21975 + // 80 steps in SHA-1 algorithm
21976 + for (i=0; i<80; i++)
21977 + {
21978 + if (i<20)
21979 + SHA1Step(SHA1_F1, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
21980 + W[i], SHA1Table[0]);
21981 +
21982 + else if (i>=20 && i<40)
21983 + SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
21984 + W[i], SHA1Table[1]);
21985 +
21986 + else if (i>=40 && i<60)
21987 + SHA1Step(SHA1_F3, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
21988 + W[i], SHA1Table[2]);
21989 +
21990 + else
21991 + SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
21992 + W[i], SHA1Table[3]);
21993 +
21994 +
21995 + // one-word right shift
21996 + Temp = Reg[4];
21997 + Reg[4] = Reg[3];
21998 + Reg[3] = Reg[2];
21999 + Reg[2] = Reg[1];
22000 + Reg[1] = Reg[0];
22001 + Reg[0] = Temp;
22002 +
22003 + } // end of for-loop
22004 +
22005 +
22006 + // (temporary)output
22007 + for (i=0; i<5; i++)
22008 + Buf[i] += Reg[i];
22009 +
22010 +}
22011 +
22012 +
22013 +/* ========================= AES En/Decryption ========================== */
22014 +
22015 +/* forward S-box */
22016 +static uint32 FSb[256] =
22017 +{
22018 + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
22019 + 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
22020 + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
22021 + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
22022 + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
22023 + 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
22024 + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
22025 + 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
22026 + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
22027 + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
22028 + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
22029 + 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
22030 + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
22031 + 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
22032 + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
22033 + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
22034 + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
22035 + 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
22036 + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
22037 + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
22038 + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
22039 + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
22040 + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
22041 + 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
22042 + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
22043 + 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
22044 + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
22045 + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
22046 + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
22047 + 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
22048 + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
22049 + 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
22050 +};
22051 +
22052 +/* forward table */
22053 +#define FT \
22054 +\
22055 + V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \
22056 + V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \
22057 + V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \
22058 + V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \
22059 + V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \
22060 + V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \
22061 + V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \
22062 + V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \
22063 + V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \
22064 + V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \
22065 + V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \
22066 + V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \
22067 + V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \
22068 + V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \
22069 + V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \
22070 + V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \
22071 + V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \
22072 + V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \
22073 + V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \
22074 + V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \
22075 + V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \
22076 + V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \
22077 + V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \
22078 + V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \
22079 + V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \
22080 + V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \
22081 + V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \
22082 + V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \
22083 + V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \
22084 + V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \
22085 + V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \
22086 + V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \
22087 + V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \
22088 + V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \
22089 + V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \
22090 + V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \
22091 + V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \
22092 + V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \
22093 + V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \
22094 + V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \
22095 + V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \
22096 + V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \
22097 + V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \
22098 + V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \
22099 + V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \
22100 + V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \
22101 + V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \
22102 + V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \
22103 + V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \
22104 + V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \
22105 + V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \
22106 + V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \
22107 + V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \
22108 + V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \
22109 + V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \
22110 + V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \
22111 + V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \
22112 + V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \
22113 + V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \
22114 + V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \
22115 + V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \
22116 + V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \
22117 + V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \
22118 + V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A)
22119 +
22120 +#define V(a,b,c,d) 0x##a##b##c##d
22121 +static uint32 FT0[256] = { FT };
22122 +#undef V
22123 +
22124 +#define V(a,b,c,d) 0x##d##a##b##c
22125 +static uint32 FT1[256] = { FT };
22126 +#undef V
22127 +
22128 +#define V(a,b,c,d) 0x##c##d##a##b
22129 +static uint32 FT2[256] = { FT };
22130 +#undef V
22131 +
22132 +#define V(a,b,c,d) 0x##b##c##d##a
22133 +static uint32 FT3[256] = { FT };
22134 +#undef V
22135 +
22136 +#undef FT
22137 +
22138 +/* reverse S-box */
22139 +
22140 +static uint32 RSb[256] =
22141 +{
22142 + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
22143 + 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
22144 + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
22145 + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
22146 + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
22147 + 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
22148 + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
22149 + 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
22150 + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
22151 + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
22152 + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
22153 + 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
22154 + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
22155 + 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
22156 + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
22157 + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
22158 + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
22159 + 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
22160 + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
22161 + 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
22162 + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
22163 + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
22164 + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
22165 + 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
22166 + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
22167 + 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
22168 + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
22169 + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
22170 + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
22171 + 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
22172 + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
22173 + 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
22174 +};
22175 +
22176 +/* reverse table */
22177 +
22178 +#define RT \
22179 +\
22180 + V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \
22181 + V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \
22182 + V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \
22183 + V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \
22184 + V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \
22185 + V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \
22186 + V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \
22187 + V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \
22188 + V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \
22189 + V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \
22190 + V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \
22191 + V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \
22192 + V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \
22193 + V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \
22194 + V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \
22195 + V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \
22196 + V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \
22197 + V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \
22198 + V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \
22199 + V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \
22200 + V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \
22201 + V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \
22202 + V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \
22203 + V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \
22204 + V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \
22205 + V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \
22206 + V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \
22207 + V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \
22208 + V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \
22209 + V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \
22210 + V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \
22211 + V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \
22212 + V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \
22213 + V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \
22214 + V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \
22215 + V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \
22216 + V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \
22217 + V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \
22218 + V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \
22219 + V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \
22220 + V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \
22221 + V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \
22222 + V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \
22223 + V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \
22224 + V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \
22225 + V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \
22226 + V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \
22227 + V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \
22228 + V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \
22229 + V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \
22230 + V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \
22231 + V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \
22232 + V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \
22233 + V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \
22234 + V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \
22235 + V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \
22236 + V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \
22237 + V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \
22238 + V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \
22239 + V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \
22240 + V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \
22241 + V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \
22242 + V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \
22243 + V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42)
22244 +
22245 +#define V(a,b,c,d) 0x##a##b##c##d
22246 +static uint32 RT0[256] = { RT };
22247 +#undef V
22248 +
22249 +#define V(a,b,c,d) 0x##d##a##b##c
22250 +static uint32 RT1[256] = { RT };
22251 +#undef V
22252 +
22253 +#define V(a,b,c,d) 0x##c##d##a##b
22254 +static uint32 RT2[256] = { RT };
22255 +#undef V
22256 +
22257 +#define V(a,b,c,d) 0x##b##c##d##a
22258 +static uint32 RT3[256] = { RT };
22259 +#undef V
22260 +
22261 +#undef RT
22262 +
22263 +/* round constants */
22264 +
22265 +static uint32 RCON[10] =
22266 +{
22267 + 0x01000000, 0x02000000, 0x04000000, 0x08000000,
22268 + 0x10000000, 0x20000000, 0x40000000, 0x80000000,
22269 + 0x1B000000, 0x36000000
22270 +};
22271 +
22272 +/* key schedule tables */
22273 +
22274 +static int KT_init = 1;
22275 +
22276 +static uint32 KT0[256];
22277 +static uint32 KT1[256];
22278 +static uint32 KT2[256];
22279 +static uint32 KT3[256];
22280 +
22281 +/* platform-independant 32-bit integer manipulation macros */
22282 +
22283 +#define GET_UINT32(n,b,i) \
22284 +{ \
22285 + (n) = ( (uint32) (b)[(i) ] << 24 ) \
22286 + | ( (uint32) (b)[(i) + 1] << 16 ) \
22287 + | ( (uint32) (b)[(i) + 2] << 8 ) \
22288 + | ( (uint32) (b)[(i) + 3] ); \
22289 +}
22290 +
22291 +#define PUT_UINT32(n,b,i) \
22292 +{ \
22293 + (b)[(i) ] = (uint8) ( (n) >> 24 ); \
22294 + (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
22295 + (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
22296 + (b)[(i) + 3] = (uint8) ( (n) ); \
22297 +}
22298 +
22299 +/* AES key scheduling routine */
22300 +
22301 +int rtmp_aes_set_key( aes_context *ctx, uint8 *key, int nbits )
22302 +{
22303 + int i;
22304 + uint32 *RK, *SK;
22305 +
22306 + switch( nbits )
22307 + {
22308 + case 128: ctx->nr = 10; break;
22309 + case 192: ctx->nr = 12; break;
22310 + case 256: ctx->nr = 14; break;
22311 + default : return( 1 );
22312 + }
22313 +
22314 + RK = ctx->erk;
22315 +
22316 + for( i = 0; i < (nbits >> 5); i++ )
22317 + {
22318 + GET_UINT32( RK[i], key, i * 4 );
22319 + }
22320 +
22321 + /* setup encryption round keys */
22322 +
22323 + switch( nbits )
22324 + {
22325 + case 128:
22326 +
22327 + for( i = 0; i < 10; i++, RK += 4 )
22328 + {
22329 + RK[4] = RK[0] ^ RCON[i] ^
22330 + ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^
22331 + ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^
22332 + ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^
22333 + ( FSb[ (uint8) ( RK[3] >> 24 ) ] );
22334 +
22335 + RK[5] = RK[1] ^ RK[4];
22336 + RK[6] = RK[2] ^ RK[5];
22337 + RK[7] = RK[3] ^ RK[6];
22338 + }
22339 + break;
22340 +
22341 + case 192:
22342 +
22343 + for( i = 0; i < 8; i++, RK += 6 )
22344 + {
22345 + RK[6] = RK[0] ^ RCON[i] ^
22346 + ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^
22347 + ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^
22348 + ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^
22349 + ( FSb[ (uint8) ( RK[5] >> 24 ) ] );
22350 +
22351 + RK[7] = RK[1] ^ RK[6];
22352 + RK[8] = RK[2] ^ RK[7];
22353 + RK[9] = RK[3] ^ RK[8];
22354 + RK[10] = RK[4] ^ RK[9];
22355 + RK[11] = RK[5] ^ RK[10];
22356 + }
22357 + break;
22358 +
22359 + case 256:
22360 +
22361 + for( i = 0; i < 7; i++, RK += 8 )
22362 + {
22363 + RK[8] = RK[0] ^ RCON[i] ^
22364 + ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^
22365 + ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^
22366 + ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^
22367 + ( FSb[ (uint8) ( RK[7] >> 24 ) ] );
22368 +
22369 + RK[9] = RK[1] ^ RK[8];
22370 + RK[10] = RK[2] ^ RK[9];
22371 + RK[11] = RK[3] ^ RK[10];
22372 +
22373 + RK[12] = RK[4] ^
22374 + ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^
22375 + ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^
22376 + ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^
22377 + ( FSb[ (uint8) ( RK[11] ) ] );
22378 +
22379 + RK[13] = RK[5] ^ RK[12];
22380 + RK[14] = RK[6] ^ RK[13];
22381 + RK[15] = RK[7] ^ RK[14];
22382 + }
22383 + break;
22384 + }
22385 +
22386 + /* setup decryption round keys */
22387 +
22388 + if( KT_init )
22389 + {
22390 + for( i = 0; i < 256; i++ )
22391 + {
22392 + KT0[i] = RT0[ FSb[i] ];
22393 + KT1[i] = RT1[ FSb[i] ];
22394 + KT2[i] = RT2[ FSb[i] ];
22395 + KT3[i] = RT3[ FSb[i] ];
22396 + }
22397 +
22398 + KT_init = 0;
22399 + }
22400 +
22401 + SK = ctx->drk;
22402 +
22403 + *SK++ = *RK++;
22404 + *SK++ = *RK++;
22405 + *SK++ = *RK++;
22406 + *SK++ = *RK++;
22407 +
22408 + for( i = 1; i < ctx->nr; i++ )
22409 + {
22410 + RK -= 8;
22411 +
22412 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22413 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22414 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22415 + KT3[ (uint8) ( *RK ) ]; RK++;
22416 +
22417 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22418 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22419 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22420 + KT3[ (uint8) ( *RK ) ]; RK++;
22421 +
22422 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22423 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22424 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22425 + KT3[ (uint8) ( *RK ) ]; RK++;
22426 +
22427 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22428 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22429 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22430 + KT3[ (uint8) ( *RK ) ]; RK++;
22431 + }
22432 +
22433 + RK -= 8;
22434 +
22435 + *SK++ = *RK++;
22436 + *SK++ = *RK++;
22437 + *SK++ = *RK++;
22438 + *SK++ = *RK++;
22439 +
22440 + return( 0 );
22441 +}
22442 +
22443 +/* AES 128-bit block encryption routine */
22444 +
22445 +void rtmp_aes_encrypt(aes_context *ctx, uint8 input[16], uint8 output[16] )
22446 +{
22447 + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
22448 +
22449 + RK = ctx->erk;
22450 + GET_UINT32( X0, input, 0 ); X0 ^= RK[0];
22451 + GET_UINT32( X1, input, 4 ); X1 ^= RK[1];
22452 + GET_UINT32( X2, input, 8 ); X2 ^= RK[2];
22453 + GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
22454 +
22455 +#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
22456 +{ \
22457 + RK += 4; \
22458 + \
22459 + X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \
22460 + FT1[ (uint8) ( Y1 >> 16 ) ] ^ \
22461 + FT2[ (uint8) ( Y2 >> 8 ) ] ^ \
22462 + FT3[ (uint8) ( Y3 ) ]; \
22463 + \
22464 + X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \
22465 + FT1[ (uint8) ( Y2 >> 16 ) ] ^ \
22466 + FT2[ (uint8) ( Y3 >> 8 ) ] ^ \
22467 + FT3[ (uint8) ( Y0 ) ]; \
22468 + \
22469 + X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \
22470 + FT1[ (uint8) ( Y3 >> 16 ) ] ^ \
22471 + FT2[ (uint8) ( Y0 >> 8 ) ] ^ \
22472 + FT3[ (uint8) ( Y1 ) ]; \
22473 + \
22474 + X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \
22475 + FT1[ (uint8) ( Y0 >> 16 ) ] ^ \
22476 + FT2[ (uint8) ( Y1 >> 8 ) ] ^ \
22477 + FT3[ (uint8) ( Y2 ) ]; \
22478 +}
22479 +
22480 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */
22481 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */
22482 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */
22483 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */
22484 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */
22485 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */
22486 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */
22487 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */
22488 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */
22489 +
22490 + if( ctx->nr > 10 )
22491 + {
22492 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */
22493 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */
22494 + }
22495 +
22496 + if( ctx->nr > 12 )
22497 + {
22498 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */
22499 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */
22500 + }
22501 +
22502 + /* last round */
22503 +
22504 + RK += 4;
22505 +
22506 + X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
22507 + ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
22508 + ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
22509 + ( FSb[ (uint8) ( Y3 ) ] );
22510 +
22511 + X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
22512 + ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
22513 + ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
22514 + ( FSb[ (uint8) ( Y0 ) ] );
22515 +
22516 + X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
22517 + ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
22518 + ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
22519 + ( FSb[ (uint8) ( Y1 ) ] );
22520 +
22521 + X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
22522 + ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
22523 + ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
22524 + ( FSb[ (uint8) ( Y2 ) ] );
22525 +
22526 + PUT_UINT32( X0, output, 0 );
22527 + PUT_UINT32( X1, output, 4 );
22528 + PUT_UINT32( X2, output, 8 );
22529 + PUT_UINT32( X3, output, 12 );
22530 +}
22531 +
22532 +/* AES 128-bit block decryption routine */
22533 +
22534 +void rtmp_aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] )
22535 +{
22536 + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
22537 +
22538 + RK = ctx->drk;
22539 +
22540 + GET_UINT32( X0, input, 0 ); X0 ^= RK[0];
22541 + GET_UINT32( X1, input, 4 ); X1 ^= RK[1];
22542 + GET_UINT32( X2, input, 8 ); X2 ^= RK[2];
22543 + GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
22544 +
22545 +#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
22546 +{ \
22547 + RK += 4; \
22548 + \
22549 + X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \
22550 + RT1[ (uint8) ( Y3 >> 16 ) ] ^ \
22551 + RT2[ (uint8) ( Y2 >> 8 ) ] ^ \
22552 + RT3[ (uint8) ( Y1 ) ]; \
22553 + \
22554 + X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \
22555 + RT1[ (uint8) ( Y0 >> 16 ) ] ^ \
22556 + RT2[ (uint8) ( Y3 >> 8 ) ] ^ \
22557 + RT3[ (uint8) ( Y2 ) ]; \
22558 + \
22559 + X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \
22560 + RT1[ (uint8) ( Y1 >> 16 ) ] ^ \
22561 + RT2[ (uint8) ( Y0 >> 8 ) ] ^ \
22562 + RT3[ (uint8) ( Y3 ) ]; \
22563 + \
22564 + X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \
22565 + RT1[ (uint8) ( Y2 >> 16 ) ] ^ \
22566 + RT2[ (uint8) ( Y1 >> 8 ) ] ^ \
22567 + RT3[ (uint8) ( Y0 ) ]; \
22568 +}
22569 +
22570 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */
22571 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */
22572 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */
22573 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */
22574 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */
22575 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */
22576 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */
22577 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */
22578 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */
22579 +
22580 + if( ctx->nr > 10 )
22581 + {
22582 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */
22583 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */
22584 + }
22585 +
22586 + if( ctx->nr > 12 )
22587 + {
22588 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */
22589 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */
22590 + }
22591 +
22592 + /* last round */
22593 +
22594 + RK += 4;
22595 +
22596 + X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
22597 + ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
22598 + ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
22599 + ( RSb[ (uint8) ( Y1 ) ] );
22600 +
22601 + X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
22602 + ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
22603 + ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
22604 + ( RSb[ (uint8) ( Y2 ) ] );
22605 +
22606 + X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
22607 + ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
22608 + ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
22609 + ( RSb[ (uint8) ( Y3 ) ] );
22610 +
22611 + X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
22612 + ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
22613 + ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
22614 + ( RSb[ (uint8) ( Y0 ) ] );
22615 +
22616 + PUT_UINT32( X0, output, 0 );
22617 + PUT_UINT32( X1, output, 4 );
22618 + PUT_UINT32( X2, output, 8 );
22619 + PUT_UINT32( X3, output, 12 );
22620 +}
22621 +
22622 +/*
22623 + ========================================================================
22624 +
22625 + Routine Description:
22626 + SHA1 function
22627 +
22628 + Arguments:
22629 +
22630 + Return Value:
22631 +
22632 + Note:
22633 +
22634 + ========================================================================
22635 +*/
22636 +VOID HMAC_SHA1(
22637 + IN UCHAR *text,
22638 + IN UINT text_len,
22639 + IN UCHAR *key,
22640 + IN UINT key_len,
22641 + IN UCHAR *digest)
22642 +{
22643 + SHA_CTX context;
22644 + UCHAR k_ipad[65]; /* inner padding - key XORd with ipad */
22645 + UCHAR k_opad[65]; /* outer padding - key XORd with opad */
22646 + INT i;
22647 +
22648 + // if key is longer than 64 bytes reset it to key=SHA1(key)
22649 + if (key_len > 64)
22650 + {
22651 + SHA_CTX tctx;
22652 + SHAInit(&tctx);
22653 + SHAUpdate(&tctx, key, key_len);
22654 + SHAFinal(&tctx, key);
22655 + key_len = 20;
22656 + }
22657 + NdisZeroMemory(k_ipad, sizeof(k_ipad));
22658 + NdisZeroMemory(k_opad, sizeof(k_opad));
22659 + NdisMoveMemory(k_ipad, key, key_len);
22660 + NdisMoveMemory(k_opad, key, key_len);
22661 +
22662 + // XOR key with ipad and opad values
22663 + for (i = 0; i < 64; i++)
22664 + {
22665 + k_ipad[i] ^= 0x36;
22666 + k_opad[i] ^= 0x5c;
22667 + }
22668 +
22669 + // perform inner SHA1
22670 + SHAInit(&context); /* init context for 1st pass */
22671 + SHAUpdate(&context, k_ipad, 64); /* start with inner pad */
22672 + SHAUpdate(&context, text, text_len); /* then text of datagram */
22673 + SHAFinal(&context, digest); /* finish up 1st pass */
22674 +
22675 + //perform outer SHA1
22676 + SHAInit(&context); /* init context for 2nd pass */
22677 + SHAUpdate(&context, k_opad, 64); /* start with outer pad */
22678 + SHAUpdate(&context, digest, 20); /* then results of 1st hash */
22679 + SHAFinal(&context, digest); /* finish up 2nd pass */
22680 +
22681 +}
22682 +
22683 +/*
22684 +* F(P, S, c, i) = U1 xor U2 xor ... Uc
22685 +* U1 = PRF(P, S || Int(i))
22686 +* U2 = PRF(P, U1)
22687 +* Uc = PRF(P, Uc-1)
22688 +*/
22689 +
22690 +void F(char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output)
22691 +{
22692 + unsigned char digest[36], digest1[SHA_DIGEST_LEN];
22693 + int i, j;
22694 +
22695 + /* U1 = PRF(P, S || int(i)) */
22696 + memcpy(digest, ssid, ssidlength);
22697 + digest[ssidlength] = (unsigned char)((count>>24) & 0xff);
22698 + digest[ssidlength+1] = (unsigned char)((count>>16) & 0xff);
22699 + digest[ssidlength+2] = (unsigned char)((count>>8) & 0xff);
22700 + digest[ssidlength+3] = (unsigned char)(count & 0xff);
22701 + HMAC_SHA1(digest, ssidlength+4, (unsigned char*) password, (int) strlen(password), digest1); // for WPA update
22702 +
22703 + /* output = U1 */
22704 + memcpy(output, digest1, SHA_DIGEST_LEN);
22705 +
22706 + for (i = 1; i < iterations; i++)
22707 + {
22708 + /* Un = PRF(P, Un-1) */
22709 + HMAC_SHA1(digest1, SHA_DIGEST_LEN, (unsigned char*) password, (int) strlen(password), digest); // for WPA update
22710 + memcpy(digest1, digest, SHA_DIGEST_LEN);
22711 +
22712 + /* output = output xor Un */
22713 + for (j = 0; j < SHA_DIGEST_LEN; j++)
22714 + {
22715 + output[j] ^= digest[j];
22716 + }
22717 + }
22718 +}
22719 +/*
22720 +* password - ascii string up to 63 characters in length
22721 +* ssid - octet string up to 32 octets
22722 +* ssidlength - length of ssid in octets
22723 +* output must be 40 octets in length and outputs 256 bits of key
22724 +*/
22725 +int PasswordHash(char *password, unsigned char *ssid, int ssidlength, unsigned char *output)
22726 +{
22727 + if ((strlen(password) > 63) || (ssidlength > 32))
22728 + return 0;
22729 +
22730 + F(password, ssid, ssidlength, 4096, 1, output);
22731 + F(password, ssid, ssidlength, 4096, 2, &output[SHA_DIGEST_LEN]);
22732 + return 1;
22733 +}
22734 +
22735 +
22736 --- /dev/null
22737 +++ b/drivers/staging/rt2870/common/mlme.c
22738 @@ -0,0 +1,8609 @@
22739 +/*
22740 + *************************************************************************
22741 + * Ralink Tech Inc.
22742 + * 5F., No.36, Taiyuan St., Jhubei City,
22743 + * Hsinchu County 302,
22744 + * Taiwan, R.O.C.
22745 + *
22746 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
22747 + *
22748 + * This program is free software; you can redistribute it and/or modify *
22749 + * it under the terms of the GNU General Public License as published by *
22750 + * the Free Software Foundation; either version 2 of the License, or *
22751 + * (at your option) any later version. *
22752 + * *
22753 + * This program is distributed in the hope that it will be useful, *
22754 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22755 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22756 + * GNU General Public License for more details. *
22757 + * *
22758 + * You should have received a copy of the GNU General Public License *
22759 + * along with this program; if not, write to the *
22760 + * Free Software Foundation, Inc., *
22761 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22762 + * *
22763 + *************************************************************************
22764 +
22765 + Module Name:
22766 + mlme.c
22767 +
22768 + Abstract:
22769 +
22770 + Revision History:
22771 + Who When What
22772 + -------- ---------- ----------------------------------------------
22773 + John Chang 2004-08-25 Modify from RT2500 code base
22774 + John Chang 2004-09-06 modified for RT2600
22775 +*/
22776 +
22777 +#include "../rt_config.h"
22778 +#include <stdarg.h>
22779 +
22780 +UCHAR CISCO_OUI[] = {0x00, 0x40, 0x96};
22781 +
22782 +UCHAR WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
22783 +UCHAR RSN_OUI[] = {0x00, 0x0f, 0xac};
22784 +UCHAR WAPI_OUI[] = {0x00, 0x14, 0x72};
22785 +UCHAR WME_INFO_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
22786 +UCHAR WME_PARM_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
22787 +UCHAR Ccx2QosInfo[] = {0x00, 0x40, 0x96, 0x04};
22788 +UCHAR RALINK_OUI[] = {0x00, 0x0c, 0x43};
22789 +UCHAR BROADCOM_OUI[] = {0x00, 0x90, 0x4c};
22790 +UCHAR WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
22791 +#ifdef CONFIG_STA_SUPPORT
22792 +#ifdef DOT11_N_SUPPORT
22793 +UCHAR PRE_N_HT_OUI[] = {0x00, 0x90, 0x4c};
22794 +#endif // DOT11_N_SUPPORT //
22795 +#endif // CONFIG_STA_SUPPORT //
22796 +
22797 +UCHAR RateSwitchTable[] = {
22798 +// 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)
22799 + 0x11, 0x00, 0, 0, 0, // Initial used item after association
22800 + 0x00, 0x00, 0, 40, 101,
22801 + 0x01, 0x00, 1, 40, 50,
22802 + 0x02, 0x00, 2, 35, 45,
22803 + 0x03, 0x00, 3, 20, 45,
22804 + 0x04, 0x21, 0, 30, 50,
22805 + 0x05, 0x21, 1, 20, 50,
22806 + 0x06, 0x21, 2, 20, 50,
22807 + 0x07, 0x21, 3, 15, 50,
22808 + 0x08, 0x21, 4, 15, 30,
22809 + 0x09, 0x21, 5, 10, 25,
22810 + 0x0a, 0x21, 6, 8, 25,
22811 + 0x0b, 0x21, 7, 8, 25,
22812 + 0x0c, 0x20, 12, 15, 30,
22813 + 0x0d, 0x20, 13, 8, 20,
22814 + 0x0e, 0x20, 14, 8, 20,
22815 + 0x0f, 0x20, 15, 8, 25,
22816 + 0x10, 0x22, 15, 8, 25,
22817 + 0x11, 0x00, 0, 0, 0,
22818 + 0x12, 0x00, 0, 0, 0,
22819 + 0x13, 0x00, 0, 0, 0,
22820 + 0x14, 0x00, 0, 0, 0,
22821 + 0x15, 0x00, 0, 0, 0,
22822 + 0x16, 0x00, 0, 0, 0,
22823 + 0x17, 0x00, 0, 0, 0,
22824 + 0x18, 0x00, 0, 0, 0,
22825 + 0x19, 0x00, 0, 0, 0,
22826 + 0x1a, 0x00, 0, 0, 0,
22827 + 0x1b, 0x00, 0, 0, 0,
22828 + 0x1c, 0x00, 0, 0, 0,
22829 + 0x1d, 0x00, 0, 0, 0,
22830 + 0x1e, 0x00, 0, 0, 0,
22831 + 0x1f, 0x00, 0, 0, 0,
22832 +};
22833 +
22834 +UCHAR RateSwitchTable11B[] = {
22835 +// 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)
22836 + 0x04, 0x03, 0, 0, 0, // Initial used item after association
22837 + 0x00, 0x00, 0, 40, 101,
22838 + 0x01, 0x00, 1, 40, 50,
22839 + 0x02, 0x00, 2, 35, 45,
22840 + 0x03, 0x00, 3, 20, 45,
22841 +};
22842 +
22843 +UCHAR RateSwitchTable11BG[] = {
22844 +// 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)
22845 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
22846 + 0x00, 0x00, 0, 40, 101,
22847 + 0x01, 0x00, 1, 40, 50,
22848 + 0x02, 0x00, 2, 35, 45,
22849 + 0x03, 0x00, 3, 20, 45,
22850 + 0x04, 0x10, 2, 20, 35,
22851 + 0x05, 0x10, 3, 16, 35,
22852 + 0x06, 0x10, 4, 10, 25,
22853 + 0x07, 0x10, 5, 16, 25,
22854 + 0x08, 0x10, 6, 10, 25,
22855 + 0x09, 0x10, 7, 10, 13,
22856 +};
22857 +
22858 +UCHAR RateSwitchTable11G[] = {
22859 +// 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)
22860 + 0x08, 0x00, 0, 0, 0, // Initial used item after association
22861 + 0x00, 0x10, 0, 20, 101,
22862 + 0x01, 0x10, 1, 20, 35,
22863 + 0x02, 0x10, 2, 20, 35,
22864 + 0x03, 0x10, 3, 16, 35,
22865 + 0x04, 0x10, 4, 10, 25,
22866 + 0x05, 0x10, 5, 16, 25,
22867 + 0x06, 0x10, 6, 10, 25,
22868 + 0x07, 0x10, 7, 10, 13,
22869 +};
22870 +
22871 +#ifdef DOT11_N_SUPPORT
22872 +UCHAR RateSwitchTable11N1S[] = {
22873 +// 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)
22874 + 0x09, 0x00, 0, 0, 0, // Initial used item after association
22875 + 0x00, 0x21, 0, 30, 101,
22876 + 0x01, 0x21, 1, 20, 50,
22877 + 0x02, 0x21, 2, 20, 50,
22878 + 0x03, 0x21, 3, 15, 50,
22879 + 0x04, 0x21, 4, 15, 30,
22880 + 0x05, 0x21, 5, 10, 25,
22881 + 0x06, 0x21, 6, 8, 14,
22882 + 0x07, 0x21, 7, 8, 14,
22883 + 0x08, 0x23, 7, 8, 14,
22884 +};
22885 +
22886 +UCHAR RateSwitchTable11N2S[] = {
22887 +// 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)
22888 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
22889 + 0x00, 0x21, 0, 30, 101,
22890 + 0x01, 0x21, 1, 20, 50,
22891 + 0x02, 0x21, 2, 20, 50,
22892 + 0x03, 0x21, 3, 15, 50,
22893 + 0x04, 0x21, 4, 15, 30,
22894 + 0x05, 0x20, 12, 15, 30,
22895 + 0x06, 0x20, 13, 8, 20,
22896 + 0x07, 0x20, 14, 8, 20,
22897 + 0x08, 0x20, 15, 8, 25,
22898 + 0x09, 0x22, 15, 8, 25,
22899 +};
22900 +
22901 +UCHAR RateSwitchTable11N3S[] = {
22902 +// 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)
22903 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
22904 + 0x00, 0x21, 0, 30, 101,
22905 + 0x01, 0x21, 1, 20, 50,
22906 + 0x02, 0x21, 2, 20, 50,
22907 + 0x03, 0x21, 3, 15, 50,
22908 + 0x04, 0x21, 4, 15, 30,
22909 + 0x05, 0x20, 12, 15, 30,
22910 + 0x06, 0x20, 13, 8, 20,
22911 + 0x07, 0x20, 14, 8, 20,
22912 + 0x08, 0x20, 15, 8, 25,
22913 + 0x09, 0x22, 15, 8, 25,
22914 +};
22915 +
22916 +UCHAR RateSwitchTable11N2SForABand[] = {
22917 +// 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)
22918 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
22919 + 0x00, 0x21, 0, 30, 101,
22920 + 0x01, 0x21, 1, 20, 50,
22921 + 0x02, 0x21, 2, 20, 50,
22922 + 0x03, 0x21, 3, 15, 50,
22923 + 0x04, 0x21, 4, 15, 30,
22924 + 0x05, 0x21, 5, 15, 30,
22925 + 0x06, 0x20, 12, 15, 30,
22926 + 0x07, 0x20, 13, 8, 20,
22927 + 0x08, 0x20, 14, 8, 20,
22928 + 0x09, 0x20, 15, 8, 25,
22929 + 0x0a, 0x22, 15, 8, 25,
22930 +};
22931 +
22932 +UCHAR RateSwitchTable11N3SForABand[] = { // 3*3
22933 +// 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)
22934 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
22935 + 0x00, 0x21, 0, 30, 101,
22936 + 0x01, 0x21, 1, 20, 50,
22937 + 0x02, 0x21, 2, 20, 50,
22938 + 0x03, 0x21, 3, 15, 50,
22939 + 0x04, 0x21, 4, 15, 30,
22940 + 0x05, 0x21, 5, 15, 30,
22941 + 0x06, 0x20, 12, 15, 30,
22942 + 0x07, 0x20, 13, 8, 20,
22943 + 0x08, 0x20, 14, 8, 20,
22944 + 0x09, 0x20, 15, 8, 25,
22945 + 0x0a, 0x22, 15, 8, 25,
22946 +};
22947 +
22948 +UCHAR RateSwitchTable11BGN1S[] = {
22949 +// 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)
22950 + 0x0d, 0x00, 0, 0, 0, // Initial used item after association
22951 + 0x00, 0x00, 0, 40, 101,
22952 + 0x01, 0x00, 1, 40, 50,
22953 + 0x02, 0x00, 2, 35, 45,
22954 + 0x03, 0x00, 3, 20, 45,
22955 + 0x04, 0x21, 0, 30,101, //50
22956 + 0x05, 0x21, 1, 20, 50,
22957 + 0x06, 0x21, 2, 20, 50,
22958 + 0x07, 0x21, 3, 15, 50,
22959 + 0x08, 0x21, 4, 15, 30,
22960 + 0x09, 0x21, 5, 10, 25,
22961 + 0x0a, 0x21, 6, 8, 14,
22962 + 0x0b, 0x21, 7, 8, 14,
22963 + 0x0c, 0x23, 7, 8, 14,
22964 +};
22965 +
22966 +UCHAR RateSwitchTable11BGN2S[] = {
22967 +// 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)
22968 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
22969 + 0x00, 0x21, 0, 30,101, //50
22970 + 0x01, 0x21, 1, 20, 50,
22971 + 0x02, 0x21, 2, 20, 50,
22972 + 0x03, 0x21, 3, 15, 50,
22973 + 0x04, 0x21, 4, 15, 30,
22974 + 0x05, 0x20, 12, 15, 30,
22975 + 0x06, 0x20, 13, 8, 20,
22976 + 0x07, 0x20, 14, 8, 20,
22977 + 0x08, 0x20, 15, 8, 25,
22978 + 0x09, 0x22, 15, 8, 25,
22979 +};
22980 +
22981 +UCHAR RateSwitchTable11BGN3S[] = { // 3*3
22982 +// 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)
22983 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
22984 + 0x00, 0x21, 0, 30,101, //50
22985 + 0x01, 0x21, 1, 20, 50,
22986 + 0x02, 0x21, 2, 20, 50,
22987 + 0x03, 0x21, 3, 20, 50,
22988 + 0x04, 0x21, 4, 15, 50,
22989 +#if 1
22990 + 0x05, 0x20, 20, 15, 30,
22991 + 0x06, 0x20, 21, 8, 20,
22992 + 0x07, 0x20, 22, 8, 20,
22993 + 0x08, 0x20, 23, 8, 25,
22994 + 0x09, 0x22, 23, 8, 25,
22995 +#else // for RT2860 2*3 test
22996 + 0x05, 0x20, 12, 15, 30,
22997 + 0x06, 0x20, 13, 8, 20,
22998 + 0x07, 0x20, 14, 8, 20,
22999 + 0x08, 0x20, 15, 8, 25,
23000 + 0x09, 0x22, 15, 8, 25,
23001 +#endif
23002 +};
23003 +
23004 +UCHAR RateSwitchTable11BGN2SForABand[] = {
23005 +// 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)
23006 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
23007 + 0x00, 0x21, 0, 30,101, //50
23008 + 0x01, 0x21, 1, 20, 50,
23009 + 0x02, 0x21, 2, 20, 50,
23010 + 0x03, 0x21, 3, 15, 50,
23011 + 0x04, 0x21, 4, 15, 30,
23012 + 0x05, 0x21, 5, 15, 30,
23013 + 0x06, 0x20, 12, 15, 30,
23014 + 0x07, 0x20, 13, 8, 20,
23015 + 0x08, 0x20, 14, 8, 20,
23016 + 0x09, 0x20, 15, 8, 25,
23017 + 0x0a, 0x22, 15, 8, 25,
23018 +};
23019 +
23020 +UCHAR RateSwitchTable11BGN3SForABand[] = { // 3*3
23021 +// 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)
23022 + 0x0c, 0x09, 0, 0, 0, // Initial used item after association
23023 + 0x00, 0x21, 0, 30,101, //50
23024 + 0x01, 0x21, 1, 20, 50,
23025 + 0x02, 0x21, 2, 20, 50,
23026 + 0x03, 0x21, 3, 15, 50,
23027 + 0x04, 0x21, 4, 15, 30,
23028 + 0x05, 0x21, 5, 15, 30,
23029 + 0x06, 0x21, 12, 15, 30,
23030 + 0x07, 0x20, 20, 15, 30,
23031 + 0x08, 0x20, 21, 8, 20,
23032 + 0x09, 0x20, 22, 8, 20,
23033 + 0x0a, 0x20, 23, 8, 25,
23034 + 0x0b, 0x22, 23, 8, 25,
23035 +};
23036 +#endif // DOT11_N_SUPPORT //
23037 +
23038 +PUCHAR ReasonString[] = {
23039 + /* 0 */ "Reserved",
23040 + /* 1 */ "Unspecified Reason",
23041 + /* 2 */ "Previous Auth no longer valid",
23042 + /* 3 */ "STA is leaving / has left",
23043 + /* 4 */ "DIS-ASSOC due to inactivity",
23044 + /* 5 */ "AP unable to hanle all associations",
23045 + /* 6 */ "class 2 error",
23046 + /* 7 */ "class 3 error",
23047 + /* 8 */ "STA is leaving / has left",
23048 + /* 9 */ "require auth before assoc/re-assoc",
23049 + /* 10 */ "Reserved",
23050 + /* 11 */ "Reserved",
23051 + /* 12 */ "Reserved",
23052 + /* 13 */ "invalid IE",
23053 + /* 14 */ "MIC error",
23054 + /* 15 */ "4-way handshake timeout",
23055 + /* 16 */ "2-way (group key) handshake timeout",
23056 + /* 17 */ "4-way handshake IE diff among AssosReq/Rsp/Beacon",
23057 + /* 18 */
23058 +};
23059 +
23060 +extern UCHAR OfdmRateToRxwiMCS[];
23061 +// since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate.
23062 +// otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rate
23063 +ULONG BasicRateMask[12] = {0xfffff001 /* 1-Mbps */, 0xfffff003 /* 2 Mbps */, 0xfffff007 /* 5.5 */, 0xfffff00f /* 11 */,
23064 + 0xfffff01f /* 6 */ , 0xfffff03f /* 9 */ , 0xfffff07f /* 12 */ , 0xfffff0ff /* 18 */,
23065 + 0xfffff1ff /* 24 */ , 0xfffff3ff /* 36 */ , 0xfffff7ff /* 48 */ , 0xffffffff /* 54 */};
23066 +
23067 +UCHAR MULTICAST_ADDR[MAC_ADDR_LEN] = {0x1, 0x00, 0x00, 0x00, 0x00, 0x00};
23068 +UCHAR BROADCAST_ADDR[MAC_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
23069 +UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
23070 +
23071 +// e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than
23072 +// this value, then it's quaranteed capable of operating in 36 mbps TX rate in
23073 +// clean environment.
23074 +// TxRate: 1 2 5.5 11 6 9 12 18 24 36 48 54 72 100
23075 +CHAR RssiSafeLevelForTxRate[] ={ -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 };
23076 +
23077 +UCHAR RateIdToMbps[] = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100};
23078 +USHORT RateIdTo500Kbps[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200};
23079 +
23080 +UCHAR SsidIe = IE_SSID;
23081 +UCHAR SupRateIe = IE_SUPP_RATES;
23082 +UCHAR ExtRateIe = IE_EXT_SUPP_RATES;
23083 +#ifdef DOT11_N_SUPPORT
23084 +UCHAR HtCapIe = IE_HT_CAP;
23085 +UCHAR AddHtInfoIe = IE_ADD_HT;
23086 +UCHAR NewExtChanIe = IE_SECONDARY_CH_OFFSET;
23087 +#ifdef DOT11N_DRAFT3
23088 +UCHAR ExtHtCapIe = IE_EXT_CAPABILITY;
23089 +#endif // DOT11N_DRAFT3 //
23090 +#endif // DOT11_N_SUPPORT //
23091 +UCHAR ErpIe = IE_ERP;
23092 +UCHAR DsIe = IE_DS_PARM;
23093 +UCHAR TimIe = IE_TIM;
23094 +UCHAR WpaIe = IE_WPA;
23095 +UCHAR Wpa2Ie = IE_WPA2;
23096 +UCHAR IbssIe = IE_IBSS_PARM;
23097 +UCHAR Ccx2Ie = IE_CCX_V2;
23098 +UCHAR WapiIe = IE_WAPI;
23099 +
23100 +extern UCHAR WPA_OUI[];
23101 +
23102 +UCHAR SES_OUI[] = {0x00, 0x90, 0x4c};
23103 +
23104 +UCHAR ZeroSsid[32] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
23105 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
23106 +
23107 +// Reset the RFIC setting to new series
23108 +RTMP_RF_REGS RF2850RegTable[] = {
23109 +// ch R1 R2 R3(TX0~4=0) R4
23110 + {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b},
23111 + {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f},
23112 + {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b},
23113 + {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f},
23114 + {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b},
23115 + {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f},
23116 + {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b},
23117 + {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f},
23118 + {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b},
23119 + {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f},
23120 + {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b},
23121 + {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f},
23122 + {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b},
23123 + {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193},
23124 +
23125 + // 802.11 UNI / HyperLan 2
23126 + {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3},
23127 + {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193},
23128 + {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183},
23129 + {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3},
23130 + {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b},
23131 + {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b},
23132 + {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193},
23133 + {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3},
23134 + {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b},
23135 + {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183},
23136 + {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193},
23137 + {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}, // Plugfest#4, Day4, change RFR3 left4th 9->5.
23138 +
23139 + // 802.11 HyperLan 2
23140 + {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783},
23141 +
23142 + // 2008.04.30 modified
23143 + // The system team has AN to improve the EVM value
23144 + // for channel 102 to 108 for the RT2850/RT2750 dual band solution.
23145 + {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793},
23146 + {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3},
23147 + {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193},
23148 +
23149 + {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183},
23150 + {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b},
23151 + {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3},
23152 + {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193},
23153 + {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183},
23154 + {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193},
23155 + {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}, // 0x980ed1bb->0x980ed15b required by Rory 20070927
23156 + {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3},
23157 + {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b},
23158 + {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193},
23159 + {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b},
23160 + {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183},
23161 +
23162 + // 802.11 UNII
23163 + {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7},
23164 + {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187},
23165 + {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f},
23166 + {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f},
23167 + {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7},
23168 + {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187},
23169 + {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197},
23170 +
23171 + // Japan
23172 + {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b},
23173 + {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13},
23174 + {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b},
23175 + {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23},
23176 + {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13},
23177 + {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b},
23178 + {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23},
23179 +
23180 + // still lack of MMAC(Japan) ch 34,38,42,46
23181 +};
23182 +UCHAR NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(RTMP_RF_REGS));
23183 +
23184 +FREQUENCY_ITEM FreqItems3020[] =
23185 +{
23186 + /**************************************************/
23187 + // ISM : 2.4 to 2.483 GHz //
23188 + /**************************************************/
23189 + // 11g
23190 + /**************************************************/
23191 + //-CH---N-------R---K-----------
23192 + {1, 241, 2, 2},
23193 + {2, 241, 2, 7},
23194 + {3, 242, 2, 2},
23195 + {4, 242, 2, 7},
23196 + {5, 243, 2, 2},
23197 + {6, 243, 2, 7},
23198 + {7, 244, 2, 2},
23199 + {8, 244, 2, 7},
23200 + {9, 245, 2, 2},
23201 + {10, 245, 2, 7},
23202 + {11, 246, 2, 2},
23203 + {12, 246, 2, 7},
23204 + {13, 247, 2, 2},
23205 + {14, 248, 2, 4},
23206 +};
23207 +#define NUM_OF_3020_CHNL (sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM))
23208 +
23209 +/*
23210 + ==========================================================================
23211 + Description:
23212 + initialize the MLME task and its data structure (queue, spinlock,
23213 + timer, state machines).
23214 +
23215 + IRQL = PASSIVE_LEVEL
23216 +
23217 + Return:
23218 + always return NDIS_STATUS_SUCCESS
23219 +
23220 + ==========================================================================
23221 +*/
23222 +NDIS_STATUS MlmeInit(
23223 + IN PRTMP_ADAPTER pAd)
23224 +{
23225 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
23226 +
23227 + DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n"));
23228 +
23229 + do
23230 + {
23231 + Status = MlmeQueueInit(&pAd->Mlme.Queue);
23232 + if(Status != NDIS_STATUS_SUCCESS)
23233 + break;
23234 +
23235 + pAd->Mlme.bRunning = FALSE;
23236 + NdisAllocateSpinLock(&pAd->Mlme.TaskLock);
23237 +
23238 +#ifdef CONFIG_STA_SUPPORT
23239 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23240 + {
23241 + BssTableInit(&pAd->ScanTab);
23242 +
23243 + // init STA state machines
23244 + AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine, pAd->Mlme.AssocFunc);
23245 + AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine, pAd->Mlme.AuthFunc);
23246 + AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine, pAd->Mlme.AuthRspFunc);
23247 + SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine, pAd->Mlme.SyncFunc);
23248 + WpaPskStateMachineInit(pAd, &pAd->Mlme.WpaPskMachine, pAd->Mlme.WpaPskFunc);
23249 + AironetStateMachineInit(pAd, &pAd->Mlme.AironetMachine, pAd->Mlme.AironetFunc);
23250 +
23251 +#ifdef QOS_DLS_SUPPORT
23252 + DlsStateMachineInit(pAd, &pAd->Mlme.DlsMachine, pAd->Mlme.DlsFunc);
23253 +#endif // QOS_DLS_SUPPORT //
23254 +
23255 +
23256 + // Since we are using switch/case to implement it, the init is different from the above
23257 + // state machine init
23258 + MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL);
23259 + }
23260 +#endif // CONFIG_STA_SUPPORT //
23261 +
23262 +
23263 +
23264 + ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine, pAd->Mlme.ActFunc);
23265 +
23266 + // Init mlme periodic timer
23267 + RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer, GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE);
23268 +
23269 + // Set mlme periodic timer
23270 + RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
23271 +
23272 + // software-based RX Antenna diversity
23273 + RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE);
23274 +
23275 + } while (FALSE);
23276 +
23277 + DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n"));
23278 +
23279 + return Status;
23280 +}
23281 +
23282 +/*
23283 + ==========================================================================
23284 + Description:
23285 + main loop of the MLME
23286 + Pre:
23287 + Mlme has to be initialized, and there are something inside the queue
23288 + Note:
23289 + This function is invoked from MPSetInformation and MPReceive;
23290 + This task guarantee only one MlmeHandler will run.
23291 +
23292 + IRQL = DISPATCH_LEVEL
23293 +
23294 + ==========================================================================
23295 + */
23296 +VOID MlmeHandler(
23297 + IN PRTMP_ADAPTER pAd)
23298 +{
23299 + MLME_QUEUE_ELEM *Elem = NULL;
23300 +#ifdef APCLI_SUPPORT
23301 + SHORT apcliIfIndex;
23302 +#endif
23303 +
23304 + // Only accept MLME and Frame from peer side, no other (control/data) frame should
23305 + // get into this state machine
23306 +
23307 + NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
23308 + if(pAd->Mlme.bRunning)
23309 + {
23310 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23311 + return;
23312 + }
23313 + else
23314 + {
23315 + pAd->Mlme.bRunning = TRUE;
23316 + }
23317 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23318 +
23319 + while (!MlmeQueueEmpty(&pAd->Mlme.Queue))
23320 + {
23321 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) ||
23322 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
23323 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23324 + {
23325 + DBGPRINT(RT_DEBUG_TRACE, ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n", pAd->Mlme.Queue.Num));
23326 + break;
23327 + }
23328 +
23329 +#ifdef RALINK_ATE
23330 + if(ATE_ON(pAd))
23331 + {
23332 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now in MlmeHandler\n"));
23333 + break;
23334 + }
23335 +#endif // RALINK_ATE //
23336 +
23337 + //From message type, determine which state machine I should drive
23338 + if (MlmeDequeue(&pAd->Mlme.Queue, &Elem))
23339 + {
23340 +#ifdef RT2870
23341 + if (Elem->MsgType == MT2_RESET_CONF)
23342 + {
23343 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! reset MLME state machine !!!\n"));
23344 + MlmeRestartStateMachine(pAd);
23345 + Elem->Occupied = FALSE;
23346 + Elem->MsgLen = 0;
23347 + continue;
23348 + }
23349 +#endif // RT2870 //
23350 +
23351 + // if dequeue success
23352 + switch (Elem->Machine)
23353 + {
23354 + // STA state machines
23355 +#ifdef CONFIG_STA_SUPPORT
23356 + case ASSOC_STATE_MACHINE:
23357 + StateMachinePerformAction(pAd, &pAd->Mlme.AssocMachine, Elem);
23358 + break;
23359 + case AUTH_STATE_MACHINE:
23360 + StateMachinePerformAction(pAd, &pAd->Mlme.AuthMachine, Elem);
23361 + break;
23362 + case AUTH_RSP_STATE_MACHINE:
23363 + StateMachinePerformAction(pAd, &pAd->Mlme.AuthRspMachine, Elem);
23364 + break;
23365 + case SYNC_STATE_MACHINE:
23366 + StateMachinePerformAction(pAd, &pAd->Mlme.SyncMachine, Elem);
23367 + break;
23368 + case MLME_CNTL_STATE_MACHINE:
23369 + MlmeCntlMachinePerformAction(pAd, &pAd->Mlme.CntlMachine, Elem);
23370 + break;
23371 + case WPA_PSK_STATE_MACHINE:
23372 + StateMachinePerformAction(pAd, &pAd->Mlme.WpaPskMachine, Elem);
23373 + break;
23374 +#ifdef LEAP_SUPPORT
23375 + case LEAP_STATE_MACHINE:
23376 + LeapMachinePerformAction(pAd, &pAd->Mlme.LeapMachine, Elem);
23377 + break;
23378 +#endif
23379 + case AIRONET_STATE_MACHINE:
23380 + StateMachinePerformAction(pAd, &pAd->Mlme.AironetMachine, Elem);
23381 + break;
23382 +
23383 +#ifdef QOS_DLS_SUPPORT
23384 + case DLS_STATE_MACHINE:
23385 + StateMachinePerformAction(pAd, &pAd->Mlme.DlsMachine, Elem);
23386 + break;
23387 +#endif // QOS_DLS_SUPPORT //
23388 +#endif // CONFIG_STA_SUPPORT //
23389 +
23390 + case ACTION_STATE_MACHINE:
23391 + StateMachinePerformAction(pAd, &pAd->Mlme.ActMachine, Elem);
23392 + break;
23393 +
23394 +
23395 +
23396 +
23397 + default:
23398 + DBGPRINT(RT_DEBUG_TRACE, ("ERROR: Illegal machine %ld in MlmeHandler()\n", Elem->Machine));
23399 + break;
23400 + } // end of switch
23401 +
23402 + // free MLME element
23403 + Elem->Occupied = FALSE;
23404 + Elem->MsgLen = 0;
23405 +
23406 + }
23407 + else {
23408 + DBGPRINT_ERR(("MlmeHandler: MlmeQueue empty\n"));
23409 + }
23410 + }
23411 +
23412 + NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
23413 + pAd->Mlme.bRunning = FALSE;
23414 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23415 +}
23416 +
23417 +/*
23418 + ==========================================================================
23419 + Description:
23420 + Destructor of MLME (Destroy queue, state machine, spin lock and timer)
23421 + Parameters:
23422 + Adapter - NIC Adapter pointer
23423 + Post:
23424 + The MLME task will no longer work properly
23425 +
23426 + IRQL = PASSIVE_LEVEL
23427 +
23428 + ==========================================================================
23429 + */
23430 +VOID MlmeHalt(
23431 + IN PRTMP_ADAPTER pAd)
23432 +{
23433 + BOOLEAN Cancelled;
23434 +
23435 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n"));
23436 +
23437 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23438 + {
23439 + // disable BEACON generation and other BEACON related hardware timers
23440 + AsicDisableSync(pAd);
23441 + }
23442 +
23443 +#ifdef CONFIG_STA_SUPPORT
23444 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23445 + {
23446 +#ifdef QOS_DLS_SUPPORT
23447 + UCHAR i;
23448 +#endif // QOS_DLS_SUPPORT //
23449 + // Cancel pending timers
23450 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
23451 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
23452 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
23453 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
23454 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
23455 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
23456 +
23457 +#ifdef QOS_DLS_SUPPORT
23458 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
23459 + {
23460 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled);
23461 + }
23462 +#endif // QOS_DLS_SUPPORT //
23463 + }
23464 +#endif // CONFIG_STA_SUPPORT //
23465 +
23466 + RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
23467 + RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled);
23468 +
23469 +
23470 +
23471 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23472 + {
23473 + // Set LED
23474 + RTMPSetLED(pAd, LED_HALT);
23475 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
23476 +#ifdef RT2870
23477 + {
23478 + LED_CFG_STRUC LedCfg;
23479 + RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word);
23480 + LedCfg.field.LedPolar = 0;
23481 + LedCfg.field.RLedMode = 0;
23482 + LedCfg.field.GLedMode = 0;
23483 + LedCfg.field.YLedMode = 0;
23484 + RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word);
23485 + }
23486 +#endif // RT2870 //
23487 + }
23488 +
23489 + RTMPusecDelay(5000); // 5 msec to gurantee Ant Diversity timer canceled
23490 +
23491 + MlmeQueueDestroy(&pAd->Mlme.Queue);
23492 + NdisFreeSpinLock(&pAd->Mlme.TaskLock);
23493 +
23494 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n"));
23495 +}
23496 +
23497 +VOID MlmeResetRalinkCounters(
23498 + IN PRTMP_ADAPTER pAd)
23499 +{
23500 + pAd->RalinkCounters.LastOneSecRxOkDataCnt = pAd->RalinkCounters.OneSecRxOkDataCnt;
23501 + // clear all OneSecxxx counters.
23502 + pAd->RalinkCounters.OneSecBeaconSentCnt = 0;
23503 + pAd->RalinkCounters.OneSecFalseCCACnt = 0;
23504 + pAd->RalinkCounters.OneSecRxFcsErrCnt = 0;
23505 + pAd->RalinkCounters.OneSecRxOkCnt = 0;
23506 + pAd->RalinkCounters.OneSecTxFailCount = 0;
23507 + pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0;
23508 + pAd->RalinkCounters.OneSecTxRetryOkCount = 0;
23509 + pAd->RalinkCounters.OneSecRxOkDataCnt = 0;
23510 +
23511 + // TODO: for debug only. to be removed
23512 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0;
23513 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0;
23514 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0;
23515 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0;
23516 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0;
23517 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0;
23518 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0;
23519 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0;
23520 + pAd->RalinkCounters.OneSecTxDoneCount = 0;
23521 + pAd->RalinkCounters.OneSecRxCount = 0;
23522 + pAd->RalinkCounters.OneSecTxAggregationCount = 0;
23523 + pAd->RalinkCounters.OneSecRxAggregationCount = 0;
23524 +
23525 + return;
23526 +}
23527 +
23528 +unsigned long rx_AMSDU;
23529 +unsigned long rx_Total;
23530 +
23531 +/*
23532 + ==========================================================================
23533 + Description:
23534 + This routine is executed periodically to -
23535 + 1. Decide if it's a right time to turn on PwrMgmt bit of all
23536 + outgoiing frames
23537 + 2. Calculate ChannelQuality based on statistics of the last
23538 + period, so that TX rate won't toggling very frequently between a
23539 + successful TX and a failed TX.
23540 + 3. If the calculated ChannelQuality indicated current connection not
23541 + healthy, then a ROAMing attempt is tried here.
23542 +
23543 + IRQL = DISPATCH_LEVEL
23544 +
23545 + ==========================================================================
23546 + */
23547 +#define ADHOC_BEACON_LOST_TIME (8*OS_HZ) // 8 sec
23548 +VOID MlmePeriodicExec(
23549 + IN PVOID SystemSpecific1,
23550 + IN PVOID FunctionContext,
23551 + IN PVOID SystemSpecific2,
23552 + IN PVOID SystemSpecific3)
23553 +{
23554 + ULONG TxTotalCnt;
23555 + PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext;
23556 +
23557 + // Do nothing if the driver is starting halt state.
23558 + // This might happen when timer already been fired before cancel timer with mlmehalt
23559 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_HALT_IN_PROGRESS |
23560 + fRTMP_ADAPTER_RADIO_OFF |
23561 + fRTMP_ADAPTER_RADIO_MEASUREMENT |
23562 + fRTMP_ADAPTER_RESET_IN_PROGRESS))))
23563 + return;
23564 +
23565 + RT28XX_MLME_PRE_SANITY_CHECK(pAd);
23566 +
23567 +#ifdef RALINK_ATE
23568 + /* Do not show RSSI until "Normal 1 second Mlme PeriodicExec". */
23569 + if (ATE_ON(pAd))
23570 + {
23571 + if (pAd->Mlme.PeriodicRound % MLME_TASK_EXEC_MULTIPLE != (MLME_TASK_EXEC_MULTIPLE - 1))
23572 + {
23573 + pAd->Mlme.PeriodicRound ++;
23574 + return;
23575 + }
23576 + }
23577 +#endif // RALINK_ATE //
23578 +
23579 +#ifdef CONFIG_STA_SUPPORT
23580 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23581 + {
23582 + // Do nothing if monitor mode is on
23583 + if (MONITOR_ON(pAd))
23584 + return;
23585 +
23586 + if (pAd->Mlme.PeriodicRound & 0x1)
23587 + {
23588 + // This is the fix for wifi 11n extension channel overlapping test case. for 2860D
23589 + if (((pAd->MACVersion & 0xffff) == 0x0101) &&
23590 + (STA_TGN_WIFI_ON(pAd)) &&
23591 + (pAd->CommonCfg.IOTestParm.bToggle == FALSE))
23592 +
23593 + {
23594 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf);
23595 + pAd->CommonCfg.IOTestParm.bToggle = TRUE;
23596 + }
23597 + else if ((STA_TGN_WIFI_ON(pAd)) &&
23598 + ((pAd->MACVersion & 0xffff) == 0x0101))
23599 + {
23600 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f);
23601 + pAd->CommonCfg.IOTestParm.bToggle = FALSE;
23602 + }
23603 + }
23604 + }
23605 +#endif // CONFIG_STA_SUPPORT //
23606 +
23607 + pAd->bUpdateBcnCntDone = FALSE;
23608 +
23609 +// RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3);
23610 + pAd->Mlme.PeriodicRound ++;
23611 +
23612 + // execute every 500ms
23613 + if ((pAd->Mlme.PeriodicRound % 5 == 0) && RTMPAutoRateSwitchCheck(pAd)/*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED))*/)
23614 + {
23615 +#ifdef CONFIG_STA_SUPPORT
23616 + // perform dynamic tx rate switching based on past TX history
23617 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23618 + {
23619 + if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
23620 + )
23621 + && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)))
23622 + MlmeDynamicTxRateSwitching(pAd);
23623 + }
23624 +#endif // CONFIG_STA_SUPPORT //
23625 + }
23626 +
23627 + // Normal 1 second Mlme PeriodicExec.
23628 + if (pAd->Mlme.PeriodicRound %MLME_TASK_EXEC_MULTIPLE == 0)
23629 + {
23630 + pAd->Mlme.OneSecPeriodicRound ++;
23631 +
23632 +#ifdef RALINK_ATE
23633 + if (ATE_ON(pAd))
23634 + {
23635 + /* request from Baron : move this routine from later to here */
23636 + /* for showing Rx error count in ATE RXFRAME */
23637 + NICUpdateRawCounters(pAd);
23638 + if (pAd->ate.bRxFer == 1)
23639 + {
23640 + pAd->ate.RxTotalCnt += pAd->ate.RxCntPerSec;
23641 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx packet cnt = %d/%d\n", pAd->ate.RxCntPerSec, pAd->ate.RxTotalCnt);
23642 + pAd->ate.RxCntPerSec = 0;
23643 +
23644 + if (pAd->ate.RxAntennaSel == 0)
23645 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi0=%d, AvgRssi1=%d, AvgRssi2=%d\n\n",
23646 + pAd->ate.AvgRssi0, pAd->ate.AvgRssi1, pAd->ate.AvgRssi2);
23647 + else
23648 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi=%d\n\n", pAd->ate.AvgRssi0);
23649 + }
23650 + MlmeResetRalinkCounters(pAd);
23651 + return;
23652 + }
23653 +#endif // RALINK_ATE //
23654 +
23655 +
23656 + if (rx_Total)
23657 + {
23658 +
23659 + // reset counters
23660 + rx_AMSDU = 0;
23661 + rx_Total = 0;
23662 + }
23663 +
23664 + //ORIBATimerTimeout(pAd);
23665 +
23666 + // Media status changed, report to NDIS
23667 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE))
23668 + {
23669 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
23670 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
23671 + {
23672 + pAd->IndicateMediaState = NdisMediaStateConnected;
23673 + RTMP_IndicateMediaState(pAd);
23674 +
23675 + }
23676 + else
23677 + {
23678 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
23679 + RTMP_IndicateMediaState(pAd);
23680 + }
23681 + }
23682 +
23683 + NdisGetSystemUpTime(&pAd->Mlme.Now32);
23684 +
23685 + // add the most up-to-date h/w raw counters into software variable, so that
23686 + // the dynamic tuning mechanism below are based on most up-to-date information
23687 + NICUpdateRawCounters(pAd);
23688 +
23689 +#ifdef RT2870
23690 + RT2870_WatchDog(pAd);
23691 +#endif // RT2870 //
23692 +
23693 +#ifdef DOT11_N_SUPPORT
23694 + // Need statistics after read counter. So put after NICUpdateRawCounters
23695 + ORIBATimerTimeout(pAd);
23696 +#endif // DOT11_N_SUPPORT //
23697 +
23698 + // if MGMT RING is full more than twice within 1 second, we consider there's
23699 + // a hardware problem stucking the TX path. In this case, try a hardware reset
23700 + // to recover the system
23701 + // if (pAd->RalinkCounters.MgmtRingFullCount >= 2)
23702 + // RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HARDWARE_ERROR);
23703 + // else
23704 + // pAd->RalinkCounters.MgmtRingFullCount = 0;
23705 +
23706 + // The time period for checking antenna is according to traffic
23707 + if (pAd->Mlme.bEnableAutoAntennaCheck)
23708 + {
23709 + TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
23710 + pAd->RalinkCounters.OneSecTxRetryOkCount +
23711 + pAd->RalinkCounters.OneSecTxFailCount;
23712 +
23713 + if (TxTotalCnt > 50)
23714 + {
23715 + if (pAd->Mlme.OneSecPeriodicRound % 10 == 0)
23716 + {
23717 + AsicEvaluateRxAnt(pAd);
23718 + }
23719 + }
23720 + else
23721 + {
23722 + if (pAd->Mlme.OneSecPeriodicRound % 3 == 0)
23723 + {
23724 + AsicEvaluateRxAnt(pAd);
23725 + }
23726 + }
23727 + }
23728 +
23729 +#ifdef CONFIG_STA_SUPPORT
23730 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23731 + STAMlmePeriodicExec(pAd);
23732 +#endif // CONFIG_STA_SUPPORT //
23733 +
23734 + MlmeResetRalinkCounters(pAd);
23735 +
23736 +#ifdef CONFIG_STA_SUPPORT
23737 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23738 + {
23739 + {
23740 + // When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock
23741 + // and sending CTS-to-self over and over.
23742 + // Software Patch Solution:
23743 + // 1. Polling debug state register 0x10F4 every one second.
23744 + // 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred.
23745 + // 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again.
23746 +
23747 + UINT32 MacReg = 0;
23748 +
23749 + RTMP_IO_READ32(pAd, 0x10F4, &MacReg);
23750 + if (((MacReg & 0x20000000) && (MacReg & 0x80)) || ((MacReg & 0x20000000) && (MacReg & 0x20)))
23751 + {
23752 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
23753 + RTMPusecDelay(1);
23754 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC);
23755 +
23756 + DBGPRINT(RT_DEBUG_WARN,("Warning, MAC specific condition occurs \n"));
23757 + }
23758 + }
23759 + }
23760 +#endif // CONFIG_STA_SUPPORT //
23761 +
23762 + RT28XX_MLME_HANDLER(pAd);
23763 + }
23764 +
23765 +
23766 + pAd->bUpdateBcnCntDone = FALSE;
23767 +}
23768 +
23769 +#ifdef CONFIG_STA_SUPPORT
23770 +VOID STAMlmePeriodicExec(
23771 + PRTMP_ADAPTER pAd)
23772 +{
23773 + ULONG TxTotalCnt;
23774 + int i;
23775 +
23776 +//
23777 +// We return here in ATE mode, because the statistics
23778 +// that ATE needs are not collected via this routine.
23779 +//
23780 +#ifdef RALINK_ATE
23781 + // It is supposed that we will never reach here in ATE mode.
23782 + ASSERT(!(ATE_ON(pAd)));
23783 + if (ATE_ON(pAd))
23784 + return;
23785 +#endif // RALINK_ATE //
23786 +
23787 +#ifdef WPA_SUPPLICANT_SUPPORT
23788 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)
23789 +#endif // WPA_SUPPLICANT_SUPPORT //
23790 + {
23791 + // WPA MIC error should block association attempt for 60 seconds
23792 + if (pAd->StaCfg.bBlockAssoc && (pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ) < pAd->Mlme.Now32))
23793 + pAd->StaCfg.bBlockAssoc = FALSE;
23794 + }
23795 +
23796 + if ((pAd->PreMediaState != pAd->IndicateMediaState) && (pAd->CommonCfg.bWirelessEvent))
23797 + {
23798 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
23799 + {
23800 + RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
23801 + }
23802 + pAd->PreMediaState = pAd->IndicateMediaState;
23803 + }
23804 +
23805 +
23806 +
23807 +
23808 + AsicStaBbpTuning(pAd);
23809 +
23810 + TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
23811 + pAd->RalinkCounters.OneSecTxRetryOkCount +
23812 + pAd->RalinkCounters.OneSecTxFailCount;
23813 +
23814 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
23815 + {
23816 + // update channel quality for Roaming and UI LinkQuality display
23817 + MlmeCalculateChannelQuality(pAd, pAd->Mlme.Now32);
23818 + }
23819 +
23820 + // must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if
23821 + // Radio is currently in noisy environment
23822 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
23823 + AsicAdjustTxPower(pAd);
23824 +
23825 + if (INFRA_ON(pAd))
23826 + {
23827 +#ifdef QOS_DLS_SUPPORT
23828 + // Check DLS time out, then tear down those session
23829 + RTMPCheckDLSTimeOut(pAd);
23830 +#endif // QOS_DLS_SUPPORT //
23831 +
23832 + // Is PSM bit consistent with user power management policy?
23833 + // This is the only place that will set PSM bit ON.
23834 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
23835 + MlmeCheckPsmChange(pAd, pAd->Mlme.Now32);
23836 +
23837 + pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt;
23838 +
23839 + if ((pAd->StaCfg.LastBeaconRxTime + 1*OS_HZ < pAd->Mlme.Now32) &&
23840 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
23841 + ((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt < 600)))
23842 + {
23843 + RTMPSetAGCInitValue(pAd, BW_20);
23844 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n", (0x2E + GET_LNA_GAIN(pAd))));
23845 + }
23846 +
23847 + //if ((pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) &&
23848 + // (pAd->RalinkCounters.OneSecTxRetryOkCount == 0))
23849 + {
23850 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable)
23851 + {
23852 + // When APSD is enabled, the period changes as 20 sec
23853 + if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8)
23854 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
23855 + }
23856 + else
23857 + {
23858 + // Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out)
23859 + if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8)
23860 + {
23861 + if (pAd->CommonCfg.bWmmCapable)
23862 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
23863 + else
23864 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE);
23865 + }
23866 + }
23867 + }
23868 +
23869 + if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality))
23870 + {
23871 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount));
23872 + pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE;
23873 + pAd->StaCfg.CCXAdjacentAPLinkDownTime = pAd->StaCfg.LastBeaconRxTime;
23874 +
23875 + // Lost AP, send disconnect & link down event
23876 + LinkDown(pAd, FALSE);
23877 +
23878 +#ifdef WPA_SUPPLICANT_SUPPORT
23879 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
23880 + if (pAd->StaCfg.WpaSupplicantUP)
23881 + {
23882 + union iwreq_data wrqu;
23883 + //send disassociate event to wpa_supplicant
23884 + memset(&wrqu, 0, sizeof(wrqu));
23885 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
23886 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
23887 + }
23888 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
23889 +#endif // WPA_SUPPLICANT_SUPPORT //
23890 +
23891 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
23892 + {
23893 + union iwreq_data wrqu;
23894 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
23895 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
23896 + }
23897 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
23898 +
23899 + // RTMPPatchMacBbpBug(pAd);
23900 + MlmeAutoReconnectLastSSID(pAd);
23901 + }
23902 + else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality))
23903 + {
23904 + pAd->RalinkCounters.BadCQIAutoRecoveryCount ++;
23905 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount));
23906 + MlmeAutoReconnectLastSSID(pAd);
23907 + }
23908 +
23909 + // Add auto seamless roaming
23910 + if (pAd->StaCfg.bFastRoaming)
23911 + {
23912 + SHORT dBmToRoam = (SHORT)pAd->StaCfg.dBmToRoam;
23913 +
23914 + 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));
23915 +
23916 + if (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) <= (CHAR)dBmToRoam)
23917 + {
23918 + MlmeCheckForFastRoaming(pAd, pAd->Mlme.Now32);
23919 + }
23920 + }
23921 + }
23922 + else if (ADHOC_ON(pAd))
23923 + {
23924 + //radar detect
23925 + if ((pAd->CommonCfg.Channel > 14)
23926 + && (pAd->CommonCfg.bIEEE80211H == 1)
23927 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
23928 + {
23929 + RadarDetectPeriodic(pAd);
23930 + }
23931 +
23932 + // If all peers leave, and this STA becomes the last one in this IBSS, then change MediaState
23933 + // to DISCONNECTED. But still holding this IBSS (i.e. sending BEACON) so that other STAs can
23934 + // join later.
23935 + if ((pAd->StaCfg.LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32) &&
23936 + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
23937 + {
23938 + MLME_START_REQ_STRUCT StartReq;
23939 +
23940 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - excessive BEACON lost, last STA in this IBSS, MediaState=Disconnected\n"));
23941 + LinkDown(pAd, FALSE);
23942 +
23943 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
23944 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
23945 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
23946 + }
23947 +
23948 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
23949 + {
23950 + MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[i];
23951 +
23952 + if (pEntry->ValidAsCLI == FALSE)
23953 + continue;
23954 +
23955 + if (pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32)
23956 + MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr);
23957 + }
23958 + }
23959 + else // no INFRA nor ADHOC connection
23960 + {
23961 +
23962 + if (pAd->StaCfg.bScanReqIsFromWebUI &&
23963 + ((pAd->StaCfg.LastScanTime + 30 * OS_HZ) > pAd->Mlme.Now32))
23964 + goto SKIP_AUTO_SCAN_CONN;
23965 + else
23966 + pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
23967 +
23968 + if ((pAd->StaCfg.bAutoReconnect == TRUE)
23969 + && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)
23970 + && (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE))
23971 + {
23972 + if ((pAd->ScanTab.BssNr==0) && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE))
23973 + {
23974 + MLME_SCAN_REQ_STRUCT ScanReq;
23975 +
23976 + if ((pAd->StaCfg.LastScanTime + 10 * OS_HZ) < pAd->Mlme.Now32)
23977 + {
23978 + DBGPRINT(RT_DEBUG_TRACE, ("STAMlmePeriodicExec():CNTL - ScanTab.BssNr==0, start a new ACTIVE scan SSID[%s]\n", pAd->MlmeAux.AutoReconnectSsid));
23979 + ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen, BSS_ANY, SCAN_ACTIVE);
23980 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
23981 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
23982 + // Reset Missed scan number
23983 + pAd->StaCfg.LastScanTime = pAd->Mlme.Now32;
23984 + }
23985 + else if (pAd->StaCfg.BssType == BSS_ADHOC) // Quit the forever scan when in a very clean room
23986 + MlmeAutoReconnectLastSSID(pAd);
23987 + }
23988 + else if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
23989 + {
23990 + if ((pAd->Mlme.OneSecPeriodicRound % 7) == 0)
23991 + {
23992 + MlmeAutoScan(pAd);
23993 + pAd->StaCfg.LastScanTime = pAd->Mlme.Now32;
23994 + }
23995 + else
23996 + {
23997 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
23998 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
23999 + {
24000 + if ((pAd->Mlme.OneSecPeriodicRound % 5) == 1)
24001 + MlmeAutoReconnectLastSSID(pAd);
24002 + }
24003 + else
24004 +#endif // CARRIER_DETECTION_SUPPORT //
24005 + MlmeAutoReconnectLastSSID(pAd);
24006 + }
24007 + }
24008 + }
24009 + }
24010 +
24011 +SKIP_AUTO_SCAN_CONN:
24012 +
24013 +#ifdef DOT11_N_SUPPORT
24014 + if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap !=0) && (pAd->MacTab.fAnyBASession == FALSE))
24015 + {
24016 + pAd->MacTab.fAnyBASession = TRUE;
24017 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, FALSE, FALSE);
24018 + }
24019 + else if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap ==0) && (pAd->MacTab.fAnyBASession == TRUE))
24020 + {
24021 + pAd->MacTab.fAnyBASession = FALSE;
24022 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
24023 + }
24024 +#endif // DOT11_N_SUPPORT //
24025 +
24026 +
24027 +#ifdef DOT11_N_SUPPORT
24028 +#ifdef DOT11N_DRAFT3
24029 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SCAN_2040))
24030 + TriEventCounterMaintenance(pAd);
24031 +#endif // DOT11N_DRAFT3 //
24032 +#endif // DOT11_N_SUPPORT //
24033 +
24034 + return;
24035 +}
24036 +
24037 +// Link down report
24038 +VOID LinkDownExec(
24039 + IN PVOID SystemSpecific1,
24040 + IN PVOID FunctionContext,
24041 + IN PVOID SystemSpecific2,
24042 + IN PVOID SystemSpecific3)
24043 +{
24044 +
24045 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
24046 +
24047 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
24048 + RTMP_IndicateMediaState(pAd);
24049 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
24050 +}
24051 +
24052 +// IRQL = DISPATCH_LEVEL
24053 +VOID MlmeAutoScan(
24054 + IN PRTMP_ADAPTER pAd)
24055 +{
24056 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24057 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24058 + {
24059 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Driver auto scan\n"));
24060 + MlmeEnqueue(pAd,
24061 + MLME_CNTL_STATE_MACHINE,
24062 + OID_802_11_BSSID_LIST_SCAN,
24063 + 0,
24064 + NULL);
24065 + RT28XX_MLME_HANDLER(pAd);
24066 + }
24067 +}
24068 +
24069 +// IRQL = DISPATCH_LEVEL
24070 +VOID MlmeAutoReconnectLastSSID(
24071 + IN PRTMP_ADAPTER pAd)
24072 +{
24073 +
24074 +
24075 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24076 + if ((pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) &&
24077 + (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE))
24078 + {
24079 + NDIS_802_11_SSID OidSsid;
24080 + OidSsid.SsidLength = pAd->MlmeAux.AutoReconnectSsidLen;
24081 + NdisMoveMemory(OidSsid.Ssid, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
24082 +
24083 + DBGPRINT(RT_DEBUG_TRACE, ("Driver auto reconnect to last OID_802_11_SSID setting - %s, len - %d\n", pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen));
24084 + MlmeEnqueue(pAd,
24085 + MLME_CNTL_STATE_MACHINE,
24086 + OID_802_11_SSID,
24087 + sizeof(NDIS_802_11_SSID),
24088 + &OidSsid);
24089 + RT28XX_MLME_HANDLER(pAd);
24090 + }
24091 +}
24092 +#endif // CONFIG_STA_SUPPORT //
24093 +
24094 +/*
24095 + ==========================================================================
24096 + Validate SSID for connection try and rescan purpose
24097 + Valid SSID will have visible chars only.
24098 + The valid length is from 0 to 32.
24099 + IRQL = DISPATCH_LEVEL
24100 + ==========================================================================
24101 + */
24102 +BOOLEAN MlmeValidateSSID(
24103 + IN PUCHAR pSsid,
24104 + IN UCHAR SsidLen)
24105 +{
24106 + int index;
24107 +
24108 + if (SsidLen > MAX_LEN_OF_SSID)
24109 + return (FALSE);
24110 +
24111 + // Check each character value
24112 + for (index = 0; index < SsidLen; index++)
24113 + {
24114 + if (pSsid[index] < 0x20)
24115 + return (FALSE);
24116 + }
24117 +
24118 + // All checked
24119 + return (TRUE);
24120 +}
24121 +
24122 +VOID MlmeSelectTxRateTable(
24123 + IN PRTMP_ADAPTER pAd,
24124 + IN PMAC_TABLE_ENTRY pEntry,
24125 + IN PUCHAR *ppTable,
24126 + IN PUCHAR pTableSize,
24127 + IN PUCHAR pInitTxRateIdx)
24128 +{
24129 + do
24130 + {
24131 + // decide the rate table for tuning
24132 + if (pAd->CommonCfg.TxRateTableSize > 0)
24133 + {
24134 + *ppTable = RateSwitchTable;
24135 + *pTableSize = RateSwitchTable[0];
24136 + *pInitTxRateIdx = RateSwitchTable[1];
24137 +
24138 + break;
24139 + }
24140 +
24141 +#ifdef CONFIG_STA_SUPPORT
24142 + if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd))
24143 + {
24144 +#ifdef DOT11_N_SUPPORT
24145 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) &&
24146 + (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24147 + ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24148 + {// 11N 1S Adhoc
24149 + *ppTable = RateSwitchTable11N1S;
24150 + *pTableSize = RateSwitchTable11N1S[0];
24151 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24152 +
24153 + }
24154 + else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) &&
24155 + (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24156 + (pEntry->HTCapability.MCSSet[1] == 0xff) &&
24157 + (pAd->Antenna.field.TxPath == 2))
24158 + {// 11N 2S Adhoc
24159 + if (pAd->LatchRfRegs.Channel <= 14)
24160 + {
24161 + *ppTable = RateSwitchTable11N2S;
24162 + *pTableSize = RateSwitchTable11N2S[0];
24163 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24164 + }
24165 + else
24166 + {
24167 + *ppTable = RateSwitchTable11N2SForABand;
24168 + *pTableSize = RateSwitchTable11N2SForABand[0];
24169 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24170 + }
24171 +
24172 + }
24173 + else
24174 +#endif // DOT11_N_SUPPORT //
24175 + if ((pEntry->RateLen == 4)
24176 +#ifdef DOT11_N_SUPPORT
24177 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24178 +#endif // DOT11_N_SUPPORT //
24179 + )
24180 + {
24181 + *ppTable = RateSwitchTable11B;
24182 + *pTableSize = RateSwitchTable11B[0];
24183 + *pInitTxRateIdx = RateSwitchTable11B[1];
24184 +
24185 + }
24186 + else if (pAd->LatchRfRegs.Channel <= 14)
24187 + {
24188 + *ppTable = RateSwitchTable11BG;
24189 + *pTableSize = RateSwitchTable11BG[0];
24190 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24191 +
24192 + }
24193 + else
24194 + {
24195 + *ppTable = RateSwitchTable11G;
24196 + *pTableSize = RateSwitchTable11G[0];
24197 + *pInitTxRateIdx = RateSwitchTable11G[1];
24198 +
24199 + }
24200 + break;
24201 + }
24202 +#endif // CONFIG_STA_SUPPORT //
24203 +
24204 +#ifdef DOT11_N_SUPPORT
24205 + //if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) &&
24206 + // ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24207 + if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24208 + ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1)))
24209 + {// 11BGN 1S AP
24210 + *ppTable = RateSwitchTable11BGN1S;
24211 + *pTableSize = RateSwitchTable11BGN1S[0];
24212 + *pInitTxRateIdx = RateSwitchTable11BGN1S[1];
24213 +
24214 + break;
24215 + }
24216 +
24217 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) &&
24218 + // (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2))
24219 + if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24220 + (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2))
24221 + {// 11BGN 2S AP
24222 + if (pAd->LatchRfRegs.Channel <= 14)
24223 + {
24224 + *ppTable = RateSwitchTable11BGN2S;
24225 + *pTableSize = RateSwitchTable11BGN2S[0];
24226 + *pInitTxRateIdx = RateSwitchTable11BGN2S[1];
24227 +
24228 + }
24229 + else
24230 + {
24231 + *ppTable = RateSwitchTable11BGN2SForABand;
24232 + *pTableSize = RateSwitchTable11BGN2SForABand[0];
24233 + *pInitTxRateIdx = RateSwitchTable11BGN2SForABand[1];
24234 +
24235 + }
24236 + break;
24237 + }
24238 +
24239 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24240 + if ((pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1)))
24241 + {// 11N 1S AP
24242 + *ppTable = RateSwitchTable11N1S;
24243 + *pTableSize = RateSwitchTable11N1S[0];
24244 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24245 +
24246 + break;
24247 + }
24248 +
24249 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2))
24250 + if ((pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2))
24251 + {// 11N 2S AP
24252 + if (pAd->LatchRfRegs.Channel <= 14)
24253 + {
24254 + *ppTable = RateSwitchTable11N2S;
24255 + *pTableSize = RateSwitchTable11N2S[0];
24256 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24257 + }
24258 + else
24259 + {
24260 + *ppTable = RateSwitchTable11N2SForABand;
24261 + *pTableSize = RateSwitchTable11N2SForABand[0];
24262 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24263 + }
24264 +
24265 + break;
24266 + }
24267 +#endif // DOT11_N_SUPPORT //
24268 + //else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24269 + if ((pEntry->RateLen == 4)
24270 +#ifdef DOT11_N_SUPPORT
24271 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24272 +#endif // DOT11_N_SUPPORT //
24273 + )
24274 + {// B only AP
24275 + *ppTable = RateSwitchTable11B;
24276 + *pTableSize = RateSwitchTable11B[0];
24277 + *pInitTxRateIdx = RateSwitchTable11B[1];
24278 +
24279 + break;
24280 + }
24281 +
24282 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24283 + if ((pEntry->RateLen > 8)
24284 +#ifdef DOT11_N_SUPPORT
24285 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24286 +#endif // DOT11_N_SUPPORT //
24287 + )
24288 + {// B/G mixed AP
24289 + *ppTable = RateSwitchTable11BG;
24290 + *pTableSize = RateSwitchTable11BG[0];
24291 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24292 +
24293 + break;
24294 + }
24295 +
24296 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24297 + if ((pEntry->RateLen == 8)
24298 +#ifdef DOT11_N_SUPPORT
24299 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24300 +#endif // DOT11_N_SUPPORT //
24301 + )
24302 + {// G only AP
24303 + *ppTable = RateSwitchTable11G;
24304 + *pTableSize = RateSwitchTable11G[0];
24305 + *pInitTxRateIdx = RateSwitchTable11G[1];
24306 +
24307 + break;
24308 + }
24309 +#ifdef DOT11_N_SUPPORT
24310 +#endif // DOT11_N_SUPPORT //
24311 +
24312 +#ifdef CONFIG_STA_SUPPORT
24313 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
24314 + {
24315 +#ifdef DOT11_N_SUPPORT
24316 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24317 + if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0))
24318 +#endif // DOT11_N_SUPPORT //
24319 + { // Legacy mode
24320 + if (pAd->CommonCfg.MaxTxRate <= RATE_11)
24321 + {
24322 + *ppTable = RateSwitchTable11B;
24323 + *pTableSize = RateSwitchTable11B[0];
24324 + *pInitTxRateIdx = RateSwitchTable11B[1];
24325 + }
24326 + else if ((pAd->CommonCfg.MaxTxRate > RATE_11) && (pAd->CommonCfg.MinTxRate > RATE_11))
24327 + {
24328 + *ppTable = RateSwitchTable11G;
24329 + *pTableSize = RateSwitchTable11G[0];
24330 + *pInitTxRateIdx = RateSwitchTable11G[1];
24331 +
24332 + }
24333 + else
24334 + {
24335 + *ppTable = RateSwitchTable11BG;
24336 + *pTableSize = RateSwitchTable11BG[0];
24337 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24338 + }
24339 + break;
24340 + }
24341 +#ifdef DOT11_N_SUPPORT
24342 + if (pAd->LatchRfRegs.Channel <= 14)
24343 + {
24344 + if (pAd->CommonCfg.TxStream == 1)
24345 + {
24346 + *ppTable = RateSwitchTable11N1S;
24347 + *pTableSize = RateSwitchTable11N1S[0];
24348 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24349 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n"));
24350 + }
24351 + else
24352 + {
24353 + *ppTable = RateSwitchTable11N2S;
24354 + *pTableSize = RateSwitchTable11N2S[0];
24355 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24356 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n"));
24357 + }
24358 + }
24359 + else
24360 + {
24361 + if (pAd->CommonCfg.TxStream == 1)
24362 + {
24363 + *ppTable = RateSwitchTable11N1S;
24364 + *pTableSize = RateSwitchTable11N1S[0];
24365 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24366 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n"));
24367 + }
24368 + else
24369 + {
24370 + *ppTable = RateSwitchTable11N2SForABand;
24371 + *pTableSize = RateSwitchTable11N2SForABand[0];
24372 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24373 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n"));
24374 + }
24375 + }
24376 +#endif // DOT11_N_SUPPORT //
24377 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n",
24378 + pAd->StaActive.SupRateLen, pAd->StaActive.ExtRateLen, pAd->StaActive.SupportedPhyInfo.MCSSet[0], pAd->StaActive.SupportedPhyInfo.MCSSet[1]));
24379 + }
24380 +#endif // CONFIG_STA_SUPPORT //
24381 + } while(FALSE);
24382 +}
24383 +
24384 +#ifdef CONFIG_STA_SUPPORT
24385 +/*
24386 + ==========================================================================
24387 + Description:
24388 + This routine checks if there're other APs out there capable for
24389 + roaming. Caller should call this routine only when Link up in INFRA mode
24390 + and channel quality is below CQI_GOOD_THRESHOLD.
24391 +
24392 + IRQL = DISPATCH_LEVEL
24393 +
24394 + Output:
24395 + ==========================================================================
24396 + */
24397 +VOID MlmeCheckForRoaming(
24398 + IN PRTMP_ADAPTER pAd,
24399 + IN ULONG Now32)
24400 +{
24401 + USHORT i;
24402 + BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab;
24403 + BSS_ENTRY *pBss;
24404 +
24405 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForRoaming\n"));
24406 + // put all roaming candidates into RoamTab, and sort in RSSI order
24407 + BssTableInit(pRoamTab);
24408 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
24409 + {
24410 + pBss = &pAd->ScanTab.BssEntry[i];
24411 +
24412 + if ((pBss->LastBeaconRxTime + BEACON_LOST_TIME) < Now32)
24413 + continue; // AP disappear
24414 + if (pBss->Rssi <= RSSI_THRESHOLD_FOR_ROAMING)
24415 + continue; // RSSI too weak. forget it.
24416 + if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
24417 + continue; // skip current AP
24418 + if (pBss->Rssi < (pAd->StaCfg.RssiSample.LastRssi0 + RSSI_DELTA))
24419 + continue; // only AP with stronger RSSI is eligible for roaming
24420 +
24421 + // AP passing all above rules is put into roaming candidate table
24422 + NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY));
24423 + pRoamTab->BssNr += 1;
24424 + }
24425 +
24426 + if (pRoamTab->BssNr > 0)
24427 + {
24428 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24429 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24430 + {
24431 + pAd->RalinkCounters.PoorCQIRoamingCount ++;
24432 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount));
24433 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL);
24434 + RT28XX_MLME_HANDLER(pAd);
24435 + }
24436 + }
24437 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForRoaming(# of candidate= %d)\n",pRoamTab->BssNr));
24438 +}
24439 +
24440 +/*
24441 + ==========================================================================
24442 + Description:
24443 + This routine checks if there're other APs out there capable for
24444 + roaming. Caller should call this routine only when link up in INFRA mode
24445 + and channel quality is below CQI_GOOD_THRESHOLD.
24446 +
24447 + IRQL = DISPATCH_LEVEL
24448 +
24449 + Output:
24450 + ==========================================================================
24451 + */
24452 +VOID MlmeCheckForFastRoaming(
24453 + IN PRTMP_ADAPTER pAd,
24454 + IN ULONG Now)
24455 +{
24456 + USHORT i;
24457 + BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab;
24458 + BSS_ENTRY *pBss;
24459 +
24460 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForFastRoaming\n"));
24461 + // put all roaming candidates into RoamTab, and sort in RSSI order
24462 + BssTableInit(pRoamTab);
24463 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
24464 + {
24465 + pBss = &pAd->ScanTab.BssEntry[i];
24466 +
24467 + if ((pBss->Rssi <= -50) && (pBss->Channel == pAd->CommonCfg.Channel))
24468 + continue; // RSSI too weak. forget it.
24469 + if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
24470 + continue; // skip current AP
24471 + if (!SSID_EQUAL(pBss->Ssid, pBss->SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))
24472 + continue; // skip different SSID
24473 + if (pBss->Rssi < (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) + RSSI_DELTA))
24474 + continue; // skip AP without better RSSI
24475 +
24476 + 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));
24477 + // AP passing all above rules is put into roaming candidate table
24478 + NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY));
24479 + pRoamTab->BssNr += 1;
24480 + }
24481 +
24482 + if (pRoamTab->BssNr > 0)
24483 + {
24484 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24485 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24486 + {
24487 + pAd->RalinkCounters.PoorCQIRoamingCount ++;
24488 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount));
24489 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL);
24490 + RT28XX_MLME_HANDLER(pAd);
24491 + }
24492 + }
24493 + // Maybe site survey required
24494 + else
24495 + {
24496 + if ((pAd->StaCfg.LastScanTime + 10 * 1000) < Now)
24497 + {
24498 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24499 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming, No eligable entry, try new scan!\n"));
24500 + pAd->StaCfg.ScanCnt = 2;
24501 + pAd->StaCfg.LastScanTime = Now;
24502 + MlmeAutoScan(pAd);
24503 + }
24504 + }
24505 +
24506 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForFastRoaming (BssNr=%d)\n", pRoamTab->BssNr));
24507 +}
24508 +
24509 +/*
24510 + ==========================================================================
24511 + Description:
24512 + This routine calculates TxPER, RxPER of the past N-sec period. And
24513 + according to the calculation result, ChannelQuality is calculated here
24514 + to decide if current AP is still doing the job.
24515 +
24516 + If ChannelQuality is not good, a ROAMing attempt may be tried later.
24517 + Output:
24518 + StaCfg.ChannelQuality - 0..100
24519 +
24520 + IRQL = DISPATCH_LEVEL
24521 +
24522 + NOTE: This routine decide channle quality based on RX CRC error ratio.
24523 + Caller should make sure a function call to NICUpdateRawCounters(pAd)
24524 + is performed right before this routine, so that this routine can decide
24525 + channel quality based on the most up-to-date information
24526 + ==========================================================================
24527 + */
24528 +VOID MlmeCalculateChannelQuality(
24529 + IN PRTMP_ADAPTER pAd,
24530 + IN ULONG Now32)
24531 +{
24532 + ULONG TxOkCnt, TxCnt, TxPER, TxPRR;
24533 + ULONG RxCnt, RxPER;
24534 + UCHAR NorRssi;
24535 + CHAR MaxRssi;
24536 + ULONG BeaconLostTime = BEACON_LOST_TIME;
24537 +
24538 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
24539 + // longer beacon lost time when carrier detection enabled
24540 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
24541 + {
24542 + BeaconLostTime = BEACON_LOST_TIME + BEACON_LOST_TIME/2;
24543 + }
24544 +#endif // CARRIER_DETECTION_SUPPORT //
24545 +
24546 + MaxRssi = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
24547 +
24548 + //
24549 + // calculate TX packet error ratio and TX retry ratio - if too few TX samples, skip TX related statistics
24550 + //
24551 + TxOkCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + pAd->RalinkCounters.OneSecTxRetryOkCount;
24552 + TxCnt = TxOkCnt + pAd->RalinkCounters.OneSecTxFailCount;
24553 + if (TxCnt < 5)
24554 + {
24555 + TxPER = 0;
24556 + TxPRR = 0;
24557 + }
24558 + else
24559 + {
24560 + TxPER = (pAd->RalinkCounters.OneSecTxFailCount * 100) / TxCnt;
24561 + TxPRR = ((TxCnt - pAd->RalinkCounters.OneSecTxNoRetryOkCount) * 100) / TxCnt;
24562 + }
24563 +
24564 + //
24565 + // calculate RX PER - don't take RxPER into consideration if too few sample
24566 + //
24567 + RxCnt = pAd->RalinkCounters.OneSecRxOkCnt + pAd->RalinkCounters.OneSecRxFcsErrCnt;
24568 + if (RxCnt < 5)
24569 + RxPER = 0;
24570 + else
24571 + RxPER = (pAd->RalinkCounters.OneSecRxFcsErrCnt * 100) / RxCnt;
24572 +
24573 + //
24574 + // decide ChannelQuality based on: 1)last BEACON received time, 2)last RSSI, 3)TxPER, and 4)RxPER
24575 + //
24576 + if (INFRA_ON(pAd) &&
24577 + (pAd->RalinkCounters.OneSecTxNoRetryOkCount < 2) && // no heavy traffic
24578 + (pAd->StaCfg.LastBeaconRxTime + BeaconLostTime < Now32))
24579 + {
24580 + DBGPRINT(RT_DEBUG_TRACE, ("BEACON lost > %ld msec with TxOkCnt=%ld -> CQI=0\n", BeaconLostTime, TxOkCnt));
24581 + pAd->Mlme.ChannelQuality = 0;
24582 + }
24583 + else
24584 + {
24585 + // Normalize Rssi
24586 + if (MaxRssi > -40)
24587 + NorRssi = 100;
24588 + else if (MaxRssi < -90)
24589 + NorRssi = 0;
24590 + else
24591 + NorRssi = (MaxRssi + 90) * 2;
24592 +
24593 + // ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER (RSSI 0..100), (TxPER 100..0), (RxPER 100..0)
24594 + pAd->Mlme.ChannelQuality = (RSSI_WEIGHTING * NorRssi +
24595 + TX_WEIGHTING * (100 - TxPRR) +
24596 + RX_WEIGHTING* (100 - RxPER)) / 100;
24597 + if (pAd->Mlme.ChannelQuality >= 100)
24598 + pAd->Mlme.ChannelQuality = 100;
24599 + }
24600 +
24601 +}
24602 +
24603 +VOID MlmeSetTxRate(
24604 + IN PRTMP_ADAPTER pAd,
24605 + IN PMAC_TABLE_ENTRY pEntry,
24606 + IN PRTMP_TX_RATE_SWITCH pTxRate)
24607 +{
24608 + UCHAR MaxMode = MODE_OFDM;
24609 +
24610 +#ifdef DOT11_N_SUPPORT
24611 + MaxMode = MODE_HTGREENFIELD;
24612 +
24613 + if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC) && (pAd->Antenna.field.TxPath == 2))
24614 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE;
24615 + else
24616 +#endif // DOT11_N_SUPPORT //
24617 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
24618 +
24619 + if (pTxRate->CurrMCS < MCS_AUTO)
24620 + pAd->StaCfg.HTPhyMode.field.MCS = pTxRate->CurrMCS;
24621 +
24622 + if (pAd->StaCfg.HTPhyMode.field.MCS > 7)
24623 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
24624 +
24625 + if (ADHOC_ON(pAd))
24626 + {
24627 + // If peer adhoc is b-only mode, we can't send 11g rate.
24628 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24629 + pEntry->HTPhyMode.field.STBC = STBC_NONE;
24630 +
24631 + //
24632 + // For Adhoc MODE_CCK, driver will use AdhocBOnlyJoined flag to roll back to B only if necessary
24633 + //
24634 + pEntry->HTPhyMode.field.MODE = pTxRate->Mode;
24635 + pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI;
24636 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24637 +
24638 + // Patch speed error in status page
24639 + pAd->StaCfg.HTPhyMode.field.MODE = pEntry->HTPhyMode.field.MODE;
24640 + }
24641 + else
24642 + {
24643 + if (pTxRate->Mode <= MaxMode)
24644 + pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode;
24645 +
24646 +#ifdef DOT11_N_SUPPORT
24647 + if (pTxRate->ShortGI && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI))
24648 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400;
24649 + else
24650 +#endif // DOT11_N_SUPPORT //
24651 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24652 +
24653 +#ifdef DOT11_N_SUPPORT
24654 + // Reexam each bandwidth's SGI support.
24655 + if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400)
24656 + {
24657 + if ((pEntry->HTPhyMode.field.BW == BW_20) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE)))
24658 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24659 + if ((pEntry->HTPhyMode.field.BW == BW_40) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE)))
24660 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24661 + }
24662 +
24663 + // Turn RTS/CTS rate to 6Mbps.
24664 + if ((pEntry->HTPhyMode.field.MCS == 0) && (pAd->StaCfg.HTPhyMode.field.MCS != 0))
24665 + {
24666 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24667 + if (pAd->MacTab.fAnyBASession)
24668 + {
24669 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24670 + }
24671 + else
24672 + {
24673 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24674 + }
24675 + }
24676 + else if ((pEntry->HTPhyMode.field.MCS == 8) && (pAd->StaCfg.HTPhyMode.field.MCS != 8))
24677 + {
24678 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24679 + if (pAd->MacTab.fAnyBASession)
24680 + {
24681 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24682 + }
24683 + else
24684 + {
24685 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24686 + }
24687 + }
24688 + else if ((pEntry->HTPhyMode.field.MCS != 0) && (pAd->StaCfg.HTPhyMode.field.MCS == 0))
24689 + {
24690 + AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24691 +
24692 + }
24693 + else if ((pEntry->HTPhyMode.field.MCS != 8) && (pAd->StaCfg.HTPhyMode.field.MCS == 8))
24694 + {
24695 + AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24696 + }
24697 +#endif // DOT11_N_SUPPORT //
24698 +
24699 + pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC;
24700 + pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI;
24701 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24702 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
24703 +#ifdef DOT11_N_SUPPORT
24704 + if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD) &&
24705 + pAd->WIFItestbed.bGreenField)
24706 + pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD;
24707 +#endif // DOT11_N_SUPPORT //
24708 + }
24709 +
24710 + pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
24711 +}
24712 +
24713 +/*
24714 + ==========================================================================
24715 + Description:
24716 + This routine calculates the acumulated TxPER of eaxh TxRate. And
24717 + according to the calculation result, change CommonCfg.TxRate which
24718 + is the stable TX Rate we expect the Radio situation could sustained.
24719 +
24720 + CommonCfg.TxRate will change dynamically within {RATE_1/RATE_6, MaxTxRate}
24721 + Output:
24722 + CommonCfg.TxRate -
24723 +
24724 + IRQL = DISPATCH_LEVEL
24725 +
24726 + NOTE:
24727 + call this routine every second
24728 + ==========================================================================
24729 + */
24730 +VOID MlmeDynamicTxRateSwitching(
24731 + IN PRTMP_ADAPTER pAd)
24732 +{
24733 + UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx;
24734 + ULONG i, AccuTxTotalCnt = 0, TxTotalCnt;
24735 + ULONG TxErrorRatio = 0;
24736 + BOOLEAN bTxRateChanged, bUpgradeQuality = FALSE;
24737 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL;
24738 + PUCHAR pTable;
24739 + UCHAR TableSize = 0;
24740 + UCHAR InitTxRateIdx = 0, TrainUp, TrainDown;
24741 + CHAR Rssi, RssiOffset = 0;
24742 + TX_STA_CNT1_STRUC StaTx1;
24743 + TX_STA_CNT0_STRUC TxStaCnt0;
24744 + ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
24745 + MAC_TABLE_ENTRY *pEntry;
24746 +
24747 +#ifdef RALINK_ATE
24748 + if (ATE_ON(pAd))
24749 + {
24750 + return;
24751 + }
24752 +#endif // RALINK_ATE //
24753 +
24754 + //
24755 + // walk through MAC table, see if need to change AP's TX rate toward each entry
24756 + //
24757 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
24758 + {
24759 + pEntry = &pAd->MacTab.Content[i];
24760 +
24761 + // check if this entry need to switch rate automatically
24762 + if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
24763 + continue;
24764 +
24765 + if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls))
24766 + {
24767 + Rssi = RTMPMaxRssi(pAd,
24768 + pAd->StaCfg.RssiSample.AvgRssi0,
24769 + pAd->StaCfg.RssiSample.AvgRssi1,
24770 + pAd->StaCfg.RssiSample.AvgRssi2);
24771 +
24772 + // Update statistic counter
24773 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
24774 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
24775 + pAd->bUpdateBcnCntDone = TRUE;
24776 + TxRetransmit = StaTx1.field.TxRetransmit;
24777 + TxSuccess = StaTx1.field.TxSuccess;
24778 + TxFailCount = TxStaCnt0.field.TxFailCount;
24779 + TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
24780 +
24781 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
24782 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
24783 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
24784 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
24785 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
24786 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
24787 +
24788 + // if no traffic in the past 1-sec period, don't change TX rate,
24789 + // but clear all bad history. because the bad history may affect the next
24790 + // Chariot throughput test
24791 + AccuTxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
24792 + pAd->RalinkCounters.OneSecTxRetryOkCount +
24793 + pAd->RalinkCounters.OneSecTxFailCount;
24794 +
24795 + if (TxTotalCnt)
24796 + TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt;
24797 + }
24798 + else
24799 + {
24800 + if (INFRA_ON(pAd) && (i == 1))
24801 + Rssi = RTMPMaxRssi(pAd,
24802 + pAd->StaCfg.RssiSample.AvgRssi0,
24803 + pAd->StaCfg.RssiSample.AvgRssi1,
24804 + pAd->StaCfg.RssiSample.AvgRssi2);
24805 + else
24806 + Rssi = RTMPMaxRssi(pAd,
24807 + pEntry->RssiSample.AvgRssi0,
24808 + pEntry->RssiSample.AvgRssi1,
24809 + pEntry->RssiSample.AvgRssi2);
24810 +
24811 + TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
24812 + pEntry->OneSecTxRetryOkCount +
24813 + pEntry->OneSecTxFailCount;
24814 +
24815 + if (TxTotalCnt)
24816 + TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt;
24817 + }
24818 +
24819 + CurrRateIdx = pEntry->CurrTxRateIndex;
24820 +
24821 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx);
24822 +
24823 + if (CurrRateIdx >= TableSize)
24824 + {
24825 + CurrRateIdx = TableSize - 1;
24826 + }
24827 +
24828 + // When switch from Fixed rate -> auto rate, the REAL TX rate might be different from pAd->CommonCfg.TxRateIndex.
24829 + // So need to sync here.
24830 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
24831 + if ((pEntry->HTPhyMode.field.MCS != pCurrTxRate->CurrMCS)
24832 + //&& (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
24833 + )
24834 + {
24835 +
24836 + // Need to sync Real Tx rate and our record.
24837 + // Then return for next DRS.
24838 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(InitTxRateIdx+1)*5];
24839 + pEntry->CurrTxRateIndex = InitTxRateIdx;
24840 + MlmeSetTxRate(pAd, pEntry, pCurrTxRate);
24841 +
24842 + // reset all OneSecTx counters
24843 + RESET_ONE_SEC_TX_CNT(pEntry);
24844 + continue;
24845 + }
24846 +
24847 + // decide the next upgrade rate and downgrade rate, if any
24848 + if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1)))
24849 + {
24850 + UpRateIdx = CurrRateIdx + 1;
24851 + DownRateIdx = CurrRateIdx -1;
24852 + }
24853 + else if (CurrRateIdx == 0)
24854 + {
24855 + UpRateIdx = CurrRateIdx + 1;
24856 + DownRateIdx = CurrRateIdx;
24857 + }
24858 + else if (CurrRateIdx == (TableSize - 1))
24859 + {
24860 + UpRateIdx = CurrRateIdx;
24861 + DownRateIdx = CurrRateIdx - 1;
24862 + }
24863 +
24864 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
24865 +
24866 +#ifdef DOT11_N_SUPPORT
24867 + if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX))
24868 + {
24869 + TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1));
24870 + TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1));
24871 + }
24872 + else
24873 +#endif // DOT11_N_SUPPORT //
24874 + {
24875 + TrainUp = pCurrTxRate->TrainUp;
24876 + TrainDown = pCurrTxRate->TrainDown;
24877 + }
24878 +
24879 + //pAd->DrsCounters.LastTimeTxRateChangeAction = pAd->DrsCounters.LastSecTxRateChangeAction;
24880 +
24881 + //
24882 + // Keep the last time TxRateChangeAction status.
24883 + //
24884 + pEntry->LastTimeTxRateChangeAction = pEntry->LastSecTxRateChangeAction;
24885 +
24886 +
24887 +
24888 + //
24889 + // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI
24890 + // (criteria copied from RT2500 for Netopia case)
24891 + //
24892 + if (TxTotalCnt <= 15)
24893 + {
24894 + CHAR idx = 0;
24895 + UCHAR TxRateIdx;
24896 + //UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS7 = 0, MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0;
24897 + UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS5 =0, MCS6 = 0, MCS7 = 0;
24898 + UCHAR MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0;
24899 + UCHAR MCS20 = 0, MCS21 = 0, MCS22 = 0, MCS23 = 0; // 3*3
24900 +
24901 + // check the existence and index of each needed MCS
24902 + while (idx < pTable[0])
24903 + {
24904 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(idx+1)*5];
24905 +
24906 + if (pCurrTxRate->CurrMCS == MCS_0)
24907 + {
24908 + MCS0 = idx;
24909 + }
24910 + else if (pCurrTxRate->CurrMCS == MCS_1)
24911 + {
24912 + MCS1 = idx;
24913 + }
24914 + else if (pCurrTxRate->CurrMCS == MCS_2)
24915 + {
24916 + MCS2 = idx;
24917 + }
24918 + else if (pCurrTxRate->CurrMCS == MCS_3)
24919 + {
24920 + MCS3 = idx;
24921 + }
24922 + else if (pCurrTxRate->CurrMCS == MCS_4)
24923 + {
24924 + MCS4 = idx;
24925 + }
24926 + else if (pCurrTxRate->CurrMCS == MCS_5)
24927 + {
24928 + MCS5 = idx;
24929 + }
24930 + else if (pCurrTxRate->CurrMCS == MCS_6)
24931 + {
24932 + MCS6 = idx;
24933 + }
24934 + //else if (pCurrTxRate->CurrMCS == MCS_7)
24935 + else if ((pCurrTxRate->CurrMCS == MCS_7) && (pCurrTxRate->ShortGI == GI_800)) // prevent the highest MCS using short GI when 1T and low throughput
24936 + {
24937 + MCS7 = idx;
24938 + }
24939 + else if (pCurrTxRate->CurrMCS == MCS_12)
24940 + {
24941 + MCS12 = idx;
24942 + }
24943 + else if (pCurrTxRate->CurrMCS == MCS_13)
24944 + {
24945 + MCS13 = idx;
24946 + }
24947 + else if (pCurrTxRate->CurrMCS == MCS_14)
24948 + {
24949 + MCS14 = idx;
24950 + }
24951 + //else if ((pCurrTxRate->CurrMCS == MCS_15)/* && (pCurrTxRate->ShortGI == GI_800)*/) //we hope to use ShortGI as initial rate
24952 + else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800)) //we hope to use ShortGI as initial rate, however Atheros's chip has bugs when short GI
24953 + {
24954 + MCS15 = idx;
24955 + }
24956 + else if (pCurrTxRate->CurrMCS == MCS_20) // 3*3
24957 + {
24958 + MCS20 = idx;
24959 + }
24960 + else if (pCurrTxRate->CurrMCS == MCS_21)
24961 + {
24962 + MCS21 = idx;
24963 + }
24964 + else if (pCurrTxRate->CurrMCS == MCS_22)
24965 + {
24966 + MCS22 = idx;
24967 + }
24968 + else if (pCurrTxRate->CurrMCS == MCS_23)
24969 + {
24970 + MCS23 = idx;
24971 + }
24972 + idx ++;
24973 + }
24974 +
24975 + if (pAd->LatchRfRegs.Channel <= 14)
24976 + {
24977 + if (pAd->NicConfig2.field.ExternalLNAForG)
24978 + {
24979 + RssiOffset = 2;
24980 + }
24981 + else
24982 + {
24983 + RssiOffset = 5;
24984 + }
24985 + }
24986 + else
24987 + {
24988 + if (pAd->NicConfig2.field.ExternalLNAForA)
24989 + {
24990 + RssiOffset = 5;
24991 + }
24992 + else
24993 + {
24994 + RssiOffset = 8;
24995 + }
24996 + }
24997 +#ifdef DOT11_N_SUPPORT
24998 + /*if (MCS15)*/
24999 + if ((pTable == RateSwitchTable11BGN3S) ||
25000 + (pTable == RateSwitchTable11N3S) ||
25001 + (pTable == RateSwitchTable))
25002 + {// N mode with 3 stream // 3*3
25003 + if (MCS23 && (Rssi >= -70))
25004 + TxRateIdx = MCS15;
25005 + else if (MCS22 && (Rssi >= -72))
25006 + TxRateIdx = MCS14;
25007 + else if (MCS21 && (Rssi >= -76))
25008 + TxRateIdx = MCS13;
25009 + else if (MCS20 && (Rssi >= -78))
25010 + TxRateIdx = MCS12;
25011 + else if (MCS4 && (Rssi >= -82))
25012 + TxRateIdx = MCS4;
25013 + else if (MCS3 && (Rssi >= -84))
25014 + TxRateIdx = MCS3;
25015 + else if (MCS2 && (Rssi >= -86))
25016 + TxRateIdx = MCS2;
25017 + else if (MCS1 && (Rssi >= -88))
25018 + TxRateIdx = MCS1;
25019 + else
25020 + TxRateIdx = MCS0;
25021 + }
25022 +// else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand) || (pTable == RateSwitchTable))
25023 + else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand)) // 3*3
25024 + {// N mode with 2 stream
25025 + if (MCS15 && (Rssi >= (-70+RssiOffset)))
25026 + TxRateIdx = MCS15;
25027 + else if (MCS14 && (Rssi >= (-72+RssiOffset)))
25028 + TxRateIdx = MCS14;
25029 + else if (MCS13 && (Rssi >= (-76+RssiOffset)))
25030 + TxRateIdx = MCS13;
25031 + else if (MCS12 && (Rssi >= (-78+RssiOffset)))
25032 + TxRateIdx = MCS12;
25033 + else if (MCS4 && (Rssi >= (-82+RssiOffset)))
25034 + TxRateIdx = MCS4;
25035 + else if (MCS3 && (Rssi >= (-84+RssiOffset)))
25036 + TxRateIdx = MCS3;
25037 + else if (MCS2 && (Rssi >= (-86+RssiOffset)))
25038 + TxRateIdx = MCS2;
25039 + else if (MCS1 && (Rssi >= (-88+RssiOffset)))
25040 + TxRateIdx = MCS1;
25041 + else
25042 + TxRateIdx = MCS0;
25043 + }
25044 + else if ((pTable == RateSwitchTable11BGN1S) || (pTable == RateSwitchTable11N1S))
25045 + {// N mode with 1 stream
25046 + if (MCS7 && (Rssi > (-72+RssiOffset)))
25047 + TxRateIdx = MCS7;
25048 + else if (MCS6 && (Rssi > (-74+RssiOffset)))
25049 + TxRateIdx = MCS6;
25050 + else if (MCS5 && (Rssi > (-77+RssiOffset)))
25051 + TxRateIdx = MCS5;
25052 + else if (MCS4 && (Rssi > (-79+RssiOffset)))
25053 + TxRateIdx = MCS4;
25054 + else if (MCS3 && (Rssi > (-81+RssiOffset)))
25055 + TxRateIdx = MCS3;
25056 + else if (MCS2 && (Rssi > (-83+RssiOffset)))
25057 + TxRateIdx = MCS2;
25058 + else if (MCS1 && (Rssi > (-86+RssiOffset)))
25059 + TxRateIdx = MCS1;
25060 + else
25061 + TxRateIdx = MCS0;
25062 + }
25063 + else
25064 +#endif // DOT11_N_SUPPORT //
25065 + {// Legacy mode
25066 + if (MCS7 && (Rssi > -70))
25067 + TxRateIdx = MCS7;
25068 + else if (MCS6 && (Rssi > -74))
25069 + TxRateIdx = MCS6;
25070 + else if (MCS5 && (Rssi > -78))
25071 + TxRateIdx = MCS5;
25072 + else if (MCS4 && (Rssi > -82))
25073 + TxRateIdx = MCS4;
25074 + else if (MCS4 == 0) // for B-only mode
25075 + TxRateIdx = MCS3;
25076 + else if (MCS3 && (Rssi > -85))
25077 + TxRateIdx = MCS3;
25078 + else if (MCS2 && (Rssi > -87))
25079 + TxRateIdx = MCS2;
25080 + else if (MCS1 && (Rssi > -90))
25081 + TxRateIdx = MCS1;
25082 + else
25083 + TxRateIdx = MCS0;
25084 + }
25085 +
25086 + // if (TxRateIdx != pAd->CommonCfg.TxRateIndex)
25087 + {
25088 + pEntry->CurrTxRateIndex = TxRateIdx;
25089 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5];
25090 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25091 + }
25092 +
25093 + NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25094 + NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25095 + pEntry->fLastSecAccordingRSSI = TRUE;
25096 + // reset all OneSecTx counters
25097 + RESET_ONE_SEC_TX_CNT(pEntry);
25098 +
25099 + continue;
25100 + }
25101 +
25102 + if (pEntry->fLastSecAccordingRSSI == TRUE)
25103 + {
25104 + pEntry->fLastSecAccordingRSSI = FALSE;
25105 + pEntry->LastSecTxRateChangeAction = 0;
25106 + // reset all OneSecTx counters
25107 + RESET_ONE_SEC_TX_CNT(pEntry);
25108 +
25109 + continue;
25110 + }
25111 +
25112 + do
25113 + {
25114 + BOOLEAN bTrainUpDown = FALSE;
25115 +
25116 + pEntry->CurrTxRateStableTime ++;
25117 +
25118 + // downgrade TX quality if PER >= Rate-Down threshold
25119 + if (TxErrorRatio >= TrainDown)
25120 + {
25121 + bTrainUpDown = TRUE;
25122 + pEntry->TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25123 + }
25124 + // upgrade TX quality if PER <= Rate-Up threshold
25125 + else if (TxErrorRatio <= TrainUp)
25126 + {
25127 + bTrainUpDown = TRUE;
25128 + bUpgradeQuality = TRUE;
25129 + if (pEntry->TxQuality[CurrRateIdx])
25130 + pEntry->TxQuality[CurrRateIdx] --; // quality very good in CurrRate
25131 +
25132 + if (pEntry->TxRateUpPenalty)
25133 + pEntry->TxRateUpPenalty --;
25134 + else if (pEntry->TxQuality[UpRateIdx])
25135 + pEntry->TxQuality[UpRateIdx] --; // may improve next UP rate's quality
25136 + }
25137 +
25138 + pEntry->PER[CurrRateIdx] = (UCHAR)TxErrorRatio;
25139 +
25140 + if (bTrainUpDown)
25141 + {
25142 + // perform DRS - consider TxRate Down first, then rate up.
25143 + if ((CurrRateIdx != DownRateIdx) && (pEntry->TxQuality[CurrRateIdx] >= DRS_TX_QUALITY_WORST_BOUND))
25144 + {
25145 + pEntry->CurrTxRateIndex = DownRateIdx;
25146 + }
25147 + else if ((CurrRateIdx != UpRateIdx) && (pEntry->TxQuality[UpRateIdx] <= 0))
25148 + {
25149 + pEntry->CurrTxRateIndex = UpRateIdx;
25150 + }
25151 + }
25152 + } while (FALSE);
25153 +
25154 + // if rate-up happen, clear all bad history of all TX rates
25155 + if (pEntry->CurrTxRateIndex > CurrRateIdx)
25156 + {
25157 + pEntry->CurrTxRateStableTime = 0;
25158 + pEntry->TxRateUpPenalty = 0;
25159 + pEntry->LastSecTxRateChangeAction = 1; // rate UP
25160 + NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25161 + NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25162 +
25163 + //
25164 + // For TxRate fast train up
25165 + //
25166 + if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning)
25167 + {
25168 + RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100);
25169 +
25170 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE;
25171 + }
25172 + bTxRateChanged = TRUE;
25173 + }
25174 + // if rate-down happen, only clear DownRate's bad history
25175 + else if (pEntry->CurrTxRateIndex < CurrRateIdx)
25176 + {
25177 + pEntry->CurrTxRateStableTime = 0;
25178 + pEntry->TxRateUpPenalty = 0; // no penalty
25179 + pEntry->LastSecTxRateChangeAction = 2; // rate DOWN
25180 + pEntry->TxQuality[pEntry->CurrTxRateIndex] = 0;
25181 + pEntry->PER[pEntry->CurrTxRateIndex] = 0;
25182 +
25183 + //
25184 + // For TxRate fast train down
25185 + //
25186 + if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning)
25187 + {
25188 + RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100);
25189 +
25190 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE;
25191 + }
25192 + bTxRateChanged = TRUE;
25193 + }
25194 + else
25195 + {
25196 + pEntry->LastSecTxRateChangeAction = 0; // rate no change
25197 + bTxRateChanged = FALSE;
25198 + }
25199 +
25200 + pEntry->LastTxOkCount = TxSuccess;
25201 +
25202 + // reset all OneSecTx counters
25203 + RESET_ONE_SEC_TX_CNT(pEntry);
25204 +
25205 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5];
25206 + if (bTxRateChanged && pNextTxRate)
25207 + {
25208 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25209 + }
25210 + }
25211 +}
25212 +
25213 +/*
25214 + ========================================================================
25215 + Routine Description:
25216 + Station side, Auto TxRate faster train up timer call back function.
25217 +
25218 + Arguments:
25219 + SystemSpecific1 - Not used.
25220 + FunctionContext - Pointer to our Adapter context.
25221 + SystemSpecific2 - Not used.
25222 + SystemSpecific3 - Not used.
25223 +
25224 + Return Value:
25225 + None
25226 +
25227 + ========================================================================
25228 +*/
25229 +VOID StaQuickResponeForRateUpExec(
25230 + IN PVOID SystemSpecific1,
25231 + IN PVOID FunctionContext,
25232 + IN PVOID SystemSpecific2,
25233 + IN PVOID SystemSpecific3)
25234 +{
25235 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext;
25236 + UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0;
25237 + ULONG TxTotalCnt;
25238 + ULONG TxErrorRatio = 0;
25239 + BOOLEAN bTxRateChanged; //, bUpgradeQuality = FALSE;
25240 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL;
25241 + PUCHAR pTable;
25242 + UCHAR TableSize = 0;
25243 + UCHAR InitTxRateIdx = 0, TrainUp, TrainDown;
25244 + TX_STA_CNT1_STRUC StaTx1;
25245 + TX_STA_CNT0_STRUC TxStaCnt0;
25246 + CHAR Rssi, ratio;
25247 + ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
25248 + MAC_TABLE_ENTRY *pEntry;
25249 + ULONG i;
25250 +
25251 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
25252 +
25253 + //
25254 + // walk through MAC table, see if need to change AP's TX rate toward each entry
25255 + //
25256 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
25257 + {
25258 + pEntry = &pAd->MacTab.Content[i];
25259 +
25260 + // check if this entry need to switch rate automatically
25261 + if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
25262 + continue;
25263 +
25264 + if (INFRA_ON(pAd) && (i == 1))
25265 + Rssi = RTMPMaxRssi(pAd,
25266 + pAd->StaCfg.RssiSample.AvgRssi0,
25267 + pAd->StaCfg.RssiSample.AvgRssi1,
25268 + pAd->StaCfg.RssiSample.AvgRssi2);
25269 + else
25270 + Rssi = RTMPMaxRssi(pAd,
25271 + pEntry->RssiSample.AvgRssi0,
25272 + pEntry->RssiSample.AvgRssi1,
25273 + pEntry->RssiSample.AvgRssi2);
25274 +
25275 + CurrRateIdx = pAd->CommonCfg.TxRateIndex;
25276 +
25277 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx);
25278 +
25279 + // decide the next upgrade rate and downgrade rate, if any
25280 + if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1)))
25281 + {
25282 + UpRateIdx = CurrRateIdx + 1;
25283 + DownRateIdx = CurrRateIdx -1;
25284 + }
25285 + else if (CurrRateIdx == 0)
25286 + {
25287 + UpRateIdx = CurrRateIdx + 1;
25288 + DownRateIdx = CurrRateIdx;
25289 + }
25290 + else if (CurrRateIdx == (TableSize - 1))
25291 + {
25292 + UpRateIdx = CurrRateIdx;
25293 + DownRateIdx = CurrRateIdx - 1;
25294 + }
25295 +
25296 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
25297 +
25298 +#ifdef DOT11_N_SUPPORT
25299 + if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX))
25300 + {
25301 + TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1));
25302 + TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1));
25303 + }
25304 + else
25305 +#endif // DOT11_N_SUPPORT //
25306 + {
25307 + TrainUp = pCurrTxRate->TrainUp;
25308 + TrainDown = pCurrTxRate->TrainDown;
25309 + }
25310 +
25311 + if (pAd->MacTab.Size == 1)
25312 + {
25313 + // Update statistic counter
25314 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
25315 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
25316 +
25317 + TxRetransmit = StaTx1.field.TxRetransmit;
25318 + TxSuccess = StaTx1.field.TxSuccess;
25319 + TxFailCount = TxStaCnt0.field.TxFailCount;
25320 + TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
25321 +
25322 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
25323 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
25324 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
25325 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
25326 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
25327 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
25328 +
25329 +#if 0 // test by Gary.
25330 + // if no traffic in the past 1-sec period, don't change TX rate,
25331 + // but clear all bad history. because the bad history may affect the next
25332 + // Chariot throughput test
25333 + TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
25334 + pAd->RalinkCounters.OneSecTxRetryOkCount +
25335 + pAd->RalinkCounters.OneSecTxFailCount;
25336 +#endif
25337 + if (TxTotalCnt)
25338 + TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt;
25339 + }
25340 + else
25341 + {
25342 + TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
25343 + pEntry->OneSecTxRetryOkCount +
25344 + pEntry->OneSecTxFailCount;
25345 +
25346 + if (TxTotalCnt)
25347 + TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt;
25348 + }
25349 +
25350 +
25351 + //
25352 + // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI
25353 + // (criteria copied from RT2500 for Netopia case)
25354 + //
25355 + if (TxTotalCnt <= 12)
25356 + {
25357 + NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25358 + NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25359 +
25360 + if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx))
25361 + {
25362 + pAd->CommonCfg.TxRateIndex = DownRateIdx;
25363 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25364 + }
25365 + else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx))
25366 + {
25367 + pAd->CommonCfg.TxRateIndex = UpRateIdx;
25368 + }
25369 +
25370 + DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: TxTotalCnt <= 15, train back to original rate \n"));
25371 + return;
25372 + }
25373 +
25374 + do
25375 + {
25376 + ULONG OneSecTxNoRetryOKRationCount;
25377 +
25378 + if (pAd->DrsCounters.LastTimeTxRateChangeAction == 0)
25379 + ratio = 5;
25380 + else
25381 + ratio = 4;
25382 +
25383 + // downgrade TX quality if PER >= Rate-Down threshold
25384 + if (TxErrorRatio >= TrainDown)
25385 + {
25386 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25387 + }
25388 +
25389 + pAd->DrsCounters.PER[CurrRateIdx] = (UCHAR)TxErrorRatio;
25390 +
25391 + OneSecTxNoRetryOKRationCount = (TxSuccess * ratio);
25392 +
25393 + // perform DRS - consider TxRate Down first, then rate up.
25394 + if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx))
25395 + {
25396 + if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount)
25397 + {
25398 + pAd->CommonCfg.TxRateIndex = DownRateIdx;
25399 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25400 +
25401 + }
25402 +
25403 + }
25404 + else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx))
25405 + {
25406 + if ((TxErrorRatio >= 50) || (TxErrorRatio >= TrainDown))
25407 + {
25408 +
25409 + }
25410 + else if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount)
25411 + {
25412 + pAd->CommonCfg.TxRateIndex = UpRateIdx;
25413 + }
25414 + }
25415 + }while (FALSE);
25416 +
25417 + // if rate-up happen, clear all bad history of all TX rates
25418 + if (pAd->CommonCfg.TxRateIndex > CurrRateIdx)
25419 + {
25420 + pAd->DrsCounters.TxRateUpPenalty = 0;
25421 + NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25422 + NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25423 + bTxRateChanged = TRUE;
25424 + }
25425 + // if rate-down happen, only clear DownRate's bad history
25426 + else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx)
25427 + {
25428 + DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: --TX rate from %d to %d \n", CurrRateIdx, pAd->CommonCfg.TxRateIndex));
25429 +
25430 + pAd->DrsCounters.TxRateUpPenalty = 0; // no penalty
25431 + pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] = 0;
25432 + pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0;
25433 + bTxRateChanged = TRUE;
25434 + }
25435 + else
25436 + {
25437 + bTxRateChanged = FALSE;
25438 + }
25439 +
25440 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pAd->CommonCfg.TxRateIndex+1)*5];
25441 + if (bTxRateChanged && pNextTxRate)
25442 + {
25443 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25444 + }
25445 + }
25446 +}
25447 +
25448 +/*
25449 + ==========================================================================
25450 + Description:
25451 + This routine is executed periodically inside MlmePeriodicExec() after
25452 + association with an AP.
25453 + It checks if StaCfg.Psm is consistent with user policy (recorded in
25454 + StaCfg.WindowsPowerMode). If not, enforce user policy. However,
25455 + there're some conditions to consider:
25456 + 1. we don't support power-saving in ADHOC mode, so Psm=PWR_ACTIVE all
25457 + the time when Mibss==TRUE
25458 + 2. When link up in INFRA mode, Psm should not be switch to PWR_SAVE
25459 + if outgoing traffic available in TxRing or MgmtRing.
25460 + Output:
25461 + 1. change pAd->StaCfg.Psm to PWR_SAVE or leave it untouched
25462 +
25463 + IRQL = DISPATCH_LEVEL
25464 +
25465 + ==========================================================================
25466 + */
25467 +VOID MlmeCheckPsmChange(
25468 + IN PRTMP_ADAPTER pAd,
25469 + IN ULONG Now32)
25470 +{
25471 + ULONG PowerMode;
25472 +
25473 + // condition -
25474 + // 1. Psm maybe ON only happen in INFRASTRUCTURE mode
25475 + // 2. user wants either MAX_PSP or FAST_PSP
25476 + // 3. but current psm is not in PWR_SAVE
25477 + // 4. CNTL state machine is not doing SCANning
25478 + // 5. no TX SUCCESS event for the past 1-sec period
25479 +#ifdef NDIS51_MINIPORT
25480 + if (pAd->StaCfg.WindowsPowerProfile == NdisPowerProfileBattery)
25481 + PowerMode = pAd->StaCfg.WindowsBatteryPowerMode;
25482 + else
25483 +#endif
25484 + PowerMode = pAd->StaCfg.WindowsPowerMode;
25485 +
25486 + if (INFRA_ON(pAd) &&
25487 + (PowerMode != Ndis802_11PowerModeCAM) &&
25488 + (pAd->StaCfg.Psm == PWR_ACTIVE) &&
25489 +// (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
25490 + (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) /*&&
25491 + (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) &&
25492 + (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)*/)
25493 + {
25494 + NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime);
25495 + pAd->RalinkCounters.RxCountSinceLastNULL = 0;
25496 + MlmeSetPsmBit(pAd, PWR_SAVE);
25497 + if (!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable))
25498 + {
25499 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE);
25500 + }
25501 + else
25502 + {
25503 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
25504 + }
25505 + }
25506 +}
25507 +
25508 +// IRQL = PASSIVE_LEVEL
25509 +// IRQL = DISPATCH_LEVEL
25510 +VOID MlmeSetPsmBit(
25511 + IN PRTMP_ADAPTER pAd,
25512 + IN USHORT psm)
25513 +{
25514 + AUTO_RSP_CFG_STRUC csr4;
25515 +
25516 + pAd->StaCfg.Psm = psm;
25517 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
25518 + csr4.field.AckCtsPsmBit = (psm == PWR_SAVE)? 1:0;
25519 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
25520 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetPsmBit = %d\n", psm));
25521 +}
25522 +#endif // CONFIG_STA_SUPPORT //
25523 +
25524 +
25525 +// IRQL = DISPATCH_LEVEL
25526 +VOID MlmeSetTxPreamble(
25527 + IN PRTMP_ADAPTER pAd,
25528 + IN USHORT TxPreamble)
25529 +{
25530 + AUTO_RSP_CFG_STRUC csr4;
25531 +
25532 + //
25533 + // Always use Long preamble before verifiation short preamble functionality works well.
25534 + // Todo: remove the following line if short preamble functionality works
25535 + //
25536 + //TxPreamble = Rt802_11PreambleLong;
25537 +
25538 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
25539 + if (TxPreamble == Rt802_11PreambleLong)
25540 + {
25541 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= LONG PREAMBLE)\n"));
25542 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
25543 + csr4.field.AutoResponderPreamble = 0;
25544 + }
25545 + else
25546 + {
25547 + // NOTE: 1Mbps should always use long preamble
25548 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= SHORT PREAMBLE)\n"));
25549 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
25550 + csr4.field.AutoResponderPreamble = 1;
25551 + }
25552 +
25553 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
25554 +}
25555 +
25556 +/*
25557 + ==========================================================================
25558 + Description:
25559 + Update basic rate bitmap
25560 + ==========================================================================
25561 + */
25562 +
25563 +VOID UpdateBasicRateBitmap(
25564 + IN PRTMP_ADAPTER pAdapter)
25565 +{
25566 + INT i, j;
25567 + /* 1 2 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
25568 + UCHAR rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 };
25569 + UCHAR *sup_p = pAdapter->CommonCfg.SupRate;
25570 + UCHAR *ext_p = pAdapter->CommonCfg.ExtRate;
25571 + ULONG bitmap = pAdapter->CommonCfg.BasicRateBitmap;
25572 +
25573 +
25574 + /* if A mode, always use fix BasicRateBitMap */
25575 + //if (pAdapter->CommonCfg.Channel == PHY_11A)
25576 + if (pAdapter->CommonCfg.Channel > 14)
25577 + pAdapter->CommonCfg.BasicRateBitmap = 0x150; /* 6, 12, 24M */
25578 + /* End of if */
25579 +
25580 + if (pAdapter->CommonCfg.BasicRateBitmap > 4095)
25581 + {
25582 + /* (2 ^ MAX_LEN_OF_SUPPORTED_RATES) -1 */
25583 + return;
25584 + } /* End of if */
25585 +
25586 + for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25587 + {
25588 + sup_p[i] &= 0x7f;
25589 + ext_p[i] &= 0x7f;
25590 + } /* End of for */
25591 +
25592 + for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25593 + {
25594 + if (bitmap & (1 << i))
25595 + {
25596 + for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++)
25597 + {
25598 + if (sup_p[j] == rate[i])
25599 + sup_p[j] |= 0x80;
25600 + /* End of if */
25601 + } /* End of for */
25602 +
25603 + for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++)
25604 + {
25605 + if (ext_p[j] == rate[i])
25606 + ext_p[j] |= 0x80;
25607 + /* End of if */
25608 + } /* End of for */
25609 + } /* End of if */
25610 + } /* End of for */
25611 +} /* End of UpdateBasicRateBitmap */
25612 +
25613 +// IRQL = PASSIVE_LEVEL
25614 +// IRQL = DISPATCH_LEVEL
25615 +// bLinkUp is to identify the inital link speed.
25616 +// TRUE indicates the rate update at linkup, we should not try to set the rate at 54Mbps.
25617 +VOID MlmeUpdateTxRates(
25618 + IN PRTMP_ADAPTER pAd,
25619 + IN BOOLEAN bLinkUp,
25620 + IN UCHAR apidx)
25621 +{
25622 + int i, num;
25623 + UCHAR Rate = RATE_6, MaxDesire = RATE_1, MaxSupport = RATE_1;
25624 + UCHAR MinSupport = RATE_54;
25625 + ULONG BasicRateBitmap = 0;
25626 + UCHAR CurrBasicRate = RATE_1;
25627 + UCHAR *pSupRate, SupRateLen, *pExtRate, ExtRateLen;
25628 + PHTTRANSMIT_SETTING pHtPhy = NULL;
25629 + PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
25630 + PHTTRANSMIT_SETTING pMinHtPhy = NULL;
25631 + BOOLEAN *auto_rate_cur_p;
25632 + UCHAR HtMcs = MCS_AUTO;
25633 +
25634 + // find max desired rate
25635 + UpdateBasicRateBitmap(pAd);
25636 +
25637 + num = 0;
25638 + auto_rate_cur_p = NULL;
25639 + for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25640 + {
25641 + switch (pAd->CommonCfg.DesireRate[i] & 0x7f)
25642 + {
25643 + case 2: Rate = RATE_1; num++; break;
25644 + case 4: Rate = RATE_2; num++; break;
25645 + case 11: Rate = RATE_5_5; num++; break;
25646 + case 22: Rate = RATE_11; num++; break;
25647 + case 12: Rate = RATE_6; num++; break;
25648 + case 18: Rate = RATE_9; num++; break;
25649 + case 24: Rate = RATE_12; num++; break;
25650 + case 36: Rate = RATE_18; num++; break;
25651 + case 48: Rate = RATE_24; num++; break;
25652 + case 72: Rate = RATE_36; num++; break;
25653 + case 96: Rate = RATE_48; num++; break;
25654 + case 108: Rate = RATE_54; num++; break;
25655 + //default: Rate = RATE_1; break;
25656 + }
25657 + if (MaxDesire < Rate) MaxDesire = Rate;
25658 + }
25659 +
25660 +//===========================================================================
25661 +//===========================================================================
25662 +
25663 +#ifdef CONFIG_STA_SUPPORT
25664 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
25665 + {
25666 + pHtPhy = &pAd->StaCfg.HTPhyMode;
25667 + pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
25668 + pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
25669 +
25670 + auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
25671 + HtMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
25672 +
25673 + if ((pAd->StaCfg.BssType == BSS_ADHOC) &&
25674 + (pAd->CommonCfg.PhyMode == PHY_11B) &&
25675 + (MaxDesire > RATE_11))
25676 + {
25677 + MaxDesire = RATE_11;
25678 + }
25679 + }
25680 +#endif // CONFIG_STA_SUPPORT //
25681 +
25682 + pAd->CommonCfg.MaxDesiredRate = MaxDesire;
25683 + pMinHtPhy->word = 0;
25684 + pMaxHtPhy->word = 0;
25685 + pHtPhy->word = 0;
25686 +
25687 + // Auto rate switching is enabled only if more than one DESIRED RATES are
25688 + // specified; otherwise disabled
25689 + if (num <= 1)
25690 + {
25691 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
25692 + //pAd->CommonCfg.bAutoTxRateSwitch = FALSE;
25693 + *auto_rate_cur_p = FALSE;
25694 + }
25695 + else
25696 + {
25697 + //OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
25698 + //pAd->CommonCfg.bAutoTxRateSwitch = TRUE;
25699 + *auto_rate_cur_p = TRUE;
25700 + }
25701 +
25702 +#if 1
25703 + if (HtMcs != MCS_AUTO)
25704 + {
25705 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
25706 + //pAd->CommonCfg.bAutoTxRateSwitch = FALSE;
25707 + *auto_rate_cur_p = FALSE;
25708 + }
25709 + else
25710 + {
25711 + //OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
25712 + //pAd->CommonCfg.bAutoTxRateSwitch = TRUE;
25713 + *auto_rate_cur_p = TRUE;
25714 + }
25715 +#endif
25716 +
25717 +#ifdef CONFIG_STA_SUPPORT
25718 + if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA))
25719 + {
25720 + pSupRate = &pAd->StaActive.SupRate[0];
25721 + pExtRate = &pAd->StaActive.ExtRate[0];
25722 + SupRateLen = pAd->StaActive.SupRateLen;
25723 + ExtRateLen = pAd->StaActive.ExtRateLen;
25724 + }
25725 + else
25726 +#endif // CONFIG_STA_SUPPORT //
25727 + {
25728 + pSupRate = &pAd->CommonCfg.SupRate[0];
25729 + pExtRate = &pAd->CommonCfg.ExtRate[0];
25730 + SupRateLen = pAd->CommonCfg.SupRateLen;
25731 + ExtRateLen = pAd->CommonCfg.ExtRateLen;
25732 + }
25733 +
25734 + // find max supported rate
25735 + for (i=0; i<SupRateLen; i++)
25736 + {
25737 + switch (pSupRate[i] & 0x7f)
25738 + {
25739 + case 2: Rate = RATE_1; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0001; break;
25740 + case 4: Rate = RATE_2; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0002; break;
25741 + case 11: Rate = RATE_5_5; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0004; break;
25742 + case 22: Rate = RATE_11; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0008; break;
25743 + case 12: Rate = RATE_6; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break;
25744 + case 18: Rate = RATE_9; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0020; break;
25745 + case 24: Rate = RATE_12; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break;
25746 + case 36: Rate = RATE_18; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0080; break;
25747 + case 48: Rate = RATE_24; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break;
25748 + case 72: Rate = RATE_36; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0200; break;
25749 + case 96: Rate = RATE_48; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0400; break;
25750 + case 108: Rate = RATE_54; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0800; break;
25751 + default: Rate = RATE_1; break;
25752 + }
25753 + if (MaxSupport < Rate) MaxSupport = Rate;
25754 +
25755 + if (MinSupport > Rate) MinSupport = Rate;
25756 + }
25757 +
25758 + for (i=0; i<ExtRateLen; i++)
25759 + {
25760 + switch (pExtRate[i] & 0x7f)
25761 + {
25762 + case 2: Rate = RATE_1; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0001; break;
25763 + case 4: Rate = RATE_2; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0002; break;
25764 + case 11: Rate = RATE_5_5; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0004; break;
25765 + case 22: Rate = RATE_11; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0008; break;
25766 + case 12: Rate = RATE_6; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break;
25767 + case 18: Rate = RATE_9; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0020; break;
25768 + case 24: Rate = RATE_12; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break;
25769 + case 36: Rate = RATE_18; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0080; break;
25770 + case 48: Rate = RATE_24; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break;
25771 + case 72: Rate = RATE_36; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0200; break;
25772 + case 96: Rate = RATE_48; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0400; break;
25773 + case 108: Rate = RATE_54; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0800; break;
25774 + default: Rate = RATE_1; break;
25775 + }
25776 + if (MaxSupport < Rate) MaxSupport = Rate;
25777 +
25778 + if (MinSupport > Rate) MinSupport = Rate;
25779 + }
25780 +
25781 + RTMP_IO_WRITE32(pAd, LEGACY_BASIC_RATE, BasicRateBitmap);
25782 +
25783 + // bug fix
25784 + // pAd->CommonCfg.BasicRateBitmap = BasicRateBitmap;
25785 +
25786 + // calculate the exptected ACK rate for each TX rate. This info is used to caculate
25787 + // the DURATION field of outgoing uniicast DATA/MGMT frame
25788 + for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25789 + {
25790 + if (BasicRateBitmap & (0x01 << i))
25791 + CurrBasicRate = (UCHAR)i;
25792 + pAd->CommonCfg.ExpectedACKRate[i] = CurrBasicRate;
25793 + }
25794 +
25795 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateTxRates[MaxSupport = %d] = MaxDesire %d Mbps\n", RateIdToMbps[MaxSupport], RateIdToMbps[MaxDesire]));
25796 + // max tx rate = min {max desire rate, max supported rate}
25797 + if (MaxSupport < MaxDesire)
25798 + pAd->CommonCfg.MaxTxRate = MaxSupport;
25799 + else
25800 + pAd->CommonCfg.MaxTxRate = MaxDesire;
25801 +
25802 + pAd->CommonCfg.MinTxRate = MinSupport;
25803 + // 2003-07-31 john - 2500 doesn't have good sensitivity at high OFDM rates. to increase the success
25804 + // ratio of initial DHCP packet exchange, TX rate starts from a lower rate depending
25805 + // on average RSSI
25806 + // 1. RSSI >= -70db, start at 54 Mbps (short distance)
25807 + // 2. -70 > RSSI >= -75, start at 24 Mbps (mid distance)
25808 + // 3. -75 > RSSI, start at 11 Mbps (long distance)
25809 + //if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)/* &&
25810 + // OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)*/)
25811 + if (*auto_rate_cur_p)
25812 + {
25813 + short dbm = 0;
25814 +#ifdef CONFIG_STA_SUPPORT
25815 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
25816 + dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta;
25817 +#endif // CONFIG_STA_SUPPORT //
25818 + if (bLinkUp == TRUE)
25819 + pAd->CommonCfg.TxRate = RATE_24;
25820 + else
25821 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
25822 +
25823 + if (dbm < -75)
25824 + pAd->CommonCfg.TxRate = RATE_11;
25825 + else if (dbm < -70)
25826 + pAd->CommonCfg.TxRate = RATE_24;
25827 +
25828 + // should never exceed MaxTxRate (consider 11B-only mode)
25829 + if (pAd->CommonCfg.TxRate > pAd->CommonCfg.MaxTxRate)
25830 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
25831 +
25832 + pAd->CommonCfg.TxRateIndex = 0;
25833 + }
25834 + else
25835 + {
25836 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
25837 + pHtPhy->field.MCS = (pAd->CommonCfg.MaxTxRate > 3) ? (pAd->CommonCfg.MaxTxRate - 4) : pAd->CommonCfg.MaxTxRate;
25838 + pHtPhy->field.MODE = (pAd->CommonCfg.MaxTxRate > 3) ? MODE_OFDM : MODE_CCK;
25839 +
25840 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC = pHtPhy->field.STBC;
25841 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI = pHtPhy->field.ShortGI;
25842 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS = pHtPhy->field.MCS;
25843 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE = pHtPhy->field.MODE;
25844 + }
25845 +
25846 + if (pAd->CommonCfg.TxRate <= RATE_11)
25847 + {
25848 + pMaxHtPhy->field.MODE = MODE_CCK;
25849 + pMaxHtPhy->field.MCS = pAd->CommonCfg.TxRate;
25850 + pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;
25851 + }
25852 + else
25853 + {
25854 + pMaxHtPhy->field.MODE = MODE_OFDM;
25855 + pMaxHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.TxRate];
25856 + if (pAd->CommonCfg.MinTxRate >= RATE_6 && (pAd->CommonCfg.MinTxRate <= RATE_54))
25857 + {pMinHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MinTxRate];}
25858 + else
25859 + {pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;}
25860 + }
25861 +
25862 + pHtPhy->word = (pMaxHtPhy->word);
25863 + if (bLinkUp && (pAd->OpMode == OPMODE_STA))
25864 + {
25865 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word = pHtPhy->word;
25866 + pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word = pMaxHtPhy->word;
25867 + pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word = pMinHtPhy->word;
25868 + }
25869 + else
25870 + {
25871 + switch (pAd->CommonCfg.PhyMode)
25872 + {
25873 + case PHY_11BG_MIXED:
25874 + case PHY_11B:
25875 +#ifdef DOT11_N_SUPPORT
25876 + case PHY_11BGN_MIXED:
25877 +#endif // DOT11_N_SUPPORT //
25878 + pAd->CommonCfg.MlmeRate = RATE_1;
25879 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
25880 + pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
25881 +
25882 +//#ifdef WIFI_TEST
25883 + pAd->CommonCfg.RtsRate = RATE_11;
25884 +//#else
25885 +// pAd->CommonCfg.RtsRate = RATE_1;
25886 +//#endif
25887 + break;
25888 + case PHY_11G:
25889 + case PHY_11A:
25890 +#ifdef DOT11_N_SUPPORT
25891 + case PHY_11AGN_MIXED:
25892 + case PHY_11GN_MIXED:
25893 + case PHY_11N_2_4G:
25894 + case PHY_11AN_MIXED:
25895 + case PHY_11N_5G:
25896 +#endif // DOT11_N_SUPPORT //
25897 + pAd->CommonCfg.MlmeRate = RATE_6;
25898 + pAd->CommonCfg.RtsRate = RATE_6;
25899 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
25900 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
25901 + break;
25902 + case PHY_11ABG_MIXED:
25903 +#ifdef DOT11_N_SUPPORT
25904 + case PHY_11ABGN_MIXED:
25905 +#endif // DOT11_N_SUPPORT //
25906 + if (pAd->CommonCfg.Channel <= 14)
25907 + {
25908 + pAd->CommonCfg.MlmeRate = RATE_1;
25909 + pAd->CommonCfg.RtsRate = RATE_1;
25910 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
25911 + pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
25912 + }
25913 + else
25914 + {
25915 + pAd->CommonCfg.MlmeRate = RATE_6;
25916 + pAd->CommonCfg.RtsRate = RATE_6;
25917 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
25918 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
25919 + }
25920 + break;
25921 + default: // error
25922 + pAd->CommonCfg.MlmeRate = RATE_6;
25923 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
25924 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
25925 + pAd->CommonCfg.RtsRate = RATE_1;
25926 + break;
25927 + }
25928 + //
25929 + // Keep Basic Mlme Rate.
25930 + //
25931 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.word = pAd->CommonCfg.MlmeTransmit.word;
25932 + if (pAd->CommonCfg.MlmeTransmit.field.MODE == MODE_OFDM)
25933 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[RATE_24];
25934 + else
25935 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = RATE_1;
25936 + pAd->CommonCfg.BasicMlmeRate = pAd->CommonCfg.MlmeRate;
25937 + }
25938 +
25939 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (MaxDesire=%d, MaxSupport=%d, MaxTxRate=%d, MinRate=%d, Rate Switching =%d)\n",
25940 + RateIdToMbps[MaxDesire], RateIdToMbps[MaxSupport], RateIdToMbps[pAd->CommonCfg.MaxTxRate], RateIdToMbps[pAd->CommonCfg.MinTxRate],
25941 + /*OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)*/*auto_rate_cur_p));
25942 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (TxRate=%d, RtsRate=%d, BasicRateBitmap=0x%04lx)\n",
25943 + RateIdToMbps[pAd->CommonCfg.TxRate], RateIdToMbps[pAd->CommonCfg.RtsRate], BasicRateBitmap));
25944 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateTxRates (MlmeTransmit=0x%x, MinHTPhyMode=%x, MaxHTPhyMode=0x%x, HTPhyMode=0x%x)\n",
25945 + 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 ));
25946 +}
25947 +
25948 +#ifdef DOT11_N_SUPPORT
25949 +/*
25950 + ==========================================================================
25951 + Description:
25952 + This function update HT Rate setting.
25953 + Input Wcid value is valid for 2 case :
25954 + 1. it's used for Station in infra mode that copy AP rate to Mactable.
25955 + 2. OR Station in adhoc mode to copy peer's HT rate to Mactable.
25956 +
25957 + IRQL = DISPATCH_LEVEL
25958 +
25959 + ==========================================================================
25960 + */
25961 +VOID MlmeUpdateHtTxRates(
25962 + IN PRTMP_ADAPTER pAd,
25963 + IN UCHAR apidx)
25964 +{
25965 + UCHAR StbcMcs; //j, StbcMcs, bitmask;
25966 + CHAR i; // 3*3
25967 + RT_HT_CAPABILITY *pRtHtCap = NULL;
25968 + RT_HT_PHY_INFO *pActiveHtPhy = NULL;
25969 + ULONG BasicMCS;
25970 + UCHAR j, bitmask;
25971 + PRT_HT_PHY_INFO pDesireHtPhy = NULL;
25972 + PHTTRANSMIT_SETTING pHtPhy = NULL;
25973 + PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
25974 + PHTTRANSMIT_SETTING pMinHtPhy = NULL;
25975 + BOOLEAN *auto_rate_cur_p;
25976 +
25977 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates===> \n"));
25978 +
25979 + auto_rate_cur_p = NULL;
25980 +
25981 +#ifdef CONFIG_STA_SUPPORT
25982 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
25983 + {
25984 + pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
25985 + pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
25986 + pHtPhy = &pAd->StaCfg.HTPhyMode;
25987 + pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
25988 + pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
25989 +
25990 + auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
25991 + }
25992 +#endif // CONFIG_STA_SUPPORT //
25993 +
25994 +#ifdef CONFIG_STA_SUPPORT
25995 + if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA))
25996 + {
25997 + if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
25998 + return;
25999 +
26000 + pRtHtCap = &pAd->StaActive.SupportedHtPhy;
26001 + pActiveHtPhy = &pAd->StaActive.SupportedPhyInfo;
26002 + StbcMcs = (UCHAR)pAd->MlmeAux.AddHtInfo.AddHtInfo3.StbcMcs;
26003 + BasicMCS =pAd->MlmeAux.AddHtInfo.MCSSet[0]+(pAd->MlmeAux.AddHtInfo.MCSSet[1]<<8)+(StbcMcs<<16);
26004 + if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2))
26005 + pMaxHtPhy->field.STBC = STBC_USE;
26006 + else
26007 + pMaxHtPhy->field.STBC = STBC_NONE;
26008 + }
26009 + else
26010 +#endif // CONFIG_STA_SUPPORT //
26011 + {
26012 + if (pDesireHtPhy->bHtEnable == FALSE)
26013 + return;
26014 +
26015 + pRtHtCap = &pAd->CommonCfg.DesiredHtPhy;
26016 + StbcMcs = (UCHAR)pAd->CommonCfg.AddHTInfo.AddHtInfo3.StbcMcs;
26017 + BasicMCS = pAd->CommonCfg.AddHTInfo.MCSSet[0]+(pAd->CommonCfg.AddHTInfo.MCSSet[1]<<8)+(StbcMcs<<16);
26018 + if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2))
26019 + pMaxHtPhy->field.STBC = STBC_USE;
26020 + else
26021 + pMaxHtPhy->field.STBC = STBC_NONE;
26022 + }
26023 +
26024 + // Decide MAX ht rate.
26025 + if ((pRtHtCap->GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
26026 + pMaxHtPhy->field.MODE = MODE_HTGREENFIELD;
26027 + else
26028 + pMaxHtPhy->field.MODE = MODE_HTMIX;
26029 +
26030 + if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth) && (pRtHtCap->ChannelWidth))
26031 + pMaxHtPhy->field.BW = BW_40;
26032 + else
26033 + pMaxHtPhy->field.BW = BW_20;
26034 +
26035 + if (pMaxHtPhy->field.BW == BW_20)
26036 + pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 & pRtHtCap->ShortGIfor20);
26037 + else
26038 + pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 & pRtHtCap->ShortGIfor40);
26039 +
26040 + for (i=23; i>=0; i--) // 3*3
26041 + {
26042 + j = i/8;
26043 + bitmask = (1<<(i-(j*8)));
26044 +
26045 + if ((pActiveHtPhy->MCSSet[j] & bitmask) && (pDesireHtPhy->MCSSet[j] & bitmask))
26046 + {
26047 + pMaxHtPhy->field.MCS = i;
26048 + break;
26049 + }
26050 +
26051 + if (i==0)
26052 + break;
26053 + }
26054 +
26055 + // Copy MIN ht rate. rt2860???
26056 + pMinHtPhy->field.BW = BW_20;
26057 + pMinHtPhy->field.MCS = 0;
26058 + pMinHtPhy->field.STBC = 0;
26059 + pMinHtPhy->field.ShortGI = 0;
26060 + //If STA assigns fixed rate. update to fixed here.
26061 +#ifdef CONFIG_STA_SUPPORT
26062 + if ( (pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff))
26063 + {
26064 + if (pDesireHtPhy->MCSSet[4] != 0)
26065 + {
26066 + pMaxHtPhy->field.MCS = 32;
26067 + pMinHtPhy->field.MCS = 32;
26068 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== Use Fixed MCS = %d\n",pMinHtPhy->field.MCS));
26069 + }
26070 +
26071 + for (i=23; (CHAR)i >= 0; i--) // 3*3
26072 + {
26073 + j = i/8;
26074 + bitmask = (1<<(i-(j*8)));
26075 + if ( (pDesireHtPhy->MCSSet[j] & bitmask) && (pActiveHtPhy->MCSSet[j] & bitmask))
26076 + {
26077 + pMaxHtPhy->field.MCS = i;
26078 + pMinHtPhy->field.MCS = i;
26079 + break;
26080 + }
26081 + if (i==0)
26082 + break;
26083 + }
26084 + }
26085 +#endif // CONFIG_STA_SUPPORT //
26086 +
26087 +
26088 + // Decide ht rate
26089 + pHtPhy->field.STBC = pMaxHtPhy->field.STBC;
26090 + pHtPhy->field.BW = pMaxHtPhy->field.BW;
26091 + pHtPhy->field.MODE = pMaxHtPhy->field.MODE;
26092 + pHtPhy->field.MCS = pMaxHtPhy->field.MCS;
26093 + pHtPhy->field.ShortGI = pMaxHtPhy->field.ShortGI;
26094 +
26095 + // use default now. rt2860
26096 + if (pDesireHtPhy->MCSSet[0] != 0xff)
26097 + *auto_rate_cur_p = FALSE;
26098 + else
26099 + *auto_rate_cur_p = TRUE;
26100 +
26101 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateHtTxRates<---.AMsduSize = %d \n", pAd->CommonCfg.DesiredHtPhy.AmsduSize ));
26102 + DBGPRINT(RT_DEBUG_TRACE,("TX: MCS[0] = %x (choose %d), BW = %d, ShortGI = %d, MODE = %d, \n", pActiveHtPhy->MCSSet[0],pHtPhy->field.MCS,
26103 + pHtPhy->field.BW, pHtPhy->field.ShortGI, pHtPhy->field.MODE));
26104 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== \n"));
26105 +}
26106 +#endif // DOT11_N_SUPPORT //
26107 +
26108 +// IRQL = DISPATCH_LEVEL
26109 +VOID MlmeRadioOff(
26110 + IN PRTMP_ADAPTER pAd)
26111 +{
26112 + RT28XX_MLME_RADIO_OFF(pAd);
26113 +}
26114 +
26115 +// IRQL = DISPATCH_LEVEL
26116 +VOID MlmeRadioOn(
26117 + IN PRTMP_ADAPTER pAd)
26118 +{
26119 + RT28XX_MLME_RADIO_ON(pAd);
26120 +}
26121 +
26122 +// ===========================================================================================
26123 +// bss_table.c
26124 +// ===========================================================================================
26125 +
26126 +
26127 +/*! \brief initialize BSS table
26128 + * \param p_tab pointer to the table
26129 + * \return none
26130 + * \pre
26131 + * \post
26132 +
26133 + IRQL = PASSIVE_LEVEL
26134 + IRQL = DISPATCH_LEVEL
26135 +
26136 + */
26137 +VOID BssTableInit(
26138 + IN BSS_TABLE *Tab)
26139 +{
26140 + int i;
26141 +
26142 + Tab->BssNr = 0;
26143 + Tab->BssOverlapNr = 0;
26144 + for (i = 0; i < MAX_LEN_OF_BSS_TABLE; i++)
26145 + {
26146 + NdisZeroMemory(&Tab->BssEntry[i], sizeof(BSS_ENTRY));
26147 + Tab->BssEntry[i].Rssi = -127; // initial the rssi as a minimum value
26148 + }
26149 +}
26150 +
26151 +#ifdef DOT11_N_SUPPORT
26152 +VOID BATableInit(
26153 + IN PRTMP_ADAPTER pAd,
26154 + IN BA_TABLE *Tab)
26155 +{
26156 + int i;
26157 +
26158 + Tab->numAsOriginator = 0;
26159 + Tab->numAsRecipient = 0;
26160 + NdisAllocateSpinLock(&pAd->BATabLock);
26161 + for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++)
26162 + {
26163 + Tab->BARecEntry[i].REC_BA_Status = Recipient_NONE;
26164 + NdisAllocateSpinLock(&(Tab->BARecEntry[i].RxReRingLock));
26165 + }
26166 + for (i = 0; i < MAX_LEN_OF_BA_ORI_TABLE; i++)
26167 + {
26168 + Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE;
26169 + }
26170 +}
26171 +#endif // DOT11_N_SUPPORT //
26172 +
26173 +/*! \brief search the BSS table by SSID
26174 + * \param p_tab pointer to the bss table
26175 + * \param ssid SSID string
26176 + * \return index of the table, BSS_NOT_FOUND if not in the table
26177 + * \pre
26178 + * \post
26179 + * \note search by sequential search
26180 +
26181 + IRQL = DISPATCH_LEVEL
26182 +
26183 + */
26184 +ULONG BssTableSearch(
26185 + IN BSS_TABLE *Tab,
26186 + IN PUCHAR pBssid,
26187 + IN UCHAR Channel)
26188 +{
26189 + UCHAR i;
26190 +
26191 + for (i = 0; i < Tab->BssNr; i++)
26192 + {
26193 + //
26194 + // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G.
26195 + // We should distinguish this case.
26196 + //
26197 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26198 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26199 + MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid))
26200 + {
26201 + return i;
26202 + }
26203 + }
26204 + return (ULONG)BSS_NOT_FOUND;
26205 +}
26206 +
26207 +ULONG BssSsidTableSearch(
26208 + IN BSS_TABLE *Tab,
26209 + IN PUCHAR pBssid,
26210 + IN PUCHAR pSsid,
26211 + IN UCHAR SsidLen,
26212 + IN UCHAR Channel)
26213 +{
26214 + UCHAR i;
26215 +
26216 + for (i = 0; i < Tab->BssNr; i++)
26217 + {
26218 + //
26219 + // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G.
26220 + // We should distinguish this case.
26221 + //
26222 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26223 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26224 + MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid) &&
26225 + SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen))
26226 + {
26227 + return i;
26228 + }
26229 + }
26230 + return (ULONG)BSS_NOT_FOUND;
26231 +}
26232 +
26233 +ULONG BssTableSearchWithSSID(
26234 + IN BSS_TABLE *Tab,
26235 + IN PUCHAR Bssid,
26236 + IN PUCHAR pSsid,
26237 + IN UCHAR SsidLen,
26238 + IN UCHAR Channel)
26239 +{
26240 + UCHAR i;
26241 +
26242 + for (i = 0; i < Tab->BssNr; i++)
26243 + {
26244 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26245 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26246 + MAC_ADDR_EQUAL(&(Tab->BssEntry[i].Bssid), Bssid) &&
26247 + (SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen) ||
26248 + (NdisEqualMemory(pSsid, ZeroSsid, SsidLen)) ||
26249 + (NdisEqualMemory(Tab->BssEntry[i].Ssid, ZeroSsid, Tab->BssEntry[i].SsidLen))))
26250 + {
26251 + return i;
26252 + }
26253 + }
26254 + return (ULONG)BSS_NOT_FOUND;
26255 +}
26256 +
26257 +// IRQL = DISPATCH_LEVEL
26258 +VOID BssTableDeleteEntry(
26259 + IN OUT BSS_TABLE *Tab,
26260 + IN PUCHAR pBssid,
26261 + IN UCHAR Channel)
26262 +{
26263 + UCHAR i, j;
26264 +
26265 + for (i = 0; i < Tab->BssNr; i++)
26266 + {
26267 + if ((Tab->BssEntry[i].Channel == Channel) &&
26268 + (MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid)))
26269 + {
26270 + for (j = i; j < Tab->BssNr - 1; j++)
26271 + {
26272 + NdisMoveMemory(&(Tab->BssEntry[j]), &(Tab->BssEntry[j + 1]), sizeof(BSS_ENTRY));
26273 + }
26274 + NdisZeroMemory(&(Tab->BssEntry[Tab->BssNr - 1]), sizeof(BSS_ENTRY));
26275 + Tab->BssNr -= 1;
26276 + return;
26277 + }
26278 + }
26279 +}
26280 +
26281 +#ifdef DOT11_N_SUPPORT
26282 +/*
26283 + ========================================================================
26284 + Routine Description:
26285 + Delete the Originator Entry in BAtable. Or decrease numAs Originator by 1 if needed.
26286 +
26287 + Arguments:
26288 + // IRQL = DISPATCH_LEVEL
26289 + ========================================================================
26290 +*/
26291 +VOID BATableDeleteORIEntry(
26292 + IN OUT PRTMP_ADAPTER pAd,
26293 + IN BA_ORI_ENTRY *pBAORIEntry)
26294 +{
26295 +
26296 + if (pBAORIEntry->ORI_BA_Status != Originator_NONE)
26297 + {
26298 + NdisAcquireSpinLock(&pAd->BATabLock);
26299 + if (pBAORIEntry->ORI_BA_Status == Originator_Done)
26300 + {
26301 + pAd->BATable.numAsOriginator -= 1;
26302 + DBGPRINT(RT_DEBUG_TRACE, ("BATableDeleteORIEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient));
26303 + // Erase Bitmap flag.
26304 + }
26305 + pAd->MacTab.Content[pBAORIEntry->Wcid].TXBAbitmap &= (~(1<<(pBAORIEntry->TID) )); // If STA mode, erase flag here
26306 + pAd->MacTab.Content[pBAORIEntry->Wcid].BAOriWcidArray[pBAORIEntry->TID] = 0; // If STA mode, erase flag here
26307 + pBAORIEntry->ORI_BA_Status = Originator_NONE;
26308 + pBAORIEntry->Token = 1;
26309 + // Not clear Sequence here.
26310 + NdisReleaseSpinLock(&pAd->BATabLock);
26311 + }
26312 +}
26313 +#endif // DOT11_N_SUPPORT //
26314 +
26315 +/*! \brief
26316 + * \param
26317 + * \return
26318 + * \pre
26319 + * \post
26320 +
26321 + IRQL = DISPATCH_LEVEL
26322 +
26323 + */
26324 +VOID BssEntrySet(
26325 + IN PRTMP_ADAPTER pAd,
26326 + OUT BSS_ENTRY *pBss,
26327 + IN PUCHAR pBssid,
26328 + IN CHAR Ssid[],
26329 + IN UCHAR SsidLen,
26330 + IN UCHAR BssType,
26331 + IN USHORT BeaconPeriod,
26332 + IN PCF_PARM pCfParm,
26333 + IN USHORT AtimWin,
26334 + IN USHORT CapabilityInfo,
26335 + IN UCHAR SupRate[],
26336 + IN UCHAR SupRateLen,
26337 + IN UCHAR ExtRate[],
26338 + IN UCHAR ExtRateLen,
26339 + IN HT_CAPABILITY_IE *pHtCapability,
26340 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
26341 + IN UCHAR HtCapabilityLen,
26342 + IN UCHAR AddHtInfoLen,
26343 + IN UCHAR NewExtChanOffset,
26344 + IN UCHAR Channel,
26345 + IN CHAR Rssi,
26346 + IN LARGE_INTEGER TimeStamp,
26347 + IN UCHAR CkipFlag,
26348 + IN PEDCA_PARM pEdcaParm,
26349 + IN PQOS_CAPABILITY_PARM pQosCapability,
26350 + IN PQBSS_LOAD_PARM pQbssLoad,
26351 + IN USHORT LengthVIE,
26352 + IN PNDIS_802_11_VARIABLE_IEs pVIE)
26353 +{
26354 + COPY_MAC_ADDR(pBss->Bssid, pBssid);
26355 + // Default Hidden SSID to be TRUE, it will be turned to FALSE after coping SSID
26356 + pBss->Hidden = 1;
26357 + if (SsidLen > 0)
26358 + {
26359 + // For hidden SSID AP, it might send beacon with SSID len equal to 0
26360 + // Or send beacon /probe response with SSID len matching real SSID length,
26361 + // but SSID is all zero. such as "00-00-00-00" with length 4.
26362 + // We have to prevent this case overwrite correct table
26363 + if (NdisEqualMemory(Ssid, ZeroSsid, SsidLen) == 0)
26364 + {
26365 + NdisZeroMemory(pBss->Ssid, MAX_LEN_OF_SSID);
26366 + NdisMoveMemory(pBss->Ssid, Ssid, SsidLen);
26367 + pBss->SsidLen = SsidLen;
26368 + pBss->Hidden = 0;
26369 + }
26370 + }
26371 + else
26372 + pBss->SsidLen = 0;
26373 + pBss->BssType = BssType;
26374 + pBss->BeaconPeriod = BeaconPeriod;
26375 + if (BssType == BSS_INFRA)
26376 + {
26377 + if (pCfParm->bValid)
26378 + {
26379 + pBss->CfpCount = pCfParm->CfpCount;
26380 + pBss->CfpPeriod = pCfParm->CfpPeriod;
26381 + pBss->CfpMaxDuration = pCfParm->CfpMaxDuration;
26382 + pBss->CfpDurRemaining = pCfParm->CfpDurRemaining;
26383 + }
26384 + }
26385 + else
26386 + {
26387 + pBss->AtimWin = AtimWin;
26388 + }
26389 +
26390 + pBss->CapabilityInfo = CapabilityInfo;
26391 + // The privacy bit indicate security is ON, it maight be WEP, TKIP or AES
26392 + // Combine with AuthMode, they will decide the connection methods.
26393 + pBss->Privacy = CAP_IS_PRIVACY_ON(pBss->CapabilityInfo);
26394 + ASSERT(SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
26395 + if (SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES)
26396 + NdisMoveMemory(pBss->SupRate, SupRate, SupRateLen);
26397 + else
26398 + NdisMoveMemory(pBss->SupRate, SupRate, MAX_LEN_OF_SUPPORTED_RATES);
26399 + pBss->SupRateLen = SupRateLen;
26400 + ASSERT(ExtRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
26401 + NdisMoveMemory(pBss->ExtRate, ExtRate, ExtRateLen);
26402 + NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen);
26403 + NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen);
26404 + pBss->NewExtChanOffset = NewExtChanOffset;
26405 + pBss->ExtRateLen = ExtRateLen;
26406 + pBss->Channel = Channel;
26407 + pBss->CentralChannel = Channel;
26408 + pBss->Rssi = Rssi;
26409 + // Update CkipFlag. if not exists, the value is 0x0
26410 + pBss->CkipFlag = CkipFlag;
26411 +
26412 + // New for microsoft Fixed IEs
26413 + NdisMoveMemory(pBss->FixIEs.Timestamp, &TimeStamp, 8);
26414 + pBss->FixIEs.BeaconInterval = BeaconPeriod;
26415 + pBss->FixIEs.Capabilities = CapabilityInfo;
26416 +
26417 + // New for microsoft Variable IEs
26418 + if (LengthVIE != 0)
26419 + {
26420 + pBss->VarIELen = LengthVIE;
26421 + NdisMoveMemory(pBss->VarIEs, pVIE, pBss->VarIELen);
26422 + }
26423 + else
26424 + {
26425 + pBss->VarIELen = 0;
26426 + }
26427 +
26428 + pBss->AddHtInfoLen = 0;
26429 + pBss->HtCapabilityLen = 0;
26430 +#ifdef DOT11_N_SUPPORT
26431 + if (HtCapabilityLen> 0)
26432 + {
26433 + pBss->HtCapabilityLen = HtCapabilityLen;
26434 + NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen);
26435 + if (AddHtInfoLen > 0)
26436 + {
26437 + pBss->AddHtInfoLen = AddHtInfoLen;
26438 + NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen);
26439 +
26440 + if ((pAddHtInfo->ControlChan > 2)&& (pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40))
26441 + {
26442 + pBss->CentralChannel = pAddHtInfo->ControlChan - 2;
26443 + }
26444 + else if ((pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40))
26445 + {
26446 + pBss->CentralChannel = pAddHtInfo->ControlChan + 2;
26447 + }
26448 + }
26449 + }
26450 +#endif // DOT11_N_SUPPORT //
26451 +
26452 + BssCipherParse(pBss);
26453 +
26454 + // new for QOS
26455 + if (pEdcaParm)
26456 + NdisMoveMemory(&pBss->EdcaParm, pEdcaParm, sizeof(EDCA_PARM));
26457 + else
26458 + pBss->EdcaParm.bValid = FALSE;
26459 + if (pQosCapability)
26460 + NdisMoveMemory(&pBss->QosCapability, pQosCapability, sizeof(QOS_CAPABILITY_PARM));
26461 + else
26462 + pBss->QosCapability.bValid = FALSE;
26463 + if (pQbssLoad)
26464 + NdisMoveMemory(&pBss->QbssLoad, pQbssLoad, sizeof(QBSS_LOAD_PARM));
26465 + else
26466 + pBss->QbssLoad.bValid = FALSE;
26467 +
26468 +#ifdef CONFIG_STA_SUPPORT
26469 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
26470 + {
26471 + PEID_STRUCT pEid;
26472 + USHORT Length = 0;
26473 +
26474 +
26475 + NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN);
26476 + NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN);
26477 +#ifdef EXT_BUILD_CHANNEL_LIST
26478 + NdisZeroMemory(&pBss->CountryString[0], 3);
26479 + pBss->bHasCountryIE = FALSE;
26480 +#endif // EXT_BUILD_CHANNEL_LIST //
26481 + pEid = (PEID_STRUCT) pVIE;
26482 + while ((Length + 2 + (USHORT)pEid->Len) <= LengthVIE)
26483 + {
26484 + switch(pEid->Eid)
26485 + {
26486 + case IE_WPA:
26487 + if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
26488 + {
26489 + if ((pEid->Len + 2) > MAX_CUSTOM_LEN)
26490 + {
26491 + pBss->WpaIE.IELen = 0;
26492 + break;
26493 + }
26494 + pBss->WpaIE.IELen = pEid->Len + 2;
26495 + NdisMoveMemory(pBss->WpaIE.IE, pEid, pBss->WpaIE.IELen);
26496 + }
26497 + break;
26498 + case IE_RSN:
26499 + if (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
26500 + {
26501 + if ((pEid->Len + 2) > MAX_CUSTOM_LEN)
26502 + {
26503 + pBss->RsnIE.IELen = 0;
26504 + break;
26505 + }
26506 + pBss->RsnIE.IELen = pEid->Len + 2;
26507 + NdisMoveMemory(pBss->RsnIE.IE, pEid, pBss->RsnIE.IELen);
26508 + }
26509 + break;
26510 +#ifdef EXT_BUILD_CHANNEL_LIST
26511 + case IE_COUNTRY:
26512 + NdisMoveMemory(&pBss->CountryString[0], pEid->Octet, 3);
26513 + pBss->bHasCountryIE = TRUE;
26514 + break;
26515 +#endif // EXT_BUILD_CHANNEL_LIST //
26516 + }
26517 + Length = Length + 2 + (USHORT)pEid->Len; // Eid[1] + Len[1]+ content[Len]
26518 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
26519 + }
26520 + }
26521 +#endif // CONFIG_STA_SUPPORT //
26522 +}
26523 +
26524 +/*!
26525 + * \brief insert an entry into the bss table
26526 + * \param p_tab The BSS table
26527 + * \param Bssid BSSID
26528 + * \param ssid SSID
26529 + * \param ssid_len Length of SSID
26530 + * \param bss_type
26531 + * \param beacon_period
26532 + * \param timestamp
26533 + * \param p_cf
26534 + * \param atim_win
26535 + * \param cap
26536 + * \param rates
26537 + * \param rates_len
26538 + * \param channel_idx
26539 + * \return none
26540 + * \pre
26541 + * \post
26542 + * \note If SSID is identical, the old entry will be replaced by the new one
26543 +
26544 + IRQL = DISPATCH_LEVEL
26545 +
26546 + */
26547 +ULONG BssTableSetEntry(
26548 + IN PRTMP_ADAPTER pAd,
26549 + OUT BSS_TABLE *Tab,
26550 + IN PUCHAR pBssid,
26551 + IN CHAR Ssid[],
26552 + IN UCHAR SsidLen,
26553 + IN UCHAR BssType,
26554 + IN USHORT BeaconPeriod,
26555 + IN CF_PARM *CfParm,
26556 + IN USHORT AtimWin,
26557 + IN USHORT CapabilityInfo,
26558 + IN UCHAR SupRate[],
26559 + IN UCHAR SupRateLen,
26560 + IN UCHAR ExtRate[],
26561 + IN UCHAR ExtRateLen,
26562 + IN HT_CAPABILITY_IE *pHtCapability,
26563 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
26564 + IN UCHAR HtCapabilityLen,
26565 + IN UCHAR AddHtInfoLen,
26566 + IN UCHAR NewExtChanOffset,
26567 + IN UCHAR ChannelNo,
26568 + IN CHAR Rssi,
26569 + IN LARGE_INTEGER TimeStamp,
26570 + IN UCHAR CkipFlag,
26571 + IN PEDCA_PARM pEdcaParm,
26572 + IN PQOS_CAPABILITY_PARM pQosCapability,
26573 + IN PQBSS_LOAD_PARM pQbssLoad,
26574 + IN USHORT LengthVIE,
26575 + IN PNDIS_802_11_VARIABLE_IEs pVIE)
26576 +{
26577 + ULONG Idx;
26578 +
26579 + Idx = BssTableSearchWithSSID(Tab, pBssid, Ssid, SsidLen, ChannelNo);
26580 + if (Idx == BSS_NOT_FOUND)
26581 + {
26582 + if (Tab->BssNr >= MAX_LEN_OF_BSS_TABLE)
26583 + {
26584 + //
26585 + // It may happen when BSS Table was full.
26586 + // The desired AP will not be added into BSS Table
26587 + // In this case, if we found the desired AP then overwrite BSS Table.
26588 + //
26589 + if(!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
26590 + {
26591 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, pBssid) ||
26592 + SSID_EQUAL(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Ssid, SsidLen))
26593 + {
26594 + Idx = Tab->BssOverlapNr;
26595 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin,
26596 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26597 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26598 + Tab->BssOverlapNr = (Tab->BssOverlapNr++) % MAX_LEN_OF_BSS_TABLE;
26599 + }
26600 + return Idx;
26601 + }
26602 + else
26603 + {
26604 + return BSS_NOT_FOUND;
26605 + }
26606 + }
26607 + Idx = Tab->BssNr;
26608 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin,
26609 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26610 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26611 + Tab->BssNr++;
26612 + }
26613 + else
26614 + {
26615 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod,CfParm, AtimWin,
26616 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26617 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26618 + }
26619 +
26620 + return Idx;
26621 +}
26622 +
26623 +#ifdef CONFIG_STA_SUPPORT
26624 +#ifdef DOT11_N_SUPPORT
26625 +#ifdef DOT11N_DRAFT3
26626 +VOID TriEventInit(
26627 + IN PRTMP_ADAPTER pAd)
26628 +{
26629 + UCHAR i;
26630 +
26631 + for (i = 0;i < MAX_TRIGGER_EVENT;i++)
26632 + pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE;
26633 +
26634 + pAd->CommonCfg.TriggerEventTab.EventANo = 0;
26635 + pAd->CommonCfg.TriggerEventTab.EventBCountDown = 0;
26636 +}
26637 +
26638 +ULONG TriEventTableSetEntry(
26639 + IN PRTMP_ADAPTER pAd,
26640 + OUT TRIGGER_EVENT_TAB *Tab,
26641 + IN PUCHAR pBssid,
26642 + IN HT_CAPABILITY_IE *pHtCapability,
26643 + IN UCHAR HtCapabilityLen,
26644 + IN UCHAR RegClass,
26645 + IN UCHAR ChannelNo)
26646 +{
26647 + // Event A
26648 + if (HtCapabilityLen == 0)
26649 + {
26650 + if (Tab->EventANo < MAX_TRIGGER_EVENT)
26651 + {
26652 + RTMPMoveMemory(Tab->EventA[Tab->EventANo].BSSID, pBssid, 6);
26653 + Tab->EventA[Tab->EventANo].bValid = TRUE;
26654 + Tab->EventA[Tab->EventANo].Channel = ChannelNo;
26655 + Tab->EventA[Tab->EventANo].CDCounter = pAd->CommonCfg.Dot11BssWidthChanTranDelay;
26656 + if (RegClass != 0)
26657 + {
26658 + // Beacon has Regulatory class IE. So use beacon's
26659 + Tab->EventA[Tab->EventANo].RegClass = RegClass;
26660 + }
26661 + else
26662 + {
26663 + // Use Station's Regulatory class instead.
26664 + if (pAd->StaActive.SupportedHtPhy.bHtEnable == TRUE)
26665 + {
26666 + if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
26667 + {
26668 + Tab->EventA[Tab->EventANo].RegClass = 32;
26669 + }
26670 + else if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
26671 + Tab->EventA[Tab->EventANo].RegClass = 33;
26672 + }
26673 + else
26674 + Tab->EventA[Tab->EventANo].RegClass = ??;
26675 +
26676 + }
26677 +
26678 + Tab->EventANo ++;
26679 + }
26680 + }
26681 + else if (pHtCapability->HtCapInfo.Intolerant40)
26682 + {
26683 + Tab->EventBCountDown = pAd->CommonCfg.Dot11BssWidthChanTranDelay;
26684 + }
26685 +
26686 +}
26687 +
26688 +/*
26689 + ========================================================================
26690 + Routine Description:
26691 + Trigger Event table Maintainence called once every second.
26692 +
26693 + Arguments:
26694 + // IRQL = DISPATCH_LEVEL
26695 + ========================================================================
26696 +*/
26697 +VOID TriEventCounterMaintenance(
26698 + IN PRTMP_ADAPTER pAd)
26699 +{
26700 + UCHAR i;
26701 + BOOLEAN bNotify = FALSE;
26702 + for (i = 0;i < MAX_TRIGGER_EVENT;i++)
26703 + {
26704 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].bValid && (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter > 0))
26705 + {
26706 + pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter--;
26707 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter == 0)
26708 + {
26709 + pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE;
26710 + pAd->CommonCfg.TriggerEventTab.EventANo --;
26711 + // Need to send 20/40 Coexistence Notify frame if has status change.
26712 + bNotify = TRUE;
26713 + }
26714 + }
26715 + }
26716 + if (pAd->CommonCfg.TriggerEventTab.EventBCountDown > 0)
26717 + {
26718 + pAd->CommonCfg.TriggerEventTab.EventBCountDown--;
26719 + if (pAd->CommonCfg.TriggerEventTab.EventBCountDown == 0)
26720 + bNotify = TRUE;
26721 + }
26722 +
26723 + if (bNotify == TRUE)
26724 + Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
26725 +}
26726 +#endif // DOT11N_DRAFT3 //
26727 +#endif // DOT11_N_SUPPORT //
26728 +
26729 +// IRQL = DISPATCH_LEVEL
26730 +VOID BssTableSsidSort(
26731 + IN PRTMP_ADAPTER pAd,
26732 + OUT BSS_TABLE *OutTab,
26733 + IN CHAR Ssid[],
26734 + IN UCHAR SsidLen)
26735 +{
26736 + INT i;
26737 + BssTableInit(OutTab);
26738 +
26739 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
26740 + {
26741 + BSS_ENTRY *pInBss = &pAd->ScanTab.BssEntry[i];
26742 + BOOLEAN bIsHiddenApIncluded = FALSE;
26743 +
26744 + if (((pAd->CommonCfg.bIEEE80211H == 1) &&
26745 + (pAd->MlmeAux.Channel > 14) &&
26746 + RadarChannelCheck(pAd, pInBss->Channel))
26747 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
26748 + || (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
26749 +#endif // CARRIER_DETECTION_SUPPORT //
26750 + )
26751 + {
26752 + if (pInBss->Hidden)
26753 + bIsHiddenApIncluded = TRUE;
26754 + }
26755 +
26756 + if ((pInBss->BssType == pAd->StaCfg.BssType) &&
26757 + (SSID_EQUAL(Ssid, SsidLen, pInBss->Ssid, pInBss->SsidLen) || bIsHiddenApIncluded))
26758 + {
26759 + BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
26760 +
26761 +
26762 +#ifdef EXT_BUILD_CHANNEL_LIST
26763 + // If no Country IE exists no Connection will be established when IEEE80211dClientMode is strict.
26764 + if ((pAd->StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict) &&
26765 + (pInBss->bHasCountryIE == FALSE))
26766 + {
26767 + DBGPRINT(RT_DEBUG_TRACE,("StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict, but this AP doesn't have country IE.\n"));
26768 + continue;
26769 + }
26770 +#endif // EXT_BUILD_CHANNEL_LIST //
26771 +
26772 +#ifdef DOT11_N_SUPPORT
26773 + // 2.4G/5G N only mode
26774 + if ((pInBss->HtCapabilityLen == 0) &&
26775 + ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)))
26776 + {
26777 + DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
26778 + continue;
26779 + }
26780 +#endif // DOT11_N_SUPPORT //
26781 +
26782 + // New for WPA2
26783 + // Check the Authmode first
26784 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
26785 + {
26786 + // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode
26787 + if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux))
26788 + // None matched
26789 + continue;
26790 +
26791 + // Check cipher suite, AP must have more secured cipher than station setting
26792 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
26793 + {
26794 + // If it's not mixed mode, we should only let BSS pass with the same encryption
26795 + if (pInBss->WPA.bMixMode == FALSE)
26796 + if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher)
26797 + continue;
26798 +
26799 + // check group cipher
26800 + if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) &&
26801 + (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP40Enabled) &&
26802 + (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP104Enabled))
26803 + continue;
26804 +
26805 + // check pairwise cipher, skip if none matched
26806 + // If profile set to AES, let it pass without question.
26807 + // If profile set to TKIP, we must find one mateched
26808 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
26809 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) &&
26810 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux))
26811 + continue;
26812 + }
26813 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
26814 + {
26815 + // If it's not mixed mode, we should only let BSS pass with the same encryption
26816 + if (pInBss->WPA2.bMixMode == FALSE)
26817 + if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher)
26818 + continue;
26819 +
26820 + // check group cipher
26821 + if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) &&
26822 + (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP40Enabled) &&
26823 + (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP104Enabled))
26824 + continue;
26825 +
26826 + // check pairwise cipher, skip if none matched
26827 + // If profile set to AES, let it pass without question.
26828 + // If profile set to TKIP, we must find one mateched
26829 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
26830 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) &&
26831 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux))
26832 + continue;
26833 + }
26834 + }
26835 + // Bss Type matched, SSID matched.
26836 + // We will check wepstatus for qualification Bss
26837 + else if (pAd->StaCfg.WepStatus != pInBss->WepStatus)
26838 + {
26839 + DBGPRINT(RT_DEBUG_TRACE,("StaCfg.WepStatus=%d, while pInBss->WepStatus=%d\n", pAd->StaCfg.WepStatus, pInBss->WepStatus));
26840 + //
26841 + // For the SESv2 case, we will not qualify WepStatus.
26842 + //
26843 + if (!pInBss->bSES)
26844 + continue;
26845 + }
26846 +
26847 + // Since the AP is using hidden SSID, and we are trying to connect to ANY
26848 + // It definitely will fail. So, skip it.
26849 + // CCX also require not even try to connect it!!
26850 + if (SsidLen == 0)
26851 + continue;
26852 +
26853 +#ifdef DOT11_N_SUPPORT
26854 + // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region
26855 + // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead,
26856 + if ((pInBss->CentralChannel != pInBss->Channel) &&
26857 + (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
26858 + {
26859 + if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE)
26860 + {
26861 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
26862 + SetCommonHT(pAd);
26863 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
26864 + }
26865 + else
26866 + {
26867 + if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BAND_WIDTH_20)
26868 + {
26869 + SetCommonHT(pAd);
26870 + }
26871 + }
26872 + }
26873 +#endif // DOT11_N_SUPPORT //
26874 +
26875 + // copy matching BSS from InTab to OutTab
26876 + NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY));
26877 +
26878 + OutTab->BssNr++;
26879 + }
26880 + else if ((pInBss->BssType == pAd->StaCfg.BssType) && (SsidLen == 0))
26881 + {
26882 + BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
26883 +
26884 +
26885 +#ifdef DOT11_N_SUPPORT
26886 + // 2.4G/5G N only mode
26887 + if ((pInBss->HtCapabilityLen == 0) &&
26888 + ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)))
26889 + {
26890 + DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
26891 + continue;
26892 + }
26893 +#endif // DOT11_N_SUPPORT //
26894 +
26895 + // New for WPA2
26896 + // Check the Authmode first
26897 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
26898 + {
26899 + // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode
26900 + if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux))
26901 + // None matched
26902 + continue;
26903 +
26904 + // Check cipher suite, AP must have more secured cipher than station setting
26905 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
26906 + {
26907 + // If it's not mixed mode, we should only let BSS pass with the same encryption
26908 + if (pInBss->WPA.bMixMode == FALSE)
26909 + if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher)
26910 + continue;
26911 +
26912 + // check group cipher
26913 + if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher)
26914 + continue;
26915 +
26916 + // check pairwise cipher, skip if none matched
26917 + // If profile set to AES, let it pass without question.
26918 + // If profile set to TKIP, we must find one mateched
26919 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
26920 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) &&
26921 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux))
26922 + continue;
26923 + }
26924 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
26925 + {
26926 + // If it's not mixed mode, we should only let BSS pass with the same encryption
26927 + if (pInBss->WPA2.bMixMode == FALSE)
26928 + if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher)
26929 + continue;
26930 +
26931 + // check group cipher
26932 + if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher)
26933 + continue;
26934 +
26935 + // check pairwise cipher, skip if none matched
26936 + // If profile set to AES, let it pass without question.
26937 + // If profile set to TKIP, we must find one mateched
26938 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
26939 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) &&
26940 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux))
26941 + continue;
26942 + }
26943 + }
26944 + // Bss Type matched, SSID matched.
26945 + // We will check wepstatus for qualification Bss
26946 + else if (pAd->StaCfg.WepStatus != pInBss->WepStatus)
26947 + continue;
26948 +
26949 +#ifdef DOT11_N_SUPPORT
26950 + // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region
26951 + // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead,
26952 + if ((pInBss->CentralChannel != pInBss->Channel) &&
26953 + (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
26954 + {
26955 + if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE)
26956 + {
26957 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
26958 + SetCommonHT(pAd);
26959 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
26960 + }
26961 + }
26962 +#endif // DOT11_N_SUPPORT //
26963 +
26964 + // copy matching BSS from InTab to OutTab
26965 + NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY));
26966 +
26967 + OutTab->BssNr++;
26968 + }
26969 +
26970 + if (OutTab->BssNr >= MAX_LEN_OF_BSS_TABLE)
26971 + break;
26972 + }
26973 +
26974 + BssTableSortByRssi(OutTab);
26975 +}
26976 +
26977 +
26978 +// IRQL = DISPATCH_LEVEL
26979 +VOID BssTableSortByRssi(
26980 + IN OUT BSS_TABLE *OutTab)
26981 +{
26982 + INT i, j;
26983 + BSS_ENTRY TmpBss;
26984 +
26985 + for (i = 0; i < OutTab->BssNr - 1; i++)
26986 + {
26987 + for (j = i+1; j < OutTab->BssNr; j++)
26988 + {
26989 + if (OutTab->BssEntry[j].Rssi > OutTab->BssEntry[i].Rssi)
26990 + {
26991 + NdisMoveMemory(&TmpBss, &OutTab->BssEntry[j], sizeof(BSS_ENTRY));
26992 + NdisMoveMemory(&OutTab->BssEntry[j], &OutTab->BssEntry[i], sizeof(BSS_ENTRY));
26993 + NdisMoveMemory(&OutTab->BssEntry[i], &TmpBss, sizeof(BSS_ENTRY));
26994 + }
26995 + }
26996 + }
26997 +}
26998 +#endif // CONFIG_STA_SUPPORT //
26999 +
27000 +
27001 +VOID BssCipherParse(
27002 + IN OUT PBSS_ENTRY pBss)
27003 +{
27004 + PEID_STRUCT pEid;
27005 + PUCHAR pTmp;
27006 + PRSN_IE_HEADER_STRUCT pRsnHeader;
27007 + PCIPHER_SUITE_STRUCT pCipher;
27008 + PAKM_SUITE_STRUCT pAKM;
27009 + USHORT Count;
27010 + INT Length;
27011 + NDIS_802_11_ENCRYPTION_STATUS TmpCipher;
27012 +
27013 + //
27014 + // WepStatus will be reset later, if AP announce TKIP or AES on the beacon frame.
27015 + //
27016 + if (pBss->Privacy)
27017 + {
27018 + pBss->WepStatus = Ndis802_11WEPEnabled;
27019 + }
27020 + else
27021 + {
27022 + pBss->WepStatus = Ndis802_11WEPDisabled;
27023 + }
27024 + // Set default to disable & open authentication before parsing variable IE
27025 + pBss->AuthMode = Ndis802_11AuthModeOpen;
27026 + pBss->AuthModeAux = Ndis802_11AuthModeOpen;
27027 +
27028 + // Init WPA setting
27029 + pBss->WPA.PairCipher = Ndis802_11WEPDisabled;
27030 + pBss->WPA.PairCipherAux = Ndis802_11WEPDisabled;
27031 + pBss->WPA.GroupCipher = Ndis802_11WEPDisabled;
27032 + pBss->WPA.RsnCapability = 0;
27033 + pBss->WPA.bMixMode = FALSE;
27034 +
27035 + // Init WPA2 setting
27036 + pBss->WPA2.PairCipher = Ndis802_11WEPDisabled;
27037 + pBss->WPA2.PairCipherAux = Ndis802_11WEPDisabled;
27038 + pBss->WPA2.GroupCipher = Ndis802_11WEPDisabled;
27039 + pBss->WPA2.RsnCapability = 0;
27040 + pBss->WPA2.bMixMode = FALSE;
27041 +
27042 +
27043 + Length = (INT) pBss->VarIELen;
27044 +
27045 + while (Length > 0)
27046 + {
27047 + // Parse cipher suite base on WPA1 & WPA2, they should be parsed differently
27048 + pTmp = ((PUCHAR) pBss->VarIEs) + pBss->VarIELen - Length;
27049 + pEid = (PEID_STRUCT) pTmp;
27050 + switch (pEid->Eid)
27051 + {
27052 + case IE_WPA:
27053 + //Parse Cisco IE_WPA (LEAP, CCKM, etc.)
27054 + if ( NdisEqualMemory((pTmp+8), CISCO_OUI, 3))
27055 + {
27056 + pTmp += 11;
27057 + switch (*pTmp)
27058 + {
27059 + case 1:
27060 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27061 + pBss->WepStatus = Ndis802_11Encryption1Enabled;
27062 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27063 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27064 + break;
27065 + case 2:
27066 + pBss->WepStatus = Ndis802_11Encryption2Enabled;
27067 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27068 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27069 + break;
27070 + case 4:
27071 + pBss->WepStatus = Ndis802_11Encryption3Enabled;
27072 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27073 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27074 + break;
27075 + default:
27076 + break;
27077 + }
27078 +
27079 + // if Cisco IE_WPA, break
27080 + break;
27081 + }
27082 + else if (NdisEqualMemory(pEid->Octet, SES_OUI, 3) && (pEid->Len == 7))
27083 + {
27084 + pBss->bSES = TRUE;
27085 + break;
27086 + }
27087 + else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4) != 1)
27088 + {
27089 + // if unsupported vendor specific IE
27090 + break;
27091 + }
27092 + // Skip OUI, version, and multicast suite
27093 + // This part should be improved in the future when AP supported multiple cipher suite.
27094 + // For now, it's OK since almost all APs have fixed cipher suite supported.
27095 + // pTmp = (PUCHAR) pEid->Octet;
27096 + pTmp += 11;
27097 +
27098 + // Cipher Suite Selectors from Spec P802.11i/D3.2 P26.
27099 + // Value Meaning
27100 + // 0 None
27101 + // 1 WEP-40
27102 + // 2 Tkip
27103 + // 3 WRAP
27104 + // 4 AES
27105 + // 5 WEP-104
27106 + // Parse group cipher
27107 + switch (*pTmp)
27108 + {
27109 + case 1:
27110 + pBss->WPA.GroupCipher = Ndis802_11GroupWEP40Enabled;
27111 + break;
27112 + case 5:
27113 + pBss->WPA.GroupCipher = Ndis802_11GroupWEP104Enabled;
27114 + break;
27115 + case 2:
27116 + pBss->WPA.GroupCipher = Ndis802_11Encryption2Enabled;
27117 + break;
27118 + case 4:
27119 + pBss->WPA.GroupCipher = Ndis802_11Encryption3Enabled;
27120 + break;
27121 + default:
27122 + break;
27123 + }
27124 + // number of unicast suite
27125 + pTmp += 1;
27126 +
27127 + // skip all unicast cipher suites
27128 + //Count = *(PUSHORT) pTmp;
27129 + Count = (pTmp[1]<<8) + pTmp[0];
27130 + pTmp += sizeof(USHORT);
27131 +
27132 + // Parsing all unicast cipher suite
27133 + while (Count > 0)
27134 + {
27135 + // Skip OUI
27136 + pTmp += 3;
27137 + TmpCipher = Ndis802_11WEPDisabled;
27138 + switch (*pTmp)
27139 + {
27140 + case 1:
27141 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27142 + TmpCipher = Ndis802_11Encryption1Enabled;
27143 + break;
27144 + case 2:
27145 + TmpCipher = Ndis802_11Encryption2Enabled;
27146 + break;
27147 + case 4:
27148 + TmpCipher = Ndis802_11Encryption3Enabled;
27149 + break;
27150 + default:
27151 + break;
27152 + }
27153 + if (TmpCipher > pBss->WPA.PairCipher)
27154 + {
27155 + // Move the lower cipher suite to PairCipherAux
27156 + pBss->WPA.PairCipherAux = pBss->WPA.PairCipher;
27157 + pBss->WPA.PairCipher = TmpCipher;
27158 + }
27159 + else
27160 + {
27161 + pBss->WPA.PairCipherAux = TmpCipher;
27162 + }
27163 + pTmp++;
27164 + Count--;
27165 + }
27166 +
27167 + // 4. get AKM suite counts
27168 + //Count = *(PUSHORT) pTmp;
27169 + Count = (pTmp[1]<<8) + pTmp[0];
27170 + pTmp += sizeof(USHORT);
27171 + pTmp += 3;
27172 +
27173 + switch (*pTmp)
27174 + {
27175 + case 1:
27176 + // Set AP support WPA mode
27177 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27178 + pBss->AuthMode = Ndis802_11AuthModeWPA;
27179 + else
27180 + pBss->AuthModeAux = Ndis802_11AuthModeWPA;
27181 + break;
27182 + case 2:
27183 + // Set AP support WPA mode
27184 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27185 + pBss->AuthMode = Ndis802_11AuthModeWPAPSK;
27186 + else
27187 + pBss->AuthModeAux = Ndis802_11AuthModeWPAPSK;
27188 + break;
27189 + default:
27190 + break;
27191 + }
27192 + pTmp += 1;
27193 +
27194 + // Fixed for WPA-None
27195 + if (pBss->BssType == BSS_ADHOC)
27196 + {
27197 + pBss->AuthMode = Ndis802_11AuthModeWPANone;
27198 + pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
27199 + pBss->WepStatus = pBss->WPA.GroupCipher;
27200 + // Patched bugs for old driver
27201 + if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled)
27202 + pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher;
27203 + }
27204 + else
27205 + pBss->WepStatus = pBss->WPA.PairCipher;
27206 +
27207 + // Check the Pair & Group, if different, turn on mixed mode flag
27208 + if (pBss->WPA.GroupCipher != pBss->WPA.PairCipher)
27209 + pBss->WPA.bMixMode = TRUE;
27210 +
27211 + break;
27212 +
27213 + case IE_RSN:
27214 + pRsnHeader = (PRSN_IE_HEADER_STRUCT) pTmp;
27215 +
27216 + // 0. Version must be 1
27217 + if (le2cpu16(pRsnHeader->Version) != 1)
27218 + break;
27219 + pTmp += sizeof(RSN_IE_HEADER_STRUCT);
27220 +
27221 + // 1. Check group cipher
27222 + pCipher = (PCIPHER_SUITE_STRUCT) pTmp;
27223 + if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
27224 + break;
27225 +
27226 + // Parse group cipher
27227 + switch (pCipher->Type)
27228 + {
27229 + case 1:
27230 + pBss->WPA2.GroupCipher = Ndis802_11GroupWEP40Enabled;
27231 + break;
27232 + case 5:
27233 + pBss->WPA2.GroupCipher = Ndis802_11GroupWEP104Enabled;
27234 + break;
27235 + case 2:
27236 + pBss->WPA2.GroupCipher = Ndis802_11Encryption2Enabled;
27237 + break;
27238 + case 4:
27239 + pBss->WPA2.GroupCipher = Ndis802_11Encryption3Enabled;
27240 + break;
27241 + default:
27242 + break;
27243 + }
27244 + // set to correct offset for next parsing
27245 + pTmp += sizeof(CIPHER_SUITE_STRUCT);
27246 +
27247 + // 2. Get pairwise cipher counts
27248 + //Count = *(PUSHORT) pTmp;
27249 + Count = (pTmp[1]<<8) + pTmp[0];
27250 + pTmp += sizeof(USHORT);
27251 +
27252 + // 3. Get pairwise cipher
27253 + // Parsing all unicast cipher suite
27254 + while (Count > 0)
27255 + {
27256 + // Skip OUI
27257 + pCipher = (PCIPHER_SUITE_STRUCT) pTmp;
27258 + TmpCipher = Ndis802_11WEPDisabled;
27259 + switch (pCipher->Type)
27260 + {
27261 + case 1:
27262 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27263 + TmpCipher = Ndis802_11Encryption1Enabled;
27264 + break;
27265 + case 2:
27266 + TmpCipher = Ndis802_11Encryption2Enabled;
27267 + break;
27268 + case 4:
27269 + TmpCipher = Ndis802_11Encryption3Enabled;
27270 + break;
27271 + default:
27272 + break;
27273 + }
27274 + if (TmpCipher > pBss->WPA2.PairCipher)
27275 + {
27276 + // Move the lower cipher suite to PairCipherAux
27277 + pBss->WPA2.PairCipherAux = pBss->WPA2.PairCipher;
27278 + pBss->WPA2.PairCipher = TmpCipher;
27279 + }
27280 + else
27281 + {
27282 + pBss->WPA2.PairCipherAux = TmpCipher;
27283 + }
27284 + pTmp += sizeof(CIPHER_SUITE_STRUCT);
27285 + Count--;
27286 + }
27287 +
27288 + // 4. get AKM suite counts
27289 + //Count = *(PUSHORT) pTmp;
27290 + Count = (pTmp[1]<<8) + pTmp[0];
27291 + pTmp += sizeof(USHORT);
27292 +
27293 + // 5. Get AKM ciphers
27294 + pAKM = (PAKM_SUITE_STRUCT) pTmp;
27295 + if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
27296 + break;
27297 +
27298 + switch (pAKM->Type)
27299 + {
27300 + case 1:
27301 + // Set AP support WPA mode
27302 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27303 + pBss->AuthMode = Ndis802_11AuthModeWPA2;
27304 + else
27305 + pBss->AuthModeAux = Ndis802_11AuthModeWPA2;
27306 + break;
27307 + case 2:
27308 + // Set AP support WPA mode
27309 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27310 + pBss->AuthMode = Ndis802_11AuthModeWPA2PSK;
27311 + else
27312 + pBss->AuthModeAux = Ndis802_11AuthModeWPA2PSK;
27313 + break;
27314 + default:
27315 + break;
27316 + }
27317 + pTmp += (Count * sizeof(AKM_SUITE_STRUCT));
27318 +
27319 + // Fixed for WPA-None
27320 + if (pBss->BssType == BSS_ADHOC)
27321 + {
27322 + pBss->AuthMode = Ndis802_11AuthModeWPANone;
27323 + pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
27324 + pBss->WPA.PairCipherAux = pBss->WPA2.PairCipherAux;
27325 + pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher;
27326 + pBss->WepStatus = pBss->WPA.GroupCipher;
27327 + // Patched bugs for old driver
27328 + if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled)
27329 + pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher;
27330 + }
27331 + pBss->WepStatus = pBss->WPA2.PairCipher;
27332 +
27333 + // 6. Get RSN capability
27334 + //pBss->WPA2.RsnCapability = *(PUSHORT) pTmp;
27335 + pBss->WPA2.RsnCapability = (pTmp[1]<<8) + pTmp[0];
27336 + pTmp += sizeof(USHORT);
27337 +
27338 + // Check the Pair & Group, if different, turn on mixed mode flag
27339 + if (pBss->WPA2.GroupCipher != pBss->WPA2.PairCipher)
27340 + pBss->WPA2.bMixMode = TRUE;
27341 +
27342 + break;
27343 + default:
27344 + break;
27345 + }
27346 + Length -= (pEid->Len + 2);
27347 + }
27348 +}
27349 +
27350 +// ===========================================================================================
27351 +// mac_table.c
27352 +// ===========================================================================================
27353 +
27354 +/*! \brief generates a random mac address value for IBSS BSSID
27355 + * \param Addr the bssid location
27356 + * \return none
27357 + * \pre
27358 + * \post
27359 + */
27360 +VOID MacAddrRandomBssid(
27361 + IN PRTMP_ADAPTER pAd,
27362 + OUT PUCHAR pAddr)
27363 +{
27364 + INT i;
27365 +
27366 + for (i = 0; i < MAC_ADDR_LEN; i++)
27367 + {
27368 + pAddr[i] = RandomByte(pAd);
27369 + }
27370 +
27371 + pAddr[0] = (pAddr[0] & 0xfe) | 0x02; // the first 2 bits must be 01xxxxxxxx
27372 +}
27373 +
27374 +/*! \brief init the management mac frame header
27375 + * \param p_hdr mac header
27376 + * \param subtype subtype of the frame
27377 + * \param p_ds destination address, don't care if it is a broadcast address
27378 + * \return none
27379 + * \pre the station has the following information in the pAd->StaCfg
27380 + * - bssid
27381 + * - station address
27382 + * \post
27383 + * \note this function initializes the following field
27384 +
27385 + IRQL = PASSIVE_LEVEL
27386 + IRQL = DISPATCH_LEVEL
27387 +
27388 + */
27389 +VOID MgtMacHeaderInit(
27390 + IN PRTMP_ADAPTER pAd,
27391 + IN OUT PHEADER_802_11 pHdr80211,
27392 + IN UCHAR SubType,
27393 + IN UCHAR ToDs,
27394 + IN PUCHAR pDA,
27395 + IN PUCHAR pBssid)
27396 +{
27397 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
27398 +
27399 + pHdr80211->FC.Type = BTYPE_MGMT;
27400 + pHdr80211->FC.SubType = SubType;
27401 +// if (SubType == SUBTYPE_ACK) // sample, no use, it will conflict with ACTION frame sub type
27402 +// pHdr80211->FC.Type = BTYPE_CNTL;
27403 + pHdr80211->FC.ToDs = ToDs;
27404 + COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
27405 +#ifdef CONFIG_STA_SUPPORT
27406 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27407 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
27408 +#endif // CONFIG_STA_SUPPORT //
27409 + COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
27410 +}
27411 +
27412 +// ===========================================================================================
27413 +// mem_mgmt.c
27414 +// ===========================================================================================
27415 +
27416 +/*!***************************************************************************
27417 + * This routine build an outgoing frame, and fill all information specified
27418 + * in argument list to the frame body. The actual frame size is the summation
27419 + * of all arguments.
27420 + * input params:
27421 + * Buffer - pointer to a pre-allocated memory segment
27422 + * args - a list of <int arg_size, arg> pairs.
27423 + * NOTE NOTE NOTE!!!! the last argument must be NULL, otherwise this
27424 + * function will FAIL!!!
27425 + * return:
27426 + * Size of the buffer
27427 + * usage:
27428 + * MakeOutgoingFrame(Buffer, output_length, 2, &fc, 2, &dur, 6, p_addr1, 6,p_addr2, END_OF_ARGS);
27429 +
27430 + IRQL = PASSIVE_LEVEL
27431 + IRQL = DISPATCH_LEVEL
27432 +
27433 + ****************************************************************************/
27434 +ULONG MakeOutgoingFrame(
27435 + OUT CHAR *Buffer,
27436 + OUT ULONG *FrameLen, ...)
27437 +{
27438 + CHAR *p;
27439 + int leng;
27440 + ULONG TotLeng;
27441 + va_list Args;
27442 +
27443 + // calculates the total length
27444 + TotLeng = 0;
27445 + va_start(Args, FrameLen);
27446 + do
27447 + {
27448 + leng = va_arg(Args, int);
27449 + if (leng == END_OF_ARGS)
27450 + {
27451 + break;
27452 + }
27453 + p = va_arg(Args, PVOID);
27454 + NdisMoveMemory(&Buffer[TotLeng], p, leng);
27455 + TotLeng = TotLeng + leng;
27456 + } while(TRUE);
27457 +
27458 + va_end(Args); /* clean up */
27459 + *FrameLen = TotLeng;
27460 + return TotLeng;
27461 +}
27462 +
27463 +// ===========================================================================================
27464 +// mlme_queue.c
27465 +// ===========================================================================================
27466 +
27467 +/*! \brief Initialize The MLME Queue, used by MLME Functions
27468 + * \param *Queue The MLME Queue
27469 + * \return Always Return NDIS_STATE_SUCCESS in this implementation
27470 + * \pre
27471 + * \post
27472 + * \note Because this is done only once (at the init stage), no need to be locked
27473 +
27474 + IRQL = PASSIVE_LEVEL
27475 +
27476 + */
27477 +NDIS_STATUS MlmeQueueInit(
27478 + IN MLME_QUEUE *Queue)
27479 +{
27480 + INT i;
27481 +
27482 + NdisAllocateSpinLock(&Queue->Lock);
27483 +
27484 + Queue->Num = 0;
27485 + Queue->Head = 0;
27486 + Queue->Tail = 0;
27487 +
27488 + for (i = 0; i < MAX_LEN_OF_MLME_QUEUE; i++)
27489 + {
27490 + Queue->Entry[i].Occupied = FALSE;
27491 + Queue->Entry[i].MsgLen = 0;
27492 + NdisZeroMemory(Queue->Entry[i].Msg, MGMT_DMA_BUFFER_SIZE);
27493 + }
27494 +
27495 + return NDIS_STATUS_SUCCESS;
27496 +}
27497 +
27498 +/*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread
27499 + * \param *Queue The MLME Queue
27500 + * \param Machine The State Machine Id
27501 + * \param MsgType The Message Type
27502 + * \param MsgLen The Message length
27503 + * \param *Msg The message pointer
27504 + * \return TRUE if enqueue is successful, FALSE if the queue is full
27505 + * \pre
27506 + * \post
27507 + * \note The message has to be initialized
27508 +
27509 + IRQL = PASSIVE_LEVEL
27510 + IRQL = DISPATCH_LEVEL
27511 +
27512 + */
27513 +BOOLEAN MlmeEnqueue(
27514 + IN PRTMP_ADAPTER pAd,
27515 + IN ULONG Machine,
27516 + IN ULONG MsgType,
27517 + IN ULONG MsgLen,
27518 + IN VOID *Msg)
27519 +{
27520 + INT Tail;
27521 + MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue;
27522 +
27523 + // Do nothing if the driver is starting halt state.
27524 + // This might happen when timer already been fired before cancel timer with mlmehalt
27525 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
27526 + return FALSE;
27527 +
27528 + // First check the size, it MUST not exceed the mlme queue size
27529 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
27530 + {
27531 + DBGPRINT_ERR(("MlmeEnqueue: msg too large, size = %ld \n", MsgLen));
27532 + return FALSE;
27533 + }
27534 +
27535 + if (MlmeQueueFull(Queue))
27536 + {
27537 + return FALSE;
27538 + }
27539 +
27540 + NdisAcquireSpinLock(&(Queue->Lock));
27541 + Tail = Queue->Tail;
27542 + Queue->Tail++;
27543 + Queue->Num++;
27544 + if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE)
27545 + {
27546 + Queue->Tail = 0;
27547 + }
27548 +
27549 + Queue->Entry[Tail].Wcid = RESERVED_WCID;
27550 + Queue->Entry[Tail].Occupied = TRUE;
27551 + Queue->Entry[Tail].Machine = Machine;
27552 + Queue->Entry[Tail].MsgType = MsgType;
27553 + Queue->Entry[Tail].MsgLen = MsgLen;
27554 +
27555 + if (Msg != NULL)
27556 + {
27557 + NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
27558 + }
27559 +
27560 + NdisReleaseSpinLock(&(Queue->Lock));
27561 + return TRUE;
27562 +}
27563 +
27564 +/*! \brief This function is used when Recv gets a MLME message
27565 + * \param *Queue The MLME Queue
27566 + * \param TimeStampHigh The upper 32 bit of timestamp
27567 + * \param TimeStampLow The lower 32 bit of timestamp
27568 + * \param Rssi The receiving RSSI strength
27569 + * \param MsgLen The length of the message
27570 + * \param *Msg The message pointer
27571 + * \return TRUE if everything ok, FALSE otherwise (like Queue Full)
27572 + * \pre
27573 + * \post
27574 +
27575 + IRQL = DISPATCH_LEVEL
27576 +
27577 + */
27578 +BOOLEAN MlmeEnqueueForRecv(
27579 + IN PRTMP_ADAPTER pAd,
27580 + IN ULONG Wcid,
27581 + IN ULONG TimeStampHigh,
27582 + IN ULONG TimeStampLow,
27583 + IN UCHAR Rssi0,
27584 + IN UCHAR Rssi1,
27585 + IN UCHAR Rssi2,
27586 + IN ULONG MsgLen,
27587 + IN VOID *Msg,
27588 + IN UCHAR Signal)
27589 +{
27590 + INT Tail, Machine;
27591 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
27592 + INT MsgType;
27593 + MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue;
27594 +
27595 +#ifdef RALINK_ATE
27596 + /* Nothing to do in ATE mode */
27597 + if(ATE_ON(pAd))
27598 + return FALSE;
27599 +#endif // RALINK_ATE //
27600 +
27601 + // Do nothing if the driver is starting halt state.
27602 + // This might happen when timer already been fired before cancel timer with mlmehalt
27603 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
27604 + {
27605 + DBGPRINT_ERR(("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n"));
27606 + return FALSE;
27607 + }
27608 +
27609 + // First check the size, it MUST not exceed the mlme queue size
27610 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
27611 + {
27612 + DBGPRINT_ERR(("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen));
27613 + return FALSE;
27614 + }
27615 +
27616 + if (MlmeQueueFull(Queue))
27617 + {
27618 + return FALSE;
27619 + }
27620 +
27621 +#ifdef CONFIG_STA_SUPPORT
27622 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27623 + {
27624 + if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType))
27625 + {
27626 + DBGPRINT_ERR(("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n",pFrame->Hdr.FC.SubType));
27627 + return FALSE;
27628 + }
27629 + }
27630 +#endif // CONFIG_STA_SUPPORT //
27631 +
27632 + // OK, we got all the informations, it is time to put things into queue
27633 + NdisAcquireSpinLock(&(Queue->Lock));
27634 + Tail = Queue->Tail;
27635 + Queue->Tail++;
27636 + Queue->Num++;
27637 + if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE)
27638 + {
27639 + Queue->Tail = 0;
27640 + }
27641 + Queue->Entry[Tail].Occupied = TRUE;
27642 + Queue->Entry[Tail].Machine = Machine;
27643 + Queue->Entry[Tail].MsgType = MsgType;
27644 + Queue->Entry[Tail].MsgLen = MsgLen;
27645 + Queue->Entry[Tail].TimeStamp.u.LowPart = TimeStampLow;
27646 + Queue->Entry[Tail].TimeStamp.u.HighPart = TimeStampHigh;
27647 + Queue->Entry[Tail].Rssi0 = Rssi0;
27648 + Queue->Entry[Tail].Rssi1 = Rssi1;
27649 + Queue->Entry[Tail].Rssi2 = Rssi2;
27650 + Queue->Entry[Tail].Signal = Signal;
27651 + Queue->Entry[Tail].Wcid = (UCHAR)Wcid;
27652 +
27653 + Queue->Entry[Tail].Channel = pAd->LatchRfRegs.Channel;
27654 +
27655 + if (Msg != NULL)
27656 + {
27657 + NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
27658 + }
27659 +
27660 + NdisReleaseSpinLock(&(Queue->Lock));
27661 +
27662 + RT28XX_MLME_HANDLER(pAd);
27663 +
27664 + return TRUE;
27665 +}
27666 +
27667 +
27668 +/*! \brief Dequeue a message from the MLME Queue
27669 + * \param *Queue The MLME Queue
27670 + * \param *Elem The message dequeued from MLME Queue
27671 + * \return TRUE if the Elem contains something, FALSE otherwise
27672 + * \pre
27673 + * \post
27674 +
27675 + IRQL = DISPATCH_LEVEL
27676 +
27677 + */
27678 +BOOLEAN MlmeDequeue(
27679 + IN MLME_QUEUE *Queue,
27680 + OUT MLME_QUEUE_ELEM **Elem)
27681 +{
27682 + NdisAcquireSpinLock(&(Queue->Lock));
27683 + *Elem = &(Queue->Entry[Queue->Head]);
27684 + Queue->Num--;
27685 + Queue->Head++;
27686 + if (Queue->Head == MAX_LEN_OF_MLME_QUEUE)
27687 + {
27688 + Queue->Head = 0;
27689 + }
27690 + NdisReleaseSpinLock(&(Queue->Lock));
27691 + return TRUE;
27692 +}
27693 +
27694 +// IRQL = DISPATCH_LEVEL
27695 +VOID MlmeRestartStateMachine(
27696 + IN PRTMP_ADAPTER pAd)
27697 +{
27698 +#ifdef CONFIG_STA_SUPPORT
27699 + BOOLEAN Cancelled;
27700 +#endif // CONFIG_STA_SUPPORT //
27701 +
27702 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n"));
27703 +
27704 +
27705 +#ifdef CONFIG_STA_SUPPORT
27706 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27707 + {
27708 +#ifdef QOS_DLS_SUPPORT
27709 + UCHAR i;
27710 +#endif // QOS_DLS_SUPPORT //
27711 + // Cancel all timer events
27712 + // Be careful to cancel new added timer
27713 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
27714 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
27715 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
27716 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
27717 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
27718 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
27719 +
27720 +#ifdef QOS_DLS_SUPPORT
27721 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
27722 + {
27723 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled);
27724 + }
27725 +#endif // QOS_DLS_SUPPORT //
27726 + }
27727 +#endif // CONFIG_STA_SUPPORT //
27728 +
27729 + // Change back to original channel in case of doing scan
27730 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
27731 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
27732 +
27733 + // Resume MSDU which is turned off durning scan
27734 + RTMPResumeMsduTransmission(pAd);
27735 +
27736 +#ifdef CONFIG_STA_SUPPORT
27737 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27738 + {
27739 + // Set all state machines back IDLE
27740 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
27741 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
27742 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
27743 + pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
27744 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
27745 + pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
27746 +#ifdef QOS_DLS_SUPPORT
27747 + pAd->Mlme.DlsMachine.CurrState = DLS_IDLE;
27748 +#endif // QOS_DLS_SUPPORT //
27749 + }
27750 +#endif // CONFIG_STA_SUPPORT //
27751 +
27752 +}
27753 +
27754 +/*! \brief test if the MLME Queue is empty
27755 + * \param *Queue The MLME Queue
27756 + * \return TRUE if the Queue is empty, FALSE otherwise
27757 + * \pre
27758 + * \post
27759 +
27760 + IRQL = DISPATCH_LEVEL
27761 +
27762 + */
27763 +BOOLEAN MlmeQueueEmpty(
27764 + IN MLME_QUEUE *Queue)
27765 +{
27766 + BOOLEAN Ans;
27767 +
27768 + NdisAcquireSpinLock(&(Queue->Lock));
27769 + Ans = (Queue->Num == 0);
27770 + NdisReleaseSpinLock(&(Queue->Lock));
27771 +
27772 + return Ans;
27773 +}
27774 +
27775 +/*! \brief test if the MLME Queue is full
27776 + * \param *Queue The MLME Queue
27777 + * \return TRUE if the Queue is empty, FALSE otherwise
27778 + * \pre
27779 + * \post
27780 +
27781 + IRQL = PASSIVE_LEVEL
27782 + IRQL = DISPATCH_LEVEL
27783 +
27784 + */
27785 +BOOLEAN MlmeQueueFull(
27786 + IN MLME_QUEUE *Queue)
27787 +{
27788 + BOOLEAN Ans;
27789 +
27790 + NdisAcquireSpinLock(&(Queue->Lock));
27791 + Ans = (Queue->Num == MAX_LEN_OF_MLME_QUEUE || Queue->Entry[Queue->Tail].Occupied);
27792 + NdisReleaseSpinLock(&(Queue->Lock));
27793 +
27794 + return Ans;
27795 +}
27796 +
27797 +/*! \brief The destructor of MLME Queue
27798 + * \param
27799 + * \return
27800 + * \pre
27801 + * \post
27802 + * \note Clear Mlme Queue, Set Queue->Num to Zero.
27803 +
27804 + IRQL = PASSIVE_LEVEL
27805 +
27806 + */
27807 +VOID MlmeQueueDestroy(
27808 + IN MLME_QUEUE *pQueue)
27809 +{
27810 + NdisAcquireSpinLock(&(pQueue->Lock));
27811 + pQueue->Num = 0;
27812 + pQueue->Head = 0;
27813 + pQueue->Tail = 0;
27814 + NdisReleaseSpinLock(&(pQueue->Lock));
27815 + NdisFreeSpinLock(&(pQueue->Lock));
27816 +}
27817 +
27818 +/*! \brief To substitute the message type if the message is coming from external
27819 + * \param pFrame The frame received
27820 + * \param *Machine The state machine
27821 + * \param *MsgType the message type for the state machine
27822 + * \return TRUE if the substitution is successful, FALSE otherwise
27823 + * \pre
27824 + * \post
27825 +
27826 + IRQL = DISPATCH_LEVEL
27827 +
27828 + */
27829 +#ifdef CONFIG_STA_SUPPORT
27830 +BOOLEAN MsgTypeSubst(
27831 + IN PRTMP_ADAPTER pAd,
27832 + IN PFRAME_802_11 pFrame,
27833 + OUT INT *Machine,
27834 + OUT INT *MsgType)
27835 +{
27836 + USHORT Seq;
27837 + UCHAR EAPType;
27838 + PUCHAR pData;
27839 +
27840 + // Pointer to start of data frames including SNAP header
27841 + pData = (PUCHAR) pFrame + LENGTH_802_11;
27842 +
27843 + // The only data type will pass to this function is EAPOL frame
27844 + if (pFrame->Hdr.FC.Type == BTYPE_DATA)
27845 + {
27846 + if (NdisEqualMemory(SNAP_AIRONET, pData, LENGTH_802_1_H))
27847 + {
27848 + // Cisco Aironet SNAP header
27849 + *Machine = AIRONET_STATE_MACHINE;
27850 + *MsgType = MT2_AIRONET_MSG;
27851 + return (TRUE);
27852 + }
27853 +#ifdef LEAP_SUPPORT
27854 + if ( pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP ) //LEAP
27855 + {
27856 + // LEAP frames
27857 + *Machine = LEAP_STATE_MACHINE;
27858 + EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1);
27859 + return (LeapMsgTypeSubst(EAPType, MsgType));
27860 + }
27861 + else
27862 +#endif // LEAP_SUPPORT //
27863 + {
27864 + *Machine = WPA_PSK_STATE_MACHINE;
27865 + EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1);
27866 + return(WpaMsgTypeSubst(EAPType, MsgType));
27867 + }
27868 + }
27869 +
27870 + switch (pFrame->Hdr.FC.SubType)
27871 + {
27872 + case SUBTYPE_ASSOC_REQ:
27873 + *Machine = ASSOC_STATE_MACHINE;
27874 + *MsgType = MT2_PEER_ASSOC_REQ;
27875 + break;
27876 + case SUBTYPE_ASSOC_RSP:
27877 + *Machine = ASSOC_STATE_MACHINE;
27878 + *MsgType = MT2_PEER_ASSOC_RSP;
27879 + break;
27880 + case SUBTYPE_REASSOC_REQ:
27881 + *Machine = ASSOC_STATE_MACHINE;
27882 + *MsgType = MT2_PEER_REASSOC_REQ;
27883 + break;
27884 + case SUBTYPE_REASSOC_RSP:
27885 + *Machine = ASSOC_STATE_MACHINE;
27886 + *MsgType = MT2_PEER_REASSOC_RSP;
27887 + break;
27888 + case SUBTYPE_PROBE_REQ:
27889 + *Machine = SYNC_STATE_MACHINE;
27890 + *MsgType = MT2_PEER_PROBE_REQ;
27891 + break;
27892 + case SUBTYPE_PROBE_RSP:
27893 + *Machine = SYNC_STATE_MACHINE;
27894 + *MsgType = MT2_PEER_PROBE_RSP;
27895 + break;
27896 + case SUBTYPE_BEACON:
27897 + *Machine = SYNC_STATE_MACHINE;
27898 + *MsgType = MT2_PEER_BEACON;
27899 + break;
27900 + case SUBTYPE_ATIM:
27901 + *Machine = SYNC_STATE_MACHINE;
27902 + *MsgType = MT2_PEER_ATIM;
27903 + break;
27904 + case SUBTYPE_DISASSOC:
27905 + *Machine = ASSOC_STATE_MACHINE;
27906 + *MsgType = MT2_PEER_DISASSOC_REQ;
27907 + break;
27908 + case SUBTYPE_AUTH:
27909 + // get the sequence number from payload 24 Mac Header + 2 bytes algorithm
27910 + NdisMoveMemory(&Seq, &pFrame->Octet[2], sizeof(USHORT));
27911 + if (Seq == 1 || Seq == 3)
27912 + {
27913 + *Machine = AUTH_RSP_STATE_MACHINE;
27914 + *MsgType = MT2_PEER_AUTH_ODD;
27915 + }
27916 + else if (Seq == 2 || Seq == 4)
27917 + {
27918 + *Machine = AUTH_STATE_MACHINE;
27919 + *MsgType = MT2_PEER_AUTH_EVEN;
27920 + }
27921 + else
27922 + {
27923 + return FALSE;
27924 + }
27925 + break;
27926 + case SUBTYPE_DEAUTH:
27927 + *Machine = AUTH_RSP_STATE_MACHINE;
27928 + *MsgType = MT2_PEER_DEAUTH;
27929 + break;
27930 + case SUBTYPE_ACTION:
27931 + *Machine = ACTION_STATE_MACHINE;
27932 + // Sometimes Sta will return with category bytes with MSB = 1, if they receive catogory out of their support
27933 + if ((pFrame->Octet[0]&0x7F) > MAX_PEER_CATE_MSG)
27934 + {
27935 + *MsgType = MT2_ACT_INVALID;
27936 + }
27937 + else
27938 + {
27939 + *MsgType = (pFrame->Octet[0]&0x7F);
27940 + }
27941 + break;
27942 + default:
27943 + return FALSE;
27944 + break;
27945 + }
27946 +
27947 + return TRUE;
27948 +}
27949 +#endif // CONFIG_STA_SUPPORT //
27950 +
27951 +// ===========================================================================================
27952 +// state_machine.c
27953 +// ===========================================================================================
27954 +
27955 +/*! \brief Initialize the state machine.
27956 + * \param *S pointer to the state machine
27957 + * \param Trans State machine transition function
27958 + * \param StNr number of states
27959 + * \param MsgNr number of messages
27960 + * \param DefFunc default function, when there is invalid state/message combination
27961 + * \param InitState initial state of the state machine
27962 + * \param Base StateMachine base, internal use only
27963 + * \pre p_sm should be a legal pointer
27964 + * \post
27965 +
27966 + IRQL = PASSIVE_LEVEL
27967 +
27968 + */
27969 +VOID StateMachineInit(
27970 + IN STATE_MACHINE *S,
27971 + IN STATE_MACHINE_FUNC Trans[],
27972 + IN ULONG StNr,
27973 + IN ULONG MsgNr,
27974 + IN STATE_MACHINE_FUNC DefFunc,
27975 + IN ULONG InitState,
27976 + IN ULONG Base)
27977 +{
27978 + ULONG i, j;
27979 +
27980 + // set number of states and messages
27981 + S->NrState = StNr;
27982 + S->NrMsg = MsgNr;
27983 + S->Base = Base;
27984 +
27985 + S->TransFunc = Trans;
27986 +
27987 + // init all state transition to default function
27988 + for (i = 0; i < StNr; i++)
27989 + {
27990 + for (j = 0; j < MsgNr; j++)
27991 + {
27992 + S->TransFunc[i * MsgNr + j] = DefFunc;
27993 + }
27994 + }
27995 +
27996 + // set the starting state
27997 + S->CurrState = InitState;
27998 +}
27999 +
28000 +/*! \brief This function fills in the function pointer into the cell in the state machine
28001 + * \param *S pointer to the state machine
28002 + * \param St state
28003 + * \param Msg incoming message
28004 + * \param f the function to be executed when (state, message) combination occurs at the state machine
28005 + * \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
28006 + * \post
28007 +
28008 + IRQL = PASSIVE_LEVEL
28009 +
28010 + */
28011 +VOID StateMachineSetAction(
28012 + IN STATE_MACHINE *S,
28013 + IN ULONG St,
28014 + IN ULONG Msg,
28015 + IN STATE_MACHINE_FUNC Func)
28016 +{
28017 + ULONG MsgIdx;
28018 +
28019 + MsgIdx = Msg - S->Base;
28020 +
28021 + if (St < S->NrState && MsgIdx < S->NrMsg)
28022 + {
28023 + // boundary checking before setting the action
28024 + S->TransFunc[St * S->NrMsg + MsgIdx] = Func;
28025 + }
28026 +}
28027 +
28028 +/*! \brief This function does the state transition
28029 + * \param *Adapter the NIC adapter pointer
28030 + * \param *S the state machine
28031 + * \param *Elem the message to be executed
28032 + * \return None
28033 +
28034 + IRQL = DISPATCH_LEVEL
28035 +
28036 + */
28037 +VOID StateMachinePerformAction(
28038 + IN PRTMP_ADAPTER pAd,
28039 + IN STATE_MACHINE *S,
28040 + IN MLME_QUEUE_ELEM *Elem)
28041 +{
28042 + (*(S->TransFunc[S->CurrState * S->NrMsg + Elem->MsgType - S->Base]))(pAd, Elem);
28043 +}
28044 +
28045 +/*
28046 + ==========================================================================
28047 + Description:
28048 + The drop function, when machine executes this, the message is simply
28049 + ignored. This function does nothing, the message is freed in
28050 + StateMachinePerformAction()
28051 + ==========================================================================
28052 + */
28053 +VOID Drop(
28054 + IN PRTMP_ADAPTER pAd,
28055 + IN MLME_QUEUE_ELEM *Elem)
28056 +{
28057 +}
28058 +
28059 +// ===========================================================================================
28060 +// lfsr.c
28061 +// ===========================================================================================
28062 +
28063 +/*
28064 + ==========================================================================
28065 + Description:
28066 +
28067 + IRQL = PASSIVE_LEVEL
28068 +
28069 + ==========================================================================
28070 + */
28071 +VOID LfsrInit(
28072 + IN PRTMP_ADAPTER pAd,
28073 + IN ULONG Seed)
28074 +{
28075 + if (Seed == 0)
28076 + pAd->Mlme.ShiftReg = 1;
28077 + else
28078 + pAd->Mlme.ShiftReg = Seed;
28079 +}
28080 +
28081 +/*
28082 + ==========================================================================
28083 + Description:
28084 + ==========================================================================
28085 + */
28086 +UCHAR RandomByte(
28087 + IN PRTMP_ADAPTER pAd)
28088 +{
28089 + ULONG i;
28090 + UCHAR R, Result;
28091 +
28092 + R = 0;
28093 +
28094 + if (pAd->Mlme.ShiftReg == 0)
28095 + NdisGetSystemUpTime((ULONG *)&pAd->Mlme.ShiftReg);
28096 +
28097 + for (i = 0; i < 8; i++)
28098 + {
28099 + if (pAd->Mlme.ShiftReg & 0x00000001)
28100 + {
28101 + pAd->Mlme.ShiftReg = ((pAd->Mlme.ShiftReg ^ LFSR_MASK) >> 1) | 0x80000000;
28102 + Result = 1;
28103 + }
28104 + else
28105 + {
28106 + pAd->Mlme.ShiftReg = pAd->Mlme.ShiftReg >> 1;
28107 + Result = 0;
28108 + }
28109 + R = (R << 1) | Result;
28110 + }
28111 +
28112 + return R;
28113 +}
28114 +
28115 +VOID AsicUpdateAutoFallBackTable(
28116 + IN PRTMP_ADAPTER pAd,
28117 + IN PUCHAR pRateTable)
28118 +{
28119 + UCHAR i;
28120 + HT_FBK_CFG0_STRUC HtCfg0;
28121 + HT_FBK_CFG1_STRUC HtCfg1;
28122 + LG_FBK_CFG0_STRUC LgCfg0;
28123 + LG_FBK_CFG1_STRUC LgCfg1;
28124 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate;
28125 +
28126 + // set to initial value
28127 + HtCfg0.word = 0x65432100;
28128 + HtCfg1.word = 0xedcba988;
28129 + LgCfg0.word = 0xedcba988;
28130 + LgCfg1.word = 0x00002100;
28131 +
28132 + pNextTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1;
28133 + for (i = 1; i < *((PUCHAR) pRateTable); i++)
28134 + {
28135 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1+i;
28136 + switch (pCurrTxRate->Mode)
28137 + {
28138 + case 0: //CCK
28139 + break;
28140 + case 1: //OFDM
28141 + {
28142 + switch(pCurrTxRate->CurrMCS)
28143 + {
28144 + case 0:
28145 + LgCfg0.field.OFDMMCS0FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28146 + break;
28147 + case 1:
28148 + LgCfg0.field.OFDMMCS1FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28149 + break;
28150 + case 2:
28151 + LgCfg0.field.OFDMMCS2FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28152 + break;
28153 + case 3:
28154 + LgCfg0.field.OFDMMCS3FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28155 + break;
28156 + case 4:
28157 + LgCfg0.field.OFDMMCS4FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28158 + break;
28159 + case 5:
28160 + LgCfg0.field.OFDMMCS5FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28161 + break;
28162 + case 6:
28163 + LgCfg0.field.OFDMMCS6FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28164 + break;
28165 + case 7:
28166 + LgCfg0.field.OFDMMCS7FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28167 + break;
28168 + }
28169 + }
28170 + break;
28171 +#ifdef DOT11_N_SUPPORT
28172 + case 2: //HT-MIX
28173 + case 3: //HT-GF
28174 + {
28175 + if ((pNextTxRate->Mode >= MODE_HTMIX) && (pCurrTxRate->CurrMCS != pNextTxRate->CurrMCS))
28176 + {
28177 + switch(pCurrTxRate->CurrMCS)
28178 + {
28179 + case 0:
28180 + HtCfg0.field.HTMCS0FBK = pNextTxRate->CurrMCS;
28181 + break;
28182 + case 1:
28183 + HtCfg0.field.HTMCS1FBK = pNextTxRate->CurrMCS;
28184 + break;
28185 + case 2:
28186 + HtCfg0.field.HTMCS2FBK = pNextTxRate->CurrMCS;
28187 + break;
28188 + case 3:
28189 + HtCfg0.field.HTMCS3FBK = pNextTxRate->CurrMCS;
28190 + break;
28191 + case 4:
28192 + HtCfg0.field.HTMCS4FBK = pNextTxRate->CurrMCS;
28193 + break;
28194 + case 5:
28195 + HtCfg0.field.HTMCS5FBK = pNextTxRate->CurrMCS;
28196 + break;
28197 + case 6:
28198 + HtCfg0.field.HTMCS6FBK = pNextTxRate->CurrMCS;
28199 + break;
28200 + case 7:
28201 + HtCfg0.field.HTMCS7FBK = pNextTxRate->CurrMCS;
28202 + break;
28203 + case 8:
28204 + HtCfg1.field.HTMCS8FBK = pNextTxRate->CurrMCS;
28205 + break;
28206 + case 9:
28207 + HtCfg1.field.HTMCS9FBK = pNextTxRate->CurrMCS;
28208 + break;
28209 + case 10:
28210 + HtCfg1.field.HTMCS10FBK = pNextTxRate->CurrMCS;
28211 + break;
28212 + case 11:
28213 + HtCfg1.field.HTMCS11FBK = pNextTxRate->CurrMCS;
28214 + break;
28215 + case 12:
28216 + HtCfg1.field.HTMCS12FBK = pNextTxRate->CurrMCS;
28217 + break;
28218 + case 13:
28219 + HtCfg1.field.HTMCS13FBK = pNextTxRate->CurrMCS;
28220 + break;
28221 + case 14:
28222 + HtCfg1.field.HTMCS14FBK = pNextTxRate->CurrMCS;
28223 + break;
28224 + case 15:
28225 + HtCfg1.field.HTMCS15FBK = pNextTxRate->CurrMCS;
28226 + break;
28227 + default:
28228 + DBGPRINT(RT_DEBUG_ERROR, ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n", pCurrTxRate->CurrMCS));
28229 + }
28230 + }
28231 + }
28232 + break;
28233 +#endif // DOT11_N_SUPPORT //
28234 + }
28235 +
28236 + pNextTxRate = pCurrTxRate;
28237 + }
28238 +
28239 + RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word);
28240 + RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word);
28241 + RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word);
28242 + RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word);
28243 +}
28244 +
28245 +/*
28246 + ========================================================================
28247 +
28248 + Routine Description:
28249 + Set MAC register value according operation mode.
28250 + OperationMode AND bNonGFExist are for MM and GF Proteciton.
28251 + If MM or GF mask is not set, those passing argument doesn't not take effect.
28252 +
28253 + Operation mode meaning:
28254 + = 0 : Pure HT, no preotection.
28255 + = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS.
28256 + = 0x10: No Transmission in 40M is protected.
28257 + = 0x11: Transmission in both 40M and 20M shall be protected
28258 + if (bNonGFExist)
28259 + we should choose not to use GF. But still set correct ASIC registers.
28260 + ========================================================================
28261 +*/
28262 +VOID AsicUpdateProtect(
28263 + IN PRTMP_ADAPTER pAd,
28264 + IN USHORT OperationMode,
28265 + IN UCHAR SetMask,
28266 + IN BOOLEAN bDisableBGProtect,
28267 + IN BOOLEAN bNonGFExist)
28268 +{
28269 + PROT_CFG_STRUC ProtCfg, ProtCfg4;
28270 + UINT32 Protect[6];
28271 + USHORT offset;
28272 + UCHAR i;
28273 + UINT32 MacReg = 0;
28274 +
28275 +#ifdef RALINK_ATE
28276 + if (ATE_ON(pAd))
28277 + return;
28278 +#endif // RALINK_ATE //
28279 +
28280 +#ifdef DOT11_N_SUPPORT
28281 + if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8))
28282 + {
28283 + return;
28284 + }
28285 +
28286 + if (pAd->BATable.numAsOriginator)
28287 + {
28288 + //
28289 + // enable the RTS/CTS to avoid channel collision
28290 + //
28291 + SetMask = ALLN_SETPROTECT;
28292 + OperationMode = 8;
28293 + }
28294 +#endif // DOT11_N_SUPPORT //
28295 +
28296 + // Config ASIC RTS threshold register
28297 + RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
28298 + MacReg &= 0xFF0000FF;
28299 +#if 0
28300 + MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
28301 +#else
28302 + // If the user want disable RtsThreshold and enbale Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096
28303 + if ((
28304 +#ifdef DOT11_N_SUPPORT
28305 + (pAd->CommonCfg.BACapability.field.AmsduEnable) ||
28306 +#endif // DOT11_N_SUPPORT //
28307 + (pAd->CommonCfg.bAggregationCapable == TRUE))
28308 + && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD)
28309 + {
28310 + MacReg |= (0x1000 << 8);
28311 + }
28312 + else
28313 + {
28314 + MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
28315 + }
28316 +#endif
28317 +
28318 + RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
28319 +
28320 + // Initial common protection settings
28321 + RTMPZeroMemory(Protect, sizeof(Protect));
28322 + ProtCfg4.word = 0;
28323 + ProtCfg.word = 0;
28324 + ProtCfg.field.TxopAllowGF40 = 1;
28325 + ProtCfg.field.TxopAllowGF20 = 1;
28326 + ProtCfg.field.TxopAllowMM40 = 1;
28327 + ProtCfg.field.TxopAllowMM20 = 1;
28328 + ProtCfg.field.TxopAllowOfdm = 1;
28329 + ProtCfg.field.TxopAllowCck = 1;
28330 + ProtCfg.field.RTSThEn = 1;
28331 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28332 +
28333 + // update PHY mode and rate
28334 + if (pAd->CommonCfg.Channel > 14)
28335 + ProtCfg.field.ProtectRate = 0x4000;
28336 + ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate;
28337 +
28338 + // Handle legacy(B/G) protection
28339 + if (bDisableBGProtect)
28340 + {
28341 + //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
28342 + ProtCfg.field.ProtectCtrl = 0;
28343 + Protect[0] = ProtCfg.word;
28344 + Protect[1] = ProtCfg.word;
28345 + }
28346 + else
28347 + {
28348 + //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
28349 + ProtCfg.field.ProtectCtrl = 0; // CCK do not need to be protected
28350 + Protect[0] = ProtCfg.word;
28351 + ProtCfg.field.ProtectCtrl = ASIC_CTS; // OFDM needs using CCK to protect
28352 + Protect[1] = ProtCfg.word;
28353 + }
28354 +
28355 +#ifdef DOT11_N_SUPPORT
28356 + // Decide HT frame protection.
28357 + if ((SetMask & ALLN_SETPROTECT) != 0)
28358 + {
28359 + switch(OperationMode)
28360 + {
28361 + case 0x0:
28362 + // NO PROTECT
28363 + // 1.All STAs in the BSS are 20/40 MHz HT
28364 + // 2. in ai 20/40MHz BSS
28365 + // 3. all STAs are 20MHz in a 20MHz BSS
28366 + // Pure HT. no protection.
28367 +
28368 + // MM20_PROT_CFG
28369 + // Reserved (31:27)
28370 + // PROT_TXOP(25:20) -- 010111
28371 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28372 + // PROT_CTRL(17:16) -- 00 (None)
28373 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
28374 + Protect[2] = 0x01744004;
28375 +
28376 + // MM40_PROT_CFG
28377 + // Reserved (31:27)
28378 + // PROT_TXOP(25:20) -- 111111
28379 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28380 + // PROT_CTRL(17:16) -- 00 (None)
28381 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
28382 + Protect[3] = 0x03f44084;
28383 +
28384 + // CF20_PROT_CFG
28385 + // Reserved (31:27)
28386 + // PROT_TXOP(25:20) -- 010111
28387 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28388 + // PROT_CTRL(17:16) -- 00 (None)
28389 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
28390 + Protect[4] = 0x01744004;
28391 +
28392 + // CF40_PROT_CFG
28393 + // Reserved (31:27)
28394 + // PROT_TXOP(25:20) -- 111111
28395 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28396 + // PROT_CTRL(17:16) -- 00 (None)
28397 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
28398 + Protect[5] = 0x03f44084;
28399 +
28400 + if (bNonGFExist)
28401 + {
28402 + // PROT_NAV(19:18) -- 01 (Short NAV protectiion)
28403 + // PROT_CTRL(17:16) -- 01 (RTS/CTS)
28404 + Protect[4] = 0x01754004;
28405 + Protect[5] = 0x03f54084;
28406 + }
28407 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
28408 + break;
28409 +
28410 + case 1:
28411 + // This is "HT non-member protection mode."
28412 + // If there may be non-HT STAs my BSS
28413 + ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None)
28414 + ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1.
28415 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
28416 + {
28417 + ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18..
28418 + ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083;
28419 + }
28420 + //Assign Protection method for 20&40 MHz packets
28421 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28422 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28423 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28424 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28425 + Protect[2] = ProtCfg.word;
28426 + Protect[3] = ProtCfg4.word;
28427 + Protect[4] = ProtCfg.word;
28428 + Protect[5] = ProtCfg4.word;
28429 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28430 + break;
28431 +
28432 + case 2:
28433 + // If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets
28434 + ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None)
28435 + ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1.
28436 +
28437 + //Assign Protection method for 40MHz packets
28438 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28439 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28440 + Protect[2] = ProtCfg.word;
28441 + Protect[3] = ProtCfg4.word;
28442 + if (bNonGFExist)
28443 + {
28444 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28445 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28446 + }
28447 + Protect[4] = ProtCfg.word;
28448 + Protect[5] = ProtCfg4.word;
28449 +
28450 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
28451 + break;
28452 +
28453 + case 3:
28454 + // HT mixed mode. PROTECT ALL!
28455 + // Assign Rate
28456 + ProtCfg.word = 0x01744004; //duplicaet legacy 24M. BW set 1.
28457 + ProtCfg4.word = 0x03f44084;
28458 + // both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the
28459 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
28460 + {
28461 + ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18..
28462 + ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083
28463 + }
28464 + //Assign Protection method for 20&40 MHz packets
28465 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28466 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28467 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28468 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28469 + Protect[2] = ProtCfg.word;
28470 + Protect[3] = ProtCfg4.word;
28471 + Protect[4] = ProtCfg.word;
28472 + Protect[5] = ProtCfg4.word;
28473 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28474 + break;
28475 +
28476 + case 8:
28477 + // Special on for Atheros problem n chip.
28478 + Protect[2] = 0x01754004;
28479 + Protect[3] = 0x03f54084;
28480 + Protect[4] = 0x01754004;
28481 + Protect[5] = 0x03f54084;
28482 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28483 + break;
28484 + }
28485 + }
28486 +#endif // DOT11_N_SUPPORT //
28487 +
28488 + offset = CCK_PROT_CFG;
28489 + for (i = 0;i < 6;i++)
28490 + {
28491 + if ((SetMask & (1<< i)))
28492 + {
28493 + RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
28494 + }
28495 + }
28496 +}
28497 +
28498 +/*
28499 + ==========================================================================
28500 + Description:
28501 +
28502 + IRQL = PASSIVE_LEVEL
28503 + IRQL = DISPATCH_LEVEL
28504 +
28505 + ==========================================================================
28506 + */
28507 +VOID AsicSwitchChannel(
28508 + IN PRTMP_ADAPTER pAd,
28509 + IN UCHAR Channel,
28510 + IN BOOLEAN bScan)
28511 +{
28512 + ULONG R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0;
28513 + CHAR TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; //Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER;
28514 + UCHAR index;
28515 + UINT32 Value = 0; //BbpReg, Value;
28516 + RTMP_RF_REGS *RFRegTable;
28517 +
28518 + // Search Tx power value
28519 + for (index = 0; index < pAd->ChannelListNum; index++)
28520 + {
28521 + if (Channel == pAd->ChannelList[index].Channel)
28522 + {
28523 + TxPwer = pAd->ChannelList[index].Power;
28524 + TxPwer2 = pAd->ChannelList[index].Power2;
28525 + break;
28526 + }
28527 + }
28528 +
28529 + if (index == MAX_NUM_OF_CHANNELS)
28530 + {
28531 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Cant find the Channel#%d \n", Channel));
28532 + }
28533 +
28534 +#ifdef RT2870
28535 + // The RF programming sequence is difference between 3xxx and 2xxx
28536 + if (IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020)))
28537 + {
28538 + /* modify by WY for Read RF Reg. error */
28539 + UCHAR RFValue;
28540 +
28541 + for (index = 0; index < NUM_OF_3020_CHNL; index++)
28542 + {
28543 + if (Channel == FreqItems3020[index].Channel)
28544 + {
28545 + // Programming channel parameters
28546 + RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N);
28547 + RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K);
28548 +
28549 + RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue);
28550 + RFValue = (RFValue & 0xFC) | FreqItems3020[index].R;
28551 + RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue);
28552 +
28553 + // Set Tx Power
28554 + RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
28555 + RFValue = (RFValue & 0xE0) | TxPwer;
28556 + RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
28557 +
28558 + // Set RF offset
28559 + RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
28560 + RFValue = (RFValue & 0x80) | pAd->RfFreqOffset;
28561 + RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
28562 +
28563 + // Set BW
28564 + if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40))
28565 + {
28566 + RFValue = pAd->Mlme.CaliBW40RfR24;
28567 + //DISABLE_11N_CHECK(pAd);
28568 + }
28569 + else
28570 + {
28571 + RFValue = pAd->Mlme.CaliBW20RfR24;
28572 + }
28573 + RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue);
28574 +
28575 + // Enable RF tuning
28576 + RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue);
28577 + RFValue = RFValue | 0x1;
28578 + RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue);
28579 +
28580 + // latch channel for future usage.
28581 + pAd->LatchRfRegs.Channel = Channel;
28582 +
28583 + break;
28584 + }
28585 + }
28586 +
28587 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
28588 + Channel,
28589 + pAd->RfIcType,
28590 + TxPwer,
28591 + TxPwer2,
28592 + pAd->Antenna.field.TxPath,
28593 + FreqItems3020[index].N,
28594 + FreqItems3020[index].K,
28595 + FreqItems3020[index].R));
28596 + }
28597 + else
28598 +#endif // RT2870 //
28599 + {
28600 + RFRegTable = RF2850RegTable;
28601 +
28602 + switch (pAd->RfIcType)
28603 + {
28604 + case RFIC_2820:
28605 + case RFIC_2850:
28606 + case RFIC_2720:
28607 + case RFIC_2750:
28608 +
28609 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
28610 + {
28611 + if (Channel == RFRegTable[index].Channel)
28612 + {
28613 + R2 = RFRegTable[index].R2;
28614 + if (pAd->Antenna.field.TxPath == 1)
28615 + {
28616 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
28617 + }
28618 +
28619 + if (pAd->Antenna.field.RxPath == 2)
28620 + {
28621 + R2 |= 0x40; // write 1 to off Rxpath.
28622 + }
28623 + else if (pAd->Antenna.field.RxPath == 1)
28624 + {
28625 + R2 |= 0x20040; // write 1 to off RxPath
28626 + }
28627 +
28628 + if (Channel > 14)
28629 + {
28630 + // initialize R3, R4
28631 + R3 = (RFRegTable[index].R3 & 0xffffc1ff);
28632 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15);
28633 +
28634 + // 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
28635 + // R3
28636 + if ((TxPwer >= -7) && (TxPwer < 0))
28637 + {
28638 + TxPwer = (7+TxPwer);
28639 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
28640 + R3 |= (TxPwer << 10);
28641 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer=%d \n", TxPwer));
28642 + }
28643 + else
28644 + {
28645 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
28646 + R3 |= (TxPwer << 10) | (1 << 9);
28647 + }
28648 +
28649 + // R4
28650 + if ((TxPwer2 >= -7) && (TxPwer2 < 0))
28651 + {
28652 + TxPwer2 = (7+TxPwer2);
28653 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
28654 + R4 |= (TxPwer2 << 7);
28655 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
28656 + }
28657 + else
28658 + {
28659 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
28660 + R4 |= (TxPwer2 << 7) | (1 << 6);
28661 + }
28662 + }
28663 + else
28664 + {
28665 + R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
28666 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 <<6);// Set freq Offset & TxPwr1
28667 + }
28668 +
28669 + // Based on BBP current mode before changing RF channel.
28670 + if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40))
28671 + {
28672 + R4 |=0x200000;
28673 + }
28674 +
28675 + // Update variables
28676 + pAd->LatchRfRegs.Channel = Channel;
28677 + pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
28678 + pAd->LatchRfRegs.R2 = R2;
28679 + pAd->LatchRfRegs.R3 = R3;
28680 + pAd->LatchRfRegs.R4 = R4;
28681 +
28682 + // Set RF value 1's set R3[bit2] = [0]
28683 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
28684 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
28685 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
28686 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
28687 +
28688 + RTMPusecDelay(200);
28689 +
28690 + // Set RF value 2's set R3[bit2] = [1]
28691 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
28692 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
28693 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
28694 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
28695 +
28696 + RTMPusecDelay(200);
28697 +
28698 + // Set RF value 3's set R3[bit2] = [0]
28699 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
28700 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
28701 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
28702 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
28703 +
28704 + break;
28705 + }
28706 + }
28707 + break;
28708 +
28709 + default:
28710 + break;
28711 + }
28712 + }
28713 +
28714 + // Change BBP setting during siwtch from a->g, g->a
28715 + if (Channel <= 14)
28716 + {
28717 + ULONG TxPinCfg = 0x00050F0A;//Gary 2007/08/09 0x050A0A
28718 +
28719 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
28720 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
28721 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
28722 + 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.
28723 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
28724 +
28725 + // Rx High power VGA offset for LNA select
28726 + if (pAd->NicConfig2.field.ExternalLNAForG)
28727 + {
28728 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
28729 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
28730 + }
28731 + else
28732 + {
28733 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
28734 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
28735 + }
28736 +
28737 + // 5G band selection PIN, bit1 and bit2 are complement
28738 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
28739 + Value &= (~0x6);
28740 + Value |= (0x04);
28741 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
28742 +
28743 + // Turn off unused PA or LNA when only 1T or 1R
28744 + if (pAd->Antenna.field.TxPath == 1)
28745 + {
28746 + TxPinCfg &= 0xFFFFFFF3;
28747 + }
28748 + if (pAd->Antenna.field.RxPath == 1)
28749 + {
28750 + TxPinCfg &= 0xFFFFF3FF;
28751 + }
28752 +
28753 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
28754 + }
28755 + else
28756 + {
28757 + ULONG TxPinCfg = 0x00050F05;//Gary 2007/8/9 0x050505
28758 +
28759 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
28760 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
28761 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
28762 + 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.
28763 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
28764 +
28765 + // Rx High power VGA offset for LNA select
28766 + if (pAd->NicConfig2.field.ExternalLNAForA)
28767 + {
28768 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
28769 + }
28770 + else
28771 + {
28772 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
28773 + }
28774 +
28775 + // 5G band selection PIN, bit1 and bit2 are complement
28776 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
28777 + Value &= (~0x6);
28778 + Value |= (0x02);
28779 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
28780 +
28781 + // Turn off unused PA or LNA when only 1T or 1R
28782 + if (pAd->Antenna.field.TxPath == 1)
28783 + {
28784 + TxPinCfg &= 0xFFFFFFF3;
28785 + }
28786 + if (pAd->Antenna.field.RxPath == 1)
28787 + {
28788 + TxPinCfg &= 0xFFFFF3FF;
28789 + }
28790 +
28791 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
28792 + }
28793 +
28794 + // R66 should be set according to Channel and use 20MHz when scanning
28795 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd)));
28796 + if (bScan)
28797 + RTMPSetAGCInitValue(pAd, BW_20);
28798 + else
28799 + RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
28800 +
28801 + //
28802 + // On 11A, We should delay and wait RF/BBP to be stable
28803 + // and the appropriate time should be 1000 micro seconds
28804 + // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
28805 + //
28806 + RTMPusecDelay(1000);
28807 +
28808 + 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",
28809 + Channel,
28810 + pAd->RfIcType,
28811 + (R3 & 0x00003e00) >> 9,
28812 + (R4 & 0x000007c0) >> 6,
28813 + pAd->Antenna.field.TxPath,
28814 + pAd->LatchRfRegs.R1,
28815 + pAd->LatchRfRegs.R2,
28816 + pAd->LatchRfRegs.R3,
28817 + pAd->LatchRfRegs.R4));
28818 +}
28819 +
28820 +/*
28821 + ==========================================================================
28822 + Description:
28823 + This function is required for 2421 only, and should not be used during
28824 + site survey. It's only required after NIC decided to stay at a channel
28825 + for a longer period.
28826 + When this function is called, it's always after AsicSwitchChannel().
28827 +
28828 + IRQL = PASSIVE_LEVEL
28829 + IRQL = DISPATCH_LEVEL
28830 +
28831 + ==========================================================================
28832 + */
28833 +VOID AsicLockChannel(
28834 + IN PRTMP_ADAPTER pAd,
28835 + IN UCHAR Channel)
28836 +{
28837 +}
28838 +
28839 +/*
28840 + ==========================================================================
28841 + Description:
28842 +
28843 + IRQL = PASSIVE_LEVEL
28844 + IRQL = DISPATCH_LEVEL
28845 +
28846 + ==========================================================================
28847 + */
28848 +VOID AsicAntennaSelect(
28849 + IN PRTMP_ADAPTER pAd,
28850 + IN UCHAR Channel)
28851 +{
28852 +}
28853 +
28854 +/*
28855 + ========================================================================
28856 +
28857 + Routine Description:
28858 + Antenna miscellaneous setting.
28859 +
28860 + Arguments:
28861 + pAd Pointer to our adapter
28862 + BandState Indicate current Band State.
28863 +
28864 + Return Value:
28865 + None
28866 +
28867 + IRQL <= DISPATCH_LEVEL
28868 +
28869 + Note:
28870 + 1.) Frame End type control
28871 + only valid for G only (RF_2527 & RF_2529)
28872 + 0: means DPDT, set BBP R4 bit 5 to 1
28873 + 1: means SPDT, set BBP R4 bit 5 to 0
28874 +
28875 +
28876 + ========================================================================
28877 +*/
28878 +VOID AsicAntennaSetting(
28879 + IN PRTMP_ADAPTER pAd,
28880 + IN ABGBAND_STATE BandState)
28881 +{
28882 +}
28883 +
28884 +VOID AsicRfTuningExec(
28885 + IN PVOID SystemSpecific1,
28886 + IN PVOID FunctionContext,
28887 + IN PVOID SystemSpecific2,
28888 + IN PVOID SystemSpecific3)
28889 +{
28890 +}
28891 +
28892 +/*
28893 + ==========================================================================
28894 + Description:
28895 + Gives CCK TX rate 2 more dB TX power.
28896 + This routine works only in LINK UP in INFRASTRUCTURE mode.
28897 +
28898 + calculate desired Tx power in RF R3.Tx0~5, should consider -
28899 + 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
28900 + 1. TxPowerPercentage
28901 + 2. auto calibration based on TSSI feedback
28902 + 3. extra 2 db for CCK
28903 + 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
28904 +
28905 + NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
28906 + it should be called AFTER MlmeDynamicTxRatSwitching()
28907 + ==========================================================================
28908 + */
28909 +VOID AsicAdjustTxPower(
28910 + IN PRTMP_ADAPTER pAd)
28911 +{
28912 + INT i, j;
28913 + CHAR DeltaPwr = 0;
28914 + BOOLEAN bAutoTxAgc = FALSE;
28915 + UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
28916 + UCHAR BbpR1 = 0, BbpR49 = 0, idx;
28917 + PCHAR pTxAgcCompensate;
28918 + ULONG TxPwr[5];
28919 + CHAR Value;
28920 +
28921 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
28922 + {
28923 + if (pAd->CommonCfg.CentralChannel > 14)
28924 + {
28925 + TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
28926 + TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
28927 + TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
28928 + TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
28929 + TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
28930 + }
28931 + else
28932 + {
28933 + TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
28934 + TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
28935 + TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
28936 + TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
28937 + TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
28938 + }
28939 + }
28940 + else
28941 + {
28942 + if (pAd->CommonCfg.Channel > 14)
28943 + {
28944 + TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
28945 + TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
28946 + TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
28947 + TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
28948 + TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
28949 + }
28950 + else
28951 + {
28952 + TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
28953 + TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
28954 + TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
28955 + TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
28956 + TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
28957 + }
28958 + }
28959 +
28960 + // TX power compensation for temperature variation based on TSSI. try every 4 second
28961 + if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
28962 + {
28963 + if (pAd->CommonCfg.Channel <= 14)
28964 + {
28965 + /* bg channel */
28966 + bAutoTxAgc = pAd->bAutoTxAgcG;
28967 + TssiRef = pAd->TssiRefG;
28968 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
28969 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
28970 + TxAgcStep = pAd->TxAgcStepG;
28971 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
28972 + }
28973 + else
28974 + {
28975 + /* a channel */
28976 + bAutoTxAgc = pAd->bAutoTxAgcA;
28977 + TssiRef = pAd->TssiRefA;
28978 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
28979 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
28980 + TxAgcStep = pAd->TxAgcStepA;
28981 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
28982 + }
28983 +
28984 + if (bAutoTxAgc)
28985 + {
28986 + /* BbpR1 is unsigned char */
28987 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
28988 +
28989 + /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
28990 + /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
28991 + /* step value is defined in pAd->TxAgcStepG for tx power value */
28992 +
28993 + /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
28994 + /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
28995 + above value are examined in mass factory production */
28996 + /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
28997 +
28998 + /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */
28999 + /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
29000 + /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */
29001 +
29002 + if (BbpR49 > pTssiMinusBoundary[1])
29003 + {
29004 + // Reading is larger than the reference value
29005 + // check for how large we need to decrease the Tx power
29006 + for (idx = 1; idx < 5; idx++)
29007 + {
29008 + if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
29009 + break;
29010 + }
29011 + // The index is the step we should decrease, idx = 0 means there is nothing to compensate
29012 +// if (R3 > (ULONG) (TxAgcStep * (idx-1)))
29013 + *pTxAgcCompensate = -(TxAgcStep * (idx-1));
29014 +// else
29015 +// *pTxAgcCompensate = -((UCHAR)R3);
29016 +
29017 + DeltaPwr += (*pTxAgcCompensate);
29018 + DBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
29019 + BbpR49, TssiRef, TxAgcStep, idx-1));
29020 + }
29021 + else if (BbpR49 < pTssiPlusBoundary[1])
29022 + {
29023 + // Reading is smaller than the reference value
29024 + // check for how large we need to increase the Tx power
29025 + for (idx = 1; idx < 5; idx++)
29026 + {
29027 + if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
29028 + break;
29029 + }
29030 + // The index is the step we should increase, idx = 0 means there is nothing to compensate
29031 + *pTxAgcCompensate = TxAgcStep * (idx-1);
29032 + DeltaPwr += (*pTxAgcCompensate);
29033 + DBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
29034 + BbpR49, TssiRef, TxAgcStep, idx-1));
29035 + }
29036 + else
29037 + {
29038 + *pTxAgcCompensate = 0;
29039 + DBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
29040 + BbpR49, TssiRef, TxAgcStep, 0));
29041 + }
29042 + }
29043 + }
29044 + else
29045 + {
29046 + if (pAd->CommonCfg.Channel <= 14)
29047 + {
29048 + bAutoTxAgc = pAd->bAutoTxAgcG;
29049 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
29050 + }
29051 + else
29052 + {
29053 + bAutoTxAgc = pAd->bAutoTxAgcA;
29054 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
29055 + }
29056 +
29057 + if (bAutoTxAgc)
29058 + DeltaPwr += (*pTxAgcCompensate);
29059 + }
29060 +
29061 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1);
29062 + BbpR1 &= 0xFC;
29063 +
29064 +#ifdef SINGLE_SKU
29065 + // Handle regulatory max tx power constrain
29066 + do
29067 + {
29068 + UCHAR TxPwrInEEPROM = 0xFF, CountryTxPwr = 0xFF, criterion;
29069 + UCHAR AdjustMaxTxPwr[40];
29070 +
29071 + if (pAd->CommonCfg.Channel > 14) // 5G band
29072 + TxPwrInEEPROM = ((pAd->CommonCfg.DefineMaxTxPwr & 0xFF00) >> 8);
29073 + else // 2.4G band
29074 + TxPwrInEEPROM = (pAd->CommonCfg.DefineMaxTxPwr & 0x00FF);
29075 + CountryTxPwr = GetCuntryMaxTxPwr(pAd, pAd->CommonCfg.Channel);
29076 +
29077 + // error handling, range check
29078 + if ((TxPwrInEEPROM > 0x50) || (CountryTxPwr > 0x50))
29079 + {
29080 + DBGPRINT(RT_DEBUG_ERROR,("AsicAdjustTxPower - Invalid max tx power (=0x%02x), CountryTxPwr=%d\n", TxPwrInEEPROM, CountryTxPwr));
29081 + break;
29082 + }
29083 +
29084 + criterion = *((PUCHAR)TxPwr + 2) & 0xF; // FAE use OFDM 6M as criterion
29085 +
29086 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (criterion=%d, TxPwrInEEPROM=%d, CountryTxPwr=%d)\n", criterion, TxPwrInEEPROM, CountryTxPwr));
29087 +
29088 + // Adjust max tx power according to the relationship of tx power in E2PROM
29089 + for (i=0; i<5; i++)
29090 + {
29091 + // CCK will have 4dBm larger than OFDM
29092 + // Therefore, we should separate to parse the tx power field
29093 + if (i == 0)
29094 + {
29095 + for (j=0; j<8; j++)
29096 + {
29097 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29098 +
29099 + if (j < 4)
29100 + {
29101 + // CCK will have 4dBm larger than OFDM
29102 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion) + 4;
29103 + }
29104 + else
29105 + {
29106 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion);
29107 + }
29108 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29109 + }
29110 + }
29111 + else
29112 + {
29113 + for (j=0; j<8; j++)
29114 + {
29115 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29116 +
29117 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion);
29118 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29119 + }
29120 + }
29121 + }
29122 +
29123 + // Adjust tx power according to the relationship
29124 + for (i=0; i<5; i++)
29125 + {
29126 + if (TxPwr[i] != 0xffffffff)
29127 + {
29128 + for (j=0; j<8; j++)
29129 + {
29130 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29131 +
29132 + // The system tx power is larger than the regulatory, the power should be restrain
29133 + if (AdjustMaxTxPwr[i*8+j] > CountryTxPwr)
29134 + {
29135 + // decrease to zero and don't need to take care BBPR1
29136 + if ((Value - (AdjustMaxTxPwr[i*8+j] - CountryTxPwr)) > 0)
29137 + Value -= (AdjustMaxTxPwr[i*8+j] - CountryTxPwr);
29138 + else
29139 + Value = 0;
29140 +
29141 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29142 + }
29143 + else
29144 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d, no change)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29145 +
29146 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
29147 + }
29148 + }
29149 + }
29150 + } while (FALSE);
29151 +#endif // SINGLE_SKU //
29152 +
29153 + /* calculate delta power based on the percentage specified from UI */
29154 + // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
29155 + // We lower TX power here according to the percentage specified from UI
29156 + if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
29157 + ;
29158 + else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
29159 + ;
29160 + else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1;
29161 + {
29162 + DeltaPwr -= 1;
29163 + }
29164 + else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3;
29165 + {
29166 + DeltaPwr -= 3;
29167 + }
29168 + else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6;
29169 + {
29170 + BbpR1 |= 0x01;
29171 + }
29172 + else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9;
29173 + {
29174 + BbpR1 |= 0x01;
29175 + DeltaPwr -= 3;
29176 + }
29177 + else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12;
29178 + {
29179 + BbpR1 |= 0x02;
29180 + }
29181 +
29182 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1);
29183 +
29184 + /* reset different new tx power for different TX rate */
29185 + for(i=0; i<5; i++)
29186 + {
29187 + if (TxPwr[i] != 0xffffffff)
29188 + {
29189 + for (j=0; j<8; j++)
29190 + {
29191 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
29192 +
29193 + if ((Value + DeltaPwr) < 0)
29194 + {
29195 + Value = 0; /* min */
29196 + }
29197 + else if ((Value + DeltaPwr) > 0xF)
29198 + {
29199 + Value = 0xF; /* max */
29200 + }
29201 + else
29202 + {
29203 + Value += DeltaPwr; /* temperature compensation */
29204 + }
29205 +
29206 + /* fill new value to CSR offset */
29207 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
29208 + }
29209 +
29210 + /* write tx power value to CSR */
29211 + /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
29212 + TX power for OFDM 6M/9M
29213 + TX power for CCK5.5M/11M
29214 + TX power for CCK1M/2M */
29215 + /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
29216 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
29217 + }
29218 + }
29219 +
29220 +}
29221 +
29222 +#ifdef CONFIG_STA_SUPPORT
29223 +/*
29224 + ==========================================================================
29225 + Description:
29226 + put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup
29227 + automatically. Instead, MCU will issue a TwakeUpInterrupt to host after
29228 + the wakeup timer timeout. Driver has to issue a separate command to wake
29229 + PHY up.
29230 +
29231 + IRQL = DISPATCH_LEVEL
29232 +
29233 + ==========================================================================
29234 + */
29235 +VOID AsicSleepThenAutoWakeup(
29236 + IN PRTMP_ADAPTER pAd,
29237 + IN USHORT TbttNumToNextWakeUp)
29238 +{
29239 + RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp);
29240 +}
29241 +
29242 +/*
29243 + ==========================================================================
29244 + Description:
29245 + AsicForceWakeup() is used whenever manual wakeup is required
29246 + AsicForceSleep() should only be used when not in INFRA BSS. When
29247 + in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead.
29248 + ==========================================================================
29249 + */
29250 +VOID AsicForceSleep(
29251 + IN PRTMP_ADAPTER pAd)
29252 +{
29253 +
29254 +}
29255 +
29256 +/*
29257 + ==========================================================================
29258 + Description:
29259 + AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup)
29260 + expired.
29261 +
29262 + IRQL = PASSIVE_LEVEL
29263 + IRQL = DISPATCH_LEVEL
29264 + ==========================================================================
29265 + */
29266 +VOID AsicForceWakeup(
29267 + IN PRTMP_ADAPTER pAd,
29268 + IN BOOLEAN bFromTx)
29269 +{
29270 + DBGPRINT(RT_DEBUG_TRACE, ("--> AsicForceWakeup \n"));
29271 + RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx);
29272 +}
29273 +#endif // CONFIG_STA_SUPPORT //
29274 +/*
29275 + ==========================================================================
29276 + Description:
29277 + Set My BSSID
29278 +
29279 + IRQL = DISPATCH_LEVEL
29280 +
29281 + ==========================================================================
29282 + */
29283 +VOID AsicSetBssid(
29284 + IN PRTMP_ADAPTER pAd,
29285 + IN PUCHAR pBssid)
29286 +{
29287 + ULONG Addr4;
29288 + DBGPRINT(RT_DEBUG_TRACE, ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n",
29289 + pBssid[0],pBssid[1],pBssid[2],pBssid[3], pBssid[4],pBssid[5]));
29290 +
29291 + Addr4 = (ULONG)(pBssid[0]) |
29292 + (ULONG)(pBssid[1] << 8) |
29293 + (ULONG)(pBssid[2] << 16) |
29294 + (ULONG)(pBssid[3] << 24);
29295 + RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4);
29296 +
29297 + Addr4 = 0;
29298 + // always one BSSID in STA mode
29299 + Addr4 = (ULONG)(pBssid[4]) | (ULONG)(pBssid[5] << 8);
29300 +
29301 + RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4);
29302 +}
29303 +
29304 +VOID AsicSetMcastWC(
29305 + IN PRTMP_ADAPTER pAd)
29306 +{
29307 + MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[MCAST_WCID];
29308 + USHORT offset;
29309 +
29310 + pEntry->Sst = SST_ASSOC;
29311 + pEntry->Aid = MCAST_WCID; // Softap supports 1 BSSID and use WCID=0 as multicast Wcid index
29312 + pEntry->PsMode = PWR_ACTIVE;
29313 + pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate;
29314 + offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE;
29315 +}
29316 +
29317 +/*
29318 + ==========================================================================
29319 + Description:
29320 +
29321 + IRQL = DISPATCH_LEVEL
29322 +
29323 + ==========================================================================
29324 + */
29325 +VOID AsicDelWcidTab(
29326 + IN PRTMP_ADAPTER pAd,
29327 + IN UCHAR Wcid)
29328 +{
29329 + ULONG Addr0 = 0x0, Addr1 = 0x0;
29330 + ULONG offset;
29331 +
29332 + DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n",Wcid));
29333 + offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE;
29334 + RTMP_IO_WRITE32(pAd, offset, Addr0);
29335 + offset += 4;
29336 + RTMP_IO_WRITE32(pAd, offset, Addr1);
29337 +}
29338 +
29339 +/*
29340 + ==========================================================================
29341 + Description:
29342 +
29343 + IRQL = DISPATCH_LEVEL
29344 +
29345 + ==========================================================================
29346 + */
29347 +VOID AsicEnableRDG(
29348 + IN PRTMP_ADAPTER pAd)
29349 +{
29350 + TX_LINK_CFG_STRUC TxLinkCfg;
29351 + UINT32 Data = 0;
29352 +
29353 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
29354 + TxLinkCfg.field.TxRDGEn = 1;
29355 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
29356 +
29357 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
29358 + Data &= 0xFFFFFF00;
29359 + Data |= 0x80;
29360 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
29361 +
29362 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
29363 +}
29364 +
29365 +/*
29366 + ==========================================================================
29367 + Description:
29368 +
29369 + IRQL = DISPATCH_LEVEL
29370 +
29371 + ==========================================================================
29372 + */
29373 +VOID AsicDisableRDG(
29374 + IN PRTMP_ADAPTER pAd)
29375 +{
29376 + TX_LINK_CFG_STRUC TxLinkCfg;
29377 + UINT32 Data = 0;
29378 +
29379 +
29380 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
29381 + TxLinkCfg.field.TxRDGEn = 0;
29382 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
29383 +
29384 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
29385 +
29386 + Data &= 0xFFFFFF00;
29387 + //Data |= 0x20;
29388 +#ifndef WIFI_TEST
29389 + //if ( pAd->CommonCfg.bEnableTxBurst )
29390 + // Data |= 0x60; // for performance issue not set the TXOP to 0
29391 +#endif
29392 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE)
29393 +#ifdef DOT11_N_SUPPORT
29394 + && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE)
29395 +#endif // DOT11_N_SUPPORT //
29396 + )
29397 + {
29398 + // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode
29399 + if (pAd->CommonCfg.bEnableTxBurst)
29400 + Data |= 0x20;
29401 + }
29402 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
29403 +}
29404 +
29405 +/*
29406 + ==========================================================================
29407 + Description:
29408 +
29409 + IRQL = PASSIVE_LEVEL
29410 + IRQL = DISPATCH_LEVEL
29411 +
29412 + ==========================================================================
29413 + */
29414 +VOID AsicDisableSync(
29415 + IN PRTMP_ADAPTER pAd)
29416 +{
29417 + BCN_TIME_CFG_STRUC csr;
29418 +
29419 + DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n"));
29420 +
29421 + // 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect
29422 + // that NIC will never wakes up because TSF stops and no more
29423 + // TBTT interrupts
29424 + pAd->TbttTickCount = 0;
29425 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
29426 + csr.field.bBeaconGen = 0;
29427 + csr.field.bTBTTEnable = 0;
29428 + csr.field.TsfSyncMode = 0;
29429 + csr.field.bTsfTicking = 0;
29430 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
29431 +
29432 +}
29433 +
29434 +/*
29435 + ==========================================================================
29436 + Description:
29437 +
29438 + IRQL = DISPATCH_LEVEL
29439 +
29440 + ==========================================================================
29441 + */
29442 +VOID AsicEnableBssSync(
29443 + IN PRTMP_ADAPTER pAd)
29444 +{
29445 + BCN_TIME_CFG_STRUC csr;
29446 +
29447 + DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n"));
29448 +
29449 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
29450 +// RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, 0x00000000);
29451 +#ifdef CONFIG_STA_SUPPORT
29452 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29453 + {
29454 + csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU
29455 + csr.field.bTsfTicking = 1;
29456 + csr.field.TsfSyncMode = 1; // sync TSF in INFRASTRUCTURE mode
29457 + csr.field.bBeaconGen = 0; // do NOT generate BEACON
29458 + csr.field.bTBTTEnable = 1;
29459 + }
29460 +#endif // CONFIG_STA_SUPPORT //
29461 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
29462 +}
29463 +
29464 +/*
29465 + ==========================================================================
29466 + Description:
29467 + Note:
29468 + BEACON frame in shared memory should be built ok before this routine
29469 + can be called. Otherwise, a garbage frame maybe transmitted out every
29470 + Beacon period.
29471 +
29472 + IRQL = DISPATCH_LEVEL
29473 +
29474 + ==========================================================================
29475 + */
29476 +VOID AsicEnableIbssSync(
29477 + IN PRTMP_ADAPTER pAd)
29478 +{
29479 + BCN_TIME_CFG_STRUC csr9;
29480 + PUCHAR ptr;
29481 + UINT i;
29482 +
29483 + DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n", pAd->BeaconTxWI.MPDUtotalByteCount));
29484 +
29485 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word);
29486 + csr9.field.bBeaconGen = 0;
29487 + csr9.field.bTBTTEnable = 0;
29488 + csr9.field.bTsfTicking = 0;
29489 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
29490 +
29491 +
29492 +#ifdef RT2870
29493 + // move BEACON TXD and frame content to on-chip memory
29494 + ptr = (PUCHAR)&pAd->BeaconTxWI;
29495 + for (i=0; i<TXWI_SIZE; i+=2) // 16-byte TXWI field
29496 + {
29497 + //UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
29498 + //RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr);
29499 + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2);
29500 + ptr += 2;
29501 + }
29502 +
29503 + // start right after the 16-byte TXWI field
29504 + ptr = pAd->BeaconBuf;
29505 + for (i=0; i< pAd->BeaconTxWI.MPDUtotalByteCount; i+=2)
29506 + {
29507 + //UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
29508 + //RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr);
29509 + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2);
29510 + ptr +=2;
29511 + }
29512 +#endif // RT2870 //
29513 +
29514 + //
29515 + // For Wi-Fi faily generated beacons between participating stations.
29516 + // Set TBTT phase adaptive adjustment step to 8us (default 16us)
29517 + // don't change settings 2006-5- by Jerry
29518 + //RTMP_IO_WRITE32(pAd, TBTT_SYNC_CFG, 0x00001010);
29519 +
29520 + // start sending BEACON
29521 + csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU
29522 + csr9.field.bTsfTicking = 1;
29523 + csr9.field.TsfSyncMode = 2; // sync TSF in IBSS mode
29524 + csr9.field.bTBTTEnable = 1;
29525 + csr9.field.bBeaconGen = 1;
29526 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
29527 +}
29528 +
29529 +/*
29530 + ==========================================================================
29531 + Description:
29532 +
29533 + IRQL = PASSIVE_LEVEL
29534 + IRQL = DISPATCH_LEVEL
29535 +
29536 + ==========================================================================
29537 + */
29538 +VOID AsicSetEdcaParm(
29539 + IN PRTMP_ADAPTER pAd,
29540 + IN PEDCA_PARM pEdcaParm)
29541 +{
29542 + EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg;
29543 + AC_TXOP_CSR0_STRUC csr0;
29544 + AC_TXOP_CSR1_STRUC csr1;
29545 + AIFSN_CSR_STRUC AifsnCsr;
29546 + CWMIN_CSR_STRUC CwminCsr;
29547 + CWMAX_CSR_STRUC CwmaxCsr;
29548 + int i;
29549 +
29550 + Ac0Cfg.word = 0;
29551 + Ac1Cfg.word = 0;
29552 + Ac2Cfg.word = 0;
29553 + Ac3Cfg.word = 0;
29554 + if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE))
29555 + {
29556 + DBGPRINT(RT_DEBUG_TRACE,("AsicSetEdcaParm\n"));
29557 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED);
29558 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
29559 + {
29560 + if (pAd->MacTab.Content[i].ValidAsCLI || pAd->MacTab.Content[i].ValidAsApCli)
29561 + CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[i], fCLIENT_STATUS_WMM_CAPABLE);
29562 + }
29563 +
29564 + //========================================================
29565 + // MAC Register has a copy .
29566 + //========================================================
29567 +//#ifndef WIFI_TEST
29568 + if( pAd->CommonCfg.bEnableTxBurst )
29569 + {
29570 + // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode
29571 + Ac0Cfg.field.AcTxop = 0x20; // Suggest by John for TxBurst in HT Mode
29572 + }
29573 + else
29574 + Ac0Cfg.field.AcTxop = 0; // QID_AC_BE
29575 +//#else
29576 +// Ac0Cfg.field.AcTxop = 0; // QID_AC_BE
29577 +//#endif
29578 + Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS;
29579 + Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS;
29580 + Ac0Cfg.field.Aifsn = 2;
29581 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
29582 +
29583 + Ac1Cfg.field.AcTxop = 0; // QID_AC_BK
29584 + Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS;
29585 + Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS;
29586 + Ac1Cfg.field.Aifsn = 2;
29587 + RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
29588 +
29589 + if (pAd->CommonCfg.PhyMode == PHY_11B)
29590 + {
29591 + Ac2Cfg.field.AcTxop = 192; // AC_VI: 192*32us ~= 6ms
29592 + Ac3Cfg.field.AcTxop = 96; // AC_VO: 96*32us ~= 3ms
29593 + }
29594 + else
29595 + {
29596 + Ac2Cfg.field.AcTxop = 96; // AC_VI: 96*32us ~= 3ms
29597 + Ac3Cfg.field.AcTxop = 48; // AC_VO: 48*32us ~= 1.5ms
29598 + }
29599 + Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS;
29600 + Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS;
29601 + Ac2Cfg.field.Aifsn = 2;
29602 + RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
29603 + Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS;
29604 + Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS;
29605 + Ac3Cfg.field.Aifsn = 2;
29606 + RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
29607 +
29608 + //========================================================
29609 + // DMA Register has a copy too.
29610 + //========================================================
29611 + csr0.field.Ac0Txop = 0; // QID_AC_BE
29612 + csr0.field.Ac1Txop = 0; // QID_AC_BK
29613 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
29614 + if (pAd->CommonCfg.PhyMode == PHY_11B)
29615 + {
29616 + csr1.field.Ac2Txop = 192; // AC_VI: 192*32us ~= 6ms
29617 + csr1.field.Ac3Txop = 96; // AC_VO: 96*32us ~= 3ms
29618 + }
29619 + else
29620 + {
29621 + csr1.field.Ac2Txop = 96; // AC_VI: 96*32us ~= 3ms
29622 + csr1.field.Ac3Txop = 48; // AC_VO: 48*32us ~= 1.5ms
29623 + }
29624 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
29625 +
29626 + CwminCsr.word = 0;
29627 + CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS;
29628 + CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS;
29629 + CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS;
29630 + CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS;
29631 + RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
29632 +
29633 + CwmaxCsr.word = 0;
29634 + CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS;
29635 + CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS;
29636 + CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS;
29637 + CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS;
29638 + RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
29639 +
29640 + RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222);
29641 +
29642 + NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(EDCA_PARM));
29643 + }
29644 + else
29645 + {
29646 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED);
29647 + //========================================================
29648 + // MAC Register has a copy.
29649 + //========================================================
29650 + //
29651 + // Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27
29652 + // To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue.
29653 + //
29654 + //pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this
29655 +
29656 + Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE];
29657 + Ac0Cfg.field.Cwmin= pEdcaParm->Cwmin[QID_AC_BE];
29658 + Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE];
29659 + Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; //+1;
29660 +
29661 + Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
29662 + Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; //+2;
29663 + Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK];
29664 + Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; //+1;
29665 +
29666 + Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10;
29667 + Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI];
29668 + Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI];
29669 + Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI];
29670 +#ifdef CONFIG_STA_SUPPORT
29671 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29672 + {
29673 + // Tuning for Wi-Fi WMM S06
29674 + if (pAd->CommonCfg.bWiFiTest &&
29675 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
29676 + Ac2Cfg.field.Aifsn -= 1;
29677 +
29678 + // Tuning for TGn Wi-Fi 5.2.32
29679 + // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta
29680 + if (STA_TGN_WIFI_ON(pAd) &&
29681 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
29682 + {
29683 + Ac0Cfg.field.Aifsn = 3;
29684 + Ac2Cfg.field.AcTxop = 5;
29685 + }
29686 + }
29687 +#endif // CONFIG_STA_SUPPORT //
29688 +
29689 + Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO];
29690 + Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO];
29691 + Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO];
29692 + Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO];
29693 +
29694 +//#ifdef WIFI_TEST
29695 + if (pAd->CommonCfg.bWiFiTest)
29696 + {
29697 + if (Ac3Cfg.field.AcTxop == 102)
29698 + {
29699 + Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm->Txop[QID_AC_BE] : 10;
29700 + Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]-1; /* AIFSN must >= 1 */
29701 + Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
29702 + Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK];
29703 + Ac2Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VI];
29704 + } /* End of if */
29705 + }
29706 +//#endif // WIFI_TEST //
29707 +
29708 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
29709 + RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
29710 + RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
29711 + RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
29712 +
29713 +
29714 + //========================================================
29715 + // DMA Register has a copy too.
29716 + //========================================================
29717 + csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop;
29718 + csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop;
29719 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
29720 +
29721 + csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop;
29722 + csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop;
29723 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
29724 +
29725 + CwminCsr.word = 0;
29726 + CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE];
29727 + CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK];
29728 + CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI];
29729 +#ifdef CONFIG_STA_SUPPORT
29730 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29731 + CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; //for TGn wifi test
29732 +#endif // CONFIG_STA_SUPPORT //
29733 + RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
29734 +
29735 + CwmaxCsr.word = 0;
29736 + CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE];
29737 + CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK];
29738 + CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI];
29739 + CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO];
29740 + RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
29741 +
29742 + AifsnCsr.word = 0;
29743 + AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BE];
29744 + AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BK];
29745 + AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_VI];
29746 +#ifdef CONFIG_STA_SUPPORT
29747 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29748 + {
29749 + // Tuning for Wi-Fi WMM S06
29750 + if (pAd->CommonCfg.bWiFiTest &&
29751 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
29752 + AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4;
29753 +
29754 + // Tuning for TGn Wi-Fi 5.2.32
29755 + // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta
29756 + if (STA_TGN_WIFI_ON(pAd) &&
29757 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
29758 + {
29759 + AifsnCsr.field.Aifsn0 = 3;
29760 + AifsnCsr.field.Aifsn2 = 7;
29761 + }
29762 +
29763 + if (INFRA_ON(pAd))
29764 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_WMM_CAPABLE);
29765 + }
29766 +#endif // CONFIG_STA_SUPPORT //
29767 +
29768 +#ifdef CONFIG_STA_SUPPORT
29769 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29770 + AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; //pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test
29771 +#endif // CONFIG_STA_SUPPORT //
29772 + RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word);
29773 +
29774 + NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM));
29775 + if (!ADHOC_ON(pAd))
29776 + {
29777 + DBGPRINT(RT_DEBUG_TRACE,("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n", pEdcaParm->EdcaUpdateCount));
29778 + DBGPRINT(RT_DEBUG_TRACE,(" AC_BE %2d %2d %2d %4d %d\n",
29779 + pEdcaParm->Aifsn[0],
29780 + pEdcaParm->Cwmin[0],
29781 + pEdcaParm->Cwmax[0],
29782 + pEdcaParm->Txop[0]<<5,
29783 + pEdcaParm->bACM[0]));
29784 + DBGPRINT(RT_DEBUG_TRACE,(" AC_BK %2d %2d %2d %4d %d\n",
29785 + pEdcaParm->Aifsn[1],
29786 + pEdcaParm->Cwmin[1],
29787 + pEdcaParm->Cwmax[1],
29788 + pEdcaParm->Txop[1]<<5,
29789 + pEdcaParm->bACM[1]));
29790 + DBGPRINT(RT_DEBUG_TRACE,(" AC_VI %2d %2d %2d %4d %d\n",
29791 + pEdcaParm->Aifsn[2],
29792 + pEdcaParm->Cwmin[2],
29793 + pEdcaParm->Cwmax[2],
29794 + pEdcaParm->Txop[2]<<5,
29795 + pEdcaParm->bACM[2]));
29796 + DBGPRINT(RT_DEBUG_TRACE,(" AC_VO %2d %2d %2d %4d %d\n",
29797 + pEdcaParm->Aifsn[3],
29798 + pEdcaParm->Cwmin[3],
29799 + pEdcaParm->Cwmax[3],
29800 + pEdcaParm->Txop[3]<<5,
29801 + pEdcaParm->bACM[3]));
29802 + }
29803 + }
29804 +}
29805 +
29806 +/*
29807 + ==========================================================================
29808 + Description:
29809 +
29810 + IRQL = PASSIVE_LEVEL
29811 + IRQL = DISPATCH_LEVEL
29812 +
29813 + ==========================================================================
29814 + */
29815 +VOID AsicSetSlotTime(
29816 + IN PRTMP_ADAPTER pAd,
29817 + IN BOOLEAN bUseShortSlotTime)
29818 +{
29819 + ULONG SlotTime;
29820 + UINT32 RegValue = 0;
29821 +
29822 +#ifdef CONFIG_STA_SUPPORT
29823 + if (pAd->CommonCfg.Channel > 14)
29824 + bUseShortSlotTime = TRUE;
29825 +#endif // CONFIG_STA_SUPPORT //
29826 +
29827 + if (bUseShortSlotTime)
29828 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
29829 + else
29830 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
29831 +
29832 + SlotTime = (bUseShortSlotTime)? 9 : 20;
29833 +
29834 +#ifdef CONFIG_STA_SUPPORT
29835 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29836 + {
29837 + // force using short SLOT time for FAE to demo performance when TxBurst is ON
29838 + if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
29839 +#ifdef DOT11_N_SUPPORT
29840 + || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE))
29841 +#endif // DOT11_N_SUPPORT //
29842 + )
29843 + {
29844 + // In this case, we will think it is doing Wi-Fi test
29845 + // And we will not set to short slot when bEnableTxBurst is TRUE.
29846 + }
29847 + else if (pAd->CommonCfg.bEnableTxBurst)
29848 + SlotTime = 9;
29849 + }
29850 +#endif // CONFIG_STA_SUPPORT //
29851 +
29852 + //
29853 + // For some reasons, always set it to short slot time.
29854 + //
29855 + // ToDo: Should consider capability with 11B
29856 + //
29857 +#ifdef CONFIG_STA_SUPPORT
29858 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
29859 + {
29860 + if (pAd->StaCfg.BssType == BSS_ADHOC)
29861 + SlotTime = 20;
29862 + }
29863 +#endif // CONFIG_STA_SUPPORT //
29864 +
29865 + RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue);
29866 + RegValue = RegValue & 0xFFFFFF00;
29867 +
29868 + RegValue |= SlotTime;
29869 +
29870 + RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue);
29871 +}
29872 +
29873 +/*
29874 + ========================================================================
29875 + Description:
29876 + Add Shared key information into ASIC.
29877 + Update shared key, TxMic and RxMic to Asic Shared key table
29878 + Update its cipherAlg to Asic Shared key Mode.
29879 +
29880 + Return:
29881 + ========================================================================
29882 +*/
29883 +VOID AsicAddSharedKeyEntry(
29884 + IN PRTMP_ADAPTER pAd,
29885 + IN UCHAR BssIndex,
29886 + IN UCHAR KeyIdx,
29887 + IN UCHAR CipherAlg,
29888 + IN PUCHAR pKey,
29889 + IN PUCHAR pTxMic,
29890 + IN PUCHAR pRxMic)
29891 +{
29892 + ULONG offset; //, csr0;
29893 + SHAREDKEY_MODE_STRUC csr1;
29894 +
29895 + DBGPRINT(RT_DEBUG_TRACE, ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,KeyIdx));
29896 +//============================================================================================
29897 +
29898 + DBGPRINT(RT_DEBUG_TRACE,("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg], BssIndex*4 + KeyIdx));
29899 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
29900 + 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]));
29901 + if (pRxMic)
29902 + {
29903 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
29904 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
29905 + }
29906 + if (pTxMic)
29907 + {
29908 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
29909 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
29910 + }
29911 +//============================================================================================
29912 + //
29913 + // fill key material - key + TX MIC + RX MIC
29914 + //
29915 +
29916 +#ifdef RT2870
29917 +{
29918 + offset = SHARED_KEY_TABLE_BASE + (4*BssIndex + KeyIdx)*HW_KEY_ENTRY_SIZE;
29919 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY);
29920 +
29921 + offset += MAX_LEN_OF_SHARE_KEY;
29922 + if (pTxMic)
29923 + {
29924 + RTUSBMultiWrite(pAd, offset, pTxMic, 8);
29925 + }
29926 +
29927 + offset += 8;
29928 + if (pRxMic)
29929 + {
29930 + RTUSBMultiWrite(pAd, offset, pRxMic, 8);
29931 + }
29932 +}
29933 +#endif // RT2870 //
29934 +
29935 + //
29936 + // Update cipher algorithm. WSTA always use BSS0
29937 + //
29938 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word);
29939 + DBGPRINT(RT_DEBUG_TRACE,("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n", BssIndex,KeyIdx, csr1.word));
29940 + if ((BssIndex%2) == 0)
29941 + {
29942 + if (KeyIdx == 0)
29943 + csr1.field.Bss0Key0CipherAlg = CipherAlg;
29944 + else if (KeyIdx == 1)
29945 + csr1.field.Bss0Key1CipherAlg = CipherAlg;
29946 + else if (KeyIdx == 2)
29947 + csr1.field.Bss0Key2CipherAlg = CipherAlg;
29948 + else
29949 + csr1.field.Bss0Key3CipherAlg = CipherAlg;
29950 + }
29951 + else
29952 + {
29953 + if (KeyIdx == 0)
29954 + csr1.field.Bss1Key0CipherAlg = CipherAlg;
29955 + else if (KeyIdx == 1)
29956 + csr1.field.Bss1Key1CipherAlg = CipherAlg;
29957 + else if (KeyIdx == 2)
29958 + csr1.field.Bss1Key2CipherAlg = CipherAlg;
29959 + else
29960 + csr1.field.Bss1Key3CipherAlg = CipherAlg;
29961 + }
29962 + DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word));
29963 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word);
29964 +
29965 +}
29966 +
29967 +// IRQL = DISPATCH_LEVEL
29968 +VOID AsicRemoveSharedKeyEntry(
29969 + IN PRTMP_ADAPTER pAd,
29970 + IN UCHAR BssIndex,
29971 + IN UCHAR KeyIdx)
29972 +{
29973 + //ULONG SecCsr0;
29974 + SHAREDKEY_MODE_STRUC csr1;
29975 +
29976 + DBGPRINT(RT_DEBUG_TRACE,("AsicRemoveSharedKeyEntry: #%d \n", BssIndex*4 + KeyIdx));
29977 +
29978 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word);
29979 + if ((BssIndex%2) == 0)
29980 + {
29981 + if (KeyIdx == 0)
29982 + csr1.field.Bss0Key0CipherAlg = 0;
29983 + else if (KeyIdx == 1)
29984 + csr1.field.Bss0Key1CipherAlg = 0;
29985 + else if (KeyIdx == 2)
29986 + csr1.field.Bss0Key2CipherAlg = 0;
29987 + else
29988 + csr1.field.Bss0Key3CipherAlg = 0;
29989 + }
29990 + else
29991 + {
29992 + if (KeyIdx == 0)
29993 + csr1.field.Bss1Key0CipherAlg = 0;
29994 + else if (KeyIdx == 1)
29995 + csr1.field.Bss1Key1CipherAlg = 0;
29996 + else if (KeyIdx == 2)
29997 + csr1.field.Bss1Key2CipherAlg = 0;
29998 + else
29999 + csr1.field.Bss1Key3CipherAlg = 0;
30000 + }
30001 + DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word));
30002 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word);
30003 + ASSERT(BssIndex < 4);
30004 + ASSERT(KeyIdx < 4);
30005 +
30006 +}
30007 +
30008 +
30009 +VOID AsicUpdateWCIDAttribute(
30010 + IN PRTMP_ADAPTER pAd,
30011 + IN USHORT WCID,
30012 + IN UCHAR BssIndex,
30013 + IN UCHAR CipherAlg,
30014 + IN BOOLEAN bUsePairewiseKeyTable)
30015 +{
30016 + ULONG WCIDAttri = 0, offset;
30017 +
30018 + //
30019 + // Update WCID attribute.
30020 + // Only TxKey could update WCID attribute.
30021 + //
30022 + offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE);
30023 + WCIDAttri = (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable);
30024 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
30025 +}
30026 +
30027 +VOID AsicUpdateWCIDIVEIV(
30028 + IN PRTMP_ADAPTER pAd,
30029 + IN USHORT WCID,
30030 + IN ULONG uIV,
30031 + IN ULONG uEIV)
30032 +{
30033 + ULONG offset;
30034 +
30035 + offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
30036 +
30037 + RTMP_IO_WRITE32(pAd, offset, uIV);
30038 + RTMP_IO_WRITE32(pAd, offset + 4, uEIV);
30039 +}
30040 +
30041 +VOID AsicUpdateRxWCIDTable(
30042 + IN PRTMP_ADAPTER pAd,
30043 + IN USHORT WCID,
30044 + IN PUCHAR pAddr)
30045 +{
30046 + ULONG offset;
30047 + ULONG Addr;
30048 +
30049 + offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE);
30050 + Addr = pAddr[0] + (pAddr[1] << 8) +(pAddr[2] << 16) +(pAddr[3] << 24);
30051 + RTMP_IO_WRITE32(pAd, offset, Addr);
30052 + Addr = pAddr[4] + (pAddr[5] << 8);
30053 + RTMP_IO_WRITE32(pAd, offset + 4, Addr);
30054 +}
30055 +
30056 +
30057 +/*
30058 + ========================================================================
30059 +
30060 + Routine Description:
30061 + Set Cipher Key, Cipher algorithm, IV/EIV to Asic
30062 +
30063 + Arguments:
30064 + pAd Pointer to our adapter
30065 + WCID WCID Entry number.
30066 + BssIndex BSSID index, station or none multiple BSSID support
30067 + this value should be 0.
30068 + KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled
30069 + pCipherKey Pointer to Cipher Key.
30070 + bUsePairewiseKeyTable TRUE means saved the key in SharedKey table,
30071 + otherwise PairewiseKey table
30072 + bTxKey This is the transmit key if enabled.
30073 +
30074 + Return Value:
30075 + None
30076 +
30077 + Note:
30078 + This routine will set the relative key stuff to Asic including WCID attribute,
30079 + Cipher Key, Cipher algorithm and IV/EIV.
30080 +
30081 + IV/EIV will be update if this CipherKey is the transmission key because
30082 + ASIC will base on IV's KeyID value to select Cipher Key.
30083 +
30084 + If bTxKey sets to FALSE, this is not the TX key, but it could be
30085 + RX key
30086 +
30087 + For AP mode bTxKey must be always set to TRUE.
30088 + ========================================================================
30089 +*/
30090 +VOID AsicAddKeyEntry(
30091 + IN PRTMP_ADAPTER pAd,
30092 + IN USHORT WCID,
30093 + IN UCHAR BssIndex,
30094 + IN UCHAR KeyIdx,
30095 + IN PCIPHER_KEY pCipherKey,
30096 + IN BOOLEAN bUsePairewiseKeyTable,
30097 + IN BOOLEAN bTxKey)
30098 +{
30099 + ULONG offset;
30100 +// ULONG WCIDAttri = 0;
30101 + UCHAR IV4 = 0;
30102 + PUCHAR pKey = pCipherKey->Key;
30103 +// ULONG KeyLen = pCipherKey->KeyLen;
30104 + PUCHAR pTxMic = pCipherKey->TxMic;
30105 + PUCHAR pRxMic = pCipherKey->RxMic;
30106 + PUCHAR pTxtsc = pCipherKey->TxTsc;
30107 + UCHAR CipherAlg = pCipherKey->CipherAlg;
30108 + SHAREDKEY_MODE_STRUC csr1;
30109 +
30110 +// ASSERT(KeyLen <= MAX_LEN_OF_PEER_KEY);
30111 +
30112 + DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n"));
30113 + //
30114 + // 1.) decide key table offset
30115 + //
30116 + if (bUsePairewiseKeyTable)
30117 + offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
30118 + else
30119 + offset = SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE;
30120 +
30121 + //
30122 + // 2.) Set Key to Asic
30123 + //
30124 + //for (i = 0; i < KeyLen; i++)
30125 +
30126 +#ifdef RT2870
30127 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY);
30128 + offset += MAX_LEN_OF_PEER_KEY;
30129 +
30130 + //
30131 + // 3.) Set MIC key if available
30132 + //
30133 + if (pTxMic)
30134 + {
30135 + RTUSBMultiWrite(pAd, offset, pTxMic, 8);
30136 + }
30137 + offset += LEN_TKIP_TXMICK;
30138 +
30139 + if (pRxMic)
30140 + {
30141 + RTUSBMultiWrite(pAd, offset, pRxMic, 8);
30142 + }
30143 +#endif // RT2870 //
30144 +
30145 + //
30146 + // 4.) Modify IV/EIV if needs
30147 + // This will force Asic to use this key ID by setting IV.
30148 + //
30149 + if (bTxKey)
30150 + {
30151 +
30152 +#ifdef RT2870
30153 + UINT32 tmpVal;
30154 +
30155 + //
30156 + // Write IV
30157 + //
30158 + IV4 = (KeyIdx << 6);
30159 + if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) ||(CipherAlg == CIPHER_AES))
30160 + IV4 |= 0x20; // turn on extension bit means EIV existence
30161 +
30162 + tmpVal = pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) + (pTxtsc[0] << 16) + (IV4 << 24);
30163 + RTMP_IO_WRITE32(pAd, offset, tmpVal);
30164 +
30165 + //
30166 + // Write EIV
30167 + //
30168 + offset += 4;
30169 + RTMP_IO_WRITE32(pAd, offset, *(PUINT32)&pCipherKey->TxTsc[2]);
30170 +#endif // RT2870 //
30171 + AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg, bUsePairewiseKeyTable);
30172 + }
30173 +
30174 + if (!bUsePairewiseKeyTable)
30175 + {
30176 + //
30177 + // Only update the shared key security mode
30178 + //
30179 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), &csr1.word);
30180 + if ((BssIndex % 2) == 0)
30181 + {
30182 + if (KeyIdx == 0)
30183 + csr1.field.Bss0Key0CipherAlg = CipherAlg;
30184 + else if (KeyIdx == 1)
30185 + csr1.field.Bss0Key1CipherAlg = CipherAlg;
30186 + else if (KeyIdx == 2)
30187 + csr1.field.Bss0Key2CipherAlg = CipherAlg;
30188 + else
30189 + csr1.field.Bss0Key3CipherAlg = CipherAlg;
30190 + }
30191 + else
30192 + {
30193 + if (KeyIdx == 0)
30194 + csr1.field.Bss1Key0CipherAlg = CipherAlg;
30195 + else if (KeyIdx == 1)
30196 + csr1.field.Bss1Key1CipherAlg = CipherAlg;
30197 + else if (KeyIdx == 2)
30198 + csr1.field.Bss1Key2CipherAlg = CipherAlg;
30199 + else
30200 + csr1.field.Bss1Key3CipherAlg = CipherAlg;
30201 + }
30202 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), csr1.word);
30203 + }
30204 +
30205 + DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n"));
30206 +}
30207 +
30208 +
30209 +/*
30210 + ========================================================================
30211 + Description:
30212 + Add Pair-wise key material into ASIC.
30213 + Update pairwise key, TxMic and RxMic to Asic Pair-wise key table
30214 +
30215 + Return:
30216 + ========================================================================
30217 +*/
30218 +VOID AsicAddPairwiseKeyEntry(
30219 + IN PRTMP_ADAPTER pAd,
30220 + IN PUCHAR pAddr,
30221 + IN UCHAR WCID,
30222 + IN CIPHER_KEY *pCipherKey)
30223 +{
30224 + INT i;
30225 + ULONG offset;
30226 + PUCHAR pKey = pCipherKey->Key;
30227 + PUCHAR pTxMic = pCipherKey->TxMic;
30228 + PUCHAR pRxMic = pCipherKey->RxMic;
30229 +#ifdef DBG
30230 + UCHAR CipherAlg = pCipherKey->CipherAlg;
30231 +#endif // DBG //
30232 +
30233 + // EKEY
30234 + offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
30235 +#ifdef RT2870
30236 + RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY);
30237 +#endif // RT2870 //
30238 + for (i=0; i<MAX_LEN_OF_PEER_KEY; i+=4)
30239 + {
30240 + UINT32 Value;
30241 + RTMP_IO_READ32(pAd, offset + i, &Value);
30242 + }
30243 +
30244 + offset += MAX_LEN_OF_PEER_KEY;
30245 +
30246 + // MIC KEY
30247 + if (pTxMic)
30248 + {
30249 +#ifdef RT2870
30250 + RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8);
30251 +#endif // RT2870 //
30252 + }
30253 + offset += 8;
30254 + if (pRxMic)
30255 + {
30256 +#ifdef RT2870
30257 + RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8);
30258 +#endif // RT2870 //
30259 + }
30260 +
30261 + DBGPRINT(RT_DEBUG_TRACE,("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n",WCID, CipherName[CipherAlg]));
30262 + DBGPRINT(RT_DEBUG_TRACE,(" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30263 + 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]));
30264 + if (pRxMic)
30265 + {
30266 + DBGPRINT(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30267 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
30268 + }
30269 + if (pTxMic)
30270 + {
30271 + DBGPRINT(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30272 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
30273 + }
30274 +}
30275 +/*
30276 + ========================================================================
30277 + Description:
30278 + Remove Pair-wise key material from ASIC.
30279 +
30280 + Return:
30281 + ========================================================================
30282 +*/
30283 +VOID AsicRemovePairwiseKeyEntry(
30284 + IN PRTMP_ADAPTER pAd,
30285 + IN UCHAR BssIdx,
30286 + IN UCHAR Wcid)
30287 +{
30288 + ULONG WCIDAttri;
30289 + USHORT offset;
30290 +
30291 + // re-set the entry's WCID attribute as OPEN-NONE.
30292 + offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
30293 + WCIDAttri = (BssIdx<<4) | PAIRWISEKEYTABLE;
30294 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
30295 +}
30296 +
30297 +BOOLEAN AsicSendCommandToMcu(
30298 + IN PRTMP_ADAPTER pAd,
30299 + IN UCHAR Command,
30300 + IN UCHAR Token,
30301 + IN UCHAR Arg0,
30302 + IN UCHAR Arg1)
30303 +{
30304 + HOST_CMD_CSR_STRUC H2MCmd;
30305 + H2M_MAILBOX_STRUC H2MMailbox;
30306 + ULONG i = 0;
30307 + do
30308 + {
30309 + RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word);
30310 + if (H2MMailbox.field.Owner == 0)
30311 + break;
30312 +
30313 + RTMPusecDelay(2);
30314 + } while(i++ < 100);
30315 +
30316 + if (i >= 100)
30317 + {
30318 + {
30319 + DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n"));
30320 + }
30321 + return FALSE;
30322 + }
30323 +
30324 +
30325 + H2MMailbox.field.Owner = 1; // pass ownership to MCU
30326 + H2MMailbox.field.CmdToken = Token;
30327 + H2MMailbox.field.HighByte = Arg1;
30328 + H2MMailbox.field.LowByte = Arg0;
30329 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word);
30330 +
30331 + H2MCmd.word = 0;
30332 + H2MCmd.field.HostCommand = Command;
30333 + RTMP_IO_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word);
30334 +
30335 + if (Command != 0x80)
30336 + {
30337 + }
30338 +
30339 + return TRUE;
30340 +}
30341 +
30342 +
30343 +/*
30344 + ========================================================================
30345 +
30346 + Routine Description:
30347 + Verify the support rate for different PHY type
30348 +
30349 + Arguments:
30350 + pAd Pointer to our adapter
30351 +
30352 + Return Value:
30353 + None
30354 +
30355 + IRQL = PASSIVE_LEVEL
30356 +
30357 + ========================================================================
30358 +*/
30359 +VOID RTMPCheckRates(
30360 + IN PRTMP_ADAPTER pAd,
30361 + IN OUT UCHAR SupRate[],
30362 + IN OUT UCHAR *SupRateLen)
30363 +{
30364 + UCHAR RateIdx, i, j;
30365 + UCHAR NewRate[12], NewRateLen;
30366 +
30367 + NewRateLen = 0;
30368 +
30369 + if (pAd->CommonCfg.PhyMode == PHY_11B)
30370 + RateIdx = 4;
30371 + else
30372 + RateIdx = 12;
30373 +
30374 + // Check for support rates exclude basic rate bit
30375 + for (i = 0; i < *SupRateLen; i++)
30376 + for (j = 0; j < RateIdx; j++)
30377 + if ((SupRate[i] & 0x7f) == RateIdTo500Kbps[j])
30378 + NewRate[NewRateLen++] = SupRate[i];
30379 +
30380 + *SupRateLen = NewRateLen;
30381 + NdisMoveMemory(SupRate, NewRate, NewRateLen);
30382 +}
30383 +
30384 +#ifdef CONFIG_STA_SUPPORT
30385 +#ifdef DOT11_N_SUPPORT
30386 +BOOLEAN RTMPCheckChannel(
30387 + IN PRTMP_ADAPTER pAd,
30388 + IN UCHAR CentralChannel,
30389 + IN UCHAR Channel)
30390 +{
30391 + UCHAR k;
30392 + UCHAR UpperChannel = 0, LowerChannel = 0;
30393 + UCHAR NoEffectChannelinList = 0;
30394 +
30395 + // Find upper and lower channel according to 40MHz current operation.
30396 + if (CentralChannel < Channel)
30397 + {
30398 + UpperChannel = Channel;
30399 + if (CentralChannel > 2)
30400 + LowerChannel = CentralChannel - 2;
30401 + else
30402 + return FALSE;
30403 + }
30404 + else if (CentralChannel > Channel)
30405 + {
30406 + UpperChannel = CentralChannel + 2;
30407 + LowerChannel = Channel;
30408 + }
30409 +
30410 + for (k = 0;k < pAd->ChannelListNum;k++)
30411 + {
30412 + if (pAd->ChannelList[k].Channel == UpperChannel)
30413 + {
30414 + NoEffectChannelinList ++;
30415 + }
30416 + if (pAd->ChannelList[k].Channel == LowerChannel)
30417 + {
30418 + NoEffectChannelinList ++;
30419 + }
30420 + }
30421 +
30422 + DBGPRINT(RT_DEBUG_TRACE,("Total Channel in Channel List = [%d]\n", NoEffectChannelinList));
30423 + if (NoEffectChannelinList == 2)
30424 + return TRUE;
30425 + else
30426 + return FALSE;
30427 +}
30428 +
30429 +/*
30430 + ========================================================================
30431 +
30432 + Routine Description:
30433 + Verify the support rate for HT phy type
30434 +
30435 + Arguments:
30436 + pAd Pointer to our adapter
30437 +
30438 + Return Value:
30439 + FALSE if pAd->CommonCfg.SupportedHtPhy doesn't accept the pHtCapability. (AP Mode)
30440 +
30441 + IRQL = PASSIVE_LEVEL
30442 +
30443 + ========================================================================
30444 +*/
30445 +BOOLEAN RTMPCheckHt(
30446 + IN PRTMP_ADAPTER pAd,
30447 + IN UCHAR Wcid,
30448 + IN HT_CAPABILITY_IE *pHtCapability,
30449 + IN ADD_HT_INFO_IE *pAddHtInfo)
30450 +{
30451 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
30452 + return FALSE;
30453 +
30454 + // If use AMSDU, set flag.
30455 + if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable)
30456 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_AMSDU_INUSED);
30457 + // Save Peer Capability
30458 + if (pHtCapability->HtCapInfo.ShortGIfor20)
30459 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI20_CAPABLE);
30460 + if (pHtCapability->HtCapInfo.ShortGIfor40)
30461 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI40_CAPABLE);
30462 + if (pHtCapability->HtCapInfo.TxSTBC)
30463 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_TxSTBC_CAPABLE);
30464 + if (pHtCapability->HtCapInfo.RxSTBC)
30465 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RxSTBC_CAPABLE);
30466 + if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport)
30467 + {
30468 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RDG_CAPABLE);
30469 + }
30470 +
30471 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
30472 + {
30473 + pAd->MacTab.Content[Wcid].MpduDensity = pHtCapability->HtCapParm.MpduDensity;
30474 + }
30475 +
30476 + // Will check ChannelWidth for MCSSet[4] below
30477 + pAd->MlmeAux.HtCapability.MCSSet[4] = 0x1;
30478 + switch (pAd->CommonCfg.RxStream)
30479 + {
30480 + case 1:
30481 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
30482 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0x00;
30483 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
30484 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
30485 + break;
30486 + case 2:
30487 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
30488 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
30489 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
30490 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
30491 + break;
30492 + case 3:
30493 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
30494 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
30495 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0xff;
30496 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
30497 + break;
30498 + }
30499 +
30500 + pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth = pAddHtInfo->AddHtInfo.RecomWidth & pAd->CommonCfg.DesiredHtPhy.ChannelWidth;
30501 +
30502 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPCheckHt:: HtCapInfo.ChannelWidth=%d, RecomWidth=%d, DesiredHtPhy.ChannelWidth=%d, BW40MAvailForA/G=%d/%d, PhyMode=%d \n",
30503 + pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth, pAddHtInfo->AddHtInfo.RecomWidth, pAd->CommonCfg.DesiredHtPhy.ChannelWidth,
30504 + pAd->NicConfig2.field.BW40MAvailForA, pAd->NicConfig2.field.BW40MAvailForG, pAd->CommonCfg.PhyMode));
30505 +
30506 + pAd->MlmeAux.HtCapability.HtCapInfo.GF = pHtCapability->HtCapInfo.GF &pAd->CommonCfg.DesiredHtPhy.GF;
30507 +
30508 + // Send Assoc Req with my HT capability.
30509 + pAd->MlmeAux.HtCapability.HtCapInfo.AMsduSize = pAd->CommonCfg.DesiredHtPhy.AmsduSize;
30510 + pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs = pAd->CommonCfg.DesiredHtPhy.MimoPs;
30511 + pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (pHtCapability->HtCapInfo.ShortGIfor20);
30512 + pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (pHtCapability->HtCapInfo.ShortGIfor40);
30513 + pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC = (pAd->CommonCfg.DesiredHtPhy.TxSTBC)&(pHtCapability->HtCapInfo.RxSTBC);
30514 + pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC = (pAd->CommonCfg.DesiredHtPhy.RxSTBC)&(pHtCapability->HtCapInfo.TxSTBC);
30515 + pAd->MlmeAux.HtCapability.HtCapParm.MaxRAmpduFactor = pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor;
30516 + pAd->MlmeAux.HtCapability.HtCapParm.MpduDensity = pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity;
30517 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC;
30518 + pAd->MacTab.Content[Wcid].HTCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC;
30519 + if (pAd->CommonCfg.bRdg)
30520 + {
30521 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.RDGSupport = pHtCapability->ExtHtCapInfo.RDGSupport;
30522 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = 1;
30523 + }
30524 +
30525 + if (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_20)
30526 + pAd->MlmeAux.HtCapability.MCSSet[4] = 0x0; // BW20 can't transmit MCS32
30527 +
30528 + COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability);
30529 + return TRUE;
30530 +}
30531 +#endif // DOT11_N_SUPPORT //
30532 +#endif // CONFIG_STA_SUPPORT //
30533 +
30534 +/*
30535 + ========================================================================
30536 +
30537 + Routine Description:
30538 + Verify the support rate for different PHY type
30539 +
30540 + Arguments:
30541 + pAd Pointer to our adapter
30542 +
30543 + Return Value:
30544 + None
30545 +
30546 + IRQL = PASSIVE_LEVEL
30547 +
30548 + ========================================================================
30549 +*/
30550 +VOID RTMPUpdateMlmeRate(
30551 + IN PRTMP_ADAPTER pAd)
30552 +{
30553 + UCHAR MinimumRate;
30554 + UCHAR ProperMlmeRate; //= RATE_54;
30555 + UCHAR i, j, RateIdx = 12; //1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
30556 + BOOLEAN bMatch = FALSE;
30557 +
30558 + switch (pAd->CommonCfg.PhyMode)
30559 + {
30560 + case PHY_11B:
30561 + ProperMlmeRate = RATE_11;
30562 + MinimumRate = RATE_1;
30563 + break;
30564 + case PHY_11BG_MIXED:
30565 +#ifdef DOT11_N_SUPPORT
30566 + case PHY_11ABGN_MIXED:
30567 + case PHY_11BGN_MIXED:
30568 +#endif // DOT11_N_SUPPORT //
30569 + if ((pAd->MlmeAux.SupRateLen == 4) &&
30570 + (pAd->MlmeAux.ExtRateLen == 0))
30571 + // B only AP
30572 + ProperMlmeRate = RATE_11;
30573 + else
30574 + ProperMlmeRate = RATE_24;
30575 +
30576 + if (pAd->MlmeAux.Channel <= 14)
30577 + MinimumRate = RATE_1;
30578 + else
30579 + MinimumRate = RATE_6;
30580 + break;
30581 + case PHY_11A:
30582 +#ifdef DOT11_N_SUPPORT
30583 + case PHY_11N_2_4G: // rt2860 need to check mlmerate for 802.11n
30584 + case PHY_11GN_MIXED:
30585 + case PHY_11AGN_MIXED:
30586 + case PHY_11AN_MIXED:
30587 + case PHY_11N_5G:
30588 +#endif // DOT11_N_SUPPORT //
30589 + ProperMlmeRate = RATE_24;
30590 + MinimumRate = RATE_6;
30591 + break;
30592 + case PHY_11ABG_MIXED:
30593 + ProperMlmeRate = RATE_24;
30594 + if (pAd->MlmeAux.Channel <= 14)
30595 + MinimumRate = RATE_1;
30596 + else
30597 + MinimumRate = RATE_6;
30598 + break;
30599 + default: // error
30600 + ProperMlmeRate = RATE_1;
30601 + MinimumRate = RATE_1;
30602 + break;
30603 + }
30604 +
30605 + for (i = 0; i < pAd->MlmeAux.SupRateLen; i++)
30606 + {
30607 + for (j = 0; j < RateIdx; j++)
30608 + {
30609 + if ((pAd->MlmeAux.SupRate[i] & 0x7f) == RateIdTo500Kbps[j])
30610 + {
30611 + if (j == ProperMlmeRate)
30612 + {
30613 + bMatch = TRUE;
30614 + break;
30615 + }
30616 + }
30617 + }
30618 +
30619 + if (bMatch)
30620 + break;
30621 + }
30622 +
30623 + if (bMatch == FALSE)
30624 + {
30625 + for (i = 0; i < pAd->MlmeAux.ExtRateLen; i++)
30626 + {
30627 + for (j = 0; j < RateIdx; j++)
30628 + {
30629 + if ((pAd->MlmeAux.ExtRate[i] & 0x7f) == RateIdTo500Kbps[j])
30630 + {
30631 + if (j == ProperMlmeRate)
30632 + {
30633 + bMatch = TRUE;
30634 + break;
30635 + }
30636 + }
30637 + }
30638 +
30639 + if (bMatch)
30640 + break;
30641 + }
30642 + }
30643 +
30644 + if (bMatch == FALSE)
30645 + {
30646 + ProperMlmeRate = MinimumRate;
30647 + }
30648 +
30649 + pAd->CommonCfg.MlmeRate = MinimumRate;
30650 + pAd->CommonCfg.RtsRate = ProperMlmeRate;
30651 + if (pAd->CommonCfg.MlmeRate >= RATE_6)
30652 + {
30653 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
30654 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
30655 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
30656 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
30657 + }
30658 + else
30659 + {
30660 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
30661 + pAd->CommonCfg.MlmeTransmit.field.MCS = pAd->CommonCfg.MlmeRate;
30662 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_CCK;
30663 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = pAd->CommonCfg.MlmeRate;
30664 + }
30665 +
30666 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateMlmeRate ==> MlmeTransmit = 0x%x \n" , pAd->CommonCfg.MlmeTransmit.word));
30667 +}
30668 +
30669 +CHAR RTMPMaxRssi(
30670 + IN PRTMP_ADAPTER pAd,
30671 + IN CHAR Rssi0,
30672 + IN CHAR Rssi1,
30673 + IN CHAR Rssi2)
30674 +{
30675 + CHAR larger = -127;
30676 +
30677 + if ((pAd->Antenna.field.RxPath == 1) && (Rssi0 != 0))
30678 + {
30679 + larger = Rssi0;
30680 + }
30681 +
30682 + if ((pAd->Antenna.field.RxPath >= 2) && (Rssi1 != 0))
30683 + {
30684 + larger = max(Rssi0, Rssi1);
30685 + }
30686 +
30687 + if ((pAd->Antenna.field.RxPath == 3) && (Rssi2 != 0))
30688 + {
30689 + larger = max(larger, Rssi2);
30690 + }
30691 +
30692 + if (larger == -127)
30693 + larger = 0;
30694 +
30695 + return larger;
30696 +}
30697 +
30698 +/*
30699 + ========================================================================
30700 + Routine Description:
30701 + Periodic evaluate antenna link status
30702 +
30703 + Arguments:
30704 + pAd - Adapter pointer
30705 +
30706 + Return Value:
30707 + None
30708 +
30709 + ========================================================================
30710 +*/
30711 +VOID AsicEvaluateRxAnt(
30712 + IN PRTMP_ADAPTER pAd)
30713 +{
30714 + UCHAR BBPR3 = 0;
30715 +
30716 +#ifdef RALINK_ATE
30717 + if (ATE_ON(pAd))
30718 + return;
30719 +#endif // RALINK_ATE //
30720 +
30721 +
30722 +#ifdef CONFIG_STA_SUPPORT
30723 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30724 + {
30725 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS |
30726 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
30727 + fRTMP_ADAPTER_RADIO_OFF |
30728 + fRTMP_ADAPTER_NIC_NOT_EXIST |
30729 + fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
30730 + return;
30731 +
30732 + if (pAd->StaCfg.Psm == PWR_SAVE)
30733 + return;
30734 + }
30735 +#endif // CONFIG_STA_SUPPORT //
30736 +
30737 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
30738 + BBPR3 &= (~0x18);
30739 + if(pAd->Antenna.field.RxPath == 3)
30740 + {
30741 + BBPR3 |= (0x10);
30742 + }
30743 + else if(pAd->Antenna.field.RxPath == 2)
30744 + {
30745 + BBPR3 |= (0x8);
30746 + }
30747 + else if(pAd->Antenna.field.RxPath == 1)
30748 + {
30749 + BBPR3 |= (0x0);
30750 + }
30751 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
30752 +#ifdef CONFIG_STA_SUPPORT
30753 +#endif // CONFIG_STA_SUPPORT //
30754 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
30755 + )
30756 + {
30757 + ULONG TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
30758 + pAd->RalinkCounters.OneSecTxRetryOkCount +
30759 + pAd->RalinkCounters.OneSecTxFailCount;
30760 +
30761 + if (TxTotalCnt > 50)
30762 + {
30763 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 20);
30764 + pAd->Mlme.bLowThroughput = FALSE;
30765 + }
30766 + else
30767 + {
30768 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300);
30769 + pAd->Mlme.bLowThroughput = TRUE;
30770 + }
30771 + }
30772 +}
30773 +
30774 +/*
30775 + ========================================================================
30776 + Routine Description:
30777 + After evaluation, check antenna link status
30778 +
30779 + Arguments:
30780 + pAd - Adapter pointer
30781 +
30782 + Return Value:
30783 + None
30784 +
30785 + ========================================================================
30786 +*/
30787 +VOID AsicRxAntEvalTimeout(
30788 + IN PVOID SystemSpecific1,
30789 + IN PVOID FunctionContext,
30790 + IN PVOID SystemSpecific2,
30791 + IN PVOID SystemSpecific3)
30792 +{
30793 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
30794 +#ifdef CONFIG_STA_SUPPORT
30795 + UCHAR BBPR3 = 0;
30796 + CHAR larger = -127, rssi0, rssi1, rssi2;
30797 +#endif // CONFIG_STA_SUPPORT //
30798 +
30799 +#ifdef RALINK_ATE
30800 + if (ATE_ON(pAd))
30801 + return;
30802 +#endif // RALINK_ATE //
30803 +
30804 +
30805 +#ifdef CONFIG_STA_SUPPORT
30806 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30807 + {
30808 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
30809 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
30810 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF) ||
30811 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
30812 + return;
30813 +
30814 + if (pAd->StaCfg.Psm == PWR_SAVE)
30815 + return;
30816 +
30817 +
30818 + // if the traffic is low, use average rssi as the criteria
30819 + if (pAd->Mlme.bLowThroughput == TRUE)
30820 + {
30821 + rssi0 = pAd->StaCfg.RssiSample.LastRssi0;
30822 + rssi1 = pAd->StaCfg.RssiSample.LastRssi1;
30823 + rssi2 = pAd->StaCfg.RssiSample.LastRssi2;
30824 + }
30825 + else
30826 + {
30827 + rssi0 = pAd->StaCfg.RssiSample.AvgRssi0;
30828 + rssi1 = pAd->StaCfg.RssiSample.AvgRssi1;
30829 + rssi2 = pAd->StaCfg.RssiSample.AvgRssi2;
30830 + }
30831 +
30832 + if(pAd->Antenna.field.RxPath == 3)
30833 + {
30834 + larger = max(rssi0, rssi1);
30835 +
30836 + if (larger > (rssi2 + 20))
30837 + pAd->Mlme.RealRxPath = 2;
30838 + else
30839 + pAd->Mlme.RealRxPath = 3;
30840 + }
30841 + else if(pAd->Antenna.field.RxPath == 2)
30842 + {
30843 + if (rssi0 > (rssi1 + 20))
30844 + pAd->Mlme.RealRxPath = 1;
30845 + else
30846 + pAd->Mlme.RealRxPath = 2;
30847 + }
30848 +
30849 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
30850 + BBPR3 &= (~0x18);
30851 + if(pAd->Mlme.RealRxPath == 3)
30852 + {
30853 + BBPR3 |= (0x10);
30854 + }
30855 + else if(pAd->Mlme.RealRxPath == 2)
30856 + {
30857 + BBPR3 |= (0x8);
30858 + }
30859 + else if(pAd->Mlme.RealRxPath == 1)
30860 + {
30861 + BBPR3 |= (0x0);
30862 + }
30863 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
30864 + }
30865 +
30866 +#endif // CONFIG_STA_SUPPORT //
30867 +
30868 +}
30869 +
30870 +
30871 +
30872 +VOID APSDPeriodicExec(
30873 + IN PVOID SystemSpecific1,
30874 + IN PVOID FunctionContext,
30875 + IN PVOID SystemSpecific2,
30876 + IN PVOID SystemSpecific3)
30877 +{
30878 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
30879 +
30880 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
30881 + return;
30882 +
30883 + pAd->CommonCfg.TriggerTimerCount++;
30884 +
30885 +// Driver should not send trigger frame, it should be send by application layer
30886 +/*
30887 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable
30888 + && (pAd->CommonCfg.bNeedSendTriggerFrame ||
30889 + (((pAd->CommonCfg.TriggerTimerCount%20) == 19) && (!pAd->CommonCfg.bAPSDAC_BE || !pAd->CommonCfg.bAPSDAC_BK || !pAd->CommonCfg.bAPSDAC_VI || !pAd->CommonCfg.bAPSDAC_VO))))
30890 + {
30891 + DBGPRINT(RT_DEBUG_TRACE,("Sending trigger frame and enter service period when support APSD\n"));
30892 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
30893 + pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
30894 + pAd->CommonCfg.TriggerTimerCount = 0;
30895 + pAd->CommonCfg.bInServicePeriod = TRUE;
30896 + }*/
30897 +}
30898 +
30899 +/*
30900 + ========================================================================
30901 + Routine Description:
30902 + Set/reset MAC registers according to bPiggyBack parameter
30903 +
30904 + Arguments:
30905 + pAd - Adapter pointer
30906 + bPiggyBack - Enable / Disable Piggy-Back
30907 +
30908 + Return Value:
30909 + None
30910 +
30911 + ========================================================================
30912 +*/
30913 +VOID RTMPSetPiggyBack(
30914 + IN PRTMP_ADAPTER pAd,
30915 + IN BOOLEAN bPiggyBack)
30916 +{
30917 + TX_LINK_CFG_STRUC TxLinkCfg;
30918 +
30919 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
30920 +
30921 + TxLinkCfg.field.TxCFAckEn = bPiggyBack;
30922 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
30923 +}
30924 +
30925 +/*
30926 + ========================================================================
30927 + Routine Description:
30928 + check if this entry need to switch rate automatically
30929 +
30930 + Arguments:
30931 + pAd
30932 + pEntry
30933 +
30934 + Return Value:
30935 + TURE
30936 + FALSE
30937 +
30938 + ========================================================================
30939 +*/
30940 +BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(
30941 + IN PRTMP_ADAPTER pAd,
30942 + IN PMAC_TABLE_ENTRY pEntry)
30943 +{
30944 + BOOLEAN result = TRUE;
30945 +
30946 +
30947 +#ifdef CONFIG_STA_SUPPORT
30948 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30949 + {
30950 + // only associated STA counts
30951 + if (pEntry && (pEntry->ValidAsCLI) && (pEntry->Sst == SST_ASSOC))
30952 + {
30953 + result = pAd->StaCfg.bAutoTxRateSwitch;
30954 + }
30955 + else
30956 + result = FALSE;
30957 +
30958 +#ifdef QOS_DLS_SUPPORT
30959 + if (pEntry && (pEntry->ValidAsDls))
30960 + result = pAd->StaCfg.bAutoTxRateSwitch;
30961 +#endif // QOS_DLS_SUPPORT //
30962 + }
30963 +#endif // CONFIG_STA_SUPPORT //
30964 +
30965 +
30966 +
30967 + return result;
30968 +}
30969 +
30970 +
30971 +BOOLEAN RTMPAutoRateSwitchCheck(
30972 + IN PRTMP_ADAPTER pAd)
30973 +{
30974 +
30975 +#ifdef CONFIG_STA_SUPPORT
30976 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30977 + {
30978 + if (pAd->StaCfg.bAutoTxRateSwitch)
30979 + return TRUE;
30980 + }
30981 +#endif // CONFIG_STA_SUPPORT //
30982 + return FALSE;
30983 +}
30984 +
30985 +
30986 +/*
30987 + ========================================================================
30988 + Routine Description:
30989 + check if this entry need to fix tx legacy rate
30990 +
30991 + Arguments:
30992 + pAd
30993 + pEntry
30994 +
30995 + Return Value:
30996 + TURE
30997 + FALSE
30998 +
30999 + ========================================================================
31000 +*/
31001 +UCHAR RTMPStaFixedTxMode(
31002 + IN PRTMP_ADAPTER pAd,
31003 + IN PMAC_TABLE_ENTRY pEntry)
31004 +{
31005 + UCHAR tx_mode = FIXED_TXMODE_HT;
31006 +
31007 +
31008 +#ifdef CONFIG_STA_SUPPORT
31009 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31010 + {
31011 + tx_mode = (UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode;
31012 + }
31013 +#endif // CONFIG_STA_SUPPORT //
31014 +
31015 + return tx_mode;
31016 +}
31017 +
31018 +/*
31019 + ========================================================================
31020 + Routine Description:
31021 + Overwrite HT Tx Mode by Fixed Legency Tx Mode, if specified.
31022 +
31023 + Arguments:
31024 + pAd
31025 + pEntry
31026 +
31027 + Return Value:
31028 + TURE
31029 + FALSE
31030 +
31031 + ========================================================================
31032 +*/
31033 +VOID RTMPUpdateLegacyTxSetting(
31034 + UCHAR fixed_tx_mode,
31035 + PMAC_TABLE_ENTRY pEntry)
31036 +{
31037 + HTTRANSMIT_SETTING TransmitSetting;
31038 +
31039 + if (fixed_tx_mode == FIXED_TXMODE_HT)
31040 + return;
31041 +
31042 + TransmitSetting.word = 0;
31043 +
31044 + TransmitSetting.field.MODE = pEntry->HTPhyMode.field.MODE;
31045 + TransmitSetting.field.MCS = pEntry->HTPhyMode.field.MCS;
31046 +
31047 + if (fixed_tx_mode == FIXED_TXMODE_CCK)
31048 + {
31049 + TransmitSetting.field.MODE = MODE_CCK;
31050 + // CCK mode allow MCS 0~3
31051 + if (TransmitSetting.field.MCS > MCS_3)
31052 + TransmitSetting.field.MCS = MCS_3;
31053 + }
31054 + else
31055 + {
31056 + TransmitSetting.field.MODE = MODE_OFDM;
31057 + // OFDM mode allow MCS 0~7
31058 + if (TransmitSetting.field.MCS > MCS_7)
31059 + TransmitSetting.field.MCS = MCS_7;
31060 + }
31061 +
31062 + if (pEntry->HTPhyMode.field.MODE >= TransmitSetting.field.MODE)
31063 + {
31064 + pEntry->HTPhyMode.word = TransmitSetting.word;
31065 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateLegacyTxSetting : wcid-%d, MODE=%s, MCS=%d \n",
31066 + pEntry->Aid, GetPhyMode(pEntry->HTPhyMode.field.MODE), pEntry->HTPhyMode.field.MCS));
31067 + }
31068 +}
31069 +
31070 +#ifdef CONFIG_STA_SUPPORT
31071 +/*
31072 + ==========================================================================
31073 + Description:
31074 + dynamic tune BBP R66 to find a balance between sensibility and
31075 + noise isolation
31076 +
31077 + IRQL = DISPATCH_LEVEL
31078 +
31079 + ==========================================================================
31080 + */
31081 +VOID AsicStaBbpTuning(
31082 + IN PRTMP_ADAPTER pAd)
31083 +{
31084 + UCHAR OrigR66Value = 0, R66;//, R66UpperBound = 0x30, R66LowerBound = 0x30;
31085 + CHAR Rssi;
31086 +
31087 + // 2860C did not support Fase CCA, therefore can't tune
31088 + if (pAd->MACVersion == 0x28600100)
31089 + return;
31090 +
31091 + //
31092 + // work as a STA
31093 + //
31094 + if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) // no R66 tuning when SCANNING
31095 + return;
31096 +
31097 + if ((pAd->OpMode == OPMODE_STA)
31098 + && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
31099 + )
31100 + && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
31101 + )
31102 + {
31103 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value);
31104 + R66 = OrigR66Value;
31105 +
31106 + if (pAd->Antenna.field.RxPath > 1)
31107 + Rssi = (pAd->StaCfg.RssiSample.AvgRssi0 + pAd->StaCfg.RssiSample.AvgRssi1) >> 1;
31108 + else
31109 + Rssi = pAd->StaCfg.RssiSample.AvgRssi0;
31110 +
31111 + if (pAd->LatchRfRegs.Channel <= 14)
31112 + { //BG band
31113 +#ifdef RT2870
31114 + // RT3070 is a no LNA solution, it should have different control regarding to AGC gain control
31115 + // Otherwise, it will have some throughput side effect when low RSSI
31116 + if (IS_RT3070(pAd))
31117 + {
31118 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31119 + {
31120 + R66 = 0x1C + 2*GET_LNA_GAIN(pAd) + 0x20;
31121 + if (OrigR66Value != R66)
31122 + {
31123 + RTUSBWriteBBPRegister(pAd, BBP_R66, R66);
31124 + }
31125 + }
31126 + else
31127 + {
31128 + R66 = 0x1C + 2*GET_LNA_GAIN(pAd);
31129 + if (OrigR66Value != R66)
31130 + {
31131 + RTUSBWriteBBPRegister(pAd, BBP_R66, R66);
31132 + }
31133 + }
31134 + }
31135 + else
31136 +#endif // RT2870 //
31137 + {
31138 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31139 + {
31140 + R66 = (0x2E + GET_LNA_GAIN(pAd)) + 0x10;
31141 + if (OrigR66Value != R66)
31142 + {
31143 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31144 + }
31145 + }
31146 + else
31147 + {
31148 + R66 = 0x2E + GET_LNA_GAIN(pAd);
31149 + if (OrigR66Value != R66)
31150 + {
31151 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31152 + }
31153 + }
31154 + }
31155 + }
31156 + else
31157 + { //A band
31158 + if (pAd->CommonCfg.BBPCurrentBW == BW_20)
31159 + {
31160 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31161 + {
31162 + R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3 + 0x10;
31163 + if (OrigR66Value != R66)
31164 + {
31165 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31166 + }
31167 + }
31168 + else
31169 + {
31170 + R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3;
31171 + if (OrigR66Value != R66)
31172 + {
31173 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31174 + }
31175 + }
31176 + }
31177 + else
31178 + {
31179 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31180 + {
31181 + R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3 + 0x10;
31182 + if (OrigR66Value != R66)
31183 + {
31184 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31185 + }
31186 + }
31187 + else
31188 + {
31189 + R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3;
31190 + if (OrigR66Value != R66)
31191 + {
31192 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31193 + }
31194 + }
31195 + }
31196 + }
31197 +
31198 +
31199 + }
31200 +}
31201 +#endif // CONFIG_STA_SUPPORT //
31202 +
31203 +VOID RTMPSetAGCInitValue(
31204 + IN PRTMP_ADAPTER pAd,
31205 + IN UCHAR BandWidth)
31206 +{
31207 + UCHAR R66 = 0x30;
31208 +
31209 + if (pAd->LatchRfRegs.Channel <= 14)
31210 + { // BG band
31211 + R66 = 0x2E + GET_LNA_GAIN(pAd);
31212 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31213 + }
31214 + else
31215 + { //A band
31216 + if (BandWidth == BW_20)
31217 + {
31218 + R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
31219 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31220 + }
31221 +#ifdef DOT11_N_SUPPORT
31222 + else
31223 + {
31224 + R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
31225 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31226 + }
31227 +#endif // DOT11_N_SUPPORT //
31228 + }
31229 +
31230 +}
31231 +
31232 +VOID AsicTurnOffRFClk(
31233 + IN PRTMP_ADAPTER pAd,
31234 + IN UCHAR Channel)
31235 +{
31236 +
31237 + // RF R2 bit 18 = 0
31238 + UINT32 R1 = 0, R2 = 0, R3 = 0;
31239 + UCHAR index;
31240 + RTMP_RF_REGS *RFRegTable;
31241 +
31242 + RFRegTable = RF2850RegTable;
31243 +
31244 + switch (pAd->RfIcType)
31245 + {
31246 + case RFIC_2820:
31247 + case RFIC_2850:
31248 + case RFIC_2720:
31249 + case RFIC_2750:
31250 +
31251 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
31252 + {
31253 + if (Channel == RFRegTable[index].Channel)
31254 + {
31255 + R1 = RFRegTable[index].R1 & 0xffffdfff;
31256 + R2 = RFRegTable[index].R2 & 0xfffbffff;
31257 + R3 = RFRegTable[index].R3 & 0xfff3ffff;
31258 +
31259 + RTMP_RF_IO_WRITE32(pAd, R1);
31260 + RTMP_RF_IO_WRITE32(pAd, R2);
31261 +
31262 + // Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0.
31263 + // Set RF R2 bit18=0, R3 bit[18:19]=0
31264 + //if (pAd->StaCfg.bRadio == FALSE)
31265 + if (1)
31266 + {
31267 + RTMP_RF_IO_WRITE32(pAd, R3);
31268 +
31269 + DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n",
31270 + Channel, pAd->RfIcType, R2, R3));
31271 + }
31272 + else
31273 + DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n",
31274 + Channel, pAd->RfIcType, R2));
31275 + break;
31276 + }
31277 + }
31278 + break;
31279 +
31280 + default:
31281 + break;
31282 + }
31283 +}
31284 +
31285 +
31286 +VOID AsicTurnOnRFClk(
31287 + IN PRTMP_ADAPTER pAd,
31288 + IN UCHAR Channel)
31289 +{
31290 +
31291 + // RF R2 bit 18 = 0
31292 + UINT32 R1 = 0, R2 = 0, R3 = 0;
31293 + UCHAR index;
31294 + RTMP_RF_REGS *RFRegTable;
31295 +
31296 + RFRegTable = RF2850RegTable;
31297 +
31298 + switch (pAd->RfIcType)
31299 + {
31300 + case RFIC_2820:
31301 + case RFIC_2850:
31302 + case RFIC_2720:
31303 + case RFIC_2750:
31304 +
31305 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
31306 + {
31307 + if (Channel == RFRegTable[index].Channel)
31308 + {
31309 + R3 = pAd->LatchRfRegs.R3;
31310 + R3 &= 0xfff3ffff;
31311 + R3 |= 0x00080000;
31312 + RTMP_RF_IO_WRITE32(pAd, R3);
31313 +
31314 + R1 = RFRegTable[index].R1;
31315 + RTMP_RF_IO_WRITE32(pAd, R1);
31316 +
31317 + R2 = RFRegTable[index].R2;
31318 + if (pAd->Antenna.field.TxPath == 1)
31319 + {
31320 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
31321 + }
31322 +
31323 + if (pAd->Antenna.field.RxPath == 2)
31324 + {
31325 + R2 |= 0x40; // write 1 to off Rxpath.
31326 + }
31327 + else if (pAd->Antenna.field.RxPath == 1)
31328 + {
31329 + R2 |= 0x20040; // write 1 to off RxPath
31330 + }
31331 + RTMP_RF_IO_WRITE32(pAd, R2);
31332 +
31333 + break;
31334 + }
31335 + }
31336 + break;
31337 +
31338 + default:
31339 + break;
31340 + }
31341 +
31342 + DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n",
31343 + Channel,
31344 + pAd->RfIcType,
31345 + R2));
31346 +}
31347 +
31348 --- /dev/null
31349 +++ b/drivers/staging/rt2870/common/netif_block.c
31350 @@ -0,0 +1,144 @@
31351 +/*
31352 + *************************************************************************
31353 + * Ralink Tech Inc.
31354 + * 5F., No.36, Taiyuan St., Jhubei City,
31355 + * Hsinchu County 302,
31356 + * Taiwan, R.O.C.
31357 + *
31358 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
31359 + *
31360 + * This program is free software; you can redistribute it and/or modify *
31361 + * it under the terms of the GNU General Public License as published by *
31362 + * the Free Software Foundation; either version 2 of the License, or *
31363 + * (at your option) any later version. *
31364 + * *
31365 + * This program is distributed in the hope that it will be useful, *
31366 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31367 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31368 + * GNU General Public License for more details. *
31369 + * *
31370 + * You should have received a copy of the GNU General Public License *
31371 + * along with this program; if not, write to the *
31372 + * Free Software Foundation, Inc., *
31373 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
31374 + * *
31375 + *************************************************************************
31376 + */
31377 +
31378 +#include "../rt_config.h"
31379 +#include "netif_block.h"
31380 +
31381 +static NETIF_ENTRY freeNetIfEntryPool[FREE_NETIF_POOL_SIZE];
31382 +static LIST_HEADER freeNetIfEntryList;
31383 +
31384 +void initblockQueueTab(
31385 + IN PRTMP_ADAPTER pAd)
31386 +{
31387 + int i;
31388 +
31389 + initList(&freeNetIfEntryList);
31390 + for (i = 0; i < FREE_NETIF_POOL_SIZE; i++)
31391 + insertTailList(&freeNetIfEntryList, (PLIST_ENTRY)&freeNetIfEntryPool[i]);
31392 +
31393 + for (i=0; i < NUM_OF_TX_RING; i++)
31394 + initList(&pAd->blockQueueTab[i].NetIfList);
31395 +
31396 + return;
31397 +}
31398 +
31399 +BOOLEAN blockNetIf(
31400 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry,
31401 + IN PNET_DEV pNetDev)
31402 +{
31403 + PNETIF_ENTRY pNetIfEntry = NULL;
31404 +
31405 + if ((pNetIfEntry = (PNETIF_ENTRY)removeHeadList(&freeNetIfEntryList)) != NULL)
31406 + {
31407 + netif_stop_queue(pNetDev);
31408 + pNetIfEntry->pNetDev = pNetDev;
31409 + insertTailList(&pBlockQueueEntry->NetIfList, (PLIST_ENTRY)pNetIfEntry);
31410 +
31411 + pBlockQueueEntry->SwTxQueueBlockFlag = TRUE;
31412 + DBGPRINT(RT_DEBUG_TRACE, ("netif_stop_queue(%s)\n", pNetDev->name));
31413 + }
31414 + else
31415 + return FALSE;
31416 +
31417 + return TRUE;
31418 +}
31419 +
31420 +VOID releaseNetIf(
31421 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry)
31422 +{
31423 + PNETIF_ENTRY pNetIfEntry = NULL;
31424 + PLIST_HEADER pNetIfList = &pBlockQueueEntry->NetIfList;
31425 +
31426 + while((pNetIfEntry = (PNETIF_ENTRY)removeHeadList(pNetIfList)) != NULL)
31427 + {
31428 + PNET_DEV pNetDev = pNetIfEntry->pNetDev;
31429 + netif_wake_queue(pNetDev);
31430 + insertTailList(&freeNetIfEntryList, (PLIST_ENTRY)pNetIfEntry);
31431 +
31432 + DBGPRINT(RT_DEBUG_TRACE, ("netif_wake_queue(%s)\n", pNetDev->name));
31433 + }
31434 + pBlockQueueEntry->SwTxQueueBlockFlag = FALSE;
31435 + return;
31436 +}
31437 +
31438 +
31439 +VOID StopNetIfQueue(
31440 + IN PRTMP_ADAPTER pAd,
31441 + IN UCHAR QueIdx,
31442 + IN PNDIS_PACKET pPacket)
31443 +{
31444 + PNET_DEV NetDev = NULL;
31445 + UCHAR IfIdx = 0;
31446 + BOOLEAN valid = FALSE;
31447 +
31448 +#ifdef APCLI_SUPPORT
31449 + if (RTMP_GET_PACKET_NET_DEVICE(pPacket) >= MIN_NET_DEVICE_FOR_APCLI)
31450 + {
31451 + IfIdx = (RTMP_GET_PACKET_NET_DEVICE(pPacket) - MIN_NET_DEVICE_FOR_APCLI) % MAX_APCLI_NUM;
31452 + NetDev = pAd->ApCfg.ApCliTab[IfIdx].dev;
31453 + }
31454 + else
31455 +#endif // APCLI_SUPPORT //
31456 +#ifdef WDS_SUPPORT
31457 + if (RTMP_GET_PACKET_NET_DEVICE(pPacket) >= MIN_NET_DEVICE_FOR_WDS)
31458 + {
31459 + IfIdx = (RTMP_GET_PACKET_NET_DEVICE(pPacket) - MIN_NET_DEVICE_FOR_WDS) % MAX_WDS_ENTRY;
31460 + NetDev = pAd->WdsTab.WdsEntry[IfIdx].dev;
31461 + }
31462 + else
31463 +#endif // WDS_SUPPORT //
31464 + {
31465 +#ifdef MBSS_SUPPORT
31466 + if (pAd->OpMode == OPMODE_AP)
31467 + {
31468 + IfIdx = (RTMP_GET_PACKET_NET_DEVICE(pPacket) - MIN_NET_DEVICE_FOR_MBSSID) % MAX_MBSSID_NUM;
31469 + NetDev = pAd->ApCfg.MBSSID[IfIdx].MSSIDDev;
31470 + }
31471 + else
31472 + {
31473 + IfIdx = MAIN_MBSSID;
31474 + NetDev = pAd->net_dev;
31475 + }
31476 +#else
31477 + IfIdx = MAIN_MBSSID;
31478 + NetDev = pAd->net_dev;
31479 +#endif
31480 + }
31481 +
31482 + // WMM support 4 software queues.
31483 + // One software queue full doesn't mean device have no capbility to transmit packet.
31484 + // So disable block Net-If queue function while WMM enable.
31485 +#ifdef CONFIG_STA_SUPPORT
31486 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31487 + valid = (pAd->CommonCfg.bWmmCapable == TRUE) ? FALSE : TRUE;
31488 +#endif // CONFIG_STA_SUPPORT //
31489 +
31490 + if (valid)
31491 + blockNetIf(&pAd->blockQueueTab[QueIdx], NetDev);
31492 + return;
31493 +}
31494 +
31495 --- /dev/null
31496 +++ b/drivers/staging/rt2870/common/rtmp_init.c
31497 @@ -0,0 +1,4132 @@
31498 +/*
31499 + *************************************************************************
31500 + * Ralink Tech Inc.
31501 + * 5F., No.36, Taiyuan St., Jhubei City,
31502 + * Hsinchu County 302,
31503 + * Taiwan, R.O.C.
31504 + *
31505 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
31506 + *
31507 + * This program is free software; you can redistribute it and/or modify *
31508 + * it under the terms of the GNU General Public License as published by *
31509 + * the Free Software Foundation; either version 2 of the License, or *
31510 + * (at your option) any later version. *
31511 + * *
31512 + * This program is distributed in the hope that it will be useful, *
31513 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31514 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31515 + * GNU General Public License for more details. *
31516 + * *
31517 + * You should have received a copy of the GNU General Public License *
31518 + * along with this program; if not, write to the *
31519 + * Free Software Foundation, Inc., *
31520 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
31521 + * *
31522 + *************************************************************************
31523 +
31524 + Module Name:
31525 + rtmp_init.c
31526 +
31527 + Abstract:
31528 + Miniport generic portion header file
31529 +
31530 + Revision History:
31531 + Who When What
31532 + -------- ---------- ----------------------------------------------
31533 + Paul Lin 2002-08-01 created
31534 + John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme
31535 + Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT.
31536 +*/
31537 +#include "../rt_config.h"
31538 +#include "firmware.h"
31539 +
31540 +//#define BIN_IN_FILE /* use *.bin firmware */
31541 +
31542 +UCHAR BIT8[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
31543 +ULONG BIT32[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008,
31544 + 0x00000010, 0x00000020, 0x00000040, 0x00000080,
31545 + 0x00000100, 0x00000200, 0x00000400, 0x00000800,
31546 + 0x00001000, 0x00002000, 0x00004000, 0x00008000,
31547 + 0x00010000, 0x00020000, 0x00040000, 0x00080000,
31548 + 0x00100000, 0x00200000, 0x00400000, 0x00800000,
31549 + 0x01000000, 0x02000000, 0x04000000, 0x08000000,
31550 + 0x10000000, 0x20000000, 0x40000000, 0x80000000};
31551 +
31552 +char* CipherName[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"};
31553 +
31554 +const unsigned short ccitt_16Table[] = {
31555 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
31556 + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
31557 + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
31558 + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
31559 + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
31560 + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
31561 + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
31562 + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
31563 + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
31564 + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
31565 + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
31566 + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
31567 + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
31568 + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
31569 + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
31570 + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
31571 + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
31572 + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
31573 + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
31574 + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
31575 + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
31576 + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
31577 + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
31578 + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
31579 + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
31580 + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
31581 + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
31582 + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
31583 + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
31584 + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
31585 + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
31586 + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
31587 +};
31588 +#define ByteCRC16(v, crc) \
31589 + (unsigned short)((crc << 8) ^ ccitt_16Table[((crc >> 8) ^ (v)) & 255])
31590 +
31591 +unsigned char BitReverse(unsigned char x)
31592 +{
31593 + int i;
31594 + unsigned char Temp=0;
31595 + for(i=0; ; i++)
31596 + {
31597 + if(x & 0x80) Temp |= 0x80;
31598 + if(i==7) break;
31599 + x <<= 1;
31600 + Temp >>= 1;
31601 + }
31602 + return Temp;
31603 +}
31604 +
31605 +//
31606 +// BBP register initialization set
31607 +//
31608 +REG_PAIR BBPRegTable[] = {
31609 + {BBP_R65, 0x2C}, // fix rssi issue
31610 + {BBP_R66, 0x38}, // Also set this default value to pAd->BbpTuning.R66CurrentValue at initial
31611 + {BBP_R69, 0x12},
31612 + {BBP_R70, 0xa}, // BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa
31613 + {BBP_R73, 0x10},
31614 + {BBP_R81, 0x37},
31615 + {BBP_R82, 0x62},
31616 + {BBP_R83, 0x6A},
31617 + {BBP_R84, 0x99}, // 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before
31618 + {BBP_R86, 0x00}, // middle range issue, Rory @2008-01-28
31619 + {BBP_R91, 0x04}, // middle range issue, Rory @2008-01-28
31620 + {BBP_R92, 0x00}, // middle range issue, Rory @2008-01-28
31621 + {BBP_R103, 0x00}, // near range high-power issue, requested from Gary @2008-0528
31622 + {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.
31623 +};
31624 +#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(REG_PAIR))
31625 +
31626 +//
31627 +// RF register initialization set
31628 +//
31629 +#ifdef RT2870
31630 +REG_PAIR RT30xx_RFRegTable[] = {
31631 + {RF_R04, 0x40},
31632 + {RF_R05, 0x03},
31633 + {RF_R06, 0x02},
31634 + {RF_R07, 0x70},
31635 + {RF_R09, 0x0F},
31636 + {RF_R10, 0x71},
31637 + {RF_R11, 0x21},
31638 + {RF_R12, 0x7B},
31639 + {RF_R14, 0x90},
31640 + {RF_R15, 0x58},
31641 + {RF_R16, 0xB3},
31642 + {RF_R17, 0x92},
31643 + {RF_R18, 0x2C},
31644 + {RF_R19, 0x02},
31645 + {RF_R20, 0xBA},
31646 + {RF_R21, 0xDB},
31647 + {RF_R24, 0x16},
31648 + {RF_R25, 0x01},
31649 + {RF_R27, 0x03},
31650 + {RF_R29, 0x1F},
31651 +};
31652 +#define NUM_RF_REG_PARMS (sizeof(RT30xx_RFRegTable) / sizeof(REG_PAIR))
31653 +#endif // RT2870 //
31654 +
31655 +//
31656 +// ASIC register initialization sets
31657 +//
31658 +
31659 +RTMP_REG_PAIR MACRegTable[] = {
31660 +#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)
31661 + {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */
31662 + {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */
31663 +#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)
31664 + {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
31665 + {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
31666 +#else
31667 + #error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!!!
31668 +#endif // HW_BEACON_OFFSET //
31669 +
31670 + {LEGACY_BASIC_RATE, 0x0000013f}, // Basic rate set bitmap
31671 + {HT_BASIC_RATE, 0x00008003}, // Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI.
31672 + {MAC_SYS_CTRL, 0x00}, // 0x1004, , default Disable RX
31673 + {RX_FILTR_CFG, 0x17f97}, //0x1400 , RX filter control,
31674 + {BKOFF_SLOT_CFG, 0x209}, // default set short slot time, CC_DELAY_TIME should be 2
31675 + {TX_SW_CFG0, 0x0}, // Gary,2008-05-21 for CWC test
31676 + {TX_SW_CFG1, 0x80606}, // Gary,2006-08-23
31677 + {TX_LINK_CFG, 0x1020}, // Gary,2006-08-23
31678 + //{TX_TIMEOUT_CFG, 0x00182090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT
31679 + {TX_TIMEOUT_CFG, 0x000a2090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01
31680 + {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, // 0x3018, MAX frame length. Max PSDU = 16kbytes.
31681 + {LED_CFG, 0x7f031e46}, // Gary, 2006-08-23
31682 + {PBF_MAX_PCNT, 0x1F3FBF9F}, //0x1F3f7f9f}, //Jan, 2006/04/20
31683 + //{TX_RTY_CFG, 0x6bb80408}, // Jan, 2006/11/16
31684 + {TX_RTY_CFG, 0x47d01f0f}, // Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03
31685 + {AUTO_RSP_CFG, 0x00000013}, // Initial Auto_Responder, because QA will turn off Auto-Responder
31686 + {CCK_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
31687 + {OFDM_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
31688 +#ifdef RT2870
31689 + {PBF_CFG, 0xf40006}, // Only enable Queue 2
31690 + {MM40_PROT_CFG, 0x3F44084}, // Initial Auto_Responder, because QA will turn off Auto-Responder
31691 + {WPDMA_GLO_CFG, 0x00000030},
31692 +#endif // RT2870 //
31693 + {GF20_PROT_CFG, 0x01744004}, // set 19:18 --> Short NAV for MIMO PS
31694 + {GF40_PROT_CFG, 0x03F44084},
31695 + {MM20_PROT_CFG, 0x01744004},
31696 + {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f*/ /*0x000024bf*/}, //Extension channel backoff.
31697 + {TX_RTS_CFG, 0x00092b20},
31698 +//#ifdef WIFI_TEST
31699 + {EXP_ACK_TIME, 0x002400ca}, // default value
31700 +//#else
31701 +// {EXP_ACK_TIME, 0x005400ca}, // suggested by Gray @ 20070323 for 11n intel-sta throughput
31702 +//#endif // end - WIFI_TEST //
31703 + {TXOP_HLDR_ET, 0x00000002},
31704 +
31705 + /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us
31706 + is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0
31707 + and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping
31708 + will always lost. So we change the SIFS of CCK from 10us to 16us. */
31709 + {XIFS_TIME_CFG, 0x33a41010},
31710 + {PWR_PIN_CFG, 0x00000003}, // patch for 2880-E
31711 +};
31712 +
31713 +
31714 +#ifdef CONFIG_STA_SUPPORT
31715 +RTMP_REG_PAIR STAMACRegTable[] = {
31716 + {WMM_AIFSN_CFG, 0x00002273},
31717 + {WMM_CWMIN_CFG, 0x00002344},
31718 + {WMM_CWMAX_CFG, 0x000034aa},
31719 +};
31720 +#endif // CONFIG_STA_SUPPORT //
31721 +
31722 +#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))
31723 +#ifdef CONFIG_STA_SUPPORT
31724 +#define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(RTMP_REG_PAIR))
31725 +#endif // CONFIG_STA_SUPPORT //
31726 +
31727 +#ifdef RT2870
31728 +//
31729 +// RT2870 Firmware Spec only used 1 oct for version expression
31730 +//
31731 +#define FIRMWARE_MINOR_VERSION 7
31732 +
31733 +#endif // RT2870 //
31734 +
31735 +// New 8k byte firmware size for RT3071/RT3072
31736 +#define FIRMWAREIMAGE_MAX_LENGTH 0x2000
31737 +#define FIRMWAREIMAGE_LENGTH (sizeof (FirmwareImage) / sizeof(UCHAR))
31738 +#define FIRMWARE_MAJOR_VERSION 0
31739 +
31740 +#define FIRMWAREIMAGEV1_LENGTH 0x1000
31741 +#define FIRMWAREIMAGEV2_LENGTH 0x1000
31742 +
31743 +
31744 +
31745 +/*
31746 + ========================================================================
31747 +
31748 + Routine Description:
31749 + Allocate RTMP_ADAPTER data block and do some initialization
31750 +
31751 + Arguments:
31752 + Adapter Pointer to our adapter
31753 +
31754 + Return Value:
31755 + NDIS_STATUS_SUCCESS
31756 + NDIS_STATUS_FAILURE
31757 +
31758 + IRQL = PASSIVE_LEVEL
31759 +
31760 + Note:
31761 +
31762 + ========================================================================
31763 +*/
31764 +NDIS_STATUS RTMPAllocAdapterBlock(
31765 + IN PVOID handle,
31766 + OUT PRTMP_ADAPTER *ppAdapter)
31767 +{
31768 + PRTMP_ADAPTER pAd;
31769 + NDIS_STATUS Status;
31770 + INT index;
31771 + UCHAR *pBeaconBuf = NULL;
31772 +
31773 + DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n"));
31774 +
31775 + *ppAdapter = NULL;
31776 +
31777 + do
31778 + {
31779 + // Allocate RTMP_ADAPTER memory block
31780 + pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG);
31781 + if (pBeaconBuf == NULL)
31782 + {
31783 + Status = NDIS_STATUS_FAILURE;
31784 + DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n"));
31785 + break;
31786 + }
31787 +
31788 + Status = AdapterBlockAllocateMemory(handle, (PVOID *)&pAd);
31789 + if (Status != NDIS_STATUS_SUCCESS)
31790 + {
31791 + DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n"));
31792 + break;
31793 + }
31794 + pAd->BeaconBuf = pBeaconBuf;
31795 + printk("\n\n=== pAd = %p, size = %d ===\n\n", pAd, (UINT32)sizeof(RTMP_ADAPTER));
31796 +
31797 +
31798 + // Init spin locks
31799 + NdisAllocateSpinLock(&pAd->MgmtRingLock);
31800 +
31801 + for (index =0 ; index < NUM_OF_TX_RING; index++)
31802 + {
31803 + NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]);
31804 + NdisAllocateSpinLock(&pAd->DeQueueLock[index]);
31805 + pAd->DeQueueRunning[index] = FALSE;
31806 + }
31807 +
31808 + NdisAllocateSpinLock(&pAd->irq_lock);
31809 +
31810 + } while (FALSE);
31811 +
31812 + if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf))
31813 + kfree(pBeaconBuf);
31814 +
31815 + *ppAdapter = pAd;
31816 +
31817 + DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status));
31818 + return Status;
31819 +}
31820 +
31821 +/*
31822 + ========================================================================
31823 +
31824 + Routine Description:
31825 + Read initial Tx power per MCS and BW from EEPROM
31826 +
31827 + Arguments:
31828 + Adapter Pointer to our adapter
31829 +
31830 + Return Value:
31831 + None
31832 +
31833 + IRQL = PASSIVE_LEVEL
31834 +
31835 + Note:
31836 +
31837 + ========================================================================
31838 +*/
31839 +VOID RTMPReadTxPwrPerRate(
31840 + IN PRTMP_ADAPTER pAd)
31841 +{
31842 + ULONG data, Adata, Gdata;
31843 + USHORT i, value, value2;
31844 + INT Apwrdelta, Gpwrdelta;
31845 + UCHAR t1,t2,t3,t4;
31846 + BOOLEAN bValid, bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE;
31847 +
31848 + //
31849 + // Get power delta for 20MHz and 40MHz.
31850 + //
31851 + DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n"));
31852 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2);
31853 + Apwrdelta = 0;
31854 + Gpwrdelta = 0;
31855 +
31856 + if ((value2 & 0xff) != 0xff)
31857 + {
31858 + if ((value2 & 0x80))
31859 + Gpwrdelta = (value2&0xf);
31860 +
31861 + if ((value2 & 0x40))
31862 + bGpwrdeltaMinus = FALSE;
31863 + else
31864 + bGpwrdeltaMinus = TRUE;
31865 + }
31866 + if ((value2 & 0xff00) != 0xff00)
31867 + {
31868 + if ((value2 & 0x8000))
31869 + Apwrdelta = ((value2&0xf00)>>8);
31870 +
31871 + if ((value2 & 0x4000))
31872 + bApwrdeltaMinus = FALSE;
31873 + else
31874 + bApwrdeltaMinus = TRUE;
31875 + }
31876 + DBGPRINT(RT_DEBUG_TRACE, ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta));
31877 +
31878 + //
31879 + // Get Txpower per MCS for 20MHz in 2.4G.
31880 + //
31881 + for (i=0; i<5; i++)
31882 + {
31883 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4, value);
31884 + data = value;
31885 + if (bApwrdeltaMinus == FALSE)
31886 + {
31887 + t1 = (value&0xf)+(Apwrdelta);
31888 + if (t1 > 0xf)
31889 + t1 = 0xf;
31890 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
31891 + if (t2 > 0xf)
31892 + t2 = 0xf;
31893 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
31894 + if (t3 > 0xf)
31895 + t3 = 0xf;
31896 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
31897 + if (t4 > 0xf)
31898 + t4 = 0xf;
31899 + }
31900 + else
31901 + {
31902 + if ((value&0xf) > Apwrdelta)
31903 + t1 = (value&0xf)-(Apwrdelta);
31904 + else
31905 + t1 = 0;
31906 + if (((value&0xf0)>>4) > Apwrdelta)
31907 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
31908 + else
31909 + t2 = 0;
31910 + if (((value&0xf00)>>8) > Apwrdelta)
31911 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
31912 + else
31913 + t3 = 0;
31914 + if (((value&0xf000)>>12) > Apwrdelta)
31915 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
31916 + else
31917 + t4 = 0;
31918 + }
31919 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
31920 + if (bGpwrdeltaMinus == FALSE)
31921 + {
31922 + t1 = (value&0xf)+(Gpwrdelta);
31923 + if (t1 > 0xf)
31924 + t1 = 0xf;
31925 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
31926 + if (t2 > 0xf)
31927 + t2 = 0xf;
31928 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
31929 + if (t3 > 0xf)
31930 + t3 = 0xf;
31931 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
31932 + if (t4 > 0xf)
31933 + t4 = 0xf;
31934 + }
31935 + else
31936 + {
31937 + if ((value&0xf) > Gpwrdelta)
31938 + t1 = (value&0xf)-(Gpwrdelta);
31939 + else
31940 + t1 = 0;
31941 + if (((value&0xf0)>>4) > Gpwrdelta)
31942 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
31943 + else
31944 + t2 = 0;
31945 + if (((value&0xf00)>>8) > Gpwrdelta)
31946 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
31947 + else
31948 + t3 = 0;
31949 + if (((value&0xf000)>>12) > Gpwrdelta)
31950 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
31951 + else
31952 + t4 = 0;
31953 + }
31954 + Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
31955 +
31956 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4 + 2, value);
31957 + if (bApwrdeltaMinus == FALSE)
31958 + {
31959 + t1 = (value&0xf)+(Apwrdelta);
31960 + if (t1 > 0xf)
31961 + t1 = 0xf;
31962 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
31963 + if (t2 > 0xf)
31964 + t2 = 0xf;
31965 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
31966 + if (t3 > 0xf)
31967 + t3 = 0xf;
31968 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
31969 + if (t4 > 0xf)
31970 + t4 = 0xf;
31971 + }
31972 + else
31973 + {
31974 + if ((value&0xf) > Apwrdelta)
31975 + t1 = (value&0xf)-(Apwrdelta);
31976 + else
31977 + t1 = 0;
31978 + if (((value&0xf0)>>4) > Apwrdelta)
31979 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
31980 + else
31981 + t2 = 0;
31982 + if (((value&0xf00)>>8) > Apwrdelta)
31983 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
31984 + else
31985 + t3 = 0;
31986 + if (((value&0xf000)>>12) > Apwrdelta)
31987 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
31988 + else
31989 + t4 = 0;
31990 + }
31991 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
31992 + if (bGpwrdeltaMinus == FALSE)
31993 + {
31994 + t1 = (value&0xf)+(Gpwrdelta);
31995 + if (t1 > 0xf)
31996 + t1 = 0xf;
31997 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
31998 + if (t2 > 0xf)
31999 + t2 = 0xf;
32000 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32001 + if (t3 > 0xf)
32002 + t3 = 0xf;
32003 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32004 + if (t4 > 0xf)
32005 + t4 = 0xf;
32006 + }
32007 + else
32008 + {
32009 + if ((value&0xf) > Gpwrdelta)
32010 + t1 = (value&0xf)-(Gpwrdelta);
32011 + else
32012 + t1 = 0;
32013 + if (((value&0xf0)>>4) > Gpwrdelta)
32014 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32015 + else
32016 + t2 = 0;
32017 + if (((value&0xf00)>>8) > Gpwrdelta)
32018 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32019 + else
32020 + t3 = 0;
32021 + if (((value&0xf000)>>12) > Gpwrdelta)
32022 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32023 + else
32024 + t4 = 0;
32025 + }
32026 + Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32027 + data |= (value<<16);
32028 +
32029 + pAd->Tx20MPwrCfgABand[i] = pAd->Tx40MPwrCfgABand[i] = Adata;
32030 + pAd->Tx20MPwrCfgGBand[i] = pAd->Tx40MPwrCfgGBand[i] = Gdata;
32031 +
32032 + if (data != 0xffffffff)
32033 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, data);
32034 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n", data, Adata, Gdata));
32035 + }
32036 +
32037 + //
32038 + // Check this block is valid for 40MHz in 2.4G. If invalid, use parameter for 20MHz in 2.4G
32039 + //
32040 + bValid = TRUE;
32041 + for (i=0; i<6; i++)
32042 + {
32043 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + 2 + i*2, value);
32044 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
32045 + {
32046 + bValid = FALSE;
32047 + break;
32048 + }
32049 + }
32050 +
32051 + //
32052 + // Get Txpower per MCS for 40MHz in 2.4G.
32053 + //
32054 + if (bValid)
32055 + {
32056 + for (i=0; i<4; i++)
32057 + {
32058 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4, value);
32059 + if (bGpwrdeltaMinus == FALSE)
32060 + {
32061 + t1 = (value&0xf)+(Gpwrdelta);
32062 + if (t1 > 0xf)
32063 + t1 = 0xf;
32064 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32065 + if (t2 > 0xf)
32066 + t2 = 0xf;
32067 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32068 + if (t3 > 0xf)
32069 + t3 = 0xf;
32070 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32071 + if (t4 > 0xf)
32072 + t4 = 0xf;
32073 + }
32074 + else
32075 + {
32076 + if ((value&0xf) > Gpwrdelta)
32077 + t1 = (value&0xf)-(Gpwrdelta);
32078 + else
32079 + t1 = 0;
32080 + if (((value&0xf0)>>4) > Gpwrdelta)
32081 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32082 + else
32083 + t2 = 0;
32084 + if (((value&0xf00)>>8) > Gpwrdelta)
32085 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32086 + else
32087 + t3 = 0;
32088 + if (((value&0xf000)>>12) > Gpwrdelta)
32089 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32090 + else
32091 + t4 = 0;
32092 + }
32093 + Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32094 +
32095 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4 + 2, value);
32096 + if (bGpwrdeltaMinus == FALSE)
32097 + {
32098 + t1 = (value&0xf)+(Gpwrdelta);
32099 + if (t1 > 0xf)
32100 + t1 = 0xf;
32101 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32102 + if (t2 > 0xf)
32103 + t2 = 0xf;
32104 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32105 + if (t3 > 0xf)
32106 + t3 = 0xf;
32107 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32108 + if (t4 > 0xf)
32109 + t4 = 0xf;
32110 + }
32111 + else
32112 + {
32113 + if ((value&0xf) > Gpwrdelta)
32114 + t1 = (value&0xf)-(Gpwrdelta);
32115 + else
32116 + t1 = 0;
32117 + if (((value&0xf0)>>4) > Gpwrdelta)
32118 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32119 + else
32120 + t2 = 0;
32121 + if (((value&0xf00)>>8) > Gpwrdelta)
32122 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32123 + else
32124 + t3 = 0;
32125 + if (((value&0xf000)>>12) > Gpwrdelta)
32126 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32127 + else
32128 + t4 = 0;
32129 + }
32130 + Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32131 +
32132 + if (i == 0)
32133 + pAd->Tx40MPwrCfgGBand[i+1] = (pAd->Tx40MPwrCfgGBand[i+1] & 0x0000FFFF) | (Gdata & 0xFFFF0000);
32134 + else
32135 + pAd->Tx40MPwrCfgGBand[i+1] = Gdata;
32136 +
32137 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 2.4G band, Gdata = %lx \n", Gdata));
32138 + }
32139 + }
32140 +
32141 + //
32142 + // Check this block is valid for 20MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
32143 + //
32144 + bValid = TRUE;
32145 + for (i=0; i<8; i++)
32146 + {
32147 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + 2 + i*2, value);
32148 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
32149 + {
32150 + bValid = FALSE;
32151 + break;
32152 + }
32153 + }
32154 +
32155 + //
32156 + // Get Txpower per MCS for 20MHz in 5G.
32157 + //
32158 + if (bValid)
32159 + {
32160 + for (i=0; i<5; i++)
32161 + {
32162 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4, value);
32163 + if (bApwrdeltaMinus == FALSE)
32164 + {
32165 + t1 = (value&0xf)+(Apwrdelta);
32166 + if (t1 > 0xf)
32167 + t1 = 0xf;
32168 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32169 + if (t2 > 0xf)
32170 + t2 = 0xf;
32171 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32172 + if (t3 > 0xf)
32173 + t3 = 0xf;
32174 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32175 + if (t4 > 0xf)
32176 + t4 = 0xf;
32177 + }
32178 + else
32179 + {
32180 + if ((value&0xf) > Apwrdelta)
32181 + t1 = (value&0xf)-(Apwrdelta);
32182 + else
32183 + t1 = 0;
32184 + if (((value&0xf0)>>4) > Apwrdelta)
32185 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32186 + else
32187 + t2 = 0;
32188 + if (((value&0xf00)>>8) > Apwrdelta)
32189 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32190 + else
32191 + t3 = 0;
32192 + if (((value&0xf000)>>12) > Apwrdelta)
32193 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32194 + else
32195 + t4 = 0;
32196 + }
32197 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32198 +
32199 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4 + 2, value);
32200 + if (bApwrdeltaMinus == FALSE)
32201 + {
32202 + t1 = (value&0xf)+(Apwrdelta);
32203 + if (t1 > 0xf)
32204 + t1 = 0xf;
32205 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32206 + if (t2 > 0xf)
32207 + t2 = 0xf;
32208 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32209 + if (t3 > 0xf)
32210 + t3 = 0xf;
32211 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32212 + if (t4 > 0xf)
32213 + t4 = 0xf;
32214 + }
32215 + else
32216 + {
32217 + if ((value&0xf) > Apwrdelta)
32218 + t1 = (value&0xf)-(Apwrdelta);
32219 + else
32220 + t1 = 0;
32221 + if (((value&0xf0)>>4) > Apwrdelta)
32222 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32223 + else
32224 + t2 = 0;
32225 + if (((value&0xf00)>>8) > Apwrdelta)
32226 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32227 + else
32228 + t3 = 0;
32229 + if (((value&0xf000)>>12) > Apwrdelta)
32230 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32231 + else
32232 + t4 = 0;
32233 + }
32234 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32235 +
32236 + if (i == 0)
32237 + pAd->Tx20MPwrCfgABand[i] = (pAd->Tx20MPwrCfgABand[i] & 0x0000FFFF) | (Adata & 0xFFFF0000);
32238 + else
32239 + pAd->Tx20MPwrCfgABand[i] = Adata;
32240 +
32241 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 5GHz band, Adata = %lx \n", Adata));
32242 + }
32243 + }
32244 +
32245 + //
32246 + // Check this block is valid for 40MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
32247 + //
32248 + bValid = TRUE;
32249 + for (i=0; i<6; i++)
32250 + {
32251 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + 2 + i*2, value);
32252 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
32253 + {
32254 + bValid = FALSE;
32255 + break;
32256 + }
32257 + }
32258 +
32259 + //
32260 + // Get Txpower per MCS for 40MHz in 5G.
32261 + //
32262 + if (bValid)
32263 + {
32264 + for (i=0; i<4; i++)
32265 + {
32266 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4, value);
32267 + if (bApwrdeltaMinus == FALSE)
32268 + {
32269 + t1 = (value&0xf)+(Apwrdelta);
32270 + if (t1 > 0xf)
32271 + t1 = 0xf;
32272 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32273 + if (t2 > 0xf)
32274 + t2 = 0xf;
32275 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32276 + if (t3 > 0xf)
32277 + t3 = 0xf;
32278 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32279 + if (t4 > 0xf)
32280 + t4 = 0xf;
32281 + }
32282 + else
32283 + {
32284 + if ((value&0xf) > Apwrdelta)
32285 + t1 = (value&0xf)-(Apwrdelta);
32286 + else
32287 + t1 = 0;
32288 + if (((value&0xf0)>>4) > Apwrdelta)
32289 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32290 + else
32291 + t2 = 0;
32292 + if (((value&0xf00)>>8) > Apwrdelta)
32293 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32294 + else
32295 + t3 = 0;
32296 + if (((value&0xf000)>>12) > Apwrdelta)
32297 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32298 + else
32299 + t4 = 0;
32300 + }
32301 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32302 +
32303 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4 + 2, value);
32304 + if (bApwrdeltaMinus == FALSE)
32305 + {
32306 + t1 = (value&0xf)+(Apwrdelta);
32307 + if (t1 > 0xf)
32308 + t1 = 0xf;
32309 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32310 + if (t2 > 0xf)
32311 + t2 = 0xf;
32312 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32313 + if (t3 > 0xf)
32314 + t3 = 0xf;
32315 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32316 + if (t4 > 0xf)
32317 + t4 = 0xf;
32318 + }
32319 + else
32320 + {
32321 + if ((value&0xf) > Apwrdelta)
32322 + t1 = (value&0xf)-(Apwrdelta);
32323 + else
32324 + t1 = 0;
32325 + if (((value&0xf0)>>4) > Apwrdelta)
32326 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32327 + else
32328 + t2 = 0;
32329 + if (((value&0xf00)>>8) > Apwrdelta)
32330 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32331 + else
32332 + t3 = 0;
32333 + if (((value&0xf000)>>12) > Apwrdelta)
32334 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32335 + else
32336 + t4 = 0;
32337 + }
32338 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32339 +
32340 + if (i == 0)
32341 + pAd->Tx40MPwrCfgABand[i+1] = (pAd->Tx40MPwrCfgABand[i+1] & 0x0000FFFF) | (Adata & 0xFFFF0000);
32342 + else
32343 + pAd->Tx40MPwrCfgABand[i+1] = Adata;
32344 +
32345 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 5GHz band, Adata = %lx \n", Adata));
32346 + }
32347 + }
32348 +}
32349 +
32350 +
32351 +/*
32352 + ========================================================================
32353 +
32354 + Routine Description:
32355 + Read initial channel power parameters from EEPROM
32356 +
32357 + Arguments:
32358 + Adapter Pointer to our adapter
32359 +
32360 + Return Value:
32361 + None
32362 +
32363 + IRQL = PASSIVE_LEVEL
32364 +
32365 + Note:
32366 +
32367 + ========================================================================
32368 +*/
32369 +VOID RTMPReadChannelPwr(
32370 + IN PRTMP_ADAPTER pAd)
32371 +{
32372 + UCHAR i, choffset;
32373 + EEPROM_TX_PWR_STRUC Power;
32374 + EEPROM_TX_PWR_STRUC Power2;
32375 +
32376 + // Read Tx power value for all channels
32377 + // Value from 1 - 0x7f. Default value is 24.
32378 + // Power value : 2.4G 0x00 (0) ~ 0x1F (31)
32379 + // : 5.5G 0xF9 (-7) ~ 0x0F (15)
32380 +
32381 + // 0. 11b/g, ch1 - ch 14
32382 + for (i = 0; i < 7; i++)
32383 + {
32384 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2);
32385 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2);
32386 + RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2, Power.word);
32387 + RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2, Power2.word);
32388 + pAd->TxPower[i * 2].Channel = i * 2 + 1;
32389 + pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2;
32390 +
32391 + if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0))
32392 + pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER;
32393 + else
32394 + pAd->TxPower[i * 2].Power = Power.field.Byte0;
32395 +
32396 + if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0))
32397 + pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER;
32398 + else
32399 + pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1;
32400 +
32401 + if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0))
32402 + pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER;
32403 + else
32404 + pAd->TxPower[i * 2].Power2 = Power2.field.Byte0;
32405 +
32406 + if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0))
32407 + pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER;
32408 + else
32409 + pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1;
32410 + }
32411 +
32412 + // 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz)
32413 + // 1.1 Fill up channel
32414 + choffset = 14;
32415 + for (i = 0; i < 4; i++)
32416 + {
32417 + pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0;
32418 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
32419 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
32420 +
32421 + pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2;
32422 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
32423 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
32424 +
32425 + pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4;
32426 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
32427 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
32428 + }
32429 +
32430 + // 1.2 Fill up power
32431 + for (i = 0; i < 6; i++)
32432 + {
32433 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2);
32434 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2);
32435 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2, Power.word);
32436 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2, Power2.word);
32437 +
32438 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
32439 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
32440 +
32441 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
32442 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
32443 +
32444 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
32445 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
32446 +
32447 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
32448 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
32449 + }
32450 +
32451 + // 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)
32452 + // 2.1 Fill up channel
32453 + choffset = 14 + 12;
32454 + for (i = 0; i < 5; i++)
32455 + {
32456 + pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0;
32457 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
32458 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
32459 +
32460 + pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2;
32461 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
32462 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
32463 +
32464 + pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4;
32465 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
32466 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
32467 + }
32468 + pAd->TxPower[3 * 5 + choffset + 0].Channel = 140;
32469 + pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
32470 + pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
32471 +
32472 + // 2.2 Fill up power
32473 + for (i = 0; i < 8; i++)
32474 + {
32475 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);
32476 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);
32477 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word);
32478 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word);
32479 +
32480 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
32481 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
32482 +
32483 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
32484 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
32485 +
32486 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
32487 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
32488 +
32489 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
32490 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
32491 + }
32492 +
32493 + // 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165 (including central frequency in BW 40MHz)
32494 + // 3.1 Fill up channel
32495 + choffset = 14 + 12 + 16;
32496 + for (i = 0; i < 2; i++)
32497 + {
32498 + pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0;
32499 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
32500 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
32501 +
32502 + pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2;
32503 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
32504 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
32505 +
32506 + pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4;
32507 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
32508 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
32509 + }
32510 + pAd->TxPower[3 * 2 + choffset + 0].Channel = 165;
32511 + pAd->TxPower[3 * 2 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
32512 + pAd->TxPower[3 * 2 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
32513 +
32514 + // 3.2 Fill up power
32515 + for (i = 0; i < 4; i++)
32516 + {
32517 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);
32518 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);
32519 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word);
32520 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word);
32521 +
32522 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
32523 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
32524 +
32525 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
32526 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
32527 +
32528 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
32529 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
32530 +
32531 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
32532 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
32533 + }
32534 +
32535 + // 4. Print and Debug
32536 + choffset = 14 + 12 + 16 + 7;
32537 +
32538 +}
32539 +
32540 +/*
32541 + ========================================================================
32542 +
32543 + Routine Description:
32544 + Read the following from the registry
32545 + 1. All the parameters
32546 + 2. NetworkAddres
32547 +
32548 + Arguments:
32549 + Adapter Pointer to our adapter
32550 + WrapperConfigurationContext For use by NdisOpenConfiguration
32551 +
32552 + Return Value:
32553 + NDIS_STATUS_SUCCESS
32554 + NDIS_STATUS_FAILURE
32555 + NDIS_STATUS_RESOURCES
32556 +
32557 + IRQL = PASSIVE_LEVEL
32558 +
32559 + Note:
32560 +
32561 + ========================================================================
32562 +*/
32563 +NDIS_STATUS NICReadRegParameters(
32564 + IN PRTMP_ADAPTER pAd,
32565 + IN NDIS_HANDLE WrapperConfigurationContext
32566 + )
32567 +{
32568 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
32569 + DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status));
32570 + return Status;
32571 +}
32572 +
32573 +
32574 +#ifdef RT2870
32575 +/*
32576 + ========================================================================
32577 +
32578 + Routine Description:
32579 + For RF filter calibration purpose
32580 +
32581 + Arguments:
32582 + pAd Pointer to our adapter
32583 +
32584 + Return Value:
32585 + None
32586 +
32587 + IRQL = PASSIVE_LEVEL
32588 +
32589 + ========================================================================
32590 +*/
32591 +VOID RTUSBFilterCalibration(
32592 + IN PRTMP_ADAPTER pAd)
32593 +{
32594 + UCHAR R55x = 0, value, FilterTarget = 0x1E, BBPValue;
32595 + UINT loop = 0, count = 0, loopcnt = 0, ReTry = 0;
32596 + UCHAR RF_R24_Value = 0;
32597 +
32598 + // Give bbp filter initial value
32599 + pAd->Mlme.CaliBW20RfR24 = 0x16;
32600 + pAd->Mlme.CaliBW40RfR24 = 0x36; //Bit[5] must be 1 for BW 40
32601 +
32602 + do
32603 + {
32604 + if (loop == 1) //BandWidth = 40 MHz
32605 + {
32606 + // Write 0x27 to RF_R24 to program filter
32607 + RF_R24_Value = 0x27;
32608 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
32609 + FilterTarget = 0x19;
32610 +
32611 + // when calibrate BW40, BBP mask must set to BW40.
32612 + RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue);
32613 + BBPValue&= (~0x18);
32614 + BBPValue|= (0x10);
32615 + RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue);
32616 + }
32617 + else //BandWidth = 20 MHz
32618 + {
32619 + // Write 0x07 to RF_R24 to program filter
32620 + RF_R24_Value = 0x07;
32621 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
32622 + FilterTarget = 0x16;
32623 + }
32624 +
32625 + // Write 0x01 to RF_R22 to enable baseband loopback mode
32626 + RT30xxReadRFRegister(pAd, RF_R22, &value);
32627 + value |= 0x01;
32628 + RT30xxWriteRFRegister(pAd, RF_R22, value);
32629 +
32630 + // Write 0x00 to BBP_R24 to set power & frequency of passband test tone
32631 + RTUSBWriteBBPRegister(pAd, BBP_R24, 0);
32632 +
32633 + do
32634 + {
32635 + // Write 0x90 to BBP_R25 to transmit test tone
32636 + RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90);
32637 +
32638 + RTMPusecDelay(1000);
32639 + // Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0]
32640 + RTUSBReadBBPRegister(pAd, BBP_R55, &value);
32641 + R55x = value & 0xFF;
32642 +
32643 + } while ((ReTry++ < 100) && (R55x == 0));
32644 +
32645 + // Write 0x06 to BBP_R24 to set power & frequency of stopband test tone
32646 + RTUSBWriteBBPRegister(pAd, BBP_R24, 0x06);
32647 +
32648 + while(TRUE)
32649 + {
32650 + // Write 0x90 to BBP_R25 to transmit test tone
32651 + RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90);
32652 +
32653 + //We need to wait for calibration
32654 + RTMPusecDelay(1000);
32655 + RTUSBReadBBPRegister(pAd, BBP_R55, &value);
32656 + value &= 0xFF;
32657 + if ((R55x - value) < FilterTarget)
32658 + {
32659 + RF_R24_Value ++;
32660 + }
32661 + else if ((R55x - value) == FilterTarget)
32662 + {
32663 + RF_R24_Value ++;
32664 + count ++;
32665 + }
32666 + else
32667 + {
32668 + break;
32669 + }
32670 +
32671 + // prevent infinite loop cause driver hang.
32672 + if (loopcnt++ > 100)
32673 + {
32674 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt));
32675 + break;
32676 + }
32677 +
32678 + // Write RF_R24 to program filter
32679 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
32680 + }
32681 +
32682 + if (count > 0)
32683 + {
32684 + RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0));
32685 + }
32686 +
32687 + // Store for future usage
32688 + if (loopcnt < 100)
32689 + {
32690 + if (loop++ == 0)
32691 + {
32692 + //BandWidth = 20 MHz
32693 + pAd->Mlme.CaliBW20RfR24 = (UCHAR)RF_R24_Value;
32694 + }
32695 + else
32696 + {
32697 + //BandWidth = 40 MHz
32698 + pAd->Mlme.CaliBW40RfR24 = (UCHAR)RF_R24_Value;
32699 + break;
32700 + }
32701 + }
32702 + else
32703 + break;
32704 +
32705 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
32706 +
32707 + // reset count
32708 + count = 0;
32709 + } while(TRUE);
32710 +
32711 + //
32712 + // Set back to initial state
32713 + //
32714 + RTUSBWriteBBPRegister(pAd, BBP_R24, 0);
32715 +
32716 + RT30xxReadRFRegister(pAd, RF_R22, &value);
32717 + value &= ~(0x01);
32718 + RT30xxWriteRFRegister(pAd, RF_R22, value);
32719 +
32720 + // set BBP back to BW20
32721 + RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue);
32722 + BBPValue&= (~0x18);
32723 + RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue);
32724 +
32725 + DBGPRINT(RT_DEBUG_TRACE, ("RTUSBFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24));
32726 +}
32727 +
32728 +
32729 +VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd)
32730 +{
32731 + INT i;
32732 + // Driver must read EEPROM to get RfIcType before initial RF registers
32733 + // Initialize RF register to default value
32734 + if (IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) ||(pAd->RfIcType == RFIC_2020)))
32735 + {
32736 + // Init RF calibration
32737 + // Driver should toggle RF R30 bit7 before init RF registers
32738 + ULONG RfReg = 0;
32739 + RT30xxReadRFRegister(pAd, RF_R30, (PUCHAR)&RfReg);
32740 + RfReg |= 0x80;
32741 + RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg);
32742 + RTMPusecDelay(1000);
32743 + RfReg &= 0x7F;
32744 + RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg);
32745 +
32746 + // Initialize RF register to default value
32747 + for (i = 0; i < NUM_RF_REG_PARMS; i++)
32748 + {
32749 + RT30xxWriteRFRegister(pAd, RT30xx_RFRegTable[i].Register, RT30xx_RFRegTable[i].Value);
32750 + }
32751 +
32752 + //For RF filter Calibration
32753 + RTUSBFilterCalibration(pAd);
32754 + }
32755 +
32756 +}
32757 +#endif // RT2870 //
32758 +
32759 +
32760 +/*
32761 + ========================================================================
32762 +
32763 + Routine Description:
32764 + Read initial parameters from EEPROM
32765 +
32766 + Arguments:
32767 + Adapter Pointer to our adapter
32768 +
32769 + Return Value:
32770 + None
32771 +
32772 + IRQL = PASSIVE_LEVEL
32773 +
32774 + Note:
32775 +
32776 + ========================================================================
32777 +*/
32778 +VOID NICReadEEPROMParameters(
32779 + IN PRTMP_ADAPTER pAd,
32780 + IN PUCHAR mac_addr)
32781 +{
32782 + UINT32 data = 0;
32783 + USHORT i, value, value2;
32784 + UCHAR TmpPhy;
32785 + EEPROM_TX_PWR_STRUC Power;
32786 + EEPROM_VERSION_STRUC Version;
32787 + EEPROM_ANTENNA_STRUC Antenna;
32788 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
32789 +
32790 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n"));
32791 +
32792 + // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8
32793 + RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
32794 + DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data));
32795 +
32796 + if((data & 0x30) == 0)
32797 + pAd->EEPROMAddressNum = 6; // 93C46
32798 + else if((data & 0x30) == 0x10)
32799 + pAd->EEPROMAddressNum = 8; // 93C66
32800 + else
32801 + pAd->EEPROMAddressNum = 8; // 93C86
32802 + DBGPRINT(RT_DEBUG_TRACE, ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum ));
32803 +
32804 + // RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to intialize
32805 + // MAC address registers according to E2PROM setting
32806 + if (mac_addr == NULL ||
32807 + strlen(mac_addr) != 17 ||
32808 + mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' ||
32809 + mac_addr[11] != ':' || mac_addr[14] != ':')
32810 + {
32811 + USHORT Addr01,Addr23,Addr45 ;
32812 +
32813 + RT28xx_EEPROM_READ16(pAd, 0x04, Addr01);
32814 + RT28xx_EEPROM_READ16(pAd, 0x06, Addr23);
32815 + RT28xx_EEPROM_READ16(pAd, 0x08, Addr45);
32816 +
32817 + pAd->PermanentAddress[0] = (UCHAR)(Addr01 & 0xff);
32818 + pAd->PermanentAddress[1] = (UCHAR)(Addr01 >> 8);
32819 + pAd->PermanentAddress[2] = (UCHAR)(Addr23 & 0xff);
32820 + pAd->PermanentAddress[3] = (UCHAR)(Addr23 >> 8);
32821 + pAd->PermanentAddress[4] = (UCHAR)(Addr45 & 0xff);
32822 + pAd->PermanentAddress[5] = (UCHAR)(Addr45 >> 8);
32823 +
32824 + DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from E2PROM \n"));
32825 + }
32826 + else
32827 + {
32828 + INT j;
32829 + PUCHAR macptr;
32830 +
32831 + macptr = mac_addr;
32832 +
32833 + for (j=0; j<MAC_ADDR_LEN; j++)
32834 + {
32835 + AtoH(macptr, &pAd->PermanentAddress[j], 1);
32836 + macptr=macptr+3;
32837 + }
32838 +
32839 + DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from module parameter \n"));
32840 + }
32841 +
32842 +
32843 + {
32844 +#if 0
32845 + USHORT Addr01,Addr23,Addr45 ;
32846 +
32847 + Addr01=RTMP_EEPROM_READ16(pAd, 0x04);
32848 + Addr23=RTMP_EEPROM_READ16(pAd, 0x06);
32849 + Addr45=RTMP_EEPROM_READ16(pAd, 0x08);
32850 +
32851 + pAd->PermanentAddress[0] = (UCHAR)(Addr01 & 0xff);
32852 + pAd->PermanentAddress[1] = (UCHAR)(Addr01 >> 8);
32853 + pAd->PermanentAddress[2] = (UCHAR)(Addr23 & 0xff);
32854 + pAd->PermanentAddress[3] = (UCHAR)(Addr23 >> 8);
32855 + pAd->PermanentAddress[4] = (UCHAR)(Addr45 & 0xff);
32856 + pAd->PermanentAddress[5] = (UCHAR)(Addr45 >> 8);
32857 +#endif
32858 + //more conveninet to test mbssid, so ap's bssid &0xf1
32859 + if (pAd->PermanentAddress[0] == 0xff)
32860 + pAd->PermanentAddress[0] = RandomByte(pAd)&0xf8;
32861 +
32862 + //if (pAd->PermanentAddress[5] == 0xff)
32863 + // pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8;
32864 +
32865 + DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
32866 + pAd->PermanentAddress[0], pAd->PermanentAddress[1],
32867 + pAd->PermanentAddress[2], pAd->PermanentAddress[3],
32868 + pAd->PermanentAddress[4], pAd->PermanentAddress[5]));
32869 + if (pAd->bLocalAdminMAC == FALSE)
32870 + {
32871 + MAC_DW0_STRUC csr2;
32872 + MAC_DW1_STRUC csr3;
32873 + COPY_MAC_ADDR(pAd->CurrentAddress, pAd->PermanentAddress);
32874 + csr2.field.Byte0 = pAd->CurrentAddress[0];
32875 + csr2.field.Byte1 = pAd->CurrentAddress[1];
32876 + csr2.field.Byte2 = pAd->CurrentAddress[2];
32877 + csr2.field.Byte3 = pAd->CurrentAddress[3];
32878 + RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word);
32879 + csr3.word = 0;
32880 + csr3.field.Byte4 = pAd->CurrentAddress[4];
32881 + csr3.field.Byte5 = pAd->CurrentAddress[5];
32882 + csr3.field.U2MeMask = 0xff;
32883 + RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word);
32884 + DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
32885 + pAd->PermanentAddress[0], pAd->PermanentAddress[1],
32886 + pAd->PermanentAddress[2], pAd->PermanentAddress[3],
32887 + pAd->PermanentAddress[4], pAd->PermanentAddress[5]));
32888 + }
32889 + }
32890 +
32891 + // if not return early. cause fail at emulation.
32892 + // Init the channel number for TX channel power
32893 + RTMPReadChannelPwr(pAd);
32894 +
32895 + // if E2PROM version mismatch with driver's expectation, then skip
32896 + // all subsequent E2RPOM retieval and set a system error bit to notify GUI
32897 + RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word);
32898 + pAd->EepromVersion = Version.field.Version + Version.field.FaeReleaseNumber * 256;
32899 + DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: Version = %d, FAE release #%d\n", Version.field.Version, Version.field.FaeReleaseNumber));
32900 +
32901 + if (Version.field.Version > VALID_EEPROM_VERSION)
32902 + {
32903 + DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n",Version.field.Version, VALID_EEPROM_VERSION));
32904 + /*pAd->SystemErrorBitmap |= 0x00000001;
32905 +
32906 + // hard-code default value when no proper E2PROM installed
32907 + pAd->bAutoTxAgcA = FALSE;
32908 + pAd->bAutoTxAgcG = FALSE;
32909 +
32910 + // Default the channel power
32911 + for (i = 0; i < MAX_NUM_OF_CHANNELS; i++)
32912 + pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER;
32913 +
32914 + // Default the channel power
32915 + for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++)
32916 + pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER;
32917 +
32918 + for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++)
32919 + pAd->EEPROMDefaultValue[i] = 0xffff;
32920 + return; */
32921 + }
32922 +
32923 + // Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd
32924 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value);
32925 + pAd->EEPROMDefaultValue[0] = value;
32926 +
32927 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value);
32928 + pAd->EEPROMDefaultValue[1] = value;
32929 +
32930 + RT28xx_EEPROM_READ16(pAd, 0x38, value); // Country Region
32931 + pAd->EEPROMDefaultValue[2] = value;
32932 +
32933 + for(i = 0; i < 8; i++)
32934 + {
32935 + RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i*2, value);
32936 + pAd->EEPROMDefaultValue[i+3] = value;
32937 + }
32938 +
32939 + // We have to parse NIC configuration 0 at here.
32940 + // If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
32941 + // Therefore, we have to read TxAutoAgc control beforehand.
32942 + // Read Tx AGC control bit
32943 + Antenna.word = pAd->EEPROMDefaultValue[0];
32944 + if (Antenna.word == 0xFFFF)
32945 + {
32946 + Antenna.word = 0;
32947 + Antenna.field.RfIcType = RFIC_2820;
32948 + Antenna.field.TxPath = 1;
32949 + Antenna.field.RxPath = 2;
32950 + DBGPRINT(RT_DEBUG_WARN, ("E2PROM error, hard code as 0x%04x\n", Antenna.word));
32951 + }
32952 +
32953 + // Choose the desired Tx&Rx stream.
32954 + if ((pAd->CommonCfg.TxStream == 0) || (pAd->CommonCfg.TxStream > Antenna.field.TxPath))
32955 + pAd->CommonCfg.TxStream = Antenna.field.TxPath;
32956 +
32957 + if ((pAd->CommonCfg.RxStream == 0) || (pAd->CommonCfg.RxStream > Antenna.field.RxPath))
32958 + {
32959 + pAd->CommonCfg.RxStream = Antenna.field.RxPath;
32960 +
32961 + if ((pAd->MACVersion < RALINK_2883_VERSION) &&
32962 + (pAd->CommonCfg.RxStream > 2))
32963 + {
32964 + // only 2 Rx streams for RT2860 series
32965 + pAd->CommonCfg.RxStream = 2;
32966 + }
32967 + }
32968 +
32969 + // 3*3
32970 + // read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2
32971 + // yet implement
32972 + for(i=0; i<3; i++)
32973 + {
32974 + }
32975 +
32976 + NicConfig2.word = pAd->EEPROMDefaultValue[1];
32977 +
32978 +
32979 +
32980 +#ifdef CONFIG_STA_SUPPORT
32981 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
32982 + {
32983 + NicConfig2.word = 0;
32984 + if ((NicConfig2.word & 0x00ff) == 0xff)
32985 + {
32986 + NicConfig2.word &= 0xff00;
32987 + }
32988 +
32989 + if ((NicConfig2.word >> 8) == 0xff)
32990 + {
32991 + NicConfig2.word &= 0x00ff;
32992 + }
32993 + }
32994 +#endif // CONFIG_STA_SUPPORT //
32995 +
32996 + if (NicConfig2.field.DynamicTxAgcControl == 1)
32997 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
32998 + else
32999 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
33000 +
33001 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n", Antenna.field.RxPath, Antenna.field.TxPath));
33002 +
33003 + // Save the antenna for future use
33004 + pAd->Antenna.word = Antenna.word;
33005 +
33006 + //
33007 + // Reset PhyMode if we don't support 802.11a
33008 + // Only RFIC_2850 & RFIC_2750 support 802.11a
33009 + //
33010 + if ((Antenna.field.RfIcType != RFIC_2850) && (Antenna.field.RfIcType != RFIC_2750))
33011 + {
33012 + if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) ||
33013 + (pAd->CommonCfg.PhyMode == PHY_11A))
33014 + pAd->CommonCfg.PhyMode = PHY_11BG_MIXED;
33015 +#ifdef DOT11_N_SUPPORT
33016 + else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) ||
33017 + (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) ||
33018 + (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) ||
33019 + (pAd->CommonCfg.PhyMode == PHY_11N_5G))
33020 + pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED;
33021 +#endif // DOT11_N_SUPPORT //
33022 + }
33023 +
33024 + // Read TSSI reference and TSSI boundary for temperature compensation. This is ugly
33025 + // 0. 11b/g
33026 + {
33027 + /* these are tempature reference value (0x00 ~ 0xFE)
33028 + ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
33029 + TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) +
33030 + TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */
33031 + RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word);
33032 + pAd->TssiMinusBoundaryG[4] = Power.field.Byte0;
33033 + pAd->TssiMinusBoundaryG[3] = Power.field.Byte1;
33034 + RT28xx_EEPROM_READ16(pAd, 0x70, Power.word);
33035 + pAd->TssiMinusBoundaryG[2] = Power.field.Byte0;
33036 + pAd->TssiMinusBoundaryG[1] = Power.field.Byte1;
33037 + RT28xx_EEPROM_READ16(pAd, 0x72, Power.word);
33038 + pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */
33039 + pAd->TssiPlusBoundaryG[1] = Power.field.Byte1;
33040 + RT28xx_EEPROM_READ16(pAd, 0x74, Power.word);
33041 + pAd->TssiPlusBoundaryG[2] = Power.field.Byte0;
33042 + pAd->TssiPlusBoundaryG[3] = Power.field.Byte1;
33043 + RT28xx_EEPROM_READ16(pAd, 0x76, Power.word);
33044 + pAd->TssiPlusBoundaryG[4] = Power.field.Byte0;
33045 + pAd->TxAgcStepG = Power.field.Byte1;
33046 + pAd->TxAgcCompensateG = 0;
33047 + pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG;
33048 + pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG;
33049 +
33050 + // Disable TxAgc if the based value is not right
33051 + if (pAd->TssiRefG == 0xff)
33052 + pAd->bAutoTxAgcG = FALSE;
33053 +
33054 + DBGPRINT(RT_DEBUG_TRACE,("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
33055 + pAd->TssiMinusBoundaryG[4], pAd->TssiMinusBoundaryG[3], pAd->TssiMinusBoundaryG[2], pAd->TssiMinusBoundaryG[1],
33056 + pAd->TssiRefG,
33057 + pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2], pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4],
33058 + pAd->TxAgcStepG, pAd->bAutoTxAgcG));
33059 + }
33060 + // 1. 11a
33061 + {
33062 + RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word);
33063 + pAd->TssiMinusBoundaryA[4] = Power.field.Byte0;
33064 + pAd->TssiMinusBoundaryA[3] = Power.field.Byte1;
33065 + RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word);
33066 + pAd->TssiMinusBoundaryA[2] = Power.field.Byte0;
33067 + pAd->TssiMinusBoundaryA[1] = Power.field.Byte1;
33068 + RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word);
33069 + pAd->TssiRefA = Power.field.Byte0;
33070 + pAd->TssiPlusBoundaryA[1] = Power.field.Byte1;
33071 + RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word);
33072 + pAd->TssiPlusBoundaryA[2] = Power.field.Byte0;
33073 + pAd->TssiPlusBoundaryA[3] = Power.field.Byte1;
33074 + RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word);
33075 + pAd->TssiPlusBoundaryA[4] = Power.field.Byte0;
33076 + pAd->TxAgcStepA = Power.field.Byte1;
33077 + pAd->TxAgcCompensateA = 0;
33078 + pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA;
33079 + pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA;
33080 +
33081 + // Disable TxAgc if the based value is not right
33082 + if (pAd->TssiRefA == 0xff)
33083 + pAd->bAutoTxAgcA = FALSE;
33084 +
33085 + DBGPRINT(RT_DEBUG_TRACE,("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
33086 + pAd->TssiMinusBoundaryA[4], pAd->TssiMinusBoundaryA[3], pAd->TssiMinusBoundaryA[2], pAd->TssiMinusBoundaryA[1],
33087 + pAd->TssiRefA,
33088 + pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2], pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4],
33089 + pAd->TxAgcStepA, pAd->bAutoTxAgcA));
33090 + }
33091 + pAd->BbpRssiToDbmDelta = 0x0;
33092 +
33093 + // Read frequency offset setting for RF
33094 + RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value);
33095 + if ((value & 0x00FF) != 0x00FF)
33096 + pAd->RfFreqOffset = (ULONG) (value & 0x00FF);
33097 + else
33098 + pAd->RfFreqOffset = 0;
33099 + DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset));
33100 +
33101 + //CountryRegion byte offset (38h)
33102 + value = pAd->EEPROMDefaultValue[2] >> 8; // 2.4G band
33103 + value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; // 5G band
33104 +
33105 + if ((value <= REGION_MAXIMUM_BG_BAND) && (value2 <= REGION_MAXIMUM_A_BAND))
33106 + {
33107 + pAd->CommonCfg.CountryRegion = ((UCHAR) value) | 0x80;
33108 + pAd->CommonCfg.CountryRegionForABand = ((UCHAR) value2) | 0x80;
33109 + TmpPhy = pAd->CommonCfg.PhyMode;
33110 + pAd->CommonCfg.PhyMode = 0xff;
33111 + RTMPSetPhyMode(pAd, TmpPhy);
33112 +#ifdef DOT11_N_SUPPORT
33113 + SetCommonHT(pAd);
33114 +#endif // DOT11_N_SUPPORT //
33115 + }
33116 +
33117 + //
33118 + // Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch.
33119 + // The valid value are (-10 ~ 10)
33120 + //
33121 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value);
33122 + pAd->BGRssiOffset0 = value & 0x00ff;
33123 + pAd->BGRssiOffset1 = (value >> 8);
33124 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET+2, value);
33125 + pAd->BGRssiOffset2 = value & 0x00ff;
33126 + pAd->ALNAGain1 = (value >> 8);
33127 + RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value);
33128 + pAd->BLNAGain = value & 0x00ff;
33129 + pAd->ALNAGain0 = (value >> 8);
33130 +
33131 + // Validate 11b/g RSSI_0 offset.
33132 + if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10))
33133 + pAd->BGRssiOffset0 = 0;
33134 +
33135 + // Validate 11b/g RSSI_1 offset.
33136 + if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10))
33137 + pAd->BGRssiOffset1 = 0;
33138 +
33139 + // Validate 11b/g RSSI_2 offset.
33140 + if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10))
33141 + pAd->BGRssiOffset2 = 0;
33142 +
33143 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value);
33144 + pAd->ARssiOffset0 = value & 0x00ff;
33145 + pAd->ARssiOffset1 = (value >> 8);
33146 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET+2), value);
33147 + pAd->ARssiOffset2 = value & 0x00ff;
33148 + pAd->ALNAGain2 = (value >> 8);
33149 +
33150 + if (((UCHAR)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00))
33151 + pAd->ALNAGain1 = pAd->ALNAGain0;
33152 + if (((UCHAR)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00))
33153 + pAd->ALNAGain2 = pAd->ALNAGain0;
33154 +
33155 + // Validate 11a RSSI_0 offset.
33156 + if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10))
33157 + pAd->ARssiOffset0 = 0;
33158 +
33159 + // Validate 11a RSSI_1 offset.
33160 + if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10))
33161 + pAd->ARssiOffset1 = 0;
33162 +
33163 + //Validate 11a RSSI_2 offset.
33164 + if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10))
33165 + pAd->ARssiOffset2 = 0;
33166 +
33167 + //
33168 + // Get LED Setting.
33169 + //
33170 + RT28xx_EEPROM_READ16(pAd, 0x3a, value);
33171 + pAd->LedCntl.word = (value&0xff00) >> 8;
33172 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value);
33173 + pAd->Led1 = value;
33174 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value);
33175 + pAd->Led2 = value;
33176 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value);
33177 + pAd->Led3 = value;
33178 +
33179 + RTMPReadTxPwrPerRate(pAd);
33180 +
33181 +#ifdef SINGLE_SKU
33182 + //pAd->CommonCfg.DefineMaxTxPwr = RTMP_EEPROM_READ16(pAd, EEPROM_DEFINE_MAX_TXPWR);
33183 + RT28xx_EEPROM_READ16(pAd, EEPROM_DEFINE_MAX_TXPWR, pAd->CommonCfg.DefineMaxTxPwr);
33184 +#endif // SINGLE_SKU //
33185 +
33186 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n"));
33187 +}
33188 +
33189 +/*
33190 + ========================================================================
33191 +
33192 + Routine Description:
33193 + Set default value from EEPROM
33194 +
33195 + Arguments:
33196 + Adapter Pointer to our adapter
33197 +
33198 + Return Value:
33199 + None
33200 +
33201 + IRQL = PASSIVE_LEVEL
33202 +
33203 + Note:
33204 +
33205 + ========================================================================
33206 +*/
33207 +VOID NICInitAsicFromEEPROM(
33208 + IN PRTMP_ADAPTER pAd)
33209 +{
33210 +#ifdef CONFIG_STA_SUPPORT
33211 + UINT32 data = 0;
33212 + UCHAR BBPR1 = 0;
33213 +#endif // CONFIG_STA_SUPPORT //
33214 + USHORT i;
33215 + EEPROM_ANTENNA_STRUC Antenna;
33216 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
33217 + UCHAR BBPR3 = 0;
33218 +
33219 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n"));
33220 + for(i = 3; i < NUM_EEPROM_BBP_PARMS; i++)
33221 + {
33222 + UCHAR BbpRegIdx, BbpValue;
33223 +
33224 + if ((pAd->EEPROMDefaultValue[i] != 0xFFFF) && (pAd->EEPROMDefaultValue[i] != 0))
33225 + {
33226 + BbpRegIdx = (UCHAR)(pAd->EEPROMDefaultValue[i] >> 8);
33227 + BbpValue = (UCHAR)(pAd->EEPROMDefaultValue[i] & 0xff);
33228 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue);
33229 + }
33230 + }
33231 +
33232 + Antenna.word = pAd->Antenna.word;
33233 + pAd->Mlme.RealRxPath = (UCHAR) Antenna.field.RxPath;
33234 + pAd->RfIcType = (UCHAR) Antenna.field.RfIcType;
33235 +
33236 + NicConfig2.word = pAd->EEPROMDefaultValue[1];
33237 +
33238 +
33239 + // Save the antenna for future use
33240 + pAd->NicConfig2.word = NicConfig2.word;
33241 +
33242 + //
33243 + // Send LED Setting to MCU.
33244 + //
33245 + if (pAd->LedCntl.word == 0xFF)
33246 + {
33247 + pAd->LedCntl.word = 0x01;
33248 + pAd->Led1 = 0x5555;
33249 + pAd->Led2 = 0x2221;
33250 +
33251 +#ifdef RT2870
33252 + pAd->Led3 = 0x5627;
33253 +#endif // RT2870 //
33254 + }
33255 +
33256 + AsicSendCommandToMcu(pAd, 0x52, 0xff, (UCHAR)pAd->Led1, (UCHAR)(pAd->Led1 >> 8));
33257 + AsicSendCommandToMcu(pAd, 0x53, 0xff, (UCHAR)pAd->Led2, (UCHAR)(pAd->Led2 >> 8));
33258 + AsicSendCommandToMcu(pAd, 0x54, 0xff, (UCHAR)pAd->Led3, (UCHAR)(pAd->Led3 >> 8));
33259 + pAd->LedIndicatorStregth = 0xFF;
33260 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, before link up
33261 +
33262 +#ifdef CONFIG_STA_SUPPORT
33263 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33264 + {
33265 + // Read Hardware controlled Radio state enable bit
33266 + if (NicConfig2.field.HardwareRadioControl == 1)
33267 + {
33268 + pAd->StaCfg.bHardwareRadio = TRUE;
33269 +
33270 + // Read GPIO pin2 as Hardware controlled radio state
33271 + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
33272 + if ((data & 0x04) == 0)
33273 + {
33274 + pAd->StaCfg.bHwRadio = FALSE;
33275 + pAd->StaCfg.bRadio = FALSE;
33276 +// RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818);
33277 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
33278 + }
33279 + }
33280 + else
33281 + pAd->StaCfg.bHardwareRadio = FALSE;
33282 +
33283 + if (pAd->StaCfg.bRadio == FALSE)
33284 + {
33285 + RTMPSetLED(pAd, LED_RADIO_OFF);
33286 + }
33287 + else
33288 + {
33289 + RTMPSetLED(pAd, LED_RADIO_ON);
33290 + }
33291 + }
33292 +#endif // CONFIG_STA_SUPPORT //
33293 +
33294 + // Turn off patching for cardbus controller
33295 + if (NicConfig2.field.CardbusAcceleration == 1)
33296 + {
33297 +// pAd->bTest1 = TRUE;
33298 + }
33299 +
33300 + if (NicConfig2.field.DynamicTxAgcControl == 1)
33301 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
33302 + else
33303 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
33304 + //
33305 + // Since BBP has been progamed, to make sure BBP setting will be
33306 + // upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND!!
33307 + //
33308 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
33309 +
33310 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
33311 + BBPR3 &= (~0x18);
33312 + if(pAd->Antenna.field.RxPath == 3)
33313 + {
33314 + BBPR3 |= (0x10);
33315 + }
33316 + else if(pAd->Antenna.field.RxPath == 2)
33317 + {
33318 + BBPR3 |= (0x8);
33319 + }
33320 + else if(pAd->Antenna.field.RxPath == 1)
33321 + {
33322 + BBPR3 |= (0x0);
33323 + }
33324 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
33325 +
33326 +#ifdef CONFIG_STA_SUPPORT
33327 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33328 + {
33329 + // Handle the difference when 1T
33330 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1);
33331 + if(pAd->Antenna.field.TxPath == 1)
33332 + {
33333 + BBPR1 &= (~0x18);
33334 + }
33335 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1);
33336 +
33337 + DBGPRINT(RT_DEBUG_TRACE, ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n", pAd->CommonCfg.bHardwareRadio, pAd->CommonCfg.bHardwareRadio));
33338 + }
33339 +#endif // CONFIG_STA_SUPPORT //
33340 + 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));
33341 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n"));
33342 +}
33343 +
33344 +/*
33345 + ========================================================================
33346 +
33347 + Routine Description:
33348 + Initialize NIC hardware
33349 +
33350 + Arguments:
33351 + Adapter Pointer to our adapter
33352 +
33353 + Return Value:
33354 + None
33355 +
33356 + IRQL = PASSIVE_LEVEL
33357 +
33358 + Note:
33359 +
33360 + ========================================================================
33361 +*/
33362 +NDIS_STATUS NICInitializeAdapter(
33363 + IN PRTMP_ADAPTER pAd,
33364 + IN BOOLEAN bHardReset)
33365 +{
33366 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
33367 + WPDMA_GLO_CFG_STRUC GloCfg;
33368 +// INT_MASK_CSR_STRUC IntMask;
33369 + ULONG i =0, j=0;
33370 + AC_TXOP_CSR0_STRUC csr0;
33371 +
33372 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n"));
33373 +
33374 + // 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits:
33375 +retry:
33376 + i = 0;
33377 + do
33378 + {
33379 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
33380 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
33381 + break;
33382 +
33383 + RTMPusecDelay(1000);
33384 + i++;
33385 + }while ( i<100);
33386 + DBGPRINT(RT_DEBUG_TRACE, ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word));
33387 + GloCfg.word &= 0xff0;
33388 + GloCfg.field.EnTXWriteBackDDONE =1;
33389 + RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
33390 +
33391 + // Record HW Beacon offset
33392 + pAd->BeaconOffset[0] = HW_BEACON_BASE0;
33393 + pAd->BeaconOffset[1] = HW_BEACON_BASE1;
33394 + pAd->BeaconOffset[2] = HW_BEACON_BASE2;
33395 + pAd->BeaconOffset[3] = HW_BEACON_BASE3;
33396 + pAd->BeaconOffset[4] = HW_BEACON_BASE4;
33397 + pAd->BeaconOffset[5] = HW_BEACON_BASE5;
33398 + pAd->BeaconOffset[6] = HW_BEACON_BASE6;
33399 + pAd->BeaconOffset[7] = HW_BEACON_BASE7;
33400 +
33401 + //
33402 + // write all shared Ring's base address into ASIC
33403 + //
33404 +
33405 + // asic simulation sequence put this ahead before loading firmware.
33406 + // pbf hardware reset
33407 +
33408 + // Initialze ASIC for TX & Rx operation
33409 + if (NICInitializeAsic(pAd , bHardReset) != NDIS_STATUS_SUCCESS)
33410 + {
33411 + if (j++ == 0)
33412 + {
33413 + NICLoadFirmware(pAd);
33414 + goto retry;
33415 + }
33416 + return NDIS_STATUS_FAILURE;
33417 + }
33418 +
33419 +
33420 +
33421 +
33422 + // WMM parameter
33423 + csr0.word = 0;
33424 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
33425 + if (pAd->CommonCfg.PhyMode == PHY_11B)
33426 + {
33427 + csr0.field.Ac0Txop = 192; // AC_VI: 192*32us ~= 6ms
33428 + csr0.field.Ac1Txop = 96; // AC_VO: 96*32us ~= 3ms
33429 + }
33430 + else
33431 + {
33432 + csr0.field.Ac0Txop = 96; // AC_VI: 96*32us ~= 3ms
33433 + csr0.field.Ac1Txop = 48; // AC_VO: 48*32us ~= 1.5ms
33434 + }
33435 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word);
33436 +
33437 +
33438 +
33439 +
33440 + // reset action
33441 + // Load firmware
33442 + // Status = NICLoadFirmware(pAd);
33443 +
33444 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n"));
33445 + return Status;
33446 +}
33447 +
33448 +/*
33449 + ========================================================================
33450 +
33451 + Routine Description:
33452 + Initialize ASIC
33453 +
33454 + Arguments:
33455 + Adapter Pointer to our adapter
33456 +
33457 + Return Value:
33458 + None
33459 +
33460 + IRQL = PASSIVE_LEVEL
33461 +
33462 + Note:
33463 +
33464 + ========================================================================
33465 +*/
33466 +NDIS_STATUS NICInitializeAsic(
33467 + IN PRTMP_ADAPTER pAd,
33468 + IN BOOLEAN bHardReset)
33469 +{
33470 + ULONG Index = 0;
33471 + UCHAR R0 = 0xff;
33472 + UINT32 MacCsr12 = 0, Counter = 0;
33473 +#ifdef RT2870
33474 + UINT32 MacCsr0 = 0;
33475 + NTSTATUS Status;
33476 + UCHAR Value = 0xff;
33477 +#endif // RT2870 //
33478 + USHORT KeyIdx;
33479 + INT i,apidx;
33480 +
33481 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n"));
33482 +
33483 +
33484 +#ifdef RT2870
33485 + //
33486 + // Make sure MAC gets ready after NICLoadFirmware().
33487 + //
33488 + Index = 0;
33489 +
33490 + //To avoid hang-on issue when interface up in kernel 2.4,
33491 + //we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly.
33492 + do
33493 + {
33494 + RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
33495 +
33496 + if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
33497 + break;
33498 +
33499 + RTMPusecDelay(10);
33500 + } while (Index++ < 100);
33501 +
33502 + pAd->MACVersion = MacCsr0;
33503 + DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
33504 + // turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue.
33505 + RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12);
33506 + MacCsr12 &= (~0x2000);
33507 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12);
33508 +
33509 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
33510 + RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0);
33511 + Status = RTUSBVenderReset(pAd);
33512 +
33513 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
33514 +
33515 + // Initialize MAC register to default value
33516 + for(Index=0; Index<NUM_MAC_REG_PARMS; Index++)
33517 + {
33518 + RTMP_IO_WRITE32(pAd, (USHORT)MACRegTable[Index].Register, MACRegTable[Index].Value);
33519 + }
33520 +
33521 + if(IS_RT3070(pAd))
33522 + {
33523 + // According to Frank Hsu (from Gary Tsao)
33524 + RTMP_IO_WRITE32(pAd, (USHORT)TX_SW_CFG0, 0x00000400);
33525 +
33526 + // Initialize RT3070 serial MAC registers which is different from RT2870 serial
33527 + RTUSBWriteMACRegister(pAd, TX_SW_CFG1, 0);
33528 + RTUSBWriteMACRegister(pAd, TX_SW_CFG2, 0);
33529 + }
33530 +
33531 +
33532 +#ifdef CONFIG_STA_SUPPORT
33533 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33534 + {
33535 + for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++)
33536 + {
33537 + RTMP_IO_WRITE32(pAd, (USHORT)STAMACRegTable[Index].Register, STAMACRegTable[Index].Value);
33538 + }
33539 + }
33540 +#endif // CONFIG_STA_SUPPORT //
33541 +#endif // RT2870 //
33542 +
33543 + //
33544 + // Before program BBP, we need to wait BBP/RF get wake up.
33545 + //
33546 + Index = 0;
33547 + do
33548 + {
33549 + RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12);
33550 +
33551 + if ((MacCsr12 & 0x03) == 0) // if BB.RF is stable
33552 + break;
33553 +
33554 + DBGPRINT(RT_DEBUG_TRACE, ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12));
33555 + RTMPusecDelay(1000);
33556 + } while (Index++ < 100);
33557 +
33558 + // The commands to firmware should be after these commands, these commands will init firmware
33559 + // PCI and USB are not the same because PCI driver needs to wait for PCI bus ready
33560 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); // initialize BBP R/W access agent
33561 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
33562 + RTMPusecDelay(1000);
33563 +
33564 + // Read BBP register, make sure BBP is up and running before write new data
33565 + Index = 0;
33566 + do
33567 + {
33568 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0);
33569 + DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0));
33570 + } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00)));
33571 + //ASSERT(Index < 20); //this will cause BSOD on Check-build driver
33572 +
33573 + if ((R0 == 0xff) || (R0 == 0x00))
33574 + return NDIS_STATUS_FAILURE;
33575 +
33576 + // Initialize BBP register to default value
33577 + for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++)
33578 + {
33579 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, BBPRegTable[Index].Value);
33580 + }
33581 +
33582 + // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT.
33583 + if ((pAd->MACVersion&0xffff) != 0x0101)
33584 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19);
33585 +
33586 +#ifdef RT2870
33587 + //write RT3070 BBP wchich different with 2870 after write RT2870 BBP
33588 + if (IS_RT3070(pAd))
33589 + {
33590 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0a);
33591 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x99);
33592 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R105, 0x05);
33593 + }
33594 +#endif // RT2870 //
33595 +
33596 + if (pAd->MACVersion == 0x28600100)
33597 + {
33598 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
33599 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12);
33600 + }
33601 +
33602 + if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) // 3*3
33603 + {
33604 + // enlarge MAX_LEN_CFG
33605 + UINT32 csr;
33606 + RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr);
33607 + csr &= 0xFFF;
33608 + csr |= 0x2000;
33609 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr);
33610 + }
33611 +
33612 +#ifdef RT2870
33613 +{
33614 + UCHAR MAC_Value[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0};
33615 +
33616 + //Initialize WCID table
33617 + Value = 0xff;
33618 + for(Index =0 ;Index < 254;Index++)
33619 + {
33620 + RTUSBMultiWrite(pAd, (USHORT)(MAC_WCID_BASE + Index * 8), MAC_Value, 8);
33621 + }
33622 +}
33623 +#endif // RT2870 //
33624 +
33625 + // Add radio off control
33626 +#ifdef CONFIG_STA_SUPPORT
33627 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33628 + {
33629 + if (pAd->StaCfg.bRadio == FALSE)
33630 + {
33631 +// RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818);
33632 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
33633 + DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n"));
33634 + }
33635 + }
33636 +#endif // CONFIG_STA_SUPPORT //
33637 +
33638 + // Clear raw counters
33639 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
33640 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
33641 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
33642 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
33643 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
33644 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
33645 +
33646 + // ASIC will keep garbage value after boot
33647 + // Clear all seared key table when initial
33648 + // This routine can be ignored in radio-ON/OFF operation.
33649 + if (bHardReset)
33650 + {
33651 + for (KeyIdx = 0; KeyIdx < 4; KeyIdx++)
33652 + {
33653 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4*KeyIdx, 0);
33654 + }
33655 +
33656 + // Clear all pairwise key table when initial
33657 + for (KeyIdx = 0; KeyIdx < 256; KeyIdx++)
33658 + {
33659 + RTMP_IO_WRITE32(pAd, MAC_WCID_ATTRIBUTE_BASE + (KeyIdx * HW_WCID_ATTRI_SIZE), 1);
33660 + }
33661 + }
33662 +
33663 + // assert HOST ready bit
33664 +// RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x0); // 2004-09-14 asked by Mark
33665 +// RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x4);
33666 +
33667 + // It isn't necessary to clear this space when not hard reset.
33668 + if (bHardReset == TRUE)
33669 + {
33670 + // clear all on-chip BEACON frame space
33671 + for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++)
33672 + {
33673 + for (i = 0; i < HW_BEACON_OFFSET>>2; i+=4)
33674 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[apidx] + i, 0x00);
33675 + }
33676 + }
33677 +#ifdef RT2870
33678 + AsicDisableSync(pAd);
33679 + // Clear raw counters
33680 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
33681 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
33682 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
33683 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
33684 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
33685 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
33686 + // Default PCI clock cycle per ms is different as default setting, which is based on PCI.
33687 + RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter);
33688 + Counter&=0xffffff00;
33689 + Counter|=0x000001e;
33690 + RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter);
33691 +#endif // RT2870 //
33692 +
33693 +#ifdef CONFIG_STA_SUPPORT
33694 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33695 + {
33696 + // for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT.
33697 + if ((pAd->MACVersion&0xffff) != 0x0101)
33698 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f);
33699 + }
33700 +#endif // CONFIG_STA_SUPPORT //
33701 +
33702 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n"));
33703 + return NDIS_STATUS_SUCCESS;
33704 +}
33705 +
33706 +/*
33707 + ========================================================================
33708 +
33709 + Routine Description:
33710 + Reset NIC Asics
33711 +
33712 + Arguments:
33713 + Adapter Pointer to our adapter
33714 +
33715 + Return Value:
33716 + None
33717 +
33718 + IRQL = PASSIVE_LEVEL
33719 +
33720 + Note:
33721 + Reset NIC to initial state AS IS system boot up time.
33722 +
33723 + ========================================================================
33724 +*/
33725 +VOID NICIssueReset(
33726 + IN PRTMP_ADAPTER pAd)
33727 +{
33728 + UINT32 Value = 0;
33729 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n"));
33730 +
33731 + // Abort Tx, prevent ASIC from writing to Host memory
33732 + //RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x001f0000);
33733 +
33734 + // Disable Rx, register value supposed will remain after reset
33735 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
33736 + Value &= (0xfffffff3);
33737 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
33738 +
33739 + // Issue reset and clear from reset state
33740 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); // 2004-09-17 change from 0x01
33741 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00);
33742 +
33743 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n"));
33744 +}
33745 +
33746 +/*
33747 + ========================================================================
33748 +
33749 + Routine Description:
33750 + Check ASIC registers and find any reason the system might hang
33751 +
33752 + Arguments:
33753 + Adapter Pointer to our adapter
33754 +
33755 + Return Value:
33756 + None
33757 +
33758 + IRQL = DISPATCH_LEVEL
33759 +
33760 + ========================================================================
33761 +*/
33762 +BOOLEAN NICCheckForHang(
33763 + IN PRTMP_ADAPTER pAd)
33764 +{
33765 + return (FALSE);
33766 +}
33767 +
33768 +VOID NICUpdateFifoStaCounters(
33769 + IN PRTMP_ADAPTER pAd)
33770 +{
33771 + TX_STA_FIFO_STRUC StaFifo;
33772 + MAC_TABLE_ENTRY *pEntry;
33773 + UCHAR i = 0;
33774 + UCHAR pid = 0, wcid = 0;
33775 + CHAR reTry;
33776 + UCHAR succMCS;
33777 +
33778 +#ifdef RALINK_ATE
33779 + /* Nothing to do in ATE mode */
33780 + if (ATE_ON(pAd))
33781 + return;
33782 +#endif // RALINK_ATE //
33783 +
33784 + do
33785 + {
33786 + RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word);
33787 +
33788 + if (StaFifo.field.bValid == 0)
33789 + break;
33790 +
33791 + wcid = (UCHAR)StaFifo.field.wcid;
33792 +
33793 +
33794 + /* ignore NoACK and MGMT frame use 0xFF as WCID */
33795 + if ((StaFifo.field.TxAckRequired == 0) || (wcid >= MAX_LEN_OF_MAC_TABLE))
33796 + {
33797 + i++;
33798 + continue;
33799 + }
33800 +
33801 + /* PID store Tx MCS Rate */
33802 + pid = (UCHAR)StaFifo.field.PidType;
33803 +
33804 + pEntry = &pAd->MacTab.Content[wcid];
33805 +
33806 + pEntry->DebugFIFOCount++;
33807 +
33808 +#ifdef DOT11_N_SUPPORT
33809 + if (StaFifo.field.TxBF) // 3*3
33810 + pEntry->TxBFCount++;
33811 +#endif // DOT11_N_SUPPORT //
33812 +
33813 +#ifdef UAPSD_AP_SUPPORT
33814 + UAPSD_SP_AUE_Handle(pAd, pEntry, StaFifo.field.TxSuccess);
33815 +#endif // UAPSD_AP_SUPPORT //
33816 +
33817 + if (!StaFifo.field.TxSuccess)
33818 + {
33819 + pEntry->FIFOCount++;
33820 + pEntry->OneSecTxFailCount++;
33821 +
33822 + if (pEntry->FIFOCount >= 1)
33823 + {
33824 + DBGPRINT(RT_DEBUG_TRACE, ("#"));
33825 +#if 0
33826 + SendRefreshBAR(pAd, pEntry);
33827 + pEntry->NoBADataCountDown = 64;
33828 +#else
33829 +#ifdef DOT11_N_SUPPORT
33830 + pEntry->NoBADataCountDown = 64;
33831 +#endif // DOT11_N_SUPPORT //
33832 +
33833 + if(pEntry->PsMode == PWR_ACTIVE)
33834 + {
33835 +#ifdef DOT11_N_SUPPORT
33836 + int tid;
33837 + for (tid=0; tid<NUM_OF_TID; tid++)
33838 + {
33839 + BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, FALSE);
33840 + }
33841 +#endif // DOT11_N_SUPPORT //
33842 +
33843 + // Update the continuous transmission counter except PS mode
33844 + pEntry->ContinueTxFailCnt++;
33845 + }
33846 + else
33847 + {
33848 + // Clear the FIFOCount when sta in Power Save mode. Basically we assume
33849 + // this tx error happened due to sta just go to sleep.
33850 + pEntry->FIFOCount = 0;
33851 + pEntry->ContinueTxFailCnt = 0;
33852 + }
33853 +#endif
33854 + //pEntry->FIFOCount = 0;
33855 + }
33856 + //pEntry->bSendBAR = TRUE;
33857 + }
33858 + else
33859 + {
33860 +#ifdef DOT11_N_SUPPORT
33861 + if ((pEntry->PsMode != PWR_SAVE) && (pEntry->NoBADataCountDown > 0))
33862 + {
33863 + pEntry->NoBADataCountDown--;
33864 + if (pEntry->NoBADataCountDown==0)
33865 + {
33866 + DBGPRINT(RT_DEBUG_TRACE, ("@\n"));
33867 + }
33868 + }
33869 +#endif // DOT11_N_SUPPORT //
33870 + pEntry->FIFOCount = 0;
33871 + pEntry->OneSecTxNoRetryOkCount++;
33872 + // update NoDataIdleCount when sucessful send packet to STA.
33873 + pEntry->NoDataIdleCount = 0;
33874 + pEntry->ContinueTxFailCnt = 0;
33875 + }
33876 +
33877 + succMCS = StaFifo.field.SuccessRate & 0x7F;
33878 +
33879 + reTry = pid - succMCS;
33880 +
33881 + if (StaFifo.field.TxSuccess)
33882 + {
33883 + pEntry->TXMCSExpected[pid]++;
33884 + if (pid == succMCS)
33885 + {
33886 + pEntry->TXMCSSuccessful[pid]++;
33887 + }
33888 + else
33889 + {
33890 + pEntry->TXMCSAutoFallBack[pid][succMCS]++;
33891 + }
33892 + }
33893 + else
33894 + {
33895 + pEntry->TXMCSFailed[pid]++;
33896 + }
33897 +
33898 + if (reTry > 0)
33899 + {
33900 + if ((pid >= 12) && succMCS <=7)
33901 + {
33902 + reTry -= 4;
33903 + }
33904 + pEntry->OneSecTxRetryOkCount += reTry;
33905 + }
33906 +
33907 + i++;
33908 + // ASIC store 16 stack
33909 + } while ( i < (2*TX_RING_SIZE) );
33910 +
33911 +}
33912 +
33913 +/*
33914 + ========================================================================
33915 +
33916 + Routine Description:
33917 + Read statistical counters from hardware registers and record them
33918 + in software variables for later on query
33919 +
33920 + Arguments:
33921 + pAd Pointer to our adapter
33922 +
33923 + Return Value:
33924 + None
33925 +
33926 + IRQL = DISPATCH_LEVEL
33927 +
33928 + ========================================================================
33929 +*/
33930 +VOID NICUpdateRawCounters(
33931 + IN PRTMP_ADAPTER pAd)
33932 +{
33933 + UINT32 OldValue;
33934 + RX_STA_CNT0_STRUC RxStaCnt0;
33935 + RX_STA_CNT1_STRUC RxStaCnt1;
33936 + RX_STA_CNT2_STRUC RxStaCnt2;
33937 + TX_STA_CNT0_STRUC TxStaCnt0;
33938 + TX_STA_CNT1_STRUC StaTx1;
33939 + TX_STA_CNT2_STRUC StaTx2;
33940 + TX_AGG_CNT_STRUC TxAggCnt;
33941 + TX_AGG_CNT0_STRUC TxAggCnt0;
33942 + TX_AGG_CNT1_STRUC TxAggCnt1;
33943 + TX_AGG_CNT2_STRUC TxAggCnt2;
33944 + TX_AGG_CNT3_STRUC TxAggCnt3;
33945 + TX_AGG_CNT4_STRUC TxAggCnt4;
33946 + TX_AGG_CNT5_STRUC TxAggCnt5;
33947 + TX_AGG_CNT6_STRUC TxAggCnt6;
33948 + TX_AGG_CNT7_STRUC TxAggCnt7;
33949 +
33950 +
33951 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word);
33952 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word);
33953 +
33954 + {
33955 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word);
33956 + // Update RX PLCP error counter
33957 + pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr;
33958 + // Update False CCA counter
33959 + pAd->RalinkCounters.OneSecFalseCCACnt += RxStaCnt1.field.FalseCca;
33960 + }
33961 +
33962 + // Update FCS counters
33963 + OldValue= pAd->WlanCounters.FCSErrorCount.u.LowPart;
33964 + pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); // >> 7);
33965 + if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue)
33966 + pAd->WlanCounters.FCSErrorCount.u.HighPart++;
33967 +
33968 + // Add FCS error count to private counters
33969 + pAd->RalinkCounters.OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr;
33970 + OldValue = pAd->RalinkCounters.RealFcsErrCount.u.LowPart;
33971 + pAd->RalinkCounters.RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr;
33972 + if (pAd->RalinkCounters.RealFcsErrCount.u.LowPart < OldValue)
33973 + pAd->RalinkCounters.RealFcsErrCount.u.HighPart++;
33974 +
33975 + // Update Duplicate Rcv check
33976 + pAd->RalinkCounters.DuplicateRcv += RxStaCnt2.field.RxDupliCount;
33977 + pAd->WlanCounters.FrameDuplicateCount.u.LowPart += RxStaCnt2.field.RxDupliCount;
33978 + // Update RX Overflow counter
33979 + pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount);
33980 +
33981 + //pAd->RalinkCounters.RxCount = 0;
33982 +#ifdef RT2870
33983 + if (pAd->RalinkCounters.RxCount != pAd->watchDogRxCnt)
33984 + {
33985 + pAd->watchDogRxCnt = pAd->RalinkCounters.RxCount;
33986 + pAd->watchDogRxOverFlowCnt = 0;
33987 + }
33988 + else
33989 + {
33990 + if (RxStaCnt2.field.RxFifoOverflowCount)
33991 + pAd->watchDogRxOverFlowCnt++;
33992 + else
33993 + pAd->watchDogRxOverFlowCnt = 0;
33994 + }
33995 +#endif // RT2870 //
33996 +
33997 +
33998 + //if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) ||
33999 + // (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) && (pAd->MacTab.Size != 1)))
34000 + if (!pAd->bUpdateBcnCntDone)
34001 + {
34002 + // Update BEACON sent count
34003 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
34004 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
34005 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word);
34006 + pAd->RalinkCounters.OneSecBeaconSentCnt += TxStaCnt0.field.TxBeaconCount;
34007 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
34008 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
34009 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
34010 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
34011 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
34012 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
34013 + }
34014 +
34015 +#if 0
34016 + Retry = StaTx1.field.TxRetransmit;
34017 + Fail = TxStaCnt0.field.TxFailCount;
34018 + TxErrorRatio = 0;
34019 + OneSecTransmitCount = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart- pAd->WlanCounters.LastTransmittedFragmentCount.u.LowPart;
34020 + if ((OneSecTransmitCount+Retry + Fail) > 0)
34021 + TxErrorRatio = (( Retry + Fail) *100) / (OneSecTransmitCount+Retry + Fail);
34022 +
34023 + if ((OneSecTransmitCount+Retry + Fail) > 0)
34024 + TxErrorRatio = (( Retry + Fail) *100) / (OneSecTransmitCount+Retry + Fail);
34025 + DBGPRINT(RT_DEBUG_INFO, ("TX ERROR Rate = %ld %%, Retry = %ld, Fail = %ld, Total = %ld \n",TxErrorRatio, Retry, Fail, (OneSecTransmitCount+Retry + Fail)));
34026 + pAd->WlanCounters.LastTransmittedFragmentCount.u.LowPart = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart;
34027 +#endif
34028 +
34029 + //if (pAd->bStaFifoTest == TRUE)
34030 + {
34031 + RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word);
34032 + RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word);
34033 + RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word);
34034 + RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word);
34035 + RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word);
34036 + RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word);
34037 + RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word);
34038 + RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word);
34039 + RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word);
34040 + pAd->RalinkCounters.TxAggCount += TxAggCnt.field.AggTxCount;
34041 + pAd->RalinkCounters.TxNonAggCount += TxAggCnt.field.NonAggTxCount;
34042 + pAd->RalinkCounters.TxAgg1MPDUCount += TxAggCnt0.field.AggSize1Count;
34043 + pAd->RalinkCounters.TxAgg2MPDUCount += TxAggCnt0.field.AggSize2Count;
34044 +
34045 + pAd->RalinkCounters.TxAgg3MPDUCount += TxAggCnt1.field.AggSize3Count;
34046 + pAd->RalinkCounters.TxAgg4MPDUCount += TxAggCnt1.field.AggSize4Count;
34047 + pAd->RalinkCounters.TxAgg5MPDUCount += TxAggCnt2.field.AggSize5Count;
34048 + pAd->RalinkCounters.TxAgg6MPDUCount += TxAggCnt2.field.AggSize6Count;
34049 +
34050 + pAd->RalinkCounters.TxAgg7MPDUCount += TxAggCnt3.field.AggSize7Count;
34051 + pAd->RalinkCounters.TxAgg8MPDUCount += TxAggCnt3.field.AggSize8Count;
34052 + pAd->RalinkCounters.TxAgg9MPDUCount += TxAggCnt4.field.AggSize9Count;
34053 + pAd->RalinkCounters.TxAgg10MPDUCount += TxAggCnt4.field.AggSize10Count;
34054 +
34055 + pAd->RalinkCounters.TxAgg11MPDUCount += TxAggCnt5.field.AggSize11Count;
34056 + pAd->RalinkCounters.TxAgg12MPDUCount += TxAggCnt5.field.AggSize12Count;
34057 + pAd->RalinkCounters.TxAgg13MPDUCount += TxAggCnt6.field.AggSize13Count;
34058 + pAd->RalinkCounters.TxAgg14MPDUCount += TxAggCnt6.field.AggSize14Count;
34059 +
34060 + pAd->RalinkCounters.TxAgg15MPDUCount += TxAggCnt7.field.AggSize15Count;
34061 + pAd->RalinkCounters.TxAgg16MPDUCount += TxAggCnt7.field.AggSize16Count;
34062 +
34063 + // Calculate the transmitted A-MPDU count
34064 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += TxAggCnt0.field.AggSize1Count;
34065 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt0.field.AggSize2Count / 2);
34066 +
34067 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize3Count / 3);
34068 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize4Count / 4);
34069 +
34070 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize5Count / 5);
34071 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize6Count / 6);
34072 +
34073 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize7Count / 7);
34074 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize8Count / 8);
34075 +
34076 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize9Count / 9);
34077 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize10Count / 10);
34078 +
34079 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize11Count / 11);
34080 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize12Count / 12);
34081 +
34082 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize13Count / 13);
34083 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize14Count / 14);
34084 +
34085 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize15Count / 15);
34086 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize16Count / 16);
34087 + }
34088 +
34089 +#ifdef DBG_DIAGNOSE
34090 + {
34091 + RtmpDiagStruct *pDiag;
34092 + COUNTER_RALINK *pRalinkCounters;
34093 + UCHAR ArrayCurIdx, i;
34094 +
34095 + pDiag = &pAd->DiagStruct;
34096 + pRalinkCounters = &pAd->RalinkCounters;
34097 + ArrayCurIdx = pDiag->ArrayCurIdx;
34098 +
34099 + if (pDiag->inited == 0)
34100 + {
34101 + NdisZeroMemory(pDiag, sizeof(struct _RtmpDiagStrcut_));
34102 + pDiag->ArrayStartIdx = pDiag->ArrayCurIdx = 0;
34103 + pDiag->inited = 1;
34104 + }
34105 + else
34106 + {
34107 + // Tx
34108 + pDiag->TxFailCnt[ArrayCurIdx] = TxStaCnt0.field.TxFailCount;
34109 + pDiag->TxAggCnt[ArrayCurIdx] = TxAggCnt.field.AggTxCount;
34110 + pDiag->TxNonAggCnt[ArrayCurIdx] = TxAggCnt.field.NonAggTxCount;
34111 + pDiag->TxAMPDUCnt[ArrayCurIdx][0] = TxAggCnt0.field.AggSize1Count;
34112 + pDiag->TxAMPDUCnt[ArrayCurIdx][1] = TxAggCnt0.field.AggSize2Count;
34113 + pDiag->TxAMPDUCnt[ArrayCurIdx][2] = TxAggCnt1.field.AggSize3Count;
34114 + pDiag->TxAMPDUCnt[ArrayCurIdx][3] = TxAggCnt1.field.AggSize4Count;
34115 + pDiag->TxAMPDUCnt[ArrayCurIdx][4] = TxAggCnt2.field.AggSize5Count;
34116 + pDiag->TxAMPDUCnt[ArrayCurIdx][5] = TxAggCnt2.field.AggSize6Count;
34117 + pDiag->TxAMPDUCnt[ArrayCurIdx][6] = TxAggCnt3.field.AggSize7Count;
34118 + pDiag->TxAMPDUCnt[ArrayCurIdx][7] = TxAggCnt3.field.AggSize8Count;
34119 + pDiag->TxAMPDUCnt[ArrayCurIdx][8] = TxAggCnt4.field.AggSize9Count;
34120 + pDiag->TxAMPDUCnt[ArrayCurIdx][9] = TxAggCnt4.field.AggSize10Count;
34121 + pDiag->TxAMPDUCnt[ArrayCurIdx][10] = TxAggCnt5.field.AggSize11Count;
34122 + pDiag->TxAMPDUCnt[ArrayCurIdx][11] = TxAggCnt5.field.AggSize12Count;
34123 + pDiag->TxAMPDUCnt[ArrayCurIdx][12] = TxAggCnt6.field.AggSize13Count;
34124 + pDiag->TxAMPDUCnt[ArrayCurIdx][13] = TxAggCnt6.field.AggSize14Count;
34125 + pDiag->TxAMPDUCnt[ArrayCurIdx][14] = TxAggCnt7.field.AggSize15Count;
34126 + pDiag->TxAMPDUCnt[ArrayCurIdx][15] = TxAggCnt7.field.AggSize16Count;
34127 +
34128 + pDiag->RxCrcErrCnt[ArrayCurIdx] = RxStaCnt0.field.CrcErr;
34129 +
34130 + INC_RING_INDEX(pDiag->ArrayCurIdx, DIAGNOSE_TIME);
34131 + ArrayCurIdx = pDiag->ArrayCurIdx;
34132 + for (i =0; i < 9; i++)
34133 + {
34134 + pDiag->TxDescCnt[ArrayCurIdx][i]= 0;
34135 + pDiag->TxSWQueCnt[ArrayCurIdx][i] =0;
34136 + pDiag->TxMcsCnt[ArrayCurIdx][i] = 0;
34137 + pDiag->RxMcsCnt[ArrayCurIdx][i] = 0;
34138 + }
34139 + pDiag->TxDataCnt[ArrayCurIdx] = 0;
34140 + pDiag->TxFailCnt[ArrayCurIdx] = 0;
34141 + pDiag->RxDataCnt[ArrayCurIdx] = 0;
34142 + pDiag->RxCrcErrCnt[ArrayCurIdx] = 0;
34143 +// for (i = 9; i < 16; i++)
34144 + for (i = 9; i < 24; i++) // 3*3
34145 + {
34146 + pDiag->TxDescCnt[ArrayCurIdx][i] = 0;
34147 + pDiag->TxMcsCnt[ArrayCurIdx][i] = 0;
34148 + pDiag->RxMcsCnt[ArrayCurIdx][i] = 0;
34149 +}
34150 +
34151 + if (pDiag->ArrayCurIdx == pDiag->ArrayStartIdx)
34152 + INC_RING_INDEX(pDiag->ArrayStartIdx, DIAGNOSE_TIME);
34153 + }
34154 +
34155 + }
34156 +#endif // DBG_DIAGNOSE //
34157 +
34158 +
34159 +}
34160 +
34161 +
34162 +/*
34163 + ========================================================================
34164 +
34165 + Routine Description:
34166 + Reset NIC from error
34167 +
34168 + Arguments:
34169 + Adapter Pointer to our adapter
34170 +
34171 + Return Value:
34172 + None
34173 +
34174 + IRQL = PASSIVE_LEVEL
34175 +
34176 + Note:
34177 + Reset NIC from error state
34178 +
34179 + ========================================================================
34180 +*/
34181 +VOID NICResetFromError(
34182 + IN PRTMP_ADAPTER pAd)
34183 +{
34184 + // Reset BBP (according to alex, reset ASIC will force reset BBP
34185 + // Therefore, skip the reset BBP
34186 + // RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2);
34187 +
34188 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
34189 + // Remove ASIC from reset state
34190 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
34191 +
34192 + NICInitializeAdapter(pAd, FALSE);
34193 + NICInitAsicFromEEPROM(pAd);
34194 +
34195 + // Switch to current channel, since during reset process, the connection should remains on.
34196 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
34197 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
34198 +}
34199 +
34200 +/*
34201 + ========================================================================
34202 +
34203 + Routine Description:
34204 + erase 8051 firmware image in MAC ASIC
34205 +
34206 + Arguments:
34207 + Adapter Pointer to our adapter
34208 +
34209 + IRQL = PASSIVE_LEVEL
34210 +
34211 + ========================================================================
34212 +*/
34213 +VOID NICEraseFirmware(
34214 + IN PRTMP_ADAPTER pAd)
34215 +{
34216 + ULONG i;
34217 +
34218 + for(i=0; i<MAX_FIRMWARE_IMAGE_SIZE; i+=4)
34219 + RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, 0);
34220 +
34221 +}/* End of NICEraseFirmware */
34222 +
34223 +/*
34224 + ========================================================================
34225 +
34226 + Routine Description:
34227 + Load 8051 firmware RT2561.BIN file into MAC ASIC
34228 +
34229 + Arguments:
34230 + Adapter Pointer to our adapter
34231 +
34232 + Return Value:
34233 + NDIS_STATUS_SUCCESS firmware image load ok
34234 + NDIS_STATUS_FAILURE image not found
34235 +
34236 + IRQL = PASSIVE_LEVEL
34237 +
34238 + ========================================================================
34239 +*/
34240 +NDIS_STATUS NICLoadFirmware(
34241 + IN PRTMP_ADAPTER pAd)
34242 +{
34243 +#ifdef BIN_IN_FILE
34244 +#define NICLF_DEFAULT_USE() \
34245 + flg_default_firm_use = TRUE; \
34246 + printk("%s - Use default firmware!\n", __FUNCTION__);
34247 +
34248 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
34249 + PUCHAR src;
34250 + struct file *srcf;
34251 + INT retval, orgfsuid, orgfsgid, i;
34252 + mm_segment_t orgfs;
34253 + PUCHAR pFirmwareImage;
34254 + UINT FileLength = 0;
34255 + UINT32 MacReg;
34256 + ULONG Index;
34257 + ULONG firm;
34258 + BOOLEAN flg_default_firm_use = FALSE;
34259 +
34260 +
34261 + DBGPRINT(RT_DEBUG_TRACE, ("===> %s\n", __FUNCTION__));
34262 +
34263 + /* init */
34264 + pFirmwareImage = NULL;
34265 + src = RTMP_FIRMWARE_FILE_NAME;
34266 +
34267 + /* save uid and gid used for filesystem access.
34268 + set user and group to 0 (root) */
34269 + orgfsuid = current->fsuid;
34270 + orgfsgid = current->fsgid;
34271 + current->fsuid = current->fsgid = 0;
34272 + orgfs = get_fs();
34273 + set_fs(KERNEL_DS);
34274 +
34275 + pAd->FirmwareVersion = (FIRMWARE_MAJOR_VERSION << 8) + \
34276 + FIRMWARE_MINOR_VERSION;
34277 +
34278 +
34279 + /* allocate firmware buffer */
34280 + pFirmwareImage = kmalloc(MAX_FIRMWARE_IMAGE_SIZE, MEM_ALLOC_FLAG);
34281 + if (pFirmwareImage == NULL)
34282 + {
34283 + /* allocate fail, use default firmware array in firmware.h */
34284 + printk("%s - Allocate memory fail!\n", __FUNCTION__);
34285 + NICLF_DEFAULT_USE();
34286 + }
34287 + else
34288 + {
34289 + /* allocate ok! zero the firmware buffer */
34290 + memset(pFirmwareImage, 0x00, MAX_FIRMWARE_IMAGE_SIZE);
34291 + } /* End of if */
34292 +
34293 +
34294 + /* if ok, read firmware file from *.bin file */
34295 + if (flg_default_firm_use == FALSE)
34296 + {
34297 + do
34298 + {
34299 + /* open the bin file */
34300 + srcf = filp_open(src, O_RDONLY, 0);
34301 +
34302 + if (IS_ERR(srcf))
34303 + {
34304 + printk("%s - Error %ld opening %s\n",
34305 + __FUNCTION__, -PTR_ERR(srcf), src);
34306 + NICLF_DEFAULT_USE();
34307 + break;
34308 + } /* End of if */
34309 +
34310 + /* the object must have a read method */
34311 + if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
34312 + {
34313 + printk("%s - %s does not have a write method\n", __FUNCTION__, src);
34314 + NICLF_DEFAULT_USE();
34315 + break;
34316 + } /* End of if */
34317 +
34318 + /* read the firmware from the file *.bin */
34319 + FileLength = srcf->f_op->read(srcf,
34320 + pFirmwareImage,
34321 + MAX_FIRMWARE_IMAGE_SIZE,
34322 + &srcf->f_pos);
34323 +
34324 + if (FileLength != MAX_FIRMWARE_IMAGE_SIZE)
34325 + {
34326 + printk("%s: error file length (=%d) in RT2860AP.BIN\n",
34327 + __FUNCTION__, FileLength);
34328 + NICLF_DEFAULT_USE();
34329 + break;
34330 + }
34331 + else
34332 + {
34333 + PUCHAR ptr = pFirmwareImage;
34334 + USHORT crc = 0xffff;
34335 +
34336 +
34337 + /* calculate firmware CRC */
34338 + for(i=0; i<(MAX_FIRMWARE_IMAGE_SIZE-2); i++, ptr++)
34339 + crc = ByteCRC16(BitReverse(*ptr), crc);
34340 + /* End of for */
34341 +
34342 + if ((pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-2] != \
34343 + (UCHAR)BitReverse((UCHAR)(crc>>8))) ||
34344 + (pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-1] != \
34345 + (UCHAR)BitReverse((UCHAR)crc)))
34346 + {
34347 + /* CRC fail */
34348 + printk("%s: CRC = 0x%02x 0x%02x "
34349 + "error, should be 0x%02x 0x%02x\n",
34350 + __FUNCTION__,
34351 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-2],
34352 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-1],
34353 + (UCHAR)(crc>>8), (UCHAR)(crc));
34354 + NICLF_DEFAULT_USE();
34355 + break;
34356 + }
34357 + else
34358 + {
34359 + /* firmware is ok */
34360 + pAd->FirmwareVersion = \
34361 + (pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-4] << 8) +
34362 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-3];
34363 +
34364 + /* check if firmware version of the file is too old */
34365 + if ((pAd->FirmwareVersion) < \
34366 + ((FIRMWARE_MAJOR_VERSION << 8) +
34367 + FIRMWARE_MINOR_VERSION))
34368 + {
34369 + printk("%s: firmware version too old!\n", __FUNCTION__);
34370 + NICLF_DEFAULT_USE();
34371 + break;
34372 + } /* End of if */
34373 + } /* End of if */
34374 +
34375 + DBGPRINT(RT_DEBUG_TRACE,
34376 + ("NICLoadFirmware: CRC ok, ver=%d.%d\n",
34377 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-4],
34378 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-3]));
34379 + } /* End of if (FileLength == MAX_FIRMWARE_IMAGE_SIZE) */
34380 + break;
34381 + } while(TRUE);
34382 +
34383 + /* close firmware file */
34384 + if (IS_ERR(srcf))
34385 + ;
34386 + else
34387 + {
34388 + retval = filp_close(srcf, NULL);
34389 + if (retval)
34390 + {
34391 + DBGPRINT(RT_DEBUG_ERROR,
34392 + ("--> Error %d closing %s\n", -retval, src));
34393 + } /* End of if */
34394 + } /* End of if */
34395 + } /* End of if */
34396 +
34397 +
34398 + /* write firmware to ASIC */
34399 + if (flg_default_firm_use == TRUE)
34400 + {
34401 + /* use default fimeware, free allocated buffer */
34402 + if (pFirmwareImage != NULL)
34403 + kfree(pFirmwareImage);
34404 + /* End of if */
34405 +
34406 + /* use default *.bin array */
34407 + pFirmwareImage = FirmwareImage;
34408 + FileLength = sizeof(FirmwareImage);
34409 + } /* End of if */
34410 +
34411 + /* enable Host program ram write selection */
34412 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x10000);
34413 +
34414 + for(i=0; i<FileLength; i+=4)
34415 + {
34416 + firm = pFirmwareImage[i] +
34417 + (pFirmwareImage[i+3] << 24) +
34418 + (pFirmwareImage[i+2] << 16) +
34419 + (pFirmwareImage[i+1] << 8);
34420 +
34421 + RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, firm);
34422 + } /* End of for */
34423 +
34424 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x00000);
34425 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x00001);
34426 +
34427 + /* initialize BBP R/W access agent */
34428 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0);
34429 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
34430 +
34431 + if (flg_default_firm_use == FALSE)
34432 + {
34433 + /* use file firmware, free allocated buffer */
34434 + if (pFirmwareImage != NULL)
34435 + kfree(pFirmwareImage);
34436 + /* End of if */
34437 + } /* End of if */
34438 +
34439 + set_fs(orgfs);
34440 + current->fsuid = orgfsuid;
34441 + current->fsgid = orgfsgid;
34442 +#else
34443 +
34444 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
34445 + PUCHAR pFirmwareImage;
34446 + ULONG FileLength, Index;
34447 + //ULONG firm;
34448 + UINT32 MacReg = 0;
34449 +#ifdef RT2870
34450 + UINT32 Version = (pAd->MACVersion >> 16);
34451 +#endif // RT2870 //
34452 +
34453 + pFirmwareImage = FirmwareImage;
34454 + FileLength = sizeof(FirmwareImage);
34455 +#ifdef RT2870
34456 + // New 8k byte firmware size for RT3071/RT3072
34457 + //printk("Usb Chip\n");
34458 + if (FIRMWAREIMAGE_LENGTH == FIRMWAREIMAGE_MAX_LENGTH)
34459 + //The firmware image consists of two parts. One is the origianl and the other is the new.
34460 + //Use Second Part
34461 + {
34462 + if ((Version != 0x2860) && (Version != 0x2872) && (Version != 0x3070))
34463 + { // Use Firmware V2.
34464 + //printk("KH:Use New Version,part2\n");
34465 + pFirmwareImage = (PUCHAR)&FirmwareImage[FIRMWAREIMAGEV1_LENGTH];
34466 + FileLength = FIRMWAREIMAGEV2_LENGTH;
34467 + }
34468 + else
34469 + {
34470 + //printk("KH:Use New Version,part1\n");
34471 + pFirmwareImage = FirmwareImage;
34472 + FileLength = FIRMWAREIMAGEV1_LENGTH;
34473 + }
34474 + }
34475 + else
34476 + {
34477 + DBGPRINT(RT_DEBUG_ERROR, ("KH: bin file should be 8KB.\n"));
34478 + Status = NDIS_STATUS_FAILURE;
34479 + }
34480 +
34481 +#endif // RT2870 //
34482 +
34483 +#if 0
34484 + /* enable Host program ram write selection */
34485 + RT28XX_FIRMUD_INIT(pAd);
34486 +
34487 + for(i=0; i<FileLength; i+=4)
34488 + {
34489 + firm = pFirmwareImage[i] +
34490 + (pFirmwareImage[i+3] << 24) +
34491 + (pFirmwareImage[i+2] << 16) +
34492 + (pFirmwareImage[i+1] << 8);
34493 +
34494 + RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, firm);
34495 + } /* End of for */
34496 +
34497 + RT28XX_FIRMUD_END(pAd);
34498 +#else
34499 + RT28XX_WRITE_FIRMWARE(pAd, pFirmwareImage, FileLength);
34500 +#endif
34501 +
34502 +#endif
34503 +
34504 + /* check if MCU is ready */
34505 + Index = 0;
34506 + do
34507 + {
34508 + RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacReg);
34509 +
34510 + if (MacReg & 0x80)
34511 + break;
34512 +
34513 + RTMPusecDelay(1000);
34514 + } while (Index++ < 1000);
34515 +
34516 + if (Index >= 1000)
34517 + {
34518 + Status = NDIS_STATUS_FAILURE;
34519 + DBGPRINT(RT_DEBUG_ERROR, ("NICLoadFirmware: MCU is not ready\n\n\n"));
34520 + } /* End of if */
34521 +
34522 +#if 0
34523 + DBGPRINT(RT_DEBUG_TRACE,
34524 + ("<=== %s (src=%s, status=%d)\n", __FUNCTION__, src, Status));
34525 +#else
34526 + DBGPRINT(RT_DEBUG_TRACE,
34527 + ("<=== %s (status=%d)\n", __FUNCTION__, Status));
34528 +#endif
34529 + return Status;
34530 +} /* End of NICLoadFirmware */
34531 +
34532 +
34533 +/*
34534 + ========================================================================
34535 +
34536 + Routine Description:
34537 + Load Tx rate switching parameters
34538 +
34539 + Arguments:
34540 + Adapter Pointer to our adapter
34541 +
34542 + Return Value:
34543 + NDIS_STATUS_SUCCESS firmware image load ok
34544 + NDIS_STATUS_FAILURE image not found
34545 +
34546 + IRQL = PASSIVE_LEVEL
34547 +
34548 + Rate Table Format:
34549 + 1. (B0: Valid Item number) (B1:Initial item from zero)
34550 + 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec)
34551 +
34552 + ========================================================================
34553 +*/
34554 +NDIS_STATUS NICLoadRateSwitchingParams(
34555 + IN PRTMP_ADAPTER pAd)
34556 +{
34557 +#if 0
34558 + NDIS_STATUS Status;
34559 +
34560 + NDIS_HANDLE FileHandle;
34561 + UINT FileLength = 0, i, j;
34562 + PUCHAR pFirmwareImage;
34563 + NDIS_STRING FileName;
34564 + NDIS_PHYSICAL_ADDRESS HighestAcceptableMax = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);
34565 +
34566 + DBGPRINT(RT_DEBUG_TRACE,("===> NICLoadRateSwitchingParams \n"));
34567 + pAd->CommonCfg.TxRateTableSize = 0;
34568 +
34569 + if ((pAd->DeviceID == NIC2860_PCI_DEVICE_ID) || (pAd->DeviceID == NIC2860_PCIe_DEVICE_ID))
34570 + {
34571 + NdisInitializeString(&FileName,"rate.bin");
34572 + DBGPRINT(RT_DEBUG_TRACE, ("NICLoadRateSwitchingParams: load file - rate.bin for tx rate switch \n"));
34573 + }
34574 + else
34575 + {
34576 + DBGPRINT_ERR(("NICLoadRateSwitchingParams: wrong DeviceID = 0x%04x, can't find Tx rate switch parameters file\n", pAd->DeviceID));
34577 + return NDIS_STATUS_SUCCESS;
34578 + }
34579 + NdisOpenFile(&Status, &FileHandle, &FileLength, &FileName, HighestAcceptableMax);
34580 + NdisFreeString(FileName);
34581 +
34582 + if (Status != NDIS_STATUS_SUCCESS)
34583 + {
34584 + DBGPRINT(RT_DEBUG_ERROR, ("NICLoadRateSwitchingParams: NdisOpenFile() failed, used RateSwitchTable instead\n"));
34585 + return NDIS_STATUS_SUCCESS;
34586 + }
34587 +
34588 + if ((FileLength == 0) || (FileLength > (MAX_STEP_OF_TX_RATE_SWITCH+1)*16))
34589 + {
34590 + DBGPRINT(RT_DEBUG_ERROR, ("NICLoadRateSwitchingParams: file size is not reasonable, used RateSwitchTable instead\n"));
34591 +
34592 + NdisCloseFile(FileHandle);
34593 + return NDIS_STATUS_SUCCESS;
34594 + }
34595 + else
34596 + {
34597 + //
34598 + // NDIS_STATUS_SUCCESS means
34599 + // The handle at FileHandle is valid for a subsequent call to NdisMapFile.
34600 + //
34601 + NdisMapFile(&Status, &pFirmwareImage, FileHandle);
34602 + DBGPRINT(RT_DEBUG_TRACE, ("NdisMapFile FileLength=%d\n", FileLength));
34603 + }
34604 +
34605 + for (i=0, j=0; i<FileLength; i++)
34606 + {
34607 + if ((i%16) <= 4) // trim reserved field
34608 + {
34609 + if (i%16 == 1) // deal with DEC and HEX, only row0 is Hex, others are Dec
34610 + {
34611 + RateSwitchTable[j] = *(pFirmwareImage + i);
34612 + }
34613 + else
34614 + {
34615 + RateSwitchTable[j] = (*(pFirmwareImage + i)>>4) * 10 + (*(pFirmwareImage + i) & 0x0F);
34616 + }
34617 +
34618 + j++;
34619 + }
34620 + }
34621 +
34622 + pAd->CommonCfg.TxRateTableSize = RateSwitchTable[0]; // backup table size
34623 +
34624 + if (Status == NDIS_STATUS_SUCCESS)
34625 + {
34626 + NdisUnmapFile(FileHandle);
34627 + NdisCloseFile(FileHandle);
34628 + }
34629 +
34630 + DBGPRINT(RT_DEBUG_TRACE,("<=== NICLoadRateSwitchingParams(Valid TxRateTable item number=%d)\n", pAd->CommonCfg.TxRateTableSize));
34631 +#endif
34632 + return NDIS_STATUS_SUCCESS;
34633 +}
34634 +
34635 +/*
34636 + ========================================================================
34637 +
34638 + Routine Description:
34639 + if pSrc1 all zero with length Length, return 0.
34640 + If not all zero, return 1
34641 +
34642 + Arguments:
34643 + pSrc1
34644 +
34645 + Return Value:
34646 + 1: not all zero
34647 + 0: all zero
34648 +
34649 + IRQL = DISPATCH_LEVEL
34650 +
34651 + Note:
34652 +
34653 + ========================================================================
34654 +*/
34655 +ULONG RTMPNotAllZero(
34656 + IN PVOID pSrc1,
34657 + IN ULONG Length)
34658 +{
34659 + PUCHAR pMem1;
34660 + ULONG Index = 0;
34661 +
34662 + pMem1 = (PUCHAR) pSrc1;
34663 +
34664 + for (Index = 0; Index < Length; Index++)
34665 + {
34666 + if (pMem1[Index] != 0x0)
34667 + {
34668 + break;
34669 + }
34670 + }
34671 +
34672 + if (Index == Length)
34673 + {
34674 + return (0);
34675 + }
34676 + else
34677 + {
34678 + return (1);
34679 + }
34680 +}
34681 +
34682 +/*
34683 + ========================================================================
34684 +
34685 + Routine Description:
34686 + Compare two memory block
34687 +
34688 + Arguments:
34689 + pSrc1 Pointer to first memory address
34690 + pSrc2 Pointer to second memory address
34691 +
34692 + Return Value:
34693 + 0: memory is equal
34694 + 1: pSrc1 memory is larger
34695 + 2: pSrc2 memory is larger
34696 +
34697 + IRQL = DISPATCH_LEVEL
34698 +
34699 + Note:
34700 +
34701 + ========================================================================
34702 +*/
34703 +ULONG RTMPCompareMemory(
34704 + IN PVOID pSrc1,
34705 + IN PVOID pSrc2,
34706 + IN ULONG Length)
34707 +{
34708 + PUCHAR pMem1;
34709 + PUCHAR pMem2;
34710 + ULONG Index = 0;
34711 +
34712 + pMem1 = (PUCHAR) pSrc1;
34713 + pMem2 = (PUCHAR) pSrc2;
34714 +
34715 + for (Index = 0; Index < Length; Index++)
34716 + {
34717 + if (pMem1[Index] > pMem2[Index])
34718 + return (1);
34719 + else if (pMem1[Index] < pMem2[Index])
34720 + return (2);
34721 + }
34722 +
34723 + // Equal
34724 + return (0);
34725 +}
34726 +
34727 +/*
34728 + ========================================================================
34729 +
34730 + Routine Description:
34731 + Zero out memory block
34732 +
34733 + Arguments:
34734 + pSrc1 Pointer to memory address
34735 + Length Size
34736 +
34737 + Return Value:
34738 + None
34739 +
34740 + IRQL = PASSIVE_LEVEL
34741 + IRQL = DISPATCH_LEVEL
34742 +
34743 + Note:
34744 +
34745 + ========================================================================
34746 +*/
34747 +VOID RTMPZeroMemory(
34748 + IN PVOID pSrc,
34749 + IN ULONG Length)
34750 +{
34751 + PUCHAR pMem;
34752 + ULONG Index = 0;
34753 +
34754 + pMem = (PUCHAR) pSrc;
34755 +
34756 + for (Index = 0; Index < Length; Index++)
34757 + {
34758 + pMem[Index] = 0x00;
34759 + }
34760 +}
34761 +
34762 +VOID RTMPFillMemory(
34763 + IN PVOID pSrc,
34764 + IN ULONG Length,
34765 + IN UCHAR Fill)
34766 +{
34767 + PUCHAR pMem;
34768 + ULONG Index = 0;
34769 +
34770 + pMem = (PUCHAR) pSrc;
34771 +
34772 + for (Index = 0; Index < Length; Index++)
34773 + {
34774 + pMem[Index] = Fill;
34775 + }
34776 +}
34777 +
34778 +/*
34779 + ========================================================================
34780 +
34781 + Routine Description:
34782 + Copy data from memory block 1 to memory block 2
34783 +
34784 + Arguments:
34785 + pDest Pointer to destination memory address
34786 + pSrc Pointer to source memory address
34787 + Length Copy size
34788 +
34789 + Return Value:
34790 + None
34791 +
34792 + IRQL = PASSIVE_LEVEL
34793 + IRQL = DISPATCH_LEVEL
34794 +
34795 + Note:
34796 +
34797 + ========================================================================
34798 +*/
34799 +VOID RTMPMoveMemory(
34800 + OUT PVOID pDest,
34801 + IN PVOID pSrc,
34802 + IN ULONG Length)
34803 +{
34804 + PUCHAR pMem1;
34805 + PUCHAR pMem2;
34806 + UINT Index;
34807 +
34808 + ASSERT((Length==0) || (pDest && pSrc));
34809 +
34810 + pMem1 = (PUCHAR) pDest;
34811 + pMem2 = (PUCHAR) pSrc;
34812 +
34813 + for (Index = 0; Index < Length; Index++)
34814 + {
34815 + pMem1[Index] = pMem2[Index];
34816 + }
34817 +}
34818 +
34819 +/*
34820 + ========================================================================
34821 +
34822 + Routine Description:
34823 + Initialize port configuration structure
34824 +
34825 + Arguments:
34826 + Adapter Pointer to our adapter
34827 +
34828 + Return Value:
34829 + None
34830 +
34831 + IRQL = PASSIVE_LEVEL
34832 +
34833 + Note:
34834 +
34835 + ========================================================================
34836 +*/
34837 +VOID UserCfgInit(
34838 + IN PRTMP_ADAPTER pAd)
34839 +{
34840 +// EDCA_PARM DefaultEdcaParm;
34841 + UINT key_index, bss_index;
34842 +
34843 + DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n"));
34844 +
34845 + //
34846 + // part I. intialize common configuration
34847 + //
34848 +#ifdef RT2870
34849 + pAd->BulkOutReq = 0;
34850 +
34851 + pAd->BulkOutComplete = 0;
34852 + pAd->BulkOutCompleteOther = 0;
34853 + pAd->BulkOutCompleteCancel = 0;
34854 + pAd->BulkInReq = 0;
34855 + pAd->BulkInComplete = 0;
34856 + pAd->BulkInCompleteFail = 0;
34857 +
34858 + //pAd->QuickTimerP = 100;
34859 + //pAd->TurnAggrBulkInCount = 0;
34860 + pAd->bUsbTxBulkAggre = 0;
34861 +
34862 + // init as unsed value to ensure driver will set to MCU once.
34863 + pAd->LedIndicatorStregth = 0xFF;
34864 +
34865 + pAd->CommonCfg.MaxPktOneTxBulk = 2;
34866 + pAd->CommonCfg.TxBulkFactor = 1;
34867 + pAd->CommonCfg.RxBulkFactor =1;
34868 +
34869 + pAd->CommonCfg.TxPower = 100; //mW
34870 +
34871 + NdisZeroMemory(&pAd->CommonCfg.IOTestParm, sizeof(pAd->CommonCfg.IOTestParm));
34872 +#endif // RT2870 //
34873 +
34874 + for(key_index=0; key_index<SHARE_KEY_NUM; key_index++)
34875 + {
34876 + for(bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++)
34877 + {
34878 + pAd->SharedKey[bss_index][key_index].KeyLen = 0;
34879 + pAd->SharedKey[bss_index][key_index].CipherAlg = CIPHER_NONE;
34880 + }
34881 + }
34882 +
34883 + pAd->Antenna.word = 0;
34884 + pAd->CommonCfg.BBPCurrentBW = BW_20;
34885 +
34886 + pAd->LedCntl.word = 0;
34887 +
34888 + pAd->bAutoTxAgcA = FALSE; // Default is OFF
34889 + pAd->bAutoTxAgcG = FALSE; // Default is OFF
34890 + pAd->RfIcType = RFIC_2820;
34891 +
34892 + // Init timer for reset complete event
34893 + pAd->CommonCfg.CentralChannel = 1;
34894 + pAd->bForcePrintTX = FALSE;
34895 + pAd->bForcePrintRX = FALSE;
34896 + pAd->bStaFifoTest = FALSE;
34897 + pAd->bProtectionTest = FALSE;
34898 + pAd->bHCCATest = FALSE;
34899 + pAd->bGenOneHCCA = FALSE;
34900 + pAd->CommonCfg.Dsifs = 10; // in units of usec
34901 + pAd->CommonCfg.TxPower = 100; //mW
34902 + pAd->CommonCfg.TxPowerPercentage = 0xffffffff; // AUTO
34903 + pAd->CommonCfg.TxPowerDefault = 0xffffffff; // AUTO
34904 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; // use Long preamble on TX by defaut
34905 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
34906 + pAd->CommonCfg.RtsThreshold = 2347;
34907 + pAd->CommonCfg.FragmentThreshold = 2346;
34908 + pAd->CommonCfg.UseBGProtection = 0; // 0: AUTO
34909 + pAd->CommonCfg.bEnableTxBurst = TRUE; //0;
34910 + pAd->CommonCfg.PhyMode = 0xff; // unknown
34911 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
34912 + pAd->CommonCfg.RadarDetect.CSPeriod = 10;
34913 + pAd->CommonCfg.RadarDetect.CSCount = 0;
34914 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
34915 + pAd->CommonCfg.RadarDetect.ChMovingTime = 65;
34916 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3;
34917 + pAd->CommonCfg.bAPSDCapable = FALSE;
34918 + pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
34919 + pAd->CommonCfg.TriggerTimerCount = 0;
34920 + pAd->CommonCfg.bAPSDForcePowerSave = FALSE;
34921 + pAd->CommonCfg.bCountryFlag = FALSE;
34922 + pAd->CommonCfg.TxStream = 0;
34923 + pAd->CommonCfg.RxStream = 0;
34924 +
34925 + NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI));
34926 +
34927 +#ifdef DOT11_N_SUPPORT
34928 + NdisZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
34929 + pAd->HTCEnable = FALSE;
34930 + pAd->bBroadComHT = FALSE;
34931 + pAd->CommonCfg.bRdg = FALSE;
34932 +
34933 +#ifdef DOT11N_DRAFT3
34934 + pAd->CommonCfg.Dot11OBssScanPassiveDwell = dot11OBSSScanPassiveDwell; // Unit : TU. 5~1000
34935 + pAd->CommonCfg.Dot11OBssScanActiveDwell = dot11OBSSScanActiveDwell; // Unit : TU. 10~1000
34936 + pAd->CommonCfg.Dot11BssWidthTriggerScanInt = dot11BSSWidthTriggerScanInterval; // Unit : Second
34937 + pAd->CommonCfg.Dot11OBssScanPassiveTotalPerChannel = dot11OBSSScanPassiveTotalPerChannel; // Unit : TU. 200~10000
34938 + pAd->CommonCfg.Dot11OBssScanActiveTotalPerChannel = dot11OBSSScanActiveTotalPerChannel; // Unit : TU. 20~10000
34939 + pAd->CommonCfg.Dot11BssWidthChanTranDelayFactor = dot11BSSWidthChannelTransactionDelayFactor;
34940 + pAd->CommonCfg.Dot11OBssScanActivityThre = dot11BSSScanActivityThreshold; // Unit : percentage
34941 + pAd->CommonCfg.Dot11BssWidthChanTranDelay = (pAd->CommonCfg.Dot11BssWidthTriggerScanInt * pAd->CommonCfg.Dot11BssWidthChanTranDelayFactor);
34942 +#endif // DOT11N_DRAFT3 //
34943 +
34944 + NdisZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
34945 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
34946 + pAd->CommonCfg.BACapability.field.MpduDensity = 0;
34947 + pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
34948 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; //32;
34949 + pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; //32;
34950 + DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit. BACapability = 0x%x\n", pAd->CommonCfg.BACapability.word));
34951 +
34952 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
34953 + BATableInit(pAd, &pAd->BATable);
34954 +
34955 + pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1;
34956 + pAd->CommonCfg.bHTProtect = 1;
34957 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
34958 + pAd->CommonCfg.bBADecline = FALSE;
34959 + pAd->CommonCfg.bDisableReordering = FALSE;
34960 +
34961 + pAd->CommonCfg.TxBASize = 7;
34962 +
34963 + pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word;
34964 +#endif // DOT11_N_SUPPORT //
34965 +
34966 + //pAd->CommonCfg.HTPhyMode.field.BW = BW_20;
34967 + //pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO;
34968 + //pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800;
34969 + //pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE;
34970 + pAd->CommonCfg.TxRate = RATE_6;
34971 +
34972 + pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6;
34973 + pAd->CommonCfg.MlmeTransmit.field.BW = BW_20;
34974 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
34975 +
34976 + pAd->CommonCfg.BeaconPeriod = 100; // in mSec
34977 +
34978 + //
34979 + // part II. intialize STA specific configuration
34980 + //
34981 +#ifdef CONFIG_STA_SUPPORT
34982 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34983 + {
34984 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT);
34985 + RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST);
34986 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST);
34987 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST);
34988 +
34989 + pAd->StaCfg.Psm = PWR_ACTIVE;
34990 +
34991 + pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled;
34992 + pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled;
34993 + pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled;
34994 + pAd->StaCfg.bMixCipher = FALSE;
34995 + pAd->StaCfg.DefaultKeyId = 0;
34996 +
34997 + // 802.1x port control
34998 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
34999 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
35000 + pAd->StaCfg.LastMicErrorTime = 0;
35001 + pAd->StaCfg.MicErrCnt = 0;
35002 + pAd->StaCfg.bBlockAssoc = FALSE;
35003 + pAd->StaCfg.WpaState = SS_NOTUSE;
35004 +
35005 + pAd->CommonCfg.NdisRadioStateOff = FALSE; // New to support microsoft disable radio with OID command
35006 +
35007 + pAd->StaCfg.RssiTrigger = 0;
35008 + NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(RSSI_SAMPLE));
35009 + pAd->StaCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
35010 + pAd->StaCfg.AtimWin = 0;
35011 + pAd->StaCfg.DefaultListenCount = 3;//default listen count;
35012 + pAd->StaCfg.BssType = BSS_INFRA; // BSS_INFRA or BSS_ADHOC or BSS_MONITOR
35013 + pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
35014 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
35015 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
35016 +
35017 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
35018 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
35019 + }
35020 +
35021 +#ifdef EXT_BUILD_CHANNEL_LIST
35022 + pAd->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
35023 +#endif // EXT_BUILD_CHANNEL_LIST //
35024 +#endif // CONFIG_STA_SUPPORT //
35025 +
35026 + // global variables mXXXX used in MAC protocol state machines
35027 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
35028 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
35029 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
35030 +
35031 + // PHY specification
35032 + pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; // default PHY mode
35033 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); // CCK use LONG preamble
35034 +
35035 +#ifdef CONFIG_STA_SUPPORT
35036 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
35037 + {
35038 + // user desired power mode
35039 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
35040 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
35041 + pAd->StaCfg.bWindowsACCAMEnable = FALSE;
35042 +
35043 +#ifdef LEAP_SUPPORT
35044 + // CCX v1.0 releated init value
35045 + RTMPInitTimer(pAd, &pAd->StaCfg.LeapAuthTimer, GET_TIMER_FUNCTION(LeapAuthTimeout), pAd, FALSE);
35046 + pAd->StaCfg.LeapAuthMode = CISCO_AuthModeLEAPNone;
35047 + pAd->StaCfg.bCkipOn = FALSE;
35048 +#endif // LEAP_SUPPORT //
35049 +
35050 + RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer, GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec), pAd, FALSE);
35051 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
35052 +
35053 + // Patch for Ndtest
35054 + pAd->StaCfg.ScanCnt = 0;
35055 +
35056 + // CCX 2.0 control flag init
35057 + pAd->StaCfg.CCXEnable = FALSE;
35058 + pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED;
35059 + pAd->StaCfg.CCXQosECWMin = 4;
35060 + pAd->StaCfg.CCXQosECWMax = 10;
35061 +
35062 + pAd->StaCfg.bHwRadio = TRUE; // Default Hardware Radio status is On
35063 + pAd->StaCfg.bSwRadio = TRUE; // Default Software Radio status is On
35064 + pAd->StaCfg.bRadio = TRUE; // bHwRadio && bSwRadio
35065 + pAd->StaCfg.bHardwareRadio = FALSE; // Default is OFF
35066 + pAd->StaCfg.bShowHiddenSSID = FALSE; // Default no show
35067 +
35068 + // Nitro mode control
35069 + pAd->StaCfg.bAutoReconnect = TRUE;
35070 +
35071 + // Save the init time as last scan time, the system should do scan after 2 seconds.
35072 + // This patch is for driver wake up from standby mode, system will do scan right away.
35073 + pAd->StaCfg.LastScanTime = 0;
35074 + NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE+1);
35075 + sprintf(pAd->nickname, "%s", STA_NIC_DEVICE_NAME);
35076 + RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer, GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc), pAd, FALSE);
35077 +#ifdef WPA_SUPPLICANT_SUPPORT
35078 + pAd->StaCfg.IEEE8021X = FALSE;
35079 + pAd->StaCfg.IEEE8021x_required_keys = FALSE;
35080 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
35081 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
35082 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
35083 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
35084 +#endif // WPA_SUPPLICANT_SUPPORT //
35085 +
35086 + }
35087 +#endif // CONFIG_STA_SUPPORT //
35088 +
35089 + // Default for extra information is not valid
35090 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
35091 +
35092 + // Default Config change flag
35093 + pAd->bConfigChanged = FALSE;
35094 +
35095 + //
35096 + // part III. AP configurations
35097 + //
35098 +
35099 +
35100 + //
35101 + // part IV. others
35102 + //
35103 + // dynamic BBP R66:sensibity tuning to overcome background noise
35104 + pAd->BbpTuning.bEnable = TRUE;
35105 + pAd->BbpTuning.FalseCcaLowerThreshold = 100;
35106 + pAd->BbpTuning.FalseCcaUpperThreshold = 512;
35107 + pAd->BbpTuning.R66Delta = 4;
35108 + pAd->Mlme.bEnableAutoAntennaCheck = TRUE;
35109 +
35110 + //
35111 + // Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value.
35112 + // if not initial this value, the default value will be 0.
35113 + //
35114 + pAd->BbpTuning.R66CurrentValue = 0x38;
35115 +
35116 + pAd->Bbp94 = BBPR94_DEFAULT;
35117 + pAd->BbpForCCK = FALSE;
35118 +
35119 + // Default is FALSE for test bit 1
35120 + //pAd->bTest1 = FALSE;
35121 +
35122 + // initialize MAC table and allocate spin lock
35123 + NdisZeroMemory(&pAd->MacTab, sizeof(MAC_TABLE));
35124 + InitializeQueueHeader(&pAd->MacTab.McastPsQueue);
35125 + NdisAllocateSpinLock(&pAd->MacTabLock);
35126 +
35127 + //RTMPInitTimer(pAd, &pAd->RECBATimer, RECBATimerTimeout, pAd, TRUE);
35128 + //RTMPSetTimer(&pAd->RECBATimer, REORDER_EXEC_INTV);
35129 +
35130 +#ifdef RALINK_ATE
35131 + NdisZeroMemory(&pAd->ate, sizeof(ATE_INFO));
35132 + pAd->ate.Mode = ATE_STOP;
35133 + pAd->ate.TxCount = 200;/* to exceed TX_RING_SIZE ... */
35134 + pAd->ate.TxLength = 1024;
35135 + pAd->ate.TxWI.ShortGI = 0;// LONG GI : 800 ns
35136 + pAd->ate.TxWI.PHYMODE = MODE_CCK;
35137 + pAd->ate.TxWI.MCS = 3;
35138 + pAd->ate.TxWI.BW = BW_20;
35139 + pAd->ate.Channel = 1;
35140 + pAd->ate.QID = QID_AC_BE;
35141 + pAd->ate.Addr1[0] = 0x00;
35142 + pAd->ate.Addr1[1] = 0x11;
35143 + pAd->ate.Addr1[2] = 0x22;
35144 + pAd->ate.Addr1[3] = 0xAA;
35145 + pAd->ate.Addr1[4] = 0xBB;
35146 + pAd->ate.Addr1[5] = 0xCC;
35147 + NdisMoveMemory(pAd->ate.Addr2, pAd->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
35148 + NdisMoveMemory(pAd->ate.Addr3, pAd->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
35149 + pAd->ate.bRxFer = 0;
35150 + pAd->ate.bQATxStart = FALSE;
35151 + pAd->ate.bQARxStart = FALSE;
35152 +#ifdef RALINK_28xx_QA
35153 + //pAd->ate.Repeat = 0;
35154 + pAd->ate.TxStatus = 0;
35155 + pAd->ate.AtePid = THREAD_PID_INIT_VALUE;
35156 +#endif // RALINK_28xx_QA //
35157 +#endif // RALINK_ATE //
35158 +
35159 +
35160 + pAd->CommonCfg.bWiFiTest = FALSE;
35161 +
35162 +
35163 + DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n"));
35164 +}
35165 +
35166 +// IRQL = PASSIVE_LEVEL
35167 +UCHAR BtoH(char ch)
35168 +{
35169 + if (ch >= '0' && ch <= '9') return (ch - '0'); // Handle numerals
35170 + if (ch >= 'A' && ch <= 'F') return (ch - 'A' + 0xA); // Handle capitol hex digits
35171 + if (ch >= 'a' && ch <= 'f') return (ch - 'a' + 0xA); // Handle small hex digits
35172 + return(255);
35173 +}
35174 +
35175 +//
35176 +// FUNCTION: AtoH(char *, UCHAR *, int)
35177 +//
35178 +// PURPOSE: Converts ascii string to network order hex
35179 +//
35180 +// PARAMETERS:
35181 +// src - pointer to input ascii string
35182 +// dest - pointer to output hex
35183 +// destlen - size of dest
35184 +//
35185 +// COMMENTS:
35186 +//
35187 +// 2 ascii bytes make a hex byte so must put 1st ascii byte of pair
35188 +// into upper nibble and 2nd ascii byte of pair into lower nibble.
35189 +//
35190 +// IRQL = PASSIVE_LEVEL
35191 +
35192 +void AtoH(char * src, UCHAR * dest, int destlen)
35193 +{
35194 + char * srcptr;
35195 + PUCHAR destTemp;
35196 +
35197 + srcptr = src;
35198 + destTemp = (PUCHAR) dest;
35199 +
35200 + while(destlen--)
35201 + {
35202 + *destTemp = BtoH(*srcptr++) << 4; // Put 1st ascii byte in upper nibble.
35203 + *destTemp += BtoH(*srcptr++); // Add 2nd ascii byte to above.
35204 + destTemp++;
35205 + }
35206 +}
35207 +
35208 +VOID RTMPPatchMacBbpBug(
35209 + IN PRTMP_ADAPTER pAd)
35210 +{
35211 + ULONG Index;
35212 +
35213 + // Initialize BBP register to default value
35214 + for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++)
35215 + {
35216 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, (UCHAR)BBPRegTable[Index].Value);
35217 + }
35218 +
35219 + // Initialize RF register to default value
35220 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
35221 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
35222 +
35223 + // Re-init BBP register from EEPROM value
35224 + NICInitAsicFromEEPROM(pAd);
35225 +}
35226 +
35227 +/*
35228 + ========================================================================
35229 +
35230 + Routine Description:
35231 + Init timer objects
35232 +
35233 + Arguments:
35234 + pAd Pointer to our adapter
35235 + pTimer Timer structure
35236 + pTimerFunc Function to execute when timer expired
35237 + Repeat Ture for period timer
35238 +
35239 + Return Value:
35240 + None
35241 +
35242 + Note:
35243 +
35244 + ========================================================================
35245 +*/
35246 +VOID RTMPInitTimer(
35247 + IN PRTMP_ADAPTER pAd,
35248 + IN PRALINK_TIMER_STRUCT pTimer,
35249 + IN PVOID pTimerFunc,
35250 + IN PVOID pData,
35251 + IN BOOLEAN Repeat)
35252 +{
35253 + //
35254 + // Set Valid to TRUE for later used.
35255 + // It will crash if we cancel a timer or set a timer
35256 + // that we haven't initialize before.
35257 + //
35258 + pTimer->Valid = TRUE;
35259 +
35260 + pTimer->PeriodicType = Repeat;
35261 + pTimer->State = FALSE;
35262 + pTimer->cookie = (ULONG) pData;
35263 +
35264 +#ifdef RT2870
35265 + pTimer->pAd = pAd;
35266 +#endif // RT2870 //
35267 +
35268 + RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (PVOID) pTimer);
35269 +}
35270 +
35271 +/*
35272 + ========================================================================
35273 +
35274 + Routine Description:
35275 + Init timer objects
35276 +
35277 + Arguments:
35278 + pTimer Timer structure
35279 + Value Timer value in milliseconds
35280 +
35281 + Return Value:
35282 + None
35283 +
35284 + Note:
35285 + To use this routine, must call RTMPInitTimer before.
35286 +
35287 + ========================================================================
35288 +*/
35289 +VOID RTMPSetTimer(
35290 + IN PRALINK_TIMER_STRUCT pTimer,
35291 + IN ULONG Value)
35292 +{
35293 + if (pTimer->Valid)
35294 + {
35295 + pTimer->TimerValue = Value;
35296 + pTimer->State = FALSE;
35297 + if (pTimer->PeriodicType == TRUE)
35298 + {
35299 + pTimer->Repeat = TRUE;
35300 + RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value);
35301 + }
35302 + else
35303 + {
35304 + pTimer->Repeat = FALSE;
35305 + RTMP_OS_Add_Timer(&pTimer->TimerObj, Value);
35306 + }
35307 + }
35308 + else
35309 + {
35310 + DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n"));
35311 + }
35312 +}
35313 +
35314 +
35315 +/*
35316 + ========================================================================
35317 +
35318 + Routine Description:
35319 + Init timer objects
35320 +
35321 + Arguments:
35322 + pTimer Timer structure
35323 + Value Timer value in milliseconds
35324 +
35325 + Return Value:
35326 + None
35327 +
35328 + Note:
35329 + To use this routine, must call RTMPInitTimer before.
35330 +
35331 + ========================================================================
35332 +*/
35333 +VOID RTMPModTimer(
35334 + IN PRALINK_TIMER_STRUCT pTimer,
35335 + IN ULONG Value)
35336 +{
35337 + BOOLEAN Cancel;
35338 +
35339 + if (pTimer->Valid)
35340 + {
35341 + pTimer->TimerValue = Value;
35342 + pTimer->State = FALSE;
35343 + if (pTimer->PeriodicType == TRUE)
35344 + {
35345 + RTMPCancelTimer(pTimer, &Cancel);
35346 + RTMPSetTimer(pTimer, Value);
35347 + }
35348 + else
35349 + {
35350 + RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value);
35351 + }
35352 + }
35353 + else
35354 + {
35355 + DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n"));
35356 + }
35357 +}
35358 +
35359 +/*
35360 + ========================================================================
35361 +
35362 + Routine Description:
35363 + Cancel timer objects
35364 +
35365 + Arguments:
35366 + Adapter Pointer to our adapter
35367 +
35368 + Return Value:
35369 + None
35370 +
35371 + IRQL = PASSIVE_LEVEL
35372 + IRQL = DISPATCH_LEVEL
35373 +
35374 + Note:
35375 + 1.) To use this routine, must call RTMPInitTimer before.
35376 + 2.) Reset NIC to initial state AS IS system boot up time.
35377 +
35378 + ========================================================================
35379 +*/
35380 +VOID RTMPCancelTimer(
35381 + IN PRALINK_TIMER_STRUCT pTimer,
35382 + OUT BOOLEAN *pCancelled)
35383 +{
35384 + if (pTimer->Valid)
35385 + {
35386 + if (pTimer->State == FALSE)
35387 + pTimer->Repeat = FALSE;
35388 + RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled);
35389 +
35390 + if (*pCancelled == TRUE)
35391 + pTimer->State = TRUE;
35392 +
35393 +#ifdef RT2870
35394 + // We need to go-through the TimerQ to findout this timer handler and remove it if
35395 + // it's still waiting for execution.
35396 +
35397 + RT2870_TimerQ_Remove(pTimer->pAd, pTimer);
35398 +#endif // RT2870 //
35399 + }
35400 + else
35401 + {
35402 + //
35403 + // NdisMCancelTimer just canced the timer and not mean release the timer.
35404 + // And don't set the "Valid" to False. So that we can use this timer again.
35405 + //
35406 + DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n"));
35407 + }
35408 +}
35409 +
35410 +/*
35411 + ========================================================================
35412 +
35413 + Routine Description:
35414 + Set LED Status
35415 +
35416 + Arguments:
35417 + pAd Pointer to our adapter
35418 + Status LED Status
35419 +
35420 + Return Value:
35421 + None
35422 +
35423 + IRQL = PASSIVE_LEVEL
35424 + IRQL = DISPATCH_LEVEL
35425 +
35426 + Note:
35427 +
35428 + ========================================================================
35429 +*/
35430 +VOID RTMPSetLED(
35431 + IN PRTMP_ADAPTER pAd,
35432 + IN UCHAR Status)
35433 +{
35434 + //ULONG data;
35435 + UCHAR HighByte = 0;
35436 + UCHAR LowByte;
35437 +
35438 +// In ATE mode of RT2860 AP/STA, we have erased 8051 firmware.
35439 +// So LED mode is not supported when ATE is running.
35440 +#ifdef RALINK_ATE
35441 + if (ATE_ON(pAd))
35442 + return;
35443 +#endif // RALINK_ATE //
35444 +
35445 + LowByte = pAd->LedCntl.field.LedMode&0x7f;
35446 + switch (Status)
35447 + {
35448 + case LED_LINK_DOWN:
35449 + HighByte = 0x20;
35450 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35451 + pAd->LedIndicatorStregth = 0;
35452 + break;
35453 + case LED_LINK_UP:
35454 + if (pAd->CommonCfg.Channel > 14)
35455 + HighByte = 0xa0;
35456 + else
35457 + HighByte = 0x60;
35458 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35459 + break;
35460 + case LED_RADIO_ON:
35461 + HighByte = 0x20;
35462 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35463 + break;
35464 + case LED_HALT:
35465 + LowByte = 0; // Driver sets MAC register and MAC controls LED
35466 + case LED_RADIO_OFF:
35467 + HighByte = 0;
35468 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35469 + break;
35470 + case LED_WPS:
35471 + HighByte = 0x10;
35472 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35473 + break;
35474 + case LED_ON_SITE_SURVEY:
35475 + HighByte = 0x08;
35476 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35477 + break;
35478 + case LED_POWER_UP:
35479 + HighByte = 0x04;
35480 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
35481 + break;
35482 + default:
35483 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetLED::Unknown Status %d\n", Status));
35484 + break;
35485 + }
35486 +
35487 + //
35488 + // Keep LED status for LED SiteSurvey mode.
35489 + // After SiteSurvey, we will set the LED mode to previous status.
35490 + //
35491 + if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP))
35492 + pAd->LedStatus = Status;
35493 +
35494 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n", pAd->LedCntl.field.LedMode, HighByte, LowByte));
35495 +}
35496 +
35497 +/*
35498 + ========================================================================
35499 +
35500 + Routine Description:
35501 + Set LED Signal Stregth
35502 +
35503 + Arguments:
35504 + pAd Pointer to our adapter
35505 + Dbm Signal Stregth
35506 +
35507 + Return Value:
35508 + None
35509 +
35510 + IRQL = PASSIVE_LEVEL
35511 +
35512 + Note:
35513 + Can be run on any IRQL level.
35514 +
35515 + According to Microsoft Zero Config Wireless Signal Stregth definition as belows.
35516 + <= -90 No Signal
35517 + <= -81 Very Low
35518 + <= -71 Low
35519 + <= -67 Good
35520 + <= -57 Very Good
35521 + > -57 Excellent
35522 + ========================================================================
35523 +*/
35524 +VOID RTMPSetSignalLED(
35525 + IN PRTMP_ADAPTER pAd,
35526 + IN NDIS_802_11_RSSI Dbm)
35527 +{
35528 + UCHAR nLed = 0;
35529 +
35530 + //
35531 + // if not Signal Stregth, then do nothing.
35532 + //
35533 + if (pAd->LedCntl.field.LedMode != LED_MODE_SIGNAL_STREGTH)
35534 + {
35535 + return;
35536 + }
35537 +
35538 + if (Dbm <= -90)
35539 + nLed = 0;
35540 + else if (Dbm <= -81)
35541 + nLed = 1;
35542 + else if (Dbm <= -71)
35543 + nLed = 3;
35544 + else if (Dbm <= -67)
35545 + nLed = 7;
35546 + else if (Dbm <= -57)
35547 + nLed = 15;
35548 + else
35549 + nLed = 31;
35550 +
35551 + //
35552 + // Update Signal Stregth to firmware if changed.
35553 + //
35554 + if (pAd->LedIndicatorStregth != nLed)
35555 + {
35556 + AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed, pAd->LedCntl.field.Polarity);
35557 + pAd->LedIndicatorStregth = nLed;
35558 + }
35559 +}
35560 +
35561 +/*
35562 + ========================================================================
35563 +
35564 + Routine Description:
35565 + Enable RX
35566 +
35567 + Arguments:
35568 + pAd Pointer to our adapter
35569 +
35570 + Return Value:
35571 + None
35572 +
35573 + IRQL <= DISPATCH_LEVEL
35574 +
35575 + Note:
35576 + Before Enable RX, make sure you have enabled Interrupt.
35577 + ========================================================================
35578 +*/
35579 +VOID RTMPEnableRxTx(
35580 + IN PRTMP_ADAPTER pAd)
35581 +{
35582 +// WPDMA_GLO_CFG_STRUC GloCfg;
35583 +// ULONG i = 0;
35584 +
35585 + DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n"));
35586 +
35587 +#if 0
35588 + // Enable Rx DMA.
35589 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
35590 + do
35591 + {
35592 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
35593 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
35594 + break;
35595 +
35596 + DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
35597 + RTMPusecDelay(1000);
35598 + i++;
35599 + }while ( i <200);
35600 +
35601 + RTMPusecDelay(50);
35602 + RT28XX_DMA_WRITE_INIT(GloCfg);
35603 + DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
35604 + RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
35605 +
35606 + RT28XX_DMA_POST_WRITE(pAd);
35607 +#else
35608 + // Enable Rx DMA.
35609 + RT28XXDMAEnable(pAd);
35610 +#endif
35611 +
35612 + // enable RX of MAC block
35613 + if (pAd->OpMode == OPMODE_AP)
35614 + {
35615 + UINT32 rx_filter_flag = APNORMAL;
35616 +
35617 +
35618 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); // enable RX of DMA block
35619 + }
35620 + else
35621 + {
35622 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
35623 + }
35624 +
35625 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc);
35626 + DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n"));
35627 +}
35628 +
35629 +
35630 --- /dev/null
35631 +++ b/drivers/staging/rt2870/common/rtmp_tkip.c
35632 @@ -0,0 +1,1613 @@
35633 +/*
35634 + *************************************************************************
35635 + * Ralink Tech Inc.
35636 + * 5F., No.36, Taiyuan St., Jhubei City,
35637 + * Hsinchu County 302,
35638 + * Taiwan, R.O.C.
35639 + *
35640 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
35641 + *
35642 + * This program is free software; you can redistribute it and/or modify *
35643 + * it under the terms of the GNU General Public License as published by *
35644 + * the Free Software Foundation; either version 2 of the License, or *
35645 + * (at your option) any later version. *
35646 + * *
35647 + * This program is distributed in the hope that it will be useful, *
35648 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
35649 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
35650 + * GNU General Public License for more details. *
35651 + * *
35652 + * You should have received a copy of the GNU General Public License *
35653 + * along with this program; if not, write to the *
35654 + * Free Software Foundation, Inc., *
35655 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
35656 + * *
35657 + *************************************************************************
35658 +
35659 + Module Name:
35660 + rtmp_tkip.c
35661 +
35662 + Abstract:
35663 +
35664 + Revision History:
35665 + Who When What
35666 + -------- ---------- ----------------------------------------------
35667 + Paul Wu 02-25-02 Initial
35668 +*/
35669 +
35670 +#include "../rt_config.h"
35671 +
35672 +// Rotation functions on 32 bit values
35673 +#define ROL32( A, n ) \
35674 + ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
35675 +#define ROR32( A, n ) ROL32( (A), 32-(n) )
35676 +
35677 +UINT Tkip_Sbox_Lower[256] =
35678 +{
35679 + 0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54,
35680 + 0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A,
35681 + 0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B,
35682 + 0xEC,0x67,0xFD,0xEA,0xBF,0xF7,0x96,0x5B,
35683 + 0xC2,0x1C,0xAE,0x6A,0x5A,0x41,0x02,0x4F,
35684 + 0x5C,0xF4,0x34,0x08,0x93,0x73,0x53,0x3F,
35685 + 0x0C,0x52,0x65,0x5E,0x28,0xA1,0x0F,0xB5,
35686 + 0x09,0x36,0x9B,0x3D,0x26,0x69,0xCD,0x9F,
35687 + 0x1B,0x9E,0x74,0x2E,0x2D,0xB2,0xEE,0xFB,
35688 + 0xF6,0x4D,0x61,0xCE,0x7B,0x3E,0x71,0x97,
35689 + 0xF5,0x68,0x00,0x2C,0x60,0x1F,0xC8,0xED,
35690 + 0xBE,0x46,0xD9,0x4B,0xDE,0xD4,0xE8,0x4A,
35691 + 0x6B,0x2A,0xE5,0x16,0xC5,0xD7,0x55,0x94,
35692 + 0xCF,0x10,0x06,0x81,0xF0,0x44,0xBA,0xE3,
35693 + 0xF3,0xFE,0xC0,0x8A,0xAD,0xBC,0x48,0x04,
35694 + 0xDF,0xC1,0x75,0x63,0x30,0x1A,0x0E,0x6D,
35695 + 0x4C,0x14,0x35,0x2F,0xE1,0xA2,0xCC,0x39,
35696 + 0x57,0xF2,0x82,0x47,0xAC,0xE7,0x2B,0x95,
35697 + 0xA0,0x98,0xD1,0x7F,0x66,0x7E,0xAB,0x83,
35698 + 0xCA,0x29,0xD3,0x3C,0x79,0xE2,0x1D,0x76,
35699 + 0x3B,0x56,0x4E,0x1E,0xDB,0x0A,0x6C,0xE4,
35700 + 0x5D,0x6E,0xEF,0xA6,0xA8,0xA4,0x37,0x8B,
35701 + 0x32,0x43,0x59,0xB7,0x8C,0x64,0xD2,0xE0,
35702 + 0xB4,0xFA,0x07,0x25,0xAF,0x8E,0xE9,0x18,
35703 + 0xD5,0x88,0x6F,0x72,0x24,0xF1,0xC7,0x51,
35704 + 0x23,0x7C,0x9C,0x21,0xDD,0xDC,0x86,0x85,
35705 + 0x90,0x42,0xC4,0xAA,0xD8,0x05,0x01,0x12,
35706 + 0xA3,0x5F,0xF9,0xD0,0x91,0x58,0x27,0xB9,
35707 + 0x38,0x13,0xB3,0x33,0xBB,0x70,0x89,0xA7,
35708 + 0xB6,0x22,0x92,0x20,0x49,0xFF,0x78,0x7A,
35709 + 0x8F,0xF8,0x80,0x17,0xDA,0x31,0xC6,0xB8,
35710 + 0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A
35711 +};
35712 +
35713 +UINT Tkip_Sbox_Upper[256] =
35714 +{
35715 + 0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91,
35716 + 0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC,
35717 + 0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB,
35718 + 0x41,0xB3,0x5F,0x45,0x23,0x53,0xE4,0x9B,
35719 + 0x75,0xE1,0x3D,0x4C,0x6C,0x7E,0xF5,0x83,
35720 + 0x68,0x51,0xD1,0xF9,0xE2,0xAB,0x62,0x2A,
35721 + 0x08,0x95,0x46,0x9D,0x30,0x37,0x0A,0x2F,
35722 + 0x0E,0x24,0x1B,0xDF,0xCD,0x4E,0x7F,0xEA,
35723 + 0x12,0x1D,0x58,0x34,0x36,0xDC,0xB4,0x5B,
35724 + 0xA4,0x76,0xB7,0x7D,0x52,0xDD,0x5E,0x13,
35725 + 0xA6,0xB9,0x00,0xC1,0x40,0xE3,0x79,0xB6,
35726 + 0xD4,0x8D,0x67,0x72,0x94,0x98,0xB0,0x85,
35727 + 0xBB,0xC5,0x4F,0xED,0x86,0x9A,0x66,0x11,
35728 + 0x8A,0xE9,0x04,0xFE,0xA0,0x78,0x25,0x4B,
35729 + 0xA2,0x5D,0x80,0x05,0x3F,0x21,0x70,0xF1,
35730 + 0x63,0x77,0xAF,0x42,0x20,0xE5,0xFD,0xBF,
35731 + 0x81,0x18,0x26,0xC3,0xBE,0x35,0x88,0x2E,
35732 + 0x93,0x55,0xFC,0x7A,0xC8,0xBA,0x32,0xE6,
35733 + 0xC0,0x19,0x9E,0xA3,0x44,0x54,0x3B,0x0B,
35734 + 0x8C,0xC7,0x6B,0x28,0xA7,0xBC,0x16,0xAD,
35735 + 0xDB,0x64,0x74,0x14,0x92,0x0C,0x48,0xB8,
35736 + 0x9F,0xBD,0x43,0xC4,0x39,0x31,0xD3,0xF2,
35737 + 0xD5,0x8B,0x6E,0xDA,0x01,0xB1,0x9C,0x49,
35738 + 0xD8,0xAC,0xF3,0xCF,0xCA,0xF4,0x47,0x10,
35739 + 0x6F,0xF0,0x4A,0x5C,0x38,0x57,0x73,0x97,
35740 + 0xCB,0xA1,0xE8,0x3E,0x96,0x61,0x0D,0x0F,
35741 + 0xE0,0x7C,0x71,0xCC,0x90,0x06,0xF7,0x1C,
35742 + 0xC2,0x6A,0xAE,0x69,0x17,0x99,0x3A,0x27,
35743 + 0xD9,0xEB,0x2B,0x22,0xD2,0xA9,0x07,0x33,
35744 + 0x2D,0x3C,0x15,0xC9,0x87,0xAA,0x50,0xA5,
35745 + 0x03,0x59,0x09,0x1A,0x65,0xD7,0x84,0xD0,
35746 + 0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C
35747 +};
35748 +
35749 +/*****************************/
35750 +/******** SBOX Table *********/
35751 +/*****************************/
35752 +
35753 +UCHAR SboxTable[256] =
35754 +{
35755 + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
35756 + 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
35757 + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
35758 + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
35759 + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
35760 + 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
35761 + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
35762 + 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
35763 + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
35764 + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
35765 + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
35766 + 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
35767 + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
35768 + 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
35769 + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
35770 + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
35771 + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
35772 + 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
35773 + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
35774 + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
35775 + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
35776 + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
35777 + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
35778 + 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
35779 + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
35780 + 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
35781 + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
35782 + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
35783 + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
35784 + 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
35785 + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
35786 + 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
35787 +};
35788 +
35789 +VOID xor_32(
35790 + IN PUCHAR a,
35791 + IN PUCHAR b,
35792 + OUT PUCHAR out);
35793 +
35794 +VOID xor_128(
35795 + IN PUCHAR a,
35796 + IN PUCHAR b,
35797 + OUT PUCHAR out);
35798 +
35799 +VOID next_key(
35800 + IN PUCHAR key,
35801 + IN INT round);
35802 +
35803 +VOID byte_sub(
35804 + IN PUCHAR in,
35805 + OUT PUCHAR out);
35806 +
35807 +VOID shift_row(
35808 + IN PUCHAR in,
35809 + OUT PUCHAR out);
35810 +
35811 +VOID mix_column(
35812 + IN PUCHAR in,
35813 + OUT PUCHAR out);
35814 +
35815 +UCHAR RTMPCkipSbox(
35816 + IN UCHAR a);
35817 +//
35818 +// Expanded IV for TKIP function.
35819 +//
35820 +typedef struct PACKED _IV_CONTROL_
35821 +{
35822 + union PACKED
35823 + {
35824 + struct PACKED
35825 + {
35826 + UCHAR rc0;
35827 + UCHAR rc1;
35828 + UCHAR rc2;
35829 +
35830 + union PACKED
35831 + {
35832 + struct PACKED
35833 + {
35834 +#ifdef RT_BIG_ENDIAN
35835 + UCHAR KeyID:2;
35836 + UCHAR ExtIV:1;
35837 + UCHAR Rsvd:5;
35838 +#else
35839 + UCHAR Rsvd:5;
35840 + UCHAR ExtIV:1;
35841 + UCHAR KeyID:2;
35842 +#endif
35843 + } field;
35844 + UCHAR Byte;
35845 + } CONTROL;
35846 + } field;
35847 +
35848 + ULONG word;
35849 + } IV16;
35850 +
35851 + ULONG IV32;
35852 +} TKIP_IV, *PTKIP_IV;
35853 +
35854 +
35855 +/*
35856 + ========================================================================
35857 +
35858 + Routine Description:
35859 + Convert from UCHAR[] to ULONG in a portable way
35860 +
35861 + Arguments:
35862 + pMICKey pointer to MIC Key
35863 +
35864 + Return Value:
35865 + None
35866 +
35867 + Note:
35868 +
35869 + ========================================================================
35870 +*/
35871 +ULONG RTMPTkipGetUInt32(
35872 + IN PUCHAR pMICKey)
35873 +{
35874 + ULONG res = 0;
35875 + INT i;
35876 +
35877 + for (i = 0; i < 4; i++)
35878 + {
35879 + res |= (*pMICKey++) << (8 * i);
35880 + }
35881 +
35882 + return res;
35883 +}
35884 +
35885 +/*
35886 + ========================================================================
35887 +
35888 + Routine Description:
35889 + Convert from ULONG to UCHAR[] in a portable way
35890 +
35891 + Arguments:
35892 + pDst pointer to destination for convert ULONG to UCHAR[]
35893 + val the value for convert
35894 +
35895 + Return Value:
35896 + None
35897 +
35898 + IRQL = DISPATCH_LEVEL
35899 +
35900 + Note:
35901 +
35902 + ========================================================================
35903 +*/
35904 +VOID RTMPTkipPutUInt32(
35905 + IN OUT PUCHAR pDst,
35906 + IN ULONG val)
35907 +{
35908 + INT i;
35909 +
35910 + for(i = 0; i < 4; i++)
35911 + {
35912 + *pDst++ = (UCHAR) (val & 0xff);
35913 + val >>= 8;
35914 + }
35915 +}
35916 +
35917 +/*
35918 + ========================================================================
35919 +
35920 + Routine Description:
35921 + Set the MIC Key.
35922 +
35923 + Arguments:
35924 + pAd Pointer to our adapter
35925 + pMICKey pointer to MIC Key
35926 +
35927 + Return Value:
35928 + None
35929 +
35930 + IRQL = DISPATCH_LEVEL
35931 +
35932 + Note:
35933 +
35934 + ========================================================================
35935 +*/
35936 +VOID RTMPTkipSetMICKey(
35937 + IN PTKIP_KEY_INFO pTkip,
35938 + IN PUCHAR pMICKey)
35939 +{
35940 + // Set the key
35941 + pTkip->K0 = RTMPTkipGetUInt32(pMICKey);
35942 + pTkip->K1 = RTMPTkipGetUInt32(pMICKey + 4);
35943 + // and reset the message
35944 + pTkip->L = pTkip->K0;
35945 + pTkip->R = pTkip->K1;
35946 + pTkip->nBytesInM = 0;
35947 + pTkip->M = 0;
35948 +}
35949 +
35950 +/*
35951 + ========================================================================
35952 +
35953 + Routine Description:
35954 + Calculate the MIC Value.
35955 +
35956 + Arguments:
35957 + pAd Pointer to our adapter
35958 + uChar Append this uChar
35959 +
35960 + Return Value:
35961 + None
35962 +
35963 + IRQL = DISPATCH_LEVEL
35964 +
35965 + Note:
35966 +
35967 + ========================================================================
35968 +*/
35969 +VOID RTMPTkipAppendByte(
35970 + IN PTKIP_KEY_INFO pTkip,
35971 + IN UCHAR uChar)
35972 +{
35973 + // Append the byte to our word-sized buffer
35974 + pTkip->M |= (uChar << (8* pTkip->nBytesInM));
35975 + pTkip->nBytesInM++;
35976 + // Process the word if it is full.
35977 + if( pTkip->nBytesInM >= 4 )
35978 + {
35979 + pTkip->L ^= pTkip->M;
35980 + pTkip->R ^= ROL32( pTkip->L, 17 );
35981 + pTkip->L += pTkip->R;
35982 + pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->L & 0x00ff00ff) << 8);
35983 + pTkip->L += pTkip->R;
35984 + pTkip->R ^= ROL32( pTkip->L, 3 );
35985 + pTkip->L += pTkip->R;
35986 + pTkip->R ^= ROR32( pTkip->L, 2 );
35987 + pTkip->L += pTkip->R;
35988 + // Clear the buffer
35989 + pTkip->M = 0;
35990 + pTkip->nBytesInM = 0;
35991 + }
35992 +}
35993 +
35994 +/*
35995 + ========================================================================
35996 +
35997 + Routine Description:
35998 + Calculate the MIC Value.
35999 +
36000 + Arguments:
36001 + pAd Pointer to our adapter
36002 + pSrc Pointer to source data for Calculate MIC Value
36003 + Len Indicate the length of the source data
36004 +
36005 + Return Value:
36006 + None
36007 +
36008 + IRQL = DISPATCH_LEVEL
36009 +
36010 + Note:
36011 +
36012 + ========================================================================
36013 +*/
36014 +VOID RTMPTkipAppend(
36015 + IN PTKIP_KEY_INFO pTkip,
36016 + IN PUCHAR pSrc,
36017 + IN UINT nBytes)
36018 +{
36019 + // This is simple
36020 + while(nBytes > 0)
36021 + {
36022 + RTMPTkipAppendByte(pTkip, *pSrc++);
36023 + nBytes--;
36024 + }
36025 +}
36026 +
36027 +/*
36028 + ========================================================================
36029 +
36030 + Routine Description:
36031 + Get the MIC Value.
36032 +
36033 + Arguments:
36034 + pAd Pointer to our adapter
36035 +
36036 + Return Value:
36037 + None
36038 +
36039 + IRQL = DISPATCH_LEVEL
36040 +
36041 + Note:
36042 + the MIC Value is store in pAd->PrivateInfo.MIC
36043 + ========================================================================
36044 +*/
36045 +VOID RTMPTkipGetMIC(
36046 + IN PTKIP_KEY_INFO pTkip)
36047 +{
36048 + // Append the minimum padding
36049 + RTMPTkipAppendByte(pTkip, 0x5a );
36050 + RTMPTkipAppendByte(pTkip, 0 );
36051 + RTMPTkipAppendByte(pTkip, 0 );
36052 + RTMPTkipAppendByte(pTkip, 0 );
36053 + RTMPTkipAppendByte(pTkip, 0 );
36054 + // and then zeroes until the length is a multiple of 4
36055 + while( pTkip->nBytesInM != 0 )
36056 + {
36057 + RTMPTkipAppendByte(pTkip, 0 );
36058 + }
36059 + // The appendByte function has already computed the result.
36060 + RTMPTkipPutUInt32(pTkip->MIC, pTkip->L);
36061 + RTMPTkipPutUInt32(pTkip->MIC + 4, pTkip->R);
36062 +}
36063 +
36064 +/*
36065 + ========================================================================
36066 +
36067 + Routine Description:
36068 + Init Tkip function.
36069 +
36070 + Arguments:
36071 + pAd Pointer to our adapter
36072 + pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
36073 + KeyId TK Key ID
36074 + pTA Pointer to transmitter address
36075 + pMICKey pointer to MIC Key
36076 +
36077 + Return Value:
36078 + None
36079 +
36080 + IRQL = DISPATCH_LEVEL
36081 +
36082 + Note:
36083 +
36084 + ========================================================================
36085 +*/
36086 +VOID RTMPInitTkipEngine(
36087 + IN PRTMP_ADAPTER pAd,
36088 + IN PUCHAR pKey,
36089 + IN UCHAR KeyId,
36090 + IN PUCHAR pTA,
36091 + IN PUCHAR pMICKey,
36092 + IN PUCHAR pTSC,
36093 + OUT PULONG pIV16,
36094 + OUT PULONG pIV32)
36095 +{
36096 + TKIP_IV tkipIv;
36097 +
36098 + // Prepare 8 bytes TKIP encapsulation for MPDU
36099 + NdisZeroMemory(&tkipIv, sizeof(TKIP_IV));
36100 + tkipIv.IV16.field.rc0 = *(pTSC + 1);
36101 + tkipIv.IV16.field.rc1 = (tkipIv.IV16.field.rc0 | 0x20) & 0x7f;
36102 + tkipIv.IV16.field.rc2 = *pTSC;
36103 + tkipIv.IV16.field.CONTROL.field.ExtIV = 1; // 0: non-extended IV, 1: an extended IV
36104 + tkipIv.IV16.field.CONTROL.field.KeyID = KeyId;
36105 +// tkipIv.IV32 = *(PULONG)(pTSC + 2);
36106 + NdisMoveMemory(&tkipIv.IV32, (pTSC + 2), 4); // Copy IV
36107 +
36108 + *pIV16 = tkipIv.IV16.word;
36109 + *pIV32 = tkipIv.IV32;
36110 +}
36111 +
36112 +/*
36113 + ========================================================================
36114 +
36115 + Routine Description:
36116 + Init MIC Value calculation function which include set MIC key &
36117 + calculate first 16 bytes (DA + SA + priority + 0)
36118 +
36119 + Arguments:
36120 + pAd Pointer to our adapter
36121 + pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
36122 + pDA Pointer to DA address
36123 + pSA Pointer to SA address
36124 + pMICKey pointer to MIC Key
36125 +
36126 + Return Value:
36127 + None
36128 +
36129 + Note:
36130 +
36131 + ========================================================================
36132 +*/
36133 +VOID RTMPInitMICEngine(
36134 + IN PRTMP_ADAPTER pAd,
36135 + IN PUCHAR pKey,
36136 + IN PUCHAR pDA,
36137 + IN PUCHAR pSA,
36138 + IN UCHAR UserPriority,
36139 + IN PUCHAR pMICKey)
36140 +{
36141 + ULONG Priority = UserPriority;
36142 +
36143 + // Init MIC value calculation
36144 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Tx, pMICKey);
36145 + // DA
36146 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pDA, MAC_ADDR_LEN);
36147 + // SA
36148 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSA, MAC_ADDR_LEN);
36149 + // Priority + 3 bytes of 0
36150 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, (PUCHAR)&Priority, 4);
36151 +}
36152 +
36153 +/*
36154 + ========================================================================
36155 +
36156 + Routine Description:
36157 + Compare MIC value of received MSDU
36158 +
36159 + Arguments:
36160 + pAd Pointer to our adapter
36161 + pSrc Pointer to the received Plain text data
36162 + pDA Pointer to DA address
36163 + pSA Pointer to SA address
36164 + pMICKey pointer to MIC Key
36165 + Len the length of the received plain text data exclude MIC value
36166 +
36167 + Return Value:
36168 + TRUE MIC value matched
36169 + FALSE MIC value mismatched
36170 +
36171 + IRQL = DISPATCH_LEVEL
36172 +
36173 + Note:
36174 +
36175 + ========================================================================
36176 +*/
36177 +BOOLEAN RTMPTkipCompareMICValue(
36178 + IN PRTMP_ADAPTER pAd,
36179 + IN PUCHAR pSrc,
36180 + IN PUCHAR pDA,
36181 + IN PUCHAR pSA,
36182 + IN PUCHAR pMICKey,
36183 + IN UCHAR UserPriority,
36184 + IN UINT Len)
36185 +{
36186 + UCHAR OldMic[8];
36187 + ULONG Priority = UserPriority;
36188 +
36189 + // Init MIC value calculation
36190 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey);
36191 + // DA
36192 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN);
36193 + // SA
36194 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN);
36195 + // Priority + 3 bytes of 0
36196 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4);
36197 +
36198 + // Calculate MIC value from plain text data
36199 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len);
36200 +
36201 + // Get MIC valude from received frame
36202 + NdisMoveMemory(OldMic, pSrc + Len, 8);
36203 +
36204 + // Get MIC value from decrypted plain data
36205 + RTMPTkipGetMIC(&pAd->PrivateInfo.Rx);
36206 +
36207 + // Move MIC value from MSDU, this steps should move to data path.
36208 + // Since the MIC value might cross MPDUs.
36209 + if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8))
36210 + {
36211 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValue(): TKIP MIC Error !\n")); //MIC error.
36212 +
36213 +
36214 + return (FALSE);
36215 + }
36216 + return (TRUE);
36217 +}
36218 +
36219 +/*
36220 + ========================================================================
36221 +
36222 + Routine Description:
36223 + Compare MIC value of received MSDU
36224 +
36225 + Arguments:
36226 + pAd Pointer to our adapter
36227 + pLLC LLC header
36228 + pSrc Pointer to the received Plain text data
36229 + pDA Pointer to DA address
36230 + pSA Pointer to SA address
36231 + pMICKey pointer to MIC Key
36232 + Len the length of the received plain text data exclude MIC value
36233 +
36234 + Return Value:
36235 + TRUE MIC value matched
36236 + FALSE MIC value mismatched
36237 +
36238 + IRQL = DISPATCH_LEVEL
36239 +
36240 + Note:
36241 +
36242 + ========================================================================
36243 +*/
36244 +BOOLEAN RTMPTkipCompareMICValueWithLLC(
36245 + IN PRTMP_ADAPTER pAd,
36246 + IN PUCHAR pLLC,
36247 + IN PUCHAR pSrc,
36248 + IN PUCHAR pDA,
36249 + IN PUCHAR pSA,
36250 + IN PUCHAR pMICKey,
36251 + IN UINT Len)
36252 +{
36253 + UCHAR OldMic[8];
36254 + ULONG Priority = 0;
36255 +
36256 + // Init MIC value calculation
36257 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey);
36258 + // DA
36259 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN);
36260 + // SA
36261 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN);
36262 + // Priority + 3 bytes of 0
36263 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4);
36264 +
36265 + // Start with LLC header
36266 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pLLC, 8);
36267 +
36268 + // Calculate MIC value from plain text data
36269 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len);
36270 +
36271 + // Get MIC valude from received frame
36272 + NdisMoveMemory(OldMic, pSrc + Len, 8);
36273 +
36274 + // Get MIC value from decrypted plain data
36275 + RTMPTkipGetMIC(&pAd->PrivateInfo.Rx);
36276 +
36277 + // Move MIC value from MSDU, this steps should move to data path.
36278 + // Since the MIC value might cross MPDUs.
36279 + if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8))
36280 + {
36281 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValueWithLLC(): TKIP MIC Error !\n")); //MIC error.
36282 +
36283 +
36284 + return (FALSE);
36285 + }
36286 + return (TRUE);
36287 +}
36288 +/*
36289 + ========================================================================
36290 +
36291 + Routine Description:
36292 + Copy frame from waiting queue into relative ring buffer and set
36293 + appropriate ASIC register to kick hardware transmit function
36294 +
36295 + Arguments:
36296 + pAd Pointer to our adapter
36297 + PNDIS_PACKET Pointer to Ndis Packet for MIC calculation
36298 + pEncap Pointer to LLC encap data
36299 + LenEncap Total encap length, might be 0 which indicates no encap
36300 +
36301 + Return Value:
36302 + None
36303 +
36304 + IRQL = DISPATCH_LEVEL
36305 +
36306 + Note:
36307 +
36308 + ========================================================================
36309 +*/
36310 +VOID RTMPCalculateMICValue(
36311 + IN PRTMP_ADAPTER pAd,
36312 + IN PNDIS_PACKET pPacket,
36313 + IN PUCHAR pEncap,
36314 + IN PCIPHER_KEY pKey,
36315 + IN UCHAR apidx)
36316 +{
36317 + PACKET_INFO PacketInfo;
36318 + PUCHAR pSrcBufVA;
36319 + UINT SrcBufLen;
36320 + PUCHAR pSrc;
36321 + UCHAR UserPriority;
36322 + UCHAR vlan_offset = 0;
36323 +
36324 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
36325 +
36326 + UserPriority = RTMP_GET_PACKET_UP(pPacket);
36327 + pSrc = pSrcBufVA;
36328 +
36329 + // determine if this is a vlan packet
36330 + if (((*(pSrc + 12) << 8) + *(pSrc + 13)) == 0x8100)
36331 + vlan_offset = 4;
36332 +
36333 +#ifdef CONFIG_STA_SUPPORT
36334 +#endif // CONFIG_STA_SUPPORT //
36335 + {
36336 + RTMPInitMICEngine(
36337 + pAd,
36338 + pKey->Key,
36339 + pSrc,
36340 + pSrc + 6,
36341 + UserPriority,
36342 + pKey->TxMic);
36343 + }
36344 +
36345 +
36346 + if (pEncap != NULL)
36347 + {
36348 + // LLC encapsulation
36349 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pEncap, 6);
36350 + // Protocol Type
36351 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc + 12 + vlan_offset, 2);
36352 + }
36353 + SrcBufLen -= (14 + vlan_offset);
36354 + pSrc += (14 + vlan_offset);
36355 + do
36356 + {
36357 + if (SrcBufLen > 0)
36358 + {
36359 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc, SrcBufLen);
36360 + }
36361 +
36362 + break; // No need handle next packet
36363 +
36364 + } while (TRUE); // End of copying payload
36365 +
36366 + // Compute the final MIC Value
36367 + RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
36368 +}
36369 +
36370 +
36371 +/************************************************************/
36372 +/* tkip_sbox() */
36373 +/* Returns a 16 bit value from a 64K entry table. The Table */
36374 +/* is synthesized from two 256 entry byte wide tables. */
36375 +/************************************************************/
36376 +
36377 +UINT tkip_sbox(UINT index)
36378 +{
36379 + UINT index_low;
36380 + UINT index_high;
36381 + UINT left, right;
36382 +
36383 + index_low = (index % 256);
36384 + index_high = ((index >> 8) % 256);
36385 +
36386 + left = Tkip_Sbox_Lower[index_low] + (Tkip_Sbox_Upper[index_low] * 256);
36387 + right = Tkip_Sbox_Upper[index_high] + (Tkip_Sbox_Lower[index_high] * 256);
36388 +
36389 + return (left ^ right);
36390 +}
36391 +
36392 +UINT rotr1(UINT a)
36393 +{
36394 + unsigned int b;
36395 +
36396 + if ((a & 0x01) == 0x01)
36397 + {
36398 + b = (a >> 1) | 0x8000;
36399 + }
36400 + else
36401 + {
36402 + b = (a >> 1) & 0x7fff;
36403 + }
36404 + b = b % 65536;
36405 + return b;
36406 +}
36407 +
36408 +VOID RTMPTkipMixKey(
36409 + UCHAR *key,
36410 + UCHAR *ta,
36411 + ULONG pnl, /* Least significant 16 bits of PN */
36412 + ULONG pnh, /* Most significant 32 bits of PN */
36413 + UCHAR *rc4key,
36414 + UINT *p1k)
36415 +{
36416 +
36417 + UINT tsc0;
36418 + UINT tsc1;
36419 + UINT tsc2;
36420 +
36421 + UINT ppk0;
36422 + UINT ppk1;
36423 + UINT ppk2;
36424 + UINT ppk3;
36425 + UINT ppk4;
36426 + UINT ppk5;
36427 +
36428 + INT i;
36429 + INT j;
36430 +
36431 + tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
36432 + tsc1 = (unsigned int)(pnh % 65536);
36433 + tsc2 = (unsigned int)(pnl % 65536); /* lsb */
36434 +
36435 + /* Phase 1, step 1 */
36436 + p1k[0] = tsc1;
36437 + p1k[1] = tsc0;
36438 + p1k[2] = (UINT)(ta[0] + (ta[1]*256));
36439 + p1k[3] = (UINT)(ta[2] + (ta[3]*256));
36440 + p1k[4] = (UINT)(ta[4] + (ta[5]*256));
36441 +
36442 + /* Phase 1, step 2 */
36443 + for (i=0; i<8; i++)
36444 + {
36445 + j = 2*(i & 1);
36446 + p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*key[1+j]) + key[j])) % 65536 )) % 65536;
36447 + p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*key[5+j]) + key[4+j])) % 65536 )) % 65536;
36448 + p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*key[9+j]) + key[8+j])) % 65536 )) % 65536;
36449 + p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*key[13+j]) + key[12+j])) % 65536 )) % 65536;
36450 + p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*key[1+j]) + key[j]))) % 65536 )) % 65536;
36451 + p1k[4] = (p1k[4] + i) % 65536;
36452 + }
36453 +
36454 + /* Phase 2, Step 1 */
36455 + ppk0 = p1k[0];
36456 + ppk1 = p1k[1];
36457 + ppk2 = p1k[2];
36458 + ppk3 = p1k[3];
36459 + ppk4 = p1k[4];
36460 + ppk5 = (p1k[4] + tsc2) % 65536;
36461 +
36462 + /* Phase2, Step 2 */
36463 + ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*key[1]) + key[0])) % 65536);
36464 + ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*key[3]) + key[2])) % 65536);
36465 + ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*key[5]) + key[4])) % 65536);
36466 + ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*key[7]) + key[6])) % 65536);
36467 + ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*key[9]) + key[8])) % 65536);
36468 + ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*key[11]) + key[10])) % 65536);
36469 +
36470 + ppk0 = ppk0 + rotr1(ppk5 ^ ((256*key[13]) + key[12]));
36471 + ppk1 = ppk1 + rotr1(ppk0 ^ ((256*key[15]) + key[14]));
36472 + ppk2 = ppk2 + rotr1(ppk1);
36473 + ppk3 = ppk3 + rotr1(ppk2);
36474 + ppk4 = ppk4 + rotr1(ppk3);
36475 + ppk5 = ppk5 + rotr1(ppk4);
36476 +
36477 + /* Phase 2, Step 3 */
36478 + /* Phase 2, Step 3 */
36479 +
36480 + tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
36481 + tsc1 = (unsigned int)(pnh % 65536);
36482 + tsc2 = (unsigned int)(pnl % 65536); /* lsb */
36483 +
36484 + rc4key[0] = (tsc2 >> 8) % 256;
36485 + rc4key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
36486 + rc4key[2] = tsc2 % 256;
36487 + rc4key[3] = ((ppk5 ^ ((256*key[1]) + key[0])) >> 1) % 256;
36488 +
36489 + rc4key[4] = ppk0 % 256;
36490 + rc4key[5] = (ppk0 >> 8) % 256;
36491 +
36492 + rc4key[6] = ppk1 % 256;
36493 + rc4key[7] = (ppk1 >> 8) % 256;
36494 +
36495 + rc4key[8] = ppk2 % 256;
36496 + rc4key[9] = (ppk2 >> 8) % 256;
36497 +
36498 + rc4key[10] = ppk3 % 256;
36499 + rc4key[11] = (ppk3 >> 8) % 256;
36500 +
36501 + rc4key[12] = ppk4 % 256;
36502 + rc4key[13] = (ppk4 >> 8) % 256;
36503 +
36504 + rc4key[14] = ppk5 % 256;
36505 + rc4key[15] = (ppk5 >> 8) % 256;
36506 +}
36507 +
36508 +
36509 +/************************************************/
36510 +/* construct_mic_header1() */
36511 +/* Builds the first MIC header block from */
36512 +/* header fields. */
36513 +/************************************************/
36514 +
36515 +void construct_mic_header1(
36516 + unsigned char *mic_header1,
36517 + int header_length,
36518 + unsigned char *mpdu)
36519 +{
36520 + mic_header1[0] = (unsigned char)((header_length - 2) / 256);
36521 + mic_header1[1] = (unsigned char)((header_length - 2) % 256);
36522 + mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */
36523 + mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */
36524 + mic_header1[4] = mpdu[4]; /* A1 */
36525 + mic_header1[5] = mpdu[5];
36526 + mic_header1[6] = mpdu[6];
36527 + mic_header1[7] = mpdu[7];
36528 + mic_header1[8] = mpdu[8];
36529 + mic_header1[9] = mpdu[9];
36530 + mic_header1[10] = mpdu[10]; /* A2 */
36531 + mic_header1[11] = mpdu[11];
36532 + mic_header1[12] = mpdu[12];
36533 + mic_header1[13] = mpdu[13];
36534 + mic_header1[14] = mpdu[14];
36535 + mic_header1[15] = mpdu[15];
36536 +}
36537 +
36538 +/************************************************/
36539 +/* construct_mic_header2() */
36540 +/* Builds the last MIC header block from */
36541 +/* header fields. */
36542 +/************************************************/
36543 +
36544 +void construct_mic_header2(
36545 + unsigned char *mic_header2,
36546 + unsigned char *mpdu,
36547 + int a4_exists,
36548 + int qc_exists)
36549 +{
36550 + int i;
36551 +
36552 + for (i = 0; i<16; i++) mic_header2[i]=0x00;
36553 +
36554 + mic_header2[0] = mpdu[16]; /* A3 */
36555 + mic_header2[1] = mpdu[17];
36556 + mic_header2[2] = mpdu[18];
36557 + mic_header2[3] = mpdu[19];
36558 + mic_header2[4] = mpdu[20];
36559 + mic_header2[5] = mpdu[21];
36560 +
36561 + // In Sequence Control field, mute sequence numer bits (12-bit)
36562 + mic_header2[6] = mpdu[22] & 0x0f; /* SC */
36563 + mic_header2[7] = 0x00; /* mpdu[23]; */
36564 +
36565 + if ((!qc_exists) & a4_exists)
36566 + {
36567 + for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
36568 +
36569 + }
36570 +
36571 + if (qc_exists && (!a4_exists))
36572 + {
36573 + mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */
36574 + mic_header2[9] = mpdu[25] & 0x00;
36575 + }
36576 +
36577 + if (qc_exists && a4_exists)
36578 + {
36579 + for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
36580 +
36581 + mic_header2[14] = mpdu[30] & 0x0f;
36582 + mic_header2[15] = mpdu[31] & 0x00;
36583 + }
36584 +}
36585 +
36586 +
36587 +/************************************************/
36588 +/* construct_mic_iv() */
36589 +/* Builds the MIC IV from header fields and PN */
36590 +/************************************************/
36591 +
36592 +void construct_mic_iv(
36593 + unsigned char *mic_iv,
36594 + int qc_exists,
36595 + int a4_exists,
36596 + unsigned char *mpdu,
36597 + unsigned int payload_length,
36598 + unsigned char *pn_vector)
36599 +{
36600 + int i;
36601 +
36602 + mic_iv[0] = 0x59;
36603 + if (qc_exists && a4_exists)
36604 + mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */
36605 + if (qc_exists && !a4_exists)
36606 + mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */
36607 + if (!qc_exists)
36608 + mic_iv[1] = 0x00;
36609 + for (i = 2; i < 8; i++)
36610 + mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */
36611 +#ifdef CONSISTENT_PN_ORDER
36612 + for (i = 8; i < 14; i++)
36613 + mic_iv[i] = pn_vector[i - 8]; /* mic_iv[8:13] = PN[0:5] */
36614 +#else
36615 + for (i = 8; i < 14; i++)
36616 + mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */
36617 +#endif
36618 + i = (payload_length / 256);
36619 + i = (payload_length % 256);
36620 + mic_iv[14] = (unsigned char) (payload_length / 256);
36621 + mic_iv[15] = (unsigned char) (payload_length % 256);
36622 +
36623 +}
36624 +
36625 +
36626 +
36627 +/************************************/
36628 +/* bitwise_xor() */
36629 +/* A 128 bit, bitwise exclusive or */
36630 +/************************************/
36631 +
36632 +void bitwise_xor(unsigned char *ina, unsigned char *inb, unsigned char *out)
36633 +{
36634 + int i;
36635 + for (i=0; i<16; i++)
36636 + {
36637 + out[i] = ina[i] ^ inb[i];
36638 + }
36639 +}
36640 +
36641 +
36642 +void aes128k128d(unsigned char *key, unsigned char *data, unsigned char *ciphertext)
36643 +{
36644 + int round;
36645 + int i;
36646 + unsigned char intermediatea[16];
36647 + unsigned char intermediateb[16];
36648 + unsigned char round_key[16];
36649 +
36650 + for(i=0; i<16; i++) round_key[i] = key[i];
36651 +
36652 + for (round = 0; round < 11; round++)
36653 + {
36654 + if (round == 0)
36655 + {
36656 + xor_128(round_key, data, ciphertext);
36657 + next_key(round_key, round);
36658 + }
36659 + else if (round == 10)
36660 + {
36661 + byte_sub(ciphertext, intermediatea);
36662 + shift_row(intermediatea, intermediateb);
36663 + xor_128(intermediateb, round_key, ciphertext);
36664 + }
36665 + else /* 1 - 9 */
36666 + {
36667 + byte_sub(ciphertext, intermediatea);
36668 + shift_row(intermediatea, intermediateb);
36669 + mix_column(&intermediateb[0], &intermediatea[0]);
36670 + mix_column(&intermediateb[4], &intermediatea[4]);
36671 + mix_column(&intermediateb[8], &intermediatea[8]);
36672 + mix_column(&intermediateb[12], &intermediatea[12]);
36673 + xor_128(intermediatea, round_key, ciphertext);
36674 + next_key(round_key, round);
36675 + }
36676 + }
36677 +
36678 +}
36679 +
36680 +void construct_ctr_preload(
36681 + unsigned char *ctr_preload,
36682 + int a4_exists,
36683 + int qc_exists,
36684 + unsigned char *mpdu,
36685 + unsigned char *pn_vector,
36686 + int c)
36687 +{
36688 +
36689 + int i = 0;
36690 + for (i=0; i<16; i++) ctr_preload[i] = 0x00;
36691 + i = 0;
36692 +
36693 + ctr_preload[0] = 0x01; /* flag */
36694 + if (qc_exists && a4_exists) ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */
36695 + if (qc_exists && !a4_exists) ctr_preload[1] = mpdu[24] & 0x0f;
36696 +
36697 + for (i = 2; i < 8; i++)
36698 + ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
36699 +#ifdef CONSISTENT_PN_ORDER
36700 + for (i = 8; i < 14; i++)
36701 + ctr_preload[i] = pn_vector[i - 8]; /* ctr_preload[8:13] = PN[0:5] */
36702 +#else
36703 + for (i = 8; i < 14; i++)
36704 + ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */
36705 +#endif
36706 + ctr_preload[14] = (unsigned char) (c / 256); // Ctr
36707 + ctr_preload[15] = (unsigned char) (c % 256);
36708 +
36709 +}
36710 +
36711 +
36712 +//
36713 +// TRUE: Success!
36714 +// FALSE: Decrypt Error!
36715 +//
36716 +BOOLEAN RTMPSoftDecryptTKIP(
36717 + IN PRTMP_ADAPTER pAd,
36718 + IN PUCHAR pData,
36719 + IN ULONG DataByteCnt,
36720 + IN UCHAR UserPriority,
36721 + IN PCIPHER_KEY pWpaKey)
36722 +{
36723 + UCHAR KeyID;
36724 + UINT HeaderLen;
36725 + UCHAR fc0;
36726 + UCHAR fc1;
36727 + USHORT fc;
36728 + UINT frame_type;
36729 + UINT frame_subtype;
36730 + UINT from_ds;
36731 + UINT to_ds;
36732 + INT a4_exists;
36733 + INT qc_exists;
36734 + USHORT duration;
36735 + USHORT seq_control;
36736 + USHORT qos_control;
36737 + UCHAR TA[MAC_ADDR_LEN];
36738 + UCHAR DA[MAC_ADDR_LEN];
36739 + UCHAR SA[MAC_ADDR_LEN];
36740 + UCHAR RC4Key[16];
36741 + UINT p1k[5]; //for mix_key;
36742 + ULONG pnl;/* Least significant 16 bits of PN */
36743 + ULONG pnh;/* Most significant 32 bits of PN */
36744 + UINT num_blocks;
36745 + UINT payload_remainder;
36746 + ARCFOURCONTEXT ArcFourContext;
36747 + UINT crc32 = 0;
36748 + UINT trailfcs = 0;
36749 + UCHAR MIC[8];
36750 + UCHAR TrailMIC[8];
36751 +
36752 +#ifdef RT_BIG_ENDIAN
36753 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
36754 +#endif
36755 +
36756 + fc0 = *pData;
36757 + fc1 = *(pData + 1);
36758 +
36759 + fc = *((PUSHORT)pData);
36760 +
36761 + frame_type = ((fc0 >> 2) & 0x03);
36762 + frame_subtype = ((fc0 >> 4) & 0x0f);
36763 +
36764 + from_ds = (fc1 & 0x2) >> 1;
36765 + to_ds = (fc1 & 0x1);
36766 +
36767 + a4_exists = (from_ds & to_ds);
36768 + qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
36769 + (frame_subtype == 0x09) || /* Likely to change. */
36770 + (frame_subtype == 0x0a) ||
36771 + (frame_subtype == 0x0b)
36772 + );
36773 +
36774 + HeaderLen = 24;
36775 + if (a4_exists)
36776 + HeaderLen += 6;
36777 +
36778 + KeyID = *((PUCHAR)(pData+ HeaderLen + 3));
36779 + KeyID = KeyID >> 6;
36780 +
36781 + if (pWpaKey[KeyID].KeyLen == 0)
36782 + {
36783 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP failed!(KeyID[%d] Length can not be 0)\n", KeyID));
36784 + return FALSE;
36785 + }
36786 +
36787 + duration = *((PUSHORT)(pData+2));
36788 +
36789 + seq_control = *((PUSHORT)(pData+22));
36790 +
36791 + if (qc_exists)
36792 + {
36793 + if (a4_exists)
36794 + {
36795 + qos_control = *((PUSHORT)(pData+30));
36796 + }
36797 + else
36798 + {
36799 + qos_control = *((PUSHORT)(pData+24));
36800 + }
36801 + }
36802 +
36803 + if (to_ds == 0 && from_ds == 1)
36804 + {
36805 + NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN);
36806 + NdisMoveMemory(SA, pData+16, MAC_ADDR_LEN);
36807 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); //BSSID
36808 + }
36809 + else if (to_ds == 0 && from_ds == 0 )
36810 + {
36811 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
36812 + NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN);
36813 + NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN);
36814 + }
36815 + else if (to_ds == 1 && from_ds == 0)
36816 + {
36817 + NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN);
36818 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
36819 + NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN);
36820 + }
36821 + else if (to_ds == 1 && from_ds == 1)
36822 + {
36823 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
36824 + NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN);
36825 + NdisMoveMemory(SA, pData+22, MAC_ADDR_LEN);
36826 + }
36827 +
36828 + num_blocks = (DataByteCnt - 16) / 16;
36829 + payload_remainder = (DataByteCnt - 16) % 16;
36830 +
36831 + pnl = (*(pData + HeaderLen)) * 256 + *(pData + HeaderLen + 2);
36832 + pnh = *((PULONG)(pData + HeaderLen + 4));
36833 + pnh = cpu2le32(pnh);
36834 + RTMPTkipMixKey(pWpaKey[KeyID].Key, TA, pnl, pnh, RC4Key, p1k);
36835 +
36836 + ARCFOUR_INIT(&ArcFourContext, RC4Key, 16);
36837 +
36838 + ARCFOUR_DECRYPT(&ArcFourContext, pData + HeaderLen, pData + HeaderLen + 8, DataByteCnt - HeaderLen - 8);
36839 + NdisMoveMemory(&trailfcs, pData + DataByteCnt - 8 - 4, 4);
36840 + crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 4); //Skip IV+EIV 8 bytes & Skip last 4 bytes(FCS).
36841 + crc32 ^= 0xffffffff; /* complement */
36842 +
36843 + if(crc32 != cpu2le32(trailfcs))
36844 + {
36845 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP, WEP Data ICV Error !\n")); //ICV error.
36846 +
36847 + return (FALSE);
36848 + }
36849 +
36850 + NdisMoveMemory(TrailMIC, pData + DataByteCnt - 8 - 8 - 4, 8);
36851 + RTMPInitMICEngine(pAd, pWpaKey[KeyID].Key, DA, SA, UserPriority, pWpaKey[KeyID].RxMic);
36852 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 12);
36853 + RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
36854 + NdisMoveMemory(MIC, pAd->PrivateInfo.Tx.MIC, 8);
36855 +
36856 + if (!NdisEqualMemory(MIC, TrailMIC, 8))
36857 + {
36858 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptTKIP, WEP Data MIC Error !\n")); //MIC error.
36859 + //RTMPReportMicError(pAd, &pWpaKey[KeyID]); // marked by AlbertY @ 20060630
36860 + return (FALSE);
36861 + }
36862 +
36863 +#ifdef RT_BIG_ENDIAN
36864 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
36865 +#endif
36866 + //DBGPRINT(RT_DEBUG_TRACE, "RTMPSoftDecryptTKIP Decript done!!\n");
36867 + return TRUE;
36868 +}
36869 +
36870 +
36871 +
36872 +
36873 +BOOLEAN RTMPSoftDecryptAES(
36874 + IN PRTMP_ADAPTER pAd,
36875 + IN PUCHAR pData,
36876 + IN ULONG DataByteCnt,
36877 + IN PCIPHER_KEY pWpaKey)
36878 +{
36879 + UCHAR KeyID;
36880 + UINT HeaderLen;
36881 + UCHAR PN[6];
36882 + UINT payload_len;
36883 + UINT num_blocks;
36884 + UINT payload_remainder;
36885 + USHORT fc;
36886 + UCHAR fc0;
36887 + UCHAR fc1;
36888 + UINT frame_type;
36889 + UINT frame_subtype;
36890 + UINT from_ds;
36891 + UINT to_ds;
36892 + INT a4_exists;
36893 + INT qc_exists;
36894 + UCHAR aes_out[16];
36895 + int payload_index;
36896 + UINT i;
36897 + UCHAR ctr_preload[16];
36898 + UCHAR chain_buffer[16];
36899 + UCHAR padded_buffer[16];
36900 + UCHAR mic_iv[16];
36901 + UCHAR mic_header1[16];
36902 + UCHAR mic_header2[16];
36903 + UCHAR MIC[8];
36904 + UCHAR TrailMIC[8];
36905 +
36906 +#ifdef RT_BIG_ENDIAN
36907 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
36908 +#endif
36909 +
36910 + fc0 = *pData;
36911 + fc1 = *(pData + 1);
36912 +
36913 + fc = *((PUSHORT)pData);
36914 +
36915 + frame_type = ((fc0 >> 2) & 0x03);
36916 + frame_subtype = ((fc0 >> 4) & 0x0f);
36917 +
36918 + from_ds = (fc1 & 0x2) >> 1;
36919 + to_ds = (fc1 & 0x1);
36920 +
36921 + a4_exists = (from_ds & to_ds);
36922 + qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
36923 + (frame_subtype == 0x09) || /* Likely to change. */
36924 + (frame_subtype == 0x0a) ||
36925 + (frame_subtype == 0x0b)
36926 + );
36927 +
36928 + HeaderLen = 24;
36929 + if (a4_exists)
36930 + HeaderLen += 6;
36931 +
36932 + KeyID = *((PUCHAR)(pData+ HeaderLen + 3));
36933 + KeyID = KeyID >> 6;
36934 +
36935 + if (pWpaKey[KeyID].KeyLen == 0)
36936 + {
36937 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptAES failed!(KeyID[%d] Length can not be 0)\n", KeyID));
36938 + return FALSE;
36939 + }
36940 +
36941 + PN[0] = *(pData+ HeaderLen);
36942 + PN[1] = *(pData+ HeaderLen + 1);
36943 + PN[2] = *(pData+ HeaderLen + 4);
36944 + PN[3] = *(pData+ HeaderLen + 5);
36945 + PN[4] = *(pData+ HeaderLen + 6);
36946 + PN[5] = *(pData+ HeaderLen + 7);
36947 +
36948 + payload_len = DataByteCnt - HeaderLen - 8 - 8; // 8 bytes for CCMP header , 8 bytes for MIC
36949 + payload_remainder = (payload_len) % 16;
36950 + num_blocks = (payload_len) / 16;
36951 +
36952 +
36953 +
36954 + // Find start of payload
36955 + payload_index = HeaderLen + 8; //IV+EIV
36956 +
36957 + for (i=0; i< num_blocks; i++)
36958 + {
36959 + construct_ctr_preload(ctr_preload,
36960 + a4_exists,
36961 + qc_exists,
36962 + pData,
36963 + PN,
36964 + i+1 );
36965 +
36966 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
36967 +
36968 + bitwise_xor(aes_out, pData + payload_index, chain_buffer);
36969 + NdisMoveMemory(pData + payload_index - 8, chain_buffer, 16);
36970 + payload_index += 16;
36971 + }
36972 +
36973 + //
36974 + // If there is a short final block, then pad it
36975 + // encrypt it and copy the unpadded part back
36976 + //
36977 + if (payload_remainder > 0)
36978 + {
36979 + construct_ctr_preload(ctr_preload,
36980 + a4_exists,
36981 + qc_exists,
36982 + pData,
36983 + PN,
36984 + num_blocks + 1);
36985 +
36986 + NdisZeroMemory(padded_buffer, 16);
36987 + NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder);
36988 +
36989 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
36990 +
36991 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
36992 + NdisMoveMemory(pData + payload_index - 8, chain_buffer, payload_remainder);
36993 + payload_index += payload_remainder;
36994 + }
36995 +
36996 + //
36997 + // Descrypt the MIC
36998 + //
36999 + construct_ctr_preload(ctr_preload,
37000 + a4_exists,
37001 + qc_exists,
37002 + pData,
37003 + PN,
37004 + 0);
37005 + NdisZeroMemory(padded_buffer, 16);
37006 + NdisMoveMemory(padded_buffer, pData + payload_index, 8);
37007 +
37008 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
37009 +
37010 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
37011 +
37012 + NdisMoveMemory(TrailMIC, chain_buffer, 8);
37013 +
37014 + //
37015 + // Calculate MIC
37016 + //
37017 +
37018 + //Force the protected frame bit on
37019 + *(pData + 1) = *(pData + 1) | 0x40;
37020 +
37021 + // Find start of payload
37022 + // Because the CCMP header has been removed
37023 + payload_index = HeaderLen;
37024 +
37025 + construct_mic_iv(
37026 + mic_iv,
37027 + qc_exists,
37028 + a4_exists,
37029 + pData,
37030 + payload_len,
37031 + PN);
37032 +
37033 + construct_mic_header1(
37034 + mic_header1,
37035 + HeaderLen,
37036 + pData);
37037 +
37038 + construct_mic_header2(
37039 + mic_header2,
37040 + pData,
37041 + a4_exists,
37042 + qc_exists);
37043 +
37044 + aes128k128d(pWpaKey[KeyID].Key, mic_iv, aes_out);
37045 + bitwise_xor(aes_out, mic_header1, chain_buffer);
37046 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37047 + bitwise_xor(aes_out, mic_header2, chain_buffer);
37048 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37049 +
37050 + // iterate through each 16 byte payload block
37051 + for (i = 0; i < num_blocks; i++)
37052 + {
37053 + bitwise_xor(aes_out, pData + payload_index, chain_buffer);
37054 + payload_index += 16;
37055 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37056 + }
37057 +
37058 + // Add on the final payload block if it needs padding
37059 + if (payload_remainder > 0)
37060 + {
37061 + NdisZeroMemory(padded_buffer, 16);
37062 + NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder);
37063 +
37064 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
37065 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37066 + }
37067 +
37068 + // aes_out contains padded mic, discard most significant
37069 + // 8 bytes to generate 64 bit MIC
37070 + for (i = 0 ; i < 8; i++) MIC[i] = aes_out[i];
37071 +
37072 + if (!NdisEqualMemory(MIC, TrailMIC, 8))
37073 + {
37074 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptAES, MIC Error !\n")); //MIC error.
37075 + return FALSE;
37076 + }
37077 +
37078 +#ifdef RT_BIG_ENDIAN
37079 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
37080 +#endif
37081 +
37082 + return TRUE;
37083 +}
37084 +
37085 +/****************************************/
37086 +/* aes128k128d() */
37087 +/* Performs a 128 bit AES encrypt with */
37088 +/* 128 bit data. */
37089 +/****************************************/
37090 +VOID xor_128(
37091 + IN PUCHAR a,
37092 + IN PUCHAR b,
37093 + OUT PUCHAR out)
37094 +{
37095 + INT i;
37096 +
37097 + for (i=0;i<16; i++)
37098 + {
37099 + out[i] = a[i] ^ b[i];
37100 + }
37101 +}
37102 +
37103 +VOID next_key(
37104 + IN PUCHAR key,
37105 + IN INT round)
37106 +{
37107 + UCHAR rcon;
37108 + UCHAR sbox_key[4];
37109 + UCHAR rcon_table[12] =
37110 + {
37111 + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
37112 + 0x1b, 0x36, 0x36, 0x36
37113 + };
37114 +
37115 + sbox_key[0] = RTMPCkipSbox(key[13]);
37116 + sbox_key[1] = RTMPCkipSbox(key[14]);
37117 + sbox_key[2] = RTMPCkipSbox(key[15]);
37118 + sbox_key[3] = RTMPCkipSbox(key[12]);
37119 +
37120 + rcon = rcon_table[round];
37121 +
37122 + xor_32(&key[0], sbox_key, &key[0]);
37123 + key[0] = key[0] ^ rcon;
37124 +
37125 + xor_32(&key[4], &key[0], &key[4]);
37126 + xor_32(&key[8], &key[4], &key[8]);
37127 + xor_32(&key[12], &key[8], &key[12]);
37128 +}
37129 +
37130 +VOID xor_32(
37131 + IN PUCHAR a,
37132 + IN PUCHAR b,
37133 + OUT PUCHAR out)
37134 +{
37135 + INT i;
37136 +
37137 + for (i=0;i<4; i++)
37138 + {
37139 + out[i] = a[i] ^ b[i];
37140 + }
37141 +}
37142 +
37143 +VOID byte_sub(
37144 + IN PUCHAR in,
37145 + OUT PUCHAR out)
37146 +{
37147 + INT i;
37148 +
37149 + for (i=0; i< 16; i++)
37150 + {
37151 + out[i] = RTMPCkipSbox(in[i]);
37152 + }
37153 +}
37154 +
37155 +UCHAR RTMPCkipSbox(
37156 + IN UCHAR a)
37157 +{
37158 + return SboxTable[(int)a];
37159 +}
37160 +
37161 +VOID shift_row(
37162 + IN PUCHAR in,
37163 + OUT PUCHAR out)
37164 +{
37165 + out[0] = in[0];
37166 + out[1] = in[5];
37167 + out[2] = in[10];
37168 + out[3] = in[15];
37169 + out[4] = in[4];
37170 + out[5] = in[9];
37171 + out[6] = in[14];
37172 + out[7] = in[3];
37173 + out[8] = in[8];
37174 + out[9] = in[13];
37175 + out[10] = in[2];
37176 + out[11] = in[7];
37177 + out[12] = in[12];
37178 + out[13] = in[1];
37179 + out[14] = in[6];
37180 + out[15] = in[11];
37181 +}
37182 +
37183 +VOID mix_column(
37184 + IN PUCHAR in,
37185 + OUT PUCHAR out)
37186 +{
37187 + INT i;
37188 + UCHAR add1b[4];
37189 + UCHAR add1bf7[4];
37190 + UCHAR rotl[4];
37191 + UCHAR swap_halfs[4];
37192 + UCHAR andf7[4];
37193 + UCHAR rotr[4];
37194 + UCHAR temp[4];
37195 + UCHAR tempb[4];
37196 +
37197 + for (i=0 ; i<4; i++)
37198 + {
37199 + if ((in[i] & 0x80)== 0x80)
37200 + add1b[i] = 0x1b;
37201 + else
37202 + add1b[i] = 0x00;
37203 + }
37204 +
37205 + swap_halfs[0] = in[2]; /* Swap halfs */
37206 + swap_halfs[1] = in[3];
37207 + swap_halfs[2] = in[0];
37208 + swap_halfs[3] = in[1];
37209 +
37210 + rotl[0] = in[3]; /* Rotate left 8 bits */
37211 + rotl[1] = in[0];
37212 + rotl[2] = in[1];
37213 + rotl[3] = in[2];
37214 +
37215 + andf7[0] = in[0] & 0x7f;
37216 + andf7[1] = in[1] & 0x7f;
37217 + andf7[2] = in[2] & 0x7f;
37218 + andf7[3] = in[3] & 0x7f;
37219 +
37220 + for (i = 3; i>0; i--) /* logical shift left 1 bit */
37221 + {
37222 + andf7[i] = andf7[i] << 1;
37223 + if ((andf7[i-1] & 0x80) == 0x80)
37224 + {
37225 + andf7[i] = (andf7[i] | 0x01);
37226 + }
37227 + }
37228 + andf7[0] = andf7[0] << 1;
37229 + andf7[0] = andf7[0] & 0xfe;
37230 +
37231 + xor_32(add1b, andf7, add1bf7);
37232 +
37233 + xor_32(in, add1bf7, rotr);
37234 +
37235 + temp[0] = rotr[0]; /* Rotate right 8 bits */
37236 + rotr[0] = rotr[1];
37237 + rotr[1] = rotr[2];
37238 + rotr[2] = rotr[3];
37239 + rotr[3] = temp[0];
37240 +
37241 + xor_32(add1bf7, rotr, temp);
37242 + xor_32(swap_halfs, rotl,tempb);
37243 + xor_32(temp, tempb, out);
37244 +}
37245 +
37246 --- /dev/null
37247 +++ b/drivers/staging/rt2870/common/rtmp_wep.c
37248 @@ -0,0 +1,508 @@
37249 +/*
37250 + *************************************************************************
37251 + * Ralink Tech Inc.
37252 + * 5F., No.36, Taiyuan St., Jhubei City,
37253 + * Hsinchu County 302,
37254 + * Taiwan, R.O.C.
37255 + *
37256 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
37257 + *
37258 + * This program is free software; you can redistribute it and/or modify *
37259 + * it under the terms of the GNU General Public License as published by *
37260 + * the Free Software Foundation; either version 2 of the License, or *
37261 + * (at your option) any later version. *
37262 + * *
37263 + * This program is distributed in the hope that it will be useful, *
37264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
37265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
37266 + * GNU General Public License for more details. *
37267 + * *
37268 + * You should have received a copy of the GNU General Public License *
37269 + * along with this program; if not, write to the *
37270 + * Free Software Foundation, Inc., *
37271 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
37272 + * *
37273 + *************************************************************************
37274 +
37275 + Module Name:
37276 + rtmp_wep.c
37277 +
37278 + Abstract:
37279 +
37280 + Revision History:
37281 + Who When What
37282 + -------- ---------- ----------------------------------------------
37283 + Paul Wu 10-28-02 Initial
37284 +*/
37285 +
37286 +#include "../rt_config.h"
37287 +
37288 +UINT FCSTAB_32[256] =
37289 +{
37290 + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
37291 + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
37292 + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
37293 + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
37294 + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
37295 + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
37296 + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
37297 + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
37298 + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
37299 + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
37300 + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
37301 + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
37302 + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
37303 + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
37304 + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
37305 + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
37306 + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
37307 + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
37308 + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
37309 + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
37310 + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
37311 + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
37312 + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
37313 + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
37314 + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
37315 + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
37316 + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
37317 + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
37318 + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
37319 + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
37320 + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
37321 + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
37322 + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
37323 + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
37324 + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
37325 + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
37326 + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
37327 + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
37328 + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
37329 + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
37330 + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
37331 + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
37332 + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
37333 + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
37334 + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
37335 + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
37336 + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
37337 + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
37338 + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
37339 + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
37340 + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
37341 + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
37342 + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
37343 + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
37344 + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
37345 + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
37346 + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
37347 + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
37348 + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
37349 + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
37350 + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
37351 + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
37352 + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
37353 + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
37354 +};
37355 +
37356 +/*
37357 +UCHAR WEPKEY[] = {
37358 + //IV
37359 + 0x00, 0x11, 0x22,
37360 + //WEP KEY
37361 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
37362 + };
37363 + */
37364 +
37365 +/*
37366 + ========================================================================
37367 +
37368 + Routine Description:
37369 + Init WEP function.
37370 +
37371 + Arguments:
37372 + pAd Pointer to our adapter
37373 + pKey Pointer to the WEP KEY
37374 + KeyId WEP Key ID
37375 + KeyLen the length of WEP KEY
37376 + pDest Pointer to the destination which Encryption data will store in.
37377 +
37378 + Return Value:
37379 + None
37380 +
37381 + IRQL = DISPATCH_LEVEL
37382 +
37383 + Note:
37384 +
37385 + ========================================================================
37386 +*/
37387 +VOID RTMPInitWepEngine(
37388 + IN PRTMP_ADAPTER pAd,
37389 + IN PUCHAR pKey,
37390 + IN UCHAR KeyId,
37391 + IN UCHAR KeyLen,
37392 + IN OUT PUCHAR pDest)
37393 +{
37394 + UINT i;
37395 + UCHAR WEPKEY[] = {
37396 + //IV
37397 + 0x00, 0x11, 0x22,
37398 + //WEP KEY
37399 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
37400 + };
37401 +
37402 + pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32.
37403 +
37404 +#ifdef CONFIG_STA_SUPPORT
37405 + if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10) && (pAd->OpMode == OPMODE_STA))
37406 + {
37407 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, pKey, KeyLen); //INIT SBOX, KEYLEN+3(IV)
37408 + NdisMoveMemory(pDest, pKey, 3); //Append Init Vector
37409 + }
37410 + else
37411 +#endif // CONFIG_STA_SUPPORT //
37412 + {
37413 + NdisMoveMemory(WEPKEY + 3, pKey, KeyLen);
37414 +
37415 + for(i = 0; i < 3; i++)
37416 + WEPKEY[i] = RandomByte(pAd); //Call mlme RandomByte() function.
37417 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, KeyLen + 3); //INIT SBOX, KEYLEN+3(IV)
37418 +
37419 + NdisMoveMemory(pDest, WEPKEY, 3); //Append Init Vector
37420 + }
37421 + *(pDest+3) = (KeyId << 6); //Append KEYID
37422 +
37423 +}
37424 +
37425 +/*
37426 + ========================================================================
37427 +
37428 + Routine Description:
37429 + Encrypt transimitted data
37430 +
37431 + Arguments:
37432 + pAd Pointer to our adapter
37433 + pSrc Pointer to the transimitted source data that will be encrypt
37434 + pDest Pointer to the destination where entryption data will be store in.
37435 + Len Indicate the length of the source data
37436 +
37437 + Return Value:
37438 + None
37439 +
37440 + IRQL = DISPATCH_LEVEL
37441 +
37442 + Note:
37443 +
37444 + ========================================================================
37445 +*/
37446 +VOID RTMPEncryptData(
37447 + IN PRTMP_ADAPTER pAd,
37448 + IN PUCHAR pSrc,
37449 + IN PUCHAR pDest,
37450 + IN UINT Len)
37451 +{
37452 + pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, pSrc, Len);
37453 + ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, pSrc, Len);
37454 +}
37455 +
37456 +
37457 +/*
37458 + ========================================================================
37459 +
37460 + Routine Description:
37461 + Decrypt received WEP data
37462 +
37463 + Arguments:
37464 + pAdapter Pointer to our adapter
37465 + pSrc Pointer to the received data
37466 + Len the length of the received data
37467 +
37468 + Return Value:
37469 + TRUE Decrypt WEP data success
37470 + FALSE Decrypt WEP data failed
37471 +
37472 + Note:
37473 +
37474 + ========================================================================
37475 +*/
37476 +BOOLEAN RTMPSoftDecryptWEP(
37477 + IN PRTMP_ADAPTER pAd,
37478 + IN PUCHAR pData,
37479 + IN ULONG DataByteCnt,
37480 + IN PCIPHER_KEY pGroupKey)
37481 +{
37482 + UINT trailfcs;
37483 + UINT crc32;
37484 + UCHAR KeyIdx;
37485 + UCHAR WEPKEY[] = {
37486 + //IV
37487 + 0x00, 0x11, 0x22,
37488 + //WEP KEY
37489 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
37490 + };
37491 + UCHAR *pPayload = (UCHAR *)pData + LENGTH_802_11;
37492 + ULONG payload_len = DataByteCnt - LENGTH_802_11;
37493 +
37494 + NdisMoveMemory(WEPKEY, pPayload, 3); //Get WEP IV
37495 +
37496 + KeyIdx = (*(pPayload + 3) & 0xc0) >> 6;
37497 + if (pGroupKey[KeyIdx].KeyLen == 0)
37498 + return (FALSE);
37499 +
37500 + NdisMoveMemory(WEPKEY + 3, pGroupKey[KeyIdx].Key, pGroupKey[KeyIdx].KeyLen);
37501 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, pGroupKey[KeyIdx].KeyLen + 3);
37502 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, pPayload, pPayload + 4, payload_len - 4);
37503 + NdisMoveMemory(&trailfcs, pPayload + payload_len - 8, 4);
37504 + crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pPayload, payload_len - 8); //Skip last 4 bytes(FCS).
37505 + crc32 ^= 0xffffffff; /* complement */
37506 +
37507 + if(crc32 != cpu2le32(trailfcs))
37508 + {
37509 + DBGPRINT(RT_DEBUG_TRACE, ("! WEP Data CRC Error !\n")); //CRC error.
37510 + return (FALSE);
37511 + }
37512 + return (TRUE);
37513 +}
37514 +
37515 +/*
37516 + ========================================================================
37517 +
37518 + Routine Description:
37519 + The Stream Cipher Encryption Algorithm "ARCFOUR" initialize
37520 +
37521 + Arguments:
37522 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
37523 + pKey Pointer to the WEP KEY
37524 + KeyLen Indicate the length fo the WEP KEY
37525 +
37526 + Return Value:
37527 + None
37528 +
37529 + IRQL = DISPATCH_LEVEL
37530 +
37531 + Note:
37532 +
37533 + ========================================================================
37534 +*/
37535 +VOID ARCFOUR_INIT(
37536 + IN PARCFOURCONTEXT Ctx,
37537 + IN PUCHAR pKey,
37538 + IN UINT KeyLen)
37539 +{
37540 + UCHAR t, u;
37541 + UINT keyindex;
37542 + UINT stateindex;
37543 + PUCHAR state;
37544 + UINT counter;
37545 +
37546 + state = Ctx->STATE;
37547 + Ctx->X = 0;
37548 + Ctx->Y = 0;
37549 + for (counter = 0; counter < 256; counter++)
37550 + state[counter] = (UCHAR)counter;
37551 + keyindex = 0;
37552 + stateindex = 0;
37553 + for (counter = 0; counter < 256; counter++)
37554 + {
37555 + t = state[counter];
37556 + stateindex = (stateindex + pKey[keyindex] + t) & 0xff;
37557 + u = state[stateindex];
37558 + state[stateindex] = t;
37559 + state[counter] = u;
37560 + if (++keyindex >= KeyLen)
37561 + keyindex = 0;
37562 + }
37563 +}
37564 +
37565 +/*
37566 + ========================================================================
37567 +
37568 + Routine Description:
37569 + Get bytes from ARCFOUR CONTEXT (S-BOX)
37570 +
37571 + Arguments:
37572 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
37573 +
37574 + Return Value:
37575 + UCHAR - the value of the ARCFOUR CONTEXT (S-BOX)
37576 +
37577 + Note:
37578 +
37579 + ========================================================================
37580 +*/
37581 +UCHAR ARCFOUR_BYTE(
37582 + IN PARCFOURCONTEXT Ctx)
37583 +{
37584 + UINT x;
37585 + UINT y;
37586 + UCHAR sx, sy;
37587 + PUCHAR state;
37588 +
37589 + state = Ctx->STATE;
37590 + x = (Ctx->X + 1) & 0xff;
37591 + sx = state[x];
37592 + y = (sx + Ctx->Y) & 0xff;
37593 + sy = state[y];
37594 + Ctx->X = x;
37595 + Ctx->Y = y;
37596 + state[y] = sx;
37597 + state[x] = sy;
37598 +
37599 + return(state[(sx + sy) & 0xff]);
37600 +
37601 +}
37602 +
37603 +/*
37604 + ========================================================================
37605 +
37606 + Routine Description:
37607 + The Stream Cipher Decryption Algorithm
37608 +
37609 + Arguments:
37610 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
37611 + pDest Pointer to the Destination
37612 + pSrc Pointer to the Source data
37613 + Len Indicate the length of the Source data
37614 +
37615 + Return Value:
37616 + None
37617 +
37618 + Note:
37619 +
37620 + ========================================================================
37621 +*/
37622 +VOID ARCFOUR_DECRYPT(
37623 + IN PARCFOURCONTEXT Ctx,
37624 + IN PUCHAR pDest,
37625 + IN PUCHAR pSrc,
37626 + IN UINT Len)
37627 +{
37628 + UINT i;
37629 +
37630 + for (i = 0; i < Len; i++)
37631 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
37632 +}
37633 +
37634 +/*
37635 + ========================================================================
37636 +
37637 + Routine Description:
37638 + The Stream Cipher Encryption Algorithm
37639 +
37640 + Arguments:
37641 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
37642 + pDest Pointer to the Destination
37643 + pSrc Pointer to the Source data
37644 + Len Indicate the length of the Source dta
37645 +
37646 + Return Value:
37647 + None
37648 +
37649 + IRQL = DISPATCH_LEVEL
37650 +
37651 + Note:
37652 +
37653 + ========================================================================
37654 +*/
37655 +VOID ARCFOUR_ENCRYPT(
37656 + IN PARCFOURCONTEXT Ctx,
37657 + IN PUCHAR pDest,
37658 + IN PUCHAR pSrc,
37659 + IN UINT Len)
37660 +{
37661 + UINT i;
37662 +
37663 + for (i = 0; i < Len; i++)
37664 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
37665 +}
37666 +
37667 +/*
37668 + ========================================================================
37669 +
37670 + Routine Description:
37671 + The Stream Cipher Encryption Algorithm which conform to the special requirement to encrypt GTK.
37672 +
37673 + Arguments:
37674 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
37675 + pDest Pointer to the Destination
37676 + pSrc Pointer to the Source data
37677 + Len Indicate the length of the Source dta
37678 +
37679 +
37680 + ========================================================================
37681 +*/
37682 +
37683 +VOID WPAARCFOUR_ENCRYPT(
37684 + IN PARCFOURCONTEXT Ctx,
37685 + IN PUCHAR pDest,
37686 + IN PUCHAR pSrc,
37687 + IN UINT Len)
37688 +{
37689 + UINT i;
37690 + //discard first 256 bytes
37691 + for (i = 0; i < 256; i++)
37692 + ARCFOUR_BYTE(Ctx);
37693 +
37694 + for (i = 0; i < Len; i++)
37695 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
37696 +}
37697 +
37698 +
37699 +/*
37700 + ========================================================================
37701 +
37702 + Routine Description:
37703 + Calculate a new FCS given the current FCS and the new data.
37704 +
37705 + Arguments:
37706 + Fcs the original FCS value
37707 + Cp pointer to the data which will be calculate the FCS
37708 + Len the length of the data
37709 +
37710 + Return Value:
37711 + UINT - FCS 32 bits
37712 +
37713 + IRQL = DISPATCH_LEVEL
37714 +
37715 + Note:
37716 +
37717 + ========================================================================
37718 +*/
37719 +UINT RTMP_CALC_FCS32(
37720 + IN UINT Fcs,
37721 + IN PUCHAR Cp,
37722 + IN INT Len)
37723 +{
37724 + while (Len--)
37725 + Fcs = (((Fcs) >> 8) ^ FCSTAB_32[((Fcs) ^ (*Cp++)) & 0xff]);
37726 +
37727 + return (Fcs);
37728 +}
37729 +
37730 +
37731 +/*
37732 + ========================================================================
37733 +
37734 + Routine Description:
37735 + Get last FCS and encrypt it to the destination
37736 +
37737 + Arguments:
37738 + pDest Pointer to the Destination
37739 +
37740 + Return Value:
37741 + None
37742 +
37743 + Note:
37744 +
37745 + ========================================================================
37746 +*/
37747 +VOID RTMPSetICV(
37748 + IN PRTMP_ADAPTER pAd,
37749 + IN PUCHAR pDest)
37750 +{
37751 + pAd->PrivateInfo.FCSCRC32 ^= 0xffffffff; /* complement */
37752 + pAd->PrivateInfo.FCSCRC32 = cpu2le32(pAd->PrivateInfo.FCSCRC32);
37753 +
37754 + ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, (PUCHAR) &pAd->PrivateInfo.FCSCRC32, 4);
37755 +}
37756 +
37757 --- /dev/null
37758 +++ b/drivers/staging/rt2870/common/rtusb_bulk.c
37759 @@ -0,0 +1,1981 @@
37760 + /*
37761 + *************************************************************************
37762 + * Ralink Tech Inc.
37763 + * 5F., No.36, Taiyuan St., Jhubei City,
37764 + * Hsinchu County 302,
37765 + * Taiwan, R.O.C.
37766 + *
37767 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
37768 + *
37769 + * This program is free software; you can redistribute it and/or modify *
37770 + * it under the terms of the GNU General Public License as published by *
37771 + * the Free Software Foundation; either version 2 of the License, or *
37772 + * (at your option) any later version. *
37773 + * *
37774 + * This program is distributed in the hope that it will be useful, *
37775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
37776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
37777 + * GNU General Public License for more details. *
37778 + * *
37779 + * You should have received a copy of the GNU General Public License *
37780 + * along with this program; if not, write to the *
37781 + * Free Software Foundation, Inc., *
37782 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
37783 + * *
37784 + *************************************************************************
37785 +
37786 + Module Name:
37787 + rtusb_bulk.c
37788 +
37789 + Abstract:
37790 +
37791 + Revision History:
37792 + Who When What
37793 + -------- ---------- ----------------------------------------------
37794 + Name Date Modification logs
37795 + Paul Lin 06-25-2004 created
37796 +
37797 +*/
37798 +
37799 +#include "../rt_config.h"
37800 +// Match total 6 bulkout endpoint to corresponding queue.
37801 +UCHAR EpToQueue[6]={FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_MGMT};
37802 +
37803 +//static BOOLEAN SingleBulkOut = FALSE;
37804 +
37805 +void RTUSB_FILL_BULK_URB (struct urb *pUrb,
37806 + struct usb_device *pUsb_Dev,
37807 + unsigned int bulkpipe,
37808 + void *pTransferBuf,
37809 + int BufSize,
37810 + usb_complete_t Complete,
37811 + void *pContext)
37812 +{
37813 +
37814 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
37815 + usb_fill_bulk_urb(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize, (usb_complete_t)Complete, pContext);
37816 +#else
37817 + FILL_BULK_URB(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize, Complete, pContext);
37818 +#endif
37819 +
37820 +}
37821 +
37822 +VOID RTUSBInitTxDesc(
37823 + IN PRTMP_ADAPTER pAd,
37824 + IN PTX_CONTEXT pTxContext,
37825 + IN UCHAR BulkOutPipeId,
37826 + IN usb_complete_t Func)
37827 +{
37828 + PURB pUrb;
37829 + PUCHAR pSrc = NULL;
37830 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
37831 +
37832 + pUrb = pTxContext->pUrb;
37833 + ASSERT(pUrb);
37834 +
37835 + // Store BulkOut PipeId
37836 + pTxContext->BulkOutPipeId = BulkOutPipeId;
37837 +
37838 + if (pTxContext->bAggregatible)
37839 + {
37840 + pSrc = &pTxContext->TransferBuffer->Aggregation[2];
37841 + }
37842 + else
37843 + {
37844 + pSrc = (PUCHAR) pTxContext->TransferBuffer->field.WirelessPacket;
37845 + }
37846 +
37847 +
37848 + //Initialize a tx bulk urb
37849 + RTUSB_FILL_BULK_URB(pUrb,
37850 + pObj->pUsb_Dev,
37851 + usb_sndbulkpipe(pObj->pUsb_Dev, pAd->BulkOutEpAddr[BulkOutPipeId]),
37852 + pSrc,
37853 + pTxContext->BulkOutSize,
37854 + Func,
37855 + pTxContext);
37856 +
37857 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
37858 + if (pTxContext->bAggregatible)
37859 + pUrb->transfer_dma = (pTxContext->data_dma + TX_BUFFER_NORMSIZE + 2);
37860 + else
37861 + pUrb->transfer_dma = pTxContext->data_dma;
37862 +
37863 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
37864 +#endif
37865 +
37866 +}
37867 +
37868 +VOID RTUSBInitHTTxDesc(
37869 + IN PRTMP_ADAPTER pAd,
37870 + IN PHT_TX_CONTEXT pTxContext,
37871 + IN UCHAR BulkOutPipeId,
37872 + IN ULONG BulkOutSize,
37873 + IN usb_complete_t Func)
37874 +{
37875 + PURB pUrb;
37876 + PUCHAR pSrc = NULL;
37877 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
37878 +
37879 + pUrb = pTxContext->pUrb;
37880 + ASSERT(pUrb);
37881 +
37882 + // Store BulkOut PipeId
37883 + pTxContext->BulkOutPipeId = BulkOutPipeId;
37884 +
37885 + pSrc = &pTxContext->TransferBuffer->field.WirelessPacket[pTxContext->NextBulkOutPosition];
37886 +
37887 +
37888 + //Initialize a tx bulk urb
37889 + RTUSB_FILL_BULK_URB(pUrb,
37890 + pObj->pUsb_Dev,
37891 + usb_sndbulkpipe(pObj->pUsb_Dev, pAd->BulkOutEpAddr[BulkOutPipeId]),
37892 + pSrc,
37893 + BulkOutSize,
37894 + Func,
37895 + pTxContext);
37896 +
37897 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
37898 + pUrb->transfer_dma = (pTxContext->data_dma + pTxContext->NextBulkOutPosition);
37899 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
37900 +#endif
37901 +
37902 +}
37903 +
37904 +VOID RTUSBInitRxDesc(
37905 + IN PRTMP_ADAPTER pAd,
37906 + IN PRX_CONTEXT pRxContext)
37907 +{
37908 + PURB pUrb;
37909 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
37910 + ULONG RX_bulk_size;
37911 +
37912 +
37913 + pUrb = pRxContext->pUrb;
37914 + ASSERT(pUrb);
37915 +
37916 + if ( pAd->BulkInMaxPacketSize == 64)
37917 + RX_bulk_size = 4096;
37918 + else
37919 + RX_bulk_size = MAX_RXBULK_SIZE;
37920 +
37921 + //Initialize a rx bulk urb
37922 + RTUSB_FILL_BULK_URB(pUrb,
37923 + pObj->pUsb_Dev,
37924 + usb_rcvbulkpipe(pObj->pUsb_Dev, pAd->BulkInEpAddr),
37925 + &(pRxContext->TransferBuffer[pAd->NextRxBulkInPosition]),
37926 + RX_bulk_size - (pAd->NextRxBulkInPosition),
37927 + (usb_complete_t)RTUSBBulkRxComplete,
37928 + (void *)pRxContext);
37929 +
37930 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
37931 + pUrb->transfer_dma = pRxContext->data_dma + pAd->NextRxBulkInPosition;
37932 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
37933 +#endif
37934 +
37935 +
37936 +}
37937 +
37938 +/*
37939 + ========================================================================
37940 +
37941 + Routine Description:
37942 +
37943 + Arguments:
37944 +
37945 + Return Value:
37946 +
37947 + Note:
37948 +
37949 + ========================================================================
37950 +*/
37951 +
37952 +#define BULK_OUT_LOCK(pLock, IrqFlags) \
37953 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
37954 + RTMP_IRQ_LOCK((pLock), IrqFlags);
37955 +
37956 +#define BULK_OUT_UNLOCK(pLock, IrqFlags) \
37957 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
37958 + RTMP_IRQ_UNLOCK((pLock), IrqFlags);
37959 +
37960 +
37961 +VOID RTUSBBulkOutDataPacket(
37962 + IN PRTMP_ADAPTER pAd,
37963 + IN UCHAR BulkOutPipeId,
37964 + IN UCHAR Index)
37965 +{
37966 +
37967 + PHT_TX_CONTEXT pHTTXContext;
37968 + PURB pUrb;
37969 + int ret = 0;
37970 + PTXINFO_STRUC pTxInfo, pLastTxInfo = NULL;
37971 + PTXWI_STRUC pTxWI;
37972 + ULONG TmpBulkEndPos, ThisBulkSize;
37973 + unsigned long IrqFlags = 0, IrqFlags2 = 0;
37974 + PUCHAR pWirelessPkt, pAppendant;
37975 + BOOLEAN bTxQLastRound = FALSE;
37976 + UCHAR allzero[4]= {0x0,0x0,0x0,0x0};
37977 +
37978 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
37979 + if ((pAd->BulkOutPending[BulkOutPipeId] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
37980 + {
37981 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
37982 + return;
37983 + }
37984 + pAd->BulkOutPending[BulkOutPipeId] = TRUE;
37985 +
37986 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
37987 + )
37988 + {
37989 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
37990 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
37991 + return;
37992 + }
37993 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
37994 +
37995 +
37996 + pHTTXContext = &(pAd->TxContext[BulkOutPipeId]);
37997 +
37998 + BULK_OUT_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
37999 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition)
38000 + || ((pHTTXContext->ENextBulkOutPosition-8) == pHTTXContext->CurWritePosition))
38001 + {
38002 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
38003 +
38004 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38005 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38006 +
38007 + // Clear Data flag
38008 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId));
38009 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
38010 +
38011 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38012 + return;
38013 + }
38014 +
38015 + // Clear Data flag
38016 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId));
38017 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
38018 +
38019 + //DBGPRINT(RT_DEBUG_TRACE,("BulkOut-B:I=0x%lx, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", in_interrupt(),
38020 + // pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition,
38021 + // pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
38022 + pHTTXContext->NextBulkOutPosition = pHTTXContext->ENextBulkOutPosition;
38023 + ThisBulkSize = 0;
38024 + TmpBulkEndPos = pHTTXContext->NextBulkOutPosition;
38025 + pWirelessPkt = &pHTTXContext->TransferBuffer->field.WirelessPacket[0];
38026 +
38027 + if ((pHTTXContext->bCopySavePad == TRUE))
38028 + {
38029 + if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero,4))
38030 + {
38031 + DBGPRINT_RAW(RT_DEBUG_ERROR,("e1, allzero : %x %x %x %x %x %x %x %x \n",
38032 + pHTTXContext->SavedPad[0], pHTTXContext->SavedPad[1], pHTTXContext->SavedPad[2],pHTTXContext->SavedPad[3]
38033 + ,pHTTXContext->SavedPad[4], pHTTXContext->SavedPad[5], pHTTXContext->SavedPad[6],pHTTXContext->SavedPad[7]));
38034 + }
38035 + NdisMoveMemory(&pWirelessPkt[TmpBulkEndPos], pHTTXContext->SavedPad, 8);
38036 + pHTTXContext->bCopySavePad = FALSE;
38037 + if (pAd->bForcePrintTX == TRUE)
38038 + DBGPRINT(RT_DEBUG_TRACE,("RTUSBBulkOutDataPacket --> COPY PAD. CurWrite = %ld, NextBulk = %ld. ENextBulk = %ld.\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition));
38039 + }
38040 +
38041 + do
38042 + {
38043 + pTxInfo = (PTXINFO_STRUC)&pWirelessPkt[TmpBulkEndPos];
38044 + pTxWI = (PTXWI_STRUC)&pWirelessPkt[TmpBulkEndPos + TXINFO_SIZE];
38045 +
38046 + if (pAd->bForcePrintTX == TRUE)
38047 + DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkOutDataPacket AMPDU = %d.\n", pTxWI->AMPDU));
38048 +
38049 + // add by Iverson, limit BulkOut size to 4k to pass WMM b mode 2T1R test items
38050 + //if ((ThisBulkSize != 0) && (pTxWI->AMPDU == 0))
38051 + if ((ThisBulkSize != 0) && (pTxWI->PHYMODE == MODE_CCK))
38052 + {
38053 + if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x1000) == 0x1000))
38054 + {
38055 + // Limit BulkOut size to about 4k bytes.
38056 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38057 + break;
38058 + }
38059 + else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize&0xfffff800) != 0) ) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0))*/)
38060 + {
38061 + // For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size.
38062 + // 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.
38063 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38064 + break;
38065 + }
38066 + }
38067 + // end Iverson
38068 + else
38069 + {
38070 + if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x6000) == 0x6000))
38071 + { // Limit BulkOut size to about 24k bytes.
38072 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38073 + break;
38074 + }
38075 + else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize&0xfffff800) != 0) ) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0))*/)
38076 + { // For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size.
38077 + // 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.
38078 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38079 + break;
38080 + }
38081 + }
38082 +
38083 + if (TmpBulkEndPos == pHTTXContext->CurWritePosition)
38084 + {
38085 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38086 + break;
38087 + }
38088 +
38089 + if (pTxInfo->QSEL != FIFO_EDCA)
38090 + {
38091 + printk("%s(): ====> pTxInfo->QueueSel(%d)!= FIFO_EDCA!!!!\n", __FUNCTION__, pTxInfo->QSEL);
38092 + printk("\tCWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad);
38093 + hex_dump("Wrong QSel Pkt:", (PUCHAR)&pWirelessPkt[TmpBulkEndPos], (pHTTXContext->CurWritePosition - pHTTXContext->NextBulkOutPosition));
38094 + }
38095 +
38096 + if (pTxInfo->USBDMATxPktLen <= 8)
38097 + {
38098 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
38099 + DBGPRINT(RT_DEBUG_ERROR /*RT_DEBUG_TRACE*/,("e2, USBDMATxPktLen==0, Size=%ld, bCSPad=%d, CWPos=%ld, NBPos=%ld, CWRPos=%ld!\n",
38100 + pHTTXContext->BulkOutSize, pHTTXContext->bCopySavePad, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->CurWriteRealPos));
38101 + {
38102 + DBGPRINT_RAW(RT_DEBUG_ERROR /*RT_DEBUG_TRACE*/,("%x %x %x %x %x %x %x %x \n",
38103 + pHTTXContext->SavedPad[0], pHTTXContext->SavedPad[1], pHTTXContext->SavedPad[2],pHTTXContext->SavedPad[3]
38104 + ,pHTTXContext->SavedPad[4], pHTTXContext->SavedPad[5], pHTTXContext->SavedPad[6],pHTTXContext->SavedPad[7]));
38105 + }
38106 + pAd->bForcePrintTX = TRUE;
38107 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38108 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38109 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38110 + //DBGPRINT(RT_DEBUG_LOUD,("Out:pTxInfo->USBDMATxPktLen=%d!\n", pTxInfo->USBDMATxPktLen));
38111 + return;
38112 + }
38113 +
38114 + // Increase Total transmit byte counter
38115 + pAd->RalinkCounters.OneSecTransmittedByteCount += pTxWI->MPDUtotalByteCount;
38116 + pAd->RalinkCounters.TransmittedByteCount += pTxWI->MPDUtotalByteCount;
38117 +
38118 + pLastTxInfo = pTxInfo;
38119 +
38120 + // Make sure we use EDCA QUEUE.
38121 + pTxInfo->QSEL = FIFO_EDCA;
38122 + ThisBulkSize += (pTxInfo->USBDMATxPktLen+4);
38123 + TmpBulkEndPos += (pTxInfo->USBDMATxPktLen+4);
38124 +
38125 + if (TmpBulkEndPos != pHTTXContext->CurWritePosition)
38126 + pTxInfo->USBDMANextVLD = 1;
38127 +
38128 + if (pTxInfo->SwUseLastRound == 1)
38129 + {
38130 + if (pHTTXContext->CurWritePosition == 8)
38131 + pTxInfo->USBDMANextVLD = 0;
38132 + pTxInfo->SwUseLastRound = 0;
38133 +
38134 + bTxQLastRound = TRUE;
38135 + pHTTXContext->ENextBulkOutPosition = 8;
38136 +
38137 + #ifdef RT_BIG_ENDIAN
38138 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
38139 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
38140 + #endif // RT_BIG_ENDIAN //
38141 +
38142 + break;
38143 + }
38144 +
38145 +#ifdef RT_BIG_ENDIAN
38146 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
38147 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
38148 +#endif // RT_BIG_ENDIAN //
38149 +
38150 + }while (TRUE);
38151 +
38152 + // adjust the pTxInfo->USBDMANextVLD value of last pTxInfo.
38153 + if (pLastTxInfo)
38154 + {
38155 +#ifdef RT_BIG_ENDIAN
38156 + RTMPDescriptorEndianChange((PUCHAR)pLastTxInfo, TYPE_TXINFO);
38157 +#endif // RT_BIG_ENDIAN //
38158 + pLastTxInfo->USBDMANextVLD = 0;
38159 +#ifdef RT_BIG_ENDIAN
38160 + RTMPDescriptorEndianChange((PUCHAR)pLastTxInfo, TYPE_TXINFO);
38161 +#endif // RT_BIG_ENDIAN //
38162 + }
38163 +
38164 + /*
38165 + We need to copy SavedPad when following condition matched!
38166 + 1. Not the last round of the TxQueue and
38167 + 2. any match of following cases:
38168 + (1). The End Position of this bulk out is reach to the Currenct Write position and
38169 + the TxInfo and related header already write to the CurWritePosition.
38170 + =>(ENextBulkOutPosition == CurWritePosition) && (CurWriteRealPos > CurWritePosition)
38171 +
38172 + (2). The EndPosition of the bulk out is not reach to the Current Write Position.
38173 + =>(ENextBulkOutPosition != CurWritePosition)
38174 + */
38175 + if ((bTxQLastRound == FALSE) &&
38176 + (((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition) && (pHTTXContext->CurWriteRealPos > pHTTXContext->CurWritePosition)) ||
38177 + (pHTTXContext->ENextBulkOutPosition != pHTTXContext->CurWritePosition))
38178 + )
38179 + {
38180 + NdisMoveMemory(pHTTXContext->SavedPad, &pWirelessPkt[pHTTXContext->ENextBulkOutPosition], 8);
38181 + pHTTXContext->bCopySavePad = TRUE;
38182 + if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero,4))
38183 + {
38184 + PUCHAR pBuf = &pHTTXContext->SavedPad[0];
38185 + 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",
38186 + pBuf[0], pBuf[1], pBuf[2],pBuf[3],pBuf[4], pBuf[5], pBuf[6],pBuf[7], pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos,
38187 + pHTTXContext->bCurWriting, pHTTXContext->NextBulkOutPosition, TmpBulkEndPos, ThisBulkSize));
38188 +
38189 + pBuf = &pWirelessPkt[pHTTXContext->CurWritePosition];
38190 + 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]));
38191 + }
38192 + //DBGPRINT(RT_DEBUG_LOUD,("ENPos==CWPos=%ld, CWRPos=%ld, bCSPad=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->bCopySavePad));
38193 + }
38194 +
38195 + if (pAd->bForcePrintTX == TRUE)
38196 + 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));
38197 + //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));
38198 +
38199 + // USB DMA engine requires to pad extra 4 bytes. This pad doesn't count into real bulkoutsize.
38200 + pAppendant = &pWirelessPkt[TmpBulkEndPos];
38201 + NdisZeroMemory(pAppendant, 8);
38202 + ThisBulkSize += 4;
38203 + pHTTXContext->LastOne = TRUE;
38204 + if ((ThisBulkSize % pAd->BulkOutMaxPacketSize) == 0)
38205 + ThisBulkSize += 4;
38206 + pHTTXContext->BulkOutSize = ThisBulkSize;
38207 +
38208 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 1;
38209 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
38210 +
38211 + // Init Tx context descriptor
38212 + RTUSBInitHTTxDesc(pAd, pHTTXContext, BulkOutPipeId, ThisBulkSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete);
38213 +
38214 + pUrb = pHTTXContext->pUrb;
38215 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
38216 + {
38217 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
38218 +
38219 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38220 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38221 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
38222 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38223 +
38224 + return;
38225 + }
38226 +
38227 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38228 + pHTTXContext->IRPPending = TRUE;
38229 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38230 + pAd->BulkOutReq++;
38231 +
38232 +}
38233 +
38234 +
38235 +VOID RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
38236 +{
38237 +#if 0 // sample, IRQ LOCK
38238 + PRTMP_ADAPTER pAd;
38239 + POS_COOKIE pObj;
38240 + PHT_TX_CONTEXT pHTTXContext;
38241 + UCHAR BulkOutPipeId;
38242 + NTSTATUS Status;
38243 + unsigned long IrqFlags;
38244 +
38245 + DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutDataPacketComplete\n"));
38246 +
38247 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
38248 + pAd = pHTTXContext->pAd;
38249 + pObj = (POS_COOKIE) pAd->OS_Cookie;
38250 + Status = pUrb->status;
38251 +
38252 + // Store BulkOut PipeId
38253 + BulkOutPipeId = pHTTXContext->BulkOutPipeId;
38254 + pAd->BulkOutDataOneSecCount++;
38255 +
38256 + //DBGPRINT(RT_DEBUG_LOUD, ("Done-B(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", BulkOutPipeId, in_interrupt(), pHTTXContext->CurWritePosition,
38257 + // pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
38258 +
38259 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38260 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38261 + pHTTXContext->IRPPending = FALSE;
38262 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38263 +
38264 + if (Status == USB_ST_NOERROR)
38265 + {
38266 + pAd->BulkOutComplete++;
38267 +
38268 + pAd->Counters8023.GoodTransmits++;
38269 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
38270 + FREE_HTTX_RING(pAd, BulkOutPipeId, pHTTXContext);
38271 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
38272 +
38273 +
38274 + }
38275 + else // STATUS_OTHER
38276 + {
38277 + PUCHAR pBuf;
38278 +
38279 + pAd->BulkOutCompleteOther++;
38280 +
38281 + pBuf = &pHTTXContext->TransferBuffer->WirelessPacket[pHTTXContext->NextBulkOutPosition];
38282 +
38283 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkOutDataPacket failed: ReasonCode=%d!\n", Status));
38284 + DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther));
38285 + DBGPRINT_RAW(RT_DEBUG_ERROR, (">>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]));
38286 + //DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOutCompleteCancel=0x%x, BulkOutCompleteOther=0x%x\n", pAd->BulkOutCompleteCancel, pAd->BulkOutCompleteOther));
38287 +
38288 + if (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
38289 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
38290 + fRTMP_ADAPTER_NIC_NOT_EXIST |
38291 + fRTMP_ADAPTER_BULKOUT_RESET)))
38292 + {
38293 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38294 + pAd->bulkResetPipeid = BulkOutPipeId;
38295 + }
38296 + }
38297 +
38298 + //
38299 + // bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut
38300 + // bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out.
38301 + //
38302 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
38303 + if ((pHTTXContext->ENextBulkOutPosition != pHTTXContext->CurWritePosition) &&
38304 + (pHTTXContext->ENextBulkOutPosition != (pHTTXContext->CurWritePosition+8)) &&
38305 + !RTUSB_TEST_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId)))
38306 + {
38307 + // Indicate There is data avaliable
38308 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
38309 + }
38310 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
38311 +
38312 + // Always call Bulk routine, even reset bulk.
38313 + // The protection of rest bulk should be in BulkOut routine
38314 + RTUSBKickBulkOut(pAd);
38315 +
38316 +
38317 + //DBGPRINT(RT_DEBUG_LOUD,("Done-A(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d\n", BulkOutPipeId, in_interrupt(),
38318 + // pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
38319 +
38320 + switch (BulkOutPipeId)
38321 + {
38322 + case 0:
38323 + pObj->ac0_dma_done_task.data = (unsigned long)pAd;
38324 + tasklet_hi_schedule(&pObj->ac0_dma_done_task);
38325 + break;
38326 + case 1:
38327 + pObj->ac1_dma_done_task.data = (unsigned long)pAd;
38328 + tasklet_hi_schedule(&pObj->ac1_dma_done_task);
38329 + break;
38330 + case 2:
38331 + pObj->ac2_dma_done_task.data = (unsigned long)pAd;
38332 + tasklet_hi_schedule(&pObj->ac2_dma_done_task);
38333 + break;
38334 + case 3:
38335 + pObj->ac3_dma_done_task.data = (unsigned long)pAd;
38336 + tasklet_hi_schedule(&pObj->ac3_dma_done_task);
38337 + break;
38338 + case 4:
38339 + pObj->hcca_dma_done_task.data = (unsigned long)pAd;
38340 + tasklet_hi_schedule(&pObj->hcca_dma_done_task);
38341 + break;
38342 + }
38343 +#else
38344 +
38345 +{
38346 + PHT_TX_CONTEXT pHTTXContext;
38347 + PRTMP_ADAPTER pAd;
38348 + POS_COOKIE pObj;
38349 + UCHAR BulkOutPipeId;
38350 +
38351 +
38352 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
38353 + pAd = pHTTXContext->pAd;
38354 + pObj = (POS_COOKIE) pAd->OS_Cookie;
38355 +
38356 + // Store BulkOut PipeId
38357 + BulkOutPipeId = pHTTXContext->BulkOutPipeId;
38358 + pAd->BulkOutDataOneSecCount++;
38359 +
38360 + switch (BulkOutPipeId)
38361 + {
38362 + case 0:
38363 + pObj->ac0_dma_done_task.data = (unsigned long)pUrb;
38364 + tasklet_hi_schedule(&pObj->ac0_dma_done_task);
38365 + break;
38366 + case 1:
38367 + pObj->ac1_dma_done_task.data = (unsigned long)pUrb;
38368 + tasklet_hi_schedule(&pObj->ac1_dma_done_task);
38369 + break;
38370 + case 2:
38371 + pObj->ac2_dma_done_task.data = (unsigned long)pUrb;
38372 + tasklet_hi_schedule(&pObj->ac2_dma_done_task);
38373 + break;
38374 + case 3:
38375 + pObj->ac3_dma_done_task.data = (unsigned long)pUrb;
38376 + tasklet_hi_schedule(&pObj->ac3_dma_done_task);
38377 + break;
38378 + case 4:
38379 + pObj->hcca_dma_done_task.data = (unsigned long)pUrb;
38380 + tasklet_hi_schedule(&pObj->hcca_dma_done_task);
38381 + break;
38382 + }
38383 +}
38384 +#endif
38385 +
38386 +
38387 +}
38388 +
38389 +
38390 +/*
38391 + ========================================================================
38392 +
38393 + Routine Description:
38394 +
38395 + Arguments:
38396 +
38397 + Return Value:
38398 +
38399 + Note: NULL frame use BulkOutPipeId = 0
38400 +
38401 + ========================================================================
38402 +*/
38403 +VOID RTUSBBulkOutNullFrame(
38404 + IN PRTMP_ADAPTER pAd)
38405 +{
38406 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
38407 + PURB pUrb;
38408 + int ret = 0;
38409 + unsigned long IrqFlags;
38410 +
38411 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38412 + if ((pAd->BulkOutPending[0] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
38413 + {
38414 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38415 + return;
38416 + }
38417 + pAd->BulkOutPending[0] = TRUE;
38418 + pAd->watchDogTxPendingCnt[0] = 1;
38419 + pNullContext->IRPPending = TRUE;
38420 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38421 +
38422 + // Increase Total transmit byte counter
38423 + pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
38424 +
38425 +
38426 + // Clear Null frame bulk flag
38427 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
38428 +
38429 +#ifdef RT_BIG_ENDIAN
38430 + RTMPDescriptorEndianChange((PUCHAR)pNullContext->TransferBuffer, TYPE_TXINFO);
38431 +#endif // RT_BIG_ENDIAN //
38432 +
38433 + // Init Tx context descriptor
38434 + RTUSBInitTxDesc(pAd, pNullContext, 0, (usb_complete_t)RTUSBBulkOutNullFrameComplete);
38435 +
38436 + pUrb = pNullContext->pUrb;
38437 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
38438 + {
38439 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38440 + pAd->BulkOutPending[0] = FALSE;
38441 + pAd->watchDogTxPendingCnt[0] = 0;
38442 + pNullContext->IRPPending = FALSE;
38443 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38444 +
38445 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutNullFrame: Submit Tx URB failed %d\n", ret));
38446 + return;
38447 + }
38448 +
38449 +}
38450 +
38451 +// NULL frame use BulkOutPipeId = 0
38452 +VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs)
38453 +{
38454 + PRTMP_ADAPTER pAd;
38455 + PTX_CONTEXT pNullContext;
38456 + NTSTATUS Status;
38457 +#if 0 // sample, IRQ LOCK
38458 + unsigned long IrqFlags;
38459 +#endif
38460 + POS_COOKIE pObj;
38461 +
38462 +
38463 + pNullContext = (PTX_CONTEXT)pUrb->context;
38464 + pAd = pNullContext->pAd;
38465 + Status = pUrb->status;
38466 +
38467 +#if 0 // sample, IRQ LOCK
38468 + // Reset Null frame context flags
38469 + pNullContext->IRPPending = FALSE;
38470 + pNullContext->InUse = FALSE;
38471 +
38472 + if (Status == USB_ST_NOERROR)
38473 + {
38474 + // Don't worry about the queue is empty or not, this function will check itself
38475 + //RTMPUSBDeQueuePacket(pAd, 0);
38476 + RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS);
38477 + }
38478 + else // STATUS_OTHER
38479 + {
38480 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
38481 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
38482 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
38483 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
38484 + {
38485 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out Null Frame Failed\n"));
38486 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38487 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
38488 + }
38489 + }
38490 +
38491 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38492 + pAd->BulkOutPending[0] = FALSE;
38493 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38494 +
38495 + // Always call Bulk routine, even reset bulk.
38496 + // The protectioon of rest bulk should be in BulkOut routine
38497 + RTUSBKickBulkOut(pAd);
38498 +#else
38499 +
38500 + pObj = (POS_COOKIE) pAd->OS_Cookie;
38501 + pObj->null_frame_complete_task.data = (unsigned long)pUrb;
38502 + tasklet_hi_schedule(&pObj->null_frame_complete_task);
38503 +#endif
38504 +
38505 +}
38506 +
38507 +#if 0 // For RT2870, RTS frame not used now, but maybe will use it latter.
38508 +/*
38509 + ========================================================================
38510 +
38511 + Routine Description:
38512 +
38513 + Arguments:
38514 +
38515 + Return Value:
38516 +
38517 + Note: RTS frame use BulkOutPipeId = 0
38518 +
38519 + ========================================================================
38520 +*/
38521 +VOID RTUSBBulkOutRTSFrame(
38522 + IN PRTMP_ADAPTER pAd)
38523 +{
38524 + PTX_CONTEXT pRTSContext = &(pAd->RTSContext);
38525 + PURB pUrb;
38526 + int ret = 0;
38527 + unsigned long IrqFlags;
38528 + UCHAR PipeID=0;
38529 +
38530 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_4))
38531 + PipeID= 3;
38532 + else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_3))
38533 + PipeID= 2;
38534 + else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_2))
38535 + PipeID= 1;
38536 + else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL))
38537 + PipeID= 0;
38538 +
38539 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[PipeID], IrqFlags);
38540 + if ((pAd->BulkOutPending[PipeID] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
38541 + {
38542 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[PipeID], IrqFlags);
38543 + return;
38544 + }
38545 + pAd->BulkOutPending[PipeID] = TRUE;
38546 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[PipeID], IrqFlags);
38547 +
38548 + // Increase Total transmit byte counter
38549 + pAd->RalinkCounters.TransmittedByteCount += pRTSContext->BulkOutSize;
38550 +
38551 + DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutRTSFrame \n"));
38552 +
38553 + // Clear RTS frame bulk flag
38554 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_RTS);
38555 +
38556 +#ifdef RT_BIG_ENDIAN
38557 + RTMPDescriptorEndianChange((PUCHAR)pRTSContext->TransferBuffer, TYPE_TXINFO);
38558 +#endif // RT_BIG_ENDIAN //
38559 +
38560 + // Init Tx context descriptor
38561 + RTUSBInitTxDesc(pAd, pRTSContext, PipeID, (usb_complete_t)RTUSBBulkOutRTSFrameComplete);
38562 + pRTSContext->IRPPending = TRUE;
38563 +
38564 + pUrb = pRTSContext->pUrb;
38565 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
38566 + {
38567 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutRTSFrame: Submit Tx URB failed %d\n", ret));
38568 + return;
38569 + }
38570 +
38571 + DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutRTSFrame \n"));
38572 +
38573 +}
38574 +
38575 +// RTS frame use BulkOutPipeId = 0
38576 +VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs)
38577 +{
38578 + PRTMP_ADAPTER pAd;
38579 + PTX_CONTEXT pRTSContext;
38580 + NTSTATUS Status;
38581 +#if 0 // sample, IRQ LOCK
38582 + unsigned long IrqFlags;
38583 +#endif
38584 + POS_COOKIE pObj;
38585 +
38586 + DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutRTSFrameComplete\n"));
38587 +
38588 + pRTSContext = (PTX_CONTEXT)pUrb->context;
38589 + pAd = pRTSContext->pAd;
38590 + Status = pUrb->status;
38591 +
38592 +#if 0 // sample, IRQ LOCK
38593 + // Reset RTS frame context flags
38594 + pRTSContext->IRPPending = FALSE;
38595 + pRTSContext->InUse = FALSE;
38596 +
38597 + if (Status == USB_ST_NOERROR)
38598 + {
38599 + // Don't worry about the queue is empty or not, this function will check itself
38600 + //RTMPUSBDeQueuePacket(pAd, pRTSContext->BulkOutPipeId);
38601 + RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS);
38602 + }
38603 + else // STATUS_OTHER
38604 + {
38605 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
38606 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
38607 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
38608 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
38609 + {
38610 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out RTS Frame Failed\n"));
38611 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38612 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
38613 + }
38614 + }
38615 +
38616 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags);
38617 + pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE;
38618 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags);
38619 +
38620 + // Always call Bulk routine, even reset bulk.
38621 + // The protectioon of rest bulk should be in BulkOut routine
38622 + RTUSBKickBulkOut(pAd);
38623 +#else
38624 +
38625 + pObj = (POS_COOKIE) pAd->OS_Cookie;
38626 + pObj->rts_frame_complete_task.data = (unsigned long)pUrb;
38627 + tasklet_hi_schedule(&pObj->rts_frame_complete_task);
38628 +#endif
38629 +
38630 + DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutRTSFrameComplete\n"));
38631 +
38632 +}
38633 +#endif
38634 +
38635 +/*
38636 + ========================================================================
38637 +
38638 + Routine Description:
38639 +
38640 + Arguments:
38641 +
38642 + Return Value:
38643 +
38644 + Note: MLME use BulkOutPipeId = 0
38645 +
38646 + ========================================================================
38647 +*/
38648 +VOID RTUSBBulkOutMLMEPacket(
38649 + IN PRTMP_ADAPTER pAd,
38650 + IN UCHAR Index)
38651 +{
38652 + PTX_CONTEXT pMLMEContext;
38653 + PURB pUrb;
38654 + int ret = 0;
38655 + unsigned long IrqFlags;
38656 +
38657 + pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa;
38658 + pUrb = pMLMEContext->pUrb;
38659 +
38660 + if ((pAd->MgmtRing.TxSwFreeIdx >= MGMT_RING_SIZE) ||
38661 + (pMLMEContext->InUse == FALSE) ||
38662 + (pMLMEContext->bWaitingBulkOut == FALSE))
38663 + {
38664 +
38665 +
38666 + // Clear MLME bulk flag
38667 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
38668 +
38669 + return;
38670 + }
38671 +
38672 +
38673 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38674 + if ((pAd->BulkOutPending[MGMTPIPEIDX] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
38675 + {
38676 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38677 + return;
38678 + }
38679 +
38680 + pAd->BulkOutPending[MGMTPIPEIDX] = TRUE;
38681 + pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 1;
38682 + pMLMEContext->IRPPending = TRUE;
38683 + pMLMEContext->bWaitingBulkOut = FALSE;
38684 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38685 +
38686 + // Increase Total transmit byte counter
38687 + pAd->RalinkCounters.TransmittedByteCount += pMLMEContext->BulkOutSize;
38688 +
38689 + // Clear MLME bulk flag
38690 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
38691 +
38692 +
38693 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutMLMEPacket\n"));
38694 +#if 0 // for debug
38695 +{
38696 + printk("MLME-Out, C=%d!, D=%d, F=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx);
38697 +
38698 + //TODO: Need to remove it when formal release
38699 + PTXINFO_STRUC pTxInfo;
38700 +
38701 + pTxInfo = (PTXINFO_STRUC)pMLMEContext->TransferBuffer;
38702 + if (pTxInfo->QSEL != FIFO_EDCA)
38703 + {
38704 + printk("%s(): ====> pTxInfo->QueueSel(%d)!= FIFO_EDCA!!!!\n", __FUNCTION__, pTxInfo->QSEL);
38705 + printk("\tMLME_Index=%d!\n", Index);
38706 + hex_dump("Wrong QSel Pkt:", (PUCHAR)pMLMEContext->TransferBuffer, pTxInfo->USBDMATxPktLen);
38707 + }
38708 +}
38709 +#endif
38710 +
38711 +#ifdef RT_BIG_ENDIAN
38712 + RTMPDescriptorEndianChange((PUCHAR)pMLMEContext->TransferBuffer, TYPE_TXINFO);
38713 +#endif // RT_BIG_ENDIAN //
38714 +
38715 + // Init Tx context descriptor
38716 + RTUSBInitTxDesc(pAd, pMLMEContext, MGMTPIPEIDX, (usb_complete_t)RTUSBBulkOutMLMEPacketComplete);
38717 +
38718 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38719 + //For mgmt urb buffer, because we use sk_buff, so we need to notify the USB controller do dma mapping.
38720 + pUrb->transfer_dma = 0;
38721 + pUrb->transfer_flags &= (~URB_NO_TRANSFER_DMA_MAP);
38722 +#endif
38723 +
38724 + pUrb = pMLMEContext->pUrb;
38725 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
38726 + {
38727 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutMLMEPacket: Submit MLME URB failed %d\n", ret));
38728 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38729 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
38730 + pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 0;
38731 + pMLMEContext->IRPPending = FALSE;
38732 + pMLMEContext->bWaitingBulkOut = TRUE;
38733 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38734 +
38735 + return;
38736 + }
38737 +
38738 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutMLMEPacket \n"));
38739 +// printk("<---RTUSBBulkOutMLMEPacket,Cpu=%d!, Dma=%d, SwIdx=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx);
38740 +}
38741 +
38742 +
38743 +VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
38744 +{
38745 + PTX_CONTEXT pMLMEContext;
38746 + PRTMP_ADAPTER pAd;
38747 + NTSTATUS Status;
38748 + POS_COOKIE pObj;
38749 + int index;
38750 +#if 0 // sample, IRQ LOCK
38751 + unsigned long IrqFlags;
38752 + PNDIS_PACKET pPacket;
38753 +#endif
38754 +
38755 +
38756 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutMLMEPacketComplete\n"));
38757 + pMLMEContext = (PTX_CONTEXT)pUrb->context;
38758 + pAd = pMLMEContext->pAd;
38759 + pObj = (POS_COOKIE)pAd->OS_Cookie;
38760 + Status = pUrb->status;
38761 + index = pMLMEContext->SelfIdx;
38762 +
38763 +
38764 +#if 0 // sample, IRQ LOCK
38765 + ASSERT((pAd->MgmtRing.TxDmaIdx == index));
38766 + //printk("MLME-Done-B: C=%d, D=%d, F=%d, Self=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx, pMLMEContext->SelfIdx);
38767 +
38768 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38769 +
38770 +
38771 + if (Status != USB_ST_NOERROR)
38772 + {
38773 + //Bulk-Out fail status handle
38774 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
38775 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
38776 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
38777 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
38778 + {
38779 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out MLME Failed, Status=%d!\n", Status));
38780 + // TODO: How to handle about the MLMEBulkOut failed issue. Need to resend the mgmt pkt?
38781 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38782 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
38783 + }
38784 + }
38785 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
38786 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
38787 +
38788 + RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
38789 + // Reset MLME context flags
38790 + pMLMEContext->IRPPending = FALSE;
38791 + pMLMEContext->InUse = FALSE;
38792 + pMLMEContext->bWaitingBulkOut = FALSE;
38793 + pMLMEContext->BulkOutSize = 0;
38794 +
38795 + pPacket = pAd->MgmtRing.Cell[index].pNdisPacket;
38796 + pAd->MgmtRing.Cell[index].pNdisPacket = NULL;
38797 +
38798 + // Increase MgmtRing Index
38799 + INC_RING_INDEX(pAd->MgmtRing.TxDmaIdx, MGMT_RING_SIZE);
38800 + pAd->MgmtRing.TxSwFreeIdx++;
38801 +
38802 + RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
38803 +
38804 + // No-matter success or fail, we free the mgmt packet.
38805 + if (pPacket)
38806 + RTMPFreeNdisPacket(pAd, pPacket);
38807 +
38808 +#if 0
38809 + //Bulk-Out fail status handle
38810 + if (Status != USB_ST_NOERROR)
38811 + {
38812 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
38813 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
38814 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
38815 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
38816 + {
38817 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out MLME Failed, Status=%d!\n", Status));
38818 + // TODO: How to handle about the MLMEBulkOut failed issue. Need to reset the endpoint?
38819 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38820 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
38821 + }
38822 + }
38823 +#endif
38824 +
38825 + //printk("MLME-Done-A: C=%d, D=%d, F=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx);
38826 +
38827 + pObj->mgmt_dma_done_task.data = (unsigned long)pAd;
38828 + tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
38829 +
38830 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutMLMEPacketComplete\n"));
38831 +// printk("<---RTUSBBulkOutMLMEPacketComplete, Cpu=%d, Dma=%d, SwIdx=%d!\n",
38832 +// pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx);
38833 +
38834 +#else
38835 +
38836 + pObj->mgmt_dma_done_task.data = (unsigned long)pUrb;
38837 + tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
38838 +#endif
38839 +}
38840 +
38841 +
38842 +/*
38843 + ========================================================================
38844 +
38845 + Routine Description:
38846 +
38847 + Arguments:
38848 +
38849 + Return Value:
38850 +
38851 + Note: PsPoll use BulkOutPipeId = 0
38852 +
38853 + ========================================================================
38854 +*/
38855 +VOID RTUSBBulkOutPsPoll(
38856 + IN PRTMP_ADAPTER pAd)
38857 +{
38858 + PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext);
38859 + PURB pUrb;
38860 + int ret = 0;
38861 + unsigned long IrqFlags;
38862 +
38863 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38864 + if ((pAd->BulkOutPending[0] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
38865 + {
38866 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38867 + return;
38868 + }
38869 + pAd->BulkOutPending[0] = TRUE;
38870 + pAd->watchDogTxPendingCnt[0] = 1;
38871 + pPsPollContext->IRPPending = TRUE;
38872 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38873 +
38874 +
38875 + // Clear PS-Poll bulk flag
38876 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);
38877 +
38878 +#ifdef RT_BIG_ENDIAN
38879 + RTMPDescriptorEndianChange((PUCHAR)pPsPollContext->TransferBuffer, TYPE_TXINFO);
38880 +#endif // RT_BIG_ENDIAN //
38881 +
38882 + // Init Tx context descriptor
38883 + RTUSBInitTxDesc(pAd, pPsPollContext, MGMTPIPEIDX, (usb_complete_t)RTUSBBulkOutPsPollComplete);
38884 +
38885 + pUrb = pPsPollContext->pUrb;
38886 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
38887 + {
38888 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38889 + pAd->BulkOutPending[0] = FALSE;
38890 + pAd->watchDogTxPendingCnt[0] = 0;
38891 + pPsPollContext->IRPPending = FALSE;
38892 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38893 +
38894 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutPsPoll: Submit Tx URB failed %d\n", ret));
38895 + return;
38896 + }
38897 +
38898 +}
38899 +
38900 +// PS-Poll frame use BulkOutPipeId = 0
38901 +VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb,struct pt_regs *pt_regs)
38902 +{
38903 + PRTMP_ADAPTER pAd;
38904 + PTX_CONTEXT pPsPollContext;
38905 + NTSTATUS Status;
38906 +#if 0 // sample, IRQ LOCK
38907 + unsigned long IrqFlags;
38908 +#endif
38909 + POS_COOKIE pObj;
38910 +
38911 +
38912 + pPsPollContext= (PTX_CONTEXT)pUrb->context;
38913 + pAd = pPsPollContext->pAd;
38914 + Status = pUrb->status;
38915 +
38916 +#if 0 // sample, IRQ LOCK
38917 + // Reset PsPoll context flags
38918 + pPsPollContext->IRPPending = FALSE;
38919 + pPsPollContext->InUse = FALSE;
38920 +
38921 + if (Status == USB_ST_NOERROR)
38922 + {
38923 + // Don't worry about the queue is empty or not, this function will check itself
38924 + RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS);
38925 + }
38926 + else // STATUS_OTHER
38927 + {
38928 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
38929 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
38930 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
38931 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
38932 + {
38933 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out PSPoll Failed\n"));
38934 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
38935 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
38936 + }
38937 + }
38938 +
38939 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
38940 + pAd->BulkOutPending[0] = FALSE;
38941 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
38942 +
38943 + // Always call Bulk routine, even reset bulk.
38944 + // The protectioon of rest bulk should be in BulkOut routine
38945 + RTUSBKickBulkOut(pAd);
38946 +#else
38947 +
38948 + pObj = (POS_COOKIE) pAd->OS_Cookie;
38949 + pObj->pspoll_frame_complete_task.data = (unsigned long)pUrb;
38950 + tasklet_hi_schedule(&pObj->pspoll_frame_complete_task);
38951 +#endif
38952 +}
38953 +
38954 +
38955 +#if 0
38956 +/*
38957 + ========================================================================
38958 +
38959 + Routine Description:
38960 + USB_RxPacket initializes a URB and uses the Rx IRP to submit it
38961 + to USB. It checks if an Rx Descriptor is available and passes the
38962 + the coresponding buffer to be filled. If no descriptor is available
38963 + fails the request. When setting the completion routine we pass our
38964 + Adapter Object as Context.
38965 +
38966 + Arguments:
38967 +
38968 + Return Value:
38969 + TRUE found matched tuple cache
38970 + FALSE no matched found
38971 +
38972 + Note:
38973 +
38974 + ========================================================================
38975 +*/
38976 +VOID RTUSBBulkReceive(
38977 + IN PRTMP_ADAPTER pAd)
38978 +{
38979 + PRX_CONTEXT pRxContext;
38980 + PURB pUrb;
38981 + int ret = 0;
38982 + unsigned long IrqFlags;
38983 +
38984 +
38985 + /* device had been closed */
38986 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS))
38987 + return;
38988 +
38989 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
38990 +
38991 + // Last is time point between 2 separate URB.
38992 + if (pAd->NextRxBulkInPosition == 0)
38993 + {
38994 + //pAd->NextRxBulkInIndex = (pAd->NextRxBulkInIndex + 1) % (RX_RING_SIZE);
38995 + INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE);
38996 + }
38997 + else if ((pAd->NextRxBulkInPosition&0x1ff) != 0)
38998 + {
38999 + //pAd->NextRxBulkInIndex = (pAd->NextRxBulkInIndex + 1) % (RX_RING_SIZE);
39000 + INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE);
39001 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("pAd->NextRxBulkInPosition = 0x%lx. End of URB.\n", pAd->NextRxBulkInPosition ));
39002 + pAd->NextRxBulkInPosition = 0;
39003 + }
39004 +
39005 + if (pAd->NextRxBulkInPosition == MAX_RXBULK_SIZE)
39006 + pAd->NextRxBulkInPosition = 0;
39007 +
39008 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
39009 +
39010 + // TODO: Why need to check if pRxContext->InUsed == TRUE?
39011 + //if ((pRxContext->InUse == TRUE) || (pRxContext->Readable == TRUE))
39012 + if ((pRxContext->InUse == FALSE) && (pRxContext->Readable == TRUE))
39013 + {
39014 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("pRxContext[%d] InUse = %d.pRxContext->Readable = %d. Return.\n", pAd->NextRxBulkInIndex,pRxContext->InUse, pRxContext->Readable ));
39015 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39016 +
39017 + // read RxContext, Since not
39018 +#ifdef CONFIG_STA_SUPPORT
39019 + STARxDoneInterruptHandle(pAd, TRUE);
39020 +#endif // CONFIG_STA_SUPPORT //
39021 +
39022 + //return;
39023 + }
39024 + pRxContext->InUse = TRUE;
39025 + pRxContext->IRPPending= TRUE;
39026 +
39027 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39028 +
39029 + // Init Rx context descriptor
39030 + NdisZeroMemory(pRxContext->TransferBuffer, BUFFER_SIZE);
39031 + RTUSBInitRxDesc(pAd, pRxContext);
39032 +
39033 + pUrb = pRxContext->pUrb;
39034 + if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39035 + {
39036 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkReceive: Submit Rx URB failed %d\n", ret));
39037 + return;
39038 + }
39039 + else // success
39040 + {
39041 + NdisInterlockedIncrement(&pAd->PendingRx);
39042 + pAd->BulkInReq++;
39043 + }
39044 +
39045 + // read RxContext, Since not
39046 +#ifdef CONFIG_STA_SUPPORT
39047 + STARxDoneInterruptHandle(pAd, FALSE);
39048 +#endif // CONFIG_STA_SUPPORT //
39049 +}
39050 +
39051 +/*
39052 + ========================================================================
39053 +
39054 + Routine Description:
39055 + This routine process Rx Irp and call rx complete function.
39056 +
39057 + Arguments:
39058 + DeviceObject Pointer to the device object for next lower
39059 + device. DeviceObject passed in here belongs to
39060 + the next lower driver in the stack because we
39061 + were invoked via IoCallDriver in USB_RxPacket
39062 + AND it is not OUR device object
39063 + Irp Ptr to completed IRP
39064 + Context Ptr to our Adapter object (context specified
39065 + in IoSetCompletionRoutine
39066 +
39067 + Return Value:
39068 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39069 +
39070 + Note:
39071 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39072 + ========================================================================
39073 +*/
39074 +VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39075 +{
39076 +#if 0
39077 + PRX_CONTEXT pRxContext;
39078 + PRTMP_ADAPTER pAd;
39079 + NTSTATUS Status;
39080 +// POS_COOKIE pObj;
39081 +
39082 + pRxContext = (PRX_CONTEXT)pUrb->context;
39083 + pAd = pRxContext->pAd;
39084 +// pObj = (POS_COOKIE) pAd->OS_Cookie;
39085 +
39086 +
39087 + Status = pUrb->status;
39088 + //pRxContext->pIrp = NULL;
39089 +
39090 + pRxContext->InUse = FALSE;
39091 + pRxContext->IRPPending = FALSE;
39092 +
39093 + if (Status == USB_ST_NOERROR)
39094 + {
39095 + pAd->BulkInComplete++;
39096 + pRxContext->Readable = TRUE;
39097 + pAd->NextRxBulkInPosition = 0;
39098 +
39099 + }
39100 + else // STATUS_OTHER
39101 + {
39102 + pAd->BulkInCompleteFail++;
39103 + // Still read this packet although it may comtain wrong bytes.
39104 + pRxContext->Readable = FALSE;
39105 + // Parsing all packets. because after reset, the index will reset to all zero.
39106 +
39107 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
39108 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET)) &&
39109 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
39110 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
39111 + {
39112 +
39113 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk In Failed. Status = %d\n", Status));
39114 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("==>NextRxBulkInIndex=0x%x, NextRxBulkInReadIndex=0x%x, TransferBufferLength= 0x%x\n",
39115 + pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pRxContext->pUrb->actual_length));
39116 +
39117 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
39118 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
39119 + }
39120 + //pUrb = NULL;
39121 + }
39122 +
39123 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
39124 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET)) &&
39125 +// (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) &&
39126 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) &&
39127 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
39128 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
39129 + {
39130 + RTUSBBulkReceive(pAd);
39131 +#if 0
39132 +#if 1
39133 + STARxDoneInterruptHandle(pAd, FALSE);
39134 +#else
39135 + pObj->rx_bh.data = (unsigned long)pUrb;
39136 + tasklet_schedule(&pObj->rx_bh);
39137 +#endif
39138 +#endif
39139 + }
39140 +
39141 + // Call RxPacket to process packet and return the status
39142 + NdisInterlockedDecrement(&pAd->PendingRx);
39143 +#else
39144 +
39145 +
39146 + // use a receive tasklet to handle received packets;
39147 + // or sometimes hardware IRQ will be disabled here, so we can not
39148 + // use spin_lock_bh()/spin_unlock_bh() after IRQ is disabled. :<
39149 + PRX_CONTEXT pRxContext;
39150 + PRTMP_ADAPTER pAd;
39151 + POS_COOKIE pObj;
39152 +
39153 +
39154 + pRxContext = (PRX_CONTEXT)pUrb->context;
39155 + pAd = pRxContext->pAd;
39156 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39157 +
39158 + pObj->rx_done_task.data = (unsigned long)pUrb;
39159 + tasklet_hi_schedule(&pObj->rx_done_task);
39160 +#endif
39161 +}
39162 +
39163 +#else
39164 +
39165 +VOID DoBulkIn(IN RTMP_ADAPTER *pAd)
39166 +{
39167 + PRX_CONTEXT pRxContext;
39168 + PURB pUrb;
39169 + int ret = 0;
39170 + unsigned long IrqFlags;
39171 +
39172 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39173 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
39174 + if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE))
39175 + {
39176 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39177 + return;
39178 + }
39179 + pRxContext->InUse = TRUE;
39180 + pRxContext->IRPPending = TRUE;
39181 + pAd->PendingRx++;
39182 + pAd->BulkInReq++;
39183 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39184 +
39185 + // Init Rx context descriptor
39186 + NdisZeroMemory(pRxContext->TransferBuffer, pRxContext->BulkInOffset);
39187 + RTUSBInitRxDesc(pAd, pRxContext);
39188 +
39189 + pUrb = pRxContext->pUrb;
39190 + if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39191 + { // fail
39192 +
39193 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39194 + pRxContext->InUse = FALSE;
39195 + pRxContext->IRPPending = FALSE;
39196 + pAd->PendingRx--;
39197 + pAd->BulkInReq--;
39198 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39199 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkReceive: Submit Rx URB failed %d\n", ret));
39200 + }
39201 + else
39202 + { // success
39203 +#if 0
39204 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39205 + pRxContext->IRPPending = TRUE;
39206 + //NdisInterlockedIncrement(&pAd->PendingRx);
39207 + pAd->PendingRx++;
39208 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39209 + pAd->BulkInReq++;
39210 +#endif
39211 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
39212 + //printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex);
39213 + }
39214 +}
39215 +
39216 +
39217 +/*
39218 + ========================================================================
39219 +
39220 + Routine Description:
39221 + USB_RxPacket initializes a URB and uses the Rx IRP to submit it
39222 + to USB. It checks if an Rx Descriptor is available and passes the
39223 + the coresponding buffer to be filled. If no descriptor is available
39224 + fails the request. When setting the completion routine we pass our
39225 + Adapter Object as Context.
39226 +
39227 + Arguments:
39228 +
39229 + Return Value:
39230 + TRUE found matched tuple cache
39231 + FALSE no matched found
39232 +
39233 + Note:
39234 +
39235 + ========================================================================
39236 +*/
39237 +#define fRTMP_ADAPTER_NEED_STOP_RX \
39238 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
39239 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
39240 + fRTMP_ADAPTER_REMOVE_IN_PROGRESS | fRTMP_ADAPTER_BULKIN_RESET)
39241 +
39242 +#define fRTMP_ADAPTER_NEED_STOP_HANDLE_RX \
39243 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
39244 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
39245 + fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
39246 +
39247 +VOID RTUSBBulkReceive(
39248 + IN PRTMP_ADAPTER pAd)
39249 +{
39250 + PRX_CONTEXT pRxContext;
39251 + unsigned long IrqFlags;
39252 +
39253 +
39254 + /* sanity check */
39255 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_HANDLE_RX))
39256 + return;
39257 +
39258 + while(1)
39259 + {
39260 +
39261 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39262 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInReadIndex]);
39263 + if (((pRxContext->InUse == FALSE) && (pRxContext->Readable == TRUE)) &&
39264 + (pRxContext->bRxHandling == FALSE))
39265 + {
39266 + pRxContext->bRxHandling = TRUE;
39267 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39268 +
39269 + // read RxContext, Since not
39270 +#ifdef CONFIG_STA_SUPPORT
39271 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
39272 + STARxDoneInterruptHandle(pAd, TRUE);
39273 +#endif // CONFIG_STA_SUPPORT //
39274 +
39275 + // Finish to handle this bulkIn buffer.
39276 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39277 + pRxContext->BulkInOffset = 0;
39278 + pRxContext->Readable = FALSE;
39279 + pRxContext->bRxHandling = FALSE;
39280 + pAd->ReadPosition = 0;
39281 + pAd->TransferBufferLength = 0;
39282 + INC_RING_INDEX(pAd->NextRxBulkInReadIndex, RX_RING_SIZE);
39283 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39284 +
39285 + }
39286 + else
39287 + {
39288 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39289 + break;
39290 + }
39291 + }
39292 +
39293 + if (!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_RX)))
39294 + DoBulkIn(pAd);
39295 +
39296 +}
39297 +
39298 +
39299 +/*
39300 + ========================================================================
39301 +
39302 + Routine Description:
39303 + This routine process Rx Irp and call rx complete function.
39304 +
39305 + Arguments:
39306 + DeviceObject Pointer to the device object for next lower
39307 + device. DeviceObject passed in here belongs to
39308 + the next lower driver in the stack because we
39309 + were invoked via IoCallDriver in USB_RxPacket
39310 + AND it is not OUR device object
39311 + Irp Ptr to completed IRP
39312 + Context Ptr to our Adapter object (context specified
39313 + in IoSetCompletionRoutine
39314 +
39315 + Return Value:
39316 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39317 +
39318 + Note:
39319 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39320 + ========================================================================
39321 +*/
39322 +VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39323 +{
39324 + // use a receive tasklet to handle received packets;
39325 + // or sometimes hardware IRQ will be disabled here, so we can not
39326 + // use spin_lock_bh()/spin_unlock_bh() after IRQ is disabled. :<
39327 + PRX_CONTEXT pRxContext;
39328 + PRTMP_ADAPTER pAd;
39329 + POS_COOKIE pObj;
39330 +
39331 +
39332 + pRxContext = (PRX_CONTEXT)pUrb->context;
39333 + pAd = pRxContext->pAd;
39334 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39335 +
39336 + pObj->rx_done_task.data = (unsigned long)pUrb;
39337 + tasklet_hi_schedule(&pObj->rx_done_task);
39338 +
39339 +}
39340 +
39341 +#endif
39342 +
39343 +
39344 +
39345 +/*
39346 + ========================================================================
39347 +
39348 + Routine Description:
39349 +
39350 + Arguments:
39351 +
39352 + Return Value:
39353 +
39354 + Note:
39355 +
39356 + ========================================================================
39357 +*/
39358 +VOID RTUSBKickBulkOut(
39359 + IN PRTMP_ADAPTER pAd)
39360 +{
39361 + // BulkIn Reset will reset whole USB PHY. So we need to make sure fRTMP_ADAPTER_BULKIN_RESET not flaged.
39362 + if (!RTMP_TEST_FLAG(pAd ,fRTMP_ADAPTER_NEED_STOP_TX)
39363 +#ifdef RALINK_ATE
39364 + && !(ATE_ON(pAd))
39365 +#endif // RALINK_ATE //
39366 + )
39367 + {
39368 +#if 0 // not used now in RT28xx, but may used latter.
39369 + // 1. Data Fragment has highest priority
39370 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_FRAG))
39371 + {
39372 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39373 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39374 + ))
39375 + {
39376 + RTUSBBulkOutDataPacket(pAd, 0, pAd->NextBulkOutIndex[0]);
39377 + }
39378 + }
39379 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_FRAG_2))
39380 + {
39381 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39382 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39383 + ))
39384 + {
39385 + RTUSBBulkOutDataPacket(pAd, 1, pAd->NextBulkOutIndex[1]);
39386 + }
39387 + }
39388 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_FRAG_3))
39389 + {
39390 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39391 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39392 + ))
39393 + {
39394 + RTUSBBulkOutDataPacket(pAd, 2, pAd->NextBulkOutIndex[2]);
39395 + }
39396 + }
39397 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_FRAG_4))
39398 + {
39399 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39400 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39401 + ))
39402 + {
39403 + RTUSBBulkOutDataPacket(pAd, 3, pAd->NextBulkOutIndex[3]);
39404 + }
39405 + }
39406 +#endif
39407 +
39408 + // 2. PS-Poll frame is next
39409 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL))
39410 + {
39411 + RTUSBBulkOutPsPoll(pAd);
39412 + }
39413 +
39414 + // 5. Mlme frame is next
39415 + else if ((RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME)) &&
39416 + (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE))
39417 + {
39418 + RTUSBBulkOutMLMEPacket(pAd, pAd->MgmtRing.TxDmaIdx);
39419 + }
39420 +
39421 + // 6. Data frame normal is next
39422 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL))
39423 + {
39424 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39425 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39426 + ))
39427 + {
39428 + RTUSBBulkOutDataPacket(pAd, 0, pAd->NextBulkOutIndex[0]);
39429 + }
39430 + }
39431 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_2))
39432 + {
39433 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39434 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39435 + ))
39436 + {
39437 + RTUSBBulkOutDataPacket(pAd, 1, pAd->NextBulkOutIndex[1]);
39438 + }
39439 + }
39440 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_3))
39441 + {
39442 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39443 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39444 + ))
39445 + {
39446 + RTUSBBulkOutDataPacket(pAd, 2, pAd->NextBulkOutIndex[2]);
39447 + }
39448 + }
39449 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_4))
39450 + {
39451 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39452 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39453 + ))
39454 + {
39455 + RTUSBBulkOutDataPacket(pAd, 3, pAd->NextBulkOutIndex[3]);
39456 + }
39457 + }
39458 +
39459 + // 7. Null frame is the last
39460 + else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL))
39461 + {
39462 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
39463 + {
39464 + RTUSBBulkOutNullFrame(pAd);
39465 + }
39466 + }
39467 +
39468 + // 8. No data avaliable
39469 + else
39470 + {
39471 +
39472 + }
39473 + }
39474 +#ifdef RALINK_ATE
39475 + /* If the mode is in ATE mode. */
39476 + else if((ATE_ON(pAd)) &&
39477 + !RTMP_TEST_FLAG(pAd ,fRTMP_ADAPTER_NEED_STOP_TX))// PETER : watch out !
39478 + {
39479 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE))
39480 + {
39481 + ATE_RTUSBBulkOutDataPacket(pAd, 0);
39482 + }
39483 + }
39484 +#endif // RALINK_ATE //
39485 +
39486 +}
39487 +
39488 +/*
39489 + ========================================================================
39490 +
39491 + Routine Description:
39492 + Call from Reset action after BulkOut failed.
39493 + Arguments:
39494 +
39495 + Return Value:
39496 +
39497 + Note:
39498 +
39499 + ========================================================================
39500 +*/
39501 +VOID RTUSBCleanUpDataBulkOutQueue(
39502 + IN PRTMP_ADAPTER pAd)
39503 +{
39504 + UCHAR Idx;
39505 + PHT_TX_CONTEXT pTxContext;
39506 +
39507 + DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpDataBulkOutQueue\n"));
39508 +
39509 + for (Idx = 0; Idx < 4; Idx++)
39510 + {
39511 + pTxContext = &pAd->TxContext[Idx];
39512 +
39513 + pTxContext->CurWritePosition = pTxContext->NextBulkOutPosition;
39514 + pTxContext->LastOne = FALSE;
39515 + NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
39516 + pAd->BulkOutPending[Idx] = FALSE;
39517 + NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
39518 + }
39519 +
39520 + DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpDataBulkOutQueue\n"));
39521 +}
39522 +
39523 +/*
39524 + ========================================================================
39525 +
39526 + Routine Description:
39527 +
39528 + Arguments:
39529 +
39530 + Return Value:
39531 +
39532 + Note:
39533 +
39534 + ========================================================================
39535 +*/
39536 +VOID RTUSBCleanUpMLMEBulkOutQueue(
39537 + IN PRTMP_ADAPTER pAd)
39538 +{
39539 + DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpMLMEBulkOutQueue\n"));
39540 +
39541 +#if 0 // Do nothing!
39542 + NdisAcquireSpinLock(&pAd->MLMEBulkOutLock);
39543 + while (pAd->PrioRingTxCnt > 0)
39544 + {
39545 + pAd->MLMEContext[pAd->PrioRingFirstIndex].InUse = FALSE;
39546 +
39547 + pAd->PrioRingFirstIndex++;
39548 + if (pAd->PrioRingFirstIndex >= MGMT_RING_SIZE)
39549 + {
39550 + pAd->PrioRingFirstIndex = 0;
39551 + }
39552 +
39553 + pAd->PrioRingTxCnt--;
39554 + }
39555 + NdisReleaseSpinLock(&pAd->MLMEBulkOutLock);
39556 +#endif
39557 +
39558 + DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpMLMEBulkOutQueue\n"));
39559 +}
39560 +
39561 +
39562 +/*
39563 + ========================================================================
39564 +
39565 + Routine Description:
39566 +
39567 + Arguments:
39568 +
39569 + Return Value:
39570 +
39571 +
39572 + Note:
39573 +
39574 + ========================================================================
39575 +*/
39576 +VOID RTUSBCancelPendingIRPs(
39577 + IN PRTMP_ADAPTER pAd)
39578 +{
39579 + RTUSBCancelPendingBulkInIRP(pAd);
39580 + RTUSBCancelPendingBulkOutIRP(pAd);
39581 +}
39582 +
39583 +/*
39584 + ========================================================================
39585 +
39586 + Routine Description:
39587 +
39588 + Arguments:
39589 +
39590 + Return Value:
39591 +
39592 + Note:
39593 +
39594 + ========================================================================
39595 +*/
39596 +VOID RTUSBCancelPendingBulkInIRP(
39597 + IN PRTMP_ADAPTER pAd)
39598 +{
39599 + PRX_CONTEXT pRxContext;
39600 + UINT i;
39601 +
39602 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->RTUSBCancelPendingBulkInIRP\n"));
39603 + for ( i = 0; i < (RX_RING_SIZE); i++)
39604 + {
39605 + pRxContext = &(pAd->RxContext[i]);
39606 + if(pRxContext->IRPPending == TRUE)
39607 + {
39608 + RTUSB_UNLINK_URB(pRxContext->pUrb);
39609 + pRxContext->IRPPending = FALSE;
39610 + pRxContext->InUse = FALSE;
39611 + //NdisInterlockedDecrement(&pAd->PendingRx);
39612 + //pAd->PendingRx--;
39613 + }
39614 + }
39615 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("<---RTUSBCancelPendingBulkInIRP\n"));
39616 +}
39617 +
39618 +
39619 +/*
39620 + ========================================================================
39621 +
39622 + Routine Description:
39623 +
39624 + Arguments:
39625 +
39626 + Return Value:
39627 +
39628 + Note:
39629 +
39630 + ========================================================================
39631 +*/
39632 +VOID RTUSBCancelPendingBulkOutIRP(
39633 + IN PRTMP_ADAPTER pAd)
39634 +{
39635 + PHT_TX_CONTEXT pHTTXContext;
39636 + PTX_CONTEXT pMLMEContext;
39637 + PTX_CONTEXT pBeaconContext;
39638 + PTX_CONTEXT pNullContext;
39639 + PTX_CONTEXT pPsPollContext;
39640 + PTX_CONTEXT pRTSContext;
39641 + UINT i, Idx;
39642 +// unsigned int IrqFlags;
39643 +// NDIS_SPIN_LOCK *pLock;
39644 +// BOOLEAN *pPending;
39645 +
39646 +
39647 +// pLock = &pAd->BulkOutLock[MGMTPIPEIDX];
39648 +// pPending = &pAd->BulkOutPending[MGMTPIPEIDX];
39649 +
39650 + for (Idx = 0; Idx < 4; Idx++)
39651 + {
39652 + pHTTXContext = &(pAd->TxContext[Idx]);
39653 +
39654 + if (pHTTXContext->IRPPending == TRUE)
39655 + {
39656 +
39657 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
39658 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
39659 + // when the last IRP on the list has been cancelled; that's how we exit this loop
39660 + //
39661 +
39662 + RTUSB_UNLINK_URB(pHTTXContext->pUrb);
39663 +
39664 + // Sleep 200 microseconds to give cancellation time to work
39665 + RTMPusecDelay(200);
39666 + }
39667 +
39668 +#ifdef RALINK_ATE
39669 + pHTTXContext->bCopySavePad = 0;
39670 + pHTTXContext->CurWritePosition = 0;
39671 + pHTTXContext->CurWriteRealPos = 0;
39672 + pHTTXContext->bCurWriting = FALSE;
39673 + pHTTXContext->NextBulkOutPosition = 0;
39674 + pHTTXContext->ENextBulkOutPosition = 0;
39675 +#endif // RALINK_ATE //
39676 + pAd->BulkOutPending[Idx] = FALSE;
39677 + }
39678 +
39679 + //RTMP_IRQ_LOCK(pLock, IrqFlags);
39680 + for (i = 0; i < MGMT_RING_SIZE; i++)
39681 + {
39682 + pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[i].AllocVa;
39683 + if(pMLMEContext && (pMLMEContext->IRPPending == TRUE))
39684 + {
39685 +
39686 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
39687 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
39688 + // when the last IRP on the list has been cancelled; that's how we exit this loop
39689 + //
39690 +
39691 + RTUSB_UNLINK_URB(pMLMEContext->pUrb);
39692 + pMLMEContext->IRPPending = FALSE;
39693 +
39694 + // Sleep 200 microsecs to give cancellation time to work
39695 + RTMPusecDelay(200);
39696 + }
39697 + }
39698 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
39699 + //RTMP_IRQ_UNLOCK(pLock, IrqFlags);
39700 +
39701 +
39702 + for (i = 0; i < BEACON_RING_SIZE; i++)
39703 + {
39704 + pBeaconContext = &(pAd->BeaconContext[i]);
39705 +
39706 + if(pBeaconContext->IRPPending == TRUE)
39707 + {
39708 +
39709 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
39710 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
39711 + // when the last IRP on the list has been cancelled; that's how we exit this loop
39712 + //
39713 +
39714 + RTUSB_UNLINK_URB(pBeaconContext->pUrb);
39715 +
39716 + // Sleep 200 microsecs to give cancellation time to work
39717 + RTMPusecDelay(200);
39718 + }
39719 + }
39720 +
39721 + pNullContext = &(pAd->NullContext);
39722 + if (pNullContext->IRPPending == TRUE)
39723 + RTUSB_UNLINK_URB(pNullContext->pUrb);
39724 +
39725 + pRTSContext = &(pAd->RTSContext);
39726 + if (pRTSContext->IRPPending == TRUE)
39727 + RTUSB_UNLINK_URB(pRTSContext->pUrb);
39728 +
39729 + pPsPollContext = &(pAd->PsPollContext);
39730 + if (pPsPollContext->IRPPending == TRUE)
39731 + RTUSB_UNLINK_URB(pPsPollContext->pUrb);
39732 +
39733 + for (Idx = 0; Idx < 4; Idx++)
39734 + {
39735 + NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
39736 + pAd->BulkOutPending[Idx] = FALSE;
39737 + NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
39738 + }
39739 +}
39740 +
39741 --- /dev/null
39742 +++ b/drivers/staging/rt2870/common/rtusb_data.c
39743 @@ -0,0 +1,229 @@
39744 +/*
39745 + *************************************************************************
39746 + * Ralink Tech Inc.
39747 + * 5F., No.36, Taiyuan St., Jhubei City,
39748 + * Hsinchu County 302,
39749 + * Taiwan, R.O.C.
39750 + *
39751 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
39752 + *
39753 + * This program is free software; you can redistribute it and/or modify *
39754 + * it under the terms of the GNU General Public License as published by *
39755 + * the Free Software Foundation; either version 2 of the License, or *
39756 + * (at your option) any later version. *
39757 + * *
39758 + * This program is distributed in the hope that it will be useful, *
39759 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
39760 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
39761 + * GNU General Public License for more details. *
39762 + * *
39763 + * You should have received a copy of the GNU General Public License *
39764 + * along with this program; if not, write to the *
39765 + * Free Software Foundation, Inc., *
39766 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
39767 + * *
39768 + *************************************************************************
39769 +
39770 + Module Name:
39771 + rtusb_data.c
39772 +
39773 + Abstract:
39774 + Ralink USB driver Tx/Rx functions.
39775 +
39776 + Revision History:
39777 + Who When What
39778 + -------- ---------- ----------------------------------------------
39779 + Jan 03-25-2006 created
39780 +
39781 +*/
39782 +#include "../rt_config.h"
39783 +
39784 +extern UCHAR Phy11BGNextRateUpward[]; // defined in mlme.c
39785 +extern UCHAR EpToQueue[];
39786 +
39787 +VOID REPORT_AMSDU_FRAMES_TO_LLC(
39788 + IN PRTMP_ADAPTER pAd,
39789 + IN PUCHAR pData,
39790 + IN ULONG DataSize)
39791 +{
39792 + PNDIS_PACKET pPacket;
39793 + UINT nMSDU;
39794 + struct sk_buff *pSkb;
39795 +
39796 + nMSDU = 0;
39797 + /* allocate a rx packet */
39798 + pSkb = dev_alloc_skb(RX_BUFFER_AGGRESIZE);
39799 + pPacket = (PNDIS_PACKET)OSPKT_TO_RTPKT(pSkb);
39800 + if (pSkb)
39801 + {
39802 +
39803 + /* convert 802.11 to 802.3 packet */
39804 + pSkb->dev = get_netdev_from_bssid(pAd, BSS0);
39805 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
39806 + deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
39807 + }
39808 + else
39809 + {
39810 + DBGPRINT(RT_DEBUG_ERROR,("Can't allocate skb\n"));
39811 + }
39812 +}
39813 +
39814 +NDIS_STATUS RTUSBFreeDescriptorRequest(
39815 + IN PRTMP_ADAPTER pAd,
39816 + IN UCHAR BulkOutPipeId,
39817 + IN UINT32 NumberRequired)
39818 +{
39819 +// UCHAR FreeNumber = 0;
39820 +// UINT Index;
39821 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
39822 + unsigned long IrqFlags;
39823 + HT_TX_CONTEXT *pHTTXContext;
39824 +
39825 +
39826 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
39827 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39828 + if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition) && ((pHTTXContext->CurWritePosition + NumberRequired + LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition))
39829 + {
39830 +
39831 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
39832 + }
39833 + else if ((pHTTXContext->CurWritePosition == 8) && (pHTTXContext->NextBulkOutPosition < (NumberRequired + LOCAL_TXBUF_SIZE)))
39834 + {
39835 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
39836 + }
39837 + else if (pHTTXContext->bCurWriting == TRUE)
39838 + {
39839 + DBGPRINT(RT_DEBUG_TRACE,("RTUSBFreeD c3 --> QueIdx=%d, CWPos=%ld, NBOutPos=%ld!\n", BulkOutPipeId, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition));
39840 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
39841 + }
39842 + else
39843 + {
39844 + Status = NDIS_STATUS_SUCCESS;
39845 + }
39846 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39847 +
39848 +
39849 + return (Status);
39850 +}
39851 +
39852 +NDIS_STATUS RTUSBFreeDescriptorRelease(
39853 + IN RTMP_ADAPTER *pAd,
39854 + IN UCHAR BulkOutPipeId)
39855 +{
39856 + unsigned long IrqFlags;
39857 + HT_TX_CONTEXT *pHTTXContext;
39858 +
39859 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
39860 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39861 + pHTTXContext->bCurWriting = FALSE;
39862 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39863 +
39864 + return (NDIS_STATUS_SUCCESS);
39865 +}
39866 +
39867 +
39868 +BOOLEAN RTUSBNeedQueueBackForAgg(
39869 + IN RTMP_ADAPTER *pAd,
39870 + IN UCHAR BulkOutPipeId)
39871 +{
39872 + unsigned long IrqFlags;
39873 + HT_TX_CONTEXT *pHTTXContext;
39874 + BOOLEAN needQueBack = FALSE;
39875 +
39876 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
39877 +
39878 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39879 + if ((pHTTXContext->IRPPending == TRUE) /*&& (pAd->TxSwQueue[BulkOutPipeId].Number == 0) */)
39880 + {
39881 +#if 0
39882 + if ((pHTTXContext->CurWritePosition <= 8) &&
39883 + (pHTTXContext->NextBulkOutPosition > 8 && (pHTTXContext->NextBulkOutPosition+MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT))
39884 + {
39885 + needQueBack = TRUE;
39886 + }
39887 + else if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition) &&
39888 + ((pHTTXContext->NextBulkOutPosition + MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT))
39889 + {
39890 + needQueBack = TRUE;
39891 + }
39892 +#else
39893 + if ((pHTTXContext->CurWritePosition < pHTTXContext->ENextBulkOutPosition) &&
39894 + (((pHTTXContext->ENextBulkOutPosition+MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT) || (pHTTXContext->CurWritePosition > MAX_AGGREGATION_SIZE)))
39895 + {
39896 + needQueBack = TRUE;
39897 + }
39898 +#endif
39899 + else if ((pHTTXContext->CurWritePosition > pHTTXContext->ENextBulkOutPosition) &&
39900 + ((pHTTXContext->ENextBulkOutPosition + MAX_AGGREGATION_SIZE) < pHTTXContext->CurWritePosition))
39901 + {
39902 + needQueBack = TRUE;
39903 + }
39904 + }
39905 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
39906 +
39907 + return needQueBack;
39908 +
39909 +}
39910 +
39911 +
39912 +/*
39913 + ========================================================================
39914 +
39915 + Routine Description:
39916 +
39917 + Arguments:
39918 +
39919 + Return Value:
39920 +
39921 + IRQL =
39922 +
39923 + Note:
39924 +
39925 + ========================================================================
39926 +*/
39927 +VOID RTUSBRejectPendingPackets(
39928 + IN PRTMP_ADAPTER pAd)
39929 +{
39930 + UCHAR Index;
39931 + PQUEUE_ENTRY pEntry;
39932 + PNDIS_PACKET pPacket;
39933 + PQUEUE_HEADER pQueue;
39934 +
39935 +
39936 + for (Index = 0; Index < 4; Index++)
39937 + {
39938 + NdisAcquireSpinLock(&pAd->TxSwQueueLock[Index]);
39939 + while (pAd->TxSwQueue[Index].Head != NULL)
39940 + {
39941 + pQueue = (PQUEUE_HEADER) &(pAd->TxSwQueue[Index]);
39942 + pEntry = RemoveHeadQueue(pQueue);
39943 + pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
39944 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
39945 + }
39946 + NdisReleaseSpinLock(&pAd->TxSwQueueLock[Index]);
39947 +
39948 + }
39949 +
39950 +}
39951 +
39952 +VOID RTMPWriteTxInfo(
39953 + IN PRTMP_ADAPTER pAd,
39954 + IN PTXINFO_STRUC pTxInfo,
39955 + IN USHORT USBDMApktLen,
39956 + IN BOOLEAN bWiv,
39957 + IN UCHAR QueueSel,
39958 + IN UCHAR NextValid,
39959 + IN UCHAR TxBurst)
39960 +{
39961 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
39962 + pTxInfo->QSEL = QueueSel;
39963 + if (QueueSel != FIFO_EDCA)
39964 + DBGPRINT(RT_DEBUG_TRACE, ("====> QueueSel != FIFO_EDCA<============\n"));
39965 + pTxInfo->USBDMANextVLD = FALSE; //NextValid; // Need to check with Jan about this.
39966 + pTxInfo->USBDMATxburst = TxBurst;
39967 + pTxInfo->WIV = bWiv;
39968 + pTxInfo->SwUseLastRound = 0;
39969 + pTxInfo->rsv = 0;
39970 + pTxInfo->rsv2 = 0;
39971 +}
39972 +
39973 --- /dev/null
39974 +++ b/drivers/staging/rt2870/common/rtusb_io.c
39975 @@ -0,0 +1,2006 @@
39976 +/*
39977 + *************************************************************************
39978 + * Ralink Tech Inc.
39979 + * 5F., No.36, Taiyuan St., Jhubei City,
39980 + * Hsinchu County 302,
39981 + * Taiwan, R.O.C.
39982 + *
39983 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
39984 + *
39985 + * This program is free software; you can redistribute it and/or modify *
39986 + * it under the terms of the GNU General Public License as published by *
39987 + * the Free Software Foundation; either version 2 of the License, or *
39988 + * (at your option) any later version. *
39989 + * *
39990 + * This program is distributed in the hope that it will be useful, *
39991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
39992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
39993 + * GNU General Public License for more details. *
39994 + * *
39995 + * You should have received a copy of the GNU General Public License *
39996 + * along with this program; if not, write to the *
39997 + * Free Software Foundation, Inc., *
39998 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
39999 + * *
40000 + *************************************************************************
40001 +
40002 + Module Name:
40003 + rtusb_io.c
40004 +
40005 + Abstract:
40006 +
40007 + Revision History:
40008 + Who When What
40009 + -------- ---------- ----------------------------------------------
40010 + Name Date Modification logs
40011 + Paul Lin 06-25-2004 created
40012 +*/
40013 +
40014 +#include "../rt_config.h"
40015 +
40016 +
40017 +/*
40018 + ========================================================================
40019 +
40020 + Routine Description: NIC initialization complete
40021 +
40022 + Arguments:
40023 +
40024 + Return Value:
40025 +
40026 + IRQL =
40027 +
40028 + Note:
40029 +
40030 + ========================================================================
40031 +*/
40032 +
40033 +NTSTATUS RTUSBFirmwareRun(
40034 + IN PRTMP_ADAPTER pAd)
40035 +{
40036 + NTSTATUS Status;
40037 +
40038 + Status = RTUSB_VendorRequest(
40039 + pAd,
40040 + USBD_TRANSFER_DIRECTION_OUT,
40041 + DEVICE_VENDOR_REQUEST_OUT,
40042 + 0x01,
40043 + 0x8,
40044 + 0,
40045 + NULL,
40046 + 0);
40047 +
40048 + return Status;
40049 +}
40050 +
40051 +
40052 +
40053 +/*
40054 + ========================================================================
40055 +
40056 + Routine Description: Write Firmware to NIC.
40057 +
40058 + Arguments:
40059 +
40060 + Return Value:
40061 +
40062 + IRQL =
40063 +
40064 + Note:
40065 +
40066 + ========================================================================
40067 +*/
40068 +NTSTATUS RTUSBFirmwareWrite(
40069 + IN PRTMP_ADAPTER pAd,
40070 + IN PUCHAR pFwImage,
40071 + IN ULONG FwLen)
40072 +{
40073 + UINT32 MacReg;
40074 + NTSTATUS Status;
40075 +// ULONG i;
40076 + USHORT writeLen;
40077 +
40078 + Status = RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg);
40079 +
40080 +
40081 + writeLen = FwLen;
40082 + RTUSBMultiWrite(pAd, FIRMWARE_IMAGE_BASE, pFwImage, writeLen);
40083 +
40084 + Status = RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff);
40085 + Status = RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff);
40086 + Status = RTUSBFirmwareRun(pAd);
40087 +
40088 + return Status;
40089 +}
40090 +
40091 +
40092 +/*
40093 + ========================================================================
40094 +
40095 + Routine Description: Get current firmware operation mode (Return Value)
40096 +
40097 + Arguments:
40098 +
40099 + Return Value:
40100 + 0 or 1 = Downloaded by host driver
40101 + others = Driver doesn't download firmware
40102 +
40103 + IRQL =
40104 +
40105 + Note:
40106 +
40107 + ========================================================================
40108 +*/
40109 +NTSTATUS RTUSBFirmwareOpmode(
40110 + IN PRTMP_ADAPTER pAd,
40111 + OUT PUINT32 pValue)
40112 +{
40113 + NTSTATUS Status;
40114 +
40115 + Status = RTUSB_VendorRequest(
40116 + pAd,
40117 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40118 + DEVICE_VENDOR_REQUEST_IN,
40119 + 0x1,
40120 + 0x11,
40121 + 0,
40122 + pValue,
40123 + 4);
40124 + return Status;
40125 +}
40126 +NTSTATUS RTUSBVenderReset(
40127 + IN PRTMP_ADAPTER pAd)
40128 +{
40129 + NTSTATUS Status;
40130 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("-->RTUSBVenderReset\n"));
40131 + Status = RTUSB_VendorRequest(
40132 + pAd,
40133 + USBD_TRANSFER_DIRECTION_OUT,
40134 + DEVICE_VENDOR_REQUEST_OUT,
40135 + 0x01,
40136 + 0x1,
40137 + 0,
40138 + NULL,
40139 + 0);
40140 +
40141 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("<--RTUSBVenderReset\n"));
40142 + return Status;
40143 +}
40144 +/*
40145 + ========================================================================
40146 +
40147 + Routine Description: Read various length data from RT2573
40148 +
40149 + Arguments:
40150 +
40151 + Return Value:
40152 +
40153 + IRQL =
40154 +
40155 + Note:
40156 +
40157 + ========================================================================
40158 +*/
40159 +NTSTATUS RTUSBMultiRead(
40160 + IN PRTMP_ADAPTER pAd,
40161 + IN USHORT Offset,
40162 + OUT PUCHAR pData,
40163 + IN USHORT length)
40164 +{
40165 + NTSTATUS Status;
40166 +
40167 + Status = RTUSB_VendorRequest(
40168 + pAd,
40169 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40170 + DEVICE_VENDOR_REQUEST_IN,
40171 + 0x7,
40172 + 0,
40173 + Offset,
40174 + pData,
40175 + length);
40176 +
40177 + return Status;
40178 +}
40179 +
40180 +/*
40181 + ========================================================================
40182 +
40183 + Routine Description: Write various length data to RT2573
40184 +
40185 + Arguments:
40186 +
40187 + Return Value:
40188 +
40189 + IRQL =
40190 +
40191 + Note:
40192 +
40193 + ========================================================================
40194 +*/
40195 +NTSTATUS RTUSBMultiWrite_OneByte(
40196 + IN PRTMP_ADAPTER pAd,
40197 + IN USHORT Offset,
40198 + IN PUCHAR pData)
40199 +{
40200 + NTSTATUS Status;
40201 +
40202 + // TODO: In 2870, use this funciton carefully cause it's not stable.
40203 + Status = RTUSB_VendorRequest(
40204 + pAd,
40205 + USBD_TRANSFER_DIRECTION_OUT,
40206 + DEVICE_VENDOR_REQUEST_OUT,
40207 + 0x6,
40208 + 0,
40209 + Offset,
40210 + pData,
40211 + 1);
40212 +
40213 + return Status;
40214 +}
40215 +
40216 +NTSTATUS RTUSBMultiWrite(
40217 + IN PRTMP_ADAPTER pAd,
40218 + IN USHORT Offset,
40219 + IN PUCHAR pData,
40220 + IN USHORT length)
40221 +{
40222 + NTSTATUS Status;
40223 +
40224 +
40225 + USHORT index = 0,Value;
40226 + PUCHAR pSrc = pData;
40227 + USHORT resude = 0;
40228 +
40229 + resude = length % 2;
40230 + length += resude;
40231 + do
40232 + {
40233 + Value =(USHORT)( *pSrc | (*(pSrc + 1) << 8));
40234 + Status = RTUSBSingleWrite(pAd,Offset + index,Value);
40235 + index +=2;
40236 + length -= 2;
40237 + pSrc = pSrc + 2;
40238 + }while(length > 0);
40239 +
40240 + return Status;
40241 +}
40242 +
40243 +
40244 +NTSTATUS RTUSBSingleWrite(
40245 + IN RTMP_ADAPTER *pAd,
40246 + IN USHORT Offset,
40247 + IN USHORT Value)
40248 +{
40249 + NTSTATUS Status;
40250 +
40251 + Status = RTUSB_VendorRequest(
40252 + pAd,
40253 + USBD_TRANSFER_DIRECTION_OUT,
40254 + DEVICE_VENDOR_REQUEST_OUT,
40255 + 0x2,
40256 + Value,
40257 + Offset,
40258 + NULL,
40259 + 0);
40260 +
40261 + return Status;
40262 +
40263 +}
40264 +
40265 +
40266 +/*
40267 + ========================================================================
40268 +
40269 + Routine Description: Read 32-bit MAC register
40270 +
40271 + Arguments:
40272 +
40273 + Return Value:
40274 +
40275 + IRQL =
40276 +
40277 + Note:
40278 +
40279 + ========================================================================
40280 +*/
40281 +NTSTATUS RTUSBReadMACRegister(
40282 + IN PRTMP_ADAPTER pAd,
40283 + IN USHORT Offset,
40284 + OUT PUINT32 pValue)
40285 +{
40286 + NTSTATUS Status;
40287 + UINT32 localVal;
40288 +
40289 + Status = RTUSB_VendorRequest(
40290 + pAd,
40291 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40292 + DEVICE_VENDOR_REQUEST_IN,
40293 + 0x7,
40294 + 0,
40295 + Offset,
40296 + &localVal,
40297 + 4);
40298 +
40299 + *pValue = le2cpu32(localVal);
40300 +
40301 +
40302 + if (Status < 0)
40303 + *pValue = 0xffffffff;
40304 +
40305 + return Status;
40306 +}
40307 +
40308 +
40309 +/*
40310 + ========================================================================
40311 +
40312 + Routine Description: Write 32-bit MAC register
40313 +
40314 + Arguments:
40315 +
40316 + Return Value:
40317 +
40318 + IRQL =
40319 +
40320 + Note:
40321 +
40322 + ========================================================================
40323 +*/
40324 +NTSTATUS RTUSBWriteMACRegister(
40325 + IN PRTMP_ADAPTER pAd,
40326 + IN USHORT Offset,
40327 + IN UINT32 Value)
40328 +{
40329 + NTSTATUS Status;
40330 + UINT32 localVal;
40331 +
40332 + localVal = Value;
40333 +
40334 + Status = RTUSBSingleWrite(pAd, Offset, (USHORT)(localVal & 0xffff));
40335 + Status = RTUSBSingleWrite(pAd, Offset + 2, (USHORT)((localVal & 0xffff0000) >> 16));
40336 +
40337 + return Status;
40338 +}
40339 +
40340 +
40341 +
40342 +#if 1
40343 +/*
40344 + ========================================================================
40345 +
40346 + Routine Description: Read 8-bit BBP register
40347 +
40348 + Arguments:
40349 +
40350 + Return Value:
40351 +
40352 + IRQL =
40353 +
40354 + Note:
40355 +
40356 + ========================================================================
40357 +*/
40358 +NTSTATUS RTUSBReadBBPRegister(
40359 + IN PRTMP_ADAPTER pAd,
40360 + IN UCHAR Id,
40361 + IN PUCHAR pValue)
40362 +{
40363 + BBP_CSR_CFG_STRUC BbpCsr;
40364 + UINT i = 0;
40365 + NTSTATUS status;
40366 +
40367 + // Verify the busy condition
40368 + do
40369 + {
40370 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40371 + if(status >= 0)
40372 + {
40373 + if (!(BbpCsr.field.Busy == BUSY))
40374 + break;
40375 + }
40376 + printk("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n", i);
40377 + i++;
40378 + }
40379 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40380 +
40381 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40382 + {
40383 + //
40384 + // Read failed then Return Default value.
40385 + //
40386 + *pValue = pAd->BbpWriteLatch[Id];
40387 +
40388 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40389 + return STATUS_UNSUCCESSFUL;
40390 + }
40391 +
40392 + // Prepare for write material
40393 + BbpCsr.word = 0;
40394 + BbpCsr.field.fRead = 1;
40395 + BbpCsr.field.Busy = 1;
40396 + BbpCsr.field.RegNum = Id;
40397 + RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
40398 +
40399 + i = 0;
40400 + // Verify the busy condition
40401 + do
40402 + {
40403 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40404 + if (status >= 0)
40405 + {
40406 + if (!(BbpCsr.field.Busy == BUSY))
40407 + {
40408 + *pValue = (UCHAR)BbpCsr.field.Value;
40409 + break;
40410 + }
40411 + }
40412 + printk("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n", i);
40413 + i++;
40414 + }
40415 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40416 +
40417 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40418 + {
40419 + //
40420 + // Read failed then Return Default value.
40421 + //
40422 + *pValue = pAd->BbpWriteLatch[Id];
40423 +
40424 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40425 + return STATUS_UNSUCCESSFUL;
40426 + }
40427 +
40428 + return STATUS_SUCCESS;
40429 +}
40430 +#else
40431 +/*
40432 + ========================================================================
40433 +
40434 + Routine Description: Read 8-bit BBP register via firmware
40435 +
40436 + Arguments:
40437 +
40438 + Return Value:
40439 +
40440 + IRQL =
40441 +
40442 + Note:
40443 +
40444 + ========================================================================
40445 +*/
40446 +NTSTATUS RTUSBReadBBPRegister(
40447 + IN PRTMP_ADAPTER pAd,
40448 + IN UCHAR Id,
40449 + IN PUCHAR pValue)
40450 +{
40451 + BBP_CSR_CFG_STRUC BbpCsr;
40452 + int i, k;
40453 + for (i=0; i<MAX_BUSY_COUNT; i++)
40454 + {
40455 + RTUSBReadMACRegister(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40456 + if (BbpCsr.field.Busy == BUSY)
40457 + {
40458 + continue;
40459 + }
40460 + BbpCsr.word = 0;
40461 + BbpCsr.field.fRead = 1;
40462 + BbpCsr.field.BBP_RW_MODE = 1;
40463 + BbpCsr.field.Busy = 1;
40464 + BbpCsr.field.RegNum = Id;
40465 + RTUSBWriteMACRegister(pAd, H2M_BBP_AGENT, BbpCsr.word);
40466 + AsicSendCommandToMcu(pAd, 0x80, 0xff, 0x0, 0x0);
40467 + for (k=0; k<MAX_BUSY_COUNT; k++)
40468 + {
40469 + RTUSBReadMACRegister(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40470 + if (BbpCsr.field.Busy == IDLE)
40471 + break;
40472 + }
40473 + if ((BbpCsr.field.Busy == IDLE) &&
40474 + (BbpCsr.field.RegNum == Id))
40475 + {
40476 + *pValue = (UCHAR)BbpCsr.field.Value;
40477 + break;
40478 + }
40479 + }
40480 + if (BbpCsr.field.Busy == BUSY)
40481 + {
40482 + DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", Id, BbpCsr.word));
40483 + *pValue = pAd->BbpWriteLatch[Id];
40484 + return STATUS_UNSUCCESSFUL;
40485 + }
40486 + return STATUS_SUCCESS;
40487 +}
40488 +#endif
40489 +
40490 +#if 1
40491 +/*
40492 + ========================================================================
40493 +
40494 + Routine Description: Write 8-bit BBP register
40495 +
40496 + Arguments:
40497 +
40498 + Return Value:
40499 +
40500 + IRQL =
40501 +
40502 + Note:
40503 +
40504 + ========================================================================
40505 +*/
40506 +NTSTATUS RTUSBWriteBBPRegister(
40507 + IN PRTMP_ADAPTER pAd,
40508 + IN UCHAR Id,
40509 + IN UCHAR Value)
40510 +{
40511 + BBP_CSR_CFG_STRUC BbpCsr;
40512 + UINT i = 0;
40513 + NTSTATUS status;
40514 + // Verify the busy condition
40515 + do
40516 + {
40517 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40518 + if (status >= 0)
40519 + {
40520 + if (!(BbpCsr.field.Busy == BUSY))
40521 + break;
40522 + }
40523 + printk("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n", i);
40524 + i++;
40525 + }
40526 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40527 +
40528 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40529 + {
40530 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40531 + return STATUS_UNSUCCESSFUL;
40532 + }
40533 +
40534 + // Prepare for write material
40535 + BbpCsr.word = 0;
40536 + BbpCsr.field.fRead = 0;
40537 + BbpCsr.field.Value = Value;
40538 + BbpCsr.field.Busy = 1;
40539 + BbpCsr.field.RegNum = Id;
40540 + RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
40541 +
40542 + pAd->BbpWriteLatch[Id] = Value;
40543 +
40544 + return STATUS_SUCCESS;
40545 +}
40546 +#else
40547 +/*
40548 + ========================================================================
40549 +
40550 + Routine Description: Write 8-bit BBP register via firmware
40551 +
40552 + Arguments:
40553 +
40554 + Return Value:
40555 +
40556 + IRQL =
40557 +
40558 + Note:
40559 +
40560 + ========================================================================
40561 +*/
40562 +
40563 +NTSTATUS RTUSBWriteBBPRegister(
40564 + IN PRTMP_ADAPTER pAd,
40565 + IN UCHAR Id,
40566 + IN UCHAR Value)
40567 +
40568 +{
40569 + BBP_CSR_CFG_STRUC BbpCsr;
40570 + int BusyCnt;
40571 + for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)
40572 + {
40573 + RTMP_IO_READ32(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40574 + if (BbpCsr.field.Busy == BUSY)
40575 + continue;
40576 + BbpCsr.word = 0;
40577 + BbpCsr.field.fRead = 0;
40578 + BbpCsr.field.BBP_RW_MODE = 1;
40579 + BbpCsr.field.Busy = 1;
40580 + BbpCsr.field.Value = Value;
40581 + BbpCsr.field.RegNum = Id;
40582 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, BbpCsr.word);
40583 + AsicSendCommandToMcu(pAd, 0x80, 0xff, 0x0, 0x0);
40584 + pAd->BbpWriteLatch[Id] = Value;
40585 + break;
40586 + }
40587 + if (BusyCnt == MAX_BUSY_COUNT)
40588 + {
40589 + DBGPRINT_ERR(("BBP write R%d=0x%x fail\n", Id, BbpCsr.word));
40590 + return STATUS_UNSUCCESSFUL;
40591 + }
40592 + return STATUS_SUCCESS;
40593 +}
40594 +#endif
40595 +/*
40596 + ========================================================================
40597 +
40598 + Routine Description: Write RF register through MAC
40599 +
40600 + Arguments:
40601 +
40602 + Return Value:
40603 +
40604 + IRQL =
40605 +
40606 + Note:
40607 +
40608 + ========================================================================
40609 +*/
40610 +NTSTATUS RTUSBWriteRFRegister(
40611 + IN PRTMP_ADAPTER pAd,
40612 + IN UINT32 Value)
40613 +{
40614 + PHY_CSR4_STRUC PhyCsr4;
40615 + UINT i = 0;
40616 + NTSTATUS status;
40617 +
40618 + NdisZeroMemory(&PhyCsr4, sizeof(PHY_CSR4_STRUC));
40619 + do
40620 + {
40621 + status = RTUSBReadMACRegister(pAd, RF_CSR_CFG0, &PhyCsr4.word);
40622 + if (status >= 0)
40623 + {
40624 + if (!(PhyCsr4.field.Busy))
40625 + break;
40626 + }
40627 + printk("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n", i);
40628 + i++;
40629 + }
40630 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40631 +
40632 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40633 + {
40634 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40635 + return STATUS_UNSUCCESSFUL;
40636 + }
40637 +
40638 + RTUSBWriteMACRegister(pAd, RF_CSR_CFG0, Value);
40639 +
40640 + return STATUS_SUCCESS;
40641 +}
40642 +
40643 +/*
40644 + ========================================================================
40645 +
40646 + Routine Description: Write RT3070 RF register through MAC
40647 +
40648 + Arguments:
40649 +
40650 + Return Value:
40651 +
40652 + IRQL =
40653 +
40654 + Note:
40655 +
40656 + ========================================================================
40657 +*/
40658 +NTSTATUS RT30xxWriteRFRegister(
40659 + IN PRTMP_ADAPTER pAd,
40660 + IN UCHAR RegID,
40661 + IN UCHAR Value)
40662 +{
40663 + RF_CSR_CFG_STRUC rfcsr;
40664 + UINT i = 0;
40665 +
40666 + do
40667 + {
40668 + RTUSBReadMACRegister(pAd, RF_CSR_CFG, &rfcsr.word);
40669 +
40670 + if (!rfcsr.field.RF_CSR_KICK)
40671 + break;
40672 + i++;
40673 + }
40674 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40675 +
40676 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40677 + {
40678 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40679 + return STATUS_UNSUCCESSFUL;
40680 + }
40681 +
40682 + rfcsr.field.RF_CSR_WR = 1;
40683 + rfcsr.field.RF_CSR_KICK = 1;
40684 + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID;
40685 + rfcsr.field.RF_CSR_DATA = Value;
40686 +
40687 + RTUSBWriteMACRegister(pAd, RF_CSR_CFG, rfcsr.word);
40688 +
40689 + return STATUS_SUCCESS;
40690 +}
40691 +
40692 +/*
40693 + ========================================================================
40694 +
40695 + Routine Description: Read RT3070 RF register through MAC
40696 +
40697 + Arguments:
40698 +
40699 + Return Value:
40700 +
40701 + IRQL =
40702 +
40703 + Note:
40704 +
40705 + ========================================================================
40706 +*/
40707 +NTSTATUS RT30xxReadRFRegister(
40708 + IN PRTMP_ADAPTER pAd,
40709 + IN UCHAR RegID,
40710 + IN PUCHAR pValue)
40711 +{
40712 + RF_CSR_CFG_STRUC rfcsr;
40713 + UINT i=0, k;
40714 +
40715 + for (i=0; i<MAX_BUSY_COUNT; i++)
40716 + {
40717 + RTUSBReadMACRegister(pAd, RF_CSR_CFG, &rfcsr.word);
40718 +
40719 + if (rfcsr.field.RF_CSR_KICK == BUSY)
40720 + {
40721 + continue;
40722 + }
40723 + rfcsr.word = 0;
40724 + rfcsr.field.RF_CSR_WR = 0;
40725 + rfcsr.field.RF_CSR_KICK = 1;
40726 + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID;
40727 + RTUSBWriteMACRegister(pAd, RF_CSR_CFG, rfcsr.word);
40728 + for (k=0; k<MAX_BUSY_COUNT; k++)
40729 + {
40730 + RTUSBReadMACRegister(pAd, RF_CSR_CFG, &rfcsr.word);
40731 +
40732 + if (rfcsr.field.RF_CSR_KICK == IDLE)
40733 + break;
40734 + }
40735 + if ((rfcsr.field.RF_CSR_KICK == IDLE) &&
40736 + (rfcsr.field.TESTCSR_RFACC_REGNUM == RegID))
40737 + {
40738 + *pValue = (UCHAR)rfcsr.field.RF_CSR_DATA;
40739 + break;
40740 + }
40741 + }
40742 + if (rfcsr.field.RF_CSR_KICK == BUSY)
40743 + {
40744 + DBGPRINT_ERR(("RF read R%d=0x%x fail\n", RegID, rfcsr.word));
40745 + return STATUS_UNSUCCESSFUL;
40746 + }
40747 +
40748 + return STATUS_SUCCESS;
40749 +}
40750 +
40751 +/*
40752 + ========================================================================
40753 +
40754 + Routine Description:
40755 +
40756 + Arguments:
40757 +
40758 + Return Value:
40759 +
40760 + IRQL =
40761 +
40762 + Note:
40763 +
40764 + ========================================================================
40765 +*/
40766 +NTSTATUS RTUSBReadEEPROM(
40767 + IN PRTMP_ADAPTER pAd,
40768 + IN USHORT Offset,
40769 + OUT PUCHAR pData,
40770 + IN USHORT length)
40771 +{
40772 + NTSTATUS Status = STATUS_SUCCESS;
40773 +
40774 + Status = RTUSB_VendorRequest(
40775 + pAd,
40776 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40777 + DEVICE_VENDOR_REQUEST_IN,
40778 + 0x9,
40779 + 0,
40780 + Offset,
40781 + pData,
40782 + length);
40783 +
40784 + return Status;
40785 +}
40786 +
40787 +/*
40788 + ========================================================================
40789 +
40790 + Routine Description:
40791 +
40792 + Arguments:
40793 +
40794 + Return Value:
40795 +
40796 + IRQL =
40797 +
40798 + Note:
40799 +
40800 + ========================================================================
40801 +*/
40802 +NTSTATUS RTUSBWriteEEPROM(
40803 + IN PRTMP_ADAPTER pAd,
40804 + IN USHORT Offset,
40805 + IN PUCHAR pData,
40806 + IN USHORT length)
40807 +{
40808 + NTSTATUS Status = STATUS_SUCCESS;
40809 +
40810 + Status = RTUSB_VendorRequest(
40811 + pAd,
40812 + USBD_TRANSFER_DIRECTION_OUT,
40813 + DEVICE_VENDOR_REQUEST_OUT,
40814 + 0x8,
40815 + 0,
40816 + Offset,
40817 + pData,
40818 + length);
40819 +
40820 + return Status;
40821 +}
40822 +
40823 +/*
40824 + ========================================================================
40825 +
40826 + Routine Description:
40827 +
40828 + Arguments:
40829 +
40830 + Return Value:
40831 +
40832 + IRQL =
40833 +
40834 + Note:
40835 +
40836 + ========================================================================
40837 +*/
40838 +VOID RTUSBPutToSleep(
40839 + IN PRTMP_ADAPTER pAd)
40840 +{
40841 + UINT32 value;
40842 +
40843 + // Timeout 0x40 x 50us
40844 + value = (SLEEPCID<<16)+(OWNERMCU<<24)+ (0x40<<8)+1;
40845 + RTUSBWriteMACRegister(pAd, 0x7010, value);
40846 + RTUSBWriteMACRegister(pAd, 0x404, 0x30);
40847 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
40848 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Sleep Mailbox testvalue %x\n", value));
40849 +
40850 +}
40851 +
40852 +/*
40853 + ========================================================================
40854 +
40855 + Routine Description:
40856 +
40857 + Arguments:
40858 +
40859 + Return Value:
40860 +
40861 + IRQL =
40862 +
40863 + Note:
40864 +
40865 + ========================================================================
40866 +*/
40867 +NTSTATUS RTUSBWakeUp(
40868 + IN PRTMP_ADAPTER pAd)
40869 +{
40870 + NTSTATUS Status;
40871 +
40872 + Status = RTUSB_VendorRequest(
40873 + pAd,
40874 + USBD_TRANSFER_DIRECTION_OUT,
40875 + DEVICE_VENDOR_REQUEST_OUT,
40876 + 0x01,
40877 + 0x09,
40878 + 0,
40879 + NULL,
40880 + 0);
40881 +
40882 + return Status;
40883 +}
40884 +
40885 +/*
40886 + ========================================================================
40887 +
40888 + Routine Description:
40889 +
40890 + Arguments:
40891 +
40892 + Return Value:
40893 +
40894 + IRQL =
40895 +
40896 + Note:
40897 +
40898 + ========================================================================
40899 +*/
40900 +VOID RTUSBInitializeCmdQ(
40901 + IN PCmdQ cmdq)
40902 +{
40903 + cmdq->head = NULL;
40904 + cmdq->tail = NULL;
40905 + cmdq->size = 0;
40906 + cmdq->CmdQState = RT2870_THREAD_INITED;
40907 +}
40908 +
40909 +/*
40910 + ========================================================================
40911 +
40912 + Routine Description:
40913 +
40914 + Arguments:
40915 +
40916 + Return Value:
40917 +
40918 + IRQL =
40919 +
40920 + Note:
40921 +
40922 + ========================================================================
40923 +*/
40924 +NDIS_STATUS RTUSBEnqueueCmdFromNdis(
40925 + IN PRTMP_ADAPTER pAd,
40926 + IN NDIS_OID Oid,
40927 + IN BOOLEAN SetInformation,
40928 + IN PVOID pInformationBuffer,
40929 + IN UINT32 InformationBufferLength)
40930 +{
40931 + NDIS_STATUS status;
40932 + PCmdQElmt cmdqelmt = NULL;
40933 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
40934 +
40935 +
40936 + CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)
40937 + return (NDIS_STATUS_RESOURCES);
40938 +
40939 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt, sizeof(CmdQElmt));
40940 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
40941 + return (NDIS_STATUS_RESOURCES);
40942 +
40943 + cmdqelmt->buffer = NULL;
40944 + if (pInformationBuffer != NULL)
40945 + {
40946 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt->buffer, InformationBufferLength);
40947 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt->buffer == NULL))
40948 + {
40949 + kfree(cmdqelmt);
40950 + return (NDIS_STATUS_RESOURCES);
40951 + }
40952 + else
40953 + {
40954 + NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, InformationBufferLength);
40955 + cmdqelmt->bufferlength = InformationBufferLength;
40956 + }
40957 + }
40958 + else
40959 + cmdqelmt->bufferlength = 0;
40960 +
40961 + cmdqelmt->command = Oid;
40962 + cmdqelmt->CmdFromNdis = TRUE;
40963 + if (SetInformation == TRUE)
40964 + cmdqelmt->SetOperation = TRUE;
40965 + else
40966 + cmdqelmt->SetOperation = FALSE;
40967 +
40968 + NdisAcquireSpinLock(&pAd->CmdQLock);
40969 + if (pAd->CmdQ.CmdQState & RT2870_THREAD_CAN_DO_INSERT)
40970 + {
40971 + EnqueueCmd((&pAd->CmdQ), cmdqelmt);
40972 + status = NDIS_STATUS_SUCCESS;
40973 + }
40974 + else
40975 + {
40976 + status = NDIS_STATUS_FAILURE;
40977 + }
40978 + NdisReleaseSpinLock(&pAd->CmdQLock);
40979 +
40980 + if (status == NDIS_STATUS_FAILURE)
40981 + {
40982 + if (cmdqelmt->buffer)
40983 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
40984 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
40985 + }
40986 + else
40987 + RTUSBCMDUp(pAd);
40988 +
40989 +
40990 + return(NDIS_STATUS_SUCCESS);
40991 +}
40992 +
40993 +/*
40994 + ========================================================================
40995 +
40996 + Routine Description:
40997 +
40998 + Arguments:
40999 +
41000 + Return Value:
41001 +
41002 + IRQL =
41003 +
41004 + Note:
41005 +
41006 + ========================================================================
41007 +*/
41008 +NDIS_STATUS RTUSBEnqueueInternalCmd(
41009 + IN PRTMP_ADAPTER pAd,
41010 + IN NDIS_OID Oid,
41011 + IN PVOID pInformationBuffer,
41012 + IN UINT32 InformationBufferLength)
41013 +{
41014 + NDIS_STATUS status;
41015 + PCmdQElmt cmdqelmt = NULL;
41016 +
41017 +
41018 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt, sizeof(CmdQElmt));
41019 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
41020 + return (NDIS_STATUS_RESOURCES);
41021 + NdisZeroMemory(cmdqelmt, sizeof(CmdQElmt));
41022 +
41023 + if(InformationBufferLength > 0)
41024 + {
41025 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt->buffer, InformationBufferLength);
41026 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt->buffer == NULL))
41027 + {
41028 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41029 + return (NDIS_STATUS_RESOURCES);
41030 + }
41031 + else
41032 + {
41033 + NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, InformationBufferLength);
41034 + cmdqelmt->bufferlength = InformationBufferLength;
41035 + }
41036 + }
41037 + else
41038 + {
41039 + cmdqelmt->buffer = NULL;
41040 + cmdqelmt->bufferlength = 0;
41041 + }
41042 +
41043 + cmdqelmt->command = Oid;
41044 + cmdqelmt->CmdFromNdis = FALSE;
41045 +
41046 + if (cmdqelmt != NULL)
41047 + {
41048 + NdisAcquireSpinLock(&pAd->CmdQLock);
41049 + if (pAd->CmdQ.CmdQState & RT2870_THREAD_CAN_DO_INSERT)
41050 + {
41051 + EnqueueCmd((&pAd->CmdQ), cmdqelmt);
41052 + status = NDIS_STATUS_SUCCESS;
41053 + }
41054 + else
41055 + {
41056 + status = NDIS_STATUS_FAILURE;
41057 + }
41058 + NdisReleaseSpinLock(&pAd->CmdQLock);
41059 +
41060 + if (status == NDIS_STATUS_FAILURE)
41061 + {
41062 + if (cmdqelmt->buffer)
41063 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
41064 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41065 + }
41066 + else
41067 + RTUSBCMDUp(pAd);
41068 + }
41069 + return(NDIS_STATUS_SUCCESS);
41070 +}
41071 +
41072 +/*
41073 + ========================================================================
41074 +
41075 + Routine Description:
41076 +
41077 + Arguments:
41078 +
41079 + Return Value:
41080 +
41081 + IRQL =
41082 +
41083 + Note:
41084 +
41085 + ========================================================================
41086 +*/
41087 +VOID RTUSBDequeueCmd(
41088 + IN PCmdQ cmdq,
41089 + OUT PCmdQElmt *pcmdqelmt)
41090 +{
41091 + *pcmdqelmt = cmdq->head;
41092 +
41093 + if (*pcmdqelmt != NULL)
41094 + {
41095 + cmdq->head = cmdq->head->next;
41096 + cmdq->size--;
41097 + if (cmdq->size == 0)
41098 + cmdq->tail = NULL;
41099 + }
41100 +}
41101 +
41102 +/*
41103 + ========================================================================
41104 + usb_control_msg - Builds a control urb, sends it off and waits for completion
41105 + @dev: pointer to the usb device to send the message to
41106 + @pipe: endpoint "pipe" to send the message to
41107 + @request: USB message request value
41108 + @requesttype: USB message request type value
41109 + @value: USB message value
41110 + @index: USB message index value
41111 + @data: pointer to the data to send
41112 + @size: length in bytes of the data to send
41113 + @timeout: time in jiffies to wait for the message to complete before
41114 + timing out (if 0 the wait is forever)
41115 + Context: !in_interrupt ()
41116 +
41117 + This function sends a simple control message to a specified endpoint
41118 + and waits for the message to complete, or timeout.
41119 + If successful, it returns the number of bytes transferred, otherwise a negative error number.
41120 +
41121 + Don't use this function from within an interrupt context, like a
41122 + bottom half handler. If you need an asynchronous message, or need to send
41123 + a message from within interrupt context, use usb_submit_urb()
41124 + If a thread in your driver uses this call, make sure your disconnect()
41125 + method can wait for it to complete. Since you don't have a handle on
41126 + the URB used, you can't cancel the request.
41127 +
41128 +
41129 + Routine Description:
41130 +
41131 + Arguments:
41132 +
41133 + Return Value:
41134 +
41135 + Note:
41136 +
41137 + ========================================================================
41138 +*/
41139 +NTSTATUS RTUSB_VendorRequest(
41140 + IN PRTMP_ADAPTER pAd,
41141 + IN UINT32 TransferFlags,
41142 + IN UCHAR RequestType,
41143 + IN UCHAR Request,
41144 + IN USHORT Value,
41145 + IN USHORT Index,
41146 + IN PVOID TransferBuffer,
41147 + IN UINT32 TransferBufferLength)
41148 +{
41149 + int ret;
41150 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
41151 +
41152 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
41153 + {
41154 + DBGPRINT(RT_DEBUG_ERROR, ("device disconnected\n"));
41155 + return -1;
41156 + }
41157 + else if (in_interrupt())
41158 + {
41159 + DBGPRINT(RT_DEBUG_ERROR, ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n",Request,Value,Index));
41160 +
41161 + return -1;
41162 + }
41163 + else
41164 + {
41165 +#define MAX_RETRY_COUNT 10
41166 +
41167 + int retryCount = 0;
41168 + void *tmpBuf = TransferBuffer;
41169 +
41170 + // Acquire Control token
41171 +#ifdef INF_AMAZON_SE
41172 + //Semaphore fix INF_AMAZON_SE hang
41173 + //pAd->UsbVendorReqBuf is the swap for DEVICE_VENDOR_REQUEST_IN to fix dma bug.
41174 + ret = down_interruptible(&(pAd->UsbVendorReq_semaphore));
41175 + if (pAd->UsbVendorReqBuf)
41176 + {
41177 + ASSERT(TransferBufferLength <MAX_PARAM_BUFFER_SIZE);
41178 +
41179 + tmpBuf = (void *)pAd->UsbVendorReqBuf;
41180 + NdisZeroMemory(pAd->UsbVendorReqBuf, TransferBufferLength);
41181 +
41182 + if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
41183 + NdisMoveMemory(tmpBuf, TransferBuffer, TransferBufferLength);
41184 + }
41185 +#endif // INF_AMAZON_SE //
41186 + do {
41187 + if( RequestType == DEVICE_VENDOR_REQUEST_OUT)
41188 + ret=usb_control_msg(pObj->pUsb_Dev, usb_sndctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, tmpBuf, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41189 + else if(RequestType == DEVICE_VENDOR_REQUEST_IN)
41190 + ret=usb_control_msg(pObj->pUsb_Dev, usb_rcvctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, tmpBuf, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41191 + else
41192 + {
41193 + DBGPRINT(RT_DEBUG_ERROR, ("vendor request direction is failed\n"));
41194 + ret = -1;
41195 + }
41196 +
41197 + retryCount++;
41198 + if (ret < 0) {
41199 + printk("#\n");
41200 + RTMPusecDelay(5000);
41201 + }
41202 + } while((ret < 0) && (retryCount < MAX_RETRY_COUNT));
41203 +
41204 +#ifdef INF_AMAZON_SE
41205 + if ((pAd->UsbVendorReqBuf) && (RequestType == DEVICE_VENDOR_REQUEST_IN))
41206 + NdisMoveMemory(TransferBuffer, tmpBuf, TransferBufferLength);
41207 + up(&(pAd->UsbVendorReq_semaphore));
41208 +#endif // INF_AMAZON_SE //
41209 +
41210 + if (ret < 0) {
41211 +// DBGPRINT(RT_DEBUG_ERROR, ("USBVendorRequest failed ret=%d \n",ret));
41212 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n",
41213 + ret, TransferFlags, (RequestType == DEVICE_VENDOR_REQUEST_OUT ? "OUT" : "IN"), Request, Index));
41214 + if (Request == 0x2)
41215 + DBGPRINT(RT_DEBUG_ERROR, ("\tRequest Value=0x%04x!\n", Value));
41216 +
41217 + if ((TransferBuffer!= NULL) && (TransferBufferLength > 0))
41218 + hex_dump("Failed TransferBuffer value", TransferBuffer, TransferBufferLength);
41219 + }
41220 +
41221 +#if 0
41222 + // retry
41223 + if (ret < 0) {
41224 + int temp_i=0;
41225 + DBGPRINT(RT_DEBUG_ERROR, ("USBVendorRequest failed ret=%d, \n",ret));
41226 + ret = 0;
41227 + do
41228 + {
41229 + if( RequestType == DEVICE_VENDOR_REQUEST_OUT)
41230 + ret=usb_control_msg(pObj->pUsb_Dev, usb_sndctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, TransferBuffer, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41231 + else if(RequestType == DEVICE_VENDOR_REQUEST_IN)
41232 + ret=usb_control_msg(pObj->pUsb_Dev, usb_rcvctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, TransferBuffer, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41233 + temp_i++;
41234 + } while( (ret < 0) && (temp_i <= 1) );
41235 +
41236 + if( ret >= 0)
41237 + return ret;
41238 +
41239 + }
41240 +#endif
41241 +
41242 + }
41243 + return ret;
41244 +}
41245 +
41246 +/*
41247 + ========================================================================
41248 +
41249 + Routine Description:
41250 + Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT
41251 + synchronously. Callers of this function must be running at
41252 + PASSIVE LEVEL.
41253 +
41254 + Arguments:
41255 +
41256 + Return Value:
41257 +
41258 + Note:
41259 +
41260 + ========================================================================
41261 +*/
41262 +NTSTATUS RTUSB_ResetDevice(
41263 + IN PRTMP_ADAPTER pAd)
41264 +{
41265 + NTSTATUS Status = TRUE;
41266 +
41267 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->USB_ResetDevice\n"));
41268 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
41269 + return Status;
41270 +}
41271 +
41272 +VOID CMDHandler(
41273 + IN PRTMP_ADAPTER pAd)
41274 +{
41275 + PCmdQElmt cmdqelmt;
41276 + PUCHAR pData;
41277 + NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
41278 +// ULONG Now = 0;
41279 + NTSTATUS ntStatus;
41280 +// unsigned long IrqFlags;
41281 +
41282 + while (pAd->CmdQ.size > 0)
41283 + {
41284 + NdisStatus = NDIS_STATUS_SUCCESS;
41285 +
41286 + NdisAcquireSpinLock(&pAd->CmdQLock);
41287 + RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt);
41288 + NdisReleaseSpinLock(&pAd->CmdQLock);
41289 +
41290 + if (cmdqelmt == NULL)
41291 + break;
41292 +
41293 + pData = cmdqelmt->buffer;
41294 +
41295 + if(!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
41296 + {
41297 + switch (cmdqelmt->command)
41298 + {
41299 + case CMDTHREAD_CHECK_GPIO:
41300 + {
41301 +#ifdef CONFIG_STA_SUPPORT
41302 + UINT32 data;
41303 +#endif // CONFIG_STA_SUPPORT //
41304 +#ifdef RALINK_ATE
41305 + if(ATE_ON(pAd))
41306 + {
41307 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
41308 + break;
41309 + }
41310 +#endif // RALINK_ATE //
41311 +
41312 +#ifdef CONFIG_STA_SUPPORT
41313 +
41314 +
41315 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
41316 + {
41317 + // Read GPIO pin2 as Hardware controlled radio state
41318 +
41319 + RTUSBReadMACRegister( pAd, GPIO_CTRL_CFG, &data);
41320 +
41321 + if (data & 0x04)
41322 + {
41323 + pAd->StaCfg.bHwRadio = TRUE;
41324 + }
41325 + else
41326 + {
41327 + pAd->StaCfg.bHwRadio = FALSE;
41328 + }
41329 +
41330 + if(pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
41331 + {
41332 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
41333 + if(pAd->StaCfg.bRadio == TRUE)
41334 + {
41335 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio On !!!\n"));
41336 +
41337 + MlmeRadioOn(pAd);
41338 + // Update extra information
41339 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
41340 + }
41341 + else
41342 + {
41343 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio Off !!!\n"));
41344 +
41345 + MlmeRadioOff(pAd);
41346 + // Update extra information
41347 + pAd->ExtraInfo = HW_RADIO_OFF;
41348 + }
41349 + }
41350 + }
41351 +#endif // CONFIG_STA_SUPPORT //
41352 + }
41353 + break;
41354 +
41355 +#ifdef CONFIG_STA_SUPPORT
41356 + case CMDTHREAD_QKERIODIC_EXECUT:
41357 + {
41358 + StaQuickResponeForRateUpExec(NULL, pAd, NULL, NULL);
41359 + }
41360 + break;
41361 +#endif // CONFIG_STA_SUPPORT //
41362 +
41363 + case CMDTHREAD_RESET_BULK_OUT:
41364 + {
41365 + UINT32 MACValue;
41366 + UCHAR Index;
41367 + int ret=0;
41368 + PHT_TX_CONTEXT pHTTXContext;
41369 +// RTMP_TX_RING *pTxRing;
41370 + unsigned long IrqFlags;
41371 +#ifdef RALINK_ATE
41372 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
41373 +#endif // RALINK_ATE //
41374 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", pAd->bulkResetPipeid));
41375 + // All transfers must be aborted or cancelled before attempting to reset the pipe.
41376 + //RTUSBCancelPendingBulkOutIRP(pAd);
41377 + // Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007
41378 + Index = 0;
41379 + do
41380 + {
41381 + RTUSBReadMACRegister(pAd, TXRXQ_PCNT, &MACValue);
41382 + if ((MACValue & 0xf00000/*0x800000*/) == 0)
41383 + break;
41384 + Index++;
41385 + RTMPusecDelay(10000);
41386 + }while(Index < 100);
41387 + MACValue = 0;
41388 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41389 + // To prevent Read Register error, we 2nd check the validity.
41390 + if ((MACValue & 0xc00000) == 0)
41391 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41392 + // To prevent Read Register error, we 3rd check the validity.
41393 + if ((MACValue & 0xc00000) == 0)
41394 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41395 + MACValue |= 0x80000;
41396 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue);
41397 +
41398 + // Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
41399 + RTMPusecDelay(1000);
41400 +
41401 + MACValue &= (~0x80000);
41402 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue);
41403 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n"));
41404 +
41405 + // Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
41406 + //RTMPusecDelay(5000);
41407 +
41408 + if ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG)
41409 + {
41410 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41411 + if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */)
41412 + {
41413 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
41414 + }
41415 + RTUSBKickBulkOut(pAd);
41416 +
41417 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tTX MGMT RECOVER Done!\n"));
41418 + }
41419 + else
41420 + {
41421 + pHTTXContext = &(pAd->TxContext[pAd->bulkResetPipeid]);
41422 + //NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41423 + RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41424 + if ( pAd->BulkOutPending[pAd->bulkResetPipeid] == FALSE)
41425 + {
41426 + pAd->BulkOutPending[pAd->bulkResetPipeid] = TRUE;
41427 + pHTTXContext->IRPPending = TRUE;
41428 + pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 1;
41429 +
41430 + // no matter what, clean the flag
41431 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41432 +
41433 + //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41434 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41435 +/*-----------------------------------------------------------------------------------------------*/
41436 +#ifdef RALINK_ATE
41437 + if(ATE_ON(pAd))
41438 + {
41439 + pNullContext->IRPPending = TRUE;
41440 + //
41441 + // If driver is still in ATE TXFRAME mode,
41442 + // keep on transmitting ATE frames.
41443 + //
41444 + 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)));
41445 + if((pAd->ate.Mode == ATE_TXFRAME) && ((pAd->ContinBulkOut == TRUE) || (atomic_read(&pAd->BulkOutRemained) > 0)))
41446 + {
41447 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("After CMDTHREAD_RESET_BULK_OUT, continue to bulk out frames !\n"));
41448 +
41449 + // Init Tx context descriptor
41450 + RTUSBInitTxDesc(pAd, pNullContext, 0/* pAd->bulkResetPipeid */, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
41451 +
41452 + if((ret = RTUSB_SUBMIT_URB(pNullContext->pUrb))!=0)
41453 + {
41454 + DBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
41455 + }
41456 +
41457 + pAd->BulkOutReq++;
41458 + }
41459 + }
41460 + else
41461 +#endif // RALINK_ATE //
41462 +/*-----------------------------------------------------------------------------------------------*/
41463 + {
41464 + RTUSBInitHTTxDesc(pAd, pHTTXContext, pAd->bulkResetPipeid, pHTTXContext->BulkOutSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete);
41465 +
41466 + if((ret = RTUSB_SUBMIT_URB(pHTTXContext->pUrb))!=0)
41467 + {
41468 + RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41469 + pAd->BulkOutPending[pAd->bulkResetPipeid] = FALSE;
41470 + pHTTXContext->IRPPending = FALSE;
41471 + pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 0;
41472 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41473 +
41474 + DBGPRINT(RT_DEBUG_ERROR, ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n", ret));
41475 + }
41476 + else
41477 + {
41478 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41479 + DBGPRINT_RAW(RT_DEBUG_TRACE,("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n",
41480 + pAd->bulkResetPipeid, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition,
41481 + pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, pAd->BulkOutPending[pAd->bulkResetPipeid]));
41482 + DBGPRINT_RAW(RT_DEBUG_TRACE,("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
41483 + pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther));
41484 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41485 + 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));
41486 +
41487 + }
41488 + }
41489 + }
41490 + else
41491 + {
41492 + //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41493 + //RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41494 +
41495 + 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));
41496 + if (pAd->bulkResetPipeid == 0)
41497 + {
41498 + UCHAR pendingContext = 0;
41499 + PHT_TX_CONTEXT pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[pAd->bulkResetPipeid ]);
41500 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
41501 + PTX_CONTEXT pNULLContext = (PTX_CONTEXT)(&pAd->PsPollContext);
41502 + PTX_CONTEXT pPsPollContext = (PTX_CONTEXT)(&pAd->NullContext);
41503 +
41504 + if (pHTTXContext->IRPPending)
41505 + pendingContext |= 1;
41506 + else if (pMLMEContext->IRPPending)
41507 + pendingContext |= 2;
41508 + else if (pNULLContext->IRPPending)
41509 + pendingContext |= 4;
41510 + else if (pPsPollContext->IRPPending)
41511 + pendingContext |= 8;
41512 + else
41513 + pendingContext = 0;
41514 +
41515 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("\tTX Occupied by %d!\n", pendingContext));
41516 + }
41517 +
41518 + // no matter what, clean the flag
41519 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41520 +
41521 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41522 +
41523 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << pAd->bulkResetPipeid));
41524 + }
41525 +
41526 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
41527 + //RTUSBKickBulkOut(pAd);
41528 + }
41529 +
41530 + }
41531 + /*
41532 + // Don't cancel BULKIN.
41533 + while ((atomic_read(&pAd->PendingRx) > 0) &&
41534 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41535 + {
41536 + if (atomic_read(&pAd->PendingRx) > 0)
41537 + {
41538 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n"));
41539 + RTUSBCancelPendingBulkInIRP(pAd);
41540 + }
41541 + RTMPusecDelay(100000);
41542 + }
41543 +
41544 + if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
41545 + {
41546 + UCHAR i;
41547 + RTUSBRxPacket(pAd);
41548 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
41549 + pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
41550 + for (i = 0; i < (RX_RING_SIZE); i++)
41551 + {
41552 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
41553 +
41554 + pRxContext->pAd = pAd;
41555 + pRxContext->InUse = FALSE;
41556 + pRxContext->IRPPending = FALSE;
41557 + pRxContext->Readable = FALSE;
41558 + pRxContext->ReorderInUse = FALSE;
41559 +
41560 + }
41561 + RTUSBBulkReceive(pAd);
41562 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n"));
41563 + }*/
41564 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n"));
41565 + break;
41566 +
41567 + case CMDTHREAD_RESET_BULK_IN:
41568 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n"));
41569 +
41570 + // All transfers must be aborted or cancelled before attempting to reset the pipe.
41571 + {
41572 + UINT32 MACValue;
41573 +/*-----------------------------------------------------------------------------------------------*/
41574 +#ifdef RALINK_ATE
41575 + if (ATE_ON(pAd))
41576 + {
41577 + if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41578 + {
41579 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("ATE : BulkIn IRP Pending!!!\n"));
41580 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
41581 + RTMPusecDelay(100000);
41582 + pAd->PendingRx = 0;
41583 + }
41584 + }
41585 + else
41586 +#endif // RALINK_ATE //
41587 +/*-----------------------------------------------------------------------------------------------*/
41588 + {
41589 + //while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41590 + if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41591 + {
41592 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!!\n"));
41593 + RTUSBCancelPendingBulkInIRP(pAd);
41594 + RTMPusecDelay(100000);
41595 + pAd->PendingRx = 0;
41596 + }
41597 + }
41598 +
41599 + // Wait 10ms before reading register.
41600 + RTMPusecDelay(10000);
41601 + ntStatus = RTUSBReadMACRegister(pAd, MAC_CSR0, &MACValue);
41602 +
41603 + if ((NT_SUCCESS(ntStatus) == TRUE) &&
41604 + (!(RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF |
41605 + fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))))
41606 + {
41607 + UCHAR i;
41608 +
41609 + if (RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF |
41610 + fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))
41611 + break;
41612 + pAd->NextRxBulkInPosition = pAd->RxContext[pAd->NextRxBulkInIndex].BulkInOffset;
41613 + 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",
41614 + pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pAd->NextRxBulkInPosition, pAd->BulkInReq, pAd->BulkInComplete, pAd->BulkInCompleteFail));
41615 + for (i = 0; i < RX_RING_SIZE; i++)
41616 + {
41617 + DBGPRINT(RT_DEBUG_TRACE, ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n"
41618 + , i, pAd->RxContext[i].IRPPending, pAd->RxContext[i].InUse, pAd->RxContext[i].Readable));
41619 + }
41620 + /*
41621 +
41622 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n"));
41623 +
41624 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
41625 + pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
41626 + for (i = 0; i < (RX_RING_SIZE); i++)
41627 + {
41628 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
41629 +
41630 + pRxContext->pAd = pAd;
41631 + pRxContext->InUse = FALSE;
41632 + pRxContext->IRPPending = FALSE;
41633 + pRxContext->Readable = FALSE;
41634 + pRxContext->ReorderInUse = FALSE;
41635 +
41636 + }*/
41637 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
41638 + for (i = 0; i < pAd->CommonCfg.NumOfBulkInIRP; i++)
41639 + {
41640 + //RTUSBBulkReceive(pAd);
41641 + PRX_CONTEXT pRxContext;
41642 + PURB pUrb;
41643 + int ret = 0;
41644 + unsigned long IrqFlags;
41645 +
41646 +
41647 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
41648 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
41649 + if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE))
41650 + {
41651 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41652 + break;
41653 + }
41654 + pRxContext->InUse = TRUE;
41655 + pRxContext->IRPPending = TRUE;
41656 + pAd->PendingRx++;
41657 + pAd->BulkInReq++;
41658 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41659 +
41660 + // Init Rx context descriptor
41661 + RTUSBInitRxDesc(pAd, pRxContext);
41662 + pUrb = pRxContext->pUrb;
41663 + if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
41664 + { // fail
41665 +
41666 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
41667 + pRxContext->InUse = FALSE;
41668 + pRxContext->IRPPending = FALSE;
41669 + pAd->PendingRx--;
41670 + pAd->BulkInReq--;
41671 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41672 + DBGPRINT(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", ret, pUrb->status));
41673 + }
41674 + else
41675 + { // success
41676 +#if 0
41677 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
41678 + pRxContext->IRPPending = TRUE;
41679 + //NdisInterlockedIncrement(&pAd->PendingRx);
41680 + pAd->PendingRx++;
41681 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41682 + pAd->BulkInReq++;
41683 +#endif
41684 + //printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex);
41685 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", pUrb->status));
41686 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
41687 + }
41688 + }
41689 +
41690 + }
41691 + else
41692 + {
41693 + // Card must be removed
41694 + if (NT_SUCCESS(ntStatus) != TRUE)
41695 + {
41696 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
41697 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n"));
41698 + }
41699 + else
41700 + {
41701 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", pAd->Flags));
41702 + }
41703 + }
41704 + }
41705 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n"));
41706 + break;
41707 +
41708 + case CMDTHREAD_SET_ASIC_WCID:
41709 + {
41710 + RT_SET_ASIC_WCID SetAsicWcid;
41711 + USHORT offset;
41712 + UINT32 MACValue, MACRValue = 0;
41713 + SetAsicWcid = *((PRT_SET_ASIC_WCID)(pData));
41714 +
41715 + if (SetAsicWcid.WCID >= MAX_LEN_OF_MAC_TABLE)
41716 + return;
41717 +
41718 + offset = MAC_WCID_BASE + ((UCHAR)SetAsicWcid.WCID)*HW_WCID_ENTRY_SIZE;
41719 +
41720 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", SetAsicWcid.WCID, SetAsicWcid.SetTid, SetAsicWcid.DeleteTid));
41721 + 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]);
41722 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("1-MACValue= %x,\n", MACValue));
41723 + RTUSBWriteMACRegister(pAd, offset, MACValue);
41724 + // Read bitmask
41725 + RTUSBReadMACRegister(pAd, offset+4, &MACRValue);
41726 + if ( SetAsicWcid.DeleteTid != 0xffffffff)
41727 + MACRValue &= (~SetAsicWcid.DeleteTid);
41728 + if (SetAsicWcid.SetTid != 0xffffffff)
41729 + MACRValue |= (SetAsicWcid.SetTid);
41730 + MACRValue &= 0xffff0000;
41731 +
41732 + MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[5]<<8)+pAd->MacTab.Content[SetAsicWcid.WCID].Addr[4];
41733 + MACValue |= MACRValue;
41734 + RTUSBWriteMACRegister(pAd, offset+4, MACValue);
41735 +
41736 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-MACValue= %x,\n", MACValue));
41737 + }
41738 + break;
41739 +
41740 + case CMDTHREAD_SET_ASIC_WCID_CIPHER:
41741 + {
41742 +#ifdef CONFIG_STA_SUPPORT
41743 + RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri;
41744 + USHORT offset;
41745 + UINT32 MACRValue = 0;
41746 + SHAREDKEY_MODE_STRUC csr1;
41747 + SetAsicWcidAttri = *((PRT_SET_ASIC_WCID_ATTRI)(pData));
41748 +
41749 + if (SetAsicWcidAttri.WCID >= MAX_LEN_OF_MAC_TABLE)
41750 + return;
41751 +
41752 + offset = MAC_WCID_ATTRIBUTE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_WCID_ATTRI_SIZE;
41753 +
41754 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n", SetAsicWcidAttri.WCID, SetAsicWcidAttri.Cipher));
41755 + // Read bitmask
41756 + RTUSBReadMACRegister(pAd, offset, &MACRValue);
41757 + MACRValue = 0;
41758 + MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1);
41759 +
41760 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41761 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue));
41762 +
41763 + offset = PAIRWISE_IVEIV_TABLE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_IVEIV_ENTRY_SIZE;
41764 + MACRValue = 0;
41765 + if ( (SetAsicWcidAttri.Cipher <= CIPHER_WEP128))
41766 + MACRValue |= ( pAd->StaCfg.DefaultKeyId << 30);
41767 + else
41768 + MACRValue |= (0x20000000);
41769 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41770 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue));
41771 +
41772 + //
41773 + // Update cipher algorithm. WSTA always use BSS0
41774 + //
41775 + // for adhoc mode only ,because wep status slow than add key, when use zero config
41776 + if (pAd->StaCfg.BssType == BSS_ADHOC )
41777 + {
41778 + offset = MAC_WCID_ATTRIBUTE_BASE;
41779 +
41780 + RTUSBReadMACRegister(pAd, offset, &MACRValue);
41781 + MACRValue &= (~0xe);
41782 + MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1);
41783 +
41784 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41785 +
41786 + //Update group key cipher,,because wep status slow than add key, when use zero config
41787 + RTUSBReadMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), &csr1.word);
41788 +
41789 + csr1.field.Bss0Key0CipherAlg = SetAsicWcidAttri.Cipher;
41790 + csr1.field.Bss0Key1CipherAlg = SetAsicWcidAttri.Cipher;
41791 +
41792 + RTUSBWriteMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), csr1.word);
41793 + }
41794 +#endif // CONFIG_STA_SUPPORT //
41795 + }
41796 + break;
41797 +
41798 +#ifdef CONFIG_STA_SUPPORT
41799 +#ifdef QOS_DLS_SUPPORT
41800 + // avoid in interrupt when write key
41801 + case RT_CMD_SET_KEY_TABLE: //General call for AsicAddPairwiseKeyEntry()
41802 + {
41803 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
41804 + KeyInfo = *((PRT_ADD_PAIRWISE_KEY_ENTRY)(pData));
41805 + AsicAddPairwiseKeyEntry(pAd,
41806 + KeyInfo.MacAddr,
41807 + (UCHAR)KeyInfo.MacTabMatchWCID,
41808 + &KeyInfo.CipherKey);
41809 + }
41810 + break;
41811 +
41812 + case RT_CMD_SET_RX_WCID_TABLE: //General call for RTMPAddWcidAttributeEntry()
41813 + {
41814 + PMAC_TABLE_ENTRY pEntry ;
41815 + pEntry = (PMAC_TABLE_ENTRY)(pData);
41816 + RTMPAddWcidAttributeEntry(pAd,
41817 + BSS0,
41818 + 0,
41819 + pEntry->PairwiseKey.CipherAlg,
41820 + pEntry);
41821 + }
41822 + break;
41823 +#endif // QOS_DLS_SUPPORT //
41824 +#endif // CONFIG_STA_SUPPORT //
41825 +
41826 + case CMDTHREAD_SET_CLIENT_MAC_ENTRY:
41827 + {
41828 + MAC_TABLE_ENTRY *pEntry;
41829 + pEntry = (MAC_TABLE_ENTRY *)pData;
41830 +
41831 +
41832 +#ifdef CONFIG_STA_SUPPORT
41833 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
41834 + {
41835 + AsicRemovePairwiseKeyEntry(pAd, pEntry->apidx, (UCHAR)pEntry->Aid);
41836 + if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && (pEntry->WepStatus == Ndis802_11Encryption1Enabled))
41837 + {
41838 + UINT32 uIV = 0;
41839 + PUCHAR ptr;
41840 +
41841 + ptr = (PUCHAR) &uIV;
41842 + *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6);
41843 + AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0);
41844 + AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE);
41845 + }
41846 + else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone)
41847 + {
41848 + UINT32 uIV = 0;
41849 + PUCHAR ptr;
41850 +
41851 + ptr = (PUCHAR) &uIV;
41852 + *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6);
41853 + AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0);
41854 + AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE);
41855 + }
41856 + else
41857 + {
41858 + //
41859 + // Other case, disable engine.
41860 + // Don't worry WPA key, we will add WPA Key after 4-Way handshaking.
41861 + //
41862 + USHORT offset;
41863 + offset = MAC_WCID_ATTRIBUTE_BASE + (pEntry->Aid * HW_WCID_ATTRI_SIZE);
41864 + // RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0
41865 + RTUSBWriteMACRegister(pAd, offset, 0);
41866 + }
41867 + }
41868 +#endif // CONFIG_STA_SUPPORT //
41869 +
41870 + AsicUpdateRxWCIDTable(pAd, pEntry->Aid, pEntry->Addr);
41871 + printk("UpdateRxWCIDTable(): Aid=%d, Addr=%02x:%02x:%02x:%02x:%02x:%02x!\n", pEntry->Aid,
41872 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2], pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
41873 + }
41874 + break;
41875 +
41876 + case OID_802_11_ADD_WEP:
41877 + {
41878 +#ifdef CONFIG_STA_SUPPORT
41879 + UINT i;
41880 + UINT32 KeyIdx;
41881 + PNDIS_802_11_WEP pWepKey;
41882 +
41883 + DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP \n"));
41884 +
41885 + pWepKey = (PNDIS_802_11_WEP)pData;
41886 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
41887 +
41888 + // it is a shared key
41889 + if ((KeyIdx >= 4) || ((pWepKey->KeyLength != 5) && (pWepKey->KeyLength != 13)))
41890 + {
41891 + NdisStatus = NDIS_STATUS_INVALID_DATA;
41892 + DBGPRINT(RT_DEBUG_ERROR, ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n"));
41893 + }
41894 + else
41895 + {
41896 + UCHAR CipherAlg;
41897 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
41898 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
41899 + CipherAlg = (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 5)? CIPHER_WEP64 : CIPHER_WEP128;
41900 +
41901 + //
41902 + // Change the WEP cipher to CKIP cipher if CKIP KP on.
41903 + // Funk UI or Meetinghouse UI will add ckip key from this path.
41904 + //
41905 +
41906 + if (pAd->OpMode == OPMODE_STA)
41907 + {
41908 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
41909 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = pAd->SharedKey[BSS0][KeyIdx].KeyLen;
41910 + }
41911 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
41912 + if (pWepKey->KeyIndex & 0x80000000)
41913 + {
41914 + // Default key for tx (shared key)
41915 + UCHAR IVEIV[8];
41916 + UINT32 WCIDAttri, Value;
41917 + USHORT offset, offset2;
41918 + NdisZeroMemory(IVEIV, 8);
41919 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
41920 + // Add BSSID to WCTable. because this is Tx wep key.
41921 + // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0
41922 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
41923 +
41924 + offset = MAC_WCID_ATTRIBUTE_BASE + (BSSID_WCID* HW_WCID_ATTRI_SIZE);
41925 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
41926 + // 1. IV/EIV
41927 + // Specify key index to find shared key.
41928 + IVEIV[3] = (UCHAR)(KeyIdx<< 6); //WEP Eiv bit off. groupkey index is not 0
41929 + offset = PAIRWISE_IVEIV_TABLE_BASE + (BSS0Mcast_WCID * HW_IVEIV_ENTRY_SIZE);
41930 + offset2 = PAIRWISE_IVEIV_TABLE_BASE + (BSSID_WCID* HW_IVEIV_ENTRY_SIZE);
41931 + for (i=0; i<8;)
41932 + {
41933 + Value = IVEIV[i];
41934 + Value += (IVEIV[i+1]<<8);
41935 + Value += (IVEIV[i+2]<<16);
41936 + Value += (IVEIV[i+3]<<24);
41937 + RTUSBWriteMACRegister(pAd, offset+i, Value);
41938 + RTUSBWriteMACRegister(pAd, offset2+i, Value);
41939 + i+=4;
41940 + }
41941 +
41942 + // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0
41943 + WCIDAttri = (pAd->SharedKey[BSS0][KeyIdx].CipherAlg<<1)|SHAREDKEYTABLE;
41944 + offset = MAC_WCID_ATTRIBUTE_BASE + (BSS0Mcast_WCID* HW_WCID_ATTRI_SIZE);
41945 + DBGPRINT(RT_DEBUG_TRACE, ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n", offset, WCIDAttri));
41946 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
41947 +
41948 + }
41949 + AsicAddSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx, CipherAlg, pWepKey->KeyMaterial, NULL, NULL);
41950 + DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n", KeyIdx, pWepKey->KeyLength));
41951 + }
41952 +#endif // CONFIG_STA_SUPPORT //
41953 + }
41954 + break;
41955 +
41956 + case CMDTHREAD_802_11_COUNTER_MEASURE:
41957 + break;
41958 + default:
41959 + DBGPRINT(RT_DEBUG_ERROR, ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", cmdqelmt->command));
41960 + break;
41961 + }
41962 + }
41963 +
41964 + if (cmdqelmt->CmdFromNdis == TRUE)
41965 + {
41966 + if (cmdqelmt->buffer != NULL)
41967 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
41968 +
41969 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41970 + }
41971 + else
41972 + {
41973 + if ((cmdqelmt->buffer != NULL) && (cmdqelmt->bufferlength != 0))
41974 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
41975 + {
41976 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41977 + }
41978 + }
41979 + } /* end of while */
41980 +}
41981 +
41982 --- /dev/null
41983 +++ b/drivers/staging/rt2870/common/spectrum.c
41984 @@ -0,0 +1,1876 @@
41985 +/*
41986 + *************************************************************************
41987 + * Ralink Tech Inc.
41988 + * 5F., No.36, Taiyuan St., Jhubei City,
41989 + * Hsinchu County 302,
41990 + * Taiwan, R.O.C.
41991 + *
41992 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
41993 + *
41994 + * This program is free software; you can redistribute it and/or modify *
41995 + * it under the terms of the GNU General Public License as published by *
41996 + * the Free Software Foundation; either version 2 of the License, or *
41997 + * (at your option) any later version. *
41998 + * *
41999 + * This program is distributed in the hope that it will be useful, *
42000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
42001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
42002 + * GNU General Public License for more details. *
42003 + * *
42004 + * You should have received a copy of the GNU General Public License *
42005 + * along with this program; if not, write to the *
42006 + * Free Software Foundation, Inc., *
42007 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
42008 + * *
42009 + *************************************************************************
42010 +
42011 + Module Name:
42012 + action.c
42013 +
42014 + Abstract:
42015 + Handle association related requests either from WSTA or from local MLME
42016 +
42017 + Revision History:
42018 + Who When What
42019 + --------- ---------- ----------------------------------------------
42020 + Fonchi Wu 2008 created for 802.11h
42021 + */
42022 +
42023 +#include "../rt_config.h"
42024 +#include "action.h"
42025 +
42026 +VOID MeasureReqTabInit(
42027 + IN PRTMP_ADAPTER pAd)
42028 +{
42029 + NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
42030 +
42031 + pAd->CommonCfg.pMeasureReqTab = kmalloc(sizeof(MEASURE_REQ_TAB), GFP_ATOMIC);
42032 + if (pAd->CommonCfg.pMeasureReqTab)
42033 + NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab, sizeof(MEASURE_REQ_TAB));
42034 + else
42035 + DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n", __FUNCTION__));
42036 +
42037 + return;
42038 +}
42039 +
42040 +VOID MeasureReqTabExit(
42041 + IN PRTMP_ADAPTER pAd)
42042 +{
42043 + NdisFreeSpinLock(pAd->CommonCfg.MeasureReqTabLock);
42044 +
42045 + if (pAd->CommonCfg.pMeasureReqTab)
42046 + kfree(pAd->CommonCfg.pMeasureReqTab);
42047 + pAd->CommonCfg.pMeasureReqTab = NULL;
42048 +
42049 + return;
42050 +}
42051 +
42052 +static PMEASURE_REQ_ENTRY MeasureReqLookUp(
42053 + IN PRTMP_ADAPTER pAd,
42054 + IN UINT8 DialogToken)
42055 +{
42056 + UINT HashIdx;
42057 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42058 + PMEASURE_REQ_ENTRY pEntry = NULL;
42059 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42060 +
42061 + if (pTab == NULL)
42062 + {
42063 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42064 + return NULL;
42065 + }
42066 +
42067 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42068 +
42069 + HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
42070 + pEntry = pTab->Hash[HashIdx];
42071 +
42072 + while (pEntry)
42073 + {
42074 + if (pEntry->DialogToken == DialogToken)
42075 + break;
42076 + else
42077 + {
42078 + pPrevEntry = pEntry;
42079 + pEntry = pEntry->pNext;
42080 + }
42081 + }
42082 +
42083 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42084 +
42085 + return pEntry;
42086 +}
42087 +
42088 +static PMEASURE_REQ_ENTRY MeasureReqInsert(
42089 + IN PRTMP_ADAPTER pAd,
42090 + IN UINT8 DialogToken)
42091 +{
42092 + INT i;
42093 + ULONG HashIdx;
42094 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42095 + PMEASURE_REQ_ENTRY pEntry = NULL, pCurrEntry;
42096 + ULONG Now;
42097 +
42098 + if(pTab == NULL)
42099 + {
42100 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42101 + return NULL;
42102 + }
42103 +
42104 + pEntry = MeasureReqLookUp(pAd, DialogToken);
42105 + if (pEntry == NULL)
42106 + {
42107 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42108 + for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++)
42109 + {
42110 + NdisGetSystemUpTime(&Now);
42111 + pEntry = &pTab->Content[i];
42112 +
42113 + if ((pEntry->Valid == TRUE)
42114 + && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + MQ_REQ_AGE_OUT)))
42115 + {
42116 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42117 + ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42118 + PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42119 +
42120 + // update Hash list
42121 + do
42122 + {
42123 + if (pProbeEntry == pEntry)
42124 + {
42125 + if (pPrevEntry == NULL)
42126 + {
42127 + pTab->Hash[HashIdx] = pEntry->pNext;
42128 + }
42129 + else
42130 + {
42131 + pPrevEntry->pNext = pEntry->pNext;
42132 + }
42133 + break;
42134 + }
42135 +
42136 + pPrevEntry = pProbeEntry;
42137 + pProbeEntry = pProbeEntry->pNext;
42138 + } while (pProbeEntry);
42139 +
42140 + NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
42141 + pTab->Size--;
42142 +
42143 + break;
42144 + }
42145 +
42146 + if (pEntry->Valid == FALSE)
42147 + break;
42148 + }
42149 +
42150 + if (i < MAX_MEASURE_REQ_TAB_SIZE)
42151 + {
42152 + NdisGetSystemUpTime(&Now);
42153 + pEntry->lastTime = Now;
42154 + pEntry->Valid = TRUE;
42155 + pEntry->DialogToken = DialogToken;
42156 + pTab->Size++;
42157 + }
42158 + else
42159 + {
42160 + pEntry = NULL;
42161 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab tab full.\n", __FUNCTION__));
42162 + }
42163 +
42164 + // add this Neighbor entry into HASH table
42165 + if (pEntry)
42166 + {
42167 + HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
42168 + if (pTab->Hash[HashIdx] == NULL)
42169 + {
42170 + pTab->Hash[HashIdx] = pEntry;
42171 + }
42172 + else
42173 + {
42174 + pCurrEntry = pTab->Hash[HashIdx];
42175 + while (pCurrEntry->pNext != NULL)
42176 + pCurrEntry = pCurrEntry->pNext;
42177 + pCurrEntry->pNext = pEntry;
42178 + }
42179 + }
42180 +
42181 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42182 + }
42183 +
42184 + return pEntry;
42185 +}
42186 +
42187 +static VOID MeasureReqDelete(
42188 + IN PRTMP_ADAPTER pAd,
42189 + IN UINT8 DialogToken)
42190 +{
42191 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42192 + PMEASURE_REQ_ENTRY pEntry = NULL;
42193 +
42194 + if(pTab == NULL)
42195 + {
42196 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42197 + return;
42198 + }
42199 +
42200 + // if empty, return
42201 + if (pTab->Size == 0)
42202 + {
42203 + DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n"));
42204 + return;
42205 + }
42206 +
42207 + pEntry = MeasureReqLookUp(pAd, DialogToken);
42208 + if (pEntry != NULL)
42209 + {
42210 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42211 + ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42212 + PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42213 +
42214 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42215 + // update Hash list
42216 + do
42217 + {
42218 + if (pProbeEntry == pEntry)
42219 + {
42220 + if (pPrevEntry == NULL)
42221 + {
42222 + pTab->Hash[HashIdx] = pEntry->pNext;
42223 + }
42224 + else
42225 + {
42226 + pPrevEntry->pNext = pEntry->pNext;
42227 + }
42228 + break;
42229 + }
42230 +
42231 + pPrevEntry = pProbeEntry;
42232 + pProbeEntry = pProbeEntry->pNext;
42233 + } while (pProbeEntry);
42234 +
42235 + NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
42236 + pTab->Size--;
42237 +
42238 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42239 + }
42240 +
42241 + return;
42242 +}
42243 +
42244 +VOID TpcReqTabInit(
42245 + IN PRTMP_ADAPTER pAd)
42246 +{
42247 + NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock);
42248 +
42249 + pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(TPC_REQ_TAB), GFP_ATOMIC);
42250 + if (pAd->CommonCfg.pTpcReqTab)
42251 + NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(TPC_REQ_TAB));
42252 + else
42253 + DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n", __FUNCTION__));
42254 +
42255 + return;
42256 +}
42257 +
42258 +VOID TpcReqTabExit(
42259 + IN PRTMP_ADAPTER pAd)
42260 +{
42261 + NdisFreeSpinLock(pAd->CommonCfg.TpcReqTabLock);
42262 +
42263 + if (pAd->CommonCfg.pTpcReqTab)
42264 + kfree(pAd->CommonCfg.pTpcReqTab);
42265 + pAd->CommonCfg.pTpcReqTab = NULL;
42266 +
42267 + return;
42268 +}
42269 +
42270 +static PTPC_REQ_ENTRY TpcReqLookUp(
42271 + IN PRTMP_ADAPTER pAd,
42272 + IN UINT8 DialogToken)
42273 +{
42274 + UINT HashIdx;
42275 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42276 + PTPC_REQ_ENTRY pEntry = NULL;
42277 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42278 +
42279 + if (pTab == NULL)
42280 + {
42281 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42282 + return NULL;
42283 + }
42284 +
42285 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42286 +
42287 + HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
42288 + pEntry = pTab->Hash[HashIdx];
42289 +
42290 + while (pEntry)
42291 + {
42292 + if (pEntry->DialogToken == DialogToken)
42293 + break;
42294 + else
42295 + {
42296 + pPrevEntry = pEntry;
42297 + pEntry = pEntry->pNext;
42298 + }
42299 + }
42300 +
42301 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42302 +
42303 + return pEntry;
42304 +}
42305 +
42306 +
42307 +static PTPC_REQ_ENTRY TpcReqInsert(
42308 + IN PRTMP_ADAPTER pAd,
42309 + IN UINT8 DialogToken)
42310 +{
42311 + INT i;
42312 + ULONG HashIdx;
42313 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42314 + PTPC_REQ_ENTRY pEntry = NULL, pCurrEntry;
42315 + ULONG Now;
42316 +
42317 + if(pTab == NULL)
42318 + {
42319 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42320 + return NULL;
42321 + }
42322 +
42323 + pEntry = TpcReqLookUp(pAd, DialogToken);
42324 + if (pEntry == NULL)
42325 + {
42326 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42327 + for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++)
42328 + {
42329 + NdisGetSystemUpTime(&Now);
42330 + pEntry = &pTab->Content[i];
42331 +
42332 + if ((pEntry->Valid == TRUE)
42333 + && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + TPC_REQ_AGE_OUT)))
42334 + {
42335 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42336 + ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42337 + PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42338 +
42339 + // update Hash list
42340 + do
42341 + {
42342 + if (pProbeEntry == pEntry)
42343 + {
42344 + if (pPrevEntry == NULL)
42345 + {
42346 + pTab->Hash[HashIdx] = pEntry->pNext;
42347 + }
42348 + else
42349 + {
42350 + pPrevEntry->pNext = pEntry->pNext;
42351 + }
42352 + break;
42353 + }
42354 +
42355 + pPrevEntry = pProbeEntry;
42356 + pProbeEntry = pProbeEntry->pNext;
42357 + } while (pProbeEntry);
42358 +
42359 + NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
42360 + pTab->Size--;
42361 +
42362 + break;
42363 + }
42364 +
42365 + if (pEntry->Valid == FALSE)
42366 + break;
42367 + }
42368 +
42369 + if (i < MAX_TPC_REQ_TAB_SIZE)
42370 + {
42371 + NdisGetSystemUpTime(&Now);
42372 + pEntry->lastTime = Now;
42373 + pEntry->Valid = TRUE;
42374 + pEntry->DialogToken = DialogToken;
42375 + pTab->Size++;
42376 + }
42377 + else
42378 + {
42379 + pEntry = NULL;
42380 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab tab full.\n", __FUNCTION__));
42381 + }
42382 +
42383 + // add this Neighbor entry into HASH table
42384 + if (pEntry)
42385 + {
42386 + HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
42387 + if (pTab->Hash[HashIdx] == NULL)
42388 + {
42389 + pTab->Hash[HashIdx] = pEntry;
42390 + }
42391 + else
42392 + {
42393 + pCurrEntry = pTab->Hash[HashIdx];
42394 + while (pCurrEntry->pNext != NULL)
42395 + pCurrEntry = pCurrEntry->pNext;
42396 + pCurrEntry->pNext = pEntry;
42397 + }
42398 + }
42399 +
42400 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42401 + }
42402 +
42403 + return pEntry;
42404 +}
42405 +
42406 +static VOID TpcReqDelete(
42407 + IN PRTMP_ADAPTER pAd,
42408 + IN UINT8 DialogToken)
42409 +{
42410 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42411 + PTPC_REQ_ENTRY pEntry = NULL;
42412 +
42413 + if(pTab == NULL)
42414 + {
42415 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42416 + return;
42417 + }
42418 +
42419 + // if empty, return
42420 + if (pTab->Size == 0)
42421 + {
42422 + DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n"));
42423 + return;
42424 + }
42425 +
42426 + pEntry = TpcReqLookUp(pAd, DialogToken);
42427 + if (pEntry != NULL)
42428 + {
42429 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42430 + ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42431 + PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42432 +
42433 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42434 + // update Hash list
42435 + do
42436 + {
42437 + if (pProbeEntry == pEntry)
42438 + {
42439 + if (pPrevEntry == NULL)
42440 + {
42441 + pTab->Hash[HashIdx] = pEntry->pNext;
42442 + }
42443 + else
42444 + {
42445 + pPrevEntry->pNext = pEntry->pNext;
42446 + }
42447 + break;
42448 + }
42449 +
42450 + pPrevEntry = pProbeEntry;
42451 + pProbeEntry = pProbeEntry->pNext;
42452 + } while (pProbeEntry);
42453 +
42454 + NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
42455 + pTab->Size--;
42456 +
42457 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42458 + }
42459 +
42460 + return;
42461 +}
42462 +
42463 +/*
42464 + ==========================================================================
42465 + Description:
42466 + Get Current TimeS tamp.
42467 +
42468 + Parametrs:
42469 +
42470 + Return : Current Time Stamp.
42471 + ==========================================================================
42472 + */
42473 +static UINT64 GetCurrentTimeStamp(
42474 + IN PRTMP_ADAPTER pAd)
42475 +{
42476 + // get current time stamp.
42477 + return 0;
42478 +}
42479 +
42480 +/*
42481 + ==========================================================================
42482 + Description:
42483 + Get Current Transmit Power.
42484 +
42485 + Parametrs:
42486 +
42487 + Return : Current Time Stamp.
42488 + ==========================================================================
42489 + */
42490 +static UINT8 GetCurTxPwr(
42491 + IN PRTMP_ADAPTER pAd,
42492 + IN UINT8 Wcid)
42493 +{
42494 + return 16; /* 16 dBm */
42495 +}
42496 +
42497 +/*
42498 + ==========================================================================
42499 + Description:
42500 + Insert Dialog Token into frame.
42501 +
42502 + Parametrs:
42503 + 1. frame buffer pointer.
42504 + 2. frame length.
42505 + 3. Dialog token.
42506 +
42507 + Return : None.
42508 + ==========================================================================
42509 + */
42510 +static VOID InsertDialogToken(
42511 + IN PRTMP_ADAPTER pAd,
42512 + OUT PUCHAR pFrameBuf,
42513 + OUT PULONG pFrameLen,
42514 + IN UINT8 DialogToken)
42515 +{
42516 + ULONG TempLen;
42517 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42518 + 1, &DialogToken,
42519 + END_OF_ARGS);
42520 +
42521 + *pFrameLen = *pFrameLen + TempLen;
42522 +
42523 + return;
42524 +}
42525 +
42526 +/*
42527 + ==========================================================================
42528 + Description:
42529 + Insert TPC Request IE into frame.
42530 +
42531 + Parametrs:
42532 + 1. frame buffer pointer.
42533 + 2. frame length.
42534 +
42535 + Return : None.
42536 + ==========================================================================
42537 + */
42538 + static VOID InsertTpcReqIE(
42539 + IN PRTMP_ADAPTER pAd,
42540 + OUT PUCHAR pFrameBuf,
42541 + OUT PULONG pFrameLen)
42542 +{
42543 + ULONG TempLen;
42544 + ULONG Len = 0;
42545 + UINT8 ElementID = IE_TPC_REQUEST;
42546 +
42547 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42548 + 1, &ElementID,
42549 + 1, &Len,
42550 + END_OF_ARGS);
42551 +
42552 + *pFrameLen = *pFrameLen + TempLen;
42553 +
42554 + return;
42555 +}
42556 +
42557 +/*
42558 + ==========================================================================
42559 + Description:
42560 + Insert TPC Report IE into frame.
42561 +
42562 + Parametrs:
42563 + 1. frame buffer pointer.
42564 + 2. frame length.
42565 + 3. Transmit Power.
42566 + 4. Link Margin.
42567 +
42568 + Return : None.
42569 + ==========================================================================
42570 + */
42571 + static VOID InsertTpcReportIE(
42572 + IN PRTMP_ADAPTER pAd,
42573 + OUT PUCHAR pFrameBuf,
42574 + OUT PULONG pFrameLen,
42575 + IN UINT8 TxPwr,
42576 + IN UINT8 LinkMargin)
42577 +{
42578 + ULONG TempLen;
42579 + ULONG Len = sizeof(TPC_REPORT_INFO);
42580 + UINT8 ElementID = IE_TPC_REPORT;
42581 + TPC_REPORT_INFO TpcReportIE;
42582 +
42583 + TpcReportIE.TxPwr = TxPwr;
42584 + TpcReportIE.LinkMargin = LinkMargin;
42585 +
42586 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42587 + 1, &ElementID,
42588 + 1, &Len,
42589 + Len, &TpcReportIE,
42590 + END_OF_ARGS);
42591 +
42592 + *pFrameLen = *pFrameLen + TempLen;
42593 +
42594 +
42595 + return;
42596 +}
42597 +
42598 +/*
42599 + ==========================================================================
42600 + Description:
42601 + Insert Channel Switch Announcement IE into frame.
42602 +
42603 + Parametrs:
42604 + 1. frame buffer pointer.
42605 + 2. frame length.
42606 + 3. channel switch announcement mode.
42607 + 4. new selected channel.
42608 + 5. channel switch announcement count.
42609 +
42610 + Return : None.
42611 + ==========================================================================
42612 + */
42613 +static VOID InsertChSwAnnIE(
42614 + IN PRTMP_ADAPTER pAd,
42615 + OUT PUCHAR pFrameBuf,
42616 + OUT PULONG pFrameLen,
42617 + IN UINT8 ChSwMode,
42618 + IN UINT8 NewChannel,
42619 + IN UINT8 ChSwCnt)
42620 +{
42621 + ULONG TempLen;
42622 + ULONG Len = sizeof(CH_SW_ANN_INFO);
42623 + UINT8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT;
42624 + CH_SW_ANN_INFO ChSwAnnIE;
42625 +
42626 + ChSwAnnIE.ChSwMode = ChSwMode;
42627 + ChSwAnnIE.Channel = NewChannel;
42628 + ChSwAnnIE.ChSwCnt = ChSwCnt;
42629 +
42630 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42631 + 1, &ElementID,
42632 + 1, &Len,
42633 + Len, &ChSwAnnIE,
42634 + END_OF_ARGS);
42635 +
42636 + *pFrameLen = *pFrameLen + TempLen;
42637 +
42638 +
42639 + return;
42640 +}
42641 +
42642 +/*
42643 + ==========================================================================
42644 + Description:
42645 + Insert Measure Request IE into frame.
42646 +
42647 + Parametrs:
42648 + 1. frame buffer pointer.
42649 + 2. frame length.
42650 + 3. Measure Token.
42651 + 4. Measure Request Mode.
42652 + 5. Measure Request Type.
42653 + 6. Measure Channel.
42654 + 7. Measure Start time.
42655 + 8. Measure Duration.
42656 +
42657 +
42658 + Return : None.
42659 + ==========================================================================
42660 + */
42661 +static VOID InsertMeasureReqIE(
42662 + IN PRTMP_ADAPTER pAd,
42663 + OUT PUCHAR pFrameBuf,
42664 + OUT PULONG pFrameLen,
42665 + IN PMEASURE_REQ_INFO pMeasureReqIE)
42666 +{
42667 + ULONG TempLen;
42668 + UINT8 Len = sizeof(MEASURE_REQ_INFO);
42669 + UINT8 ElementID = IE_MEASUREMENT_REQUEST;
42670 +
42671 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42672 + 1, &ElementID,
42673 + 1, &Len,
42674 + Len, pMeasureReqIE,
42675 + END_OF_ARGS);
42676 +
42677 + *pFrameLen = *pFrameLen + TempLen;
42678 +
42679 + return;
42680 +}
42681 +
42682 +/*
42683 + ==========================================================================
42684 + Description:
42685 + Insert Measure Report IE into frame.
42686 +
42687 + Parametrs:
42688 + 1. frame buffer pointer.
42689 + 2. frame length.
42690 + 3. Measure Token.
42691 + 4. Measure Request Mode.
42692 + 5. Measure Request Type.
42693 + 6. Length of Report Infomation
42694 + 7. Pointer of Report Infomation Buffer.
42695 +
42696 + Return : None.
42697 + ==========================================================================
42698 + */
42699 +static VOID InsertMeasureReportIE(
42700 + IN PRTMP_ADAPTER pAd,
42701 + OUT PUCHAR pFrameBuf,
42702 + OUT PULONG pFrameLen,
42703 + IN PMEASURE_REPORT_INFO pMeasureReportIE,
42704 + IN UINT8 ReportLnfoLen,
42705 + IN PUINT8 pReportInfo)
42706 +{
42707 + ULONG TempLen;
42708 + ULONG Len;
42709 + UINT8 ElementID = IE_MEASUREMENT_REPORT;
42710 +
42711 + Len = sizeof(MEASURE_REPORT_INFO) + ReportLnfoLen;
42712 +
42713 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42714 + 1, &ElementID,
42715 + 1, &Len,
42716 + Len, pMeasureReportIE,
42717 + END_OF_ARGS);
42718 +
42719 + *pFrameLen = *pFrameLen + TempLen;
42720 +
42721 + if ((ReportLnfoLen > 0) && (pReportInfo != NULL))
42722 + {
42723 + MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen,
42724 + ReportLnfoLen, pReportInfo,
42725 + END_OF_ARGS);
42726 +
42727 + *pFrameLen = *pFrameLen + TempLen;
42728 + }
42729 + return;
42730 +}
42731 +
42732 +/*
42733 + ==========================================================================
42734 + Description:
42735 + Prepare Measurement request action frame and enqueue it into
42736 + management queue waiting for transmition.
42737 +
42738 + Parametrs:
42739 + 1. the destination mac address of the frame.
42740 +
42741 + Return : None.
42742 + ==========================================================================
42743 + */
42744 +VOID EnqueueMeasurementReq(
42745 + IN PRTMP_ADAPTER pAd,
42746 + IN PUCHAR pDA,
42747 + IN UINT8 MeasureToken,
42748 + IN UINT8 MeasureReqMode,
42749 + IN UINT8 MeasureReqType,
42750 + IN UINT8 MeasureCh,
42751 + IN UINT16 MeasureDuration)
42752 +{
42753 + PUCHAR pOutBuffer = NULL;
42754 + NDIS_STATUS NStatus;
42755 + ULONG FrameLen;
42756 + HEADER_802_11 ActHdr;
42757 + MEASURE_REQ_INFO MeasureReqIE;
42758 + UINT8 RmReqDailogToken = RandomByte(pAd);
42759 + UINT64 MeasureStartTime = GetCurrentTimeStamp(pAd);
42760 +
42761 + // build action frame header.
42762 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42763 + pAd->CurrentAddress);
42764 +
42765 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42766 + if(NStatus != NDIS_STATUS_SUCCESS)
42767 + {
42768 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42769 + return;
42770 + }
42771 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42772 + FrameLen = sizeof(HEADER_802_11);
42773 +
42774 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRQ);
42775 +
42776 + // fill Dialog Token
42777 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, MeasureToken);
42778 +
42779 + // prepare Measurement IE.
42780 + NdisZeroMemory(&MeasureReqIE, sizeof(MEASURE_REQ_INFO));
42781 + MeasureReqIE.Token = RmReqDailogToken;
42782 + MeasureReqIE.ReqMode.word = MeasureReqMode;
42783 + MeasureReqIE.ReqType = MeasureReqType;
42784 + MeasureReqIE.MeasureReq.ChNum = MeasureCh;
42785 + MeasureReqIE.MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
42786 + MeasureReqIE.MeasureReq.MeasureDuration = cpu2le16(MeasureDuration);
42787 + InsertMeasureReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureReqIE);
42788 +
42789 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
42790 + MlmeFreeMemory(pAd, pOutBuffer);
42791 +
42792 + return;
42793 +}
42794 +
42795 +/*
42796 + ==========================================================================
42797 + Description:
42798 + Prepare Measurement report action frame and enqueue it into
42799 + management queue waiting for transmition.
42800 +
42801 + Parametrs:
42802 + 1. the destination mac address of the frame.
42803 +
42804 + Return : None.
42805 + ==========================================================================
42806 + */
42807 +VOID EnqueueMeasurementRep(
42808 + IN PRTMP_ADAPTER pAd,
42809 + IN PUCHAR pDA,
42810 + IN UINT8 DialogToken,
42811 + IN UINT8 MeasureToken,
42812 + IN UINT8 MeasureReqMode,
42813 + IN UINT8 MeasureReqType,
42814 + IN UINT8 ReportInfoLen,
42815 + IN PUINT8 pReportInfo)
42816 +{
42817 + PUCHAR pOutBuffer = NULL;
42818 + NDIS_STATUS NStatus;
42819 + ULONG FrameLen;
42820 + HEADER_802_11 ActHdr;
42821 + MEASURE_REPORT_INFO MeasureRepIE;
42822 +
42823 + // build action frame header.
42824 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42825 + pAd->CurrentAddress);
42826 +
42827 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42828 + if(NStatus != NDIS_STATUS_SUCCESS)
42829 + {
42830 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42831 + return;
42832 + }
42833 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42834 + FrameLen = sizeof(HEADER_802_11);
42835 +
42836 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRP);
42837 +
42838 + // fill Dialog Token
42839 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
42840 +
42841 + // prepare Measurement IE.
42842 + NdisZeroMemory(&MeasureRepIE, sizeof(MEASURE_REPORT_INFO));
42843 + MeasureRepIE.Token = MeasureToken;
42844 + MeasureRepIE.ReportMode.word = MeasureReqMode;
42845 + MeasureRepIE.ReportType = MeasureReqType;
42846 + InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureRepIE, ReportInfoLen, pReportInfo);
42847 +
42848 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
42849 + MlmeFreeMemory(pAd, pOutBuffer);
42850 +
42851 + return;
42852 +}
42853 +
42854 +/*
42855 + ==========================================================================
42856 + Description:
42857 + Prepare TPC Request action frame and enqueue it into
42858 + management queue waiting for transmition.
42859 +
42860 + Parametrs:
42861 + 1. the destination mac address of the frame.
42862 +
42863 + Return : None.
42864 + ==========================================================================
42865 + */
42866 +VOID EnqueueTPCReq(
42867 + IN PRTMP_ADAPTER pAd,
42868 + IN PUCHAR pDA,
42869 + IN UCHAR DialogToken)
42870 +{
42871 + PUCHAR pOutBuffer = NULL;
42872 + NDIS_STATUS NStatus;
42873 + ULONG FrameLen;
42874 +
42875 + HEADER_802_11 ActHdr;
42876 +
42877 + // build action frame header.
42878 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42879 + pAd->CurrentAddress);
42880 +
42881 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42882 + if(NStatus != NDIS_STATUS_SUCCESS)
42883 + {
42884 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42885 + return;
42886 + }
42887 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42888 + FrameLen = sizeof(HEADER_802_11);
42889 +
42890 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRQ);
42891 +
42892 + // fill Dialog Token
42893 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
42894 +
42895 + // Insert TPC Request IE.
42896 + InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen);
42897 +
42898 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
42899 + MlmeFreeMemory(pAd, pOutBuffer);
42900 +
42901 + return;
42902 +}
42903 +
42904 +/*
42905 + ==========================================================================
42906 + Description:
42907 + Prepare TPC Report action frame and enqueue it into
42908 + management queue waiting for transmition.
42909 +
42910 + Parametrs:
42911 + 1. the destination mac address of the frame.
42912 +
42913 + Return : None.
42914 + ==========================================================================
42915 + */
42916 +VOID EnqueueTPCRep(
42917 + IN PRTMP_ADAPTER pAd,
42918 + IN PUCHAR pDA,
42919 + IN UINT8 DialogToken,
42920 + IN UINT8 TxPwr,
42921 + IN UINT8 LinkMargin)
42922 +{
42923 + PUCHAR pOutBuffer = NULL;
42924 + NDIS_STATUS NStatus;
42925 + ULONG FrameLen;
42926 +
42927 + HEADER_802_11 ActHdr;
42928 +
42929 + // build action frame header.
42930 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42931 + pAd->CurrentAddress);
42932 +
42933 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42934 + if(NStatus != NDIS_STATUS_SUCCESS)
42935 + {
42936 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42937 + return;
42938 + }
42939 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42940 + FrameLen = sizeof(HEADER_802_11);
42941 +
42942 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRP);
42943 +
42944 + // fill Dialog Token
42945 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
42946 +
42947 + // Insert TPC Request IE.
42948 + InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr, LinkMargin);
42949 +
42950 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
42951 + MlmeFreeMemory(pAd, pOutBuffer);
42952 +
42953 + return;
42954 +}
42955 +
42956 +/*
42957 + ==========================================================================
42958 + Description:
42959 + Prepare Channel Switch Announcement action frame and enqueue it into
42960 + management queue waiting for transmition.
42961 +
42962 + Parametrs:
42963 + 1. the destination mac address of the frame.
42964 + 2. Channel switch announcement mode.
42965 + 2. a New selected channel.
42966 +
42967 + Return : None.
42968 + ==========================================================================
42969 + */
42970 +VOID EnqueueChSwAnn(
42971 + IN PRTMP_ADAPTER pAd,
42972 + IN PUCHAR pDA,
42973 + IN UINT8 ChSwMode,
42974 + IN UINT8 NewCh)
42975 +{
42976 + PUCHAR pOutBuffer = NULL;
42977 + NDIS_STATUS NStatus;
42978 + ULONG FrameLen;
42979 +
42980 + HEADER_802_11 ActHdr;
42981 +
42982 + // build action frame header.
42983 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42984 + pAd->CurrentAddress);
42985 +
42986 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42987 + if(NStatus != NDIS_STATUS_SUCCESS)
42988 + {
42989 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42990 + return;
42991 + }
42992 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42993 + FrameLen = sizeof(HEADER_802_11);
42994 +
42995 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH);
42996 +
42997 + InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode, NewCh, 0);
42998 +
42999 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
43000 + MlmeFreeMemory(pAd, pOutBuffer);
43001 +
43002 + return;
43003 +}
43004 +
43005 +static BOOLEAN DfsRequirementCheck(
43006 + IN PRTMP_ADAPTER pAd,
43007 + IN UINT8 Channel)
43008 +{
43009 + BOOLEAN Result = FALSE;
43010 + INT i;
43011 +
43012 + do
43013 + {
43014 + // check DFS procedure is running.
43015 + // make sure DFS procedure won't start twice.
43016 + if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
43017 + {
43018 + Result = FALSE;
43019 + break;
43020 + }
43021 +
43022 + // check the new channel carried from Channel Switch Announcemnet is valid.
43023 + for (i=0; i<pAd->ChannelListNum; i++)
43024 + {
43025 + if ((Channel == pAd->ChannelList[i].Channel)
43026 + &&(pAd->ChannelList[i].RemainingTimeForUse == 0))
43027 + {
43028 + // found radar signal in the channel. the channel can't use at least for 30 minutes.
43029 + pAd->ChannelList[i].RemainingTimeForUse = 1800;//30 min = 1800 sec
43030 + Result = TRUE;
43031 + break;
43032 + }
43033 + }
43034 + } while(FALSE);
43035 +
43036 + return Result;
43037 +}
43038 +
43039 +VOID NotifyChSwAnnToPeerAPs(
43040 + IN PRTMP_ADAPTER pAd,
43041 + IN PUCHAR pRA,
43042 + IN PUCHAR pTA,
43043 + IN UINT8 ChSwMode,
43044 + IN UINT8 Channel)
43045 +{
43046 +#ifdef WDS_SUPPORT
43047 + if (!((pRA[0] & 0xff) == 0xff)) // is pRA a broadcase address.
43048 + {
43049 + INT i;
43050 + // info neighbor APs that Radar signal found throgh WDS link.
43051 + for (i = 0; i < MAX_WDS_ENTRY; i++)
43052 + {
43053 + if (ValidWdsEntry(pAd, i))
43054 + {
43055 + PUCHAR pDA = pAd->WdsTab.WdsEntry[i].PeerWdsAddr;
43056 +
43057 + // DA equal to SA. have no necessary orignal AP which found Radar signal.
43058 + if (MAC_ADDR_EQUAL(pTA, pDA))
43059 + continue;
43060 +
43061 + // send Channel Switch Action frame to info Neighbro APs.
43062 + EnqueueChSwAnn(pAd, pDA, ChSwMode, Channel);
43063 + }
43064 + }
43065 + }
43066 +#endif // WDS_SUPPORT //
43067 +}
43068 +
43069 +static VOID StartDFSProcedure(
43070 + IN PRTMP_ADAPTER pAd,
43071 + IN UCHAR Channel,
43072 + IN UINT8 ChSwMode)
43073 +{
43074 + // start DFS procedure
43075 + pAd->CommonCfg.Channel = Channel;
43076 +#ifdef DOT11_N_SUPPORT
43077 + N_ChannelCheck(pAd);
43078 +#endif // DOT11_N_SUPPORT //
43079 + pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE;
43080 + pAd->CommonCfg.RadarDetect.CSCount = 0;
43081 +}
43082 +
43083 +/*
43084 + ==========================================================================
43085 + Description:
43086 + Channel Switch Announcement action frame sanity check.
43087 +
43088 + Parametrs:
43089 + 1. MLME message containing the received frame
43090 + 2. message length.
43091 + 3. Channel switch announcement infomation buffer.
43092 +
43093 +
43094 + Return : None.
43095 + ==========================================================================
43096 + */
43097 +
43098 +/*
43099 + Channel Switch Announcement IE.
43100 + +----+-----+-----------+------------+-----------+
43101 + | ID | Len |Ch Sw Mode | New Ch Num | Ch Sw Cnt |
43102 + +----+-----+-----------+------------+-----------+
43103 + 1 1 1 1 1
43104 +*/
43105 +static BOOLEAN PeerChSwAnnSanity(
43106 + IN PRTMP_ADAPTER pAd,
43107 + IN VOID *pMsg,
43108 + IN ULONG MsgLen,
43109 + OUT PCH_SW_ANN_INFO pChSwAnnInfo)
43110 +{
43111 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43112 + PUCHAR pFramePtr = Fr->Octet;
43113 + BOOLEAN result = FALSE;
43114 + PEID_STRUCT eid_ptr;
43115 +
43116 + // skip 802.11 header.
43117 + MsgLen -= sizeof(HEADER_802_11);
43118 +
43119 + // skip category and action code.
43120 + pFramePtr += 2;
43121 + MsgLen -= 2;
43122 +
43123 + if (pChSwAnnInfo == NULL)
43124 + return result;
43125 +
43126 + eid_ptr = (PEID_STRUCT)pFramePtr;
43127 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43128 + {
43129 + switch(eid_ptr->Eid)
43130 + {
43131 + case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
43132 + NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet, 1);
43133 + NdisMoveMemory(&pChSwAnnInfo->Channel, eid_ptr->Octet + 1, 1);
43134 + NdisMoveMemory(&pChSwAnnInfo->ChSwCnt, eid_ptr->Octet + 2, 1);
43135 +
43136 + result = TRUE;
43137 + break;
43138 +
43139 + default:
43140 + break;
43141 + }
43142 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43143 + }
43144 +
43145 + return result;
43146 +}
43147 +
43148 +/*
43149 + ==========================================================================
43150 + Description:
43151 + Measurement request action frame sanity check.
43152 +
43153 + Parametrs:
43154 + 1. MLME message containing the received frame
43155 + 2. message length.
43156 + 3. Measurement request infomation buffer.
43157 +
43158 + Return : None.
43159 + ==========================================================================
43160 + */
43161 +static BOOLEAN PeerMeasureReqSanity(
43162 + IN PRTMP_ADAPTER pAd,
43163 + IN VOID *pMsg,
43164 + IN ULONG MsgLen,
43165 + OUT PUINT8 pDialogToken,
43166 + OUT PMEASURE_REQ_INFO pMeasureReqInfo)
43167 +{
43168 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43169 + PUCHAR pFramePtr = Fr->Octet;
43170 + BOOLEAN result = FALSE;
43171 + PEID_STRUCT eid_ptr;
43172 + PUCHAR ptr;
43173 + UINT64 MeasureStartTime;
43174 + UINT16 MeasureDuration;
43175 +
43176 + // skip 802.11 header.
43177 + MsgLen -= sizeof(HEADER_802_11);
43178 +
43179 + // skip category and action code.
43180 + pFramePtr += 2;
43181 + MsgLen -= 2;
43182 +
43183 + if (pMeasureReqInfo == NULL)
43184 + return result;
43185 +
43186 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43187 + pFramePtr += 1;
43188 + MsgLen -= 1;
43189 +
43190 + eid_ptr = (PEID_STRUCT)pFramePtr;
43191 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43192 + {
43193 + switch(eid_ptr->Eid)
43194 + {
43195 + case IE_MEASUREMENT_REQUEST:
43196 + NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, 1);
43197 + NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, eid_ptr->Octet + 1, 1);
43198 + NdisMoveMemory(&pMeasureReqInfo->ReqType, eid_ptr->Octet + 2, 1);
43199 + ptr = eid_ptr->Octet + 3;
43200 + NdisMoveMemory(&pMeasureReqInfo->MeasureReq.ChNum, ptr, 1);
43201 + NdisMoveMemory(&MeasureStartTime, ptr + 1, 8);
43202 + pMeasureReqInfo->MeasureReq.MeasureStartTime = SWAP64(MeasureStartTime);
43203 + NdisMoveMemory(&MeasureDuration, ptr + 9, 2);
43204 + pMeasureReqInfo->MeasureReq.MeasureDuration = SWAP16(MeasureDuration);
43205 +
43206 + result = TRUE;
43207 + break;
43208 +
43209 + default:
43210 + break;
43211 + }
43212 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43213 + }
43214 +
43215 + return result;
43216 +}
43217 +
43218 +/*
43219 + ==========================================================================
43220 + Description:
43221 + Measurement report action frame sanity check.
43222 +
43223 + Parametrs:
43224 + 1. MLME message containing the received frame
43225 + 2. message length.
43226 + 3. Measurement report infomation buffer.
43227 + 4. basic report infomation buffer.
43228 +
43229 + Return : None.
43230 + ==========================================================================
43231 + */
43232 +
43233 +/*
43234 + Measurement Report IE.
43235 + +----+-----+-------+-------------+--------------+----------------+
43236 + | ID | Len | Token | Report Mode | Measure Type | Measure Report |
43237 + +----+-----+-------+-------------+--------------+----------------+
43238 + 1 1 1 1 1 variable
43239 +
43240 + Basic Report.
43241 + +--------+------------+----------+-----+
43242 + | Ch Num | Start Time | Duration | Map |
43243 + +--------+------------+----------+-----+
43244 + 1 8 2 1
43245 +
43246 + Map Field Bit Format.
43247 + +-----+---------------+---------------------+-------+------------+----------+
43248 + | Bss | OFDM Preamble | Unidentified signal | Radar | Unmeasured | Reserved |
43249 + +-----+---------------+---------------------+-------+------------+----------+
43250 + 0 1 2 3 4 5-7
43251 +*/
43252 +static BOOLEAN PeerMeasureReportSanity(
43253 + IN PRTMP_ADAPTER pAd,
43254 + IN VOID *pMsg,
43255 + IN ULONG MsgLen,
43256 + OUT PUINT8 pDialogToken,
43257 + OUT PMEASURE_REPORT_INFO pMeasureReportInfo,
43258 + OUT PUINT8 pReportBuf)
43259 +{
43260 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43261 + PUCHAR pFramePtr = Fr->Octet;
43262 + BOOLEAN result = FALSE;
43263 + PEID_STRUCT eid_ptr;
43264 + PUCHAR ptr;
43265 +
43266 + // skip 802.11 header.
43267 + MsgLen -= sizeof(HEADER_802_11);
43268 +
43269 + // skip category and action code.
43270 + pFramePtr += 2;
43271 + MsgLen -= 2;
43272 +
43273 + if (pMeasureReportInfo == NULL)
43274 + return result;
43275 +
43276 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43277 + pFramePtr += 1;
43278 + MsgLen -= 1;
43279 +
43280 + eid_ptr = (PEID_STRUCT)pFramePtr;
43281 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43282 + {
43283 + switch(eid_ptr->Eid)
43284 + {
43285 + case IE_MEASUREMENT_REPORT:
43286 + NdisMoveMemory(&pMeasureReportInfo->Token, eid_ptr->Octet, 1);
43287 + NdisMoveMemory(&pMeasureReportInfo->ReportMode, eid_ptr->Octet + 1, 1);
43288 + NdisMoveMemory(&pMeasureReportInfo->ReportType, eid_ptr->Octet + 2, 1);
43289 + if (pMeasureReportInfo->ReportType == RM_BASIC)
43290 + {
43291 + PMEASURE_BASIC_REPORT pReport = (PMEASURE_BASIC_REPORT)pReportBuf;
43292 + ptr = eid_ptr->Octet + 3;
43293 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43294 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43295 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43296 + NdisMoveMemory(&pReport->Map, ptr + 11, 1);
43297 +
43298 + }
43299 + else if (pMeasureReportInfo->ReportType == RM_CCA)
43300 + {
43301 + PMEASURE_CCA_REPORT pReport = (PMEASURE_CCA_REPORT)pReportBuf;
43302 + ptr = eid_ptr->Octet + 3;
43303 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43304 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43305 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43306 + NdisMoveMemory(&pReport->CCA_Busy_Fraction, ptr + 11, 1);
43307 +
43308 + }
43309 + else if (pMeasureReportInfo->ReportType == RM_RPI_HISTOGRAM)
43310 + {
43311 + PMEASURE_RPI_REPORT pReport = (PMEASURE_RPI_REPORT)pReportBuf;
43312 + ptr = eid_ptr->Octet + 3;
43313 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43314 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43315 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43316 + NdisMoveMemory(&pReport->RPI_Density, ptr + 11, 8);
43317 + }
43318 + result = TRUE;
43319 + break;
43320 +
43321 + default:
43322 + break;
43323 + }
43324 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43325 + }
43326 +
43327 + return result;
43328 +}
43329 +
43330 +/*
43331 + ==========================================================================
43332 + Description:
43333 + TPC Request action frame sanity check.
43334 +
43335 + Parametrs:
43336 + 1. MLME message containing the received frame
43337 + 2. message length.
43338 + 3. Dialog Token.
43339 +
43340 + Return : None.
43341 + ==========================================================================
43342 + */
43343 +static BOOLEAN PeerTpcReqSanity(
43344 + IN PRTMP_ADAPTER pAd,
43345 + IN VOID *pMsg,
43346 + IN ULONG MsgLen,
43347 + OUT PUINT8 pDialogToken)
43348 +{
43349 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43350 + PUCHAR pFramePtr = Fr->Octet;
43351 + BOOLEAN result = FALSE;
43352 + PEID_STRUCT eid_ptr;
43353 +
43354 + MsgLen -= sizeof(HEADER_802_11);
43355 +
43356 + // skip category and action code.
43357 + pFramePtr += 2;
43358 + MsgLen -= 2;
43359 +
43360 + if (pDialogToken == NULL)
43361 + return result;
43362 +
43363 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43364 + pFramePtr += 1;
43365 + MsgLen -= 1;
43366 +
43367 + eid_ptr = (PEID_STRUCT)pFramePtr;
43368 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43369 + {
43370 + switch(eid_ptr->Eid)
43371 + {
43372 + case IE_TPC_REQUEST:
43373 + result = TRUE;
43374 + break;
43375 +
43376 + default:
43377 + break;
43378 + }
43379 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43380 + }
43381 +
43382 + return result;
43383 +}
43384 +
43385 +/*
43386 + ==========================================================================
43387 + Description:
43388 + TPC Report action frame sanity check.
43389 +
43390 + Parametrs:
43391 + 1. MLME message containing the received frame
43392 + 2. message length.
43393 + 3. Dialog Token.
43394 + 4. TPC Report IE.
43395 +
43396 + Return : None.
43397 + ==========================================================================
43398 + */
43399 +static BOOLEAN PeerTpcRepSanity(
43400 + IN PRTMP_ADAPTER pAd,
43401 + IN VOID *pMsg,
43402 + IN ULONG MsgLen,
43403 + OUT PUINT8 pDialogToken,
43404 + OUT PTPC_REPORT_INFO pTpcRepInfo)
43405 +{
43406 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43407 + PUCHAR pFramePtr = Fr->Octet;
43408 + BOOLEAN result = FALSE;
43409 + PEID_STRUCT eid_ptr;
43410 +
43411 + MsgLen -= sizeof(HEADER_802_11);
43412 +
43413 + // skip category and action code.
43414 + pFramePtr += 2;
43415 + MsgLen -= 2;
43416 +
43417 + if (pDialogToken == NULL)
43418 + return result;
43419 +
43420 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43421 + pFramePtr += 1;
43422 + MsgLen -= 1;
43423 +
43424 + eid_ptr = (PEID_STRUCT)pFramePtr;
43425 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43426 + {
43427 + switch(eid_ptr->Eid)
43428 + {
43429 + case IE_TPC_REPORT:
43430 + NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1);
43431 + NdisMoveMemory(&pTpcRepInfo->LinkMargin, eid_ptr->Octet + 1, 1);
43432 + result = TRUE;
43433 + break;
43434 +
43435 + default:
43436 + break;
43437 + }
43438 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43439 + }
43440 +
43441 + return result;
43442 +}
43443 +
43444 +/*
43445 + ==========================================================================
43446 + Description:
43447 + Channel Switch Announcement action frame handler.
43448 +
43449 + Parametrs:
43450 + Elme - MLME message containing the received frame
43451 +
43452 + Return : None.
43453 + ==========================================================================
43454 + */
43455 +static VOID PeerChSwAnnAction(
43456 + IN PRTMP_ADAPTER pAd,
43457 + IN MLME_QUEUE_ELEM *Elem)
43458 +{
43459 + CH_SW_ANN_INFO ChSwAnnInfo;
43460 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43461 +#ifdef CONFIG_STA_SUPPORT
43462 + UCHAR index = 0, Channel = 0, NewChannel = 0;
43463 + ULONG Bssidx = 0;
43464 +#endif // CONFIG_STA_SUPPORT //
43465 +
43466 + NdisZeroMemory(&ChSwAnnInfo, sizeof(CH_SW_ANN_INFO));
43467 + if (! PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo))
43468 + {
43469 + DBGPRINT(RT_DEBUG_TRACE, ("Invalid Channel Switch Action Frame.\n"));
43470 + return;
43471 + }
43472 +
43473 +
43474 +#ifdef CONFIG_STA_SUPPORT
43475 + if (pAd->OpMode == OPMODE_STA)
43476 + {
43477 + Bssidx = BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3, pAd->CommonCfg.Channel);
43478 + if (Bssidx == BSS_NOT_FOUND)
43479 + {
43480 + DBGPRINT(RT_DEBUG_TRACE, ("PeerChSwAnnAction - Bssidx is not found\n"));
43481 + return;
43482 + }
43483 +
43484 + DBGPRINT(RT_DEBUG_TRACE, ("\n****Bssidx is %d, Channel = %d\n", index, pAd->ScanTab.BssEntry[Bssidx].Channel));
43485 + hex_dump("SSID",pAd->ScanTab.BssEntry[Bssidx].Bssid ,6);
43486 +
43487 + Channel = pAd->CommonCfg.Channel;
43488 + NewChannel = ChSwAnnInfo.Channel;
43489 +
43490 + if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
43491 + {
43492 + // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
43493 + // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
43494 + AsicSwitchChannel(pAd, 1, FALSE);
43495 + AsicLockChannel(pAd, 1);
43496 + LinkDown(pAd, FALSE);
43497 + MlmeQueueInit(&pAd->Mlme.Queue);
43498 + BssTableInit(&pAd->ScanTab);
43499 + RTMPusecDelay(1000000); // use delay to prevent STA do reassoc
43500 +
43501 + // channel sanity check
43502 + for (index = 0 ; index < pAd->ChannelListNum; index++)
43503 + {
43504 + if (pAd->ChannelList[index].Channel == NewChannel)
43505 + {
43506 + pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
43507 + pAd->CommonCfg.Channel = NewChannel;
43508 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
43509 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
43510 + DBGPRINT(RT_DEBUG_TRACE, ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
43511 + break;
43512 + }
43513 + }
43514 +
43515 + if (index >= pAd->ChannelListNum)
43516 + {
43517 + DBGPRINT_ERR(("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
43518 + }
43519 + }
43520 + }
43521 +#endif // CONFIG_STA_SUPPORT //
43522 +
43523 + return;
43524 +}
43525 +
43526 +
43527 +/*
43528 + ==========================================================================
43529 + Description:
43530 + Measurement Request action frame handler.
43531 +
43532 + Parametrs:
43533 + Elme - MLME message containing the received frame
43534 +
43535 + Return : None.
43536 + ==========================================================================
43537 + */
43538 +static VOID PeerMeasureReqAction(
43539 + IN PRTMP_ADAPTER pAd,
43540 + IN MLME_QUEUE_ELEM *Elem)
43541 +{
43542 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43543 + UINT8 DialogToken;
43544 + MEASURE_REQ_INFO MeasureReqInfo;
43545 + MEASURE_REPORT_MODE ReportMode;
43546 +
43547 + if(PeerMeasureReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo))
43548 + {
43549 + ReportMode.word = 0;
43550 + ReportMode.field.Incapable = 1;
43551 + EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken, MeasureReqInfo.Token, ReportMode.word, MeasureReqInfo.ReqType, 0, NULL);
43552 + }
43553 +
43554 + return;
43555 +}
43556 +
43557 +/*
43558 + ==========================================================================
43559 + Description:
43560 + Measurement Report action frame handler.
43561 +
43562 + Parametrs:
43563 + Elme - MLME message containing the received frame
43564 +
43565 + Return : None.
43566 + ==========================================================================
43567 + */
43568 +static VOID PeerMeasureReportAction(
43569 + IN PRTMP_ADAPTER pAd,
43570 + IN MLME_QUEUE_ELEM *Elem)
43571 +{
43572 + MEASURE_REPORT_INFO MeasureReportInfo;
43573 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43574 + UINT8 DialogToken;
43575 + PUINT8 pMeasureReportInfo;
43576 +
43577 +// if (pAd->CommonCfg.bIEEE80211H != TRUE)
43578 +// return;
43579 +
43580 + if ((pMeasureReportInfo = kmalloc(sizeof(MEASURE_RPI_REPORT), GFP_ATOMIC)) == NULL)
43581 + {
43582 + DBGPRINT(RT_DEBUG_ERROR, ("%s unable to alloc memory for measure report buffer (size=%d).\n", __FUNCTION__, sizeof(MEASURE_RPI_REPORT)));
43583 + return;
43584 + }
43585 +
43586 + NdisZeroMemory(&MeasureReportInfo, sizeof(MEASURE_REPORT_INFO));
43587 + NdisZeroMemory(pMeasureReportInfo, sizeof(MEASURE_RPI_REPORT));
43588 + if (PeerMeasureReportSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo, pMeasureReportInfo))
43589 + {
43590 + do {
43591 + PMEASURE_REQ_ENTRY pEntry = NULL;
43592 +
43593 + // Not a autonomous measure report.
43594 + // check the dialog token field. drop it if the dialog token doesn't match.
43595 + if ((DialogToken != 0)
43596 + && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) == NULL))
43597 + break;
43598 +
43599 + if (pEntry != NULL)
43600 + MeasureReqDelete(pAd, pEntry->DialogToken);
43601 +
43602 + if (MeasureReportInfo.ReportType == RM_BASIC)
43603 + {
43604 + PMEASURE_BASIC_REPORT pBasicReport = (PMEASURE_BASIC_REPORT)pMeasureReportInfo;
43605 + if ((pBasicReport->Map.field.Radar)
43606 + && (DfsRequirementCheck(pAd, pBasicReport->ChNum) == TRUE))
43607 + {
43608 + NotifyChSwAnnToPeerAPs(pAd, pFr->Hdr.Addr1, pFr->Hdr.Addr2, 1, pBasicReport->ChNum);
43609 + StartDFSProcedure(pAd, pBasicReport->ChNum, 1);
43610 + }
43611 + }
43612 + } while (FALSE);
43613 + }
43614 + else
43615 + DBGPRINT(RT_DEBUG_TRACE, ("Invalid Measurement Report Frame.\n"));
43616 +
43617 + kfree(pMeasureReportInfo);
43618 +
43619 + return;
43620 +}
43621 +
43622 +/*
43623 + ==========================================================================
43624 + Description:
43625 + TPC Request action frame handler.
43626 +
43627 + Parametrs:
43628 + Elme - MLME message containing the received frame
43629 +
43630 + Return : None.
43631 + ==========================================================================
43632 + */
43633 +static VOID PeerTpcReqAction(
43634 + IN PRTMP_ADAPTER pAd,
43635 + IN MLME_QUEUE_ELEM *Elem)
43636 +{
43637 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43638 + PUCHAR pFramePtr = pFr->Octet;
43639 + UINT8 DialogToken;
43640 + UINT8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid);
43641 + UINT8 LinkMargin = 0;
43642 + CHAR RealRssi;
43643 +
43644 + // link margin: Ratio of the received signal power to the minimum desired by the station (STA). The
43645 + // STA may incorporate rate information and channel conditions, including interference, into its computation
43646 + // of link margin.
43647 +
43648 + RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
43649 + ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
43650 + ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
43651 +
43652 + // skip Category and action code.
43653 + pFramePtr += 2;
43654 +
43655 + // Dialog token.
43656 + NdisMoveMemory(&DialogToken, pFramePtr, 1);
43657 +
43658 + LinkMargin = (RealRssi / MIN_RCV_PWR);
43659 + if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken))
43660 + EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr, LinkMargin);
43661 +
43662 + return;
43663 +}
43664 +
43665 +/*
43666 + ==========================================================================
43667 + Description:
43668 + TPC Report action frame handler.
43669 +
43670 + Parametrs:
43671 + Elme - MLME message containing the received frame
43672 +
43673 + Return : None.
43674 + ==========================================================================
43675 + */
43676 +static VOID PeerTpcRepAction(
43677 + IN PRTMP_ADAPTER pAd,
43678 + IN MLME_QUEUE_ELEM *Elem)
43679 +{
43680 + UINT8 DialogToken;
43681 + TPC_REPORT_INFO TpcRepInfo;
43682 + PTPC_REQ_ENTRY pEntry = NULL;
43683 +
43684 + NdisZeroMemory(&TpcRepInfo, sizeof(TPC_REPORT_INFO));
43685 + if (PeerTpcRepSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo))
43686 + {
43687 + if ((pEntry = TpcReqLookUp(pAd, DialogToken)) != NULL)
43688 + {
43689 + TpcReqDelete(pAd, pEntry->DialogToken);
43690 + DBGPRINT(RT_DEBUG_TRACE, ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n",
43691 + __FUNCTION__, DialogToken, TpcRepInfo.TxPwr, TpcRepInfo.LinkMargin));
43692 + }
43693 + }
43694 +
43695 + return;
43696 +}
43697 +
43698 +/*
43699 + ==========================================================================
43700 + Description:
43701 + Spectrun action frames Handler such as channel switch annoucement,
43702 + measurement report, measurement request actions frames.
43703 +
43704 + Parametrs:
43705 + Elme - MLME message containing the received frame
43706 +
43707 + Return : None.
43708 + ==========================================================================
43709 + */
43710 +VOID PeerSpectrumAction(
43711 + IN PRTMP_ADAPTER pAd,
43712 + IN MLME_QUEUE_ELEM *Elem)
43713 +{
43714 +
43715 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
43716 +
43717 + if (pAd->CommonCfg.bIEEE80211H != TRUE)
43718 + return;
43719 +
43720 + switch(Action)
43721 + {
43722 + case SPEC_MRQ:
43723 + // current rt2860 unable do such measure specified in Measurement Request.
43724 + // reject all measurement request.
43725 + PeerMeasureReqAction(pAd, Elem);
43726 + break;
43727 +
43728 + case SPEC_MRP:
43729 + PeerMeasureReportAction(pAd, Elem);
43730 + break;
43731 +
43732 + case SPEC_TPCRQ:
43733 + PeerTpcReqAction(pAd, Elem);
43734 + break;
43735 +
43736 + case SPEC_TPCRP:
43737 + PeerTpcRepAction(pAd, Elem);
43738 + break;
43739 +
43740 + case SPEC_CHANNEL_SWITCH:
43741 +{
43742 +#ifdef DOT11N_DRAFT3
43743 + SEC_CHA_OFFSET_IE Secondary;
43744 + CHA_SWITCH_ANNOUNCE_IE ChannelSwitch;
43745 +
43746 + // 802.11h only has Channel Switch Announcement IE.
43747 + RTMPMoveMemory(&ChannelSwitch, &Elem->Msg[LENGTH_802_11+4], sizeof (CHA_SWITCH_ANNOUNCE_IE));
43748 +
43749 + // 802.11n D3.03 adds secondary channel offset element in the end.
43750 + if (Elem->MsgLen == (LENGTH_802_11 + 2 + sizeof (CHA_SWITCH_ANNOUNCE_IE) + sizeof (SEC_CHA_OFFSET_IE)))
43751 + {
43752 + RTMPMoveMemory(&Secondary, &Elem->Msg[LENGTH_802_11+9], sizeof (SEC_CHA_OFFSET_IE));
43753 + }
43754 + else
43755 + {
43756 + Secondary.SecondaryChannelOffset = 0;
43757 + }
43758 +
43759 + if ((Elem->Msg[LENGTH_802_11+2] == IE_CHANNEL_SWITCH_ANNOUNCEMENT) && (Elem->Msg[LENGTH_802_11+3] == 3))
43760 + {
43761 + ChannelSwitchAction(pAd, Elem->Wcid, ChannelSwitch.NewChannel, Secondary.SecondaryChannelOffset);
43762 + }
43763 +#endif // DOT11N_DRAFT3 //
43764 +}
43765 + PeerChSwAnnAction(pAd, Elem);
43766 + break;
43767 + }
43768 +
43769 + return;
43770 +}
43771 +
43772 +/*
43773 + ==========================================================================
43774 + Description:
43775 +
43776 + Parametrs:
43777 +
43778 + Return : None.
43779 + ==========================================================================
43780 + */
43781 +INT Set_MeasureReq_Proc(
43782 + IN PRTMP_ADAPTER pAd,
43783 + IN PUCHAR arg)
43784 +{
43785 + UINT Aid = 1;
43786 + UINT ArgIdx;
43787 + PUCHAR thisChar;
43788 +
43789 + MEASURE_REQ_MODE MeasureReqMode;
43790 + UINT8 MeasureReqToken = RandomByte(pAd);
43791 + UINT8 MeasureReqType = RM_BASIC;
43792 + UINT8 MeasureCh = 1;
43793 +
43794 + ArgIdx = 1;
43795 + while ((thisChar = strsep((char **)&arg, "-")) != NULL)
43796 + {
43797 + switch(ArgIdx)
43798 + {
43799 + case 1: // Aid.
43800 + Aid = simple_strtol(thisChar, 0, 16);
43801 + break;
43802 +
43803 + case 2: // Measurement Request Type.
43804 + MeasureReqType = simple_strtol(thisChar, 0, 16);
43805 + if (MeasureReqType > 3)
43806 + {
43807 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow MeasureReqType(%d)\n", __FUNCTION__, MeasureReqType));
43808 + return TRUE;
43809 + }
43810 + break;
43811 +
43812 + case 3: // Measurement channel.
43813 + MeasureCh = simple_strtol(thisChar, 0, 16);
43814 + break;
43815 + }
43816 + ArgIdx++;
43817 + }
43818 +
43819 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __FUNCTION__, Aid, MeasureReqType, MeasureCh));
43820 + if (!VALID_WCID(Aid))
43821 + {
43822 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __FUNCTION__, Aid));
43823 + return TRUE;
43824 + }
43825 +
43826 + MeasureReqMode.word = 0;
43827 + MeasureReqMode.field.Enable = 1;
43828 +
43829 + MeasureReqInsert(pAd, MeasureReqToken);
43830 +
43831 + EnqueueMeasurementReq(pAd, pAd->MacTab.Content[Aid].Addr,
43832 + MeasureReqToken, MeasureReqMode.word, MeasureReqType, MeasureCh, 2000);
43833 +
43834 + return TRUE;
43835 +}
43836 +
43837 +INT Set_TpcReq_Proc(
43838 + IN PRTMP_ADAPTER pAd,
43839 + IN PUCHAR arg)
43840 +{
43841 + UINT Aid;
43842 +
43843 + UINT8 TpcReqToken = RandomByte(pAd);
43844 +
43845 + Aid = simple_strtol(arg, 0, 16);
43846 +
43847 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __FUNCTION__, Aid));
43848 + if (!VALID_WCID(Aid))
43849 + {
43850 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __FUNCTION__, Aid));
43851 + return TRUE;
43852 + }
43853 +
43854 + TpcReqInsert(pAd, TpcReqToken);
43855 +
43856 + EnqueueTPCReq(pAd, pAd->MacTab.Content[Aid].Addr, TpcReqToken);
43857 +
43858 + return TRUE;
43859 +}
43860 +
43861 --- /dev/null
43862 +++ b/drivers/staging/rt2870/dfs.h
43863 @@ -0,0 +1,100 @@
43864 +/*
43865 + *************************************************************************
43866 + * Ralink Tech Inc.
43867 + * 5F., No.36, Taiyuan St., Jhubei City,
43868 + * Hsinchu County 302,
43869 + * Taiwan, R.O.C.
43870 + *
43871 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
43872 + *
43873 + * This program is free software; you can redistribute it and/or modify *
43874 + * it under the terms of the GNU General Public License as published by *
43875 + * the Free Software Foundation; either version 2 of the License, or *
43876 + * (at your option) any later version. *
43877 + * *
43878 + * This program is distributed in the hope that it will be useful, *
43879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
43880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
43881 + * GNU General Public License for more details. *
43882 + * *
43883 + * You should have received a copy of the GNU General Public License *
43884 + * along with this program; if not, write to the *
43885 + * Free Software Foundation, Inc., *
43886 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
43887 + * *
43888 + *************************************************************************
43889 +
43890 + Module Name:
43891 + dfs.h
43892 +
43893 + Abstract:
43894 + Support DFS function.
43895 +
43896 + Revision History:
43897 + Who When What
43898 + -------- ---------- ----------------------------------------------
43899 + Fonchi 03-12-2007 created
43900 +*/
43901 +
43902 +#define RADAR_PULSE 1
43903 +#define RADAR_WIDTH 2
43904 +
43905 +#define WIDTH_RD_IDLE 0
43906 +#define WIDTH_RD_CHECK 1
43907 +
43908 +
43909 +VOID BbpRadarDetectionStart(
43910 + IN PRTMP_ADAPTER pAd);
43911 +
43912 +VOID BbpRadarDetectionStop(
43913 + IN PRTMP_ADAPTER pAd);
43914 +
43915 +VOID RadarDetectionStart(
43916 + IN PRTMP_ADAPTER pAd,
43917 + IN BOOLEAN CTS_Protect,
43918 + IN UINT8 CTSPeriod);
43919 +
43920 +VOID RadarDetectionStop(
43921 + IN PRTMP_ADAPTER pAd);
43922 +
43923 +VOID RadarDetectPeriodic(
43924 + IN PRTMP_ADAPTER pAd);
43925 +
43926 +
43927 +BOOLEAN RadarChannelCheck(
43928 + IN PRTMP_ADAPTER pAd,
43929 + IN UCHAR Ch);
43930 +
43931 +ULONG JapRadarType(
43932 + IN PRTMP_ADAPTER pAd);
43933 +
43934 +ULONG RTMPBbpReadRadarDuration(
43935 + IN PRTMP_ADAPTER pAd);
43936 +
43937 +ULONG RTMPReadRadarDuration(
43938 + IN PRTMP_ADAPTER pAd);
43939 +
43940 +VOID RTMPCleanRadarDuration(
43941 + IN PRTMP_ADAPTER pAd);
43942 +
43943 +VOID RTMPPrepareRDCTSFrame(
43944 + IN PRTMP_ADAPTER pAd,
43945 + IN PUCHAR pDA,
43946 + IN ULONG Duration,
43947 + IN UCHAR RTSRate,
43948 + IN ULONG CTSBaseAddr,
43949 + IN UCHAR FrameGap);
43950 +
43951 +VOID RTMPPrepareRadarDetectParams(
43952 + IN PRTMP_ADAPTER pAd);
43953 +
43954 +
43955 +INT Set_ChMovingTime_Proc(
43956 + IN PRTMP_ADAPTER pAd,
43957 + IN PUCHAR arg);
43958 +
43959 +INT Set_LongPulseRadarTh_Proc(
43960 + IN PRTMP_ADAPTER pAd,
43961 + IN PUCHAR arg);
43962 +
43963 +
43964 --- /dev/null
43965 +++ b/drivers/staging/rt2870/Kconfig
43966 @@ -0,0 +1,6 @@
43967 +config RT2870
43968 + tristate "Ralink 2870 wireless support"
43969 + depends on USB && X86 && WLAN_80211
43970 + ---help---
43971 + This is an experimental driver for the Ralink 2870 wireless chip.
43972 +
43973 --- /dev/null
43974 +++ b/drivers/staging/rt2870/leap.h
43975 @@ -0,0 +1,215 @@
43976 +/*
43977 + *************************************************************************
43978 + * Ralink Tech Inc.
43979 + * 5F., No.36, Taiyuan St., Jhubei City,
43980 + * Hsinchu County 302,
43981 + * Taiwan, R.O.C.
43982 + *
43983 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
43984 + *
43985 + * This program is free software; you can redistribute it and/or modify *
43986 + * it under the terms of the GNU General Public License as published by *
43987 + * the Free Software Foundation; either version 2 of the License, or *
43988 + * (at your option) any later version. *
43989 + * *
43990 + * This program is distributed in the hope that it will be useful, *
43991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
43992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
43993 + * GNU General Public License for more details. *
43994 + * *
43995 + * You should have received a copy of the GNU General Public License *
43996 + * along with this program; if not, write to the *
43997 + * Free Software Foundation, Inc., *
43998 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
43999 + * *
44000 + *************************************************************************
44001 +
44002 + Module Name:
44003 + leap.h
44004 +
44005 + Abstract:
44006 +
44007 + Revision History:
44008 + Who When What
44009 + -------- ---------- ----------------------------------------------
44010 + Name Date Modification logs
44011 +*/
44012 +#ifndef __LEAP_H__
44013 +#define __LEAP_H__
44014 +
44015 +// Messages for Associate state machine
44016 +#define LEAP_MACHINE_BASE 30
44017 +
44018 +#define LEAP_MSG_REQUEST_IDENTITY 31
44019 +#define LEAP_MSG_REQUEST_LEAP 32
44020 +#define LEAP_MSG_SUCCESS 33
44021 +#define LEAP_MSG_FAILED 34
44022 +#define LEAP_MSG_RESPONSE_LEAP 35
44023 +#define LEAP_MSG_EAPOLKEY 36
44024 +#define LEAP_MSG_UNKNOWN 37
44025 +#define LEAP_MSG 38
44026 +//! assoc state-machine states
44027 +#define LEAP_IDLE 0
44028 +#define LEAP_WAIT_IDENTITY_REQUEST 1
44029 +#define LEAP_WAIT_CHANLLENGE_REQUEST 2
44030 +#define LEAP_WAIT_SUCCESS 3
44031 +#define LEAP_WAIT_CHANLLENGE_RESPONSE 4
44032 +#define LEAP_WAIT_EAPOLKEY 5
44033 +
44034 +#define LEAP_REASON_INVALID_AUTH 0x01
44035 +#define LEAP_REASON_AUTH_TIMEOUT 0x02
44036 +#define LEAP_REASON_CHALLENGE_FROM_AP_FAILED 0x03
44037 +#define LEAP_REASON_CHALLENGE_TO_AP_FAILED 0x04
44038 +
44039 +#define CISCO_AuthModeLEAP 0x80
44040 +#define CISCO_AuthModeLEAPNone 0x00
44041 +#define LEAP_AUTH_TIMEOUT 30000
44042 +#define LEAP_CHALLENGE_RESPONSE_LENGTH 24
44043 +#define LEAP_CHALLENGE_REQUEST_LENGTH 8
44044 +
44045 +typedef struct _LEAP_EAPOL_HEADER_ {
44046 + UCHAR Version;
44047 + UCHAR Type;
44048 + UCHAR Length[2];
44049 +} LEAP_EAPOL_HEADER, *PLEAP_EAPOL_HEADER;
44050 +
44051 +typedef struct _LEAP_EAPOL_PACKET_ {
44052 + UCHAR Code;
44053 + UCHAR Identifier;
44054 + UCHAR Length[2];
44055 + UCHAR Type;
44056 +} LEAP_EAPOL_PACKET, *PLEAP_EAPOL_PACKET;
44057 +
44058 +typedef struct _LEAP_EAP_CONTENTS_ {
44059 + UCHAR Version;
44060 + UCHAR Reserved;
44061 + UCHAR Length;
44062 +} LEAP_EAP_CONTENTS, *PLEAP_EAP_CONTENTS;
44063 +
44064 +/*** EAPOL key ***/
44065 +typedef struct _EAPOL_KEY_HEADER_ {
44066 + UCHAR Type;
44067 + UCHAR Length[2];
44068 + UCHAR Counter[8];
44069 + UCHAR IV[16];
44070 + UCHAR Index;
44071 + UCHAR Signature[16];
44072 +} EAPOL_KEY_HEADER, *PEAPOL_KEY_HEADER;
44073 +
44074 +BOOLEAN LeapMsgTypeSubst(
44075 + IN UCHAR EAPType,
44076 + OUT ULONG *MsgType);
44077 +
44078 +VOID LeapMachinePerformAction(
44079 + IN PRTMP_ADAPTER pAd,
44080 + IN STATE_MACHINE *S,
44081 + IN MLME_QUEUE_ELEM *Elem);
44082 +
44083 +VOID LeapMacHeaderInit(
44084 + IN PRTMP_ADAPTER pAd,
44085 + IN OUT PHEADER_802_11 pHdr80211,
44086 + IN UCHAR wep,
44087 + IN PUCHAR pAddr3);
44088 +
44089 +VOID LeapStartAction(
44090 + IN PRTMP_ADAPTER pAd,
44091 + IN MLME_QUEUE_ELEM *Elem);
44092 +
44093 +VOID LeapIdentityAction(
44094 + IN PRTMP_ADAPTER pAd,
44095 + IN MLME_QUEUE_ELEM *Elem);
44096 +
44097 +VOID LeapPeerChallengeAction(
44098 + IN PRTMP_ADAPTER pAd,
44099 + IN MLME_QUEUE_ELEM *Elem);
44100 +
44101 +VOID HashPwd(
44102 + IN PUCHAR pwd,
44103 + IN INT pwdlen,
44104 + OUT PUCHAR hash);
44105 +
44106 +VOID PeerChallengeResponse(
44107 + IN PUCHAR szChallenge,
44108 + IN PUCHAR smbPasswd,
44109 + OUT PUCHAR szResponse);
44110 +
44111 +VOID ParityKey(
44112 + OUT PUCHAR szOut,
44113 + IN PUCHAR szIn);
44114 +
44115 +VOID DesKey(
44116 + OUT ULONG k[16][2],
44117 + IN PUCHAR key,
44118 + IN INT decrypt);
44119 +
44120 +VOID Des(
44121 + IN ULONG ks[16][2],
44122 + OUT UCHAR block[8]);
44123 +
44124 +VOID DesEncrypt(
44125 + IN PUCHAR szClear,
44126 + IN PUCHAR szKey,
44127 + OUT PUCHAR szOut);
44128 +
44129 +VOID LeapNetworkChallengeAction(
44130 + IN PRTMP_ADAPTER pAd,
44131 + IN MLME_QUEUE_ELEM *Elem);
44132 +
44133 +VOID LeapNetworkChallengeResponse(
44134 + IN PRTMP_ADAPTER pAd,
44135 + IN MLME_QUEUE_ELEM *Elem);
44136 +
44137 +VOID HashpwdHash(
44138 + IN PUCHAR hash,
44139 + IN PUCHAR hashhash);
44140 +
44141 +VOID ProcessSessionKey(
44142 + OUT PUCHAR SessionKey,
44143 + IN PUCHAR hash2,
44144 + IN PUCHAR ChallengeToRadius,
44145 + IN PUCHAR ChallengeResponseFromRadius,
44146 + IN PUCHAR ChallengeFromRadius,
44147 + IN PUCHAR ChallengeResponseToRadius);
44148 +
44149 +VOID LeapEapolKeyAction(
44150 + IN PRTMP_ADAPTER pAd,
44151 + IN MLME_QUEUE_ELEM *Elem);
44152 +
44153 +VOID RogueApTableInit(
44154 + IN ROGUEAP_TABLE *Tab);
44155 +
44156 +ULONG RogueApTableSearch(
44157 + IN ROGUEAP_TABLE *Tab,
44158 + IN PUCHAR pAddr);
44159 +
44160 +VOID RogueApEntrySet(
44161 + IN PRTMP_ADAPTER pAd,
44162 + OUT ROGUEAP_ENTRY *pRogueAp,
44163 + IN PUCHAR pAddr,
44164 + IN UCHAR FaileCode);
44165 +
44166 +ULONG RogueApTableSetEntry(
44167 + IN PRTMP_ADAPTER pAd,
44168 + OUT ROGUEAP_TABLE *Tab,
44169 + IN PUCHAR pAddr,
44170 + IN UCHAR FaileCode);
44171 +
44172 +VOID RogueApTableDeleteEntry(
44173 + IN OUT ROGUEAP_TABLE *Tab,
44174 + IN PUCHAR pAddr);
44175 +
44176 +VOID LeapAuthTimeout(
44177 + IN PVOID SystemSpecific1,
44178 + IN PVOID FunctionContext,
44179 + IN PVOID SystemSpecific2,
44180 + IN PVOID SystemSpecific3);
44181 +
44182 +VOID LeapSendRogueAPReport(
44183 + IN PRTMP_ADAPTER pAd);
44184 +
44185 +BOOLEAN CCKMAssocRspSanity(
44186 + IN PRTMP_ADAPTER pAd,
44187 + IN VOID *Msg,
44188 + IN ULONG MsgLen);
44189 +
44190 +#endif // __LEAP_H__
44191 --- /dev/null
44192 +++ b/drivers/staging/rt2870/link_list.h
44193 @@ -0,0 +1,134 @@
44194 +/*
44195 + *************************************************************************
44196 + * Ralink Tech Inc.
44197 + * 5F., No.36, Taiyuan St., Jhubei City,
44198 + * Hsinchu County 302,
44199 + * Taiwan, R.O.C.
44200 + *
44201 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44202 + *
44203 + * This program is free software; you can redistribute it and/or modify *
44204 + * it under the terms of the GNU General Public License as published by *
44205 + * the Free Software Foundation; either version 2 of the License, or *
44206 + * (at your option) any later version. *
44207 + * *
44208 + * This program is distributed in the hope that it will be useful, *
44209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44211 + * GNU General Public License for more details. *
44212 + * *
44213 + * You should have received a copy of the GNU General Public License *
44214 + * along with this program; if not, write to the *
44215 + * Free Software Foundation, Inc., *
44216 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44217 + * *
44218 + *************************************************************************
44219 + */
44220 +
44221 +#ifndef __LINK_LIST_H__
44222 +#define __LINK_LIST_H__
44223 +
44224 +typedef struct _LIST_ENTRY
44225 +{
44226 + struct _LIST_ENTRY *pNext;
44227 +} LIST_ENTRY, *PLIST_ENTRY;
44228 +
44229 +typedef struct _LIST_HEADR
44230 +{
44231 + PLIST_ENTRY pHead;
44232 + PLIST_ENTRY pTail;
44233 + UCHAR size;
44234 +} LIST_HEADER, *PLIST_HEADER;
44235 +
44236 +static inline VOID initList(
44237 + IN PLIST_HEADER pList)
44238 +{
44239 + pList->pHead = pList->pTail = NULL;
44240 + pList->size = 0;
44241 + return;
44242 +}
44243 +
44244 +static inline VOID insertTailList(
44245 + IN PLIST_HEADER pList,
44246 + IN PLIST_ENTRY pEntry)
44247 +{
44248 + pEntry->pNext = NULL;
44249 + if (pList->pTail)
44250 + pList->pTail->pNext = pEntry;
44251 + else
44252 + pList->pHead = pEntry;
44253 + pList->pTail = pEntry;
44254 + pList->size++;
44255 +
44256 + return;
44257 +}
44258 +
44259 +static inline PLIST_ENTRY removeHeadList(
44260 + IN PLIST_HEADER pList)
44261 +{
44262 + PLIST_ENTRY pNext;
44263 + PLIST_ENTRY pEntry;
44264 +
44265 + pEntry = pList->pHead;
44266 + if (pList->pHead != NULL)
44267 + {
44268 + pNext = pList->pHead->pNext;
44269 + pList->pHead = pNext;
44270 + if (pNext == NULL)
44271 + pList->pTail = NULL;
44272 + pList->size--;
44273 + }
44274 + return pEntry;
44275 +}
44276 +
44277 +static inline int getListSize(
44278 + IN PLIST_HEADER pList)
44279 +{
44280 + return pList->size;
44281 +}
44282 +
44283 +static inline PLIST_ENTRY delEntryList(
44284 + IN PLIST_HEADER pList,
44285 + IN PLIST_ENTRY pEntry)
44286 +{
44287 + PLIST_ENTRY pCurEntry;
44288 + PLIST_ENTRY pPrvEntry;
44289 +
44290 + if(pList->pHead == NULL)
44291 + return NULL;
44292 +
44293 + if(pEntry == pList->pHead)
44294 + {
44295 + pCurEntry = pList->pHead;
44296 + pList->pHead = pCurEntry->pNext;
44297 +
44298 + if(pList->pHead == NULL)
44299 + pList->pTail = NULL;
44300 +
44301 + pList->size--;
44302 + return pCurEntry;
44303 + }
44304 +
44305 + pPrvEntry = pList->pHead;
44306 + pCurEntry = pPrvEntry->pNext;
44307 + while(pCurEntry != NULL)
44308 + {
44309 + if (pEntry == pCurEntry)
44310 + {
44311 + pPrvEntry->pNext = pCurEntry->pNext;
44312 +
44313 + if(pEntry == pList->pTail)
44314 + pList->pTail = pPrvEntry;
44315 +
44316 + pList->size--;
44317 + break;
44318 + }
44319 + pPrvEntry = pCurEntry;
44320 + pCurEntry = pPrvEntry->pNext;
44321 + }
44322 +
44323 + return pCurEntry;
44324 +}
44325 +
44326 +#endif // ___LINK_LIST_H__ //
44327 +
44328 --- /dev/null
44329 +++ b/drivers/staging/rt2870/Makefile
44330 @@ -0,0 +1,47 @@
44331 +obj-$(CONFIG_RT2870) += rt2870sta.o
44332 +
44333 +# TODO: all of these should be removed
44334 +EXTRA_CFLAGS += -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT
44335 +EXTRA_CFLAGS += -DRT2870
44336 +EXTRA_CFLAGS += -DCONFIG_STA_SUPPORT
44337 +EXTRA_CFLAGS += -DDBG
44338 +EXTRA_CFLAGS += -DDOT11_N_SUPPORT
44339 +EXTRA_CFLAGS += -DWPA_SUPPLICANT_SUPPORT
44340 +EXTRA_CFLAGS += -DNATIVE_WPA_SUPPLICANT_SUPPORT
44341 +
44342 +rt2870sta-objs := \
44343 + common/md5.o \
44344 + common/mlme.o \
44345 + common/rtmp_wep.o \
44346 + common/action.o \
44347 + common/cmm_data.o \
44348 + common/rtmp_init.o \
44349 + common/rtmp_tkip.o \
44350 + common/cmm_sync.o \
44351 + common/eeprom.o \
44352 + common/cmm_sanity.o \
44353 + common/cmm_info.o \
44354 + common/cmm_wpa.o \
44355 + common/dfs.o \
44356 + common/spectrum.o \
44357 + sta/assoc.o \
44358 + sta/aironet.o \
44359 + sta/auth.o \
44360 + sta/auth_rsp.o \
44361 + sta/sync.o \
44362 + sta/sanity.o \
44363 + sta/rtmp_data.o \
44364 + sta/connect.o \
44365 + sta/wpa.o \
44366 + rt_linux.o \
44367 + rt_profile.o \
44368 + rt_main_dev.o \
44369 + sta_ioctl.o \
44370 + common/ba_action.o \
44371 + 2870_main_dev.o \
44372 + common/2870_rtmp_init.o \
44373 + common/rtusb_io.o \
44374 + common/rtusb_bulk.o \
44375 + common/rtusb_data.o \
44376 + common/cmm_data_2870.o
44377 +
44378 --- /dev/null
44379 +++ b/drivers/staging/rt2870/md4.h
44380 @@ -0,0 +1,42 @@
44381 +/*
44382 + *************************************************************************
44383 + * Ralink Tech Inc.
44384 + * 5F., No.36, Taiyuan St., Jhubei City,
44385 + * Hsinchu County 302,
44386 + * Taiwan, R.O.C.
44387 + *
44388 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44389 + *
44390 + * This program is free software; you can redistribute it and/or modify *
44391 + * it under the terms of the GNU General Public License as published by *
44392 + * the Free Software Foundation; either version 2 of the License, or *
44393 + * (at your option) any later version. *
44394 + * *
44395 + * This program is distributed in the hope that it will be useful, *
44396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44398 + * GNU General Public License for more details. *
44399 + * *
44400 + * You should have received a copy of the GNU General Public License *
44401 + * along with this program; if not, write to the *
44402 + * Free Software Foundation, Inc., *
44403 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44404 + * *
44405 + *************************************************************************
44406 + */
44407 +
44408 +#ifndef __MD4_H__
44409 +#define __MD4_H__
44410 +
44411 +/* MD4 context. */
44412 +typedef struct _MD4_CTX_ {
44413 + ULONG state[4]; /* state (ABCD) */
44414 + ULONG count[2]; /* number of bits, modulo 2^64 (lsb first) */
44415 + UCHAR buffer[64]; /* input buffer */
44416 +} MD4_CTX;
44417 +
44418 +VOID MD4Init (MD4_CTX *);
44419 +VOID MD4Update (MD4_CTX *, PUCHAR, UINT);
44420 +VOID MD4Final (UCHAR [16], MD4_CTX *);
44421 +
44422 +#endif //__MD4_H__
44423 \ No newline at end of file
44424 --- /dev/null
44425 +++ b/drivers/staging/rt2870/md5.h
44426 @@ -0,0 +1,107 @@
44427 +/*
44428 + *************************************************************************
44429 + * Ralink Tech Inc.
44430 + * 5F., No.36, Taiyuan St., Jhubei City,
44431 + * Hsinchu County 302,
44432 + * Taiwan, R.O.C.
44433 + *
44434 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44435 + *
44436 + * This program is free software; you can redistribute it and/or modify *
44437 + * it under the terms of the GNU General Public License as published by *
44438 + * the Free Software Foundation; either version 2 of the License, or *
44439 + * (at your option) any later version. *
44440 + * *
44441 + * This program is distributed in the hope that it will be useful, *
44442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44444 + * GNU General Public License for more details. *
44445 + * *
44446 + * You should have received a copy of the GNU General Public License *
44447 + * along with this program; if not, write to the *
44448 + * Free Software Foundation, Inc., *
44449 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44450 + * *
44451 + *************************************************************************
44452 +
44453 + Module Name:
44454 + md5.h
44455 +
44456 + Abstract:
44457 +
44458 + Revision History:
44459 + Who When What
44460 + -------- ---------- ----------------------------------------------
44461 + Name Date Modification logs
44462 + jan 10-28-03 Initial
44463 + Rita 11-23-04 Modify MD5 and SHA-1
44464 +*/
44465 +
44466 +#ifndef uint8
44467 +#define uint8 unsigned char
44468 +#endif
44469 +
44470 +#ifndef uint32
44471 +#define uint32 unsigned long int
44472 +#endif
44473 +
44474 +
44475 +#ifndef __MD5_H__
44476 +#define __MD5_H__
44477 +
44478 +#define MD5_MAC_LEN 16
44479 +
44480 +typedef struct _MD5_CTX {
44481 + UINT32 Buf[4]; // buffers of four states
44482 + UCHAR Input[64]; // input message
44483 + UINT32 LenInBitCount[2]; // length counter for input message, 0 up to 64 bits
44484 +} MD5_CTX;
44485 +
44486 +VOID MD5Init(MD5_CTX *pCtx);
44487 +VOID MD5Update(MD5_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes);
44488 +VOID MD5Final(UCHAR Digest[16], MD5_CTX *pCtx);
44489 +VOID MD5Transform(UINT32 Buf[4], UINT32 Mes[16]);
44490 +
44491 +void md5_mac(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac);
44492 +void hmac_md5(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac);
44493 +
44494 +//
44495 +// SHA context
44496 +//
44497 +typedef struct _SHA_CTX
44498 +{
44499 + UINT32 Buf[5]; // buffers of five states
44500 + UCHAR Input[80]; // input message
44501 + UINT32 LenInBitCount[2]; // length counter for input message, 0 up to 64 bits
44502 +
44503 +} SHA_CTX;
44504 +
44505 +VOID SHAInit(SHA_CTX *pCtx);
44506 +UCHAR SHAUpdate(SHA_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes);
44507 +VOID SHAFinal(SHA_CTX *pCtx, UCHAR Digest[20]);
44508 +VOID SHATransform(UINT32 Buf[5], UINT32 Mes[20]);
44509 +
44510 +#define SHA_DIGEST_LEN 20
44511 +#endif // __MD5_H__
44512 +
44513 +/******************************************************************************/
44514 +#ifndef _AES_H
44515 +#define _AES_H
44516 +
44517 +typedef struct
44518 +{
44519 + uint32 erk[64]; /* encryption round keys */
44520 + uint32 drk[64]; /* decryption round keys */
44521 + int nr; /* number of rounds */
44522 +}
44523 +aes_context;
44524 +
44525 +int rtmp_aes_set_key( aes_context *ctx, uint8 *key, int nbits );
44526 +void rtmp_aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
44527 +void rtmp_aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
44528 +
44529 +void F(char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output);
44530 +int PasswordHash(char *password, unsigned char *ssid, int ssidlength, unsigned char *output);
44531 +
44532 +#endif /* aes.h */
44533 +
44534 --- /dev/null
44535 +++ b/drivers/staging/rt2870/mlme.h
44536 @@ -0,0 +1,1471 @@
44537 +/*
44538 + *************************************************************************
44539 + * Ralink Tech Inc.
44540 + * 5F., No.36, Taiyuan St., Jhubei City,
44541 + * Hsinchu County 302,
44542 + * Taiwan, R.O.C.
44543 + *
44544 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44545 + *
44546 + * This program is free software; you can redistribute it and/or modify *
44547 + * it under the terms of the GNU General Public License as published by *
44548 + * the Free Software Foundation; either version 2 of the License, or *
44549 + * (at your option) any later version. *
44550 + * *
44551 + * This program is distributed in the hope that it will be useful, *
44552 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44553 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44554 + * GNU General Public License for more details. *
44555 + * *
44556 + * You should have received a copy of the GNU General Public License *
44557 + * along with this program; if not, write to the *
44558 + * Free Software Foundation, Inc., *
44559 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44560 + * *
44561 + *************************************************************************
44562 +
44563 + Module Name:
44564 + mlme.h
44565 +
44566 + Abstract:
44567 +
44568 + Revision History:
44569 + Who When What
44570 + -------- ---------- ----------------------------------------------
44571 + John Chang 2003-08-28 Created
44572 + John Chang 2004-09-06 modified for RT2600
44573 +
44574 +*/
44575 +#ifndef __MLME_H__
44576 +#define __MLME_H__
44577 +
44578 +//extern UCHAR BROADCAST_ADDR[];
44579 +
44580 +// maximum supported capability information -
44581 +// ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot
44582 +#define SUPPORTED_CAPABILITY_INFO 0x0533
44583 +
44584 +#define END_OF_ARGS -1
44585 +#define LFSR_MASK 0x80000057
44586 +#define MLME_TASK_EXEC_INTV 100/*200*/ //
44587 +#define LEAD_TIME 5
44588 +#define MLME_TASK_EXEC_MULTIPLE 10 /*5*/ // MLME_TASK_EXEC_MULTIPLE * MLME_TASK_EXEC_INTV = 1 sec
44589 +#define REORDER_EXEC_INTV 100 // 0.1 sec
44590 +//#define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
44591 +
44592 +// The definition of Radar detection duration region
44593 +#define CE 0
44594 +#define FCC 1
44595 +#define JAP 2
44596 +#define JAP_W53 3
44597 +#define JAP_W56 4
44598 +#define MAX_RD_REGION 5
44599 +
44600 +#ifdef NDIS51_MINIPORT
44601 +#define BEACON_LOST_TIME 4000 // 2048 msec = 2 sec
44602 +#else
44603 +#define BEACON_LOST_TIME 4 * OS_HZ // 2048 msec = 2 sec
44604 +#endif
44605 +
44606 +#define DLS_TIMEOUT 1200 // unit: msec
44607 +#define AUTH_TIMEOUT 300 // unit: msec
44608 +#define ASSOC_TIMEOUT 300 // unit: msec
44609 +#define JOIN_TIMEOUT 2 * OS_HZ // unit: msec
44610 +#define SHORT_CHANNEL_TIME 90 // unit: msec
44611 +#define MIN_CHANNEL_TIME 110 // unit: msec, for dual band scan
44612 +#define MAX_CHANNEL_TIME 140 // unit: msec, for single band scan
44613 +#define FAST_ACTIVE_SCAN_TIME 30 // Active scan waiting for probe response time
44614 +#define CW_MIN_IN_BITS 4 // actual CwMin = 2^CW_MIN_IN_BITS - 1
44615 +
44616 +
44617 +#ifdef CONFIG_STA_SUPPORT
44618 +#ifndef CONFIG_AP_SUPPORT
44619 +#define CW_MAX_IN_BITS 10 // actual CwMax = 2^CW_MAX_IN_BITS - 1
44620 +#endif
44621 +#endif // CONFIG_STA_SUPPORT //
44622 +
44623 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
44624 +extern UINT32 CW_MAX_IN_BITS;
44625 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
44626 +
44627 +// Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720).
44628 +// SHould not refer to this constant anymore
44629 +//#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm
44630 +#define RSSI_FOR_MID_TX_POWER -55 // -55 db is considered mid-distance
44631 +#define RSSI_FOR_LOW_TX_POWER -45 // -45 db is considered very short distance and
44632 + // eligible to use a lower TX power
44633 +#define RSSI_FOR_LOWEST_TX_POWER -30
44634 +//#define MID_TX_POWER_DELTA 0 // 0 db from full TX power upon mid-distance to AP
44635 +#define LOW_TX_POWER_DELTA 6 // -3 db from full TX power upon very short distance. 1 grade is 0.5 db
44636 +#define LOWEST_TX_POWER_DELTA 16 // -8 db from full TX power upon shortest distance. 1 grade is 0.5 db
44637 +
44638 +#define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0
44639 +#define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1
44640 +#define RSSI_THRESHOLD_FOR_ROAMING 25
44641 +#define RSSI_DELTA 5
44642 +
44643 +// Channel Quality Indication
44644 +#define CQI_IS_GOOD(cqi) ((cqi) >= 50)
44645 +//#define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50))
44646 +#define CQI_IS_POOR(cqi) (cqi < 50) //(((cqi) >= 5) && ((cqi) < 20))
44647 +#define CQI_IS_BAD(cqi) (cqi < 5)
44648 +#define CQI_IS_DEAD(cqi) (cqi == 0)
44649 +
44650 +// weighting factor to calculate Channel quality, total should be 100%
44651 +#define RSSI_WEIGHTING 50
44652 +#define TX_WEIGHTING 30
44653 +#define RX_WEIGHTING 20
44654 +
44655 +//#define PEER_KEY_NOT_USED 0
44656 +//#define PEER_KEY_64_BIT 64
44657 +//#define PEER_KEY_128_BIT 128
44658 +
44659 +//#define PEER_KEY_64BIT_LEN 8
44660 +//#define PEER_KEY_128BIT_LEN 16
44661 +
44662 +#define BSS_NOT_FOUND 0xFFFFFFFF
44663 +
44664 +
44665 +#ifdef CONFIG_STA_SUPPORT
44666 +#define MAX_LEN_OF_MLME_QUEUE 40 //10
44667 +#endif // CONFIG_STA_SUPPORT //
44668 +
44669 +#define SCAN_PASSIVE 18 // scan with no probe request, only wait beacon and probe response
44670 +#define SCAN_ACTIVE 19 // scan with probe request, and wait beacon and probe response
44671 +#define SCAN_CISCO_PASSIVE 20 // Single channel passive scan
44672 +#define SCAN_CISCO_ACTIVE 21 // Single channel active scan
44673 +#define SCAN_CISCO_NOISE 22 // Single channel passive scan for noise histogram collection
44674 +#define SCAN_CISCO_CHANNEL_LOAD 23 // Single channel passive scan for channel load collection
44675 +#define FAST_SCAN_ACTIVE 24 // scan with probe request, and wait beacon and probe response
44676 +
44677 +#ifdef DOT11N_DRAFT3
44678 +#define SCAN_2040_BSS_COEXIST 26
44679 +#endif // DOT11N_DRAFT3 //
44680 +
44681 +//#define BSS_TABLE_EMPTY(x) ((x).BssNr == 0)
44682 +#define MAC_ADDR_IS_GROUP(Addr) (((Addr[0]) & 0x01))
44683 +#define MAC_ADDR_HASH(Addr) (Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
44684 +#define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
44685 +#define TID_MAC_HASH(Addr,TID) (TID^Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
44686 +#define TID_MAC_HASH_INDEX(Addr,TID) (TID_MAC_HASH(Addr,TID) % HASH_TABLE_SIZE)
44687 +
44688 +// LED Control
44689 +// assoiation ON. one LED ON. another blinking when TX, OFF when idle
44690 +// no association, both LED off
44691 +#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46)
44692 +#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46)
44693 +
44694 +// bit definition of the 2-byte pBEACON->Capability field
44695 +#define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0)
44696 +#define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0)
44697 +#define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0)
44698 +#define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0)
44699 +#define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0)
44700 +#define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0)
44701 +#define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0)
44702 +#define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0)
44703 +#define CAP_IS_SPECTRUM_MGMT(x) (((x) & 0x0100) != 0) // 802.11e d9
44704 +#define CAP_IS_QOS(x) (((x) & 0x0200) != 0) // 802.11e d9
44705 +#define CAP_IS_SHORT_SLOT(x) (((x) & 0x0400) != 0)
44706 +#define CAP_IS_APSD(x) (((x) & 0x0800) != 0) // 802.11e d9
44707 +#define CAP_IS_IMMED_BA(x) (((x) & 0x1000) != 0) // 802.11e d9
44708 +#define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0)
44709 +#define CAP_IS_DELAY_BA(x) (((x) & 0x4000) != 0) // 802.11e d9
44710 +
44711 +#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))
44712 +
44713 +//#define STA_QOS_CAPABILITY 0 // 1-byte. see 802.11e d9.0 for bit definition
44714 +
44715 +#define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) // 802.11g
44716 +#define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) // 802.11g
44717 +#define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) // 802.11g
44718 +
44719 +#define DRS_TX_QUALITY_WORST_BOUND 8// 3 // just test by gary
44720 +#define DRS_PENALTY 8
44721 +
44722 +#define BA_NOTUSE 2
44723 +//BA Policy subfiled value in ADDBA frame
44724 +#define IMMED_BA 1
44725 +#define DELAY_BA 0
44726 +
44727 +// BA Initiator subfield in DELBA frame
44728 +#define ORIGINATOR 1
44729 +#define RECIPIENT 0
44730 +
44731 +// ADDBA Status Code
44732 +#define ADDBA_RESULTCODE_SUCCESS 0
44733 +#define ADDBA_RESULTCODE_REFUSED 37
44734 +#define ADDBA_RESULTCODE_INVALID_PARAMETERS 38
44735 +
44736 +// DELBA Reason Code
44737 +#define DELBA_REASONCODE_QSTA_LEAVING 36
44738 +#define DELBA_REASONCODE_END_BA 37
44739 +#define DELBA_REASONCODE_UNKNOWN_BA 38
44740 +#define DELBA_REASONCODE_TIMEOUT 39
44741 +
44742 +// reset all OneSecTx counters
44743 +#define RESET_ONE_SEC_TX_CNT(__pEntry) \
44744 +if (((__pEntry)) != NULL) \
44745 +{ \
44746 + (__pEntry)->OneSecTxRetryOkCount = 0; \
44747 + (__pEntry)->OneSecTxFailCount = 0; \
44748 + (__pEntry)->OneSecTxNoRetryOkCount = 0; \
44749 +}
44750 +
44751 +//
44752 +// 802.11 frame formats
44753 +//
44754 +// HT Capability INFO field in HT Cap IE .
44755 +typedef struct PACKED {
44756 +#ifdef RT_BIG_ENDIAN
44757 + USHORT LSIGTxopProSup:1;
44758 + USHORT Forty_Mhz_Intolerant:1;
44759 + USHORT PSMP:1;
44760 + USHORT CCKmodein40:1;
44761 + USHORT AMsduSize:1;
44762 + USHORT DelayedBA:1; //rt2860c not support
44763 + USHORT RxSTBC:2;
44764 + USHORT TxSTBC:1;
44765 + USHORT ShortGIfor40:1; //for40MHz
44766 + USHORT ShortGIfor20:1;
44767 + USHORT GF:1; //green field
44768 + USHORT MimoPs:2;//momi power safe
44769 + USHORT ChannelWidth:1;
44770 + USHORT AdvCoding:1;
44771 +#else
44772 + USHORT AdvCoding:1;
44773 + USHORT ChannelWidth:1;
44774 + USHORT MimoPs:2;//momi power safe
44775 + USHORT GF:1; //green field
44776 + USHORT ShortGIfor20:1;
44777 + USHORT ShortGIfor40:1; //for40MHz
44778 + USHORT TxSTBC:1;
44779 + USHORT RxSTBC:2;
44780 + USHORT DelayedBA:1; //rt2860c not support
44781 + USHORT AMsduSize:1; // only support as zero
44782 + USHORT CCKmodein40:1;
44783 + USHORT PSMP:1;
44784 + USHORT Forty_Mhz_Intolerant:1;
44785 + USHORT LSIGTxopProSup:1;
44786 +#endif /* !RT_BIG_ENDIAN */
44787 +} HT_CAP_INFO, *PHT_CAP_INFO;
44788 +
44789 +// HT Capability INFO field in HT Cap IE .
44790 +typedef struct PACKED {
44791 +#ifdef RT_BIG_ENDIAN
44792 + UCHAR rsv:3;//momi power safe
44793 + UCHAR MpduDensity:3;
44794 + UCHAR MaxRAmpduFactor:2;
44795 +#else
44796 + UCHAR MaxRAmpduFactor:2;
44797 + UCHAR MpduDensity:3;
44798 + UCHAR rsv:3;//momi power safe
44799 +#endif /* !RT_BIG_ENDIAN */
44800 +} HT_CAP_PARM, *PHT_CAP_PARM;
44801 +
44802 +// HT Capability INFO field in HT Cap IE .
44803 +typedef struct PACKED {
44804 + UCHAR MCSSet[10];
44805 + UCHAR SupRate[2]; // unit : 1Mbps
44806 +#ifdef RT_BIG_ENDIAN
44807 + UCHAR rsv:3;
44808 + UCHAR MpduDensity:1;
44809 + UCHAR TxStream:2;
44810 + UCHAR TxRxNotEqual:1;
44811 + UCHAR TxMCSSetDefined:1;
44812 +#else
44813 + UCHAR TxMCSSetDefined:1;
44814 + UCHAR TxRxNotEqual:1;
44815 + UCHAR TxStream:2;
44816 + UCHAR MpduDensity:1;
44817 + UCHAR rsv:3;
44818 +#endif // RT_BIG_ENDIAN //
44819 + UCHAR rsv3[3];
44820 +} HT_MCS_SET, *PHT_MCS_SET;
44821 +
44822 +// HT Capability INFO field in HT Cap IE .
44823 +typedef struct PACKED {
44824 +#ifdef RT_BIG_ENDIAN
44825 + USHORT rsv2:4;
44826 + USHORT RDGSupport:1; //reverse Direction Grant support
44827 + USHORT PlusHTC:1; //+HTC control field support
44828 + USHORT MCSFeedback:2; //0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv.
44829 + USHORT rsv:5;//momi power safe
44830 + USHORT TranTime:2;
44831 + USHORT Pco:1;
44832 +#else
44833 + USHORT Pco:1;
44834 + USHORT TranTime:2;
44835 + USHORT rsv:5;//momi power safe
44836 + USHORT MCSFeedback:2; //0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv.
44837 + USHORT PlusHTC:1; //+HTC control field support
44838 + USHORT RDGSupport:1; //reverse Direction Grant support
44839 + USHORT rsv2:4;
44840 +#endif /* RT_BIG_ENDIAN */
44841 +} EXT_HT_CAP_INFO, *PEXT_HT_CAP_INFO;
44842 +
44843 +// HT Beamforming field in HT Cap IE .
44844 +typedef struct PACKED _HT_BF_CAP{
44845 +#ifdef RT_BIG_ENDIAN
44846 + ULONG rsv:3;
44847 + ULONG ChanEstimation:2;
44848 + ULONG CSIRowBFSup:2;
44849 + ULONG ComSteerBFAntSup:2;
44850 + ULONG NoComSteerBFAntSup:2;
44851 + ULONG CSIBFAntSup:2;
44852 + ULONG MinGrouping:2;
44853 + ULONG ExpComBF:2;
44854 + ULONG ExpNoComBF:2;
44855 + ULONG ExpCSIFbk:2;
44856 + ULONG ExpComSteerCapable:1;
44857 + ULONG ExpNoComSteerCapable:1;
44858 + ULONG ExpCSICapable:1;
44859 + ULONG Calibration:2;
44860 + ULONG ImpTxBFCapable:1;
44861 + ULONG TxNDPCapable:1;
44862 + ULONG RxNDPCapable:1;
44863 + ULONG TxSoundCapable:1;
44864 + ULONG RxSoundCapable:1;
44865 + ULONG TxBFRecCapable:1;
44866 +#else
44867 + ULONG TxBFRecCapable:1;
44868 + ULONG RxSoundCapable:1;
44869 + ULONG TxSoundCapable:1;
44870 + ULONG RxNDPCapable:1;
44871 + ULONG TxNDPCapable:1;
44872 + ULONG ImpTxBFCapable:1;
44873 + ULONG Calibration:2;
44874 + ULONG ExpCSICapable:1;
44875 + ULONG ExpNoComSteerCapable:1;
44876 + ULONG ExpComSteerCapable:1;
44877 + ULONG ExpCSIFbk:2;
44878 + ULONG ExpNoComBF:2;
44879 + ULONG ExpComBF:2;
44880 + ULONG MinGrouping:2;
44881 + ULONG CSIBFAntSup:2;
44882 + ULONG NoComSteerBFAntSup:2;
44883 + ULONG ComSteerBFAntSup:2;
44884 + ULONG CSIRowBFSup:2;
44885 + ULONG ChanEstimation:2;
44886 + ULONG rsv:3;
44887 +#endif // RT_BIG_ENDIAN //
44888 +} HT_BF_CAP, *PHT_BF_CAP;
44889 +
44890 +// HT antenna selection field in HT Cap IE .
44891 +typedef struct PACKED _HT_AS_CAP{
44892 +#ifdef RT_BIG_ENDIAN
44893 + UCHAR rsv:1;
44894 + UCHAR TxSoundPPDU:1;
44895 + UCHAR RxASel:1;
44896 + UCHAR AntIndFbk:1;
44897 + UCHAR ExpCSIFbk:1;
44898 + UCHAR AntIndFbkTxASEL:1;
44899 + UCHAR ExpCSIFbkTxASEL:1;
44900 + UCHAR AntSelect:1;
44901 +#else
44902 + UCHAR AntSelect:1;
44903 + UCHAR ExpCSIFbkTxASEL:1;
44904 + UCHAR AntIndFbkTxASEL:1;
44905 + UCHAR ExpCSIFbk:1;
44906 + UCHAR AntIndFbk:1;
44907 + UCHAR RxASel:1;
44908 + UCHAR TxSoundPPDU:1;
44909 + UCHAR rsv:1;
44910 +#endif // RT_BIG_ENDIAN //
44911 +} HT_AS_CAP, *PHT_AS_CAP;
44912 +
44913 +// Draft 1.0 set IE length 26, but is extensible..
44914 +#define SIZE_HT_CAP_IE 26
44915 +// The structure for HT Capability IE.
44916 +typedef struct PACKED _HT_CAPABILITY_IE{
44917 + HT_CAP_INFO HtCapInfo;
44918 + HT_CAP_PARM HtCapParm;
44919 +// HT_MCS_SET HtMCSSet;
44920 + UCHAR MCSSet[16];
44921 + EXT_HT_CAP_INFO ExtHtCapInfo;
44922 + HT_BF_CAP TxBFCap; // beamforming cap. rt2860c not support beamforming.
44923 + HT_AS_CAP ASCap; //antenna selection.
44924 +} HT_CAPABILITY_IE, *PHT_CAPABILITY_IE;
44925 +
44926 +
44927 +// 802.11n draft3 related structure definitions.
44928 +// 7.3.2.60
44929 +#define dot11OBSSScanPassiveDwell 20 // in TU. min amount of time that the STA continously scans each channel when performing an active OBSS scan.
44930 +#define dot11OBSSScanActiveDwell 10 // in TU.min amount of time that the STA continously scans each channel when performing an passive OBSS scan.
44931 +#define dot11BSSWidthTriggerScanInterval 300 // in sec. max interval between scan operations to be performed to detect BSS channel width trigger events.
44932 +#define dot11OBSSScanPassiveTotalPerChannel 200 // in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan.
44933 +#define dot11OBSSScanActiveTotalPerChannel 20 //in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan
44934 +#define dot11BSSWidthChannelTransactionDelayFactor 5 // min ratio between the delay time in performing a switch from 20MHz BSS to 20/40 BSS operation and the maxima
44935 + // interval between overlapping BSS scan operations.
44936 +#define dot11BSSScanActivityThreshold 25 // in %%, max total time that a STA may be active on the medium during a period of
44937 + // (dot11BSSWidthChannelTransactionDelayFactor * dot11BSSWidthTriggerScanInterval) seconds without
44938 + // being obligated to perform OBSS Scan operations. default is 25(== 0.25%)
44939 +
44940 +typedef struct PACKED _OVERLAP_BSS_SCAN_IE{
44941 + USHORT ScanPassiveDwell;
44942 + USHORT ScanActiveDwell;
44943 + USHORT TriggerScanInt; // Trigger scan interval
44944 + USHORT PassiveTalPerChannel; // passive total per channel
44945 + USHORT ActiveTalPerChannel; // active total per channel
44946 + USHORT DelayFactor; // BSS width channel transition delay factor
44947 + USHORT ScanActThre; // Scan Activity threshold
44948 +}OVERLAP_BSS_SCAN_IE, *POVERLAP_BSS_SCAN_IE;
44949 +
44950 +
44951 +// 7.3.2.56. 20/40 Coexistence element used in Element ID = 72 = IE_2040_BSS_COEXIST
44952 +typedef union PACKED _BSS_2040_COEXIST_IE{
44953 + struct PACKED {
44954 + #ifdef RT_BIG_ENDIAN
44955 + UCHAR rsv:5;
44956 + UCHAR BSS20WidthReq:1;
44957 + UCHAR Intolerant40:1;
44958 + UCHAR InfoReq:1;
44959 + #else
44960 + UCHAR InfoReq:1;
44961 + UCHAR Intolerant40:1; // Inter-BSS. set 1 when prohibits a receiving BSS from operating as a 20/40 Mhz BSS.
44962 + UCHAR BSS20WidthReq:1; // Intra-BSS set 1 when prohibits a receiving AP from operating its BSS as a 20/40MHz BSS.
44963 + UCHAR rsv:5;
44964 +#endif // RT_BIG_ENDIAN //
44965 + } field;
44966 + UCHAR word;
44967 +} BSS_2040_COEXIST_IE, *PBSS_2040_COEXIST_IE;
44968 +
44969 +
44970 +typedef struct _TRIGGER_EVENTA{
44971 + BOOLEAN bValid;
44972 + UCHAR BSSID[6];
44973 + UCHAR RegClass; // Regulatory Class
44974 + USHORT Channel;
44975 + ULONG CDCounter; // Maintain a seperate count down counter for each Event A.
44976 +} TRIGGER_EVENTA, *PTRIGGER_EVENTA;
44977 +
44978 +// 20/40 trigger event table
44979 +// If one Event A delete or created, or if Event B is detected or not detected, STA should send 2040BSSCoexistence to AP.
44980 +#define MAX_TRIGGER_EVENT 64
44981 +typedef struct _TRIGGER_EVENT_TAB{
44982 + UCHAR EventANo;
44983 + TRIGGER_EVENTA EventA[MAX_TRIGGER_EVENT];
44984 + ULONG EventBCountDown; // Count down counter for Event B.
44985 +} TRIGGER_EVENT_TAB, *PTRIGGER_EVENT_TAB;
44986 +
44987 +// 7.3.27 20/40 Bss Coexistence Mgmt capability used in extended capabilities information IE( ID = 127 = IE_EXT_CAPABILITY).
44988 +// This is the first octet and was defined in 802.11n D3.03 and 802.11yD9.0
44989 +typedef struct PACKED _EXT_CAP_INFO_ELEMENT{
44990 +#ifdef RT_BIG_ENDIAN
44991 + UCHAR rsv2:5;
44992 + UCHAR ExtendChannelSwitch:1;
44993 + UCHAR rsv:1;
44994 + UCHAR BssCoexistMgmtSupport:1;
44995 +#else
44996 + UCHAR BssCoexistMgmtSupport:1;
44997 + UCHAR rsv:1;
44998 + UCHAR ExtendChannelSwitch:1;
44999 + UCHAR rsv2:5;
45000 +#endif // RT_BIG_ENDIAN //
45001 +}EXT_CAP_INFO_ELEMENT, *PEXT_CAP_INFO_ELEMENT;
45002 +
45003 +
45004 +// 802.11n 7.3.2.61
45005 +typedef struct PACKED _BSS_2040_COEXIST_ELEMENT{
45006 + UCHAR ElementID; // ID = IE_2040_BSS_COEXIST = 72
45007 + UCHAR Len;
45008 + BSS_2040_COEXIST_IE BssCoexistIe;
45009 +}BSS_2040_COEXIST_ELEMENT, *PBSS_2040_COEXIST_ELEMENT;
45010 +
45011 +
45012 +//802.11n 7.3.2.59
45013 +typedef struct PACKED _BSS_2040_INTOLERANT_CH_REPORT{
45014 + UCHAR ElementID; // ID = IE_2040_BSS_INTOLERANT_REPORT = 73
45015 + UCHAR Len;
45016 + UCHAR RegulatoryClass;
45017 + UCHAR ChList[0];
45018 +}BSS_2040_INTOLERANT_CH_REPORT, *PBSS_2040_INTOLERANT_CH_REPORT;
45019 +
45020 +
45021 +// The structure for channel switch annoucement IE. This is in 802.11n D3.03
45022 +typedef struct PACKED _CHA_SWITCH_ANNOUNCE_IE{
45023 + UCHAR SwitchMode; //channel switch mode
45024 + UCHAR NewChannel; //
45025 + UCHAR SwitchCount; //
45026 +} CHA_SWITCH_ANNOUNCE_IE, *PCHA_SWITCH_ANNOUNCE_IE;
45027 +
45028 +
45029 +// The structure for channel switch annoucement IE. This is in 802.11n D3.03
45030 +typedef struct PACKED _SEC_CHA_OFFSET_IE{
45031 + UCHAR SecondaryChannelOffset; // 1: Secondary above, 3: Secondary below, 0: no Secondary
45032 +} SEC_CHA_OFFSET_IE, *PSEC_CHA_OFFSET_IE;
45033 +
45034 +
45035 +// This structure is extracted from struct RT_HT_CAPABILITY
45036 +typedef struct {
45037 + BOOLEAN bHtEnable; // If we should use ht rate.
45038 + BOOLEAN bPreNHt; // If we should use ht rate.
45039 + //Substract from HT Capability IE
45040 + UCHAR MCSSet[16]; //only supoort MCS=0-15,32 ,
45041 +} RT_HT_PHY_INFO, *PRT_HT_PHY_INFO;
45042 +
45043 +//This structure substracts ralink supports from all 802.11n-related features.
45044 +//Features not listed here but contained in 802.11n spec are not supported in rt2860.
45045 +typedef struct {
45046 +#if 0 // move to
45047 + BOOLEAN bHtEnable; // If we should use ht rate.
45048 + BOOLEAN bPreNHt; // If we should use ht rate.
45049 + //Substract from HT Capability IE
45050 + UCHAR MCSSet[16]; //only supoort MCS=0-15,32 ,
45051 +#endif
45052 +#ifdef RT_BIG_ENDIAN
45053 + USHORT rsv:5;
45054 + USHORT AmsduSize:1; // Max receiving A-MSDU size
45055 + USHORT AmsduEnable:1; // Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n
45056 + USHORT RxSTBC:2; // 2 bits
45057 + USHORT TxSTBC:1;
45058 + USHORT ShortGIfor40:1; //for40MHz
45059 + USHORT ShortGIfor20:1;
45060 + USHORT GF:1; //green field
45061 + USHORT MimoPs:2;//mimo power safe MMPS_
45062 + USHORT ChannelWidth:1;
45063 +#else
45064 + USHORT ChannelWidth:1;
45065 + USHORT MimoPs:2;//mimo power safe MMPS_
45066 + USHORT GF:1; //green field
45067 + USHORT ShortGIfor20:1;
45068 + USHORT ShortGIfor40:1; //for40MHz
45069 + USHORT TxSTBC:1;
45070 + USHORT RxSTBC:2; // 2 bits
45071 + USHORT AmsduEnable:1; // Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n
45072 + USHORT AmsduSize:1; // Max receiving A-MSDU size
45073 + USHORT rsv:5;
45074 +#endif
45075 +
45076 + //Substract from Addiont HT INFO IE
45077 +#ifdef RT_BIG_ENDIAN
45078 + UCHAR RecomWidth:1;
45079 + UCHAR ExtChanOffset:2; // Please not the difference with following UCHAR NewExtChannelOffset; from 802.11n
45080 + UCHAR MpduDensity:3;
45081 + UCHAR MaxRAmpduFactor:2;
45082 +#else
45083 + UCHAR MaxRAmpduFactor:2;
45084 + UCHAR MpduDensity:3;
45085 + UCHAR ExtChanOffset:2; // Please not the difference with following UCHAR NewExtChannelOffset; from 802.11n
45086 + UCHAR RecomWidth:1;
45087 +#endif
45088 +
45089 +#ifdef RT_BIG_ENDIAN
45090 + USHORT rsv2:11;
45091 + USHORT OBSS_NonHTExist:1;
45092 + USHORT rsv3:1;
45093 + USHORT NonGfPresent:1;
45094 + USHORT OperaionMode:2;
45095 +#else
45096 + USHORT OperaionMode:2;
45097 + USHORT NonGfPresent:1;
45098 + USHORT rsv3:1;
45099 + USHORT OBSS_NonHTExist:1;
45100 + USHORT rsv2:11;
45101 +#endif
45102 +
45103 + // New Extension Channel Offset IE
45104 + UCHAR NewExtChannelOffset;
45105 + // Extension Capability IE = 127
45106 + UCHAR BSSCoexist2040;
45107 +} RT_HT_CAPABILITY, *PRT_HT_CAPABILITY;
45108 +
45109 +// field in Addtional HT Information IE .
45110 +typedef struct PACKED {
45111 +#ifdef RT_BIG_ENDIAN
45112 + UCHAR SerInterGranu:3;
45113 + UCHAR S_PSMPSup:1;
45114 + UCHAR RifsMode:1;
45115 + UCHAR RecomWidth:1;
45116 + UCHAR ExtChanOffset:2;
45117 +#else
45118 + UCHAR ExtChanOffset:2;
45119 + UCHAR RecomWidth:1;
45120 + UCHAR RifsMode:1;
45121 + UCHAR S_PSMPSup:1; //Indicate support for scheduled PSMP
45122 + UCHAR SerInterGranu:3; //service interval granularity
45123 +#endif
45124 +} ADD_HTINFO, *PADD_HTINFO;
45125 +
45126 +typedef struct PACKED{
45127 +#ifdef RT_BIG_ENDIAN
45128 + USHORT rsv2:11;
45129 + USHORT OBSS_NonHTExist:1;
45130 + USHORT rsv:1;
45131 + USHORT NonGfPresent:1;
45132 + USHORT OperaionMode:2;
45133 +#else
45134 + USHORT OperaionMode:2;
45135 + USHORT NonGfPresent:1;
45136 + USHORT rsv:1;
45137 + USHORT OBSS_NonHTExist:1;
45138 + USHORT rsv2:11;
45139 +#endif
45140 +} ADD_HTINFO2, *PADD_HTINFO2;
45141 +
45142 +
45143 +// TODO: Need sync with spec about the definition of StbcMcs. In Draft 3.03, it's reserved.
45144 +typedef struct PACKED{
45145 +#ifdef RT_BIG_ENDIAN
45146 + USHORT rsv:4;
45147 + USHORT PcoPhase:1;
45148 + USHORT PcoActive:1;
45149 + USHORT LsigTxopProt:1;
45150 + USHORT STBCBeacon:1;
45151 + USHORT DualCTSProtect:1;
45152 + USHORT DualBeacon:1;
45153 + USHORT StbcMcs:6;
45154 +#else
45155 + USHORT StbcMcs:6;
45156 + USHORT DualBeacon:1;
45157 + USHORT DualCTSProtect:1;
45158 + USHORT STBCBeacon:1;
45159 + USHORT LsigTxopProt:1; // L-SIG TXOP protection full support
45160 + USHORT PcoActive:1;
45161 + USHORT PcoPhase:1;
45162 + USHORT rsv:4;
45163 +#endif // RT_BIG_ENDIAN //
45164 +} ADD_HTINFO3, *PADD_HTINFO3;
45165 +
45166 +#define SIZE_ADD_HT_INFO_IE 22
45167 +typedef struct PACKED{
45168 + UCHAR ControlChan;
45169 + ADD_HTINFO AddHtInfo;
45170 + ADD_HTINFO2 AddHtInfo2;
45171 + ADD_HTINFO3 AddHtInfo3;
45172 + UCHAR MCSSet[16]; // Basic MCS set
45173 +} ADD_HT_INFO_IE, *PADD_HT_INFO_IE;
45174 +
45175 +typedef struct PACKED{
45176 + UCHAR NewExtChanOffset;
45177 +} NEW_EXT_CHAN_IE, *PNEW_EXT_CHAN_IE;
45178 +
45179 +
45180 +// 4-byte HTC field. maybe included in any frame except non-QOS data frame. The Order bit must set 1.
45181 +typedef struct PACKED {
45182 +#ifdef RT_BIG_ENDIAN
45183 + UINT32 RDG:1; //RDG / More PPDU
45184 + UINT32 ACConstraint:1; //feedback request
45185 + UINT32 rsv:5; //calibration sequence
45186 + UINT32 ZLFAnnouce:1; // ZLF announcement
45187 + UINT32 CSISTEERING:2; //CSI/ STEERING
45188 + UINT32 FBKReq:2; //feedback request
45189 + UINT32 CalSeq:2; //calibration sequence
45190 + UINT32 CalPos:2; // calibration position
45191 + UINT32 MFBorASC:7; //Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available
45192 + UINT32 MFS:3; //SET to the received value of MRS. 0x111 for unsolicited MFB.
45193 + UINT32 MRSorASI:3; // MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110.
45194 + UINT32 MRQ:1; //MCS feedback. Request for a MCS feedback
45195 + UINT32 TRQ:1; //sounding request
45196 + UINT32 MA:1; //management action payload exist in (QoS Null+HTC)
45197 +#else
45198 + UINT32 MA:1; //management action payload exist in (QoS Null+HTC)
45199 + UINT32 TRQ:1; //sounding request
45200 + UINT32 MRQ:1; //MCS feedback. Request for a MCS feedback
45201 + UINT32 MRSorASI:3; // MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110.
45202 + UINT32 MFS:3; //SET to the received value of MRS. 0x111 for unsolicited MFB.
45203 + UINT32 MFBorASC:7; //Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available
45204 + UINT32 CalPos:2; // calibration position
45205 + UINT32 CalSeq:2; //calibration sequence
45206 + UINT32 FBKReq:2; //feedback request
45207 + UINT32 CSISTEERING:2; //CSI/ STEERING
45208 + UINT32 ZLFAnnouce:1; // ZLF announcement
45209 + UINT32 rsv:5; //calibration sequence
45210 + UINT32 ACConstraint:1; //feedback request
45211 + UINT32 RDG:1; //RDG / More PPDU
45212 +#endif /* !RT_BIG_ENDIAN */
45213 +} HT_CONTROL, *PHT_CONTROL;
45214 +
45215 +// 2-byte QOS CONTROL field
45216 +typedef struct PACKED {
45217 +#ifdef RT_BIG_ENDIAN
45218 + USHORT Txop_QueueSize:8;
45219 + USHORT AMsduPresent:1;
45220 + USHORT AckPolicy:2; //0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA
45221 + USHORT EOSP:1;
45222 + USHORT TID:4;
45223 +#else
45224 + USHORT TID:4;
45225 + USHORT EOSP:1;
45226 + USHORT AckPolicy:2; //0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA
45227 + USHORT AMsduPresent:1;
45228 + USHORT Txop_QueueSize:8;
45229 +#endif /* !RT_BIG_ENDIAN */
45230 +} QOS_CONTROL, *PQOS_CONTROL;
45231 +
45232 +// 2-byte Frame control field
45233 +typedef struct PACKED {
45234 +#ifdef RT_BIG_ENDIAN
45235 + USHORT Order:1; // Strict order expected
45236 + USHORT Wep:1; // Wep data
45237 + USHORT MoreData:1; // More data bit
45238 + USHORT PwrMgmt:1; // Power management bit
45239 + USHORT Retry:1; // Retry status bit
45240 + USHORT MoreFrag:1; // More fragment bit
45241 + USHORT FrDs:1; // From DS indication
45242 + USHORT ToDs:1; // To DS indication
45243 + USHORT SubType:4; // MSDU subtype
45244 + USHORT Type:2; // MSDU type
45245 + USHORT Ver:2; // Protocol version
45246 +#else
45247 + USHORT Ver:2; // Protocol version
45248 + USHORT Type:2; // MSDU type
45249 + USHORT SubType:4; // MSDU subtype
45250 + USHORT ToDs:1; // To DS indication
45251 + USHORT FrDs:1; // From DS indication
45252 + USHORT MoreFrag:1; // More fragment bit
45253 + USHORT Retry:1; // Retry status bit
45254 + USHORT PwrMgmt:1; // Power management bit
45255 + USHORT MoreData:1; // More data bit
45256 + USHORT Wep:1; // Wep data
45257 + USHORT Order:1; // Strict order expected
45258 +#endif /* !RT_BIG_ENDIAN */
45259 +} FRAME_CONTROL, *PFRAME_CONTROL;
45260 +
45261 +typedef struct PACKED _HEADER_802_11 {
45262 + FRAME_CONTROL FC;
45263 + USHORT Duration;
45264 + UCHAR Addr1[MAC_ADDR_LEN];
45265 + UCHAR Addr2[MAC_ADDR_LEN];
45266 + UCHAR Addr3[MAC_ADDR_LEN];
45267 +#ifdef RT_BIG_ENDIAN
45268 + USHORT Sequence:12;
45269 + USHORT Frag:4;
45270 +#else
45271 + USHORT Frag:4;
45272 + USHORT Sequence:12;
45273 +#endif /* !RT_BIG_ENDIAN */
45274 + UCHAR Octet[0];
45275 +} HEADER_802_11, *PHEADER_802_11;
45276 +
45277 +typedef struct PACKED _FRAME_802_11 {
45278 + HEADER_802_11 Hdr;
45279 + UCHAR Octet[1];
45280 +} FRAME_802_11, *PFRAME_802_11;
45281 +
45282 +// QoSNull embedding of management action. When HT Control MA field set to 1.
45283 +typedef struct PACKED _MA_BODY {
45284 + UCHAR Category;
45285 + UCHAR Action;
45286 + UCHAR Octet[1];
45287 +} MA_BODY, *PMA_BODY;
45288 +
45289 +typedef struct PACKED _HEADER_802_3 {
45290 + UCHAR DAAddr1[MAC_ADDR_LEN];
45291 + UCHAR SAAddr2[MAC_ADDR_LEN];
45292 + UCHAR Octet[2];
45293 +} HEADER_802_3, *PHEADER_802_3;
45294 +////Block ACK related format
45295 +// 2-byte BA Parameter field in DELBA frames to terminate an already set up bA
45296 +typedef struct PACKED{
45297 +#ifdef RT_BIG_ENDIAN
45298 + USHORT TID:4; // value of TC os TS
45299 + USHORT Initiator:1; // 1: originator 0:recipient
45300 + USHORT Rsv:11; // always set to 0
45301 +#else
45302 + USHORT Rsv:11; // always set to 0
45303 + USHORT Initiator:1; // 1: originator 0:recipient
45304 + USHORT TID:4; // value of TC os TS
45305 +#endif /* !RT_BIG_ENDIAN */
45306 +} DELBA_PARM, *PDELBA_PARM;
45307 +
45308 +// 2-byte BA Parameter Set field in ADDBA frames to signal parm for setting up a BA
45309 +typedef struct PACKED {
45310 +#ifdef RT_BIG_ENDIAN
45311 + USHORT BufSize:10; // number of buffe of size 2304 octetsr
45312 + USHORT TID:4; // value of TC os TS
45313 + USHORT BAPolicy:1; // 1: immediately BA 0:delayed BA
45314 + USHORT AMSDUSupported:1; // 0: not permitted 1: permitted
45315 +#else
45316 + USHORT AMSDUSupported:1; // 0: not permitted 1: permitted
45317 + USHORT BAPolicy:1; // 1: immediately BA 0:delayed BA
45318 + USHORT TID:4; // value of TC os TS
45319 + USHORT BufSize:10; // number of buffe of size 2304 octetsr
45320 +#endif /* !RT_BIG_ENDIAN */
45321 +} BA_PARM, *PBA_PARM;
45322 +
45323 +// 2-byte BA Starting Seq CONTROL field
45324 +typedef union PACKED {
45325 + struct PACKED {
45326 +#ifdef RT_BIG_ENDIAN
45327 + USHORT StartSeq:12; // sequence number of the 1st MSDU for which this BAR is sent
45328 + USHORT FragNum:4; // always set to 0
45329 +#else
45330 + USHORT FragNum:4; // always set to 0
45331 + USHORT StartSeq:12; // sequence number of the 1st MSDU for which this BAR is sent
45332 +#endif /* RT_BIG_ENDIAN */
45333 + } field;
45334 + USHORT word;
45335 +} BASEQ_CONTROL, *PBASEQ_CONTROL;
45336 +
45337 +//BAControl and BARControl are the same
45338 +// 2-byte BA CONTROL field in BA frame
45339 +typedef struct PACKED {
45340 +#ifdef RT_BIG_ENDIAN
45341 + USHORT TID:4;
45342 + USHORT Rsv:9;
45343 + USHORT Compressed:1;
45344 + USHORT MTID:1; //EWC V1.24
45345 + USHORT ACKPolicy:1; // only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK
45346 +#else
45347 + USHORT ACKPolicy:1; // only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK
45348 + USHORT MTID:1; //EWC V1.24
45349 + USHORT Compressed:1;
45350 + USHORT Rsv:9;
45351 + USHORT TID:4;
45352 +#endif /* !RT_BIG_ENDIAN */
45353 +} BA_CONTROL, *PBA_CONTROL;
45354 +
45355 +// 2-byte BAR CONTROL field in BAR frame
45356 +typedef struct PACKED {
45357 +#ifdef RT_BIG_ENDIAN
45358 + USHORT TID:4;
45359 + USHORT Rsv1:9;
45360 + USHORT Compressed:1;
45361 + USHORT MTID:1; //if this bit1, use FRAME_MTBA_REQ, if 0, use FRAME_BA_REQ
45362 + USHORT ACKPolicy:1;
45363 +#else
45364 + USHORT ACKPolicy:1; // 0:normal ack, 1:no ack.
45365 + USHORT MTID:1; //if this bit1, use FRAME_MTBA_REQ, if 0, use FRAME_BA_REQ
45366 + USHORT Compressed:1;
45367 + USHORT Rsv1:9;
45368 + USHORT TID:4;
45369 +#endif /* !RT_BIG_ENDIAN */
45370 +} BAR_CONTROL, *PBAR_CONTROL;
45371 +
45372 +// BARControl in MTBAR frame
45373 +typedef struct PACKED {
45374 +#ifdef RT_BIG_ENDIAN
45375 + USHORT NumTID:4;
45376 + USHORT Rsv1:9;
45377 + USHORT Compressed:1;
45378 + USHORT MTID:1;
45379 + USHORT ACKPolicy:1;
45380 +#else
45381 + USHORT ACKPolicy:1;
45382 + USHORT MTID:1;
45383 + USHORT Compressed:1;
45384 + USHORT Rsv1:9;
45385 + USHORT NumTID:4;
45386 +#endif /* !RT_BIG_ENDIAN */
45387 +} MTBAR_CONTROL, *PMTBAR_CONTROL;
45388 +
45389 +typedef struct PACKED {
45390 +#ifdef RT_BIG_ENDIAN
45391 + USHORT TID:4;
45392 + USHORT Rsv1:12;
45393 +#else
45394 + USHORT Rsv1:12;
45395 + USHORT TID:4;
45396 +#endif /* !RT_BIG_ENDIAN */
45397 +} PER_TID_INFO, *PPER_TID_INFO;
45398 +
45399 +typedef struct {
45400 + PER_TID_INFO PerTID;
45401 + BASEQ_CONTROL BAStartingSeq;
45402 +} EACH_TID, *PEACH_TID;
45403 +
45404 +
45405 +typedef struct PACKED _PSPOLL_FRAME {
45406 + FRAME_CONTROL FC;
45407 + USHORT Aid;
45408 + UCHAR Bssid[MAC_ADDR_LEN];
45409 + UCHAR Ta[MAC_ADDR_LEN];
45410 +} PSPOLL_FRAME, *PPSPOLL_FRAME;
45411 +
45412 +typedef struct PACKED _RTS_FRAME {
45413 + FRAME_CONTROL FC;
45414 + USHORT Duration;
45415 + UCHAR Addr1[MAC_ADDR_LEN];
45416 + UCHAR Addr2[MAC_ADDR_LEN];
45417 +}RTS_FRAME, *PRTS_FRAME;
45418 +
45419 +// BAREQ AND MTBAREQ have the same subtype BAR, 802.11n BAR use compressed bitmap.
45420 +typedef struct PACKED _FRAME_BA_REQ {
45421 + FRAME_CONTROL FC;
45422 + USHORT Duration;
45423 + UCHAR Addr1[MAC_ADDR_LEN];
45424 + UCHAR Addr2[MAC_ADDR_LEN];
45425 + BAR_CONTROL BARControl;
45426 + BASEQ_CONTROL BAStartingSeq;
45427 +} FRAME_BA_REQ, *PFRAME_BA_REQ;
45428 +
45429 +typedef struct PACKED _FRAME_MTBA_REQ {
45430 + FRAME_CONTROL FC;
45431 + USHORT Duration;
45432 + UCHAR Addr1[MAC_ADDR_LEN];
45433 + UCHAR Addr2[MAC_ADDR_LEN];
45434 + MTBAR_CONTROL MTBARControl;
45435 + PER_TID_INFO PerTIDInfo;
45436 + BASEQ_CONTROL BAStartingSeq;
45437 +} FRAME_MTBA_REQ, *PFRAME_MTBA_REQ;
45438 +
45439 +// Compressed format is mandantory in HT STA
45440 +typedef struct PACKED _FRAME_MTBA {
45441 + FRAME_CONTROL FC;
45442 + USHORT Duration;
45443 + UCHAR Addr1[MAC_ADDR_LEN];
45444 + UCHAR Addr2[MAC_ADDR_LEN];
45445 + BA_CONTROL BAControl;
45446 + BASEQ_CONTROL BAStartingSeq;
45447 + UCHAR BitMap[8];
45448 +} FRAME_MTBA, *PFRAME_MTBA;
45449 +
45450 +typedef struct PACKED _FRAME_PSMP_ACTION {
45451 + HEADER_802_11 Hdr;
45452 + UCHAR Category;
45453 + UCHAR Action;
45454 + UCHAR Psmp; // 7.3.1.25
45455 +} FRAME_PSMP_ACTION, *PFRAME_PSMP_ACTION;
45456 +
45457 +typedef struct PACKED _FRAME_ACTION_HDR {
45458 + HEADER_802_11 Hdr;
45459 + UCHAR Category;
45460 + UCHAR Action;
45461 +} FRAME_ACTION_HDR, *PFRAME_ACTION_HDR;
45462 +
45463 +//Action Frame
45464 +//Action Frame Category:Spectrum, Action:Channel Switch. 7.3.2.20
45465 +typedef struct PACKED _CHAN_SWITCH_ANNOUNCE {
45466 + UCHAR ElementID; // ID = IE_CHANNEL_SWITCH_ANNOUNCEMENT = 37
45467 + UCHAR Len;
45468 + CHA_SWITCH_ANNOUNCE_IE CSAnnounceIe;
45469 +} CHAN_SWITCH_ANNOUNCE, *PCHAN_SWITCH_ANNOUNCE;
45470 +
45471 +
45472 +//802.11n : 7.3.2.20a
45473 +typedef struct PACKED _SECOND_CHAN_OFFSET {
45474 + UCHAR ElementID; // ID = IE_SECONDARY_CH_OFFSET = 62
45475 + UCHAR Len;
45476 + SEC_CHA_OFFSET_IE SecChOffsetIe;
45477 +} SECOND_CHAN_OFFSET, *PSECOND_CHAN_OFFSET;
45478 +
45479 +
45480 +typedef struct PACKED _FRAME_SPETRUM_CS {
45481 + HEADER_802_11 Hdr;
45482 + UCHAR Category;
45483 + UCHAR Action;
45484 + CHAN_SWITCH_ANNOUNCE CSAnnounce;
45485 + SECOND_CHAN_OFFSET SecondChannel;
45486 +} FRAME_SPETRUM_CS, *PFRAME_SPETRUM_CS;
45487 +
45488 +
45489 +typedef struct PACKED _FRAME_ADDBA_REQ {
45490 + HEADER_802_11 Hdr;
45491 + UCHAR Category;
45492 + UCHAR Action;
45493 + UCHAR Token; // 1
45494 + BA_PARM BaParm; // 2 - 10
45495 + USHORT TimeOutValue; // 0 - 0
45496 + BASEQ_CONTROL BaStartSeq; // 0-0
45497 +} FRAME_ADDBA_REQ, *PFRAME_ADDBA_REQ;
45498 +
45499 +typedef struct PACKED _FRAME_ADDBA_RSP {
45500 + HEADER_802_11 Hdr;
45501 + UCHAR Category;
45502 + UCHAR Action;
45503 + UCHAR Token;
45504 + USHORT StatusCode;
45505 + BA_PARM BaParm; //0 - 2
45506 + USHORT TimeOutValue;
45507 +} FRAME_ADDBA_RSP, *PFRAME_ADDBA_RSP;
45508 +
45509 +typedef struct PACKED _FRAME_DELBA_REQ {
45510 + HEADER_802_11 Hdr;
45511 + UCHAR Category;
45512 + UCHAR Action;
45513 + DELBA_PARM DelbaParm;
45514 + USHORT ReasonCode;
45515 +} FRAME_DELBA_REQ, *PFRAME_DELBA_REQ;
45516 +
45517 +
45518 +//7.2.1.7
45519 +typedef struct PACKED _FRAME_BAR {
45520 + FRAME_CONTROL FC;
45521 + USHORT Duration;
45522 + UCHAR Addr1[MAC_ADDR_LEN];
45523 + UCHAR Addr2[MAC_ADDR_LEN];
45524 + BAR_CONTROL BarControl;
45525 + BASEQ_CONTROL StartingSeq;
45526 +} FRAME_BAR, *PFRAME_BAR;
45527 +
45528 +//7.2.1.7
45529 +typedef struct PACKED _FRAME_BA {
45530 + FRAME_CONTROL FC;
45531 + USHORT Duration;
45532 + UCHAR Addr1[MAC_ADDR_LEN];
45533 + UCHAR Addr2[MAC_ADDR_LEN];
45534 + BAR_CONTROL BarControl;
45535 + BASEQ_CONTROL StartingSeq;
45536 + UCHAR bitmask[8];
45537 +} FRAME_BA, *PFRAME_BA;
45538 +
45539 +
45540 +// Radio Measuement Request Frame Format
45541 +typedef struct PACKED _FRAME_RM_REQ_ACTION {
45542 + HEADER_802_11 Hdr;
45543 + UCHAR Category;
45544 + UCHAR Action;
45545 + UCHAR Token;
45546 + USHORT Repetition;
45547 + UCHAR data[0];
45548 +} FRAME_RM_REQ_ACTION, *PFRAME_RM_REQ_ACTION;
45549 +
45550 +typedef struct PACKED {
45551 + UCHAR ID;
45552 + UCHAR Length;
45553 + UCHAR ChannelSwitchMode;
45554 + UCHAR NewRegClass;
45555 + UCHAR NewChannelNum;
45556 + UCHAR ChannelSwitchCount;
45557 +} HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE, *PHT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE;
45558 +
45559 +
45560 +//
45561 +// _Limit must be the 2**n - 1
45562 +// _SEQ1 , _SEQ2 must be within 0 ~ _Limit
45563 +//
45564 +#define SEQ_STEPONE(_SEQ1, _SEQ2, _Limit) ((_SEQ1 == ((_SEQ2+1) & _Limit)))
45565 +#define SEQ_SMALLER(_SEQ1, _SEQ2, _Limit) (((_SEQ1-_SEQ2) & ((_Limit+1)>>1)))
45566 +#define SEQ_LARGER(_SEQ1, _SEQ2, _Limit) ((_SEQ1 != _SEQ2) && !(((_SEQ1-_SEQ2) & ((_Limit+1)>>1))))
45567 +#define SEQ_WITHIN_WIN(_SEQ1, _SEQ2, _WIN, _Limit) (SEQ_LARGER(_SEQ1, _SEQ2, _Limit) && \
45568 + SEQ_SMALLER(_SEQ1, ((_SEQ2+_WIN+1)&_Limit), _Limit))
45569 +
45570 +//
45571 +// Contention-free parameter (without ID and Length)
45572 +//
45573 +typedef struct PACKED {
45574 + BOOLEAN bValid; // 1: variable contains valid value
45575 + UCHAR CfpCount;
45576 + UCHAR CfpPeriod;
45577 + USHORT CfpMaxDuration;
45578 + USHORT CfpDurRemaining;
45579 +} CF_PARM, *PCF_PARM;
45580 +
45581 +typedef struct _CIPHER_SUITE {
45582 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher 1, this one has more secured cipher suite
45583 + NDIS_802_11_ENCRYPTION_STATUS PairCipherAux; // Unicast cipher 2 if AP announce two unicast cipher suite
45584 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Group cipher
45585 + USHORT RsnCapability; // RSN capability from beacon
45586 + BOOLEAN bMixMode; // Indicate Pair & Group cipher might be different
45587 +} CIPHER_SUITE, *PCIPHER_SUITE;
45588 +
45589 +// EDCA configuration from AP's BEACON/ProbeRsp
45590 +typedef struct {
45591 + BOOLEAN bValid; // 1: variable contains valid value
45592 + BOOLEAN bAdd; // 1: variable contains valid value
45593 + BOOLEAN bQAck;
45594 + BOOLEAN bQueueRequest;
45595 + BOOLEAN bTxopRequest;
45596 + BOOLEAN bAPSDCapable;
45597 +// BOOLEAN bMoreDataAck;
45598 + UCHAR EdcaUpdateCount;
45599 + UCHAR Aifsn[4]; // 0:AC_BK, 1:AC_BE, 2:AC_VI, 3:AC_VO
45600 + UCHAR Cwmin[4];
45601 + UCHAR Cwmax[4];
45602 + USHORT Txop[4]; // in unit of 32-us
45603 + BOOLEAN bACM[4]; // 1: Admission Control of AC_BK is mandattory
45604 +} EDCA_PARM, *PEDCA_PARM;
45605 +
45606 +// QBSS LOAD information from QAP's BEACON/ProbeRsp
45607 +typedef struct {
45608 + BOOLEAN bValid; // 1: variable contains valid value
45609 + USHORT StaNum;
45610 + UCHAR ChannelUtilization;
45611 + USHORT RemainingAdmissionControl; // in unit of 32-us
45612 +} QBSS_LOAD_PARM, *PQBSS_LOAD_PARM;
45613 +
45614 +// QBSS Info field in QSTA's assoc req
45615 +typedef struct PACKED {
45616 +#ifdef RT_BIG_ENDIAN
45617 + UCHAR Rsv2:1;
45618 + UCHAR MaxSPLength:2;
45619 + UCHAR Rsv1:1;
45620 + UCHAR UAPSD_AC_BE:1;
45621 + UCHAR UAPSD_AC_BK:1;
45622 + UCHAR UAPSD_AC_VI:1;
45623 + UCHAR UAPSD_AC_VO:1;
45624 +#else
45625 + UCHAR UAPSD_AC_VO:1;
45626 + UCHAR UAPSD_AC_VI:1;
45627 + UCHAR UAPSD_AC_BK:1;
45628 + UCHAR UAPSD_AC_BE:1;
45629 + UCHAR Rsv1:1;
45630 + UCHAR MaxSPLength:2;
45631 + UCHAR Rsv2:1;
45632 +#endif /* !RT_BIG_ENDIAN */
45633 +} QBSS_STA_INFO_PARM, *PQBSS_STA_INFO_PARM;
45634 +
45635 +// QBSS Info field in QAP's Beacon/ProbeRsp
45636 +typedef struct PACKED {
45637 +#ifdef RT_BIG_ENDIAN
45638 + UCHAR UAPSD:1;
45639 + UCHAR Rsv:3;
45640 + UCHAR ParamSetCount:4;
45641 +#else
45642 + UCHAR ParamSetCount:4;
45643 + UCHAR Rsv:3;
45644 + UCHAR UAPSD:1;
45645 +#endif /* !RT_BIG_ENDIAN */
45646 +} QBSS_AP_INFO_PARM, *PQBSS_AP_INFO_PARM;
45647 +
45648 +// QOS Capability reported in QAP's BEACON/ProbeRsp
45649 +// QOS Capability sent out in QSTA's AssociateReq/ReAssociateReq
45650 +typedef struct {
45651 + BOOLEAN bValid; // 1: variable contains valid value
45652 + BOOLEAN bQAck;
45653 + BOOLEAN bQueueRequest;
45654 + BOOLEAN bTxopRequest;
45655 +// BOOLEAN bMoreDataAck;
45656 + UCHAR EdcaUpdateCount;
45657 +} QOS_CAPABILITY_PARM, *PQOS_CAPABILITY_PARM;
45658 +
45659 +#ifdef CONFIG_STA_SUPPORT
45660 +typedef struct {
45661 + UCHAR IELen;
45662 + UCHAR IE[MAX_CUSTOM_LEN];
45663 +} WPA_IE_;
45664 +#endif // CONFIG_STA_SUPPORT //
45665 +
45666 +
45667 +typedef struct {
45668 + UCHAR Bssid[MAC_ADDR_LEN];
45669 + UCHAR Channel;
45670 + UCHAR CentralChannel; //Store the wide-band central channel for 40MHz. .used in 40MHz AP. Or this is the same as Channel.
45671 + UCHAR BssType;
45672 + USHORT AtimWin;
45673 + USHORT BeaconPeriod;
45674 +
45675 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
45676 + UCHAR SupRateLen;
45677 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
45678 + UCHAR ExtRateLen;
45679 + HT_CAPABILITY_IE HtCapability;
45680 + UCHAR HtCapabilityLen;
45681 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
45682 + UCHAR AddHtInfoLen;
45683 + UCHAR NewExtChanOffset;
45684 + CHAR Rssi;
45685 + UCHAR Privacy; // Indicate security function ON/OFF. Don't mess up with auth mode.
45686 + UCHAR Hidden;
45687 +
45688 + USHORT DtimPeriod;
45689 + USHORT CapabilityInfo;
45690 +
45691 + USHORT CfpCount;
45692 + USHORT CfpPeriod;
45693 + USHORT CfpMaxDuration;
45694 + USHORT CfpDurRemaining;
45695 + UCHAR SsidLen;
45696 + CHAR Ssid[MAX_LEN_OF_SSID];
45697 +
45698 + ULONG LastBeaconRxTime; // OS's timestamp
45699 +
45700 + BOOLEAN bSES;
45701 +
45702 + // New for WPA2
45703 + CIPHER_SUITE WPA; // AP announced WPA cipher suite
45704 + CIPHER_SUITE WPA2; // AP announced WPA2 cipher suite
45705 +
45706 + // New for microsoft WPA support
45707 + NDIS_802_11_FIXED_IEs FixIEs;
45708 + NDIS_802_11_AUTHENTICATION_MODE AuthModeAux; // Addition mode for WPA2 / WPA capable AP
45709 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
45710 + NDIS_802_11_WEP_STATUS WepStatus; // Unicast Encryption Algorithm extract from VAR_IE
45711 + USHORT VarIELen; // Length of next VIE include EID & Length
45712 + UCHAR VarIEs[MAX_VIE_LEN];
45713 +
45714 + // CCX Ckip information
45715 + UCHAR CkipFlag;
45716 +
45717 + // CCX 2 TSF
45718 + UCHAR PTSF[4]; // Parent TSF
45719 + UCHAR TTSF[8]; // Target TSF
45720 +
45721 + // 802.11e d9, and WMM
45722 + EDCA_PARM EdcaParm;
45723 + QOS_CAPABILITY_PARM QosCapability;
45724 + QBSS_LOAD_PARM QbssLoad;
45725 +#ifdef CONFIG_STA_SUPPORT
45726 + WPA_IE_ WpaIE;
45727 + WPA_IE_ RsnIE;
45728 +#ifdef EXT_BUILD_CHANNEL_LIST
45729 + UCHAR CountryString[3];
45730 + BOOLEAN bHasCountryIE;
45731 +#endif // EXT_BUILD_CHANNEL_LIST //
45732 +#endif // CONFIG_STA_SUPPORT //
45733 +} BSS_ENTRY, *PBSS_ENTRY;
45734 +
45735 +typedef struct {
45736 + UCHAR BssNr;
45737 + UCHAR BssOverlapNr;
45738 + BSS_ENTRY BssEntry[MAX_LEN_OF_BSS_TABLE];
45739 +} BSS_TABLE, *PBSS_TABLE;
45740 +
45741 +
45742 +typedef struct _MLME_QUEUE_ELEM {
45743 + ULONG Machine;
45744 + ULONG MsgType;
45745 + ULONG MsgLen;
45746 + UCHAR Msg[MGMT_DMA_BUFFER_SIZE];
45747 + LARGE_INTEGER TimeStamp;
45748 + UCHAR Rssi0;
45749 + UCHAR Rssi1;
45750 + UCHAR Rssi2;
45751 + UCHAR Signal;
45752 + UCHAR Channel;
45753 + UCHAR Wcid;
45754 + BOOLEAN Occupied;
45755 +} MLME_QUEUE_ELEM, *PMLME_QUEUE_ELEM;
45756 +
45757 +typedef struct _MLME_QUEUE {
45758 + ULONG Num;
45759 + ULONG Head;
45760 + ULONG Tail;
45761 + NDIS_SPIN_LOCK Lock;
45762 + MLME_QUEUE_ELEM Entry[MAX_LEN_OF_MLME_QUEUE];
45763 +} MLME_QUEUE, *PMLME_QUEUE;
45764 +
45765 +typedef VOID (*STATE_MACHINE_FUNC)(VOID *Adaptor, MLME_QUEUE_ELEM *Elem);
45766 +
45767 +typedef struct _STATE_MACHINE {
45768 + ULONG Base;
45769 + ULONG NrState;
45770 + ULONG NrMsg;
45771 + ULONG CurrState;
45772 + STATE_MACHINE_FUNC *TransFunc;
45773 +} STATE_MACHINE, *PSTATE_MACHINE;
45774 +
45775 +
45776 +// MLME AUX data structure that hold temporarliy settings during a connection attempt.
45777 +// Once this attemp succeeds, all settings will be copy to pAd->StaActive.
45778 +// A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of
45779 +// several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely
45780 +// separate this under-trial settings away from pAd->StaActive so that once
45781 +// this new attempt failed, driver can auto-recover back to the active settings.
45782 +typedef struct _MLME_AUX {
45783 + UCHAR BssType;
45784 + UCHAR Ssid[MAX_LEN_OF_SSID];
45785 + UCHAR SsidLen;
45786 + UCHAR Bssid[MAC_ADDR_LEN];
45787 + UCHAR AutoReconnectSsid[MAX_LEN_OF_SSID];
45788 + UCHAR AutoReconnectSsidLen;
45789 + USHORT Alg;
45790 + UCHAR ScanType;
45791 + UCHAR Channel;
45792 + UCHAR CentralChannel;
45793 + USHORT Aid;
45794 + USHORT CapabilityInfo;
45795 + USHORT BeaconPeriod;
45796 + USHORT CfpMaxDuration;
45797 + USHORT CfpPeriod;
45798 + USHORT AtimWin;
45799 +
45800 + // Copy supported rate from desired AP's beacon. We are trying to match
45801 + // AP's supported and extended rate settings.
45802 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
45803 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
45804 + UCHAR SupRateLen;
45805 + UCHAR ExtRateLen;
45806 + HT_CAPABILITY_IE HtCapability;
45807 + UCHAR HtCapabilityLen;
45808 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
45809 + UCHAR NewExtChannelOffset;
45810 + //RT_HT_CAPABILITY SupportedHtPhy;
45811 +
45812 + // new for QOS
45813 + QOS_CAPABILITY_PARM APQosCapability; // QOS capability of the current associated AP
45814 + EDCA_PARM APEdcaParm; // EDCA parameters of the current associated AP
45815 + QBSS_LOAD_PARM APQbssLoad; // QBSS load of the current associated AP
45816 +
45817 + // new to keep Ralink specific feature
45818 + ULONG APRalinkIe;
45819 +
45820 + BSS_TABLE SsidBssTab; // AP list for the same SSID
45821 + BSS_TABLE RoamTab; // AP list eligible for roaming
45822 + ULONG BssIdx;
45823 + ULONG RoamIdx;
45824 +
45825 + BOOLEAN CurrReqIsFromNdis;
45826 +
45827 + RALINK_TIMER_STRUCT BeaconTimer, ScanTimer;
45828 + RALINK_TIMER_STRUCT AuthTimer;
45829 + RALINK_TIMER_STRUCT AssocTimer, ReassocTimer, DisassocTimer;
45830 +} MLME_AUX, *PMLME_AUX;
45831 +
45832 +typedef struct _MLME_ADDBA_REQ_STRUCT{
45833 + UCHAR Wcid; //
45834 + UCHAR pAddr[MAC_ADDR_LEN];
45835 + UCHAR BaBufSize;
45836 + USHORT TimeOutValue;
45837 + UCHAR TID;
45838 + UCHAR Token;
45839 + USHORT BaStartSeq;
45840 +} MLME_ADDBA_REQ_STRUCT, *PMLME_ADDBA_REQ_STRUCT;
45841 +
45842 +
45843 +typedef struct _MLME_DELBA_REQ_STRUCT{
45844 + UCHAR Wcid; //
45845 + UCHAR Addr[MAC_ADDR_LEN];
45846 + UCHAR TID;
45847 + UCHAR Initiator;
45848 +} MLME_DELBA_REQ_STRUCT, *PMLME_DELBA_REQ_STRUCT;
45849 +
45850 +// assoc struct is equal to reassoc
45851 +typedef struct _MLME_ASSOC_REQ_STRUCT{
45852 + UCHAR Addr[MAC_ADDR_LEN];
45853 + USHORT CapabilityInfo;
45854 + USHORT ListenIntv;
45855 + ULONG Timeout;
45856 +} MLME_ASSOC_REQ_STRUCT, *PMLME_ASSOC_REQ_STRUCT, MLME_REASSOC_REQ_STRUCT, *PMLME_REASSOC_REQ_STRUCT;
45857 +
45858 +typedef struct _MLME_DISASSOC_REQ_STRUCT{
45859 + UCHAR Addr[MAC_ADDR_LEN];
45860 + USHORT Reason;
45861 +} MLME_DISASSOC_REQ_STRUCT, *PMLME_DISASSOC_REQ_STRUCT;
45862 +
45863 +typedef struct _MLME_AUTH_REQ_STRUCT {
45864 + UCHAR Addr[MAC_ADDR_LEN];
45865 + USHORT Alg;
45866 + ULONG Timeout;
45867 +} MLME_AUTH_REQ_STRUCT, *PMLME_AUTH_REQ_STRUCT;
45868 +
45869 +typedef struct _MLME_DEAUTH_REQ_STRUCT {
45870 + UCHAR Addr[MAC_ADDR_LEN];
45871 + USHORT Reason;
45872 +} MLME_DEAUTH_REQ_STRUCT, *PMLME_DEAUTH_REQ_STRUCT;
45873 +
45874 +typedef struct {
45875 + ULONG BssIdx;
45876 +} MLME_JOIN_REQ_STRUCT;
45877 +
45878 +typedef struct _MLME_SCAN_REQ_STRUCT {
45879 + UCHAR Bssid[MAC_ADDR_LEN];
45880 + UCHAR BssType;
45881 + UCHAR ScanType;
45882 + UCHAR SsidLen;
45883 + CHAR Ssid[MAX_LEN_OF_SSID];
45884 +} MLME_SCAN_REQ_STRUCT, *PMLME_SCAN_REQ_STRUCT;
45885 +
45886 +typedef struct _MLME_START_REQ_STRUCT {
45887 + CHAR Ssid[MAX_LEN_OF_SSID];
45888 + UCHAR SsidLen;
45889 +} MLME_START_REQ_STRUCT, *PMLME_START_REQ_STRUCT;
45890 +
45891 +#ifdef CONFIG_STA_SUPPORT
45892 +#ifdef QOS_DLS_SUPPORT
45893 +// structure for DLS
45894 +typedef struct _RT_802_11_DLS {
45895 + USHORT TimeOut; // Use to time out while slience, unit: second , set by UI
45896 + USHORT CountDownTimer; // Use to time out while slience,unit: second , used by driver only
45897 + NDIS_802_11_MAC_ADDRESS MacAddr; // set by UI
45898 + UCHAR Status; // 0: none , 1: wait STAkey, 2: finish DLS setup , set by driver only
45899 + BOOLEAN Valid; // 1: valid , 0: invalid , set by UI, use to setup or tear down DLS link
45900 + RALINK_TIMER_STRUCT Timer; // Use to time out while handshake
45901 + USHORT Sequence;
45902 + USHORT MacTabMatchWCID; // ASIC
45903 + BOOLEAN bHTCap;
45904 + PVOID pAd;
45905 +} RT_802_11_DLS, *PRT_802_11_DLS;
45906 +
45907 +typedef struct _MLME_DLS_REQ_STRUCT {
45908 + PRT_802_11_DLS pDLS;
45909 + USHORT Reason;
45910 +} MLME_DLS_REQ_STRUCT, *PMLME_DLS_REQ_STRUCT;
45911 +#endif // QOS_DLS_SUPPORT //
45912 +#endif // CONFIG_STA_SUPPORT //
45913 +
45914 +typedef struct PACKED {
45915 + UCHAR Eid;
45916 + UCHAR Len;
45917 + CHAR Octet[1];
45918 +} EID_STRUCT,*PEID_STRUCT, BEACON_EID_STRUCT, *PBEACON_EID_STRUCT;
45919 +
45920 +typedef struct PACKED _RTMP_TX_RATE_SWITCH
45921 +{
45922 + UCHAR ItemNo;
45923 +#ifdef RT_BIG_ENDIAN
45924 + UCHAR Rsv2:2;
45925 + UCHAR Mode:2;
45926 + UCHAR Rsv1:1;
45927 + UCHAR BW:1;
45928 + UCHAR ShortGI:1;
45929 + UCHAR STBC:1;
45930 +#else
45931 + UCHAR STBC:1;
45932 + UCHAR ShortGI:1;
45933 + UCHAR BW:1;
45934 + UCHAR Rsv1:1;
45935 + UCHAR Mode:2;
45936 + UCHAR Rsv2:2;
45937 +#endif
45938 + UCHAR CurrMCS;
45939 + UCHAR TrainUp;
45940 + UCHAR TrainDown;
45941 +} RRTMP_TX_RATE_SWITCH, *PRTMP_TX_RATE_SWITCH;
45942 +
45943 +// ========================== AP mlme.h ===============================
45944 +#define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
45945 +#define DEFAULT_DTIM_PERIOD 1
45946 +
45947 +// weighting factor to calculate Channel quality, total should be 100%
45948 +//#define RSSI_WEIGHTING 0
45949 +//#define TX_WEIGHTING 40
45950 +//#define RX_WEIGHTING 60
45951 +
45952 +#define MAC_TABLE_AGEOUT_TIME 300 // unit: sec
45953 +#define MAC_TABLE_ASSOC_TIMEOUT 5 // unit: sec
45954 +#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE)
45955 +
45956 +// AP shall drop the sta if contine Tx fail count reach it.
45957 +#define MAC_ENTRY_LIFE_CHECK_CNT 20 // packet cnt.
45958 +
45959 +// Value domain of pMacEntry->Sst
45960 +typedef enum _Sst {
45961 + SST_NOT_AUTH, // 0: equivalent to IEEE 802.11/1999 state 1
45962 + SST_AUTH, // 1: equivalent to IEEE 802.11/1999 state 2
45963 + SST_ASSOC // 2: equivalent to IEEE 802.11/1999 state 3
45964 +} SST;
45965 +
45966 +// value domain of pMacEntry->AuthState
45967 +typedef enum _AuthState {
45968 + AS_NOT_AUTH,
45969 + AS_AUTH_OPEN, // STA has been authenticated using OPEN SYSTEM
45970 + AS_AUTH_KEY, // STA has been authenticated using SHARED KEY
45971 + AS_AUTHENTICATING // STA is waiting for AUTH seq#3 using SHARED KEY
45972 +} AUTH_STATE;
45973 +
45974 +//for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
45975 +typedef enum _ApWpaState {
45976 + AS_NOTUSE, // 0
45977 + AS_DISCONNECT, // 1
45978 + AS_DISCONNECTED, // 2
45979 + AS_INITIALIZE, // 3
45980 + AS_AUTHENTICATION, // 4
45981 + AS_AUTHENTICATION2, // 5
45982 + AS_INITPMK, // 6
45983 + AS_INITPSK, // 7
45984 + AS_PTKSTART, // 8
45985 + AS_PTKINIT_NEGOTIATING, // 9
45986 + AS_PTKINITDONE, // 10
45987 + AS_UPDATEKEYS, // 11
45988 + AS_INTEGRITY_FAILURE, // 12
45989 + AS_KEYUPDATE, // 13
45990 +} AP_WPA_STATE;
45991 +
45992 +// for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
45993 +typedef enum _GTKState {
45994 + REKEY_NEGOTIATING,
45995 + REKEY_ESTABLISHED,
45996 + KEYERROR,
45997 +} GTK_STATE;
45998 +
45999 +// for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
46000 +typedef enum _WpaGTKState {
46001 + SETKEYS,
46002 + SETKEYS_DONE,
46003 +} WPA_GTK_STATE;
46004 +// ====================== end of AP mlme.h ============================
46005 +
46006 +
46007 +#endif // MLME_H__
46008 --- /dev/null
46009 +++ b/drivers/staging/rt2870/netif_block.h
46010 @@ -0,0 +1,58 @@
46011 +/*
46012 + *************************************************************************
46013 + * Ralink Tech Inc.
46014 + * 5F., No.36, Taiyuan St., Jhubei City,
46015 + * Hsinchu County 302,
46016 + * Taiwan, R.O.C.
46017 + *
46018 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
46019 + *
46020 + * This program is free software; you can redistribute it and/or modify *
46021 + * it under the terms of the GNU General Public License as published by *
46022 + * the Free Software Foundation; either version 2 of the License, or *
46023 + * (at your option) any later version. *
46024 + * *
46025 + * This program is distributed in the hope that it will be useful, *
46026 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46027 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
46028 + * GNU General Public License for more details. *
46029 + * *
46030 + * You should have received a copy of the GNU General Public License *
46031 + * along with this program; if not, write to the *
46032 + * Free Software Foundation, Inc., *
46033 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
46034 + * *
46035 + *************************************************************************
46036 + */
46037 +
46038 +#ifndef __NET_IF_BLOCK_H__
46039 +#define __NET_IF_BLOCK_H__
46040 +
46041 +//#include <linux/device.h>
46042 +#include "link_list.h"
46043 +#include "rtmp.h"
46044 +
46045 +#define FREE_NETIF_POOL_SIZE 32
46046 +
46047 +typedef struct _NETIF_ENTRY
46048 +{
46049 + struct _NETIF_ENTRY *pNext;
46050 + PNET_DEV pNetDev;
46051 +} NETIF_ENTRY, *PNETIF_ENTRY;
46052 +
46053 +void initblockQueueTab(
46054 + IN PRTMP_ADAPTER pAd);
46055 +
46056 +BOOLEAN blockNetIf(
46057 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry,
46058 + IN PNET_DEV pNetDev);
46059 +
46060 +VOID releaseNetIf(
46061 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry);
46062 +
46063 +VOID StopNetIfQueue(
46064 + IN PRTMP_ADAPTER pAd,
46065 + IN UCHAR QueIdx,
46066 + IN PNDIS_PACKET pPacket);
46067 +#endif // __NET_IF_BLOCK_H__
46068 +
46069 --- /dev/null
46070 +++ b/drivers/staging/rt2870/oid.h
46071 @@ -0,0 +1,1091 @@
46072 +/*
46073 + *************************************************************************
46074 + * Ralink Tech Inc.
46075 + * 5F., No.36, Taiyuan St., Jhubei City,
46076 + * Hsinchu County 302,
46077 + * Taiwan, R.O.C.
46078 + *
46079 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
46080 + *
46081 + * This program is free software; you can redistribute it and/or modify *
46082 + * it under the terms of the GNU General Public License as published by *
46083 + * the Free Software Foundation; either version 2 of the License, or *
46084 + * (at your option) any later version. *
46085 + * *
46086 + * This program is distributed in the hope that it will be useful, *
46087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
46089 + * GNU General Public License for more details. *
46090 + * *
46091 + * You should have received a copy of the GNU General Public License *
46092 + * along with this program; if not, write to the *
46093 + * Free Software Foundation, Inc., *
46094 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
46095 + * *
46096 + *************************************************************************
46097 +
46098 + Module Name:
46099 + oid.h
46100 +
46101 + Abstract:
46102 +
46103 + Revision History:
46104 + Who When What
46105 + -------- ---------- ----------------------------------------------
46106 + Name Date Modification logs
46107 +*/
46108 +#ifndef _OID_H_
46109 +#define _OID_H_
46110 +
46111 +#define TRUE 1
46112 +#define FALSE 0
46113 +//
46114 +// IEEE 802.11 Structures and definitions
46115 +//
46116 +#define MAX_TX_POWER_LEVEL 100 /* mW */
46117 +#define MAX_RSSI_TRIGGER -10 /* dBm */
46118 +#define MIN_RSSI_TRIGGER -200 /* dBm */
46119 +#define MAX_FRAG_THRESHOLD 2346 /* byte count */
46120 +#define MIN_FRAG_THRESHOLD 256 /* byte count */
46121 +#define MAX_RTS_THRESHOLD 2347 /* byte count */
46122 +
46123 +// new types for Media Specific Indications
46124 +// Extension channel offset
46125 +#define EXTCHA_NONE 0
46126 +#define EXTCHA_ABOVE 0x1
46127 +#define EXTCHA_BELOW 0x3
46128 +
46129 +// BW
46130 +#define BAND_WIDTH_20 0
46131 +#define BAND_WIDTH_40 1
46132 +#define BAND_WIDTH_BOTH 2
46133 +#define BAND_WIDTH_10 3 // 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field.
46134 +// SHORTGI
46135 +#define GAP_INTERVAL_400 1 // only support in HT mode
46136 +#define GAP_INTERVAL_800 0
46137 +#define GAP_INTERVAL_BOTH 2
46138 +
46139 +#define NdisMediaStateConnected 1
46140 +#define NdisMediaStateDisconnected 0
46141 +
46142 +#define NDIS_802_11_LENGTH_SSID 32
46143 +#define NDIS_802_11_LENGTH_RATES 8
46144 +#define NDIS_802_11_LENGTH_RATES_EX 16
46145 +#define MAC_ADDR_LENGTH 6
46146 +#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL terminationc
46147 +#define MAX_NUMBER_OF_EVENT 10 // entry # in EVENT table
46148 +#define MAX_NUMBER_OF_MAC 32 // if MAX_MBSSID_NUM is 8, this value can't be larger than 211
46149 +#define MAX_NUMBER_OF_ACL 64
46150 +#define MAX_LENGTH_OF_SUPPORT_RATES 12 // 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
46151 +#define MAX_NUMBER_OF_DLS_ENTRY 4
46152 +
46153 +#ifndef UNDER_CE
46154 +// OID definition, since NDIS 5.0 didn't define these, we need to define for our own
46155 +//#if _WIN32_WINNT<=0x0500
46156 +
46157 +#define OID_GEN_MACHINE_NAME 0x0001021A
46158 +
46159 +#ifdef RALINK_ATE
46160 +#define RT_QUERY_ATE_TXDONE_COUNT 0x0401
46161 +#endif // RALINK_ATE //
46162 +#define RT_QUERY_SIGNAL_CONTEXT 0x0402
46163 +#define RT_SET_IAPP_PID 0x0404
46164 +#define RT_SET_APD_PID 0x0405
46165 +#define RT_SET_DEL_MAC_ENTRY 0x0406
46166 +
46167 +//
46168 +// IEEE 802.11 OIDs
46169 +//
46170 +#define OID_GET_SET_TOGGLE 0x8000
46171 +
46172 +#define OID_802_11_NETWORK_TYPES_SUPPORTED 0x0103
46173 +#define OID_802_11_NETWORK_TYPE_IN_USE 0x0104
46174 +#define OID_802_11_RSSI_TRIGGER 0x0107
46175 +#define RT_OID_802_11_RSSI 0x0108 //rt2860 only , kathy
46176 +#define RT_OID_802_11_RSSI_1 0x0109 //rt2860 only , kathy
46177 +#define RT_OID_802_11_RSSI_2 0x010A //rt2860 only , kathy
46178 +#define OID_802_11_NUMBER_OF_ANTENNAS 0x010B
46179 +#define OID_802_11_RX_ANTENNA_SELECTED 0x010C
46180 +#define OID_802_11_TX_ANTENNA_SELECTED 0x010D
46181 +#define OID_802_11_SUPPORTED_RATES 0x010E
46182 +#define OID_802_11_ADD_WEP 0x0112
46183 +#define OID_802_11_REMOVE_WEP 0x0113
46184 +#define OID_802_11_DISASSOCIATE 0x0114
46185 +#define OID_802_11_PRIVACY_FILTER 0x0118
46186 +#define OID_802_11_ASSOCIATION_INFORMATION 0x011E
46187 +#define OID_802_11_TEST 0x011F
46188 +#define RT_OID_802_11_COUNTRY_REGION 0x0507
46189 +#define OID_802_11_BSSID_LIST_SCAN 0x0508
46190 +#define OID_802_11_SSID 0x0509
46191 +#define OID_802_11_BSSID 0x050A
46192 +#define RT_OID_802_11_RADIO 0x050B
46193 +#define RT_OID_802_11_PHY_MODE 0x050C
46194 +#define RT_OID_802_11_STA_CONFIG 0x050D
46195 +#define OID_802_11_DESIRED_RATES 0x050E
46196 +#define RT_OID_802_11_PREAMBLE 0x050F
46197 +#define OID_802_11_WEP_STATUS 0x0510
46198 +#define OID_802_11_AUTHENTICATION_MODE 0x0511
46199 +#define OID_802_11_INFRASTRUCTURE_MODE 0x0512
46200 +#define RT_OID_802_11_RESET_COUNTERS 0x0513
46201 +#define OID_802_11_RTS_THRESHOLD 0x0514
46202 +#define OID_802_11_FRAGMENTATION_THRESHOLD 0x0515
46203 +#define OID_802_11_POWER_MODE 0x0516
46204 +#define OID_802_11_TX_POWER_LEVEL 0x0517
46205 +#define RT_OID_802_11_ADD_WPA 0x0518
46206 +#define OID_802_11_REMOVE_KEY 0x0519
46207 +#define OID_802_11_ADD_KEY 0x0520
46208 +#define OID_802_11_CONFIGURATION 0x0521
46209 +#define OID_802_11_TX_PACKET_BURST 0x0522
46210 +#define RT_OID_802_11_QUERY_NOISE_LEVEL 0x0523
46211 +#define RT_OID_802_11_EXTRA_INFO 0x0524
46212 +#ifdef DBG
46213 +#define RT_OID_802_11_HARDWARE_REGISTER 0x0525
46214 +#endif
46215 +#define OID_802_11_ENCRYPTION_STATUS OID_802_11_WEP_STATUS
46216 +#define OID_802_11_DEAUTHENTICATION 0x0526
46217 +#define OID_802_11_DROP_UNENCRYPTED 0x0527
46218 +#define OID_802_11_MIC_FAILURE_REPORT_FRAME 0x0528
46219 +
46220 +// For 802.1x daemin using to require current driver configuration
46221 +#define OID_802_11_RADIUS_QUERY_SETTING 0x0540
46222 +
46223 +#define RT_OID_DEVICE_NAME 0x0607
46224 +#define RT_OID_VERSION_INFO 0x0608
46225 +#define OID_802_11_BSSID_LIST 0x0609
46226 +#define OID_802_3_CURRENT_ADDRESS 0x060A
46227 +#define OID_GEN_MEDIA_CONNECT_STATUS 0x060B
46228 +#define RT_OID_802_11_QUERY_LINK_STATUS 0x060C
46229 +#define OID_802_11_RSSI 0x060D
46230 +#define OID_802_11_STATISTICS 0x060E
46231 +#define OID_GEN_RCV_OK 0x060F
46232 +#define OID_GEN_RCV_NO_BUFFER 0x0610
46233 +#define RT_OID_802_11_QUERY_EEPROM_VERSION 0x0611
46234 +#define RT_OID_802_11_QUERY_FIRMWARE_VERSION 0x0612
46235 +#define RT_OID_802_11_QUERY_LAST_RX_RATE 0x0613
46236 +#define RT_OID_802_11_TX_POWER_LEVEL_1 0x0614
46237 +#define RT_OID_802_11_QUERY_PIDVID 0x0615
46238 +//for WPA_SUPPLICANT_SUPPORT
46239 +#define OID_SET_COUNTERMEASURES 0x0616
46240 +#define OID_802_11_SET_IEEE8021X 0x0617
46241 +#define OID_802_11_SET_IEEE8021X_REQUIRE_KEY 0x0618
46242 +#define OID_802_11_PMKID 0x0620
46243 +#define RT_OID_WPA_SUPPLICANT_SUPPORT 0x0621
46244 +#define RT_OID_WE_VERSION_COMPILED 0x0622
46245 +#define RT_OID_NEW_DRIVER 0x0623
46246 +
46247 +
46248 +//rt2860 , kathy
46249 +#define RT_OID_802_11_SNR_0 0x0630
46250 +#define RT_OID_802_11_SNR_1 0x0631
46251 +#define RT_OID_802_11_QUERY_LAST_TX_RATE 0x0632
46252 +#define RT_OID_802_11_QUERY_HT_PHYMODE 0x0633
46253 +#define RT_OID_802_11_SET_HT_PHYMODE 0x0634
46254 +#define OID_802_11_RELOAD_DEFAULTS 0x0635
46255 +#define RT_OID_802_11_QUERY_APSD_SETTING 0x0636
46256 +#define RT_OID_802_11_SET_APSD_SETTING 0x0637
46257 +#define RT_OID_802_11_QUERY_APSD_PSM 0x0638
46258 +#define RT_OID_802_11_SET_APSD_PSM 0x0639
46259 +#define RT_OID_802_11_QUERY_DLS 0x063A
46260 +#define RT_OID_802_11_SET_DLS 0x063B
46261 +#define RT_OID_802_11_QUERY_DLS_PARAM 0x063C
46262 +#define RT_OID_802_11_SET_DLS_PARAM 0x063D
46263 +#define RT_OID_802_11_QUERY_WMM 0x063E
46264 +#define RT_OID_802_11_SET_WMM 0x063F
46265 +#define RT_OID_802_11_QUERY_IMME_BA_CAP 0x0640
46266 +#define RT_OID_802_11_SET_IMME_BA_CAP 0x0641
46267 +#define RT_OID_802_11_QUERY_BATABLE 0x0642
46268 +#define RT_OID_802_11_ADD_IMME_BA 0x0643
46269 +#define RT_OID_802_11_TEAR_IMME_BA 0x0644
46270 +#define RT_OID_DRIVER_DEVICE_NAME 0x0645
46271 +#define RT_OID_802_11_QUERY_DAT_HT_PHYMODE 0x0646
46272 +#define RT_OID_QUERY_MULTIPLE_CARD_SUPPORT 0x0647
46273 +
46274 +// Ralink defined OIDs
46275 +// Dennis Lee move to platform specific
46276 +
46277 +#define RT_OID_802_11_BSSID (OID_GET_SET_TOGGLE | OID_802_11_BSSID)
46278 +#define RT_OID_802_11_SSID (OID_GET_SET_TOGGLE | OID_802_11_SSID)
46279 +#define RT_OID_802_11_INFRASTRUCTURE_MODE (OID_GET_SET_TOGGLE | OID_802_11_INFRASTRUCTURE_MODE)
46280 +#define RT_OID_802_11_ADD_WEP (OID_GET_SET_TOGGLE | OID_802_11_ADD_WEP)
46281 +#define RT_OID_802_11_ADD_KEY (OID_GET_SET_TOGGLE | OID_802_11_ADD_KEY)
46282 +#define RT_OID_802_11_REMOVE_WEP (OID_GET_SET_TOGGLE | OID_802_11_REMOVE_WEP)
46283 +#define RT_OID_802_11_REMOVE_KEY (OID_GET_SET_TOGGLE | OID_802_11_REMOVE_KEY)
46284 +#define RT_OID_802_11_DISASSOCIATE (OID_GET_SET_TOGGLE | OID_802_11_DISASSOCIATE)
46285 +#define RT_OID_802_11_AUTHENTICATION_MODE (OID_GET_SET_TOGGLE | OID_802_11_AUTHENTICATION_MODE)
46286 +#define RT_OID_802_11_PRIVACY_FILTER (OID_GET_SET_TOGGLE | OID_802_11_PRIVACY_FILTER)
46287 +#define RT_OID_802_11_BSSID_LIST_SCAN (OID_GET_SET_TOGGLE | OID_802_11_BSSID_LIST_SCAN)
46288 +#define RT_OID_802_11_WEP_STATUS (OID_GET_SET_TOGGLE | OID_802_11_WEP_STATUS)
46289 +#define RT_OID_802_11_RELOAD_DEFAULTS (OID_GET_SET_TOGGLE | OID_802_11_RELOAD_DEFAULTS)
46290 +#define RT_OID_802_11_NETWORK_TYPE_IN_USE (OID_GET_SET_TOGGLE | OID_802_11_NETWORK_TYPE_IN_USE)
46291 +#define RT_OID_802_11_TX_POWER_LEVEL (OID_GET_SET_TOGGLE | OID_802_11_TX_POWER_LEVEL)
46292 +#define RT_OID_802_11_RSSI_TRIGGER (OID_GET_SET_TOGGLE | OID_802_11_RSSI_TRIGGER)
46293 +#define RT_OID_802_11_FRAGMENTATION_THRESHOLD (OID_GET_SET_TOGGLE | OID_802_11_FRAGMENTATION_THRESHOLD)
46294 +#define RT_OID_802_11_RTS_THRESHOLD (OID_GET_SET_TOGGLE | OID_802_11_RTS_THRESHOLD)
46295 +#define RT_OID_802_11_RX_ANTENNA_SELECTED (OID_GET_SET_TOGGLE | OID_802_11_RX_ANTENNA_SELECTED)
46296 +#define RT_OID_802_11_TX_ANTENNA_SELECTED (OID_GET_SET_TOGGLE | OID_802_11_TX_ANTENNA_SELECTED)
46297 +#define RT_OID_802_11_SUPPORTED_RATES (OID_GET_SET_TOGGLE | OID_802_11_SUPPORTED_RATES)
46298 +#define RT_OID_802_11_DESIRED_RATES (OID_GET_SET_TOGGLE | OID_802_11_DESIRED_RATES)
46299 +#define RT_OID_802_11_CONFIGURATION (OID_GET_SET_TOGGLE | OID_802_11_CONFIGURATION)
46300 +#define RT_OID_802_11_POWER_MODE (OID_GET_SET_TOGGLE | OID_802_11_POWER_MODE)
46301 +
46302 +typedef enum _NDIS_802_11_STATUS_TYPE
46303 +{
46304 + Ndis802_11StatusType_Authentication,
46305 + Ndis802_11StatusType_MediaStreamMode,
46306 + Ndis802_11StatusType_PMKID_CandidateList,
46307 + Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
46308 +} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
46309 +
46310 +typedef UCHAR NDIS_802_11_MAC_ADDRESS[6];
46311 +
46312 +typedef struct _NDIS_802_11_STATUS_INDICATION
46313 +{
46314 + NDIS_802_11_STATUS_TYPE StatusType;
46315 +} NDIS_802_11_STATUS_INDICATION, *PNDIS_802_11_STATUS_INDICATION;
46316 +
46317 +// mask for authentication/integrity fields
46318 +#define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS 0x0f
46319 +
46320 +#define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
46321 +#define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
46322 +#define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
46323 +#define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
46324 +
46325 +typedef struct _NDIS_802_11_AUTHENTICATION_REQUEST
46326 +{
46327 + ULONG Length; // Length of structure
46328 + NDIS_802_11_MAC_ADDRESS Bssid;
46329 + ULONG Flags;
46330 +} NDIS_802_11_AUTHENTICATION_REQUEST, *PNDIS_802_11_AUTHENTICATION_REQUEST;
46331 +
46332 +//Added new types for PMKID Candidate lists.
46333 +typedef struct _PMKID_CANDIDATE {
46334 + NDIS_802_11_MAC_ADDRESS BSSID;
46335 + ULONG Flags;
46336 +} PMKID_CANDIDATE, *PPMKID_CANDIDATE;
46337 +
46338 +typedef struct _NDIS_802_11_PMKID_CANDIDATE_LIST
46339 +{
46340 + ULONG Version; // Version of the structure
46341 + ULONG NumCandidates; // No. of pmkid candidates
46342 + PMKID_CANDIDATE CandidateList[1];
46343 +} NDIS_802_11_PMKID_CANDIDATE_LIST, *PNDIS_802_11_PMKID_CANDIDATE_LIST;
46344 +
46345 +//Flags for PMKID Candidate list structure
46346 +#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
46347 +
46348 +// Added new types for OFDM 5G and 2.4G
46349 +typedef enum _NDIS_802_11_NETWORK_TYPE
46350 +{
46351 + Ndis802_11FH,
46352 + Ndis802_11DS,
46353 + Ndis802_11OFDM5,
46354 + Ndis802_11OFDM5_N,
46355 + Ndis802_11OFDM24,
46356 + Ndis802_11OFDM24_N,
46357 + Ndis802_11Automode,
46358 + Ndis802_11NetworkTypeMax // not a real type, defined as an upper bound
46359 +} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
46360 +
46361 +typedef struct _NDIS_802_11_NETWORK_TYPE_LIST
46362 +{
46363 + UINT NumberOfItems; // in list below, at least 1
46364 + NDIS_802_11_NETWORK_TYPE NetworkType [1];
46365 +} NDIS_802_11_NETWORK_TYPE_LIST, *PNDIS_802_11_NETWORK_TYPE_LIST;
46366 +
46367 +typedef enum _NDIS_802_11_POWER_MODE
46368 +{
46369 + Ndis802_11PowerModeCAM,
46370 + Ndis802_11PowerModeMAX_PSP,
46371 + Ndis802_11PowerModeFast_PSP,
46372 + Ndis802_11PowerModeLegacy_PSP,
46373 + Ndis802_11PowerModeMax // not a real mode, defined as an upper bound
46374 +} NDIS_802_11_POWER_MODE, *PNDIS_802_11_POWER_MODE;
46375 +
46376 +typedef ULONG NDIS_802_11_TX_POWER_LEVEL; // in milliwatts
46377 +
46378 +//
46379 +// Received Signal Strength Indication
46380 +//
46381 +typedef LONG NDIS_802_11_RSSI; // in dBm
46382 +
46383 +typedef struct _NDIS_802_11_CONFIGURATION_FH
46384 +{
46385 + ULONG Length; // Length of structure
46386 + ULONG HopPattern; // As defined by 802.11, MSB set
46387 + ULONG HopSet; // to one if non-802.11
46388 + ULONG DwellTime; // units are Kusec
46389 +} NDIS_802_11_CONFIGURATION_FH, *PNDIS_802_11_CONFIGURATION_FH;
46390 +
46391 +typedef struct _NDIS_802_11_CONFIGURATION
46392 +{
46393 + ULONG Length; // Length of structure
46394 + ULONG BeaconPeriod; // units are Kusec
46395 + ULONG ATIMWindow; // units are Kusec
46396 + ULONG DSConfig; // Frequency, units are kHz
46397 + NDIS_802_11_CONFIGURATION_FH FHConfig;
46398 +} NDIS_802_11_CONFIGURATION, *PNDIS_802_11_CONFIGURATION;
46399 +
46400 +typedef struct _NDIS_802_11_STATISTICS
46401 +{
46402 + ULONG Length; // Length of structure
46403 + LARGE_INTEGER TransmittedFragmentCount;
46404 + LARGE_INTEGER MulticastTransmittedFrameCount;
46405 + LARGE_INTEGER FailedCount;
46406 + LARGE_INTEGER RetryCount;
46407 + LARGE_INTEGER MultipleRetryCount;
46408 + LARGE_INTEGER RTSSuccessCount;
46409 + LARGE_INTEGER RTSFailureCount;
46410 + LARGE_INTEGER ACKFailureCount;
46411 + LARGE_INTEGER FrameDuplicateCount;
46412 + LARGE_INTEGER ReceivedFragmentCount;
46413 + LARGE_INTEGER MulticastReceivedFrameCount;
46414 + LARGE_INTEGER FCSErrorCount;
46415 + LARGE_INTEGER TKIPLocalMICFailures;
46416 + LARGE_INTEGER TKIPRemoteMICErrors;
46417 + LARGE_INTEGER TKIPICVErrors;
46418 + LARGE_INTEGER TKIPCounterMeasuresInvoked;
46419 + LARGE_INTEGER TKIPReplays;
46420 + LARGE_INTEGER CCMPFormatErrors;
46421 + LARGE_INTEGER CCMPReplays;
46422 + LARGE_INTEGER CCMPDecryptErrors;
46423 + LARGE_INTEGER FourWayHandshakeFailures;
46424 +} NDIS_802_11_STATISTICS, *PNDIS_802_11_STATISTICS;
46425 +
46426 +typedef ULONG NDIS_802_11_KEY_INDEX;
46427 +typedef ULONGLONG NDIS_802_11_KEY_RSC;
46428 +
46429 +#define MAX_RADIUS_SRV_NUM 2 // 802.1x failover number
46430 +
46431 +typedef struct PACKED _RADIUS_SRV_INFO {
46432 + UINT32 radius_ip;
46433 + UINT32 radius_port;
46434 + UCHAR radius_key[64];
46435 + UCHAR radius_key_len;
46436 +} RADIUS_SRV_INFO, *PRADIUS_SRV_INFO;
46437 +
46438 +typedef struct PACKED _RADIUS_KEY_INFO
46439 +{
46440 + UCHAR radius_srv_num;
46441 + RADIUS_SRV_INFO radius_srv_info[MAX_RADIUS_SRV_NUM];
46442 + UCHAR ieee8021xWEP; // dynamic WEP
46443 + UCHAR key_index;
46444 + UCHAR key_length; // length of key in bytes
46445 + UCHAR key_material[13];
46446 +} RADIUS_KEY_INFO, *PRADIUS_KEY_INFO;
46447 +
46448 +// It's used by 802.1x daemon to require relative configuration
46449 +typedef struct PACKED _RADIUS_CONF
46450 +{
46451 + UINT32 Length; // Length of this structure
46452 + UCHAR mbss_num; // indicate multiple BSS number
46453 + UINT32 own_ip_addr;
46454 + UINT32 retry_interval;
46455 + UINT32 session_timeout_interval;
46456 + UCHAR EAPifname[IFNAMSIZ];
46457 + UCHAR EAPifname_len;
46458 + UCHAR PreAuthifname[IFNAMSIZ];
46459 + UCHAR PreAuthifname_len;
46460 + RADIUS_KEY_INFO RadiusInfo[8/*MAX_MBSSID_NUM*/];
46461 +} RADIUS_CONF, *PRADIUS_CONF;
46462 +
46463 +
46464 +
46465 +#ifdef CONFIG_STA_SUPPORT
46466 +// Key mapping keys require a BSSID
46467 +typedef struct _NDIS_802_11_KEY
46468 +{
46469 + UINT Length; // Length of this structure
46470 + UINT KeyIndex;
46471 + UINT KeyLength; // length of key in bytes
46472 + NDIS_802_11_MAC_ADDRESS BSSID;
46473 + NDIS_802_11_KEY_RSC KeyRSC;
46474 + UCHAR KeyMaterial[1]; // variable length depending on above field
46475 +} NDIS_802_11_KEY, *PNDIS_802_11_KEY;
46476 +#endif // CONFIG_STA_SUPPORT //
46477 +
46478 +typedef struct _NDIS_802_11_REMOVE_KEY
46479 +{
46480 + UINT Length; // Length of this structure
46481 + UINT KeyIndex;
46482 + NDIS_802_11_MAC_ADDRESS BSSID;
46483 +} NDIS_802_11_REMOVE_KEY, *PNDIS_802_11_REMOVE_KEY;
46484 +
46485 +typedef struct _NDIS_802_11_WEP
46486 +{
46487 + UINT Length; // Length of this structure
46488 + UINT KeyIndex; // 0 is the per-client key, 1-N are the
46489 + // global keys
46490 + UINT KeyLength; // length of key in bytes
46491 + UCHAR KeyMaterial[1];// variable length depending on above field
46492 +} NDIS_802_11_WEP, *PNDIS_802_11_WEP;
46493 +
46494 +
46495 +typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE
46496 +{
46497 + Ndis802_11IBSS,
46498 + Ndis802_11Infrastructure,
46499 + Ndis802_11AutoUnknown,
46500 + Ndis802_11Monitor,
46501 + Ndis802_11InfrastructureMax // Not a real value, defined as upper bound
46502 +} NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE;
46503 +
46504 +// Add new authentication modes
46505 +typedef enum _NDIS_802_11_AUTHENTICATION_MODE
46506 +{
46507 + Ndis802_11AuthModeOpen,
46508 + Ndis802_11AuthModeShared,
46509 + Ndis802_11AuthModeAutoSwitch,
46510 + Ndis802_11AuthModeWPA,
46511 + Ndis802_11AuthModeWPAPSK,
46512 + Ndis802_11AuthModeWPANone,
46513 + Ndis802_11AuthModeWPA2,
46514 + Ndis802_11AuthModeWPA2PSK,
46515 + Ndis802_11AuthModeWPA1WPA2,
46516 + Ndis802_11AuthModeWPA1PSKWPA2PSK,
46517 + Ndis802_11AuthModeMax // Not a real mode, defined as upper bound
46518 +} NDIS_802_11_AUTHENTICATION_MODE, *PNDIS_802_11_AUTHENTICATION_MODE;
46519 +
46520 +typedef UCHAR NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; // Set of 8 data rates
46521 +typedef UCHAR NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; // Set of 16 data rates
46522 +
46523 +typedef struct PACKED _NDIS_802_11_SSID
46524 +{
46525 + UINT SsidLength; // length of SSID field below, in bytes;
46526 + // this can be zero.
46527 + UCHAR Ssid[NDIS_802_11_LENGTH_SSID]; // SSID information field
46528 +} NDIS_802_11_SSID, *PNDIS_802_11_SSID;
46529 +
46530 +
46531 +typedef struct PACKED _NDIS_WLAN_BSSID
46532 +{
46533 + ULONG Length; // Length of this structure
46534 + NDIS_802_11_MAC_ADDRESS MacAddress; // BSSID
46535 + UCHAR Reserved[2];
46536 + NDIS_802_11_SSID Ssid; // SSID
46537 + ULONG Privacy; // WEP encryption requirement
46538 + NDIS_802_11_RSSI Rssi; // receive signal strength in dBm
46539 + NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
46540 + NDIS_802_11_CONFIGURATION Configuration;
46541 + NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
46542 + NDIS_802_11_RATES SupportedRates;
46543 +} NDIS_WLAN_BSSID, *PNDIS_WLAN_BSSID;
46544 +
46545 +typedef struct PACKED _NDIS_802_11_BSSID_LIST
46546 +{
46547 + UINT NumberOfItems; // in list below, at least 1
46548 + NDIS_WLAN_BSSID Bssid[1];
46549 +} NDIS_802_11_BSSID_LIST, *PNDIS_802_11_BSSID_LIST;
46550 +
46551 +// Added Capabilities, IELength and IEs for each BSSID
46552 +typedef struct PACKED _NDIS_WLAN_BSSID_EX
46553 +{
46554 + ULONG Length; // Length of this structure
46555 + NDIS_802_11_MAC_ADDRESS MacAddress; // BSSID
46556 + UCHAR Reserved[2];
46557 + NDIS_802_11_SSID Ssid; // SSID
46558 + UINT Privacy; // WEP encryption requirement
46559 + NDIS_802_11_RSSI Rssi; // receive signal
46560 + // strength in dBm
46561 + NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
46562 + NDIS_802_11_CONFIGURATION Configuration;
46563 + NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
46564 + NDIS_802_11_RATES_EX SupportedRates;
46565 + ULONG IELength;
46566 + UCHAR IEs[1];
46567 +} NDIS_WLAN_BSSID_EX, *PNDIS_WLAN_BSSID_EX;
46568 +
46569 +typedef struct PACKED _NDIS_802_11_BSSID_LIST_EX
46570 +{
46571 + UINT NumberOfItems; // in list below, at least 1
46572 + NDIS_WLAN_BSSID_EX Bssid[1];
46573 +} NDIS_802_11_BSSID_LIST_EX, *PNDIS_802_11_BSSID_LIST_EX;
46574 +
46575 +typedef struct PACKED _NDIS_802_11_FIXED_IEs
46576 +{
46577 + UCHAR Timestamp[8];
46578 + USHORT BeaconInterval;
46579 + USHORT Capabilities;
46580 +} NDIS_802_11_FIXED_IEs, *PNDIS_802_11_FIXED_IEs;
46581 +
46582 +typedef struct _NDIS_802_11_VARIABLE_IEs
46583 +{
46584 + UCHAR ElementID;
46585 + UCHAR Length; // Number of bytes in data field
46586 + UCHAR data[1];
46587 +} NDIS_802_11_VARIABLE_IEs, *PNDIS_802_11_VARIABLE_IEs;
46588 +
46589 +typedef ULONG NDIS_802_11_FRAGMENTATION_THRESHOLD;
46590 +
46591 +typedef ULONG NDIS_802_11_RTS_THRESHOLD;
46592 +
46593 +typedef ULONG NDIS_802_11_ANTENNA;
46594 +
46595 +typedef enum _NDIS_802_11_PRIVACY_FILTER
46596 +{
46597 + Ndis802_11PrivFilterAcceptAll,
46598 + Ndis802_11PrivFilter8021xWEP
46599 +} NDIS_802_11_PRIVACY_FILTER, *PNDIS_802_11_PRIVACY_FILTER;
46600 +
46601 +// Added new encryption types
46602 +// Also aliased typedef to new name
46603 +typedef enum _NDIS_802_11_WEP_STATUS
46604 +{
46605 + Ndis802_11WEPEnabled,
46606 + Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
46607 + Ndis802_11WEPDisabled,
46608 + Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
46609 + Ndis802_11WEPKeyAbsent,
46610 + Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
46611 + Ndis802_11WEPNotSupported,
46612 + Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
46613 + Ndis802_11Encryption2Enabled,
46614 + Ndis802_11Encryption2KeyAbsent,
46615 + Ndis802_11Encryption3Enabled,
46616 + Ndis802_11Encryption3KeyAbsent,
46617 + Ndis802_11Encryption4Enabled, // TKIP or AES mix
46618 + Ndis802_11Encryption4KeyAbsent,
46619 + Ndis802_11GroupWEP40Enabled,
46620 + Ndis802_11GroupWEP104Enabled,
46621 +} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
46622 + NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
46623 +
46624 +typedef enum _NDIS_802_11_RELOAD_DEFAULTS
46625 +{
46626 + Ndis802_11ReloadWEPKeys
46627 +} NDIS_802_11_RELOAD_DEFAULTS, *PNDIS_802_11_RELOAD_DEFAULTS;
46628 +
46629 +#define NDIS_802_11_AI_REQFI_CAPABILITIES 1
46630 +#define NDIS_802_11_AI_REQFI_LISTENINTERVAL 2
46631 +#define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS 4
46632 +
46633 +#define NDIS_802_11_AI_RESFI_CAPABILITIES 1
46634 +#define NDIS_802_11_AI_RESFI_STATUSCODE 2
46635 +#define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4
46636 +
46637 +typedef struct _NDIS_802_11_AI_REQFI
46638 +{
46639 + USHORT Capabilities;
46640 + USHORT ListenInterval;
46641 + NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
46642 +} NDIS_802_11_AI_REQFI, *PNDIS_802_11_AI_REQFI;
46643 +
46644 +typedef struct _NDIS_802_11_AI_RESFI
46645 +{
46646 + USHORT Capabilities;
46647 + USHORT StatusCode;
46648 + USHORT AssociationId;
46649 +} NDIS_802_11_AI_RESFI, *PNDIS_802_11_AI_RESFI;
46650 +
46651 +typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION
46652 +{
46653 + ULONG Length;
46654 + USHORT AvailableRequestFixedIEs;
46655 + NDIS_802_11_AI_REQFI RequestFixedIEs;
46656 + ULONG RequestIELength;
46657 + ULONG OffsetRequestIEs;
46658 + USHORT AvailableResponseFixedIEs;
46659 + NDIS_802_11_AI_RESFI ResponseFixedIEs;
46660 + ULONG ResponseIELength;
46661 + ULONG OffsetResponseIEs;
46662 +} NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
46663 +
46664 +typedef struct _NDIS_802_11_AUTHENTICATION_EVENT
46665 +{
46666 + NDIS_802_11_STATUS_INDICATION Status;
46667 + NDIS_802_11_AUTHENTICATION_REQUEST Request[1];
46668 +} NDIS_802_11_AUTHENTICATION_EVENT, *PNDIS_802_11_AUTHENTICATION_EVENT;
46669 +
46670 +/*
46671 +typedef struct _NDIS_802_11_TEST
46672 +{
46673 + ULONG Length;
46674 + ULONG Type;
46675 + union
46676 + {
46677 + NDIS_802_11_AUTHENTICATION_EVENT AuthenticationEvent;
46678 + NDIS_802_11_RSSI RssiTrigger;
46679 + };
46680 +} NDIS_802_11_TEST, *PNDIS_802_11_TEST;
46681 + */
46682 +
46683 +// 802.11 Media stream constraints, associated with OID_802_11_MEDIA_STREAM_MODE
46684 +typedef enum _NDIS_802_11_MEDIA_STREAM_MODE
46685 +{
46686 + Ndis802_11MediaStreamOff,
46687 + Ndis802_11MediaStreamOn,
46688 +} NDIS_802_11_MEDIA_STREAM_MODE, *PNDIS_802_11_MEDIA_STREAM_MODE;
46689 +
46690 +// PMKID Structures
46691 +typedef UCHAR NDIS_802_11_PMKID_VALUE[16];
46692 +
46693 +#ifdef CONFIG_STA_SUPPORT
46694 +typedef struct _BSSID_INFO
46695 +{
46696 + NDIS_802_11_MAC_ADDRESS BSSID;
46697 + NDIS_802_11_PMKID_VALUE PMKID;
46698 +} BSSID_INFO, *PBSSID_INFO;
46699 +
46700 +typedef struct _NDIS_802_11_PMKID
46701 +{
46702 + UINT Length;
46703 + UINT BSSIDInfoCount;
46704 + BSSID_INFO BSSIDInfo[1];
46705 +} NDIS_802_11_PMKID, *PNDIS_802_11_PMKID;
46706 +#endif // CONFIG_STA_SUPPORT //
46707 +
46708 +
46709 +typedef struct _NDIS_802_11_AUTHENTICATION_ENCRYPTION
46710 +{
46711 + NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported;
46712 + NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported;
46713 +} NDIS_802_11_AUTHENTICATION_ENCRYPTION, *PNDIS_802_11_AUTHENTICATION_ENCRYPTION;
46714 +
46715 +typedef struct _NDIS_802_11_CAPABILITY
46716 +{
46717 + ULONG Length;
46718 + ULONG Version;
46719 + ULONG NoOfPMKIDs;
46720 + ULONG NoOfAuthEncryptPairsSupported;
46721 + NDIS_802_11_AUTHENTICATION_ENCRYPTION AuthenticationEncryptionSupported[1];
46722 +} NDIS_802_11_CAPABILITY, *PNDIS_802_11_CAPABILITY;
46723 +
46724 +//#endif //of WIN 2k
46725 +#endif //UNDER_CE
46726 +
46727 +#if WIRELESS_EXT <= 11
46728 +#ifndef SIOCDEVPRIVATE
46729 +#define SIOCDEVPRIVATE 0x8BE0
46730 +#endif
46731 +#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
46732 +#endif
46733 +
46734 +#ifdef CONFIG_STA_SUPPORT
46735 +#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
46736 +
46737 +#ifdef DBG
46738 +#define RTPRIV_IOCTL_BBP (SIOCIWFIRSTPRIV + 0x03)
46739 +#define RTPRIV_IOCTL_MAC (SIOCIWFIRSTPRIV + 0x05)
46740 +#define RTPRIV_IOCTL_E2P (SIOCIWFIRSTPRIV + 0x07)
46741 +#endif
46742 +
46743 +#ifdef RALINK_ATE
46744 +#ifdef RALINK_28xx_QA
46745 +#define RTPRIV_IOCTL_ATE (SIOCIWFIRSTPRIV + 0x08)
46746 +#endif // RALINK_28xx_QA //
46747 +#endif // RALINK_ATE //
46748 +
46749 +#define RTPRIV_IOCTL_STATISTICS (SIOCIWFIRSTPRIV + 0x09)
46750 +#define RTPRIV_IOCTL_ADD_PMKID_CACHE (SIOCIWFIRSTPRIV + 0x0A)
46751 +#define RTPRIV_IOCTL_RADIUS_DATA (SIOCIWFIRSTPRIV + 0x0C)
46752 +#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
46753 +#define RT_PRIV_IOCTL (SIOCIWFIRSTPRIV + 0x0E) // Sync. with RT61 (for wpa_supplicant)
46754 +#define RTPRIV_IOCTL_GET_MAC_TABLE (SIOCIWFIRSTPRIV + 0x0F)
46755 +
46756 +#define RTPRIV_IOCTL_SHOW (SIOCIWFIRSTPRIV + 0x11)
46757 +enum {
46758 + SHOW_CONN_STATUS = 4,
46759 + SHOW_DRVIER_VERION = 5,
46760 + SHOW_BA_INFO = 6,
46761 + SHOW_DESC_INFO = 7,
46762 +#ifdef RT2870
46763 + SHOW_RXBULK_INFO = 8,
46764 + SHOW_TXBULK_INFO = 9,
46765 +#endif // RT2870 //
46766 + RAIO_OFF = 10,
46767 + RAIO_ON = 11,
46768 +#ifdef QOS_DLS_SUPPORT
46769 + SHOW_DLS_ENTRY_INFO = 19,
46770 +#endif // QOS_DLS_SUPPORT //
46771 + SHOW_CFG_VALUE = 20,
46772 + SHOW_ADHOC_ENTRY_INFO = 21,
46773 +};
46774 +
46775 +
46776 +#endif // CONFIG_STA_SUPPORT //
46777 +
46778 +#ifdef SNMP_SUPPORT
46779 +//SNMP ieee 802dot11, kathy , 2008_0220
46780 +// dot11res(3)
46781 +#define RT_OID_802_11_MANUFACTUREROUI 0x0700
46782 +#define RT_OID_802_11_MANUFACTURERNAME 0x0701
46783 +#define RT_OID_802_11_RESOURCETYPEIDNAME 0x0702
46784 +
46785 +// dot11smt(1)
46786 +#define RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED 0x0703
46787 +#define RT_OID_802_11_POWERMANAGEMENTMODE 0x0704
46788 +#define OID_802_11_WEPDEFAULTKEYVALUE 0x0705 // read , write
46789 +#define OID_802_11_WEPDEFAULTKEYID 0x0706
46790 +#define RT_OID_802_11_WEPKEYMAPPINGLENGTH 0x0707
46791 +#define OID_802_11_SHORTRETRYLIMIT 0x0708
46792 +#define OID_802_11_LONGRETRYLIMIT 0x0709
46793 +#define RT_OID_802_11_PRODUCTID 0x0710
46794 +#define RT_OID_802_11_MANUFACTUREID 0x0711
46795 +
46796 +// //dot11Phy(4)
46797 +#define OID_802_11_CURRENTCHANNEL 0x0712
46798 +
46799 +//dot11mac
46800 +#define RT_OID_802_11_MAC_ADDRESS 0x0713
46801 +#endif // SNMP_SUPPORT //
46802 +
46803 +#define OID_802_11_BUILD_CHANNEL_EX 0x0714
46804 +#define OID_802_11_GET_CH_LIST 0x0715
46805 +#define OID_802_11_GET_COUNTRY_CODE 0x0716
46806 +#define OID_802_11_GET_CHANNEL_GEOGRAPHY 0x0717
46807 +
46808 +#ifdef LLTD_SUPPORT
46809 +// for consistency with RT61
46810 +#define RT_OID_GET_PHY_MODE 0x761
46811 +#endif // LLTD_SUPPORT //
46812 +
46813 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition!!!
46814 +typedef union _HTTRANSMIT_SETTING {
46815 +#ifdef RT_BIG_ENDIAN
46816 + struct {
46817 + USHORT MODE:2; // Use definition MODE_xxx.
46818 +// USHORT rsv:3;
46819 + USHORT TxBF:1;
46820 + USHORT rsv:2;
46821 + USHORT STBC:2; //SPACE
46822 + USHORT ShortGI:1;
46823 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
46824 + USHORT MCS:7; // MCS
46825 + } field;
46826 +#else
46827 + struct {
46828 + USHORT MCS:7; // MCS
46829 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
46830 + USHORT ShortGI:1;
46831 + USHORT STBC:2; //SPACE
46832 +// USHORT rsv:3;
46833 + USHORT rsv:2;
46834 + USHORT TxBF:1;
46835 + USHORT MODE:2; // Use definition MODE_xxx.
46836 + } field;
46837 +#endif
46838 + USHORT word;
46839 + } HTTRANSMIT_SETTING, *PHTTRANSMIT_SETTING;
46840 +
46841 +typedef enum _RT_802_11_PREAMBLE {
46842 + Rt802_11PreambleLong,
46843 + Rt802_11PreambleShort,
46844 + Rt802_11PreambleAuto
46845 +} RT_802_11_PREAMBLE, *PRT_802_11_PREAMBLE;
46846 +
46847 +// Only for STA, need to sync with AP
46848 +typedef enum _RT_802_11_PHY_MODE {
46849 + PHY_11BG_MIXED = 0,
46850 + PHY_11B,
46851 + PHY_11A,
46852 + PHY_11ABG_MIXED,
46853 + PHY_11G,
46854 +#ifdef DOT11_N_SUPPORT
46855 + PHY_11ABGN_MIXED, // both band 5
46856 + PHY_11N_2_4G, // 11n-only with 2.4G band 6
46857 + PHY_11GN_MIXED, // 2.4G band 7
46858 + PHY_11AN_MIXED, // 5G band 8
46859 + PHY_11BGN_MIXED, // if check 802.11b. 9
46860 + PHY_11AGN_MIXED, // if check 802.11b. 10
46861 + PHY_11N_5G, // 11n-only with 5G band 11
46862 +#endif // DOT11_N_SUPPORT //
46863 +} RT_802_11_PHY_MODE;
46864 +
46865 +// put all proprietery for-query objects here to reduce # of Query_OID
46866 +typedef struct _RT_802_11_LINK_STATUS {
46867 + ULONG CurrTxRate; // in units of 0.5Mbps
46868 + ULONG ChannelQuality; // 0..100 %
46869 + ULONG TxByteCount; // both ok and fail
46870 + ULONG RxByteCount; // both ok and fail
46871 + ULONG CentralChannel; // 40MHz central channel number
46872 +} RT_802_11_LINK_STATUS, *PRT_802_11_LINK_STATUS;
46873 +
46874 +typedef struct _RT_802_11_EVENT_LOG {
46875 + LARGE_INTEGER SystemTime; // timestammp via NdisGetCurrentSystemTime()
46876 + UCHAR Addr[MAC_ADDR_LENGTH];
46877 + USHORT Event; // EVENT_xxx
46878 +} RT_802_11_EVENT_LOG, *PRT_802_11_EVENT_LOG;
46879 +
46880 +typedef struct _RT_802_11_EVENT_TABLE {
46881 + ULONG Num;
46882 + ULONG Rsv; // to align Log[] at LARGE_INEGER boundary
46883 + RT_802_11_EVENT_LOG Log[MAX_NUMBER_OF_EVENT];
46884 +} RT_802_11_EVENT_TABLE, PRT_802_11_EVENT_TABLE;
46885 +
46886 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition!!!
46887 +typedef union _MACHTTRANSMIT_SETTING {
46888 + struct {
46889 + USHORT MCS:7; // MCS
46890 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
46891 + USHORT ShortGI:1;
46892 + USHORT STBC:2; //SPACE
46893 + USHORT rsv:3;
46894 + USHORT MODE:2; // Use definition MODE_xxx.
46895 + } field;
46896 + USHORT word;
46897 + } MACHTTRANSMIT_SETTING, *PMACHTTRANSMIT_SETTING;
46898 +
46899 +typedef struct _RT_802_11_MAC_ENTRY {
46900 + UCHAR Addr[MAC_ADDR_LENGTH];
46901 + UCHAR Aid;
46902 + UCHAR Psm; // 0:PWR_ACTIVE, 1:PWR_SAVE
46903 + UCHAR MimoPs; // 0:MMPS_STATIC, 1:MMPS_DYNAMIC, 3:MMPS_Enabled
46904 + CHAR AvgRssi0;
46905 + CHAR AvgRssi1;
46906 + CHAR AvgRssi2;
46907 + UINT32 ConnectedTime;
46908 + MACHTTRANSMIT_SETTING TxRate;
46909 +} RT_802_11_MAC_ENTRY, *PRT_802_11_MAC_ENTRY;
46910 +
46911 +typedef struct _RT_802_11_MAC_TABLE {
46912 + ULONG Num;
46913 + RT_802_11_MAC_ENTRY Entry[MAX_NUMBER_OF_MAC];
46914 +} RT_802_11_MAC_TABLE, *PRT_802_11_MAC_TABLE;
46915 +
46916 +// structure for query/set hardware register - MAC, BBP, RF register
46917 +typedef struct _RT_802_11_HARDWARE_REGISTER {
46918 + ULONG HardwareType; // 0:MAC, 1:BBP, 2:RF register, 3:EEPROM
46919 + ULONG Offset; // Q/S register offset addr
46920 + ULONG Data; // R/W data buffer
46921 +} RT_802_11_HARDWARE_REGISTER, *PRT_802_11_HARDWARE_REGISTER;
46922 +
46923 +// structure to tune BBP R17 "RX AGC VGC init"
46924 +//typedef struct _RT_802_11_RX_AGC_VGC_TUNING {
46925 +// UCHAR FalseCcaLowerThreshold; // 0-255, def 10
46926 +// UCHAR FalseCcaUpperThreshold; // 0-255, def 100
46927 +// UCHAR VgcDelta; // R17 +-= VgcDelta whenever flase CCA over UpprThreshold
46928 +// // or lower than LowerThresholdupper threshold
46929 +// UCHAR VgcUpperBound; // max value of R17
46930 +//} RT_802_11_RX_AGC_VGC_TUNING, *PRT_802_11_RX_AGC_VGC_TUNING;
46931 +
46932 +typedef struct _RT_802_11_AP_CONFIG {
46933 + ULONG EnableTxBurst; // 0-disable, 1-enable
46934 + ULONG EnableTurboRate; // 0-disable, 1-enable 72/100mbps turbo rate
46935 + ULONG IsolateInterStaTraffic; // 0-disable, 1-enable isolation
46936 + ULONG HideSsid; // 0-disable, 1-enable hiding
46937 + ULONG UseBGProtection; // 0-AUTO, 1-always ON, 2-always OFF
46938 + ULONG UseShortSlotTime; // 0-no use, 1-use 9-us short slot time
46939 + ULONG Rsv1; // must be 0
46940 + ULONG SystemErrorBitmap; // ignore upon SET, return system error upon QUERY
46941 +} RT_802_11_AP_CONFIG, *PRT_802_11_AP_CONFIG;
46942 +
46943 +// structure to query/set STA_CONFIG
46944 +typedef struct _RT_802_11_STA_CONFIG {
46945 + ULONG EnableTxBurst; // 0-disable, 1-enable
46946 + ULONG EnableTurboRate; // 0-disable, 1-enable 72/100mbps turbo rate
46947 + ULONG UseBGProtection; // 0-AUTO, 1-always ON, 2-always OFF
46948 + ULONG UseShortSlotTime; // 0-no use, 1-use 9-us short slot time when applicable
46949 + ULONG AdhocMode; // 0-11b rates only (WIFI spec), 1 - b/g mixed, 2 - g only
46950 + ULONG HwRadioStatus; // 0-OFF, 1-ON, default is 1, Read-Only
46951 + ULONG Rsv1; // must be 0
46952 + ULONG SystemErrorBitmap; // ignore upon SET, return system error upon QUERY
46953 +} RT_802_11_STA_CONFIG, *PRT_802_11_STA_CONFIG;
46954 +
46955 +//
46956 +// For OID Query or Set about BA structure
46957 +//
46958 +typedef struct _OID_BACAP_STRUC {
46959 + UCHAR RxBAWinLimit;
46960 + UCHAR TxBAWinLimit;
46961 + UCHAR Policy; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid
46962 + UCHAR MpduDensity; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid
46963 + UCHAR AmsduEnable; //Enable AMSDU transmisstion
46964 + UCHAR AmsduSize; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
46965 + UCHAR MMPSmode; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
46966 + BOOLEAN AutoBA; // Auto BA will automatically
46967 +} OID_BACAP_STRUC, *POID_BACAP_STRUC;
46968 +
46969 +typedef struct _RT_802_11_ACL_ENTRY {
46970 + UCHAR Addr[MAC_ADDR_LENGTH];
46971 + USHORT Rsv;
46972 +} RT_802_11_ACL_ENTRY, *PRT_802_11_ACL_ENTRY;
46973 +
46974 +typedef struct PACKED _RT_802_11_ACL {
46975 + ULONG Policy; // 0-disable, 1-positive list, 2-negative list
46976 + ULONG Num;
46977 + RT_802_11_ACL_ENTRY Entry[MAX_NUMBER_OF_ACL];
46978 +} RT_802_11_ACL, *PRT_802_11_ACL;
46979 +
46980 +typedef struct _RT_802_11_WDS {
46981 + ULONG Num;
46982 + NDIS_802_11_MAC_ADDRESS Entry[24/*MAX_NUM_OF_WDS_LINK*/];
46983 + ULONG KeyLength;
46984 + UCHAR KeyMaterial[32];
46985 +} RT_802_11_WDS, *PRT_802_11_WDS;
46986 +
46987 +typedef struct _RT_802_11_TX_RATES_ {
46988 + UCHAR SupRateLen;
46989 + UCHAR SupRate[MAX_LENGTH_OF_SUPPORT_RATES];
46990 + UCHAR ExtRateLen;
46991 + UCHAR ExtRate[MAX_LENGTH_OF_SUPPORT_RATES];
46992 +} RT_802_11_TX_RATES, *PRT_802_11_TX_RATES;
46993 +
46994 +
46995 +// Definition of extra information code
46996 +#define GENERAL_LINK_UP 0x0 // Link is Up
46997 +#define GENERAL_LINK_DOWN 0x1 // Link is Down
46998 +#define HW_RADIO_OFF 0x2 // Hardware radio off
46999 +#define SW_RADIO_OFF 0x3 // Software radio off
47000 +#define AUTH_FAIL 0x4 // Open authentication fail
47001 +#define AUTH_FAIL_KEYS 0x5 // Shared authentication fail
47002 +#define ASSOC_FAIL 0x6 // Association failed
47003 +#define EAP_MIC_FAILURE 0x7 // Deauthencation because MIC failure
47004 +#define EAP_4WAY_TIMEOUT 0x8 // Deauthencation on 4-way handshake timeout
47005 +#define EAP_GROUP_KEY_TIMEOUT 0x9 // Deauthencation on group key handshake timeout
47006 +#define EAP_SUCCESS 0xa // EAP succeed
47007 +#define DETECT_RADAR_SIGNAL 0xb // Radar signal occur in current channel
47008 +#define EXTRA_INFO_MAX 0xb // Indicate Last OID
47009 +
47010 +#define EXTRA_INFO_CLEAR 0xffffffff
47011 +
47012 +// This is OID setting structure. So only GF or MM as Mode. This is valid when our wirelss mode has 802.11n in use.
47013 +typedef struct {
47014 + RT_802_11_PHY_MODE PhyMode; //
47015 + UCHAR TransmitNo;
47016 + UCHAR HtMode; //HTMODE_GF or HTMODE_MM
47017 + UCHAR ExtOffset; //extension channel above or below
47018 + UCHAR MCS;
47019 + UCHAR BW;
47020 + UCHAR STBC;
47021 + UCHAR SHORTGI;
47022 + UCHAR rsv;
47023 +} OID_SET_HT_PHYMODE, *POID_SET_HT_PHYMODE;
47024 +
47025 +#ifdef NINTENDO_AP
47026 +#define NINTENDO_MAX_ENTRY 16
47027 +#define NINTENDO_SSID_NAME_LN 8
47028 +#define NINTENDO_SSID_NAME "NWCUSBAP"
47029 +#define NINTENDO_PROBE_REQ_FLAG_MASK 0x03
47030 +#define NINTENDO_PROBE_REQ_ON 0x01
47031 +#define NINTENDO_PROBE_REQ_SIGNAL 0x02
47032 +#define NINTENDO_PROBE_RSP_ON 0x01
47033 +#define NINTENDO_SSID_NICKNAME_LN 20
47034 +
47035 +#define NINTENDO_WEPKEY_LN 13
47036 +
47037 +typedef struct _NINTENDO_SSID
47038 +{
47039 + UCHAR NINTENDOFixChar[NINTENDO_SSID_NAME_LN];
47040 + UCHAR zero1;
47041 + UCHAR registe;
47042 + UCHAR ID;
47043 + UCHAR zero2;
47044 + UCHAR NICKname[NINTENDO_SSID_NICKNAME_LN];
47045 +} RT_NINTENDO_SSID, *PRT_NINTENDO_SSID;
47046 +
47047 +typedef struct _NINTENDO_ENTRY
47048 +{
47049 + UCHAR NICKname[NINTENDO_SSID_NICKNAME_LN];
47050 + UCHAR DS_Addr[ETH_LENGTH_OF_ADDRESS];
47051 + UCHAR registe;
47052 + UCHAR UserSpaceAck;
47053 +} RT_NINTENDO_ENTRY, *PRT_NINTENDO_ENTRY;
47054 +
47055 +//RTPRIV_IOCTL_NINTENDO_GET_TABLE
47056 +//RTPRIV_IOCTL_NINTENDO_SET_TABLE
47057 +typedef struct _NINTENDO_TABLE
47058 +{
47059 + UINT number;
47060 + RT_NINTENDO_ENTRY entry[NINTENDO_MAX_ENTRY];
47061 +} RT_NINTENDO_TABLE, *PRT_NINTENDO_TABLE;
47062 +
47063 +//RTPRIV_IOCTL_NINTENDO_SEED_WEPKEY
47064 +typedef struct _NINTENDO_SEED_WEPKEY
47065 +{
47066 + UCHAR seed[NINTENDO_SSID_NICKNAME_LN];
47067 + UCHAR wepkey[16];//use 13 for 104 bits wep key
47068 +} RT_NINTENDO_SEED_WEPKEY, *PRT_NINTENDO_SEED_WEPKEY;
47069 +#endif // NINTENDO_AP //
47070 +
47071 +#ifdef LLTD_SUPPORT
47072 +typedef struct _RT_LLTD_ASSOICATION_ENTRY {
47073 + UCHAR Addr[ETH_LENGTH_OF_ADDRESS];
47074 + unsigned short MOR; // maximum operational rate
47075 + UCHAR phyMode;
47076 +} RT_LLTD_ASSOICATION_ENTRY, *PRT_LLTD_ASSOICATION_ENTRY;
47077 +
47078 +typedef struct _RT_LLTD_ASSOICATION_TABLE {
47079 + unsigned int Num;
47080 + RT_LLTD_ASSOICATION_ENTRY Entry[MAX_NUMBER_OF_MAC];
47081 +} RT_LLTD_ASSOICATION_TABLE, *PRT_LLTD_ASSOICATION_TABLE;
47082 +#endif // LLTD_SUPPORT //
47083 +
47084 +#ifdef CONFIG_STA_SUPPORT
47085 +#ifdef QOS_DLS_SUPPORT
47086 +//rt2860, kathy 2007-0118
47087 +// structure for DLS
47088 +typedef struct _RT_802_11_DLS_UI {
47089 + USHORT TimeOut; // unit: second , set by UI
47090 + USHORT CountDownTimer; // unit: second , used by driver only
47091 + NDIS_802_11_MAC_ADDRESS MacAddr; // set by UI
47092 + UCHAR Status; // 0: none , 1: wait STAkey, 2: finish DLS setup , set by driver only
47093 + BOOLEAN Valid; // 1: valid , 0: invalid , set by UI, use to setup or tear down DLS link
47094 +} RT_802_11_DLS_UI, *PRT_802_11_DLS_UI;
47095 +
47096 +typedef struct _RT_802_11_DLS_INFO {
47097 + RT_802_11_DLS_UI Entry[MAX_NUMBER_OF_DLS_ENTRY];
47098 + UCHAR num;
47099 +} RT_802_11_DLS_INFO, *PRT_802_11_DLS_INFO;
47100 +
47101 +typedef enum _RT_802_11_DLS_MODE {
47102 + DLS_NONE,
47103 + DLS_WAIT_KEY,
47104 + DLS_FINISH
47105 +} RT_802_11_DLS_MODE;
47106 +#endif // QOS_DLS_SUPPORT //
47107 +
47108 +#ifdef WPA_SUPPLICANT_SUPPORT
47109 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
47110 +#define RT_ASSOC_EVENT_FLAG 0x0101
47111 +#define RT_DISASSOC_EVENT_FLAG 0x0102
47112 +#define RT_REQIE_EVENT_FLAG 0x0103
47113 +#define RT_RESPIE_EVENT_FLAG 0x0104
47114 +#define RT_ASSOCINFO_EVENT_FLAG 0x0105
47115 +#define RT_PMKIDCAND_FLAG 0x0106
47116 +#define RT_INTERFACE_DOWN 0x0107
47117 +#define RT_INTERFACE_UP 0x0108
47118 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
47119 +#endif // WPA_SUPPLICANT_SUPPORT //
47120 +#endif // CONFIG_STA_SUPPORT //
47121 +
47122 +
47123 +#define MAX_CUSTOM_LEN 128
47124 +
47125 +#ifdef CONFIG_STA_SUPPORT
47126 +typedef enum _RT_802_11_D_CLIENT_MODE
47127 +{
47128 + Rt802_11_D_None,
47129 + Rt802_11_D_Flexible,
47130 + Rt802_11_D_Strict,
47131 +} RT_802_11_D_CLIENT_MODE, *PRT_802_11_D_CLIENT_MODE;
47132 +#endif // CONFIG_STA_SUPPORT //
47133 +
47134 +typedef struct _RT_CHANNEL_LIST_INFO
47135 +{
47136 + UCHAR ChannelList[MAX_NUM_OF_CHS]; // list all supported channels for site survey
47137 + UCHAR ChannelListNum; // number of channel in ChannelList[]
47138 +} RT_CHANNEL_LIST_INFO, *PRT_CHANNEL_LIST_INFO;
47139 +
47140 +// WSC configured credential
47141 +typedef struct _WSC_CREDENTIAL
47142 +{
47143 + NDIS_802_11_SSID SSID; // mandatory
47144 + USHORT AuthType; // mandatory, 1: open, 2: wpa-psk, 4: shared, 8:wpa, 0x10: wpa2, 0x20: wpa2-psk
47145 + USHORT EncrType; // mandatory, 1: none, 2: wep, 4: tkip, 8: aes
47146 + UCHAR Key[64]; // mandatory, Maximum 64 byte
47147 + USHORT KeyLength;
47148 + UCHAR MacAddr[6]; // mandatory, AP MAC address
47149 + UCHAR KeyIndex; // optional, default is 1
47150 + UCHAR Rsvd[3]; // Make alignment
47151 +} WSC_CREDENTIAL, *PWSC_CREDENTIAL;
47152 +
47153 +// WSC configured profiles
47154 +typedef struct _WSC_PROFILE
47155 +{
47156 + UINT ProfileCnt;
47157 + WSC_CREDENTIAL Profile[8]; // Support up to 8 profiles
47158 +} WSC_PROFILE, *PWSC_PROFILE;
47159 +
47160 +
47161 +#endif // _OID_H_
47162 +
47163 --- /dev/null
47164 +++ b/drivers/staging/rt2870/rt2870.h
47165 @@ -0,0 +1,761 @@
47166 +/*
47167 + *************************************************************************
47168 + * Ralink Tech Inc.
47169 + * 5F., No.36, Taiyuan St., Jhubei City,
47170 + * Hsinchu County 302,
47171 + * Taiwan, R.O.C.
47172 + *
47173 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
47174 + *
47175 + * This program is free software; you can redistribute it and/or modify *
47176 + * it under the terms of the GNU General Public License as published by *
47177 + * the Free Software Foundation; either version 2 of the License, or *
47178 + * (at your option) any later version. *
47179 + * *
47180 + * This program is distributed in the hope that it will be useful, *
47181 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
47182 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
47183 + * GNU General Public License for more details. *
47184 + * *
47185 + * You should have received a copy of the GNU General Public License *
47186 + * along with this program; if not, write to the *
47187 + * Free Software Foundation, Inc., *
47188 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
47189 + * *
47190 + *************************************************************************
47191 + */
47192 +
47193 +#ifndef __RT2870_H__
47194 +#define __RT2870_H__
47195 +
47196 +//usb header files
47197 +#include <linux/usb.h>
47198 +
47199 +/* rtmp_def.h */
47200 +//
47201 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
47202 +#define BULKAGGRE_ZISE 100
47203 +#define RT28XX_DRVDATA_SET(_a) usb_set_intfdata(_a, pAd);
47204 +#define RT28XX_PUT_DEVICE usb_put_dev
47205 +#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC)
47206 +#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, GFP_ATOMIC)
47207 +#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_buffer_alloc(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)
47208 +#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) usb_buffer_free(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)
47209 +#else
47210 +#define BULKAGGRE_ZISE 60
47211 +#define RT28XX_DRVDATA_SET(_a)
47212 +#define RT28XX_PUT_DEVICE(dev_p)
47213 +#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso)
47214 +#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb)
47215 +#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) kmalloc(BufSize, GFP_ATOMIC)
47216 +#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) kfree(pTransferBuf)
47217 +#endif
47218 +
47219 +#define RXBULKAGGRE_ZISE 12
47220 +#define MAX_TXBULK_LIMIT (LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1))
47221 +#define MAX_TXBULK_SIZE (LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE)
47222 +#define MAX_RXBULK_SIZE (LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE)
47223 +#define MAX_MLME_HANDLER_MEMORY 20
47224 +#define RETRY_LIMIT 10
47225 +#define BUFFER_SIZE 2400 //2048
47226 +#define TX_RING 0xa
47227 +#define PRIO_RING 0xc
47228 +
47229 +
47230 +// Flags for Bulkflags control for bulk out data
47231 +//
47232 +#define fRTUSB_BULK_OUT_DATA_NULL 0x00000001
47233 +#define fRTUSB_BULK_OUT_RTS 0x00000002
47234 +#define fRTUSB_BULK_OUT_MLME 0x00000004
47235 +
47236 +#define fRTUSB_BULK_OUT_DATA_NORMAL 0x00010000
47237 +#define fRTUSB_BULK_OUT_DATA_NORMAL_2 0x00020000
47238 +#define fRTUSB_BULK_OUT_DATA_NORMAL_3 0x00040000
47239 +#define fRTUSB_BULK_OUT_DATA_NORMAL_4 0x00080000
47240 +
47241 +#define fRTUSB_BULK_OUT_PSPOLL 0x00000020
47242 +#define fRTUSB_BULK_OUT_DATA_FRAG 0x00000040
47243 +#define fRTUSB_BULK_OUT_DATA_FRAG_2 0x00000080
47244 +#define fRTUSB_BULK_OUT_DATA_FRAG_3 0x00000100
47245 +#define fRTUSB_BULK_OUT_DATA_FRAG_4 0x00000200
47246 +
47247 +#ifdef RALINK_ATE
47248 +#define fRTUSB_BULK_OUT_DATA_ATE 0x00100000
47249 +#endif // RALINK_ATE //
47250 +
47251 +#define RT2870_USB_DEVICES \
47252 +{ \
47253 + {USB_DEVICE(0x148F,0x2770)}, /* Ralink */ \
47254 + {USB_DEVICE(0x148F,0x2870)}, /* Ralink */ \
47255 + {USB_DEVICE(0x148F,0x3070)}, /* Ralink */ \
47256 + {USB_DEVICE(0x0B05,0x1731)}, /* Asus */ \
47257 + {USB_DEVICE(0x0B05,0x1732)}, /* Asus */ \
47258 + {USB_DEVICE(0x0B05,0x1742)}, /* Asus */ \
47259 + {USB_DEVICE(0x0DF6,0x0017)}, /* Sitecom */ \
47260 + {USB_DEVICE(0x0DF6,0x002B)}, /* Sitecom */ \
47261 + {USB_DEVICE(0x0DF6,0x002C)}, /* Sitecom */ \
47262 + {USB_DEVICE(0x0DF6,0x002D)}, /* Sitecom */ \
47263 + {USB_DEVICE(0x14B2,0x3C06)}, /* Conceptronic */ \
47264 + {USB_DEVICE(0x14B2,0x3C28)}, /* Conceptronic */ \
47265 + {USB_DEVICE(0x2019,0xED06)}, /* Planex Communications, Inc. */ \
47266 + {USB_DEVICE(0x2019,0xAB25)}, /* Planex Communications, Inc. RT3070 */ \
47267 + {USB_DEVICE(0x07D1,0x3C09)}, /* D-Link */ \
47268 + {USB_DEVICE(0x07D1,0x3C11)}, /* D-Link */ \
47269 + {USB_DEVICE(0x14B2,0x3C07)}, /* AL */ \
47270 + {USB_DEVICE(0x14B2,0x3C12)}, /* AL */ \
47271 + {USB_DEVICE(0x050D,0x8053)}, /* Belkin */ \
47272 + {USB_DEVICE(0x14B2,0x3C23)}, /* Airlink */ \
47273 + {USB_DEVICE(0x14B2,0x3C27)}, /* Airlink */ \
47274 + {USB_DEVICE(0x07AA,0x002F)}, /* Corega */ \
47275 + {USB_DEVICE(0x07AA,0x003C)}, /* Corega */ \
47276 + {USB_DEVICE(0x07AA,0x003F)}, /* Corega */ \
47277 + {USB_DEVICE(0x18C5,0x0012)}, /* Corega */ \
47278 + {USB_DEVICE(0x1044,0x800B)}, /* Gigabyte */ \
47279 + {USB_DEVICE(0x15A9,0x0006)}, /* Sparklan */ \
47280 + {USB_DEVICE(0x083A,0xB522)}, /* SMC */ \
47281 + {USB_DEVICE(0x083A,0xA618)}, /* SMC */ \
47282 + {USB_DEVICE(0x083A,0x7522)}, /* Arcadyan */ \
47283 + {USB_DEVICE(0x0CDE,0x0022)}, /* ZCOM */ \
47284 + {USB_DEVICE(0x0586,0x3416)}, /* Zyxel */ \
47285 + {USB_DEVICE(0x0CDE,0x0025)}, /* Zyxel */ \
47286 + {USB_DEVICE(0x1740,0x9701)}, /* EnGenius */ \
47287 + {USB_DEVICE(0x1740,0x9702)}, /* EnGenius */ \
47288 + {USB_DEVICE(0x0471,0x200f)}, /* Philips */ \
47289 + {USB_DEVICE(0x14B2,0x3C25)}, /* Draytek */ \
47290 + {USB_DEVICE(0x13D3,0x3247)}, /* AzureWave */ \
47291 + {USB_DEVICE(0x083A,0x6618)}, /* Accton */ \
47292 + {USB_DEVICE(0x15c5,0x0008)}, /* Amit */ \
47293 + {USB_DEVICE(0x0E66,0x0001)}, /* Hawking */ \
47294 + {USB_DEVICE(0x0E66,0x0003)}, /* Hawking */ \
47295 + {USB_DEVICE(0x129B,0x1828)}, /* Siemens */ \
47296 + {USB_DEVICE(0x157E,0x300E)}, /* U-Media */ \
47297 + {USB_DEVICE(0x050d,0x805c)}, \
47298 + {USB_DEVICE(0x1482,0x3C09)}, /* Abocom*/ \
47299 + {USB_DEVICE(0x14B2,0x3C09)}, /* Alpha */ \
47300 + {USB_DEVICE(0x04E8,0x2018)}, /* samsung */ \
47301 + {USB_DEVICE(0x07B8,0x3070)}, /* AboCom */ \
47302 + {USB_DEVICE(0x07B8,0x3071)}, /* AboCom */ \
47303 + {USB_DEVICE(0x07B8,0x2870)}, /* AboCom */ \
47304 + {USB_DEVICE(0x07B8,0x2770)}, /* AboCom */ \
47305 + {USB_DEVICE(0x7392,0x7711)}, /* Edimax */ \
47306 + {USB_DEVICE(0x5A57,0x0280)}, /* Zinwell */ \
47307 + {USB_DEVICE(0x5A57,0x0282)}, /* Zinwell */ \
47308 + {USB_DEVICE(0x0789,0x0162)}, /* Logitec */ \
47309 + {USB_DEVICE(0x0789,0x0163)}, /* Logitec */ \
47310 + {USB_DEVICE(0x0789,0x0164)}, /* Logitec */ \
47311 + { }/* Terminating entry */ \
47312 +}
47313 +
47314 +#define FREE_HTTX_RING(_p, _b, _t) \
47315 +{ \
47316 + if ((_t)->ENextBulkOutPosition == (_t)->CurWritePosition) \
47317 + { \
47318 + (_t)->bRingEmpty = TRUE; \
47319 + } \
47320 + /*NdisInterlockedDecrement(&(_p)->TxCount); */\
47321 +}
47322 +
47323 +//
47324 +// RXINFO appends at the end of each rx packet.
47325 +//
47326 +#ifdef RT_BIG_ENDIAN
47327 +typedef struct PACKED _RXINFO_STRUC {
47328 + UINT32 PlcpSignal:12;
47329 + UINT32 LastAMSDU:1;
47330 + UINT32 CipherAlg:1;
47331 + UINT32 PlcpRssil:1;
47332 + UINT32 Decrypted:1;
47333 + UINT32 AMPDU:1; // To be moved
47334 + UINT32 L2PAD:1;
47335 + UINT32 RSSI:1;
47336 + UINT32 HTC:1;
47337 + UINT32 AMSDU:1; // rx with 802.3 header, not 802.11 header.
47338 + UINT32 CipherErr:2; // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
47339 + UINT32 Crc:1; // 1: CRC error
47340 + UINT32 MyBss:1; // 1: this frame belongs to the same BSSID
47341 + UINT32 Bcast:1; // 1: this is a broadcast frame
47342 + UINT32 Mcast:1; // 1: this is a multicast frame
47343 + UINT32 U2M:1; // 1: this RX frame is unicast to me
47344 + UINT32 FRAG:1;
47345 + UINT32 NULLDATA:1;
47346 + UINT32 DATA:1;
47347 + UINT32 BA:1;
47348 +} RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
47349 +#else
47350 +typedef struct PACKED _RXINFO_STRUC {
47351 + UINT32 BA:1;
47352 + UINT32 DATA:1;
47353 + UINT32 NULLDATA:1;
47354 + UINT32 FRAG:1;
47355 + UINT32 U2M:1; // 1: this RX frame is unicast to me
47356 + UINT32 Mcast:1; // 1: this is a multicast frame
47357 + UINT32 Bcast:1; // 1: this is a broadcast frame
47358 + UINT32 MyBss:1; // 1: this frame belongs to the same BSSID
47359 + UINT32 Crc:1; // 1: CRC error
47360 + UINT32 CipherErr:2; // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
47361 + UINT32 AMSDU:1; // rx with 802.3 header, not 802.11 header.
47362 + UINT32 HTC:1;
47363 + UINT32 RSSI:1;
47364 + UINT32 L2PAD:1;
47365 + UINT32 AMPDU:1; // To be moved
47366 + UINT32 Decrypted:1;
47367 + UINT32 PlcpRssil:1;
47368 + UINT32 CipherAlg:1;
47369 + UINT32 LastAMSDU:1;
47370 + UINT32 PlcpSignal:12;
47371 +} RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
47372 +#endif
47373 +
47374 +
47375 +//
47376 +// TXINFO
47377 +//
47378 +#ifdef RT_BIG_ENDIAN
47379 +typedef struct _TXINFO_STRUC {
47380 + // Word 0
47381 + UINT32 USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
47382 + UINT32 USBDMANextVLD:1; //used ONLY in USB bulk Aggregation, NextValid
47383 + UINT32 rsv2:2; // Software use.
47384 + UINT32 SwUseLastRound:1; // Software use.
47385 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
47386 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
47387 + UINT32 rsv:8;
47388 + UINT32 USBDMATxPktLen:16; //used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame.
47389 +} TXINFO_STRUC, *PTXINFO_STRUC;
47390 +#else
47391 +typedef struct _TXINFO_STRUC {
47392 + // Word 0
47393 + UINT32 USBDMATxPktLen:16; //used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame.
47394 + UINT32 rsv:8;
47395 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
47396 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
47397 + UINT32 SwUseLastRound:1; // Software use.
47398 + UINT32 rsv2:2; // Software use.
47399 + UINT32 USBDMANextVLD:1; //used ONLY in USB bulk Aggregation, NextValid
47400 + UINT32 USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
47401 +} TXINFO_STRUC, *PTXINFO_STRUC;
47402 +#endif
47403 +
47404 +#define TXINFO_SIZE 4
47405 +#define RXINFO_SIZE 4
47406 +#define TXPADDING_SIZE 11
47407 +
47408 +//
47409 +// Management ring buffer format
47410 +//
47411 +typedef struct _MGMT_STRUC {
47412 + BOOLEAN Valid;
47413 + PUCHAR pBuffer;
47414 + ULONG Length;
47415 +} MGMT_STRUC, *PMGMT_STRUC;
47416 +
47417 +
47418 +/* ----------------- EEPROM Related MACRO ----------------- */
47419 +#define RT28xx_EEPROM_READ16(pAd, offset, var) \
47420 + do { \
47421 + RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2); \
47422 + var = le2cpu16(var); \
47423 + }while(0)
47424 +
47425 +#define RT28xx_EEPROM_WRITE16(pAd, offset, var) \
47426 + do{ \
47427 + USHORT _tmpVar; \
47428 + _tmpVar = cpu2le16(var); \
47429 + RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2); \
47430 + }while(0)
47431 +
47432 +/* ----------------- TASK/THREAD Related MACRO ----------------- */
47433 +#define RT28XX_TASK_THREAD_INIT(pAd, Status) \
47434 + Status = CreateThreads(net_dev);
47435 +
47436 +
47437 +/* ----------------- Frimware Related MACRO ----------------- */
47438 +#if 0
47439 +#define RT28XX_FIRMUD_INIT(pAd) \
47440 + { UINT32 MacReg; \
47441 + RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg); }
47442 +
47443 +#define RT28XX_FIRMUD_END(pAd) \
47444 + RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff); \
47445 + RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff); \
47446 + RTUSBFirmwareRun(pAd);
47447 +#else
47448 +#define RT28XX_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
47449 + RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
47450 +#endif
47451 +
47452 +/* ----------------- TX Related MACRO ----------------- */
47453 +#define RT28XX_START_DEQUEUE(pAd, QueIdx, irqFlags) \
47454 + { \
47455 + RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
47456 + if (pAd->DeQueueRunning[QueIdx]) \
47457 + { \
47458 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
47459 + printk("DeQueueRunning[%d]= TRUE!\n", QueIdx); \
47460 + continue; \
47461 + } \
47462 + else \
47463 + { \
47464 + pAd->DeQueueRunning[QueIdx] = TRUE; \
47465 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
47466 + } \
47467 + }
47468 +#define RT28XX_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
47469 + do{ \
47470 + RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
47471 + pAd->DeQueueRunning[QueIdx] = FALSE; \
47472 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
47473 + }while(0)
47474 +
47475 +
47476 +#define RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
47477 + (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
47478 +
47479 +#define RT28XX_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
47480 + do{}while(0)
47481 +
47482 +#define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
47483 + ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
47484 +
47485 +
47486 +
47487 +#define fRTMP_ADAPTER_NEED_STOP_TX \
47488 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
47489 + fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
47490 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
47491 +
47492 +
47493 +#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
47494 + RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
47495 +
47496 +#define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber) \
47497 + RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
47498 +
47499 +#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
47500 + RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
47501 +
47502 +#define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber) \
47503 + RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
47504 +
47505 +#define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
47506 + RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
47507 +
47508 +#define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
47509 + /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx)*/
47510 +
47511 +#define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
47512 + RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
47513 +
47514 +
47515 +#define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
47516 + RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
47517 +
47518 +#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
47519 + RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
47520 +
47521 +#define RTMP_PKT_TAIL_PADDING 11 // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
47522 +
47523 +extern UCHAR EpToQueue[6];
47524 +
47525 +
47526 +#ifdef RT2870
47527 +#define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
47528 +#define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
47529 +#endif // RT2870 //
47530 +
47531 +
47532 +/* ----------------- RX Related MACRO ----------------- */
47533 +//#define RT28XX_RX_ERROR_CHECK RTMPCheckRxWI
47534 +
47535 +#if 0
47536 +#define RT28XX_RCV_INIT(pAd) \
47537 + pAd->TransferBufferLength = 0; \
47538 + pAd->ReadPosition = 0; \
47539 + pAd->pCurrRxContext = NULL;
47540 +#endif
47541 +
47542 +#define RT28XX_RV_ALL_BUF_END(bBulkReceive) \
47543 + /* We return STATUS_MORE_PROCESSING_REQUIRED so that the completion */ \
47544 + /* routine (IofCompleteRequest) will stop working on the irp. */ \
47545 + if (bBulkReceive == TRUE) RTUSBBulkReceive(pAd);
47546 +
47547 +
47548 +/* ----------------- ASIC Related MACRO ----------------- */
47549 +#if 0
47550 +#define RT28XX_DMA_WRITE_INIT(GloCfg) \
47551 + { GloCfg.field.EnTXWriteBackDDONE = 1; \
47552 + GloCfg.field.EnableRxDMA = 1; \
47553 + GloCfg.field.EnableTxDMA = 1; }
47554 +
47555 +#define RT28XX_DMA_POST_WRITE(_pAd) \
47556 + do{ USB_DMA_CFG_STRUC UsbCfg; \
47557 + UsbCfg.word = 0; \
47558 + /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */ \
47559 + UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3; \
47560 + UsbCfg.field.phyclear = 0; \
47561 + /* usb version is 1.1,do not use bulk in aggregation */ \
47562 + if (_pAd->BulkInMaxPacketSize == 512) \
47563 + UsbCfg.field.RxBulkAggEn = 1; \
47564 + UsbCfg.field.RxBulkEn = 1; \
47565 + UsbCfg.field.TxBulkEn = 1; \
47566 + UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */ \
47567 + RTUSBWriteMACRegister(_pAd, USB_DMA_CFG, UsbCfg.word); \
47568 + }while(0)
47569 +#endif
47570 +
47571 +// reset MAC of a station entry to 0xFFFFFFFFFFFF
47572 +#define RT28XX_STA_ENTRY_MAC_RESET(pAd, Wcid) \
47573 + { RT_SET_ASIC_WCID SetAsicWcid; \
47574 + SetAsicWcid.WCID = Wcid; \
47575 + SetAsicWcid.SetTid = 0xffffffff; \
47576 + SetAsicWcid.DeleteTid = 0xffffffff; \
47577 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID, \
47578 + &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); }
47579 +
47580 +// add this entry into ASIC RX WCID search table
47581 +#define RT28XX_STA_ENTRY_ADD(pAd, pEntry) \
47582 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY, \
47583 + pEntry, sizeof(MAC_TABLE_ENTRY));
47584 +
47585 +// remove Pair-wise key material from ASIC
47586 +// yet implement
47587 +#define RT28XX_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid)
47588 +
47589 +// add Client security information into ASIC WCID table and IVEIV table
47590 +#define RT28XX_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \
47591 + { RT28XX_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid); \
47592 + if (pEntry->Aid >= 1) { \
47593 + RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri; \
47594 + SetAsicWcidAttri.WCID = pEntry->Aid; \
47595 + if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && \
47596 + (pEntry->WepStatus == Ndis802_11Encryption1Enabled)) \
47597 + { \
47598 + SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
47599 + } \
47600 + else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone) \
47601 + { \
47602 + SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
47603 + } \
47604 + else SetAsicWcidAttri.Cipher = 0; \
47605 + DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher)); \
47606 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER, \
47607 + &SetAsicWcidAttri, sizeof(RT_SET_ASIC_WCID_ATTRI)); } }
47608 +
47609 +// Insert the BA bitmap to ASIC for the Wcid entry
47610 +#define RT28XX_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \
47611 + do{ \
47612 + RT_SET_ASIC_WCID SetAsicWcid; \
47613 + SetAsicWcid.WCID = (_Aid); \
47614 + SetAsicWcid.SetTid = (0x10000<<(_TID)); \
47615 + SetAsicWcid.DeleteTid = 0xffffffff; \
47616 + RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); \
47617 + }while(0)
47618 +
47619 +// Remove the BA bitmap from ASIC for the Wcid entry
47620 +#define RT28XX_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \
47621 + do{ \
47622 + RT_SET_ASIC_WCID SetAsicWcid; \
47623 + SetAsicWcid.WCID = (_Wcid); \
47624 + SetAsicWcid.SetTid = (0xffffffff); \
47625 + SetAsicWcid.DeleteTid = (0x10000<<(_TID) ); \
47626 + RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); \
47627 + }while(0)
47628 +
47629 +
47630 +/* ----------------- PCI/USB Related MACRO ----------------- */
47631 +#define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p) \
47632 + ((POS_COOKIE)handle)->pUsb_Dev = dev_p;
47633 +
47634 +// no use
47635 +#define RT28XX_UNMAP()
47636 +#define RT28XX_IRQ_REQUEST(net_dev)
47637 +#define RT28XX_IRQ_RELEASE(net_dev)
47638 +#define RT28XX_IRQ_INIT(pAd)
47639 +#define RT28XX_IRQ_ENABLE(pAd)
47640 +
47641 +
47642 +/* ----------------- MLME Related MACRO ----------------- */
47643 +#define RT28XX_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
47644 +
47645 +#define RT28XX_MLME_PRE_SANITY_CHECK(pAd) \
47646 + { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \
47647 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \
47648 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \
47649 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
47650 +
47651 +#define RT28XX_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
47652 + { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
47653 + RTUSBMlmeUp(pAd); }
47654 +
47655 +#define RT28XX_MLME_RESET_STATE_MACHINE(pAd) \
47656 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
47657 + RTUSBMlmeUp(pAd);
47658 +
47659 +#define RT28XX_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
47660 + { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY)); \
47661 + RTUSBMlmeUp(_pAd); \
47662 + }
47663 +
47664 +
47665 +/* ----------------- Power Save Related MACRO ----------------- */
47666 +#define RT28XX_PS_POLL_ENQUEUE(pAd) \
47667 + { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
47668 + RTUSBKickBulkOut(pAd); }
47669 +
47670 +#define RT28xx_CHIP_NAME "RT2870"
47671 +#define USB_CYC_CFG 0x02a4
47672 +#define STATUS_SUCCESS 0x00
47673 +#define STATUS_UNSUCCESSFUL 0x01
47674 +#define NT_SUCCESS(status) (((status) > 0) ? (1):(0))
47675 +#define InterlockedIncrement atomic_inc
47676 +#define NdisInterlockedIncrement atomic_inc
47677 +#define InterlockedDecrement atomic_dec
47678 +#define NdisInterlockedDecrement atomic_dec
47679 +#define InterlockedExchange atomic_set
47680 +//#define NdisMSendComplete RTMP_SendComplete
47681 +#define NdisMCancelTimer RTMPCancelTimer
47682 +#define NdisAllocMemory(_ptr, _size, _flag) \
47683 + do{_ptr = kmalloc((_size),(_flag));}while(0)
47684 +#define NdisFreeMemory(a, b, c) kfree((a))
47685 +#define NdisMSleep RTMPusecDelay /* unit: microsecond */
47686 +
47687 +
47688 +#define USBD_TRANSFER_DIRECTION_OUT 0
47689 +#define USBD_TRANSFER_DIRECTION_IN 0
47690 +#define USBD_SHORT_TRANSFER_OK 0
47691 +#define PURB purbb_t
47692 +
47693 +#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb)
47694 +
47695 +//#undef MlmeAllocateMemory
47696 +//#undef MlmeFreeMemory
47697 +
47698 +typedef int NTSTATUS;
47699 +typedef struct usb_device * PUSB_DEV;
47700 +
47701 +/* MACRO for linux usb */
47702 +typedef struct urb *purbb_t;
47703 +typedef struct usb_ctrlrequest devctrlrequest;
47704 +#define PIRP PVOID
47705 +#define PMDL PVOID
47706 +#define NDIS_OID UINT
47707 +#ifndef USB_ST_NOERROR
47708 +#define USB_ST_NOERROR 0
47709 +#endif
47710 +
47711 +// vendor-specific control operations
47712 +#define CONTROL_TIMEOUT_JIFFIES ( (100 * HZ) / 1000)
47713 +#define UNLINK_TIMEOUT_MS 3
47714 +
47715 +/* unlink urb */
47716 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,7)
47717 +#define RTUSB_UNLINK_URB(pUrb) usb_kill_urb(pUrb)
47718 +#else
47719 +#define RTUSB_UNLINK_URB(pUrb) usb_unlink_urb(pUrb)
47720 +#endif
47721 +
47722 +// Prototypes of completion funuc.
47723 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
47724 +#define RTUSBBulkOutDataPacketComplete(purb, pt_regs) RTUSBBulkOutDataPacketComplete(purb)
47725 +#define RTUSBBulkOutMLMEPacketComplete(pUrb, pt_regs) RTUSBBulkOutMLMEPacketComplete(pUrb)
47726 +#define RTUSBBulkOutNullFrameComplete(pUrb, pt_regs) RTUSBBulkOutNullFrameComplete(pUrb)
47727 +#define RTUSBBulkOutRTSFrameComplete(pUrb, pt_regs) RTUSBBulkOutRTSFrameComplete(pUrb)
47728 +#define RTUSBBulkOutPsPollComplete(pUrb, pt_regs) RTUSBBulkOutPsPollComplete(pUrb)
47729 +#define RTUSBBulkRxComplete(pUrb, pt_regs) RTUSBBulkRxComplete(pUrb)
47730 +#endif
47731 +
47732 +
47733 +VOID RTUSBBulkOutDataPacketComplete(purbb_t purb, struct pt_regs *pt_regs);
47734 +VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs);
47735 +VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
47736 +VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
47737 +VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb, struct pt_regs *pt_regs);
47738 +VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs);
47739 +
47740 +
47741 +#define RTUSBMlmeUp(pAd) \
47742 +{ \
47743 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie; \
47744 + CHECK_PID_LEGALITY(pObj->MLMEThr_pid) \
47745 + up(&(pAd->mlme_semaphore)); \
47746 +}
47747 +
47748 +#define RTUSBCMDUp(pAd) \
47749 +{ \
47750 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie; \
47751 + CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid) \
47752 + up(&(pAd->RTUSBCmd_semaphore)); \
47753 +}
47754 +
47755 +
47756 +static inline NDIS_STATUS RTMPAllocateMemory(
47757 + OUT PVOID *ptr,
47758 + IN size_t size)
47759 +{
47760 + *ptr = kmalloc(size, GFP_ATOMIC);
47761 + if(*ptr)
47762 + return NDIS_STATUS_SUCCESS;
47763 + else
47764 + return NDIS_STATUS_RESOURCES;
47765 +}
47766 +
47767 +/* rtmp.h */
47768 +#define BEACON_RING_SIZE 2
47769 +#define DEVICE_VENDOR_REQUEST_OUT 0x40
47770 +#define DEVICE_VENDOR_REQUEST_IN 0xc0
47771 +#define INTERFACE_VENDOR_REQUEST_OUT 0x41
47772 +#define INTERFACE_VENDOR_REQUEST_IN 0xc1
47773 +#define MGMTPIPEIDX 0 // EP6 is highest priority
47774 +
47775 +#define BULKOUT_MGMT_RESET_FLAG 0x80
47776 +
47777 +#define RTUSB_SET_BULK_FLAG(_M, _F) ((_M)->BulkFlags |= (_F))
47778 +#define RTUSB_CLEAR_BULK_FLAG(_M, _F) ((_M)->BulkFlags &= ~(_F))
47779 +#define RTUSB_TEST_BULK_FLAG(_M, _F) (((_M)->BulkFlags & (_F)) != 0)
47780 +
47781 +#define EnqueueCmd(cmdq, cmdqelmt) \
47782 +{ \
47783 + if (cmdq->size == 0) \
47784 + cmdq->head = cmdqelmt; \
47785 + else \
47786 + cmdq->tail->next = cmdqelmt; \
47787 + cmdq->tail = cmdqelmt; \
47788 + cmdqelmt->next = NULL; \
47789 + cmdq->size++; \
47790 +}
47791 +
47792 +typedef struct _RT_SET_ASIC_WCID {
47793 + ULONG WCID; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
47794 + ULONG SetTid; // time-based: seconds, packet-based: kilo-packets
47795 + ULONG DeleteTid; // time-based: seconds, packet-based: kilo-packets
47796 + UCHAR Addr[MAC_ADDR_LEN]; // avoid in interrupt when write key
47797 +} RT_SET_ASIC_WCID,*PRT_SET_ASIC_WCID;
47798 +
47799 +typedef struct _RT_SET_ASIC_WCID_ATTRI {
47800 + ULONG WCID; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
47801 + ULONG Cipher; // ASIC Cipher definition
47802 + UCHAR Addr[ETH_LENGTH_OF_ADDRESS];
47803 +} RT_SET_ASIC_WCID_ATTRI,*PRT_SET_ASIC_WCID_ATTRI;
47804 +
47805 +typedef struct _MLME_MEMORY_STRUCT {
47806 + PVOID AllocVa; //Pointer to the base virtual address of the allocated memory
47807 + struct _MLME_MEMORY_STRUCT *Next; //Pointer to the next virtual address of the allocated memory
47808 +} MLME_MEMORY_STRUCT, *PMLME_MEMORY_STRUCT;
47809 +
47810 +typedef struct _MLME_MEMORY_HANDLER {
47811 + BOOLEAN MemRunning; //The flag of the Mlme memory handler's status
47812 + UINT MemoryCount; //Total nonpaged system-space memory not size
47813 + UINT InUseCount; //Nonpaged system-space memory in used counts
47814 + UINT UnUseCount; //Nonpaged system-space memory available counts
47815 + INT PendingCount; //Nonpaged system-space memory for free counts
47816 + PMLME_MEMORY_STRUCT pInUseHead; //Pointer to the first nonpaed memory not used
47817 + PMLME_MEMORY_STRUCT pInUseTail; //Pointer to the last nonpaged memory not used
47818 + PMLME_MEMORY_STRUCT pUnUseHead; //Pointer to the first nonpaged memory in used
47819 + PMLME_MEMORY_STRUCT pUnUseTail; //Pointer to the last nonpaged memory in used
47820 + PULONG MemFreePending[MAX_MLME_HANDLER_MEMORY]; //an array to keep pending free-memory's pointer (32bits)
47821 +} MLME_MEMORY_HANDLER, *PMLME_MEMORY_HANDLER;
47822 +
47823 +typedef struct _CmdQElmt {
47824 + UINT command;
47825 + PVOID buffer;
47826 + ULONG bufferlength;
47827 + BOOLEAN CmdFromNdis;
47828 + BOOLEAN SetOperation;
47829 + struct _CmdQElmt *next;
47830 +} CmdQElmt, *PCmdQElmt;
47831 +
47832 +typedef struct _CmdQ {
47833 + UINT size;
47834 + CmdQElmt *head;
47835 + CmdQElmt *tail;
47836 + UINT32 CmdQState;
47837 +}CmdQ, *PCmdQ;
47838 +
47839 +//
47840 +// For WPA SUPPLICANT: WIRELESS EXT support wireless events: v14 or newer
47841 +//
47842 +#if WIRELESS_EXT >= 14
47843 +//#define WPA_SUPPLICANT_SUPPORT 1
47844 +#endif
47845 +
47846 +/* oid.h */
47847 +// Cipher suite type for mixed mode group cipher, P802.11i-2004
47848 +typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
47849 + Cipher_Type_NONE,
47850 + Cipher_Type_WEP40,
47851 + Cipher_Type_TKIP,
47852 + Cipher_Type_RSVD,
47853 + Cipher_Type_CCMP,
47854 + Cipher_Type_WEP104
47855 +} RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
47856 +
47857 +//CMDTHREAD_MULTI_READ_MAC
47858 +//CMDTHREAD_MULTI_WRITE_MAC
47859 +//CMDTHREAD_VENDOR_EEPROM_READ
47860 +//CMDTHREAD_VENDOR_EEPROM_WRITE
47861 +typedef struct _CMDHandler_TLV {
47862 + USHORT Offset;
47863 + USHORT Length;
47864 + UCHAR DataFirst;
47865 +} CMDHandler_TLV, *PCMDHandler_TLV;
47866 +
47867 +// New for MeetingHouse Api support
47868 +#define CMDTHREAD_VENDOR_RESET 0x0D730101 // cmd
47869 +#define CMDTHREAD_VENDOR_UNPLUG 0x0D730102 // cmd
47870 +#define CMDTHREAD_VENDOR_SWITCH_FUNCTION 0x0D730103 // cmd
47871 +#define CMDTHREAD_MULTI_WRITE_MAC 0x0D730107 // cmd
47872 +#define CMDTHREAD_MULTI_READ_MAC 0x0D730108 // cmd
47873 +#define CMDTHREAD_VENDOR_EEPROM_WRITE 0x0D73010A // cmd
47874 +#define CMDTHREAD_VENDOR_EEPROM_READ 0x0D73010B // cmd
47875 +#define CMDTHREAD_VENDOR_ENTER_TESTMODE 0x0D73010C // cmd
47876 +#define CMDTHREAD_VENDOR_EXIT_TESTMODE 0x0D73010D // cmd
47877 +#define CMDTHREAD_VENDOR_WRITE_BBP 0x0D730119 // cmd
47878 +#define CMDTHREAD_VENDOR_READ_BBP 0x0D730118 // cmd
47879 +#define CMDTHREAD_VENDOR_WRITE_RF 0x0D73011A // cmd
47880 +#define CMDTHREAD_VENDOR_FLIP_IQ 0x0D73011D // cmd
47881 +#define CMDTHREAD_RESET_BULK_OUT 0x0D730210 // cmd
47882 +#define CMDTHREAD_RESET_BULK_IN 0x0D730211 // cmd
47883 +#define CMDTHREAD_SET_PSM_BIT_SAVE 0x0D730212 // cmd
47884 +#define CMDTHREAD_SET_RADIO 0x0D730214 // cmd
47885 +#define CMDTHREAD_UPDATE_TX_RATE 0x0D730216 // cmd
47886 +#define CMDTHREAD_802_11_ADD_KEY_WEP 0x0D730218 // cmd
47887 +#define CMDTHREAD_RESET_FROM_ERROR 0x0D73021A // cmd
47888 +#define CMDTHREAD_LINK_DOWN 0x0D73021B // cmd
47889 +#define CMDTHREAD_RESET_FROM_NDIS 0x0D73021C // cmd
47890 +#define CMDTHREAD_CHECK_GPIO 0x0D730215 // cmd
47891 +#define CMDTHREAD_FORCE_WAKE_UP 0x0D730222 // cmd
47892 +#define CMDTHREAD_SET_BW 0x0D730225 // cmd
47893 +#define CMDTHREAD_SET_ASIC_WCID 0x0D730226 // cmd
47894 +#define CMDTHREAD_SET_ASIC_WCID_CIPHER 0x0D730227 // cmd
47895 +#define CMDTHREAD_QKERIODIC_EXECUT 0x0D73023D // cmd
47896 +#define RT_CMD_SET_KEY_TABLE 0x0D730228 // cmd
47897 +#define RT_CMD_SET_RX_WCID_TABLE 0x0D730229 // cmd
47898 +#define CMDTHREAD_SET_CLIENT_MAC_ENTRY 0x0D73023E // cmd
47899 +#define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER 0x0D710105 // cmd
47900 +#define CMDTHREAD_802_11_SET_PHY_MODE 0x0D79010C // cmd
47901 +#define CMDTHREAD_802_11_SET_STA_CONFIG 0x0D790111 // cmd
47902 +#define CMDTHREAD_802_11_SET_PREAMBLE 0x0D790101 // cmd
47903 +#define CMDTHREAD_802_11_COUNTER_MEASURE 0x0D790102 // cmd
47904 +
47905 +
47906 +#define WPA1AKMBIT 0x01
47907 +#define WPA2AKMBIT 0x02
47908 +#define WPA1PSKAKMBIT 0x04
47909 +#define WPA2PSKAKMBIT 0x08
47910 +#define TKIPBIT 0x01
47911 +#define CCMPBIT 0x02
47912 +
47913 +
47914 +#define RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx) \
47915 + RT28xxUsbStaAsicForceWakeup(pAd, bFromTx);
47916 +
47917 +#define RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
47918 + RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
47919 +
47920 +#define RT28XX_MLME_RADIO_ON(pAd) \
47921 + RT28xxUsbMlmeRadioOn(pAd);
47922 +
47923 +#define RT28XX_MLME_RADIO_OFF(pAd) \
47924 + RT28xxUsbMlmeRadioOFF(pAd);
47925 +
47926 +#endif //__RT2870_H__
47927 --- /dev/null
47928 +++ b/drivers/staging/rt2870/rt28xx.h
47929 @@ -0,0 +1,2689 @@
47930 +/*
47931 + *************************************************************************
47932 + * Ralink Tech Inc.
47933 + * 5F., No.36, Taiyuan St., Jhubei City,
47934 + * Hsinchu County 302,
47935 + * Taiwan, R.O.C.
47936 + *
47937 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
47938 + *
47939 + * This program is free software; you can redistribute it and/or modify *
47940 + * it under the terms of the GNU General Public License as published by *
47941 + * the Free Software Foundation; either version 2 of the License, or *
47942 + * (at your option) any later version. *
47943 + * *
47944 + * This program is distributed in the hope that it will be useful, *
47945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
47946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
47947 + * GNU General Public License for more details. *
47948 + * *
47949 + * You should have received a copy of the GNU General Public License *
47950 + * along with this program; if not, write to the *
47951 + * Free Software Foundation, Inc., *
47952 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
47953 + * *
47954 + *************************************************************************
47955 +
47956 + Module Name:
47957 + rt28xx.h
47958 +
47959 + Abstract:
47960 + RT28xx ASIC related definition & structures
47961 +
47962 + Revision History:
47963 + Who When What
47964 + -------- ---------- ----------------------------------------------
47965 + Jan Lee Jan-3-2006 created for RT2860c
47966 +*/
47967 +
47968 +#ifndef __RT28XX_H__
47969 +#define __RT28XX_H__
47970 +
47971 +
47972 +//
47973 +// PCI registers - base address 0x0000
47974 +//
47975 +#define PCI_CFG 0x0000
47976 +#define PCI_EECTRL 0x0004
47977 +#define PCI_MCUCTRL 0x0008
47978 +
47979 +//
47980 +// SCH/DMA registers - base address 0x0200
47981 +//
47982 +// INT_SOURCE_CSR: Interrupt source register. Write one to clear corresponding bit
47983 +//
47984 +#define DMA_CSR0 0x200
47985 +#define INT_SOURCE_CSR 0x200
47986 +#ifdef RT_BIG_ENDIAN
47987 +typedef union _INT_SOURCE_CSR_STRUC {
47988 + struct {
47989 + UINT32 :14;
47990 + UINT32 TxCoherent:1;
47991 + UINT32 RxCoherent:1;
47992 + UINT32 GPTimer:1;
47993 + UINT32 AutoWakeup:1;//bit14
47994 + UINT32 TXFifoStatusInt:1;//FIFO Statistics is full, sw should read 0x171c
47995 + UINT32 PreTBTT:1;
47996 + UINT32 TBTTInt:1;
47997 + UINT32 RxTxCoherent:1;
47998 + UINT32 MCUCommandINT:1;
47999 + UINT32 MgmtDmaDone:1;
48000 + UINT32 HccaDmaDone:1;
48001 + UINT32 Ac3DmaDone:1;
48002 + UINT32 Ac2DmaDone:1;
48003 + UINT32 Ac1DmaDone:1;
48004 + UINT32 Ac0DmaDone:1;
48005 + UINT32 RxDone:1;
48006 + UINT32 TxDelayINT:1; //delayed interrupt, not interrupt until several int or time limit hit
48007 + UINT32 RxDelayINT:1; //dealyed interrupt
48008 + } field;
48009 + UINT32 word;
48010 +} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC;
48011 +#else
48012 +typedef union _INT_SOURCE_CSR_STRUC {
48013 + struct {
48014 + UINT32 RxDelayINT:1;
48015 + UINT32 TxDelayINT:1;
48016 + UINT32 RxDone:1;
48017 + UINT32 Ac0DmaDone:1;//4
48018 + UINT32 Ac1DmaDone:1;
48019 + UINT32 Ac2DmaDone:1;
48020 + UINT32 Ac3DmaDone:1;
48021 + UINT32 HccaDmaDone:1; // bit7
48022 + UINT32 MgmtDmaDone:1;
48023 + UINT32 MCUCommandINT:1;//bit 9
48024 + UINT32 RxTxCoherent:1;
48025 + UINT32 TBTTInt:1;
48026 + UINT32 PreTBTT:1;
48027 + UINT32 TXFifoStatusInt:1;//FIFO Statistics is full, sw should read 0x171c
48028 + UINT32 AutoWakeup:1;//bit14
48029 + UINT32 GPTimer:1;
48030 + UINT32 RxCoherent:1;//bit16
48031 + UINT32 TxCoherent:1;
48032 + UINT32 :14;
48033 + } field;
48034 + UINT32 word;
48035 +} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC;
48036 +#endif
48037 +
48038 +//
48039 +// INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF
48040 +//
48041 +#define INT_MASK_CSR 0x204
48042 +#ifdef RT_BIG_ENDIAN
48043 +typedef union _INT_MASK_CSR_STRUC {
48044 + struct {
48045 + UINT32 TxCoherent:1;
48046 + UINT32 RxCoherent:1;
48047 + UINT32 :20;
48048 + UINT32 MCUCommandINT:1;
48049 + UINT32 MgmtDmaDone:1;
48050 + UINT32 HccaDmaDone:1;
48051 + UINT32 Ac3DmaDone:1;
48052 + UINT32 Ac2DmaDone:1;
48053 + UINT32 Ac1DmaDone:1;
48054 + UINT32 Ac0DmaDone:1;
48055 + UINT32 RxDone:1;
48056 + UINT32 TxDelay:1;
48057 + UINT32 RXDelay_INT_MSK:1;
48058 + } field;
48059 + UINT32 word;
48060 +}INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC;
48061 +#else
48062 +typedef union _INT_MASK_CSR_STRUC {
48063 + struct {
48064 + UINT32 RXDelay_INT_MSK:1;
48065 + UINT32 TxDelay:1;
48066 + UINT32 RxDone:1;
48067 + UINT32 Ac0DmaDone:1;
48068 + UINT32 Ac1DmaDone:1;
48069 + UINT32 Ac2DmaDone:1;
48070 + UINT32 Ac3DmaDone:1;
48071 + UINT32 HccaDmaDone:1;
48072 + UINT32 MgmtDmaDone:1;
48073 + UINT32 MCUCommandINT:1;
48074 + UINT32 :20;
48075 + UINT32 RxCoherent:1;
48076 + UINT32 TxCoherent:1;
48077 + } field;
48078 + UINT32 word;
48079 +} INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC;
48080 +#endif
48081 +#define WPDMA_GLO_CFG 0x208
48082 +#ifdef RT_BIG_ENDIAN
48083 +typedef union _WPDMA_GLO_CFG_STRUC {
48084 + struct {
48085 + UINT32 HDR_SEG_LEN:16;
48086 + UINT32 RXHdrScater:8;
48087 + UINT32 BigEndian:1;
48088 + UINT32 EnTXWriteBackDDONE:1;
48089 + UINT32 WPDMABurstSIZE:2;
48090 + UINT32 RxDMABusy:1;
48091 + UINT32 EnableRxDMA:1;
48092 + UINT32 TxDMABusy:1;
48093 + UINT32 EnableTxDMA:1;
48094 + } field;
48095 + UINT32 word;
48096 +}WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC;
48097 +#else
48098 +typedef union _WPDMA_GLO_CFG_STRUC {
48099 + struct {
48100 + UINT32 EnableTxDMA:1;
48101 + UINT32 TxDMABusy:1;
48102 + UINT32 EnableRxDMA:1;
48103 + UINT32 RxDMABusy:1;
48104 + UINT32 WPDMABurstSIZE:2;
48105 + UINT32 EnTXWriteBackDDONE:1;
48106 + UINT32 BigEndian:1;
48107 + UINT32 RXHdrScater:8;
48108 + UINT32 HDR_SEG_LEN:16;
48109 + } field;
48110 + UINT32 word;
48111 +} WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC;
48112 +#endif
48113 +#define WPDMA_RST_IDX 0x20c
48114 +#ifdef RT_BIG_ENDIAN
48115 +typedef union _WPDMA_RST_IDX_STRUC {
48116 + struct {
48117 + UINT32 :15;
48118 + UINT32 RST_DRX_IDX0:1;
48119 + UINT32 rsv:10;
48120 + UINT32 RST_DTX_IDX5:1;
48121 + UINT32 RST_DTX_IDX4:1;
48122 + UINT32 RST_DTX_IDX3:1;
48123 + UINT32 RST_DTX_IDX2:1;
48124 + UINT32 RST_DTX_IDX1:1;
48125 + UINT32 RST_DTX_IDX0:1;
48126 + } field;
48127 + UINT32 word;
48128 +}WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC;
48129 +#else
48130 +typedef union _WPDMA_RST_IDX_STRUC {
48131 + struct {
48132 + UINT32 RST_DTX_IDX0:1;
48133 + UINT32 RST_DTX_IDX1:1;
48134 + UINT32 RST_DTX_IDX2:1;
48135 + UINT32 RST_DTX_IDX3:1;
48136 + UINT32 RST_DTX_IDX4:1;
48137 + UINT32 RST_DTX_IDX5:1;
48138 + UINT32 rsv:10;
48139 + UINT32 RST_DRX_IDX0:1;
48140 + UINT32 :15;
48141 + } field;
48142 + UINT32 word;
48143 +} WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC;
48144 +#endif
48145 +#define DELAY_INT_CFG 0x0210
48146 +#ifdef RT_BIG_ENDIAN
48147 +typedef union _DELAY_INT_CFG_STRUC {
48148 + struct {
48149 + UINT32 TXDLY_INT_EN:1;
48150 + UINT32 TXMAX_PINT:7;
48151 + UINT32 TXMAX_PTIME:8;
48152 + UINT32 RXDLY_INT_EN:1;
48153 + UINT32 RXMAX_PINT:7;
48154 + UINT32 RXMAX_PTIME:8;
48155 + } field;
48156 + UINT32 word;
48157 +}DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC;
48158 +#else
48159 +typedef union _DELAY_INT_CFG_STRUC {
48160 + struct {
48161 + UINT32 RXMAX_PTIME:8;
48162 + UINT32 RXMAX_PINT:7;
48163 + UINT32 RXDLY_INT_EN:1;
48164 + UINT32 TXMAX_PTIME:8;
48165 + UINT32 TXMAX_PINT:7;
48166 + UINT32 TXDLY_INT_EN:1;
48167 + } field;
48168 + UINT32 word;
48169 +} DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC;
48170 +#endif
48171 +#define WMM_AIFSN_CFG 0x0214
48172 +#ifdef RT_BIG_ENDIAN
48173 +typedef union _AIFSN_CSR_STRUC {
48174 + struct {
48175 + UINT32 Rsv:16;
48176 + UINT32 Aifsn3:4; // for AC_VO
48177 + UINT32 Aifsn2:4; // for AC_VI
48178 + UINT32 Aifsn1:4; // for AC_BK
48179 + UINT32 Aifsn0:4; // for AC_BE
48180 + } field;
48181 + UINT32 word;
48182 +} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC;
48183 +#else
48184 +typedef union _AIFSN_CSR_STRUC {
48185 + struct {
48186 + UINT32 Aifsn0:4; // for AC_BE
48187 + UINT32 Aifsn1:4; // for AC_BK
48188 + UINT32 Aifsn2:4; // for AC_VI
48189 + UINT32 Aifsn3:4; // for AC_VO
48190 + UINT32 Rsv:16;
48191 + } field;
48192 + UINT32 word;
48193 +} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC;
48194 +#endif
48195 +//
48196 +// CWMIN_CSR: CWmin for each EDCA AC
48197 +//
48198 +#define WMM_CWMIN_CFG 0x0218
48199 +#ifdef RT_BIG_ENDIAN
48200 +typedef union _CWMIN_CSR_STRUC {
48201 + struct {
48202 + UINT32 Rsv:16;
48203 + UINT32 Cwmin3:4; // for AC_VO
48204 + UINT32 Cwmin2:4; // for AC_VI
48205 + UINT32 Cwmin1:4; // for AC_BK
48206 + UINT32 Cwmin0:4; // for AC_BE
48207 + } field;
48208 + UINT32 word;
48209 +} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC;
48210 +#else
48211 +typedef union _CWMIN_CSR_STRUC {
48212 + struct {
48213 + UINT32 Cwmin0:4; // for AC_BE
48214 + UINT32 Cwmin1:4; // for AC_BK
48215 + UINT32 Cwmin2:4; // for AC_VI
48216 + UINT32 Cwmin3:4; // for AC_VO
48217 + UINT32 Rsv:16;
48218 + } field;
48219 + UINT32 word;
48220 +} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC;
48221 +#endif
48222 +
48223 +//
48224 +// CWMAX_CSR: CWmin for each EDCA AC
48225 +//
48226 +#define WMM_CWMAX_CFG 0x021c
48227 +#ifdef RT_BIG_ENDIAN
48228 +typedef union _CWMAX_CSR_STRUC {
48229 + struct {
48230 + UINT32 Rsv:16;
48231 + UINT32 Cwmax3:4; // for AC_VO
48232 + UINT32 Cwmax2:4; // for AC_VI
48233 + UINT32 Cwmax1:4; // for AC_BK
48234 + UINT32 Cwmax0:4; // for AC_BE
48235 + } field;
48236 + UINT32 word;
48237 +} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC;
48238 +#else
48239 +typedef union _CWMAX_CSR_STRUC {
48240 + struct {
48241 + UINT32 Cwmax0:4; // for AC_BE
48242 + UINT32 Cwmax1:4; // for AC_BK
48243 + UINT32 Cwmax2:4; // for AC_VI
48244 + UINT32 Cwmax3:4; // for AC_VO
48245 + UINT32 Rsv:16;
48246 + } field;
48247 + UINT32 word;
48248 +} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC;
48249 +#endif
48250 +
48251 +
48252 +//
48253 +// AC_TXOP_CSR0: AC_BK/AC_BE TXOP register
48254 +//
48255 +#define WMM_TXOP0_CFG 0x0220
48256 +#ifdef RT_BIG_ENDIAN
48257 +typedef union _AC_TXOP_CSR0_STRUC {
48258 + struct {
48259 + USHORT Ac1Txop; // for AC_BE, in unit of 32us
48260 + USHORT Ac0Txop; // for AC_BK, in unit of 32us
48261 + } field;
48262 + UINT32 word;
48263 +} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC;
48264 +#else
48265 +typedef union _AC_TXOP_CSR0_STRUC {
48266 + struct {
48267 + USHORT Ac0Txop; // for AC_BK, in unit of 32us
48268 + USHORT Ac1Txop; // for AC_BE, in unit of 32us
48269 + } field;
48270 + UINT32 word;
48271 +} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC;
48272 +#endif
48273 +
48274 +//
48275 +// AC_TXOP_CSR1: AC_VO/AC_VI TXOP register
48276 +//
48277 +#define WMM_TXOP1_CFG 0x0224
48278 +#ifdef RT_BIG_ENDIAN
48279 +typedef union _AC_TXOP_CSR1_STRUC {
48280 + struct {
48281 + USHORT Ac3Txop; // for AC_VO, in unit of 32us
48282 + USHORT Ac2Txop; // for AC_VI, in unit of 32us
48283 + } field;
48284 + UINT32 word;
48285 +} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC;
48286 +#else
48287 +typedef union _AC_TXOP_CSR1_STRUC {
48288 + struct {
48289 + USHORT Ac2Txop; // for AC_VI, in unit of 32us
48290 + USHORT Ac3Txop; // for AC_VO, in unit of 32us
48291 + } field;
48292 + UINT32 word;
48293 +} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC;
48294 +#endif
48295 +#define RINGREG_DIFF 0x10
48296 +#define GPIO_CTRL_CFG 0x0228 //MAC_CSR13
48297 +#define MCU_CMD_CFG 0x022c
48298 +#define TX_BASE_PTR0 0x0230 //AC_BK base address
48299 +#define TX_MAX_CNT0 0x0234
48300 +#define TX_CTX_IDX0 0x0238
48301 +#define TX_DTX_IDX0 0x023c
48302 +#define TX_BASE_PTR1 0x0240 //AC_BE base address
48303 +#define TX_MAX_CNT1 0x0244
48304 +#define TX_CTX_IDX1 0x0248
48305 +#define TX_DTX_IDX1 0x024c
48306 +#define TX_BASE_PTR2 0x0250 //AC_VI base address
48307 +#define TX_MAX_CNT2 0x0254
48308 +#define TX_CTX_IDX2 0x0258
48309 +#define TX_DTX_IDX2 0x025c
48310 +#define TX_BASE_PTR3 0x0260 //AC_VO base address
48311 +#define TX_MAX_CNT3 0x0264
48312 +#define TX_CTX_IDX3 0x0268
48313 +#define TX_DTX_IDX3 0x026c
48314 +#define TX_BASE_PTR4 0x0270 //HCCA base address
48315 +#define TX_MAX_CNT4 0x0274
48316 +#define TX_CTX_IDX4 0x0278
48317 +#define TX_DTX_IDX4 0x027c
48318 +#define TX_BASE_PTR5 0x0280 //MGMT base address
48319 +#define TX_MAX_CNT5 0x0284
48320 +#define TX_CTX_IDX5 0x0288
48321 +#define TX_DTX_IDX5 0x028c
48322 +#define TX_MGMTMAX_CNT TX_MAX_CNT5
48323 +#define TX_MGMTCTX_IDX TX_CTX_IDX5
48324 +#define TX_MGMTDTX_IDX TX_DTX_IDX5
48325 +#define RX_BASE_PTR 0x0290 //RX base address
48326 +#define RX_MAX_CNT 0x0294
48327 +#define RX_CRX_IDX 0x0298
48328 +#define RX_DRX_IDX 0x029c
48329 +#define USB_DMA_CFG 0x02a0
48330 +#ifdef RT_BIG_ENDIAN
48331 +typedef union _USB_DMA_CFG_STRUC {
48332 + struct {
48333 + UINT32 TxBusy:1; //USB DMA TX FSM busy . debug only
48334 + UINT32 RxBusy:1; //USB DMA RX FSM busy . debug only
48335 + UINT32 EpoutValid:6; //OUT endpoint data valid. debug only
48336 + UINT32 TxBulkEn:1; //Enable USB DMA Tx
48337 + UINT32 RxBulkEn:1; //Enable USB DMA Rx
48338 + UINT32 RxBulkAggEn:1; //Enable Rx Bulk Aggregation
48339 + UINT32 TxopHalt:1; //Halt TXOP count down when TX buffer is full.
48340 + UINT32 TxClear:1; //Clear USB DMA TX path
48341 + UINT32 rsv:2;
48342 + UINT32 phyclear:1; //phy watch dog enable. write 1
48343 + UINT32 RxBulkAggLmt:8; //Rx Bulk Aggregation Limit in unit of 1024 bytes
48344 + UINT32 RxBulkAggTOut:8; //Rx Bulk Aggregation TimeOut in unit of 33ns
48345 + } field;
48346 + UINT32 word;
48347 +} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC;
48348 +#else
48349 +typedef union _USB_DMA_CFG_STRUC {
48350 + struct {
48351 + UINT32 RxBulkAggTOut:8; //Rx Bulk Aggregation TimeOut in unit of 33ns
48352 + UINT32 RxBulkAggLmt:8; //Rx Bulk Aggregation Limit in unit of 256 bytes
48353 + UINT32 phyclear:1; //phy watch dog enable. write 1
48354 + UINT32 rsv:2;
48355 + UINT32 TxClear:1; //Clear USB DMA TX path
48356 + UINT32 TxopHalt:1; //Halt TXOP count down when TX buffer is full.
48357 + UINT32 RxBulkAggEn:1; //Enable Rx Bulk Aggregation
48358 + UINT32 RxBulkEn:1; //Enable USB DMA Rx
48359 + UINT32 TxBulkEn:1; //Enable USB DMA Tx
48360 + UINT32 EpoutValid:6; //OUT endpoint data valid
48361 + UINT32 RxBusy:1; //USB DMA RX FSM busy
48362 + UINT32 TxBusy:1; //USB DMA TX FSM busy
48363 + } field;
48364 + UINT32 word;
48365 +} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC;
48366 +#endif
48367 +
48368 +//
48369 +// 3 PBF registers
48370 +//
48371 +//
48372 +// Most are for debug. Driver doesn't touch PBF register.
48373 +#define PBF_SYS_CTRL 0x0400
48374 +#define PBF_CFG 0x0408
48375 +#define PBF_MAX_PCNT 0x040C
48376 +#define PBF_CTRL 0x0410
48377 +#define PBF_INT_STA 0x0414
48378 +#define PBF_INT_ENA 0x0418
48379 +#define TXRXQ_PCNT 0x0438
48380 +#define PBF_DBG 0x043c
48381 +#define PBF_CAP_CTRL 0x0440
48382 +
48383 +//
48384 +// 4 MAC registers
48385 +//
48386 +//
48387 +// 4.1 MAC SYSTEM configuration registers (offset:0x1000)
48388 +//
48389 +#define MAC_CSR0 0x1000
48390 +#ifdef RT_BIG_ENDIAN
48391 +typedef union _ASIC_VER_ID_STRUC {
48392 + struct {
48393 + USHORT ASICVer; // version : 2860
48394 + USHORT ASICRev; // reversion : 0
48395 + } field;
48396 + UINT32 word;
48397 +} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC;
48398 +#else
48399 +typedef union _ASIC_VER_ID_STRUC {
48400 + struct {
48401 + USHORT ASICRev; // reversion : 0
48402 + USHORT ASICVer; // version : 2860
48403 + } field;
48404 + UINT32 word;
48405 +} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC;
48406 +#endif
48407 +#define MAC_SYS_CTRL 0x1004 //MAC_CSR1
48408 +#define MAC_ADDR_DW0 0x1008 // MAC ADDR DW0
48409 +#define MAC_ADDR_DW1 0x100c // MAC ADDR DW1
48410 +//
48411 +// MAC_CSR2: STA MAC register 0
48412 +//
48413 +#ifdef RT_BIG_ENDIAN
48414 +typedef union _MAC_DW0_STRUC {
48415 + struct {
48416 + UCHAR Byte3; // MAC address byte 3
48417 + UCHAR Byte2; // MAC address byte 2
48418 + UCHAR Byte1; // MAC address byte 1
48419 + UCHAR Byte0; // MAC address byte 0
48420 + } field;
48421 + UINT32 word;
48422 +} MAC_DW0_STRUC, *PMAC_DW0_STRUC;
48423 +#else
48424 +typedef union _MAC_DW0_STRUC {
48425 + struct {
48426 + UCHAR Byte0; // MAC address byte 0
48427 + UCHAR Byte1; // MAC address byte 1
48428 + UCHAR Byte2; // MAC address byte 2
48429 + UCHAR Byte3; // MAC address byte 3
48430 + } field;
48431 + UINT32 word;
48432 +} MAC_DW0_STRUC, *PMAC_DW0_STRUC;
48433 +#endif
48434 +
48435 +//
48436 +// MAC_CSR3: STA MAC register 1
48437 +//
48438 +#ifdef RT_BIG_ENDIAN
48439 +typedef union _MAC_DW1_STRUC {
48440 + struct {
48441 + UCHAR Rsvd1;
48442 + UCHAR U2MeMask;
48443 + UCHAR Byte5; // MAC address byte 5
48444 + UCHAR Byte4; // MAC address byte 4
48445 + } field;
48446 + UINT32 word;
48447 +} MAC_DW1_STRUC, *PMAC_DW1_STRUC;
48448 +#else
48449 +typedef union _MAC_DW1_STRUC {
48450 + struct {
48451 + UCHAR Byte4; // MAC address byte 4
48452 + UCHAR Byte5; // MAC address byte 5
48453 + UCHAR U2MeMask;
48454 + UCHAR Rsvd1;
48455 + } field;
48456 + UINT32 word;
48457 +} MAC_DW1_STRUC, *PMAC_DW1_STRUC;
48458 +#endif
48459 +
48460 +#define MAC_BSSID_DW0 0x1010 // MAC BSSID DW0
48461 +#define MAC_BSSID_DW1 0x1014 // MAC BSSID DW1
48462 +
48463 +//
48464 +// MAC_CSR5: BSSID register 1
48465 +//
48466 +#ifdef RT_BIG_ENDIAN
48467 +typedef union _MAC_CSR5_STRUC {
48468 + struct {
48469 + USHORT Rsvd:11;
48470 + USHORT MBssBcnNum:3;
48471 + USHORT BssIdMode:2; // 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID
48472 + UCHAR Byte5; // BSSID byte 5
48473 + UCHAR Byte4; // BSSID byte 4
48474 + } field;
48475 + UINT32 word;
48476 +} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC;
48477 +#else
48478 +typedef union _MAC_CSR5_STRUC {
48479 + struct {
48480 + UCHAR Byte4; // BSSID byte 4
48481 + UCHAR Byte5; // BSSID byte 5
48482 + USHORT BssIdMask:2; // 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID
48483 + USHORT MBssBcnNum:3;
48484 + USHORT Rsvd:11;
48485 + } field;
48486 + UINT32 word;
48487 +} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC;
48488 +#endif
48489 +
48490 +#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
48491 +#define BBP_CSR_CFG 0x101c //
48492 +//
48493 +// BBP_CSR_CFG: BBP serial control register
48494 +//
48495 +#ifdef RT_BIG_ENDIAN
48496 +typedef union _BBP_CSR_CFG_STRUC {
48497 + struct {
48498 + UINT32 :12;
48499 + UINT32 BBP_RW_MODE:1; // 0: use serial mode 1:parallel
48500 + UINT32 BBP_PAR_DUR:1; // 0: 4 MAC clock cycles 1: 8 MAC clock cycles
48501 + UINT32 Busy:1; // 1: ASIC is busy execute BBP programming.
48502 + UINT32 fRead:1; // 0: Write BBP, 1: Read BBP
48503 + UINT32 RegNum:8; // Selected BBP register
48504 + UINT32 Value:8; // Register value to program into BBP
48505 + } field;
48506 + UINT32 word;
48507 +} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC;
48508 +#else
48509 +typedef union _BBP_CSR_CFG_STRUC {
48510 + struct {
48511 + UINT32 Value:8; // Register value to program into BBP
48512 + UINT32 RegNum:8; // Selected BBP register
48513 + UINT32 fRead:1; // 0: Write BBP, 1: Read BBP
48514 + UINT32 Busy:1; // 1: ASIC is busy execute BBP programming.
48515 + UINT32 BBP_PAR_DUR:1; // 0: 4 MAC clock cycles 1: 8 MAC clock cycles
48516 + UINT32 BBP_RW_MODE:1; // 0: use serial mode 1:parallel
48517 + UINT32 :12;
48518 + } field;
48519 + UINT32 word;
48520 +} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC;
48521 +#endif
48522 +#define RF_CSR_CFG0 0x1020
48523 +//
48524 +// RF_CSR_CFG: RF control register
48525 +//
48526 +#ifdef RT_BIG_ENDIAN
48527 +typedef union _RF_CSR_CFG0_STRUC {
48528 + struct {
48529 + UINT32 Busy:1; // 0: idle 1: 8busy
48530 + UINT32 Sel:1; // 0:RF_LE0 activate 1:RF_LE1 activate
48531 + UINT32 StandbyMode:1; // 0: high when stand by 1: low when standby
48532 + UINT32 bitwidth:5; // Selected BBP register
48533 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48534 + } field;
48535 + UINT32 word;
48536 +} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC;
48537 +#else
48538 +typedef union _RF_CSR_CFG0_STRUC {
48539 + struct {
48540 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48541 + UINT32 bitwidth:5; // Selected BBP register
48542 + UINT32 StandbyMode:1; // 0: high when stand by 1: low when standby
48543 + UINT32 Sel:1; // 0:RF_LE0 activate 1:RF_LE1 activate
48544 + UINT32 Busy:1; // 0: idle 1: 8busy
48545 + } field;
48546 + UINT32 word;
48547 +} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC;
48548 +#endif
48549 +#define RF_CSR_CFG1 0x1024
48550 +#ifdef RT_BIG_ENDIAN
48551 +typedef union _RF_CSR_CFG1_STRUC {
48552 + struct {
48553 + UINT32 rsv:7; // 0: idle 1: 8busy
48554 + 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)
48555 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48556 + } field;
48557 + UINT32 word;
48558 +} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC;
48559 +#else
48560 +typedef union _RF_CSR_CFG1_STRUC {
48561 + struct {
48562 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48563 + 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)
48564 + UINT32 rsv:7; // 0: idle 1: 8busy
48565 + } field;
48566 + UINT32 word;
48567 +} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC;
48568 +#endif
48569 +#define RF_CSR_CFG2 0x1028 //
48570 +#ifdef RT_BIG_ENDIAN
48571 +typedef union _RF_CSR_CFG2_STRUC {
48572 + struct {
48573 + UINT32 rsv:8; // 0: idle 1: 8busy
48574 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48575 + } field;
48576 + UINT32 word;
48577 +} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC;
48578 +#else
48579 +typedef union _RF_CSR_CFG2_STRUC {
48580 + struct {
48581 + UINT32 RegIdAndContent:24; // Register value to program into BBP
48582 + UINT32 rsv:8; // 0: idle 1: 8busy
48583 + } field;
48584 + UINT32 word;
48585 +} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC;
48586 +#endif
48587 +#define LED_CFG 0x102c // MAC_CSR14
48588 +#ifdef RT_BIG_ENDIAN
48589 +typedef union _LED_CFG_STRUC {
48590 + struct {
48591 + UINT32 :1;
48592 + UINT32 LedPolar:1; // Led Polarity. 0: active low1: active high
48593 + UINT32 YLedMode:2; // yellow Led Mode
48594 + UINT32 GLedMode:2; // green Led Mode
48595 + UINT32 RLedMode:2; // red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on
48596 + UINT32 rsv:2;
48597 + UINT32 SlowBlinkPeriod:6; // slow blinking period. unit:1ms
48598 + UINT32 OffPeriod:8; // blinking off period unit 1ms
48599 + UINT32 OnPeriod:8; // blinking on period unit 1ms
48600 + } field;
48601 + UINT32 word;
48602 +} LED_CFG_STRUC, *PLED_CFG_STRUC;
48603 +#else
48604 +typedef union _LED_CFG_STRUC {
48605 + struct {
48606 + UINT32 OnPeriod:8; // blinking on period unit 1ms
48607 + UINT32 OffPeriod:8; // blinking off period unit 1ms
48608 + UINT32 SlowBlinkPeriod:6; // slow blinking period. unit:1ms
48609 + UINT32 rsv:2;
48610 + UINT32 RLedMode:2; // red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on
48611 + UINT32 GLedMode:2; // green Led Mode
48612 + UINT32 YLedMode:2; // yellow Led Mode
48613 + UINT32 LedPolar:1; // Led Polarity. 0: active low1: active high
48614 + UINT32 :1;
48615 + } field;
48616 + UINT32 word;
48617 +} LED_CFG_STRUC, *PLED_CFG_STRUC;
48618 +#endif
48619 +//
48620 +// 4.2 MAC TIMING configuration registers (offset:0x1100)
48621 +//
48622 +#define XIFS_TIME_CFG 0x1100 // MAC_CSR8 MAC_CSR9
48623 +#ifdef RT_BIG_ENDIAN
48624 +typedef union _IFS_SLOT_CFG_STRUC {
48625 + struct {
48626 + UINT32 rsv:2;
48627 + UINT32 BBRxendEnable:1; // reference RXEND signal to begin XIFS defer
48628 + UINT32 EIFS:9; // unit 1us
48629 + UINT32 OfdmXifsTime:4; //OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND
48630 + UINT32 OfdmSifsTime:8; // unit 1us. Applied after OFDM RX/TX
48631 + UINT32 CckmSifsTime:8; // unit 1us. Applied after CCK RX/TX
48632 + } field;
48633 + UINT32 word;
48634 +} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC;
48635 +#else
48636 +typedef union _IFS_SLOT_CFG_STRUC {
48637 + struct {
48638 + UINT32 CckmSifsTime:8; // unit 1us. Applied after CCK RX/TX
48639 + UINT32 OfdmSifsTime:8; // unit 1us. Applied after OFDM RX/TX
48640 + UINT32 OfdmXifsTime:4; //OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND
48641 + UINT32 EIFS:9; // unit 1us
48642 + UINT32 BBRxendEnable:1; // reference RXEND signal to begin XIFS defer
48643 + UINT32 rsv:2;
48644 + } field;
48645 + UINT32 word;
48646 +} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC;
48647 +#endif
48648 +
48649 +#define BKOFF_SLOT_CFG 0x1104 // mac_csr9 last 8 bits
48650 +#define NAV_TIME_CFG 0x1108 // NAV (MAC_CSR15)
48651 +#define CH_TIME_CFG 0x110C // Count as channel busy
48652 +#define PBF_LIFE_TIMER 0x1110 //TX/RX MPDU timestamp timer (free run)Unit: 1us
48653 +#define BCN_TIME_CFG 0x1114 // TXRX_CSR9
48654 +
48655 +#define BCN_OFFSET0 0x042C
48656 +#define BCN_OFFSET1 0x0430
48657 +
48658 +//
48659 +// BCN_TIME_CFG : Synchronization control register
48660 +//
48661 +#ifdef RT_BIG_ENDIAN
48662 +typedef union _BCN_TIME_CFG_STRUC {
48663 + struct {
48664 + UINT32 TxTimestampCompensate:8;
48665 + UINT32 :3;
48666 + UINT32 bBeaconGen:1; // Enable beacon generator
48667 + UINT32 bTBTTEnable:1;
48668 + UINT32 TsfSyncMode:2; // Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
48669 + UINT32 bTsfTicking:1; // Enable TSF auto counting
48670 + UINT32 BeaconInterval:16; // in unit of 1/16 TU
48671 + } field;
48672 + UINT32 word;
48673 +} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC;
48674 +#else
48675 +typedef union _BCN_TIME_CFG_STRUC {
48676 + struct {
48677 + UINT32 BeaconInterval:16; // in unit of 1/16 TU
48678 + UINT32 bTsfTicking:1; // Enable TSF auto counting
48679 + UINT32 TsfSyncMode:2; // Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
48680 + UINT32 bTBTTEnable:1;
48681 + UINT32 bBeaconGen:1; // Enable beacon generator
48682 + UINT32 :3;
48683 + UINT32 TxTimestampCompensate:8;
48684 + } field;
48685 + UINT32 word;
48686 +} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC;
48687 +#endif
48688 +#define TBTT_SYNC_CFG 0x1118 // txrx_csr10
48689 +#define TSF_TIMER_DW0 0x111C // Local TSF timer lsb 32 bits. Read-only
48690 +#define TSF_TIMER_DW1 0x1120 // msb 32 bits. Read-only.
48691 +#define TBTT_TIMER 0x1124 // TImer remains till next TBTT. Read-only. TXRX_CSR14
48692 +#define INT_TIMER_CFG 0x1128 //
48693 +#define INT_TIMER_EN 0x112c // GP-timer and pre-tbtt Int enable
48694 +#define CH_IDLE_STA 0x1130 // channel idle time
48695 +#define CH_BUSY_STA 0x1134 // channle busy time
48696 +//
48697 +// 4.2 MAC POWER configuration registers (offset:0x1200)
48698 +//
48699 +#define MAC_STATUS_CFG 0x1200 // old MAC_CSR12
48700 +#define PWR_PIN_CFG 0x1204 // old MAC_CSR12
48701 +#define AUTO_WAKEUP_CFG 0x1208 // old MAC_CSR10
48702 +//
48703 +// AUTO_WAKEUP_CFG: Manual power control / status register
48704 +//
48705 +#ifdef RT_BIG_ENDIAN
48706 +typedef union _AUTO_WAKEUP_STRUC {
48707 + struct {
48708 + UINT32 :16;
48709 + UINT32 EnableAutoWakeup:1; // 0:sleep, 1:awake
48710 + UINT32 NumofSleepingTbtt:7; // ForceWake has high privilege than PutToSleep when both set
48711 + UINT32 AutoLeadTime:8;
48712 + } field;
48713 + UINT32 word;
48714 +} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC;
48715 +#else
48716 +typedef union _AUTO_WAKEUP_STRUC {
48717 + struct {
48718 + UINT32 AutoLeadTime:8;
48719 + UINT32 NumofSleepingTbtt:7; // ForceWake has high privilege than PutToSleep when both set
48720 + UINT32 EnableAutoWakeup:1; // 0:sleep, 1:awake
48721 + UINT32 :16;
48722 + } field;
48723 + UINT32 word;
48724 +} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC;
48725 +#endif
48726 +//
48727 +// 4.3 MAC TX configuration registers (offset:0x1300)
48728 +//
48729 +
48730 +#define EDCA_AC0_CFG 0x1300 //AC_TXOP_CSR0 0x3474
48731 +#define EDCA_AC1_CFG 0x1304
48732 +#define EDCA_AC2_CFG 0x1308
48733 +#define EDCA_AC3_CFG 0x130c
48734 +#ifdef RT_BIG_ENDIAN
48735 +typedef union _EDCA_AC_CFG_STRUC {
48736 + struct {
48737 + UINT32 :12; //
48738 + UINT32 Cwmax:4; //unit power of 2
48739 + UINT32 Cwmin:4; //
48740 + UINT32 Aifsn:4; // # of slot time
48741 + UINT32 AcTxop:8; // in unit of 32us
48742 + } field;
48743 + UINT32 word;
48744 +} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC;
48745 +#else
48746 +typedef union _EDCA_AC_CFG_STRUC {
48747 + struct {
48748 + UINT32 AcTxop:8; // in unit of 32us
48749 + UINT32 Aifsn:4; // # of slot time
48750 + UINT32 Cwmin:4; //
48751 + UINT32 Cwmax:4; //unit power of 2
48752 + UINT32 :12; //
48753 + } field;
48754 + UINT32 word;
48755 +} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC;
48756 +#endif
48757 +
48758 +#define EDCA_TID_AC_MAP 0x1310
48759 +#define TX_PWR_CFG_0 0x1314
48760 +#define TX_PWR_CFG_1 0x1318
48761 +#define TX_PWR_CFG_2 0x131C
48762 +#define TX_PWR_CFG_3 0x1320
48763 +#define TX_PWR_CFG_4 0x1324
48764 +#define TX_PIN_CFG 0x1328
48765 +#define TX_BAND_CFG 0x132c // 0x1 use upper 20MHz. 0 juse lower 20MHz
48766 +#define TX_SW_CFG0 0x1330
48767 +#define TX_SW_CFG1 0x1334
48768 +#define TX_SW_CFG2 0x1338
48769 +#define TXOP_THRES_CFG 0x133c
48770 +#define TXOP_CTRL_CFG 0x1340
48771 +#define TX_RTS_CFG 0x1344
48772 +
48773 +#ifdef RT_BIG_ENDIAN
48774 +typedef union _TX_RTS_CFG_STRUC {
48775 + struct {
48776 + UINT32 rsv:7;
48777 + UINT32 RtsFbkEn:1; // enable rts rate fallback
48778 + UINT32 RtsThres:16; // unit:byte
48779 + UINT32 AutoRtsRetryLimit:8;
48780 + } field;
48781 + UINT32 word;
48782 +} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC;
48783 +#else
48784 +typedef union _TX_RTS_CFG_STRUC {
48785 + struct {
48786 + UINT32 AutoRtsRetryLimit:8;
48787 + UINT32 RtsThres:16; // unit:byte
48788 + UINT32 RtsFbkEn:1; // enable rts rate fallback
48789 + UINT32 rsv:7; // 1: HT non-STBC control frame enable
48790 + } field;
48791 + UINT32 word;
48792 +} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC;
48793 +#endif
48794 +#define TX_TIMEOUT_CFG 0x1348
48795 +#ifdef RT_BIG_ENDIAN
48796 +typedef union _TX_TIMEOUT_CFG_STRUC {
48797 + struct {
48798 + UINT32 rsv2:8;
48799 + UINT32 TxopTimeout:8; //TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
48800 + UINT32 RxAckTimeout:8; // unit:slot. Used for TX precedure
48801 + UINT32 MpduLifeTime:4; // expiration time = 2^(9+MPDU LIFE TIME) us
48802 + UINT32 rsv:4;
48803 + } field;
48804 + UINT32 word;
48805 +} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC;
48806 +#else
48807 +typedef union _TX_TIMEOUT_CFG_STRUC {
48808 + struct {
48809 + UINT32 rsv:4;
48810 + UINT32 MpduLifeTime:4; // expiration time = 2^(9+MPDU LIFE TIME) us
48811 + UINT32 RxAckTimeout:8; // unit:slot. Used for TX precedure
48812 + UINT32 TxopTimeout:8; //TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
48813 + UINT32 rsv2:8; // 1: HT non-STBC control frame enable
48814 + } field;
48815 + UINT32 word;
48816 +} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC;
48817 +#endif
48818 +#define TX_RTY_CFG 0x134c
48819 +#ifdef RT_BIG_ENDIAN
48820 +typedef union PACKED _TX_RTY_CFG_STRUC {
48821 + struct {
48822 + UINT32 rsv:1;
48823 + UINT32 TxautoFBEnable:1; // Tx retry PHY rate auto fallback enable
48824 + UINT32 AggRtyMode:1; // Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
48825 + UINT32 NonAggRtyMode:1; // Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
48826 + UINT32 LongRtyThre:12; // Long retry threshoold
48827 + UINT32 LongRtyLimit:8; //long retry limit
48828 + UINT32 ShortRtyLimit:8; // short retry limit
48829 +
48830 + } field;
48831 + UINT32 word;
48832 +} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC;
48833 +#else
48834 +typedef union PACKED _TX_RTY_CFG_STRUC {
48835 + struct {
48836 + UINT32 ShortRtyLimit:8; // short retry limit
48837 + UINT32 LongRtyLimit:8; //long retry limit
48838 + UINT32 LongRtyThre:12; // Long retry threshoold
48839 + UINT32 NonAggRtyMode:1; // Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
48840 + UINT32 AggRtyMode:1; // Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
48841 + UINT32 TxautoFBEnable:1; // Tx retry PHY rate auto fallback enable
48842 + UINT32 rsv:1; // 1: HT non-STBC control frame enable
48843 + } field;
48844 + UINT32 word;
48845 +} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC;
48846 +#endif
48847 +#define TX_LINK_CFG 0x1350
48848 +#ifdef RT_BIG_ENDIAN
48849 +typedef union PACKED _TX_LINK_CFG_STRUC {
48850 + struct PACKED {
48851 + UINT32 RemotMFS:8; //remote MCS feedback sequence number
48852 + UINT32 RemotMFB:8; // remote MCS feedback
48853 + UINT32 rsv:3; //
48854 + UINT32 TxCFAckEn:1; // Piggyback CF-ACK enable
48855 + UINT32 TxRDGEn:1; // RDG TX enable
48856 + UINT32 TxMRQEn:1; // MCS request TX enable
48857 + UINT32 RemoteUMFSEnable:1; // remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7)
48858 + UINT32 MFBEnable:1; // TX apply remote MFB 1:enable
48859 + UINT32 RemoteMFBLifeTime:8; //remote MFB life time. unit : 32us
48860 + } field;
48861 + UINT32 word;
48862 +} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC;
48863 +#else
48864 +typedef union PACKED _TX_LINK_CFG_STRUC {
48865 + struct PACKED {
48866 + UINT32 RemoteMFBLifeTime:8; //remote MFB life time. unit : 32us
48867 + UINT32 MFBEnable:1; // TX apply remote MFB 1:enable
48868 + UINT32 RemoteUMFSEnable:1; // remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7)
48869 + UINT32 TxMRQEn:1; // MCS request TX enable
48870 + UINT32 TxRDGEn:1; // RDG TX enable
48871 + UINT32 TxCFAckEn:1; // Piggyback CF-ACK enable
48872 + UINT32 rsv:3; //
48873 + UINT32 RemotMFB:8; // remote MCS feedback
48874 + UINT32 RemotMFS:8; //remote MCS feedback sequence number
48875 + } field;
48876 + UINT32 word;
48877 +} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC;
48878 +#endif
48879 +#define HT_FBK_CFG0 0x1354
48880 +#ifdef RT_BIG_ENDIAN
48881 +typedef union PACKED _HT_FBK_CFG0_STRUC {
48882 + struct {
48883 + UINT32 HTMCS7FBK:4;
48884 + UINT32 HTMCS6FBK:4;
48885 + UINT32 HTMCS5FBK:4;
48886 + UINT32 HTMCS4FBK:4;
48887 + UINT32 HTMCS3FBK:4;
48888 + UINT32 HTMCS2FBK:4;
48889 + UINT32 HTMCS1FBK:4;
48890 + UINT32 HTMCS0FBK:4;
48891 + } field;
48892 + UINT32 word;
48893 +} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC;
48894 +#else
48895 +typedef union PACKED _HT_FBK_CFG0_STRUC {
48896 + struct {
48897 + UINT32 HTMCS0FBK:4;
48898 + UINT32 HTMCS1FBK:4;
48899 + UINT32 HTMCS2FBK:4;
48900 + UINT32 HTMCS3FBK:4;
48901 + UINT32 HTMCS4FBK:4;
48902 + UINT32 HTMCS5FBK:4;
48903 + UINT32 HTMCS6FBK:4;
48904 + UINT32 HTMCS7FBK:4;
48905 + } field;
48906 + UINT32 word;
48907 +} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC;
48908 +#endif
48909 +#define HT_FBK_CFG1 0x1358
48910 +#ifdef RT_BIG_ENDIAN
48911 +typedef union _HT_FBK_CFG1_STRUC {
48912 + struct {
48913 + UINT32 HTMCS15FBK:4;
48914 + UINT32 HTMCS14FBK:4;
48915 + UINT32 HTMCS13FBK:4;
48916 + UINT32 HTMCS12FBK:4;
48917 + UINT32 HTMCS11FBK:4;
48918 + UINT32 HTMCS10FBK:4;
48919 + UINT32 HTMCS9FBK:4;
48920 + UINT32 HTMCS8FBK:4;
48921 + } field;
48922 + UINT32 word;
48923 +} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC;
48924 +#else
48925 +typedef union _HT_FBK_CFG1_STRUC {
48926 + struct {
48927 + UINT32 HTMCS8FBK:4;
48928 + UINT32 HTMCS9FBK:4;
48929 + UINT32 HTMCS10FBK:4;
48930 + UINT32 HTMCS11FBK:4;
48931 + UINT32 HTMCS12FBK:4;
48932 + UINT32 HTMCS13FBK:4;
48933 + UINT32 HTMCS14FBK:4;
48934 + UINT32 HTMCS15FBK:4;
48935 + } field;
48936 + UINT32 word;
48937 +} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC;
48938 +#endif
48939 +#define LG_FBK_CFG0 0x135c
48940 +#ifdef RT_BIG_ENDIAN
48941 +typedef union _LG_FBK_CFG0_STRUC {
48942 + struct {
48943 + UINT32 OFDMMCS7FBK:4; //initial value is 6
48944 + UINT32 OFDMMCS6FBK:4; //initial value is 5
48945 + UINT32 OFDMMCS5FBK:4; //initial value is 4
48946 + UINT32 OFDMMCS4FBK:4; //initial value is 3
48947 + UINT32 OFDMMCS3FBK:4; //initial value is 2
48948 + UINT32 OFDMMCS2FBK:4; //initial value is 1
48949 + UINT32 OFDMMCS1FBK:4; //initial value is 0
48950 + UINT32 OFDMMCS0FBK:4; //initial value is 0
48951 + } field;
48952 + UINT32 word;
48953 +} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC;
48954 +#else
48955 +typedef union _LG_FBK_CFG0_STRUC {
48956 + struct {
48957 + UINT32 OFDMMCS0FBK:4; //initial value is 0
48958 + UINT32 OFDMMCS1FBK:4; //initial value is 0
48959 + UINT32 OFDMMCS2FBK:4; //initial value is 1
48960 + UINT32 OFDMMCS3FBK:4; //initial value is 2
48961 + UINT32 OFDMMCS4FBK:4; //initial value is 3
48962 + UINT32 OFDMMCS5FBK:4; //initial value is 4
48963 + UINT32 OFDMMCS6FBK:4; //initial value is 5
48964 + UINT32 OFDMMCS7FBK:4; //initial value is 6
48965 + } field;
48966 + UINT32 word;
48967 +} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC;
48968 +#endif
48969 +#define LG_FBK_CFG1 0x1360
48970 +#ifdef RT_BIG_ENDIAN
48971 +typedef union _LG_FBK_CFG1_STRUC {
48972 + struct {
48973 + UINT32 rsv:16;
48974 + UINT32 CCKMCS3FBK:4; //initial value is 2
48975 + UINT32 CCKMCS2FBK:4; //initial value is 1
48976 + UINT32 CCKMCS1FBK:4; //initial value is 0
48977 + UINT32 CCKMCS0FBK:4; //initial value is 0
48978 + } field;
48979 + UINT32 word;
48980 +} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC;
48981 +#else
48982 +typedef union _LG_FBK_CFG1_STRUC {
48983 + struct {
48984 + UINT32 CCKMCS0FBK:4; //initial value is 0
48985 + UINT32 CCKMCS1FBK:4; //initial value is 0
48986 + UINT32 CCKMCS2FBK:4; //initial value is 1
48987 + UINT32 CCKMCS3FBK:4; //initial value is 2
48988 + UINT32 rsv:16;
48989 + } field;
48990 + UINT32 word;
48991 +} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC;
48992 +#endif
48993 +
48994 +//=======================================================
48995 +//================ Protection Paramater================================
48996 +//=======================================================
48997 +#define CCK_PROT_CFG 0x1364 //CCK Protection
48998 +#define ASIC_SHORTNAV 1
48999 +#define ASIC_LONGNAV 2
49000 +#define ASIC_RTS 1
49001 +#define ASIC_CTS 2
49002 +#ifdef RT_BIG_ENDIAN
49003 +typedef union _PROT_CFG_STRUC {
49004 + struct {
49005 + UINT32 rsv:5;
49006 + UINT32 RTSThEn:1; //RTS threshold enable on CCK TX
49007 + UINT32 TxopAllowGF40:1; //CCK TXOP allowance.0:disallow.
49008 + UINT32 TxopAllowGF20:1; //CCK TXOP allowance.0:disallow.
49009 + UINT32 TxopAllowMM40:1; //CCK TXOP allowance.0:disallow.
49010 + UINT32 TxopAllowMM20:1; //CCK TXOP allowance. 0:disallow.
49011 + UINT32 TxopAllowOfdm:1; //CCK TXOP allowance.0:disallow.
49012 + UINT32 TxopAllowCck:1; //CCK TXOP allowance.0:disallow.
49013 + UINT32 ProtectNav:2; //TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv
49014 + UINT32 ProtectCtrl:2; //Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv
49015 + UINT32 ProtectRate:16; //Protection control frame rate for CCK TX(RTS/CTS/CFEnd).
49016 + } field;
49017 + UINT32 word;
49018 +} PROT_CFG_STRUC, *PPROT_CFG_STRUC;
49019 +#else
49020 +typedef union _PROT_CFG_STRUC {
49021 + struct {
49022 + UINT32 ProtectRate:16; //Protection control frame rate for CCK TX(RTS/CTS/CFEnd).
49023 + UINT32 ProtectCtrl:2; //Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv
49024 + UINT32 ProtectNav:2; //TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv
49025 + UINT32 TxopAllowCck:1; //CCK TXOP allowance.0:disallow.
49026 + UINT32 TxopAllowOfdm:1; //CCK TXOP allowance.0:disallow.
49027 + UINT32 TxopAllowMM20:1; //CCK TXOP allowance. 0:disallow.
49028 + UINT32 TxopAllowMM40:1; //CCK TXOP allowance.0:disallow.
49029 + UINT32 TxopAllowGF20:1; //CCK TXOP allowance.0:disallow.
49030 + UINT32 TxopAllowGF40:1; //CCK TXOP allowance.0:disallow.
49031 + UINT32 RTSThEn:1; //RTS threshold enable on CCK TX
49032 + UINT32 rsv:5;
49033 + } field;
49034 + UINT32 word;
49035 +} PROT_CFG_STRUC, *PPROT_CFG_STRUC;
49036 +#endif
49037 +
49038 +#define OFDM_PROT_CFG 0x1368 //OFDM Protection
49039 +#define MM20_PROT_CFG 0x136C //MM20 Protection
49040 +#define MM40_PROT_CFG 0x1370 //MM40 Protection
49041 +#define GF20_PROT_CFG 0x1374 //GF20 Protection
49042 +#define GF40_PROT_CFG 0x1378 //GR40 Protection
49043 +#define EXP_CTS_TIME 0x137C //
49044 +#define EXP_ACK_TIME 0x1380 //
49045 +
49046 +//
49047 +// 4.4 MAC RX configuration registers (offset:0x1400)
49048 +//
49049 +#define RX_FILTR_CFG 0x1400 //TXRX_CSR0
49050 +#define AUTO_RSP_CFG 0x1404 //TXRX_CSR4
49051 +//
49052 +// TXRX_CSR4: Auto-Responder/
49053 +//
49054 +#ifdef RT_BIG_ENDIAN
49055 +typedef union _AUTO_RSP_CFG_STRUC {
49056 + struct {
49057 + UINT32 :24;
49058 + UINT32 AckCtsPsmBit:1; // Power bit value in conrtrol frame
49059 + UINT32 DualCTSEn:1; // Power bit value in conrtrol frame
49060 + UINT32 rsv:1; // Power bit value in conrtrol frame
49061 + UINT32 AutoResponderPreamble:1; // 0:long, 1:short preamble
49062 + UINT32 CTS40MRef:1; // Response CTS 40MHz duplicate mode
49063 + UINT32 CTS40MMode:1; // Response CTS 40MHz duplicate mode
49064 + UINT32 BACAckPolicyEnable:1; // 0:long, 1:short preamble
49065 + UINT32 AutoResponderEnable:1;
49066 + } field;
49067 + UINT32 word;
49068 +} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC;
49069 +#else
49070 +typedef union _AUTO_RSP_CFG_STRUC {
49071 + struct {
49072 + UINT32 AutoResponderEnable:1;
49073 + UINT32 BACAckPolicyEnable:1; // 0:long, 1:short preamble
49074 + UINT32 CTS40MMode:1; // Response CTS 40MHz duplicate mode
49075 + UINT32 CTS40MRef:1; // Response CTS 40MHz duplicate mode
49076 + UINT32 AutoResponderPreamble:1; // 0:long, 1:short preamble
49077 + UINT32 rsv:1; // Power bit value in conrtrol frame
49078 + UINT32 DualCTSEn:1; // Power bit value in conrtrol frame
49079 + UINT32 AckCtsPsmBit:1; // Power bit value in conrtrol frame
49080 + UINT32 :24;
49081 + } field;
49082 + UINT32 word;
49083 +} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC;
49084 +#endif
49085 +
49086 +#define LEGACY_BASIC_RATE 0x1408 // TXRX_CSR5 0x3054
49087 +#define HT_BASIC_RATE 0x140c
49088 +#define HT_CTRL_CFG 0x1410
49089 +#define SIFS_COST_CFG 0x1414
49090 +#define RX_PARSER_CFG 0x1418 //Set NAV for all received frames
49091 +
49092 +//
49093 +// 4.5 MAC Security configuration (offset:0x1500)
49094 +//
49095 +#define TX_SEC_CNT0 0x1500 //
49096 +#define RX_SEC_CNT0 0x1504 //
49097 +#define CCMP_FC_MUTE 0x1508 //
49098 +//
49099 +// 4.6 HCCA/PSMP (offset:0x1600)
49100 +//
49101 +#define TXOP_HLDR_ADDR0 0x1600
49102 +#define TXOP_HLDR_ADDR1 0x1604
49103 +#define TXOP_HLDR_ET 0x1608
49104 +#define QOS_CFPOLL_RA_DW0 0x160c
49105 +#define QOS_CFPOLL_A1_DW1 0x1610
49106 +#define QOS_CFPOLL_QC 0x1614
49107 +//
49108 +// 4.7 MAC Statistis registers (offset:0x1700)
49109 +//
49110 +#define RX_STA_CNT0 0x1700 //
49111 +#define RX_STA_CNT1 0x1704 //
49112 +#define RX_STA_CNT2 0x1708 //
49113 +
49114 +//
49115 +// RX_STA_CNT0_STRUC: RX PLCP error count & RX CRC error count
49116 +//
49117 +#ifdef RT_BIG_ENDIAN
49118 +typedef union _RX_STA_CNT0_STRUC {
49119 + struct {
49120 + USHORT PhyErr;
49121 + USHORT CrcErr;
49122 + } field;
49123 + UINT32 word;
49124 +} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC;
49125 +#else
49126 +typedef union _RX_STA_CNT0_STRUC {
49127 + struct {
49128 + USHORT CrcErr;
49129 + USHORT PhyErr;
49130 + } field;
49131 + UINT32 word;
49132 +} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC;
49133 +#endif
49134 +
49135 +//
49136 +// RX_STA_CNT1_STRUC: RX False CCA count & RX LONG frame count
49137 +//
49138 +#ifdef RT_BIG_ENDIAN
49139 +typedef union _RX_STA_CNT1_STRUC {
49140 + struct {
49141 + USHORT PlcpErr;
49142 + USHORT FalseCca;
49143 + } field;
49144 + UINT32 word;
49145 +} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC;
49146 +#else
49147 +typedef union _RX_STA_CNT1_STRUC {
49148 + struct {
49149 + USHORT FalseCca;
49150 + USHORT PlcpErr;
49151 + } field;
49152 + UINT32 word;
49153 +} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC;
49154 +#endif
49155 +
49156 +//
49157 +// RX_STA_CNT2_STRUC:
49158 +//
49159 +#ifdef RT_BIG_ENDIAN
49160 +typedef union _RX_STA_CNT2_STRUC {
49161 + struct {
49162 + USHORT RxFifoOverflowCount;
49163 + USHORT RxDupliCount;
49164 + } field;
49165 + UINT32 word;
49166 +} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC;
49167 +#else
49168 +typedef union _RX_STA_CNT2_STRUC {
49169 + struct {
49170 + USHORT RxDupliCount;
49171 + USHORT RxFifoOverflowCount;
49172 + } field;
49173 + UINT32 word;
49174 +} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC;
49175 +#endif
49176 +#define TX_STA_CNT0 0x170C //
49177 +//
49178 +// STA_CSR3: TX Beacon count
49179 +//
49180 +#ifdef RT_BIG_ENDIAN
49181 +typedef union _TX_STA_CNT0_STRUC {
49182 + struct {
49183 + USHORT TxBeaconCount;
49184 + USHORT TxFailCount;
49185 + } field;
49186 + UINT32 word;
49187 +} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC;
49188 +#else
49189 +typedef union _TX_STA_CNT0_STRUC {
49190 + struct {
49191 + USHORT TxFailCount;
49192 + USHORT TxBeaconCount;
49193 + } field;
49194 + UINT32 word;
49195 +} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC;
49196 +#endif
49197 +#define TX_STA_CNT1 0x1710 //
49198 +//
49199 +// TX_STA_CNT1: TX tx count
49200 +//
49201 +#ifdef RT_BIG_ENDIAN
49202 +typedef union _TX_STA_CNT1_STRUC {
49203 + struct {
49204 + USHORT TxRetransmit;
49205 + USHORT TxSuccess;
49206 + } field;
49207 + UINT32 word;
49208 +} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC;
49209 +#else
49210 +typedef union _TX_STA_CNT1_STRUC {
49211 + struct {
49212 + USHORT TxSuccess;
49213 + USHORT TxRetransmit;
49214 + } field;
49215 + UINT32 word;
49216 +} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC;
49217 +#endif
49218 +#define TX_STA_CNT2 0x1714 //
49219 +//
49220 +// TX_STA_CNT2: TX tx count
49221 +//
49222 +#ifdef RT_BIG_ENDIAN
49223 +typedef union _TX_STA_CNT2_STRUC {
49224 + struct {
49225 + USHORT TxUnderFlowCount;
49226 + USHORT TxZeroLenCount;
49227 + } field;
49228 + UINT32 word;
49229 +} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC;
49230 +#else
49231 +typedef union _TX_STA_CNT2_STRUC {
49232 + struct {
49233 + USHORT TxZeroLenCount;
49234 + USHORT TxUnderFlowCount;
49235 + } field;
49236 + UINT32 word;
49237 +} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC;
49238 +#endif
49239 +#define TX_STA_FIFO 0x1718 //
49240 +//
49241 +// TX_STA_FIFO_STRUC: TX Result for specific PID status fifo register
49242 +//
49243 +#ifdef RT_BIG_ENDIAN
49244 +typedef union PACKED _TX_STA_FIFO_STRUC {
49245 + struct {
49246 + UINT32 Reserve:2;
49247 + UINT32 TxBF:1; // 3*3
49248 + UINT32 SuccessRate:13; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
49249 +// UINT32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
49250 + UINT32 wcid:8; //wireless client index
49251 + UINT32 TxAckRequired:1; // ack required
49252 + UINT32 TxAggre:1; // Tx is aggregated
49253 + UINT32 TxSuccess:1; // Tx success. whether success or not
49254 + UINT32 PidType:4;
49255 + UINT32 bValid:1; // 1:This register contains a valid TX result
49256 + } field;
49257 + UINT32 word;
49258 +} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC;
49259 +#else
49260 +typedef union PACKED _TX_STA_FIFO_STRUC {
49261 + struct {
49262 + UINT32 bValid:1; // 1:This register contains a valid TX result
49263 + UINT32 PidType:4;
49264 + UINT32 TxSuccess:1; // Tx No retry success
49265 + UINT32 TxAggre:1; // Tx Retry Success
49266 + UINT32 TxAckRequired:1; // Tx fail
49267 + UINT32 wcid:8; //wireless client index
49268 +// UINT32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
49269 + UINT32 SuccessRate:13; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
49270 + UINT32 TxBF:1;
49271 + UINT32 Reserve:2;
49272 + } field;
49273 + UINT32 word;
49274 +} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC;
49275 +#endif
49276 +// Debug counter
49277 +#define TX_AGG_CNT 0x171c
49278 +#ifdef RT_BIG_ENDIAN
49279 +typedef union _TX_AGG_CNT_STRUC {
49280 + struct {
49281 + USHORT AggTxCount;
49282 + USHORT NonAggTxCount;
49283 + } field;
49284 + UINT32 word;
49285 +} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC;
49286 +#else
49287 +typedef union _TX_AGG_CNT_STRUC {
49288 + struct {
49289 + USHORT NonAggTxCount;
49290 + USHORT AggTxCount;
49291 + } field;
49292 + UINT32 word;
49293 +} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC;
49294 +#endif
49295 +// Debug counter
49296 +#define TX_AGG_CNT0 0x1720
49297 +#ifdef RT_BIG_ENDIAN
49298 +typedef union _TX_AGG_CNT0_STRUC {
49299 + struct {
49300 + USHORT AggSize2Count;
49301 + USHORT AggSize1Count;
49302 + } field;
49303 + UINT32 word;
49304 +} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC;
49305 +#else
49306 +typedef union _TX_AGG_CNT0_STRUC {
49307 + struct {
49308 + USHORT AggSize1Count;
49309 + USHORT AggSize2Count;
49310 + } field;
49311 + UINT32 word;
49312 +} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC;
49313 +#endif
49314 +// Debug counter
49315 +#define TX_AGG_CNT1 0x1724
49316 +#ifdef RT_BIG_ENDIAN
49317 +typedef union _TX_AGG_CNT1_STRUC {
49318 + struct {
49319 + USHORT AggSize4Count;
49320 + USHORT AggSize3Count;
49321 + } field;
49322 + UINT32 word;
49323 +} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC;
49324 +#else
49325 +typedef union _TX_AGG_CNT1_STRUC {
49326 + struct {
49327 + USHORT AggSize3Count;
49328 + USHORT AggSize4Count;
49329 + } field;
49330 + UINT32 word;
49331 +} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC;
49332 +#endif
49333 +#define TX_AGG_CNT2 0x1728
49334 +#ifdef RT_BIG_ENDIAN
49335 +typedef union _TX_AGG_CNT2_STRUC {
49336 + struct {
49337 + USHORT AggSize6Count;
49338 + USHORT AggSize5Count;
49339 + } field;
49340 + UINT32 word;
49341 +} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC;
49342 +#else
49343 +typedef union _TX_AGG_CNT2_STRUC {
49344 + struct {
49345 + USHORT AggSize5Count;
49346 + USHORT AggSize6Count;
49347 + } field;
49348 + UINT32 word;
49349 +} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC;
49350 +#endif
49351 +// Debug counter
49352 +#define TX_AGG_CNT3 0x172c
49353 +#ifdef RT_BIG_ENDIAN
49354 +typedef union _TX_AGG_CNT3_STRUC {
49355 + struct {
49356 + USHORT AggSize8Count;
49357 + USHORT AggSize7Count;
49358 + } field;
49359 + UINT32 word;
49360 +} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC;
49361 +#else
49362 +typedef union _TX_AGG_CNT3_STRUC {
49363 + struct {
49364 + USHORT AggSize7Count;
49365 + USHORT AggSize8Count;
49366 + } field;
49367 + UINT32 word;
49368 +} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC;
49369 +#endif
49370 +// Debug counter
49371 +#define TX_AGG_CNT4 0x1730
49372 +#ifdef RT_BIG_ENDIAN
49373 +typedef union _TX_AGG_CNT4_STRUC {
49374 + struct {
49375 + USHORT AggSize10Count;
49376 + USHORT AggSize9Count;
49377 + } field;
49378 + UINT32 word;
49379 +} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC;
49380 +#else
49381 +typedef union _TX_AGG_CNT4_STRUC {
49382 + struct {
49383 + USHORT AggSize9Count;
49384 + USHORT AggSize10Count;
49385 + } field;
49386 + UINT32 word;
49387 +} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC;
49388 +#endif
49389 +#define TX_AGG_CNT5 0x1734
49390 +#ifdef RT_BIG_ENDIAN
49391 +typedef union _TX_AGG_CNT5_STRUC {
49392 + struct {
49393 + USHORT AggSize12Count;
49394 + USHORT AggSize11Count;
49395 + } field;
49396 + UINT32 word;
49397 +} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC;
49398 +#else
49399 +typedef union _TX_AGG_CNT5_STRUC {
49400 + struct {
49401 + USHORT AggSize11Count;
49402 + USHORT AggSize12Count;
49403 + } field;
49404 + UINT32 word;
49405 +} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC;
49406 +#endif
49407 +#define TX_AGG_CNT6 0x1738
49408 +#ifdef RT_BIG_ENDIAN
49409 +typedef union _TX_AGG_CNT6_STRUC {
49410 + struct {
49411 + USHORT AggSize14Count;
49412 + USHORT AggSize13Count;
49413 + } field;
49414 + UINT32 word;
49415 +} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC;
49416 +#else
49417 +typedef union _TX_AGG_CNT6_STRUC {
49418 + struct {
49419 + USHORT AggSize13Count;
49420 + USHORT AggSize14Count;
49421 + } field;
49422 + UINT32 word;
49423 +} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC;
49424 +#endif
49425 +#define TX_AGG_CNT7 0x173c
49426 +#ifdef RT_BIG_ENDIAN
49427 +typedef union _TX_AGG_CNT7_STRUC {
49428 + struct {
49429 + USHORT AggSize16Count;
49430 + USHORT AggSize15Count;
49431 + } field;
49432 + UINT32 word;
49433 +} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC;
49434 +#else
49435 +typedef union _TX_AGG_CNT7_STRUC {
49436 + struct {
49437 + USHORT AggSize15Count;
49438 + USHORT AggSize16Count;
49439 + } field;
49440 + UINT32 word;
49441 +} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC;
49442 +#endif
49443 +#define MPDU_DENSITY_CNT 0x1740
49444 +#ifdef RT_BIG_ENDIAN
49445 +typedef union _MPDU_DEN_CNT_STRUC {
49446 + struct {
49447 + USHORT RXZeroDelCount; //RX zero length delimiter count
49448 + USHORT TXZeroDelCount; //TX zero length delimiter count
49449 + } field;
49450 + UINT32 word;
49451 +} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC;
49452 +#else
49453 +typedef union _MPDU_DEN_CNT_STRUC {
49454 + struct {
49455 + USHORT TXZeroDelCount; //TX zero length delimiter count
49456 + USHORT RXZeroDelCount; //RX zero length delimiter count
49457 + } field;
49458 + UINT32 word;
49459 +} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC;
49460 +#endif
49461 +//
49462 +// TXRX control registers - base address 0x3000
49463 +//
49464 +// rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
49465 +#define TXRX_CSR1 0x77d0
49466 +
49467 +//
49468 +// Security key table memory, base address = 0x1000
49469 +//
49470 +#define MAC_WCID_BASE 0x1800 //8-bytes(use only 6-bytes) * 256 entry =
49471 +#define HW_WCID_ENTRY_SIZE 8
49472 +#define PAIRWISE_KEY_TABLE_BASE 0x4000 // 32-byte * 256-entry = -byte
49473 +#define HW_KEY_ENTRY_SIZE 0x20
49474 +#define PAIRWISE_IVEIV_TABLE_BASE 0x6000 // 8-byte * 256-entry = -byte
49475 +#define MAC_IVEIV_TABLE_BASE 0x6000 // 8-byte * 256-entry = -byte
49476 +#define HW_IVEIV_ENTRY_SIZE 8
49477 +#define MAC_WCID_ATTRIBUTE_BASE 0x6800 // 4-byte * 256-entry = -byte
49478 +#define HW_WCID_ATTRI_SIZE 4
49479 +#define WCID_RESERVED 0x6bfc
49480 +#define SHARED_KEY_TABLE_BASE 0x6c00 // 32-byte * 16-entry = 512-byte
49481 +#define SHARED_KEY_MODE_BASE 0x7000 // 32-byte * 16-entry = 512-byte
49482 +#define HW_SHARED_KEY_MODE_SIZE 4
49483 +#define SHAREDKEYTABLE 0
49484 +#define PAIRWISEKEYTABLE 1
49485 +
49486 +
49487 +#ifdef RT_BIG_ENDIAN
49488 +typedef union _SHAREDKEY_MODE_STRUC {
49489 + struct {
49490 + UINT32 :1;
49491 + UINT32 Bss1Key3CipherAlg:3;
49492 + UINT32 :1;
49493 + UINT32 Bss1Key2CipherAlg:3;
49494 + UINT32 :1;
49495 + UINT32 Bss1Key1CipherAlg:3;
49496 + UINT32 :1;
49497 + UINT32 Bss1Key0CipherAlg:3;
49498 + UINT32 :1;
49499 + UINT32 Bss0Key3CipherAlg:3;
49500 + UINT32 :1;
49501 + UINT32 Bss0Key2CipherAlg:3;
49502 + UINT32 :1;
49503 + UINT32 Bss0Key1CipherAlg:3;
49504 + UINT32 :1;
49505 + UINT32 Bss0Key0CipherAlg:3;
49506 + } field;
49507 + UINT32 word;
49508 +} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC;
49509 +#else
49510 +typedef union _SHAREDKEY_MODE_STRUC {
49511 + struct {
49512 + UINT32 Bss0Key0CipherAlg:3;
49513 + UINT32 :1;
49514 + UINT32 Bss0Key1CipherAlg:3;
49515 + UINT32 :1;
49516 + UINT32 Bss0Key2CipherAlg:3;
49517 + UINT32 :1;
49518 + UINT32 Bss0Key3CipherAlg:3;
49519 + UINT32 :1;
49520 + UINT32 Bss1Key0CipherAlg:3;
49521 + UINT32 :1;
49522 + UINT32 Bss1Key1CipherAlg:3;
49523 + UINT32 :1;
49524 + UINT32 Bss1Key2CipherAlg:3;
49525 + UINT32 :1;
49526 + UINT32 Bss1Key3CipherAlg:3;
49527 + UINT32 :1;
49528 + } field;
49529 + UINT32 word;
49530 +} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC;
49531 +#endif
49532 +// 64-entry for pairwise key table
49533 +typedef struct _HW_WCID_ENTRY { // 8-byte per entry
49534 + UCHAR Address[6];
49535 + UCHAR Rsv[2];
49536 +} HW_WCID_ENTRY, PHW_WCID_ENTRY;
49537 +
49538 +
49539 +
49540 +//
49541 +// Other on-chip shared memory space, base = 0x2000
49542 +//
49543 +
49544 +// CIS space - base address = 0x2000
49545 +#define HW_CIS_BASE 0x2000
49546 +
49547 +// Carrier-sense CTS frame base address. It's where mac stores carrier-sense frame for carrier-sense function.
49548 +#define HW_CS_CTS_BASE 0x7700
49549 +// DFS CTS frame base address. It's where mac stores CTS frame for DFS.
49550 +#define HW_DFS_CTS_BASE 0x7780
49551 +#define HW_CTS_FRAME_SIZE 0x80
49552 +
49553 +// 2004-11-08 john - since NULL frame won't be that long (256 byte). We steal 16 tail bytes
49554 +// to save debugging settings
49555 +#define HW_DEBUG_SETTING_BASE 0x77f0 // 0x77f0~0x77ff total 16 bytes
49556 +#define HW_DEBUG_SETTING_BASE2 0x7770 // 0x77f0~0x77ff total 16 bytes
49557 +
49558 +#if 0
49559 +// on-chip BEACON frame space - base address = 0x7800
49560 +#define HW_BEACON_MAX_SIZE 0x0800 /* unit: byte */
49561 +#define HW_BEACON_BASE0 0x7800
49562 +#define HW_BEACON_BASE1 0x7900
49563 +#define HW_BEACON_BASE2 0x7a00
49564 +#define HW_BEACON_BASE3 0x7b00
49565 +#define HW_BEACON_BASE4 0x7c00
49566 +#define HW_BEACON_BASE5 0x7d00
49567 +#define HW_BEACON_BASE6 0x7e00
49568 +#define HW_BEACON_BASE7 0x7f00
49569 +/* 1. HW_BEACON_OFFSET/64B must be 0;
49570 + 2. BCN_OFFSET0 must also be changed in NICInitializeAsic();
49571 + 3. max 0x0800 for 8 beacon frames; */
49572 +#else
49573 +// In order to support maximum 8 MBSS and its maximum length is 512 for each beacon
49574 +// Three section discontinue memory segments will be used.
49575 +// 1. The original region for BCN 0~3
49576 +// 2. Extract memory from FCE table for BCN 4~5
49577 +// 3. Extract memory from Pair-wise key table for BCN 6~7
49578 +// It occupied those memory of wcid 238~253 for BCN 6
49579 +// and wcid 222~237 for BCN 7
49580 +#define HW_BEACON_MAX_SIZE 0x1000 /* unit: byte */
49581 +#define HW_BEACON_BASE0 0x7800
49582 +#define HW_BEACON_BASE1 0x7A00
49583 +#define HW_BEACON_BASE2 0x7C00
49584 +#define HW_BEACON_BASE3 0x7E00
49585 +#define HW_BEACON_BASE4 0x7200
49586 +#define HW_BEACON_BASE5 0x7400
49587 +#define HW_BEACON_BASE6 0x5DC0
49588 +#define HW_BEACON_BASE7 0x5BC0
49589 +#endif
49590 +
49591 +#define HW_BEACON_MAX_COUNT 8
49592 +#define HW_BEACON_OFFSET 0x0200
49593 +#define HW_BEACON_CONTENT_LEN (HW_BEACON_OFFSET - TXWI_SIZE)
49594 +
49595 +// HOST-MCU shared memory - base address = 0x2100
49596 +#define HOST_CMD_CSR 0x404
49597 +#define H2M_MAILBOX_CSR 0x7010
49598 +#define H2M_MAILBOX_CID 0x7014
49599 +#define H2M_MAILBOX_STATUS 0x701c
49600 +#define H2M_INT_SRC 0x7024
49601 +#define H2M_BBP_AGENT 0x7028
49602 +#define M2H_CMD_DONE_CSR 0x000c
49603 +#define MCU_TXOP_ARRAY_BASE 0x000c // TODO: to be provided by Albert
49604 +#define MCU_TXOP_ENTRY_SIZE 32 // TODO: to be provided by Albert
49605 +#define MAX_NUM_OF_TXOP_ENTRY 16 // TODO: must be same with 8051 firmware
49606 +#define MCU_MBOX_VERSION 0x01 // TODO: to be confirmed by Albert
49607 +#define MCU_MBOX_VERSION_OFFSET 5 // TODO: to be provided by Albert
49608 +
49609 +//
49610 +// Host DMA registers - base address 0x200 . TX0-3=EDCAQid0-3, TX4=HCCA, TX5=MGMT,
49611 +//
49612 +//
49613 +// DMA RING DESCRIPTOR
49614 +//
49615 +#define E2PROM_CSR 0x0004
49616 +#define IO_CNTL_CSR 0x77d0
49617 +
49618 +#ifdef RT2870
49619 +// 8051 firmware image for usb - use last-half base address = 0x3000
49620 +#define FIRMWARE_IMAGE_BASE 0x3000
49621 +#define MAX_FIRMWARE_IMAGE_SIZE 0x1000 // 4kbyte
49622 +#endif // RT2870 //
49623 +
49624 +// TODO: ????? old RT2560 registers. to keep them or remove them?
49625 +//#define MCAST0 0x0178 // multicast filter register 0
49626 +//#define MCAST1 0x017c // multicast filter register 1
49627 +
49628 +
49629 +// ================================================================
49630 +// Tx / Rx / Mgmt ring descriptor definition
49631 +// ================================================================
49632 +
49633 +// the following PID values are used to mark outgoing frame type in TXD->PID so that
49634 +// proper TX statistics can be collected based on these categories
49635 +// b3-2 of PID field -
49636 +#define PID_MGMT 0x05
49637 +#define PID_BEACON 0x0c
49638 +#define PID_DATA_NORMALUCAST 0x02
49639 +#define PID_DATA_AMPDU 0x04
49640 +#define PID_DATA_NO_ACK 0x08
49641 +#define PID_DATA_NOT_NORM_ACK 0x03
49642 +#if 0
49643 +#define PTYPE_DATA_REQUIRE_ACK 0x00 // b7-6:00, b5-0: 0~59 is MAC table index (AID?), 60~63 is WDS index
49644 +#define PTYPE_NULL_AT_HIGH_RATE 0x04 // b7-6:01, b5-0: 0~59 is MAC table index (AID?), 60~63 is WDS index
49645 +#define PTYPE_RESERVED 0x08 // b7-6:10
49646 +#define PTYPE_SPECIAL 0x0c // b7-6:11
49647 +
49648 +// when b3-2=11 (PTYPE_SPECIAL), b1-0 coube be ...
49649 +#define PSUBTYPE_DATA_NO_ACK 0x00
49650 +#define PSUBTYPE_MGMT 0x01
49651 +#define PSUBTYPE_OTHER_CNTL 0x02
49652 +#define PSUBTYPE_RTS 0x03
49653 +#endif
49654 +// value domain of pTxD->HostQId (4-bit: 0~15)
49655 +#define QID_AC_BK 1 // meet ACI definition in 802.11e
49656 +#define QID_AC_BE 0 // meet ACI definition in 802.11e
49657 +#define QID_AC_VI 2
49658 +#define QID_AC_VO 3
49659 +#define QID_HCCA 4
49660 +#define NUM_OF_TX_RING 5
49661 +#define QID_MGMT 13
49662 +#define QID_RX 14
49663 +#define QID_OTHER 15
49664 +
49665 +
49666 +// ------------------------------------------------------
49667 +// BBP & RF definition
49668 +// ------------------------------------------------------
49669 +#define BUSY 1
49670 +#define IDLE 0
49671 +
49672 +#define RF_R00 0
49673 +#define RF_R01 1
49674 +#define RF_R02 2
49675 +#define RF_R03 3
49676 +#define RF_R04 4
49677 +#define RF_R05 5
49678 +#define RF_R06 6
49679 +#define RF_R07 7
49680 +#define RF_R08 8
49681 +#define RF_R09 9
49682 +#define RF_R10 10
49683 +#define RF_R11 11
49684 +#define RF_R12 12
49685 +#define RF_R13 13
49686 +#define RF_R14 14
49687 +#define RF_R15 15
49688 +#define RF_R16 16
49689 +#define RF_R17 17
49690 +#define RF_R18 18
49691 +#define RF_R19 19
49692 +#define RF_R20 20
49693 +#define RF_R21 21
49694 +#define RF_R22 22
49695 +#define RF_R23 23
49696 +#define RF_R24 24
49697 +#define RF_R25 25
49698 +#define RF_R26 26
49699 +#define RF_R27 27
49700 +#define RF_R28 28
49701 +#define RF_R29 29
49702 +#define RF_R30 30
49703 +#define RF_R31 31
49704 +
49705 +#define BBP_R0 0 // version
49706 +#define BBP_R1 1 // TSSI
49707 +#define BBP_R2 2 // TX configure
49708 +#define BBP_R3 3
49709 +#define BBP_R4 4
49710 +#define BBP_R5 5
49711 +#define BBP_R6 6
49712 +#define BBP_R14 14 // RX configure
49713 +#define BBP_R16 16
49714 +#define BBP_R17 17 // RX sensibility
49715 +#define BBP_R18 18
49716 +#define BBP_R21 21
49717 +#define BBP_R22 22
49718 +#define BBP_R24 24
49719 +#define BBP_R25 25
49720 +#define BBP_R49 49 //TSSI
49721 +#define BBP_R50 50
49722 +#define BBP_R51 51
49723 +#define BBP_R52 52
49724 +#define BBP_R55 55
49725 +#define BBP_R62 62 // Rx SQ0 Threshold HIGH
49726 +#define BBP_R63 63
49727 +#define BBP_R64 64
49728 +#define BBP_R65 65
49729 +#define BBP_R66 66
49730 +#define BBP_R67 67
49731 +#define BBP_R68 68
49732 +#define BBP_R69 69
49733 +#define BBP_R70 70 // Rx AGC SQ CCK Xcorr threshold
49734 +#define BBP_R73 73
49735 +#define BBP_R75 75
49736 +#define BBP_R77 77
49737 +#define BBP_R81 81
49738 +#define BBP_R82 82
49739 +#define BBP_R83 83
49740 +#define BBP_R84 84
49741 +#define BBP_R86 86
49742 +#define BBP_R91 91
49743 +#define BBP_R92 92
49744 +#define BBP_R94 94 // Tx Gain Control
49745 +#define BBP_R103 103
49746 +#define BBP_R105 105
49747 +#define BBP_R113 113
49748 +#define BBP_R114 114
49749 +#define BBP_R115 115
49750 +#define BBP_R116 116
49751 +#define BBP_R117 117
49752 +#define BBP_R118 118
49753 +#define BBP_R119 119
49754 +#define BBP_R120 120
49755 +#define BBP_R121 121
49756 +#define BBP_R122 122
49757 +#define BBP_R123 123
49758 +
49759 +
49760 +#define BBPR94_DEFAULT 0x06 // Add 1 value will gain 1db
49761 +
49762 +//#define PHY_TR_SWITCH_TIME 5 // usec
49763 +
49764 +//#define BBP_R17_LOW_SENSIBILITY 0x50
49765 +//#define BBP_R17_MID_SENSIBILITY 0x41
49766 +//#define BBP_R17_DYNAMIC_UP_BOUND 0x40
49767 +#define RSSI_FOR_VERY_LOW_SENSIBILITY -35
49768 +#define RSSI_FOR_LOW_SENSIBILITY -58
49769 +#define RSSI_FOR_MID_LOW_SENSIBILITY -80
49770 +#define RSSI_FOR_MID_SENSIBILITY -90
49771 +
49772 +//-------------------------------------------------------------------------
49773 +// EEPROM definition
49774 +//-------------------------------------------------------------------------
49775 +#define EEDO 0x08
49776 +#define EEDI 0x04
49777 +#define EECS 0x02
49778 +#define EESK 0x01
49779 +#define EERL 0x80
49780 +
49781 +#define EEPROM_WRITE_OPCODE 0x05
49782 +#define EEPROM_READ_OPCODE 0x06
49783 +#define EEPROM_EWDS_OPCODE 0x10
49784 +#define EEPROM_EWEN_OPCODE 0x13
49785 +
49786 +#define NUM_EEPROM_BBP_PARMS 19 // Include NIC Config 0, 1, CR, TX ALC step, BBPs
49787 +#define NUM_EEPROM_TX_G_PARMS 7
49788 +#define EEPROM_NIC1_OFFSET 0x34 // The address is from NIC config 0, not BBP register ID
49789 +#define EEPROM_NIC2_OFFSET 0x36 // The address is from NIC config 0, not BBP register ID
49790 +#define EEPROM_BBP_BASE_OFFSET 0xf0 // The address is from NIC config 0, not BBP register ID
49791 +#define EEPROM_G_TX_PWR_OFFSET 0x52
49792 +#define EEPROM_G_TX2_PWR_OFFSET 0x60
49793 +#define EEPROM_LED1_OFFSET 0x3c
49794 +#define EEPROM_LED2_OFFSET 0x3e
49795 +#define EEPROM_LED3_OFFSET 0x40
49796 +#define EEPROM_LNA_OFFSET 0x44
49797 +#define EEPROM_RSSI_BG_OFFSET 0x46
49798 +#define EEPROM_RSSI_A_OFFSET 0x4a
49799 +#define EEPROM_DEFINE_MAX_TXPWR 0x4e
49800 +#define EEPROM_TXPOWER_BYRATE_20MHZ_2_4G 0xde // 20MHZ 2.4G tx power.
49801 +#define EEPROM_TXPOWER_BYRATE_40MHZ_2_4G 0xee // 40MHZ 2.4G tx power.
49802 +#define EEPROM_TXPOWER_BYRATE_20MHZ_5G 0xfa // 20MHZ 5G tx power.
49803 +#define EEPROM_TXPOWER_BYRATE_40MHZ_5G 0x10a // 40MHZ 5G tx power.
49804 +#define EEPROM_A_TX_PWR_OFFSET 0x78
49805 +#define EEPROM_A_TX2_PWR_OFFSET 0xa6
49806 +//#define EEPROM_Japan_TX_PWR_OFFSET 0x90 // 802.11j
49807 +//#define EEPROM_Japan_TX2_PWR_OFFSET 0xbe
49808 +//#define EEPROM_TSSI_REF_OFFSET 0x54
49809 +//#define EEPROM_TSSI_DELTA_OFFSET 0x24
49810 +//#define EEPROM_CCK_TX_PWR_OFFSET 0x62
49811 +//#define EEPROM_CALIBRATE_OFFSET 0x7c
49812 +#define EEPROM_VERSION_OFFSET 0x02
49813 +#define EEPROM_FREQ_OFFSET 0x3a
49814 +#define EEPROM_TXPOWER_BYRATE 0xde // 20MHZ power.
49815 +#define EEPROM_TXPOWER_DELTA 0x50 // 20MHZ AND 40 MHZ use different power. This is delta in 40MHZ.
49816 +#define VALID_EEPROM_VERSION 1
49817 +
49818 +// PairKeyMode definition
49819 +#define PKMODE_NONE 0
49820 +#define PKMODE_WEP64 1
49821 +#define PKMODE_WEP128 2
49822 +#define PKMODE_TKIP 3
49823 +#define PKMODE_AES 4
49824 +#define PKMODE_CKIP64 5
49825 +#define PKMODE_CKIP128 6
49826 +#define PKMODE_TKIP_NO_MIC 7 // MIC appended by driver: not a valid value in hardware key table
49827 +
49828 +// =================================================================================
49829 +// WCID format
49830 +// =================================================================================
49831 +//7.1 WCID ENTRY format : 8bytes
49832 +typedef struct _WCID_ENTRY_STRUC {
49833 + UCHAR RXBABitmap7; // bit0 for TID8, bit7 for TID 15
49834 + UCHAR RXBABitmap0; // bit0 for TID0, bit7 for TID 7
49835 + UCHAR MAC[6]; // 0 for shared key table. 1 for pairwise key table
49836 +} WCID_ENTRY_STRUC, *PWCID_ENTRY_STRUC;
49837 +
49838 +//8.1.1 SECURITY KEY format : 8DW
49839 +// 32-byte per entry, total 16-entry for shared key table, 64-entry for pairwise key table
49840 +typedef struct _HW_KEY_ENTRY { // 32-byte per entry
49841 + UCHAR Key[16];
49842 + UCHAR TxMic[8];
49843 + UCHAR RxMic[8];
49844 +} HW_KEY_ENTRY, *PHW_KEY_ENTRY;
49845 +
49846 +//8.1.2 IV/EIV format : 2DW
49847 +
49848 +//8.1.3 RX attribute entry format : 1DW
49849 +#ifdef RT_BIG_ENDIAN
49850 +typedef struct _MAC_ATTRIBUTE_STRUC {
49851 + UINT32 rsv:22;
49852 + UINT32 RXWIUDF:3;
49853 + UINT32 BSSIDIdx:3; //multipleBSS index for the WCID
49854 + UINT32 PairKeyMode:3;
49855 + UINT32 KeyTab:1; // 0 for shared key table. 1 for pairwise key table
49856 +} MAC_ATTRIBUTE_STRUC, *PMAC_ATTRIBUTE_STRUC;
49857 +#else
49858 +typedef struct _MAC_ATTRIBUTE_STRUC {
49859 + UINT32 KeyTab:1; // 0 for shared key table. 1 for pairwise key table
49860 + UINT32 PairKeyMode:3;
49861 + UINT32 BSSIDIdx:3; //multipleBSS index for the WCID
49862 + UINT32 RXWIUDF:3;
49863 + UINT32 rsv:22;
49864 +} MAC_ATTRIBUTE_STRUC, *PMAC_ATTRIBUTE_STRUC;
49865 +#endif
49866 +
49867 +
49868 +// =================================================================================
49869 +// TX / RX ring descriptor format
49870 +// =================================================================================
49871 +
49872 +// the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO.
49873 +// MAC block use this TXINFO to control the transmission behavior of this frame.
49874 +#define FIFO_MGMT 0
49875 +#define FIFO_HCCA 1
49876 +#define FIFO_EDCA 2
49877 +
49878 +//
49879 +// TX descriptor format, Tx ring, Mgmt Ring
49880 +//
49881 +#ifdef RT_BIG_ENDIAN
49882 +typedef struct PACKED _TXD_STRUC {
49883 + // Word 0
49884 + UINT32 SDPtr0;
49885 + // Word 1
49886 + UINT32 DMADONE:1;
49887 + UINT32 LastSec0:1;
49888 + UINT32 SDLen0:14;
49889 + UINT32 Burst:1;
49890 + UINT32 LastSec1:1;
49891 + UINT32 SDLen1:14;
49892 + // Word 2
49893 + UINT32 SDPtr1;
49894 + // Word 3
49895 + UINT32 ICO:1;
49896 + UINT32 UCO:1;
49897 + UINT32 TCO:1;
49898 + UINT32 rsv:2;
49899 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
49900 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
49901 + UINT32 rsv2:24;
49902 +} TXD_STRUC, *PTXD_STRUC;
49903 +#else
49904 +typedef struct PACKED _TXD_STRUC {
49905 + // Word 0
49906 + UINT32 SDPtr0;
49907 + // Word 1
49908 + UINT32 SDLen1:14;
49909 + UINT32 LastSec1:1;
49910 + UINT32 Burst:1;
49911 + UINT32 SDLen0:14;
49912 + UINT32 LastSec0:1;
49913 + UINT32 DMADONE:1;
49914 + //Word2
49915 + UINT32 SDPtr1;
49916 + //Word3
49917 + UINT32 rsv2:24;
49918 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
49919 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
49920 + UINT32 rsv:2;
49921 + UINT32 TCO:1; //
49922 + UINT32 UCO:1; //
49923 + UINT32 ICO:1; //
49924 +} TXD_STRUC, *PTXD_STRUC;
49925 +#endif
49926 +
49927 +
49928 +//
49929 +// TXD Wireless Information format for Tx ring and Mgmt Ring
49930 +//
49931 +//txop : for txop mode
49932 +// 0:txop for the MPDU frame will be handles by ASIC by register
49933 +// 1/2/3:the MPDU frame is send after PIFS/backoff/SIFS
49934 +#ifdef RT_BIG_ENDIAN
49935 +typedef struct PACKED _TXWI_STRUC {
49936 + // Word 0
49937 + UINT32 PHYMODE:2;
49938 + UINT32 TxBF:1; // 3*3
49939 + UINT32 rsv2:1;
49940 +// UINT32 rsv2:2;
49941 + UINT32 Ifs:1; //
49942 + UINT32 STBC:2; //channel bandwidth 20MHz or 40 MHz
49943 + UINT32 ShortGI:1;
49944 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
49945 + UINT32 MCS:7;
49946 +
49947 + UINT32 rsv:6;
49948 + 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.
49949 + UINT32 MpduDensity:3;
49950 + UINT32 AMPDU:1;
49951 +
49952 + UINT32 TS:1;
49953 + UINT32 CFACK:1;
49954 + UINT32 MIMOps:1; // the remote peer is in dynamic MIMO-PS mode
49955 + UINT32 FRAG:1; // 1 to inform TKIP engine this is a fragment.
49956 + // Word 1
49957 + UINT32 PacketId:4;
49958 + UINT32 MPDUtotalByteCount:12;
49959 + UINT32 WirelessCliID:8;
49960 + UINT32 BAWinSize:6;
49961 + UINT32 NSEQ:1;
49962 + UINT32 ACK:1;
49963 + // Word 2
49964 + UINT32 IV;
49965 + // Word 3
49966 + UINT32 EIV;
49967 +} TXWI_STRUC, *PTXWI_STRUC;
49968 +#else
49969 +typedef struct PACKED _TXWI_STRUC {
49970 + // Word 0
49971 + UINT32 FRAG:1; // 1 to inform TKIP engine this is a fragment.
49972 + UINT32 MIMOps:1; // the remote peer is in dynamic MIMO-PS mode
49973 + UINT32 CFACK:1;
49974 + UINT32 TS:1;
49975 +
49976 + UINT32 AMPDU:1;
49977 + UINT32 MpduDensity:3;
49978 + UINT32 txop:2; //FOR "THIS" frame. 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs only when previous frame exchange is successful.
49979 + UINT32 rsv:6;
49980 +
49981 + UINT32 MCS:7;
49982 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
49983 + UINT32 ShortGI:1;
49984 + UINT32 STBC:2; // 1: STBC support MCS =0-7, 2,3 : RESERVE
49985 + UINT32 Ifs:1; //
49986 +// UINT32 rsv2:2; //channel bandwidth 20MHz or 40 MHz
49987 + UINT32 rsv2:1;
49988 + UINT32 TxBF:1; // 3*3
49989 + UINT32 PHYMODE:2;
49990 + // Word 1
49991 + UINT32 ACK:1;
49992 + UINT32 NSEQ:1;
49993 + UINT32 BAWinSize:6;
49994 + UINT32 WirelessCliID:8;
49995 + UINT32 MPDUtotalByteCount:12;
49996 + UINT32 PacketId:4;
49997 + //Word2
49998 + UINT32 IV;
49999 + //Word3
50000 + UINT32 EIV;
50001 +} TXWI_STRUC, *PTXWI_STRUC;
50002 +#endif
50003 +//
50004 +// Rx descriptor format, Rx Ring
50005 +//
50006 +//
50007 +// RXWI wireless information format, in PBF. invisible in driver.
50008 +//
50009 +#ifdef RT_BIG_ENDIAN
50010 +typedef struct PACKED _RXWI_STRUC {
50011 + // Word 0
50012 + UINT32 TID:4;
50013 + UINT32 MPDUtotalByteCount:12;
50014 + UINT32 UDF:3;
50015 + UINT32 BSSID:3;
50016 + UINT32 KeyIndex:2;
50017 + UINT32 WirelessCliID:8;
50018 + // Word 1
50019 + UINT32 PHYMODE:2; // 1: this RX frame is unicast to me
50020 + UINT32 rsv:3;
50021 + UINT32 STBC:2;
50022 + UINT32 ShortGI:1;
50023 + UINT32 BW:1;
50024 + UINT32 MCS:7;
50025 + UINT32 SEQUENCE:12;
50026 + UINT32 FRAG:4;
50027 + // Word 2
50028 + UINT32 rsv1:8;
50029 + UINT32 RSSI2:8;
50030 + UINT32 RSSI1:8;
50031 + UINT32 RSSI0:8;
50032 + // Word 3
50033 + UINT32 rsv2:16;
50034 + UINT32 SNR1:8;
50035 + UINT32 SNR0:8;
50036 +} RXWI_STRUC, *PRXWI_STRUC;
50037 +#else
50038 +typedef struct PACKED _RXWI_STRUC {
50039 + // Word 0
50040 + UINT32 WirelessCliID:8;
50041 + UINT32 KeyIndex:2;
50042 + UINT32 BSSID:3;
50043 + UINT32 UDF:3;
50044 + UINT32 MPDUtotalByteCount:12;
50045 + UINT32 TID:4;
50046 + // Word 1
50047 + UINT32 FRAG:4;
50048 + UINT32 SEQUENCE:12;
50049 + UINT32 MCS:7;
50050 + UINT32 BW:1;
50051 + UINT32 ShortGI:1;
50052 + UINT32 STBC:2;
50053 + UINT32 rsv:3;
50054 + UINT32 PHYMODE:2; // 1: this RX frame is unicast to me
50055 + //Word2
50056 + UINT32 RSSI0:8;
50057 + UINT32 RSSI1:8;
50058 + UINT32 RSSI2:8;
50059 + UINT32 rsv1:8;
50060 + //Word3
50061 + UINT32 SNR0:8;
50062 + UINT32 SNR1:8;
50063 + UINT32 rsv2:16;
50064 +} RXWI_STRUC, *PRXWI_STRUC;
50065 +#endif
50066 +
50067 +
50068 +// =================================================================================
50069 +// HOST-MCU communication data structure
50070 +// =================================================================================
50071 +
50072 +//
50073 +// H2M_MAILBOX_CSR: Host-to-MCU Mailbox
50074 +//
50075 +#ifdef RT_BIG_ENDIAN
50076 +typedef union _H2M_MAILBOX_STRUC {
50077 + struct {
50078 + UINT32 Owner:8;
50079 + UINT32 CmdToken:8; // 0xff tells MCU not to report CmdDoneInt after excuting the command
50080 + UINT32 HighByte:8;
50081 + UINT32 LowByte:8;
50082 + } field;
50083 + UINT32 word;
50084 +} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC;
50085 +#else
50086 +typedef union _H2M_MAILBOX_STRUC {
50087 + struct {
50088 + UINT32 LowByte:8;
50089 + UINT32 HighByte:8;
50090 + UINT32 CmdToken:8;
50091 + UINT32 Owner:8;
50092 + } field;
50093 + UINT32 word;
50094 +} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC;
50095 +#endif
50096 +
50097 +//
50098 +// M2H_CMD_DONE_CSR: MCU-to-Host command complete indication
50099 +//
50100 +#ifdef RT_BIG_ENDIAN
50101 +typedef union _M2H_CMD_DONE_STRUC {
50102 + struct {
50103 + UINT32 CmdToken3;
50104 + UINT32 CmdToken2;
50105 + UINT32 CmdToken1;
50106 + UINT32 CmdToken0;
50107 + } field;
50108 + UINT32 word;
50109 +} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC;
50110 +#else
50111 +typedef union _M2H_CMD_DONE_STRUC {
50112 + struct {
50113 + UINT32 CmdToken0;
50114 + UINT32 CmdToken1;
50115 + UINT32 CmdToken2;
50116 + UINT32 CmdToken3;
50117 + } field;
50118 + UINT32 word;
50119 +} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC;
50120 +#endif
50121 +
50122 +
50123 +
50124 +//
50125 +// MCU_LEDCS: MCU LED Control Setting.
50126 +//
50127 +#ifdef RT_BIG_ENDIAN
50128 +typedef union _MCU_LEDCS_STRUC {
50129 + struct {
50130 + UCHAR Polarity:1;
50131 + UCHAR LedMode:7;
50132 + } field;
50133 + UCHAR word;
50134 +} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC;
50135 +#else
50136 +typedef union _MCU_LEDCS_STRUC {
50137 + struct {
50138 + UCHAR LedMode:7;
50139 + UCHAR Polarity:1;
50140 + } field;
50141 + UCHAR word;
50142 +} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC;
50143 +#endif
50144 +// =================================================================================
50145 +// Register format
50146 +// =================================================================================
50147 +
50148 +
50149 +
50150 +//NAV_TIME_CFG :NAV
50151 +#ifdef RT_BIG_ENDIAN
50152 +typedef union _NAV_TIME_CFG_STRUC {
50153 + struct {
50154 + USHORT rsv:6;
50155 + USHORT ZeroSifs:1; // Applied zero SIFS timer after OFDM RX 0: disable
50156 + USHORT Eifs:9; // in unit of 1-us
50157 + UCHAR SlotTime; // in unit of 1-us
50158 + UCHAR Sifs; // in unit of 1-us
50159 + } field;
50160 + UINT32 word;
50161 +} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC;
50162 +#else
50163 +typedef union _NAV_TIME_CFG_STRUC {
50164 + struct {
50165 + UCHAR Sifs; // in unit of 1-us
50166 + UCHAR SlotTime; // in unit of 1-us
50167 + USHORT Eifs:9; // in unit of 1-us
50168 + USHORT ZeroSifs:1; // Applied zero SIFS timer after OFDM RX 0: disable
50169 + USHORT rsv:6;
50170 + } field;
50171 + UINT32 word;
50172 +} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC;
50173 +#endif
50174 +
50175 +
50176 +
50177 +
50178 +
50179 +//
50180 +// RX_FILTR_CFG: /RX configuration register
50181 +//
50182 +#ifdef RT_BIG_ENDIAN
50183 +typedef union RX_FILTR_CFG_STRUC {
50184 + struct {
50185 + UINT32 :15;
50186 + UINT32 DropRsvCntlType:1;
50187 +
50188 + UINT32 DropBAR:1; //
50189 + UINT32 DropBA:1; //
50190 + UINT32 DropPsPoll:1; // Drop Ps-Poll
50191 + UINT32 DropRts:1; // Drop Ps-Poll
50192 +
50193 + UINT32 DropCts:1; // Drop Ps-Poll
50194 + UINT32 DropAck:1; // Drop Ps-Poll
50195 + UINT32 DropCFEnd:1; // Drop Ps-Poll
50196 + UINT32 DropCFEndAck:1; // Drop Ps-Poll
50197 +
50198 + UINT32 DropDuplicate:1; // Drop duplicate frame
50199 + UINT32 DropBcast:1; // Drop broadcast frames
50200 + UINT32 DropMcast:1; // Drop multicast frames
50201 + UINT32 DropVerErr:1; // Drop version error frame
50202 +
50203 + UINT32 DropNotMyBSSID:1; // Drop fram ToDs bit is true
50204 + UINT32 DropNotToMe:1; // Drop not to me unicast frame
50205 + UINT32 DropPhyErr:1; // Drop physical error
50206 + UINT32 DropCRCErr:1; // Drop CRC error
50207 + } field;
50208 + UINT32 word;
50209 +} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC;
50210 +#else
50211 +typedef union _RX_FILTR_CFG_STRUC {
50212 + struct {
50213 + UINT32 DropCRCErr:1; // Drop CRC error
50214 + UINT32 DropPhyErr:1; // Drop physical error
50215 + UINT32 DropNotToMe:1; // Drop not to me unicast frame
50216 + UINT32 DropNotMyBSSID:1; // Drop fram ToDs bit is true
50217 +
50218 + UINT32 DropVerErr:1; // Drop version error frame
50219 + UINT32 DropMcast:1; // Drop multicast frames
50220 + UINT32 DropBcast:1; // Drop broadcast frames
50221 + UINT32 DropDuplicate:1; // Drop duplicate frame
50222 +
50223 + UINT32 DropCFEndAck:1; // Drop Ps-Poll
50224 + UINT32 DropCFEnd:1; // Drop Ps-Poll
50225 + UINT32 DropAck:1; // Drop Ps-Poll
50226 + UINT32 DropCts:1; // Drop Ps-Poll
50227 +
50228 + UINT32 DropRts:1; // Drop Ps-Poll
50229 + UINT32 DropPsPoll:1; // Drop Ps-Poll
50230 + UINT32 DropBA:1; //
50231 + UINT32 DropBAR:1; //
50232 +
50233 + UINT32 DropRsvCntlType:1;
50234 + UINT32 :15;
50235 + } field;
50236 + UINT32 word;
50237 +} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC;
50238 +#endif
50239 +
50240 +
50241 +
50242 +
50243 +//
50244 +// PHY_CSR4: RF serial control register
50245 +//
50246 +#ifdef RT_BIG_ENDIAN
50247 +typedef union _PHY_CSR4_STRUC {
50248 + struct {
50249 + UINT32 Busy:1; // 1: ASIC is busy execute RF programming.
50250 + UINT32 PLL_LD:1; // RF PLL_LD status
50251 + UINT32 IFSelect:1; // 1: select IF to program, 0: select RF to program
50252 + UINT32 NumberOfBits:5; // Number of bits used in RFRegValue (I:20, RFMD:22)
50253 + UINT32 RFRegValue:24; // Register value (include register id) serial out to RF/IF chip.
50254 + } field;
50255 + UINT32 word;
50256 +} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC;
50257 +#else
50258 +typedef union _PHY_CSR4_STRUC {
50259 + struct {
50260 + UINT32 RFRegValue:24; // Register value (include register id) serial out to RF/IF chip.
50261 + UINT32 NumberOfBits:5; // Number of bits used in RFRegValue (I:20, RFMD:22)
50262 + UINT32 IFSelect:1; // 1: select IF to program, 0: select RF to program
50263 + UINT32 PLL_LD:1; // RF PLL_LD status
50264 + UINT32 Busy:1; // 1: ASIC is busy execute RF programming.
50265 + } field;
50266 + UINT32 word;
50267 +} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC;
50268 +#endif
50269 +
50270 +
50271 +//
50272 +// SEC_CSR5: shared key table security mode register
50273 +//
50274 +#ifdef RT_BIG_ENDIAN
50275 +typedef union _SEC_CSR5_STRUC {
50276 + struct {
50277 + UINT32 :1;
50278 + UINT32 Bss3Key3CipherAlg:3;
50279 + UINT32 :1;
50280 + UINT32 Bss3Key2CipherAlg:3;
50281 + UINT32 :1;
50282 + UINT32 Bss3Key1CipherAlg:3;
50283 + UINT32 :1;
50284 + UINT32 Bss3Key0CipherAlg:3;
50285 + UINT32 :1;
50286 + UINT32 Bss2Key3CipherAlg:3;
50287 + UINT32 :1;
50288 + UINT32 Bss2Key2CipherAlg:3;
50289 + UINT32 :1;
50290 + UINT32 Bss2Key1CipherAlg:3;
50291 + UINT32 :1;
50292 + UINT32 Bss2Key0CipherAlg:3;
50293 + } field;
50294 + UINT32 word;
50295 +} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC;
50296 +#else
50297 +typedef union _SEC_CSR5_STRUC {
50298 + struct {
50299 + UINT32 Bss2Key0CipherAlg:3;
50300 + UINT32 :1;
50301 + UINT32 Bss2Key1CipherAlg:3;
50302 + UINT32 :1;
50303 + UINT32 Bss2Key2CipherAlg:3;
50304 + UINT32 :1;
50305 + UINT32 Bss2Key3CipherAlg:3;
50306 + UINT32 :1;
50307 + UINT32 Bss3Key0CipherAlg:3;
50308 + UINT32 :1;
50309 + UINT32 Bss3Key1CipherAlg:3;
50310 + UINT32 :1;
50311 + UINT32 Bss3Key2CipherAlg:3;
50312 + UINT32 :1;
50313 + UINT32 Bss3Key3CipherAlg:3;
50314 + UINT32 :1;
50315 + } field;
50316 + UINT32 word;
50317 +} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC;
50318 +#endif
50319 +
50320 +
50321 +//
50322 +// HOST_CMD_CSR: For HOST to interrupt embedded processor
50323 +//
50324 +#ifdef RT_BIG_ENDIAN
50325 +typedef union _HOST_CMD_CSR_STRUC {
50326 + struct {
50327 + UINT32 Rsv:24;
50328 + UINT32 HostCommand:8;
50329 + } field;
50330 + UINT32 word;
50331 +} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC;
50332 +#else
50333 +typedef union _HOST_CMD_CSR_STRUC {
50334 + struct {
50335 + UINT32 HostCommand:8;
50336 + UINT32 Rsv:24;
50337 + } field;
50338 + UINT32 word;
50339 +} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC;
50340 +#endif
50341 +
50342 +
50343 +//
50344 +// AIFSN_CSR: AIFSN for each EDCA AC
50345 +//
50346 +
50347 +
50348 +
50349 +//
50350 +// E2PROM_CSR: EEPROM control register
50351 +//
50352 +#ifdef RT_BIG_ENDIAN
50353 +typedef union _E2PROM_CSR_STRUC {
50354 + struct {
50355 + UINT32 Rsvd:25;
50356 + UINT32 LoadStatus:1; // 1:loading, 0:done
50357 + UINT32 Type:1; // 1: 93C46, 0:93C66
50358 + UINT32 EepromDO:1;
50359 + UINT32 EepromDI:1;
50360 + UINT32 EepromCS:1;
50361 + UINT32 EepromSK:1;
50362 + UINT32 Reload:1; // Reload EEPROM content, write one to reload, self-cleared.
50363 + } field;
50364 + UINT32 word;
50365 +} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC;
50366 +#else
50367 +typedef union _E2PROM_CSR_STRUC {
50368 + struct {
50369 + UINT32 Reload:1; // Reload EEPROM content, write one to reload, self-cleared.
50370 + UINT32 EepromSK:1;
50371 + UINT32 EepromCS:1;
50372 + UINT32 EepromDI:1;
50373 + UINT32 EepromDO:1;
50374 + UINT32 Type:1; // 1: 93C46, 0:93C66
50375 + UINT32 LoadStatus:1; // 1:loading, 0:done
50376 + UINT32 Rsvd:25;
50377 + } field;
50378 + UINT32 word;
50379 +} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC;
50380 +#endif
50381 +
50382 +
50383 +// -------------------------------------------------------------------
50384 +// E2PROM data layout
50385 +// -------------------------------------------------------------------
50386 +
50387 +//
50388 +// EEPROM antenna select format
50389 +//
50390 +#ifdef RT_BIG_ENDIAN
50391 +typedef union _EEPROM_ANTENNA_STRUC {
50392 + struct {
50393 + USHORT Rsv:4;
50394 + USHORT RfIcType:4; // see E2PROM document
50395 + USHORT TxPath:4; // 1: 1T, 2: 2T
50396 + USHORT RxPath:4; // 1: 1R, 2: 2R, 3: 3R
50397 + } field;
50398 + USHORT word;
50399 +} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC;
50400 +#else
50401 +typedef union _EEPROM_ANTENNA_STRUC {
50402 + struct {
50403 + USHORT RxPath:4; // 1: 1R, 2: 2R, 3: 3R
50404 + USHORT TxPath:4; // 1: 1T, 2: 2T
50405 + USHORT RfIcType:4; // see E2PROM document
50406 + USHORT Rsv:4;
50407 + } field;
50408 + USHORT word;
50409 +} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC;
50410 +#endif
50411 +
50412 +#ifdef RT_BIG_ENDIAN
50413 +typedef union _EEPROM_NIC_CINFIG2_STRUC {
50414 + struct {
50415 + USHORT Rsv2:6; // must be 0
50416 + USHORT BW40MAvailForA:1; // 0:enable, 1:disable
50417 + USHORT BW40MAvailForG:1; // 0:enable, 1:disable
50418 + USHORT EnableWPSPBC:1; // WPS PBC Control bit
50419 + USHORT BW40MSidebandForA:1;
50420 + USHORT BW40MSidebandForG:1;
50421 + USHORT CardbusAcceleration:1; // !!! NOTE: 0 - enable, 1 - disable
50422 + USHORT ExternalLNAForA:1; // external LNA enable for 5G
50423 + USHORT ExternalLNAForG:1; // external LNA enable for 2.4G
50424 + USHORT DynamicTxAgcControl:1; //
50425 + USHORT HardwareRadioControl:1; // Whether RF is controlled by driver or HW. 1:enable hw control, 0:disable
50426 + } field;
50427 + USHORT word;
50428 +} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC;
50429 +#else
50430 +typedef union _EEPROM_NIC_CINFIG2_STRUC {
50431 + struct {
50432 + USHORT HardwareRadioControl:1; // 1:enable, 0:disable
50433 + USHORT DynamicTxAgcControl:1; //
50434 + USHORT ExternalLNAForG:1; //
50435 + USHORT ExternalLNAForA:1; // external LNA enable for 2.4G
50436 + USHORT CardbusAcceleration:1; // !!! NOTE: 0 - enable, 1 - disable
50437 + USHORT BW40MSidebandForG:1;
50438 + USHORT BW40MSidebandForA:1;
50439 + USHORT EnableWPSPBC:1; // WPS PBC Control bit
50440 + USHORT BW40MAvailForG:1; // 0:enable, 1:disable
50441 + USHORT BW40MAvailForA:1; // 0:enable, 1:disable
50442 + USHORT Rsv2:6; // must be 0
50443 + } field;
50444 + USHORT word;
50445 +} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC;
50446 +#endif
50447 +
50448 +//
50449 +// TX_PWR Value valid range 0xFA(-6) ~ 0x24(36)
50450 +//
50451 +#ifdef RT_BIG_ENDIAN
50452 +typedef union _EEPROM_TX_PWR_STRUC {
50453 + struct {
50454 + CHAR Byte1; // High Byte
50455 + CHAR Byte0; // Low Byte
50456 + } field;
50457 + USHORT word;
50458 +} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC;
50459 +#else
50460 +typedef union _EEPROM_TX_PWR_STRUC {
50461 + struct {
50462 + CHAR Byte0; // Low Byte
50463 + CHAR Byte1; // High Byte
50464 + } field;
50465 + USHORT word;
50466 +} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC;
50467 +#endif
50468 +
50469 +#ifdef RT_BIG_ENDIAN
50470 +typedef union _EEPROM_VERSION_STRUC {
50471 + struct {
50472 + UCHAR Version; // High Byte
50473 + UCHAR FaeReleaseNumber; // Low Byte
50474 + } field;
50475 + USHORT word;
50476 +} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC;
50477 +#else
50478 +typedef union _EEPROM_VERSION_STRUC {
50479 + struct {
50480 + UCHAR FaeReleaseNumber; // Low Byte
50481 + UCHAR Version; // High Byte
50482 + } field;
50483 + USHORT word;
50484 +} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC;
50485 +#endif
50486 +
50487 +#ifdef RT_BIG_ENDIAN
50488 +typedef union _EEPROM_LED_STRUC {
50489 + struct {
50490 + USHORT Rsvd:3; // Reserved
50491 + USHORT LedMode:5; // Led mode.
50492 + USHORT PolarityGPIO_4:1; // Polarity GPIO#4 setting.
50493 + USHORT PolarityGPIO_3:1; // Polarity GPIO#3 setting.
50494 + USHORT PolarityGPIO_2:1; // Polarity GPIO#2 setting.
50495 + USHORT PolarityGPIO_1:1; // Polarity GPIO#1 setting.
50496 + USHORT PolarityGPIO_0:1; // Polarity GPIO#0 setting.
50497 + USHORT PolarityACT:1; // Polarity ACT setting.
50498 + USHORT PolarityRDY_A:1; // Polarity RDY_A setting.
50499 + USHORT PolarityRDY_G:1; // Polarity RDY_G setting.
50500 + } field;
50501 + USHORT word;
50502 +} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC;
50503 +#else
50504 +typedef union _EEPROM_LED_STRUC {
50505 + struct {
50506 + USHORT PolarityRDY_G:1; // Polarity RDY_G setting.
50507 + USHORT PolarityRDY_A:1; // Polarity RDY_A setting.
50508 + USHORT PolarityACT:1; // Polarity ACT setting.
50509 + USHORT PolarityGPIO_0:1; // Polarity GPIO#0 setting.
50510 + USHORT PolarityGPIO_1:1; // Polarity GPIO#1 setting.
50511 + USHORT PolarityGPIO_2:1; // Polarity GPIO#2 setting.
50512 + USHORT PolarityGPIO_3:1; // Polarity GPIO#3 setting.
50513 + USHORT PolarityGPIO_4:1; // Polarity GPIO#4 setting.
50514 + USHORT LedMode:5; // Led mode.
50515 + USHORT Rsvd:3; // Reserved
50516 + } field;
50517 + USHORT word;
50518 +} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC;
50519 +#endif
50520 +
50521 +#ifdef RT_BIG_ENDIAN
50522 +typedef union _EEPROM_TXPOWER_DELTA_STRUC {
50523 + struct {
50524 + UCHAR TxPowerEnable:1;// Enable
50525 + UCHAR Type:1; // 1: plus the delta value, 0: minus the delta value
50526 + UCHAR DeltaValue:6; // Tx Power dalta value (MAX=4)
50527 + } field;
50528 + UCHAR value;
50529 +} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC;
50530 +#else
50531 +typedef union _EEPROM_TXPOWER_DELTA_STRUC {
50532 + struct {
50533 + UCHAR DeltaValue:6; // Tx Power dalta value (MAX=4)
50534 + UCHAR Type:1; // 1: plus the delta value, 0: minus the delta value
50535 + UCHAR TxPowerEnable:1;// Enable
50536 + } field;
50537 + UCHAR value;
50538 +} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC;
50539 +#endif
50540 +
50541 +//
50542 +// QOS_CSR0: TXOP holder address0 register
50543 +//
50544 +#ifdef RT_BIG_ENDIAN
50545 +typedef union _QOS_CSR0_STRUC {
50546 + struct {
50547 + UCHAR Byte3; // MAC address byte 3
50548 + UCHAR Byte2; // MAC address byte 2
50549 + UCHAR Byte1; // MAC address byte 1
50550 + UCHAR Byte0; // MAC address byte 0
50551 + } field;
50552 + UINT32 word;
50553 +} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC;
50554 +#else
50555 +typedef union _QOS_CSR0_STRUC {
50556 + struct {
50557 + UCHAR Byte0; // MAC address byte 0
50558 + UCHAR Byte1; // MAC address byte 1
50559 + UCHAR Byte2; // MAC address byte 2
50560 + UCHAR Byte3; // MAC address byte 3
50561 + } field;
50562 + UINT32 word;
50563 +} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC;
50564 +#endif
50565 +
50566 +//
50567 +// QOS_CSR1: TXOP holder address1 register
50568 +//
50569 +#ifdef RT_BIG_ENDIAN
50570 +typedef union _QOS_CSR1_STRUC {
50571 + struct {
50572 + UCHAR Rsvd1;
50573 + UCHAR Rsvd0;
50574 + UCHAR Byte5; // MAC address byte 5
50575 + UCHAR Byte4; // MAC address byte 4
50576 + } field;
50577 + UINT32 word;
50578 +} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC;
50579 +#else
50580 +typedef union _QOS_CSR1_STRUC {
50581 + struct {
50582 + UCHAR Byte4; // MAC address byte 4
50583 + UCHAR Byte5; // MAC address byte 5
50584 + UCHAR Rsvd0;
50585 + UCHAR Rsvd1;
50586 + } field;
50587 + UINT32 word;
50588 +} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC;
50589 +#endif
50590 +
50591 +#define RF_CSR_CFG 0x500
50592 +#ifdef RT_BIG_ENDIAN
50593 +typedef union _RF_CSR_CFG_STRUC {
50594 + struct {
50595 + UINT Rsvd1:14; // Reserved
50596 + UINT RF_CSR_KICK:1; // kick RF register read/write
50597 + UINT RF_CSR_WR:1; // 0: read 1: write
50598 + UINT Rsvd2:3; // Reserved
50599 + UINT TESTCSR_RFACC_REGNUM:5; // RF register ID
50600 + UINT RF_CSR_DATA:8; // DATA
50601 + } field;
50602 + UINT word;
50603 +} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC;
50604 +#else
50605 +typedef union _RF_CSR_CFG_STRUC {
50606 + struct {
50607 + UINT RF_CSR_DATA:8; // DATA
50608 + UINT TESTCSR_RFACC_REGNUM:5; // RF register ID
50609 + UINT Rsvd2:3; // Reserved
50610 + UINT RF_CSR_WR:1; // 0: read 1: write
50611 + UINT RF_CSR_KICK:1; // kick RF register read/write
50612 + UINT Rsvd1:14; // Reserved
50613 + } field;
50614 + UINT word;
50615 +} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC;
50616 +#endif
50617 +
50618 +#endif // __RT28XX_H__
50619 --- /dev/null
50620 +++ b/drivers/staging/rt2870/rt_ate.c
50621 @@ -0,0 +1,6452 @@
50622 +/*
50623 + *************************************************************************
50624 + * Ralink Tech Inc.
50625 + * 5F., No.36, Taiyuan St., Jhubei City,
50626 + * Hsinchu County 302,
50627 + * Taiwan, R.O.C.
50628 + *
50629 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
50630 + *
50631 + * This program is free software; you can redistribute it and/or modify *
50632 + * it under the terms of the GNU General Public License as published by *
50633 + * the Free Software Foundation; either version 2 of the License, or *
50634 + * (at your option) any later version. *
50635 + * *
50636 + * This program is distributed in the hope that it will be useful, *
50637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
50638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
50639 + * GNU General Public License for more details. *
50640 + * *
50641 + * You should have received a copy of the GNU General Public License *
50642 + * along with this program; if not, write to the *
50643 + * Free Software Foundation, Inc., *
50644 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
50645 + * *
50646 + *************************************************************************
50647 + */
50648 +
50649 +#include "rt_config.h"
50650 +
50651 +#ifdef UCOS
50652 +INT IoctlResponse(PUCHAR payload, PUCHAR msg, INT len);
50653 +#endif // UCOS //
50654 +
50655 +#ifdef RALINK_ATE
50656 +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
50657 +extern RTMP_RF_REGS RF2850RegTable[];
50658 +extern UCHAR NUM_OF_2850_CHNL;
50659 +
50660 +#ifdef RT2870
50661 +extern UCHAR EpToQueue[];
50662 +extern VOID RTUSBRejectPendingPackets( IN PRTMP_ADAPTER pAd);
50663 +#endif // RT2870 //
50664 +
50665 +#ifdef UCOS
50666 +extern INT ConsoleResponse(IN PUCHAR buff);
50667 +extern int (*remote_display)(char *);
50668 +#endif // UCOS //
50669 +
50670 +static CHAR CCKRateTable[] = {0, 1, 2, 3, 8, 9, 10, 11, -1}; /* CCK Mode. */
50671 +static CHAR OFDMRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, -1}; /* OFDM Mode. */
50672 +static CHAR HTMIXRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}; /* HT Mix Mode. */
50673 +
50674 +static INT TxDmaBusy(
50675 + IN PRTMP_ADAPTER pAd);
50676 +
50677 +static INT RxDmaBusy(
50678 + IN PRTMP_ADAPTER pAd);
50679 +
50680 +static VOID RtmpDmaEnable(
50681 + IN PRTMP_ADAPTER pAd,
50682 + IN INT Enable);
50683 +
50684 +static VOID BbpSoftReset(
50685 + IN PRTMP_ADAPTER pAd);
50686 +
50687 +static VOID RtmpRfIoWrite(
50688 + IN PRTMP_ADAPTER pAd);
50689 +
50690 +static INT ATESetUpFrame(
50691 + IN PRTMP_ADAPTER pAd,
50692 + IN UINT32 TxIdx);
50693 +
50694 +static INT ATETxPwrHandler(
50695 + IN PRTMP_ADAPTER pAd,
50696 + IN char index);
50697 +
50698 +static INT ATECmdHandler(
50699 + IN PRTMP_ADAPTER pAd,
50700 + IN PUCHAR arg);
50701 +
50702 +static int CheckMCSValid(
50703 + IN UCHAR Mode,
50704 + IN UCHAR Mcs);
50705 +
50706 +
50707 +#ifdef RT2870
50708 +static VOID ATEWriteTxInfo(
50709 + IN PRTMP_ADAPTER pAd,
50710 + IN PTXINFO_STRUC pTxInfo,
50711 + IN USHORT USBDMApktLen,
50712 + IN BOOLEAN bWiv,
50713 + IN UCHAR QueueSel,
50714 + IN UCHAR NextValid,
50715 + IN UCHAR TxBurst);
50716 +
50717 +static VOID ATEWriteTxWI(
50718 + IN PRTMP_ADAPTER pAd,
50719 + IN PTXWI_STRUC pTxWI,
50720 + IN BOOLEAN FRAG,
50721 + IN BOOLEAN InsTimestamp,
50722 + IN BOOLEAN AMPDU,
50723 + IN BOOLEAN Ack,
50724 + IN BOOLEAN NSeq, // HW new a sequence.
50725 + IN UCHAR BASize,
50726 + IN UCHAR WCID,
50727 + IN ULONG Length,
50728 + IN UCHAR PID,
50729 + IN UCHAR MIMOps,
50730 + IN UCHAR Txopmode,
50731 + IN BOOLEAN CfAck,
50732 + IN HTTRANSMIT_SETTING Transmit);
50733 +
50734 +#endif // RT2870 //
50735 +
50736 +static VOID SetJapanFilter(
50737 + IN PRTMP_ADAPTER pAd);
50738 +
50739 +/*=========================end of prototype=========================*/
50740 +
50741 +
50742 +#ifdef RT2870
50743 +static INT TxDmaBusy(
50744 + IN PRTMP_ADAPTER pAd)
50745 +{
50746 + INT result;
50747 + USB_DMA_CFG_STRUC UsbCfg;
50748 +
50749 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
50750 + if (UsbCfg.field.TxBusy)
50751 + result = 1;
50752 + else
50753 + result = 0;
50754 +
50755 + return result;
50756 +}
50757 +
50758 +static INT RxDmaBusy(
50759 + IN PRTMP_ADAPTER pAd)
50760 +{
50761 + INT result;
50762 + USB_DMA_CFG_STRUC UsbCfg;
50763 +
50764 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
50765 + if (UsbCfg.field.RxBusy)
50766 + result = 1;
50767 + else
50768 + result = 0;
50769 +
50770 + return result;
50771 +}
50772 +
50773 +static VOID RtmpDmaEnable(
50774 + IN PRTMP_ADAPTER pAd,
50775 + IN INT Enable)
50776 +{
50777 + BOOLEAN value;
50778 + ULONG WaitCnt;
50779 + USB_DMA_CFG_STRUC UsbCfg;
50780 +
50781 + value = Enable > 0 ? 1 : 0;
50782 +
50783 + // check DMA is in busy mode.
50784 + WaitCnt = 0;
50785 + while (TxDmaBusy(pAd) || RxDmaBusy(pAd))
50786 + {
50787 + RTMPusecDelay(10);
50788 + if (WaitCnt++ > 100)
50789 + break;
50790 + }
50791 +
50792 + //Why not to clear USB DMA TX path first ???
50793 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
50794 + UsbCfg.field.TxBulkEn = value;
50795 + UsbCfg.field.RxBulkEn = value;
50796 + RTMP_IO_WRITE32(pAd, USB_DMA_CFG, UsbCfg.word); // abort all TX rings
50797 + RTMPusecDelay(5000);
50798 +
50799 + return;
50800 +}
50801 +#endif // RT2870 //
50802 +
50803 +static VOID BbpSoftReset(
50804 + IN PRTMP_ADAPTER pAd)
50805 +{
50806 + UCHAR BbpData = 0;
50807 +
50808 + // Soft reset, set BBP R21 bit0=1->0
50809 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
50810 + BbpData |= 0x00000001; //set bit0=1
50811 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
50812 +
50813 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
50814 + BbpData &= ~(0x00000001); //set bit0=0
50815 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
50816 +
50817 + return;
50818 +}
50819 +
50820 +static VOID RtmpRfIoWrite(
50821 + IN PRTMP_ADAPTER pAd)
50822 +{
50823 + // Set RF value 1's set R3[bit2] = [0]
50824 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
50825 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
50826 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
50827 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
50828 +
50829 + RTMPusecDelay(200);
50830 +
50831 + // Set RF value 2's set R3[bit2] = [1]
50832 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
50833 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
50834 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
50835 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
50836 +
50837 + RTMPusecDelay(200);
50838 +
50839 + // Set RF value 3's set R3[bit2] = [0]
50840 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
50841 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
50842 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
50843 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
50844 +
50845 + return;
50846 +}
50847 +
50848 +static int CheckMCSValid(
50849 + UCHAR Mode,
50850 + UCHAR Mcs)
50851 +{
50852 + int i;
50853 + PCHAR pRateTab;
50854 +
50855 + switch(Mode)
50856 + {
50857 + case 0:
50858 + pRateTab = CCKRateTable;
50859 + break;
50860 + case 1:
50861 + pRateTab = OFDMRateTable;
50862 + break;
50863 + case 2:
50864 + case 3:
50865 + pRateTab = HTMIXRateTable;
50866 + break;
50867 + default:
50868 + ATEDBGPRINT(RT_DEBUG_ERROR, ("unrecognizable Tx Mode %d\n", Mode));
50869 + return -1;
50870 + break;
50871 + }
50872 +
50873 + i = 0;
50874 + while(pRateTab[i] != -1)
50875 + {
50876 + if (pRateTab[i] == Mcs)
50877 + return 0;
50878 + i++;
50879 + }
50880 +
50881 + return -1;
50882 +}
50883 +
50884 +#if 1
50885 +static INT ATETxPwrHandler(
50886 + IN PRTMP_ADAPTER pAd,
50887 + IN char index)
50888 +{
50889 + ULONG R;
50890 + CHAR TxPower;
50891 + UCHAR Bbp94 = 0;
50892 + BOOLEAN bPowerReduce = FALSE;
50893 +
50894 +#ifdef RALINK_28xx_QA
50895 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
50896 + {
50897 + /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
50898 + ** are not synchronized.
50899 + */
50900 +/*
50901 + pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
50902 + pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
50903 +*/
50904 + return 0;
50905 + }
50906 + else
50907 +#endif // RALINK_28xx_QA //
50908 + {
50909 + TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
50910 +
50911 + if (pAd->ate.Channel <= 14)
50912 + {
50913 + if (TxPower > 31)
50914 + {
50915 + //
50916 + // R3, R4 can't large than 31 (0x24), 31 ~ 36 used by BBP 94
50917 + //
50918 + R = 31;
50919 + if (TxPower <= 36)
50920 + Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
50921 + }
50922 + else if (TxPower < 0)
50923 + {
50924 + //
50925 + // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
50926 + //
50927 + R = 0;
50928 + if (TxPower >= -6)
50929 + Bbp94 = BBPR94_DEFAULT + TxPower;
50930 + }
50931 + else
50932 + {
50933 + // 0 ~ 31
50934 + R = (ULONG) TxPower;
50935 + Bbp94 = BBPR94_DEFAULT;
50936 + }
50937 +
50938 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
50939 + }
50940 + else// 5.5 GHz
50941 + {
50942 + if (TxPower > 15)
50943 + {
50944 + //
50945 + // R3, R4 can't large than 15 (0x0F)
50946 + //
50947 + R = 15;
50948 + }
50949 + else if (TxPower < 0)
50950 + {
50951 + //
50952 + // R3, R4 can't less than 0
50953 + //
50954 + // -1 ~ -7
50955 + ASSERT((TxPower >= -7));
50956 + R = (ULONG)(TxPower + 7);
50957 + bPowerReduce = TRUE;
50958 + }
50959 + else
50960 + {
50961 + // 0 ~ 15
50962 + R = (ULONG) TxPower;
50963 + }
50964 +
50965 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%lu)\n", __FUNCTION__, TxPower, R));
50966 + }
50967 +
50968 + if (pAd->ate.Channel <= 14)
50969 + {
50970 + if (index == 0)
50971 + {
50972 + R = R << 9; // shift TX power control to correct RF(R3) register bit position
50973 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
50974 + pAd->LatchRfRegs.R3 = R;
50975 + }
50976 + else
50977 + {
50978 + R = R << 6; // shift TX power control to correct RF(R4) register bit position
50979 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
50980 + pAd->LatchRfRegs.R4 = R;
50981 + }
50982 + }
50983 + else// 5.5GHz
50984 + {
50985 + if (bPowerReduce == FALSE)
50986 + {
50987 + if (index == 0)
50988 + {
50989 + R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
50990 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
50991 + pAd->LatchRfRegs.R3 = R;
50992 + }
50993 + else
50994 + {
50995 + R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
50996 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
50997 + pAd->LatchRfRegs.R4 = R;
50998 + }
50999 + }
51000 + else
51001 + {
51002 + if (index == 0)
51003 + {
51004 + R = (R << 10); // shift TX power control to correct RF(R3) register bit position
51005 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51006 +
51007 + /* Clear bit 9 of R3 to reduce 7dB. */
51008 + pAd->LatchRfRegs.R3 = (R & (~(1 << 9)));
51009 + }
51010 + else
51011 + {
51012 + R = (R << 7); // shift TX power control to correct RF(R4) register bit position
51013 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51014 +
51015 + /* Clear bit 6 of R4 to reduce 7dB. */
51016 + pAd->LatchRfRegs.R4 = (R & (~(1 << 6)));
51017 + }
51018 + }
51019 + }
51020 +
51021 + RtmpRfIoWrite(pAd);
51022 +
51023 + return 0;
51024 + }
51025 +}
51026 +#else// 1 //
51027 +static INT ATETxPwrHandler(
51028 + IN PRTMP_ADAPTER pAd,
51029 + IN char index)
51030 +{
51031 + ULONG R;
51032 + CHAR TxPower;
51033 + UCHAR Bbp94 = 0;
51034 +
51035 +#ifdef RALINK_28xx_QA
51036 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
51037 + {
51038 + // TODO: how to get current TxPower0/1 from pAd->LatchRfRegs ?
51039 + /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
51040 + ** are not synchronized.
51041 + */
51042 +/*
51043 + pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
51044 + pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
51045 +*/
51046 + return 0;
51047 + }
51048 + else
51049 +#endif // RALINK_28xx_QA //
51050 + {
51051 + TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
51052 +
51053 + if (TxPower > 31)
51054 + {
51055 + //
51056 + // R3, R4 can't large than 36 (0x24), 31 ~ 36 used by BBP 94
51057 + //
51058 + R = 31;
51059 + if (TxPower <= 36)
51060 + Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
51061 + }
51062 + else if (TxPower < 0)
51063 + {
51064 + //
51065 + // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
51066 + //
51067 + R = 0;
51068 + if (TxPower >= -6)
51069 + Bbp94 = BBPR94_DEFAULT + TxPower;
51070 + }
51071 + else
51072 + {
51073 + // 0 ~ 31
51074 + R = (ULONG) TxPower;
51075 + Bbp94 = BBPR94_DEFAULT;
51076 + }
51077 +
51078 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R3=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
51079 +
51080 + if (pAd->ate.Channel <= 14)
51081 + {
51082 + if (index == 0)
51083 + {
51084 + R = R << 9; // shift TX power control to correct RF(R3) register bit position
51085 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51086 + pAd->LatchRfRegs.R3 = R;
51087 + }
51088 + else
51089 + {
51090 + R = R << 6; // shift TX power control to correct RF(R4) register bit position
51091 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51092 + pAd->LatchRfRegs.R4 = R;
51093 + }
51094 + }
51095 + else
51096 + {
51097 + if (index == 0)
51098 + {
51099 + R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
51100 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51101 + pAd->LatchRfRegs.R3 = R;
51102 + }
51103 + else
51104 + {
51105 + R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
51106 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51107 + pAd->LatchRfRegs.R4 = R;
51108 + }
51109 + }
51110 +
51111 + RtmpRfIoWrite(pAd);
51112 +
51113 + return 0;
51114 + }
51115 +}
51116 +#endif // 1 //
51117 +/*
51118 + ==========================================================================
51119 + Description:
51120 + Set ATE operation mode to
51121 + 0. ATESTART = Start ATE Mode
51122 + 1. ATESTOP = Stop ATE Mode
51123 + 2. TXCONT = Continuous Transmit
51124 + 3. TXCARR = Transmit Carrier
51125 + 4. TXFRAME = Transmit Frames
51126 + 5. RXFRAME = Receive Frames
51127 +#ifdef RALINK_28xx_QA
51128 + 6. TXSTOP = Stop Any Type of Transmition
51129 + 7. RXSTOP = Stop Receiving Frames
51130 +#endif // RALINK_28xx_QA //
51131 + Return:
51132 + TRUE if all parameters are OK, FALSE otherwise
51133 + ==========================================================================
51134 +*/
51135 +/* */
51136 +/* */
51137 +/*=======================End of RT2860=======================*/
51138 +
51139 +
51140 +/*======================Start of RT2870======================*/
51141 +/* */
51142 +/* */
51143 +
51144 +#ifdef RT2870
51145 +static INT ATECmdHandler(
51146 + IN PRTMP_ADAPTER pAd,
51147 + IN PUCHAR arg)
51148 +{
51149 + UINT32 Value;
51150 + UCHAR BbpData;
51151 + UINT32 MacData;
51152 + UINT i=0, atemode;
51153 + //NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
51154 + //PUCHAR pDest;
51155 + UINT32 temp;
51156 + ULONG IrqFlags;
51157 +
51158 + ATEDBGPRINT(RT_DEBUG_TRACE, ("===> ATECmdHandler()\n"));
51159 + ATEAsicSwitchChannel(pAd);
51160 + /* AsicLockChannel() is empty function so far in fact */
51161 + AsicLockChannel(pAd, pAd->ate.Channel);
51162 +
51163 + RTMPusecDelay(5000);
51164 +
51165 + // Default value in BBP R22 is 0x0.
51166 + BbpData = 0;
51167 +
51168 + /* Enter ATE mode and set Tx/Rx Idle */
51169 + if (!strcmp(arg, "ATESTART"))
51170 + {
51171 +#ifdef CONFIG_STA_SUPPORT
51172 + BOOLEAN Cancelled;
51173 +#endif // CONFIG_STA_SUPPORT //
51174 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTART\n"));
51175 +
51176 + netif_stop_queue(pAd->net_dev);
51177 +
51178 + atemode = pAd->ate.Mode;
51179 + pAd->ate.Mode = ATE_START;
51180 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
51181 + // Disable Rx
51182 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51183 + Value &= ~(1 << 3);
51184 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51185 +
51186 + // Disable auto responder
51187 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
51188 + temp = temp & 0xFFFFFFFE;
51189 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
51190 +
51191 + // read MAC_SYS_CTRL and backup MAC_SYS_CTRL value.
51192 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51193 + // clean bit4 to stop continuous Tx production test.
51194 + MacData &= 0xFFFFFFEF;
51195 + // Stop continuous TX production test.
51196 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);//disable or cancel pending irp first ???
51197 +
51198 + if (atemode & ATE_TXCARR)
51199 + {
51200 + // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
51201 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51202 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
51203 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51204 + }
51205 + else if (atemode & ATE_TXCARRSUPP)
51206 + {
51207 + // No Cont. TX set BBP R22 bit7=0
51208 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51209 + BbpData &= ~(1 << 7); //set bit7=0
51210 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51211 +
51212 + // No Carrier Suppression set BBP R24 bit0=0
51213 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
51214 + BbpData &= 0xFFFFFFFE; //clear bit0
51215 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
51216 + }
51217 + // We should free some resource which allocate when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
51218 + // TODO:Should we free some resource which was allocated when LoopBack and ATE_STOP ?
51219 + else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
51220 + {
51221 + if (atemode & ATE_TXCONT)
51222 + {
51223 + // Not Cont. TX anymore, so set BBP R22 bit7=0
51224 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51225 + BbpData &= ~(1 << 7); //set bit7=0
51226 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51227 + }
51228 + // Abort Tx, Rx DMA.
51229 + RtmpDmaEnable(pAd, 0);
51230 +
51231 + {
51232 + // It seems nothing to free,
51233 + // because we didn't allocate any resource when we entered ATE_TXFRAME mode latestly.
51234 + }
51235 +
51236 + // Start Tx, RX DMA
51237 + RtmpDmaEnable(pAd, 1);
51238 + }
51239 +
51240 + RTUSBRejectPendingPackets(pAd);
51241 + RTUSBCleanUpDataBulkOutQueue(pAd);
51242 +
51243 +#ifdef CONFIG_STA_SUPPORT
51244 + //
51245 + // It will be called in MlmeSuspend().
51246 + //
51247 + // Cancel pending timers
51248 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
51249 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
51250 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
51251 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
51252 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
51253 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
51254 +#endif // CONFIG_STA_SUPPORT //
51255 +
51256 + //RTUSBCleanUpMLMEWaitQueue(pAd); /* not used in RT28xx */
51257 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
51258 +
51259 + // Sometimes kernel will hang on, so we avoid calling MlmeSuspend().
51260 +// MlmeSuspend(pAd, TRUE);
51261 + //RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
51262 +
51263 + // Disable Rx
51264 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51265 + Value &= ~(1 << 3);
51266 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51267 +
51268 + // Abort Tx, RX DMA.
51269 + RtmpDmaEnable(pAd, 0);
51270 +
51271 + // Disable Tx
51272 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51273 + Value &= ~(1 << 2);
51274 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51275 +
51276 + // Make sure there are no pending bulk in/out IRPs before we go on.
51277 +/*=========================================================================*/
51278 + /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
51279 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
51280 + while ((pAd->PendingRx > 0)) //pAd->BulkFlags != 0 wait bulk out finish
51281 + {
51282 +#if 1
51283 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
51284 +#else
51285 + NdisInterlockedDecrement(&pAd->PendingRx);
51286 +#endif
51287 + /* delay 0.5 seconds */
51288 + RTMPusecDelay(500000);
51289 + pAd->PendingRx = 0;
51290 + }
51291 + /* peter : why don't we have to get BulkOutLock first ? */
51292 + while (((pAd->BulkOutPending[0] == TRUE) ||
51293 + (pAd->BulkOutPending[1] == TRUE) ||
51294 + (pAd->BulkOutPending[2] == TRUE) ||
51295 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
51296 + {
51297 + do
51298 + {
51299 + /* pAd->BulkOutPending[y] will be set to FALSE in RTUSBCancelPendingBulkOutIRP(pAd) */
51300 + RTUSBCancelPendingBulkOutIRP(pAd);
51301 + } while (FALSE);
51302 +
51303 + /* we have enough time delay in RTUSBCancelPendingBulkOutIRP(pAd)
51304 + ** so this is not necessary
51305 + */
51306 +// RTMPusecDelay(500000);
51307 + }
51308 +
51309 + /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
51310 +// ASSERT(atomic_read(&pAd->PendingRx) == 0);
51311 + ASSERT(pAd->PendingRx == 0);
51312 +/*=========================================================================*/
51313 +
51314 + // reset Rx statistics.
51315 + pAd->ate.LastSNR0 = 0;
51316 + pAd->ate.LastSNR1 = 0;
51317 + pAd->ate.LastRssi0 = 0;
51318 + pAd->ate.LastRssi1 = 0;
51319 + pAd->ate.LastRssi2 = 0;
51320 + pAd->ate.AvgRssi0 = 0;
51321 + pAd->ate.AvgRssi1 = 0;
51322 + pAd->ate.AvgRssi2 = 0;
51323 + pAd->ate.AvgRssi0X8 = 0;
51324 + pAd->ate.AvgRssi1X8 = 0;
51325 + pAd->ate.AvgRssi2X8 = 0;
51326 + pAd->ate.NumOfAvgRssiSample = 0;
51327 +
51328 +#ifdef RALINK_28xx_QA
51329 + // Tx frame
51330 + pAd->ate.bQATxStart = FALSE;
51331 + pAd->ate.bQARxStart = FALSE;
51332 + pAd->ate.seq = 0;
51333 +
51334 + // counters
51335 + pAd->ate.U2M = 0;
51336 + pAd->ate.OtherData = 0;
51337 + pAd->ate.Beacon = 0;
51338 + pAd->ate.OtherCount = 0;
51339 + pAd->ate.TxAc0 = 0;
51340 + pAd->ate.TxAc1 = 0;
51341 + pAd->ate.TxAc2 = 0;
51342 + pAd->ate.TxAc3 = 0;
51343 + pAd->ate.TxHCCA = 0;
51344 + pAd->ate.TxMgmt = 0;
51345 + pAd->ate.RSSI0 = 0;
51346 + pAd->ate.RSSI1 = 0;
51347 + pAd->ate.RSSI2 = 0;
51348 + pAd->ate.SNR0 = 0;
51349 + pAd->ate.SNR1 = 0;
51350 +
51351 + // control
51352 + pAd->ate.TxDoneCount = 0;
51353 + pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
51354 +#endif // RALINK_28xx_QA //
51355 +
51356 + // Soft reset BBP.
51357 + BbpSoftReset(pAd);
51358 +
51359 +
51360 +#ifdef CONFIG_STA_SUPPORT
51361 + AsicDisableSync(pAd);
51362 +
51363 + /*
51364 + ** If we skip "LinkDown()", we should disable protection
51365 + ** to prevent from sending out RTS or CTS-to-self.
51366 + */
51367 + ATEDisableAsicProtect(pAd);
51368 + RTMPStationStop(pAd);
51369 +#endif // CONFIG_STA_SUPPORT //
51370 +
51371 + // Default value in BBP R22 is 0x0.
51372 + BbpData = 0;
51373 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51374 +
51375 + // Clean bit4 to stop continuous Tx production test.
51376 + MacData &= 0xFFFFFFEF;
51377 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51378 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
51379 + //Clean ATE Bulk in/out counter and continue setup
51380 + InterlockedExchange(&pAd->BulkOutRemained, 0);
51381 +
51382 + /* NdisAcquireSpinLock()/NdisReleaseSpinLock() need only one argument in RT28xx */
51383 + NdisAcquireSpinLock(&pAd->GenericLock);
51384 + pAd->ContinBulkOut = FALSE;
51385 + pAd->ContinBulkIn = FALSE;
51386 + NdisReleaseSpinLock(&pAd->GenericLock);
51387 +
51388 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
51389 + }
51390 + else if (!strcmp(arg, "ATESTOP"))
51391 + {
51392 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE : ATESTOP ===>\n"));
51393 +
51394 + // Default value in BBP R22 is 0x0.
51395 + BbpData = 0;
51396 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);//0820
51397 + // Clean bit4 to stop continuous Tx production test.
51398 + MacData &= 0xFFFFFFEF;
51399 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51400 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData); // recover the MAC_SYS_CTRL register back.
51401 +
51402 + // Disable Rx
51403 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51404 + Value &= ~(1 << 3);
51405 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51406 +
51407 + /*
51408 + ** Abort Tx, RX DMA.
51409 + ** Q : How to do the following I/O if Tx, Rx DMA is aborted ?
51410 + ** Ans : Bulk endpoints are aborted, while the control endpoint is not.
51411 + */
51412 + RtmpDmaEnable(pAd, 0);
51413 +
51414 + // Disable Tx
51415 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51416 + Value &= ~(1 << 2);
51417 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51418 +
51419 + /* Make sure there are no pending bulk in/out IRPs before we go on. */
51420 +/*=========================================================================*/
51421 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
51422 + while (pAd->PendingRx > 0)
51423 + {
51424 +#if 1
51425 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
51426 +#else
51427 +// NdisInterlockedDecrement(&pAd->PendingRx);
51428 + pAd->PendingRx--;
51429 +#endif
51430 + RTMPusecDelay(500000);
51431 + }
51432 +
51433 + while (((pAd->BulkOutPending[0] == TRUE) ||
51434 + (pAd->BulkOutPending[1] == TRUE) ||
51435 + (pAd->BulkOutPending[2] == TRUE) ||
51436 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
51437 + {
51438 + do
51439 + {
51440 + RTUSBCancelPendingBulkOutIRP(pAd);
51441 + } while (FALSE);
51442 +
51443 + RTMPusecDelay(500000);
51444 + }
51445 +
51446 +// ASSERT(atomic_read(&pAd->PendingRx) == 0);
51447 + ASSERT(pAd->PendingRx == 0);
51448 +/*=========================================================================*/
51449 +/* Reset Rx RING */
51450 +/*=========================================================================*/
51451 +// InterlockedExchange(&pAd->PendingRx, 0);
51452 + pAd->PendingRx = 0;
51453 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
51454 + pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
51455 + pAd->NextRxBulkInPosition = 0;
51456 + for (i = 0; i < (RX_RING_SIZE); i++)
51457 + {
51458 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
51459 + NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
51460 + /* peter : why don't we have to get BulkInLock first ? */
51461 + pRxContext->pAd = pAd;
51462 + pRxContext->pIrp = NULL;
51463 + /* peter debug ++ */
51464 + pRxContext->BulkInOffset = 0;
51465 + pRxContext->bRxHandling = FALSE;
51466 + /* peter debug -- */
51467 + pRxContext->InUse = FALSE;
51468 + pRxContext->IRPPending = FALSE;
51469 + pRxContext->Readable = FALSE;
51470 +// pRxContext->ReorderInUse = FALSE;
51471 +// pRxContext->ReadPosOffset = 0;
51472 + }
51473 +
51474 +/*=========================================================================*/
51475 +/* Reset Tx RING */
51476 +/*=========================================================================*/
51477 + do
51478 + {
51479 + RTUSBCancelPendingBulkOutIRP(pAd);
51480 + } while (FALSE);
51481 +
51482 +/*=========================================================================*/
51483 + // Enable auto responder.
51484 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
51485 + temp = temp | (0x01);
51486 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
51487 +
51488 +/*================================================*/
51489 + AsicEnableBssSync(pAd);
51490 +
51491 + /* Soft reset BBP.*/
51492 + /* In 2870 chipset, ATE_BBP_IO_READ8_BY_REG_ID() == RTMP_BBP_IO_READ8_BY_REG_ID() */
51493 + /* Both rt2870ap and rt2870sta use BbpSoftReset(pAd) to do BBP soft reset */
51494 + BbpSoftReset(pAd);
51495 +/*================================================*/
51496 + {
51497 +#ifdef CONFIG_STA_SUPPORT
51498 + // Set all state machines back IDLE
51499 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
51500 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
51501 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
51502 + pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
51503 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
51504 + pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
51505 +#endif // CONFIG_STA_SUPPORT //
51506 +
51507 + //
51508 + // ===> refer to MlmeRestartStateMachine().
51509 + // When we entered ATE_START mode, PeriodicTimer was not cancelled.
51510 + // So we don't have to set it here.
51511 + //
51512 + //RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
51513 +
51514 + ASSERT(pAd->CommonCfg.Channel != 0);
51515 +
51516 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
51517 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
51518 +
51519 +
51520 +#ifdef CONFIG_STA_SUPPORT
51521 + RTMPStationStart(pAd);
51522 +#endif // CONFIG_STA_SUPPORT //
51523 + }
51524 +//
51525 +// These two steps have been done when entering ATE_STOP mode.
51526 +//
51527 +#if 0
51528 + RTUSBWriteBBPRegister(pAd, BBP_R22, BbpData);
51529 + RTUSBWriteMACRegister(pAd, MAC_SYS_CTRL, MacData);
51530 +#endif
51531 + // Clean ATE Bulk in/out counter and continue setup.
51532 + InterlockedExchange(&pAd->BulkOutRemained, 0);
51533 + NdisAcquireSpinLock(&pAd->GenericLock);
51534 + pAd->ContinBulkOut = FALSE;
51535 + pAd->ContinBulkIn = FALSE;
51536 + NdisReleaseSpinLock(&pAd->GenericLock);
51537 +
51538 + /* Wait 50ms to prevent next URB to bulkout during HW reset. */
51539 + /* todo : remove this if not necessary */
51540 + NdisMSleep(50000);
51541 +
51542 + pAd->ate.Mode = ATE_STOP;
51543 +
51544 + // Enable Tx
51545 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51546 + Value |= (1 << 2);
51547 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51548 +
51549 +/*=========================================================================*/
51550 + /* restore RX_FILTR_CFG */
51551 +#ifdef CONFIG_STA_SUPPORT
51552 + /* restore RX_FILTR_CFG in order that QA maybe set it to 0x3 */
51553 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL);
51554 +#endif // CONFIG_STA_SUPPORT //
51555 +/*=========================================================================*/
51556 +
51557 + // Enable Tx, RX DMA.
51558 + RtmpDmaEnable(pAd, 1);
51559 +
51560 + // Enable Rx
51561 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51562 + Value |= (1 << 3);
51563 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51564 +
51565 + // Wait 10ms to wait all of the bulk-in URBs to complete.
51566 + /* todo : remove this if not necessary */
51567 + NdisMSleep(10000);
51568 +
51569 + // Everything is ready to start normal Tx/Rx.
51570 + RTUSBBulkReceive(pAd);
51571 + netif_start_queue(pAd->net_dev);
51572 +
51573 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATE : ATESTOP \n"));
51574 + }
51575 + else if (!strcmp(arg, "TXCARR")) // Tx Carrier
51576 + {
51577 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCARR\n"));
51578 + pAd->ate.Mode |= ATE_TXCARR;
51579 +
51580 + // Disable Rx
51581 + // May be we need not to do this, because these have been done in ATE_START mode ???
51582 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51583 + Value &= ~(1 << 3);
51584 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51585 +
51586 + // QA has done the following steps if it is used.
51587 + if (pAd->ate.bQATxStart == FALSE)
51588 + {
51589 + // Soft reset BBP.
51590 + BbpSoftReset(pAd);
51591 +
51592 + // Carrier Test set BBP R22 bit7=1, bit6=1, bit[5~0]=0x01
51593 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51594 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
51595 + BbpData |= 0x000000C1; //set bit7=1, bit6=1, bit[5~0]=0x01
51596 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51597 +
51598 + // set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1
51599 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51600 + Value = Value | 0x00000010;
51601 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51602 + }
51603 + }
51604 + else if (!strcmp(arg, "TXCONT")) // Tx Continue
51605 + {
51606 + if (pAd->ate.bQATxStart == TRUE)
51607 + {
51608 + /* set MAC_SYS_CTRL(0x1004) bit4(Continuous Tx Production Test)
51609 + and bit2(MAC TX enable) back to zero. */
51610 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51611 + MacData &= 0xFFFFFFEB;
51612 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
51613 +
51614 + // set BBP R22 bit7=0
51615 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51616 + BbpData &= 0xFFFFFF7F; //set bit7=0
51617 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51618 + }
51619 +
51620 + /* for TxCont mode.
51621 + ** Step 1: Send 50 packets first then wait for a moment.
51622 + ** Step 2: Send more 50 packet then start continue mode.
51623 + */
51624 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCONT\n"));
51625 + // Step 1: send 50 packets first.
51626 + pAd->ate.Mode |= ATE_TXCONT;
51627 + pAd->ate.TxCount = 50;
51628 + pAd->ate.TxDoneCount = 0;
51629 +
51630 + // Soft reset BBP.
51631 + BbpSoftReset(pAd);
51632 +
51633 + // Abort Tx, RX DMA.
51634 + RtmpDmaEnable(pAd, 0);
51635 +
51636 +
51637 + /* Only needed if we have to send some normal frames. */
51638 + SetJapanFilter(pAd);
51639 +
51640 + // Setup frame format.
51641 + ATESetUpFrame(pAd, 0);
51642 +
51643 + // Enable Tx
51644 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51645 + Value |= (1 << 2);
51646 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51647 +
51648 + // Disable Rx
51649 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51650 + Value &= ~(1 << 3);
51651 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51652 +
51653 + // Start Tx, RX DMA.
51654 + RtmpDmaEnable(pAd, 1);
51655 +
51656 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
51657 +
51658 +#ifdef RALINK_28xx_QA
51659 + if (pAd->ate.bQATxStart == TRUE)
51660 + {
51661 + pAd->ate.TxStatus = 1;
51662 + //pAd->ate.Repeat = 0;
51663 + }
51664 +#endif // RALINK_28xx_QA //
51665 +
51666 + NdisAcquireSpinLock(&pAd->GenericLock);//0820
51667 + pAd->ContinBulkOut = FALSE;
51668 + NdisReleaseSpinLock(&pAd->GenericLock);
51669 +
51670 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
51671 +
51672 + // Kick bulk out
51673 + RTUSBKickBulkOut(pAd);
51674 +
51675 + /* To make sure all the 50 frames have been bulk out before executing step 2 */
51676 + while (atomic_read(&pAd->BulkOutRemained) > 0)
51677 + {
51678 + RTMPusecDelay(5000);
51679 + }
51680 +
51681 + // Step 2: send more 50 packets then start continue mode.
51682 + // Abort Tx, RX DMA.
51683 + RtmpDmaEnable(pAd, 0);
51684 +
51685 + // Cont. TX set BBP R22 bit7=1
51686 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51687 + BbpData |= 0x00000080; //set bit7=1
51688 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51689 +
51690 + pAd->ate.TxCount = 50;
51691 + pAd->ate.TxDoneCount = 0;
51692 +
51693 + SetJapanFilter(pAd);
51694 +
51695 + // Setup frame format.
51696 + ATESetUpFrame(pAd, 0);
51697 +
51698 + // Enable Tx
51699 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51700 + Value |= (1 << 2);
51701 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51702 +
51703 + // Disable Rx
51704 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51705 + Value &= ~(1 << 3);
51706 +
51707 + // Start Tx, RX DMA.
51708 + RtmpDmaEnable(pAd, 1);
51709 +
51710 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
51711 +
51712 +#ifdef RALINK_28xx_QA
51713 + if (pAd->ate.bQATxStart == TRUE)
51714 + {
51715 + pAd->ate.TxStatus = 1;
51716 + //pAd->ate.Repeat = 0;
51717 + }
51718 +#endif // RALINK_28xx_QA //
51719 +
51720 + NdisAcquireSpinLock(&pAd->GenericLock);//0820
51721 + pAd->ContinBulkOut = FALSE;
51722 + NdisReleaseSpinLock(&pAd->GenericLock);
51723 +
51724 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
51725 + // Kick bulk out
51726 + RTUSBKickBulkOut(pAd);
51727 +
51728 +#if 1
51729 + RTMPusecDelay(500);
51730 +#else
51731 + while (atomic_read(&pAd->BulkOutRemained) > 0)
51732 + {
51733 + RTMPusecDelay(5000);
51734 + }
51735 +#endif // 1 //
51736 +
51737 + // Set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1.
51738 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51739 + MacData |= 0x00000010;
51740 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
51741 + }
51742 + else if (!strcmp(arg, "TXFRAME")) // Tx Frames
51743 + {
51744 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXFRAME(Count=0x%08x)\n", pAd->ate.TxCount));
51745 + pAd->ate.Mode |= ATE_TXFRAME;
51746 +
51747 + // Soft reset BBP.
51748 + BbpSoftReset(pAd);
51749 +
51750 + // Default value in BBP R22 is 0x0.
51751 + BbpData = 0;
51752 +
51753 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51754 +
51755 + // Clean bit4 to stop continuous Tx production test.
51756 + MacData &= 0xFFFFFFEF;
51757 +
51758 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51759 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
51760 +
51761 +#ifdef RALINK_28xx_QA
51762 + // add this for LoopBack mode
51763 + if (pAd->ate.bQARxStart == FALSE)
51764 + {
51765 + // Disable Rx
51766 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51767 + Value &= ~(1 << 3);
51768 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51769 + }
51770 +
51771 + if (pAd->ate.bQATxStart == TRUE)
51772 + {
51773 + pAd->ate.TxStatus = 1;
51774 + //pAd->ate.Repeat = 0;
51775 + }
51776 +#else
51777 + // Disable Rx
51778 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51779 + Value &= ~(1 << 3);
51780 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51781 +#endif // RALINK_28xx_QA //
51782 +
51783 + // Enable Tx
51784 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51785 + Value |= (1 << 2);
51786 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51787 +
51788 + SetJapanFilter(pAd);
51789 +
51790 + // Abort Tx, RX DMA.
51791 + RtmpDmaEnable(pAd, 0);
51792 +
51793 + pAd->ate.TxDoneCount = 0;
51794 +
51795 + // Setup frame format
51796 + ATESetUpFrame(pAd, 0);
51797 +
51798 + // Start Tx, RX DMA.
51799 + RtmpDmaEnable(pAd, 1);
51800 +
51801 + // Check count is continuous or not yet.
51802 + //
51803 + // Due to the type mismatch between "pAd->BulkOutRemained"(atomic_t) and "pAd->ate.TxCount"(UINT32)
51804 + //
51805 + if (pAd->ate.TxCount == 0)
51806 + {
51807 + InterlockedExchange(&pAd->BulkOutRemained, 0);
51808 + }
51809 + else
51810 + {
51811 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
51812 + }
51813 + ATEDBGPRINT(RT_DEBUG_TRACE, ("bulk out count = %d\n", atomic_read(&pAd->BulkOutRemained)));
51814 + ASSERT((atomic_read(&pAd->BulkOutRemained) >= 0));
51815 +
51816 + if (atomic_read(&pAd->BulkOutRemained) == 0)
51817 + {
51818 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packet countinuously\n"));
51819 +
51820 + /* In 28xx, NdisAcquireSpinLock() == spin_lock_bh() */
51821 + /* NdisAcquireSpinLock only need one argument in 28xx. */
51822 + NdisAcquireSpinLock(&pAd->GenericLock);
51823 + pAd->ContinBulkOut = TRUE;
51824 + NdisReleaseSpinLock(&pAd->GenericLock);
51825 +
51826 + /* In 28xx, BULK_OUT_LOCK() == spin_lock_irqsave() */
51827 + BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
51828 + pAd->BulkOutPending[0] = FALSE;
51829 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
51830 + }
51831 + else
51832 + {
51833 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packets depend on counter\n"));
51834 +
51835 + NdisAcquireSpinLock(&pAd->GenericLock);
51836 + pAd->ContinBulkOut = FALSE;
51837 + NdisReleaseSpinLock(&pAd->GenericLock);
51838 +
51839 + BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);
51840 + pAd->BulkOutPending[0] = FALSE;
51841 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
51842 + }
51843 +
51844 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
51845 +
51846 + // Kick bulk out
51847 + RTUSBKickBulkOut(pAd);
51848 + }
51849 +#ifdef RALINK_28xx_QA
51850 + else if (!strcmp(arg, "TXSTOP")) //Enter ATE mode and set Tx/Rx Idle
51851 + {
51852 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXSTOP\n"));
51853 +
51854 + atemode = pAd->ate.Mode;
51855 + pAd->ate.Mode &= ATE_TXSTOP;
51856 + pAd->ate.bQATxStart = FALSE;
51857 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
51858 +
51859 +/*=========================================================================*/
51860 + if (atemode & ATE_TXCARR)
51861 + {
51862 + // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
51863 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51864 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
51865 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51866 + }
51867 + else if (atemode & ATE_TXCARRSUPP)
51868 + {
51869 + // No Cont. TX set BBP R22 bit7=0
51870 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51871 + BbpData &= ~(1 << 7); //set bit7=0
51872 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51873 +
51874 + // No Carrier Suppression set BBP R24 bit0=0
51875 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
51876 + BbpData &= 0xFFFFFFFE; //clear bit0
51877 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
51878 + }
51879 + else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
51880 + {
51881 + if (atemode & ATE_TXCONT)
51882 + {
51883 + // No Cont. TX set BBP R22 bit7=0
51884 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
51885 + BbpData &= ~(1 << 7); //set bit7=0
51886 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
51887 + }
51888 + }
51889 +
51890 +/*=========================================================================*/
51891 + RTUSBRejectPendingPackets(pAd);
51892 + RTUSBCleanUpDataBulkOutQueue(pAd);
51893 +
51894 + /* not used in RT28xx */
51895 + //RTUSBCleanUpMLMEWaitQueue(pAd);
51896 + /* empty function so far */
51897 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
51898 +/*=========================================================================*/
51899 + // Abort Tx, RX DMA.
51900 + RtmpDmaEnable(pAd, 0);
51901 +/*=========================================================================*/
51902 +
51903 + /* In 28xx, pAd->PendingRx is not of type atomic_t anymore */
51904 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
51905 + /* peter todo : BulkInLock */
51906 + while (pAd->PendingRx > 0)
51907 + {
51908 +#if 1
51909 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
51910 +#else
51911 +// NdisInterlockedDecrement(&pAd->PendingRx);
51912 + pAd->PendingRx--;
51913 +#endif
51914 + RTMPusecDelay(500000);
51915 + }
51916 +
51917 + while (((pAd->BulkOutPending[0] == TRUE) ||
51918 + (pAd->BulkOutPending[1] == TRUE) ||
51919 + (pAd->BulkOutPending[2] == TRUE) ||
51920 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
51921 + {
51922 + do
51923 + {
51924 + RTUSBCancelPendingBulkOutIRP(pAd);
51925 + } while (FALSE);
51926 +
51927 + RTMPusecDelay(500000);
51928 + }
51929 +
51930 + ASSERT(pAd->PendingRx == 0);
51931 +/*=========================================================================*/
51932 + // Enable Tx, Rx DMA.
51933 + RtmpDmaEnable(pAd, 1);
51934 +
51935 + /* task Tx status : 0 --> task is idle, 1 --> task is running */
51936 + pAd->ate.TxStatus = 0;
51937 +
51938 + // Soft reset BBP.
51939 + BbpSoftReset(pAd);
51940 +
51941 + // Disable Tx
51942 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
51943 + MacData &= (0xfffffffb);
51944 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
51945 +
51946 + //Clean ATE Bulk in/out counter and continue setup
51947 + InterlockedExchange(&pAd->BulkOutRemained, 0);
51948 +
51949 + pAd->ContinBulkOut = FALSE;
51950 + }
51951 + else if (!strcmp(arg, "RXSTOP"))
51952 + {
51953 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXSTOP\n"));
51954 + atemode = pAd->ate.Mode;
51955 +
51956 + // Disable Rx
51957 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
51958 + Value &= ~(1 << 3);
51959 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
51960 +
51961 + pAd->ate.Mode &= ATE_RXSTOP;
51962 + pAd->ate.bQARxStart = FALSE;
51963 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
51964 +
51965 +/*=========================================================================*/
51966 + RTUSBRejectPendingPackets(pAd);
51967 + RTUSBCleanUpDataBulkOutQueue(pAd);
51968 +
51969 + /* not used in RT28xx */
51970 + //RTUSBCleanUpMLMEWaitQueue(pAd);
51971 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
51972 +/*=========================================================================*/
51973 +
51974 + // Abort Tx, RX DMA.
51975 + RtmpDmaEnable(pAd, 0);
51976 +/*=========================================================================*/
51977 +// while ((atomic_read(&pAd->PendingRx) > 0))
51978 + while (pAd->PendingRx > 0)
51979 + {
51980 +#if 1
51981 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
51982 +#else
51983 +// NdisInterlockedDecrement(&pAd->PendingRx);
51984 + pAd->PendingRx--;
51985 +#endif
51986 + RTMPusecDelay(500000);
51987 + }
51988 +
51989 + while (((pAd->BulkOutPending[0] == TRUE) ||
51990 + (pAd->BulkOutPending[1] == TRUE) ||
51991 + (pAd->BulkOutPending[2] == TRUE) ||
51992 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
51993 + {
51994 + do
51995 + {
51996 + RTUSBCancelPendingBulkOutIRP(pAd);
51997 + } while (FALSE);
51998 +
51999 + RTMPusecDelay(500000);
52000 + }
52001 +
52002 + ASSERT(pAd->PendingRx == 0);
52003 +/*=========================================================================*/
52004 +
52005 + // Soft reset BBP.
52006 + BbpSoftReset(pAd);
52007 + pAd->ContinBulkIn = FALSE;
52008 + }
52009 +#endif // RALINK_28xx_QA //
52010 + else if (!strcmp(arg, "RXFRAME")) // Rx Frames
52011 + {
52012 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXFRAME\n"));
52013 +
52014 + // Disable Rx of MAC block
52015 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52016 + Value &= ~(1 << 3);
52017 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52018 +
52019 + // Default value in BBP R22 is 0x0.
52020 + BbpData = 0;
52021 +
52022 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52023 + // Clean bit4 to stop continuous Tx production test.
52024 + MacData &= 0xFFFFFFEF;
52025 +
52026 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52027 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52028 +
52029 + pAd->ate.Mode |= ATE_RXFRAME;
52030 +
52031 + // Abort Tx, RX DMA.
52032 + RtmpDmaEnable(pAd, 0);
52033 +
52034 + // Disable TX of MAC block
52035 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52036 + Value &= ~(1 << 2);
52037 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52038 +
52039 + // Reset Rx RING.
52040 + for ( i = 0; i < (RX_RING_SIZE); i++)
52041 + {
52042 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
52043 +
52044 + pRxContext->InUse = FALSE;
52045 + pRxContext->IRPPending = FALSE;
52046 + pRxContext->Readable = FALSE;
52047 +
52048 + //
52049 + // Get the urb from kernel back to driver.
52050 + //
52051 + RTUSB_UNLINK_URB(pRxContext->pUrb);
52052 +
52053 + /* Sleep 200 microsecs to give cancellation time to work. */
52054 + NdisMSleep(200);
52055 + pAd->BulkInReq = 0;
52056 +
52057 +// InterlockedExchange(&pAd->PendingRx, 0);
52058 + pAd->PendingRx = 0;
52059 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
52060 + pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
52061 + pAd->NextRxBulkInPosition = 0;
52062 + }
52063 +
52064 + // read to clear counters
52065 + RTUSBReadMACRegister(pAd, RX_STA_CNT0, &temp); //RX PHY & RX CRC count
52066 + RTUSBReadMACRegister(pAd, RX_STA_CNT1, &temp); //RX PLCP error count & CCA false alarm count
52067 + RTUSBReadMACRegister(pAd, RX_STA_CNT2, &temp); //RX FIFO overflow frame count & RX duplicated filtered frame count
52068 +
52069 + pAd->ContinBulkIn = TRUE;
52070 +
52071 + // Enable Tx, RX DMA.
52072 + RtmpDmaEnable(pAd, 1);
52073 +
52074 + // Enable RX of MAC block
52075 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52076 + Value |= (1 << 3);
52077 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52078 +
52079 + // Kick bulk in
52080 + RTUSBBulkReceive(pAd);
52081 + }
52082 + else
52083 + {
52084 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: Invalid arg!\n"));
52085 + return FALSE;
52086 + }
52087 + RTMPusecDelay(5000);
52088 +
52089 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATECmdHandler()\n"));
52090 +
52091 + return TRUE;
52092 +}
52093 +#endif // RT2870 //
52094 +
52095 +INT Set_ATE_Proc(
52096 + IN PRTMP_ADAPTER pAd,
52097 + IN PUCHAR arg)
52098 +{
52099 + if (ATECmdHandler(pAd, arg))
52100 + {
52101 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Success\n"));
52102 +
52103 +
52104 + return TRUE;
52105 + }
52106 + else
52107 + {
52108 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Failed\n"));
52109 + return FALSE;
52110 + }
52111 +}
52112 +
52113 +/*
52114 + ==========================================================================
52115 + Description:
52116 + Set ATE ADDR1=DA for TxFrame(AP : To DS = 0 ; From DS = 1)
52117 + or
52118 + Set ATE ADDR3=DA for TxFrame(STA : To DS = 1 ; From DS = 0)
52119 +
52120 + Return:
52121 + TRUE if all parameters are OK, FALSE otherwise
52122 + ==========================================================================
52123 +*/
52124 +INT Set_ATE_DA_Proc(
52125 + IN PRTMP_ADAPTER pAd,
52126 + IN PUCHAR arg)
52127 +{
52128 + CHAR *value;
52129 + INT i;
52130 +
52131 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
52132 + return FALSE;
52133 +
52134 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
52135 + {
52136 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
52137 + return FALSE; //Invalid
52138 +
52139 +
52140 +#ifdef CONFIG_STA_SUPPORT
52141 + AtoH(value, &pAd->ate.Addr3[i++], 1);
52142 +#endif // CONFIG_STA_SUPPORT //
52143 + }
52144 +
52145 + if(i != 6)
52146 + return FALSE; //Invalid
52147 +
52148 +
52149 +#ifdef CONFIG_STA_SUPPORT
52150 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_DA_Proc (DA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr3[0],
52151 + pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]));
52152 +#endif // CONFIG_STA_SUPPORT //
52153 +
52154 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_DA_Proc Success\n"));
52155 +
52156 + return TRUE;
52157 +}
52158 +
52159 +/*
52160 + ==========================================================================
52161 + Description:
52162 + Set ATE ADDR3=SA for TxFrame(AP : To DS = 0 ; From DS = 1)
52163 + or
52164 + Set ATE ADDR2=SA for TxFrame(STA : To DS = 1 ; From DS = 0)
52165 +
52166 + Return:
52167 + TRUE if all parameters are OK, FALSE otherwise
52168 + ==========================================================================
52169 +*/
52170 +INT Set_ATE_SA_Proc(
52171 + IN PRTMP_ADAPTER pAd,
52172 + IN PUCHAR arg)
52173 +{
52174 + CHAR *value;
52175 + INT i;
52176 +
52177 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
52178 + return FALSE;
52179 +
52180 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
52181 + {
52182 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
52183 + return FALSE; //Invalid
52184 +
52185 +
52186 +#ifdef CONFIG_STA_SUPPORT
52187 + AtoH(value, &pAd->ate.Addr2[i++], 1);
52188 +#endif // CONFIG_STA_SUPPORT //
52189 + }
52190 +
52191 + if(i != 6)
52192 + return FALSE; //Invalid
52193 +
52194 +
52195 +#ifdef CONFIG_STA_SUPPORT
52196 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_SA_Proc (SA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr2[0],
52197 + pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]));
52198 +#endif // CONFIG_STA_SUPPORT //
52199 +
52200 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_SA_Proc Success\n"));
52201 +
52202 + return TRUE;
52203 +}
52204 +
52205 +/*
52206 + ==========================================================================
52207 + Description:
52208 + Set ATE ADDR2=BSSID for TxFrame(AP : To DS = 0 ; From DS = 1)
52209 + or
52210 + Set ATE ADDR1=BSSID for TxFrame(STA : To DS = 1 ; From DS = 0)
52211 +
52212 + Return:
52213 + TRUE if all parameters are OK, FALSE otherwise
52214 + ==========================================================================
52215 +*/
52216 +INT Set_ATE_BSSID_Proc(
52217 + IN PRTMP_ADAPTER pAd,
52218 + IN PUCHAR arg)
52219 +{
52220 + CHAR *value;
52221 + INT i;
52222 +
52223 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
52224 + return FALSE;
52225 +
52226 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
52227 + {
52228 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
52229 + return FALSE; //Invalid
52230 +
52231 +
52232 +#ifdef CONFIG_STA_SUPPORT
52233 + AtoH(value, &pAd->ate.Addr1[i++], 1);
52234 +#endif // CONFIG_STA_SUPPORT //
52235 + }
52236 +
52237 + if(i != 6)
52238 + return FALSE; //Invalid
52239 +
52240 +
52241 +#ifdef CONFIG_STA_SUPPORT
52242 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_BSSID_Proc (BSSID = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr1[0],
52243 + pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]));
52244 +#endif // CONFIG_STA_SUPPORT //
52245 +
52246 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_BSSID_Proc Success\n"));
52247 +
52248 + return TRUE;
52249 +}
52250 +
52251 +/*
52252 + ==========================================================================
52253 + Description:
52254 + Set ATE Tx Channel
52255 +
52256 + Return:
52257 + TRUE if all parameters are OK, FALSE otherwise
52258 + ==========================================================================
52259 +*/
52260 +INT Set_ATE_CHANNEL_Proc(
52261 + IN PRTMP_ADAPTER pAd,
52262 + IN PUCHAR arg)
52263 +{
52264 + UCHAR channel;
52265 +
52266 + channel = simple_strtol(arg, 0, 10);
52267 +
52268 + if ((channel < 1) || (channel > 216))// to allow A band channel : ((channel < 1) || (channel > 14))
52269 + {
52270 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_CHANNEL_Proc::Out of range, it should be in range of 1~14.\n"));
52271 + return FALSE;
52272 + }
52273 + pAd->ate.Channel = channel;
52274 +
52275 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAd->ate.Channel));
52276 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_CHANNEL_Proc Success\n"));
52277 +
52278 +
52279 + return TRUE;
52280 +}
52281 +
52282 +/*
52283 + ==========================================================================
52284 + Description:
52285 + Set ATE Tx Power0
52286 +
52287 + Return:
52288 + TRUE if all parameters are OK, FALSE otherwise
52289 + ==========================================================================
52290 +*/
52291 +INT Set_ATE_TX_POWER0_Proc(
52292 + IN PRTMP_ADAPTER pAd,
52293 + IN PUCHAR arg)
52294 +{
52295 + CHAR TxPower;
52296 +
52297 + TxPower = simple_strtol(arg, 0, 10);
52298 +
52299 + if (pAd->ate.Channel <= 14)
52300 + {
52301 + if ((TxPower > 31) || (TxPower < 0))
52302 + {
52303 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
52304 + return FALSE;
52305 + }
52306 + }
52307 + else// 5.5GHz
52308 + {
52309 + if ((TxPower > 15) || (TxPower < -7))
52310 + {
52311 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
52312 + return FALSE;
52313 + }
52314 + }
52315 +
52316 + pAd->ate.TxPower0 = TxPower;
52317 + ATETxPwrHandler(pAd, 0);
52318 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER0_Proc Success\n"));
52319 +
52320 +
52321 + return TRUE;
52322 +}
52323 +
52324 +/*
52325 + ==========================================================================
52326 + Description:
52327 + Set ATE Tx Power1
52328 +
52329 + Return:
52330 + TRUE if all parameters are OK, FALSE otherwise
52331 + ==========================================================================
52332 +*/
52333 +INT Set_ATE_TX_POWER1_Proc(
52334 + IN PRTMP_ADAPTER pAd,
52335 + IN PUCHAR arg)
52336 +{
52337 + CHAR TxPower;
52338 +
52339 + TxPower = simple_strtol(arg, 0, 10);
52340 +
52341 + if (pAd->ate.Channel <= 14)
52342 + {
52343 + if ((TxPower > 31) || (TxPower < 0))
52344 + {
52345 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
52346 + return FALSE;
52347 + }
52348 + }
52349 + else
52350 + {
52351 + if ((TxPower > 15) || (TxPower < -7))
52352 + {
52353 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
52354 + return FALSE;
52355 + }
52356 + }
52357 +
52358 + pAd->ate.TxPower1 = TxPower;
52359 + ATETxPwrHandler(pAd, 1);
52360 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER1_Proc Success\n"));
52361 +
52362 +
52363 + return TRUE;
52364 +}
52365 +
52366 +/*
52367 + ==========================================================================
52368 + Description:
52369 + Set ATE Tx Antenna
52370 +
52371 + Return:
52372 + TRUE if all parameters are OK, FALSE otherwise
52373 + ==========================================================================
52374 +*/
52375 +INT Set_ATE_TX_Antenna_Proc(
52376 + IN PRTMP_ADAPTER pAd,
52377 + IN PUCHAR arg)
52378 +{
52379 + CHAR value;
52380 +
52381 + value = simple_strtol(arg, 0, 10);
52382 +
52383 + if ((value > 2) || (value < 0))
52384 + {
52385 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_Antenna_Proc::Out of range (Value=%d)\n", value));
52386 + return FALSE;
52387 + }
52388 +
52389 + pAd->ate.TxAntennaSel = value;
52390 +
52391 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_Antenna_Proc (Antenna = %d)\n", pAd->ate.TxAntennaSel));
52392 + ATEDBGPRINT(RT_DEBUG_TRACE,("Ralink: Set_ATE_TX_Antenna_Proc Success\n"));
52393 +
52394 +
52395 + return TRUE;
52396 +}
52397 +
52398 +/*
52399 + ==========================================================================
52400 + Description:
52401 + Set ATE Rx Antenna
52402 +
52403 + Return:
52404 + TRUE if all parameters are OK, FALSE otherwise
52405 + ==========================================================================
52406 +*/
52407 +INT Set_ATE_RX_Antenna_Proc(
52408 + IN PRTMP_ADAPTER pAd,
52409 + IN PUCHAR arg)
52410 +{
52411 + CHAR value;
52412 +
52413 + value = simple_strtol(arg, 0, 10);
52414 +
52415 + if ((value > 3) || (value < 0))
52416 + {
52417 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_RX_Antenna_Proc::Out of range (Value=%d)\n", value));
52418 + return FALSE;
52419 + }
52420 +
52421 + pAd->ate.RxAntennaSel = value;
52422 +
52423 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_Antenna_Proc (Antenna = %d)\n", pAd->ate.RxAntennaSel));
52424 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_Antenna_Proc Success\n"));
52425 +
52426 +
52427 + return TRUE;
52428 +}
52429 +
52430 +/*
52431 + ==========================================================================
52432 + Description:
52433 + Set ATE RF frequence offset
52434 +
52435 + Return:
52436 + TRUE if all parameters are OK, FALSE otherwise
52437 + ==========================================================================
52438 +*/
52439 +INT Set_ATE_TX_FREQOFFSET_Proc(
52440 + IN PRTMP_ADAPTER pAd,
52441 + IN PUCHAR arg)
52442 +{
52443 + UCHAR RFFreqOffset;
52444 + ULONG R4;
52445 +
52446 + RFFreqOffset = simple_strtol(arg, 0, 10);
52447 +
52448 + if(RFFreqOffset >= 64)
52449 + {
52450 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_FREQOFFSET_Proc::Out of range, it should be in range of 0~63.\n"));
52451 + return FALSE;
52452 + }
52453 +
52454 + pAd->ate.RFFreqOffset = RFFreqOffset;
52455 + R4 = pAd->ate.RFFreqOffset << 15; // shift TX power control to correct RF register bit position
52456 + R4 |= (pAd->LatchRfRegs.R4 & ((~0x001f8000)));
52457 + pAd->LatchRfRegs.R4 = R4;
52458 +
52459 + RtmpRfIoWrite(pAd);
52460 +
52461 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_FREQOFFSET_Proc (RFFreqOffset = %d)\n", pAd->ate.RFFreqOffset));
52462 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_FREQOFFSET_Proc Success\n"));
52463 +
52464 +
52465 + return TRUE;
52466 +}
52467 +
52468 +/*
52469 + ==========================================================================
52470 + Description:
52471 + Set ATE RF BW
52472 +
52473 + Return:
52474 + TRUE if all parameters are OK, FALSE otherwise
52475 + ==========================================================================
52476 +*/
52477 +INT Set_ATE_TX_BW_Proc(
52478 + IN PRTMP_ADAPTER pAd,
52479 + IN PUCHAR arg)
52480 +{
52481 + int i;
52482 + UCHAR value = 0;
52483 + UCHAR BBPCurrentBW;
52484 +
52485 + BBPCurrentBW = simple_strtol(arg, 0, 10);
52486 +
52487 + if(BBPCurrentBW == 0)
52488 + pAd->ate.TxWI.BW = BW_20;
52489 + else
52490 + pAd->ate.TxWI.BW = BW_40;
52491 +
52492 + if(pAd->ate.TxWI.BW == BW_20)
52493 + {
52494 + if(pAd->ate.Channel <= 14)
52495 + {
52496 + for (i=0; i<5; i++)
52497 + {
52498 + if (pAd->Tx20MPwrCfgGBand[i] != 0xffffffff)
52499 + {
52500 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgGBand[i]);
52501 + RTMPusecDelay(5000);
52502 + }
52503 + }
52504 + }
52505 + else
52506 + {
52507 + for (i=0; i<5; i++)
52508 + {
52509 + if (pAd->Tx20MPwrCfgABand[i] != 0xffffffff)
52510 + {
52511 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgABand[i]);
52512 + RTMPusecDelay(5000);
52513 + }
52514 + }
52515 + }
52516 +
52517 + //Set BBP R4 bit[4:3]=0:0
52518 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
52519 + value &= (~0x18);
52520 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
52521 +
52522 + //Set BBP R66=0x3C
52523 + value = 0x3C;
52524 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
52525 + //Set BBP R68=0x0B
52526 + //to improve Rx sensitivity.
52527 + value = 0x0B;
52528 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
52529 + //Set BBP R69=0x16
52530 + value = 0x16;
52531 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
52532 + //Set BBP R70=0x08
52533 + value = 0x08;
52534 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
52535 + //Set BBP R73=0x11
52536 + value = 0x11;
52537 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
52538 +
52539 + // If Channel=14, Bandwidth=20M and Mode=CCK, Set BBP R4 bit5=1
52540 + // (Japan filter coefficients)
52541 + // This segment of code will only works when ATETXMODE and ATECHANNEL
52542 + // were set to MODE_CCK and 14 respectively before ATETXBW is set to 0.
52543 + //=====================================================================
52544 + if (pAd->ate.Channel == 14)
52545 + {
52546 + int TxMode = pAd->ate.TxWI.PHYMODE;
52547 + if (TxMode == MODE_CCK)
52548 + {
52549 + // when Channel==14 && Mode==CCK && BandWidth==20M, BBP R4 bit5=1
52550 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
52551 + value |= 0x20; //set bit5=1
52552 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
52553 + }
52554 + }
52555 +
52556 + //=====================================================================
52557 + // If bandwidth != 40M, RF Reg4 bit 21 = 0.
52558 + pAd->LatchRfRegs.R4 &= ~0x00200000;
52559 + RtmpRfIoWrite(pAd);
52560 + }
52561 + else if(pAd->ate.TxWI.BW == BW_40)
52562 + {
52563 + if(pAd->ate.Channel <= 14)
52564 + {
52565 + for (i=0; i<5; i++)
52566 + {
52567 + if (pAd->Tx40MPwrCfgGBand[i] != 0xffffffff)
52568 + {
52569 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgGBand[i]);
52570 + RTMPusecDelay(5000);
52571 + }
52572 + }
52573 + }
52574 + else
52575 + {
52576 + for (i=0; i<5; i++)
52577 + {
52578 + if (pAd->Tx40MPwrCfgABand[i] != 0xffffffff)
52579 + {
52580 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgABand[i]);
52581 + RTMPusecDelay(5000);
52582 + }
52583 + }
52584 +#ifdef DOT11_N_SUPPORT
52585 + if ((pAd->ate.TxWI.PHYMODE >= MODE_HTMIX) && (pAd->ate.TxWI.MCS == 7))
52586 + {
52587 + value = 0x28;
52588 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R67, value);
52589 + }
52590 +#endif // DOT11_N_SUPPORT //
52591 + }
52592 +
52593 + //Set BBP R4 bit[4:3]=1:0
52594 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
52595 + value &= (~0x18);
52596 + value |= 0x10;
52597 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
52598 +
52599 + //Set BBP R66=0x3C
52600 + value = 0x3C;
52601 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
52602 + //Set BBP R68=0x0C
52603 + //to improve Rx sensitivity.
52604 + value = 0x0C;
52605 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
52606 + //Set BBP R69=0x1A
52607 + value = 0x1A;
52608 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
52609 + //Set BBP R70=0x0A
52610 + value = 0x0A;
52611 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
52612 + //Set BBP R73=0x16
52613 + value = 0x16;
52614 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
52615 +
52616 + // If bandwidth = 40M, set RF Reg4 bit 21 = 1.
52617 + pAd->LatchRfRegs.R4 |= 0x00200000;
52618 + RtmpRfIoWrite(pAd);
52619 + }
52620 +
52621 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_BW_Proc (BBPCurrentBW = %d)\n", pAd->ate.TxWI.BW));
52622 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_BW_Proc Success\n"));
52623 +
52624 +
52625 + return TRUE;
52626 +}
52627 +
52628 +/*
52629 + ==========================================================================
52630 + Description:
52631 + Set ATE Tx frame length
52632 +
52633 + Return:
52634 + TRUE if all parameters are OK, FALSE otherwise
52635 + ==========================================================================
52636 +*/
52637 +INT Set_ATE_TX_LENGTH_Proc(
52638 + IN PRTMP_ADAPTER pAd,
52639 + IN PUCHAR arg)
52640 +{
52641 + pAd->ate.TxLength = simple_strtol(arg, 0, 10);
52642 +
52643 + if((pAd->ate.TxLength < 24) || (pAd->ate.TxLength > (MAX_FRAME_SIZE - 34/* == 2312 */)))
52644 + {
52645 + pAd->ate.TxLength = (MAX_FRAME_SIZE - 34/* == 2312 */);
52646 + 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 */)));
52647 + return FALSE;
52648 + }
52649 +
52650 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_LENGTH_Proc (TxLength = %d)\n", pAd->ate.TxLength));
52651 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_LENGTH_Proc Success\n"));
52652 +
52653 +
52654 + return TRUE;
52655 +}
52656 +
52657 +/*
52658 + ==========================================================================
52659 + Description:
52660 + Set ATE Tx frame count
52661 +
52662 + Return:
52663 + TRUE if all parameters are OK, FALSE otherwise
52664 + ==========================================================================
52665 +*/
52666 +INT Set_ATE_TX_COUNT_Proc(
52667 + IN PRTMP_ADAPTER pAd,
52668 + IN PUCHAR arg)
52669 +{
52670 + pAd->ate.TxCount = simple_strtol(arg, 0, 10);
52671 +
52672 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAd->ate.TxCount));
52673 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
52674 +
52675 +
52676 + return TRUE;
52677 +}
52678 +
52679 +/*
52680 + ==========================================================================
52681 + Description:
52682 + Set ATE Tx frame MCS
52683 +
52684 + Return:
52685 + TRUE if all parameters are OK, FALSE otherwise
52686 + ==========================================================================
52687 +*/
52688 +INT Set_ATE_TX_MCS_Proc(
52689 + IN PRTMP_ADAPTER pAd,
52690 + IN PUCHAR arg)
52691 +{
52692 + UCHAR MCS;
52693 + int result;
52694 +
52695 + MCS = simple_strtol(arg, 0, 10);
52696 + result = CheckMCSValid(pAd->ate.TxWI.PHYMODE, MCS);
52697 +
52698 + if (result != -1)
52699 + {
52700 + pAd->ate.TxWI.MCS = (UCHAR)MCS;
52701 + }
52702 + else
52703 + {
52704 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MCS_Proc::Out of range, refer to rate table.\n"));
52705 + return FALSE;
52706 + }
52707 +
52708 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MCS_Proc (MCS = %d)\n", pAd->ate.TxWI.MCS));
52709 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MCS_Proc Success\n"));
52710 +
52711 +
52712 + return TRUE;
52713 +}
52714 +
52715 +/*
52716 + ==========================================================================
52717 + Description:
52718 + Set ATE Tx frame Mode
52719 + 0: MODE_CCK
52720 + 1: MODE_OFDM
52721 + 2: MODE_HTMIX
52722 + 3: MODE_HTGREENFIELD
52723 +
52724 + Return:
52725 + TRUE if all parameters are OK, FALSE otherwise
52726 + ==========================================================================
52727 +*/
52728 +INT Set_ATE_TX_MODE_Proc(
52729 + IN PRTMP_ADAPTER pAd,
52730 + IN PUCHAR arg)
52731 +{
52732 + pAd->ate.TxWI.PHYMODE = simple_strtol(arg, 0, 10);
52733 +
52734 + if(pAd->ate.TxWI.PHYMODE > 3)
52735 + {
52736 + pAd->ate.TxWI.PHYMODE = 0;
52737 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MODE_Proc::Out of range. it should be in range of 0~3\n"));
52738 + ATEDBGPRINT(RT_DEBUG_ERROR, ("0: CCK, 1: OFDM, 2: HT_MIX, 3: HT_GREEN_FIELD.\n"));
52739 + return FALSE;
52740 + }
52741 +
52742 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MODE_Proc (TxMode = %d)\n", pAd->ate.TxWI.PHYMODE));
52743 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MODE_Proc Success\n"));
52744 +
52745 +
52746 + return TRUE;
52747 +}
52748 +
52749 +/*
52750 + ==========================================================================
52751 + Description:
52752 + Set ATE Tx frame GI
52753 +
52754 + Return:
52755 + TRUE if all parameters are OK, FALSE otherwise
52756 + ==========================================================================
52757 +*/
52758 +INT Set_ATE_TX_GI_Proc(
52759 + IN PRTMP_ADAPTER pAd,
52760 + IN PUCHAR arg)
52761 +{
52762 + pAd->ate.TxWI.ShortGI = simple_strtol(arg, 0, 10);
52763 +
52764 + if(pAd->ate.TxWI.ShortGI > 1)
52765 + {
52766 + pAd->ate.TxWI.ShortGI = 0;
52767 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_GI_Proc::Out of range\n"));
52768 + return FALSE;
52769 + }
52770 +
52771 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_GI_Proc (GI = %d)\n", pAd->ate.TxWI.ShortGI));
52772 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_GI_Proc Success\n"));
52773 +
52774 +
52775 + return TRUE;
52776 +}
52777 +
52778 +/*
52779 + ==========================================================================
52780 + Description:
52781 + ==========================================================================
52782 + */
52783 +INT Set_ATE_RX_FER_Proc(
52784 + IN PRTMP_ADAPTER pAd,
52785 + IN PUCHAR arg)
52786 +{
52787 + pAd->ate.bRxFer = simple_strtol(arg, 0, 10);
52788 +
52789 + if (pAd->ate.bRxFer == 1)
52790 + {
52791 + pAd->ate.RxCntPerSec = 0;
52792 + pAd->ate.RxTotalCnt = 0;
52793 + }
52794 +
52795 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_FER_Proc (bRxFer = %d)\n", pAd->ate.bRxFer));
52796 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_FER_Proc Success\n"));
52797 +
52798 +
52799 + return TRUE;
52800 +}
52801 +
52802 +INT Set_ATE_Read_RF_Proc(
52803 + IN PRTMP_ADAPTER pAd,
52804 + IN PUCHAR arg)
52805 +{
52806 + ate_print(KERN_EMERG "R1 = %lx\n", pAd->LatchRfRegs.R1);
52807 + ate_print(KERN_EMERG "R2 = %lx\n", pAd->LatchRfRegs.R2);
52808 + ate_print(KERN_EMERG "R3 = %lx\n", pAd->LatchRfRegs.R3);
52809 + ate_print(KERN_EMERG "R4 = %lx\n", pAd->LatchRfRegs.R4);
52810 +
52811 + return TRUE;
52812 +}
52813 +
52814 +INT Set_ATE_Write_RF1_Proc(
52815 + IN PRTMP_ADAPTER pAd,
52816 + IN PUCHAR arg)
52817 +{
52818 + UINT32 value = simple_strtol(arg, 0, 16);
52819 +
52820 + pAd->LatchRfRegs.R1 = value;
52821 + RtmpRfIoWrite(pAd);
52822 +
52823 + return TRUE;
52824 +}
52825 +
52826 +INT Set_ATE_Write_RF2_Proc(
52827 + IN PRTMP_ADAPTER pAd,
52828 + IN PUCHAR arg)
52829 +{
52830 + UINT32 value = simple_strtol(arg, 0, 16);
52831 +
52832 + pAd->LatchRfRegs.R2 = value;
52833 + RtmpRfIoWrite(pAd);
52834 +
52835 + return TRUE;
52836 +}
52837 +
52838 +INT Set_ATE_Write_RF3_Proc(
52839 + IN PRTMP_ADAPTER pAd,
52840 + IN PUCHAR arg)
52841 +{
52842 + UINT32 value = simple_strtol(arg, 0, 16);
52843 +
52844 + pAd->LatchRfRegs.R3 = value;
52845 + RtmpRfIoWrite(pAd);
52846 +
52847 + return TRUE;
52848 +}
52849 +
52850 +INT Set_ATE_Write_RF4_Proc(
52851 + IN PRTMP_ADAPTER pAd,
52852 + IN PUCHAR arg)
52853 +{
52854 + UINT32 value = simple_strtol(arg, 0, 16);
52855 +
52856 + pAd->LatchRfRegs.R4 = value;
52857 + RtmpRfIoWrite(pAd);
52858 +
52859 + return TRUE;
52860 +}
52861 +
52862 +/*
52863 + ==========================================================================
52864 + Description:
52865 + Load and Write EEPROM from a binary file prepared in advance.
52866 +
52867 + Return:
52868 + TRUE if all parameters are OK, FALSE otherwise
52869 + ==========================================================================
52870 +*/
52871 +#ifndef UCOS
52872 +INT Set_ATE_Load_E2P_Proc(
52873 + IN PRTMP_ADAPTER pAd,
52874 + IN PUCHAR arg)
52875 +{
52876 + BOOLEAN ret = FALSE;
52877 + PUCHAR src = EEPROM_BIN_FILE_NAME;
52878 + struct file *srcf;
52879 + INT32 retval, orgfsuid, orgfsgid;
52880 + mm_segment_t orgfs;
52881 + USHORT WriteEEPROM[(EEPROM_SIZE/2)];
52882 + UINT32 FileLength = 0;
52883 + UINT32 value = simple_strtol(arg, 0, 10);
52884 +
52885 + ATEDBGPRINT(RT_DEBUG_ERROR, ("===> %s (value=%d)\n\n", __FUNCTION__, value));
52886 +
52887 + if (value > 0)
52888 + {
52889 + /* zero the e2p buffer */
52890 + NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
52891 +
52892 + /* save uid and gid used for filesystem access.
52893 + ** set user and group to 0 (root)
52894 + */
52895 + orgfsuid = current->fsuid;
52896 + orgfsgid = current->fsgid;
52897 + /* as root */
52898 + current->fsuid = current->fsgid = 0;
52899 + orgfs = get_fs();
52900 + set_fs(KERNEL_DS);
52901 +
52902 + do
52903 + {
52904 + /* open the bin file */
52905 + srcf = filp_open(src, O_RDONLY, 0);
52906 +
52907 + if (IS_ERR(srcf))
52908 + {
52909 + ate_print("%s - Error %ld opening %s\n", __FUNCTION__, -PTR_ERR(srcf), src);
52910 + break;
52911 + }
52912 +
52913 + /* the object must have a read method */
52914 + if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
52915 + {
52916 + ate_print("%s - %s does not have a read method\n", __FUNCTION__, src);
52917 + break;
52918 + }
52919 +
52920 + /* read the firmware from the file *.bin */
52921 + FileLength = srcf->f_op->read(srcf,
52922 + (PUCHAR)WriteEEPROM,
52923 + EEPROM_SIZE,
52924 + &srcf->f_pos);
52925 +
52926 + if (FileLength != EEPROM_SIZE)
52927 + {
52928 + ate_print("%s: error file length (=%d) in e2p.bin\n",
52929 + __FUNCTION__, FileLength);
52930 + break;
52931 + }
52932 + else
52933 + {
52934 + /* write the content of .bin file to EEPROM */
52935 + rt_ee_write_all(pAd, WriteEEPROM);
52936 + ret = TRUE;
52937 + }
52938 + break;
52939 + } while(TRUE);
52940 +
52941 + /* close firmware file */
52942 + if (IS_ERR(srcf))
52943 + {
52944 + ;
52945 + }
52946 + else
52947 + {
52948 + retval = filp_close(srcf, NULL);
52949 + if (retval)
52950 + {
52951 + ATEDBGPRINT(RT_DEBUG_ERROR, ("--> Error %d closing %s\n", -retval, src));
52952 +
52953 + }
52954 + }
52955 +
52956 + /* restore */
52957 + set_fs(orgfs);
52958 + current->fsuid = orgfsuid;
52959 + current->fsgid = orgfsgid;
52960 + }
52961 + ATEDBGPRINT(RT_DEBUG_ERROR, ("<=== %s (ret=%d)\n", __FUNCTION__, ret));
52962 +
52963 + return ret;
52964 +
52965 +}
52966 +#else
52967 +INT Set_ATE_Load_E2P_Proc(
52968 + IN PRTMP_ADAPTER pAd,
52969 + IN PUCHAR arg)
52970 +{
52971 + USHORT WriteEEPROM[(EEPROM_SIZE/2)];
52972 + struct iwreq *wrq = (struct iwreq *)arg;
52973 +
52974 + ATEDBGPRINT(RT_DEBUG_TRACE, ("===> %s (wrq->u.data.length = %d)\n\n", __FUNCTION__, wrq->u.data.length));
52975 +
52976 + if (wrq->u.data.length != EEPROM_SIZE)
52977 + {
52978 + ate_print("%s: error length (=%d) from host\n",
52979 + __FUNCTION__, wrq->u.data.length);
52980 + return FALSE;
52981 + }
52982 + else/* (wrq->u.data.length == EEPROM_SIZE) */
52983 + {
52984 + /* zero the e2p buffer */
52985 + NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
52986 +
52987 + /* fill the local buffer */
52988 + NdisMoveMemory((PUCHAR)WriteEEPROM, wrq->u.data.pointer, wrq->u.data.length);
52989 +
52990 + do
52991 + {
52992 + /* write the content of .bin file to EEPROM */
52993 + rt_ee_write_all(pAd, WriteEEPROM);
52994 +
52995 + } while(FALSE);
52996 + }
52997 +
52998 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== %s\n", __FUNCTION__));
52999 +
53000 + return TRUE;
53001 +
53002 +}
53003 +#endif // !UCOS //
53004 +
53005 +INT Set_ATE_Read_E2P_Proc(
53006 + IN PRTMP_ADAPTER pAd,
53007 + IN PUCHAR arg)
53008 +{
53009 + USHORT buffer[EEPROM_SIZE/2];
53010 + USHORT *p;
53011 + int i;
53012 +
53013 + rt_ee_read_all(pAd, (USHORT *)buffer);
53014 + p = buffer;
53015 + for (i = 0; i < (EEPROM_SIZE/2); i++)
53016 + {
53017 + ate_print("%4.4x ", *p);
53018 + if (((i+1) % 16) == 0)
53019 + ate_print("\n");
53020 + p++;
53021 + }
53022 + return TRUE;
53023 +}
53024 +
53025 +INT Set_ATE_Show_Proc(
53026 + IN PRTMP_ADAPTER pAd,
53027 + IN PUCHAR arg)
53028 +{
53029 + ate_print("Mode=%d\n", pAd->ate.Mode);
53030 + ate_print("TxPower0=%d\n", pAd->ate.TxPower0);
53031 + ate_print("TxPower1=%d\n", pAd->ate.TxPower1);
53032 + ate_print("TxAntennaSel=%d\n", pAd->ate.TxAntennaSel);
53033 + ate_print("RxAntennaSel=%d\n", pAd->ate.RxAntennaSel);
53034 + ate_print("BBPCurrentBW=%d\n", pAd->ate.TxWI.BW);
53035 + ate_print("GI=%d\n", pAd->ate.TxWI.ShortGI);
53036 + ate_print("MCS=%d\n", pAd->ate.TxWI.MCS);
53037 + ate_print("TxMode=%d\n", pAd->ate.TxWI.PHYMODE);
53038 + ate_print("Addr1=%02x:%02x:%02x:%02x:%02x:%02x\n",
53039 + pAd->ate.Addr1[0], pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]);
53040 + ate_print("Addr2=%02x:%02x:%02x:%02x:%02x:%02x\n",
53041 + pAd->ate.Addr2[0], pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]);
53042 + ate_print("Addr3=%02x:%02x:%02x:%02x:%02x:%02x\n",
53043 + pAd->ate.Addr3[0], pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]);
53044 + ate_print("Channel=%d\n", pAd->ate.Channel);
53045 + ate_print("TxLength=%d\n", pAd->ate.TxLength);
53046 + ate_print("TxCount=%u\n", pAd->ate.TxCount);
53047 + ate_print("RFFreqOffset=%d\n", pAd->ate.RFFreqOffset);
53048 + ate_print(KERN_EMERG "Set_ATE_Show_Proc Success\n");
53049 + return TRUE;
53050 +}
53051 +
53052 +INT Set_ATE_Help_Proc(
53053 + IN PRTMP_ADAPTER pAd,
53054 + IN PUCHAR arg)
53055 +{
53056 + ate_print("ATE=ATESTART, ATESTOP, TXCONT, TXCARR, TXFRAME, RXFRAME\n");
53057 + ate_print("ATEDA\n");
53058 + ate_print("ATESA\n");
53059 + ate_print("ATEBSSID\n");
53060 + ate_print("ATECHANNEL, range:0~14(unless A band !)\n");
53061 + ate_print("ATETXPOW0, set power level of antenna 1.\n");
53062 + ate_print("ATETXPOW1, set power level of antenna 2.\n");
53063 + ate_print("ATETXANT, set TX antenna. 0:all, 1:antenna one, 2:antenna two.\n");
53064 + ate_print("ATERXANT, set RX antenna.0:all, 1:antenna one, 2:antenna two, 3:antenna three.\n");
53065 + ate_print("ATETXFREQOFFSET, set frequency offset, range 0~63\n");
53066 + ate_print("ATETXBW, set BandWidth, 0:20MHz, 1:40MHz.\n");
53067 + ate_print("ATETXLEN, set Frame length, range 24~%d\n", (MAX_FRAME_SIZE - 34/* == 2312 */));
53068 + ate_print("ATETXCNT, set how many frame going to transmit.\n");
53069 + ate_print("ATETXMCS, set MCS, reference to rate table.\n");
53070 + ate_print("ATETXMODE, set Mode 0:CCK, 1:OFDM, 2:HT-Mix, 3:GreenField, reference to rate table.\n");
53071 + ate_print("ATETXGI, set GI interval, 0:Long, 1:Short\n");
53072 + ate_print("ATERXFER, 0:disable Rx Frame error rate. 1:enable Rx Frame error rate.\n");
53073 + ate_print("ATERRF, show all RF registers.\n");
53074 + ate_print("ATEWRF1, set RF1 register.\n");
53075 + ate_print("ATEWRF2, set RF2 register.\n");
53076 + ate_print("ATEWRF3, set RF3 register.\n");
53077 + ate_print("ATEWRF4, set RF4 register.\n");
53078 + ate_print("ATELDE2P, load EEPROM from .bin file.\n");
53079 + ate_print("ATERE2P, display all EEPROM content.\n");
53080 + ate_print("ATESHOW, display all parameters of ATE.\n");
53081 + ate_print("ATEHELP, online help.\n");
53082 +
53083 + return TRUE;
53084 +}
53085 +
53086 +/*
53087 + ==========================================================================
53088 + Description:
53089 +
53090 + AsicSwitchChannel() dedicated for ATE.
53091 +
53092 + ==========================================================================
53093 +*/
53094 +VOID ATEAsicSwitchChannel(
53095 + IN PRTMP_ADAPTER pAd)
53096 +{
53097 + UINT32 R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0, Value = 0;
53098 + CHAR TxPwer = 0, TxPwer2 = 0;
53099 + UCHAR index, BbpValue = 0, R66 = 0x30;
53100 + RTMP_RF_REGS *RFRegTable;
53101 + UCHAR Channel;
53102 +
53103 +#ifdef RALINK_28xx_QA
53104 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
53105 + {
53106 + if (pAd->ate.Channel != pAd->LatchRfRegs.Channel)
53107 + {
53108 + pAd->ate.Channel = pAd->LatchRfRegs.Channel;
53109 + }
53110 + return;
53111 + }
53112 + else
53113 +#endif // RALINK_28xx_QA //
53114 + Channel = pAd->ate.Channel;
53115 +
53116 + // Select antenna
53117 + AsicAntennaSelect(pAd, Channel);
53118 +
53119 + // fill Tx power value
53120 + TxPwer = pAd->ate.TxPower0;
53121 + TxPwer2 = pAd->ate.TxPower1;
53122 +
53123 + RFRegTable = RF2850RegTable;
53124 +
53125 + switch (pAd->RfIcType)
53126 + {
53127 + /* But only 2850 and 2750 support 5.5GHz band... */
53128 + case RFIC_2820:
53129 + case RFIC_2850:
53130 + case RFIC_2720:
53131 + case RFIC_2750:
53132 +
53133 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
53134 + {
53135 + if (Channel == RFRegTable[index].Channel)
53136 + {
53137 + R2 = RFRegTable[index].R2;
53138 + if (pAd->Antenna.field.TxPath == 1)
53139 + {
53140 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
53141 + }
53142 +
53143 + if (pAd->Antenna.field.RxPath == 2)
53144 + {
53145 + switch (pAd->ate.RxAntennaSel)
53146 + {
53147 + case 1:
53148 + R2 |= 0x20040;
53149 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53150 + BbpValue &= 0xE4;
53151 + BbpValue |= 0x00;
53152 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53153 + break;
53154 + case 2:
53155 + R2 |= 0x10040;
53156 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53157 + BbpValue &= 0xE4;
53158 + BbpValue |= 0x01;
53159 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53160 + break;
53161 + default:
53162 + R2 |= 0x40;
53163 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53164 + BbpValue &= 0xE4;
53165 + /* Only enable two Antenna to receive. */
53166 + BbpValue |= 0x08;
53167 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53168 + break;
53169 + }
53170 + }
53171 + else if (pAd->Antenna.field.RxPath == 1)
53172 + {
53173 + R2 |= 0x20040; // write 1 to off RxPath
53174 + }
53175 +
53176 + if (pAd->Antenna.field.TxPath == 2)
53177 + {
53178 + if (pAd->ate.TxAntennaSel == 1)
53179 + {
53180 + R2 |= 0x4000; // If TX Antenna select is 1 , bit 14 = 1; Disable Ant 2
53181 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
53182 + BbpValue &= 0xE7; //11100111B
53183 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
53184 + }
53185 + else if (pAd->ate.TxAntennaSel == 2)
53186 + {
53187 + R2 |= 0x8000; // If TX Antenna select is 2 , bit 15 = 1; Disable Ant 1
53188 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
53189 + BbpValue &= 0xE7;
53190 + BbpValue |= 0x08;
53191 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
53192 + }
53193 + else
53194 + {
53195 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
53196 + BbpValue &= 0xE7;
53197 + BbpValue |= 0x10;
53198 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
53199 + }
53200 + }
53201 + if (pAd->Antenna.field.RxPath == 3)
53202 + {
53203 + switch (pAd->ate.RxAntennaSel)
53204 + {
53205 + case 1:
53206 + R2 |= 0x20040;
53207 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53208 + BbpValue &= 0xE4;
53209 + BbpValue |= 0x00;
53210 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53211 + break;
53212 + case 2:
53213 + R2 |= 0x10040;
53214 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53215 + BbpValue &= 0xE4;
53216 + BbpValue |= 0x01;
53217 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53218 + break;
53219 + case 3:
53220 + R2 |= 0x30000;
53221 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53222 + BbpValue &= 0xE4;
53223 + BbpValue |= 0x02;
53224 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53225 + break;
53226 + default:
53227 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
53228 + BbpValue &= 0xE4;
53229 + BbpValue |= 0x10;
53230 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
53231 + break;
53232 + }
53233 + }
53234 +
53235 + if (Channel > 14)
53236 + {
53237 + // initialize R3, R4
53238 + R3 = (RFRegTable[index].R3 & 0xffffc1ff);
53239 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15);
53240 +
53241 + // According the Rory's suggestion to solve the middle range issue.
53242 + // 5.5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
53243 + // R3
53244 + if ((TxPwer >= -7) && (TxPwer < 0))
53245 + {
53246 + TxPwer = (7+TxPwer);
53247 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
53248 + R3 |= (TxPwer << 10);
53249 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer=%d \n", TxPwer));
53250 + }
53251 + else
53252 + {
53253 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
53254 + R3 |= (TxPwer << 10) | (1 << 9);
53255 + }
53256 +
53257 + // R4
53258 + if ((TxPwer2 >= -7) && (TxPwer2 < 0))
53259 + {
53260 + TxPwer2 = (7+TxPwer2);
53261 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
53262 + R4 |= (TxPwer2 << 7);
53263 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
53264 + }
53265 + else
53266 + {
53267 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
53268 + R4 |= (TxPwer2 << 7) | (1 << 6);
53269 + }
53270 + }
53271 + else
53272 + {
53273 + R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
53274 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15) | (TxPwer2 <<6);// Set freq offset & TxPwr1
53275 + }
53276 +
53277 + // Based on BBP current mode before changing RF channel.
53278 + if (pAd->ate.TxWI.BW == BW_40)
53279 + {
53280 + R4 |=0x200000;
53281 + }
53282 +
53283 + // Update variables
53284 + pAd->LatchRfRegs.Channel = Channel;
53285 + pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
53286 + pAd->LatchRfRegs.R2 = R2;
53287 + pAd->LatchRfRegs.R3 = R3;
53288 + pAd->LatchRfRegs.R4 = R4;
53289 +
53290 + RtmpRfIoWrite(pAd);
53291 +
53292 + break;
53293 + }
53294 + }
53295 + break;
53296 +
53297 + default:
53298 + break;
53299 + }
53300 +
53301 + // Change BBP setting during switch from a->g, g->a
53302 + if (Channel <= 14)
53303 + {
53304 + ULONG TxPinCfg = 0x00050F0A;// 2007.10.09 by Brian : 0x0005050A ==> 0x00050F0A
53305 +
53306 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
53307 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
53308 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
53309 +
53310 + /* For 1T/2R chip only... */
53311 + if (pAd->NicConfig2.field.ExternalLNAForG)
53312 + {
53313 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
53314 + }
53315 + else
53316 + {
53317 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
53318 + }
53319 +
53320 + // According the Rory's suggestion to solve the middle range issue.
53321 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
53322 + ASSERT((BbpValue == 0x00));
53323 + if ((BbpValue != 0x00))
53324 + {
53325 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
53326 + }
53327 +
53328 + // 5.5GHz band selection PIN, bit1 and bit2 are complement
53329 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
53330 + Value &= (~0x6);
53331 + Value |= (0x04);
53332 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
53333 +
53334 + // Turn off unused PA or LNA when only 1T or 1R.
53335 + if (pAd->Antenna.field.TxPath == 1)
53336 + {
53337 + TxPinCfg &= 0xFFFFFFF3;
53338 + }
53339 + if (pAd->Antenna.field.RxPath == 1)
53340 + {
53341 + TxPinCfg &= 0xFFFFF3FF;
53342 + }
53343 +
53344 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
53345 + }
53346 + else
53347 + {
53348 + ULONG TxPinCfg = 0x00050F05;//2007.10.09 by Brian : 0x00050505 ==> 0x00050F05
53349 +
53350 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
53351 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
53352 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
53353 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
53354 +
53355 + // According the Rory's suggestion to solve the middle range issue.
53356 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
53357 + ASSERT((BbpValue == 0x00));
53358 + if ((BbpValue != 0x00))
53359 + {
53360 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
53361 + }
53362 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R91, &BbpValue);
53363 + ASSERT((BbpValue == 0x04));
53364 +
53365 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R92, &BbpValue);
53366 + ASSERT((BbpValue == 0x00));
53367 +
53368 + // 5.5GHz band selection PIN, bit1 and bit2 are complement
53369 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
53370 + Value &= (~0x6);
53371 + Value |= (0x02);
53372 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
53373 +
53374 + // Turn off unused PA or LNA when only 1T or 1R.
53375 + if (pAd->Antenna.field.TxPath == 1)
53376 + {
53377 + TxPinCfg &= 0xFFFFFFF3;
53378 + }
53379 + if (pAd->Antenna.field.RxPath == 1)
53380 + {
53381 + TxPinCfg &= 0xFFFFF3FF;
53382 + }
53383 +
53384 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
53385 + }
53386 +
53387 + // R66 should be set according to Channel and use 20MHz when scanning
53388 + if (Channel <= 14)
53389 + {
53390 + // BG band
53391 + R66 = 0x2E + GET_LNA_GAIN(pAd);
53392 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
53393 + }
53394 + else
53395 + {
53396 + // 5.5 GHz band
53397 + if (pAd->ate.TxWI.BW == BW_20)
53398 + {
53399 + R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
53400 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
53401 + }
53402 + else
53403 + {
53404 + R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
53405 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
53406 + }
53407 + }
53408 +
53409 + //
53410 + // On 11A, We should delay and wait RF/BBP to be stable
53411 + // and the appropriate time should be 1000 micro seconds
53412 + // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
53413 + //
53414 + RTMPusecDelay(1000);
53415 +
53416 + if (Channel > 14)
53417 + {
53418 + // When 5.5GHz band the LSB of TxPwr will be used to reduced 7dB or not.
53419 + ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
53420 + Channel,
53421 + pAd->RfIcType,
53422 + pAd->Antenna.field.TxPath,
53423 + pAd->LatchRfRegs.R1,
53424 + pAd->LatchRfRegs.R2,
53425 + pAd->LatchRfRegs.R3,
53426 + pAd->LatchRfRegs.R4));
53427 + }
53428 + else
53429 + {
53430 + 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",
53431 + Channel,
53432 + pAd->RfIcType,
53433 + (R3 & 0x00003e00) >> 9,
53434 + (R4 & 0x000007c0) >> 6,
53435 + pAd->Antenna.field.TxPath,
53436 + pAd->LatchRfRegs.R1,
53437 + pAd->LatchRfRegs.R2,
53438 + pAd->LatchRfRegs.R3,
53439 + pAd->LatchRfRegs.R4));
53440 + }
53441 +}
53442 +
53443 +//
53444 +// In fact, no one will call this routine so far !
53445 +//
53446 +/*
53447 + ==========================================================================
53448 + Description:
53449 + Gives CCK TX rate 2 more dB TX power.
53450 + This routine works only in ATE mode.
53451 +
53452 + calculate desired Tx power in RF R3.Tx0~5, should consider -
53453 + 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
53454 + 1. TxPowerPercentage
53455 + 2. auto calibration based on TSSI feedback
53456 + 3. extra 2 db for CCK
53457 + 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
53458 +
53459 + NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
53460 + it should be called AFTER MlmeDynamicTxRateSwitching()
53461 + ==========================================================================
53462 + */
53463 +VOID ATEAsicAdjustTxPower(
53464 + IN PRTMP_ADAPTER pAd)
53465 +{
53466 + INT i, j;
53467 + CHAR DeltaPwr = 0;
53468 + BOOLEAN bAutoTxAgc = FALSE;
53469 + UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
53470 + UCHAR BbpR49 = 0, idx;
53471 + PCHAR pTxAgcCompensate;
53472 + ULONG TxPwr[5];
53473 + CHAR Value;
53474 +
53475 + /* no one calls this procedure so far */
53476 + if (pAd->ate.TxWI.BW == BW_40)
53477 + {
53478 + if (pAd->ate.Channel > 14)
53479 + {
53480 + TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
53481 + TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
53482 + TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
53483 + TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
53484 + TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
53485 + }
53486 + else
53487 + {
53488 + TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
53489 + TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
53490 + TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
53491 + TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
53492 + TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
53493 + }
53494 + }
53495 + else
53496 + {
53497 + if (pAd->ate.Channel > 14)
53498 + {
53499 + TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
53500 + TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
53501 + TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
53502 + TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
53503 + TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
53504 + }
53505 + else
53506 + {
53507 + TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
53508 + TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
53509 + TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
53510 + TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
53511 + TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
53512 + }
53513 + }
53514 +
53515 + // TX power compensation for temperature variation based on TSSI.
53516 + // Do it per 4 seconds.
53517 + if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
53518 + {
53519 + if (pAd->ate.Channel <= 14)
53520 + {
53521 + /* bg channel */
53522 + bAutoTxAgc = pAd->bAutoTxAgcG;
53523 + TssiRef = pAd->TssiRefG;
53524 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
53525 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
53526 + TxAgcStep = pAd->TxAgcStepG;
53527 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
53528 + }
53529 + else
53530 + {
53531 + /* a channel */
53532 + bAutoTxAgc = pAd->bAutoTxAgcA;
53533 + TssiRef = pAd->TssiRefA;
53534 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
53535 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
53536 + TxAgcStep = pAd->TxAgcStepA;
53537 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
53538 + }
53539 +
53540 + if (bAutoTxAgc)
53541 + {
53542 + /* BbpR49 is unsigned char */
53543 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
53544 +
53545 + /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
53546 + /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
53547 + /* step value is defined in pAd->TxAgcStepG for tx power value */
53548 +
53549 + /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
53550 + /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
53551 + above value are examined in mass factory production */
53552 + /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
53553 +
53554 + /* plus is 0x10 ~ 0x40, minus is 0x60 ~ 0x90 */
53555 + /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
53556 + /* if value is 0x65, tx power will be -= TxAgcStep*(2-1) */
53557 +
53558 + if (BbpR49 > pTssiMinusBoundary[1])
53559 + {
53560 + // Reading is larger than the reference value.
53561 + // Check for how large we need to decrease the Tx power.
53562 + for (idx = 1; idx < 5; idx++)
53563 + {
53564 + if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
53565 + break;
53566 + }
53567 + // The index is the step we should decrease, idx = 0 means there is nothing to compensate
53568 +// if (R3 > (ULONG) (TxAgcStep * (idx-1)))
53569 + *pTxAgcCompensate = -(TxAgcStep * (idx-1));
53570 +// else
53571 +// *pTxAgcCompensate = -((UCHAR)R3);
53572 +
53573 + DeltaPwr += (*pTxAgcCompensate);
53574 + ATEDBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
53575 + BbpR49, TssiRef, TxAgcStep, idx-1));
53576 + }
53577 + else if (BbpR49 < pTssiPlusBoundary[1])
53578 + {
53579 + // Reading is smaller than the reference value
53580 + // check for how large we need to increase the Tx power
53581 + for (idx = 1; idx < 5; idx++)
53582 + {
53583 + if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
53584 + break;
53585 + }
53586 + // The index is the step we should increase, idx = 0 means there is nothing to compensate
53587 + *pTxAgcCompensate = TxAgcStep * (idx-1);
53588 + DeltaPwr += (*pTxAgcCompensate);
53589 + ATEDBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
53590 + BbpR49, TssiRef, TxAgcStep, idx-1));
53591 + }
53592 + else
53593 + {
53594 + *pTxAgcCompensate = 0;
53595 + ATEDBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
53596 + BbpR49, TssiRef, TxAgcStep, 0));
53597 + }
53598 + }
53599 + }
53600 + else
53601 + {
53602 + if (pAd->ate.Channel <= 14)
53603 + {
53604 + bAutoTxAgc = pAd->bAutoTxAgcG;
53605 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
53606 + }
53607 + else
53608 + {
53609 + bAutoTxAgc = pAd->bAutoTxAgcA;
53610 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
53611 + }
53612 +
53613 + if (bAutoTxAgc)
53614 + DeltaPwr += (*pTxAgcCompensate);
53615 + }
53616 +
53617 + /* calculate delta power based on the percentage specified from UI */
53618 + // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
53619 + // We lower TX power here according to the percentage specified from UI
53620 + if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
53621 + ;
53622 + else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
53623 + ;
53624 + else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW
53625 + {
53626 + DeltaPwr -= 1;
53627 + }
53628 + else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW
53629 + {
53630 + DeltaPwr -= 3;
53631 + }
53632 + else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW
53633 + {
53634 + DeltaPwr -= 6;
53635 + }
53636 + else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW
53637 + {
53638 + DeltaPwr -= 9;
53639 + }
53640 + else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW
53641 + {
53642 + DeltaPwr -= 12;
53643 + }
53644 +
53645 + /* reset different new tx power for different TX rate */
53646 + for(i=0; i<5; i++)
53647 + {
53648 + if (TxPwr[i] != 0xffffffff)
53649 + {
53650 + for (j=0; j<8; j++)
53651 + {
53652 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
53653 +
53654 + if ((Value + DeltaPwr) < 0)
53655 + {
53656 + Value = 0; /* min */
53657 + }
53658 + else if ((Value + DeltaPwr) > 0xF)
53659 + {
53660 + Value = 0xF; /* max */
53661 + }
53662 + else
53663 + {
53664 + Value += DeltaPwr; /* temperature compensation */
53665 + }
53666 +
53667 + /* fill new value to CSR offset */
53668 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
53669 + }
53670 +
53671 + /* write tx power value to CSR */
53672 + /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
53673 + TX power for OFDM 6M/9M
53674 + TX power for CCK5.5M/11M
53675 + TX power for CCK1M/2M */
53676 + /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
53677 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
53678 +
53679 +
53680 + }
53681 + }
53682 +
53683 +}
53684 +
53685 +/*
53686 + ========================================================================
53687 + Routine Description:
53688 + Write TxWI for ATE mode.
53689 +
53690 + Return Value:
53691 + None
53692 + ========================================================================
53693 +*/
53694 +
53695 +#ifdef RT2870
53696 +static VOID ATEWriteTxWI(
53697 + IN PRTMP_ADAPTER pAd,
53698 + IN PTXWI_STRUC pTxWI,
53699 + IN BOOLEAN FRAG,
53700 + IN BOOLEAN InsTimestamp,
53701 + IN BOOLEAN AMPDU,
53702 + IN BOOLEAN Ack,
53703 + IN BOOLEAN NSeq, // HW new a sequence.
53704 + IN UCHAR BASize,
53705 + IN UCHAR WCID,
53706 + IN ULONG Length,
53707 + IN UCHAR PID,
53708 + IN UCHAR MIMOps,
53709 + IN UCHAR Txopmode,
53710 + IN BOOLEAN CfAck,
53711 + IN HTTRANSMIT_SETTING Transmit)
53712 +{
53713 + //
53714 + // Always use Long preamble before verifiation short preamble functionality works well.
53715 + // Todo: remove the following line if short preamble functionality works
53716 + //
53717 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
53718 + pTxWI->FRAG= FRAG;
53719 + pTxWI->TS= InsTimestamp;
53720 + pTxWI->AMPDU = AMPDU;
53721 +
53722 + pTxWI->MIMOps = PWR_ACTIVE;
53723 + pTxWI->MpduDensity = 4;
53724 + pTxWI->ACK = Ack;
53725 + pTxWI->txop = Txopmode;
53726 + pTxWI->NSEQ = NSeq;
53727 + pTxWI->BAWinSize = BASize;
53728 +
53729 + pTxWI->WirelessCliID = WCID;
53730 + pTxWI->MPDUtotalByteCount = Length;
53731 + pTxWI->PacketId = PID;
53732 +
53733 + pTxWI->BW = Transmit.field.BW;
53734 + pTxWI->ShortGI = Transmit.field.ShortGI;
53735 + pTxWI->STBC= Transmit.field.STBC;
53736 +
53737 + pTxWI->MCS = Transmit.field.MCS;
53738 + pTxWI->PHYMODE= Transmit.field.MODE;
53739 +
53740 +#ifdef DOT11_N_SUPPORT
53741 + //
53742 + // MMPS is 802.11n features. Because TxWI->MCS > 7 must be HT mode,
53743 + // so need not check if it's HT rate.
53744 + //
53745 + if ((MIMOps == MMPS_STATIC) && (pTxWI->MCS > 7))
53746 + pTxWI->MCS = 7;
53747 +
53748 + if ((MIMOps == MMPS_DYNAMIC) && (pTxWI->MCS > 7)) // SMPS protect 2 spatial.
53749 + pTxWI->MIMOps = 1;
53750 +#endif // DOT11_N_SUPPORT //
53751 +
53752 + pTxWI->CFACK = CfAck;
53753 +
53754 + return;
53755 +}
53756 +#endif // RT2870 //
53757 +/*
53758 + ========================================================================
53759 +
53760 + Routine Description:
53761 + Disable protection for ATE.
53762 + ========================================================================
53763 +*/
53764 +VOID ATEDisableAsicProtect(
53765 + IN PRTMP_ADAPTER pAd)
53766 +{
53767 + PROT_CFG_STRUC ProtCfg, ProtCfg4;
53768 + UINT32 Protect[6];
53769 + USHORT offset;
53770 + UCHAR i;
53771 + UINT32 MacReg = 0;
53772 +
53773 + // Config ASIC RTS threshold register
53774 + RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
53775 + MacReg &= 0xFF0000FF;
53776 + MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
53777 + RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
53778 +
53779 + // Initial common protection settings
53780 + RTMPZeroMemory(Protect, sizeof(Protect));
53781 + ProtCfg4.word = 0;
53782 + ProtCfg.word = 0;
53783 + ProtCfg.field.TxopAllowGF40 = 1;
53784 + ProtCfg.field.TxopAllowGF20 = 1;
53785 + ProtCfg.field.TxopAllowMM40 = 1;
53786 + ProtCfg.field.TxopAllowMM20 = 1;
53787 + ProtCfg.field.TxopAllowOfdm = 1;
53788 + ProtCfg.field.TxopAllowCck = 1;
53789 + ProtCfg.field.RTSThEn = 1;
53790 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
53791 +
53792 + // Handle legacy(B/G) protection
53793 + ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
53794 + ProtCfg.field.ProtectCtrl = 0;
53795 + Protect[0] = ProtCfg.word;
53796 + Protect[1] = ProtCfg.word;
53797 +
53798 + // NO PROTECT
53799 + // 1.All STAs in the BSS are 20/40 MHz HT
53800 + // 2. in ai 20/40MHz BSS
53801 + // 3. all STAs are 20MHz in a 20MHz BSS
53802 + // Pure HT. no protection.
53803 +
53804 + // MM20_PROT_CFG
53805 + // Reserved (31:27)
53806 + // PROT_TXOP(25:20) -- 010111
53807 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
53808 + // PROT_CTRL(17:16) -- 00 (None)
53809 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
53810 + Protect[2] = 0x01744004;
53811 +
53812 + // MM40_PROT_CFG
53813 + // Reserved (31:27)
53814 + // PROT_TXOP(25:20) -- 111111
53815 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
53816 + // PROT_CTRL(17:16) -- 00 (None)
53817 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
53818 + Protect[3] = 0x03f44084;
53819 +
53820 + // CF20_PROT_CFG
53821 + // Reserved (31:27)
53822 + // PROT_TXOP(25:20) -- 010111
53823 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
53824 + // PROT_CTRL(17:16) -- 00 (None)
53825 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
53826 + Protect[4] = 0x01744004;
53827 +
53828 + // CF40_PROT_CFG
53829 + // Reserved (31:27)
53830 + // PROT_TXOP(25:20) -- 111111
53831 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
53832 + // PROT_CTRL(17:16) -- 00 (None)
53833 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
53834 + Protect[5] = 0x03f44084;
53835 +
53836 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
53837 +
53838 + offset = CCK_PROT_CFG;
53839 + for (i = 0;i < 6;i++)
53840 + RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
53841 +
53842 +}
53843 +
53844 +#ifdef RT2870
53845 +/*
53846 + ========================================================================
53847 + Routine Description:
53848 + Write TxInfo for ATE mode.
53849 +
53850 + Return Value:
53851 + None
53852 + ========================================================================
53853 +*/
53854 +static VOID ATEWriteTxInfo(
53855 + IN PRTMP_ADAPTER pAd,
53856 + IN PTXINFO_STRUC pTxInfo,
53857 + IN USHORT USBDMApktLen,
53858 + IN BOOLEAN bWiv,
53859 + IN UCHAR QueueSel,
53860 + IN UCHAR NextValid,
53861 + IN UCHAR TxBurst)
53862 +{
53863 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
53864 + pTxInfo->QSEL = QueueSel;
53865 +
53866 + if (QueueSel != FIFO_EDCA)
53867 + ATEDBGPRINT(RT_DEBUG_TRACE, ("=======> QueueSel != FIFO_EDCA<=======\n"));
53868 +
53869 + pTxInfo->USBDMANextVLD = NextValid;
53870 + pTxInfo->USBDMATxburst = TxBurst;
53871 + pTxInfo->WIV = bWiv;
53872 + pTxInfo->SwUseLastRound = 0;
53873 + pTxInfo->rsv = 0;
53874 + pTxInfo->rsv2 = 0;
53875 +
53876 + return;
53877 +}
53878 +#endif // RT2870 //
53879 +
53880 +/* There are two ways to convert Rssi */
53881 +#if 1
53882 +//
53883 +// The way used with GET_LNA_GAIN().
53884 +//
53885 +CHAR ATEConvertToRssi(
53886 + IN PRTMP_ADAPTER pAd,
53887 + IN CHAR Rssi,
53888 + IN UCHAR RssiNumber)
53889 +{
53890 + UCHAR RssiOffset, LNAGain;
53891 +
53892 + // Rssi equals to zero should be an invalid value
53893 + if (Rssi == 0)
53894 + return -99;
53895 +
53896 + LNAGain = GET_LNA_GAIN(pAd);
53897 + if (pAd->LatchRfRegs.Channel > 14)
53898 + {
53899 + if (RssiNumber == 0)
53900 + RssiOffset = pAd->ARssiOffset0;
53901 + else if (RssiNumber == 1)
53902 + RssiOffset = pAd->ARssiOffset1;
53903 + else
53904 + RssiOffset = pAd->ARssiOffset2;
53905 + }
53906 + else
53907 + {
53908 + if (RssiNumber == 0)
53909 + RssiOffset = pAd->BGRssiOffset0;
53910 + else if (RssiNumber == 1)
53911 + RssiOffset = pAd->BGRssiOffset1;
53912 + else
53913 + RssiOffset = pAd->BGRssiOffset2;
53914 + }
53915 +
53916 + return (-12 - RssiOffset - LNAGain - Rssi);
53917 +}
53918 +#else
53919 +//
53920 +// The way originally used in ATE of rt2860ap.
53921 +//
53922 +CHAR ATEConvertToRssi(
53923 + IN PRTMP_ADAPTER pAd,
53924 + IN CHAR Rssi,
53925 + IN UCHAR RssiNumber)
53926 +{
53927 + UCHAR RssiOffset, LNAGain;
53928 +
53929 + // Rssi equals to zero should be an invalid value
53930 + if (Rssi == 0)
53931 + return -99;
53932 +
53933 + if (pAd->LatchRfRegs.Channel > 14)
53934 + {
53935 + LNAGain = pAd->ALNAGain;
53936 + if (RssiNumber == 0)
53937 + RssiOffset = pAd->ARssiOffset0;
53938 + else if (RssiNumber == 1)
53939 + RssiOffset = pAd->ARssiOffset1;
53940 + else
53941 + RssiOffset = pAd->ARssiOffset2;
53942 + }
53943 + else
53944 + {
53945 + LNAGain = pAd->BLNAGain;
53946 + if (RssiNumber == 0)
53947 + RssiOffset = pAd->BGRssiOffset0;
53948 + else if (RssiNumber == 1)
53949 + RssiOffset = pAd->BGRssiOffset1;
53950 + else
53951 + RssiOffset = pAd->BGRssiOffset2;
53952 + }
53953 +
53954 + return (-32 - RssiOffset + LNAGain - Rssi);
53955 +}
53956 +#endif /* end of #if 1 */
53957 +
53958 +/*
53959 + ========================================================================
53960 +
53961 + Routine Description:
53962 + Set Japan filter coefficients if needed.
53963 + Note:
53964 + This routine should only be called when
53965 + entering TXFRAME mode or TXCONT mode.
53966 +
53967 + ========================================================================
53968 +*/
53969 +static VOID SetJapanFilter(
53970 + IN PRTMP_ADAPTER pAd)
53971 +{
53972 + UCHAR BbpData = 0;
53973 +
53974 + //
53975 + // If Channel=14 and Bandwidth=20M and Mode=CCK, set BBP R4 bit5=1
53976 + // (Japan Tx filter coefficients)when (TXFRAME or TXCONT).
53977 + //
53978 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BbpData);
53979 +
53980 + if ((pAd->ate.TxWI.PHYMODE == MODE_CCK) && (pAd->ate.Channel == 14) && (pAd->ate.TxWI.BW == BW_20))
53981 + {
53982 + BbpData |= 0x20; // turn on
53983 + ATEDBGPRINT(RT_DEBUG_TRACE, ("SetJapanFilter!!!\n"));
53984 + }
53985 + else
53986 + {
53987 + BbpData &= 0xdf; // turn off
53988 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ClearJapanFilter!!!\n"));
53989 + }
53990 +
53991 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BbpData);
53992 +}
53993 +
53994 +VOID ATESampleRssi(
53995 + IN PRTMP_ADAPTER pAd,
53996 + IN PRXWI_STRUC pRxWI)
53997 +{
53998 + /* There are two ways to collect RSSI. */
53999 +#if 1
54000 + //pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
54001 + if (pRxWI->RSSI0 != 0)
54002 + {
54003 + pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
54004 + pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
54005 + pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
54006 + }
54007 + if (pRxWI->RSSI1 != 0)
54008 + {
54009 + pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
54010 + pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
54011 + pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
54012 + }
54013 + if (pRxWI->RSSI2 != 0)
54014 + {
54015 + pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
54016 + pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
54017 + pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
54018 + }
54019 +
54020 + pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);// CHAR ==> UCHAR ?
54021 + pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);// CHAR ==> UCHAR ?
54022 +
54023 + pAd->ate.NumOfAvgRssiSample ++;
54024 +#else
54025 + pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);
54026 + pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);
54027 + pAd->ate.RxCntPerSec++;
54028 + pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
54029 + pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
54030 + pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
54031 + pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
54032 + pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
54033 + pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
54034 + pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
54035 + pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
54036 + pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
54037 + pAd->ate.NumOfAvgRssiSample ++;
54038 +#endif
54039 +}
54040 +
54041 +#ifdef CONFIG_STA_SUPPORT
54042 +VOID RTMPStationStop(
54043 + IN PRTMP_ADAPTER pAd)
54044 +{
54045 +// BOOLEAN Cancelled;
54046 +
54047 + ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStop\n"));
54048 +
54049 +#if 0
54050 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
54051 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
54052 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
54053 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
54054 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
54055 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
54056 +#endif
54057 + // For rx statistics, we need to keep this timer running.
54058 +// RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
54059 +
54060 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStop\n"));
54061 +}
54062 +
54063 +VOID RTMPStationStart(
54064 + IN PRTMP_ADAPTER pAd)
54065 +{
54066 + ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStart\n"));
54067 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStart\n"));
54068 +}
54069 +#endif // CONFIG_STA_SUPPORT //
54070 +
54071 +/*
54072 + ==========================================================================
54073 + Description:
54074 + Setup Frame format.
54075 + NOTE:
54076 + This routine should only be used in ATE mode.
54077 + ==========================================================================
54078 + */
54079 +
54080 +#ifdef RT2870
54081 +/*======================Start of RT2870======================*/
54082 +/* */
54083 +/* */
54084 +static INT ATESetUpFrame(
54085 + IN PRTMP_ADAPTER pAd,
54086 + IN UINT32 TxIdx)
54087 +{
54088 + UINT j;
54089 + PTX_CONTEXT pNullContext;
54090 + PUCHAR pDest;
54091 + HTTRANSMIT_SETTING TxHTPhyMode;
54092 + PTXWI_STRUC pTxWI;
54093 + PTXINFO_STRUC pTxInfo;
54094 + UINT32 TransferBufferLength, OrgBufferLength = 0;
54095 + UCHAR padLen = 0;
54096 +#ifdef RALINK_28xx_QA
54097 + PHEADER_802_11 pHeader80211 = NULL;
54098 +#endif // RALINK_28xx_QA //
54099 +
54100 + if ((RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
54101 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) ||
54102 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
54103 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
54104 + {
54105 + return -1;
54106 + }
54107 +
54108 + /* We always use QID_AC_BE and FIFO_EDCA in ATE mode. */
54109 +
54110 + pNullContext = &(pAd->NullContext);
54111 + ASSERT(pNullContext != NULL);
54112 +
54113 + if (pNullContext->InUse == FALSE)
54114 + {
54115 + // Set the in use bit
54116 + pNullContext->InUse = TRUE;
54117 + NdisZeroMemory(&(pAd->NullFrame), sizeof(HEADER_802_11));
54118 +
54119 + // Fill 802.11 header.
54120 +#ifdef RALINK_28xx_QA
54121 + if (pAd->ate.bQATxStart == TRUE)
54122 + {
54123 + pHeader80211 = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
54124 +// pDest = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
54125 +// pHeader80211 = (PHEADER_802_11)pDest;
54126 + }
54127 + else
54128 +#endif // RALINK_28xx_QA //
54129 + {
54130 + // Fill 802.11 header.
54131 + NdisMoveMemory(&(pAd->NullFrame), TemplateFrame, sizeof(HEADER_802_11));
54132 + }
54133 +#ifdef RT_BIG_ENDIAN
54134 + RTMPFrameEndianChange(pAd, (PUCHAR)&(pAd->NullFrame), DIR_READ, FALSE);
54135 +#endif // RT_BIG_ENDIAN //
54136 +
54137 +#ifdef RALINK_28xx_QA
54138 + if (pAd->ate.bQATxStart == TRUE)
54139 + {
54140 + /* modify sequence number.... */
54141 + if (pAd->ate.TxDoneCount == 0)
54142 + {
54143 + pAd->ate.seq = pHeader80211->Sequence;
54144 + }
54145 + else
54146 + {
54147 + pHeader80211->Sequence = ++pAd->ate.seq;
54148 + }
54149 + /* We already got all the addr. fields from QA GUI. */
54150 + }
54151 + else
54152 +#endif // RALINK_28xx_QA //
54153 + {
54154 + COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->ate.Addr1);
54155 + COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->ate.Addr2);
54156 + COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->ate.Addr3);
54157 + }
54158 +
54159 + RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], TX_BUFFER_NORMSIZE);//???
54160 + pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
54161 +
54162 +#ifdef RALINK_28xx_QA
54163 + if (pAd->ate.bQATxStart == TRUE)
54164 + {
54165 + // Avoid to exceed the range of WirelessPacket[].
54166 + ASSERT(pAd->ate.TxInfo.USBDMATxPktLen <= (MAX_FRAME_SIZE - 34/* == 2312 */));
54167 + NdisMoveMemory(pTxInfo, &(pAd->ate.TxInfo), sizeof(pAd->ate.TxInfo));
54168 + }
54169 + else
54170 +#endif // RALINK_28xx_QA //
54171 + {
54172 + // Avoid to exceed the range of WirelessPacket[].
54173 + ASSERT(pAd->ate.TxLength <= (MAX_FRAME_SIZE - 34/* == 2312 */));
54174 +
54175 + // pTxInfo->USBDMATxPktLen will be updated to include padding later.
54176 + ATEWriteTxInfo(pAd, pTxInfo, (USHORT)(TXWI_SIZE + pAd->ate.TxLength), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
54177 + pTxInfo->QSEL = FIFO_EDCA;
54178 + }
54179 +
54180 + pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
54181 +
54182 + // Fill TxWI.
54183 + if (pAd->ate.bQATxStart == TRUE)
54184 + {
54185 + TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
54186 + TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
54187 + TxHTPhyMode.field.STBC = pAd->ate.TxWI.STBC;
54188 + TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
54189 + TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
54190 + ATEWriteTxWI(pAd, pTxWI, pAd->ate.TxWI.FRAG, pAd->ate.TxWI.TS, pAd->ate.TxWI.AMPDU, pAd->ate.TxWI.ACK, pAd->ate.TxWI.NSEQ,
54191 + 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);
54192 + }
54193 + else
54194 + {
54195 + TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
54196 + TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
54197 + TxHTPhyMode.field.STBC = 0;
54198 + TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
54199 + TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
54200 +
54201 + ATEWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE/* No ack required. */, FALSE, 0, BSSID_WCID, pAd->ate.TxLength,
54202 + 0, 0, IFS_HTTXOP, FALSE, TxHTPhyMode);// "MMPS_STATIC" instead of "MMPS_DYNAMIC" ???
54203 + }
54204 +
54205 + RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
54206 +
54207 + pDest = &(pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE+sizeof(HEADER_802_11)]);
54208 +
54209 + // Prepare frame payload
54210 +#ifdef RALINK_28xx_QA
54211 + if (pAd->ate.bQATxStart == TRUE)
54212 + {
54213 + // copy pattern
54214 + if ((pAd->ate.PLen != 0))
54215 + {
54216 + for (j = 0; j < pAd->ate.DLen; j+=pAd->ate.PLen)
54217 + {
54218 + RTMPMoveMemory(pDest, pAd->ate.Pattern, pAd->ate.PLen);
54219 + pDest += pAd->ate.PLen;
54220 + }
54221 + }
54222 + TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxWI.MPDUtotalByteCount;
54223 + }
54224 + else
54225 +#endif // RALINK_28xx_QA //
54226 + {
54227 + for (j = 0; j < (pAd->ate.TxLength - sizeof(HEADER_802_11)); j++)
54228 + {
54229 + *pDest = 0xA5;
54230 + pDest += 1;
54231 + }
54232 + TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxLength;
54233 + }
54234 +
54235 +#if 1
54236 + OrgBufferLength = TransferBufferLength;
54237 + TransferBufferLength = (TransferBufferLength + 3) & (~3);
54238 +
54239 + // Always add 4 extra bytes at every packet.
54240 + padLen = TransferBufferLength - OrgBufferLength + 4;/* 4 == last packet padding */
54241 + ASSERT((padLen <= (RTMP_PKT_TAIL_PADDING - 4/* 4 == MaxBulkOutsize alignment padding */)));
54242 +
54243 + /* Now memzero all extra padding bytes. */
54244 + NdisZeroMemory(pDest, padLen);
54245 + pDest += padLen;
54246 +#else
54247 + if ((TransferBufferLength % 4) == 1)
54248 + {
54249 + NdisZeroMemory(pDest, 7);
54250 + pDest += 7;
54251 + TransferBufferLength += 3;
54252 + }
54253 + else if ((TransferBufferLength % 4) == 2)
54254 + {
54255 + NdisZeroMemory(pDest, 6);
54256 + pDest += 6;
54257 + TransferBufferLength += 2;
54258 + }
54259 + else if ((TransferBufferLength % 4) == 3)
54260 + {
54261 + NdisZeroMemory(pDest, 5);
54262 + pDest += 5;
54263 + TransferBufferLength += 1;
54264 + }
54265 +#endif // 1 //
54266 +
54267 + // Update pTxInfo->USBDMATxPktLen to include padding.
54268 + pTxInfo->USBDMATxPktLen = TransferBufferLength - TXINFO_SIZE;
54269 +
54270 + TransferBufferLength += 4;
54271 +
54272 + // If TransferBufferLength is multiple of 64, add extra 4 bytes again.
54273 + if ((TransferBufferLength % pAd->BulkOutMaxPacketSize) == 0)
54274 + {
54275 + NdisZeroMemory(pDest, 4);
54276 + TransferBufferLength += 4;
54277 + }
54278 +
54279 + // Fill out frame length information for global Bulk out arbitor
54280 + pAd->NullContext.BulkOutSize = TransferBufferLength;
54281 + }
54282 +#ifdef RT_BIG_ENDIAN
54283 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
54284 + RTMPFrameEndianChange(pAd, (((PUCHAR)pTxInfo)+TXWI_SIZE+TXINFO_SIZE), DIR_WRITE, FALSE);
54285 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
54286 +#endif // RT_BIG_ENDIAN //
54287 + return 0;
54288 +}
54289 +
54290 +VOID ATE_RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
54291 +{
54292 + PRTMP_ADAPTER pAd;
54293 + PTX_CONTEXT pNullContext;
54294 + UCHAR BulkOutPipeId;
54295 + NTSTATUS Status;
54296 + unsigned long IrqFlags;
54297 + ULONG OldValue;
54298 +
54299 + pNullContext = (PTX_CONTEXT)pUrb->context;
54300 + pAd = pNullContext->pAd;
54301 +
54302 +
54303 + // Reset Null frame context flags
54304 + pNullContext->IRPPending = FALSE;
54305 + pNullContext->InUse = FALSE;
54306 + Status = pUrb->status;
54307 +
54308 + // Store BulkOut PipeId
54309 + BulkOutPipeId = pNullContext->BulkOutPipeId;
54310 + pAd->BulkOutDataOneSecCount++;
54311 +
54312 + if (Status == USB_ST_NOERROR)
54313 + {
54314 +#ifdef RALINK_28xx_QA
54315 + if ((ATE_ON(pAd)) && (pAd->ate.bQATxStart == TRUE))
54316 + {
54317 + if (pAd->ate.QID == BulkOutPipeId)
54318 + {
54319 + // Let Rx can have a chance to break in during Tx process,
54320 + // especially for loopback mode in QA ATE.
54321 + // To trade off between tx performance and loopback mode integrity.
54322 + /* Q : Now Rx is handled by tasklet, do we still need this delay ? */
54323 + /* Ans : Even tasklet is used, Rx/Tx < 1 if we do not delay for a while right here. */
54324 + RTMPusecDelay(500);
54325 + pAd->ate.TxDoneCount++;
54326 + pAd->RalinkCounters.KickTxCount++;
54327 + ASSERT(pAd->ate.QID == 0);
54328 + pAd->ate.TxAc0++;
54329 + }
54330 + }
54331 +#endif // RALINK_28xx_QA //
54332 + pAd->BulkOutComplete++;
54333 +
54334 + pAd->Counters8023.GoodTransmits++;
54335 +
54336 + /* Don't worry about the queue is empty or not. This function will check itself. */
54337 + RTMPDeQueuePacket(pAd, TRUE, BulkOutPipeId, MAX_TX_PROCESS);
54338 +
54339 + /* In 28xx, SendTxWaitQueue ==> TxSwQueue */
54340 +/*
54341 + if (pAd->SendTxWaitQueue[BulkOutPipeId].Number > 0)
54342 + {
54343 + RTMPDeQueuePacket(pAd, BulkOutPipeId);
54344 + }
54345 +*/
54346 + }
54347 + else // STATUS_OTHER
54348 + {
54349 + pAd->BulkOutCompleteOther++;
54350 +
54351 + ATEDBGPRINT(RT_DEBUG_ERROR, ("BulkOutDataPacket Failed STATUS_OTHER = 0x%x . \n", Status));
54352 + ATEDBGPRINT(RT_DEBUG_ERROR, (">>BulkOutReq=0x%lx, BulkOutComplete=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete));
54353 +
54354 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
54355 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
54356 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
54357 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
54358 + {
54359 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
54360 + /* In 28xx, RT_OID_USB_RESET_BULK_OUT ==> CMDTHREAD_RESET_BULK_OUT */
54361 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
54362 + // Check
54363 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54364 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
54365 + pAd->bulkResetPipeid = BulkOutPipeId;
54366 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54367 + return;
54368 + }
54369 + }
54370 +
54371 +
54372 +
54373 + if (atomic_read(&pAd->BulkOutRemained) > 0)
54374 + {
54375 + atomic_dec(&pAd->BulkOutRemained);
54376 + }
54377 +
54378 + // 1st - Transmit Success
54379 + OldValue = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart;
54380 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart++;
54381 +
54382 + if (pAd->WlanCounters.TransmittedFragmentCount.u.LowPart < OldValue)
54383 + {
54384 + pAd->WlanCounters.TransmittedFragmentCount.u.HighPart++;
54385 + }
54386 +
54387 + if(((pAd->ContinBulkOut == TRUE ) ||(atomic_read(&pAd->BulkOutRemained) > 0)) && (pAd->ate.Mode & ATE_TXFRAME))
54388 + {
54389 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
54390 + }
54391 + else
54392 + {
54393 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
54394 +#ifdef RALINK_28xx_QA
54395 + pAd->ate.TxStatus = 0;
54396 +#endif // RALINK_28xx_QA //
54397 + }
54398 +
54399 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54400 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
54401 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54402 +
54403 + // Always call Bulk routine, even reset bulk.
54404 + // The protection of rest bulk should be in BulkOut routine.
54405 + RTUSBKickBulkOut(pAd);
54406 +}
54407 +
54408 +/*
54409 + ========================================================================
54410 +
54411 + Routine Description:
54412 +
54413 + Arguments:
54414 +
54415 + Return Value:
54416 +
54417 + Note:
54418 +
54419 + ========================================================================
54420 +*/
54421 +VOID ATE_RTUSBBulkOutDataPacket(
54422 + IN PRTMP_ADAPTER pAd,
54423 + IN UCHAR BulkOutPipeId)
54424 +{
54425 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
54426 + PURB pUrb;
54427 + int ret = 0;
54428 + unsigned long IrqFlags;
54429 +
54430 +
54431 + ASSERT(BulkOutPipeId == 0);
54432 +
54433 + /* Build up the frame first. */
54434 +// ATESetUpFrame(pAd, 0);
54435 +
54436 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54437 +
54438 + if (pAd->BulkOutPending[BulkOutPipeId] == TRUE)
54439 + {
54440 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54441 + return;
54442 + }
54443 +
54444 + pAd->BulkOutPending[BulkOutPipeId] = TRUE;
54445 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
54446 +
54447 + // Increase Total transmit byte counter
54448 + pAd->RalinkCounters.OneSecTransmittedByteCount += pNullContext->BulkOutSize;
54449 + pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
54450 +
54451 + // Clear ATE frame bulk out flag
54452 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
54453 +
54454 + // Init Tx context descriptor
54455 + pNullContext->IRPPending = TRUE;
54456 + RTUSBInitTxDesc(pAd, pNullContext, BulkOutPipeId, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
54457 + pUrb = pNullContext->pUrb;
54458 +
54459 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
54460 + {
54461 + ATEDBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
54462 + return;
54463 + }
54464 +
54465 + pAd->BulkOutReq++;
54466 + return;
54467 +
54468 +}
54469 +
54470 +/*
54471 + ========================================================================
54472 +
54473 + Routine Description:
54474 +
54475 + Arguments:
54476 +
54477 + Return Value:
54478 +
54479 + Note:
54480 +
54481 + ========================================================================
54482 +*/
54483 +VOID ATE_RTUSBCancelPendingBulkInIRP(
54484 + IN PRTMP_ADAPTER pAd)
54485 +{
54486 + PRX_CONTEXT pRxContext;
54487 + UINT i;
54488 +
54489 + ATEDBGPRINT(RT_DEBUG_TRACE, ("--->ATE_RTUSBCancelPendingBulkInIRP\n"));
54490 +#if 1
54491 + for ( i = 0; i < (RX_RING_SIZE); i++)
54492 + {
54493 + pRxContext = &(pAd->RxContext[i]);
54494 + if(pRxContext->IRPPending == TRUE)
54495 + {
54496 + RTUSB_UNLINK_URB(pRxContext->pUrb);
54497 + pRxContext->IRPPending = FALSE;
54498 + pRxContext->InUse = FALSE;
54499 + //NdisInterlockedDecrement(&pAd->PendingRx);
54500 + //pAd->PendingRx--;
54501 + }
54502 + }
54503 +#else
54504 + for ( i = 0; i < (RX_RING_SIZE); i++)
54505 + {
54506 + pRxContext = &(pAd->RxContext[i]);
54507 + if(atomic_read(&pRxContext->IrpLock) == IRPLOCK_CANCELABLE)
54508 + {
54509 + RTUSB_UNLINK_URB(pRxContext->pUrb);
54510 + }
54511 + InterlockedExchange(&pRxContext->IrpLock, IRPLOCK_CANCE_START);
54512 + }
54513 +#endif // 1 //
54514 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<---ATE_RTUSBCancelPendingBulkInIRP\n"));
54515 + return;
54516 +}
54517 +#endif // RT2870 //
54518 +
54519 +VOID rt_ee_read_all(PRTMP_ADAPTER pAd, USHORT *Data)
54520 +{
54521 + USHORT i;
54522 + USHORT value;
54523 +
54524 + for (i = 0 ; i < EEPROM_SIZE/2 ; )
54525 + {
54526 + /* "value" is expecially for some compilers... */
54527 + RT28xx_EEPROM_READ16(pAd, i*2, value);
54528 + Data[i] = value;
54529 + i++;
54530 + }
54531 +}
54532 +
54533 +VOID rt_ee_write_all(PRTMP_ADAPTER pAd, USHORT *Data)
54534 +{
54535 + USHORT i;
54536 + USHORT value;
54537 +
54538 + for (i = 0 ; i < EEPROM_SIZE/2 ; )
54539 + {
54540 + /* "value" is expecially for some compilers... */
54541 + value = Data[i];
54542 + RT28xx_EEPROM_WRITE16(pAd, i*2, value);
54543 + i ++;
54544 + }
54545 +}
54546 +#ifdef RALINK_28xx_QA
54547 +VOID ATE_QA_Statistics(
54548 + IN PRTMP_ADAPTER pAd,
54549 + IN PRXWI_STRUC pRxWI,
54550 + IN PRT28XX_RXD_STRUC pRxD,
54551 + IN PHEADER_802_11 pHeader)
54552 +{
54553 + // update counter first
54554 + if (pHeader != NULL)
54555 + {
54556 + if (pHeader->FC.Type == BTYPE_DATA)
54557 + {
54558 + if (pRxD->U2M)
54559 + pAd->ate.U2M++;
54560 + else
54561 + pAd->ate.OtherData++;
54562 + }
54563 + else if (pHeader->FC.Type == BTYPE_MGMT)
54564 + {
54565 + if (pHeader->FC.SubType == SUBTYPE_BEACON)
54566 + pAd->ate.Beacon++;
54567 + else
54568 + pAd->ate.OtherCount++;
54569 + }
54570 + else if (pHeader->FC.Type == BTYPE_CNTL)
54571 + {
54572 + pAd->ate.OtherCount++;
54573 + }
54574 + }
54575 + pAd->ate.RSSI0 = pRxWI->RSSI0;
54576 + pAd->ate.RSSI1 = pRxWI->RSSI1;
54577 + pAd->ate.RSSI2 = pRxWI->RSSI2;
54578 + pAd->ate.SNR0 = pRxWI->SNR0;
54579 + pAd->ate.SNR1 = pRxWI->SNR1;
54580 +}
54581 +
54582 +/* command id with Cmd Type == 0x0008(for 28xx)/0x0005(for iNIC) */
54583 +#define RACFG_CMD_RF_WRITE_ALL 0x0000
54584 +#define RACFG_CMD_E2PROM_READ16 0x0001
54585 +#define RACFG_CMD_E2PROM_WRITE16 0x0002
54586 +#define RACFG_CMD_E2PROM_READ_ALL 0x0003
54587 +#define RACFG_CMD_E2PROM_WRITE_ALL 0x0004
54588 +#define RACFG_CMD_IO_READ 0x0005
54589 +#define RACFG_CMD_IO_WRITE 0x0006
54590 +#define RACFG_CMD_IO_READ_BULK 0x0007
54591 +#define RACFG_CMD_BBP_READ8 0x0008
54592 +#define RACFG_CMD_BBP_WRITE8 0x0009
54593 +#define RACFG_CMD_BBP_READ_ALL 0x000a
54594 +#define RACFG_CMD_GET_COUNTER 0x000b
54595 +#define RACFG_CMD_CLEAR_COUNTER 0x000c
54596 +
54597 +#define RACFG_CMD_RSV1 0x000d
54598 +#define RACFG_CMD_RSV2 0x000e
54599 +#define RACFG_CMD_RSV3 0x000f
54600 +
54601 +#define RACFG_CMD_TX_START 0x0010
54602 +#define RACFG_CMD_GET_TX_STATUS 0x0011
54603 +#define RACFG_CMD_TX_STOP 0x0012
54604 +#define RACFG_CMD_RX_START 0x0013
54605 +#define RACFG_CMD_RX_STOP 0x0014
54606 +#define RACFG_CMD_GET_NOISE_LEVEL 0x0015
54607 +
54608 +#define RACFG_CMD_ATE_START 0x0080
54609 +#define RACFG_CMD_ATE_STOP 0x0081
54610 +
54611 +#define RACFG_CMD_ATE_START_TX_CARRIER 0x0100
54612 +#define RACFG_CMD_ATE_START_TX_CONT 0x0101
54613 +#define RACFG_CMD_ATE_START_TX_FRAME 0x0102
54614 +#define RACFG_CMD_ATE_SET_BW 0x0103
54615 +#define RACFG_CMD_ATE_SET_TX_POWER0 0x0104
54616 +#define RACFG_CMD_ATE_SET_TX_POWER1 0x0105
54617 +#define RACFG_CMD_ATE_SET_FREQ_OFFSET 0x0106
54618 +#define RACFG_CMD_ATE_GET_STATISTICS 0x0107
54619 +#define RACFG_CMD_ATE_RESET_COUNTER 0x0108
54620 +#define RACFG_CMD_ATE_SEL_TX_ANTENNA 0x0109
54621 +#define RACFG_CMD_ATE_SEL_RX_ANTENNA 0x010a
54622 +#define RACFG_CMD_ATE_SET_PREAMBLE 0x010b
54623 +#define RACFG_CMD_ATE_SET_CHANNEL 0x010c
54624 +#define RACFG_CMD_ATE_SET_ADDR1 0x010d
54625 +#define RACFG_CMD_ATE_SET_ADDR2 0x010e
54626 +#define RACFG_CMD_ATE_SET_ADDR3 0x010f
54627 +#define RACFG_CMD_ATE_SET_RATE 0x0110
54628 +#define RACFG_CMD_ATE_SET_TX_FRAME_LEN 0x0111
54629 +#define RACFG_CMD_ATE_SET_TX_FRAME_COUNT 0x0112
54630 +#define RACFG_CMD_ATE_START_RX_FRAME 0x0113
54631 +#define RACFG_CMD_ATE_E2PROM_READ_BULK 0x0114
54632 +#define RACFG_CMD_ATE_E2PROM_WRITE_BULK 0x0115
54633 +#define RACFG_CMD_ATE_IO_WRITE_BULK 0x0116
54634 +#define RACFG_CMD_ATE_BBP_READ_BULK 0x0117
54635 +#define RACFG_CMD_ATE_BBP_WRITE_BULK 0x0118
54636 +#define RACFG_CMD_ATE_RF_READ_BULK 0x0119
54637 +#define RACFG_CMD_ATE_RF_WRITE_BULK 0x011a
54638 +
54639 +
54640 +
54641 +#define A2Hex(_X, _p) \
54642 +{ \
54643 + UCHAR *p; \
54644 + _X = 0; \
54645 + p = _p; \
54646 + while (((*p >= 'a') && (*p <= 'f')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= '0') && (*p <= '9'))) \
54647 + { \
54648 + if ((*p >= 'a') && (*p <= 'f')) \
54649 + _X = _X * 16 + *p - 87; \
54650 + else if ((*p >= 'A') && (*p <= 'F')) \
54651 + _X = _X * 16 + *p - 55; \
54652 + else if ((*p >= '0') && (*p <= '9')) \
54653 + _X = _X * 16 + *p - 48; \
54654 + p++; \
54655 + } \
54656 +}
54657 +
54658 +
54659 +static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
54660 +static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
54661 +static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len);
54662 +
54663 +#ifdef UCOS
54664 +int ate_copy_to_user(
54665 + IN PUCHAR payload,
54666 + IN PUCHAR msg,
54667 + IN INT len)
54668 +{
54669 + memmove(payload, msg, len);
54670 + return 0;
54671 +}
54672 +
54673 +#undef copy_to_user
54674 +#define copy_to_user(x,y,z) ate_copy_to_user((PUCHAR)x, (PUCHAR)y, z)
54675 +#endif // UCOS //
54676 +
54677 +#define LEN_OF_ARG 16
54678 +
54679 +VOID RtmpDoAte(
54680 + IN PRTMP_ADAPTER pAdapter,
54681 + IN struct iwreq *wrq)
54682 +{
54683 + unsigned short Command_Id;
54684 + struct ate_racfghdr *pRaCfg;
54685 + INT Status = NDIS_STATUS_SUCCESS;
54686 +
54687 +
54688 +
54689 + if((pRaCfg = kmalloc(sizeof(struct ate_racfghdr), GFP_KERNEL)) == NULL)
54690 + {
54691 + Status = -EINVAL;
54692 + return;
54693 + }
54694 +
54695 + NdisZeroMemory(pRaCfg, sizeof(struct ate_racfghdr));
54696 +
54697 + if (copy_from_user((PUCHAR)pRaCfg, wrq->u.data.pointer, wrq->u.data.length))
54698 + {
54699 + Status = -EFAULT;
54700 + kfree(pRaCfg);
54701 + return;
54702 + }
54703 +
54704 +
54705 + Command_Id = ntohs(pRaCfg->command_id);
54706 +
54707 + ATEDBGPRINT(RT_DEBUG_TRACE,("\n%s: Command_Id = 0x%04x !\n", __FUNCTION__, Command_Id));
54708 +
54709 + switch (Command_Id)
54710 + {
54711 + // We will get this command when QA starts.
54712 + case RACFG_CMD_ATE_START:
54713 + {
54714 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START\n"));
54715 +
54716 + // prepare feedback as soon as we can to avoid QA timeout.
54717 + pRaCfg->length = htons(2);
54718 + pRaCfg->status = htons(0);
54719 +
54720 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54721 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54722 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54723 +
54724 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
54725 +
54726 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54727 + {
54728 + ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_ATE_START\n"));
54729 + Status = -EFAULT;
54730 + }
54731 + else
54732 + {
54733 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START is done !\n"));
54734 + }
54735 + Set_ATE_Proc(pAdapter, "ATESTART");
54736 + }
54737 + break;
54738 +
54739 + // We will get this command either QA is closed or ated is killed by user.
54740 + case RACFG_CMD_ATE_STOP:
54741 + {
54742 +#ifndef UCOS
54743 + INT32 ret;
54744 +#endif // !UCOS //
54745 +
54746 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_STOP\n"));
54747 +
54748 + // Distinguish this command came from QA(via ated)
54749 + // or ate daemon according to the existence of pid in payload.
54750 + // No need to prepare feedback if this cmd came directly from ate daemon.
54751 + pRaCfg->length = ntohs(pRaCfg->length);
54752 +
54753 + if (pRaCfg->length == sizeof(pAdapter->ate.AtePid))
54754 + {
54755 + // This command came from QA.
54756 + // Get the pid of ATE daemon.
54757 + memcpy((UCHAR *)&pAdapter->ate.AtePid,
54758 + (&pRaCfg->data[0]) - 2/* == &(pRaCfg->status) */,
54759 + sizeof(pAdapter->ate.AtePid));
54760 +
54761 + // prepare feedback as soon as we can to avoid QA timeout.
54762 + pRaCfg->length = htons(2);
54763 + pRaCfg->status = htons(0);
54764 +
54765 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54766 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54767 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54768 +
54769 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
54770 +
54771 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54772 + {
54773 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_STOP\n"));
54774 + Status = -EFAULT;
54775 + }
54776 +
54777 + //
54778 + // kill ATE daemon when leaving ATE mode.
54779 + // We must kill ATE daemon first before setting ATESTOP,
54780 + // or Microsoft will report sth. wrong.
54781 +#ifndef UCOS
54782 + ret = KILL_THREAD_PID(pAdapter->ate.AtePid, SIGTERM, 1);
54783 + if (ret)
54784 + {
54785 + ATEDBGPRINT(RT_DEBUG_ERROR, ("%s: unable to signal thread\n", pAdapter->net_dev->name));
54786 + }
54787 +#endif // !UCOS //
54788 + }
54789 +
54790 + // AP might have in ATE_STOP mode due to cmd from QA.
54791 + if (ATE_ON(pAdapter))
54792 + {
54793 + // Someone has killed ate daemon while QA GUI is still open.
54794 + Set_ATE_Proc(pAdapter, "ATESTOP");
54795 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_AP_START is done !\n"));
54796 + }
54797 + }
54798 + break;
54799 +
54800 + case RACFG_CMD_RF_WRITE_ALL:
54801 + {
54802 + UINT32 R1, R2, R3, R4;
54803 + USHORT channel;
54804 +
54805 + memcpy(&R1, pRaCfg->data-2, 4);
54806 + memcpy(&R2, pRaCfg->data+2, 4);
54807 + memcpy(&R3, pRaCfg->data+6, 4);
54808 + memcpy(&R4, pRaCfg->data+10, 4);
54809 + memcpy(&channel, pRaCfg->data+14, 2);
54810 +
54811 + pAdapter->LatchRfRegs.R1 = ntohl(R1);
54812 + pAdapter->LatchRfRegs.R2 = ntohl(R2);
54813 + pAdapter->LatchRfRegs.R3 = ntohl(R3);
54814 + pAdapter->LatchRfRegs.R4 = ntohl(R4);
54815 + pAdapter->LatchRfRegs.Channel = ntohs(channel);
54816 +
54817 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R1);
54818 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R2);
54819 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R3);
54820 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R4);
54821 +
54822 + // prepare feedback
54823 + pRaCfg->length = htons(2);
54824 + pRaCfg->status = htons(0);
54825 +
54826 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54827 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54828 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54829 +
54830 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
54831 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54832 + {
54833 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RF_WRITE_ALL\n"));
54834 + Status = -EFAULT;
54835 + }
54836 + else
54837 + {
54838 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RF_WRITE_ALL is done !\n"));
54839 + }
54840 + }
54841 + break;
54842 +
54843 + case RACFG_CMD_E2PROM_READ16:
54844 + {
54845 + USHORT offset, value, tmp;
54846 +
54847 + offset = ntohs(pRaCfg->status);
54848 + /* "tmp" is expecially for some compilers... */
54849 + RT28xx_EEPROM_READ16(pAdapter, offset, tmp);
54850 + value = tmp;
54851 + value = htons(value);
54852 +
54853 + ATEDBGPRINT(RT_DEBUG_TRACE,("EEPROM Read offset = 0x%04x, value = 0x%04x\n", offset, value));
54854 +
54855 + // prepare feedback
54856 + pRaCfg->length = htons(4);
54857 + pRaCfg->status = htons(0);
54858 + memcpy(pRaCfg->data, &value, 2);
54859 +
54860 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54861 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54862 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54863 +
54864 + ATEDBGPRINT(RT_DEBUG_TRACE, ("sizeof(struct ate_racfghdr) = %d\n", sizeof(struct ate_racfghdr)));
54865 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
54866 +
54867 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54868 + {
54869 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ16\n"));
54870 + Status = -EFAULT;
54871 + }
54872 + else
54873 + {
54874 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ16 is done !\n"));
54875 + }
54876 + }
54877 + break;
54878 +
54879 + case RACFG_CMD_E2PROM_WRITE16:
54880 + {
54881 + USHORT offset, value;
54882 +
54883 + offset = ntohs(pRaCfg->status);
54884 + memcpy(&value, pRaCfg->data, 2);
54885 + value = ntohs(value);
54886 + RT28xx_EEPROM_WRITE16(pAdapter, offset, value);
54887 +
54888 + // prepare feedback
54889 + pRaCfg->length = htons(2);
54890 + pRaCfg->status = htons(0);
54891 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54892 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54893 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54894 +
54895 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54896 + {
54897 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE16\n"));
54898 + Status = -EFAULT;
54899 + }
54900 + else
54901 + {
54902 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_WRITE16 is done !\n"));
54903 + }
54904 + }
54905 + break;
54906 +
54907 + case RACFG_CMD_E2PROM_READ_ALL:
54908 + {
54909 + USHORT buffer[EEPROM_SIZE/2];
54910 +
54911 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
54912 + memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer, EEPROM_SIZE);
54913 +
54914 + // prepare feedback
54915 + pRaCfg->length = htons(2+EEPROM_SIZE);
54916 + pRaCfg->status = htons(0);
54917 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54918 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54919 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54920 +
54921 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54922 + {
54923 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ_ALL\n"));
54924 + Status = -EFAULT;
54925 + }
54926 + else
54927 + {
54928 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ_ALL is done !\n"));
54929 + }
54930 + }
54931 + break;
54932 +
54933 + case RACFG_CMD_E2PROM_WRITE_ALL:
54934 + {
54935 + USHORT buffer[EEPROM_SIZE/2];
54936 +
54937 + NdisZeroMemory((UCHAR *)buffer, EEPROM_SIZE);
54938 + memcpy_exs(pAdapter, (UCHAR *)buffer, (UCHAR *)&pRaCfg->status, EEPROM_SIZE);
54939 + rt_ee_write_all(pAdapter,(USHORT *)buffer);
54940 +
54941 + // prepare feedback
54942 + pRaCfg->length = htons(2);
54943 + pRaCfg->status = htons(0);
54944 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54945 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54946 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54947 +
54948 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54949 + {
54950 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE_ALL\n"));
54951 + Status = -EFAULT;
54952 + }
54953 + else
54954 + {
54955 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_E2PROM_WRITE_ALL is done !\n"));
54956 + }
54957 +
54958 + }
54959 + break;
54960 +
54961 + case RACFG_CMD_IO_READ:
54962 + {
54963 + UINT32 offset;
54964 + UINT32 value;
54965 +
54966 + memcpy(&offset, &pRaCfg->status, 4);
54967 + offset = ntohl(offset);
54968 +
54969 + // We do not need the base address.
54970 + // So just extract the offset out.
54971 + offset &= 0x0000FFFF;
54972 + RTMP_IO_READ32(pAdapter, offset, &value);
54973 + value = htonl(value);
54974 +
54975 + // prepare feedback
54976 + pRaCfg->length = htons(6);
54977 + pRaCfg->status = htons(0);
54978 + memcpy(pRaCfg->data, &value, 4);
54979 +
54980 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
54981 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
54982 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
54983 +
54984 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
54985 + {
54986 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ\n"));
54987 + Status = -EFAULT;
54988 + }
54989 + else
54990 + {
54991 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ is done !\n"));
54992 + }
54993 + }
54994 + break;
54995 +
54996 + case RACFG_CMD_IO_WRITE:
54997 + {
54998 + UINT32 offset, value;
54999 +
55000 + memcpy(&offset, pRaCfg->data-2, 4);
55001 + memcpy(&value, pRaCfg->data+2, 4);
55002 +
55003 + offset = ntohl(offset);
55004 +
55005 + // We do not need the base address.
55006 + // So just extract out the offset.
55007 + offset &= 0x0000FFFF;
55008 + value = ntohl(value);
55009 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_IO_WRITE: offset = %x, value = %x\n", offset, value));
55010 + RTMP_IO_WRITE32(pAdapter, offset, value);
55011 +
55012 + // prepare feedback
55013 + pRaCfg->length = htons(2);
55014 + pRaCfg->status = htons(0);
55015 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55016 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55017 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55018 +
55019 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55020 + {
55021 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_WRITE\n"));
55022 + Status = -EFAULT;
55023 + }
55024 + else
55025 + {
55026 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_WRITE is done !\n"));
55027 + }
55028 + }
55029 + break;
55030 +
55031 + case RACFG_CMD_IO_READ_BULK:
55032 + {
55033 + UINT32 offset;
55034 + USHORT len;
55035 +
55036 + memcpy(&offset, &pRaCfg->status, 4);
55037 + offset = ntohl(offset);
55038 +
55039 + // We do not need the base address.
55040 + // So just extract the offset.
55041 + offset &= 0x0000FFFF;
55042 + memcpy(&len, pRaCfg->data+2, 2);
55043 + len = ntohs(len);
55044 +
55045 + if (len > 371)
55046 + {
55047 + ATEDBGPRINT(RT_DEBUG_TRACE,("len is too large, make it smaller\n"));
55048 + pRaCfg->length = htons(2);
55049 + pRaCfg->status = htons(1);
55050 + break;
55051 + }
55052 +
55053 + RTMP_IO_READ_BULK(pAdapter, pRaCfg->data, (UCHAR *)offset, len*4);// unit in four bytes
55054 +
55055 + // prepare feedback
55056 + pRaCfg->length = htons(2+len*4);// unit in four bytes
55057 + pRaCfg->status = htons(0);
55058 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55059 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55060 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55061 +
55062 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55063 + {
55064 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ_BULK\n"));
55065 + Status = -EFAULT;
55066 + }
55067 + else
55068 + {
55069 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ_BULK is done !\n"));
55070 + }
55071 + }
55072 + break;
55073 +
55074 + case RACFG_CMD_BBP_READ8:
55075 + {
55076 + USHORT offset;
55077 + UCHAR value;
55078 +
55079 + value = 0;
55080 + offset = ntohs(pRaCfg->status);
55081 +
55082 + if (ATE_ON(pAdapter))
55083 + {
55084 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
55085 + }
55086 + else
55087 + {
55088 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
55089 + }
55090 + // prepare feedback
55091 + pRaCfg->length = htons(3);
55092 + pRaCfg->status = htons(0);
55093 + pRaCfg->data[0] = value;
55094 +
55095 + ATEDBGPRINT(RT_DEBUG_TRACE,("BBP value = %x\n", value));
55096 +
55097 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55098 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55099 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55100 +
55101 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55102 + {
55103 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ8\n"));
55104 + Status = -EFAULT;
55105 + }
55106 + else
55107 + {
55108 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ8 is done !\n"));
55109 + }
55110 + }
55111 + break;
55112 + case RACFG_CMD_BBP_WRITE8:
55113 + {
55114 + USHORT offset;
55115 + UCHAR value;
55116 +
55117 + offset = ntohs(pRaCfg->status);
55118 + memcpy(&value, pRaCfg->data, 1);
55119 +
55120 + if (ATE_ON(pAdapter))
55121 + {
55122 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
55123 + }
55124 + else
55125 + {
55126 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
55127 + }
55128 +
55129 + if ((offset == BBP_R1) || (offset == BBP_R3))
55130 + {
55131 + SyncTxRxConfig(pAdapter, offset, value);
55132 + }
55133 +
55134 + // prepare feedback
55135 + pRaCfg->length = htons(2);
55136 + pRaCfg->status = htons(0);
55137 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55138 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55139 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55140 +
55141 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55142 + {
55143 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_WRITE8\n"));
55144 + Status = -EFAULT;
55145 + }
55146 + else
55147 + {
55148 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_WRITE8 is done !\n"));
55149 + }
55150 + }
55151 + break;
55152 +
55153 + case RACFG_CMD_BBP_READ_ALL:
55154 + {
55155 + USHORT j;
55156 +
55157 + for (j = 0; j < 137; j++)
55158 + {
55159 + pRaCfg->data[j] = 0;
55160 +
55161 + if (ATE_ON(pAdapter))
55162 + {
55163 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
55164 + }
55165 + else
55166 + {
55167 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
55168 + }
55169 + }
55170 +
55171 + // prepare feedback
55172 + pRaCfg->length = htons(2+137);
55173 + pRaCfg->status = htons(0);
55174 +
55175 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55176 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55177 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55178 +
55179 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55180 + {
55181 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ_ALL\n"));
55182 + Status = -EFAULT;
55183 + }
55184 + else
55185 + {
55186 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ_ALL is done !\n"));
55187 + }
55188 + }
55189 +
55190 + break;
55191 +
55192 + case RACFG_CMD_ATE_E2PROM_READ_BULK:
55193 + {
55194 + USHORT offset;
55195 + USHORT len;
55196 + USHORT buffer[EEPROM_SIZE/2];
55197 +
55198 + offset = ntohs(pRaCfg->status);
55199 + memcpy(&len, pRaCfg->data, 2);
55200 + len = ntohs(len);
55201 +
55202 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
55203 + if (offset + len <= EEPROM_SIZE)
55204 + memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer+offset, len);
55205 + else
55206 + ATEDBGPRINT(RT_DEBUG_ERROR, ("exceed EEPROM size\n"));
55207 +
55208 + // prepare feedback
55209 + pRaCfg->length = htons(2+len);
55210 + pRaCfg->status = htons(0);
55211 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55212 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55213 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55214 +
55215 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55216 + {
55217 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_READ_BULK\n"));
55218 + Status = -EFAULT;
55219 + }
55220 + else
55221 + {
55222 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_E2PROM_READ_BULK is done !\n"));
55223 + }
55224 +
55225 + }
55226 + break;
55227 +
55228 + case RACFG_CMD_ATE_E2PROM_WRITE_BULK:
55229 + {
55230 + USHORT offset;
55231 + USHORT len;
55232 + USHORT buffer[EEPROM_SIZE/2];
55233 +
55234 + offset = ntohs(pRaCfg->status);
55235 + memcpy(&len, pRaCfg->data, 2);
55236 + len = ntohs(len);
55237 +
55238 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
55239 + memcpy_exs(pAdapter, (UCHAR *)buffer + offset, (UCHAR *)pRaCfg->data + 2, len);
55240 + rt_ee_write_all(pAdapter,(USHORT *)buffer);
55241 +
55242 + // prepare feedback
55243 + pRaCfg->length = htons(2);
55244 + pRaCfg->status = htons(0);
55245 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55246 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55247 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55248 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55249 + {
55250 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_WRITE_BULK\n"));
55251 + Status = -EFAULT;
55252 + }
55253 + else
55254 + {
55255 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_E2PROM_WRITE_BULK is done !\n"));
55256 + }
55257 +
55258 + }
55259 + break;
55260 +
55261 + case RACFG_CMD_ATE_IO_WRITE_BULK:
55262 + {
55263 + UINT32 offset, i, value;
55264 + USHORT len;
55265 +
55266 + memcpy(&offset, &pRaCfg->status, 4);
55267 + offset = ntohl(offset);
55268 + memcpy(&len, pRaCfg->data+2, 2);
55269 + len = ntohs(len);
55270 +
55271 + for (i = 0; i < len; i += 4)
55272 + {
55273 + memcpy_exl(pAdapter, (UCHAR *)&value, pRaCfg->data+4+i, 4);
55274 + printk("Write %x %x\n", offset + i, value);
55275 + RTMP_IO_WRITE32(pAdapter, (offset +i) & 0xffff, value);
55276 + }
55277 +
55278 + // prepare feedback
55279 + pRaCfg->length = htons(2);
55280 + pRaCfg->status = htons(0);
55281 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55282 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55283 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55284 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55285 + {
55286 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_IO_WRITE_BULK\n"));
55287 + Status = -EFAULT;
55288 + }
55289 + else
55290 + {
55291 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_IO_WRITE_BULK is done !\n"));
55292 + }
55293 +
55294 + }
55295 + break;
55296 +
55297 + case RACFG_CMD_ATE_BBP_READ_BULK:
55298 + {
55299 + USHORT offset;
55300 + USHORT len;
55301 + USHORT j;
55302 +
55303 + offset = ntohs(pRaCfg->status);
55304 + memcpy(&len, pRaCfg->data, 2);
55305 + len = ntohs(len);
55306 +
55307 +
55308 + for (j = offset; j < (offset+len); j++)
55309 + {
55310 + pRaCfg->data[j - offset] = 0;
55311 +
55312 + if (pAdapter->ate.Mode == ATE_STOP)
55313 + {
55314 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
55315 + }
55316 + else
55317 + {
55318 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
55319 + }
55320 + }
55321 +
55322 + // prepare feedback
55323 + pRaCfg->length = htons(2+len);
55324 + pRaCfg->status = htons(0);
55325 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55326 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55327 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55328 +
55329 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55330 + {
55331 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_READ_BULK\n"));
55332 + Status = -EFAULT;
55333 + }
55334 + else
55335 + {
55336 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_READ_BULK is done !\n"));
55337 + }
55338 +
55339 + }
55340 + break;
55341 +
55342 + case RACFG_CMD_ATE_BBP_WRITE_BULK:
55343 + {
55344 + USHORT offset;
55345 + USHORT len;
55346 + USHORT j;
55347 + UCHAR *value;
55348 +
55349 + offset = ntohs(pRaCfg->status);
55350 + memcpy(&len, pRaCfg->data, 2);
55351 + len = ntohs(len);
55352 +
55353 + for (j = offset; j < (offset+len); j++)
55354 + {
55355 + value = pRaCfg->data + 2 + (j - offset);
55356 + if (pAdapter->ate.Mode == ATE_STOP)
55357 + {
55358 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
55359 + }
55360 + else
55361 + {
55362 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
55363 + }
55364 + }
55365 +
55366 + // prepare feedback
55367 + pRaCfg->length = htons(2);
55368 + pRaCfg->status = htons(0);
55369 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55370 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55371 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55372 +
55373 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55374 + {
55375 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_WRITE_BULK\n"));
55376 + Status = -EFAULT;
55377 + }
55378 + else
55379 + {
55380 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_WRITE_BULK is done !\n"));
55381 + }
55382 + }
55383 + break;
55384 +
55385 +#ifdef CONFIG_RALINK_RT3052
55386 + case RACFG_CMD_ATE_RF_READ_BULK:
55387 + {
55388 + USHORT offset;
55389 + USHORT len;
55390 + USHORT j;
55391 +
55392 + offset = ntohs(pRaCfg->status);
55393 + memcpy(&len, pRaCfg->data, 2);
55394 + len = ntohs(len);
55395 +
55396 + for (j = offset; j < (offset+len); j++)
55397 + {
55398 + pRaCfg->data[j - offset] = 0;
55399 + RT30xxReadRFRegister(pAdapter, j, &pRaCfg->data[j - offset]);
55400 + }
55401 +
55402 + // prepare feedback
55403 + pRaCfg->length = htons(2+len);
55404 + pRaCfg->status = htons(0);
55405 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55406 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55407 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55408 +
55409 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55410 + {
55411 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_READ_BULK\n"));
55412 + Status = -EFAULT;
55413 + }
55414 + else
55415 + {
55416 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_READ_BULK is done !\n"));
55417 + }
55418 +
55419 + }
55420 + break;
55421 +
55422 + case RACFG_CMD_ATE_RF_WRITE_BULK:
55423 + {
55424 + USHORT offset;
55425 + USHORT len;
55426 + USHORT j;
55427 + UCHAR *value;
55428 +
55429 + offset = ntohs(pRaCfg->status);
55430 + memcpy(&len, pRaCfg->data, 2);
55431 + len = ntohs(len);
55432 +
55433 + for (j = offset; j < (offset+len); j++)
55434 + {
55435 + value = pRaCfg->data + 2 + (j - offset);
55436 + RT30xxWriteRFRegister(pAdapter, j, *value);
55437 + }
55438 +
55439 + // prepare feedback
55440 + pRaCfg->length = htons(2);
55441 + pRaCfg->status = htons(0);
55442 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55443 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55444 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55445 +
55446 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55447 + {
55448 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_WRITE_BULK\n"));
55449 + Status = -EFAULT;
55450 + }
55451 + else
55452 + {
55453 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_WRITE_BULK is done !\n"));
55454 + }
55455 +
55456 + }
55457 + break;
55458 +#endif
55459 +
55460 +
55461 + case RACFG_CMD_GET_NOISE_LEVEL:
55462 + {
55463 + UCHAR channel;
55464 + INT32 buffer[3][10];/* 3 : RxPath ; 10 : no. of per rssi samples */
55465 +
55466 + channel = (ntohs(pRaCfg->status) & 0x00FF);
55467 + CalNoiseLevel(pAdapter, channel, buffer);
55468 + memcpy_exl(pAdapter, (UCHAR *)pRaCfg->data, (UCHAR *)&(buffer[0][0]), (sizeof(INT32)*3*10));
55469 +
55470 + // prepare feedback
55471 + pRaCfg->length = htons(2 + (sizeof(INT32)*3*10));
55472 + pRaCfg->status = htons(0);
55473 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55474 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55475 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55476 +
55477 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55478 + {
55479 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_NOISE_LEVEL\n"));
55480 + Status = -EFAULT;
55481 + }
55482 + else
55483 + {
55484 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_NOISE_LEVEL is done !\n"));
55485 + }
55486 + }
55487 + break;
55488 +
55489 + case RACFG_CMD_GET_COUNTER:
55490 + {
55491 + memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.U2M, 4);
55492 + memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->ate.OtherData, 4);
55493 + memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->ate.Beacon, 4);
55494 + memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->ate.OtherCount, 4);
55495 + memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->ate.TxAc0, 4);
55496 + memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->ate.TxAc1, 4);
55497 + memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->ate.TxAc2, 4);
55498 + memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->ate.TxAc3, 4);
55499 + memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->ate.TxHCCA, 4);
55500 + memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->ate.TxMgmt, 4);
55501 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&pAdapter->ate.RSSI0, 4);
55502 + memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&pAdapter->ate.RSSI1, 4);
55503 + memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&pAdapter->ate.RSSI2, 4);
55504 + memcpy_exl(pAdapter, &pRaCfg->data[52], (UCHAR *)&pAdapter->ate.SNR0, 4);
55505 + memcpy_exl(pAdapter, &pRaCfg->data[56], (UCHAR *)&pAdapter->ate.SNR1, 4);
55506 +
55507 + pRaCfg->length = htons(2+60);
55508 + pRaCfg->status = htons(0);
55509 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55510 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55511 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55512 +
55513 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55514 + {
55515 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_COUNTER\n"));
55516 + Status = -EFAULT;
55517 + }
55518 + else
55519 + {
55520 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_COUNTER is done !\n"));
55521 + }
55522 + }
55523 + break;
55524 +
55525 + case RACFG_CMD_CLEAR_COUNTER:
55526 + {
55527 + pAdapter->ate.U2M = 0;
55528 + pAdapter->ate.OtherData = 0;
55529 + pAdapter->ate.Beacon = 0;
55530 + pAdapter->ate.OtherCount = 0;
55531 + pAdapter->ate.TxAc0 = 0;
55532 + pAdapter->ate.TxAc1 = 0;
55533 + pAdapter->ate.TxAc2 = 0;
55534 + pAdapter->ate.TxAc3 = 0;
55535 + pAdapter->ate.TxHCCA = 0;
55536 + pAdapter->ate.TxMgmt = 0;
55537 + pAdapter->ate.TxDoneCount = 0;
55538 +
55539 + pRaCfg->length = htons(2);
55540 + pRaCfg->status = htons(0);
55541 +
55542 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55543 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55544 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55545 +
55546 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55547 + {
55548 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_CLEAR_COUNTER\n"));
55549 + Status = -EFAULT;
55550 + }
55551 + else
55552 + {
55553 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_CLEAR_COUNTER is done !\n"));
55554 + }
55555 + }
55556 +
55557 + break;
55558 +
55559 + case RACFG_CMD_TX_START:
55560 + {
55561 + USHORT *p;
55562 + USHORT err = 1;
55563 + UCHAR Bbp22Value = 0, Bbp24Value = 0;
55564 +
55565 + if ((pAdapter->ate.TxStatus != 0) && (pAdapter->ate.Mode & ATE_TXFRAME))
55566 + {
55567 + ATEDBGPRINT(RT_DEBUG_TRACE,("Ate Tx is already running, to run next Tx, you must stop it first\n"));
55568 + err = 2;
55569 + goto TX_START_ERROR;
55570 + }
55571 + else if ((pAdapter->ate.TxStatus != 0) && !(pAdapter->ate.Mode & ATE_TXFRAME))
55572 + {
55573 + int i = 0;
55574 +
55575 + while ((i++ < 10) && (pAdapter->ate.TxStatus != 0))
55576 + {
55577 + RTMPusecDelay(5000);
55578 + }
55579 +
55580 + // force it to stop
55581 + pAdapter->ate.TxStatus = 0;
55582 + pAdapter->ate.TxDoneCount = 0;
55583 + //pAdapter->ate.Repeat = 0;
55584 + pAdapter->ate.bQATxStart = FALSE;
55585 + }
55586 +
55587 + // If pRaCfg->length == 0, this "RACFG_CMD_TX_START" is for Carrier test or Carrier Suppression.
55588 + if (ntohs(pRaCfg->length) != 0)
55589 + {
55590 + // Get frame info
55591 +#ifdef RT2870
55592 + NdisMoveMemory(&pAdapter->ate.TxInfo, pRaCfg->data - 2, 4);
55593 +#ifdef RT_BIG_ENDIAN
55594 + RTMPDescriptorEndianChange((PUCHAR) &pAdapter->ate.TxInfo, TYPE_TXINFO);
55595 +#endif // RT_BIG_ENDIAN //
55596 +#endif // RT2870 //
55597 +
55598 + NdisMoveMemory(&pAdapter->ate.TxWI, pRaCfg->data + 2, 16);
55599 +#ifdef RT_BIG_ENDIAN
55600 + RTMPWIEndianChange((PUCHAR)&pAdapter->ate.TxWI, TYPE_TXWI);
55601 +#endif // RT_BIG_ENDIAN //
55602 +
55603 + NdisMoveMemory(&pAdapter->ate.TxCount, pRaCfg->data + 18, 4);
55604 + pAdapter->ate.TxCount = ntohl(pAdapter->ate.TxCount);
55605 +
55606 + p = (USHORT *)(&pRaCfg->data[22]);
55607 + //p = pRaCfg->data + 22;
55608 + // always use QID_AC_BE
55609 + pAdapter->ate.QID = 0;
55610 + p = (USHORT *)(&pRaCfg->data[24]);
55611 + //p = pRaCfg->data + 24;
55612 + pAdapter->ate.HLen = ntohs(*p);
55613 +
55614 + if (pAdapter->ate.HLen > 32)
55615 + {
55616 + ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.HLen > 32\n"));
55617 + err = 3;
55618 + goto TX_START_ERROR;
55619 + }
55620 +
55621 + NdisMoveMemory(&pAdapter->ate.Header, pRaCfg->data + 26, pAdapter->ate.HLen);
55622 +
55623 +
55624 + pAdapter->ate.PLen = ntohs(pRaCfg->length) - (pAdapter->ate.HLen + 28);
55625 +
55626 + if (pAdapter->ate.PLen > 32)
55627 + {
55628 + ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.PLen > 32\n"));
55629 + err = 4;
55630 + goto TX_START_ERROR;
55631 + }
55632 +
55633 + NdisMoveMemory(&pAdapter->ate.Pattern, pRaCfg->data + 26 + pAdapter->ate.HLen, pAdapter->ate.PLen);
55634 + pAdapter->ate.DLen = pAdapter->ate.TxWI.MPDUtotalByteCount - pAdapter->ate.HLen;
55635 + }
55636 +
55637 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R22, &Bbp22Value);
55638 +
55639 + switch (Bbp22Value)
55640 + {
55641 + case BBP22_TXFRAME:
55642 + {
55643 + if (pAdapter->ate.TxCount == 0)
55644 + {
55645 + }
55646 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXFRAME\n"));
55647 + pAdapter->ate.bQATxStart = TRUE;
55648 + Set_ATE_Proc(pAdapter, "TXFRAME");
55649 + }
55650 + break;
55651 +
55652 + case BBP22_TXCONT_OR_CARRSUPP:
55653 + {
55654 + ATEDBGPRINT(RT_DEBUG_TRACE,("BBP22_TXCONT_OR_CARRSUPP\n"));
55655 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, 24, &Bbp24Value);
55656 +
55657 + switch (Bbp24Value)
55658 + {
55659 + case BBP24_TXCONT:
55660 + {
55661 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCONT\n"));
55662 + pAdapter->ate.bQATxStart = TRUE;
55663 + Set_ATE_Proc(pAdapter, "TXCONT");
55664 + }
55665 + break;
55666 +
55667 + case BBP24_CARRSUPP:
55668 + {
55669 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARRSUPP\n"));
55670 + pAdapter->ate.bQATxStart = TRUE;
55671 + pAdapter->ate.Mode |= ATE_TXCARRSUPP;
55672 + }
55673 + break;
55674 +
55675 + default:
55676 + {
55677 + ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
55678 + }
55679 + break;
55680 + }
55681 + }
55682 + break;
55683 +
55684 + case BBP22_TXCARR:
55685 + {
55686 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARR\n"));
55687 + pAdapter->ate.bQATxStart = TRUE;
55688 + Set_ATE_Proc(pAdapter, "TXCARR");
55689 + }
55690 + break;
55691 +
55692 + default:
55693 + {
55694 + ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
55695 + }
55696 + break;
55697 + }
55698 +
55699 + if (pAdapter->ate.bQATxStart == TRUE)
55700 + {
55701 + // prepare feedback
55702 + pRaCfg->length = htons(2);
55703 + pRaCfg->status = htons(0);
55704 +
55705 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55706 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55707 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55708 +
55709 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55710 + {
55711 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() was failed in case RACFG_CMD_TX_START\n"));
55712 + Status = -EFAULT;
55713 + }
55714 + else
55715 + {
55716 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_START is done !\n"));
55717 + }
55718 + break;
55719 + }
55720 +
55721 +TX_START_ERROR:
55722 + // prepare feedback
55723 + pRaCfg->length = htons(2);
55724 + pRaCfg->status = htons(err);
55725 +
55726 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55727 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55728 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55729 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55730 + {
55731 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_TX_START\n"));
55732 + Status = -EFAULT;
55733 + }
55734 + else
55735 + {
55736 + ATEDBGPRINT(RT_DEBUG_TRACE, ("feedback of TX_START_ERROR is done !\n"));
55737 + }
55738 + }
55739 + break;
55740 +
55741 + case RACFG_CMD_GET_TX_STATUS:
55742 + {
55743 + UINT32 count;
55744 +
55745 + // prepare feedback
55746 + pRaCfg->length = htons(6);
55747 + pRaCfg->status = htons(0);
55748 + count = htonl(pAdapter->ate.TxDoneCount);
55749 + NdisMoveMemory(pRaCfg->data, &count, 4);
55750 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55751 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55752 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55753 +
55754 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55755 + {
55756 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_TX_STATUS\n"));
55757 + Status = -EFAULT;
55758 + }
55759 + else
55760 + {
55761 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_TX_STATUS is done !\n"));
55762 + }
55763 + }
55764 + break;
55765 +
55766 + case RACFG_CMD_TX_STOP:
55767 + {
55768 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_TX_STOP\n"));
55769 +
55770 + Set_ATE_Proc(pAdapter, "TXSTOP");
55771 +
55772 + // prepare feedback
55773 + pRaCfg->length = htons(2);
55774 + pRaCfg->status = htons(0);
55775 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55776 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55777 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55778 +
55779 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55780 + {
55781 + ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_TX_STOP\n"));
55782 + Status = -EFAULT;
55783 + }
55784 + else
55785 + {
55786 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_STOP is done !\n"));
55787 + }
55788 + }
55789 + break;
55790 +
55791 + case RACFG_CMD_RX_START:
55792 + {
55793 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
55794 +
55795 + pAdapter->ate.bQARxStart = TRUE;
55796 + Set_ATE_Proc(pAdapter, "RXFRAME");
55797 +
55798 + // prepare feedback
55799 + pRaCfg->length = htons(2);
55800 + pRaCfg->status = htons(0);
55801 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55802 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55803 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55804 +
55805 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55806 + {
55807 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
55808 + Status = -EFAULT;
55809 + }
55810 + else
55811 + {
55812 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
55813 + }
55814 + }
55815 + break;
55816 +
55817 + case RACFG_CMD_RX_STOP:
55818 + {
55819 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_STOP\n"));
55820 +
55821 + Set_ATE_Proc(pAdapter, "RXSTOP");
55822 +
55823 + // prepare feedback
55824 + pRaCfg->length = htons(2);
55825 + pRaCfg->status = htons(0);
55826 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55827 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55828 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55829 +
55830 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55831 + {
55832 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_STOP\n"));
55833 + Status = -EFAULT;
55834 + }
55835 + else
55836 + {
55837 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_STOP is done !\n"));
55838 + }
55839 + }
55840 + break;
55841 +
55842 + /* The following cases are for new ATE GUI(not QA). */
55843 + /*==================================================*/
55844 + case RACFG_CMD_ATE_START_TX_CARRIER:
55845 + {
55846 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CARRIER\n"));
55847 +
55848 + Set_ATE_Proc(pAdapter, "TXCARR");
55849 +
55850 + pRaCfg->length = htons(2);
55851 + pRaCfg->status = htons(0);
55852 +
55853 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55854 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55855 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55856 +
55857 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55858 +
55859 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55860 + {
55861 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CARRIER\n"));
55862 + Status = -EFAULT;
55863 + }
55864 + else
55865 + {
55866 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CARRIER is done !\n"));
55867 + }
55868 + }
55869 + break;
55870 +
55871 + case RACFG_CMD_ATE_START_TX_CONT:
55872 + {
55873 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CONT\n"));
55874 +
55875 + Set_ATE_Proc(pAdapter, "TXCONT");
55876 +
55877 + pRaCfg->length = htons(2);
55878 + pRaCfg->status = htons(0);
55879 +
55880 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55881 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55882 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55883 +
55884 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55885 +
55886 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55887 + {
55888 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CONT\n"));
55889 + Status = -EFAULT;
55890 + }
55891 + else
55892 + {
55893 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CONT is done !\n"));
55894 + }
55895 + }
55896 + break;
55897 +
55898 + case RACFG_CMD_ATE_START_TX_FRAME:
55899 + {
55900 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_FRAME\n"));
55901 +
55902 + Set_ATE_Proc(pAdapter, "TXFRAME");
55903 +
55904 + pRaCfg->length = htons(2);
55905 + pRaCfg->status = htons(0);
55906 +
55907 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55908 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55909 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55910 +
55911 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55912 +
55913 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55914 + {
55915 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_FRAME\n"));
55916 + Status = -EFAULT;
55917 + }
55918 + else
55919 + {
55920 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_FRAME is done !\n"));
55921 + }
55922 + }
55923 + break;
55924 +
55925 + case RACFG_CMD_ATE_SET_BW:
55926 + {
55927 + SHORT value = 0;
55928 + UCHAR str[LEN_OF_ARG];
55929 +
55930 + NdisZeroMemory(str, LEN_OF_ARG);
55931 +
55932 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_BW\n"));
55933 +
55934 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
55935 + value = ntohs(value);
55936 + sprintf((PCHAR)str, "%d", value);
55937 +
55938 + Set_ATE_TX_BW_Proc(pAdapter, str);
55939 +
55940 + // prepare feedback
55941 + pRaCfg->length = htons(2);
55942 + pRaCfg->status = htons(0);
55943 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55944 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55945 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55946 +
55947 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55948 + {
55949 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_BW\n"));
55950 + Status = -EFAULT;
55951 + }
55952 + else
55953 + {
55954 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_BW is done !\n"));
55955 + }
55956 + }
55957 + break;
55958 +
55959 + case RACFG_CMD_ATE_SET_TX_POWER0:
55960 + {
55961 + SHORT value = 0;
55962 + UCHAR str[LEN_OF_ARG];
55963 +
55964 + NdisZeroMemory(str, LEN_OF_ARG);
55965 +
55966 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER0\n"));
55967 +
55968 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
55969 + value = ntohs(value);
55970 + sprintf((PCHAR)str, "%d", value);
55971 + Set_ATE_TX_POWER0_Proc(pAdapter, str);
55972 +
55973 + // prepare feedback
55974 + pRaCfg->length = htons(2);
55975 + pRaCfg->status = htons(0);
55976 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55977 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55978 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55979 +
55980 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55981 + {
55982 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER0\n"));
55983 + Status = -EFAULT;
55984 + }
55985 + else
55986 + {
55987 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER0 is done !\n"));
55988 + }
55989 + }
55990 + break;
55991 +
55992 + case RACFG_CMD_ATE_SET_TX_POWER1:
55993 + {
55994 + SHORT value = 0;
55995 + UCHAR str[LEN_OF_ARG];
55996 +
55997 + NdisZeroMemory(str, LEN_OF_ARG);
55998 +
55999 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER1\n"));
56000 +
56001 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56002 + value = ntohs(value);
56003 + sprintf((PCHAR)str, "%d", value);
56004 + Set_ATE_TX_POWER1_Proc(pAdapter, str);
56005 +
56006 + // prepare feedback
56007 + pRaCfg->length = htons(2);
56008 + pRaCfg->status = htons(0);
56009 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56010 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56011 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56012 +
56013 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56014 + {
56015 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER1\n"));
56016 + Status = -EFAULT;
56017 + }
56018 + else
56019 + {
56020 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER1 is done !\n"));
56021 + }
56022 + }
56023 + break;
56024 +
56025 + case RACFG_CMD_ATE_SET_FREQ_OFFSET:
56026 + {
56027 + SHORT value = 0;
56028 + UCHAR str[LEN_OF_ARG];
56029 +
56030 + NdisZeroMemory(str, LEN_OF_ARG);
56031 +
56032 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
56033 +
56034 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56035 + value = ntohs(value);
56036 + sprintf((PCHAR)str, "%d", value);
56037 + Set_ATE_TX_FREQOFFSET_Proc(pAdapter, str);
56038 +
56039 + // prepare feedback
56040 + pRaCfg->length = htons(2);
56041 + pRaCfg->status = htons(0);
56042 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56043 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56044 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56045 +
56046 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56047 + {
56048 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
56049 + Status = -EFAULT;
56050 + }
56051 + else
56052 + {
56053 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_FREQ_OFFSET is done !\n"));
56054 + }
56055 + }
56056 + break;
56057 +
56058 + case RACFG_CMD_ATE_GET_STATISTICS:
56059 + {
56060 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_GET_STATISTICS\n"));
56061 +
56062 + memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.TxDoneCount, 4);
56063 + memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->WlanCounters.RetryCount.u.LowPart, 4);
56064 + memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->WlanCounters.FailedCount.u.LowPart, 4);
56065 + memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->WlanCounters.RTSSuccessCount.u.LowPart, 4);
56066 + memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->WlanCounters.RTSFailureCount.u.LowPart, 4);
56067 + memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart, 4);
56068 + memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->WlanCounters.FCSErrorCount.u.LowPart, 4);
56069 + memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->Counters8023.RxNoBuffer, 4);
56070 + memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart, 4);
56071 + memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->RalinkCounters.OneSecFalseCCACnt, 4);
56072 +
56073 + if (pAdapter->ate.RxAntennaSel == 0)
56074 + {
56075 + INT32 RSSI0 = 0;
56076 + INT32 RSSI1 = 0;
56077 + INT32 RSSI2 = 0;
56078 +
56079 + RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
56080 + RSSI1 = (INT32)(pAdapter->ate.LastRssi1 - pAdapter->BbpRssiToDbmDelta);
56081 + RSSI2 = (INT32)(pAdapter->ate.LastRssi2 - pAdapter->BbpRssiToDbmDelta);
56082 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
56083 + memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&RSSI1, 4);
56084 + memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&RSSI2, 4);
56085 + pRaCfg->length = htons(2+52);
56086 + }
56087 + else
56088 + {
56089 + INT32 RSSI0 = 0;
56090 +
56091 + RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
56092 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
56093 + pRaCfg->length = htons(2+44);
56094 + }
56095 + pRaCfg->status = htons(0);
56096 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56097 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56098 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56099 +
56100 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56101 + {
56102 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_GET_STATISTICS\n"));
56103 + Status = -EFAULT;
56104 + }
56105 + else
56106 + {
56107 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_GET_STATISTICS is done !\n"));
56108 + }
56109 + }
56110 + break;
56111 +
56112 + case RACFG_CMD_ATE_RESET_COUNTER:
56113 + {
56114 + SHORT value = 1;
56115 + UCHAR str[LEN_OF_ARG];
56116 +
56117 + NdisZeroMemory(str, LEN_OF_ARG);
56118 +
56119 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_RESET_COUNTER\n"));
56120 +
56121 + sprintf((PCHAR)str, "%d", value);
56122 + Set_ResetStatCounter_Proc(pAdapter, str);
56123 +
56124 + pAdapter->ate.TxDoneCount = 0;
56125 +
56126 + pRaCfg->length = htons(2);
56127 + pRaCfg->status = htons(0);
56128 +
56129 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56130 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56131 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56132 +
56133 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56134 + {
56135 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RESET_COUNTER\n"));
56136 + Status = -EFAULT;
56137 + }
56138 + else
56139 + {
56140 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RESET_COUNTER is done !\n"));
56141 + }
56142 + }
56143 +
56144 + break;
56145 +
56146 + case RACFG_CMD_ATE_SEL_TX_ANTENNA:
56147 + {
56148 + SHORT value = 0;
56149 + UCHAR str[LEN_OF_ARG];
56150 +
56151 + NdisZeroMemory(str, LEN_OF_ARG);
56152 +
56153 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
56154 +
56155 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56156 + value = ntohs(value);
56157 + sprintf((PCHAR)str, "%d", value);
56158 + Set_ATE_TX_Antenna_Proc(pAdapter, str);
56159 +
56160 + // prepare feedback
56161 + pRaCfg->length = htons(2);
56162 + pRaCfg->status = htons(0);
56163 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56164 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56165 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56166 +
56167 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56168 + {
56169 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
56170 + Status = -EFAULT;
56171 + }
56172 + else
56173 + {
56174 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_TX_ANTENNA is done !\n"));
56175 + }
56176 + }
56177 + break;
56178 +
56179 + case RACFG_CMD_ATE_SEL_RX_ANTENNA:
56180 + {
56181 + SHORT value = 0;
56182 + UCHAR str[LEN_OF_ARG];
56183 +
56184 + NdisZeroMemory(str, LEN_OF_ARG);
56185 +
56186 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
56187 +
56188 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56189 + value = ntohs(value);
56190 + sprintf((PCHAR)str, "%d", value);
56191 + Set_ATE_RX_Antenna_Proc(pAdapter, str);
56192 +
56193 + // prepare feedback
56194 + pRaCfg->length = htons(2);
56195 + pRaCfg->status = htons(0);
56196 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56197 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56198 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56199 +
56200 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56201 + {
56202 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
56203 + Status = -EFAULT;
56204 + }
56205 + else
56206 + {
56207 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_RX_ANTENNA is done !\n"));
56208 + }
56209 + }
56210 + break;
56211 +
56212 + case RACFG_CMD_ATE_SET_PREAMBLE:
56213 + {
56214 + SHORT value = 0;
56215 + UCHAR str[LEN_OF_ARG];
56216 +
56217 + NdisZeroMemory(str, LEN_OF_ARG);
56218 +
56219 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_PREAMBLE\n"));
56220 +
56221 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56222 + value = ntohs(value);
56223 + sprintf((PCHAR)str, "%d", value);
56224 + Set_ATE_TX_MODE_Proc(pAdapter, str);
56225 +
56226 + // prepare feedback
56227 + pRaCfg->length = htons(2);
56228 + pRaCfg->status = htons(0);
56229 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56230 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56231 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56232 +
56233 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56234 + {
56235 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_PREAMBLE\n"));
56236 + Status = -EFAULT;
56237 + }
56238 + else
56239 + {
56240 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_PREAMBLE is done !\n"));
56241 + }
56242 + }
56243 + break;
56244 +
56245 + case RACFG_CMD_ATE_SET_CHANNEL:
56246 + {
56247 + SHORT value = 0;
56248 + UCHAR str[LEN_OF_ARG];
56249 +
56250 + NdisZeroMemory(str, LEN_OF_ARG);
56251 +
56252 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_CHANNEL\n"));
56253 +
56254 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56255 + value = ntohs(value);
56256 + sprintf((PCHAR)str, "%d", value);
56257 + Set_ATE_CHANNEL_Proc(pAdapter, str);
56258 +
56259 + // prepare feedback
56260 + pRaCfg->length = htons(2);
56261 + pRaCfg->status = htons(0);
56262 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56263 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56264 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56265 +
56266 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56267 + {
56268 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_CHANNEL\n"));
56269 + Status = -EFAULT;
56270 + }
56271 + else
56272 + {
56273 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_CHANNEL is done !\n"));
56274 + }
56275 + }
56276 + break;
56277 +
56278 + case RACFG_CMD_ATE_SET_ADDR1:
56279 + {
56280 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR1\n"));
56281 +
56282 + // Addr is an array of UCHAR,
56283 + // so no need to perform endian swap.
56284 + memcpy(pAdapter->ate.Addr1, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
56285 +
56286 + // prepare feedback
56287 + pRaCfg->length = htons(2);
56288 + pRaCfg->status = htons(0);
56289 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56290 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56291 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56292 +
56293 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56294 + {
56295 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR1\n"));
56296 + Status = -EFAULT;
56297 + }
56298 + else
56299 + {
56300 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR1 is done !\n (ADDR1 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr1[0],
56301 + pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]));
56302 + }
56303 + }
56304 + break;
56305 +
56306 + case RACFG_CMD_ATE_SET_ADDR2:
56307 + {
56308 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR2\n"));
56309 +
56310 + // Addr is an array of UCHAR,
56311 + // so no need to perform endian swap.
56312 + memcpy(pAdapter->ate.Addr2, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
56313 +
56314 + // prepare feedback
56315 + pRaCfg->length = htons(2);
56316 + pRaCfg->status = htons(0);
56317 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56318 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56319 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56320 +
56321 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56322 + {
56323 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR2\n"));
56324 + Status = -EFAULT;
56325 + }
56326 + else
56327 + {
56328 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR2 is done !\n (ADDR2 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr2[0],
56329 + pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]));
56330 + }
56331 + }
56332 + break;
56333 +
56334 + case RACFG_CMD_ATE_SET_ADDR3:
56335 + {
56336 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR3\n"));
56337 +
56338 + // Addr is an array of UCHAR,
56339 + // so no need to perform endian swap.
56340 + memcpy(pAdapter->ate.Addr3, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
56341 +
56342 + // prepare feedback
56343 + pRaCfg->length = htons(2);
56344 + pRaCfg->status = htons(0);
56345 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56346 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56347 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56348 +
56349 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56350 + {
56351 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR3\n"));
56352 + Status = -EFAULT;
56353 + }
56354 + else
56355 + {
56356 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR3 is done !\n (ADDR3 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr3[0],
56357 + pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]));
56358 + }
56359 + }
56360 + break;
56361 +
56362 + case RACFG_CMD_ATE_SET_RATE:
56363 + {
56364 + SHORT value = 0;
56365 + UCHAR str[LEN_OF_ARG];
56366 +
56367 + NdisZeroMemory(str, LEN_OF_ARG);
56368 +
56369 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_RATE\n"));
56370 +
56371 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56372 + value = ntohs(value);
56373 + sprintf((PCHAR)str, "%d", value);
56374 + Set_ATE_TX_MCS_Proc(pAdapter, str);
56375 +
56376 + // prepare feedback
56377 + pRaCfg->length = htons(2);
56378 + pRaCfg->status = htons(0);
56379 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56380 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56381 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56382 +
56383 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56384 + {
56385 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_RATE\n"));
56386 + Status = -EFAULT;
56387 + }
56388 + else
56389 + {
56390 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_RATE is done !\n"));
56391 + }
56392 + }
56393 + break;
56394 +
56395 + case RACFG_CMD_ATE_SET_TX_FRAME_LEN:
56396 + {
56397 + SHORT value = 0;
56398 + UCHAR str[LEN_OF_ARG];
56399 +
56400 + NdisZeroMemory(str, LEN_OF_ARG);
56401 +
56402 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
56403 +
56404 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56405 + value = ntohs(value);
56406 + sprintf((PCHAR)str, "%d", value);
56407 + Set_ATE_TX_LENGTH_Proc(pAdapter, str);
56408 +
56409 + // prepare feedback
56410 + pRaCfg->length = htons(2);
56411 + pRaCfg->status = htons(0);
56412 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56413 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56414 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56415 +
56416 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56417 + {
56418 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
56419 + Status = -EFAULT;
56420 + }
56421 + else
56422 + {
56423 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_LEN is done !\n"));
56424 + }
56425 + }
56426 + break;
56427 +
56428 + case RACFG_CMD_ATE_SET_TX_FRAME_COUNT:
56429 + {
56430 + USHORT value = 0;
56431 + UCHAR str[LEN_OF_ARG];
56432 +
56433 + NdisZeroMemory(str, LEN_OF_ARG);
56434 +
56435 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
56436 +
56437 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
56438 + value = ntohs(value);
56439 + {
56440 + sprintf((PCHAR)str, "%d", value);
56441 + Set_ATE_TX_COUNT_Proc(pAdapter, str);
56442 + }
56443 +
56444 + // prepare feedback
56445 + pRaCfg->length = htons(2);
56446 + pRaCfg->status = htons(0);
56447 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56448 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56449 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56450 +
56451 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56452 + {
56453 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
56454 + Status = -EFAULT;
56455 + }
56456 + else
56457 + {
56458 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_COUNT is done !\n"));
56459 + }
56460 + }
56461 + break;
56462 +
56463 + case RACFG_CMD_ATE_START_RX_FRAME:
56464 + {
56465 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
56466 +
56467 + Set_ATE_Proc(pAdapter, "RXFRAME");
56468 +
56469 + // prepare feedback
56470 + pRaCfg->length = htons(2);
56471 + pRaCfg->status = htons(0);
56472 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56473 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56474 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56475 +
56476 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56477 + {
56478 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
56479 + Status = -EFAULT;
56480 + }
56481 + else
56482 + {
56483 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
56484 + }
56485 + }
56486 + break;
56487 + default:
56488 + break;
56489 + }
56490 + ASSERT(pRaCfg != NULL);
56491 + if (pRaCfg != NULL)
56492 + {
56493 + kfree(pRaCfg);
56494 + }
56495 + return;
56496 +}
56497 +
56498 +VOID BubbleSort(INT32 n, INT32 a[])
56499 +{
56500 + INT32 k, j, temp;
56501 +
56502 + for (k = n-1; k>0; k--)
56503 + {
56504 + for (j = 0; j<k; j++)
56505 + {
56506 + if(a[j] > a[j+1])
56507 + {
56508 + temp = a[j];
56509 + a[j]=a[j+1];
56510 + a[j+1]=temp;
56511 + }
56512 + }
56513 + }
56514 +}
56515 +
56516 +VOID CalNoiseLevel(PRTMP_ADAPTER pAd, UCHAR channel, INT32 RSSI[3][10])
56517 +{
56518 + INT32 RSSI0, RSSI1, RSSI2;
56519 + CHAR Rssi0Offset, Rssi1Offset, Rssi2Offset;
56520 + UCHAR BbpR50Rssi0 = 0, BbpR51Rssi1 = 0, BbpR52Rssi2 = 0;
56521 + UCHAR Org_BBP66value = 0, Org_BBP69value = 0, Org_BBP70value = 0, data = 0;
56522 + USHORT LNA_Gain = 0;
56523 + INT32 j = 0;
56524 + UCHAR Org_Channel = pAd->ate.Channel;
56525 + USHORT GainValue = 0, OffsetValue = 0;
56526 +
56527 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &Org_BBP66value);
56528 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R69, &Org_BBP69value);
56529 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R70, &Org_BBP70value);
56530 +
56531 + //**********************************************************************
56532 + // Read the value of LNA gain and Rssi offset
56533 + //**********************************************************************
56534 + RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, GainValue);
56535 +
56536 + // for Noise Level
56537 + if (channel <= 14)
56538 + {
56539 + LNA_Gain = GainValue & 0x00FF;
56540 +
56541 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, OffsetValue);
56542 + Rssi0Offset = OffsetValue & 0x00FF;
56543 + Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
56544 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_BG_OFFSET + 2)/* 0x48 */, OffsetValue);
56545 + Rssi2Offset = OffsetValue & 0x00FF;
56546 + }
56547 + else
56548 + {
56549 + LNA_Gain = (GainValue & 0xFF00) >> 8;
56550 +
56551 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, OffsetValue);
56552 + Rssi0Offset = OffsetValue & 0x00FF;
56553 + Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
56554 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2)/* 0x4C */, OffsetValue);
56555 + Rssi2Offset = OffsetValue & 0x00FF;
56556 + }
56557 + //**********************************************************************
56558 + {
56559 + pAd->ate.Channel = channel;
56560 + ATEAsicSwitchChannel(pAd);
56561 + mdelay(5);
56562 +
56563 + data = 0x10;
56564 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, data);
56565 + data = 0x40;
56566 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, data);
56567 + data = 0x40;
56568 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, data);
56569 + mdelay(5);
56570 +
56571 + // Start Rx
56572 + pAd->ate.bQARxStart = TRUE;
56573 + Set_ATE_Proc(pAd, "RXFRAME");
56574 +
56575 + mdelay(5);
56576 +
56577 + for (j = 0; j < 10; j++)
56578 + {
56579 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R50, &BbpR50Rssi0);
56580 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R51, &BbpR51Rssi1);
56581 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R52, &BbpR52Rssi2);
56582 +
56583 + mdelay(10);
56584 +
56585 + // Calculate RSSI 0
56586 + if (BbpR50Rssi0 == 0)
56587 + {
56588 + RSSI0 = -100;
56589 + }
56590 + else
56591 + {
56592 + RSSI0 = (INT32)(-12 - BbpR50Rssi0 - LNA_Gain - Rssi0Offset);
56593 + }
56594 + RSSI[0][j] = RSSI0;
56595 +
56596 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
56597 + {
56598 + // Calculate RSSI 1
56599 + if (BbpR51Rssi1 == 0)
56600 + {
56601 + RSSI1 = -100;
56602 + }
56603 + else
56604 + {
56605 + RSSI1 = (INT32)(-12 - BbpR51Rssi1 - LNA_Gain - Rssi1Offset);
56606 + }
56607 + RSSI[1][j] = RSSI1;
56608 + }
56609 +
56610 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
56611 + {
56612 + // Calculate RSSI 2
56613 + if (BbpR52Rssi2 == 0)
56614 + RSSI2 = -100;
56615 + else
56616 + RSSI2 = (INT32)(-12 - BbpR52Rssi2 - LNA_Gain - Rssi2Offset);
56617 +
56618 + RSSI[2][j] = RSSI2;
56619 + }
56620 + }
56621 +
56622 + // Stop Rx
56623 + Set_ATE_Proc(pAd, "RXSTOP");
56624 +
56625 + mdelay(5);
56626 +
56627 +#if 0// Debug Message................
56628 + ate_print("\n**********************************************************\n");
56629 + ate_print("Noise Level: Channel %d\n", channel);
56630 + ate_print("RSSI0 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56631 + RSSI[0][0], RSSI[0][1], RSSI[0][2],
56632 + RSSI[0][3], RSSI[0][4], RSSI[0][5],
56633 + RSSI[0][6], RSSI[0][7], RSSI[0][8],
56634 + RSSI[0][9]);
56635 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
56636 + {
56637 + ate_print("RSSI1 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56638 + RSSI[1][0], RSSI[1][1], RSSI[1][2],
56639 + RSSI[1][3], RSSI[1][4], RSSI[1][5],
56640 + RSSI[1][6], RSSI[1][7], RSSI[1][8],
56641 + RSSI[1][9]);
56642 + }
56643 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
56644 + {
56645 + ate_print("RSSI2 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56646 + RSSI[2][0], RSSI[2][1], RSSI[2][2],
56647 + RSSI[2][3], RSSI[2][4], RSSI[2][5],
56648 + RSSI[2][6], RSSI[2][7], RSSI[2][8],
56649 + RSSI[2][9]);
56650 + }
56651 +#endif // 0 //
56652 + BubbleSort(10, RSSI[0]); // 1R
56653 +
56654 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
56655 + {
56656 + BubbleSort(10, RSSI[1]);
56657 + }
56658 +
56659 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
56660 + {
56661 + BubbleSort(10, RSSI[2]);
56662 + }
56663 +
56664 +#if 0// Debug Message................
56665 + ate_print("\nAfter Sorting....Channel %d\n", channel);
56666 + ate_print("RSSI0 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56667 + RSSI[0][0], RSSI[0][1], RSSI[0][2],
56668 + RSSI[0][3], RSSI[0][4], RSSI[0][5],
56669 + RSSI[0][6], RSSI[0][7], RSSI[0][8],
56670 + RSSI[0][9]);
56671 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
56672 + {
56673 + ate_print("RSSI1 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56674 + RSSI[1][0], RSSI[1][1], RSSI[1][2],
56675 + RSSI[1][3], RSSI[1][4], RSSI[1][5],
56676 + RSSI[1][6], RSSI[1][7], RSSI[1][8],
56677 + RSSI[1][9]);
56678 + }
56679 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
56680 + {
56681 + ate_print("RSSI2 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
56682 + RSSI[2][0], RSSI[2][1], RSSI[2][2],
56683 + RSSI[2][3], RSSI[2][4], RSSI[2][5],
56684 + RSSI[2][6], RSSI[2][7], RSSI[2][8],
56685 + RSSI[2][9]);
56686 + }
56687 + ate_print("**********************************************************\n");
56688 +#endif // 0 //
56689 + }
56690 +
56691 + pAd->ate.Channel = Org_Channel;
56692 + ATEAsicSwitchChannel(pAd);
56693 +
56694 + // Restore original value
56695 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, Org_BBP66value);
56696 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, Org_BBP69value);
56697 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, Org_BBP70value);
56698 +
56699 + return;
56700 +}
56701 +
56702 +BOOLEAN SyncTxRxConfig(PRTMP_ADAPTER pAd, USHORT offset, UCHAR value)
56703 +{
56704 + UCHAR tmp = 0, bbp_data = 0;
56705 +
56706 + if (ATE_ON(pAd))
56707 + {
56708 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
56709 + }
56710 + else
56711 + {
56712 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
56713 + }
56714 +
56715 + /* confirm again */
56716 + ASSERT(bbp_data == value);
56717 +
56718 + switch(offset)
56719 + {
56720 + case BBP_R1:
56721 + /* Need to sync. tx configuration with legacy ATE. */
56722 + tmp = (bbp_data & ((1 << 4) | (1 << 3))/* 0x18 */) >> 3;
56723 + switch(tmp)
56724 + {
56725 + /* The BBP R1 bit[4:3] = 2 :: Both DACs will be used by QA. */
56726 + case 2:
56727 + /* All */
56728 + pAd->ate.TxAntennaSel = 0;
56729 + break;
56730 + /* The BBP R1 bit[4:3] = 0 :: DAC 0 will be used by QA. */
56731 + case 0:
56732 + /* Antenna one */
56733 + pAd->ate.TxAntennaSel = 1;
56734 + break;
56735 + /* The BBP R1 bit[4:3] = 1 :: DAC 1 will be used by QA. */
56736 + case 1:
56737 + /* Antenna two */
56738 + pAd->ate.TxAntennaSel = 2;
56739 + break;
56740 + default:
56741 + DBGPRINT(RT_DEBUG_TRACE, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
56742 + return FALSE;
56743 + }
56744 + break;/* case BBP_R1 */
56745 +
56746 + case BBP_R3:
56747 + /* Need to sync. rx configuration with legacy ATE. */
56748 + tmp = (bbp_data & ((1 << 1) | (1 << 0))/* 0x03 */);
56749 + switch(tmp)
56750 + {
56751 + /* The BBP R3 bit[1:0] = 3 :: All ADCs will be used by QA. */
56752 + case 3:
56753 + /* All */
56754 + pAd->ate.RxAntennaSel = 0;
56755 + break;
56756 + /* The BBP R3 bit[1:0] = 0 :: ADC 0 will be used by QA, */
56757 + /* unless the BBP R3 bit[4:3] = 2 */
56758 + case 0:
56759 + /* Antenna one */
56760 + pAd->ate.RxAntennaSel = 1;
56761 + tmp = ((bbp_data & ((1 << 4) | (1 << 3))/* 0x03 */) >> 3);
56762 + if (tmp == 2)// 3R
56763 + {
56764 + /* Default : All ADCs will be used by QA */
56765 + pAd->ate.RxAntennaSel = 0;
56766 + }
56767 + break;
56768 + /* The BBP R3 bit[1:0] = 1 :: ADC 1 will be used by QA. */
56769 + case 1:
56770 + /* Antenna two */
56771 + pAd->ate.RxAntennaSel = 2;
56772 + break;
56773 + /* The BBP R3 bit[1:0] = 2 :: ADC 2 will be used by QA. */
56774 + case 2:
56775 + /* Antenna three */
56776 + pAd->ate.RxAntennaSel = 3;
56777 + break;
56778 + default:
56779 + DBGPRINT(RT_DEBUG_ERROR, ("%s -- Impossible! : return FALSE; \n", __FUNCTION__));
56780 + return FALSE;
56781 + }
56782 + break;/* case BBP_R3 */
56783 +
56784 + default:
56785 + DBGPRINT(RT_DEBUG_ERROR, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
56786 + return FALSE;
56787 +
56788 + }
56789 + return TRUE;
56790 +}
56791 +
56792 +static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
56793 +{
56794 + ULONG i, Value = 0;
56795 + ULONG *pDst, *pSrc;
56796 + UCHAR *p8;
56797 +
56798 + p8 = src;
56799 + pDst = (ULONG *) dst;
56800 + pSrc = (ULONG *) src;
56801 +
56802 + for (i = 0 ; i < (len/4); i++)
56803 + {
56804 + /* For alignment issue, we need a variable "Value". */
56805 + memmove(&Value, pSrc, 4);
56806 + Value = htonl(Value);
56807 + memmove(pDst, &Value, 4);
56808 + pDst++;
56809 + pSrc++;
56810 + }
56811 + if ((len % 4) != 0)
56812 + {
56813 + /* wish that it will never reach here */
56814 + memmove(&Value, pSrc, (len % 4));
56815 + Value = htonl(Value);
56816 + memmove(pDst, &Value, (len % 4));
56817 + }
56818 +}
56819 +
56820 +static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
56821 +{
56822 + ULONG i;
56823 + UCHAR *pDst, *pSrc;
56824 +
56825 + pDst = dst;
56826 + pSrc = src;
56827 +
56828 + for (i = 0; i < (len/2); i++)
56829 + {
56830 + memmove(pDst, pSrc, 2);
56831 + *((USHORT *)pDst) = htons(*((USHORT *)pDst));
56832 + pDst+=2;
56833 + pSrc+=2;
56834 + }
56835 +
56836 + if ((len % 2) != 0)
56837 + {
56838 + memmove(pDst, pSrc, 1);
56839 + }
56840 +}
56841 +
56842 +static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len)
56843 +{
56844 + UINT32 i, Value;
56845 + UINT32 *pDst, *pSrc;
56846 +
56847 + pDst = (UINT32 *) dst;
56848 + pSrc = (UINT32 *) src;
56849 +
56850 + for (i = 0 ; i < (len/4); i++)
56851 + {
56852 + RTMP_IO_READ32(pAd, (ULONG)pSrc, &Value);
56853 + Value = htonl(Value);
56854 + memmove(pDst, &Value, 4);
56855 + pDst++;
56856 + pSrc++;
56857 + }
56858 + return;
56859 +}
56860 +
56861 +// TODO:
56862 +#if 0
56863 +/* These work only when RALINK_ATE is defined */
56864 +INT Set_TxStart_Proc(
56865 + IN PRTMP_ADAPTER pAd,
56866 + IN PUCHAR arg)
56867 +{
56868 + ULONG value = simple_strtol(arg, 0, 10);
56869 + UCHAR buffer[26] = {0x88, 0x02, 0x2c, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x00, 0x55, 0x44, 0x33, 0x22, 0x11, 0xc0, 0x22, 0x00, 0x00};
56870 + POS_COOKIE pObj;
56871 +
56872 + if (pAd->ate.TxStatus != 0)
56873 + return FALSE;
56874 +
56875 + pAd->ate.TxInfo = 0x04000000;
56876 + bzero(&pAd->ate.TxWI, sizeof(TXWI_STRUC));
56877 + pAd->ate.TxWI.PHYMODE = 0;// MODE_CCK
56878 + pAd->ate.TxWI.MPDUtotalByteCount = 1226;
56879 + pAd->ate.TxWI.MCS = 3;
56880 + //pAd->ate.Mode = ATE_START;
56881 + pAd->ate.Mode |= ATE_TXFRAME;
56882 + pAd->ate.TxCount = value;
56883 + pAd->ate.QID = 0;
56884 + pAd->ate.HLen = 26;
56885 + pAd->ate.PLen = 0;
56886 + pAd->ate.DLen = 1200;
56887 + memcpy(pAd->ate.Header, buffer, 26);
56888 + pAd->ate.bQATxStart = TRUE;
56889 + //pObj = (POS_COOKIE) pAd->OS_Cookie;
56890 + //tasklet_hi_schedule(&pObj->AteTxTask);
56891 + return TRUE;
56892 +}
56893 +#endif /* end of #if 0 */
56894 +
56895 +INT Set_TxStop_Proc(
56896 + IN PRTMP_ADAPTER pAd,
56897 + IN PUCHAR arg)
56898 +{
56899 + ATEDBGPRINT(RT_DEBUG_TRACE,("Set_TxStop_Proc\n"));
56900 +
56901 + if (Set_ATE_Proc(pAd, "TXSTOP"))
56902 + {
56903 + return TRUE;
56904 +}
56905 + else
56906 + {
56907 + return FALSE;
56908 + }
56909 +}
56910 +
56911 +INT Set_RxStop_Proc(
56912 + IN PRTMP_ADAPTER pAd,
56913 + IN PUCHAR arg)
56914 +{
56915 + ATEDBGPRINT(RT_DEBUG_TRACE,("Set_RxStop_Proc\n"));
56916 +
56917 + if (Set_ATE_Proc(pAd, "RXSTOP"))
56918 + {
56919 + return TRUE;
56920 +}
56921 + else
56922 + {
56923 + return FALSE;
56924 + }
56925 +}
56926 +
56927 +#if 0
56928 +INT Set_EEWrite_Proc(
56929 + IN PRTMP_ADAPTER pAd,
56930 + IN PUCHAR arg)
56931 +{
56932 + USHORT offset = 0, value;
56933 + PUCHAR p2 = arg;
56934 +
56935 + while((*p2 != ':') && (*p2 != '\0'))
56936 + {
56937 + p2++;
56938 + }
56939 +
56940 + if (*p2 == ':')
56941 + {
56942 + A2Hex(offset, arg);
56943 + A2Hex(value, p2+ 1);
56944 + }
56945 + else
56946 + {
56947 + A2Hex(value, arg);
56948 + }
56949 +
56950 + if (offset >= EEPROM_SIZE)
56951 + {
56952 + ate_print("Offset can not exceed EEPROM_SIZE( == 0x%04x)\n", EEPROM_SIZE);
56953 + return FALSE;
56954 + }
56955 +
56956 + RTMP_EEPROM_WRITE16(pAd, offset, value);
56957 +
56958 + return TRUE;
56959 +}
56960 +
56961 +INT Set_BBPRead_Proc(
56962 + IN PRTMP_ADAPTER pAd,
56963 + IN PUCHAR arg)
56964 +{
56965 + UCHAR value = 0, offset;
56966 +
56967 + A2Hex(offset, arg);
56968 +
56969 + if (ATE_ON(pAd))
56970 + {
56971 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &value);
56972 + }
56973 + else
56974 + {
56975 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &value);
56976 + }
56977 +
56978 + ate_print("%x\n", value);
56979 +
56980 + return TRUE;
56981 +}
56982 +
56983 +
56984 +INT Set_BBPWrite_Proc(
56985 + IN PRTMP_ADAPTER pAd,
56986 + IN PUCHAR arg)
56987 +{
56988 + USHORT offset = 0;
56989 + PUCHAR p2 = arg;
56990 + UCHAR value;
56991 +
56992 + while((*p2 != ':') && (*p2 != '\0'))
56993 + {
56994 + p2++;
56995 + }
56996 +
56997 + if (*p2 == ':')
56998 + {
56999 + A2Hex(offset, arg);
57000 + A2Hex(value, p2+ 1);
57001 + }
57002 + else
57003 + {
57004 + A2Hex(value, arg);
57005 + }
57006 +
57007 + if (ATE_ON(pAd))
57008 + {
57009 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, offset, value);
57010 + }
57011 + else
57012 + {
57013 + RTNP_BBP_IO_WRITE8_BY_REG_ID(pAd, offset, value);
57014 + }
57015 +
57016 + return TRUE;
57017 +}
57018 +
57019 +INT Set_RFWrite_Proc(
57020 + IN PRTMP_ADAPTER pAd,
57021 + IN PUCHAR arg)
57022 +{
57023 + PUCHAR p2, p3, p4;
57024 + ULONG R1, R2, R3, R4;
57025 +
57026 + p2 = arg;
57027 +
57028 + while((*p2 != ':') && (*p2 != '\0'))
57029 + {
57030 + p2++;
57031 + }
57032 +
57033 + if (*p2 != ':')
57034 + return FALSE;
57035 +
57036 + p3 = p2 + 1;
57037 +
57038 + while((*p3 != ':') && (*p3 != '\0'))
57039 + {
57040 + p3++;
57041 + }
57042 +
57043 + if (*p3 != ':')
57044 + return FALSE;
57045 +
57046 + p4 = p3 + 1;
57047 +
57048 + while((*p4 != ':') && (*p4 != '\0'))
57049 + {
57050 + p4++;
57051 + }
57052 +
57053 + if (*p4 != ':')
57054 + return FALSE;
57055 +
57056 +
57057 + A2Hex(R1, arg);
57058 + A2Hex(R2, p2 + 1);
57059 + A2Hex(R3, p3 + 1);
57060 + A2Hex(R4, p4 + 1);
57061 +
57062 + RTMP_RF_IO_WRITE32(pAd, R1);
57063 + RTMP_RF_IO_WRITE32(pAd, R2);
57064 + RTMP_RF_IO_WRITE32(pAd, R3);
57065 + RTMP_RF_IO_WRITE32(pAd, R4);
57066 +
57067 + return TRUE;
57068 +}
57069 +#endif // end of #if 0 //
57070 +#endif // RALINK_28xx_QA //
57071 +
57072 +#endif // RALINK_ATE //
57073 +
57074 --- /dev/null
57075 +++ b/drivers/staging/rt2870/rt_ate.h
57076 @@ -0,0 +1,315 @@
57077 +/*
57078 + *************************************************************************
57079 + * Ralink Tech Inc.
57080 + * 5F., No.36, Taiyuan St., Jhubei City,
57081 + * Hsinchu County 302,
57082 + * Taiwan, R.O.C.
57083 + *
57084 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
57085 + *
57086 + * This program is free software; you can redistribute it and/or modify *
57087 + * it under the terms of the GNU General Public License as published by *
57088 + * the Free Software Foundation; either version 2 of the License, or *
57089 + * (at your option) any later version. *
57090 + * *
57091 + * This program is distributed in the hope that it will be useful, *
57092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
57093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
57094 + * GNU General Public License for more details. *
57095 + * *
57096 + * You should have received a copy of the GNU General Public License *
57097 + * along with this program; if not, write to the *
57098 + * Free Software Foundation, Inc., *
57099 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
57100 + * *
57101 + *************************************************************************
57102 + */
57103 +
57104 +#ifndef __ATE_H__
57105 +#define __ATE_H__
57106 +
57107 +#ifndef UCOS
57108 +#define ate_print printk
57109 +#define ATEDBGPRINT DBGPRINT
57110 +
57111 +#ifdef RT2870
57112 +#define EEPROM_SIZE 0x400
57113 +#ifdef CONFIG_STA_SUPPORT
57114 +#define EEPROM_BIN_FILE_NAME "/etc/Wireless/RT2870STA/e2p.bin"
57115 +#endif // CONFIG_STA_SUPPORT //
57116 +#endif // RT2870 //
57117 +#else // !UCOS //
57118 +#define fATE_LOAD_EEPROM 0x0C43
57119 +#ifdef CONFIG_PRINTK
57120 +extern INT ConsoleResponse(IN PUCHAR buff);
57121 +extern int (*remote_display)(char *);
57122 +extern void puts (const char *s);
57123 +
57124 +/* specificly defined to redirect and show ate-related messages to host. */
57125 +/* Try to define ate_print as a macro. */
57126 +#define ate_print(fmt, args...) \
57127 +do{ int (*org_remote_display)(char *) = NULL; \
57128 + org_remote_display = remote_display;\
57129 + /* Save original "remote_display" */\
57130 + remote_display = (int (*)(char *))ConsoleResponse; \
57131 + printk(fmt, ## args); \
57132 + /* Restore the remote_display function pointer */ \
57133 + remote_display = org_remote_display; }while(0)
57134 +
57135 +#define ATEDBGPRINT(Level, Fmt) \
57136 +{ \
57137 + if ((Level) <= RTDebugLevel) \
57138 + { \
57139 + ate_print Fmt; \
57140 + } \
57141 +}
57142 +#endif // CONFIG_PRINTK //
57143 +#endif // !UCOS //
57144 +
57145 +#define ATE_ON(_p) (((_p)->ate.Mode) != ATE_STOP)
57146 +
57147 +/* RT2880_iNIC will define "RT2860". */
57148 +
57149 +/* RT2880_iNIC will define RT2860. */
57150 +
57151 +#ifdef RT2870
57152 +#define EEPROM_SIZE 0x400
57153 +#ifdef CONFIG_STA_SUPPORT
57154 +#define EEPROM_BIN_FILE_NAME "/etc/Wireless/RT2870STA/e2p.bin"
57155 +#endif // CONFIG_STA_SUPPORT //
57156 +#endif // RT2870 //
57157 +
57158 +#ifdef RT2870
57159 +#define ATE_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)
57160 +#define ATE_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)
57161 +
57162 +#define BULK_OUT_LOCK(pLock, IrqFlags) \
57163 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
57164 + RTMP_IRQ_LOCK((pLock), IrqFlags);
57165 +
57166 +#define BULK_OUT_UNLOCK(pLock, IrqFlags) \
57167 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
57168 + RTMP_IRQ_UNLOCK((pLock), IrqFlags);
57169 +
57170 +// Prototypes of completion funuc.
57171 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
57172 +#define ATE_RTUSBBulkOutDataPacketComplete(purb, pt_regs) ATE_RTUSBBulkOutDataPacketComplete(purb)
57173 +#endif
57174 +
57175 +VOID ATE_RTUSBBulkOutDataPacketComplete(
57176 + IN purbb_t purb,
57177 + OUT struct pt_regs *pt_regs);
57178 +
57179 +VOID ATE_RTUSBBulkOutDataPacket(
57180 + IN PRTMP_ADAPTER pAd,
57181 + IN UCHAR BulkOutPipeId);
57182 +
57183 +VOID ATE_RTUSBCancelPendingBulkInIRP(
57184 + IN PRTMP_ADAPTER pAd);
57185 +#endif // RT2870 //
57186 +
57187 +VOID rt_ee_read_all(
57188 + IN PRTMP_ADAPTER pAd,
57189 + OUT USHORT *Data);
57190 +
57191 +
57192 +VOID rt_ee_write_all(
57193 + IN PRTMP_ADAPTER pAd,
57194 + IN USHORT *Data);
57195 +
57196 +INT Set_ATE_Proc(
57197 + IN PRTMP_ADAPTER pAd,
57198 + IN PUCHAR arg);
57199 +
57200 +INT Set_ATE_DA_Proc(
57201 + IN PRTMP_ADAPTER pAd,
57202 + IN PUCHAR arg);
57203 +
57204 +INT Set_ATE_SA_Proc(
57205 + IN PRTMP_ADAPTER pAd,
57206 + IN PUCHAR arg);
57207 +
57208 +INT Set_ATE_BSSID_Proc(
57209 + IN PRTMP_ADAPTER pAd,
57210 + IN PUCHAR arg);
57211 +
57212 +INT Set_ATE_CHANNEL_Proc(
57213 + IN PRTMP_ADAPTER pAd,
57214 + IN PUCHAR arg);
57215 +
57216 +INT Set_ATE_TX_POWER0_Proc(
57217 + IN PRTMP_ADAPTER pAd,
57218 + IN PUCHAR arg);
57219 +
57220 +INT Set_ATE_TX_POWER1_Proc(
57221 + IN PRTMP_ADAPTER pAd,
57222 + IN PUCHAR arg);
57223 +
57224 +INT Set_ATE_TX_Antenna_Proc(
57225 + IN PRTMP_ADAPTER pAd,
57226 + IN PUCHAR arg);
57227 +
57228 +INT Set_ATE_RX_Antenna_Proc(
57229 + IN PRTMP_ADAPTER pAd,
57230 + IN PUCHAR arg);
57231 +
57232 +INT Set_ATE_TX_FREQOFFSET_Proc(
57233 + IN PRTMP_ADAPTER pAd,
57234 + IN PUCHAR arg);
57235 +
57236 +INT Set_ATE_TX_BW_Proc(
57237 + IN PRTMP_ADAPTER pAd,
57238 + IN PUCHAR arg);
57239 +
57240 +INT Set_ATE_TX_LENGTH_Proc(
57241 + IN PRTMP_ADAPTER pAd,
57242 + IN PUCHAR arg);
57243 +
57244 +INT Set_ATE_TX_COUNT_Proc(
57245 + IN PRTMP_ADAPTER pAd,
57246 + IN PUCHAR arg);
57247 +
57248 +INT Set_ATE_TX_MCS_Proc(
57249 + IN PRTMP_ADAPTER pAd,
57250 + IN PUCHAR arg);
57251 +
57252 +INT Set_ATE_TX_MODE_Proc(
57253 + IN PRTMP_ADAPTER pAd,
57254 + IN PUCHAR arg);
57255 +
57256 +INT Set_ATE_TX_GI_Proc(
57257 + IN PRTMP_ADAPTER pAd,
57258 + IN PUCHAR arg);
57259 +
57260 +
57261 +INT Set_ATE_RX_FER_Proc(
57262 + IN PRTMP_ADAPTER pAd,
57263 + IN PUCHAR arg);
57264 +
57265 +INT Set_ATE_Read_RF_Proc(
57266 + IN PRTMP_ADAPTER pAd,
57267 + IN PUCHAR arg);
57268 +
57269 +INT Set_ATE_Write_RF1_Proc(
57270 + IN PRTMP_ADAPTER pAd,
57271 + IN PUCHAR arg);
57272 +
57273 +INT Set_ATE_Write_RF2_Proc(
57274 + IN PRTMP_ADAPTER pAd,
57275 + IN PUCHAR arg);
57276 +
57277 +INT Set_ATE_Write_RF3_Proc(
57278 + IN PRTMP_ADAPTER pAd,
57279 + IN PUCHAR arg);
57280 +
57281 +INT Set_ATE_Write_RF4_Proc(
57282 + IN PRTMP_ADAPTER pAd,
57283 + IN PUCHAR arg);
57284 +
57285 +INT Set_ATE_Load_E2P_Proc(
57286 + IN PRTMP_ADAPTER pAd,
57287 + IN PUCHAR arg);
57288 +
57289 +INT Set_ATE_Read_E2P_Proc(
57290 + IN PRTMP_ADAPTER pAd,
57291 + IN PUCHAR arg);
57292 +
57293 +INT Set_ATE_Show_Proc(
57294 + IN PRTMP_ADAPTER pAd,
57295 + IN PUCHAR arg);
57296 +
57297 +INT Set_ATE_Help_Proc(
57298 + IN PRTMP_ADAPTER pAd,
57299 + IN PUCHAR arg);
57300 +
57301 +#ifdef RALINK_ATE
57302 +#ifdef RALINK_28xx_QA
57303 +VOID ATE_QA_Statistics(
57304 + IN PRTMP_ADAPTER pAd,
57305 + IN PRXWI_STRUC pRxWI,
57306 + IN PRT28XX_RXD_STRUC p28xxRxD,
57307 + IN PHEADER_802_11 pHeader);
57308 +
57309 +VOID RtmpDoAte(
57310 + IN PRTMP_ADAPTER pAdapter,
57311 + IN struct iwreq *wrq);
57312 +
57313 +VOID BubbleSort(
57314 + IN INT32 n,
57315 + IN INT32 a[]);
57316 +
57317 +VOID CalNoiseLevel(
57318 + IN PRTMP_ADAPTER pAdapter,
57319 + IN UCHAR channel,
57320 + OUT INT32 buffer[3][10]);
57321 +
57322 +BOOLEAN SyncTxRxConfig(
57323 + IN PRTMP_ADAPTER pAdapter,
57324 + IN USHORT offset,
57325 + IN UCHAR value);
57326 +
57327 +#if 0
57328 +INT Set_TxStart_Proc(
57329 + IN PRTMP_ADAPTER pAd,
57330 + IN PUCHAR arg);
57331 +#endif // 0 //
57332 +
57333 +INT Set_TxStop_Proc(
57334 + IN PRTMP_ADAPTER pAd,
57335 + IN PUCHAR arg);
57336 +
57337 +INT Set_RxStop_Proc(
57338 + IN PRTMP_ADAPTER pAd,
57339 + IN PUCHAR arg);
57340 +
57341 +#if 0
57342 +INT Set_EERead_Proc(
57343 + IN PRTMP_ADAPTER pAd,
57344 + IN PUCHAR arg);
57345 +
57346 +INT Set_EEWrite_Proc(
57347 + IN PRTMP_ADAPTER pAd,
57348 + IN PUCHAR arg);
57349 +
57350 +INT Set_BBPRead_Proc(
57351 + IN PRTMP_ADAPTER pAd,
57352 + IN PUCHAR arg);
57353 +
57354 +INT Set_BBPWrite_Proc(
57355 + IN PRTMP_ADAPTER pAd,
57356 + IN PUCHAR arg);
57357 +
57358 +INT Set_RFWrite_Proc(
57359 + IN PRTMP_ADAPTER pAd,
57360 + IN PUCHAR arg);
57361 +#endif // end of #if 0 //
57362 +#endif // RALINK_28xx_QA //
57363 +#endif // RALINK_ATE //
57364 +
57365 +VOID ATEAsicSwitchChannel(
57366 + IN PRTMP_ADAPTER pAd);
57367 +
57368 +VOID ATEAsicAdjustTxPower(
57369 + IN PRTMP_ADAPTER pAd);
57370 +
57371 +VOID ATEDisableAsicProtect(
57372 + IN PRTMP_ADAPTER pAd);
57373 +
57374 +CHAR ATEConvertToRssi(
57375 + IN PRTMP_ADAPTER pAd,
57376 + IN CHAR Rssi,
57377 + IN UCHAR RssiNumber);
57378 +
57379 +VOID ATESampleRssi(
57380 + IN PRTMP_ADAPTER pAd,
57381 + IN PRXWI_STRUC pRxWI);
57382 +
57383 +
57384 +#ifdef CONFIG_STA_SUPPORT
57385 +VOID RTMPStationStop(
57386 + IN PRTMP_ADAPTER pAd);
57387 +
57388 +VOID RTMPStationStart(
57389 + IN PRTMP_ADAPTER pAd);
57390 +#endif // CONFIG_STA_SUPPORT //
57391 +#endif // __ATE_H__ //
57392 --- /dev/null
57393 +++ b/drivers/staging/rt2870/rt_config.h
57394 @@ -0,0 +1,104 @@
57395 +/*
57396 + *************************************************************************
57397 + * Ralink Tech Inc.
57398 + * 5F., No.36, Taiyuan St., Jhubei City,
57399 + * Hsinchu County 302,
57400 + * Taiwan, R.O.C.
57401 + *
57402 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
57403 + *
57404 + * This program is free software; you can redistribute it and/or modify *
57405 + * it under the terms of the GNU General Public License as published by *
57406 + * the Free Software Foundation; either version 2 of the License, or *
57407 + * (at your option) any later version. *
57408 + * *
57409 + * This program is distributed in the hope that it will be useful, *
57410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
57411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
57412 + * GNU General Public License for more details. *
57413 + * *
57414 + * You should have received a copy of the GNU General Public License *
57415 + * along with this program; if not, write to the *
57416 + * Free Software Foundation, Inc., *
57417 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
57418 + * *
57419 + *************************************************************************
57420 +
57421 + Module Name:
57422 + rt_config.h
57423 +
57424 + Abstract:
57425 + Central header file to maintain all include files for all NDIS
57426 + miniport driver routines.
57427 +
57428 + Revision History:
57429 + Who When What
57430 + -------- ---------- ----------------------------------------------
57431 + Paul Lin 08-01-2002 created
57432 +
57433 +*/
57434 +#ifndef __RT_CONFIG_H__
57435 +#define __RT_CONFIG_H__
57436 +
57437 +#include "rtmp_type.h"
57438 +#ifdef UCOS
57439 +#include "includes.h"
57440 +#include <stdio.h>
57441 +#include "rt_ucos.h"
57442 +#endif
57443 +
57444 +#ifdef LINUX
57445 +#include "rt_linux.h"
57446 +#endif
57447 +#include "rtmp_def.h"
57448 +#include "rt28xx.h"
57449 +
57450 +
57451 +#ifdef RT2870
57452 +#include "rt2870.h"
57453 +#endif // RT2870 //
57454 +
57455 +#include "oid.h"
57456 +#include "mlme.h"
57457 +#include "wpa.h"
57458 +#include "md5.h"
57459 +#include "rtmp.h"
57460 +#include "ap.h"
57461 +#include "dfs.h"
57462 +#include "chlist.h"
57463 +#include "spectrum.h"
57464 +
57465 +
57466 +#ifdef LEAP_SUPPORT
57467 +#include "leap.h"
57468 +#endif // LEAP_SUPPORT //
57469 +
57470 +#ifdef BLOCK_NET_IF
57471 +#include "netif_block.h"
57472 +#endif // BLOCK_NET_IF //
57473 +
57474 +#ifdef IGMP_SNOOP_SUPPORT
57475 +#include "igmp_snoop.h"
57476 +#endif // IGMP_SNOOP_SUPPORT //
57477 +
57478 +#ifdef RALINK_ATE
57479 +#include "rt_ate.h"
57480 +#endif // RALINK_ATE //
57481 +
57482 +
57483 +
57484 +#ifdef CONFIG_STA_SUPPORT
57485 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
57486 +#ifndef WPA_SUPPLICANT_SUPPORT
57487 +#error "Build for being controlled by NetworkManager or wext, please set HAS_WPA_SUPPLICANT=y and HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y"
57488 +#endif // WPA_SUPPLICANT_SUPPORT //
57489 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
57490 +
57491 +#endif // CONFIG_STA_SUPPORT //
57492 +
57493 +#ifdef IKANOS_VX_1X0
57494 +#include "vr_ikans.h"
57495 +#endif // IKANOS_VX_1X0 //
57496 +
57497 +#endif // __RT_CONFIG_H__
57498 +
57499 --- /dev/null
57500 +++ b/drivers/staging/rt2870/rt_linux.c
57501 @@ -0,0 +1,1095 @@
57502 +/*
57503 + *************************************************************************
57504 + * Ralink Tech Inc.
57505 + * 5F., No.36, Taiyuan St., Jhubei City,
57506 + * Hsinchu County 302,
57507 + * Taiwan, R.O.C.
57508 + *
57509 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
57510 + *
57511 + * This program is free software; you can redistribute it and/or modify *
57512 + * it under the terms of the GNU General Public License as published by *
57513 + * the Free Software Foundation; either version 2 of the License, or *
57514 + * (at your option) any later version. *
57515 + * *
57516 + * This program is distributed in the hope that it will be useful, *
57517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
57518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
57519 + * GNU General Public License for more details. *
57520 + * *
57521 + * You should have received a copy of the GNU General Public License *
57522 + * along with this program; if not, write to the *
57523 + * Free Software Foundation, Inc., *
57524 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
57525 + * *
57526 + *************************************************************************
57527 + */
57528 +
57529 +#include "rt_config.h"
57530 +
57531 +ULONG RTDebugLevel = RT_DEBUG_ERROR;
57532 +
57533 +BUILD_TIMER_FUNCTION(MlmePeriodicExec);
57534 +//BUILD_TIMER_FUNCTION(MlmeRssiReportExec);
57535 +BUILD_TIMER_FUNCTION(AsicRxAntEvalTimeout);
57536 +BUILD_TIMER_FUNCTION(APSDPeriodicExec);
57537 +BUILD_TIMER_FUNCTION(AsicRfTuningExec);
57538 +#ifdef RT2870
57539 +BUILD_TIMER_FUNCTION(BeaconUpdateExec);
57540 +#endif // RT2870 //
57541 +
57542 +
57543 +#ifdef CONFIG_STA_SUPPORT
57544 +BUILD_TIMER_FUNCTION(BeaconTimeout);
57545 +BUILD_TIMER_FUNCTION(ScanTimeout);
57546 +BUILD_TIMER_FUNCTION(AuthTimeout);
57547 +BUILD_TIMER_FUNCTION(AssocTimeout);
57548 +BUILD_TIMER_FUNCTION(ReassocTimeout);
57549 +BUILD_TIMER_FUNCTION(DisassocTimeout);
57550 +BUILD_TIMER_FUNCTION(LinkDownExec);
57551 +#ifdef LEAP_SUPPORT
57552 +BUILD_TIMER_FUNCTION(LeapAuthTimeout);
57553 +#endif
57554 +BUILD_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
57555 +BUILD_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
57556 +#ifdef QOS_DLS_SUPPORT
57557 +BUILD_TIMER_FUNCTION(DlsTimeoutAction);
57558 +#endif // QOS_DLS_SUPPORT //
57559 +#endif // CONFIG_STA_SUPPORT //
57560 +
57561 +// for wireless system event message
57562 +char const *pWirelessSysEventText[IW_SYS_EVENT_TYPE_NUM] = {
57563 + // system status event
57564 + "had associated successfully", /* IW_ASSOC_EVENT_FLAG */
57565 + "had disassociated", /* IW_DISASSOC_EVENT_FLAG */
57566 + "had deauthenticated", /* IW_DEAUTH_EVENT_FLAG */
57567 + "had been aged-out and disassociated", /* IW_AGEOUT_EVENT_FLAG */
57568 + "occurred CounterMeasures attack", /* IW_COUNTER_MEASURES_EVENT_FLAG */
57569 + "occurred replay counter different in Key Handshaking", /* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */
57570 + "occurred RSNIE different in Key Handshaking", /* IW_RSNIE_DIFF_EVENT_FLAG */
57571 + "occurred MIC different in Key Handshaking", /* IW_MIC_DIFF_EVENT_FLAG */
57572 + "occurred ICV error in RX", /* IW_ICV_ERROR_EVENT_FLAG */
57573 + "occurred MIC error in RX", /* IW_MIC_ERROR_EVENT_FLAG */
57574 + "Group Key Handshaking timeout", /* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */
57575 + "Pairwise Key Handshaking timeout", /* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */
57576 + "RSN IE sanity check failure", /* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */
57577 + "set key done in WPA/WPAPSK", /* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */
57578 + "set key done in WPA2/WPA2PSK", /* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */
57579 + "connects with our wireless client", /* IW_STA_LINKUP_EVENT_FLAG */
57580 + "disconnects with our wireless client", /* IW_STA_LINKDOWN_EVENT_FLAG */
57581 + "scan completed" /* IW_SCAN_COMPLETED_EVENT_FLAG */
57582 + "scan terminate!! Busy!! Enqueue fail!!" /* IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG */
57583 + };
57584 +
57585 +// for wireless IDS_spoof_attack event message
57586 +char const *pWirelessSpoofEventText[IW_SPOOF_EVENT_TYPE_NUM] = {
57587 + "detected conflict SSID", /* IW_CONFLICT_SSID_EVENT_FLAG */
57588 + "detected spoofed association response", /* IW_SPOOF_ASSOC_RESP_EVENT_FLAG */
57589 + "detected spoofed reassociation responses", /* IW_SPOOF_REASSOC_RESP_EVENT_FLAG */
57590 + "detected spoofed probe response", /* IW_SPOOF_PROBE_RESP_EVENT_FLAG */
57591 + "detected spoofed beacon", /* IW_SPOOF_BEACON_EVENT_FLAG */
57592 + "detected spoofed disassociation", /* IW_SPOOF_DISASSOC_EVENT_FLAG */
57593 + "detected spoofed authentication", /* IW_SPOOF_AUTH_EVENT_FLAG */
57594 + "detected spoofed deauthentication", /* IW_SPOOF_DEAUTH_EVENT_FLAG */
57595 + "detected spoofed unknown management frame", /* IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG */
57596 + "detected replay attack" /* IW_REPLAY_ATTACK_EVENT_FLAG */
57597 + };
57598 +
57599 +// for wireless IDS_flooding_attack event message
57600 +char const *pWirelessFloodEventText[IW_FLOOD_EVENT_TYPE_NUM] = {
57601 + "detected authentication flooding", /* IW_FLOOD_AUTH_EVENT_FLAG */
57602 + "detected association request flooding", /* IW_FLOOD_ASSOC_REQ_EVENT_FLAG */
57603 + "detected reassociation request flooding", /* IW_FLOOD_REASSOC_REQ_EVENT_FLAG */
57604 + "detected probe request flooding", /* IW_FLOOD_PROBE_REQ_EVENT_FLAG */
57605 + "detected disassociation flooding", /* IW_FLOOD_DISASSOC_EVENT_FLAG */
57606 + "detected deauthentication flooding", /* IW_FLOOD_DEAUTH_EVENT_FLAG */
57607 + "detected 802.1x eap-request flooding" /* IW_FLOOD_EAP_REQ_EVENT_FLAG */
57608 + };
57609 +
57610 +/* timeout -- ms */
57611 +VOID RTMP_SetPeriodicTimer(
57612 + IN NDIS_MINIPORT_TIMER *pTimer,
57613 + IN unsigned long timeout)
57614 +{
57615 + timeout = ((timeout*HZ) / 1000);
57616 + pTimer->expires = jiffies + timeout;
57617 + add_timer(pTimer);
57618 +}
57619 +
57620 +/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */
57621 +VOID RTMP_OS_Init_Timer(
57622 + IN PRTMP_ADAPTER pAd,
57623 + IN NDIS_MINIPORT_TIMER *pTimer,
57624 + IN TIMER_FUNCTION function,
57625 + IN PVOID data)
57626 +{
57627 + init_timer(pTimer);
57628 + pTimer->data = (unsigned long)data;
57629 + pTimer->function = function;
57630 +}
57631 +
57632 +
57633 +VOID RTMP_OS_Add_Timer(
57634 + IN NDIS_MINIPORT_TIMER *pTimer,
57635 + IN unsigned long timeout)
57636 +{
57637 + if (timer_pending(pTimer))
57638 + return;
57639 +
57640 + timeout = ((timeout*HZ) / 1000);
57641 + pTimer->expires = jiffies + timeout;
57642 + add_timer(pTimer);
57643 +}
57644 +
57645 +VOID RTMP_OS_Mod_Timer(
57646 + IN NDIS_MINIPORT_TIMER *pTimer,
57647 + IN unsigned long timeout)
57648 +{
57649 + timeout = ((timeout*HZ) / 1000);
57650 + mod_timer(pTimer, jiffies + timeout);
57651 +}
57652 +
57653 +VOID RTMP_OS_Del_Timer(
57654 + IN NDIS_MINIPORT_TIMER *pTimer,
57655 + OUT BOOLEAN *pCancelled)
57656 +{
57657 + if (timer_pending(pTimer))
57658 + {
57659 + *pCancelled = del_timer_sync(pTimer);
57660 + }
57661 + else
57662 + {
57663 + *pCancelled = TRUE;
57664 + }
57665 +
57666 +}
57667 +
57668 +VOID RTMP_OS_Release_Packet(
57669 + IN PRTMP_ADAPTER pAd,
57670 + IN PQUEUE_ENTRY pEntry)
57671 +{
57672 + //RTMPFreeNdisPacket(pAd, (struct sk_buff *)pEntry);
57673 +}
57674 +
57675 +// Unify all delay routine by using udelay
57676 +VOID RTMPusecDelay(
57677 + IN ULONG usec)
57678 +{
57679 + ULONG i;
57680 +
57681 + for (i = 0; i < (usec / 50); i++)
57682 + udelay(50);
57683 +
57684 + if (usec % 50)
57685 + udelay(usec % 50);
57686 +}
57687 +
57688 +void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time)
57689 +{
57690 + time->u.LowPart = jiffies;
57691 +}
57692 +
57693 +// pAd MUST allow to be NULL
57694 +NDIS_STATUS os_alloc_mem(
57695 + IN PRTMP_ADAPTER pAd,
57696 + OUT PUCHAR *mem,
57697 + IN ULONG size)
57698 +{
57699 + *mem = (PUCHAR) kmalloc(size, GFP_ATOMIC);
57700 + if (*mem)
57701 + return (NDIS_STATUS_SUCCESS);
57702 + else
57703 + return (NDIS_STATUS_FAILURE);
57704 +}
57705 +
57706 +// pAd MUST allow to be NULL
57707 +NDIS_STATUS os_free_mem(
57708 + IN PRTMP_ADAPTER pAd,
57709 + IN PUCHAR mem)
57710 +{
57711 +
57712 + ASSERT(mem);
57713 + kfree(mem);
57714 + return (NDIS_STATUS_SUCCESS);
57715 +}
57716 +
57717 +
57718 +PNDIS_PACKET RTMP_AllocateFragPacketBuffer(
57719 + IN PRTMP_ADAPTER pAd,
57720 + IN ULONG Length)
57721 +{
57722 + struct sk_buff *pkt;
57723 +
57724 + pkt = dev_alloc_skb(Length);
57725 +
57726 + if (pkt == NULL)
57727 + {
57728 + DBGPRINT(RT_DEBUG_ERROR, ("can't allocate frag rx %ld size packet\n",Length));
57729 + }
57730 +
57731 + if (pkt)
57732 + {
57733 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
57734 + }
57735 +
57736 + return (PNDIS_PACKET) pkt;
57737 +}
57738 +
57739 +
57740 +PNDIS_PACKET RTMP_AllocateTxPacketBuffer(
57741 + IN PRTMP_ADAPTER pAd,
57742 + IN ULONG Length,
57743 + IN BOOLEAN Cached,
57744 + OUT PVOID *VirtualAddress)
57745 +{
57746 + struct sk_buff *pkt;
57747 +
57748 + pkt = dev_alloc_skb(Length);
57749 +
57750 + if (pkt == NULL)
57751 + {
57752 + DBGPRINT(RT_DEBUG_ERROR, ("can't allocate tx %ld size packet\n",Length));
57753 + }
57754 +
57755 + if (pkt)
57756 + {
57757 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
57758 + *VirtualAddress = (PVOID) pkt->data;
57759 + }
57760 + else
57761 + {
57762 + *VirtualAddress = (PVOID) NULL;
57763 + }
57764 +
57765 + return (PNDIS_PACKET) pkt;
57766 +}
57767 +
57768 +
57769 +VOID build_tx_packet(
57770 + IN PRTMP_ADAPTER pAd,
57771 + IN PNDIS_PACKET pPacket,
57772 + IN PUCHAR pFrame,
57773 + IN ULONG FrameLen)
57774 +{
57775 +
57776 + struct sk_buff *pTxPkt;
57777 +
57778 + ASSERT(pPacket);
57779 + pTxPkt = RTPKT_TO_OSPKT(pPacket);
57780 +
57781 + NdisMoveMemory(skb_put(pTxPkt, FrameLen), pFrame, FrameLen);
57782 +}
57783 +
57784 +VOID RTMPFreeAdapter(
57785 + IN PRTMP_ADAPTER pAd)
57786 +{
57787 + POS_COOKIE os_cookie;
57788 + int index;
57789 +
57790 + os_cookie=(POS_COOKIE)pAd->OS_Cookie;
57791 +
57792 + kfree(pAd->BeaconBuf);
57793 +
57794 +
57795 + NdisFreeSpinLock(&pAd->MgmtRingLock);
57796 +
57797 +
57798 + for (index =0 ; index < NUM_OF_TX_RING; index++)
57799 + {
57800 + NdisFreeSpinLock(&pAd->TxSwQueueLock[index]);
57801 + NdisFreeSpinLock(&pAd->DeQueueLock[index]);
57802 + pAd->DeQueueRunning[index] = FALSE;
57803 + }
57804 +
57805 + NdisFreeSpinLock(&pAd->irq_lock);
57806 +
57807 +
57808 + vfree(pAd); // pci_free_consistent(os_cookie->pci_dev,sizeof(RTMP_ADAPTER),pAd,os_cookie->pAd_pa);
57809 + kfree(os_cookie);
57810 +}
57811 +
57812 +BOOLEAN OS_Need_Clone_Packet(void)
57813 +{
57814 + return (FALSE);
57815 +}
57816 +
57817 +
57818 +
57819 +/*
57820 + ========================================================================
57821 +
57822 + Routine Description:
57823 + clone an input NDIS PACKET to another one. The new internally created NDIS PACKET
57824 + must have only one NDIS BUFFER
57825 + return - byte copied. 0 means can't create NDIS PACKET
57826 + NOTE: internally created NDIS_PACKET should be destroyed by RTMPFreeNdisPacket
57827 +
57828 + Arguments:
57829 + pAd Pointer to our adapter
57830 + pInsAMSDUHdr EWC A-MSDU format has extra 14-bytes header. if TRUE, insert this 14-byte hdr in front of MSDU.
57831 + *pSrcTotalLen return total packet length. This lenght is calculated with 802.3 format packet.
57832 +
57833 + Return Value:
57834 + NDIS_STATUS_SUCCESS
57835 + NDIS_STATUS_FAILURE
57836 +
57837 + Note:
57838 +
57839 + ========================================================================
57840 +*/
57841 +NDIS_STATUS RTMPCloneNdisPacket(
57842 + IN PRTMP_ADAPTER pAd,
57843 + IN BOOLEAN pInsAMSDUHdr,
57844 + IN PNDIS_PACKET pInPacket,
57845 + OUT PNDIS_PACKET *ppOutPacket)
57846 +{
57847 +
57848 + struct sk_buff *pkt;
57849 +
57850 + ASSERT(pInPacket);
57851 + ASSERT(ppOutPacket);
57852 +
57853 + // 1. Allocate a packet
57854 + pkt = dev_alloc_skb(2048);
57855 +
57856 + if (pkt == NULL)
57857 + {
57858 + return NDIS_STATUS_FAILURE;
57859 + }
57860 +
57861 + skb_put(pkt, GET_OS_PKT_LEN(pInPacket));
57862 + NdisMoveMemory(pkt->data, GET_OS_PKT_DATAPTR(pInPacket), GET_OS_PKT_LEN(pInPacket));
57863 + *ppOutPacket = OSPKT_TO_RTPKT(pkt);
57864 +
57865 +
57866 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
57867 +
57868 + printk("###Clone###\n");
57869 +
57870 + return NDIS_STATUS_SUCCESS;
57871 +}
57872 +
57873 +
57874 +// the allocated NDIS PACKET must be freed via RTMPFreeNdisPacket()
57875 +NDIS_STATUS RTMPAllocateNdisPacket(
57876 + IN PRTMP_ADAPTER pAd,
57877 + OUT PNDIS_PACKET *ppPacket,
57878 + IN PUCHAR pHeader,
57879 + IN UINT HeaderLen,
57880 + IN PUCHAR pData,
57881 + IN UINT DataLen)
57882 +{
57883 + PNDIS_PACKET pPacket;
57884 + ASSERT(pData);
57885 + ASSERT(DataLen);
57886 +
57887 + // 1. Allocate a packet
57888 + pPacket = (PNDIS_PACKET *) dev_alloc_skb(HeaderLen + DataLen + TXPADDING_SIZE);
57889 + if (pPacket == NULL)
57890 + {
57891 + *ppPacket = NULL;
57892 +#ifdef DEBUG
57893 + printk("RTMPAllocateNdisPacket Fail\n\n");
57894 +#endif
57895 + return NDIS_STATUS_FAILURE;
57896 + }
57897 +
57898 + // 2. clone the frame content
57899 + if (HeaderLen > 0)
57900 + NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket), pHeader, HeaderLen);
57901 + if (DataLen > 0)
57902 + NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket) + HeaderLen, pData, DataLen);
57903 +
57904 + // 3. update length of packet
57905 + skb_put(GET_OS_PKT_TYPE(pPacket), HeaderLen+DataLen);
57906 +
57907 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
57908 +// printk("%s : pPacket = %p, len = %d\n", __FUNCTION__, pPacket, GET_OS_PKT_LEN(pPacket));
57909 + *ppPacket = pPacket;
57910 + return NDIS_STATUS_SUCCESS;
57911 +}
57912 +
57913 +/*
57914 + ========================================================================
57915 + Description:
57916 + This routine frees a miniport internally allocated NDIS_PACKET and its
57917 + corresponding NDIS_BUFFER and allocated memory.
57918 + ========================================================================
57919 +*/
57920 +VOID RTMPFreeNdisPacket(
57921 + IN PRTMP_ADAPTER pAd,
57922 + IN PNDIS_PACKET pPacket)
57923 +{
57924 + dev_kfree_skb_any(RTPKT_TO_OSPKT(pPacket));
57925 +}
57926 +
57927 +
57928 +// IRQL = DISPATCH_LEVEL
57929 +// NOTE: we do have an assumption here, that Byte0 and Byte1 always reasid at the same
57930 +// scatter gather buffer
57931 +NDIS_STATUS Sniff2BytesFromNdisBuffer(
57932 + IN PNDIS_BUFFER pFirstBuffer,
57933 + IN UCHAR DesiredOffset,
57934 + OUT PUCHAR pByte0,
57935 + OUT PUCHAR pByte1)
57936 +{
57937 + *pByte0 = *(PUCHAR)(pFirstBuffer + DesiredOffset);
57938 + *pByte1 = *(PUCHAR)(pFirstBuffer + DesiredOffset + 1);
57939 +
57940 + return NDIS_STATUS_SUCCESS;
57941 +}
57942 +
57943 +
57944 +void RTMP_QueryPacketInfo(
57945 + IN PNDIS_PACKET pPacket,
57946 + OUT PACKET_INFO *pPacketInfo,
57947 + OUT PUCHAR *pSrcBufVA,
57948 + OUT UINT *pSrcBufLen)
57949 +{
57950 + pPacketInfo->BufferCount = 1;
57951 + pPacketInfo->pFirstBuffer = GET_OS_PKT_DATAPTR(pPacket);
57952 + pPacketInfo->PhysicalBufferCount = 1;
57953 + pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
57954 +
57955 + *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
57956 + *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
57957 +}
57958 +
57959 +void RTMP_QueryNextPacketInfo(
57960 + IN PNDIS_PACKET *ppPacket,
57961 + OUT PACKET_INFO *pPacketInfo,
57962 + OUT PUCHAR *pSrcBufVA,
57963 + OUT UINT *pSrcBufLen)
57964 +{
57965 + PNDIS_PACKET pPacket = NULL;
57966 +
57967 + if (*ppPacket)
57968 + pPacket = GET_OS_PKT_NEXT(*ppPacket);
57969 +
57970 + if (pPacket)
57971 + {
57972 + pPacketInfo->BufferCount = 1;
57973 + pPacketInfo->pFirstBuffer = GET_OS_PKT_DATAPTR(pPacket);
57974 + pPacketInfo->PhysicalBufferCount = 1;
57975 + pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
57976 +
57977 + *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
57978 + *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
57979 + *ppPacket = GET_OS_PKT_NEXT(pPacket);
57980 + }
57981 + else
57982 + {
57983 + pPacketInfo->BufferCount = 0;
57984 + pPacketInfo->pFirstBuffer = NULL;
57985 + pPacketInfo->PhysicalBufferCount = 0;
57986 + pPacketInfo->TotalPacketLength = 0;
57987 +
57988 + *pSrcBufVA = NULL;
57989 + *pSrcBufLen = 0;
57990 + *ppPacket = NULL;
57991 + }
57992 +}
57993 +
57994 +// not yet support MBSS
57995 +PNET_DEV get_netdev_from_bssid(
57996 + IN PRTMP_ADAPTER pAd,
57997 + IN UCHAR FromWhichBSSID)
57998 +{
57999 + PNET_DEV dev_p = NULL;
58000 +
58001 +
58002 +#ifdef CONFIG_STA_SUPPORT
58003 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
58004 + {
58005 + dev_p = pAd->net_dev;
58006 + }
58007 +#endif // CONFIG_STA_SUPPORT //
58008 +
58009 + ASSERT(dev_p);
58010 + return dev_p; /* return one of MBSS */
58011 +}
58012 +
58013 +PNDIS_PACKET DuplicatePacket(
58014 + IN PRTMP_ADAPTER pAd,
58015 + IN PNDIS_PACKET pPacket,
58016 + IN UCHAR FromWhichBSSID)
58017 +{
58018 + struct sk_buff *skb;
58019 + PNDIS_PACKET pRetPacket = NULL;
58020 + USHORT DataSize;
58021 + UCHAR *pData;
58022 +
58023 + DataSize = (USHORT) GET_OS_PKT_LEN(pPacket);
58024 + pData = (PUCHAR) GET_OS_PKT_DATAPTR(pPacket);
58025 +
58026 +
58027 + skb = skb_clone(RTPKT_TO_OSPKT(pPacket), MEM_ALLOC_FLAG);
58028 + if (skb)
58029 + {
58030 + skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58031 + pRetPacket = OSPKT_TO_RTPKT(skb);
58032 + }
58033 +
58034 +#if 0
58035 + if ((skb = __dev_alloc_skb(DataSize + 2+32, MEM_ALLOC_FLAG)) != NULL)
58036 + {
58037 + skb_reserve(skb, 2+32);
58038 + NdisMoveMemory(skb->tail, pData, DataSize);
58039 + skb_put(skb, DataSize);
58040 + skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58041 + pRetPacket = OSPKT_TO_RTPKT(skb);
58042 + }
58043 +#endif
58044 +
58045 + return pRetPacket;
58046 +
58047 +}
58048 +
58049 +PNDIS_PACKET duplicate_pkt(
58050 + IN PRTMP_ADAPTER pAd,
58051 + IN PUCHAR pHeader802_3,
58052 + IN UINT HdrLen,
58053 + IN PUCHAR pData,
58054 + IN ULONG DataSize,
58055 + IN UCHAR FromWhichBSSID)
58056 +{
58057 + struct sk_buff *skb;
58058 + PNDIS_PACKET pPacket = NULL;
58059 +
58060 +
58061 + if ((skb = __dev_alloc_skb(HdrLen + DataSize + 2, MEM_ALLOC_FLAG)) != NULL)
58062 + {
58063 + skb_reserve(skb, 2);
58064 + NdisMoveMemory(skb->tail, pHeader802_3, HdrLen);
58065 + skb_put(skb, HdrLen);
58066 + NdisMoveMemory(skb->tail, pData, DataSize);
58067 + skb_put(skb, DataSize);
58068 + skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58069 + pPacket = OSPKT_TO_RTPKT(skb);
58070 + }
58071 +
58072 + return pPacket;
58073 +}
58074 +
58075 +
58076 +#define TKIP_TX_MIC_SIZE 8
58077 +PNDIS_PACKET duplicate_pkt_with_TKIP_MIC(
58078 + IN PRTMP_ADAPTER pAd,
58079 + IN PNDIS_PACKET pPacket)
58080 +{
58081 + struct sk_buff *skb, *newskb;
58082 +
58083 +
58084 + skb = RTPKT_TO_OSPKT(pPacket);
58085 + if (skb_tailroom(skb) < TKIP_TX_MIC_SIZE)
58086 + {
58087 + // alloc a new skb and copy the packet
58088 + newskb = skb_copy_expand(skb, skb_headroom(skb), TKIP_TX_MIC_SIZE, GFP_ATOMIC);
58089 + dev_kfree_skb_any(skb);
58090 + if (newskb == NULL)
58091 + {
58092 + DBGPRINT(RT_DEBUG_ERROR, ("Extend Tx.MIC for packet failed!, dropping packet!\n"));
58093 + return NULL;
58094 + }
58095 + skb = newskb;
58096 + }
58097 +
58098 + return OSPKT_TO_RTPKT(skb);
58099 +
58100 +#if 0
58101 + if ((data = skb_put(skb, TKIP_TX_MIC_SIZE)) != NULL)
58102 + { // If we can extend it, well, copy it first.
58103 + NdisMoveMemory(data, pAd->PrivateInfo.Tx.MIC, TKIP_TX_MIC_SIZE);
58104 + }
58105 + else
58106 + {
58107 + // Otherwise, copy the packet.
58108 + newskb = skb_copy_expand(skb, skb_headroom(skb), TKIP_TX_MIC_SIZE, GFP_ATOMIC);
58109 + dev_kfree_skb_any(skb);
58110 + if (newskb == NULL)
58111 + {
58112 + DBGPRINT(RT_DEBUG_ERROR, ("Extend Tx.MIC to packet failed!, dropping packet\n"));
58113 + return NULL;
58114 + }
58115 + skb = newskb;
58116 +
58117 + NdisMoveMemory(skb->tail, pAd->PrivateInfo.Tx.MIC, TKIP_TX_MIC_SIZE);
58118 + skb_put(skb, TKIP_TX_MIC_SIZE);
58119 + }
58120 +
58121 + return OSPKT_TO_RTPKT(skb);
58122 +#endif
58123 +
58124 +}
58125 +
58126 +
58127 +
58128 +
58129 +PNDIS_PACKET ClonePacket(
58130 + IN PRTMP_ADAPTER pAd,
58131 + IN PNDIS_PACKET pPacket,
58132 + IN PUCHAR pData,
58133 + IN ULONG DataSize)
58134 +{
58135 + struct sk_buff *pRxPkt;
58136 + struct sk_buff *pClonedPkt;
58137 +
58138 + ASSERT(pPacket);
58139 + pRxPkt = RTPKT_TO_OSPKT(pPacket);
58140 +
58141 + // clone the packet
58142 + pClonedPkt = skb_clone(pRxPkt, MEM_ALLOC_FLAG);
58143 +
58144 + if (pClonedPkt)
58145 + {
58146 + // set the correct dataptr and data len
58147 + pClonedPkt->dev = pRxPkt->dev;
58148 + pClonedPkt->data = pData;
58149 + pClonedPkt->len = DataSize;
58150 + pClonedPkt->tail = pClonedPkt->data + pClonedPkt->len;
58151 + ASSERT(DataSize < 1530);
58152 + }
58153 + return pClonedPkt;
58154 +}
58155 +
58156 +//
58157 +// change OS packet DataPtr and DataLen
58158 +//
58159 +void update_os_packet_info(
58160 + IN PRTMP_ADAPTER pAd,
58161 + IN RX_BLK *pRxBlk,
58162 + IN UCHAR FromWhichBSSID)
58163 +{
58164 + struct sk_buff *pOSPkt;
58165 +
58166 + ASSERT(pRxBlk->pRxPacket);
58167 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
58168 +
58169 + pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58170 + pOSPkt->data = pRxBlk->pData;
58171 + pOSPkt->len = pRxBlk->DataSize;
58172 + pOSPkt->tail = pOSPkt->data + pOSPkt->len;
58173 +}
58174 +
58175 +
58176 +void wlan_802_11_to_802_3_packet(
58177 + IN PRTMP_ADAPTER pAd,
58178 + IN RX_BLK *pRxBlk,
58179 + IN PUCHAR pHeader802_3,
58180 + IN UCHAR FromWhichBSSID)
58181 +{
58182 + struct sk_buff *pOSPkt;
58183 +
58184 + ASSERT(pRxBlk->pRxPacket);
58185 + ASSERT(pHeader802_3);
58186 +
58187 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
58188 +
58189 + pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58190 + pOSPkt->data = pRxBlk->pData;
58191 + pOSPkt->len = pRxBlk->DataSize;
58192 + pOSPkt->tail = pOSPkt->data + pOSPkt->len;
58193 +
58194 + //
58195 + // copy 802.3 header
58196 + //
58197 + //
58198 +
58199 +#ifdef CONFIG_STA_SUPPORT
58200 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
58201 + NdisMoveMemory(skb_push(pOSPkt, LENGTH_802_3), pHeader802_3, LENGTH_802_3);
58202 +#endif // CONFIG_STA_SUPPORT //
58203 + }
58204 +
58205 +
58206 +
58207 +void announce_802_3_packet(
58208 + IN PRTMP_ADAPTER pAd,
58209 + IN PNDIS_PACKET pPacket)
58210 +{
58211 +
58212 + struct sk_buff *pRxPkt;
58213 +
58214 + ASSERT(pPacket);
58215 +
58216 + pRxPkt = RTPKT_TO_OSPKT(pPacket);
58217 +
58218 +#ifdef CONFIG_STA_SUPPORT
58219 +#endif // CONFIG_STA_SUPPORT //
58220 +
58221 + /* Push up the protocol stack */
58222 +#ifdef IKANOS_VX_1X0
58223 + IKANOS_DataFrameRx(pAd, pRxPkt->dev, pRxPkt, pRxPkt->len);
58224 +#else
58225 + pRxPkt->protocol = eth_type_trans(pRxPkt, pRxPkt->dev);
58226 +
58227 +//#ifdef CONFIG_5VT_ENHANCE
58228 +// *(int*)(pRxPkt->cb) = BRIDGE_TAG;
58229 +//#endif
58230 + netif_rx(pRxPkt);
58231 +#endif // IKANOS_VX_1X0 //
58232 +}
58233 +
58234 +
58235 +PRTMP_SCATTER_GATHER_LIST
58236 +rt_get_sg_list_from_packet(PNDIS_PACKET pPacket, RTMP_SCATTER_GATHER_LIST *sg)
58237 +{
58238 + sg->NumberOfElements = 1;
58239 + sg->Elements[0].Address = GET_OS_PKT_DATAPTR(pPacket);
58240 + sg->Elements[0].Length = GET_OS_PKT_LEN(pPacket);
58241 + return (sg);
58242 +}
58243 +
58244 +void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen)
58245 +{
58246 + unsigned char *pt;
58247 + int x;
58248 +
58249 + if (RTDebugLevel < RT_DEBUG_TRACE)
58250 + return;
58251 +
58252 + pt = pSrcBufVA;
58253 + printk("%s: %p, len = %d\n",str, pSrcBufVA, SrcBufLen);
58254 + for (x=0; x<SrcBufLen; x++)
58255 + {
58256 + if (x % 16 == 0)
58257 + printk("0x%04x : ", x);
58258 + printk("%02x ", ((unsigned char)pt[x]));
58259 + if (x%16 == 15) printk("\n");
58260 + }
58261 + printk("\n");
58262 +}
58263 +
58264 +/*
58265 + ========================================================================
58266 +
58267 + Routine Description:
58268 + Send log message through wireless event
58269 +
58270 + Support standard iw_event with IWEVCUSTOM. It is used below.
58271 +
58272 + iwreq_data.data.flags is used to store event_flag that is defined by user.
58273 + iwreq_data.data.length is the length of the event log.
58274 +
58275 + The format of the event log is composed of the entry's MAC address and
58276 + the desired log message (refer to pWirelessEventText).
58277 +
58278 + ex: 11:22:33:44:55:66 has associated successfully
58279 +
58280 + p.s. The requirement of Wireless Extension is v15 or newer.
58281 +
58282 + ========================================================================
58283 +*/
58284 +VOID RTMPSendWirelessEvent(
58285 + IN PRTMP_ADAPTER pAd,
58286 + IN USHORT Event_flag,
58287 + IN PUCHAR pAddr,
58288 + IN UCHAR BssIdx,
58289 + IN CHAR Rssi)
58290 +{
58291 +#if WIRELESS_EXT >= 15
58292 +
58293 + union iwreq_data wrqu;
58294 + PUCHAR pBuf = NULL, pBufPtr = NULL;
58295 + USHORT event, type, BufLen;
58296 + UCHAR event_table_len = 0;
58297 +
58298 + type = Event_flag & 0xFF00;
58299 + event = Event_flag & 0x00FF;
58300 +
58301 + switch (type)
58302 + {
58303 + case IW_SYS_EVENT_FLAG_START:
58304 + event_table_len = IW_SYS_EVENT_TYPE_NUM;
58305 + break;
58306 +
58307 + case IW_SPOOF_EVENT_FLAG_START:
58308 + event_table_len = IW_SPOOF_EVENT_TYPE_NUM;
58309 + break;
58310 +
58311 + case IW_FLOOD_EVENT_FLAG_START:
58312 + event_table_len = IW_FLOOD_EVENT_TYPE_NUM;
58313 + break;
58314 + }
58315 +
58316 + if (event_table_len == 0)
58317 + {
58318 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The type(%0x02x) is not valid.\n", __FUNCTION__, type));
58319 + return;
58320 + }
58321 +
58322 + if (event >= event_table_len)
58323 + {
58324 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The event(%0x02x) is not valid.\n", __FUNCTION__, event));
58325 + return;
58326 + }
58327 +
58328 + //Allocate memory and copy the msg.
58329 + if((pBuf = kmalloc(IW_CUSTOM_MAX_LEN, GFP_ATOMIC)) != NULL)
58330 + {
58331 + //Prepare the payload
58332 + memset(pBuf, 0, IW_CUSTOM_MAX_LEN);
58333 +
58334 + pBufPtr = pBuf;
58335 +
58336 + if (pAddr)
58337 + pBufPtr += sprintf(pBufPtr, "(RT2860) STA(%02x:%02x:%02x:%02x:%02x:%02x) ", PRINT_MAC(pAddr));
58338 + else if (BssIdx < MAX_MBSSID_NUM)
58339 + pBufPtr += sprintf(pBufPtr, "(RT2860) BSS(ra%d) ", BssIdx);
58340 + else
58341 + pBufPtr += sprintf(pBufPtr, "(RT2860) ");
58342 +
58343 + if (type == IW_SYS_EVENT_FLAG_START)
58344 + pBufPtr += sprintf(pBufPtr, "%s", pWirelessSysEventText[event]);
58345 + else if (type == IW_SPOOF_EVENT_FLAG_START)
58346 + pBufPtr += sprintf(pBufPtr, "%s (RSSI=%d)", pWirelessSpoofEventText[event], Rssi);
58347 + else if (type == IW_FLOOD_EVENT_FLAG_START)
58348 + pBufPtr += sprintf(pBufPtr, "%s", pWirelessFloodEventText[event]);
58349 + else
58350 + pBufPtr += sprintf(pBufPtr, "%s", "unknown event");
58351 +
58352 + pBufPtr[pBufPtr - pBuf] = '\0';
58353 + BufLen = pBufPtr - pBuf;
58354 +
58355 + memset(&wrqu, 0, sizeof(wrqu));
58356 + wrqu.data.flags = Event_flag;
58357 + wrqu.data.length = BufLen;
58358 +
58359 + //send wireless event
58360 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, pBuf);
58361 +
58362 + //DBGPRINT(RT_DEBUG_TRACE, ("%s : %s\n", __FUNCTION__, pBuf));
58363 +
58364 + kfree(pBuf);
58365 + }
58366 + else
58367 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Can't allocate memory for wireless event.\n", __FUNCTION__));
58368 +#else
58369 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The Wireless Extension MUST be v15 or newer.\n", __FUNCTION__));
58370 +#endif /* WIRELESS_EXT >= 15 */
58371 +}
58372 +
58373 +
58374 +#ifdef CONFIG_STA_SUPPORT
58375 +void send_monitor_packets(
58376 + IN PRTMP_ADAPTER pAd,
58377 + IN RX_BLK *pRxBlk)
58378 +{
58379 + struct sk_buff *pOSPkt;
58380 + wlan_ng_prism2_header *ph;
58381 + int rate_index = 0;
58382 + USHORT header_len = 0;
58383 + UCHAR temp_header[40] = {0};
58384 +
58385 + 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
58386 + 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,
58387 + 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};
58388 +
58389 +
58390 + ASSERT(pRxBlk->pRxPacket);
58391 + if (pRxBlk->DataSize < 10)
58392 + {
58393 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Size is too small! (%d)\n", __FUNCTION__, pRxBlk->DataSize));
58394 + goto err_free_sk_buff;
58395 + }
58396 +
58397 + if (pRxBlk->DataSize + sizeof(wlan_ng_prism2_header) > RX_BUFFER_AGGRESIZE)
58398 + {
58399 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Size is too large! (%d)\n", __FUNCTION__, pRxBlk->DataSize + sizeof(wlan_ng_prism2_header)));
58400 + goto err_free_sk_buff;
58401 + }
58402 +
58403 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
58404 + pOSPkt->dev = get_netdev_from_bssid(pAd, BSS0);
58405 + if (pRxBlk->pHeader->FC.Type == BTYPE_DATA)
58406 + {
58407 + pRxBlk->DataSize -= LENGTH_802_11;
58408 + if ((pRxBlk->pHeader->FC.ToDs == 1) &&
58409 + (pRxBlk->pHeader->FC.FrDs == 1))
58410 + header_len = LENGTH_802_11_WITH_ADDR4;
58411 + else
58412 + header_len = LENGTH_802_11;
58413 +
58414 + // QOS
58415 + if (pRxBlk->pHeader->FC.SubType & 0x08)
58416 + {
58417 + header_len += 2;
58418 + // Data skip QOS contorl field
58419 + pRxBlk->DataSize -=2;
58420 + }
58421 +
58422 + // Order bit: A-Ralink or HTC+
58423 + if (pRxBlk->pHeader->FC.Order)
58424 + {
58425 + header_len += 4;
58426 + // Data skip HTC contorl field
58427 + pRxBlk->DataSize -= 4;
58428 + }
58429 +
58430 + // Copy Header
58431 + if (header_len <= 40)
58432 + NdisMoveMemory(temp_header, pRxBlk->pData, header_len);
58433 +
58434 + // skip HW padding
58435 + if (pRxBlk->RxD.L2PAD)
58436 + pRxBlk->pData += (header_len + 2);
58437 + else
58438 + pRxBlk->pData += header_len;
58439 + } //end if
58440 +
58441 +
58442 + if (pRxBlk->DataSize < pOSPkt->len) {
58443 + skb_trim(pOSPkt,pRxBlk->DataSize);
58444 + } else {
58445 + skb_put(pOSPkt,(pRxBlk->DataSize - pOSPkt->len));
58446 + } //end if
58447 +
58448 + if ((pRxBlk->pData - pOSPkt->data) > 0) {
58449 + skb_put(pOSPkt,(pRxBlk->pData - pOSPkt->data));
58450 + skb_pull(pOSPkt,(pRxBlk->pData - pOSPkt->data));
58451 + } //end if
58452 +
58453 + if (skb_headroom(pOSPkt) < (sizeof(wlan_ng_prism2_header)+ header_len)) {
58454 + if (pskb_expand_head(pOSPkt, (sizeof(wlan_ng_prism2_header) + header_len), 0, GFP_ATOMIC)) {
58455 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Reallocate header size of sk_buff fail!\n", __FUNCTION__));
58456 + goto err_free_sk_buff;
58457 + } //end if
58458 + } //end if
58459 +
58460 + if (header_len > 0)
58461 + NdisMoveMemory(skb_push(pOSPkt, header_len), temp_header, header_len);
58462 +
58463 + ph = (wlan_ng_prism2_header *) skb_push(pOSPkt, sizeof(wlan_ng_prism2_header));
58464 + NdisZeroMemory(ph, sizeof(wlan_ng_prism2_header));
58465 +
58466 + ph->msgcode = DIDmsg_lnxind_wlansniffrm;
58467 + ph->msglen = sizeof(wlan_ng_prism2_header);
58468 + strcpy(ph->devname, pAd->net_dev->name);
58469 +
58470 + ph->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime;
58471 + ph->hosttime.status = 0;
58472 + ph->hosttime.len = 4;
58473 + ph->hosttime.data = jiffies;
58474 +
58475 + ph->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime;
58476 + ph->mactime.status = 0;
58477 + ph->mactime.len = 0;
58478 + ph->mactime.data = 0;
58479 +
58480 + ph->istx.did = DIDmsg_lnxind_wlansniffrm_istx;
58481 + ph->istx.status = 0;
58482 + ph->istx.len = 0;
58483 + ph->istx.data = 0;
58484 +
58485 + ph->channel.did = DIDmsg_lnxind_wlansniffrm_channel;
58486 + ph->channel.status = 0;
58487 + ph->channel.len = 4;
58488 +
58489 + ph->channel.data = (u_int32_t)pAd->CommonCfg.Channel;
58490 +
58491 + ph->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi;
58492 + ph->rssi.status = 0;
58493 + ph->rssi.len = 4;
58494 + 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));;
58495 +
58496 + ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal;
58497 + ph->signal.status = 0;
58498 + ph->signal.len = 4;
58499 + ph->signal.data = 0; //rssi + noise;
58500 +
58501 + ph->noise.did = DIDmsg_lnxind_wlansniffrm_noise;
58502 + ph->noise.status = 0;
58503 + ph->noise.len = 4;
58504 + ph->noise.data = 0;
58505 +
58506 +#ifdef DOT11_N_SUPPORT
58507 + if (pRxBlk->pRxWI->PHYMODE >= MODE_HTMIX)
58508 + {
58509 + rate_index = 16 + ((UCHAR)pRxBlk->pRxWI->BW *16) + ((UCHAR)pRxBlk->pRxWI->ShortGI *32) + ((UCHAR)pRxBlk->pRxWI->MCS);
58510 + }
58511 + else
58512 +#endif // DOT11_N_SUPPORT //
58513 + if (pRxBlk->pRxWI->PHYMODE == MODE_OFDM)
58514 + rate_index = (UCHAR)(pRxBlk->pRxWI->MCS) + 4;
58515 + else
58516 + rate_index = (UCHAR)(pRxBlk->pRxWI->MCS);
58517 + if (rate_index < 0)
58518 + rate_index = 0;
58519 + if (rate_index > 255)
58520 + rate_index = 255;
58521 +
58522 + ph->rate.did = DIDmsg_lnxind_wlansniffrm_rate;
58523 + ph->rate.status = 0;
58524 + ph->rate.len = 4;
58525 + ph->rate.data = ralinkrate[rate_index];
58526 +
58527 + ph->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen;
58528 + ph->frmlen.status = 0;
58529 + ph->frmlen.len = 4;
58530 + ph->frmlen.data = (u_int32_t)pRxBlk->DataSize;
58531 +
58532 +
58533 + pOSPkt->pkt_type = PACKET_OTHERHOST;
58534 + pOSPkt->protocol = eth_type_trans(pOSPkt, pOSPkt->dev);
58535 + pOSPkt->ip_summed = CHECKSUM_NONE;
58536 + netif_rx(pOSPkt);
58537 +
58538 + return;
58539 +
58540 +err_free_sk_buff:
58541 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
58542 + return;
58543 +
58544 +}
58545 +#endif // CONFIG_STA_SUPPORT //
58546 +
58547 +
58548 +void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify)
58549 +{
58550 +
58551 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
58552 + daemonize(pThreadName /*"%s",pAd->net_dev->name*/);
58553 +
58554 + allow_signal(SIGTERM);
58555 + allow_signal(SIGKILL);
58556 + current->flags |= PF_NOFREEZE;
58557 +#else
58558 + unsigned long flags;
58559 +
58560 + daemonize();
58561 + reparent_to_init();
58562 + strcpy(current->comm, pThreadName);
58563 +
58564 + siginitsetinv(&current->blocked, sigmask(SIGTERM) | sigmask(SIGKILL));
58565 +
58566 + /* Allow interception of SIGKILL only
58567 + * Don't allow other signals to interrupt the transmission */
58568 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22)
58569 + spin_lock_irqsave(&current->sigmask_lock, flags);
58570 + flush_signals(current);
58571 + recalc_sigpending(current);
58572 + spin_unlock_irqrestore(&current->sigmask_lock, flags);
58573 +#endif
58574 +#endif
58575 +
58576 + /* signal that we've started the thread */
58577 + complete(pNotify);
58578 +
58579 +}
58580 +
58581 +void RTMP_IndicateMediaState(
58582 + IN PRTMP_ADAPTER pAd)
58583 +{
58584 + if (pAd->CommonCfg.bWirelessEvent)
58585 + {
58586 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
58587 + {
58588 + RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
58589 + }
58590 + else
58591 + {
58592 + RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
58593 + }
58594 + }
58595 +}
58596 +
58597 --- /dev/null
58598 +++ b/drivers/staging/rt2870/rt_linux.h
58599 @@ -0,0 +1,908 @@
58600 +/*
58601 + *************************************************************************
58602 + * Ralink Tech Inc.
58603 + * 5F., No.36, Taiyuan St., Jhubei City,
58604 + * Hsinchu County 302,
58605 + * Taiwan, R.O.C.
58606 + *
58607 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
58608 + *
58609 + * This program is free software; you can redistribute it and/or modify *
58610 + * it under the terms of the GNU General Public License as published by *
58611 + * the Free Software Foundation; either version 2 of the License, or *
58612 + * (at your option) any later version. *
58613 + * *
58614 + * This program is distributed in the hope that it will be useful, *
58615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
58616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
58617 + * GNU General Public License for more details. *
58618 + * *
58619 + * You should have received a copy of the GNU General Public License *
58620 + * along with this program; if not, write to the *
58621 + * Free Software Foundation, Inc., *
58622 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
58623 + * *
58624 + *************************************************************************
58625 + */
58626 +
58627 +/***********************************************************************/
58628 +/* */
58629 +/* Program: rt_linux.c */
58630 +/* Created: 4/21/2006 1:17:38 PM */
58631 +/* Author: Wu Xi-Kun */
58632 +/* Comments: `description` */
58633 +/* */
58634 +/*---------------------------------------------------------------------*/
58635 +/* */
58636 +/* History: */
58637 +/* Revision 1.1 4/21/2006 1:17:38 PM xsikun */
58638 +/* Initial revision */
58639 +/* */
58640 +/***********************************************************************/
58641 +
58642 +#include "rtmp_type.h"
58643 +#include <linux/module.h>
58644 +#include <linux/version.h>
58645 +#include <linux/kernel.h>
58646 +
58647 +#include <linux/spinlock.h>
58648 +#include <linux/init.h>
58649 +#include <linux/string.h>
58650 +#include <linux/timer.h>
58651 +#include <linux/errno.h>
58652 +#include <linux/slab.h>
58653 +#include <linux/interrupt.h>
58654 +#include <linux/pci.h>
58655 +#include <linux/netdevice.h>
58656 +#include <linux/etherdevice.h>
58657 +#include <linux/skbuff.h>
58658 +#include <linux/ethtool.h>
58659 +#include <linux/wireless.h>
58660 +#include <linux/proc_fs.h>
58661 +#include <linux/delay.h>
58662 +#include <linux/if_arp.h>
58663 +#include <linux/ctype.h>
58664 +#include <linux/vmalloc.h>
58665 +
58666 +
58667 +#include <linux/wireless.h>
58668 +#include <net/iw_handler.h>
58669 +
58670 +// load firmware
58671 +#define __KERNEL_SYSCALLS__
58672 +#include <linux/unistd.h>
58673 +#include <asm/uaccess.h>
58674 +
58675 +
58676 +#define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
58677 +
58678 +#ifndef IFNAMSIZ
58679 +#define IFNAMSIZ 16
58680 +#endif
58681 +
58682 +//#define CONFIG_CKIP_SUPPORT
58683 +
58684 +#undef __inline
58685 +#define __inline static inline
58686 +
58687 +typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
58688 +
58689 +// add by kathy
58690 +
58691 +#ifdef CONFIG_STA_SUPPORT
58692 +
58693 +#ifdef RT2870
58694 +#define STA_PROFILE_PATH "/etc/Wireless/RT2870STA/RT2870STA.dat"
58695 +#define STA_RT2870_IMAGE_FILE_NAME "/etc/Wireless/RT2870STA/rt2870.bin"
58696 +#define STA_NIC_DEVICE_NAME "RT2870STA"
58697 +#define STA_DRIVER_VERSION "1.4.0.0"
58698 +#ifdef MULTIPLE_CARD_SUPPORT
58699 +#define CARD_INFO_PATH "/etc/Wireless/RT2870STA/RT2870STACard.dat"
58700 +#endif // MULTIPLE_CARD_SUPPORT //
58701 +#endif // RT2870 //
58702 +
58703 +#endif // CONFIG_STA_SUPPORT //
58704 +
58705 +
58706 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
58707 +
58708 +#define RTMP_TIME_AFTER(a,b) \
58709 + (typecheck(unsigned long, (unsigned long)a) && \
58710 + typecheck(unsigned long, (unsigned long)b) && \
58711 + ((long)(b) - (long)(a) < 0))
58712 +
58713 +#define RTMP_TIME_AFTER_EQ(a,b) \
58714 + (typecheck(unsigned long, (unsigned long)a) && \
58715 + typecheck(unsigned long, (unsigned long)b) && \
58716 + ((long)(a) - (long)(b) >= 0))
58717 +#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
58718 +#else
58719 +#define RTMP_TIME_AFTER(a,b) time_after(a, b)
58720 +#endif
58721 +
58722 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
58723 +#define RT_MOD_INC_USE_COUNT() \
58724 + if (!try_module_get(THIS_MODULE)) \
58725 + { \
58726 + DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __FUNCTION__)); \
58727 + return -1; \
58728 + }
58729 +
58730 +#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
58731 +#else
58732 +#define RT_MOD_INC_USE_COUNT() MOD_INC_USE_COUNT;
58733 +#define RT_MOD_DEC_USE_COUNT() MOD_DEC_USE_COUNT;
58734 +#endif
58735 +
58736 +#define OS_HZ HZ
58737 +
58738 +#define ETH_LENGTH_OF_ADDRESS 6
58739 +
58740 +#define IN
58741 +#define OUT
58742 +
58743 +#define NDIS_STATUS INT
58744 +#define NDIS_STATUS_SUCCESS 0x00
58745 +#define NDIS_STATUS_FAILURE 0x01
58746 +#define NDIS_STATUS_INVALID_DATA 0x02
58747 +#define NDIS_STATUS_RESOURCES 0x03
58748 +
58749 +#define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
58750 +#define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
58751 +#define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
58752 +#define MIN_NET_DEVICE_FOR_APCLI 0x20
58753 +#define MIN_NET_DEVICE_FOR_MESH 0x30
58754 +#ifdef CONFIG_STA_SUPPORT
58755 +#define MIN_NET_DEVICE_FOR_DLS 0x40
58756 +#endif // CONFIG_STA_SUPPORT //
58757 +
58758 +
58759 +#ifdef CONFIG_STA_SUPPORT
58760 +#define NDIS_PACKET_TYPE_DIRECTED 0
58761 +#define NDIS_PACKET_TYPE_MULTICAST 1
58762 +#define NDIS_PACKET_TYPE_BROADCAST 2
58763 +#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
58764 +#endif // CONFIG_STA_SUPPORT //
58765 +
58766 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
58767 +typedef struct pid * THREAD_PID;
58768 +#define THREAD_PID_INIT_VALUE NULL
58769 +#define GET_PID(_v) find_get_pid(_v)
58770 +#define GET_PID_NUMBER(_v) pid_nr(_v)
58771 +#define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
58772 +#define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
58773 +#else
58774 +typedef pid_t THREAD_PID;
58775 +#define THREAD_PID_INIT_VALUE -1
58776 +#define GET_PID(_v) _v
58777 +#define GET_PID_NUMBER(_v) _v
58778 +#define CHECK_PID_LEGALITY(_pid) if (_pid >= 0)
58779 +#define KILL_THREAD_PID(_A, _B, _C) kill_proc(_A, _B, _C)
58780 +#endif
58781 +
58782 +struct os_lock {
58783 + spinlock_t lock;
58784 + unsigned long flags;
58785 +};
58786 +
58787 +
58788 +struct os_cookie {
58789 +
58790 +#ifdef RT2870
58791 + struct usb_device *pUsb_Dev;
58792 +
58793 + THREAD_PID MLMEThr_pid;
58794 + THREAD_PID RTUSBCmdThr_pid;
58795 + THREAD_PID TimerQThr_pid;
58796 +#endif // RT2870 //
58797 +
58798 + struct tasklet_struct rx_done_task;
58799 + struct tasklet_struct mgmt_dma_done_task;
58800 + struct tasklet_struct ac0_dma_done_task;
58801 + struct tasklet_struct ac1_dma_done_task;
58802 + struct tasklet_struct ac2_dma_done_task;
58803 + struct tasklet_struct ac3_dma_done_task;
58804 + struct tasklet_struct hcca_dma_done_task;
58805 + struct tasklet_struct tbtt_task;
58806 +#ifdef RT2870
58807 + struct tasklet_struct null_frame_complete_task;
58808 + struct tasklet_struct rts_frame_complete_task;
58809 + struct tasklet_struct pspoll_frame_complete_task;
58810 +#endif // RT2870 //
58811 +
58812 +
58813 + unsigned long apd_pid; //802.1x daemon pid
58814 + INT ioctl_if_type;
58815 + INT ioctl_if;
58816 +};
58817 +
58818 +typedef struct _VIRTUAL_ADAPTER
58819 +{
58820 + struct net_device *RtmpDev;
58821 + struct net_device *VirtualDev;
58822 +} VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
58823 +
58824 +#undef ASSERT
58825 +#define ASSERT(x) \
58826 +{ \
58827 + if (!(x)) \
58828 + { \
58829 + printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
58830 + } \
58831 +}
58832 +
58833 +typedef struct os_cookie * POS_COOKIE;
58834 +typedef struct pci_dev * PPCI_DEV;
58835 +typedef struct net_device * PNET_DEV;
58836 +typedef void * PNDIS_PACKET;
58837 +typedef char NDIS_PACKET;
58838 +typedef PNDIS_PACKET * PPNDIS_PACKET;
58839 +typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
58840 +typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
58841 +//typedef struct timer_list RALINK_TIMER_STRUCT;
58842 +//typedef struct timer_list * PRALINK_TIMER_STRUCT;
58843 +//typedef struct os_lock NDIS_SPIN_LOCK;
58844 +typedef spinlock_t NDIS_SPIN_LOCK;
58845 +typedef struct timer_list NDIS_MINIPORT_TIMER;
58846 +typedef void * NDIS_HANDLE;
58847 +typedef char * PNDIS_BUFFER;
58848 +
58849 +
58850 +
58851 +void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
58852 +
58853 +dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
58854 +void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
58855 +
58856 +
58857 +////////////////////////////////////////
58858 +// MOVE TO rtmp.h ?
58859 +/////////////////////////////////////////
58860 +#define PKTSRC_NDIS 0x7f
58861 +#define PKTSRC_DRIVER 0x0f
58862 +#define PRINT_MAC(addr) \
58863 + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
58864 +
58865 +
58866 +#define RT2860_PCI_DEVICE_ID 0x0601
58867 +
58868 +
58869 +#ifdef RT2870
58870 +#define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
58871 +
58872 +#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
58873 +#endif // RT2870 //
58874 +
58875 +
58876 +#define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
58877 + dma_cache_wback(_ptr, _size)
58878 +
58879 +
58880 +//////////////////////////////////////////
58881 +//
58882 +//////////////////////////////////////////
58883 +
58884 +
58885 +#define NdisMIndicateStatus(_w, _x, _y, _z)
58886 +
58887 +typedef struct timer_list RTMP_OS_TIMER;
58888 +
58889 +#ifdef RT2870
58890 +/* ----------------- Timer Related MARCO ---------------*/
58891 +// In RT2870, we have a lot of timer functions and will read/write register, it's
58892 +// not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
58893 +// to ctrl pipe). So we need a wrapper function to take care it.
58894 +
58895 +typedef VOID (*RT2870_TIMER_HANDLE)(
58896 + IN PVOID SystemSpecific1,
58897 + IN PVOID FunctionContext,
58898 + IN PVOID SystemSpecific2,
58899 + IN PVOID SystemSpecific3);
58900 +#endif // RT2870 //
58901 +
58902 +
58903 +typedef struct _RALINK_TIMER_STRUCT {
58904 + RTMP_OS_TIMER TimerObj; // Ndis Timer object
58905 + BOOLEAN Valid; // Set to True when call RTMPInitTimer
58906 + BOOLEAN State; // True if timer cancelled
58907 + BOOLEAN PeriodicType; // True if timer is periodic timer
58908 + BOOLEAN Repeat; // True if periodic timer
58909 + ULONG TimerValue; // Timer value in milliseconds
58910 + ULONG cookie; // os specific object
58911 +#ifdef RT2870
58912 + RT2870_TIMER_HANDLE handle;
58913 + void *pAd;
58914 +#endif // RT2870 //
58915 +} RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
58916 +
58917 +
58918 +#ifdef RT2870
58919 +
58920 +typedef enum _RT2870_KERNEL_THREAD_STATUS_
58921 +{
58922 + RT2870_THREAD_UNKNOWN = 0,
58923 + RT2870_THREAD_INITED = 1,
58924 + RT2870_THREAD_RUNNING = 2,
58925 + RT2870_THREAD_STOPED = 4,
58926 +}RT2870_KERNEL_THREAD_STATUS;
58927 +
58928 +#define RT2870_THREAD_CAN_DO_INSERT (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
58929 +
58930 +typedef struct _RT2870_TIMER_ENTRY_
58931 +{
58932 + RALINK_TIMER_STRUCT *pRaTimer;
58933 + struct _RT2870_TIMER_ENTRY_ *pNext;
58934 +}RT2870_TIMER_ENTRY;
58935 +
58936 +
58937 +#define TIMER_QUEUE_SIZE_MAX 128
58938 +typedef struct _RT2870_TIMER_QUEUE_
58939 +{
58940 + unsigned int status;
58941 + //wait_queue_head_t timerWaitQ;
58942 + //atomic_t count;
58943 + UCHAR *pTimerQPoll;
58944 + RT2870_TIMER_ENTRY *pQPollFreeList;
58945 + RT2870_TIMER_ENTRY *pQHead;
58946 + RT2870_TIMER_ENTRY *pQTail;
58947 +}RT2870_TIMER_QUEUE;
58948 +#endif // RT2870 //
58949 +
58950 +
58951 +//#define DBG 1
58952 +
58953 +//
58954 +// MACRO for debugging information
58955 +//
58956 +
58957 +#ifdef DBG
58958 +extern ULONG RTDebugLevel;
58959 +
58960 +#define DBGPRINT_RAW(Level, Fmt) \
58961 +{ \
58962 + if (Level <= RTDebugLevel) \
58963 + { \
58964 + printk Fmt; \
58965 + } \
58966 +}
58967 +
58968 +#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
58969 +
58970 +
58971 +#define DBGPRINT_ERR(Fmt) \
58972 +{ \
58973 + printk("ERROR!!! "); \
58974 + printk Fmt; \
58975 +}
58976 +
58977 +#define DBGPRINT_S(Status, Fmt) \
58978 +{ \
58979 + printk Fmt; \
58980 +}
58981 +
58982 +
58983 +#else
58984 +#define DBGPRINT(Level, Fmt)
58985 +#define DBGPRINT_RAW(Level, Fmt)
58986 +#define DBGPRINT_S(Status, Fmt)
58987 +#define DBGPRINT_ERR(Fmt)
58988 +#endif
58989 +
58990 +
58991 +//
58992 +// spin_lock enhanced for Nested spin lock
58993 +//
58994 +#define NdisAllocateSpinLock(__lock) \
58995 +{ \
58996 + spin_lock_init((spinlock_t *)(__lock)); \
58997 +}
58998 +
58999 +#define NdisFreeSpinLock(lock) \
59000 +{ \
59001 +}
59002 +
59003 +
59004 +#define RTMP_SEM_LOCK(__lock) \
59005 +{ \
59006 + spin_lock_bh((spinlock_t *)(__lock)); \
59007 +}
59008 +
59009 +#define RTMP_SEM_UNLOCK(__lock) \
59010 +{ \
59011 + spin_unlock_bh((spinlock_t *)(__lock)); \
59012 +}
59013 +
59014 +#if 0 // sample, IRQ LOCK
59015 +#define RTMP_IRQ_LOCK(__lock, __irqflags) \
59016 +{ \
59017 + spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
59018 + pAd->irq_disabled |= 1; \
59019 +}
59020 +
59021 +#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
59022 +{ \
59023 + pAd->irq_disabled &= 0; \
59024 + spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
59025 +}
59026 +#else
59027 +
59028 +// sample, use semaphore lock to replace IRQ lock, 2007/11/15
59029 +#define RTMP_IRQ_LOCK(__lock, __irqflags) \
59030 +{ \
59031 + __irqflags = 0; \
59032 + spin_lock_bh((spinlock_t *)(__lock)); \
59033 + pAd->irq_disabled |= 1; \
59034 +}
59035 +
59036 +#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
59037 +{ \
59038 + pAd->irq_disabled &= 0; \
59039 + spin_unlock_bh((spinlock_t *)(__lock)); \
59040 +}
59041 +
59042 +#define RTMP_INT_LOCK(__lock, __irqflags) \
59043 +{ \
59044 + spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
59045 +}
59046 +
59047 +#define RTMP_INT_UNLOCK(__lock, __irqflag) \
59048 +{ \
59049 + spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
59050 +}
59051 +#endif
59052 +
59053 +
59054 +
59055 +#ifdef RT2870
59056 +//Patch for ASIC turst read/write bug, needs to remove after metel fix
59057 +#define RTMP_IO_READ32(_A, _R, _pV) \
59058 + RTUSBReadMACRegister(_A, _R, _pV)
59059 +
59060 +#define RTMP_IO_READ8(_A, _R, _pV) \
59061 +{ \
59062 +}
59063 +
59064 +#define RTMP_IO_WRITE32(_A, _R, _V) \
59065 + RTUSBWriteMACRegister(_A, _R, _V)
59066 +
59067 +
59068 +#define RTMP_IO_WRITE8(_A, _R, _V) \
59069 +{ \
59070 + USHORT _Val = _V; \
59071 + RTUSBSingleWrite(_A, _R, _Val); \
59072 +}
59073 +
59074 +
59075 +#define RTMP_IO_WRITE16(_A, _R, _V) \
59076 +{ \
59077 + RTUSBSingleWrite(_A, _R, _V); \
59078 +}
59079 +#endif // RT2870 //
59080 +
59081 +#ifndef wait_event_interruptible_timeout
59082 +#define __wait_event_interruptible_timeout(wq, condition, ret) \
59083 +do { \
59084 + wait_queue_t __wait; \
59085 + init_waitqueue_entry(&__wait, current); \
59086 + add_wait_queue(&wq, &__wait); \
59087 + for (;;) { \
59088 + set_current_state(TASK_INTERRUPTIBLE); \
59089 + if (condition) \
59090 + break; \
59091 + if (!signal_pending(current)) { \
59092 + ret = schedule_timeout(ret); \
59093 + if (!ret) \
59094 + break; \
59095 + continue; \
59096 + } \
59097 + ret = -ERESTARTSYS; \
59098 + break; \
59099 + } \
59100 + current->state = TASK_RUNNING; \
59101 + remove_wait_queue(&wq, &__wait); \
59102 +} while (0)
59103 +
59104 +#define wait_event_interruptible_timeout(wq, condition, timeout) \
59105 +({ \
59106 + long __ret = timeout; \
59107 + if (!(condition)) \
59108 + __wait_event_interruptible_timeout(wq, condition, __ret); \
59109 + __ret; \
59110 +})
59111 +#endif
59112 +#define ONE_TICK 1
59113 +#define OS_WAIT(_time) \
59114 +{ int _i; \
59115 + long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
59116 + wait_queue_head_t _wait; \
59117 + init_waitqueue_head(&_wait); \
59118 + for (_i=0; _i<(_loop); _i++) \
59119 + wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
59120 +
59121 +
59122 +typedef void (*TIMER_FUNCTION)(unsigned long);
59123 +
59124 +#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
59125 +
59126 +#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
59127 +#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
59128 +
59129 +
59130 +#ifdef RT2870
59131 +#define BUILD_TIMER_FUNCTION(_func) \
59132 +void linux_##_func(unsigned long data) \
59133 +{ \
59134 + PRALINK_TIMER_STRUCT _pTimer = (PRALINK_TIMER_STRUCT)data; \
59135 + RT2870_TIMER_ENTRY *_pQNode; \
59136 + RTMP_ADAPTER *_pAd; \
59137 + \
59138 + _pTimer->handle = _func; \
59139 + _pAd = (RTMP_ADAPTER *)_pTimer->pAd; \
59140 + _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer); \
59141 + if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)) \
59142 + RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ); \
59143 +}
59144 +#endif // RT2870 //
59145 +
59146 +
59147 +#define DECLARE_TIMER_FUNCTION(_func) \
59148 +void linux_##_func(unsigned long data)
59149 +
59150 +#define GET_TIMER_FUNCTION(_func) \
59151 + linux_##_func
59152 +
59153 +DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
59154 +DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
59155 +DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
59156 +DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
59157 +DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
59158 +#ifdef RT2870
59159 +DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
59160 +#endif // RT2870 //
59161 +
59162 +
59163 +#ifdef CONFIG_STA_SUPPORT
59164 +DECLARE_TIMER_FUNCTION(BeaconTimeout);
59165 +DECLARE_TIMER_FUNCTION(ScanTimeout);
59166 +DECLARE_TIMER_FUNCTION(AuthTimeout);
59167 +DECLARE_TIMER_FUNCTION(AssocTimeout);
59168 +DECLARE_TIMER_FUNCTION(ReassocTimeout);
59169 +DECLARE_TIMER_FUNCTION(DisassocTimeout);
59170 +DECLARE_TIMER_FUNCTION(LinkDownExec);
59171 +#ifdef LEAP_SUPPORT
59172 +DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
59173 +#endif
59174 +DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
59175 +DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
59176 +DECLARE_TIMER_FUNCTION(PsPollWakeExec);
59177 +DECLARE_TIMER_FUNCTION(RadioOnExec);
59178 +
59179 +#ifdef QOS_DLS_SUPPORT
59180 +DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
59181 +#endif // QOS_DLS_SUPPORT //
59182 +#endif // CONFIG_STA_SUPPORT //
59183 +
59184 +void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
59185 +
59186 +
59187 +/*
59188 + * packet helper
59189 + * - convert internal rt packet to os packet or
59190 + * os packet to rt packet
59191 + */
59192 +#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
59193 +#define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
59194 +
59195 +#define GET_OS_PKT_DATAPTR(_pkt) \
59196 + (RTPKT_TO_OSPKT(_pkt)->data)
59197 +
59198 +#define GET_OS_PKT_LEN(_pkt) \
59199 + (RTPKT_TO_OSPKT(_pkt)->len)
59200 +
59201 +#define GET_OS_PKT_DATATAIL(_pkt) \
59202 + (RTPKT_TO_OSPKT(_pkt)->tail)
59203 +
59204 +#define GET_OS_PKT_HEAD(_pkt) \
59205 + (RTPKT_TO_OSPKT(_pkt)->head)
59206 +
59207 +#define GET_OS_PKT_END(_pkt) \
59208 + (RTPKT_TO_OSPKT(_pkt)->end)
59209 +
59210 +#define GET_OS_PKT_NETDEV(_pkt) \
59211 + (RTPKT_TO_OSPKT(_pkt)->dev)
59212 +
59213 +#define GET_OS_PKT_TYPE(_pkt) \
59214 + (RTPKT_TO_OSPKT(_pkt))
59215 +
59216 +#define GET_OS_PKT_NEXT(_pkt) \
59217 + (RTPKT_TO_OSPKT(_pkt)->next)
59218 +
59219 +
59220 +#define OS_NTOHS(_Val) \
59221 + (ntohs(_Val))
59222 +#define OS_HTONS(_Val) \
59223 + (htons(_Val))
59224 +#define OS_NTOHL(_Val) \
59225 + (ntohl(_Val))
59226 +#define OS_HTONL(_Val) \
59227 + (htonl(_Val))
59228 +
59229 +/* statistics counter */
59230 +#define STATS_INC_RX_PACKETS(_pAd, _dev)
59231 +#define STATS_INC_TX_PACKETS(_pAd, _dev)
59232 +
59233 +#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
59234 +#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
59235 +
59236 +#define STATS_INC_RX_ERRORS(_pAd, _dev)
59237 +#define STATS_INC_TX_ERRORS(_pAd, _dev)
59238 +
59239 +#define STATS_INC_RX_DROPPED(_pAd, _dev)
59240 +#define STATS_INC_TX_DROPPED(_pAd, _dev)
59241 +
59242 +
59243 +#define CB_OFF 10
59244 +
59245 +
59246 +// check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
59247 +// ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
59248 +//
59249 +//#define RTMP_GET_PACKET_MR(_p) (RTPKT_TO_OSPKT(_p))
59250 +
59251 +// User Priority
59252 +#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
59253 +#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
59254 +
59255 +// Fragment #
59256 +#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
59257 +#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
59258 +
59259 +// 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.
59260 +//(this value also as MAC(on-chip WCID) table index)
59261 +// 0x80~0xff: TX to a WDS link. b0~6: WDS index
59262 +#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
59263 +#define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
59264 +
59265 +// 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
59266 +#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
59267 +#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
59268 +
59269 +// RTS/CTS-to-self protection method
59270 +#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
59271 +#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
59272 +// see RTMP_S(G)ET_PACKET_EMACTAB
59273 +
59274 +// TX rate index
59275 +#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
59276 +#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
59277 +
59278 +// From which Interface
59279 +#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
59280 +#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
59281 +#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
59282 +#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
59283 +#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
59284 +#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
59285 +#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
59286 +#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
59287 +
59288 +#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
59289 +#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
59290 +
59291 +//#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
59292 +//#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) (RTPKT_TO_OSPKT(_p)->cb[8])
59293 +
59294 +
59295 +
59296 +
59297 +#if 0
59298 +//#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
59299 +//#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
59300 +#else
59301 +//
59302 +// Sepcific Pakcet Type definition
59303 +//
59304 +#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
59305 +
59306 +#define RTMP_PACKET_SPECIFIC_DHCP 0x01
59307 +#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
59308 +#define RTMP_PACKET_SPECIFIC_IPV4 0x04
59309 +#define RTMP_PACKET_SPECIFIC_WAI 0x08
59310 +#define RTMP_PACKET_SPECIFIC_VLAN 0x10
59311 +#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
59312 +
59313 +//Specific
59314 +#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
59315 +
59316 +//DHCP
59317 +#define RTMP_SET_PACKET_DHCP(_p, _flg) \
59318 + do{ \
59319 + if (_flg) \
59320 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
59321 + else \
59322 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
59323 + }while(0)
59324 +#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
59325 +
59326 +//EAPOL
59327 +#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
59328 + do{ \
59329 + if (_flg) \
59330 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
59331 + else \
59332 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
59333 + }while(0)
59334 +#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
59335 +
59336 +//WAI
59337 +#define RTMP_SET_PACKET_WAI(_p, _flg) \
59338 + do{ \
59339 + if (_flg) \
59340 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
59341 + else \
59342 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
59343 + }while(0)
59344 +#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
59345 +
59346 +#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))
59347 +
59348 +//VLAN
59349 +#define RTMP_SET_PACKET_VLAN(_p, _flg) \
59350 + do{ \
59351 + if (_flg) \
59352 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
59353 + else \
59354 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
59355 + }while(0)
59356 +#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
59357 +
59358 +//LLC/SNAP
59359 +#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
59360 + do{ \
59361 + if (_flg) \
59362 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
59363 + else \
59364 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
59365 + }while(0)
59366 +
59367 +#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
59368 +
59369 +// IP
59370 +#define RTMP_SET_PACKET_IPV4(_p, _flg) \
59371 + do{ \
59372 + if (_flg) \
59373 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
59374 + else \
59375 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
59376 + }while(0)
59377 +
59378 +#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
59379 +
59380 +#endif
59381 +
59382 +
59383 +// If this flag is set, it indicates that this EAPoL frame MUST be clear.
59384 +#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
59385 +#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
59386 +
59387 +#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
59388 +#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
59389 +
59390 +
59391 +#ifdef CONFIG_5VT_ENHANCE
59392 +#define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
59393 +#endif
59394 +
59395 +
59396 +#define NDIS_SET_PACKET_STATUS(_p, _status)
59397 +
59398 +
59399 +#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
59400 + rt_get_sg_list_from_packet(_p, _sc)
59401 +
59402 +
59403 +#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
59404 +#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
59405 +#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
59406 +#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
59407 +#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
59408 +
59409 +
59410 +#define RTMP_INC_REF(_A) 0
59411 +#define RTMP_DEC_REF(_A) 0
59412 +#define RTMP_GET_REF(_A) 0
59413 +
59414 +
59415 +
59416 +/*
59417 + * ULONG
59418 + * RTMP_GetPhysicalAddressLow(
59419 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
59420 + */
59421 +#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
59422 +
59423 +/*
59424 + * ULONG
59425 + * RTMP_GetPhysicalAddressHigh(
59426 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
59427 + */
59428 +#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
59429 +
59430 +/*
59431 + * VOID
59432 + * RTMP_SetPhysicalAddressLow(
59433 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
59434 + * IN ULONG Value);
59435 + */
59436 +#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
59437 + PhysicalAddress = Value;
59438 +
59439 +/*
59440 + * VOID
59441 + * RTMP_SetPhysicalAddressHigh(
59442 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
59443 + * IN ULONG Value);
59444 + */
59445 +#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
59446 +
59447 +
59448 +//CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
59449 +#define QUEUE_ENTRY_TO_PACKET(pEntry) \
59450 + (PNDIS_PACKET)(pEntry)
59451 +
59452 +#define PACKET_TO_QUEUE_ENTRY(pPacket) \
59453 + (PQUEUE_ENTRY)(pPacket)
59454 +
59455 +
59456 +#ifndef CONTAINING_RECORD
59457 +#define CONTAINING_RECORD(address, type, field) \
59458 +((type *)((PCHAR)(address) - offsetof(type, field)))
59459 +#endif
59460 +
59461 +
59462 +#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
59463 +{ \
59464 + RTMPFreeNdisPacket(_pAd, _pPacket); \
59465 +}
59466 +
59467 +
59468 +#define SWITCH_PhyAB(_pAA, _pBB) \
59469 +{ \
59470 + ULONG AABasePaHigh; \
59471 + ULONG AABasePaLow; \
59472 + ULONG BBBasePaHigh; \
59473 + ULONG BBBasePaLow; \
59474 + BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
59475 + BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
59476 + AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
59477 + AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
59478 + RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
59479 + RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
59480 + RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
59481 + RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
59482 +}
59483 +
59484 +
59485 +#define NdisWriteErrorLogEntry(_a, _b, _c, _d)
59486 +#define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
59487 +
59488 +
59489 +#define NdisAcquireSpinLock RTMP_SEM_LOCK
59490 +#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
59491 +
59492 +static inline void NdisGetSystemUpTime(ULONG *time)
59493 +{
59494 + *time = jiffies;
59495 +}
59496 +
59497 +//pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
59498 +#define QUEUE_ENTRY_TO_PKT(pEntry) \
59499 + ((PNDIS_PACKET) (pEntry))
59500 +
59501 +int rt28xx_packet_xmit(struct sk_buff *skb);
59502 +
59503 +
59504 +
59505 +void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
59506 +
59507 +
59508 --- /dev/null
59509 +++ b/drivers/staging/rt2870/rt_main_dev.c
59510 @@ -0,0 +1,1863 @@
59511 +/*
59512 + *************************************************************************
59513 + * Ralink Tech Inc.
59514 + * 5F., No.36, Taiyuan St., Jhubei City,
59515 + * Hsinchu County 302,
59516 + * Taiwan, R.O.C.
59517 + *
59518 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
59519 + *
59520 + * This program is free software; you can redistribute it and/or modify *
59521 + * it under the terms of the GNU General Public License as published by *
59522 + * the Free Software Foundation; either version 2 of the License, or *
59523 + * (at your option) any later version. *
59524 + * *
59525 + * This program is distributed in the hope that it will be useful, *
59526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
59527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
59528 + * GNU General Public License for more details. *
59529 + * *
59530 + * You should have received a copy of the GNU General Public License *
59531 + * along with this program; if not, write to the *
59532 + * Free Software Foundation, Inc., *
59533 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
59534 + * *
59535 + *************************************************************************
59536 +
59537 + Module Name:
59538 + rt_main_dev.c
59539 +
59540 + Abstract:
59541 + Create and register network interface.
59542 +
59543 + Revision History:
59544 + Who When What
59545 + -------- ---------- ----------------------------------------------
59546 + Sample Mar/21/07 Merge RT2870 and RT2860 drivers.
59547 +*/
59548 +
59549 +#include "rt_config.h"
59550 +
59551 +#define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min
59552 +
59553 +#ifdef MULTIPLE_CARD_SUPPORT
59554 +// record whether the card in the card list is used in the card file
59555 +UINT8 MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
59556 +// record used card mac address in the card list
59557 +static UINT8 MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
59558 +#endif // MULTIPLE_CARD_SUPPORT //
59559 +
59560 +/*---------------------------------------------------------------------*/
59561 +/* Private Variables Used */
59562 +/*---------------------------------------------------------------------*/
59563 +//static RALINK_TIMER_STRUCT PeriodicTimer;
59564 +
59565 +char *mac = ""; // default 00:00:00:00:00:00
59566 +char *hostname = "";
59567 +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
59568 +MODULE_PARM (mac, "s");
59569 +#else
59570 +module_param (mac, charp, 0);
59571 +#endif
59572 +MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
59573 +
59574 +
59575 +/*---------------------------------------------------------------------*/
59576 +/* Prototypes of Functions Used */
59577 +/*---------------------------------------------------------------------*/
59578 +#ifdef DOT11_N_SUPPORT
59579 +extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
59580 +extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
59581 +#endif // DOT11_N_SUPPORT //
59582 +extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
59583 +
59584 +
59585 +// public function prototype
59586 +INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
59587 + IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
59588 +
59589 +// private function prototype
59590 +static int rt28xx_init(IN struct net_device *net_dev);
59591 +INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
59592 +
59593 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
59594 +struct net_device *alloc_netdev(
59595 + int sizeof_priv,
59596 + const char *mask,
59597 + void (*setup)(struct net_device *));
59598 +#endif // LINUX_VERSION_CODE //
59599 +
59600 +static void CfgInitHook(PRTMP_ADAPTER pAd);
59601 +//static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
59602 +
59603 +#ifdef CONFIG_STA_SUPPORT
59604 +extern const struct iw_handler_def rt28xx_iw_handler_def;
59605 +#endif // CONFIG_STA_SUPPORT //
59606 +
59607 +#if WIRELESS_EXT >= 12
59608 +// This function will be called when query /proc
59609 +struct iw_statistics *rt28xx_get_wireless_stats(
59610 + IN struct net_device *net_dev);
59611 +#endif
59612 +
59613 +struct net_device_stats *RT28xx_get_ether_stats(
59614 + IN struct net_device *net_dev);
59615 +
59616 +/*
59617 +========================================================================
59618 +Routine Description:
59619 + Close raxx interface.
59620 +
59621 +Arguments:
59622 + *net_dev the raxx interface pointer
59623 +
59624 +Return Value:
59625 + 0 Open OK
59626 + otherwise Open Fail
59627 +
59628 +Note:
59629 + 1. if open fail, kernel will not call the close function.
59630 + 2. Free memory for
59631 + (1) Mlme Memory Handler: MlmeHalt()
59632 + (2) TX & RX: RTMPFreeTxRxRingMemory()
59633 + (3) BA Reordering: ba_reordering_resource_release()
59634 +========================================================================
59635 +*/
59636 +int MainVirtualIF_close(IN struct net_device *net_dev)
59637 +{
59638 + RTMP_ADAPTER *pAd = net_dev->priv;
59639 +
59640 + // Sanity check for pAd
59641 + if (pAd == NULL)
59642 + return 0; // close ok
59643 +
59644 + netif_carrier_off(pAd->net_dev);
59645 + netif_stop_queue(pAd->net_dev);
59646 +
59647 +
59648 +
59649 + VIRTUAL_IF_DOWN(pAd);
59650 +
59651 + RT_MOD_DEC_USE_COUNT();
59652 +
59653 + return 0; // close ok
59654 +}
59655 +
59656 +/*
59657 +========================================================================
59658 +Routine Description:
59659 + Open raxx interface.
59660 +
59661 +Arguments:
59662 + *net_dev the raxx interface pointer
59663 +
59664 +Return Value:
59665 + 0 Open OK
59666 + otherwise Open Fail
59667 +
59668 +Note:
59669 + 1. if open fail, kernel will not call the close function.
59670 + 2. Free memory for
59671 + (1) Mlme Memory Handler: MlmeHalt()
59672 + (2) TX & RX: RTMPFreeTxRxRingMemory()
59673 + (3) BA Reordering: ba_reordering_resource_release()
59674 +========================================================================
59675 +*/
59676 +int MainVirtualIF_open(IN struct net_device *net_dev)
59677 +{
59678 + RTMP_ADAPTER *pAd = net_dev->priv;
59679 +
59680 + // Sanity check for pAd
59681 + if (pAd == NULL)
59682 + return 0; // close ok
59683 +
59684 + if (VIRTUAL_IF_UP(pAd) != 0)
59685 + return -1;
59686 +
59687 + // increase MODULE use count
59688 + RT_MOD_INC_USE_COUNT();
59689 +
59690 + netif_start_queue(net_dev);
59691 + netif_carrier_on(net_dev);
59692 + netif_wake_queue(net_dev);
59693 +
59694 + return 0;
59695 +}
59696 +
59697 +/*
59698 +========================================================================
59699 +Routine Description:
59700 + Close raxx interface.
59701 +
59702 +Arguments:
59703 + *net_dev the raxx interface pointer
59704 +
59705 +Return Value:
59706 + 0 Open OK
59707 + otherwise Open Fail
59708 +
59709 +Note:
59710 + 1. if open fail, kernel will not call the close function.
59711 + 2. Free memory for
59712 + (1) Mlme Memory Handler: MlmeHalt()
59713 + (2) TX & RX: RTMPFreeTxRxRingMemory()
59714 + (3) BA Reordering: ba_reordering_resource_release()
59715 +========================================================================
59716 +*/
59717 +int rt28xx_close(IN PNET_DEV dev)
59718 +{
59719 + struct net_device * net_dev = (struct net_device *)dev;
59720 + RTMP_ADAPTER *pAd = net_dev->priv;
59721 + BOOLEAN Cancelled = FALSE;
59722 + UINT32 i = 0;
59723 +#ifdef RT2870
59724 + DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
59725 + DECLARE_WAITQUEUE(wait, current);
59726 +
59727 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
59728 +#endif // RT2870 //
59729 +
59730 +
59731 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
59732 +
59733 + // Sanity check for pAd
59734 + if (pAd == NULL)
59735 + return 0; // close ok
59736 +
59737 +
59738 +#ifdef CONFIG_STA_SUPPORT
59739 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
59740 + {
59741 +
59742 + // If dirver doesn't wake up firmware here,
59743 + // NICLoadFirmware will hang forever when interface is up again.
59744 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
59745 + {
59746 + AsicForceWakeup(pAd, TRUE);
59747 + }
59748 +
59749 +#ifdef QOS_DLS_SUPPORT
59750 + // send DLS-TEAR_DOWN message,
59751 + if (pAd->CommonCfg.bDLSCapable)
59752 + {
59753 + UCHAR i;
59754 +
59755 + // tear down local dls table entry
59756 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
59757 + {
59758 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
59759 + {
59760 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
59761 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
59762 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
59763 + }
59764 + }
59765 +
59766 + // tear down peer dls table entry
59767 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
59768 + {
59769 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
59770 + {
59771 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
59772 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
59773 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
59774 + }
59775 + }
59776 + RT28XX_MLME_HANDLER(pAd);
59777 + }
59778 +#endif // QOS_DLS_SUPPORT //
59779 +
59780 + if (INFRA_ON(pAd) &&
59781 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
59782 + {
59783 + MLME_DISASSOC_REQ_STRUCT DisReq;
59784 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
59785 +
59786 + COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
59787 + DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
59788 +
59789 + MsgElem->Machine = ASSOC_STATE_MACHINE;
59790 + MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
59791 + MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
59792 + NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
59793 +
59794 + // Prevent to connect AP again in STAMlmePeriodicExec
59795 + pAd->MlmeAux.AutoReconnectSsidLen= 32;
59796 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
59797 +
59798 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
59799 + MlmeDisassocReqAction(pAd, MsgElem);
59800 + kfree(MsgElem);
59801 +
59802 + RTMPusecDelay(1000);
59803 + }
59804 +
59805 +#ifdef RT2870
59806 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
59807 +#endif // RT2870 //
59808 +
59809 +#ifdef CCX_SUPPORT
59810 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
59811 +#endif
59812 +
59813 + RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
59814 + RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
59815 +
59816 +#ifdef WPA_SUPPLICANT_SUPPORT
59817 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
59818 + {
59819 + union iwreq_data wrqu;
59820 + // send wireless event to wpa_supplicant for infroming interface down.
59821 + memset(&wrqu, 0, sizeof(wrqu));
59822 + wrqu.data.flags = RT_INTERFACE_DOWN;
59823 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
59824 + }
59825 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
59826 +#endif // WPA_SUPPLICANT_SUPPORT //
59827 +
59828 + MlmeRadioOff(pAd);
59829 + }
59830 +#endif // CONFIG_STA_SUPPORT //
59831 +
59832 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
59833 +
59834 + for (i = 0 ; i < NUM_OF_TX_RING; i++)
59835 + {
59836 + while (pAd->DeQueueRunning[i] == TRUE)
59837 + {
59838 + printk("Waiting for TxQueue[%d] done..........\n", i);
59839 + RTMPusecDelay(1000);
59840 + }
59841 + }
59842 +
59843 +#ifdef RT2870
59844 + // ensure there are no more active urbs.
59845 + add_wait_queue (&unlink_wakeup, &wait);
59846 + pAd->wait = &unlink_wakeup;
59847 +
59848 + // maybe wait for deletions to finish.
59849 + i = 0;
59850 + //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
59851 + while(i < 25)
59852 + {
59853 + unsigned long IrqFlags;
59854 +
59855 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
59856 + if (pAd->PendingRx == 0)
59857 + {
59858 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
59859 + break;
59860 + }
59861 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
59862 +
59863 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
59864 + msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
59865 +#else
59866 + RTMPusecDelay(UNLINK_TIMEOUT_MS*1000); //Time in microsecond
59867 +#endif
59868 + i++;
59869 + }
59870 + pAd->wait = NULL;
59871 + remove_wait_queue (&unlink_wakeup, &wait);
59872 +#endif // RT2870 //
59873 +
59874 + //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
59875 +
59876 +
59877 +#ifdef RT2870
59878 + // We need clear timerQ related structure before exits of the timer thread.
59879 + RT2870_TimerQ_Exit(pAd);
59880 + // Close kernel threads or tasklets
59881 + RT28xxThreadTerminate(pAd);
59882 +#endif // RT2870 //
59883 +
59884 + // Stop Mlme state machine
59885 + MlmeHalt(pAd);
59886 +
59887 + // Close kernel threads or tasklets
59888 + kill_thread_task(pAd);
59889 +
59890 +
59891 +#ifdef CONFIG_STA_SUPPORT
59892 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
59893 + {
59894 + MacTableReset(pAd);
59895 + }
59896 +#endif // CONFIG_STA_SUPPORT //
59897 +
59898 +
59899 + MeasureReqTabExit(pAd);
59900 + TpcReqTabExit(pAd);
59901 +
59902 +
59903 +
59904 +
59905 + // Free Ring or USB buffers
59906 + RTMPFreeTxRxRingMemory(pAd);
59907 +
59908 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
59909 +
59910 +#ifdef DOT11_N_SUPPORT
59911 + // Free BA reorder resource
59912 + ba_reordering_resource_release(pAd);
59913 +#endif // DOT11_N_SUPPORT //
59914 +
59915 +#ifdef RT2870
59916 +#ifdef INF_AMAZON_SE
59917 + if (pAd->UsbVendorReqBuf)
59918 + os_free_mem(pAd, pAd->UsbVendorReqBuf);
59919 +#endif // INF_AMAZON_SE //
59920 +#endif // RT2870 //
59921 +
59922 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
59923 +
59924 + return 0; // close ok
59925 +} /* End of rt28xx_close */
59926 +
59927 +static int rt28xx_init(IN struct net_device *net_dev)
59928 +{
59929 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->priv;
59930 + UINT index;
59931 + UCHAR TmpPhy;
59932 + NDIS_STATUS Status;
59933 + UINT32 MacCsr0 = 0;
59934 +
59935 +#ifdef RT2870
59936 +#ifdef INF_AMAZON_SE
59937 + init_MUTEX(&(pAd->UsbVendorReq_semaphore));
59938 + os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
59939 + if (pAd->UsbVendorReqBuf == NULL)
59940 + {
59941 + DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
59942 + goto err0;
59943 + }
59944 +#endif // INF_AMAZON_SE //
59945 +#endif // RT2870 //
59946 +
59947 +#ifdef DOT11_N_SUPPORT
59948 + // Allocate BA Reordering memory
59949 + ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
59950 +#endif // DOT11_N_SUPPORT //
59951 +
59952 + // Make sure MAC gets ready.
59953 + index = 0;
59954 + do
59955 + {
59956 + RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
59957 + pAd->MACVersion = MacCsr0;
59958 +
59959 + if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
59960 + break;
59961 +
59962 + RTMPusecDelay(10);
59963 + } while (index++ < 100);
59964 +
59965 + DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
59966 +
59967 + // Disable DMA
59968 + RT28XXDMADisable(pAd);
59969 +
59970 +
59971 + // Load 8051 firmware
59972 + Status = NICLoadFirmware(pAd);
59973 + if (Status != NDIS_STATUS_SUCCESS)
59974 + {
59975 + DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
59976 + goto err1;
59977 + }
59978 +
59979 + NICLoadRateSwitchingParams(pAd);
59980 +
59981 + // Disable interrupts here which is as soon as possible
59982 + // This statement should never be true. We might consider to remove it later
59983 +
59984 + Status = RTMPAllocTxRxRingMemory(pAd);
59985 + if (Status != NDIS_STATUS_SUCCESS)
59986 + {
59987 + DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
59988 + goto err1;
59989 + }
59990 +
59991 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
59992 +
59993 + // initialize MLME
59994 + //
59995 +
59996 + Status = MlmeInit(pAd);
59997 + if (Status != NDIS_STATUS_SUCCESS)
59998 + {
59999 + DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
60000 + goto err2;
60001 + }
60002 +
60003 + // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
60004 + //
60005 + UserCfgInit(pAd);
60006 +
60007 +#ifdef RT2870
60008 + // We need init timerQ related structure before create the timer thread.
60009 + RT2870_TimerQ_Init(pAd);
60010 +#endif // RT2870 //
60011 +
60012 + RT28XX_TASK_THREAD_INIT(pAd, Status);
60013 + if (Status != NDIS_STATUS_SUCCESS)
60014 + goto err1;
60015 +
60016 +// COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
60017 +// pAd->bForcePrintTX = TRUE;
60018 +
60019 + CfgInitHook(pAd);
60020 +
60021 +
60022 +#ifdef BLOCK_NET_IF
60023 + initblockQueueTab(pAd);
60024 +#endif // BLOCK_NET_IF //
60025 +
60026 +#ifdef CONFIG_STA_SUPPORT
60027 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60028 + NdisAllocateSpinLock(&pAd->MacTabLock);
60029 +#endif // CONFIG_STA_SUPPORT //
60030 +
60031 + MeasureReqTabInit(pAd);
60032 + TpcReqTabInit(pAd);
60033 +
60034 + //
60035 + // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
60036 + //
60037 + Status = NICInitializeAdapter(pAd, TRUE);
60038 + if (Status != NDIS_STATUS_SUCCESS)
60039 + {
60040 + DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
60041 + if (Status != NDIS_STATUS_SUCCESS)
60042 + goto err3;
60043 + }
60044 +
60045 + // Read parameters from Config File
60046 + Status = RTMPReadParametersHook(pAd);
60047 +
60048 + printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60049 + if (Status != NDIS_STATUS_SUCCESS)
60050 + {
60051 + DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
60052 + goto err4;
60053 + }
60054 +
60055 +#ifdef RT2870
60056 + pAd->CommonCfg.bMultipleIRP = FALSE;
60057 +
60058 + if (pAd->CommonCfg.bMultipleIRP)
60059 + pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
60060 + else
60061 + pAd->CommonCfg.NumOfBulkInIRP = 1;
60062 +#endif // RT2870 //
60063 +
60064 +
60065 + //Init Ba Capability parameters.
60066 +// RT28XX_BA_INIT(pAd);
60067 +#ifdef DOT11_N_SUPPORT
60068 + pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
60069 + pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
60070 + pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
60071 + pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
60072 + // UPdata to HT IE
60073 + pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
60074 + pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
60075 + pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
60076 +#endif // DOT11_N_SUPPORT //
60077 +
60078 + // after reading Registry, we now know if in AP mode or STA mode
60079 +
60080 + // Load 8051 firmware; crash when FW image not existent
60081 + // Status = NICLoadFirmware(pAd);
60082 + // if (Status != NDIS_STATUS_SUCCESS)
60083 + // break;
60084 +
60085 + printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60086 +
60087 + // We should read EEPROM for all cases. rt2860b
60088 + NICReadEEPROMParameters(pAd, mac);
60089 +#ifdef CONFIG_STA_SUPPORT
60090 +#endif // CONFIG_STA_SUPPORT //
60091 +
60092 + printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60093 +
60094 + NICInitAsicFromEEPROM(pAd); //rt2860b
60095 +
60096 + // Set PHY to appropriate mode
60097 + TmpPhy = pAd->CommonCfg.PhyMode;
60098 + pAd->CommonCfg.PhyMode = 0xff;
60099 + RTMPSetPhyMode(pAd, TmpPhy);
60100 +#ifdef DOT11_N_SUPPORT
60101 + SetCommonHT(pAd);
60102 +#endif // DOT11_N_SUPPORT //
60103 +
60104 + // No valid channels.
60105 + if (pAd->ChannelListNum == 0)
60106 + {
60107 + printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
60108 + goto err4;
60109 + }
60110 +
60111 +#ifdef DOT11_N_SUPPORT
60112 + printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
60113 + pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
60114 + pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
60115 +#endif // DOT11_N_SUPPORT //
60116 +
60117 +#ifdef RT2870
60118 + //Init RT30xx RFRegisters after read RFIC type from EEPROM
60119 + NICInitRT30xxRFRegisters(pAd);
60120 +#endif // RT2870 //
60121 +
60122 +#if 0
60123 + // Patch cardbus controller if EEPROM said so.
60124 + if (pAd->bTest1 == FALSE)
60125 + RTMPPatchCardBus(pAd);
60126 +#endif
60127 +
60128 +
60129 +// APInitialize(pAd);
60130 +
60131 +#ifdef IKANOS_VX_1X0
60132 + VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
60133 +#endif // IKANOS_VX_1X0 //
60134 +
60135 + //
60136 + // Initialize RF register to default value
60137 + //
60138 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
60139 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
60140 +
60141 + // 8051 firmware require the signal during booting time.
60142 + AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
60143 +
60144 + if (pAd && (Status != NDIS_STATUS_SUCCESS))
60145 + {
60146 + //
60147 + // Undo everything if it failed
60148 + //
60149 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
60150 + {
60151 +// NdisMDeregisterInterrupt(&pAd->Interrupt);
60152 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
60153 + }
60154 +// RTMPFreeAdapter(pAd); // we will free it in disconnect()
60155 + }
60156 + else if (pAd)
60157 + {
60158 + // Microsoft HCT require driver send a disconnect event after driver initialization.
60159 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
60160 +// pAd->IndicateMediaState = NdisMediaStateDisconnected;
60161 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
60162 +
60163 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
60164 +
60165 +
60166 +#ifdef RT2870
60167 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
60168 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
60169 +
60170 + //
60171 + // Support multiple BulkIn IRP,
60172 + // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
60173 + //
60174 + for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
60175 + {
60176 + RTUSBBulkReceive(pAd);
60177 + DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
60178 + }
60179 +#endif // RT2870 //
60180 + }// end of else
60181 +
60182 +
60183 + DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
60184 +
60185 + return TRUE;
60186 +
60187 +
60188 +err4:
60189 +err3:
60190 + MlmeHalt(pAd);
60191 +err2:
60192 + RTMPFreeTxRxRingMemory(pAd);
60193 +// RTMPFreeAdapter(pAd);
60194 +err1:
60195 +
60196 +#ifdef DOT11_N_SUPPORT
60197 + os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
60198 +#endif // DOT11_N_SUPPORT //
60199 + RT28XX_IRQ_RELEASE(net_dev);
60200 +
60201 + // shall not set priv to NULL here because the priv didn't been free yet.
60202 + //net_dev->priv = 0;
60203 +#ifdef INF_AMAZON_SE
60204 +err0:
60205 +#endif // INF_AMAZON_SE //
60206 + printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
60207 + return FALSE;
60208 +} /* End of rt28xx_init */
60209 +
60210 +
60211 +/*
60212 +========================================================================
60213 +Routine Description:
60214 + Open raxx interface.
60215 +
60216 +Arguments:
60217 + *net_dev the raxx interface pointer
60218 +
60219 +Return Value:
60220 + 0 Open OK
60221 + otherwise Open Fail
60222 +
60223 +Note:
60224 +========================================================================
60225 +*/
60226 +int rt28xx_open(IN PNET_DEV dev)
60227 +{
60228 + struct net_device * net_dev = (struct net_device *)dev;
60229 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->priv;
60230 + int retval = 0;
60231 + POS_COOKIE pObj;
60232 +
60233 +
60234 + // Sanity check for pAd
60235 + if (pAd == NULL)
60236 + {
60237 + /* if 1st open fail, pAd will be free;
60238 + So the net_dev->priv will be NULL in 2rd open */
60239 + return -1;
60240 + }
60241 +
60242 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
60243 + if (pAd->OpMode == OPMODE_AP)
60244 + {
60245 + CW_MAX_IN_BITS = 6;
60246 + }
60247 + else if (pAd->OpMode == OPMODE_STA)
60248 + {
60249 + CW_MAX_IN_BITS = 10;
60250 + }
60251 +
60252 +#if WIRELESS_EXT >= 12
60253 + if (net_dev->priv_flags == INT_MAIN)
60254 + {
60255 + if (pAd->OpMode == OPMODE_AP)
60256 + net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
60257 + else if (pAd->OpMode == OPMODE_STA)
60258 + net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
60259 + }
60260 +#endif // WIRELESS_EXT >= 12 //
60261 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
60262 +
60263 +#ifdef CONFIG_STA_SUPPORT
60264 +#endif // CONFIG_STA_SUPPORT //
60265 +
60266 + // Init
60267 + pObj = (POS_COOKIE)pAd->OS_Cookie;
60268 +
60269 + // reset Adapter flags
60270 + RTMP_CLEAR_FLAGS(pAd);
60271 +
60272 + // Request interrupt service routine for PCI device
60273 + // register the interrupt routine with the os
60274 + RT28XX_IRQ_REQUEST(net_dev);
60275 +
60276 +
60277 + // Init BssTab & ChannelInfo tabbles for auto channel select.
60278 +
60279 +
60280 + // Chip & other init
60281 + if (rt28xx_init(net_dev) == FALSE)
60282 + goto err;
60283 +
60284 +#ifdef CONFIG_STA_SUPPORT
60285 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60286 + {
60287 + NdisZeroMemory(pAd->StaCfg.dev_name, 16);
60288 + NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
60289 + }
60290 +#endif // CONFIG_STA_SUPPORT //
60291 +
60292 + // Set up the Mac address
60293 + NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
60294 +
60295 + // Init IRQ parameters
60296 + RT28XX_IRQ_INIT(pAd);
60297 +
60298 + // Various AP function init
60299 +
60300 +#ifdef CONFIG_STA_SUPPORT
60301 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60302 + {
60303 +#ifdef WPA_SUPPLICANT_SUPPORT
60304 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
60305 + {
60306 + union iwreq_data wrqu;
60307 + // send wireless event to wpa_supplicant for infroming interface down.
60308 + memset(&wrqu, 0, sizeof(wrqu));
60309 + wrqu.data.flags = RT_INTERFACE_UP;
60310 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
60311 + }
60312 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
60313 +#endif // WPA_SUPPLICANT_SUPPORT //
60314 +
60315 + }
60316 +#endif // CONFIG_STA_SUPPORT //
60317 +
60318 + // Enable Interrupt
60319 + RT28XX_IRQ_ENABLE(pAd);
60320 +
60321 + // Now Enable RxTx
60322 + RTMPEnableRxTx(pAd);
60323 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
60324 +
60325 + {
60326 + UINT32 reg = 0;
60327 + RTMP_IO_READ32(pAd, 0x1300, &reg); // clear garbage interrupts
60328 + printk("0x1300 = %08x\n", reg);
60329 + }
60330 +
60331 + {
60332 +// u32 reg;
60333 +// u8 byte;
60334 +// u16 tmp;
60335 +
60336 +// RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg);
60337 +
60338 +// tmp = 0x0805;
60339 +// reg = (reg & 0xffff0000) | tmp;
60340 +// RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
60341 +
60342 + }
60343 +
60344 +#if 0
60345 + /*
60346 + * debugging helper
60347 + * show the size of main table in Adapter structure
60348 + * MacTab -- 185K
60349 + * BATable -- 137K
60350 + * Total -- 385K !!!!! (5/26/2006)
60351 + */
60352 + printk("sizeof(pAd->MacTab) = %ld\n", sizeof(pAd->MacTab));
60353 + printk("sizeof(pAd->AccessControlList) = %ld\n", sizeof(pAd->AccessControlList));
60354 + printk("sizeof(pAd->ApCfg) = %ld\n", sizeof(pAd->ApCfg));
60355 + printk("sizeof(pAd->BATable) = %ld\n", sizeof(pAd->BATable));
60356 + BUG();
60357 +#endif
60358 +
60359 +#ifdef CONFIG_STA_SUPPORT
60360 +#endif // CONFIG_STA_SUPPORT //
60361 +
60362 + return (retval);
60363 +
60364 +err:
60365 + return (-1);
60366 +} /* End of rt28xx_open */
60367 +
60368 +
60369 +/* Must not be called for mdev and apdev */
60370 +static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
60371 +{
60372 + NDIS_STATUS Status;
60373 + INT i=0;
60374 + CHAR slot_name[IFNAMSIZ];
60375 + struct net_device *device;
60376 +
60377 +
60378 + //ether_setup(dev);
60379 + dev->hard_start_xmit = rt28xx_send_packets;
60380 +
60381 +#ifdef IKANOS_VX_1X0
60382 + dev->hard_start_xmit = IKANOS_DataFramesTx;
60383 +#endif // IKANOS_VX_1X0 //
60384 +
60385 +// dev->set_multicast_list = ieee80211_set_multicast_list;
60386 +// dev->change_mtu = ieee80211_change_mtu;
60387 +#ifdef CONFIG_STA_SUPPORT
60388 +#if WIRELESS_EXT >= 12
60389 + if (pAd->OpMode == OPMODE_STA)
60390 + {
60391 + dev->wireless_handlers = &rt28xx_iw_handler_def;
60392 + }
60393 +#endif //WIRELESS_EXT >= 12
60394 +#endif // CONFIG_STA_SUPPORT //
60395 +
60396 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
60397 +#if WIRELESS_EXT >= 12
60398 + if (pAd->OpMode == OPMODE_AP)
60399 + {
60400 + dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
60401 + }
60402 +#endif //WIRELESS_EXT >= 12
60403 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
60404 +
60405 +#if WIRELESS_EXT < 21
60406 + dev->get_wireless_stats = rt28xx_get_wireless_stats;
60407 +#endif
60408 + dev->get_stats = RT28xx_get_ether_stats;
60409 + dev->open = MainVirtualIF_open; //rt28xx_open;
60410 + dev->stop = MainVirtualIF_close; //rt28xx_close;
60411 +// dev->uninit = ieee80211_if_reinit;
60412 +// dev->destructor = ieee80211_if_free;
60413 + dev->priv_flags = INT_MAIN;
60414 + dev->do_ioctl = rt28xx_ioctl;
60415 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
60416 + dev->validate_addr = NULL;
60417 +#endif
60418 + // find available device name
60419 + for (i = 0; i < 8; i++)
60420 + {
60421 +#ifdef MULTIPLE_CARD_SUPPORT
60422 + if (pAd->MC_RowID >= 0)
60423 + sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
60424 + else
60425 +#endif // MULTIPLE_CARD_SUPPORT //
60426 + sprintf(slot_name, "ra%d", i);
60427 +
60428 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
60429 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
60430 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
60431 + device = dev_get_by_name(dev_net(dev), slot_name);
60432 +#else
60433 + device = dev_get_by_name(dev->nd_net, slot_name);
60434 +#endif
60435 +#else
60436 + device = dev_get_by_name(slot_name);
60437 +#endif
60438 + if (device != NULL) dev_put(device);
60439 +#else
60440 + for (device = dev_base; device != NULL; device = device->next)
60441 + {
60442 + if (strncmp(device->name, slot_name, 4) == 0)
60443 + break;
60444 + }
60445 +#endif
60446 + if(device == NULL)
60447 + break;
60448 + }
60449 +
60450 + if(i == 8)
60451 + {
60452 + DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
60453 + Status = NDIS_STATUS_FAILURE;
60454 + }
60455 + else
60456 + {
60457 +#ifdef MULTIPLE_CARD_SUPPORT
60458 + if (pAd->MC_RowID >= 0)
60459 + sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
60460 + else
60461 +#endif // MULTIPLE_CARD_SUPPORT //
60462 + sprintf(dev->name, "ra%d", i);
60463 + Status = NDIS_STATUS_SUCCESS;
60464 + }
60465 +
60466 + return Status;
60467 +
60468 +}
60469 +
60470 +
60471 +#ifdef MULTIPLE_CARD_SUPPORT
60472 +/*
60473 +========================================================================
60474 +Routine Description:
60475 + Get card profile path.
60476 +
60477 +Arguments:
60478 + pAd
60479 +
60480 +Return Value:
60481 + TRUE - Find a card profile
60482 + FALSE - use default profile
60483 +
60484 +Note:
60485 +========================================================================
60486 +*/
60487 +extern INT RTMPGetKeyParameter(
60488 + IN PCHAR key,
60489 + OUT PCHAR dest,
60490 + IN INT destsize,
60491 + IN PCHAR buffer);
60492 +
60493 +BOOLEAN RTMP_CardInfoRead(
60494 + IN PRTMP_ADAPTER pAd)
60495 +{
60496 +#define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
60497 +#define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
60498 +#define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
60499 +
60500 +#define LETTER_CASE_TRANSLATE(txt_p, card_id) \
60501 + { UINT32 _len; char _char; \
60502 + for(_len=0; _len<strlen(card_id); _len++) { \
60503 + _char = *(txt_p + _len); \
60504 + if (('A' <= _char) && (_char <= 'Z')) \
60505 + *(txt_p+_len) = 'a'+(_char-'A'); \
60506 + } }
60507 +
60508 + struct file *srcf;
60509 + INT retval, orgfsuid, orgfsgid;
60510 + mm_segment_t orgfs;
60511 + CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
60512 + BOOLEAN flg_match_ok = FALSE;
60513 + INT32 card_select_method;
60514 + INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
60515 + EEPROM_ANTENNA_STRUC antenna;
60516 + USHORT addr01, addr23, addr45;
60517 + UINT8 mac[6];
60518 + UINT32 data, card_index;
60519 + UCHAR *start_ptr;
60520 +
60521 +
60522 + // init
60523 + buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
60524 + if (buffer == NULL)
60525 + return FALSE;
60526 +
60527 + tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
60528 + if(tmpbuf == NULL)
60529 + {
60530 + kfree(buffer);
60531 + return NDIS_STATUS_FAILURE;
60532 + }
60533 +
60534 + orgfsuid = current->fsuid;
60535 + orgfsgid = current->fsgid;
60536 + current->fsuid = current->fsgid = 0;
60537 + orgfs = get_fs();
60538 + set_fs(KERNEL_DS);
60539 +
60540 + // get RF IC type
60541 + RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
60542 +
60543 + if ((data & 0x30) == 0)
60544 + pAd->EEPROMAddressNum = 6; // 93C46
60545 + else if ((data & 0x30) == 0x10)
60546 + pAd->EEPROMAddressNum = 8; // 93C66
60547 + else
60548 + pAd->EEPROMAddressNum = 8; // 93C86
60549 +
60550 + //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
60551 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
60552 +
60553 + if ((antenna.field.RfIcType == RFIC_2850) ||
60554 + (antenna.field.RfIcType == RFIC_2750))
60555 + {
60556 + /* ABGN card */
60557 + strcpy(RFIC_word, "abgn");
60558 + }
60559 + else
60560 + {
60561 + /* BGN card */
60562 + strcpy(RFIC_word, "bgn");
60563 + }
60564 +
60565 + // get MAC address
60566 + //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
60567 + //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
60568 + //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
60569 + RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
60570 + RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
60571 + RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
60572 +
60573 + mac[0] = (UCHAR)(addr01 & 0xff);
60574 + mac[1] = (UCHAR)(addr01 >> 8);
60575 + mac[2] = (UCHAR)(addr23 & 0xff);
60576 + mac[3] = (UCHAR)(addr23 >> 8);
60577 + mac[4] = (UCHAR)(addr45 & 0xff);
60578 + mac[5] = (UCHAR)(addr45 >> 8);
60579 +
60580 + // open card information file
60581 + srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
60582 + if (IS_ERR(srcf))
60583 + {
60584 + /* card information file does not exist */
60585 + DBGPRINT(RT_DEBUG_TRACE,
60586 + ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
60587 + return FALSE;
60588 + }
60589 +
60590 + if (srcf->f_op && srcf->f_op->read)
60591 + {
60592 + /* card information file exists so reading the card information */
60593 + memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
60594 + retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
60595 + if (retval < 0)
60596 + {
60597 + /* read fail */
60598 + DBGPRINT(RT_DEBUG_TRACE,
60599 + ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
60600 + }
60601 + else
60602 + {
60603 + /* get card selection method */
60604 + memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
60605 + card_select_method = MC_SELECT_CARDTYPE; // default
60606 +
60607 + if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
60608 + {
60609 + if (strcmp(tmpbuf, "CARDID") == 0)
60610 + card_select_method = MC_SELECT_CARDID;
60611 + else if (strcmp(tmpbuf, "MAC") == 0)
60612 + card_select_method = MC_SELECT_MAC;
60613 + else if (strcmp(tmpbuf, "CARDTYPE") == 0)
60614 + card_select_method = MC_SELECT_CARDTYPE;
60615 + }
60616 +
60617 + DBGPRINT(RT_DEBUG_TRACE,
60618 + ("MC> Card Selection = %d\n", card_select_method));
60619 +
60620 + // init
60621 + card_free_id = -1;
60622 + card_nouse_id = -1;
60623 + card_same_mac_id = -1;
60624 + card_match_id = -1;
60625 +
60626 + // search current card information records
60627 + for(card_index=0;
60628 + card_index<MAX_NUM_OF_MULTIPLE_CARD;
60629 + card_index++)
60630 + {
60631 + if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
60632 + (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
60633 + {
60634 + // MAC is all-0 so the entry is available
60635 + MC_CardUsed[card_index] = 0;
60636 +
60637 + if (card_free_id < 0)
60638 + card_free_id = card_index; // 1st free entry
60639 + }
60640 + else
60641 + {
60642 + if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
60643 + {
60644 + // we find the entry with same MAC
60645 + if (card_same_mac_id < 0)
60646 + card_same_mac_id = card_index; // 1st same entry
60647 + }
60648 + else
60649 + {
60650 + // MAC is not all-0 but used flag == 0
60651 + if ((MC_CardUsed[card_index] == 0) &&
60652 + (card_nouse_id < 0))
60653 + {
60654 + card_nouse_id = card_index; // 1st available entry
60655 + }
60656 + }
60657 + }
60658 + }
60659 +
60660 + DBGPRINT(RT_DEBUG_TRACE,
60661 + ("MC> Free = %d, Same = %d, NOUSE = %d\n",
60662 + card_free_id, card_same_mac_id, card_nouse_id));
60663 +
60664 + if ((card_same_mac_id >= 0) &&
60665 + ((card_select_method == MC_SELECT_CARDID) ||
60666 + (card_select_method == MC_SELECT_CARDTYPE)))
60667 + {
60668 + // same MAC entry is found
60669 + card_match_id = card_same_mac_id;
60670 +
60671 + if (card_select_method == MC_SELECT_CARDTYPE)
60672 + {
60673 + // for CARDTYPE
60674 + sprintf(card_id_buf, "%02dCARDTYPE%s",
60675 + card_match_id, RFIC_word);
60676 +
60677 + if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
60678 + {
60679 + // we found the card ID
60680 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
60681 + }
60682 + }
60683 + }
60684 + else
60685 + {
60686 + // the card is 1st plug-in, try to find the match card profile
60687 + switch(card_select_method)
60688 + {
60689 + case MC_SELECT_CARDID: // CARDID
60690 + default:
60691 + if (card_free_id >= 0)
60692 + card_match_id = card_free_id;
60693 + else
60694 + card_match_id = card_nouse_id;
60695 + break;
60696 +
60697 + case MC_SELECT_MAC: // MAC
60698 + sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
60699 + mac[0], mac[1], mac[2],
60700 + mac[3], mac[4], mac[5]);
60701 +
60702 + /* try to find the key word in the card file */
60703 + if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
60704 + {
60705 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
60706 +
60707 + /* get the row ID (2 ASCII characters) */
60708 + start_ptr -= 2;
60709 + card_id_buf[0] = *(start_ptr);
60710 + card_id_buf[1] = *(start_ptr+1);
60711 + card_id_buf[2] = 0x00;
60712 +
60713 + card_match_id = simple_strtol(card_id_buf, 0, 10);
60714 + }
60715 + break;
60716 +
60717 + case MC_SELECT_CARDTYPE: // CARDTYPE
60718 + card_nouse_id = -1;
60719 +
60720 + for(card_index=0;
60721 + card_index<MAX_NUM_OF_MULTIPLE_CARD;
60722 + card_index++)
60723 + {
60724 + sprintf(card_id_buf, "%02dCARDTYPE%s",
60725 + card_index, RFIC_word);
60726 +
60727 + if ((start_ptr=rtstrstruncasecmp(buffer,
60728 + card_id_buf)) != NULL)
60729 + {
60730 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
60731 +
60732 + if (MC_CardUsed[card_index] == 0)
60733 + {
60734 + /* current the card profile is not used */
60735 + if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
60736 + (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
60737 + {
60738 + // find it and no previous card use it
60739 + card_match_id = card_index;
60740 + break;
60741 + }
60742 + else
60743 + {
60744 + // ever a card use it
60745 + if (card_nouse_id < 0)
60746 + card_nouse_id = card_index;
60747 + }
60748 + }
60749 + }
60750 + }
60751 +
60752 + // if not find a free one, use the available one
60753 + if (card_match_id < 0)
60754 + card_match_id = card_nouse_id;
60755 + break;
60756 + }
60757 + }
60758 +
60759 + if (card_match_id >= 0)
60760 + {
60761 + // make up search keyword
60762 + switch(card_select_method)
60763 + {
60764 + case MC_SELECT_CARDID: // CARDID
60765 + sprintf(card_id_buf, "%02dCARDID", card_match_id);
60766 + break;
60767 +
60768 + case MC_SELECT_MAC: // MAC
60769 + sprintf(card_id_buf,
60770 + "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
60771 + card_match_id,
60772 + mac[0], mac[1], mac[2],
60773 + mac[3], mac[4], mac[5]);
60774 + break;
60775 +
60776 + case MC_SELECT_CARDTYPE: // CARDTYPE
60777 + default:
60778 + sprintf(card_id_buf, "%02dcardtype%s",
60779 + card_match_id, RFIC_word);
60780 + break;
60781 + }
60782 +
60783 + DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
60784 +
60785 + // read card file path
60786 + if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
60787 + {
60788 + if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
60789 + {
60790 + // backup card information
60791 + pAd->MC_RowID = card_match_id; /* base 0 */
60792 + MC_CardUsed[card_match_id] = 1;
60793 + memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
60794 +
60795 + // backup card file path
60796 + NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
60797 + pAd->MC_FileName[strlen(tmpbuf)] = '\0';
60798 + flg_match_ok = TRUE;
60799 +
60800 + DBGPRINT(RT_DEBUG_TRACE,
60801 + ("Card Profile Name = %s\n", pAd->MC_FileName));
60802 + }
60803 + else
60804 + {
60805 + DBGPRINT(RT_DEBUG_ERROR,
60806 + ("Card Profile Name length too large!\n"));
60807 + }
60808 + }
60809 + else
60810 + {
60811 + DBGPRINT(RT_DEBUG_ERROR,
60812 + ("Can not find search key word in card.dat!\n"));
60813 + }
60814 +
60815 + if ((flg_match_ok != TRUE) &&
60816 + (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
60817 + {
60818 + MC_CardUsed[card_match_id] = 0;
60819 + memset(MC_CardMac[card_match_id], 0, sizeof(mac));
60820 + }
60821 + } // if (card_match_id >= 0)
60822 + }
60823 + }
60824 +
60825 + // close file
60826 + retval = filp_close(srcf, NULL);
60827 + set_fs(orgfs);
60828 + current->fsuid = orgfsuid;
60829 + current->fsgid = orgfsgid;
60830 + kfree(buffer);
60831 + kfree(tmpbuf);
60832 + return flg_match_ok;
60833 +}
60834 +#endif // MULTIPLE_CARD_SUPPORT //
60835 +
60836 +
60837 +/*
60838 +========================================================================
60839 +Routine Description:
60840 + Probe RT28XX chipset.
60841 +
60842 +Arguments:
60843 + _dev_p Point to the PCI or USB device
60844 + _dev_id_p Point to the PCI or USB device ID
60845 +
60846 +Return Value:
60847 + 0 Probe OK
60848 + -ENODEV Probe Fail
60849 +
60850 +Note:
60851 +========================================================================
60852 +*/
60853 +INT __devinit rt28xx_probe(
60854 + IN void *_dev_p,
60855 + IN void *_dev_id_p,
60856 + IN UINT argc,
60857 + OUT PRTMP_ADAPTER *ppAd)
60858 +{
60859 + struct net_device *net_dev;
60860 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
60861 + INT status;
60862 + PVOID handle;
60863 +#ifdef RT2870
60864 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
60865 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
60866 +#else
60867 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
60868 + struct usb_device *dev_p = interface_to_usbdev(intf);
60869 +
60870 + dev_p = usb_get_dev(dev_p);
60871 +#endif // LINUX_VERSION_CODE //
60872 +#endif // RT2870 //
60873 +
60874 +
60875 +#ifdef CONFIG_STA_SUPPORT
60876 + DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
60877 +#endif // CONFIG_STA_SUPPORT //
60878 +
60879 + // Check chipset vendor/product ID
60880 +// if (RT28XXChipsetCheck(_dev_p) == FALSE)
60881 +// goto err_out;
60882 +
60883 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
60884 + net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
60885 +#else
60886 + net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
60887 +#endif
60888 + if (net_dev == NULL)
60889 + {
60890 + printk("alloc_netdev failed\n");
60891 +
60892 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
60893 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
60894 + module_put(THIS_MODULE);
60895 +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
60896 +#else
60897 + MOD_DEC_USE_COUNT;
60898 +#endif
60899 + goto err_out;
60900 + }
60901 +
60902 +// sample
60903 +// if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
60904 +// goto err_out;
60905 +
60906 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
60907 + SET_MODULE_OWNER(net_dev);
60908 +#endif
60909 +
60910 + netif_stop_queue(net_dev);
60911 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
60912 +/* for supporting Network Manager */
60913 +/* Set the sysfs physical device reference for the network logical device
60914 + * if set prior to registration will cause a symlink during initialization.
60915 + */
60916 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
60917 + SET_NETDEV_DEV(net_dev, &(dev_p->dev));
60918 +#endif
60919 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
60920 +
60921 + // Allocate RTMP_ADAPTER miniport adapter structure
60922 + handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
60923 + RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
60924 +
60925 + status = RTMPAllocAdapterBlock(handle, &pAd);
60926 + if (status != NDIS_STATUS_SUCCESS)
60927 + goto err_out_free_netdev;
60928 +
60929 + net_dev->priv = (PVOID)pAd;
60930 + pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
60931 +
60932 + RT28XXNetDevInit(_dev_p, net_dev, pAd);
60933 +
60934 +#ifdef CONFIG_STA_SUPPORT
60935 + pAd->StaCfg.OriDevType = net_dev->type;
60936 +#endif // CONFIG_STA_SUPPORT //
60937 +
60938 + // Find and assign a free interface name, raxx
60939 +// RT28XXAvailRANameAssign(net_dev->name);
60940 +
60941 + // Post config
60942 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
60943 + if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
60944 + goto err_out_unmap;
60945 +#else
60946 + if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
60947 + goto err_out_unmap;
60948 +#endif // LINUX_VERSION_CODE //
60949 +
60950 +#ifdef CONFIG_STA_SUPPORT
60951 + pAd->OpMode = OPMODE_STA;
60952 +#endif // CONFIG_STA_SUPPORT //
60953 +
60954 +
60955 +#ifdef MULTIPLE_CARD_SUPPORT
60956 + // find its profile path
60957 + pAd->MC_RowID = -1; // use default profile path
60958 + RTMP_CardInfoRead(pAd);
60959 +
60960 + if (pAd->MC_RowID == -1)
60961 +#ifdef CONFIG_STA_SUPPORT
60962 + strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
60963 +#endif // CONFIG_STA_SUPPORT //
60964 +
60965 + DBGPRINT(RT_DEBUG_TRACE,
60966 + ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
60967 +#endif // MULTIPLE_CARD_SUPPORT //
60968 +
60969 + // sample move
60970 + if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
60971 + goto err_out_unmap;
60972 +
60973 + // Register this device
60974 + status = register_netdev(net_dev);
60975 + if (status)
60976 + goto err_out_unmap;
60977 +
60978 + // Set driver data
60979 + RT28XX_DRVDATA_SET(_dev_p);
60980 +
60981 +
60982 +
60983 + *ppAd = pAd;
60984 + return 0; // probe ok
60985 +
60986 +
60987 + /* --------------------------- ERROR HANDLE --------------------------- */
60988 +err_out_unmap:
60989 + RTMPFreeAdapter(pAd);
60990 + RT28XX_UNMAP();
60991 +
60992 +err_out_free_netdev:
60993 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
60994 + free_netdev(net_dev);
60995 +#else
60996 + kfree(net_dev);
60997 +#endif
60998 +
60999 +err_out:
61000 + RT28XX_PUT_DEVICE(dev_p);
61001 +
61002 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
61003 + return (LONG)NULL;
61004 +#else
61005 + return -ENODEV; /* probe fail */
61006 +#endif // LINUX_VERSION_CODE //
61007 +} /* End of rt28xx_probe */
61008 +
61009 +
61010 +/*
61011 +========================================================================
61012 +Routine Description:
61013 + The entry point for Linux kernel sent packet to our driver.
61014 +
61015 +Arguments:
61016 + sk_buff *skb the pointer refer to a sk_buffer.
61017 +
61018 +Return Value:
61019 + 0
61020 +
61021 +Note:
61022 + This function is the entry point of Tx Path for Os delivery packet to
61023 + our driver. You only can put OS-depened & STA/AP common handle procedures
61024 + in here.
61025 +========================================================================
61026 +*/
61027 +int rt28xx_packet_xmit(struct sk_buff *skb)
61028 +{
61029 + struct net_device *net_dev = skb->dev;
61030 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv;
61031 + int status = 0;
61032 + PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
61033 +
61034 + /* RT2870STA does this in RTMPSendPackets() */
61035 +#ifdef RALINK_ATE
61036 + if (ATE_ON(pAd))
61037 + {
61038 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
61039 + return 0;
61040 + }
61041 +#endif // RALINK_ATE //
61042 +
61043 +#ifdef CONFIG_STA_SUPPORT
61044 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61045 + {
61046 + // Drop send request since we are in monitor mode
61047 + if (MONITOR_ON(pAd))
61048 + {
61049 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
61050 + goto done;
61051 + }
61052 + }
61053 +#endif // CONFIG_STA_SUPPORT //
61054 +
61055 + // EapolStart size is 18
61056 + if (skb->len < 14)
61057 + {
61058 + //printk("bad packet size: %d\n", pkt->len);
61059 + hex_dump("bad packet", skb->data, skb->len);
61060 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
61061 + goto done;
61062 + }
61063 +
61064 +#if 0
61065 +// if ((pkt->data[0] & 0x1) == 0)
61066 + {
61067 + //hex_dump(__FUNCTION__, pkt->data, pkt->len);
61068 + printk("pPacket = %x\n", pPacket);
61069 + }
61070 +#endif
61071 +
61072 + RTMP_SET_PACKET_5VT(pPacket, 0);
61073 +// MiniportMMRequest(pAd, pkt->data, pkt->len);
61074 +#ifdef CONFIG_5VT_ENHANCE
61075 + if (*(int*)(skb->cb) == BRIDGE_TAG) {
61076 + RTMP_SET_PACKET_5VT(pPacket, 1);
61077 + }
61078 +#endif
61079 +
61080 +
61081 +
61082 +#ifdef CONFIG_STA_SUPPORT
61083 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61084 + {
61085 +
61086 + STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
61087 + }
61088 +
61089 +#endif // CONFIG_STA_SUPPORT //
61090 +
61091 + status = 0;
61092 +done:
61093 +
61094 + return status;
61095 +}
61096 +
61097 +
61098 +/*
61099 +========================================================================
61100 +Routine Description:
61101 + Send a packet to WLAN.
61102 +
61103 +Arguments:
61104 + skb_p points to our adapter
61105 + dev_p which WLAN network interface
61106 +
61107 +Return Value:
61108 + 0: transmit successfully
61109 + otherwise: transmit fail
61110 +
61111 +Note:
61112 +========================================================================
61113 +*/
61114 +INT rt28xx_send_packets(
61115 + IN struct sk_buff *skb_p,
61116 + IN struct net_device *net_dev)
61117 +{
61118 + RTMP_ADAPTER *pAd = net_dev->priv;
61119 +
61120 + if (!(net_dev->flags & IFF_UP))
61121 + {
61122 + RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
61123 + return 0;
61124 + }
61125 +
61126 + NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
61127 + RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
61128 +
61129 + return rt28xx_packet_xmit(skb_p);
61130 +} /* End of MBSS_VirtualIF_PacketSend */
61131 +
61132 +
61133 +
61134 +
61135 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
61136 +//static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
61137 +struct net_device *alloc_netdev(
61138 + int sizeof_priv,
61139 + const char *mask,
61140 + void (*setup)(struct net_device *))
61141 +{
61142 + struct net_device *dev;
61143 + INT alloc_size;
61144 +
61145 +
61146 + /* ensure 32-byte alignment of the private area */
61147 + alloc_size = sizeof (*dev) + sizeof_priv + 31;
61148 +
61149 + dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
61150 + if (dev == NULL)
61151 + {
61152 + DBGPRINT(RT_DEBUG_ERROR,
61153 + ("alloc_netdev: Unable to allocate device memory.\n"));
61154 + return NULL;
61155 + }
61156 +
61157 + memset(dev, 0, alloc_size);
61158 +
61159 + if (sizeof_priv)
61160 + dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
61161 +
61162 + setup(dev);
61163 + strcpy(dev->name, mask);
61164 +
61165 + return dev;
61166 +}
61167 +#endif // LINUX_VERSION_CODE //
61168 +
61169 +
61170 +void CfgInitHook(PRTMP_ADAPTER pAd)
61171 +{
61172 + pAd->bBroadComHT = TRUE;
61173 +} /* End of CfgInitHook */
61174 +
61175 +
61176 +#if 0 // Not used now, should keep it in our source tree??
61177 +/*
61178 +========================================================================
61179 +Routine Description:
61180 + Find and assign a free interface name (raxx).
61181 +
61182 +Arguments:
61183 + *name_p the interface name pointer
61184 +
61185 +Return Value:
61186 + TRUE OK
61187 + FALSE FAIL
61188 +
61189 +Note:
61190 +========================================================================
61191 +*/
61192 +static BOOLEAN RT28XXAvailRANameAssign(
61193 + IN CHAR *name_p)
61194 +{
61195 + CHAR slot_name[IFNAMSIZ];
61196 + struct net_device *device;
61197 + UINT32 if_id;
61198 +
61199 +
61200 + for(if_id=0; if_id<8; if_id++)
61201 + {
61202 + sprintf(slot_name, "ra%d", if_id);
61203 +
61204 + for(device=dev_base; device!=NULL; device=device->next)
61205 + {
61206 + if (strncmp(device->name, slot_name, 4) == 0)
61207 + break;
61208 + }
61209 +
61210 + if (device == NULL)
61211 + break;
61212 + }
61213 +
61214 + if (if_id == 8)
61215 + {
61216 + DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
61217 + return FALSE;
61218 + }
61219 +
61220 + sprintf(name_p, "ra%d", if_id);
61221 + return TRUE;
61222 +} /* End of RT28XXAvailRANameAssign */
61223 +#endif
61224 +
61225 +#if WIRELESS_EXT >= 12
61226 +// This function will be called when query /proc
61227 +struct iw_statistics *rt28xx_get_wireless_stats(
61228 + IN struct net_device *net_dev)
61229 +{
61230 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv;
61231 +
61232 +
61233 + DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
61234 +
61235 + pAd->iw_stats.status = 0; // Status - device dependent for now
61236 +
61237 + // link quality
61238 + pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
61239 + if(pAd->iw_stats.qual.qual > 100)
61240 + pAd->iw_stats.qual.qual = 100;
61241 +
61242 +#ifdef CONFIG_STA_SUPPORT
61243 + if (pAd->OpMode == OPMODE_STA)
61244 + pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
61245 +#endif // CONFIG_STA_SUPPORT //
61246 +
61247 + pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
61248 +
61249 + pAd->iw_stats.qual.noise += 256 - 143;
61250 + pAd->iw_stats.qual.updated = 1; // Flags to know if updated
61251 +#ifdef IW_QUAL_DBM
61252 + pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
61253 +#endif // IW_QUAL_DBM //
61254 +
61255 + pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
61256 + pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
61257 +
61258 + DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
61259 + return &pAd->iw_stats;
61260 +} /* End of rt28xx_get_wireless_stats */
61261 +#endif // WIRELESS_EXT //
61262 +
61263 +
61264 +
61265 +void tbtt_tasklet(unsigned long data)
61266 +{
61267 +#define MAX_TX_IN_TBTT (16)
61268 +
61269 +}
61270 +
61271 +INT rt28xx_ioctl(
61272 + IN struct net_device *net_dev,
61273 + IN OUT struct ifreq *rq,
61274 + IN INT cmd)
61275 +{
61276 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
61277 + RTMP_ADAPTER *pAd = NULL;
61278 + INT ret = 0;
61279 +
61280 + if (net_dev->priv_flags == INT_MAIN)
61281 + {
61282 + pAd = net_dev->priv;
61283 + }
61284 + else
61285 + {
61286 + pVirtualAd = net_dev->priv;
61287 + pAd = pVirtualAd->RtmpDev->priv;
61288 + }
61289 +
61290 + if (pAd == NULL)
61291 + {
61292 + /* if 1st open fail, pAd will be free;
61293 + So the net_dev->priv will be NULL in 2rd open */
61294 + return -ENETDOWN;
61295 + }
61296 +
61297 +
61298 +#ifdef CONFIG_STA_SUPPORT
61299 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61300 + {
61301 + ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
61302 + }
61303 +#endif // CONFIG_STA_SUPPORT //
61304 +
61305 + return ret;
61306 +}
61307 +
61308 +/*
61309 + ========================================================================
61310 +
61311 + Routine Description:
61312 + return ethernet statistics counter
61313 +
61314 + Arguments:
61315 + net_dev Pointer to net_device
61316 +
61317 + Return Value:
61318 + net_device_stats*
61319 +
61320 + Note:
61321 +
61322 + ========================================================================
61323 +*/
61324 +struct net_device_stats *RT28xx_get_ether_stats(
61325 + IN struct net_device *net_dev)
61326 +{
61327 + RTMP_ADAPTER *pAd = NULL;
61328 +
61329 + if (net_dev)
61330 + pAd = net_dev->priv;
61331 +
61332 + if (pAd)
61333 + {
61334 +
61335 + pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
61336 + pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
61337 +
61338 + pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
61339 + pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
61340 +
61341 + pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
61342 + pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
61343 +
61344 + pAd->stats.rx_dropped = 0;
61345 + pAd->stats.tx_dropped = 0;
61346 +
61347 + pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
61348 + pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
61349 +
61350 + pAd->stats.rx_length_errors = 0;
61351 + pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
61352 + pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
61353 + pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
61354 + pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
61355 + pAd->stats.rx_missed_errors = 0; // receiver missed packet
61356 +
61357 + // detailed tx_errors
61358 + pAd->stats.tx_aborted_errors = 0;
61359 + pAd->stats.tx_carrier_errors = 0;
61360 + pAd->stats.tx_fifo_errors = 0;
61361 + pAd->stats.tx_heartbeat_errors = 0;
61362 + pAd->stats.tx_window_errors = 0;
61363 +
61364 + // for cslip etc
61365 + pAd->stats.rx_compressed = 0;
61366 + pAd->stats.tx_compressed = 0;
61367 +
61368 + return &pAd->stats;
61369 + }
61370 + else
61371 + return NULL;
61372 +}
61373 +
61374 --- /dev/null
61375 +++ b/drivers/staging/rt2870/rtmp_ckipmic.h
61376 @@ -0,0 +1,113 @@
61377 +/*
61378 + *************************************************************************
61379 + * Ralink Tech Inc.
61380 + * 5F., No.36, Taiyuan St., Jhubei City,
61381 + * Hsinchu County 302,
61382 + * Taiwan, R.O.C.
61383 + *
61384 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
61385 + *
61386 + * This program is free software; you can redistribute it and/or modify *
61387 + * it under the terms of the GNU General Public License as published by *
61388 + * the Free Software Foundation; either version 2 of the License, or *
61389 + * (at your option) any later version. *
61390 + * *
61391 + * This program is distributed in the hope that it will be useful, *
61392 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
61393 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
61394 + * GNU General Public License for more details. *
61395 + * *
61396 + * You should have received a copy of the GNU General Public License *
61397 + * along with this program; if not, write to the *
61398 + * Free Software Foundation, Inc., *
61399 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
61400 + * *
61401 + *************************************************************************
61402 +
61403 + Module Name:
61404 + rtmp_ckipmic.h
61405 +
61406 + Abstract:
61407 +
61408 + Revision History:
61409 + Who When What
61410 + -------- ---------- ----------------------------------------------
61411 + Name Date Modification logs
61412 +*/
61413 +#ifndef __RTMP_CKIPMIC_H__
61414 +#define __RTMP_CKIPMIC_H__
61415 +
61416 +typedef struct _MIC_CONTEXT {
61417 + /* --- MMH context */
61418 + UCHAR CK[16]; /* the key */
61419 + UCHAR coefficient[16]; /* current aes counter mode coefficients */
61420 + ULONGLONG accum; /* accumulated mic, reduced to u32 in final() */
61421 + UINT position; /* current position (byte offset) in message */
61422 + UCHAR part[4]; /* for conversion of message to u32 for mmh */
61423 +} MIC_CONTEXT, *PMIC_CONTEXT;
61424 +
61425 +VOID CKIP_key_permute(
61426 + OUT UCHAR *PK, /* output permuted key */
61427 + IN UCHAR *CK, /* input CKIP key */
61428 + IN UCHAR toDsFromDs, /* input toDs/FromDs bits */
61429 + IN UCHAR *piv); /* input pointer to IV */
61430 +
61431 +VOID RTMPCkipMicInit(
61432 + IN PMIC_CONTEXT pContext,
61433 + IN PUCHAR CK);
61434 +
61435 +VOID RTMPMicUpdate(
61436 + IN PMIC_CONTEXT pContext,
61437 + IN PUCHAR pOctets,
61438 + IN INT len);
61439 +
61440 +ULONG RTMPMicGetCoefficient(
61441 + IN PMIC_CONTEXT pContext);
61442 +
61443 +VOID xor_128(
61444 + IN PUCHAR a,
61445 + IN PUCHAR b,
61446 + OUT PUCHAR out);
61447 +
61448 +UCHAR RTMPCkipSbox(
61449 + IN UCHAR a);
61450 +
61451 +VOID xor_32(
61452 + IN PUCHAR a,
61453 + IN PUCHAR b,
61454 + OUT PUCHAR out);
61455 +
61456 +VOID next_key(
61457 + IN PUCHAR key,
61458 + IN INT round);
61459 +
61460 +VOID byte_sub(
61461 + IN PUCHAR in,
61462 + OUT PUCHAR out);
61463 +
61464 +VOID shift_row(
61465 + IN PUCHAR in,
61466 + OUT PUCHAR out);
61467 +
61468 +VOID mix_column(
61469 + IN PUCHAR in,
61470 + OUT PUCHAR out);
61471 +
61472 +VOID RTMPAesEncrypt(
61473 + IN PUCHAR key,
61474 + IN PUCHAR data,
61475 + IN PUCHAR ciphertext);
61476 +
61477 +VOID RTMPMicFinal(
61478 + IN PMIC_CONTEXT pContext,
61479 + OUT UCHAR digest[4]);
61480 +
61481 +VOID RTMPCkipInsertCMIC(
61482 + IN PRTMP_ADAPTER pAd,
61483 + OUT PUCHAR pMIC,
61484 + IN PUCHAR p80211hdr,
61485 + IN PNDIS_PACKET pPacket,
61486 + IN PCIPHER_KEY pKey,
61487 + IN PUCHAR mic_snap);
61488 +
61489 +#endif //__RTMP_CKIPMIC_H__
61490 --- /dev/null
61491 +++ b/drivers/staging/rt2870/rtmp_def.h
61492 @@ -0,0 +1,1622 @@
61493 +/*
61494 + *************************************************************************
61495 + * Ralink Tech Inc.
61496 + * 5F., No.36, Taiyuan St., Jhubei City,
61497 + * Hsinchu County 302,
61498 + * Taiwan, R.O.C.
61499 + *
61500 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
61501 + *
61502 + * This program is free software; you can redistribute it and/or modify *
61503 + * it under the terms of the GNU General Public License as published by *
61504 + * the Free Software Foundation; either version 2 of the License, or *
61505 + * (at your option) any later version. *
61506 + * *
61507 + * This program is distributed in the hope that it will be useful, *
61508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
61509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
61510 + * GNU General Public License for more details. *
61511 + * *
61512 + * You should have received a copy of the GNU General Public License *
61513 + * along with this program; if not, write to the *
61514 + * Free Software Foundation, Inc., *
61515 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
61516 + * *
61517 + *************************************************************************
61518 +
61519 + Module Name:
61520 + rtmp_def.h
61521 +
61522 + Abstract:
61523 + Miniport related definition header
61524 +
61525 + Revision History:
61526 + Who When What
61527 + -------- ---------- ----------------------------------------------
61528 + Paul Lin 08-01-2002 created
61529 + John Chang 08-05-2003 add definition for 11g & other drafts
61530 +*/
61531 +#ifndef __RTMP_DEF_H__
61532 +#define __RTMP_DEF_H__
61533 +
61534 +#include "oid.h"
61535 +
61536 +//
61537 +// Debug information verbosity: lower values indicate higher urgency
61538 +//
61539 +#define RT_DEBUG_OFF 0
61540 +#define RT_DEBUG_ERROR 1
61541 +#define RT_DEBUG_WARN 2
61542 +#define RT_DEBUG_TRACE 3
61543 +#define RT_DEBUG_INFO 4
61544 +#define RT_DEBUG_LOUD 5
61545 +
61546 +#define NIC_TAG ((ULONG)'0682')
61547 +#define NIC_DBG_STRING ("**RT28xx**")
61548 +
61549 +#ifdef SNMP_SUPPORT
61550 +// for snmp
61551 +// to get manufacturer OUI, kathy, 2008_0220
61552 +#define ManufacturerOUI_LEN 3
61553 +#define ManufacturerNAME ("Ralink Technology Company.")
61554 +#define ResourceTypeIdName ("Ralink_ID")
61555 +#endif
61556 +
61557 +
61558 +//#define PACKED
61559 +
61560 +#define RALINK_2883_VERSION ((UINT32)0x28830300)
61561 +#define RALINK_2880E_VERSION ((UINT32)0x28720200)
61562 +#define RALINK_3070_VERSION ((UINT32)0x30700200)
61563 +
61564 +//
61565 +// NDIS version in use by the NIC driver.
61566 +// The high byte is the major version. The low byte is the minor version.
61567 +//
61568 +#ifdef NDIS51_MINIPORT
61569 +#define NIC_DRIVER_VERSION 0x0501
61570 +#else
61571 +#define NIC_DRIVER_VERSION 0x0500
61572 +#endif
61573 +
61574 +//
61575 +// NDIS media type, current is ethernet, change if native wireless supported
61576 +//
61577 +#define NIC_MEDIA_TYPE NdisMedium802_3
61578 +#define NIC_PCI_HDR_LENGTH 0xe2
61579 +#define NIC_MAX_PACKET_SIZE 2304
61580 +#define NIC_HEADER_SIZE 14
61581 +#define MAX_MAP_REGISTERS_NEEDED 32
61582 +#define MIN_MAP_REGISTERS_NEEDED 2 //Todo: should consider fragment issue.
61583 +
61584 +//
61585 +// interface type, we use PCI
61586 +//
61587 +#define NIC_INTERFACE_TYPE NdisInterfacePci
61588 +#define NIC_INTERRUPT_MODE NdisInterruptLevelSensitive
61589 +
61590 +//
61591 +// buffer size passed in NdisMQueryAdapterResources
61592 +// We should only need three adapter resources (IO, interrupt and memory),
61593 +// Some devices get extra resources, so have room for 10 resources
61594 +// UF_SIZE (sizeof(NDIS_RESOURCE_LIST) + (10*sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)))
61595 +
61596 +
61597 +#define NIC_RESOURCE_B//
61598 +// IO space length
61599 +//
61600 +#define NIC_MAP_IOSPACE_LENGTH sizeof(CSR_STRUC)
61601 +
61602 +#define MAX_RX_PKT_LEN 1520
61603 +
61604 +//
61605 +// Entry number for each DMA descriptor ring
61606 +//
61607 +
61608 +
61609 +#ifdef RT2870
61610 +#define TX_RING_SIZE 8 // 1
61611 +#define PRIO_RING_SIZE 8
61612 +#define MGMT_RING_SIZE 32 // PRIO_RING_SIZE
61613 +#define RX_RING_SIZE 8
61614 +#define MAX_TX_PROCESS 4
61615 +#define LOCAL_TXBUF_SIZE 2048
61616 +#endif // RT2870 //
61617 +
61618 +#ifdef MULTIPLE_CARD_SUPPORT
61619 +// MC: Multple Cards
61620 +#define MAX_NUM_OF_MULTIPLE_CARD 32
61621 +#endif // MULTIPLE_CARD_SUPPORT //
61622 +
61623 +#define MAX_RX_PROCESS 128 //64 //32
61624 +#define NUM_OF_LOCAL_TXBUF 2
61625 +#define TXD_SIZE 16
61626 +#define TXWI_SIZE 16
61627 +#define RXD_SIZE 16
61628 +#define RXWI_SIZE 16
61629 +// TXINFO_SIZE + TXWI_SIZE + 802.11 Header Size + AMSDU sub frame header
61630 +#define TX_DMA_1ST_BUFFER_SIZE 96 // only the 1st physical buffer is pre-allocated
61631 +#define MGMT_DMA_BUFFER_SIZE 1536 //2048
61632 +#define RX_BUFFER_AGGRESIZE 3840 //3904 //3968 //4096 //2048 //4096
61633 +#define RX_BUFFER_NORMSIZE 3840 //3904 //3968 //4096 //2048 //4096
61634 +#define TX_BUFFER_NORMSIZE RX_BUFFER_NORMSIZE
61635 +#define MAX_FRAME_SIZE 2346 // Maximum 802.11 frame size
61636 +#define MAX_AGGREGATION_SIZE 3840 //3904 //3968 //4096
61637 +#define MAX_NUM_OF_TUPLE_CACHE 2
61638 +#define MAX_MCAST_LIST_SIZE 32
61639 +#define MAX_LEN_OF_VENDOR_DESC 64
61640 +//#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
61641 +#define MAX_SIZE_OF_MCAST_PSQ 32
61642 +
61643 +#define MAX_RX_PROCESS_CNT (RX_RING_SIZE)
61644 +
61645 +
61646 +#define MAX_PACKETS_IN_QUEUE (512) //(512) // to pass WMM A5-WPAPSK
61647 +#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32
61648 +#define MAX_PACKETS_IN_PS_QUEUE 128 //32
61649 +#define WMM_NUM_OF_AC 4 /* AC0, AC1, AC2, and AC3 */
61650 +
61651 +
61652 +
61653 +// RxFilter
61654 +#define STANORMAL 0x17f97
61655 +#define APNORMAL 0x15f97
61656 +//
61657 +// RTMP_ADAPTER flags
61658 +//
61659 +#define fRTMP_ADAPTER_MAP_REGISTER 0x00000001
61660 +#define fRTMP_ADAPTER_INTERRUPT_IN_USE 0x00000002
61661 +#define fRTMP_ADAPTER_HARDWARE_ERROR 0x00000004
61662 +#define fRTMP_ADAPTER_SCATTER_GATHER 0x00000008
61663 +#define fRTMP_ADAPTER_SEND_PACKET_ERROR 0x00000010
61664 +#define fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS 0x00000020
61665 +#define fRTMP_ADAPTER_HALT_IN_PROGRESS 0x00000040
61666 +#define fRTMP_ADAPTER_RESET_IN_PROGRESS 0x00000080
61667 +#define fRTMP_ADAPTER_NIC_NOT_EXIST 0x00000100
61668 +#define fRTMP_ADAPTER_TX_RING_ALLOCATED 0x00000200
61669 +#define fRTMP_ADAPTER_REMOVE_IN_PROGRESS 0x00000400
61670 +#define fRTMP_ADAPTER_MIMORATE_INUSED 0x00000800
61671 +#define fRTMP_ADAPTER_RX_RING_ALLOCATED 0x00001000
61672 +#define fRTMP_ADAPTER_INTERRUPT_ACTIVE 0x00002000
61673 +#define fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS 0x00004000
61674 +#define fRTMP_ADAPTER_REASSOC_IN_PROGRESS 0x00008000
61675 +#define fRTMP_ADAPTER_MEDIA_STATE_PENDING 0x00010000
61676 +#define fRTMP_ADAPTER_RADIO_OFF 0x00020000
61677 +#define fRTMP_ADAPTER_BULKOUT_RESET 0x00040000
61678 +#define fRTMP_ADAPTER_BULKIN_RESET 0x00080000
61679 +#define fRTMP_ADAPTER_RDG_ACTIVE 0x00100000
61680 +#define fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE 0x00200000
61681 +#define fRTMP_ADAPTER_SCAN_2040 0x04000000
61682 +#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000
61683 +
61684 +#define fRTMP_ADAPTER_START_UP 0x10000000 //Devive already initialized and enabled Tx/Rx.
61685 +#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000
61686 +#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000
61687 +
61688 +// Lock bit for accessing different ring buffers
61689 +//#define fRTMP_ADAPTER_TX_RING_BUSY 0x80000000
61690 +//#define fRTMP_ADAPTER_MGMT_RING_BUSY 0x40000000
61691 +//#define fRTMP_ADAPTER_ATIM_RING_BUSY 0x20000000
61692 +//#define fRTMP_ADAPTER_RX_RING_BUSY 0x10000000
61693 +
61694 +// Lock bit for accessing different queue
61695 +//#define fRTMP_ADAPTER_TX_QUEUE_BUSY 0x08000000
61696 +//#define fRTMP_ADAPTER_MGMT_QUEUE_BUSY 0x04000000
61697 +
61698 +//
61699 +// STA operation status flags
61700 +//
61701 +#define fOP_STATUS_INFRA_ON 0x00000001
61702 +#define fOP_STATUS_ADHOC_ON 0x00000002
61703 +#define fOP_STATUS_BG_PROTECTION_INUSED 0x00000004
61704 +#define fOP_STATUS_SHORT_SLOT_INUSED 0x00000008
61705 +#define fOP_STATUS_SHORT_PREAMBLE_INUSED 0x00000010
61706 +#define fOP_STATUS_RECEIVE_DTIM 0x00000020
61707 +//#define fOP_STATUS_TX_RATE_SWITCH_ENABLED 0x00000040
61708 +#define fOP_STATUS_MEDIA_STATE_CONNECTED 0x00000080
61709 +#define fOP_STATUS_WMM_INUSED 0x00000100
61710 +#define fOP_STATUS_AGGREGATION_INUSED 0x00000200
61711 +#define fOP_STATUS_DOZE 0x00000400 // debug purpose
61712 +#define fOP_STATUS_PIGGYBACK_INUSED 0x00000800 // piggy-back, and aggregation
61713 +#define fOP_STATUS_APSD_INUSED 0x00001000
61714 +#define fOP_STATUS_TX_AMSDU_INUSED 0x00002000
61715 +#define fOP_STATUS_MAX_RETRY_ENABLED 0x00004000
61716 +#define fOP_STATUS_WAKEUP_NOW 0x00008000
61717 +#define fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE 0x00020000
61718 +
61719 +#ifdef DOT11N_DRAFT3
61720 +#define fOP_STATUS_SCAN_2040 0x00040000
61721 +#endif // DOT11N_DRAFT3 //
61722 +
61723 +#define CCKSETPROTECT 0x1
61724 +#define OFDMSETPROTECT 0x2
61725 +#define MM20SETPROTECT 0x4
61726 +#define MM40SETPROTECT 0x8
61727 +#define GF20SETPROTECT 0x10
61728 +#define GR40SETPROTECT 0x20
61729 +#define ALLN_SETPROTECT (GR40SETPROTECT | GF20SETPROTECT | MM40SETPROTECT | MM20SETPROTECT)
61730 +
61731 +//
61732 +// AP's client table operation status flags
61733 +//
61734 +#define fCLIENT_STATUS_WMM_CAPABLE 0x00000001 // CLIENT can parse QOS DATA frame
61735 +#define fCLIENT_STATUS_AGGREGATION_CAPABLE 0x00000002 // CLIENT can receive Ralink's proprietary TX aggregation frame
61736 +#define fCLIENT_STATUS_PIGGYBACK_CAPABLE 0x00000004 // CLIENT support piggy-back
61737 +#define fCLIENT_STATUS_AMSDU_INUSED 0x00000008
61738 +#define fCLIENT_STATUS_SGI20_CAPABLE 0x00000010
61739 +#define fCLIENT_STATUS_SGI40_CAPABLE 0x00000020
61740 +#define fCLIENT_STATUS_TxSTBC_CAPABLE 0x00000040
61741 +#define fCLIENT_STATUS_RxSTBC_CAPABLE 0x00000080
61742 +#define fCLIENT_STATUS_HTC_CAPABLE 0x00000100
61743 +#define fCLIENT_STATUS_RDG_CAPABLE 0x00000200
61744 +#define fCLIENT_STATUS_MCSFEEDBACK_CAPABLE 0x00000400
61745 +#define fCLIENT_STATUS_APSD_CAPABLE 0x00000800 /* UAPSD STATION */
61746 +
61747 +#ifdef DOT11N_DRAFT3
61748 +#define fCLIENT_STATUS_BSSCOEXIST_CAPABLE 0x00001000
61749 +#endif // DOT11N_DRAFT3 //
61750 +
61751 +#define fCLIENT_STATUS_RALINK_CHIPSET 0x00100000
61752 +//
61753 +// STA configuration flags
61754 +//
61755 +//#define fSTA_CFG_ENABLE_TX_BURST 0x00000001
61756 +
61757 +// 802.11n Operating Mode Definition. 0-3 also used in ASICUPdateProtect switch case
61758 +#define HT_NO_PROTECT 0
61759 +#define HT_LEGACY_PROTECT 1
61760 +#define HT_40_PROTECT 2
61761 +#define HT_2040_PROTECT 3
61762 +#define HT_RTSCTS_6M 7
61763 +//following is our own definition in order to turn on our ASIC protection register in INFRASTRUCTURE.
61764 +#define HT_ATHEROS 8 // rt2860c has problem with atheros chip. we need to turn on RTS/CTS .
61765 +#define HT_FORCERTSCTS 9 // Force turn on RTS/CTS first. then go to evaluate if this force RTS is necessary.
61766 +
61767 +//
61768 +// RX Packet Filter control flags. Apply on pAd->PacketFilter
61769 +//
61770 +#define fRX_FILTER_ACCEPT_DIRECT NDIS_PACKET_TYPE_DIRECTED
61771 +#define fRX_FILTER_ACCEPT_MULTICAST NDIS_PACKET_TYPE_MULTICAST
61772 +#define fRX_FILTER_ACCEPT_BROADCAST NDIS_PACKET_TYPE_BROADCAST
61773 +#define fRX_FILTER_ACCEPT_ALL_MULTICAST NDIS_PACKET_TYPE_ALL_MULTICAST
61774 +
61775 +//
61776 +// Error code section
61777 +//
61778 +// NDIS_ERROR_CODE_ADAPTER_NOT_FOUND
61779 +#define ERRLOG_READ_PCI_SLOT_FAILED 0x00000101L
61780 +#define ERRLOG_WRITE_PCI_SLOT_FAILED 0x00000102L
61781 +#define ERRLOG_VENDOR_DEVICE_NOMATCH 0x00000103L
61782 +
61783 +// NDIS_ERROR_CODE_ADAPTER_DISABLED
61784 +#define ERRLOG_BUS_MASTER_DISABLED 0x00000201L
61785 +
61786 +// NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION
61787 +#define ERRLOG_INVALID_SPEED_DUPLEX 0x00000301L
61788 +#define ERRLOG_SET_SECONDARY_FAILED 0x00000302L
61789 +
61790 +// NDIS_ERROR_CODE_OUT_OF_RESOURCES
61791 +#define ERRLOG_OUT_OF_MEMORY 0x00000401L
61792 +#define ERRLOG_OUT_OF_SHARED_MEMORY 0x00000402L
61793 +#define ERRLOG_OUT_OF_MAP_REGISTERS 0x00000403L
61794 +#define ERRLOG_OUT_OF_BUFFER_POOL 0x00000404L
61795 +#define ERRLOG_OUT_OF_NDIS_BUFFER 0x00000405L
61796 +#define ERRLOG_OUT_OF_PACKET_POOL 0x00000406L
61797 +#define ERRLOG_OUT_OF_NDIS_PACKET 0x00000407L
61798 +#define ERRLOG_OUT_OF_LOOKASIDE_MEMORY 0x00000408L
61799 +
61800 +// NDIS_ERROR_CODE_HARDWARE_FAILURE
61801 +#define ERRLOG_SELFTEST_FAILED 0x00000501L
61802 +#define ERRLOG_INITIALIZE_ADAPTER 0x00000502L
61803 +#define ERRLOG_REMOVE_MINIPORT 0x00000503L
61804 +
61805 +// NDIS_ERROR_CODE_RESOURCE_CONFLICT
61806 +#define ERRLOG_MAP_IO_SPACE 0x00000601L
61807 +#define ERRLOG_QUERY_ADAPTER_RESOURCES 0x00000602L
61808 +#define ERRLOG_NO_IO_RESOURCE 0x00000603L
61809 +#define ERRLOG_NO_INTERRUPT_RESOURCE 0x00000604L
61810 +#define ERRLOG_NO_MEMORY_RESOURCE 0x00000605L
61811 +
61812 +
61813 +// WDS definition
61814 +#define MAX_WDS_ENTRY 4
61815 +#define WDS_PAIRWISE_KEY_OFFSET 60 // WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table
61816 +
61817 +#define WDS_DISABLE_MODE 0
61818 +#define WDS_RESTRICT_MODE 1
61819 +#define WDS_BRIDGE_MODE 2
61820 +#define WDS_REPEATER_MODE 3
61821 +#define WDS_LAZY_MODE 4
61822 +
61823 +
61824 +#define MAX_MESH_NUM 0
61825 +
61826 +#define MAX_APCLI_NUM 0
61827 +#ifdef APCLI_SUPPORT
61828 +#undef MAX_APCLI_NUM
61829 +#define MAX_APCLI_NUM 1
61830 +#endif // APCLI_SUPPORT //
61831 +
61832 +#define MAX_MBSSID_NUM 1
61833 +
61834 +/* sanity check for apidx */
61835 +#define MBSS_MR_APIDX_SANITY_CHECK(apidx) \
61836 + { if (apidx > MAX_MBSSID_NUM) { \
61837 + printk("%s> Error! apidx = %d > MAX_MBSSID_NUM!\n", __FUNCTION__, apidx); \
61838 + apidx = MAIN_MBSSID; } }
61839 +
61840 +#define VALID_WCID(_wcid) ((_wcid) > 0 && (_wcid) < MAX_LEN_OF_MAC_TABLE )
61841 +
61842 +#define MAIN_MBSSID 0
61843 +#define FIRST_MBSSID 1
61844 +
61845 +
61846 +#define MAX_BEACON_SIZE 512
61847 +// If the MAX_MBSSID_NUM is larger than 6,
61848 +// it shall reserve some WCID space(wcid 222~253) for beacon frames.
61849 +// - these wcid 238~253 are reserved for beacon#6(ra6).
61850 +// - these wcid 222~237 are reserved for beacon#7(ra7).
61851 +#if defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 8)
61852 +#define HW_RESERVED_WCID 222
61853 +#elif defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 7)
61854 +#define HW_RESERVED_WCID 238
61855 +#else
61856 +#define HW_RESERVED_WCID 255
61857 +#endif
61858 +
61859 +// Then dedicate wcid of DFS and Carrier-Sense.
61860 +#define DFS_CTS_WCID (HW_RESERVED_WCID - 1)
61861 +#define CS_CTS_WCID (HW_RESERVED_WCID - 2)
61862 +#define LAST_SPECIFIC_WCID (HW_RESERVED_WCID - 2)
61863 +
61864 +// If MAX_MBSSID_NUM is 8, the maximum available wcid for the associated STA is 211.
61865 +// If MAX_MBSSID_NUM is 7, the maximum available wcid for the associated STA is 228.
61866 +#define MAX_AVAILABLE_CLIENT_WCID (LAST_SPECIFIC_WCID - MAX_MBSSID_NUM - 1)
61867 +
61868 +// TX need WCID to find Cipher Key
61869 +// these wcid 212 ~ 219 are reserved for bc/mc packets if MAX_MBSSID_NUM is 8.
61870 +#define GET_GroupKey_WCID(__wcid, __bssidx) \
61871 + { \
61872 + __wcid = LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM) + __bssidx; \
61873 + }
61874 +
61875 +#define IsGroupKeyWCID(__wcid) (((__wcid) < LAST_SPECIFIC_WCID) && ((__wcid) >= (LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM))))
61876 +
61877 +
61878 +// definition to support multiple BSSID
61879 +#define BSS0 0
61880 +#define BSS1 1
61881 +#define BSS2 2
61882 +#define BSS3 3
61883 +#define BSS4 4
61884 +#define BSS5 5
61885 +#define BSS6 6
61886 +#define BSS7 7
61887 +
61888 +
61889 +//============================================================
61890 +// Length definitions
61891 +#define PEER_KEY_NO 2
61892 +#define MAC_ADDR_LEN 6
61893 +#define TIMESTAMP_LEN 8
61894 +#define MAX_LEN_OF_SUPPORTED_RATES MAX_LENGTH_OF_SUPPORT_RATES // 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
61895 +#define MAX_LEN_OF_KEY 32 // 32 octets == 256 bits, Redefine for WPA
61896 +#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
61897 +#define MAX_NUM_OF_11JCHANNELS 20 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination
61898 +#define MAX_LEN_OF_SSID 32
61899 +#define CIPHER_TEXT_LEN 128
61900 +#define HASH_TABLE_SIZE 256
61901 +#define MAX_VIE_LEN 1024 // New for WPA cipher suite variable IE sizes.
61902 +#define MAX_SUPPORT_MCS 32
61903 +
61904 +//============================================================
61905 +// ASIC WCID Table definition.
61906 +//============================================================
61907 +#define BSSID_WCID 1 // in infra mode, always put bssid with this WCID
61908 +#define MCAST_WCID 0x0
61909 +#define BSS0Mcast_WCID 0x0
61910 +#define BSS1Mcast_WCID 0xf8
61911 +#define BSS2Mcast_WCID 0xf9
61912 +#define BSS3Mcast_WCID 0xfa
61913 +#define BSS4Mcast_WCID 0xfb
61914 +#define BSS5Mcast_WCID 0xfc
61915 +#define BSS6Mcast_WCID 0xfd
61916 +#define BSS7Mcast_WCID 0xfe
61917 +#define RESERVED_WCID 0xff
61918 +
61919 +#define MAX_NUM_OF_ACL_LIST MAX_NUMBER_OF_ACL
61920 +
61921 +#define MAX_LEN_OF_MAC_TABLE MAX_NUMBER_OF_MAC // if MAX_MBSSID_NUM is 8, this value can't be larger than 211
61922 +
61923 +#if MAX_LEN_OF_MAC_TABLE>MAX_AVAILABLE_CLIENT_WCID
61924 +#error MAX_LEN_OF_MAC_TABLE can not be larger than MAX_AVAILABLE_CLIENT_WCID!!!!
61925 +#endif
61926 +
61927 +#define MAX_NUM_OF_WDS_LINK_PERBSSID 3
61928 +#define MAX_NUM_OF_WDS_LINK (MAX_NUM_OF_WDS_LINK_PERBSSID*MAX_MBSSID_NUM)
61929 +#define MAX_NUM_OF_EVENT MAX_NUMBER_OF_EVENT
61930 +#define WDS_LINK_START_WCID (MAX_LEN_OF_MAC_TABLE-1)
61931 +
61932 +#define NUM_OF_TID 8
61933 +#define MAX_AID_BA 4
61934 +#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
61935 +#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
61936 +#define MAX_LEN_OF_BSS_TABLE 64
61937 +#define MAX_REORDERING_MPDU_NUM 512
61938 +
61939 +// key related definitions
61940 +#define SHARE_KEY_NUM 4
61941 +#define MAX_LEN_OF_SHARE_KEY 16 // byte count
61942 +#define MAX_LEN_OF_PEER_KEY 16 // byte count
61943 +#define PAIRWISE_KEY_NUM 64 // in MAC ASIC pairwise key table
61944 +#define GROUP_KEY_NUM 4
61945 +#define PMK_LEN 32
61946 +#define WDS_PAIRWISE_KEY_OFFSET 60 // WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table
61947 +#define PMKID_NO 4 // Number of PMKID saved supported
61948 +#define MAX_LEN_OF_MLME_BUFFER 2048
61949 +
61950 +// power status related definitions
61951 +#define PWR_ACTIVE 0
61952 +#define PWR_SAVE 1
61953 +#define PWR_MMPS 2 //MIMO power save
61954 +//#define PWR_UNKNOWN 2
61955 +
61956 +// Auth and Assoc mode related definitions
61957 +#define AUTH_MODE_OPEN 0x00
61958 +#define AUTH_MODE_KEY 0x01
61959 +//#define AUTH_MODE_AUTO_SWITCH 0x03
61960 +//#define AUTH_MODE_DEAUTH 0x04
61961 +//#define AUTH_MODE_UPLAYER 0x05 // reserved for 802.11i use
61962 +
61963 +// BSS Type definitions
61964 +#define BSS_ADHOC 0 // = Ndis802_11IBSS
61965 +#define BSS_INFRA 1 // = Ndis802_11Infrastructure
61966 +#define BSS_ANY 2 // = Ndis802_11AutoUnknown
61967 +#define BSS_MONITOR 3 // = Ndis802_11Monitor
61968 +
61969 +
61970 +// Reason code definitions
61971 +#define REASON_RESERVED 0
61972 +#define REASON_UNSPECIFY 1
61973 +#define REASON_NO_LONGER_VALID 2
61974 +#define REASON_DEAUTH_STA_LEAVING 3
61975 +#define REASON_DISASSOC_INACTIVE 4
61976 +#define REASON_DISASSPC_AP_UNABLE 5
61977 +#define REASON_CLS2ERR 6
61978 +#define REASON_CLS3ERR 7
61979 +#define REASON_DISASSOC_STA_LEAVING 8
61980 +#define REASON_STA_REQ_ASSOC_NOT_AUTH 9
61981 +#define REASON_INVALID_IE 13
61982 +#define REASON_MIC_FAILURE 14
61983 +#define REASON_4_WAY_TIMEOUT 15
61984 +#define REASON_GROUP_KEY_HS_TIMEOUT 16
61985 +#define REASON_IE_DIFFERENT 17
61986 +#define REASON_MCIPHER_NOT_VALID 18
61987 +#define REASON_UCIPHER_NOT_VALID 19
61988 +#define REASON_AKMP_NOT_VALID 20
61989 +#define REASON_UNSUPPORT_RSNE_VER 21
61990 +#define REASON_INVALID_RSNE_CAP 22
61991 +#define REASON_8021X_AUTH_FAIL 23
61992 +#define REASON_CIPHER_SUITE_REJECTED 24
61993 +#define REASON_DECLINED 37
61994 +
61995 +#define REASON_QOS_UNSPECIFY 32
61996 +#define REASON_QOS_LACK_BANDWIDTH 33
61997 +#define REASON_POOR_CHANNEL_CONDITION 34
61998 +#define REASON_QOS_OUTSIDE_TXOP_LIMITION 35
61999 +#define REASON_QOS_QSTA_LEAVING_QBSS 36
62000 +#define REASON_QOS_UNWANTED_MECHANISM 37
62001 +#define REASON_QOS_MECH_SETUP_REQUIRED 38
62002 +#define REASON_QOS_REQUEST_TIMEOUT 39
62003 +#define REASON_QOS_CIPHER_NOT_SUPPORT 45
62004 +
62005 +// Status code definitions
62006 +#define MLME_SUCCESS 0
62007 +#define MLME_UNSPECIFY_FAIL 1
62008 +#define MLME_CANNOT_SUPPORT_CAP 10
62009 +#define MLME_REASSOC_DENY_ASSOC_EXIST 11
62010 +#define MLME_ASSOC_DENY_OUT_SCOPE 12
62011 +#define MLME_ALG_NOT_SUPPORT 13
62012 +#define MLME_SEQ_NR_OUT_OF_SEQUENCE 14
62013 +#define MLME_REJ_CHALLENGE_FAILURE 15
62014 +#define MLME_REJ_TIMEOUT 16
62015 +#define MLME_ASSOC_REJ_UNABLE_HANDLE_STA 17
62016 +#define MLME_ASSOC_REJ_DATA_RATE 18
62017 +
62018 +#define MLME_ASSOC_REJ_NO_EXT_RATE 22
62019 +#define MLME_ASSOC_REJ_NO_EXT_RATE_PBCC 23
62020 +#define MLME_ASSOC_REJ_NO_CCK_OFDM 24
62021 +
62022 +#define MLME_QOS_UNSPECIFY 32
62023 +#define MLME_REQUEST_DECLINED 37
62024 +#define MLME_REQUEST_WITH_INVALID_PARAM 38
62025 +#define MLME_DLS_NOT_ALLOW_IN_QBSS 48
62026 +#define MLME_DEST_STA_NOT_IN_QBSS 49
62027 +#define MLME_DEST_STA_IS_NOT_A_QSTA 50
62028 +
62029 +#define MLME_INVALID_FORMAT 0x51
62030 +#define MLME_FAIL_NO_RESOURCE 0x52
62031 +#define MLME_STATE_MACHINE_REJECT 0x53
62032 +#define MLME_MAC_TABLE_FAIL 0x54
62033 +
62034 +// IE code
62035 +#define IE_SSID 0
62036 +#define IE_SUPP_RATES 1
62037 +#define IE_FH_PARM 2
62038 +#define IE_DS_PARM 3
62039 +#define IE_CF_PARM 4
62040 +#define IE_TIM 5
62041 +#define IE_IBSS_PARM 6
62042 +#define IE_COUNTRY 7 // 802.11d
62043 +#define IE_802_11D_REQUEST 10 // 802.11d
62044 +#define IE_QBSS_LOAD 11 // 802.11e d9
62045 +#define IE_EDCA_PARAMETER 12 // 802.11e d9
62046 +#define IE_TSPEC 13 // 802.11e d9
62047 +#define IE_TCLAS 14 // 802.11e d9
62048 +#define IE_SCHEDULE 15 // 802.11e d9
62049 +#define IE_CHALLENGE_TEXT 16
62050 +#define IE_POWER_CONSTRAINT 32 // 802.11h d3.3
62051 +#define IE_POWER_CAPABILITY 33 // 802.11h d3.3
62052 +#define IE_TPC_REQUEST 34 // 802.11h d3.3
62053 +#define IE_TPC_REPORT 35 // 802.11h d3.3
62054 +#define IE_SUPP_CHANNELS 36 // 802.11h d3.3
62055 +#define IE_CHANNEL_SWITCH_ANNOUNCEMENT 37 // 802.11h d3.3
62056 +#define IE_MEASUREMENT_REQUEST 38 // 802.11h d3.3
62057 +#define IE_MEASUREMENT_REPORT 39 // 802.11h d3.3
62058 +#define IE_QUIET 40 // 802.11h d3.3
62059 +#define IE_IBSS_DFS 41 // 802.11h d3.3
62060 +#define IE_ERP 42 // 802.11g
62061 +#define IE_TS_DELAY 43 // 802.11e d9
62062 +#define IE_TCLAS_PROCESSING 44 // 802.11e d9
62063 +#define IE_QOS_CAPABILITY 46 // 802.11e d6
62064 +#define IE_HT_CAP 45 // 802.11n d1. HT CAPABILITY. ELEMENT ID TBD
62065 +#define IE_AP_CHANNEL_REPORT 51 // 802.11k d6
62066 +#define IE_HT_CAP2 52 // 802.11n d1. HT CAPABILITY. ELEMENT ID TBD
62067 +#define IE_RSN 48 // 802.11i d3.0
62068 +#define IE_WPA2 48 // WPA2
62069 +#define IE_EXT_SUPP_RATES 50 // 802.11g
62070 +#define IE_SUPP_REG_CLASS 59 // 802.11y. Supported regulatory classes.
62071 +#define IE_EXT_CHANNEL_SWITCH_ANNOUNCEMENT 60 // 802.11n
62072 +#define IE_ADD_HT 61 // 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD
62073 +#define IE_ADD_HT2 53 // 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD
62074 +
62075 +
62076 +// For 802.11n D3.03
62077 +//#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset elemet
62078 +#define IE_SECONDARY_CH_OFFSET 62 // 802.11n D3.03 Secondary Channel Offset element
62079 +#define IE_WAPI 68 // WAPI information element
62080 +#define IE_2040_BSS_COEXIST 72 // 802.11n D3.0.3
62081 +#define IE_2040_BSS_INTOLERANT_REPORT 73 // 802.11n D3.03
62082 +#define IE_OVERLAPBSS_SCAN_PARM 74 // 802.11n D3.03
62083 +#define IE_EXT_CAPABILITY 127 // 802.11n D3.03
62084 +
62085 +
62086 +#define IE_WPA 221 // WPA
62087 +#define IE_VENDOR_SPECIFIC 221 // Wifi WMM (WME)
62088 +
62089 +#define OUI_BROADCOM_HT 51 //
62090 +#define OUI_BROADCOM_HTADD 52 //
62091 +#define OUI_PREN_HT_CAP 51 //
62092 +#define OUI_PREN_ADD_HT 52 //
62093 +
62094 +// CCX information
62095 +#define IE_AIRONET_CKIP 133 // CCX1.0 ID 85H for CKIP
62096 +#define IE_AP_TX_POWER 150 // CCX 2.0 for AP transmit power
62097 +#define IE_MEASUREMENT_CAPABILITY 221 // CCX 2.0
62098 +#define IE_CCX_V2 221
62099 +#define IE_AIRONET_IPADDRESS 149 // CCX ID 95H for IP Address
62100 +#define IE_AIRONET_CCKMREASSOC 156 // CCX ID 9CH for CCKM Reassociation Request element
62101 +#define CKIP_NEGOTIATION_LENGTH 30
62102 +#define AIRONET_IPADDRESS_LENGTH 10
62103 +#define AIRONET_CCKMREASSOC_LENGTH 24
62104 +
62105 +// ========================================================
62106 +// MLME state machine definition
62107 +// ========================================================
62108 +
62109 +// STA MLME state mahcines
62110 +#define ASSOC_STATE_MACHINE 1
62111 +#define AUTH_STATE_MACHINE 2
62112 +#define AUTH_RSP_STATE_MACHINE 3
62113 +#define SYNC_STATE_MACHINE 4
62114 +#define MLME_CNTL_STATE_MACHINE 5
62115 +#define WPA_PSK_STATE_MACHINE 6
62116 +#define LEAP_STATE_MACHINE 7
62117 +#define AIRONET_STATE_MACHINE 8
62118 +#define ACTION_STATE_MACHINE 9
62119 +
62120 +// AP MLME state machines
62121 +#define AP_ASSOC_STATE_MACHINE 11
62122 +#define AP_AUTH_STATE_MACHINE 12
62123 +#define AP_AUTH_RSP_STATE_MACHINE 13
62124 +#define AP_SYNC_STATE_MACHINE 14
62125 +#define AP_CNTL_STATE_MACHINE 15
62126 +#define AP_WPA_STATE_MACHINE 16
62127 +
62128 +#ifdef QOS_DLS_SUPPORT
62129 +#define DLS_STATE_MACHINE 26
62130 +#endif // QOS_DLS_SUPPORT //
62131 +
62132 +//
62133 +// STA's CONTROL/CONNECT state machine: states, events, total function #
62134 +//
62135 +#define CNTL_IDLE 0
62136 +#define CNTL_WAIT_DISASSOC 1
62137 +#define CNTL_WAIT_JOIN 2
62138 +#define CNTL_WAIT_REASSOC 3
62139 +#define CNTL_WAIT_START 4
62140 +#define CNTL_WAIT_AUTH 5
62141 +#define CNTL_WAIT_ASSOC 6
62142 +#define CNTL_WAIT_AUTH2 7
62143 +#define CNTL_WAIT_OID_LIST_SCAN 8
62144 +#define CNTL_WAIT_OID_DISASSOC 9
62145 +#ifdef RT2870
62146 +#define CNTL_WAIT_SCAN_FOR_CONNECT 10
62147 +#endif // RT2870 //
62148 +
62149 +#define MT2_ASSOC_CONF 34
62150 +#define MT2_AUTH_CONF 35
62151 +#define MT2_DEAUTH_CONF 36
62152 +#define MT2_DISASSOC_CONF 37
62153 +#define MT2_REASSOC_CONF 38
62154 +#define MT2_PWR_MGMT_CONF 39
62155 +#define MT2_JOIN_CONF 40
62156 +#define MT2_SCAN_CONF 41
62157 +#define MT2_START_CONF 42
62158 +#define MT2_GET_CONF 43
62159 +#define MT2_SET_CONF 44
62160 +#define MT2_RESET_CONF 45
62161 +#define MT2_MLME_ROAMING_REQ 52
62162 +
62163 +#define CNTL_FUNC_SIZE 1
62164 +
62165 +//
62166 +// STA's ASSOC state machine: states, events, total function #
62167 +//
62168 +#define ASSOC_IDLE 0
62169 +#define ASSOC_WAIT_RSP 1
62170 +#define REASSOC_WAIT_RSP 2
62171 +#define DISASSOC_WAIT_RSP 3
62172 +#define MAX_ASSOC_STATE 4
62173 +
62174 +#define ASSOC_MACHINE_BASE 0
62175 +#define MT2_MLME_ASSOC_REQ 0
62176 +#define MT2_MLME_REASSOC_REQ 1
62177 +#define MT2_MLME_DISASSOC_REQ 2
62178 +#define MT2_PEER_DISASSOC_REQ 3
62179 +#define MT2_PEER_ASSOC_REQ 4
62180 +#define MT2_PEER_ASSOC_RSP 5
62181 +#define MT2_PEER_REASSOC_REQ 6
62182 +#define MT2_PEER_REASSOC_RSP 7
62183 +#define MT2_DISASSOC_TIMEOUT 8
62184 +#define MT2_ASSOC_TIMEOUT 9
62185 +#define MT2_REASSOC_TIMEOUT 10
62186 +#define MAX_ASSOC_MSG 11
62187 +
62188 +#define ASSOC_FUNC_SIZE (MAX_ASSOC_STATE * MAX_ASSOC_MSG)
62189 +
62190 +//
62191 +// ACT state machine: states, events, total function #
62192 +//
62193 +#define ACT_IDLE 0
62194 +#define MAX_ACT_STATE 1
62195 +
62196 +#define ACT_MACHINE_BASE 0
62197 +
62198 +//Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please don'es modify it by your self.
62199 +//Category
62200 +#define MT2_PEER_SPECTRUM_CATE 0
62201 +#define MT2_PEER_QOS_CATE 1
62202 +#define MT2_PEER_DLS_CATE 2
62203 +#define MT2_PEER_BA_CATE 3
62204 +#define MT2_PEER_PUBLIC_CATE 4
62205 +#define MT2_PEER_RM_CATE 5
62206 +#define MT2_PEER_HT_CATE 7 // 7.4.7
62207 +#define MAX_PEER_CATE_MSG 7
62208 +#define MT2_MLME_ADD_BA_CATE 8
62209 +#define MT2_MLME_ORI_DELBA_CATE 9
62210 +#define MT2_MLME_REC_DELBA_CATE 10
62211 +#define MT2_MLME_QOS_CATE 11
62212 +#define MT2_MLME_DLS_CATE 12
62213 +#define MT2_ACT_INVALID 13
62214 +#define MAX_ACT_MSG 14
62215 +
62216 +//Category field
62217 +#define CATEGORY_SPECTRUM 0
62218 +#define CATEGORY_QOS 1
62219 +#define CATEGORY_DLS 2
62220 +#define CATEGORY_BA 3
62221 +#define CATEGORY_PUBLIC 4
62222 +#define CATEGORY_RM 5
62223 +#define CATEGORY_HT 7
62224 +
62225 +
62226 +// DLS Action frame definition
62227 +#define ACTION_DLS_REQUEST 0
62228 +#define ACTION_DLS_RESPONSE 1
62229 +#define ACTION_DLS_TEARDOWN 2
62230 +
62231 +//Spectrum Action field value 802.11h 7.4.1
62232 +#define SPEC_MRQ 0 // Request
62233 +#define SPEC_MRP 1 //Report
62234 +#define SPEC_TPCRQ 2
62235 +#define SPEC_TPCRP 3
62236 +#define SPEC_CHANNEL_SWITCH 4
62237 +
62238 +
62239 +//BA Action field value
62240 +#define ADDBA_REQ 0
62241 +#define ADDBA_RESP 1
62242 +#define DELBA 2
62243 +
62244 +//Public's Action field value in Public Category. Some in 802.11y and some in 11n
62245 +#define ACTION_BSS_2040_COEXIST 0 // 11n
62246 +#define ACTION_DSE_ENABLEMENT 1 // 11y D9.0
62247 +#define ACTION_DSE_DEENABLEMENT 2 // 11y D9.0
62248 +#define ACTION_DSE_REG_LOCATION_ANNOUNCE 3 // 11y D9.0
62249 +#define ACTION_EXT_CH_SWITCH_ANNOUNCE 4 // 11y D9.0
62250 +#define ACTION_DSE_MEASUREMENT_REQ 5 // 11y D9.0
62251 +#define ACTION_DSE_MEASUREMENT_REPORT 6 // 11y D9.0
62252 +#define ACTION_MEASUREMENT_PILOT_ACTION 7 // 11y D9.0
62253 +#define ACTION_DSE_POWER_CONSTRAINT 8 // 11y D9.0
62254 +
62255 +
62256 +//HT Action field value
62257 +#define NOTIFY_BW_ACTION 0
62258 +#define SMPS_ACTION 1
62259 +#define PSMP_ACTION 2
62260 +#define SETPCO_ACTION 3
62261 +#define MIMO_CHA_MEASURE_ACTION 4
62262 +#define MIMO_N_BEACONFORM 5
62263 +#define MIMO_BEACONFORM 6
62264 +#define ANTENNA_SELECT 7
62265 +#define HT_INFO_EXCHANGE 8
62266 +
62267 +#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG)
62268 +//
62269 +// STA's AUTHENTICATION state machine: states, evvents, total function #
62270 +//
62271 +#define AUTH_REQ_IDLE 0
62272 +#define AUTH_WAIT_SEQ2 1
62273 +#define AUTH_WAIT_SEQ4 2
62274 +#define MAX_AUTH_STATE 3
62275 +
62276 +#define AUTH_MACHINE_BASE 0
62277 +#define MT2_MLME_AUTH_REQ 0
62278 +#define MT2_PEER_AUTH_EVEN 1
62279 +#define MT2_AUTH_TIMEOUT 2
62280 +#define MAX_AUTH_MSG 3
62281 +
62282 +#define AUTH_FUNC_SIZE (MAX_AUTH_STATE * MAX_AUTH_MSG)
62283 +
62284 +//
62285 +// STA's AUTH_RSP state machine: states, events, total function #
62286 +//
62287 +#define AUTH_RSP_IDLE 0
62288 +#define AUTH_RSP_WAIT_CHAL 1
62289 +#define MAX_AUTH_RSP_STATE 2
62290 +
62291 +#define AUTH_RSP_MACHINE_BASE 0
62292 +#define MT2_AUTH_CHALLENGE_TIMEOUT 0
62293 +#define MT2_PEER_AUTH_ODD 1
62294 +#define MT2_PEER_DEAUTH 2
62295 +#define MAX_AUTH_RSP_MSG 3
62296 +
62297 +#define AUTH_RSP_FUNC_SIZE (MAX_AUTH_RSP_STATE * MAX_AUTH_RSP_MSG)
62298 +
62299 +//
62300 +// STA's SYNC state machine: states, events, total function #
62301 +//
62302 +#define SYNC_IDLE 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
62303 +#define JOIN_WAIT_BEACON 1
62304 +#define SCAN_LISTEN 2
62305 +#define MAX_SYNC_STATE 3
62306 +
62307 +#define SYNC_MACHINE_BASE 0
62308 +#define MT2_MLME_SCAN_REQ 0
62309 +#define MT2_MLME_JOIN_REQ 1
62310 +#define MT2_MLME_START_REQ 2
62311 +#define MT2_PEER_BEACON 3
62312 +#define MT2_PEER_PROBE_RSP 4
62313 +#define MT2_PEER_ATIM 5
62314 +#define MT2_SCAN_TIMEOUT 6
62315 +#define MT2_BEACON_TIMEOUT 7
62316 +#define MT2_ATIM_TIMEOUT 8
62317 +#define MT2_PEER_PROBE_REQ 9
62318 +#define MAX_SYNC_MSG 10
62319 +
62320 +#define SYNC_FUNC_SIZE (MAX_SYNC_STATE * MAX_SYNC_MSG)
62321 +
62322 +//Messages for the DLS state machine
62323 +#define DLS_IDLE 0
62324 +#define MAX_DLS_STATE 1
62325 +
62326 +#define DLS_MACHINE_BASE 0
62327 +#define MT2_MLME_DLS_REQ 0
62328 +#define MT2_PEER_DLS_REQ 1
62329 +#define MT2_PEER_DLS_RSP 2
62330 +#define MT2_MLME_DLS_TEAR_DOWN 3
62331 +#define MT2_PEER_DLS_TEAR_DOWN 4
62332 +#define MAX_DLS_MSG 5
62333 +
62334 +#define DLS_FUNC_SIZE (MAX_DLS_STATE * MAX_DLS_MSG)
62335 +
62336 +//
62337 +// STA's WPA-PSK State machine: states, events, total function #
62338 +//
62339 +#define WPA_PSK_IDLE 0
62340 +#define MAX_WPA_PSK_STATE 1
62341 +
62342 +#define WPA_MACHINE_BASE 0
62343 +#define MT2_EAPPacket 0
62344 +#define MT2_EAPOLStart 1
62345 +#define MT2_EAPOLLogoff 2
62346 +#define MT2_EAPOLKey 3
62347 +#define MT2_EAPOLASFAlert 4
62348 +#define MAX_WPA_PSK_MSG 5
62349 +
62350 +#define WPA_PSK_FUNC_SIZE (MAX_WPA_PSK_STATE * MAX_WPA_PSK_MSG)
62351 +
62352 +//
62353 +// STA's CISCO-AIRONET State machine: states, events, total function #
62354 +//
62355 +#define AIRONET_IDLE 0
62356 +#define AIRONET_SCANNING 1
62357 +#define MAX_AIRONET_STATE 2
62358 +
62359 +#define AIRONET_MACHINE_BASE 0
62360 +#define MT2_AIRONET_MSG 0
62361 +#define MT2_AIRONET_SCAN_REQ 1
62362 +#define MT2_AIRONET_SCAN_DONE 2
62363 +#define MAX_AIRONET_MSG 3
62364 +
62365 +#define AIRONET_FUNC_SIZE (MAX_AIRONET_STATE * MAX_AIRONET_MSG)
62366 +
62367 +//
62368 +// AP's CONTROL/CONNECT state machine: states, events, total function #
62369 +//
62370 +#define AP_CNTL_FUNC_SIZE 1
62371 +
62372 +//
62373 +// AP's ASSOC state machine: states, events, total function #
62374 +//
62375 +#define AP_ASSOC_IDLE 0
62376 +#define AP_MAX_ASSOC_STATE 1
62377 +
62378 +#define AP_ASSOC_MACHINE_BASE 0
62379 +#define APMT2_MLME_DISASSOC_REQ 0
62380 +#define APMT2_PEER_DISASSOC_REQ 1
62381 +#define APMT2_PEER_ASSOC_REQ 2
62382 +#define APMT2_PEER_REASSOC_REQ 3
62383 +#define APMT2_CLS3ERR 4
62384 +#define AP_MAX_ASSOC_MSG 5
62385 +
62386 +#define AP_ASSOC_FUNC_SIZE (AP_MAX_ASSOC_STATE * AP_MAX_ASSOC_MSG)
62387 +
62388 +//
62389 +// AP's AUTHENTICATION state machine: states, events, total function #
62390 +//
62391 +#define AP_AUTH_REQ_IDLE 0
62392 +#define AP_MAX_AUTH_STATE 1
62393 +
62394 +#define AP_AUTH_MACHINE_BASE 0
62395 +#define APMT2_MLME_DEAUTH_REQ 0
62396 +#define APMT2_CLS2ERR 1
62397 +#define AP_MAX_AUTH_MSG 2
62398 +
62399 +#define AP_AUTH_FUNC_SIZE (AP_MAX_AUTH_STATE * AP_MAX_AUTH_MSG)
62400 +
62401 +//
62402 +// AP's AUTH-RSP state machine: states, events, total function #
62403 +//
62404 +#define AP_AUTH_RSP_IDLE 0
62405 +#define AP_MAX_AUTH_RSP_STATE 1
62406 +
62407 +#define AP_AUTH_RSP_MACHINE_BASE 0
62408 +#define APMT2_AUTH_CHALLENGE_TIMEOUT 0
62409 +#define APMT2_PEER_AUTH_ODD 1
62410 +#define APMT2_PEER_DEAUTH 2
62411 +#define AP_MAX_AUTH_RSP_MSG 3
62412 +
62413 +#define AP_AUTH_RSP_FUNC_SIZE (AP_MAX_AUTH_RSP_STATE * AP_MAX_AUTH_RSP_MSG)
62414 +
62415 +//
62416 +// AP's SYNC state machine: states, events, total function #
62417 +//
62418 +#define AP_SYNC_IDLE 0
62419 +#define AP_SCAN_LISTEN 1
62420 +#define AP_MAX_SYNC_STATE 2
62421 +
62422 +#define AP_SYNC_MACHINE_BASE 0
62423 +#define APMT2_PEER_PROBE_REQ 0
62424 +#define APMT2_PEER_BEACON 1
62425 +#define APMT2_MLME_SCAN_REQ 2
62426 +#define APMT2_PEER_PROBE_RSP 3
62427 +#define APMT2_SCAN_TIMEOUT 4
62428 +#define APMT2_MLME_SCAN_CNCL 5
62429 +#define AP_MAX_SYNC_MSG 6
62430 +
62431 +#define AP_SYNC_FUNC_SIZE (AP_MAX_SYNC_STATE * AP_MAX_SYNC_MSG)
62432 +
62433 +//
62434 +// AP's WPA state machine: states, events, total function #
62435 +//
62436 +#define AP_WPA_PTK 0
62437 +#define AP_MAX_WPA_PTK_STATE 1
62438 +
62439 +#define AP_WPA_MACHINE_BASE 0
62440 +#define APMT2_EAPPacket 0
62441 +#define APMT2_EAPOLStart 1
62442 +#define APMT2_EAPOLLogoff 2
62443 +#define APMT2_EAPOLKey 3
62444 +#define APMT2_EAPOLASFAlert 4
62445 +#define AP_MAX_WPA_MSG 5
62446 +
62447 +#define AP_WPA_FUNC_SIZE (AP_MAX_WPA_PTK_STATE * AP_MAX_WPA_MSG)
62448 +
62449 +#ifdef APCLI_SUPPORT
62450 +//ApCli authentication state machine
62451 +#define APCLI_AUTH_REQ_IDLE 0
62452 +#define APCLI_AUTH_WAIT_SEQ2 1
62453 +#define APCLI_AUTH_WAIT_SEQ4 2
62454 +#define APCLI_MAX_AUTH_STATE 3
62455 +
62456 +#define APCLI_AUTH_MACHINE_BASE 0
62457 +#define APCLI_MT2_MLME_AUTH_REQ 0
62458 +#define APCLI_MT2_MLME_DEAUTH_REQ 1
62459 +#define APCLI_MT2_PEER_AUTH_EVEN 2
62460 +#define APCLI_MT2_PEER_DEAUTH 3
62461 +#define APCLI_MT2_AUTH_TIMEOUT 4
62462 +#define APCLI_MAX_AUTH_MSG 5
62463 +
62464 +#define APCLI_AUTH_FUNC_SIZE (APCLI_MAX_AUTH_STATE * APCLI_MAX_AUTH_MSG)
62465 +
62466 +//ApCli association state machine
62467 +#define APCLI_ASSOC_IDLE 0
62468 +#define APCLI_ASSOC_WAIT_RSP 1
62469 +#define APCLI_MAX_ASSOC_STATE 2
62470 +
62471 +#define APCLI_ASSOC_MACHINE_BASE 0
62472 +#define APCLI_MT2_MLME_ASSOC_REQ 0
62473 +#define APCLI_MT2_MLME_DISASSOC_REQ 1
62474 +#define APCLI_MT2_PEER_DISASSOC_REQ 2
62475 +#define APCLI_MT2_PEER_ASSOC_RSP 3
62476 +#define APCLI_MT2_ASSOC_TIMEOUT 4
62477 +#define APCLI_MAX_ASSOC_MSG 5
62478 +
62479 +#define APCLI_ASSOC_FUNC_SIZE (APCLI_MAX_ASSOC_STATE * APCLI_MAX_ASSOC_MSG)
62480 +
62481 +//ApCli sync state machine
62482 +#define APCLI_SYNC_IDLE 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
62483 +#define APCLI_JOIN_WAIT_PROBE_RSP 1
62484 +#define APCLI_MAX_SYNC_STATE 2
62485 +
62486 +#define APCLI_SYNC_MACHINE_BASE 0
62487 +#define APCLI_MT2_MLME_PROBE_REQ 0
62488 +#define APCLI_MT2_PEER_PROBE_RSP 1
62489 +#define APCLI_MT2_PROBE_TIMEOUT 2
62490 +#define APCLI_MAX_SYNC_MSG 3
62491 +
62492 +#define APCLI_SYNC_FUNC_SIZE (APCLI_MAX_SYNC_STATE * APCLI_MAX_SYNC_MSG)
62493 +
62494 +//ApCli ctrl state machine
62495 +#define APCLI_CTRL_DISCONNECTED 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
62496 +#define APCLI_CTRL_PROBE 1
62497 +#define APCLI_CTRL_AUTH 2
62498 +#define APCLI_CTRL_AUTH_2 3
62499 +#define APCLI_CTRL_ASSOC 4
62500 +#define APCLI_CTRL_DEASSOC 5
62501 +#define APCLI_CTRL_CONNECTED 6
62502 +#define APCLI_MAX_CTRL_STATE 7
62503 +
62504 +#define APCLI_CTRL_MACHINE_BASE 0
62505 +#define APCLI_CTRL_JOIN_REQ 0
62506 +#define APCLI_CTRL_PROBE_RSP 1
62507 +#define APCLI_CTRL_AUTH_RSP 2
62508 +#define APCLI_CTRL_DISCONNECT_REQ 3
62509 +#define APCLI_CTRL_PEER_DISCONNECT_REQ 4
62510 +#define APCLI_CTRL_ASSOC_RSP 5
62511 +#define APCLI_CTRL_DEASSOC_RSP 6
62512 +#define APCLI_CTRL_JOIN_REQ_TIMEOUT 7
62513 +#define APCLI_CTRL_AUTH_REQ_TIMEOUT 8
62514 +#define APCLI_CTRL_ASSOC_REQ_TIMEOUT 9
62515 +#define APCLI_MAX_CTRL_MSG 10
62516 +
62517 +#define APCLI_CTRL_FUNC_SIZE (APCLI_MAX_CTRL_STATE * APCLI_MAX_CTRL_MSG)
62518 +
62519 +#if 0 // remove those variables by AlbertY
62520 +// ApCli WPA state machine
62521 +#define APCLI_WPA_PSK_IDLE 0
62522 +#define APCLI_MAX_WPA_PSK_STATE 1
62523 +
62524 +// ApCli WPA MSG Type
62525 +#define APCLI_WPA_MACHINE_BASE 0
62526 +#define APCLI_MT2_EAPPacket 0
62527 +#define APCLI_MT2_EAPOLStart 1
62528 +#define APCLI_MT2_EAPOLLogoff 2
62529 +#define APCLI_MT2_EAPOLKey 3
62530 +#define APCLI_MT2_EAPOLASFAlert 4
62531 +#define APCLI_MAX_WPA_PSK_MSG 5
62532 +
62533 +#define APCLI_WPA_PSK_FUNC_SIZE (APCLI_MAX_WPA_PSK_STATE * APCLI_MAX_WPA_PSK_MSG)
62534 +#endif // end - 0 //
62535 +
62536 +#endif // APCLI_SUPPORT //
62537 +
62538 +
62539 +// =============================================================================
62540 +
62541 +// value domain of 802.11 header FC.Tyte, which is b3..b2 of the 1st-byte of MAC header
62542 +#define BTYPE_MGMT 0
62543 +#define BTYPE_CNTL 1
62544 +#define BTYPE_DATA 2
62545 +
62546 +// value domain of 802.11 MGMT frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
62547 +#define SUBTYPE_ASSOC_REQ 0
62548 +#define SUBTYPE_ASSOC_RSP 1
62549 +#define SUBTYPE_REASSOC_REQ 2
62550 +#define SUBTYPE_REASSOC_RSP 3
62551 +#define SUBTYPE_PROBE_REQ 4
62552 +#define SUBTYPE_PROBE_RSP 5
62553 +#define SUBTYPE_BEACON 8
62554 +#define SUBTYPE_ATIM 9
62555 +#define SUBTYPE_DISASSOC 10
62556 +#define SUBTYPE_AUTH 11
62557 +#define SUBTYPE_DEAUTH 12
62558 +#define SUBTYPE_ACTION 13
62559 +#define SUBTYPE_ACTION_NO_ACK 14
62560 +
62561 +// value domain of 802.11 CNTL frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
62562 +#define SUBTYPE_WRAPPER 7
62563 +#define SUBTYPE_BLOCK_ACK_REQ 8
62564 +#define SUBTYPE_BLOCK_ACK 9
62565 +#define SUBTYPE_PS_POLL 10
62566 +#define SUBTYPE_RTS 11
62567 +#define SUBTYPE_CTS 12
62568 +#define SUBTYPE_ACK 13
62569 +#define SUBTYPE_CFEND 14
62570 +#define SUBTYPE_CFEND_CFACK 15
62571 +
62572 +// value domain of 802.11 DATA frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
62573 +#define SUBTYPE_DATA 0
62574 +#define SUBTYPE_DATA_CFACK 1
62575 +#define SUBTYPE_DATA_CFPOLL 2
62576 +#define SUBTYPE_DATA_CFACK_CFPOLL 3
62577 +#define SUBTYPE_NULL_FUNC 4
62578 +#define SUBTYPE_CFACK 5
62579 +#define SUBTYPE_CFPOLL 6
62580 +#define SUBTYPE_CFACK_CFPOLL 7
62581 +#define SUBTYPE_QDATA 8
62582 +#define SUBTYPE_QDATA_CFACK 9
62583 +#define SUBTYPE_QDATA_CFPOLL 10
62584 +#define SUBTYPE_QDATA_CFACK_CFPOLL 11
62585 +#define SUBTYPE_QOS_NULL 12
62586 +#define SUBTYPE_QOS_CFACK 13
62587 +#define SUBTYPE_QOS_CFPOLL 14
62588 +#define SUBTYPE_QOS_CFACK_CFPOLL 15
62589 +
62590 +// ACK policy of QOS Control field bit 6:5
62591 +#define NORMAL_ACK 0x00 // b6:5 = 00
62592 +#define NO_ACK 0x20 // b6:5 = 01
62593 +#define NO_EXPLICIT_ACK 0x40 // b6:5 = 10
62594 +#define BLOCK_ACK 0x60 // b6:5 = 11
62595 +
62596 +//
62597 +// rtmp_data.c use these definition
62598 +//
62599 +#define LENGTH_802_11 24
62600 +#define LENGTH_802_11_AND_H 30
62601 +#define LENGTH_802_11_CRC_H 34
62602 +#define LENGTH_802_11_CRC 28
62603 +#define LENGTH_802_11_WITH_ADDR4 30
62604 +#define LENGTH_802_3 14
62605 +#define LENGTH_802_3_TYPE 2
62606 +#define LENGTH_802_1_H 8
62607 +#define LENGTH_EAPOL_H 4
62608 +#define LENGTH_WMMQOS_H 2
62609 +#define LENGTH_CRC 4
62610 +#define MAX_SEQ_NUMBER 0x0fff
62611 +#define LENGTH_802_3_NO_TYPE 12
62612 +#define LENGTH_802_1Q 4 /* VLAN related */
62613 +
62614 +// STA_CSR4.field.TxResult
62615 +#define TX_RESULT_SUCCESS 0
62616 +#define TX_RESULT_ZERO_LENGTH 1
62617 +#define TX_RESULT_UNDER_RUN 2
62618 +#define TX_RESULT_OHY_ERROR 4
62619 +#define TX_RESULT_RETRY_FAIL 6
62620 +
62621 +// All PHY rate summary in TXD
62622 +// Preamble MODE in TxD
62623 +#define MODE_CCK 0
62624 +#define MODE_OFDM 1
62625 +#ifdef DOT11_N_SUPPORT
62626 +#define MODE_HTMIX 2
62627 +#define MODE_HTGREENFIELD 3
62628 +#endif // DOT11_N_SUPPORT //
62629 +// MCS for CCK. BW.SGI.STBC are reserved
62630 +#define MCS_LONGP_RATE_1 0 // long preamble CCK 1Mbps
62631 +#define MCS_LONGP_RATE_2 1 // long preamble CCK 1Mbps
62632 +#define MCS_LONGP_RATE_5_5 2
62633 +#define MCS_LONGP_RATE_11 3
62634 +#define MCS_SHORTP_RATE_1 4 // long preamble CCK 1Mbps. short is forbidden in 1Mbps
62635 +#define MCS_SHORTP_RATE_2 5 // short preamble CCK 2Mbps
62636 +#define MCS_SHORTP_RATE_5_5 6
62637 +#define MCS_SHORTP_RATE_11 7
62638 +// To send duplicate legacy OFDM. set BW=BW_40. SGI.STBC are reserved
62639 +#define MCS_RATE_6 0 // legacy OFDM
62640 +#define MCS_RATE_9 1 // OFDM
62641 +#define MCS_RATE_12 2 // OFDM
62642 +#define MCS_RATE_18 3 // OFDM
62643 +#define MCS_RATE_24 4 // OFDM
62644 +#define MCS_RATE_36 5 // OFDM
62645 +#define MCS_RATE_48 6 // OFDM
62646 +#define MCS_RATE_54 7 // OFDM
62647 +// HT
62648 +#define MCS_0 0 // 1S
62649 +#define MCS_1 1
62650 +#define MCS_2 2
62651 +#define MCS_3 3
62652 +#define MCS_4 4
62653 +#define MCS_5 5
62654 +#define MCS_6 6
62655 +#define MCS_7 7
62656 +#define MCS_8 8 // 2S
62657 +#define MCS_9 9
62658 +#define MCS_10 10
62659 +#define MCS_11 11
62660 +#define MCS_12 12
62661 +#define MCS_13 13
62662 +#define MCS_14 14
62663 +#define MCS_15 15
62664 +#define MCS_16 16 // 3*3
62665 +#define MCS_17 17
62666 +#define MCS_18 18
62667 +#define MCS_19 19
62668 +#define MCS_20 20
62669 +#define MCS_21 21
62670 +#define MCS_22 22
62671 +#define MCS_23 23
62672 +#define MCS_32 32
62673 +#define MCS_AUTO 33
62674 +
62675 +#ifdef DOT11_N_SUPPORT
62676 +// OID_HTPHYMODE
62677 +// MODE
62678 +#define HTMODE_MM 0
62679 +#define HTMODE_GF 1
62680 +#endif // DOT11_N_SUPPORT //
62681 +
62682 +// Fixed Tx MODE - HT, CCK or OFDM
62683 +#define FIXED_TXMODE_HT 0
62684 +#define FIXED_TXMODE_CCK 1
62685 +#define FIXED_TXMODE_OFDM 2
62686 +// BW
62687 +#define BW_20 BAND_WIDTH_20
62688 +#define BW_40 BAND_WIDTH_40
62689 +#define BW_BOTH BAND_WIDTH_BOTH
62690 +#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.
62691 +
62692 +#ifdef DOT11_N_SUPPORT
62693 +// SHORTGI
62694 +#define GI_400 GAP_INTERVAL_400 // only support in HT mode
62695 +#define GI_BOTH GAP_INTERVAL_BOTH
62696 +#endif // DOT11_N_SUPPORT //
62697 +#define GI_800 GAP_INTERVAL_800
62698 +// STBC
62699 +#define STBC_NONE 0
62700 +#ifdef DOT11_N_SUPPORT
62701 +#define STBC_USE 1 // limited use in rt2860b phy
62702 +#define RXSTBC_ONE 1 // rx support of one spatial stream
62703 +#define RXSTBC_TWO 2 // rx support of 1 and 2 spatial stream
62704 +#define RXSTBC_THR 3 // rx support of 1~3 spatial stream
62705 +// MCS FEEDBACK
62706 +#define MCSFBK_NONE 0 // not support mcs feedback /
62707 +#define MCSFBK_RSV 1 // reserved
62708 +#define MCSFBK_UNSOLICIT 2 // only support unsolict mcs feedback
62709 +#define MCSFBK_MRQ 3 // response to both MRQ and unsolict mcs feedback
62710 +
62711 +// MIMO power safe
62712 +#define MMPS_STATIC 0
62713 +#define MMPS_DYNAMIC 1
62714 +#define MMPS_RSV 2
62715 +#define MMPS_ENABLE 3
62716 +
62717 +
62718 +// A-MSDU size
62719 +#define AMSDU_0 0
62720 +#define AMSDU_1 1
62721 +
62722 +#endif // DOT11_N_SUPPORT //
62723 +
62724 +// MCS use 7 bits
62725 +#define TXRATEMIMO 0x80
62726 +#define TXRATEMCS 0x7F
62727 +#define TXRATEOFDM 0x7F
62728 +#define RATE_1 0
62729 +#define RATE_2 1
62730 +#define RATE_5_5 2
62731 +#define RATE_11 3
62732 +#define RATE_6 4 // OFDM
62733 +#define RATE_9 5 // OFDM
62734 +#define RATE_12 6 // OFDM
62735 +#define RATE_18 7 // OFDM
62736 +#define RATE_24 8 // OFDM
62737 +#define RATE_36 9 // OFDM
62738 +#define RATE_48 10 // OFDM
62739 +#define RATE_54 11 // OFDM
62740 +#define RATE_FIRST_OFDM_RATE RATE_6
62741 +#define RATE_LAST_OFDM_RATE RATE_54
62742 +#define RATE_6_5 12 // HT mix
62743 +#define RATE_13 13 // HT mix
62744 +#define RATE_19_5 14 // HT mix
62745 +#define RATE_26 15 // HT mix
62746 +#define RATE_39 16 // HT mix
62747 +#define RATE_52 17 // HT mix
62748 +#define RATE_58_5 18 // HT mix
62749 +#define RATE_65 19 // HT mix
62750 +#define RATE_78 20 // HT mix
62751 +#define RATE_104 21 // HT mix
62752 +#define RATE_117 22 // HT mix
62753 +#define RATE_130 23 // HT mix
62754 +//#define RATE_AUTO_SWITCH 255 // for StaCfg.FixedTxRate only
62755 +#define HTRATE_0 12
62756 +#define RATE_FIRST_MM_RATE HTRATE_0
62757 +#define RATE_FIRST_HT_RATE HTRATE_0
62758 +#define RATE_LAST_HT_RATE HTRATE_0
62759 +
62760 +// pTxWI->txop
62761 +#define IFS_HTTXOP 0 // The txop will be handles by ASIC.
62762 +#define IFS_PIFS 1
62763 +#define IFS_SIFS 2
62764 +#define IFS_BACKOFF 3
62765 +
62766 +// pTxD->RetryMode
62767 +#define LONG_RETRY 1
62768 +#define SHORT_RETRY 0
62769 +
62770 +// Country Region definition
62771 +#define REGION_MINIMUM_BG_BAND 0
62772 +#define REGION_0_BG_BAND 0 // 1-11
62773 +#define REGION_1_BG_BAND 1 // 1-13
62774 +#define REGION_2_BG_BAND 2 // 10-11
62775 +#define REGION_3_BG_BAND 3 // 10-13
62776 +#define REGION_4_BG_BAND 4 // 14
62777 +#define REGION_5_BG_BAND 5 // 1-14
62778 +#define REGION_6_BG_BAND 6 // 3-9
62779 +#define REGION_7_BG_BAND 7 // 5-13
62780 +#define REGION_31_BG_BAND 31 // 5-13
62781 +#define REGION_MAXIMUM_BG_BAND 7
62782 +
62783 +#define REGION_MINIMUM_A_BAND 0
62784 +#define REGION_0_A_BAND 0 // 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165
62785 +#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
62786 +#define REGION_2_A_BAND 2 // 36, 40, 44, 48, 52, 56, 60, 64
62787 +#define REGION_3_A_BAND 3 // 52, 56, 60, 64, 149, 153, 157, 161
62788 +#define REGION_4_A_BAND 4 // 149, 153, 157, 161, 165
62789 +#define REGION_5_A_BAND 5 // 149, 153, 157, 161
62790 +#define REGION_6_A_BAND 6 // 36, 40, 44, 48
62791 +#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
62792 +#define REGION_8_A_BAND 8 // 52, 56, 60, 64
62793 +#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
62794 +#define REGION_10_A_BAND 10 // 36, 40, 44, 48, 149, 153, 157, 161, 165
62795 +#define REGION_11_A_BAND 11 // 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161
62796 +#define REGION_MAXIMUM_A_BAND 11
62797 +
62798 +// pTxD->CipherAlg
62799 +#define CIPHER_NONE 0
62800 +#define CIPHER_WEP64 1
62801 +#define CIPHER_WEP128 2
62802 +#define CIPHER_TKIP 3
62803 +#define CIPHER_AES 4
62804 +#define CIPHER_CKIP64 5
62805 +#define CIPHER_CKIP128 6
62806 +#define CIPHER_TKIP_NO_MIC 7 // MIC appended by driver: not a valid value in hardware key table
62807 +#define CIPHER_SMS4 8
62808 +
62809 +// value domain of pAd->RfIcType
62810 +#define RFIC_2820 1 // 2.4G 2T3R
62811 +#define RFIC_2850 2 // 2.4G/5G 2T3R
62812 +#define RFIC_2720 3 // 2.4G 1T2R
62813 +#define RFIC_2750 4 // 2.4G/5G 1T2R
62814 +#define RFIC_3020 5 // 2.4G 1T1R
62815 +#define RFIC_2020 6 // 2.4G B/G
62816 +
62817 +// LED Status.
62818 +#define LED_LINK_DOWN 0
62819 +#define LED_LINK_UP 1
62820 +#define LED_RADIO_OFF 2
62821 +#define LED_RADIO_ON 3
62822 +#define LED_HALT 4
62823 +#define LED_WPS 5
62824 +#define LED_ON_SITE_SURVEY 6
62825 +#define LED_POWER_UP 7
62826 +
62827 +// value domain of pAd->LedCntl.LedMode and E2PROM
62828 +#define LED_MODE_DEFAULT 0
62829 +#define LED_MODE_TWO_LED 1
62830 +#define LED_MODE_SIGNAL_STREGTH 8 // EEPROM define =8
62831 +
62832 +// RC4 init value, used fro WEP & TKIP
62833 +#define PPPINITFCS32 0xffffffff /* Initial FCS value */
62834 +
62835 +// value domain of pAd->StaCfg.PortSecured. 802.1X controlled port definition
62836 +#define WPA_802_1X_PORT_SECURED 1
62837 +#define WPA_802_1X_PORT_NOT_SECURED 2
62838 +
62839 +#define PAIRWISE_KEY 1
62840 +#define GROUP_KEY 2
62841 +
62842 +//definition of DRS
62843 +#define MAX_STEP_OF_TX_RATE_SWITCH 32
62844 +
62845 +
62846 +// pre-allocated free NDIS PACKET/BUFFER poll for internal usage
62847 +#define MAX_NUM_OF_FREE_NDIS_PACKET 128
62848 +
62849 +//Block ACK
62850 +#define MAX_TX_REORDERBUF 64
62851 +#define MAX_RX_REORDERBUF 64
62852 +#define DEFAULT_TX_TIMEOUT 30
62853 +#define DEFAULT_RX_TIMEOUT 30
62854 +
62855 +// definition of Recipient or Originator
62856 +#define I_RECIPIENT TRUE
62857 +#define I_ORIGINATOR FALSE
62858 +
62859 +#define DEFAULT_BBP_TX_POWER 0
62860 +#define DEFAULT_RF_TX_POWER 5
62861 +
62862 +#define MAX_INI_BUFFER_SIZE 4096
62863 +#define MAX_PARAM_BUFFER_SIZE (2048) // enough for ACL (18*64)
62864 + //18 : the length of Mac address acceptable format "01:02:03:04:05:06;")
62865 + //64 : MAX_NUM_OF_ACL_LIST
62866 +// definition of pAd->OpMode
62867 +#define OPMODE_STA 0
62868 +#define OPMODE_AP 1
62869 +//#define OPMODE_L3_BRG 2 // as AP and STA at the same time
62870 +
62871 +#ifdef RT_BIG_ENDIAN
62872 +#define DIR_READ 0
62873 +#define DIR_WRITE 1
62874 +#define TYPE_TXD 0
62875 +#define TYPE_RXD 1
62876 +#define TYPE_TXINFO 0
62877 +#define TYPE_RXINFO 1
62878 +#define TYPE_TXWI 0
62879 +#define TYPE_RXWI 1
62880 +#endif
62881 +
62882 +// ========================= AP rtmp_def.h ===========================
62883 +// value domain for pAd->EventTab.Log[].Event
62884 +#define EVENT_RESET_ACCESS_POINT 0 // Log = "hh:mm:ss Restart Access Point"
62885 +#define EVENT_ASSOCIATED 1 // Log = "hh:mm:ss STA 00:01:02:03:04:05 associated"
62886 +#define EVENT_DISASSOCIATED 2 // Log = "hh:mm:ss STA 00:01:02:03:04:05 left this BSS"
62887 +#define EVENT_AGED_OUT 3 // Log = "hh:mm:ss STA 00:01:02:03:04:05 was aged-out and removed from this BSS"
62888 +#define EVENT_COUNTER_M 4
62889 +#define EVENT_INVALID_PSK 5
62890 +#define EVENT_MAX_EVENT_TYPE 6
62891 +// ==== end of AP rtmp_def.h ============
62892 +
62893 +// definition RSSI Number
62894 +#define RSSI_0 0
62895 +#define RSSI_1 1
62896 +#define RSSI_2 2
62897 +
62898 +// definition of radar detection
62899 +#define RD_NORMAL_MODE 0 // Not found radar signal
62900 +#define RD_SWITCHING_MODE 1 // Found radar signal, and doing channel switch
62901 +#define RD_SILENCE_MODE 2 // After channel switch, need to be silence a while to ensure radar not found
62902 +
62903 +//Driver defined cid for mapping status and command.
62904 +#define SLEEPCID 0x11
62905 +#define WAKECID 0x22
62906 +#define QUERYPOWERCID 0x33
62907 +#define OWNERMCU 0x1
62908 +#define OWNERCPU 0x0
62909 +
62910 +// MBSSID definition
62911 +#define ENTRY_NOT_FOUND 0xFF
62912 +
62913 +
62914 +/* After Linux 2.6.9,
62915 + * VLAN module use Private (from user) interface flags (netdevice->priv_flags).
62916 + * #define IFF_802_1Q_VLAN 0x1 -- 802.1Q VLAN device. in if.h
62917 + * ref to ip_sabotage_out() [ out->priv_flags & IFF_802_1Q_VLAN ] in br_netfilter.c
62918 + *
62919 + * For this reason, we MUST use EVEN value in priv_flags
62920 + */
62921 +#define INT_MAIN 0x0100
62922 +#define INT_MBSSID 0x0200
62923 +#define INT_WDS 0x0300
62924 +#define INT_APCLI 0x0400
62925 +#define INT_MESH 0x0500
62926 +
62927 +// Use bitmap to allow coexist of ATE_TXFRAME and ATE_RXFRAME(i.e.,to support LoopBack mode)
62928 +#ifdef RALINK_ATE
62929 +#define ATE_START 0x00 // Start ATE
62930 +#define ATE_STOP 0x80 // Stop ATE
62931 +#define ATE_TXCONT 0x05 // Continuous Transmit
62932 +#define ATE_TXCARR 0x09 // Transmit Carrier
62933 +#define ATE_TXCARRSUPP 0x11 // Transmit Carrier Suppression
62934 +#define ATE_TXFRAME 0x01 // Transmit Frames
62935 +#define ATE_RXFRAME 0x02 // Receive Frames
62936 +#ifdef RALINK_28xx_QA
62937 +#define ATE_TXSTOP 0xe2 // Stop Transmition(i.e., TXCONT, TXCARR, TXCARRSUPP, and TXFRAME)
62938 +#define ATE_RXSTOP 0xfd // Stop receiving Frames
62939 +#define BBP22_TXFRAME 0x00 // Transmit Frames
62940 +#define BBP22_TXCONT_OR_CARRSUPP 0x80 // Continuous Transmit or Carrier Suppression
62941 +#define BBP22_TXCARR 0xc1 // Transmit Carrier
62942 +#define BBP24_TXCONT 0x00 // Continuous Transmit
62943 +#define BBP24_CARRSUPP 0x01 // Carrier Suppression
62944 +#endif // RALINK_28xx_QA //
62945 +#endif // RALINK_ATE //
62946 +
62947 +// WEP Key TYPE
62948 +#define WEP_HEXADECIMAL_TYPE 0
62949 +#define WEP_ASCII_TYPE 1
62950 +
62951 +
62952 +
62953 +// WIRELESS EVENTS definition
62954 +/* Max number of char in custom event, refer to wireless_tools.28/wireless.20.h */
62955 +#define IW_CUSTOM_MAX_LEN 255 /* In bytes */
62956 +
62957 +// For system event - start
62958 +#define IW_SYS_EVENT_FLAG_START 0x0200
62959 +#define IW_ASSOC_EVENT_FLAG 0x0200
62960 +#define IW_DISASSOC_EVENT_FLAG 0x0201
62961 +#define IW_DEAUTH_EVENT_FLAG 0x0202
62962 +#define IW_AGEOUT_EVENT_FLAG 0x0203
62963 +#define IW_COUNTER_MEASURES_EVENT_FLAG 0x0204
62964 +#define IW_REPLAY_COUNTER_DIFF_EVENT_FLAG 0x0205
62965 +#define IW_RSNIE_DIFF_EVENT_FLAG 0x0206
62966 +#define IW_MIC_DIFF_EVENT_FLAG 0x0207
62967 +#define IW_ICV_ERROR_EVENT_FLAG 0x0208
62968 +#define IW_MIC_ERROR_EVENT_FLAG 0x0209
62969 +#define IW_GROUP_HS_TIMEOUT_EVENT_FLAG 0x020A
62970 +#define IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG 0x020B
62971 +#define IW_RSNIE_SANITY_FAIL_EVENT_FLAG 0x020C
62972 +#define IW_SET_KEY_DONE_WPA1_EVENT_FLAG 0x020D
62973 +#define IW_SET_KEY_DONE_WPA2_EVENT_FLAG 0x020E
62974 +#define IW_STA_LINKUP_EVENT_FLAG 0x020F
62975 +#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210
62976 +#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211
62977 +#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212
62978 +// if add new system event flag, please upadte the IW_SYS_EVENT_FLAG_END
62979 +#define IW_SYS_EVENT_FLAG_END 0x0212
62980 +#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1)
62981 +// For system event - end
62982 +
62983 +// For spoof attack event - start
62984 +#define IW_SPOOF_EVENT_FLAG_START 0x0300
62985 +#define IW_CONFLICT_SSID_EVENT_FLAG 0x0300
62986 +#define IW_SPOOF_ASSOC_RESP_EVENT_FLAG 0x0301
62987 +#define IW_SPOOF_REASSOC_RESP_EVENT_FLAG 0x0302
62988 +#define IW_SPOOF_PROBE_RESP_EVENT_FLAG 0x0303
62989 +#define IW_SPOOF_BEACON_EVENT_FLAG 0x0304
62990 +#define IW_SPOOF_DISASSOC_EVENT_FLAG 0x0305
62991 +#define IW_SPOOF_AUTH_EVENT_FLAG 0x0306
62992 +#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307
62993 +#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308
62994 +#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309
62995 +// if add new spoof attack event flag, please upadte the IW_SPOOF_EVENT_FLAG_END
62996 +#define IW_SPOOF_EVENT_FLAG_END 0x0309
62997 +#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1)
62998 +// For spoof attack event - end
62999 +
63000 +// For flooding attack event - start
63001 +#define IW_FLOOD_EVENT_FLAG_START 0x0400
63002 +#define IW_FLOOD_AUTH_EVENT_FLAG 0x0400
63003 +#define IW_FLOOD_ASSOC_REQ_EVENT_FLAG 0x0401
63004 +#define IW_FLOOD_REASSOC_REQ_EVENT_FLAG 0x0402
63005 +#define IW_FLOOD_PROBE_REQ_EVENT_FLAG 0x0403
63006 +#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404
63007 +#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405
63008 +#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406
63009 +// if add new flooding attack event flag, please upadte the IW_FLOOD_EVENT_FLAG_END
63010 +#define IW_FLOOD_EVENT_FLAG_END 0x0406
63011 +#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1)
63012 +// For flooding attack - end
63013 +
63014 +// End - WIRELESS EVENTS definition
63015 +
63016 +#ifdef CONFIG_STA_SUPPORT
63017 +// definition for DLS, kathy
63018 +#define MAX_NUM_OF_INIT_DLS_ENTRY 1
63019 +#define MAX_NUM_OF_DLS_ENTRY MAX_NUMBER_OF_DLS_ENTRY
63020 +
63021 +//Block ACK , rt2860, kathy
63022 +#define MAX_TX_REORDERBUF 64
63023 +#define MAX_RX_REORDERBUF 64
63024 +#define DEFAULT_TX_TIMEOUT 30
63025 +#define DEFAULT_RX_TIMEOUT 30
63026 +#ifndef CONFIG_AP_SUPPORT
63027 +#define MAX_BARECI_SESSION 8
63028 +#endif
63029 +
63030 +#ifndef IW_ESSID_MAX_SIZE
63031 +/* Maximum size of the ESSID and pAd->nickname strings */
63032 +#define IW_ESSID_MAX_SIZE 32
63033 +#endif
63034 +#endif // CONFIG_STA_SUPPORT //
63035 +
63036 +#ifdef MCAST_RATE_SPECIFIC
63037 +#define MCAST_DISABLE 0
63038 +#define MCAST_CCK 1
63039 +#define MCAST_OFDM 2
63040 +#define MCAST_HTMIX 3
63041 +#endif // MCAST_RATE_SPECIFIC //
63042 +
63043 +// For AsicRadioOff/AsicRadioOn function
63044 +#define DOT11POWERSAVE 0
63045 +#define GUIRADIO_OFF 1
63046 +#define RTMP_HALT 2
63047 +#define GUI_IDLE_POWER_SAVE 3
63048 +// --
63049 +
63050 +
63051 +// definition for WpaSupport flag
63052 +#define WPA_SUPPLICANT_DISABLE 0
63053 +#define WPA_SUPPLICANT_ENABLE 1
63054 +#define WPA_SUPPLICANT_ENABLE_WITH_WEB_UI 2
63055 +
63056 +// Endian byte swapping codes
63057 +#define SWAP16(x) \
63058 + ((UINT16)( \
63059 + (((UINT16)(x) & (UINT16) 0x00ffU) << 8) | \
63060 + (((UINT16)(x) & (UINT16) 0xff00U) >> 8) ))
63061 +
63062 +#define SWAP32(x) \
63063 + ((UINT32)( \
63064 + (((UINT32)(x) & (UINT32) 0x000000ffUL) << 24) | \
63065 + (((UINT32)(x) & (UINT32) 0x0000ff00UL) << 8) | \
63066 + (((UINT32)(x) & (UINT32) 0x00ff0000UL) >> 8) | \
63067 + (((UINT32)(x) & (UINT32) 0xff000000UL) >> 24) ))
63068 +
63069 +#define SWAP64(x) \
63070 + ((UINT64)( \
63071 + (UINT64)(((UINT64)(x) & (UINT64) 0x00000000000000ffULL) << 56) | \
63072 + (UINT64)(((UINT64)(x) & (UINT64) 0x000000000000ff00ULL) << 40) | \
63073 + (UINT64)(((UINT64)(x) & (UINT64) 0x0000000000ff0000ULL) << 24) | \
63074 + (UINT64)(((UINT64)(x) & (UINT64) 0x00000000ff000000ULL) << 8) | \
63075 + (UINT64)(((UINT64)(x) & (UINT64) 0x000000ff00000000ULL) >> 8) | \
63076 + (UINT64)(((UINT64)(x) & (UINT64) 0x0000ff0000000000ULL) >> 24) | \
63077 + (UINT64)(((UINT64)(x) & (UINT64) 0x00ff000000000000ULL) >> 40) | \
63078 + (UINT64)(((UINT64)(x) & (UINT64) 0xff00000000000000ULL) >> 56) ))
63079 +
63080 +#ifdef RT_BIG_ENDIAN
63081 +
63082 +#define cpu2le64(x) SWAP64((x))
63083 +#define le2cpu64(x) SWAP64((x))
63084 +#define cpu2le32(x) SWAP32((x))
63085 +#define le2cpu32(x) SWAP32((x))
63086 +#define cpu2le16(x) SWAP16((x))
63087 +#define le2cpu16(x) SWAP16((x))
63088 +#define cpu2be64(x) ((UINT64)(x))
63089 +#define be2cpu64(x) ((UINT64)(x))
63090 +#define cpu2be32(x) ((UINT32)(x))
63091 +#define be2cpu32(x) ((UINT32)(x))
63092 +#define cpu2be16(x) ((UINT16)(x))
63093 +#define be2cpu16(x) ((UINT16)(x))
63094 +
63095 +#else // Little_Endian
63096 +
63097 +#define cpu2le64(x) ((UINT64)(x))
63098 +#define le2cpu64(x) ((UINT64)(x))
63099 +#define cpu2le32(x) ((UINT32)(x))
63100 +#define le2cpu32(x) ((UINT32)(x))
63101 +#define cpu2le16(x) ((UINT16)(x))
63102 +#define le2cpu16(x) ((UINT16)(x))
63103 +#define cpu2be64(x) SWAP64((x))
63104 +#define be2cpu64(x) SWAP64((x))
63105 +#define cpu2be32(x) SWAP32((x))
63106 +#define be2cpu32(x) SWAP32((x))
63107 +#define cpu2be16(x) SWAP16((x))
63108 +#define be2cpu16(x) SWAP16((x))
63109 +
63110 +#endif // RT_BIG_ENDIAN
63111 +
63112 +#endif // __RTMP_DEF_H__
63113 +
63114 +
63115 --- /dev/null
63116 +++ b/drivers/staging/rt2870/rtmp.h
63117 @@ -0,0 +1,7586 @@
63118 +/*
63119 + *************************************************************************
63120 + * Ralink Tech Inc.
63121 + * 5F., No.36, Taiyuan St., Jhubei City,
63122 + * Hsinchu County 302,
63123 + * Taiwan, R.O.C.
63124 + *
63125 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
63126 + *
63127 + * This program is free software; you can redistribute it and/or modify *
63128 + * it under the terms of the GNU General Public License as published by *
63129 + * the Free Software Foundation; either version 2 of the License, or *
63130 + * (at your option) any later version. *
63131 + * *
63132 + * This program is distributed in the hope that it will be useful, *
63133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
63134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
63135 + * GNU General Public License for more details. *
63136 + * *
63137 + * You should have received a copy of the GNU General Public License *
63138 + * along with this program; if not, write to the *
63139 + * Free Software Foundation, Inc., *
63140 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
63141 + * *
63142 + *************************************************************************
63143 +
63144 + Module Name:
63145 + rtmp.h
63146 +
63147 + Abstract:
63148 + Miniport generic portion header file
63149 +
63150 + Revision History:
63151 + Who When What
63152 + -------- ---------- ----------------------------------------------
63153 + Paul Lin 2002-08-01 created
63154 + James Tan 2002-09-06 modified (Revise NTCRegTable)
63155 + John Chang 2004-09-06 modified for RT2600
63156 +*/
63157 +#ifndef __RTMP_H__
63158 +#define __RTMP_H__
63159 +
63160 +#include "link_list.h"
63161 +#include "spectrum_def.h"
63162 +
63163 +
63164 +#ifdef CONFIG_STA_SUPPORT
63165 +#include "aironet.h"
63166 +#endif // CONFIG_STA_SUPPORT //
63167 +
63168 +//#define DBG 1
63169 +
63170 +//#define DBG_DIAGNOSE 1
63171 +
63172 +#if defined(CONFIG_AP_SUPPORT) && defined(CONFIG_STA_SUPPORT)
63173 +#define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd) if(_pAd->OpMode == OPMODE_AP)
63174 +#define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd) if(_pAd->OpMode == OPMODE_STA)
63175 +#else
63176 +#define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd)
63177 +#define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd)
63178 +#endif
63179 +
63180 +#define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
63181 +#define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
63182 +#define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
63183 +
63184 +#ifdef RT2870
63185 +////////////////////////////////////////////////////////////////////////////
63186 +// The TX_BUFFER structure forms the transmitted USB packet to the device
63187 +////////////////////////////////////////////////////////////////////////////
63188 +typedef struct __TX_BUFFER{
63189 + union {
63190 + UCHAR WirelessPacket[TX_BUFFER_NORMSIZE];
63191 + HEADER_802_11 NullFrame;
63192 + PSPOLL_FRAME PsPollPacket;
63193 + RTS_FRAME RTSFrame;
63194 + }field;
63195 + UCHAR Aggregation[4]; //Buffer for save Aggregation size.
63196 +} TX_BUFFER, *PTX_BUFFER;
63197 +
63198 +typedef struct __HTTX_BUFFER{
63199 + union {
63200 + UCHAR WirelessPacket[MAX_TXBULK_SIZE];
63201 + HEADER_802_11 NullFrame;
63202 + PSPOLL_FRAME PsPollPacket;
63203 + RTS_FRAME RTSFrame;
63204 + }field;
63205 + UCHAR Aggregation[4]; //Buffer for save Aggregation size.
63206 +} HTTX_BUFFER, *PHTTX_BUFFER;
63207 +
63208 +
63209 +// used to track driver-generated write irps
63210 +typedef struct _TX_CONTEXT
63211 +{
63212 + PVOID pAd; //Initialized in MiniportInitialize
63213 + PURB pUrb; //Initialized in MiniportInitialize
63214 + PIRP pIrp; //used to cancel pending bulk out.
63215 + //Initialized in MiniportInitialize
63216 + PTX_BUFFER TransferBuffer; //Initialized in MiniportInitialize
63217 + ULONG BulkOutSize;
63218 + UCHAR BulkOutPipeId;
63219 + UCHAR SelfIdx;
63220 + BOOLEAN InUse;
63221 + BOOLEAN bWaitingBulkOut; // at least one packet is in this TxContext, ready for making IRP anytime.
63222 + BOOLEAN bFullForBulkOut; // all tx buffer are full , so waiting for tx bulkout.
63223 + BOOLEAN IRPPending;
63224 + BOOLEAN LastOne;
63225 + BOOLEAN bAggregatible;
63226 + UCHAR Header_802_3[LENGTH_802_3];
63227 + UCHAR Rsv[2];
63228 + ULONG DataOffset;
63229 + UINT TxRate;
63230 + dma_addr_t data_dma; // urb dma on linux
63231 +
63232 +} TX_CONTEXT, *PTX_CONTEXT, **PPTX_CONTEXT;
63233 +
63234 +
63235 +// used to track driver-generated write irps
63236 +typedef struct _HT_TX_CONTEXT
63237 +{
63238 + PVOID pAd; //Initialized in MiniportInitialize
63239 + PURB pUrb; //Initialized in MiniportInitialize
63240 + PIRP pIrp; //used to cancel pending bulk out.
63241 + //Initialized in MiniportInitialize
63242 + PHTTX_BUFFER TransferBuffer; //Initialized in MiniportInitialize
63243 + ULONG BulkOutSize; // Indicate the total bulk-out size in bytes in one bulk-transmission
63244 + UCHAR BulkOutPipeId;
63245 + BOOLEAN IRPPending;
63246 + BOOLEAN LastOne;
63247 + BOOLEAN bCurWriting;
63248 + BOOLEAN bRingEmpty;
63249 + BOOLEAN bCopySavePad;
63250 + UCHAR SavedPad[8];
63251 + UCHAR Header_802_3[LENGTH_802_3];
63252 + ULONG CurWritePosition; // Indicate the buffer offset which packet will be inserted start from.
63253 + ULONG CurWriteRealPos; // Indicate the buffer offset which packet now are writing to.
63254 + ULONG NextBulkOutPosition; // Indicate the buffer start offset of a bulk-transmission
63255 + ULONG ENextBulkOutPosition; // Indicate the buffer end offset of a bulk-transmission
63256 + UINT TxRate;
63257 + dma_addr_t data_dma; // urb dma on linux
63258 +} HT_TX_CONTEXT, *PHT_TX_CONTEXT, **PPHT_TX_CONTEXT;
63259 +
63260 +
63261 +//
63262 +// Structure to keep track of receive packets and buffers to indicate
63263 +// receive data to the protocol.
63264 +//
63265 +typedef struct _RX_CONTEXT
63266 +{
63267 + PUCHAR TransferBuffer;
63268 + PVOID pAd;
63269 + PIRP pIrp;//used to cancel pending bulk in.
63270 + PURB pUrb;
63271 + //These 2 Boolean shouldn't both be 1 at the same time.
63272 + ULONG BulkInOffset; // number of packets waiting for reordering .
63273 +// BOOLEAN ReorderInUse; // At least one packet in this buffer are in reordering buffer and wait for receive indication
63274 + BOOLEAN bRxHandling; // Notify this packet is being process now.
63275 + BOOLEAN InUse; // USB Hardware Occupied. Wait for USB HW to put packet.
63276 + BOOLEAN Readable; // Receive Complete back. OK for driver to indicate receiving packet.
63277 + BOOLEAN IRPPending; // TODO: To be removed
63278 + atomic_t IrpLock;
63279 + NDIS_SPIN_LOCK RxContextLock;
63280 + dma_addr_t data_dma; // urb dma on linux
63281 +} RX_CONTEXT, *PRX_CONTEXT;
63282 +#endif // RT2870 //
63283 +
63284 +
63285 +//
63286 +// NDIS Version definitions
63287 +//
63288 +#ifdef NDIS50_MINIPORT
63289 +#define RTMP_NDIS_MAJOR_VERSION 5
63290 +#define RTMP_NDIS_MINOR_VERSION 0
63291 +#endif
63292 +
63293 +#ifdef NDIS51_MINIPORT
63294 +#define RTMP_NDIS_MAJOR_VERSION 5
63295 +#define RTMP_NDIS_MINOR_VERSION 1
63296 +#endif
63297 +
63298 +extern char NIC_VENDOR_DESC[];
63299 +extern int NIC_VENDOR_DESC_LEN;
63300 +
63301 +extern unsigned char SNAP_AIRONET[];
63302 +extern unsigned char CipherSuiteCiscoCCKM[];
63303 +extern unsigned char CipherSuiteCiscoCCKMLen;
63304 +extern unsigned char CipherSuiteCiscoCCKM24[];
63305 +extern unsigned char CipherSuiteCiscoCCKM24Len;
63306 +extern unsigned char CipherSuiteCCXTkip[];
63307 +extern unsigned char CipherSuiteCCXTkipLen;
63308 +extern unsigned char CISCO_OUI[];
63309 +extern UCHAR BaSizeArray[4];
63310 +
63311 +extern UCHAR BROADCAST_ADDR[MAC_ADDR_LEN];
63312 +extern UCHAR MULTICAST_ADDR[MAC_ADDR_LEN];
63313 +extern UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN];
63314 +extern ULONG BIT32[32];
63315 +extern UCHAR BIT8[8];
63316 +extern char* CipherName[];
63317 +extern char* MCSToMbps[];
63318 +extern UCHAR RxwiMCSToOfdmRate[12];
63319 +extern UCHAR SNAP_802_1H[6];
63320 +extern UCHAR SNAP_BRIDGE_TUNNEL[6];
63321 +extern UCHAR SNAP_AIRONET[8];
63322 +extern UCHAR CKIP_LLC_SNAP[8];
63323 +extern UCHAR EAPOL_LLC_SNAP[8];
63324 +extern UCHAR EAPOL[2];
63325 +extern UCHAR IPX[2];
63326 +extern UCHAR APPLE_TALK[2];
63327 +extern UCHAR RateIdToPlcpSignal[12]; // see IEEE802.11a-1999 p.14
63328 +extern UCHAR OfdmRateToRxwiMCS[];
63329 +extern UCHAR OfdmSignalToRateId[16] ;
63330 +extern UCHAR default_cwmin[4];
63331 +extern UCHAR default_cwmax[4];
63332 +extern UCHAR default_sta_aifsn[4];
63333 +extern UCHAR MapUserPriorityToAccessCategory[8];
63334 +
63335 +extern USHORT RateUpPER[];
63336 +extern USHORT RateDownPER[];
63337 +extern UCHAR Phy11BNextRateDownward[];
63338 +extern UCHAR Phy11BNextRateUpward[];
63339 +extern UCHAR Phy11BGNextRateDownward[];
63340 +extern UCHAR Phy11BGNextRateUpward[];
63341 +extern UCHAR Phy11ANextRateDownward[];
63342 +extern UCHAR Phy11ANextRateUpward[];
63343 +extern CHAR RssiSafeLevelForTxRate[];
63344 +extern UCHAR RateIdToMbps[];
63345 +extern USHORT RateIdTo500Kbps[];
63346 +
63347 +extern UCHAR CipherSuiteWpaNoneTkip[];
63348 +extern UCHAR CipherSuiteWpaNoneTkipLen;
63349 +
63350 +extern UCHAR CipherSuiteWpaNoneAes[];
63351 +extern UCHAR CipherSuiteWpaNoneAesLen;
63352 +
63353 +extern UCHAR SsidIe;
63354 +extern UCHAR SupRateIe;
63355 +extern UCHAR ExtRateIe;
63356 +
63357 +#ifdef DOT11_N_SUPPORT
63358 +extern UCHAR HtCapIe;
63359 +extern UCHAR AddHtInfoIe;
63360 +extern UCHAR NewExtChanIe;
63361 +#ifdef DOT11N_DRAFT3
63362 +extern UCHAR ExtHtCapIe;
63363 +#endif // DOT11N_DRAFT3 //
63364 +#endif // DOT11_N_SUPPORT //
63365 +
63366 +extern UCHAR ErpIe;
63367 +extern UCHAR DsIe;
63368 +extern UCHAR TimIe;
63369 +extern UCHAR WpaIe;
63370 +extern UCHAR Wpa2Ie;
63371 +extern UCHAR IbssIe;
63372 +extern UCHAR Ccx2Ie;
63373 +
63374 +extern UCHAR WPA_OUI[];
63375 +extern UCHAR RSN_OUI[];
63376 +extern UCHAR WME_INFO_ELEM[];
63377 +extern UCHAR WME_PARM_ELEM[];
63378 +extern UCHAR Ccx2QosInfo[];
63379 +extern UCHAR Ccx2IeInfo[];
63380 +extern UCHAR RALINK_OUI[];
63381 +extern UCHAR PowerConstraintIE[];
63382 +
63383 +
63384 +extern UCHAR RateSwitchTable[];
63385 +extern UCHAR RateSwitchTable11B[];
63386 +extern UCHAR RateSwitchTable11G[];
63387 +extern UCHAR RateSwitchTable11BG[];
63388 +
63389 +#ifdef DOT11_N_SUPPORT
63390 +extern UCHAR RateSwitchTable11BGN1S[];
63391 +extern UCHAR RateSwitchTable11BGN2S[];
63392 +extern UCHAR RateSwitchTable11BGN2SForABand[];
63393 +extern UCHAR RateSwitchTable11N1S[];
63394 +extern UCHAR RateSwitchTable11N2S[];
63395 +extern UCHAR RateSwitchTable11N2SForABand[];
63396 +
63397 +#ifdef CONFIG_STA_SUPPORT
63398 +extern UCHAR PRE_N_HT_OUI[];
63399 +#endif // CONFIG_STA_SUPPORT //
63400 +#endif // DOT11_N_SUPPORT //
63401 +
63402 +#define MAXSEQ (0xFFF)
63403 +
63404 +#ifdef RALINK_ATE
63405 +typedef struct _ATE_INFO {
63406 + UCHAR Mode;
63407 + CHAR TxPower0;
63408 + CHAR TxPower1;
63409 + CHAR TxAntennaSel;
63410 + CHAR RxAntennaSel;
63411 + TXWI_STRUC TxWI; // TXWI
63412 + USHORT QID;
63413 + UCHAR Addr1[MAC_ADDR_LEN];
63414 + UCHAR Addr2[MAC_ADDR_LEN];
63415 + UCHAR Addr3[MAC_ADDR_LEN];
63416 + UCHAR Channel;
63417 + UINT32 TxLength;
63418 + UINT32 TxCount;
63419 + UINT32 TxDoneCount; // Tx DMA Done
63420 + UINT32 RFFreqOffset;
63421 + BOOLEAN bRxFer;
63422 + BOOLEAN bQATxStart; // Have compiled QA in and use it to ATE tx.
63423 + BOOLEAN bQARxStart; // Have compiled QA in and use it to ATE rx.
63424 + UINT32 RxTotalCnt;
63425 + UINT32 RxCntPerSec;
63426 +
63427 + CHAR LastSNR0; // last received SNR
63428 + CHAR LastSNR1; // last received SNR for 2nd antenna
63429 + CHAR LastRssi0; // last received RSSI
63430 + CHAR LastRssi1; // last received RSSI for 2nd antenna
63431 + CHAR LastRssi2; // last received RSSI for 3rd antenna
63432 + CHAR AvgRssi0; // last 8 frames' average RSSI
63433 + CHAR AvgRssi1; // last 8 frames' average RSSI
63434 + CHAR AvgRssi2; // last 8 frames' average RSSI
63435 + SHORT AvgRssi0X8; // sum of last 8 frames' RSSI
63436 + SHORT AvgRssi1X8; // sum of last 8 frames' RSSI
63437 + SHORT AvgRssi2X8; // sum of last 8 frames' RSSI
63438 +
63439 + UINT32 NumOfAvgRssiSample;
63440 +
63441 +#ifdef RALINK_28xx_QA
63442 + // Tx frame
63443 +#ifdef RT2870
63444 + /* not used in RT2860 */
63445 + TXINFO_STRUC TxInfo; // TxInfo
63446 +#endif // RT2870 //
63447 + USHORT HLen; // Header Length
63448 + USHORT PLen; // Pattern Length
63449 + UCHAR Header[32]; // Header buffer
63450 + UCHAR Pattern[32]; // Pattern buffer
63451 + USHORT DLen; // Data Length
63452 + USHORT seq;
63453 + UINT32 CID;
63454 + THREAD_PID AtePid;
63455 + // counters
63456 + UINT32 U2M;
63457 + UINT32 OtherData;
63458 + UINT32 Beacon;
63459 + UINT32 OtherCount;
63460 + UINT32 TxAc0;
63461 + UINT32 TxAc1;
63462 + UINT32 TxAc2;
63463 + UINT32 TxAc3;
63464 + UINT32 TxHCCA;
63465 + UINT32 TxMgmt;
63466 + UINT32 RSSI0;
63467 + UINT32 RSSI1;
63468 + UINT32 RSSI2;
63469 + UINT32 SNR0;
63470 + UINT32 SNR1;
63471 + // control
63472 + //UINT32 Repeat; // Tx Cpu count
63473 + UCHAR TxStatus; // task Tx status // 0 --> task is idle, 1 --> task is running
63474 +#endif // RALINK_28xx_QA //
63475 +} ATE_INFO, *PATE_INFO;
63476 +
63477 +#ifdef RALINK_28xx_QA
63478 +struct ate_racfghdr {
63479 + UINT32 magic_no;
63480 + USHORT command_type;
63481 + USHORT command_id;
63482 + USHORT length;
63483 + USHORT sequence;
63484 + USHORT status;
63485 + UCHAR data[2046];
63486 +} __attribute__((packed));
63487 +#endif // RALINK_28xx_QA //
63488 +#endif // RALINK_ATE //
63489 +
63490 +#ifdef DOT11_N_SUPPORT
63491 +struct reordering_mpdu
63492 +{
63493 + struct reordering_mpdu *next;
63494 + PNDIS_PACKET pPacket; /* coverted to 802.3 frame */
63495 + int Sequence; /* sequence number of MPDU */
63496 + BOOLEAN bAMSDU;
63497 +};
63498 +
63499 +struct reordering_list
63500 +{
63501 + struct reordering_mpdu *next;
63502 + int qlen;
63503 +};
63504 +
63505 +struct reordering_mpdu_pool
63506 +{
63507 + PVOID mem;
63508 + NDIS_SPIN_LOCK lock;
63509 + struct reordering_list freelist;
63510 +};
63511 +#endif // DOT11_N_SUPPORT //
63512 +
63513 +typedef struct _RSSI_SAMPLE {
63514 + CHAR LastRssi0; // last received RSSI
63515 + CHAR LastRssi1; // last received RSSI
63516 + CHAR LastRssi2; // last received RSSI
63517 + CHAR AvgRssi0;
63518 + CHAR AvgRssi1;
63519 + CHAR AvgRssi2;
63520 + SHORT AvgRssi0X8;
63521 + SHORT AvgRssi1X8;
63522 + SHORT AvgRssi2X8;
63523 +} RSSI_SAMPLE;
63524 +
63525 +//
63526 +// Queue structure and macros
63527 +//
63528 +typedef struct _QUEUE_ENTRY {
63529 + struct _QUEUE_ENTRY *Next;
63530 +} QUEUE_ENTRY, *PQUEUE_ENTRY;
63531 +
63532 +// Queue structure
63533 +typedef struct _QUEUE_HEADER {
63534 + PQUEUE_ENTRY Head;
63535 + PQUEUE_ENTRY Tail;
63536 + ULONG Number;
63537 +} QUEUE_HEADER, *PQUEUE_HEADER;
63538 +
63539 +#define InitializeQueueHeader(QueueHeader) \
63540 +{ \
63541 + (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \
63542 + (QueueHeader)->Number = 0; \
63543 +}
63544 +
63545 +#define RemoveHeadQueue(QueueHeader) \
63546 +(QueueHeader)->Head; \
63547 +{ \
63548 + PQUEUE_ENTRY pNext; \
63549 + if ((QueueHeader)->Head != NULL) \
63550 + { \
63551 + pNext = (QueueHeader)->Head->Next; \
63552 + (QueueHeader)->Head = pNext; \
63553 + if (pNext == NULL) \
63554 + (QueueHeader)->Tail = NULL; \
63555 + (QueueHeader)->Number--; \
63556 + } \
63557 +}
63558 +
63559 +#define InsertHeadQueue(QueueHeader, QueueEntry) \
63560 +{ \
63561 + ((PQUEUE_ENTRY)QueueEntry)->Next = (QueueHeader)->Head; \
63562 + (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
63563 + if ((QueueHeader)->Tail == NULL) \
63564 + (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
63565 + (QueueHeader)->Number++; \
63566 +}
63567 +
63568 +#define InsertTailQueue(QueueHeader, QueueEntry) \
63569 +{ \
63570 + ((PQUEUE_ENTRY)QueueEntry)->Next = NULL; \
63571 + if ((QueueHeader)->Tail) \
63572 + (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
63573 + else \
63574 + (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
63575 + (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
63576 + (QueueHeader)->Number++; \
63577 +}
63578 +
63579 +//
63580 +// Macros for flag and ref count operations
63581 +//
63582 +#define RTMP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
63583 +#define RTMP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
63584 +#define RTMP_CLEAR_FLAGS(_M) ((_M)->Flags = 0)
63585 +#define RTMP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
63586 +#define RTMP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
63587 +
63588 +#define OPSTATUS_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
63589 +#define OPSTATUS_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
63590 +#define OPSTATUS_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
63591 +
63592 +#define CLIENT_STATUS_SET_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags |= (_F))
63593 +#define CLIENT_STATUS_CLEAR_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags &= ~(_F))
63594 +#define CLIENT_STATUS_TEST_FLAG(_pEntry,_F) (((_pEntry)->ClientStatusFlags & (_F)) != 0)
63595 +
63596 +#define RX_FILTER_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter |= (_F))
63597 +#define RX_FILTER_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
63598 +#define RX_FILTER_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
63599 +
63600 +#ifdef CONFIG_STA_SUPPORT
63601 +#define STA_NO_SECURITY_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
63602 +#define STA_WEP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
63603 +#define STA_TKIP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
63604 +#define STA_AES_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
63605 +
63606 +#define STA_TGN_WIFI_ON(_p) (_p->StaCfg.bTGnWifiTest == TRUE)
63607 +#endif // CONFIG_STA_SUPPORT //
63608 +
63609 +#define CKIP_KP_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
63610 +#define CKIP_CMIC_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
63611 +
63612 +
63613 +#define INC_RING_INDEX(_idx, _RingSize) \
63614 +{ \
63615 + (_idx) = (_idx+1) % (_RingSize); \
63616 +}
63617 +
63618 +#define IS_RT3070(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30700000)
63619 +
63620 +#define RING_PACKET_INIT(_TxRing, _idx) \
63621 +{ \
63622 + _TxRing->Cell[_idx].pNdisPacket = NULL; \
63623 + _TxRing->Cell[_idx].pNextNdisPacket = NULL; \
63624 +}
63625 +
63626 +#define TXDT_INIT(_TxD) \
63627 +{ \
63628 + NdisZeroMemory(_TxD, TXD_SIZE); \
63629 + _TxD->DMADONE = 1; \
63630 +}
63631 +
63632 +//Set last data segment
63633 +#define RING_SET_LASTDS(_TxD, _IsSD0) \
63634 +{ \
63635 + if (_IsSD0) {_TxD->LastSec0 = 1;} \
63636 + else {_TxD->LastSec1 = 1;} \
63637 +}
63638 +
63639 +// Increase TxTsc value for next transmission
63640 +// TODO:
63641 +// When i==6, means TSC has done one full cycle, do re-keying stuff follow specs
63642 +// Should send a special event microsoft defined to request re-key
63643 +#define INC_TX_TSC(_tsc) \
63644 +{ \
63645 + int i=0; \
63646 + while (++_tsc[i] == 0x0) \
63647 + { \
63648 + i++; \
63649 + if (i == 6) \
63650 + break; \
63651 + } \
63652 +}
63653 +
63654 +#ifdef DOT11_N_SUPPORT
63655 +// StaActive.SupportedHtPhy.MCSSet is copied from AP beacon. Don't need to update here.
63656 +#define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
63657 +{ \
63658 + _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth; \
63659 + _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs; \
63660 + _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF; \
63661 + _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20; \
63662 + _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40; \
63663 + _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC; \
63664 + _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC; \
63665 + _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset; \
63666 + _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth; \
63667 + _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode; \
63668 + _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent; \
63669 + NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(UCHAR) * 16);\
63670 +}
63671 +
63672 +#define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability) \
63673 +{ \
63674 + _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (UCHAR)(_pHtCapability->HtCapInfo.AMsduSize); \
63675 + _pAd->MacTab.Content[BSSID_WCID].MmpsMode= (UCHAR)(_pHtCapability->HtCapInfo.MimoPs); \
63676 + _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (UCHAR)(_pHtCapability->HtCapParm.MaxRAmpduFactor); \
63677 +}
63678 +#endif // DOT11_N_SUPPORT //
63679 +
63680 +//
63681 +// BBP & RF are using indirect access. Before write any value into it.
63682 +// We have to make sure there is no outstanding command pending via checking busy bit.
63683 +//
63684 +#define MAX_BUSY_COUNT 100 // Number of retry before failing access BBP & RF indirect register
63685 +//
63686 +
63687 +#ifdef RT2870
63688 +#define RTMP_RF_IO_WRITE32(_A, _V) RTUSBWriteRFRegister(_A, _V)
63689 +#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
63690 +#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
63691 +
63692 +#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
63693 +#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
63694 +#endif // RT2870 //
63695 +
63696 +#define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \
63697 + switch (ch) \
63698 + { \
63699 + case 1: khz = 2412000; break; \
63700 + case 2: khz = 2417000; break; \
63701 + case 3: khz = 2422000; break; \
63702 + case 4: khz = 2427000; break; \
63703 + case 5: khz = 2432000; break; \
63704 + case 6: khz = 2437000; break; \
63705 + case 7: khz = 2442000; break; \
63706 + case 8: khz = 2447000; break; \
63707 + case 9: khz = 2452000; break; \
63708 + case 10: khz = 2457000; break; \
63709 + case 11: khz = 2462000; break; \
63710 + case 12: khz = 2467000; break; \
63711 + case 13: khz = 2472000; break; \
63712 + case 14: khz = 2484000; break; \
63713 + case 36: /* UNII */ khz = 5180000; break; \
63714 + case 40: /* UNII */ khz = 5200000; break; \
63715 + case 44: /* UNII */ khz = 5220000; break; \
63716 + case 48: /* UNII */ khz = 5240000; break; \
63717 + case 52: /* UNII */ khz = 5260000; break; \
63718 + case 56: /* UNII */ khz = 5280000; break; \
63719 + case 60: /* UNII */ khz = 5300000; break; \
63720 + case 64: /* UNII */ khz = 5320000; break; \
63721 + case 149: /* UNII */ khz = 5745000; break; \
63722 + case 153: /* UNII */ khz = 5765000; break; \
63723 + case 157: /* UNII */ khz = 5785000; break; \
63724 + case 161: /* UNII */ khz = 5805000; break; \
63725 + case 165: /* UNII */ khz = 5825000; break; \
63726 + case 100: /* HiperLAN2 */ khz = 5500000; break; \
63727 + case 104: /* HiperLAN2 */ khz = 5520000; break; \
63728 + case 108: /* HiperLAN2 */ khz = 5540000; break; \
63729 + case 112: /* HiperLAN2 */ khz = 5560000; break; \
63730 + case 116: /* HiperLAN2 */ khz = 5580000; break; \
63731 + case 120: /* HiperLAN2 */ khz = 5600000; break; \
63732 + case 124: /* HiperLAN2 */ khz = 5620000; break; \
63733 + case 128: /* HiperLAN2 */ khz = 5640000; break; \
63734 + case 132: /* HiperLAN2 */ khz = 5660000; break; \
63735 + case 136: /* HiperLAN2 */ khz = 5680000; break; \
63736 + case 140: /* HiperLAN2 */ khz = 5700000; break; \
63737 + case 34: /* Japan MMAC */ khz = 5170000; break; \
63738 + case 38: /* Japan MMAC */ khz = 5190000; break; \
63739 + case 42: /* Japan MMAC */ khz = 5210000; break; \
63740 + case 46: /* Japan MMAC */ khz = 5230000; break; \
63741 + case 184: /* Japan */ khz = 4920000; break; \
63742 + case 188: /* Japan */ khz = 4940000; break; \
63743 + case 192: /* Japan */ khz = 4960000; break; \
63744 + case 196: /* Japan */ khz = 4980000; break; \
63745 + case 208: /* Japan, means J08 */ khz = 5040000; break; \
63746 + case 212: /* Japan, means J12 */ khz = 5060000; break; \
63747 + case 216: /* Japan, means J16 */ khz = 5080000; break; \
63748 + default: khz = 2412000; break; \
63749 + } \
63750 + }
63751 +
63752 +#define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \
63753 + switch (khz) \
63754 + { \
63755 + case 2412000: ch = 1; break; \
63756 + case 2417000: ch = 2; break; \
63757 + case 2422000: ch = 3; break; \
63758 + case 2427000: ch = 4; break; \
63759 + case 2432000: ch = 5; break; \
63760 + case 2437000: ch = 6; break; \
63761 + case 2442000: ch = 7; break; \
63762 + case 2447000: ch = 8; break; \
63763 + case 2452000: ch = 9; break; \
63764 + case 2457000: ch = 10; break; \
63765 + case 2462000: ch = 11; break; \
63766 + case 2467000: ch = 12; break; \
63767 + case 2472000: ch = 13; break; \
63768 + case 2484000: ch = 14; break; \
63769 + case 5180000: ch = 36; /* UNII */ break; \
63770 + case 5200000: ch = 40; /* UNII */ break; \
63771 + case 5220000: ch = 44; /* UNII */ break; \
63772 + case 5240000: ch = 48; /* UNII */ break; \
63773 + case 5260000: ch = 52; /* UNII */ break; \
63774 + case 5280000: ch = 56; /* UNII */ break; \
63775 + case 5300000: ch = 60; /* UNII */ break; \
63776 + case 5320000: ch = 64; /* UNII */ break; \
63777 + case 5745000: ch = 149; /* UNII */ break; \
63778 + case 5765000: ch = 153; /* UNII */ break; \
63779 + case 5785000: ch = 157; /* UNII */ break; \
63780 + case 5805000: ch = 161; /* UNII */ break; \
63781 + case 5825000: ch = 165; /* UNII */ break; \
63782 + case 5500000: ch = 100; /* HiperLAN2 */ break; \
63783 + case 5520000: ch = 104; /* HiperLAN2 */ break; \
63784 + case 5540000: ch = 108; /* HiperLAN2 */ break; \
63785 + case 5560000: ch = 112; /* HiperLAN2 */ break; \
63786 + case 5580000: ch = 116; /* HiperLAN2 */ break; \
63787 + case 5600000: ch = 120; /* HiperLAN2 */ break; \
63788 + case 5620000: ch = 124; /* HiperLAN2 */ break; \
63789 + case 5640000: ch = 128; /* HiperLAN2 */ break; \
63790 + case 5660000: ch = 132; /* HiperLAN2 */ break; \
63791 + case 5680000: ch = 136; /* HiperLAN2 */ break; \
63792 + case 5700000: ch = 140; /* HiperLAN2 */ break; \
63793 + case 5170000: ch = 34; /* Japan MMAC */ break; \
63794 + case 5190000: ch = 38; /* Japan MMAC */ break; \
63795 + case 5210000: ch = 42; /* Japan MMAC */ break; \
63796 + case 5230000: ch = 46; /* Japan MMAC */ break; \
63797 + case 4920000: ch = 184; /* Japan */ break; \
63798 + case 4940000: ch = 188; /* Japan */ break; \
63799 + case 4960000: ch = 192; /* Japan */ break; \
63800 + case 4980000: ch = 196; /* Japan */ break; \
63801 + case 5040000: ch = 208; /* Japan, means J08 */ break; \
63802 + case 5060000: ch = 212; /* Japan, means J12 */ break; \
63803 + case 5080000: ch = 216; /* Japan, means J16 */ break; \
63804 + default: ch = 1; break; \
63805 + } \
63806 + }
63807 +
63808 +//
63809 +// Common fragment list structure - Identical to the scatter gather frag list structure
63810 +//
63811 +//#define RTMP_SCATTER_GATHER_ELEMENT SCATTER_GATHER_ELEMENT
63812 +//#define PRTMP_SCATTER_GATHER_ELEMENT PSCATTER_GATHER_ELEMENT
63813 +#define NIC_MAX_PHYS_BUF_COUNT 8
63814 +
63815 +typedef struct _RTMP_SCATTER_GATHER_ELEMENT {
63816 + PVOID Address;
63817 + ULONG Length;
63818 + PULONG Reserved;
63819 +} RTMP_SCATTER_GATHER_ELEMENT, *PRTMP_SCATTER_GATHER_ELEMENT;
63820 +
63821 +
63822 +typedef struct _RTMP_SCATTER_GATHER_LIST {
63823 + ULONG NumberOfElements;
63824 + PULONG Reserved;
63825 + RTMP_SCATTER_GATHER_ELEMENT Elements[NIC_MAX_PHYS_BUF_COUNT];
63826 +} RTMP_SCATTER_GATHER_LIST, *PRTMP_SCATTER_GATHER_LIST;
63827 +
63828 +//
63829 +// Some utility macros
63830 +//
63831 +#ifndef min
63832 +#define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
63833 +#endif
63834 +
63835 +#ifndef max
63836 +#define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
63837 +#endif
63838 +
63839 +#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))))
63840 +
63841 +#define INC_COUNTER64(Val) (Val.QuadPart++)
63842 +
63843 +#define INFRA_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
63844 +#define ADHOC_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
63845 +#define MONITOR_ON(_p) (((_p)->StaCfg.BssType) == BSS_MONITOR)
63846 +#define IDLE_ON(_p) (!INFRA_ON(_p) && !ADHOC_ON(_p))
63847 +
63848 +// Check LEAP & CCKM flags
63849 +#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
63850 +#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
63851 +
63852 +// if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required
63853 +#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \
63854 +{ \
63855 + if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) \
63856 + { \
63857 + _pExtraLlcSnapEncap = SNAP_802_1H; \
63858 + if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || \
63859 + NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) \
63860 + { \
63861 + _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
63862 + } \
63863 + } \
63864 + else \
63865 + { \
63866 + _pExtraLlcSnapEncap = NULL; \
63867 + } \
63868 +}
63869 +
63870 +// New Define for new Tx Path.
63871 +#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap) \
63872 +{ \
63873 + if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) \
63874 + { \
63875 + _pExtraLlcSnapEncap = SNAP_802_1H; \
63876 + if (NdisEqualMemory(IPX, _pBufVA, 2) || \
63877 + NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) \
63878 + { \
63879 + _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
63880 + } \
63881 + } \
63882 + else \
63883 + { \
63884 + _pExtraLlcSnapEncap = NULL; \
63885 + } \
63886 +}
63887 +
63888 +
63889 +#define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType) \
63890 +{ \
63891 + NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN); \
63892 + NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN); \
63893 + NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
63894 +}
63895 +
63896 +// if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way.
63897 +// else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field
63898 +// else remove the LLC/SNAP field from the result Ethernet frame
63899 +// Patch for WHQL only, which did not turn on Netbios but use IPX within its payload
63900 +// Note:
63901 +// _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO
63902 +// _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed
63903 +#define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP) \
63904 +{ \
63905 + char LLC_Len[2]; \
63906 + \
63907 + _pRemovedLLCSNAP = NULL; \
63908 + if (NdisEqualMemory(SNAP_802_1H, _pData, 6) || \
63909 + NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) \
63910 + { \
63911 + PUCHAR pProto = _pData + 6; \
63912 + \
63913 + if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) && \
63914 + NdisEqualMemory(SNAP_802_1H, _pData, 6)) \
63915 + { \
63916 + LLC_Len[0] = (UCHAR)(_DataSize / 256); \
63917 + LLC_Len[1] = (UCHAR)(_DataSize % 256); \
63918 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
63919 + } \
63920 + else \
63921 + { \
63922 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto); \
63923 + _pRemovedLLCSNAP = _pData; \
63924 + _DataSize -= LENGTH_802_1_H; \
63925 + _pData += LENGTH_802_1_H; \
63926 + } \
63927 + } \
63928 + else \
63929 + { \
63930 + LLC_Len[0] = (UCHAR)(_DataSize / 256); \
63931 + LLC_Len[1] = (UCHAR)(_DataSize % 256); \
63932 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
63933 + } \
63934 +}
63935 +
63936 +#define SWITCH_AB( _pAA, _pBB) \
63937 +{ \
63938 + PVOID pCC; \
63939 + pCC = _pBB; \
63940 + _pBB = _pAA; \
63941 + _pAA = pCC; \
63942 +}
63943 +
63944 +// Enqueue this frame to MLME engine
63945 +// We need to enqueue the whole frame because MLME need to pass data type
63946 +// information from 802.11 header
63947 +#ifdef RT2870
63948 +#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \
63949 +{ \
63950 + UINT32 High32TSF=0, Low32TSF=0; \
63951 + MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (UCHAR)_Rssi0, (UCHAR)_Rssi1,(UCHAR)_Rssi2,_FrameSize, _pFrame, (UCHAR)_PlcpSignal); \
63952 +}
63953 +#endif // RT2870 //
63954 +
63955 +#define NDIS_QUERY_BUFFER(_NdisBuf, _ppVA, _pBufLen) \
63956 + NdisQueryBuffer(_NdisBuf, _ppVA, _pBufLen)
63957 +
63958 +#define MAC_ADDR_EQUAL(pAddr1,pAddr2) RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
63959 +#define SSID_EQUAL(ssid1, len1, ssid2, len2) ((len1==len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
63960 +
63961 +//
63962 +// Check if it is Japan W53(ch52,56,60,64) channel.
63963 +//
63964 +#define JapanChannelCheck(channel) ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
63965 +
63966 +#ifdef CONFIG_STA_SUPPORT
63967 +#define STA_PORT_SECURED(_pAd) \
63968 +{ \
63969 + _pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
63970 + NdisAcquireSpinLock(&_pAd->MacTabLock); \
63971 + _pAd->MacTab.Content[BSSID_WCID].PortSecured = _pAd->StaCfg.PortSecured; \
63972 + NdisReleaseSpinLock(&_pAd->MacTabLock); \
63973 +}
63974 +#endif // CONFIG_STA_SUPPORT //
63975 +
63976 +
63977 +//
63978 +// Register set pair for initialzation register set definition
63979 +//
63980 +typedef struct _RTMP_REG_PAIR
63981 +{
63982 + ULONG Register;
63983 + ULONG Value;
63984 +} RTMP_REG_PAIR, *PRTMP_REG_PAIR;
63985 +
63986 +typedef struct _REG_PAIR
63987 +{
63988 + UCHAR Register;
63989 + UCHAR Value;
63990 +} REG_PAIR, *PREG_PAIR;
63991 +
63992 +//
63993 +// Register set pair for initialzation register set definition
63994 +//
63995 +typedef struct _RTMP_RF_REGS
63996 +{
63997 + UCHAR Channel;
63998 + ULONG R1;
63999 + ULONG R2;
64000 + ULONG R3;
64001 + ULONG R4;
64002 +} RTMP_RF_REGS, *PRTMP_RF_REGS;
64003 +
64004 +typedef struct _FREQUENCY_ITEM {
64005 + UCHAR Channel;
64006 + UCHAR N;
64007 + UCHAR R;
64008 + UCHAR K;
64009 +} FREQUENCY_ITEM, *PFREQUENCY_ITEM;
64010 +
64011 +//
64012 +// Data buffer for DMA operation, the buffer must be contiguous physical memory
64013 +// Both DMA to / from CPU use the same structure.
64014 +//
64015 +typedef struct _RTMP_DMABUF
64016 +{
64017 + ULONG AllocSize;
64018 + PVOID AllocVa; // TxBuf virtual address
64019 + NDIS_PHYSICAL_ADDRESS AllocPa; // TxBuf physical address
64020 +} RTMP_DMABUF, *PRTMP_DMABUF;
64021 +
64022 +
64023 +typedef union _HEADER_802_11_SEQ{
64024 +#ifdef RT_BIG_ENDIAN
64025 + struct {
64026 + USHORT Sequence:12;
64027 + USHORT Frag:4;
64028 + } field;
64029 +#else
64030 + struct {
64031 + USHORT Frag:4;
64032 + USHORT Sequence:12;
64033 + } field;
64034 +#endif
64035 + USHORT value;
64036 +} HEADER_802_11_SEQ, *PHEADER_802_11_SEQ;
64037 +
64038 +//
64039 +// Data buffer for DMA operation, the buffer must be contiguous physical memory
64040 +// Both DMA to / from CPU use the same structure.
64041 +//
64042 +typedef struct _RTMP_REORDERBUF
64043 +{
64044 + BOOLEAN IsFull;
64045 + PVOID AllocVa; // TxBuf virtual address
64046 + UCHAR Header802_3[14];
64047 + HEADER_802_11_SEQ Sequence; //support compressed bitmap BA, so no consider fragment in BA
64048 + UCHAR DataOffset;
64049 + USHORT Datasize;
64050 + ULONG AllocSize;
64051 +#ifdef RT2870
64052 + PUCHAR AllocPa;
64053 +#endif // RT2870 //
64054 +} RTMP_REORDERBUF, *PRTMP_REORDERBUF;
64055 +
64056 +//
64057 +// Control block (Descriptor) for all ring descriptor DMA operation, buffer must be
64058 +// contiguous physical memory. NDIS_PACKET stored the binding Rx packet descriptor
64059 +// which won't be released, driver has to wait until upper layer return the packet
64060 +// before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair
64061 +// to describe the packet buffer. For Tx, NDIS_PACKET stored the tx packet descriptor
64062 +// which driver should ACK upper layer when the tx is physically done or failed.
64063 +//
64064 +typedef struct _RTMP_DMACB
64065 +{
64066 + ULONG AllocSize; // Control block size
64067 + PVOID AllocVa; // Control block virtual address
64068 + NDIS_PHYSICAL_ADDRESS AllocPa; // Control block physical address
64069 + PNDIS_PACKET pNdisPacket;
64070 + PNDIS_PACKET pNextNdisPacket;
64071 +
64072 + RTMP_DMABUF DmaBuf; // Associated DMA buffer structure
64073 +} RTMP_DMACB, *PRTMP_DMACB;
64074 +
64075 +typedef struct _RTMP_TX_BUF
64076 +{
64077 + PQUEUE_ENTRY Next;
64078 + UCHAR Index;
64079 + ULONG AllocSize; // Control block size
64080 + PVOID AllocVa; // Control block virtual address
64081 + NDIS_PHYSICAL_ADDRESS AllocPa; // Control block physical address
64082 +} RTMP_TXBUF, *PRTMP_TXBUF;
64083 +
64084 +typedef struct _RTMP_RX_BUF
64085 +{
64086 + BOOLEAN InUse;
64087 + ULONG ByBaRecIndex;
64088 + RTMP_REORDERBUF MAP_RXBuf[MAX_RX_REORDERBUF];
64089 +} RTMP_RXBUF, *PRTMP_RXBUF;
64090 +typedef struct _RTMP_TX_RING
64091 +{
64092 + RTMP_DMACB Cell[TX_RING_SIZE];
64093 + UINT32 TxCpuIdx;
64094 + UINT32 TxDmaIdx;
64095 + UINT32 TxSwFreeIdx; // software next free tx index
64096 +} RTMP_TX_RING, *PRTMP_TX_RING;
64097 +
64098 +typedef struct _RTMP_RX_RING
64099 +{
64100 + RTMP_DMACB Cell[RX_RING_SIZE];
64101 + UINT32 RxCpuIdx;
64102 + UINT32 RxDmaIdx;
64103 + INT32 RxSwReadIdx; // software next read index
64104 +} RTMP_RX_RING, *PRTMP_RX_RING;
64105 +
64106 +typedef struct _RTMP_MGMT_RING
64107 +{
64108 + RTMP_DMACB Cell[MGMT_RING_SIZE];
64109 + UINT32 TxCpuIdx;
64110 + UINT32 TxDmaIdx;
64111 + UINT32 TxSwFreeIdx; // software next free tx index
64112 +} RTMP_MGMT_RING, *PRTMP_MGMT_RING;
64113 +
64114 +//
64115 +// Statistic counter structure
64116 +//
64117 +typedef struct _COUNTER_802_3
64118 +{
64119 + // General Stats
64120 + ULONG GoodTransmits;
64121 + ULONG GoodReceives;
64122 + ULONG TxErrors;
64123 + ULONG RxErrors;
64124 + ULONG RxNoBuffer;
64125 +
64126 + // Ethernet Stats
64127 + ULONG RcvAlignmentErrors;
64128 + ULONG OneCollision;
64129 + ULONG MoreCollisions;
64130 +
64131 +} COUNTER_802_3, *PCOUNTER_802_3;
64132 +
64133 +typedef struct _COUNTER_802_11 {
64134 + ULONG Length;
64135 + LARGE_INTEGER LastTransmittedFragmentCount;
64136 + LARGE_INTEGER TransmittedFragmentCount;
64137 + LARGE_INTEGER MulticastTransmittedFrameCount;
64138 + LARGE_INTEGER FailedCount;
64139 + LARGE_INTEGER RetryCount;
64140 + LARGE_INTEGER MultipleRetryCount;
64141 + LARGE_INTEGER RTSSuccessCount;
64142 + LARGE_INTEGER RTSFailureCount;
64143 + LARGE_INTEGER ACKFailureCount;
64144 + LARGE_INTEGER FrameDuplicateCount;
64145 + LARGE_INTEGER ReceivedFragmentCount;
64146 + LARGE_INTEGER MulticastReceivedFrameCount;
64147 + LARGE_INTEGER FCSErrorCount;
64148 +} COUNTER_802_11, *PCOUNTER_802_11;
64149 +
64150 +typedef struct _COUNTER_RALINK {
64151 + ULONG TransmittedByteCount; // both successful and failure, used to calculate TX throughput
64152 + ULONG ReceivedByteCount; // both CRC okay and CRC error, used to calculate RX throughput
64153 + ULONG BeenDisassociatedCount;
64154 + ULONG BadCQIAutoRecoveryCount;
64155 + ULONG PoorCQIRoamingCount;
64156 + ULONG MgmtRingFullCount;
64157 + ULONG RxCountSinceLastNULL;
64158 + ULONG RxCount;
64159 + ULONG RxRingErrCount;
64160 + ULONG KickTxCount;
64161 + ULONG TxRingErrCount;
64162 + LARGE_INTEGER RealFcsErrCount;
64163 + ULONG PendingNdisPacketCount;
64164 +
64165 + ULONG OneSecOsTxCount[NUM_OF_TX_RING];
64166 + ULONG OneSecDmaDoneCount[NUM_OF_TX_RING];
64167 + UINT32 OneSecTxDoneCount;
64168 + ULONG OneSecRxCount;
64169 + UINT32 OneSecTxAggregationCount;
64170 + UINT32 OneSecRxAggregationCount;
64171 +
64172 + UINT32 OneSecFrameDuplicateCount;
64173 +
64174 +#ifdef RT2870
64175 + ULONG OneSecTransmittedByteCount; // both successful and failure, used to calculate TX throughput
64176 +#endif // RT2870 //
64177 +
64178 + UINT32 OneSecTxNoRetryOkCount;
64179 + UINT32 OneSecTxRetryOkCount;
64180 + UINT32 OneSecTxFailCount;
64181 + UINT32 OneSecFalseCCACnt; // CCA error count, for debug purpose, might move to global counter
64182 + UINT32 OneSecRxOkCnt; // RX without error
64183 + UINT32 OneSecRxOkDataCnt; // unicast-to-me DATA frame count
64184 + UINT32 OneSecRxFcsErrCnt; // CRC error
64185 + UINT32 OneSecBeaconSentCnt;
64186 + UINT32 LastOneSecTotalTxCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
64187 + UINT32 LastOneSecRxOkDataCnt; // OneSecRxOkDataCnt
64188 + ULONG DuplicateRcv;
64189 + ULONG TxAggCount;
64190 + ULONG TxNonAggCount;
64191 + ULONG TxAgg1MPDUCount;
64192 + ULONG TxAgg2MPDUCount;
64193 + ULONG TxAgg3MPDUCount;
64194 + ULONG TxAgg4MPDUCount;
64195 + ULONG TxAgg5MPDUCount;
64196 + ULONG TxAgg6MPDUCount;
64197 + ULONG TxAgg7MPDUCount;
64198 + ULONG TxAgg8MPDUCount;
64199 + ULONG TxAgg9MPDUCount;
64200 + ULONG TxAgg10MPDUCount;
64201 + ULONG TxAgg11MPDUCount;
64202 + ULONG TxAgg12MPDUCount;
64203 + ULONG TxAgg13MPDUCount;
64204 + ULONG TxAgg14MPDUCount;
64205 + ULONG TxAgg15MPDUCount;
64206 + ULONG TxAgg16MPDUCount;
64207 +
64208 + LARGE_INTEGER TransmittedOctetsInAMSDU;
64209 + LARGE_INTEGER TransmittedAMSDUCount;
64210 + LARGE_INTEGER ReceivedOctesInAMSDUCount;
64211 + LARGE_INTEGER ReceivedAMSDUCount;
64212 + LARGE_INTEGER TransmittedAMPDUCount;
64213 + LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
64214 + LARGE_INTEGER TransmittedOctetsInAMPDUCount;
64215 + LARGE_INTEGER MPDUInReceivedAMPDUCount;
64216 +} COUNTER_RALINK, *PCOUNTER_RALINK;
64217 +
64218 +typedef struct _PID_COUNTER {
64219 + ULONG TxAckRequiredCount; // CRC error
64220 + ULONG TxAggreCount;
64221 + ULONG TxSuccessCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
64222 + ULONG LastSuccessRate;
64223 +} PID_COUNTER, *PPID_COUNTER;
64224 +
64225 +typedef struct _COUNTER_DRS {
64226 + // to record the each TX rate's quality. 0 is best, the bigger the worse.
64227 + USHORT TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
64228 + UCHAR PER[MAX_STEP_OF_TX_RATE_SWITCH];
64229 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
64230 + ULONG CurrTxRateStableTime; // # of second in current TX rate
64231 + BOOLEAN fNoisyEnvironment;
64232 + BOOLEAN fLastSecAccordingRSSI;
64233 + UCHAR LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
64234 + UCHAR LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
64235 + ULONG LastTxOkCount;
64236 +} COUNTER_DRS, *PCOUNTER_DRS;
64237 +
64238 +//
64239 +// Arcfour Structure Added by PaulWu
64240 +//
64241 +typedef struct _ARCFOUR
64242 +{
64243 + UINT X;
64244 + UINT Y;
64245 + UCHAR STATE[256];
64246 +} ARCFOURCONTEXT, *PARCFOURCONTEXT;
64247 +
64248 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI too. just copy to TXWI.
64249 +typedef struct _RECEIVE_SETTING {
64250 +#ifdef RT_BIG_ENDIAN
64251 + USHORT MIMO:1;
64252 + USHORT OFDM:1;
64253 + USHORT rsv:3;
64254 + USHORT STBC:2; //SPACE
64255 + USHORT ShortGI:1;
64256 + USHORT Mode:2; //channel bandwidth 20MHz or 40 MHz
64257 + USHORT NumOfRX:2; // MIMO. WE HAVE 3R
64258 +#else
64259 + USHORT NumOfRX:2; // MIMO. WE HAVE 3R
64260 + USHORT Mode:2; //channel bandwidth 20MHz or 40 MHz
64261 + USHORT ShortGI:1;
64262 + USHORT STBC:2; //SPACE
64263 + USHORT rsv:3;
64264 + USHORT OFDM:1;
64265 + USHORT MIMO:1;
64266 +#endif
64267 + } RECEIVE_SETTING, *PRECEIVE_SETTING;
64268 +
64269 +// Shared key data structure
64270 +typedef struct _WEP_KEY {
64271 + UCHAR KeyLen; // Key length for each key, 0: entry is invalid
64272 + UCHAR Key[MAX_LEN_OF_KEY]; // right now we implement 4 keys, 128 bits max
64273 +} WEP_KEY, *PWEP_KEY;
64274 +
64275 +typedef struct _CIPHER_KEY {
64276 + UCHAR Key[16]; // right now we implement 4 keys, 128 bits max
64277 + UCHAR RxMic[8]; // make alignment
64278 + UCHAR TxMic[8];
64279 + UCHAR TxTsc[6]; // 48bit TSC value
64280 + UCHAR RxTsc[6]; // 48bit TSC value
64281 + UCHAR CipherAlg; // 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128
64282 + UCHAR KeyLen;
64283 +#ifdef CONFIG_STA_SUPPORT
64284 + UCHAR BssId[6];
64285 +#endif // CONFIG_STA_SUPPORT //
64286 + // Key length for each key, 0: entry is invalid
64287 + UCHAR Type; // Indicate Pairwise/Group when reporting MIC error
64288 +} CIPHER_KEY, *PCIPHER_KEY;
64289 +
64290 +typedef struct _BBP_TUNING_STRUCT {
64291 + BOOLEAN Enable;
64292 + UCHAR FalseCcaCountUpperBound; // 100 per sec
64293 + UCHAR FalseCcaCountLowerBound; // 10 per sec
64294 + UCHAR R17LowerBound; // specified in E2PROM
64295 + UCHAR R17UpperBound; // 0x68 according to David Tung
64296 + UCHAR CurrentR17Value;
64297 +} BBP_TUNING, *PBBP_TUNING;
64298 +
64299 +typedef struct _SOFT_RX_ANT_DIVERSITY_STRUCT {
64300 + UCHAR EvaluatePeriod; // 0:not evalute status, 1: evaluate status, 2: switching status
64301 + UCHAR Pair1PrimaryRxAnt; // 0:Ant-E1, 1:Ant-E2
64302 + UCHAR Pair1SecondaryRxAnt; // 0:Ant-E1, 1:Ant-E2
64303 + UCHAR Pair2PrimaryRxAnt; // 0:Ant-E3, 1:Ant-E4
64304 + UCHAR Pair2SecondaryRxAnt; // 0:Ant-E3, 1:Ant-E4
64305 + SHORT Pair1AvgRssi[2]; // AvgRssi[0]:E1, AvgRssi[1]:E2
64306 + SHORT Pair2AvgRssi[2]; // AvgRssi[0]:E3, AvgRssi[1]:E4
64307 + SHORT Pair1LastAvgRssi; //
64308 + SHORT Pair2LastAvgRssi; //
64309 + ULONG RcvPktNumWhenEvaluate;
64310 + BOOLEAN FirstPktArrivedWhenEvaluate;
64311 + RALINK_TIMER_STRUCT RxAntDiversityTimer;
64312 +} SOFT_RX_ANT_DIVERSITY, *PSOFT_RX_ANT_DIVERSITY;
64313 +
64314 +typedef struct _LEAP_AUTH_INFO {
64315 + BOOLEAN Enabled; //Ture: Enable LEAP Authentication
64316 + BOOLEAN CCKM; //Ture: Use Fast Reauthentication with CCKM
64317 + UCHAR Reserve[2];
64318 + UCHAR UserName[256]; //LEAP, User name
64319 + ULONG UserNameLen;
64320 + UCHAR Password[256]; //LEAP, User Password
64321 + ULONG PasswordLen;
64322 +} LEAP_AUTH_INFO, *PLEAP_AUTH_INFO;
64323 +
64324 +typedef struct {
64325 + UCHAR Addr[MAC_ADDR_LEN];
64326 + UCHAR ErrorCode[2]; //00 01-Invalid authentication type
64327 + //00 02-Authentication timeout
64328 + //00 03-Challenge from AP failed
64329 + //00 04-Challenge to AP failed
64330 + BOOLEAN Reported;
64331 +} ROGUEAP_ENTRY, *PROGUEAP_ENTRY;
64332 +
64333 +typedef struct {
64334 + UCHAR RogueApNr;
64335 + ROGUEAP_ENTRY RogueApEntry[MAX_LEN_OF_BSS_TABLE];
64336 +} ROGUEAP_TABLE, *PROGUEAP_TABLE;
64337 +
64338 +typedef struct {
64339 + BOOLEAN Enable;
64340 + UCHAR Delta;
64341 + BOOLEAN PlusSign;
64342 +} CCK_TX_POWER_CALIBRATE, *PCCK_TX_POWER_CALIBRATE;
64343 +
64344 +//
64345 +// Receive Tuple Cache Format
64346 +//
64347 +typedef struct _TUPLE_CACHE {
64348 + BOOLEAN Valid;
64349 + UCHAR MacAddress[MAC_ADDR_LEN];
64350 + USHORT Sequence;
64351 + USHORT Frag;
64352 +} TUPLE_CACHE, *PTUPLE_CACHE;
64353 +
64354 +//
64355 +// Fragment Frame structure
64356 +//
64357 +typedef struct _FRAGMENT_FRAME {
64358 + PNDIS_PACKET pFragPacket;
64359 + ULONG RxSize;
64360 + USHORT Sequence;
64361 + USHORT LastFrag;
64362 + ULONG Flags; // Some extra frame information. bit 0: LLC presented
64363 +} FRAGMENT_FRAME, *PFRAGMENT_FRAME;
64364 +
64365 +
64366 +//
64367 +// Packet information for NdisQueryPacket
64368 +//
64369 +typedef struct _PACKET_INFO {
64370 + UINT PhysicalBufferCount; // Physical breaks of buffer descripor chained
64371 + UINT BufferCount ; // Number of Buffer descriptor chained
64372 + UINT TotalPacketLength ; // Self explained
64373 + PNDIS_BUFFER pFirstBuffer; // Pointer to first buffer descriptor
64374 +} PACKET_INFO, *PPACKET_INFO;
64375 +
64376 +//
64377 +// Tkip Key structure which RC4 key & MIC calculation
64378 +//
64379 +typedef struct _TKIP_KEY_INFO {
64380 + UINT nBytesInM; // # bytes in M for MICKEY
64381 + ULONG IV16;
64382 + ULONG IV32;
64383 + ULONG K0; // for MICKEY Low
64384 + ULONG K1; // for MICKEY Hig
64385 + ULONG L; // Current state for MICKEY
64386 + ULONG R; // Current state for MICKEY
64387 + ULONG M; // Message accumulator for MICKEY
64388 + UCHAR RC4KEY[16];
64389 + UCHAR MIC[8];
64390 +} TKIP_KEY_INFO, *PTKIP_KEY_INFO;
64391 +
64392 +//
64393 +// Private / Misc data, counters for driver internal use
64394 +//
64395 +typedef struct __PRIVATE_STRUC {
64396 + UINT SystemResetCnt; // System reset counter
64397 + UINT TxRingFullCnt; // Tx ring full occurrance number
64398 + UINT PhyRxErrCnt; // PHY Rx error count, for debug purpose, might move to global counter
64399 + // Variables for WEP encryption / decryption in rtmp_wep.c
64400 + UINT FCSCRC32;
64401 + ARCFOURCONTEXT WEPCONTEXT;
64402 + // Tkip stuff
64403 + TKIP_KEY_INFO Tx;
64404 + TKIP_KEY_INFO Rx;
64405 +} PRIVATE_STRUC, *PPRIVATE_STRUC;
64406 +
64407 +// structure to tune BBP R66 (BBP TUNING)
64408 +typedef struct _BBP_R66_TUNING {
64409 + BOOLEAN bEnable;
64410 + USHORT FalseCcaLowerThreshold; // default 100
64411 + USHORT FalseCcaUpperThreshold; // default 512
64412 + UCHAR R66Delta;
64413 + UCHAR R66CurrentValue;
64414 + BOOLEAN R66LowerUpperSelect; //Before LinkUp, Used LowerBound or UpperBound as R66 value.
64415 +} BBP_R66_TUNING, *PBBP_R66_TUNING;
64416 +
64417 +// structure to store channel TX power
64418 +typedef struct _CHANNEL_TX_POWER {
64419 + USHORT RemainingTimeForUse; //unit: sec
64420 + UCHAR Channel;
64421 +#ifdef DOT11N_DRAFT3
64422 + BOOLEAN bEffectedChannel; // For BW 40 operating in 2.4GHz , the "effected channel" is the channel that is covered in 40Mhz.
64423 +#endif // DOT11N_DRAFT3 //
64424 + CHAR Power;
64425 + CHAR Power2;
64426 + UCHAR MaxTxPwr;
64427 + UCHAR DfsReq;
64428 +} CHANNEL_TX_POWER, *PCHANNEL_TX_POWER;
64429 +
64430 +// structure to store 802.11j channel TX power
64431 +typedef struct _CHANNEL_11J_TX_POWER {
64432 + UCHAR Channel;
64433 + UCHAR BW; // BW_10 or BW_20
64434 + CHAR Power;
64435 + CHAR Power2;
64436 + USHORT RemainingTimeForUse; //unit: sec
64437 +} CHANNEL_11J_TX_POWER, *PCHANNEL_11J_TX_POWER;
64438 +
64439 +typedef enum _ABGBAND_STATE_ {
64440 + UNKNOWN_BAND,
64441 + BG_BAND,
64442 + A_BAND,
64443 +} ABGBAND_STATE;
64444 +
64445 +typedef struct _MLME_STRUCT {
64446 +#ifdef CONFIG_STA_SUPPORT
64447 + // STA state machines
64448 + STATE_MACHINE CntlMachine;
64449 + STATE_MACHINE AssocMachine;
64450 + STATE_MACHINE AuthMachine;
64451 + STATE_MACHINE AuthRspMachine;
64452 + STATE_MACHINE SyncMachine;
64453 + STATE_MACHINE WpaPskMachine;
64454 + STATE_MACHINE LeapMachine;
64455 + STATE_MACHINE AironetMachine;
64456 + STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
64457 + STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
64458 + STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
64459 + STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
64460 + STATE_MACHINE_FUNC WpaPskFunc[WPA_PSK_FUNC_SIZE];
64461 + STATE_MACHINE_FUNC AironetFunc[AIRONET_FUNC_SIZE];
64462 +#endif // CONFIG_STA_SUPPORT //
64463 + STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
64464 + // Action
64465 + STATE_MACHINE ActMachine;
64466 +
64467 +
64468 +#ifdef QOS_DLS_SUPPORT
64469 + STATE_MACHINE DlsMachine;
64470 + STATE_MACHINE_FUNC DlsFunc[DLS_FUNC_SIZE];
64471 +#endif // QOS_DLS_SUPPORT //
64472 +
64473 +
64474 +
64475 +
64476 + ULONG ChannelQuality; // 0..100, Channel Quality Indication for Roaming
64477 + ULONG Now32; // latch the value of NdisGetSystemUpTime()
64478 + ULONG LastSendNULLpsmTime;
64479 +
64480 + BOOLEAN bRunning;
64481 + NDIS_SPIN_LOCK TaskLock;
64482 + MLME_QUEUE Queue;
64483 +
64484 + UINT ShiftReg;
64485 +
64486 + RALINK_TIMER_STRUCT PeriodicTimer;
64487 + RALINK_TIMER_STRUCT APSDPeriodicTimer;
64488 + RALINK_TIMER_STRUCT LinkDownTimer;
64489 + RALINK_TIMER_STRUCT LinkUpTimer;
64490 + ULONG PeriodicRound;
64491 + ULONG OneSecPeriodicRound;
64492 +
64493 + UCHAR RealRxPath;
64494 + BOOLEAN bLowThroughput;
64495 + BOOLEAN bEnableAutoAntennaCheck;
64496 + RALINK_TIMER_STRUCT RxAntEvalTimer;
64497 +
64498 +#ifdef RT2870
64499 + UCHAR CaliBW40RfR24;
64500 + UCHAR CaliBW20RfR24;
64501 +#endif // RT2870 //
64502 +
64503 +} MLME_STRUCT, *PMLME_STRUCT;
64504 +
64505 +// structure for radar detection and channel switch
64506 +typedef struct _RADAR_DETECT_STRUCT {
64507 + //BOOLEAN IEEE80211H; // 0: disable, 1: enable IEEE802.11h
64508 + UCHAR CSCount; //Channel switch counter
64509 + UCHAR CSPeriod; //Channel switch period (beacon count)
64510 + UCHAR RDCount; //Radar detection counter
64511 + UCHAR RDMode; //Radar Detection mode
64512 + UCHAR RDDurRegion; //Radar detection duration region
64513 + UCHAR BBPR16;
64514 + UCHAR BBPR17;
64515 + UCHAR BBPR18;
64516 + UCHAR BBPR21;
64517 + UCHAR BBPR22;
64518 + UCHAR BBPR64;
64519 + ULONG InServiceMonitorCount; // unit: sec
64520 + UINT8 DfsSessionTime;
64521 + BOOLEAN bFastDfs;
64522 + UINT8 ChMovingTime;
64523 + UINT8 LongPulseRadarTh;
64524 +} RADAR_DETECT_STRUCT, *PRADAR_DETECT_STRUCT;
64525 +
64526 +#ifdef CARRIER_DETECTION_SUPPORT
64527 +typedef enum CD_STATE_n
64528 +{
64529 + CD_NORMAL,
64530 + CD_SILENCE,
64531 + CD_MAX_STATE
64532 +} CD_STATE;
64533 +
64534 +typedef struct CARRIER_DETECTION_s
64535 +{
64536 + BOOLEAN Enable;
64537 + UINT8 CDSessionTime;
64538 + UINT8 CDPeriod;
64539 + CD_STATE CD_State;
64540 +} CARRIER_DETECTION, *PCARRIER_DETECTION;
64541 +#endif // CARRIER_DETECTION_SUPPORT //
64542 +
64543 +typedef enum _REC_BLOCKACK_STATUS
64544 +{
64545 + Recipient_NONE=0,
64546 + Recipient_USED,
64547 + Recipient_HandleRes,
64548 + Recipient_Accept
64549 +} REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
64550 +
64551 +typedef enum _ORI_BLOCKACK_STATUS
64552 +{
64553 + Originator_NONE=0,
64554 + Originator_USED,
64555 + Originator_WaitRes,
64556 + Originator_Done
64557 +} ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
64558 +
64559 +#ifdef DOT11_N_SUPPORT
64560 +typedef struct _BA_ORI_ENTRY{
64561 + UCHAR Wcid;
64562 + UCHAR TID;
64563 + UCHAR BAWinSize;
64564 + UCHAR Token;
64565 +// Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header.
64566 + USHORT Sequence;
64567 + USHORT TimeOutValue;
64568 + ORI_BLOCKACK_STATUS ORI_BA_Status;
64569 + RALINK_TIMER_STRUCT ORIBATimer;
64570 + PVOID pAdapter;
64571 +} BA_ORI_ENTRY, *PBA_ORI_ENTRY;
64572 +
64573 +typedef struct _BA_REC_ENTRY {
64574 + UCHAR Wcid;
64575 + UCHAR TID;
64576 + UCHAR BAWinSize; // 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU.
64577 + //UCHAR NumOfRxPkt;
64578 + //UCHAR Curindidx; // the head in the RX reordering buffer
64579 + USHORT LastIndSeq;
64580 +// USHORT LastIndSeqAtTimer;
64581 + USHORT TimeOutValue;
64582 + RALINK_TIMER_STRUCT RECBATimer;
64583 + ULONG LastIndSeqAtTimer;
64584 + ULONG nDropPacket;
64585 + ULONG rcvSeq;
64586 + REC_BLOCKACK_STATUS REC_BA_Status;
64587 +// UCHAR RxBufIdxUsed;
64588 + // corresponding virtual address for RX reordering packet storage.
64589 + //RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF];
64590 + NDIS_SPIN_LOCK RxReRingLock; // Rx Ring spinlock
64591 +// struct _BA_REC_ENTRY *pNext;
64592 + PVOID pAdapter;
64593 + struct reordering_list list;
64594 +} BA_REC_ENTRY, *PBA_REC_ENTRY;
64595 +
64596 +
64597 +typedef struct {
64598 + ULONG numAsRecipient; // I am recipient of numAsRecipient clients. These client are in the BARecEntry[]
64599 + ULONG numAsOriginator; // I am originator of numAsOriginator clients. These clients are in the BAOriEntry[]
64600 + BA_ORI_ENTRY BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
64601 + BA_REC_ENTRY BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
64602 +} BA_TABLE, *PBA_TABLE;
64603 +
64604 +//For QureyBATableOID use;
64605 +typedef struct PACKED _OID_BA_REC_ENTRY{
64606 + UCHAR MACAddr[MAC_ADDR_LEN];
64607 + UCHAR BaBitmap; // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize
64608 + UCHAR rsv;
64609 + UCHAR BufSize[8];
64610 + REC_BLOCKACK_STATUS REC_BA_Status[8];
64611 +} OID_BA_REC_ENTRY, *POID_BA_REC_ENTRY;
64612 +
64613 +//For QureyBATableOID use;
64614 +typedef struct PACKED _OID_BA_ORI_ENTRY{
64615 + UCHAR MACAddr[MAC_ADDR_LEN];
64616 + 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
64617 + UCHAR rsv;
64618 + UCHAR BufSize[8];
64619 + ORI_BLOCKACK_STATUS ORI_BA_Status[8];
64620 +} OID_BA_ORI_ENTRY, *POID_BA_ORI_ENTRY;
64621 +
64622 +typedef struct _QUERYBA_TABLE{
64623 + OID_BA_ORI_ENTRY BAOriEntry[32];
64624 + OID_BA_REC_ENTRY BARecEntry[32];
64625 + UCHAR OriNum;// Number of below BAOriEntry
64626 + UCHAR RecNum;// Number of below BARecEntry
64627 +} QUERYBA_TABLE, *PQUERYBA_TABLE;
64628 +
64629 +typedef union _BACAP_STRUC {
64630 +#ifdef RT_BIG_ENDIAN
64631 + struct {
64632 + UINT32 :4;
64633 + 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.
64634 + UINT32 bHtAdhoc:1; // adhoc can use ht rate.
64635 + UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
64636 + UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
64637 + UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
64638 + UINT32 MpduDensity:3;
64639 + UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
64640 + UINT32 AutoBA:1; // automatically BA
64641 + UINT32 TxBAWinLimit:8;
64642 + UINT32 RxBAWinLimit:8;
64643 + } field;
64644 +#else
64645 + struct {
64646 + UINT32 RxBAWinLimit:8;
64647 + UINT32 TxBAWinLimit:8;
64648 + UINT32 AutoBA:1; // automatically BA
64649 + UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
64650 + UINT32 MpduDensity:3;
64651 + UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
64652 + UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
64653 + UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
64654 + UINT32 bHtAdhoc:1; // adhoc can use ht rate.
64655 + 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.
64656 + UINT32 :4;
64657 + } field;
64658 +#endif
64659 + UINT32 word;
64660 +} BACAP_STRUC, *PBACAP_STRUC;
64661 +#endif // DOT11_N_SUPPORT //
64662 +
64663 +//This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second. (Details see MLMEPeriodic)
64664 +typedef struct _IOT_STRUC {
64665 + UCHAR Threshold[2];
64666 + UCHAR ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[0]
64667 + UCHAR RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[1]
64668 + ULONG OneSecInWindowCount;
64669 + ULONG OneSecFrameDuplicateCount;
64670 + ULONG OneSecOutWindowCount;
64671 + UCHAR DelOriAct;
64672 + UCHAR DelRecAct;
64673 + UCHAR RTSShortProt;
64674 + UCHAR RTSLongProt;
64675 + BOOLEAN bRTSLongProtOn;
64676 +#ifdef CONFIG_STA_SUPPORT
64677 + BOOLEAN bLastAtheros;
64678 + BOOLEAN bCurrentAtheros;
64679 + BOOLEAN bNowAtherosBurstOn;
64680 + BOOLEAN bNextDisableRxBA;
64681 + BOOLEAN bToggle;
64682 +#endif // CONFIG_STA_SUPPORT //
64683 +} IOT_STRUC, *PIOT_STRUC;
64684 +
64685 +// This is the registry setting for 802.11n transmit setting. Used in advanced page.
64686 +typedef union _REG_TRANSMIT_SETTING {
64687 +#ifdef RT_BIG_ENDIAN
64688 + struct {
64689 + UINT32 rsv:13;
64690 + UINT32 EXTCHA:2;
64691 + UINT32 HTMODE:1;
64692 + UINT32 TRANSNO:2;
64693 + UINT32 STBC:1; //SPACE
64694 + UINT32 ShortGI:1;
64695 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
64696 + UINT32 TxBF:1; // 3*3
64697 + UINT32 rsv0:10;
64698 + //UINT32 MCS:7; // MCS
64699 + //UINT32 PhyMode:4;
64700 + } field;
64701 +#else
64702 + struct {
64703 + //UINT32 PhyMode:4;
64704 + //UINT32 MCS:7; // MCS
64705 + UINT32 rsv0:10;
64706 + UINT32 TxBF:1;
64707 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
64708 + UINT32 ShortGI:1;
64709 + UINT32 STBC:1; //SPACE
64710 + UINT32 TRANSNO:2;
64711 + UINT32 HTMODE:1;
64712 + UINT32 EXTCHA:2;
64713 + UINT32 rsv:13;
64714 + } field;
64715 +#endif
64716 + UINT32 word;
64717 +} REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
64718 +
64719 +typedef union _DESIRED_TRANSMIT_SETTING {
64720 +#ifdef RT_BIG_ENDIAN
64721 + struct {
64722 + USHORT rsv:3;
64723 + USHORT FixedTxMode:2; // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
64724 + USHORT PhyMode:4;
64725 + USHORT MCS:7; // MCS
64726 + } field;
64727 +#else
64728 + struct {
64729 + USHORT MCS:7; // MCS
64730 + USHORT PhyMode:4;
64731 + USHORT FixedTxMode:2; // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
64732 + USHORT rsv:3;
64733 + } field;
64734 +#endif
64735 + USHORT word;
64736 + } DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
64737 +
64738 +typedef struct {
64739 + BOOLEAN IsRecipient;
64740 + UCHAR MACAddr[MAC_ADDR_LEN];
64741 + UCHAR TID;
64742 + UCHAR nMSDU;
64743 + USHORT TimeOut;
64744 + BOOLEAN bAllTid; // If True, delete all TID for BA sessions with this MACaddr.
64745 +} OID_ADD_BA_ENTRY, *POID_ADD_BA_ENTRY;
64746 +
64747 +//
64748 +// Multiple SSID structure
64749 +//
64750 +#define WLAN_MAX_NUM_OF_TIM ((MAX_LEN_OF_MAC_TABLE >> 3) + 1) /* /8 + 1 */
64751 +#define WLAN_CT_TIM_BCMC_OFFSET 0 /* unit: 32B */
64752 +
64753 +/* clear bcmc TIM bit */
64754 +#define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
64755 + pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
64756 +
64757 +/* set bcmc TIM bit */
64758 +#define WLAN_MR_TIM_BCMC_SET(apidx) \
64759 + pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
64760 +
64761 +/* clear a station PS TIM bit */
64762 +#define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
64763 + { UCHAR tim_offset = wcid >> 3; \
64764 + UCHAR bit_offset = wcid & 0x7; \
64765 + ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
64766 +
64767 +/* set a station PS TIM bit */
64768 +#define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
64769 + { UCHAR tim_offset = wcid >> 3; \
64770 + UCHAR bit_offset = wcid & 0x7; \
64771 + ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
64772 +
64773 +#ifdef RT2870
64774 +#define BEACON_BITMAP_MASK 0xff
64775 +typedef struct _BEACON_SYNC_STRUCT_
64776 +{
64777 + UCHAR BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET];
64778 + UCHAR BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE];
64779 + ULONG TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
64780 + ULONG CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
64781 + BOOLEAN EnableBeacon; // trigger to enable beacon transmission.
64782 + UCHAR BeaconBitMap; // NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change.
64783 + UCHAR DtimBitOn; // NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change.
64784 +}BEACON_SYNC_STRUCT;
64785 +#endif // RT2870 //
64786 +
64787 +typedef struct _MULTISSID_STRUCT {
64788 + UCHAR Bssid[MAC_ADDR_LEN];
64789 + UCHAR SsidLen;
64790 + CHAR Ssid[MAX_LEN_OF_SSID];
64791 + USHORT CapabilityInfo;
64792 +
64793 + PNET_DEV MSSIDDev;
64794 +
64795 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
64796 + NDIS_802_11_WEP_STATUS WepStatus;
64797 + NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
64798 + WPA_MIX_PAIR_CIPHER WpaMixPairCipher;
64799 +
64800 + ULONG TxCount;
64801 + ULONG RxCount;
64802 + ULONG ReceivedByteCount;
64803 + ULONG TransmittedByteCount;
64804 + ULONG RxErrorCount;
64805 + ULONG RxDropCount;
64806 +
64807 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
64808 + RT_HT_PHY_INFO DesiredHtPhyInfo;
64809 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting. this is for reading registry setting only. not useful.
64810 + BOOLEAN bAutoTxRateSwitch;
64811 +
64812 + //CIPHER_KEY SharedKey[SHARE_KEY_NUM]; // ref pAd->SharedKey[BSS][4]
64813 + UCHAR DefaultKeyId;
64814 +
64815 + UCHAR TxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11, ...
64816 + UCHAR DesiredRates[MAX_LEN_OF_SUPPORTED_RATES];// OID_802_11_DESIRED_RATES
64817 + UCHAR DesiredRatesIndex;
64818 + UCHAR MaxTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
64819 +
64820 +// ULONG TimBitmap; // bit0 for broadcast, 1 for AID1, 2 for AID2, ...so on
64821 +// ULONG TimBitmap2; // b0 for AID32, b1 for AID33, ... and so on
64822 + UCHAR TimBitmaps[WLAN_MAX_NUM_OF_TIM];
64823 +
64824 + // WPA
64825 + UCHAR GMK[32];
64826 + UCHAR PMK[32];
64827 + UCHAR GTK[32];
64828 + BOOLEAN IEEE8021X;
64829 + BOOLEAN PreAuth;
64830 + UCHAR GNonce[32];
64831 + UCHAR PortSecured;
64832 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter;
64833 + UCHAR BANClass3Data;
64834 + ULONG IsolateInterStaTraffic;
64835 +
64836 + UCHAR RSNIE_Len[2];
64837 + UCHAR RSN_IE[2][MAX_LEN_OF_RSNIE];
64838 +
64839 +
64840 + UCHAR TimIELocationInBeacon;
64841 + UCHAR CapabilityInfoLocationInBeacon;
64842 + // outgoing BEACON frame buffer and corresponding TXWI
64843 + // PTXWI_STRUC BeaconTxWI; //
64844 + CHAR BeaconBuf[MAX_BEACON_SIZE]; // NOTE: BeaconBuf should be 4-byte aligned
64845 +
64846 + BOOLEAN bHideSsid;
64847 + UINT16 StationKeepAliveTime; // unit: second
64848 +
64849 + USHORT VLAN_VID;
64850 + USHORT VLAN_Priority;
64851 +
64852 + RT_802_11_ACL AccessControlList;
64853 +
64854 + // EDCA Qos
64855 + BOOLEAN bWmmCapable; // 0:disable WMM, 1:enable WMM
64856 + BOOLEAN bDLSCapable; // 0:disable DLS, 1:enable DLS
64857 +
64858 + UCHAR DlsPTK[64]; // Due to windows dirver count on meetinghouse to handle 4-way shake
64859 +
64860 + // For 802.1x daemon setting per BSS
64861 + UCHAR radius_srv_num;
64862 + RADIUS_SRV_INFO radius_srv_info[MAX_RADIUS_SRV_NUM];
64863 +
64864 +#ifdef RTL865X_SOC
64865 + unsigned int mylinkid;
64866 +#endif
64867 +
64868 +
64869 + UINT32 RcvdConflictSsidCount;
64870 + UINT32 RcvdSpoofedAssocRespCount;
64871 + UINT32 RcvdSpoofedReassocRespCount;
64872 + UINT32 RcvdSpoofedProbeRespCount;
64873 + UINT32 RcvdSpoofedBeaconCount;
64874 + UINT32 RcvdSpoofedDisassocCount;
64875 + UINT32 RcvdSpoofedAuthCount;
64876 + UINT32 RcvdSpoofedDeauthCount;
64877 + UINT32 RcvdSpoofedUnknownMgmtCount;
64878 + UINT32 RcvdReplayAttackCount;
64879 +
64880 + CHAR RssiOfRcvdConflictSsid;
64881 + CHAR RssiOfRcvdSpoofedAssocResp;
64882 + CHAR RssiOfRcvdSpoofedReassocResp;
64883 + CHAR RssiOfRcvdSpoofedProbeResp;
64884 + CHAR RssiOfRcvdSpoofedBeacon;
64885 + CHAR RssiOfRcvdSpoofedDisassoc;
64886 + CHAR RssiOfRcvdSpoofedAuth;
64887 + CHAR RssiOfRcvdSpoofedDeauth;
64888 + CHAR RssiOfRcvdSpoofedUnknownMgmt;
64889 + CHAR RssiOfRcvdReplayAttack;
64890 +
64891 + BOOLEAN bBcnSntReq;
64892 + UCHAR BcnBufIdx;
64893 +} MULTISSID_STRUCT, *PMULTISSID_STRUCT;
64894 +
64895 +
64896 +
64897 +#ifdef DOT11N_DRAFT3
64898 +typedef enum _BSS2040COEXIST_FLAG{
64899 + BSS_2040_COEXIST_DISABLE = 0,
64900 + BSS_2040_COEXIST_TIMER_FIRED = 1,
64901 + BSS_2040_COEXIST_INFO_SYNC = 2,
64902 + BSS_2040_COEXIST_INFO_NOTIFY = 4,
64903 +}BSS2040COEXIST_FLAG;
64904 +#endif // DOT11N_DRAFT3 //
64905 +
64906 +// configuration common to OPMODE_AP as well as OPMODE_STA
64907 +typedef struct _COMMON_CONFIG {
64908 +
64909 + BOOLEAN bCountryFlag;
64910 + UCHAR CountryCode[3];
64911 + UCHAR Geography;
64912 + UCHAR CountryRegion; // Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel
64913 + UCHAR CountryRegionForABand; // Enum of country region for A band
64914 + UCHAR PhyMode; // PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED
64915 + USHORT Dsifs; // in units of usec
64916 + ULONG PacketFilter; // Packet filter for receiving
64917 +
64918 + CHAR Ssid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
64919 + UCHAR SsidLen; // the actual ssid length in used
64920 + UCHAR LastSsidLen; // the actual ssid length in used
64921 + CHAR LastSsid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
64922 + UCHAR LastBssid[MAC_ADDR_LEN];
64923 +
64924 + UCHAR Bssid[MAC_ADDR_LEN];
64925 + USHORT BeaconPeriod;
64926 + UCHAR Channel;
64927 + UCHAR CentralChannel; // Central Channel when using 40MHz is indicating. not real channel.
64928 +
64929 +#if 0 // move to STA_ADMIN_CONFIG
64930 + UCHAR DefaultKeyId;
64931 +
64932 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter; // PrivacyFilter enum for 802.1X
64933 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
64934 + NDIS_802_11_WEP_STATUS WepStatus;
64935 + NDIS_802_11_WEP_STATUS OrigWepStatus; // Original wep status set from OID
64936 +
64937 + // Add to support different cipher suite for WPA2/WPA mode
64938 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Multicast cipher suite
64939 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher suite
64940 + BOOLEAN bMixCipher; // Indicate current Pair & Group use different cipher suites
64941 + USHORT RsnCapability;
64942 +
64943 + NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
64944 +#endif
64945 +
64946 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
64947 + UCHAR SupRateLen;
64948 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
64949 + UCHAR ExtRateLen;
64950 + UCHAR DesireRate[MAX_LEN_OF_SUPPORTED_RATES]; // OID_802_11_DESIRED_RATES
64951 + UCHAR MaxDesiredRate;
64952 + UCHAR ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
64953 +
64954 + ULONG BasicRateBitmap; // backup basic ratebitmap
64955 +
64956 + BOOLEAN bAPSDCapable;
64957 + BOOLEAN bInServicePeriod;
64958 + BOOLEAN bAPSDAC_BE;
64959 + BOOLEAN bAPSDAC_BK;
64960 + BOOLEAN bAPSDAC_VI;
64961 + BOOLEAN bAPSDAC_VO;
64962 + BOOLEAN bNeedSendTriggerFrame;
64963 + BOOLEAN bAPSDForcePowerSave; // Force power save mode, should only use in APSD-STAUT
64964 + ULONG TriggerTimerCount;
64965 + UCHAR MaxSPLength;
64966 + UCHAR BBPCurrentBW; // BW_10, BW_20, BW_40
64967 + // move to MULTISSID_STRUCT for MBSS
64968 + //HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
64969 + REG_TRANSMIT_SETTING RegTransmitSetting; //registry transmit setting. this is for reading registry setting only. not useful.
64970 + //UCHAR FixedTxMode; // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode
64971 + UCHAR TxRate; // Same value to fill in TXD. TxRate is 6-bit
64972 + UCHAR MaxTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
64973 + UCHAR TxRateIndex; // Tx rate index in RateSwitchTable
64974 + UCHAR TxRateTableSize; // Valid Tx rate table size in RateSwitchTable
64975 + //BOOLEAN bAutoTxRateSwitch;
64976 + UCHAR MinTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
64977 + UCHAR RtsRate; // RATE_xxx
64978 + HTTRANSMIT_SETTING MlmeTransmit; // MGMT frame PHY rate setting when operatin at Ht rate.
64979 + UCHAR MlmeRate; // RATE_xxx, used to send MLME frames
64980 + UCHAR BasicMlmeRate; // Default Rate for sending MLME frames
64981 +
64982 + USHORT RtsThreshold; // in unit of BYTE
64983 + USHORT FragmentThreshold; // in unit of BYTE
64984 +
64985 + UCHAR TxPower; // in unit of mW
64986 + ULONG TxPowerPercentage; // 0~100 %
64987 + ULONG TxPowerDefault; // keep for TxPowerPercentage
64988 +
64989 +#ifdef DOT11_N_SUPPORT
64990 + BACAP_STRUC BACapability; // NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0
64991 + BACAP_STRUC REGBACapability; // NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0
64992 +#endif // DOT11_N_SUPPORT //
64993 + IOT_STRUC IOTestParm; // 802.11n InterOpbility Test Parameter;
64994 + ULONG TxPreamble; // Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto
64995 + BOOLEAN bUseZeroToDisableFragment; // Microsoft use 0 as disable
64996 + ULONG UseBGProtection; // 0: auto, 1: always use, 2: always not use
64997 + BOOLEAN bUseShortSlotTime; // 0: disable, 1 - use short slot (9us)
64998 + BOOLEAN bEnableTxBurst; // 1: enble TX PACKET BURST, 0: disable TX PACKET BURST
64999 + BOOLEAN bAggregationCapable; // 1: enable TX aggregation when the peer supports it
65000 + BOOLEAN bPiggyBackCapable; // 1: enable TX piggy-back according MAC's version
65001 + BOOLEAN bIEEE80211H; // 1: enable IEEE802.11h spec.
65002 + ULONG DisableOLBCDetect; // 0: enable OLBC detect; 1 disable OLBC detect
65003 +
65004 +#ifdef DOT11_N_SUPPORT
65005 + BOOLEAN bRdg;
65006 +#endif // DOT11_N_SUPPORT //
65007 + BOOLEAN bWmmCapable; // 0:disable WMM, 1:enable WMM
65008 + QOS_CAPABILITY_PARM APQosCapability; // QOS capability of the current associated AP
65009 + EDCA_PARM APEdcaParm; // EDCA parameters of the current associated AP
65010 + QBSS_LOAD_PARM APQbssLoad; // QBSS load of the current associated AP
65011 + UCHAR AckPolicy[4]; // ACK policy of the specified AC. see ACK_xxx
65012 +#ifdef CONFIG_STA_SUPPORT
65013 + BOOLEAN bDLSCapable; // 0:disable DLS, 1:enable DLS
65014 +#endif // CONFIG_STA_SUPPORT //
65015 + // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
65016 + // BOOLEAN control, either ON or OFF. These flags should always be accessed via
65017 + // OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros.
65018 + // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition
65019 + ULONG OpStatusFlags;
65020 +
65021 + BOOLEAN NdisRadioStateOff; //For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff.
65022 + ABGBAND_STATE BandState; // For setting BBP used on B/G or A mode.
65023 +
65024 + // IEEE802.11H--DFS.
65025 + RADAR_DETECT_STRUCT RadarDetect;
65026 +
65027 +#ifdef CARRIER_DETECTION_SUPPORT
65028 + CARRIER_DETECTION CarrierDetect;
65029 +#endif // CARRIER_DETECTION_SUPPORT //
65030 +
65031 +#ifdef DOT11_N_SUPPORT
65032 + // HT
65033 + UCHAR BASize; // USer desired BAWindowSize. Should not exceed our max capability
65034 + //RT_HT_CAPABILITY SupportedHtPhy;
65035 + RT_HT_CAPABILITY DesiredHtPhy;
65036 + HT_CAPABILITY_IE HtCapability;
65037 + ADD_HT_INFO_IE AddHTInfo; // Useful as AP.
65038 + //This IE is used with channel switch announcement element when changing to a new 40MHz.
65039 + //This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp.
65040 + 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
65041 +
65042 +#ifdef DOT11N_DRAFT3
65043 + UCHAR Bss2040CoexistFlag; // bit 0: bBssCoexistTimerRunning, bit 1: NeedSyncAddHtInfo.
65044 + RALINK_TIMER_STRUCT Bss2040CoexistTimer;
65045 +
65046 + //This IE is used for 20/40 BSS Coexistence.
65047 + BSS_2040_COEXIST_IE BSS2040CoexistInfo;
65048 + // ====== 11n D3.0 =======================>
65049 + USHORT Dot11OBssScanPassiveDwell; // Unit : TU. 5~1000
65050 + USHORT Dot11OBssScanActiveDwell; // Unit : TU. 10~1000
65051 + USHORT Dot11BssWidthTriggerScanInt; // Unit : Second
65052 + USHORT Dot11OBssScanPassiveTotalPerChannel; // Unit : TU. 200~10000
65053 + USHORT Dot11OBssScanActiveTotalPerChannel; // Unit : TU. 20~10000
65054 + USHORT Dot11BssWidthChanTranDelayFactor;
65055 + USHORT Dot11OBssScanActivityThre; // Unit : percentage
65056 +
65057 + ULONG Dot11BssWidthChanTranDelay; // multiple of (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
65058 + ULONG CountDownCtr; // CountDown Counter from (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
65059 +
65060 + NDIS_SPIN_LOCK TriggerEventTabLock;
65061 + BSS_2040_COEXIST_IE LastBSSCoexist2040;
65062 + BSS_2040_COEXIST_IE BSSCoexist2040;
65063 + TRIGGER_EVENT_TAB TriggerEventTab;
65064 + UCHAR ChannelListIdx;
65065 + // <====== 11n D3.0 =======================
65066 + BOOLEAN bOverlapScanning;
65067 +#endif // DOT11N_DRAFT3 //
65068 +
65069 + BOOLEAN bHTProtect;
65070 + BOOLEAN bMIMOPSEnable;
65071 + BOOLEAN bBADecline;
65072 + BOOLEAN bDisableReordering;
65073 + BOOLEAN bForty_Mhz_Intolerant;
65074 + BOOLEAN bExtChannelSwitchAnnouncement;
65075 + BOOLEAN bRcvBSSWidthTriggerEvents;
65076 + ULONG LastRcvBSSWidthTriggerEventsTime;
65077 +
65078 + UCHAR TxBASize;
65079 +#endif // DOT11_N_SUPPORT //
65080 +
65081 + // Enable wireless event
65082 + BOOLEAN bWirelessEvent;
65083 + BOOLEAN bWiFiTest; // Enable this parameter for WiFi test
65084 +
65085 + // Tx & Rx Stream number selection
65086 + UCHAR TxStream;
65087 + UCHAR RxStream;
65088 +
65089 + // transmit phy mode, trasmit rate for Multicast.
65090 +#ifdef MCAST_RATE_SPECIFIC
65091 + UCHAR McastTransmitMcs;
65092 + UCHAR McastTransmitPhyMode;
65093 +#endif // MCAST_RATE_SPECIFIC //
65094 +
65095 + BOOLEAN bHardwareRadio; // Hardware controlled Radio enabled
65096 +
65097 +#ifdef RT2870
65098 + BOOLEAN bMultipleIRP; // Multiple Bulk IN flag
65099 + UCHAR NumOfBulkInIRP; // if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1
65100 + RT_HT_CAPABILITY SupportedHtPhy;
65101 + ULONG MaxPktOneTxBulk;
65102 + UCHAR TxBulkFactor;
65103 + UCHAR RxBulkFactor;
65104 +
65105 + BEACON_SYNC_STRUCT *pBeaconSync;
65106 + RALINK_TIMER_STRUCT BeaconUpdateTimer;
65107 + UINT32 BeaconAdjust;
65108 + UINT32 BeaconFactor;
65109 + UINT32 BeaconRemain;
65110 +#endif // RT2870 //
65111 +
65112 +
65113 + NDIS_SPIN_LOCK MeasureReqTabLock;
65114 + PMEASURE_REQ_TAB pMeasureReqTab;
65115 +
65116 + NDIS_SPIN_LOCK TpcReqTabLock;
65117 + PTPC_REQ_TAB pTpcReqTab;
65118 +
65119 + // transmit phy mode, trasmit rate for Multicast.
65120 +#ifdef MCAST_RATE_SPECIFIC
65121 + HTTRANSMIT_SETTING MCastPhyMode;
65122 +#endif // MCAST_RATE_SPECIFIC //
65123 +
65124 +#ifdef SINGLE_SKU
65125 + UINT16 DefineMaxTxPwr;
65126 +#endif // SINGLE_SKU //
65127 +
65128 +
65129 +} COMMON_CONFIG, *PCOMMON_CONFIG;
65130 +
65131 +
65132 +#ifdef CONFIG_STA_SUPPORT
65133 +/* Modified by Wu Xi-Kun 4/21/2006 */
65134 +// STA configuration and status
65135 +typedef struct _STA_ADMIN_CONFIG {
65136 + // GROUP 1 -
65137 + // User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
65138 + // the user intended configuration, but not necessary fully equal to the final
65139 + // settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either
65140 + // AP or IBSS holder).
65141 + // Once initialized, user configuration can only be changed via OID_xxx
65142 + UCHAR BssType; // BSS_INFRA or BSS_ADHOC
65143 + USHORT AtimWin; // used when starting a new IBSS
65144 +
65145 + // GROUP 2 -
65146 + // User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
65147 + // the user intended configuration, and should be always applied to the final
65148 + // settings in ACTIVE BSS without compromising with the BSS holder.
65149 + // Once initialized, user configuration can only be changed via OID_xxx
65150 + UCHAR RssiTrigger;
65151 + UCHAR RssiTriggerMode; // RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD
65152 + USHORT DefaultListenCount; // default listen count;
65153 + ULONG WindowsPowerMode; // Power mode for AC power
65154 + ULONG WindowsBatteryPowerMode; // Power mode for battery if exists
65155 + BOOLEAN bWindowsACCAMEnable; // Enable CAM power mode when AC on
65156 + BOOLEAN bAutoReconnect; // Set to TRUE when setting OID_802_11_SSID with no matching BSSID
65157 + ULONG WindowsPowerProfile; // Windows power profile, for NDIS5.1 PnP
65158 +
65159 + // MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1)
65160 + USHORT Psm; // power management mode (PWR_ACTIVE|PWR_SAVE)
65161 + USHORT DisassocReason;
65162 + UCHAR DisassocSta[MAC_ADDR_LEN];
65163 + USHORT DeauthReason;
65164 + UCHAR DeauthSta[MAC_ADDR_LEN];
65165 + USHORT AuthFailReason;
65166 + UCHAR AuthFailSta[MAC_ADDR_LEN];
65167 +
65168 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter; // PrivacyFilter enum for 802.1X
65169 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
65170 + NDIS_802_11_WEP_STATUS WepStatus;
65171 + NDIS_802_11_WEP_STATUS OrigWepStatus; // Original wep status set from OID
65172 +
65173 + // Add to support different cipher suite for WPA2/WPA mode
65174 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Multicast cipher suite
65175 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher suite
65176 + BOOLEAN bMixCipher; // Indicate current Pair & Group use different cipher suites
65177 + USHORT RsnCapability;
65178 +
65179 + NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
65180 +
65181 + UCHAR PMK[32]; // WPA PSK mode PMK
65182 + UCHAR PTK[64]; // WPA PSK mode PTK
65183 + UCHAR GTK[32]; // GTK from authenticator
65184 + BSSID_INFO SavedPMK[PMKID_NO];
65185 + UINT SavedPMKNum; // Saved PMKID number
65186 +
65187 + UCHAR DefaultKeyId;
65188 +
65189 +
65190 + // WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED
65191 + UCHAR PortSecured;
65192 +
65193 + // For WPA countermeasures
65194 + ULONG LastMicErrorTime; // record last MIC error time
65195 + ULONG MicErrCnt; // Should be 0, 1, 2, then reset to zero (after disassoiciation).
65196 + BOOLEAN bBlockAssoc; // Block associate attempt for 60 seconds after counter measure occurred.
65197 + // For WPA-PSK supplicant state
65198 + WPA_STATE WpaState; // Default is SS_NOTUSE and handled by microsoft 802.1x
65199 + UCHAR ReplayCounter[8];
65200 + UCHAR ANonce[32]; // ANonce for WPA-PSK from aurhenticator
65201 + UCHAR SNonce[32]; // SNonce for WPA-PSK
65202 +
65203 + UCHAR LastSNR0; // last received BEACON's SNR
65204 + UCHAR LastSNR1; // last received BEACON's SNR for 2nd antenna
65205 + RSSI_SAMPLE RssiSample;
65206 + ULONG NumOfAvgRssiSample;
65207 +
65208 + ULONG LastBeaconRxTime; // OS's timestamp of the last BEACON RX time
65209 + ULONG Last11bBeaconRxTime; // OS's timestamp of the last 11B BEACON RX time
65210 + ULONG Last11gBeaconRxTime; // OS's timestamp of the last 11G BEACON RX time
65211 + ULONG Last20NBeaconRxTime; // OS's timestamp of the last 20MHz N BEACON RX time
65212 +
65213 + ULONG LastScanTime; // Record last scan time for issue BSSID_SCAN_LIST
65214 + ULONG ScanCnt; // Scan counts since most recent SSID, BSSID, SCAN OID request
65215 + BOOLEAN bSwRadio; // Software controlled Radio On/Off, TRUE: On
65216 + BOOLEAN bHwRadio; // Hardware controlled Radio On/Off, TRUE: On
65217 + BOOLEAN bRadio; // Radio state, And of Sw & Hw radio state
65218 + BOOLEAN bHardwareRadio; // Hardware controlled Radio enabled
65219 + BOOLEAN bShowHiddenSSID; // Show all known SSID in SSID list get operation
65220 +
65221 +
65222 + // New for WPA, windows want us to to keep association information and
65223 + // Fixed IEs from last association response
65224 + NDIS_802_11_ASSOCIATION_INFORMATION AssocInfo;
65225 + USHORT ReqVarIELen; // Length of next VIE include EID & Length
65226 + UCHAR ReqVarIEs[MAX_VIE_LEN]; // The content saved here should be little-endian format.
65227 + USHORT ResVarIELen; // Length of next VIE include EID & Length
65228 + UCHAR ResVarIEs[MAX_VIE_LEN];
65229 +
65230 + UCHAR RSNIE_Len;
65231 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE]; // The content saved here should be little-endian format.
65232 +
65233 + // New variables used for CCX 1.0
65234 + BOOLEAN bCkipOn;
65235 + BOOLEAN bCkipCmicOn;
65236 + UCHAR CkipFlag;
65237 + UCHAR GIV[3]; //for CCX iv
65238 + UCHAR RxSEQ[4];
65239 + UCHAR TxSEQ[4];
65240 + UCHAR CKIPMIC[4];
65241 + UCHAR LeapAuthMode;
65242 + LEAP_AUTH_INFO LeapAuthInfo;
65243 + UCHAR HashPwd[16];
65244 + UCHAR NetworkChallenge[8];
65245 + UCHAR NetworkChallengeResponse[24];
65246 + UCHAR PeerChallenge[8];
65247 +
65248 + UCHAR PeerChallengeResponse[24];
65249 + UCHAR SessionKey[16]; //Network session keys (NSK)
65250 + RALINK_TIMER_STRUCT LeapAuthTimer;
65251 + ROGUEAP_TABLE RogueApTab; //Cisco CCX1 Rogue AP Detection
65252 +
65253 + // New control flags for CCX
65254 + CCX_CONTROL CCXControl; // Master administration state
65255 + BOOLEAN CCXEnable; // Actual CCX state
65256 + UCHAR CCXScanChannel; // Selected channel for CCX beacon request
65257 + USHORT CCXScanTime; // Time out to wait for beacon and probe response
65258 + UCHAR CCXReqType; // Current processing CCX request type
65259 + BSS_TABLE CCXBssTab; // BSS Table
65260 + UCHAR FrameReportBuf[2048]; // Buffer for creating frame report
65261 + USHORT FrameReportLen; // Current Frame report length
65262 + ULONG CLBusyBytes; // Save the total bytes received durning channel load scan time
65263 + USHORT RPIDensity[8]; // Array for RPI density collection
65264 + // Start address of each BSS table within FrameReportBuf
65265 + // It's important to update the RxPower of the corresponding Bss
65266 + USHORT BssReportOffset[MAX_LEN_OF_BSS_TABLE];
65267 + USHORT BeaconToken; // Token for beacon report
65268 + ULONG LastBssIndex; // Most current reported Bss index
65269 + RM_REQUEST_ACTION MeasurementRequest[16]; // Saved measurement request
65270 + UCHAR RMReqCnt; // Number of measurement request saved.
65271 + UCHAR CurrentRMReqIdx; // Number of measurement request saved.
65272 + BOOLEAN ParallelReq; // Parallel measurement, only one request performed,
65273 + // It must be the same channel with maximum duration
65274 + USHORT ParallelDuration; // Maximum duration for parallel measurement
65275 + UCHAR ParallelChannel; // Only one channel with parallel measurement
65276 + USHORT IAPPToken; // IAPP dialog token
65277 + UCHAR CCXQosECWMin; // Cisco QOS ECWMin for AC 0
65278 + UCHAR CCXQosECWMax; // Cisco QOS ECWMax for AC 0
65279 + // Hack for channel load and noise histogram parameters
65280 + UCHAR NHFactor; // Parameter for Noise histogram
65281 + UCHAR CLFactor; // Parameter for channel load
65282 +
65283 + UCHAR KRK[16]; //Key Refresh Key.
65284 + UCHAR BTK[32]; //Base Transient Key
65285 + BOOLEAN CCKMLinkUpFlag;
65286 + ULONG CCKMRN; //(Re)Association request number.
65287 + LARGE_INTEGER CCKMBeaconAtJoinTimeStamp; //TSF timer for Re-assocaite to the new AP
65288 + UCHAR AironetCellPowerLimit; //in dBm
65289 + UCHAR AironetIPAddress[4]; //eg. 192.168.1.1
65290 + BOOLEAN CCXAdjacentAPReportFlag; //flag for determining report Assoc Lost time
65291 + CHAR CCXAdjacentAPSsid[MAX_LEN_OF_SSID]; //Adjacent AP's SSID report
65292 + UCHAR CCXAdjacentAPSsidLen; // the actual ssid length in used
65293 + UCHAR CCXAdjacentAPBssid[MAC_ADDR_LEN]; //Adjacent AP's BSSID report
65294 + USHORT CCXAdjacentAPChannel;
65295 + ULONG CCXAdjacentAPLinkDownTime; //for Spec S32.
65296 +
65297 + RALINK_TIMER_STRUCT StaQuickResponeForRateUpTimer;
65298 + BOOLEAN StaQuickResponeForRateUpTimerRunning;
65299 +
65300 + UCHAR DtimCount; // 0.. DtimPeriod-1
65301 + UCHAR DtimPeriod; // default = 3
65302 +
65303 +#ifdef QOS_DLS_SUPPORT
65304 + RT_802_11_DLS DLSEntry[MAX_NUM_OF_DLS_ENTRY];
65305 + UCHAR DlsReplayCounter[8];
65306 +#endif // QOS_DLS_SUPPORT //
65307 + ////////////////////////////////////////////////////////////////////////////////////////
65308 + // This is only for WHQL test.
65309 + BOOLEAN WhqlTest;
65310 + ////////////////////////////////////////////////////////////////////////////////////////
65311 +
65312 + RALINK_TIMER_STRUCT WpaDisassocAndBlockAssocTimer;
65313 + // Fast Roaming
65314 + BOOLEAN bFastRoaming; // 0:disable fast roaming, 1:enable fast roaming
65315 + CHAR dBmToRoam; // the condition to roam when receiving Rssi less than this value. It's negative value.
65316 +
65317 +#ifdef WPA_SUPPLICANT_SUPPORT
65318 + BOOLEAN IEEE8021X;
65319 + BOOLEAN IEEE8021x_required_keys;
65320 + CIPHER_KEY DesireSharedKey[4]; // Record user desired WEP keys
65321 + UCHAR DesireSharedKeyId;
65322 +
65323 + // 0: driver ignores wpa_supplicant
65324 + // 1: wpa_supplicant initiates scanning and AP selection
65325 + // 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters
65326 + UCHAR WpaSupplicantUP;
65327 + UCHAR WpaSupplicantScanCount;
65328 +#endif // WPA_SUPPLICANT_SUPPORT //
65329 +
65330 + CHAR dev_name[16];
65331 + USHORT OriDevType;
65332 +
65333 + BOOLEAN bTGnWifiTest;
65334 + BOOLEAN bScanReqIsFromWebUI;
65335 +
65336 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
65337 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting;
65338 + RT_HT_PHY_INFO DesiredHtPhyInfo;
65339 + BOOLEAN bAutoTxRateSwitch;
65340 +
65341 +
65342 +#ifdef EXT_BUILD_CHANNEL_LIST
65343 + UCHAR IEEE80211dClientMode;
65344 + UCHAR StaOriCountryCode[3];
65345 + UCHAR StaOriGeography;
65346 +#endif // EXT_BUILD_CHANNEL_LIST //
65347 +} STA_ADMIN_CONFIG, *PSTA_ADMIN_CONFIG;
65348 +
65349 +// This data structure keep the current active BSS/IBSS's configuration that this STA
65350 +// had agreed upon joining the network. Which means these parameters are usually decided
65351 +// by the BSS/IBSS creator instead of user configuration. Data in this data structurre
65352 +// is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE.
65353 +// Normally, after SCAN or failed roaming attempts, we need to recover back to
65354 +// the current active settings.
65355 +typedef struct _STA_ACTIVE_CONFIG {
65356 + USHORT Aid;
65357 + USHORT AtimWin; // in kusec; IBSS parameter set element
65358 + USHORT CapabilityInfo;
65359 + USHORT CfpMaxDuration;
65360 + USHORT CfpPeriod;
65361 +
65362 + // Copy supported rate from desired AP's beacon. We are trying to match
65363 + // AP's supported and extended rate settings.
65364 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
65365 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
65366 + UCHAR SupRateLen;
65367 + UCHAR ExtRateLen;
65368 + // Copy supported ht from desired AP's beacon. We are trying to match
65369 + RT_HT_PHY_INFO SupportedPhyInfo;
65370 + RT_HT_CAPABILITY SupportedHtPhy;
65371 +} STA_ACTIVE_CONFIG, *PSTA_ACTIVE_CONFIG;
65372 +
65373 +#ifdef RT2870
65374 +// for USB interface, avoid in interrupt when write key
65375 +typedef struct RT_ADD_PAIRWISE_KEY_ENTRY {
65376 + NDIS_802_11_MAC_ADDRESS MacAddr;
65377 + USHORT MacTabMatchWCID; // ASIC
65378 + CIPHER_KEY CipherKey;
65379 +} RT_ADD_PAIRWISE_KEY_ENTRY,*PRT_ADD_PAIRWISE_KEY_ENTRY;
65380 +#endif // RT2870 //
65381 +#endif // CONFIG_STA_SUPPORT //
65382 +
65383 +// ----------- start of AP --------------------------
65384 +// AUTH-RSP State Machine Aux data structure
65385 +typedef struct _AP_MLME_AUX {
65386 + UCHAR Addr[MAC_ADDR_LEN];
65387 + USHORT Alg;
65388 + CHAR Challenge[CIPHER_TEXT_LEN];
65389 +} AP_MLME_AUX, *PAP_MLME_AUX;
65390 +
65391 +// structure to define WPA Group Key Rekey Interval
65392 +typedef struct PACKED _RT_802_11_WPA_REKEY {
65393 + ULONG ReKeyMethod; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
65394 + ULONG ReKeyInterval; // time-based: seconds, packet-based: kilo-packets
65395 +} RT_WPA_REKEY,*PRT_WPA_REKEY, RT_802_11_WPA_REKEY, *PRT_802_11_WPA_REKEY;
65396 +
65397 +typedef struct _MAC_TABLE_ENTRY {
65398 + //Choose 1 from ValidAsWDS and ValidAsCLI to validize.
65399 + BOOLEAN ValidAsCLI; // Sta mode, set this TRUE after Linkup,too.
65400 + BOOLEAN ValidAsWDS; // This is WDS Entry. only for AP mode.
65401 + BOOLEAN ValidAsApCli; //This is a AP-Client entry, only for AP mode which enable AP-Client functions.
65402 + BOOLEAN ValidAsMesh;
65403 + BOOLEAN ValidAsDls; // This is DLS Entry. only for STA mode.
65404 + BOOLEAN isCached;
65405 + BOOLEAN bIAmBadAtheros; // Flag if this is Atheros chip that has IOT problem. We need to turn on RTS/CTS protection.
65406 +
65407 + UCHAR EnqueueEapolStartTimerRunning; // Enqueue EAPoL-Start for triggering EAP SM
65408 + //jan for wpa
65409 + // record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB
65410 + UCHAR CMTimerRunning;
65411 + UCHAR apidx; // MBSS number
65412 + UCHAR RSNIE_Len;
65413 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE];
65414 + UCHAR ANonce[LEN_KEY_DESC_NONCE];
65415 + UCHAR R_Counter[LEN_KEY_DESC_REPLAY];
65416 + UCHAR PTK[64];
65417 + UCHAR ReTryCounter;
65418 + RALINK_TIMER_STRUCT RetryTimer;
65419 + RALINK_TIMER_STRUCT EnqueueStartForPSKTimer; // A timer which enqueue EAPoL-Start for triggering PSK SM
65420 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
65421 + NDIS_802_11_WEP_STATUS WepStatus;
65422 + AP_WPA_STATE WpaState;
65423 + GTK_STATE GTKState;
65424 + USHORT PortSecured;
65425 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter; // PrivacyFilter enum for 802.1X
65426 + CIPHER_KEY PairwiseKey;
65427 + PVOID pAd;
65428 + INT PMKID_CacheIdx;
65429 + UCHAR PMKID[LEN_PMKID];
65430 +
65431 +
65432 + UCHAR Addr[MAC_ADDR_LEN];
65433 + UCHAR PsMode;
65434 + SST Sst;
65435 + AUTH_STATE AuthState; // for SHARED KEY authentication state machine used only
65436 + BOOLEAN IsReassocSta; // Indicate whether this is a reassociation procedure
65437 + USHORT Aid;
65438 + USHORT CapabilityInfo;
65439 + UCHAR LastRssi;
65440 + ULONG NoDataIdleCount;
65441 + UINT16 StationKeepAliveCount; // unit: second
65442 + ULONG PsQIdleCount;
65443 + QUEUE_HEADER PsQueue;
65444 +
65445 + UINT32 StaConnectTime; // the live time of this station since associated with AP
65446 +
65447 +
65448 +#ifdef DOT11_N_SUPPORT
65449 + BOOLEAN bSendBAR;
65450 + USHORT NoBADataCountDown;
65451 +
65452 + UINT32 CachedBuf[16]; // UINT (4 bytes) for alignment
65453 + UINT TxBFCount; // 3*3
65454 +#endif // DOT11_N_SUPPORT //
65455 + UINT FIFOCount;
65456 + UINT DebugFIFOCount;
65457 + UINT DebugTxCount;
65458 + BOOLEAN bDlsInit;
65459 +
65460 +
65461 +//====================================================
65462 +//WDS entry needs these
65463 +// rt2860 add this. if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab
65464 + UINT MatchWDSTabIdx;
65465 + UCHAR MaxSupportedRate;
65466 + UCHAR CurrTxRate;
65467 + UCHAR CurrTxRateIndex;
65468 + // to record the each TX rate's quality. 0 is best, the bigger the worse.
65469 + USHORT TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
65470 +// USHORT OneSecTxOkCount;
65471 + UINT32 OneSecTxNoRetryOkCount;
65472 + UINT32 OneSecTxRetryOkCount;
65473 + UINT32 OneSecTxFailCount;
65474 + UINT32 ContinueTxFailCnt;
65475 + UINT32 CurrTxRateStableTime; // # of second in current TX rate
65476 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
65477 +//====================================================
65478 +
65479 +
65480 +
65481 +#ifdef CONFIG_STA_SUPPORT
65482 +#ifdef QOS_DLS_SUPPORT
65483 + UINT MatchDlsEntryIdx; // indicate the index in pAd->StaCfg.DLSEntry
65484 +#endif // QOS_DLS_SUPPORT //
65485 +#endif // CONFIG_STA_SUPPORT //
65486 +
65487 + BOOLEAN fNoisyEnvironment;
65488 + BOOLEAN fLastSecAccordingRSSI;
65489 + UCHAR LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
65490 + CHAR LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
65491 + ULONG LastTxOkCount;
65492 + UCHAR PER[MAX_STEP_OF_TX_RATE_SWITCH];
65493 +
65494 + // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
65495 + // BOOLEAN control, either ON or OFF. These flags should always be accessed via
65496 + // CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros.
65497 + // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED
65498 + ULONG ClientStatusFlags;
65499 +
65500 + // TODO: Shall we move that to DOT11_N_SUPPORT???
65501 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
65502 +
65503 +#ifdef DOT11_N_SUPPORT
65504 + // HT EWC MIMO-N used parameters
65505 + USHORT RXBAbitmap; // fill to on-chip RXWI_BA_BITMASK in 8.1.3RX attribute entry format
65506 + USHORT TXBAbitmap; // This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI
65507 + USHORT TXAutoBAbitmap;
65508 + USHORT BADeclineBitmap;
65509 + USHORT BARecWcidArray[NUM_OF_TID]; // The mapping wcid of recipient session. if RXBAbitmap bit is masked
65510 + USHORT BAOriWcidArray[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
65511 + USHORT BAOriSequence[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
65512 +
65513 + // 802.11n features.
65514 + UCHAR MpduDensity;
65515 + UCHAR MaxRAmpduFactor;
65516 + UCHAR AMsduSize;
65517 + UCHAR MmpsMode; // MIMO power save more.
65518 +
65519 + HT_CAPABILITY_IE HTCapability;
65520 +
65521 +#ifdef DOT11N_DRAFT3
65522 + UCHAR BSS2040CoexistenceMgmtSupport;
65523 +#endif // DOT11N_DRAFT3 //
65524 +#endif // DOT11_N_SUPPORT //
65525 +
65526 + BOOLEAN bAutoTxRateSwitch;
65527 +
65528 + UCHAR RateLen;
65529 + struct _MAC_TABLE_ENTRY *pNext;
65530 + USHORT TxSeq[NUM_OF_TID];
65531 + USHORT NonQosDataSeq;
65532 +
65533 + RSSI_SAMPLE RssiSample;
65534 +
65535 + UINT32 TXMCSExpected[16];
65536 + UINT32 TXMCSSuccessful[16];
65537 + UINT32 TXMCSFailed[16];
65538 + UINT32 TXMCSAutoFallBack[16][16];
65539 +
65540 +#ifdef CONFIG_STA_SUPPORT
65541 + ULONG LastBeaconRxTime;
65542 +#endif // CONFIG_STA_SUPPORT //
65543 +} MAC_TABLE_ENTRY, *PMAC_TABLE_ENTRY;
65544 +
65545 +typedef struct _MAC_TABLE {
65546 + USHORT Size;
65547 + MAC_TABLE_ENTRY *Hash[HASH_TABLE_SIZE];
65548 + MAC_TABLE_ENTRY Content[MAX_LEN_OF_MAC_TABLE];
65549 + QUEUE_HEADER McastPsQueue;
65550 + ULONG PsQIdleCount;
65551 + BOOLEAN fAnyStationInPsm;
65552 + BOOLEAN fAnyStationBadAtheros; // Check if any Station is atheros 802.11n Chip. We need to use RTS/CTS with Atheros 802,.11n chip.
65553 + BOOLEAN fAnyTxOPForceDisable; // Check if it is necessary to disable BE TxOP
65554 + BOOLEAN fAllStationAsRalink; // Check if all stations are ralink-chipset
65555 +#ifdef DOT11_N_SUPPORT
65556 + BOOLEAN fAnyStationIsLegacy; // Check if I use legacy rate to transmit to my BSS Station/
65557 + BOOLEAN fAnyStationNonGF; // Check if any Station can't support GF.
65558 + BOOLEAN fAnyStation20Only; // Check if any Station can't support GF.
65559 + BOOLEAN fAnyStationMIMOPSDynamic; // Check if any Station is MIMO Dynamic
65560 + BOOLEAN fAnyBASession; // Check if there is BA session. Force turn on RTS/CTS
65561 +#endif // DOT11_N_SUPPORT //
65562 +} MAC_TABLE, *PMAC_TABLE;
65563 +
65564 +#ifdef DOT11_N_SUPPORT
65565 +#define IS_HT_STA(_pMacEntry) \
65566 + (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
65567 +
65568 +#define IS_HT_RATE(_pMacEntry) \
65569 + (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
65570 +
65571 +#define PEER_IS_HT_RATE(_pMacEntry) \
65572 + (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
65573 +#endif // DOT11_N_SUPPORT //
65574 +
65575 +typedef struct _WDS_ENTRY {
65576 + BOOLEAN Valid;
65577 + UCHAR Addr[MAC_ADDR_LEN];
65578 + ULONG NoDataIdleCount;
65579 + struct _WDS_ENTRY *pNext;
65580 +} WDS_ENTRY, *PWDS_ENTRY;
65581 +
65582 +typedef struct _WDS_TABLE_ENTRY {
65583 + USHORT Size;
65584 + UCHAR WdsAddr[MAC_ADDR_LEN];
65585 + WDS_ENTRY *Hash[HASH_TABLE_SIZE];
65586 + WDS_ENTRY Content[MAX_LEN_OF_MAC_TABLE];
65587 + UCHAR MaxSupportedRate;
65588 + UCHAR CurrTxRate;
65589 + USHORT TxQuality[MAX_LEN_OF_SUPPORTED_RATES];
65590 + USHORT OneSecTxOkCount;
65591 + USHORT OneSecTxRetryOkCount;
65592 + USHORT OneSecTxFailCount;
65593 + ULONG CurrTxRateStableTime; // # of second in current TX rate
65594 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
65595 +} WDS_TABLE_ENTRY, *PWDS_TABLE_ENTRY;
65596 +
65597 +typedef struct _RT_802_11_WDS_ENTRY {
65598 + PNET_DEV dev;
65599 + UCHAR Valid;
65600 + UCHAR PhyMode;
65601 + UCHAR PeerWdsAddr[MAC_ADDR_LEN];
65602 + UCHAR MacTabMatchWCID; // ASIC
65603 + NDIS_802_11_WEP_STATUS WepStatus;
65604 + UCHAR KeyIdx;
65605 + CIPHER_KEY WdsKey;
65606 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
65607 + RT_HT_PHY_INFO DesiredHtPhyInfo;
65608 + BOOLEAN bAutoTxRateSwitch;
65609 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting.
65610 +} RT_802_11_WDS_ENTRY, *PRT_802_11_WDS_ENTRY;
65611 +
65612 +typedef struct _WDS_TABLE {
65613 + UCHAR Mode;
65614 + ULONG Size;
65615 + RT_802_11_WDS_ENTRY WdsEntry[MAX_WDS_ENTRY];
65616 +} WDS_TABLE, *PWDS_TABLE;
65617 +
65618 +typedef struct _APCLI_STRUCT {
65619 + PNET_DEV dev;
65620 +#ifdef RTL865X_SOC
65621 + unsigned int mylinkid;
65622 +#endif
65623 + BOOLEAN Enable; // Set it as 1 if the apcli interface was configured to "1" or by iwpriv cmd "ApCliEnable"
65624 + BOOLEAN Valid; // Set it as 1 if the apcli interface associated success to remote AP.
65625 + UCHAR MacTabWCID; //WCID value, which point to the entry of ASIC Mac table.
65626 + UCHAR SsidLen;
65627 + CHAR Ssid[MAX_LEN_OF_SSID];
65628 +
65629 + UCHAR CfgSsidLen;
65630 + CHAR CfgSsid[MAX_LEN_OF_SSID];
65631 + UCHAR CfgApCliBssid[ETH_LENGTH_OF_ADDRESS];
65632 + UCHAR CurrentAddress[ETH_LENGTH_OF_ADDRESS];
65633 +
65634 + ULONG ApCliRcvBeaconTime;
65635 +
65636 + ULONG CtrlCurrState;
65637 + ULONG SyncCurrState;
65638 + ULONG AuthCurrState;
65639 + ULONG AssocCurrState;
65640 + ULONG WpaPskCurrState;
65641 +
65642 + USHORT AuthReqCnt;
65643 + USHORT AssocReqCnt;
65644 +
65645 + ULONG ClientStatusFlags;
65646 + UCHAR MpduDensity;
65647 +
65648 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
65649 + NDIS_802_11_WEP_STATUS WepStatus;
65650 +
65651 + // Add to support different cipher suite for WPA2/WPA mode
65652 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Multicast cipher suite
65653 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher suite
65654 + BOOLEAN bMixCipher; // Indicate current Pair & Group use different cipher suites
65655 + USHORT RsnCapability;
65656 +
65657 + UCHAR PSK[100]; // reserve PSK key material
65658 + UCHAR PSKLen;
65659 + UCHAR PMK[32]; // WPA PSK mode PMK
65660 + //UCHAR PTK[64]; // WPA PSK mode PTK
65661 + UCHAR GTK[32]; // GTK from authenticator
65662 +
65663 + //CIPHER_KEY PairwiseKey;
65664 + CIPHER_KEY SharedKey[SHARE_KEY_NUM];
65665 + UCHAR DefaultKeyId;
65666 +
65667 + // WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED
65668 + //UCHAR PortSecured;
65669 +
65670 + // store RSN_IE built by driver
65671 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE]; // The content saved here should be convert to little-endian format.
65672 + UCHAR RSNIE_Len;
65673 +
65674 + // For WPA countermeasures
65675 + ULONG LastMicErrorTime; // record last MIC error time
65676 + //ULONG MicErrCnt; // Should be 0, 1, 2, then reset to zero (after disassoiciation).
65677 + BOOLEAN bBlockAssoc; // Block associate attempt for 60 seconds after counter measure occurred.
65678 +
65679 + // For WPA-PSK supplicant state
65680 + //WPA_STATE WpaState; // Default is SS_NOTUSE
65681 + //UCHAR ReplayCounter[8];
65682 + //UCHAR ANonce[32]; // ANonce for WPA-PSK from authenticator
65683 + UCHAR SNonce[32]; // SNonce for WPA-PSK
65684 + UCHAR GNonce[32]; // GNonce for WPA-PSK from authenticator
65685 +
65686 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
65687 + RT_HT_PHY_INFO DesiredHtPhyInfo;
65688 + BOOLEAN bAutoTxRateSwitch;
65689 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting.
65690 +} APCLI_STRUCT, *PAPCLI_STRUCT;
65691 +
65692 +// ----------- end of AP ----------------------------
65693 +
65694 +#ifdef BLOCK_NET_IF
65695 +typedef struct _BLOCK_QUEUE_ENTRY
65696 +{
65697 + BOOLEAN SwTxQueueBlockFlag;
65698 + LIST_HEADER NetIfList;
65699 +} BLOCK_QUEUE_ENTRY, *PBLOCK_QUEUE_ENTRY;
65700 +#endif // BLOCK_NET_IF //
65701 +
65702 +struct wificonf
65703 +{
65704 + BOOLEAN bShortGI;
65705 + BOOLEAN bGreenField;
65706 +};
65707 +
65708 +
65709 +
65710 +typedef struct _INF_PCI_CONFIG
65711 +{
65712 + PUCHAR CSRBaseAddress; // PCI MMIO Base Address, all access will use
65713 +}INF_PCI_CONFIG;
65714 +
65715 +typedef struct _INF_USB_CONFIG
65716 +{
65717 + UINT BulkInEpAddr; // bulk-in endpoint address
65718 + UINT BulkOutEpAddr[6]; // bulk-out endpoint address
65719 +
65720 +}INF_USB_CONFIG;
65721 +
65722 +#ifdef IKANOS_VX_1X0
65723 + typedef void (*IkanosWlanTxCbFuncP)(void *, void *);
65724 +
65725 + struct IKANOS_TX_INFO
65726 + {
65727 + struct net_device *netdev;
65728 + IkanosWlanTxCbFuncP *fp;
65729 + };
65730 +#endif // IKANOS_VX_1X0 //
65731 +
65732 +#ifdef NINTENDO_AP
65733 +typedef struct _NINDO_CTRL_BLOCK {
65734 +
65735 + RT_NINTENDO_TABLE DS_TABLE;
65736 +
65737 +#ifdef CHIP25XX
65738 + spinlock_t NINTENDO_TABLE_Lock;
65739 +#else
65740 + NDIS_SPIN_LOCK NINTENDO_TABLE_Lock;
65741 +#endif // CHIP25XX //
65742 +
65743 + UCHAR NINTENDO_UP_BUFFER[512];
65744 + UCHAR Local_KeyIdx;
65745 + CIPHER_KEY Local_SharedKey;
65746 + UCHAR Local_bHideSsid;
65747 + UCHAR Local_AuthMode;
65748 + UCHAR Local_WepStatus;
65749 + USHORT Local_CapabilityInfo;
65750 +} NINDO_CTRL_BLOCK;
65751 +#endif // NINTENDO_AP //
65752 +
65753 +
65754 +#ifdef DBG_DIAGNOSE
65755 +#define DIAGNOSE_TIME 10 // 10 sec
65756 +typedef struct _RtmpDiagStrcut_
65757 +{ // Diagnosis Related element
65758 + unsigned char inited;
65759 + unsigned char qIdx;
65760 + unsigned char ArrayStartIdx;
65761 + unsigned char ArrayCurIdx;
65762 + // Tx Related Count
65763 + USHORT TxDataCnt[DIAGNOSE_TIME];
65764 + USHORT TxFailCnt[DIAGNOSE_TIME];
65765 +// USHORT TxDescCnt[DIAGNOSE_TIME][16]; // TxDesc queue length in scale of 0~14, >=15
65766 + USHORT TxDescCnt[DIAGNOSE_TIME][24]; // 3*3 // TxDesc queue length in scale of 0~14, >=15
65767 +// USHORT TxMcsCnt[DIAGNOSE_TIME][16]; // TxDate MCS Count in range from 0 to 15, step in 1.
65768 + USHORT TxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
65769 + USHORT TxSWQueCnt[DIAGNOSE_TIME][9]; // TxSwQueue length in scale of 0, 1, 2, 3, 4, 5, 6, 7, >=8
65770 +
65771 + USHORT TxAggCnt[DIAGNOSE_TIME];
65772 + USHORT TxNonAggCnt[DIAGNOSE_TIME];
65773 +// USHORT TxAMPDUCnt[DIAGNOSE_TIME][16]; // 10 sec, TxDMA APMDU Aggregation count in range from 0 to 15, in setp of 1.
65774 + USHORT TxAMPDUCnt[DIAGNOSE_TIME][24]; // 3*3 // 10 sec, TxDMA APMDU Aggregation count in range from 0 to 15, in setp of 1.
65775 + USHORT TxRalinkCnt[DIAGNOSE_TIME]; // TxRalink Aggregation Count in 1 sec scale.
65776 + USHORT TxAMSDUCnt[DIAGNOSE_TIME]; // TxAMSUD Aggregation Count in 1 sec scale.
65777 +
65778 + // Rx Related Count
65779 + USHORT RxDataCnt[DIAGNOSE_TIME]; // Rx Total Data count.
65780 + USHORT RxCrcErrCnt[DIAGNOSE_TIME];
65781 +// USHORT RxMcsCnt[DIAGNOSE_TIME][16]; // Rx MCS Count in range from 0 to 15, step in 1.
65782 + USHORT RxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
65783 +}RtmpDiagStruct;
65784 +#endif // DBG_DIAGNOSE //
65785 +
65786 +
65787 +//
65788 +// The miniport adapter structure
65789 +//
65790 +typedef struct _RTMP_ADAPTER
65791 +{
65792 + PVOID OS_Cookie; // save specific structure relative to OS
65793 + PNET_DEV net_dev;
65794 + ULONG VirtualIfCnt;
65795 +
65796 +
65797 +
65798 + NDIS_SPIN_LOCK irq_lock;
65799 + UCHAR irq_disabled;
65800 +
65801 +#ifdef RT2870
65802 +/*****************************************************************************************/
65803 +/* USB related parameters */
65804 +/*****************************************************************************************/
65805 + struct usb_config_descriptor *config;
65806 + UINT BulkInEpAddr; // bulk-in endpoint address
65807 + UINT BulkOutEpAddr[6]; // bulk-out endpoint address
65808 +
65809 + UINT NumberOfPipes;
65810 + USHORT BulkOutMaxPacketSize;
65811 + USHORT BulkInMaxPacketSize;
65812 +
65813 + //======Control Flags
65814 + LONG PendingIoCount;
65815 + ULONG BulkFlags;
65816 + BOOLEAN bUsbTxBulkAggre; // Flags for bulk out data priority
65817 +
65818 +
65819 + //======Timer Thread
65820 + RT2870_TIMER_QUEUE TimerQ;
65821 + NDIS_SPIN_LOCK TimerQLock;
65822 +
65823 +
65824 + //======Cmd Thread
65825 + CmdQ CmdQ;
65826 + NDIS_SPIN_LOCK CmdQLock; // CmdQLock spinlock
65827 +
65828 + BOOLEAN TimerFunc_kill;
65829 + BOOLEAN mlme_kill;
65830 +
65831 +
65832 + //======Semaphores (event)
65833 + struct semaphore mlme_semaphore; /* to sleep thread on */
65834 + struct semaphore RTUSBCmd_semaphore; /* to sleep thread on */
65835 + struct semaphore RTUSBTimer_semaphore;
65836 +#ifdef INF_AMAZON_SE
65837 + struct semaphore UsbVendorReq_semaphore;
65838 + PVOID UsbVendorReqBuf;
65839 +#endif // INF_AMAZON_SE //
65840 + struct completion TimerQComplete;
65841 + struct completion mlmeComplete;
65842 + struct completion CmdQComplete;
65843 + wait_queue_head_t *wait;
65844 +
65845 + //======Lock for 2870 ATE
65846 +#ifdef RALINK_ATE
65847 + NDIS_SPIN_LOCK GenericLock; // ATE Tx/Rx generic spinlock
65848 +#endif // RALINK_ATE //
65849 +
65850 +#endif // RT2870 //
65851 +
65852 +
65853 +/*****************************************************************************************/
65854 + /* Both PCI/USB related parameters */
65855 +/*****************************************************************************************/
65856 +
65857 +
65858 +/*****************************************************************************************/
65859 +/* Tx related parameters */
65860 +/*****************************************************************************************/
65861 + BOOLEAN DeQueueRunning[NUM_OF_TX_RING]; // for ensuring RTUSBDeQueuePacket get call once
65862 + NDIS_SPIN_LOCK DeQueueLock[NUM_OF_TX_RING];
65863 +
65864 +#ifdef RT2870
65865 + // Data related context and AC specified, 4 AC supported
65866 + NDIS_SPIN_LOCK BulkOutLock[6]; // BulkOut spinlock for 4 ACs
65867 + NDIS_SPIN_LOCK MLMEBulkOutLock; // MLME BulkOut lock
65868 +
65869 + HT_TX_CONTEXT TxContext[NUM_OF_TX_RING];
65870 + NDIS_SPIN_LOCK TxContextQueueLock[NUM_OF_TX_RING]; // TxContextQueue spinlock
65871 +
65872 + // 4 sets of Bulk Out index and pending flag
65873 + UCHAR NextBulkOutIndex[4]; // only used for 4 EDCA bulkout pipe
65874 +
65875 + BOOLEAN BulkOutPending[6]; // used for total 6 bulkout pipe
65876 + UCHAR bulkResetPipeid;
65877 + BOOLEAN MgmtBulkPending;
65878 + ULONG bulkResetReq[6];
65879 +#endif // RT2870 //
65880 +
65881 + // resource for software backlog queues
65882 + QUEUE_HEADER TxSwQueue[NUM_OF_TX_RING]; // 4 AC + 1 HCCA
65883 + NDIS_SPIN_LOCK TxSwQueueLock[NUM_OF_TX_RING]; // TxSwQueue spinlock
65884 +
65885 + RTMP_DMABUF MgmtDescRing; // Shared memory for MGMT descriptors
65886 + RTMP_MGMT_RING MgmtRing;
65887 + NDIS_SPIN_LOCK MgmtRingLock; // Prio Ring spinlock
65888 +
65889 +
65890 +/*****************************************************************************************/
65891 +/* Rx related parameters */
65892 +/*****************************************************************************************/
65893 +
65894 +
65895 +#ifdef RT2870
65896 + RX_CONTEXT RxContext[RX_RING_SIZE]; // 1 for redundant multiple IRP bulk in.
65897 + NDIS_SPIN_LOCK BulkInLock; // BulkIn spinlock for 4 ACs
65898 + UCHAR PendingRx; // The Maxima pending Rx value should be RX_RING_SIZE.
65899 + UCHAR NextRxBulkInIndex; // Indicate the current RxContext Index which hold by Host controller.
65900 + UCHAR NextRxBulkInReadIndex; // Indicate the current RxContext Index which driver can read & process it.
65901 + ULONG NextRxBulkInPosition; // Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength.
65902 + ULONG TransferBufferLength; // current length of the packet buffer
65903 + ULONG ReadPosition; // current read position in a packet buffer
65904 +#endif // RT2870 //
65905 +
65906 +
65907 +/*****************************************************************************************/
65908 +/* ASIC related parameters */
65909 +/*****************************************************************************************/
65910 + UINT32 MACVersion; // MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101)..
65911 +
65912 + // ---------------------------
65913 + // E2PROM
65914 + // ---------------------------
65915 + ULONG EepromVersion; // byte 0: version, byte 1: revision, byte 2~3: unused
65916 + UCHAR EEPROMAddressNum; // 93c46=6 93c66=8
65917 + USHORT EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
65918 + ULONG FirmwareVersion; // byte 0: Minor version, byte 1: Major version, otherwise unused.
65919 +
65920 + // ---------------------------
65921 + // BBP Control
65922 + // ---------------------------
65923 + UCHAR BbpWriteLatch[140]; // record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID
65924 + UCHAR BbpRssiToDbmDelta;
65925 + BBP_R66_TUNING BbpTuning;
65926 +
65927 + // ----------------------------
65928 + // RFIC control
65929 + // ----------------------------
65930 + UCHAR RfIcType; // RFIC_xxx
65931 + ULONG RfFreqOffset; // Frequency offset for channel switching
65932 + RTMP_RF_REGS LatchRfRegs; // latch th latest RF programming value since RF IC doesn't support READ
65933 +
65934 + EEPROM_ANTENNA_STRUC Antenna; // Since ANtenna definition is different for a & g. We need to save it for future reference.
65935 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
65936 +
65937 + // This soft Rx Antenna Diversity mechanism is used only when user set
65938 + // RX Antenna = DIVERSITY ON
65939 + SOFT_RX_ANT_DIVERSITY RxAnt;
65940 +
65941 + UCHAR RFProgSeq;
65942 + CHANNEL_TX_POWER TxPower[MAX_NUM_OF_CHANNELS]; // Store Tx power value for all channels.
65943 + CHANNEL_TX_POWER ChannelList[MAX_NUM_OF_CHANNELS]; // list all supported channels for site survey
65944 + CHANNEL_11J_TX_POWER TxPower11J[MAX_NUM_OF_11JCHANNELS]; // 802.11j channel and bw
65945 + CHANNEL_11J_TX_POWER ChannelList11J[MAX_NUM_OF_11JCHANNELS]; // list all supported channels for site survey
65946 +
65947 + UCHAR ChannelListNum; // number of channel in ChannelList[]
65948 + UCHAR Bbp94;
65949 + BOOLEAN BbpForCCK;
65950 + ULONG Tx20MPwrCfgABand[5];
65951 + ULONG Tx20MPwrCfgGBand[5];
65952 + ULONG Tx40MPwrCfgABand[5];
65953 + ULONG Tx40MPwrCfgGBand[5];
65954 +
65955 + BOOLEAN bAutoTxAgcA; // Enable driver auto Tx Agc control
65956 + UCHAR TssiRefA; // Store Tssi reference value as 25 temperature.
65957 + UCHAR TssiPlusBoundaryA[5]; // Tssi boundary for increase Tx power to compensate.
65958 + UCHAR TssiMinusBoundaryA[5]; // Tssi boundary for decrease Tx power to compensate.
65959 + UCHAR TxAgcStepA; // Store Tx TSSI delta increment / decrement value
65960 + CHAR TxAgcCompensateA; // Store the compensation (TxAgcStep * (idx-1))
65961 +
65962 + BOOLEAN bAutoTxAgcG; // Enable driver auto Tx Agc control
65963 + UCHAR TssiRefG; // Store Tssi reference value as 25 temperature.
65964 + UCHAR TssiPlusBoundaryG[5]; // Tssi boundary for increase Tx power to compensate.
65965 + UCHAR TssiMinusBoundaryG[5]; // Tssi boundary for decrease Tx power to compensate.
65966 + UCHAR TxAgcStepG; // Store Tx TSSI delta increment / decrement value
65967 + CHAR TxAgcCompensateG; // Store the compensation (TxAgcStep * (idx-1))
65968 +
65969 + //+++For RT2870, the parameteres is start from BGRssiOffset1 ~ BGRssiOffset3
65970 + CHAR BGRssiOffset0; // Store B/G RSSI#0 Offset value on EEPROM 0x46h
65971 + CHAR BGRssiOffset1; // Store B/G RSSI#1 Offset value
65972 + CHAR BGRssiOffset2; // Store B/G RSSI#2 Offset value
65973 + //---
65974 +
65975 + //+++For RT2870, the parameteres is start from ARssiOffset1 ~ ARssiOffset3
65976 + CHAR ARssiOffset0; // Store A RSSI#0 Offset value on EEPROM 0x4Ah
65977 + CHAR ARssiOffset1; // Store A RSSI#1 Offset value
65978 + CHAR ARssiOffset2; // Store A RSSI#2 Offset value
65979 + //---
65980 +
65981 + CHAR BLNAGain; // Store B/G external LNA#0 value on EEPROM 0x44h
65982 + CHAR ALNAGain0; // Store A external LNA#0 value for ch36~64
65983 + CHAR ALNAGain1; // Store A external LNA#1 value for ch100~128
65984 + CHAR ALNAGain2; // Store A external LNA#2 value for ch132~165
65985 +
65986 + // ----------------------------
65987 + // LED control
65988 + // ----------------------------
65989 + MCU_LEDCS_STRUC LedCntl;
65990 + USHORT Led1; // read from EEPROM 0x3c
65991 + USHORT Led2; // EEPROM 0x3e
65992 + USHORT Led3; // EEPROM 0x40
65993 + UCHAR LedIndicatorStregth;
65994 + UCHAR RssiSingalstrengthOffet;
65995 + BOOLEAN bLedOnScanning;
65996 + UCHAR LedStatus;
65997 +
65998 +/*****************************************************************************************/
65999 +/* 802.11 related parameters */
66000 +/*****************************************************************************************/
66001 + // outgoing BEACON frame buffer and corresponding TXD
66002 + TXWI_STRUC BeaconTxWI;
66003 + PUCHAR BeaconBuf;
66004 + USHORT BeaconOffset[HW_BEACON_MAX_COUNT];
66005 +
66006 + // pre-build PS-POLL and NULL frame upon link up. for efficiency purpose.
66007 + PSPOLL_FRAME PsPollFrame;
66008 + HEADER_802_11 NullFrame;
66009 +
66010 +#ifdef RT2870
66011 + TX_CONTEXT BeaconContext[BEACON_RING_SIZE];
66012 + TX_CONTEXT NullContext;
66013 + TX_CONTEXT PsPollContext;
66014 + TX_CONTEXT RTSContext;
66015 +#endif // RT2870 //
66016 +
66017 +
66018 +
66019 +//=========AP===========
66020 +
66021 +
66022 +//=======STA===========
66023 +#ifdef CONFIG_STA_SUPPORT
66024 +/* Modified by Wu Xi-Kun 4/21/2006 */
66025 + // -----------------------------------------------
66026 + // STA specific configuration & operation status
66027 + // used only when pAd->OpMode == OPMODE_STA
66028 + // -----------------------------------------------
66029 + STA_ADMIN_CONFIG StaCfg; // user desired settings
66030 + STA_ACTIVE_CONFIG StaActive; // valid only when ADHOC_ON(pAd) || INFRA_ON(pAd)
66031 + CHAR nickname[IW_ESSID_MAX_SIZE+1]; // nickname, only used in the iwconfig i/f
66032 + NDIS_MEDIA_STATE PreMediaState;
66033 +#endif // CONFIG_STA_SUPPORT //
66034 +
66035 +//=======Common===========
66036 + // OP mode: either AP or STA
66037 + UCHAR OpMode; // OPMODE_STA, OPMODE_AP
66038 +
66039 + NDIS_MEDIA_STATE IndicateMediaState; // Base on Indication state, default is NdisMediaStateDisConnected
66040 +
66041 +
66042 + // configuration: read from Registry & E2PROM
66043 + BOOLEAN bLocalAdminMAC; // Use user changed MAC
66044 + UCHAR PermanentAddress[MAC_ADDR_LEN]; // Factory default MAC address
66045 + UCHAR CurrentAddress[MAC_ADDR_LEN]; // User changed MAC address
66046 +
66047 + // ------------------------------------------------------
66048 + // common configuration to both OPMODE_STA and OPMODE_AP
66049 + // ------------------------------------------------------
66050 + COMMON_CONFIG CommonCfg;
66051 + MLME_STRUCT Mlme;
66052 +
66053 + // AP needs those vaiables for site survey feature.
66054 + MLME_AUX MlmeAux; // temporary settings used during MLME state machine
66055 + BSS_TABLE ScanTab; // store the latest SCAN result
66056 +
66057 + //About MacTab, the sta driver will use #0 and #1 for multicast and AP.
66058 + MAC_TABLE MacTab; // ASIC on-chip WCID entry table. At TX, ASIC always use key according to this on-chip table.
66059 + NDIS_SPIN_LOCK MacTabLock;
66060 +
66061 +#ifdef DOT11_N_SUPPORT
66062 + BA_TABLE BATable;
66063 +#endif // DOT11_N_SUPPORT //
66064 + NDIS_SPIN_LOCK BATabLock;
66065 + RALINK_TIMER_STRUCT RECBATimer;
66066 +
66067 + // encryption/decryption KEY tables
66068 + CIPHER_KEY SharedKey[MAX_MBSSID_NUM][4]; // STA always use SharedKey[BSS0][0..3]
66069 +
66070 + // RX re-assembly buffer for fragmentation
66071 + FRAGMENT_FRAME FragFrame; // Frame storage for fragment frame
66072 +
66073 + // various Counters
66074 + COUNTER_802_3 Counters8023; // 802.3 counters
66075 + COUNTER_802_11 WlanCounters; // 802.11 MIB counters
66076 + COUNTER_RALINK RalinkCounters; // Ralink propriety counters
66077 + COUNTER_DRS DrsCounters; // counters for Dynamic TX Rate Switching
66078 + PRIVATE_STRUC PrivateInfo; // Private information & counters
66079 +
66080 + // flags, see fRTMP_ADAPTER_xxx flags
66081 + ULONG Flags; // Represent current device status
66082 +
66083 + // current TX sequence #
66084 + USHORT Sequence;
66085 +
66086 + // Control disconnect / connect event generation
66087 + //+++Didn't used anymore
66088 + ULONG LinkDownTime;
66089 + //---
66090 + ULONG LastRxRate;
66091 + ULONG LastTxRate;
66092 + //+++Used only for Station
66093 + BOOLEAN bConfigChanged; // Config Change flag for the same SSID setting
66094 + //---
66095 +
66096 + ULONG ExtraInfo; // Extra information for displaying status
66097 + ULONG SystemErrorBitmap; // b0: E2PROM version error
66098 +
66099 + //+++Didn't used anymore
66100 + ULONG MacIcVersion; // MAC/BBP serial interface issue solved after ver.D
66101 + //---
66102 +
66103 + // ---------------------------
66104 + // System event log
66105 + // ---------------------------
66106 + RT_802_11_EVENT_TABLE EventTab;
66107 +
66108 +
66109 + BOOLEAN HTCEnable;
66110 +
66111 + /*****************************************************************************************/
66112 + /* Statistic related parameters */
66113 + /*****************************************************************************************/
66114 +#ifdef RT2870
66115 + ULONG BulkOutDataOneSecCount;
66116 + ULONG BulkInDataOneSecCount;
66117 + ULONG BulkLastOneSecCount; // BulkOutDataOneSecCount + BulkInDataOneSecCount
66118 + ULONG watchDogRxCnt;
66119 + ULONG watchDogRxOverFlowCnt;
66120 + ULONG watchDogTxPendingCnt[NUM_OF_TX_RING];
66121 +#endif // RT2870 //
66122 +
66123 + BOOLEAN bUpdateBcnCntDone;
66124 + ULONG watchDogMacDeadlock; // prevent MAC/BBP into deadlock condition
66125 + // ----------------------------
66126 + // DEBUG paramerts
66127 + // ----------------------------
66128 + //ULONG DebugSetting[4];
66129 + BOOLEAN bBanAllBaSetup;
66130 + BOOLEAN bPromiscuous;
66131 +
66132 + // ----------------------------
66133 + // rt2860c emulation-use Parameters
66134 + // ----------------------------
66135 + ULONG rtsaccu[30];
66136 + ULONG ctsaccu[30];
66137 + ULONG cfendaccu[30];
66138 + ULONG bacontent[16];
66139 + ULONG rxint[RX_RING_SIZE+1];
66140 + UCHAR rcvba[60];
66141 + BOOLEAN bLinkAdapt;
66142 + BOOLEAN bForcePrintTX;
66143 + BOOLEAN bForcePrintRX;
66144 + BOOLEAN bDisablescanning; //defined in RT2870 USB
66145 + BOOLEAN bStaFifoTest;
66146 + BOOLEAN bProtectionTest;
66147 + BOOLEAN bHCCATest;
66148 + BOOLEAN bGenOneHCCA;
66149 + BOOLEAN bBroadComHT;
66150 + //+++Following add from RT2870 USB.
66151 + ULONG BulkOutReq;
66152 + ULONG BulkOutComplete;
66153 + ULONG BulkOutCompleteOther;
66154 + ULONG BulkOutCompleteCancel; // seems not use now?
66155 + ULONG BulkInReq;
66156 + ULONG BulkInComplete;
66157 + ULONG BulkInCompleteFail;
66158 + //---
66159 +
66160 + struct wificonf WIFItestbed;
66161 +
66162 +#ifdef RALINK_ATE
66163 + ATE_INFO ate;
66164 +#ifdef RT2870
66165 + BOOLEAN ContinBulkOut; //ATE bulk out control
66166 + BOOLEAN ContinBulkIn; //ATE bulk in control
66167 + atomic_t BulkOutRemained;
66168 + atomic_t BulkInRemained;
66169 +#endif // RT2870 //
66170 +#endif // RALINK_ATE //
66171 +
66172 +#ifdef DOT11_N_SUPPORT
66173 + struct reordering_mpdu_pool mpdu_blk_pool;
66174 +#endif // DOT11_N_SUPPORT //
66175 +
66176 + ULONG OneSecondnonBEpackets; // record non BE packets per second
66177 +
66178 +#if WIRELESS_EXT >= 12
66179 + struct iw_statistics iw_stats;
66180 +#endif
66181 +
66182 + struct net_device_stats stats;
66183 +
66184 +#ifdef BLOCK_NET_IF
66185 + BLOCK_QUEUE_ENTRY blockQueueTab[NUM_OF_TX_RING];
66186 +#endif // BLOCK_NET_IF //
66187 +
66188 +
66189 +
66190 +#ifdef MULTIPLE_CARD_SUPPORT
66191 + INT32 MC_RowID;
66192 + UCHAR MC_FileName[256];
66193 +#endif // MULTIPLE_CARD_SUPPORT //
66194 +
66195 + ULONG TbttTickCount;
66196 +#ifdef PCI_MSI_SUPPORT
66197 + BOOLEAN HaveMsi;
66198 +#endif // PCI_MSI_SUPPORT //
66199 +
66200 +
66201 + UCHAR is_on;
66202 +
66203 +#define TIME_BASE (1000000/OS_HZ)
66204 +#define TIME_ONE_SECOND (1000000/TIME_BASE)
66205 + UCHAR flg_be_adjust;
66206 + ULONG be_adjust_last_time;
66207 +
66208 +
66209 +#ifdef IKANOS_VX_1X0
66210 + struct IKANOS_TX_INFO IkanosTxInfo;
66211 + struct IKANOS_TX_INFO IkanosRxInfo[MAX_MBSSID_NUM + MAX_WDS_ENTRY + MAX_APCLI_NUM + MAX_MESH_NUM];
66212 +#endif // IKANOS_VX_1X0 //
66213 +
66214 +
66215 +#ifdef DBG_DIAGNOSE
66216 + RtmpDiagStruct DiagStruct;
66217 +#endif // DBG_DIAGNOSE //
66218 +
66219 +
66220 + UINT8 PM_FlgSuspend;
66221 +} RTMP_ADAPTER, *PRTMP_ADAPTER;
66222 +
66223 +//
66224 +// Cisco IAPP format
66225 +//
66226 +typedef struct _CISCO_IAPP_CONTENT_
66227 +{
66228 + USHORT Length; //IAPP Length
66229 + UCHAR MessageType; //IAPP type
66230 + UCHAR FunctionCode; //IAPP function type
66231 + UCHAR DestinaionMAC[MAC_ADDR_LEN];
66232 + UCHAR SourceMAC[MAC_ADDR_LEN];
66233 + USHORT Tag; //Tag(element IE) - Adjacent AP report
66234 + USHORT TagLength; //Length of element not including 4 byte header
66235 + UCHAR OUI[4]; //0x00, 0x40, 0x96, 0x00
66236 + UCHAR PreviousAP[MAC_ADDR_LEN]; //MAC Address of access point
66237 + USHORT Channel;
66238 + USHORT SsidLen;
66239 + UCHAR Ssid[MAX_LEN_OF_SSID];
66240 + USHORT Seconds; //Seconds that the client has been disassociated.
66241 +} CISCO_IAPP_CONTENT, *PCISCO_IAPP_CONTENT;
66242 +
66243 +#define DELAYINTMASK 0x0003fffb
66244 +#define INTMASK 0x0003fffb
66245 +#define IndMask 0x0003fffc
66246 +#define RxINT 0x00000005 // Delayed Rx or indivi rx
66247 +#define TxDataInt 0x000000fa // Delayed Tx or indivi tx
66248 +#define TxMgmtInt 0x00000102 // Delayed Tx or indivi tx
66249 +#define TxCoherent 0x00020000 // tx coherent
66250 +#define RxCoherent 0x00010000 // rx coherent
66251 +#define McuCommand 0x00000200 // mcu
66252 +#define PreTBTTInt 0x00001000 // Pre-TBTT interrupt
66253 +#define TBTTInt 0x00000800 // TBTT interrupt
66254 +#define GPTimeOutInt 0x00008000 // GPtimeout interrupt
66255 +#define AutoWakeupInt 0x00004000 // AutoWakeupInt interrupt
66256 +#define FifoStaFullInt 0x00002000 // fifo statistics full interrupt
66257 +
66258 +
66259 +typedef struct _RX_BLK_
66260 +{
66261 +// RXD_STRUC RxD; // sample
66262 + RT28XX_RXD_STRUC RxD;
66263 + PRXWI_STRUC pRxWI;
66264 + PHEADER_802_11 pHeader;
66265 + PNDIS_PACKET pRxPacket;
66266 + UCHAR *pData;
66267 + USHORT DataSize;
66268 + USHORT Flags;
66269 + UCHAR UserPriority; // for calculate TKIP MIC using
66270 +} RX_BLK;
66271 +
66272 +
66273 +#define RX_BLK_SET_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags |= _flag)
66274 +#define RX_BLK_TEST_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags & _flag)
66275 +#define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags &= ~(_flag))
66276 +
66277 +
66278 +#define fRX_WDS 0x0001
66279 +#define fRX_AMSDU 0x0002
66280 +#define fRX_ARALINK 0x0004
66281 +#define fRX_HTC 0x0008
66282 +#define fRX_PAD 0x0010
66283 +#define fRX_AMPDU 0x0020
66284 +#define fRX_QOS 0x0040
66285 +#define fRX_INFRA 0x0080
66286 +#define fRX_EAP 0x0100
66287 +#define fRX_MESH 0x0200
66288 +#define fRX_APCLI 0x0400
66289 +#define fRX_DLS 0x0800
66290 +#define fRX_WPI 0x1000
66291 +
66292 +#define LENGTH_AMSDU_SUBFRAMEHEAD 14
66293 +#define LENGTH_ARALINK_SUBFRAMEHEAD 14
66294 +#define LENGTH_ARALINK_HEADER_FIELD 2
66295 +
66296 +#define TX_UNKOWN_FRAME 0x00
66297 +#define TX_MCAST_FRAME 0x01
66298 +#define TX_LEGACY_FRAME 0x02
66299 +#define TX_AMPDU_FRAME 0x04
66300 +#define TX_AMSDU_FRAME 0x08
66301 +#define TX_RALINK_FRAME 0x10
66302 +#define TX_FRAG_FRAME 0x20
66303 +
66304 +
66305 +// Currently the sizeof(TX_BLK) is 148 bytes.
66306 +typedef struct _TX_BLK_
66307 +{
66308 + UCHAR QueIdx;
66309 + UCHAR TxFrameType; // Indicate the Transmission type of the all frames in one batch
66310 + UCHAR TotalFrameNum; // Total frame number want to send-out in one batch
66311 + USHORT TotalFragNum; // Total frame fragments required in one batch
66312 + USHORT TotalFrameLen; // Total length of all frames want to send-out in one batch
66313 +
66314 + QUEUE_HEADER TxPacketList;
66315 + MAC_TABLE_ENTRY *pMacEntry; // NULL: packet with 802.11 RA field is multicast/broadcast address
66316 + HTTRANSMIT_SETTING *pTransmit;
66317 +
66318 + // Following structure used for the characteristics of a specific packet.
66319 + PNDIS_PACKET pPacket;
66320 + PUCHAR pSrcBufHeader; // Reference to the head of sk_buff->data
66321 + PUCHAR pSrcBufData; // Reference to the sk_buff->data, will changed depends on hanlding progresss
66322 + UINT SrcBufLen; // Length of packet payload which not including Layer 2 header
66323 + PUCHAR pExtraLlcSnapEncap; // NULL means no extra LLC/SNAP is required
66324 + UCHAR HeaderBuf[80]; // TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP
66325 + UCHAR MpduHeaderLen; // 802.11 header length NOT including the padding
66326 + UCHAR HdrPadLen; // recording Header Padding Length;
66327 + UCHAR apidx; // The interface associated to this packet
66328 + UCHAR Wcid; // The MAC entry associated to this packet
66329 + UCHAR UserPriority; // priority class of packet
66330 + UCHAR FrameGap; // what kind of IFS this packet use
66331 + UCHAR MpduReqNum; // number of fragments of this frame
66332 + UCHAR TxRate; // TODO: Obsoleted? Should change to MCS?
66333 + UCHAR CipherAlg; // cipher alogrithm
66334 + PCIPHER_KEY pKey;
66335 +
66336 +
66337 +
66338 + USHORT Flags; //See following definitions for detail.
66339 +
66340 + //YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer.
66341 + ULONG Priv; // Hardware specific value saved in here.
66342 +} TX_BLK, *PTX_BLK;
66343 +
66344 +
66345 +#define fTX_bRtsRequired 0x0001 // Indicate if need send RTS frame for protection. Not used in RT2860/RT2870.
66346 +#define fTX_bAckRequired 0x0002 // the packet need ack response
66347 +#define fTX_bPiggyBack 0x0004 // Legacy device use Piggback or not
66348 +#define fTX_bHTRate 0x0008 // allow to use HT rate
66349 +//#define fTX_bForceLowRate 0x0010 // force to use Low Rate
66350 +#define fTX_bForceNonQoS 0x0010 // force to transmit frame without WMM-QoS in HT mode
66351 +#define fTX_bAllowFrag 0x0020 // allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment
66352 +#define fTX_bMoreData 0x0040 // there are more data packets in PowerSave Queue
66353 +#define fTX_bWMM 0x0080 // QOS Data
66354 +
66355 +#define fTX_bClearEAPFrame 0x0100
66356 +
66357 +
66358 +#ifdef CONFIG_STA_SUPPORT
66359 +#endif // CONFIG_STA_SUPPORT //
66360 +
66361 +
66362 +
66363 +#define TX_BLK_ASSIGN_FLAG(_pTxBlk, _flag, value) \
66364 + do { \
66365 + if (value) \
66366 + (_pTxBlk->Flags |= _flag) \
66367 + else \
66368 + (_pTxBlk->Flags &= ~(_flag)) \
66369 + }while(0)
66370 +
66371 +#define TX_BLK_SET_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags |= _flag)
66372 +#define TX_BLK_TEST_FLAG(_pTxBlk, _flag) (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
66373 +#define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags &= ~(_flag))
66374 +
66375 +
66376 +
66377 +
66378 +
66379 +//------------------------------------------------------------------------------------------
66380 +
66381 +
66382 +
66383 +#ifdef RT_BIG_ENDIAN
66384 +static inline VOID WriteBackToDescriptor(
66385 + IN PUCHAR Dest,
66386 + IN PUCHAR Src,
66387 + IN BOOLEAN DoEncrypt,
66388 + IN ULONG DescriptorType)
66389 +{
66390 + UINT32 *p1, *p2;
66391 +
66392 + p1 = ((UINT32 *)Dest);
66393 + p2 = ((UINT32 *)Src);
66394 +
66395 + *p1 = *p2;
66396 + *(p1+2) = *(p2+2);
66397 + *(p1+3) = *(p2+3);
66398 + *(p1+1) = *(p2+1); // Word 1; this must be written back last
66399 +}
66400 +
66401 +/*
66402 + ========================================================================
66403 +
66404 + Routine Description:
66405 + Endian conversion of Tx/Rx descriptor .
66406 +
66407 + Arguments:
66408 + pAd Pointer to our adapter
66409 + pData Pointer to Tx/Rx descriptor
66410 + DescriptorType Direction of the frame
66411 +
66412 + Return Value:
66413 + None
66414 +
66415 + Note:
66416 + Call this function when read or update descriptor
66417 + ========================================================================
66418 +*/
66419 +static inline VOID RTMPWIEndianChange(
66420 + IN PUCHAR pData,
66421 + IN ULONG DescriptorType)
66422 +{
66423 + int size;
66424 + int i;
66425 +
66426 + size = ((DescriptorType == TYPE_TXWI) ? TXWI_SIZE : RXWI_SIZE);
66427 +
66428 + if(DescriptorType == TYPE_TXWI)
66429 + {
66430 + *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData))); // Byte 0~3
66431 + *((UINT32 *)(pData + 4)) = SWAP32(*((UINT32 *)(pData+4))); // Byte 4~7
66432 + }
66433 + else
66434 + {
66435 + for(i=0; i < size/4 ; i++)
66436 + *(((UINT32 *)pData) +i) = SWAP32(*(((UINT32 *)pData)+i));
66437 + }
66438 +}
66439 +
66440 +/*
66441 + ========================================================================
66442 +
66443 + Routine Description:
66444 + Endian conversion of Tx/Rx descriptor .
66445 +
66446 + Arguments:
66447 + pAd Pointer to our adapter
66448 + pData Pointer to Tx/Rx descriptor
66449 + DescriptorType Direction of the frame
66450 +
66451 + Return Value:
66452 + None
66453 +
66454 + Note:
66455 + Call this function when read or update descriptor
66456 + ========================================================================
66457 +*/
66458 +
66459 +#ifdef RT2870
66460 +static inline VOID RTMPDescriptorEndianChange(
66461 + IN PUCHAR pData,
66462 + IN ULONG DescriptorType)
66463 +{
66464 + *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData)));
66465 +}
66466 +#endif // RT2870 //
66467 +/*
66468 + ========================================================================
66469 +
66470 + Routine Description:
66471 + Endian conversion of all kinds of 802.11 frames .
66472 +
66473 + Arguments:
66474 + pAd Pointer to our adapter
66475 + pData Pointer to the 802.11 frame structure
66476 + Dir Direction of the frame
66477 + FromRxDoneInt Caller is from RxDone interrupt
66478 +
66479 + Return Value:
66480 + None
66481 +
66482 + Note:
66483 + Call this function when read or update buffer data
66484 + ========================================================================
66485 +*/
66486 +static inline VOID RTMPFrameEndianChange(
66487 + IN PRTMP_ADAPTER pAd,
66488 + IN PUCHAR pData,
66489 + IN ULONG Dir,
66490 + IN BOOLEAN FromRxDoneInt)
66491 +{
66492 + PHEADER_802_11 pFrame;
66493 + PUCHAR pMacHdr;
66494 +
66495 + // swab 16 bit fields - Frame Control field
66496 + if(Dir == DIR_READ)
66497 + {
66498 + *(USHORT *)pData = SWAP16(*(USHORT *)pData);
66499 + }
66500 +
66501 + pFrame = (PHEADER_802_11) pData;
66502 + pMacHdr = (PUCHAR) pFrame;
66503 +
66504 + // swab 16 bit fields - Duration/ID field
66505 + *(USHORT *)(pMacHdr + 2) = SWAP16(*(USHORT *)(pMacHdr + 2));
66506 +
66507 + // swab 16 bit fields - Sequence Control field
66508 + *(USHORT *)(pMacHdr + 22) = SWAP16(*(USHORT *)(pMacHdr + 22));
66509 +
66510 + if(pFrame->FC.Type == BTYPE_MGMT)
66511 + {
66512 + switch(pFrame->FC.SubType)
66513 + {
66514 + case SUBTYPE_ASSOC_REQ:
66515 + case SUBTYPE_REASSOC_REQ:
66516 + // swab 16 bit fields - CapabilityInfo field
66517 + pMacHdr += sizeof(HEADER_802_11);
66518 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66519 +
66520 + // swab 16 bit fields - Listen Interval field
66521 + pMacHdr += 2;
66522 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66523 + break;
66524 +
66525 + case SUBTYPE_ASSOC_RSP:
66526 + case SUBTYPE_REASSOC_RSP:
66527 + // swab 16 bit fields - CapabilityInfo field
66528 + pMacHdr += sizeof(HEADER_802_11);
66529 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66530 +
66531 + // swab 16 bit fields - Status Code field
66532 + pMacHdr += 2;
66533 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66534 +
66535 + // swab 16 bit fields - AID field
66536 + pMacHdr += 2;
66537 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66538 + break;
66539 +
66540 + case SUBTYPE_AUTH:
66541 + // If from APHandleRxDoneInterrupt routine, it is still a encrypt format.
66542 + // The convertion is delayed to RTMPHandleDecryptionDoneInterrupt.
66543 + if(!FromRxDoneInt && pFrame->FC.Wep == 1)
66544 + break;
66545 + else
66546 + {
66547 + // swab 16 bit fields - Auth Alg No. field
66548 + pMacHdr += sizeof(HEADER_802_11);
66549 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66550 +
66551 + // swab 16 bit fields - Auth Seq No. field
66552 + pMacHdr += 2;
66553 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66554 +
66555 + // swab 16 bit fields - Status Code field
66556 + pMacHdr += 2;
66557 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66558 + }
66559 + break;
66560 +
66561 + case SUBTYPE_BEACON:
66562 + case SUBTYPE_PROBE_RSP:
66563 + // swab 16 bit fields - BeaconInterval field
66564 + pMacHdr += (sizeof(HEADER_802_11) + TIMESTAMP_LEN);
66565 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66566 +
66567 + // swab 16 bit fields - CapabilityInfo field
66568 + pMacHdr += sizeof(USHORT);
66569 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66570 + break;
66571 +
66572 + case SUBTYPE_DEAUTH:
66573 + case SUBTYPE_DISASSOC:
66574 + // swab 16 bit fields - Reason code field
66575 + pMacHdr += sizeof(HEADER_802_11);
66576 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
66577 + break;
66578 + }
66579 + }
66580 + else if( pFrame->FC.Type == BTYPE_DATA )
66581 + {
66582 + }
66583 + else if(pFrame->FC.Type == BTYPE_CNTL)
66584 + {
66585 + switch(pFrame->FC.SubType)
66586 + {
66587 + case SUBTYPE_BLOCK_ACK_REQ:
66588 + {
66589 + PFRAME_BA_REQ pBAReq = (PFRAME_BA_REQ)pFrame;
66590 + *(USHORT *)(&pBAReq->BARControl) = SWAP16(*(USHORT *)(&pBAReq->BARControl));
66591 + pBAReq->BAStartingSeq.word = SWAP16(pBAReq->BAStartingSeq.word);
66592 + }
66593 + break;
66594 + case SUBTYPE_BLOCK_ACK:
66595 + // For Block Ack packet, the HT_CONTROL field is in the same offset with Addr3
66596 + *(UINT32 *)(&pFrame->Addr3[0]) = SWAP32(*(UINT32 *)(&pFrame->Addr3[0]));
66597 + break;
66598 +
66599 + case SUBTYPE_ACK:
66600 + //For ACK packet, the HT_CONTROL field is in the same offset with Addr2
66601 + *(UINT32 *)(&pFrame->Addr2[0])= SWAP32(*(UINT32 *)(&pFrame->Addr2[0]));
66602 + break;
66603 + }
66604 + }
66605 + else
66606 + {
66607 + DBGPRINT(RT_DEBUG_ERROR,("Invalid Frame Type!!!\n"));
66608 + }
66609 +
66610 + // swab 16 bit fields - Frame Control
66611 + if(Dir == DIR_WRITE)
66612 + {
66613 + *(USHORT *)pData = SWAP16(*(USHORT *)pData);
66614 + }
66615 +}
66616 +#endif // RT_BIG_ENDIAN //
66617 +
66618 +
66619 +static inline VOID ConvertMulticastIP2MAC(
66620 + IN PUCHAR pIpAddr,
66621 + IN PUCHAR *ppMacAddr,
66622 + IN UINT16 ProtoType)
66623 +{
66624 + if (pIpAddr == NULL)
66625 + return;
66626 +
66627 + if (ppMacAddr == NULL || *ppMacAddr == NULL)
66628 + return;
66629 +
66630 + switch (ProtoType)
66631 + {
66632 + case ETH_P_IPV6:
66633 +// memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
66634 + *(*ppMacAddr) = 0x33;
66635 + *(*ppMacAddr + 1) = 0x33;
66636 + *(*ppMacAddr + 2) = pIpAddr[12];
66637 + *(*ppMacAddr + 3) = pIpAddr[13];
66638 + *(*ppMacAddr + 4) = pIpAddr[14];
66639 + *(*ppMacAddr + 5) = pIpAddr[15];
66640 + break;
66641 +
66642 + case ETH_P_IP:
66643 + default:
66644 +// memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
66645 + *(*ppMacAddr) = 0x01;
66646 + *(*ppMacAddr + 1) = 0x00;
66647 + *(*ppMacAddr + 2) = 0x5e;
66648 + *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
66649 + *(*ppMacAddr + 4) = pIpAddr[2];
66650 + *(*ppMacAddr + 5) = pIpAddr[3];
66651 + break;
66652 + }
66653 +
66654 + return;
66655 +}
66656 +
66657 +BOOLEAN RTMPCheckForHang(
66658 + IN NDIS_HANDLE MiniportAdapterContext
66659 + );
66660 +
66661 +VOID RTMPHalt(
66662 + IN NDIS_HANDLE MiniportAdapterContext
66663 + );
66664 +
66665 +//
66666 +// Private routines in rtmp_init.c
66667 +//
66668 +NDIS_STATUS RTMPAllocAdapterBlock(
66669 + IN PVOID handle,
66670 + OUT PRTMP_ADAPTER *ppAdapter
66671 + );
66672 +
66673 +NDIS_STATUS RTMPAllocTxRxRingMemory(
66674 + IN PRTMP_ADAPTER pAd
66675 + );
66676 +
66677 +NDIS_STATUS RTMPFindAdapter(
66678 + IN PRTMP_ADAPTER pAd,
66679 + IN NDIS_HANDLE WrapperConfigurationContext
66680 + );
66681 +
66682 +NDIS_STATUS RTMPReadParametersHook(
66683 + IN PRTMP_ADAPTER pAd
66684 + );
66685 +
66686 +VOID RTMPFreeAdapter(
66687 + IN PRTMP_ADAPTER pAd
66688 + );
66689 +
66690 +NDIS_STATUS NICReadRegParameters(
66691 + IN PRTMP_ADAPTER pAd,
66692 + IN NDIS_HANDLE WrapperConfigurationContext
66693 + );
66694 +
66695 +#ifdef RT2870
66696 +VOID NICInitRT30xxRFRegisters(
66697 + IN PRTMP_ADAPTER pAd);
66698 +#endif // RT2870 //
66699 +
66700 +VOID NICReadEEPROMParameters(
66701 + IN PRTMP_ADAPTER pAd,
66702 + IN PUCHAR mac_addr);
66703 +
66704 +VOID NICInitAsicFromEEPROM(
66705 + IN PRTMP_ADAPTER pAd);
66706 +
66707 +VOID NICInitTxRxRingAndBacklogQueue(
66708 + IN PRTMP_ADAPTER pAd);
66709 +
66710 +NDIS_STATUS NICInitializeAdapter(
66711 + IN PRTMP_ADAPTER pAd,
66712 + IN BOOLEAN bHardReset);
66713 +
66714 +NDIS_STATUS NICInitializeAsic(
66715 + IN PRTMP_ADAPTER pAd,
66716 + IN BOOLEAN bHardReset);
66717 +
66718 +VOID NICIssueReset(
66719 + IN PRTMP_ADAPTER pAd);
66720 +
66721 +VOID RTMPRingCleanUp(
66722 + IN PRTMP_ADAPTER pAd,
66723 + IN UCHAR RingType);
66724 +
66725 +VOID RxTest(
66726 + IN PRTMP_ADAPTER pAd);
66727 +
66728 +NDIS_STATUS DbgSendPacket(
66729 + IN PRTMP_ADAPTER pAd,
66730 + IN PNDIS_PACKET pPacket);
66731 +
66732 +VOID UserCfgInit(
66733 + IN PRTMP_ADAPTER pAd);
66734 +
66735 +VOID NICResetFromError(
66736 + IN PRTMP_ADAPTER pAd);
66737 +
66738 +VOID NICEraseFirmware(
66739 + IN PRTMP_ADAPTER pAd);
66740 +
66741 +NDIS_STATUS NICLoadFirmware(
66742 + IN PRTMP_ADAPTER pAd);
66743 +
66744 +NDIS_STATUS NICLoadRateSwitchingParams(
66745 + IN PRTMP_ADAPTER pAd);
66746 +
66747 +BOOLEAN NICCheckForHang(
66748 + IN PRTMP_ADAPTER pAd);
66749 +
66750 +VOID NICUpdateFifoStaCounters(
66751 + IN PRTMP_ADAPTER pAd);
66752 +
66753 +VOID NICUpdateRawCounters(
66754 + IN PRTMP_ADAPTER pAd);
66755 +
66756 +#if 0
66757 +ULONG RTMPEqualMemory(
66758 + IN PVOID pSrc1,
66759 + IN PVOID pSrc2,
66760 + IN ULONG Length);
66761 +#endif
66762 +
66763 +ULONG RTMPNotAllZero(
66764 + IN PVOID pSrc1,
66765 + IN ULONG Length);
66766 +
66767 +VOID RTMPZeroMemory(
66768 + IN PVOID pSrc,
66769 + IN ULONG Length);
66770 +
66771 +ULONG RTMPCompareMemory(
66772 + IN PVOID pSrc1,
66773 + IN PVOID pSrc2,
66774 + IN ULONG Length);
66775 +
66776 +VOID RTMPMoveMemory(
66777 + OUT PVOID pDest,
66778 + IN PVOID pSrc,
66779 + IN ULONG Length);
66780 +
66781 +VOID AtoH(
66782 + char *src,
66783 + UCHAR *dest,
66784 + int destlen);
66785 +
66786 +UCHAR BtoH(
66787 + char ch);
66788 +
66789 +VOID RTMPPatchMacBbpBug(
66790 + IN PRTMP_ADAPTER pAd);
66791 +
66792 +VOID RTMPPatchCardBus(
66793 + IN PRTMP_ADAPTER pAdapter);
66794 +
66795 +VOID RTMPPatchRalinkCardBus(
66796 + IN PRTMP_ADAPTER pAdapter,
66797 + IN ULONG Bus);
66798 +
66799 +ULONG RTMPReadCBConfig(
66800 + IN ULONG Bus,
66801 + IN ULONG Slot,
66802 + IN ULONG Func,
66803 + IN ULONG Offset);
66804 +
66805 +VOID RTMPWriteCBConfig(
66806 + IN ULONG Bus,
66807 + IN ULONG Slot,
66808 + IN ULONG Func,
66809 + IN ULONG Offset,
66810 + IN ULONG Value);
66811 +
66812 +VOID RTMPInitTimer(
66813 + IN PRTMP_ADAPTER pAd,
66814 + IN PRALINK_TIMER_STRUCT pTimer,
66815 + IN PVOID pTimerFunc,
66816 + IN PVOID pData,
66817 + IN BOOLEAN Repeat);
66818 +
66819 +VOID RTMPSetTimer(
66820 + IN PRALINK_TIMER_STRUCT pTimer,
66821 + IN ULONG Value);
66822 +
66823 +
66824 +VOID RTMPModTimer(
66825 + IN PRALINK_TIMER_STRUCT pTimer,
66826 + IN ULONG Value);
66827 +
66828 +VOID RTMPCancelTimer(
66829 + IN PRALINK_TIMER_STRUCT pTimer,
66830 + OUT BOOLEAN *pCancelled);
66831 +
66832 +VOID RTMPSetLED(
66833 + IN PRTMP_ADAPTER pAd,
66834 + IN UCHAR Status);
66835 +
66836 +VOID RTMPSetSignalLED(
66837 + IN PRTMP_ADAPTER pAd,
66838 + IN NDIS_802_11_RSSI Dbm);
66839 +
66840 +VOID RTMPEnableRxTx(
66841 + IN PRTMP_ADAPTER pAd);
66842 +
66843 +//
66844 +// prototype in action.c
66845 +//
66846 +VOID ActionStateMachineInit(
66847 + IN PRTMP_ADAPTER pAd,
66848 + IN STATE_MACHINE *S,
66849 + OUT STATE_MACHINE_FUNC Trans[]);
66850 +
66851 +VOID MlmeADDBAAction(
66852 + IN PRTMP_ADAPTER pAd,
66853 + IN MLME_QUEUE_ELEM *Elem);
66854 +
66855 +VOID MlmeDELBAAction(
66856 + IN PRTMP_ADAPTER pAd,
66857 + IN MLME_QUEUE_ELEM *Elem);
66858 +
66859 +VOID MlmeDLSAction(
66860 + IN PRTMP_ADAPTER pAd,
66861 + IN MLME_QUEUE_ELEM *Elem);
66862 +
66863 +VOID MlmeInvalidAction(
66864 + IN PRTMP_ADAPTER pAd,
66865 + IN MLME_QUEUE_ELEM *Elem);
66866 +
66867 +VOID MlmeQOSAction(
66868 + IN PRTMP_ADAPTER pAd,
66869 + IN MLME_QUEUE_ELEM *Elem);
66870 +
66871 +#ifdef DOT11_N_SUPPORT
66872 +VOID PeerAddBAReqAction(
66873 + IN PRTMP_ADAPTER pAd,
66874 + IN MLME_QUEUE_ELEM *Elem);
66875 +
66876 +VOID PeerAddBARspAction(
66877 + IN PRTMP_ADAPTER pAd,
66878 + IN MLME_QUEUE_ELEM *Elem);
66879 +
66880 +VOID PeerDelBAAction(
66881 + IN PRTMP_ADAPTER pAd,
66882 + IN MLME_QUEUE_ELEM *Elem);
66883 +
66884 +VOID PeerBAAction(
66885 + IN PRTMP_ADAPTER pAd,
66886 + IN MLME_QUEUE_ELEM *Elem);
66887 +#endif // DOT11_N_SUPPORT //
66888 +
66889 +VOID SendPSMPAction(
66890 + IN PRTMP_ADAPTER pAd,
66891 + IN UCHAR Wcid,
66892 + IN UCHAR Psmp);
66893 +
66894 +
66895 +#ifdef DOT11N_DRAFT3
66896 +VOID SendBSS2040CoexistMgmtAction(
66897 + IN PRTMP_ADAPTER pAd,
66898 + IN UCHAR Wcid,
66899 + IN UCHAR apidx,
66900 + IN UCHAR InfoReq);
66901 +
66902 +VOID SendNotifyBWActionFrame(
66903 + IN PRTMP_ADAPTER pAd,
66904 + IN UCHAR Wcid,
66905 + IN UCHAR apidx);
66906 +
66907 +BOOLEAN ChannelSwitchSanityCheck(
66908 + IN PRTMP_ADAPTER pAd,
66909 + IN UCHAR Wcid,
66910 + IN UCHAR NewChannel,
66911 + IN UCHAR Secondary);
66912 +
66913 +VOID ChannelSwitchAction(
66914 + IN PRTMP_ADAPTER pAd,
66915 + IN UCHAR Wcid,
66916 + IN UCHAR Channel,
66917 + IN UCHAR Secondary);
66918 +
66919 +ULONG BuildIntolerantChannelRep(
66920 + IN PRTMP_ADAPTER pAd,
66921 + IN PUCHAR pDest);
66922 +
66923 +VOID Update2040CoexistFrameAndNotify(
66924 + IN PRTMP_ADAPTER pAd,
66925 + IN UCHAR Wcid,
66926 + IN BOOLEAN bAddIntolerantCha);
66927 +
66928 +VOID Send2040CoexistAction(
66929 + IN PRTMP_ADAPTER pAd,
66930 + IN UCHAR Wcid,
66931 + IN BOOLEAN bAddIntolerantCha);
66932 +#endif // DOT11N_DRAFT3 //
66933 +
66934 +VOID PeerRMAction(
66935 + IN PRTMP_ADAPTER pAd,
66936 + IN MLME_QUEUE_ELEM *Elem);
66937 +
66938 +VOID PeerPublicAction(
66939 + IN PRTMP_ADAPTER pAd,
66940 + IN MLME_QUEUE_ELEM *Elem);
66941 +
66942 +#ifdef CONFIG_STA_SUPPORT
66943 +VOID StaPublicAction(
66944 + IN PRTMP_ADAPTER pAd,
66945 + IN UCHAR Bss2040Coexist);
66946 +#endif // CONFIG_STA_SUPPORT //
66947 +
66948 +
66949 +VOID PeerBSSTranAction(
66950 + IN PRTMP_ADAPTER pAd,
66951 + IN MLME_QUEUE_ELEM *Elem);
66952 +
66953 +#ifdef DOT11_N_SUPPORT
66954 +VOID PeerHTAction(
66955 + IN PRTMP_ADAPTER pAd,
66956 + IN MLME_QUEUE_ELEM *Elem);
66957 +#endif // DOT11_N_SUPPORT //
66958 +
66959 +VOID PeerQOSAction(
66960 + IN PRTMP_ADAPTER pAd,
66961 + IN MLME_QUEUE_ELEM *Elem);
66962 +
66963 +#ifdef QOS_DLS_SUPPORT
66964 +VOID PeerDLSAction(
66965 + IN PRTMP_ADAPTER pAd,
66966 + IN MLME_QUEUE_ELEM *Elem);
66967 +#endif // QOS_DLS_SUPPORT //
66968 +
66969 +#ifdef CONFIG_STA_SUPPORT
66970 +#ifdef QOS_DLS_SUPPORT
66971 +VOID DlsParmFill(
66972 + IN PRTMP_ADAPTER pAd,
66973 + IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
66974 + IN PRT_802_11_DLS pDls,
66975 + IN USHORT reason);
66976 +#endif // QOS_DLS_SUPPORT //
66977 +#endif // CONFIG_STA_SUPPORT //
66978 +
66979 +#ifdef DOT11_N_SUPPORT
66980 +VOID RECBATimerTimeout(
66981 + IN PVOID SystemSpecific1,
66982 + IN PVOID FunctionContext,
66983 + IN PVOID SystemSpecific2,
66984 + IN PVOID SystemSpecific3);
66985 +
66986 +VOID ORIBATimerTimeout(
66987 + IN PRTMP_ADAPTER pAd);
66988 +
66989 +VOID SendRefreshBAR(
66990 + IN PRTMP_ADAPTER pAd,
66991 + IN MAC_TABLE_ENTRY *pEntry);
66992 +#endif // DOT11_N_SUPPORT //
66993 +
66994 +VOID ActHeaderInit(
66995 + IN PRTMP_ADAPTER pAd,
66996 + IN OUT PHEADER_802_11 pHdr80211,
66997 + IN PUCHAR Addr1,
66998 + IN PUCHAR Addr2,
66999 + IN PUCHAR Addr3);
67000 +
67001 +VOID BarHeaderInit(
67002 + IN PRTMP_ADAPTER pAd,
67003 + IN OUT PFRAME_BAR pCntlBar,
67004 + IN PUCHAR pDA,
67005 + IN PUCHAR pSA);
67006 +
67007 +VOID InsertActField(
67008 + IN PRTMP_ADAPTER pAd,
67009 + OUT PUCHAR pFrameBuf,
67010 + OUT PULONG pFrameLen,
67011 + IN UINT8 Category,
67012 + IN UINT8 ActCode);
67013 +
67014 +BOOLEAN QosBADataParse(
67015 + IN PRTMP_ADAPTER pAd,
67016 + IN BOOLEAN bAMSDU,
67017 + IN PUCHAR p8023Header,
67018 + IN UCHAR WCID,
67019 + IN UCHAR TID,
67020 + IN USHORT Sequence,
67021 + IN UCHAR DataOffset,
67022 + IN USHORT Datasize,
67023 + IN UINT CurRxIndex);
67024 +
67025 +#ifdef DOT11_N_SUPPORT
67026 +BOOLEAN CntlEnqueueForRecv(
67027 + IN PRTMP_ADAPTER pAd,
67028 + IN ULONG Wcid,
67029 + IN ULONG MsgLen,
67030 + IN PFRAME_BA_REQ pMsg);
67031 +
67032 +VOID BaAutoManSwitch(
67033 + IN PRTMP_ADAPTER pAd);
67034 +#endif // DOT11_N_SUPPORT //
67035 +
67036 +VOID HTIOTCheck(
67037 + IN PRTMP_ADAPTER pAd,
67038 + IN UCHAR BatRecIdx);
67039 +
67040 +//
67041 +// Private routines in rtmp_data.c
67042 +//
67043 +BOOLEAN RTMPHandleRxDoneInterrupt(
67044 + IN PRTMP_ADAPTER pAd);
67045 +
67046 +VOID RTMPHandleTxDoneInterrupt(
67047 + IN PRTMP_ADAPTER pAd);
67048 +
67049 +BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(
67050 + IN PRTMP_ADAPTER pAd,
67051 + IN INT_SOURCE_CSR_STRUC TxRingBitmap);
67052 +
67053 +VOID RTMPHandleMgmtRingDmaDoneInterrupt(
67054 + IN PRTMP_ADAPTER pAd);
67055 +
67056 +VOID RTMPHandleTBTTInterrupt(
67057 + IN PRTMP_ADAPTER pAd);
67058 +
67059 +VOID RTMPHandlePreTBTTInterrupt(
67060 + IN PRTMP_ADAPTER pAd);
67061 +
67062 +void RTMPHandleTwakeupInterrupt(
67063 + IN PRTMP_ADAPTER pAd);
67064 +
67065 +VOID RTMPHandleRxCoherentInterrupt(
67066 + IN PRTMP_ADAPTER pAd);
67067 +
67068 +BOOLEAN TxFrameIsAggregatible(
67069 + IN PRTMP_ADAPTER pAd,
67070 + IN PUCHAR pPrevAddr1,
67071 + IN PUCHAR p8023hdr);
67072 +
67073 +BOOLEAN PeerIsAggreOn(
67074 + IN PRTMP_ADAPTER pAd,
67075 + IN ULONG TxRate,
67076 + IN PMAC_TABLE_ENTRY pMacEntry);
67077 +
67078 +#if 0 // It's not be used
67079 +HTTRANSMIT_SETTING *GetTxMode(
67080 + IN PRTMP_ADAPTER pAd,
67081 + IN TX_BLK *pTxBlk);
67082 +#endif
67083 +
67084 +NDIS_STATUS Sniff2BytesFromNdisBuffer(
67085 + IN PNDIS_BUFFER pFirstBuffer,
67086 + IN UCHAR DesiredOffset,
67087 + OUT PUCHAR pByte0,
67088 + OUT PUCHAR pByte1);
67089 +
67090 +NDIS_STATUS STASendPacket(
67091 + IN PRTMP_ADAPTER pAd,
67092 + IN PNDIS_PACKET pPacket);
67093 +
67094 +VOID STASendPackets(
67095 + IN NDIS_HANDLE MiniportAdapterContext,
67096 + IN PPNDIS_PACKET ppPacketArray,
67097 + IN UINT NumberOfPackets);
67098 +
67099 +VOID RTMPDeQueuePacket(
67100 + IN PRTMP_ADAPTER pAd,
67101 + IN BOOLEAN bIntContext,
67102 + IN UCHAR QueIdx,
67103 + IN UCHAR Max_Tx_Packets);
67104 +
67105 +NDIS_STATUS RTMPHardTransmit(
67106 + IN PRTMP_ADAPTER pAd,
67107 + IN PNDIS_PACKET pPacket,
67108 + IN UCHAR QueIdx,
67109 + OUT PULONG pFreeTXDLeft);
67110 +
67111 +NDIS_STATUS STAHardTransmit(
67112 + IN PRTMP_ADAPTER pAd,
67113 + IN TX_BLK *pTxBlk,
67114 + IN UCHAR QueIdx);
67115 +
67116 +VOID STARxEAPOLFrameIndicate(
67117 + IN PRTMP_ADAPTER pAd,
67118 + IN MAC_TABLE_ENTRY *pEntry,
67119 + IN RX_BLK *pRxBlk,
67120 + IN UCHAR FromWhichBSSID);
67121 +
67122 +NDIS_STATUS RTMPFreeTXDRequest(
67123 + IN PRTMP_ADAPTER pAd,
67124 + IN UCHAR RingType,
67125 + IN UCHAR NumberRequired,
67126 + IN PUCHAR FreeNumberIs);
67127 +
67128 +NDIS_STATUS MlmeHardTransmit(
67129 + IN PRTMP_ADAPTER pAd,
67130 + IN UCHAR QueIdx,
67131 + IN PNDIS_PACKET pPacket);
67132 +
67133 +NDIS_STATUS MlmeHardTransmitMgmtRing(
67134 + IN PRTMP_ADAPTER pAd,
67135 + IN UCHAR QueIdx,
67136 + IN PNDIS_PACKET pPacket);
67137 +
67138 +NDIS_STATUS MlmeHardTransmitTxRing(
67139 + IN PRTMP_ADAPTER pAd,
67140 + IN UCHAR QueIdx,
67141 + IN PNDIS_PACKET pPacket);
67142 +
67143 +USHORT RTMPCalcDuration(
67144 + IN PRTMP_ADAPTER pAd,
67145 + IN UCHAR Rate,
67146 + IN ULONG Size);
67147 +
67148 +VOID RTMPWriteTxWI(
67149 + IN PRTMP_ADAPTER pAd,
67150 + IN PTXWI_STRUC pTxWI,
67151 + IN BOOLEAN FRAG,
67152 + IN BOOLEAN CFACK,
67153 + IN BOOLEAN InsTimestamp,
67154 + IN BOOLEAN AMPDU,
67155 + IN BOOLEAN Ack,
67156 + IN BOOLEAN NSeq, // HW new a sequence.
67157 + IN UCHAR BASize,
67158 + IN UCHAR WCID,
67159 + IN ULONG Length,
67160 + IN UCHAR PID,
67161 + IN UCHAR TID,
67162 + IN UCHAR TxRate,
67163 + IN UCHAR Txopmode,
67164 + IN BOOLEAN CfAck,
67165 + IN HTTRANSMIT_SETTING *pTransmit);
67166 +
67167 +
67168 +VOID RTMPWriteTxWI_Data(
67169 + IN PRTMP_ADAPTER pAd,
67170 + IN OUT PTXWI_STRUC pTxWI,
67171 + IN TX_BLK *pTxBlk);
67172 +
67173 +
67174 +VOID RTMPWriteTxWI_Cache(
67175 + IN PRTMP_ADAPTER pAd,
67176 + IN OUT PTXWI_STRUC pTxWI,
67177 + IN TX_BLK *pTxBlk);
67178 +
67179 +VOID RTMPWriteTxDescriptor(
67180 + IN PRTMP_ADAPTER pAd,
67181 + IN PTXD_STRUC pTxD,
67182 + IN BOOLEAN bWIV,
67183 + IN UCHAR QSEL);
67184 +
67185 +VOID RTMPSuspendMsduTransmission(
67186 + IN PRTMP_ADAPTER pAd);
67187 +
67188 +VOID RTMPResumeMsduTransmission(
67189 + IN PRTMP_ADAPTER pAd);
67190 +
67191 +NDIS_STATUS MiniportMMRequest(
67192 + IN PRTMP_ADAPTER pAd,
67193 + IN UCHAR QueIdx,
67194 + IN PUCHAR pData,
67195 + IN UINT Length);
67196 +
67197 +NDIS_STATUS MiniportDataMMRequest(
67198 + IN PRTMP_ADAPTER pAd,
67199 + IN UCHAR QueIdx,
67200 + IN PUCHAR pData,
67201 + IN UINT Length);
67202 +
67203 +VOID RTMPSendNullFrame(
67204 + IN PRTMP_ADAPTER pAd,
67205 + IN UCHAR TxRate,
67206 + IN BOOLEAN bQosNull);
67207 +
67208 +VOID RTMPSendDisassociationFrame(
67209 + IN PRTMP_ADAPTER pAd);
67210 +
67211 +VOID RTMPSendRTSFrame(
67212 + IN PRTMP_ADAPTER pAd,
67213 + IN PUCHAR pDA,
67214 + IN unsigned int NextMpduSize,
67215 + IN UCHAR TxRate,
67216 + IN UCHAR RTSRate,
67217 + IN USHORT AckDuration,
67218 + IN UCHAR QueIdx,
67219 + IN UCHAR FrameGap);
67220 +
67221 +
67222 +NDIS_STATUS RTMPApplyPacketFilter(
67223 + IN PRTMP_ADAPTER pAd,
67224 + IN PRT28XX_RXD_STRUC pRxD,
67225 + IN PHEADER_802_11 pHeader);
67226 +
67227 +PQUEUE_HEADER RTMPCheckTxSwQueue(
67228 + IN PRTMP_ADAPTER pAd,
67229 + OUT UCHAR *QueIdx);
67230 +
67231 +#ifdef CONFIG_STA_SUPPORT
67232 +VOID RTMPReportMicError(
67233 + IN PRTMP_ADAPTER pAd,
67234 + IN PCIPHER_KEY pWpaKey);
67235 +
67236 +VOID WpaMicFailureReportFrame(
67237 + IN PRTMP_ADAPTER pAd,
67238 + IN MLME_QUEUE_ELEM *Elem);
67239 +
67240 +VOID WpaDisassocApAndBlockAssoc(
67241 + IN PVOID SystemSpecific1,
67242 + IN PVOID FunctionContext,
67243 + IN PVOID SystemSpecific2,
67244 + IN PVOID SystemSpecific3);
67245 +#endif // CONFIG_STA_SUPPORT //
67246 +
67247 +NDIS_STATUS RTMPCloneNdisPacket(
67248 + IN PRTMP_ADAPTER pAd,
67249 + IN BOOLEAN pInsAMSDUHdr,
67250 + IN PNDIS_PACKET pInPacket,
67251 + OUT PNDIS_PACKET *ppOutPacket);
67252 +
67253 +NDIS_STATUS RTMPAllocateNdisPacket(
67254 + IN PRTMP_ADAPTER pAd,
67255 + IN PNDIS_PACKET *pPacket,
67256 + IN PUCHAR pHeader,
67257 + IN UINT HeaderLen,
67258 + IN PUCHAR pData,
67259 + IN UINT DataLen);
67260 +
67261 +VOID RTMPFreeNdisPacket(
67262 + IN PRTMP_ADAPTER pAd,
67263 + IN PNDIS_PACKET pPacket);
67264 +
67265 +BOOLEAN RTMPFreeTXDUponTxDmaDone(
67266 + IN PRTMP_ADAPTER pAd,
67267 + IN UCHAR QueIdx);
67268 +
67269 +BOOLEAN RTMPCheckDHCPFrame(
67270 + IN PRTMP_ADAPTER pAd,
67271 + IN PNDIS_PACKET pPacket);
67272 +
67273 +
67274 +BOOLEAN RTMPCheckEtherType(
67275 + IN PRTMP_ADAPTER pAd,
67276 + IN PNDIS_PACKET pPacket);
67277 +
67278 +
67279 +VOID RTMPCckBbpTuning(
67280 + IN PRTMP_ADAPTER pAd,
67281 + IN UINT TxRate);
67282 +
67283 +//
67284 +// Private routines in rtmp_wep.c
67285 +//
67286 +VOID RTMPInitWepEngine(
67287 + IN PRTMP_ADAPTER pAd,
67288 + IN PUCHAR pKey,
67289 + IN UCHAR KeyId,
67290 + IN UCHAR KeyLen,
67291 + IN PUCHAR pDest);
67292 +
67293 +VOID RTMPEncryptData(
67294 + IN PRTMP_ADAPTER pAd,
67295 + IN PUCHAR pSrc,
67296 + IN PUCHAR pDest,
67297 + IN UINT Len);
67298 +
67299 +BOOLEAN RTMPDecryptData(
67300 + IN PRTMP_ADAPTER pAdapter,
67301 + IN PUCHAR pSrc,
67302 + IN UINT Len,
67303 + IN UINT idx);
67304 +
67305 +BOOLEAN RTMPSoftDecryptWEP(
67306 + IN PRTMP_ADAPTER pAd,
67307 + IN PUCHAR pData,
67308 + IN ULONG DataByteCnt,
67309 + IN PCIPHER_KEY pGroupKey);
67310 +
67311 +VOID RTMPSetICV(
67312 + IN PRTMP_ADAPTER pAd,
67313 + IN PUCHAR pDest);
67314 +
67315 +VOID ARCFOUR_INIT(
67316 + IN PARCFOURCONTEXT Ctx,
67317 + IN PUCHAR pKey,
67318 + IN UINT KeyLen);
67319 +
67320 +UCHAR ARCFOUR_BYTE(
67321 + IN PARCFOURCONTEXT Ctx);
67322 +
67323 +VOID ARCFOUR_DECRYPT(
67324 + IN PARCFOURCONTEXT Ctx,
67325 + IN PUCHAR pDest,
67326 + IN PUCHAR pSrc,
67327 + IN UINT Len);
67328 +
67329 +VOID ARCFOUR_ENCRYPT(
67330 + IN PARCFOURCONTEXT Ctx,
67331 + IN PUCHAR pDest,
67332 + IN PUCHAR pSrc,
67333 + IN UINT Len);
67334 +
67335 +VOID WPAARCFOUR_ENCRYPT(
67336 + IN PARCFOURCONTEXT Ctx,
67337 + IN PUCHAR pDest,
67338 + IN PUCHAR pSrc,
67339 + IN UINT Len);
67340 +
67341 +UINT RTMP_CALC_FCS32(
67342 + IN UINT Fcs,
67343 + IN PUCHAR Cp,
67344 + IN INT Len);
67345 +
67346 +//
67347 +// MLME routines
67348 +//
67349 +
67350 +// Asic/RF/BBP related functions
67351 +
67352 +VOID AsicAdjustTxPower(
67353 + IN PRTMP_ADAPTER pAd);
67354 +
67355 +VOID AsicUpdateProtect(
67356 + IN PRTMP_ADAPTER pAd,
67357 + IN USHORT OperaionMode,
67358 + IN UCHAR SetMask,
67359 + IN BOOLEAN bDisableBGProtect,
67360 + IN BOOLEAN bNonGFExist);
67361 +
67362 +VOID AsicSwitchChannel(
67363 + IN PRTMP_ADAPTER pAd,
67364 + IN UCHAR Channel,
67365 + IN BOOLEAN bScan);
67366 +
67367 +VOID AsicLockChannel(
67368 + IN PRTMP_ADAPTER pAd,
67369 + IN UCHAR Channel) ;
67370 +
67371 +VOID AsicAntennaSelect(
67372 + IN PRTMP_ADAPTER pAd,
67373 + IN UCHAR Channel);
67374 +
67375 +VOID AsicAntennaSetting(
67376 + IN PRTMP_ADAPTER pAd,
67377 + IN ABGBAND_STATE BandState);
67378 +
67379 +VOID AsicRfTuningExec(
67380 + IN PVOID SystemSpecific1,
67381 + IN PVOID FunctionContext,
67382 + IN PVOID SystemSpecific2,
67383 + IN PVOID SystemSpecific3);
67384 +
67385 +#ifdef CONFIG_STA_SUPPORT
67386 +VOID AsicSleepThenAutoWakeup(
67387 + IN PRTMP_ADAPTER pAd,
67388 + IN USHORT TbttNumToNextWakeUp);
67389 +
67390 +VOID AsicForceSleep(
67391 + IN PRTMP_ADAPTER pAd);
67392 +
67393 +VOID AsicForceWakeup(
67394 + IN PRTMP_ADAPTER pAd,
67395 + IN BOOLEAN bFromTx);
67396 +#endif // CONFIG_STA_SUPPORT //
67397 +
67398 +VOID AsicSetBssid(
67399 + IN PRTMP_ADAPTER pAd,
67400 + IN PUCHAR pBssid);
67401 +
67402 +VOID AsicSetMcastWC(
67403 + IN PRTMP_ADAPTER pAd);
67404 +
67405 +#if 0 // removed by AlbertY
67406 +VOID AsicSetBssidWC(
67407 + IN PRTMP_ADAPTER pAd,
67408 + IN PUCHAR pBssid);
67409 +#endif
67410 +
67411 +VOID AsicDelWcidTab(
67412 + IN PRTMP_ADAPTER pAd,
67413 + IN UCHAR Wcid);
67414 +
67415 +VOID AsicEnableRDG(
67416 + IN PRTMP_ADAPTER pAd);
67417 +
67418 +VOID AsicDisableRDG(
67419 + IN PRTMP_ADAPTER pAd);
67420 +
67421 +VOID AsicDisableSync(
67422 + IN PRTMP_ADAPTER pAd);
67423 +
67424 +VOID AsicEnableBssSync(
67425 + IN PRTMP_ADAPTER pAd);
67426 +
67427 +VOID AsicEnableIbssSync(
67428 + IN PRTMP_ADAPTER pAd);
67429 +
67430 +VOID AsicSetEdcaParm(
67431 + IN PRTMP_ADAPTER pAd,
67432 + IN PEDCA_PARM pEdcaParm);
67433 +
67434 +VOID AsicSetSlotTime(
67435 + IN PRTMP_ADAPTER pAd,
67436 + IN BOOLEAN bUseShortSlotTime);
67437 +
67438 +#if 0
67439 +VOID AsicAddWcidCipherEntry(
67440 + IN PRTMP_ADAPTER pAd,
67441 + IN UCHAR WCID,
67442 + IN UCHAR BssIndex,
67443 + IN UCHAR KeyTable,
67444 + IN UCHAR CipherAlg,
67445 + IN PUCHAR pAddr,
67446 + IN CIPHER_KEY *pCipherKey);
67447 +#endif
67448 +
67449 +VOID AsicAddSharedKeyEntry(
67450 + IN PRTMP_ADAPTER pAd,
67451 + IN UCHAR BssIndex,
67452 + IN UCHAR KeyIdx,
67453 + IN UCHAR CipherAlg,
67454 + IN PUCHAR pKey,
67455 + IN PUCHAR pTxMic,
67456 + IN PUCHAR pRxMic);
67457 +
67458 +VOID AsicRemoveSharedKeyEntry(
67459 + IN PRTMP_ADAPTER pAd,
67460 + IN UCHAR BssIndex,
67461 + IN UCHAR KeyIdx);
67462 +
67463 +VOID AsicUpdateWCIDAttribute(
67464 + IN PRTMP_ADAPTER pAd,
67465 + IN USHORT WCID,
67466 + IN UCHAR BssIndex,
67467 + IN UCHAR CipherAlg,
67468 + IN BOOLEAN bUsePairewiseKeyTable);
67469 +
67470 +VOID AsicUpdateWCIDIVEIV(
67471 + IN PRTMP_ADAPTER pAd,
67472 + IN USHORT WCID,
67473 + IN ULONG uIV,
67474 + IN ULONG uEIV);
67475 +
67476 +VOID AsicUpdateRxWCIDTable(
67477 + IN PRTMP_ADAPTER pAd,
67478 + IN USHORT WCID,
67479 + IN PUCHAR pAddr);
67480 +
67481 +VOID AsicAddKeyEntry(
67482 + IN PRTMP_ADAPTER pAd,
67483 + IN USHORT WCID,
67484 + IN UCHAR BssIndex,
67485 + IN UCHAR KeyIdx,
67486 + IN PCIPHER_KEY pCipherKey,
67487 + IN BOOLEAN bUsePairewiseKeyTable,
67488 + IN BOOLEAN bTxKey);
67489 +
67490 +VOID AsicAddPairwiseKeyEntry(
67491 + IN PRTMP_ADAPTER pAd,
67492 + IN PUCHAR pAddr,
67493 + IN UCHAR WCID,
67494 + IN CIPHER_KEY *pCipherKey);
67495 +
67496 +VOID AsicRemovePairwiseKeyEntry(
67497 + IN PRTMP_ADAPTER pAd,
67498 + IN UCHAR BssIdx,
67499 + IN UCHAR Wcid);
67500 +
67501 +BOOLEAN AsicSendCommandToMcu(
67502 + IN PRTMP_ADAPTER pAd,
67503 + IN UCHAR Command,
67504 + IN UCHAR Token,
67505 + IN UCHAR Arg0,
67506 + IN UCHAR Arg1);
67507 +
67508 +
67509 +VOID MacAddrRandomBssid(
67510 + IN PRTMP_ADAPTER pAd,
67511 + OUT PUCHAR pAddr);
67512 +
67513 +VOID MgtMacHeaderInit(
67514 + IN PRTMP_ADAPTER pAd,
67515 + IN OUT PHEADER_802_11 pHdr80211,
67516 + IN UCHAR SubType,
67517 + IN UCHAR ToDs,
67518 + IN PUCHAR pDA,
67519 + IN PUCHAR pBssid);
67520 +
67521 +VOID MlmeRadioOff(
67522 + IN PRTMP_ADAPTER pAd);
67523 +
67524 +VOID MlmeRadioOn(
67525 + IN PRTMP_ADAPTER pAd);
67526 +
67527 +
67528 +VOID BssTableInit(
67529 + IN BSS_TABLE *Tab);
67530 +
67531 +#ifdef DOT11_N_SUPPORT
67532 +VOID BATableInit(
67533 + IN PRTMP_ADAPTER pAd,
67534 + IN BA_TABLE *Tab);
67535 +#endif // DOT11_N_SUPPORT //
67536 +
67537 +ULONG BssTableSearch(
67538 + IN BSS_TABLE *Tab,
67539 + IN PUCHAR pBssid,
67540 + IN UCHAR Channel);
67541 +
67542 +ULONG BssSsidTableSearch(
67543 + IN BSS_TABLE *Tab,
67544 + IN PUCHAR pBssid,
67545 + IN PUCHAR pSsid,
67546 + IN UCHAR SsidLen,
67547 + IN UCHAR Channel);
67548 +
67549 +ULONG BssTableSearchWithSSID(
67550 + IN BSS_TABLE *Tab,
67551 + IN PUCHAR Bssid,
67552 + IN PUCHAR pSsid,
67553 + IN UCHAR SsidLen,
67554 + IN UCHAR Channel);
67555 +
67556 +VOID BssTableDeleteEntry(
67557 + IN OUT PBSS_TABLE pTab,
67558 + IN PUCHAR pBssid,
67559 + IN UCHAR Channel);
67560 +
67561 +#ifdef DOT11_N_SUPPORT
67562 +VOID BATableDeleteORIEntry(
67563 + IN OUT PRTMP_ADAPTER pAd,
67564 + IN BA_ORI_ENTRY *pBAORIEntry);
67565 +
67566 +VOID BATableDeleteRECEntry(
67567 + IN OUT PRTMP_ADAPTER pAd,
67568 + IN BA_REC_ENTRY *pBARECEntry);
67569 +
67570 +VOID BATableTearORIEntry(
67571 + IN OUT PRTMP_ADAPTER pAd,
67572 + IN UCHAR TID,
67573 + IN UCHAR Wcid,
67574 + IN BOOLEAN bForceDelete,
67575 + IN BOOLEAN ALL);
67576 +
67577 +VOID BATableTearRECEntry(
67578 + IN OUT PRTMP_ADAPTER pAd,
67579 + IN UCHAR TID,
67580 + IN UCHAR WCID,
67581 + IN BOOLEAN ALL);
67582 +#endif // DOT11_N_SUPPORT //
67583 +
67584 +VOID BssEntrySet(
67585 + IN PRTMP_ADAPTER pAd,
67586 + OUT PBSS_ENTRY pBss,
67587 + IN PUCHAR pBssid,
67588 + IN CHAR Ssid[],
67589 + IN UCHAR SsidLen,
67590 + IN UCHAR BssType,
67591 + IN USHORT BeaconPeriod,
67592 + IN PCF_PARM CfParm,
67593 + IN USHORT AtimWin,
67594 + IN USHORT CapabilityInfo,
67595 + IN UCHAR SupRate[],
67596 + IN UCHAR SupRateLen,
67597 + IN UCHAR ExtRate[],
67598 + IN UCHAR ExtRateLen,
67599 + IN HT_CAPABILITY_IE *pHtCapability,
67600 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
67601 + IN UCHAR HtCapabilityLen,
67602 + IN UCHAR AddHtInfoLen,
67603 + IN UCHAR NewExtChanOffset,
67604 + IN UCHAR Channel,
67605 + IN CHAR Rssi,
67606 + IN LARGE_INTEGER TimeStamp,
67607 + IN UCHAR CkipFlag,
67608 + IN PEDCA_PARM pEdcaParm,
67609 + IN PQOS_CAPABILITY_PARM pQosCapability,
67610 + IN PQBSS_LOAD_PARM pQbssLoad,
67611 + IN USHORT LengthVIE,
67612 + IN PNDIS_802_11_VARIABLE_IEs pVIE);
67613 +
67614 +ULONG BssTableSetEntry(
67615 + IN PRTMP_ADAPTER pAd,
67616 + OUT PBSS_TABLE pTab,
67617 + IN PUCHAR pBssid,
67618 + IN CHAR Ssid[],
67619 + IN UCHAR SsidLen,
67620 + IN UCHAR BssType,
67621 + IN USHORT BeaconPeriod,
67622 + IN CF_PARM *CfParm,
67623 + IN USHORT AtimWin,
67624 + IN USHORT CapabilityInfo,
67625 + IN UCHAR SupRate[],
67626 + IN UCHAR SupRateLen,
67627 + IN UCHAR ExtRate[],
67628 + IN UCHAR ExtRateLen,
67629 + IN HT_CAPABILITY_IE *pHtCapability,
67630 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
67631 + IN UCHAR HtCapabilityLen,
67632 + IN UCHAR AddHtInfoLen,
67633 + IN UCHAR NewExtChanOffset,
67634 + IN UCHAR Channel,
67635 + IN CHAR Rssi,
67636 + IN LARGE_INTEGER TimeStamp,
67637 + IN UCHAR CkipFlag,
67638 + IN PEDCA_PARM pEdcaParm,
67639 + IN PQOS_CAPABILITY_PARM pQosCapability,
67640 + IN PQBSS_LOAD_PARM pQbssLoad,
67641 + IN USHORT LengthVIE,
67642 + IN PNDIS_802_11_VARIABLE_IEs pVIE);
67643 +
67644 +#ifdef DOT11_N_SUPPORT
67645 +VOID BATableInsertEntry(
67646 + IN PRTMP_ADAPTER pAd,
67647 + IN USHORT Aid,
67648 + IN USHORT TimeOutValue,
67649 + IN USHORT StartingSeq,
67650 + IN UCHAR TID,
67651 + IN UCHAR BAWinSize,
67652 + IN UCHAR OriginatorStatus,
67653 + IN BOOLEAN IsRecipient);
67654 +
67655 +#ifdef DOT11N_DRAFT3
67656 +VOID Bss2040CoexistTimeOut(
67657 + IN PVOID SystemSpecific1,
67658 + IN PVOID FunctionContext,
67659 + IN PVOID SystemSpecific2,
67660 + IN PVOID SystemSpecific3);
67661 +
67662 +
67663 +VOID TriEventInit(
67664 + IN PRTMP_ADAPTER pAd);
67665 +
67666 +ULONG TriEventTableSetEntry(
67667 + IN PRTMP_ADAPTER pAd,
67668 + OUT TRIGGER_EVENT_TAB *Tab,
67669 + IN PUCHAR pBssid,
67670 + IN HT_CAPABILITY_IE *pHtCapability,
67671 + IN UCHAR HtCapabilityLen,
67672 + IN UCHAR RegClass,
67673 + IN UCHAR ChannelNo);
67674 +
67675 +VOID TriEventCounterMaintenance(
67676 + IN PRTMP_ADAPTER pAd);
67677 +#endif // DOT11N_DRAFT3 //
67678 +#endif // DOT11_N_SUPPORT //
67679 +
67680 +VOID BssTableSsidSort(
67681 + IN PRTMP_ADAPTER pAd,
67682 + OUT BSS_TABLE *OutTab,
67683 + IN CHAR Ssid[],
67684 + IN UCHAR SsidLen);
67685 +
67686 +VOID BssTableSortByRssi(
67687 + IN OUT BSS_TABLE *OutTab);
67688 +
67689 +VOID BssCipherParse(
67690 + IN OUT PBSS_ENTRY pBss);
67691 +
67692 +NDIS_STATUS MlmeQueueInit(
67693 + IN MLME_QUEUE *Queue);
67694 +
67695 +VOID MlmeQueueDestroy(
67696 + IN MLME_QUEUE *Queue);
67697 +
67698 +BOOLEAN MlmeEnqueue(
67699 + IN PRTMP_ADAPTER pAd,
67700 + IN ULONG Machine,
67701 + IN ULONG MsgType,
67702 + IN ULONG MsgLen,
67703 + IN VOID *Msg);
67704 +
67705 +BOOLEAN MlmeEnqueueForRecv(
67706 + IN PRTMP_ADAPTER pAd,
67707 + IN ULONG Wcid,
67708 + IN ULONG TimeStampHigh,
67709 + IN ULONG TimeStampLow,
67710 + IN UCHAR Rssi0,
67711 + IN UCHAR Rssi1,
67712 + IN UCHAR Rssi2,
67713 + IN ULONG MsgLen,
67714 + IN PVOID Msg,
67715 + IN UCHAR Signal);
67716 +
67717 +
67718 +BOOLEAN MlmeDequeue(
67719 + IN MLME_QUEUE *Queue,
67720 + OUT MLME_QUEUE_ELEM **Elem);
67721 +
67722 +VOID MlmeRestartStateMachine(
67723 + IN PRTMP_ADAPTER pAd);
67724 +
67725 +BOOLEAN MlmeQueueEmpty(
67726 + IN MLME_QUEUE *Queue);
67727 +
67728 +BOOLEAN MlmeQueueFull(
67729 + IN MLME_QUEUE *Queue);
67730 +
67731 +BOOLEAN MsgTypeSubst(
67732 + IN PRTMP_ADAPTER pAd,
67733 + IN PFRAME_802_11 pFrame,
67734 + OUT INT *Machine,
67735 + OUT INT *MsgType);
67736 +
67737 +VOID StateMachineInit(
67738 + IN STATE_MACHINE *Sm,
67739 + IN STATE_MACHINE_FUNC Trans[],
67740 + IN ULONG StNr,
67741 + IN ULONG MsgNr,
67742 + IN STATE_MACHINE_FUNC DefFunc,
67743 + IN ULONG InitState,
67744 + IN ULONG Base);
67745 +
67746 +VOID StateMachineSetAction(
67747 + IN STATE_MACHINE *S,
67748 + IN ULONG St,
67749 + ULONG Msg,
67750 + IN STATE_MACHINE_FUNC F);
67751 +
67752 +VOID StateMachinePerformAction(
67753 + IN PRTMP_ADAPTER pAd,
67754 + IN STATE_MACHINE *S,
67755 + IN MLME_QUEUE_ELEM *Elem);
67756 +
67757 +VOID Drop(
67758 + IN PRTMP_ADAPTER pAd,
67759 + IN MLME_QUEUE_ELEM *Elem);
67760 +
67761 +VOID AssocStateMachineInit(
67762 + IN PRTMP_ADAPTER pAd,
67763 + IN STATE_MACHINE *Sm,
67764 + OUT STATE_MACHINE_FUNC Trans[]);
67765 +
67766 +VOID ReassocTimeout(
67767 + IN PVOID SystemSpecific1,
67768 + IN PVOID FunctionContext,
67769 + IN PVOID SystemSpecific2,
67770 + IN PVOID SystemSpecific3);
67771 +
67772 +VOID AssocTimeout(
67773 + IN PVOID SystemSpecific1,
67774 + IN PVOID FunctionContext,
67775 + IN PVOID SystemSpecific2,
67776 + IN PVOID SystemSpecific3);
67777 +
67778 +VOID DisassocTimeout(
67779 + IN PVOID SystemSpecific1,
67780 + IN PVOID FunctionContext,
67781 + IN PVOID SystemSpecific2,
67782 + IN PVOID SystemSpecific3);
67783 +
67784 +//----------------------------------------------
67785 +VOID MlmeDisassocReqAction(
67786 + IN PRTMP_ADAPTER pAd,
67787 + IN MLME_QUEUE_ELEM *Elem);
67788 +
67789 +VOID MlmeAssocReqAction(
67790 + IN PRTMP_ADAPTER pAd,
67791 + IN MLME_QUEUE_ELEM *Elem);
67792 +
67793 +VOID MlmeReassocReqAction(
67794 + IN PRTMP_ADAPTER pAd,
67795 + IN MLME_QUEUE_ELEM *Elem);
67796 +
67797 +VOID MlmeDisassocReqAction(
67798 + IN PRTMP_ADAPTER pAd,
67799 + IN MLME_QUEUE_ELEM *Elem);
67800 +
67801 +VOID PeerAssocRspAction(
67802 + IN PRTMP_ADAPTER pAd,
67803 + IN MLME_QUEUE_ELEM *Elem);
67804 +
67805 +VOID PeerReassocRspAction(
67806 + IN PRTMP_ADAPTER pAd,
67807 + IN MLME_QUEUE_ELEM *Elem);
67808 +
67809 +VOID PeerDisassocAction(
67810 + IN PRTMP_ADAPTER pAd,
67811 + IN MLME_QUEUE_ELEM *Elem);
67812 +
67813 +VOID DisassocTimeoutAction(
67814 + IN PRTMP_ADAPTER pAd,
67815 + IN MLME_QUEUE_ELEM *Elem);
67816 +
67817 +VOID AssocTimeoutAction(
67818 + IN PRTMP_ADAPTER pAd,
67819 + IN MLME_QUEUE_ELEM *Elem);
67820 +
67821 +VOID ReassocTimeoutAction(
67822 + IN PRTMP_ADAPTER pAd,
67823 + IN MLME_QUEUE_ELEM *Elem);
67824 +
67825 +VOID Cls3errAction(
67826 + IN PRTMP_ADAPTER pAd,
67827 + IN PUCHAR pAddr);
67828 +
67829 +VOID SwitchBetweenWepAndCkip(
67830 + IN PRTMP_ADAPTER pAd);
67831 +
67832 +VOID InvalidStateWhenAssoc(
67833 + IN PRTMP_ADAPTER pAd,
67834 + IN MLME_QUEUE_ELEM *Elem);
67835 +
67836 +VOID InvalidStateWhenReassoc(
67837 + IN PRTMP_ADAPTER pAd,
67838 + IN MLME_QUEUE_ELEM *Elem);
67839 +
67840 +VOID InvalidStateWhenDisassociate(
67841 + IN PRTMP_ADAPTER pAd,
67842 + IN MLME_QUEUE_ELEM *Elem);
67843 +
67844 +#ifdef RT2870
67845 +VOID MlmeCntlConfirm(
67846 + IN PRTMP_ADAPTER pAd,
67847 + IN ULONG MsgType,
67848 + IN USHORT Msg);
67849 +#endif // RT2870 //
67850 +
67851 +VOID ComposePsPoll(
67852 + IN PRTMP_ADAPTER pAd);
67853 +
67854 +VOID ComposeNullFrame(
67855 + IN PRTMP_ADAPTER pAd);
67856 +
67857 +VOID AssocPostProc(
67858 + IN PRTMP_ADAPTER pAd,
67859 + IN PUCHAR pAddr2,
67860 + IN USHORT CapabilityInfo,
67861 + IN USHORT Aid,
67862 + IN UCHAR SupRate[],
67863 + IN UCHAR SupRateLen,
67864 + IN UCHAR ExtRate[],
67865 + IN UCHAR ExtRateLen,
67866 + IN PEDCA_PARM pEdcaParm,
67867 + IN HT_CAPABILITY_IE *pHtCapability,
67868 + IN UCHAR HtCapabilityLen,
67869 + IN ADD_HT_INFO_IE *pAddHtInfo);
67870 +
67871 +VOID AuthStateMachineInit(
67872 + IN PRTMP_ADAPTER pAd,
67873 + IN PSTATE_MACHINE sm,
67874 + OUT STATE_MACHINE_FUNC Trans[]);
67875 +
67876 +VOID AuthTimeout(
67877 + IN PVOID SystemSpecific1,
67878 + IN PVOID FunctionContext,
67879 + IN PVOID SystemSpecific2,
67880 + IN PVOID SystemSpecific3);
67881 +
67882 +VOID MlmeAuthReqAction(
67883 + IN PRTMP_ADAPTER pAd,
67884 + IN MLME_QUEUE_ELEM *Elem);
67885 +
67886 +VOID PeerAuthRspAtSeq2Action(
67887 + IN PRTMP_ADAPTER pAd,
67888 + IN MLME_QUEUE_ELEM *Elem);
67889 +
67890 +VOID PeerAuthRspAtSeq4Action(
67891 + IN PRTMP_ADAPTER pAd,
67892 + IN MLME_QUEUE_ELEM *Elem);
67893 +
67894 +VOID AuthTimeoutAction(
67895 + IN PRTMP_ADAPTER pAd,
67896 + IN MLME_QUEUE_ELEM *Elem);
67897 +
67898 +VOID Cls2errAction(
67899 + IN PRTMP_ADAPTER pAd,
67900 + IN PUCHAR pAddr);
67901 +
67902 +VOID MlmeDeauthReqAction(
67903 + IN PRTMP_ADAPTER pAd,
67904 + IN MLME_QUEUE_ELEM *Elem);
67905 +
67906 +VOID InvalidStateWhenAuth(
67907 + IN PRTMP_ADAPTER pAd,
67908 + IN MLME_QUEUE_ELEM *Elem);
67909 +
67910 +//=============================================
67911 +
67912 +VOID AuthRspStateMachineInit(
67913 + IN PRTMP_ADAPTER pAd,
67914 + IN PSTATE_MACHINE Sm,
67915 + IN STATE_MACHINE_FUNC Trans[]);
67916 +
67917 +VOID PeerDeauthAction(
67918 + IN PRTMP_ADAPTER pAd,
67919 + IN MLME_QUEUE_ELEM *Elem);
67920 +
67921 +VOID PeerAuthSimpleRspGenAndSend(
67922 + IN PRTMP_ADAPTER pAd,
67923 + IN PHEADER_802_11 pHdr80211,
67924 + IN USHORT Alg,
67925 + IN USHORT Seq,
67926 + IN USHORT Reason,
67927 + IN USHORT Status);
67928 +
67929 +//
67930 +// Private routines in dls.c
67931 +//
67932 +
67933 +#ifdef CONFIG_STA_SUPPORT
67934 +#ifdef QOS_DLS_SUPPORT
67935 +void DlsStateMachineInit(
67936 + IN PRTMP_ADAPTER pAd,
67937 + IN STATE_MACHINE *Sm,
67938 + OUT STATE_MACHINE_FUNC Trans[]);
67939 +
67940 +VOID MlmeDlsReqAction(
67941 + IN PRTMP_ADAPTER pAd,
67942 + IN MLME_QUEUE_ELEM *Elem);
67943 +
67944 +VOID PeerDlsReqAction(
67945 + IN PRTMP_ADAPTER pAd,
67946 + IN MLME_QUEUE_ELEM *Elem);
67947 +
67948 +VOID PeerDlsRspAction(
67949 + IN PRTMP_ADAPTER pAd,
67950 + IN MLME_QUEUE_ELEM *Elem);
67951 +
67952 +VOID MlmeDlsTearDownAction(
67953 + IN PRTMP_ADAPTER pAd,
67954 + IN MLME_QUEUE_ELEM *Elem);
67955 +
67956 +VOID PeerDlsTearDownAction(
67957 + IN PRTMP_ADAPTER pAd,
67958 + IN MLME_QUEUE_ELEM *Elem);
67959 +
67960 +VOID RTMPCheckDLSTimeOut(
67961 + IN PRTMP_ADAPTER pAd);
67962 +
67963 +BOOLEAN RTMPRcvFrameDLSCheck(
67964 + IN PRTMP_ADAPTER pAd,
67965 + IN PHEADER_802_11 pHeader,
67966 + IN ULONG Len,
67967 + IN PRT28XX_RXD_STRUC pRxD);
67968 +
67969 +INT RTMPCheckDLSFrame(
67970 + IN PRTMP_ADAPTER pAd,
67971 + IN PUCHAR pDA);
67972 +
67973 +VOID RTMPSendDLSTearDownFrame(
67974 + IN PRTMP_ADAPTER pAd,
67975 + IN PUCHAR pDA);
67976 +
67977 +NDIS_STATUS RTMPSendSTAKeyRequest(
67978 + IN PRTMP_ADAPTER pAd,
67979 + IN PUCHAR pDA);
67980 +
67981 +NDIS_STATUS RTMPSendSTAKeyHandShake(
67982 + IN PRTMP_ADAPTER pAd,
67983 + IN PUCHAR pDA);
67984 +
67985 +VOID DlsTimeoutAction(
67986 + IN PVOID SystemSpecific1,
67987 + IN PVOID FunctionContext,
67988 + IN PVOID SystemSpecific2,
67989 + IN PVOID SystemSpecific3);
67990 +
67991 +BOOLEAN MlmeDlsReqSanity(
67992 + IN PRTMP_ADAPTER pAd,
67993 + IN VOID *Msg,
67994 + IN ULONG MsgLen,
67995 + OUT PRT_802_11_DLS *pDLS,
67996 + OUT PUSHORT pReason);
67997 +
67998 +INT Set_DlsEntryInfo_Display_Proc(
67999 + IN PRTMP_ADAPTER pAd,
68000 + IN PUCHAR arg);
68001 +
68002 +MAC_TABLE_ENTRY *MacTableInsertDlsEntry(
68003 + IN PRTMP_ADAPTER pAd,
68004 + IN PUCHAR pAddr,
68005 + IN UINT DlsEntryIdx);
68006 +
68007 +BOOLEAN MacTableDeleteDlsEntry(
68008 + IN PRTMP_ADAPTER pAd,
68009 + IN USHORT wcid,
68010 + IN PUCHAR pAddr);
68011 +
68012 +MAC_TABLE_ENTRY *DlsEntryTableLookup(
68013 + IN PRTMP_ADAPTER pAd,
68014 + IN PUCHAR pAddr,
68015 + IN BOOLEAN bResetIdelCount);
68016 +
68017 +MAC_TABLE_ENTRY *DlsEntryTableLookupByWcid(
68018 + IN PRTMP_ADAPTER pAd,
68019 + IN UCHAR wcid,
68020 + IN PUCHAR pAddr,
68021 + IN BOOLEAN bResetIdelCount);
68022 +
68023 +INT Set_DlsAddEntry_Proc(
68024 + IN PRTMP_ADAPTER pAd,
68025 + IN PUCHAR arg);
68026 +
68027 +INT Set_DlsTearDownEntry_Proc(
68028 + IN PRTMP_ADAPTER pAd,
68029 + IN PUCHAR arg);
68030 +#endif // QOS_DLS_SUPPORT //
68031 +#endif // CONFIG_STA_SUPPORT //
68032 +
68033 +#ifdef QOS_DLS_SUPPORT
68034 +BOOLEAN PeerDlsReqSanity(
68035 + IN PRTMP_ADAPTER pAd,
68036 + IN VOID *Msg,
68037 + IN ULONG MsgLen,
68038 + OUT PUCHAR pDA,
68039 + OUT PUCHAR pSA,
68040 + OUT USHORT *pCapabilityInfo,
68041 + OUT USHORT *pDlsTimeout,
68042 + OUT UCHAR *pRatesLen,
68043 + OUT UCHAR Rates[],
68044 + OUT UCHAR *pHtCapabilityLen,
68045 + OUT HT_CAPABILITY_IE *pHtCapability);
68046 +
68047 +BOOLEAN PeerDlsRspSanity(
68048 + IN PRTMP_ADAPTER pAd,
68049 + IN VOID *Msg,
68050 + IN ULONG MsgLen,
68051 + OUT PUCHAR pDA,
68052 + OUT PUCHAR pSA,
68053 + OUT USHORT *pCapabilityInfo,
68054 + OUT USHORT *pStatus,
68055 + OUT UCHAR *pRatesLen,
68056 + OUT UCHAR Rates[],
68057 + OUT UCHAR *pHtCapabilityLen,
68058 + OUT HT_CAPABILITY_IE *pHtCapability);
68059 +
68060 +BOOLEAN PeerDlsTearDownSanity(
68061 + IN PRTMP_ADAPTER pAd,
68062 + IN VOID *Msg,
68063 + IN ULONG MsgLen,
68064 + OUT PUCHAR pDA,
68065 + OUT PUCHAR pSA,
68066 + OUT USHORT *pReason);
68067 +#endif // QOS_DLS_SUPPORT //
68068 +
68069 +//========================================
68070 +
68071 +VOID SyncStateMachineInit(
68072 + IN PRTMP_ADAPTER pAd,
68073 + IN STATE_MACHINE *Sm,
68074 + OUT STATE_MACHINE_FUNC Trans[]);
68075 +
68076 +VOID BeaconTimeout(
68077 + IN PVOID SystemSpecific1,
68078 + IN PVOID FunctionContext,
68079 + IN PVOID SystemSpecific2,
68080 + IN PVOID SystemSpecific3);
68081 +
68082 +VOID ScanTimeout(
68083 + IN PVOID SystemSpecific1,
68084 + IN PVOID FunctionContext,
68085 + IN PVOID SystemSpecific2,
68086 + IN PVOID SystemSpecific3);
68087 +
68088 +VOID MlmeScanReqAction(
68089 + IN PRTMP_ADAPTER pAd,
68090 + IN MLME_QUEUE_ELEM *Elem);
68091 +
68092 +VOID InvalidStateWhenScan(
68093 + IN PRTMP_ADAPTER pAd,
68094 + IN MLME_QUEUE_ELEM *Elem);
68095 +
68096 +VOID InvalidStateWhenJoin(
68097 + IN PRTMP_ADAPTER pAd,
68098 + IN MLME_QUEUE_ELEM *Elem);
68099 +
68100 +VOID InvalidStateWhenStart(
68101 + IN PRTMP_ADAPTER pAd,
68102 + IN MLME_QUEUE_ELEM *Elem);
68103 +
68104 +VOID PeerBeacon(
68105 + IN PRTMP_ADAPTER pAd,
68106 + IN MLME_QUEUE_ELEM *Elem);
68107 +
68108 +VOID EnqueueProbeRequest(
68109 + IN PRTMP_ADAPTER pAd);
68110 +
68111 +BOOLEAN ScanRunning(
68112 + IN PRTMP_ADAPTER pAd);
68113 +//=========================================
68114 +
68115 +VOID MlmeCntlInit(
68116 + IN PRTMP_ADAPTER pAd,
68117 + IN STATE_MACHINE *S,
68118 + OUT STATE_MACHINE_FUNC Trans[]);
68119 +
68120 +VOID MlmeCntlMachinePerformAction(
68121 + IN PRTMP_ADAPTER pAd,
68122 + IN STATE_MACHINE *S,
68123 + IN MLME_QUEUE_ELEM *Elem);
68124 +
68125 +VOID CntlIdleProc(
68126 + IN PRTMP_ADAPTER pAd,
68127 + IN MLME_QUEUE_ELEM *Elem);
68128 +
68129 +VOID CntlOidScanProc(
68130 + IN PRTMP_ADAPTER pAd,
68131 + IN MLME_QUEUE_ELEM *Elem);
68132 +
68133 +VOID CntlOidSsidProc(
68134 + IN PRTMP_ADAPTER pAd,
68135 + IN MLME_QUEUE_ELEM * Elem);
68136 +
68137 +VOID CntlOidRTBssidProc(
68138 + IN PRTMP_ADAPTER pAd,
68139 + IN MLME_QUEUE_ELEM * Elem);
68140 +
68141 +VOID CntlMlmeRoamingProc(
68142 + IN PRTMP_ADAPTER pAd,
68143 + IN MLME_QUEUE_ELEM * Elem);
68144 +
68145 +VOID CntlWaitDisassocProc(
68146 + IN PRTMP_ADAPTER pAd,
68147 + IN MLME_QUEUE_ELEM *Elem);
68148 +
68149 +VOID CntlWaitJoinProc(
68150 + IN PRTMP_ADAPTER pAd,
68151 + IN MLME_QUEUE_ELEM *Elem);
68152 +
68153 +VOID CntlWaitReassocProc(
68154 + IN PRTMP_ADAPTER pAd,
68155 + IN MLME_QUEUE_ELEM *Elem);
68156 +
68157 +VOID CntlWaitStartProc(
68158 + IN PRTMP_ADAPTER pAd,
68159 + IN MLME_QUEUE_ELEM *Elem);
68160 +
68161 +VOID CntlWaitAuthProc(
68162 + IN PRTMP_ADAPTER pAd,
68163 + IN MLME_QUEUE_ELEM *Elem);
68164 +
68165 +VOID CntlWaitAuthProc2(
68166 + IN PRTMP_ADAPTER pAd,
68167 + IN MLME_QUEUE_ELEM *Elem);
68168 +
68169 +VOID CntlWaitAssocProc(
68170 + IN PRTMP_ADAPTER pAd,
68171 + IN MLME_QUEUE_ELEM *Elem);
68172 +
68173 +#ifdef QOS_DLS_SUPPORT
68174 +VOID CntlOidDLSSetupProc(
68175 + IN PRTMP_ADAPTER pAd,
68176 + IN MLME_QUEUE_ELEM *Elem);
68177 +#endif // QOS_DLS_SUPPORT //
68178 +
68179 +VOID LinkUp(
68180 + IN PRTMP_ADAPTER pAd,
68181 + IN UCHAR BssType);
68182 +
68183 +VOID LinkDown(
68184 + IN PRTMP_ADAPTER pAd,
68185 + IN BOOLEAN IsReqFromAP);
68186 +
68187 +VOID IterateOnBssTab(
68188 + IN PRTMP_ADAPTER pAd);
68189 +
68190 +VOID IterateOnBssTab2(
68191 + IN PRTMP_ADAPTER pAd);;
68192 +
68193 +VOID JoinParmFill(
68194 + IN PRTMP_ADAPTER pAd,
68195 + IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
68196 + IN ULONG BssIdx);
68197 +
68198 +VOID AssocParmFill(
68199 + IN PRTMP_ADAPTER pAd,
68200 + IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
68201 + IN PUCHAR pAddr,
68202 + IN USHORT CapabilityInfo,
68203 + IN ULONG Timeout,
68204 + IN USHORT ListenIntv);
68205 +
68206 +VOID ScanParmFill(
68207 + IN PRTMP_ADAPTER pAd,
68208 + IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
68209 + IN CHAR Ssid[],
68210 + IN UCHAR SsidLen,
68211 + IN UCHAR BssType,
68212 + IN UCHAR ScanType);
68213 +
68214 +VOID DisassocParmFill(
68215 + IN PRTMP_ADAPTER pAd,
68216 + IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
68217 + IN PUCHAR pAddr,
68218 + IN USHORT Reason);
68219 +
68220 +VOID StartParmFill(
68221 + IN PRTMP_ADAPTER pAd,
68222 + IN OUT MLME_START_REQ_STRUCT *StartReq,
68223 + IN CHAR Ssid[],
68224 + IN UCHAR SsidLen);
68225 +
68226 +VOID AuthParmFill(
68227 + IN PRTMP_ADAPTER pAd,
68228 + IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
68229 + IN PUCHAR pAddr,
68230 + IN USHORT Alg);
68231 +
68232 +VOID EnqueuePsPoll(
68233 + IN PRTMP_ADAPTER pAd);
68234 +
68235 +VOID EnqueueBeaconFrame(
68236 + IN PRTMP_ADAPTER pAd);
68237 +
68238 +VOID MlmeJoinReqAction(
68239 + IN PRTMP_ADAPTER pAd,
68240 + IN MLME_QUEUE_ELEM *Elem);
68241 +
68242 +VOID MlmeScanReqAction(
68243 + IN PRTMP_ADAPTER pAd,
68244 + IN MLME_QUEUE_ELEM *Elem);
68245 +
68246 +VOID MlmeStartReqAction(
68247 + IN PRTMP_ADAPTER pAd,
68248 + IN MLME_QUEUE_ELEM *Elem);
68249 +
68250 +VOID ScanTimeoutAction(
68251 + IN PRTMP_ADAPTER pAd,
68252 + IN MLME_QUEUE_ELEM *Elem);
68253 +
68254 +VOID BeaconTimeoutAtJoinAction(
68255 + IN PRTMP_ADAPTER pAd,
68256 + IN MLME_QUEUE_ELEM *Elem);
68257 +
68258 +VOID PeerBeaconAtScanAction(
68259 + IN PRTMP_ADAPTER pAd,
68260 + IN MLME_QUEUE_ELEM *Elem);
68261 +
68262 +VOID PeerBeaconAtJoinAction(
68263 + IN PRTMP_ADAPTER pAd,
68264 + IN MLME_QUEUE_ELEM *Elem);
68265 +
68266 +VOID PeerBeacon(
68267 + IN PRTMP_ADAPTER pAd,
68268 + IN MLME_QUEUE_ELEM *Elem);
68269 +
68270 +VOID PeerProbeReqAction(
68271 + IN PRTMP_ADAPTER pAd,
68272 + IN MLME_QUEUE_ELEM *Elem);
68273 +
68274 +VOID ScanNextChannel(
68275 + IN PRTMP_ADAPTER pAd);
68276 +
68277 +ULONG MakeIbssBeacon(
68278 + IN PRTMP_ADAPTER pAd);
68279 +
68280 +VOID CCXAdjacentAPReport(
68281 + IN PRTMP_ADAPTER pAd);
68282 +
68283 +BOOLEAN MlmeScanReqSanity(
68284 + IN PRTMP_ADAPTER pAd,
68285 + IN VOID *Msg,
68286 + IN ULONG MsgLen,
68287 + OUT UCHAR *BssType,
68288 + OUT CHAR ssid[],
68289 + OUT UCHAR *SsidLen,
68290 + OUT UCHAR *ScanType);
68291 +
68292 +BOOLEAN PeerBeaconAndProbeRspSanity(
68293 + IN PRTMP_ADAPTER pAd,
68294 + IN VOID *Msg,
68295 + IN ULONG MsgLen,
68296 + IN UCHAR MsgChannel,
68297 + OUT PUCHAR pAddr2,
68298 + OUT PUCHAR pBssid,
68299 + OUT CHAR Ssid[],
68300 + OUT UCHAR *pSsidLen,
68301 + OUT UCHAR *pBssType,
68302 + OUT USHORT *pBeaconPeriod,
68303 + OUT UCHAR *pChannel,
68304 + OUT UCHAR *pNewChannel,
68305 + OUT LARGE_INTEGER *pTimestamp,
68306 + OUT CF_PARM *pCfParm,
68307 + OUT USHORT *pAtimWin,
68308 + OUT USHORT *pCapabilityInfo,
68309 + OUT UCHAR *pErp,
68310 + OUT UCHAR *pDtimCount,
68311 + OUT UCHAR *pDtimPeriod,
68312 + OUT UCHAR *pBcastFlag,
68313 + OUT UCHAR *pMessageToMe,
68314 + OUT UCHAR SupRate[],
68315 + OUT UCHAR *pSupRateLen,
68316 + OUT UCHAR ExtRate[],
68317 + OUT UCHAR *pExtRateLen,
68318 + OUT UCHAR *pCkipFlag,
68319 + OUT UCHAR *pAironetCellPowerLimit,
68320 + OUT PEDCA_PARM pEdcaParm,
68321 + OUT PQBSS_LOAD_PARM pQbssLoad,
68322 + OUT PQOS_CAPABILITY_PARM pQosCapability,
68323 + OUT ULONG *pRalinkIe,
68324 + OUT UCHAR *pHtCapabilityLen,
68325 +#ifdef CONFIG_STA_SUPPORT
68326 + OUT UCHAR *pPreNHtCapabilityLen,
68327 +#endif // CONFIG_STA_SUPPORT //
68328 + OUT HT_CAPABILITY_IE *pHtCapability,
68329 + OUT UCHAR *AddHtInfoLen,
68330 + OUT ADD_HT_INFO_IE *AddHtInfo,
68331 + OUT UCHAR *NewExtChannel,
68332 + OUT USHORT *LengthVIE,
68333 + OUT PNDIS_802_11_VARIABLE_IEs pVIE);
68334 +
68335 +BOOLEAN PeerAddBAReqActionSanity(
68336 + IN PRTMP_ADAPTER pAd,
68337 + IN VOID *pMsg,
68338 + IN ULONG MsgLen,
68339 + OUT PUCHAR pAddr2);
68340 +
68341 +BOOLEAN PeerAddBARspActionSanity(
68342 + IN PRTMP_ADAPTER pAd,
68343 + IN VOID *pMsg,
68344 + IN ULONG MsgLen);
68345 +
68346 +BOOLEAN PeerDelBAActionSanity(
68347 + IN PRTMP_ADAPTER pAd,
68348 + IN UCHAR Wcid,
68349 + IN VOID *pMsg,
68350 + IN ULONG MsgLen);
68351 +
68352 +BOOLEAN MlmeAssocReqSanity(
68353 + IN PRTMP_ADAPTER pAd,
68354 + IN VOID *Msg,
68355 + IN ULONG MsgLen,
68356 + OUT PUCHAR pApAddr,
68357 + OUT USHORT *CapabilityInfo,
68358 + OUT ULONG *Timeout,
68359 + OUT USHORT *ListenIntv);
68360 +
68361 +BOOLEAN MlmeAuthReqSanity(
68362 + IN PRTMP_ADAPTER pAd,
68363 + IN VOID *Msg,
68364 + IN ULONG MsgLen,
68365 + OUT PUCHAR pAddr,
68366 + OUT ULONG *Timeout,
68367 + OUT USHORT *Alg);
68368 +
68369 +BOOLEAN MlmeStartReqSanity(
68370 + IN PRTMP_ADAPTER pAd,
68371 + IN VOID *Msg,
68372 + IN ULONG MsgLen,
68373 + OUT CHAR Ssid[],
68374 + OUT UCHAR *Ssidlen);
68375 +
68376 +BOOLEAN PeerAuthSanity(
68377 + IN PRTMP_ADAPTER pAd,
68378 + IN VOID *Msg,
68379 + IN ULONG MsgLen,
68380 + OUT PUCHAR pAddr,
68381 + OUT USHORT *Alg,
68382 + OUT USHORT *Seq,
68383 + OUT USHORT *Status,
68384 + OUT CHAR ChlgText[]);
68385 +
68386 +BOOLEAN PeerAssocRspSanity(
68387 + IN PRTMP_ADAPTER pAd,
68388 + IN VOID *pMsg,
68389 + IN ULONG MsgLen,
68390 + OUT PUCHAR pAddr2,
68391 + OUT USHORT *pCapabilityInfo,
68392 + OUT USHORT *pStatus,
68393 + OUT USHORT *pAid,
68394 + OUT UCHAR SupRate[],
68395 + OUT UCHAR *pSupRateLen,
68396 + OUT UCHAR ExtRate[],
68397 + OUT UCHAR *pExtRateLen,
68398 + OUT HT_CAPABILITY_IE *pHtCapability,
68399 + OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
68400 + OUT UCHAR *pHtCapabilityLen,
68401 + OUT UCHAR *pAddHtInfoLen,
68402 + OUT UCHAR *pNewExtChannelOffset,
68403 + OUT PEDCA_PARM pEdcaParm,
68404 + OUT UCHAR *pCkipFlag);
68405 +
68406 +BOOLEAN PeerDisassocSanity(
68407 + IN PRTMP_ADAPTER pAd,
68408 + IN VOID *Msg,
68409 + IN ULONG MsgLen,
68410 + OUT PUCHAR pAddr2,
68411 + OUT USHORT *Reason);
68412 +
68413 +BOOLEAN PeerWpaMessageSanity(
68414 + IN PRTMP_ADAPTER pAd,
68415 + IN PEAPOL_PACKET pMsg,
68416 + IN ULONG MsgLen,
68417 + IN UCHAR MsgType,
68418 + IN MAC_TABLE_ENTRY *pEntry);
68419 +
68420 +BOOLEAN PeerDeauthSanity(
68421 + IN PRTMP_ADAPTER pAd,
68422 + IN VOID *Msg,
68423 + IN ULONG MsgLen,
68424 + OUT PUCHAR pAddr2,
68425 + OUT USHORT *Reason);
68426 +
68427 +BOOLEAN PeerProbeReqSanity(
68428 + IN PRTMP_ADAPTER pAd,
68429 + IN VOID *Msg,
68430 + IN ULONG MsgLen,
68431 + OUT PUCHAR pAddr2,
68432 + OUT CHAR Ssid[],
68433 + OUT UCHAR *pSsidLen);
68434 +
68435 +BOOLEAN GetTimBit(
68436 + IN CHAR *Ptr,
68437 + IN USHORT Aid,
68438 + OUT UCHAR *TimLen,
68439 + OUT UCHAR *BcastFlag,
68440 + OUT UCHAR *DtimCount,
68441 + OUT UCHAR *DtimPeriod,
68442 + OUT UCHAR *MessageToMe);
68443 +
68444 +UCHAR ChannelSanity(
68445 + IN PRTMP_ADAPTER pAd,
68446 + IN UCHAR channel);
68447 +
68448 +NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(
68449 + IN PBSS_ENTRY pBss);
68450 +
68451 +#if 0 // It's omitted
68452 +NDIS_STATUS RTMPWepKeySanity(
68453 + IN PRTMP_ADAPTER pAdapter,
68454 + IN PVOID pBuf);
68455 +#endif
68456 +
68457 +BOOLEAN MlmeDelBAReqSanity(
68458 + IN PRTMP_ADAPTER pAd,
68459 + IN VOID *Msg,
68460 + IN ULONG MsgLen);
68461 +
68462 +BOOLEAN MlmeAddBAReqSanity(
68463 + IN PRTMP_ADAPTER pAd,
68464 + IN VOID *Msg,
68465 + IN ULONG MsgLen,
68466 + OUT PUCHAR pAddr2);
68467 +
68468 +ULONG MakeOutgoingFrame(
68469 + OUT CHAR *Buffer,
68470 + OUT ULONG *Length, ...);
68471 +
68472 +VOID LfsrInit(
68473 + IN PRTMP_ADAPTER pAd,
68474 + IN ULONG Seed);
68475 +
68476 +UCHAR RandomByte(
68477 + IN PRTMP_ADAPTER pAd);
68478 +
68479 +VOID AsicUpdateAutoFallBackTable(
68480 + IN PRTMP_ADAPTER pAd,
68481 + IN PUCHAR pTxRate);
68482 +
68483 +VOID MlmePeriodicExec(
68484 + IN PVOID SystemSpecific1,
68485 + IN PVOID FunctionContext,
68486 + IN PVOID SystemSpecific2,
68487 + IN PVOID SystemSpecific3);
68488 +
68489 +VOID LinkDownExec(
68490 + IN PVOID SystemSpecific1,
68491 + IN PVOID FunctionContext,
68492 + IN PVOID SystemSpecific2,
68493 + IN PVOID SystemSpecific3);
68494 +
68495 +VOID LinkUpExec(
68496 + IN PVOID SystemSpecific1,
68497 + IN PVOID FunctionContext,
68498 + IN PVOID SystemSpecific2,
68499 + IN PVOID SystemSpecific3);
68500 +
68501 +VOID STAMlmePeriodicExec(
68502 + PRTMP_ADAPTER pAd);
68503 +
68504 +VOID MlmeAutoScan(
68505 + IN PRTMP_ADAPTER pAd);
68506 +
68507 +VOID MlmeAutoReconnectLastSSID(
68508 + IN PRTMP_ADAPTER pAd);
68509 +
68510 +BOOLEAN MlmeValidateSSID(
68511 + IN PUCHAR pSsid,
68512 + IN UCHAR SsidLen);
68513 +
68514 +VOID MlmeCheckForRoaming(
68515 + IN PRTMP_ADAPTER pAd,
68516 + IN ULONG Now32);
68517 +
68518 +VOID MlmeCheckForFastRoaming(
68519 + IN PRTMP_ADAPTER pAd,
68520 + IN ULONG Now);
68521 +
68522 +VOID MlmeDynamicTxRateSwitching(
68523 + IN PRTMP_ADAPTER pAd);
68524 +
68525 +VOID MlmeSetTxRate(
68526 + IN PRTMP_ADAPTER pAd,
68527 + IN PMAC_TABLE_ENTRY pEntry,
68528 + IN PRTMP_TX_RATE_SWITCH pTxRate);
68529 +
68530 +VOID MlmeSelectTxRateTable(
68531 + IN PRTMP_ADAPTER pAd,
68532 + IN PMAC_TABLE_ENTRY pEntry,
68533 + IN PUCHAR *ppTable,
68534 + IN PUCHAR pTableSize,
68535 + IN PUCHAR pInitTxRateIdx);
68536 +
68537 +VOID MlmeCalculateChannelQuality(
68538 + IN PRTMP_ADAPTER pAd,
68539 + IN ULONG Now);
68540 +
68541 +VOID MlmeCheckPsmChange(
68542 + IN PRTMP_ADAPTER pAd,
68543 + IN ULONG Now32);
68544 +
68545 +VOID MlmeSetPsmBit(
68546 + IN PRTMP_ADAPTER pAd,
68547 + IN USHORT psm);
68548 +
68549 +VOID MlmeSetTxPreamble(
68550 + IN PRTMP_ADAPTER pAd,
68551 + IN USHORT TxPreamble);
68552 +
68553 +VOID UpdateBasicRateBitmap(
68554 + IN PRTMP_ADAPTER pAd);
68555 +
68556 +VOID MlmeUpdateTxRates(
68557 + IN PRTMP_ADAPTER pAd,
68558 + IN BOOLEAN bLinkUp,
68559 + IN UCHAR apidx);
68560 +
68561 +#ifdef DOT11_N_SUPPORT
68562 +VOID MlmeUpdateHtTxRates(
68563 + IN PRTMP_ADAPTER pAd,
68564 + IN UCHAR apidx);
68565 +#endif // DOT11_N_SUPPORT //
68566 +
68567 +VOID RTMPCheckRates(
68568 + IN PRTMP_ADAPTER pAd,
68569 + IN OUT UCHAR SupRate[],
68570 + IN OUT UCHAR *SupRateLen);
68571 +
68572 +#ifdef CONFIG_STA_SUPPORT
68573 +BOOLEAN RTMPCheckChannel(
68574 + IN PRTMP_ADAPTER pAd,
68575 + IN UCHAR CentralChannel,
68576 + IN UCHAR Channel);
68577 +#endif // CONFIG_STA_SUPPORT //
68578 +
68579 +BOOLEAN RTMPCheckHt(
68580 + IN PRTMP_ADAPTER pAd,
68581 + IN UCHAR Wcid,
68582 + IN OUT HT_CAPABILITY_IE *pHtCapability,
68583 + IN OUT ADD_HT_INFO_IE *pAddHtInfo);
68584 +
68585 +VOID StaQuickResponeForRateUpExec(
68586 + IN PVOID SystemSpecific1,
68587 + IN PVOID FunctionContext,
68588 + IN PVOID SystemSpecific2,
68589 + IN PVOID SystemSpecific3);
68590 +
68591 +VOID AsicBbpTuning1(
68592 + IN PRTMP_ADAPTER pAd);
68593 +
68594 +VOID AsicBbpTuning2(
68595 + IN PRTMP_ADAPTER pAd);
68596 +
68597 +VOID RTMPUpdateMlmeRate(
68598 + IN PRTMP_ADAPTER pAd);
68599 +
68600 +CHAR RTMPMaxRssi(
68601 + IN PRTMP_ADAPTER pAd,
68602 + IN CHAR Rssi0,
68603 + IN CHAR Rssi1,
68604 + IN CHAR Rssi2);
68605 +
68606 +VOID AsicEvaluateRxAnt(
68607 + IN PRTMP_ADAPTER pAd);
68608 +
68609 +VOID AsicRxAntEvalTimeout(
68610 + IN PVOID SystemSpecific1,
68611 + IN PVOID FunctionContext,
68612 + IN PVOID SystemSpecific2,
68613 + IN PVOID SystemSpecific3);
68614 +
68615 +VOID APSDPeriodicExec(
68616 + IN PVOID SystemSpecific1,
68617 + IN PVOID FunctionContext,
68618 + IN PVOID SystemSpecific2,
68619 + IN PVOID SystemSpecific3);
68620 +
68621 +BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(
68622 + IN PRTMP_ADAPTER pAd,
68623 + IN PMAC_TABLE_ENTRY pEntry);
68624 +
68625 +UCHAR RTMPStaFixedTxMode(
68626 + IN PRTMP_ADAPTER pAd,
68627 + IN PMAC_TABLE_ENTRY pEntry);
68628 +
68629 +VOID RTMPUpdateLegacyTxSetting(
68630 + UCHAR fixed_tx_mode,
68631 + PMAC_TABLE_ENTRY pEntry);
68632 +
68633 +BOOLEAN RTMPAutoRateSwitchCheck(
68634 + IN PRTMP_ADAPTER pAd);
68635 +
68636 +NDIS_STATUS MlmeInit(
68637 + IN PRTMP_ADAPTER pAd);
68638 +
68639 +VOID MlmeHandler(
68640 + IN PRTMP_ADAPTER pAd);
68641 +
68642 +VOID MlmeHalt(
68643 + IN PRTMP_ADAPTER pAd);
68644 +
68645 +VOID MlmeResetRalinkCounters(
68646 + IN PRTMP_ADAPTER pAd);
68647 +
68648 +VOID BuildChannelList(
68649 + IN PRTMP_ADAPTER pAd);
68650 +
68651 +UCHAR FirstChannel(
68652 + IN PRTMP_ADAPTER pAd);
68653 +
68654 +UCHAR NextChannel(
68655 + IN PRTMP_ADAPTER pAd,
68656 + IN UCHAR channel);
68657 +
68658 +VOID ChangeToCellPowerLimit(
68659 + IN PRTMP_ADAPTER pAd,
68660 + IN UCHAR AironetCellPowerLimit);
68661 +
68662 +VOID RaiseClock(
68663 + IN PRTMP_ADAPTER pAd,
68664 + IN UINT32 *x);
68665 +
68666 +VOID LowerClock(
68667 + IN PRTMP_ADAPTER pAd,
68668 + IN UINT32 *x);
68669 +
68670 +USHORT ShiftInBits(
68671 + IN PRTMP_ADAPTER pAd);
68672 +
68673 +VOID ShiftOutBits(
68674 + IN PRTMP_ADAPTER pAd,
68675 + IN USHORT data,
68676 + IN USHORT count);
68677 +
68678 +VOID EEpromCleanup(
68679 + IN PRTMP_ADAPTER pAd);
68680 +
68681 +VOID EWDS(
68682 + IN PRTMP_ADAPTER pAd);
68683 +
68684 +VOID EWEN(
68685 + IN PRTMP_ADAPTER pAd);
68686 +
68687 +USHORT RTMP_EEPROM_READ16(
68688 + IN PRTMP_ADAPTER pAd,
68689 + IN USHORT Offset);
68690 +
68691 +VOID RTMP_EEPROM_WRITE16(
68692 + IN PRTMP_ADAPTER pAd,
68693 + IN USHORT Offset,
68694 + IN USHORT Data);
68695 +
68696 +//
68697 +// Prototypes of function definition in rtmp_tkip.c
68698 +//
68699 +VOID RTMPInitTkipEngine(
68700 + IN PRTMP_ADAPTER pAd,
68701 + IN PUCHAR pTKey,
68702 + IN UCHAR KeyId,
68703 + IN PUCHAR pTA,
68704 + IN PUCHAR pMICKey,
68705 + IN PUCHAR pTSC,
68706 + OUT PULONG pIV16,
68707 + OUT PULONG pIV32);
68708 +
68709 +VOID RTMPInitMICEngine(
68710 + IN PRTMP_ADAPTER pAd,
68711 + IN PUCHAR pKey,
68712 + IN PUCHAR pDA,
68713 + IN PUCHAR pSA,
68714 + IN UCHAR UserPriority,
68715 + IN PUCHAR pMICKey);
68716 +
68717 +BOOLEAN RTMPTkipCompareMICValue(
68718 + IN PRTMP_ADAPTER pAd,
68719 + IN PUCHAR pSrc,
68720 + IN PUCHAR pDA,
68721 + IN PUCHAR pSA,
68722 + IN PUCHAR pMICKey,
68723 + IN UCHAR UserPriority,
68724 + IN UINT Len);
68725 +
68726 +VOID RTMPCalculateMICValue(
68727 + IN PRTMP_ADAPTER pAd,
68728 + IN PNDIS_PACKET pPacket,
68729 + IN PUCHAR pEncap,
68730 + IN PCIPHER_KEY pKey,
68731 + IN UCHAR apidx);
68732 +
68733 +BOOLEAN RTMPTkipCompareMICValueWithLLC(
68734 + IN PRTMP_ADAPTER pAd,
68735 + IN PUCHAR pLLC,
68736 + IN PUCHAR pSrc,
68737 + IN PUCHAR pDA,
68738 + IN PUCHAR pSA,
68739 + IN PUCHAR pMICKey,
68740 + IN UINT Len);
68741 +
68742 +VOID RTMPTkipAppendByte(
68743 + IN PTKIP_KEY_INFO pTkip,
68744 + IN UCHAR uChar);
68745 +
68746 +VOID RTMPTkipAppend(
68747 + IN PTKIP_KEY_INFO pTkip,
68748 + IN PUCHAR pSrc,
68749 + IN UINT nBytes);
68750 +
68751 +VOID RTMPTkipGetMIC(
68752 + IN PTKIP_KEY_INFO pTkip);
68753 +
68754 +BOOLEAN RTMPSoftDecryptTKIP(
68755 + IN PRTMP_ADAPTER pAd,
68756 + IN PUCHAR pData,
68757 + IN ULONG DataByteCnt,
68758 + IN UCHAR UserPriority,
68759 + IN PCIPHER_KEY pWpaKey);
68760 +
68761 +BOOLEAN RTMPSoftDecryptAES(
68762 + IN PRTMP_ADAPTER pAd,
68763 + IN PUCHAR pData,
68764 + IN ULONG DataByteCnt,
68765 + IN PCIPHER_KEY pWpaKey);
68766 +
68767 +#if 0 // removed by AlbertY
68768 +NDIS_STATUS RTMPWPAAddKeyProc(
68769 + IN PRTMP_ADAPTER pAd,
68770 + IN PVOID pBuf);
68771 +#endif
68772 +
68773 +//
68774 +// Prototypes of function definition in cmm_info.c
68775 +//
68776 +NDIS_STATUS RTMPWPARemoveKeyProc(
68777 + IN PRTMP_ADAPTER pAd,
68778 + IN PVOID pBuf);
68779 +
68780 +VOID RTMPWPARemoveAllKeys(
68781 + IN PRTMP_ADAPTER pAd);
68782 +
68783 +BOOLEAN RTMPCheckStrPrintAble(
68784 + IN CHAR *pInPutStr,
68785 + IN UCHAR strLen);
68786 +
68787 +VOID RTMPSetPhyMode(
68788 + IN PRTMP_ADAPTER pAd,
68789 + IN ULONG phymode);
68790 +
68791 +VOID RTMPUpdateHTIE(
68792 + IN RT_HT_CAPABILITY *pRtHt,
68793 + IN UCHAR *pMcsSet,
68794 + OUT HT_CAPABILITY_IE *pHtCapability,
68795 + OUT ADD_HT_INFO_IE *pAddHtInfo);
68796 +
68797 +VOID RTMPAddWcidAttributeEntry(
68798 + IN PRTMP_ADAPTER pAd,
68799 + IN UCHAR BssIdx,
68800 + IN UCHAR KeyIdx,
68801 + IN UCHAR CipherAlg,
68802 + IN MAC_TABLE_ENTRY *pEntry);
68803 +
68804 +CHAR *GetEncryptType(
68805 + CHAR enc);
68806 +
68807 +CHAR *GetAuthMode(
68808 + CHAR auth);
68809 +
68810 +VOID RTMPIoctlGetSiteSurvey(
68811 + IN PRTMP_ADAPTER pAdapter,
68812 + IN struct iwreq *wrq);
68813 +
68814 +VOID RTMPIoctlGetMacTable(
68815 + IN PRTMP_ADAPTER pAd,
68816 + IN struct iwreq *wrq);
68817 +
68818 +VOID RTMPIndicateWPA2Status(
68819 + IN PRTMP_ADAPTER pAdapter);
68820 +
68821 +VOID RTMPOPModeSwitching(
68822 + IN PRTMP_ADAPTER pAd);
68823 +
68824 +#ifdef CONFIG_STA_SUPPORT
68825 +VOID RTMPAddBSSIDCipher(
68826 + IN PRTMP_ADAPTER pAd,
68827 + IN UCHAR Aid,
68828 + IN PNDIS_802_11_KEY pKey,
68829 + IN UCHAR CipherAlg);
68830 +#endif // CONFIG_STA_SUPPORT //
68831 +
68832 +#ifdef DOT11_N_SUPPORT
68833 +VOID RTMPSetHT(
68834 + IN PRTMP_ADAPTER pAd,
68835 + IN OID_SET_HT_PHYMODE *pHTPhyMode);
68836 +
68837 +VOID RTMPSetIndividualHT(
68838 + IN PRTMP_ADAPTER pAd,
68839 + IN UCHAR apidx);
68840 +#endif // DOT11_N_SUPPORT //
68841 +
68842 +VOID RTMPSendWirelessEvent(
68843 + IN PRTMP_ADAPTER pAd,
68844 + IN USHORT Event_flag,
68845 + IN PUCHAR pAddr,
68846 + IN UCHAR BssIdx,
68847 + IN CHAR Rssi);
68848 +
68849 +VOID NICUpdateCntlCounters(
68850 + IN PRTMP_ADAPTER pAd,
68851 + IN PHEADER_802_11 pHeader,
68852 + IN UCHAR SubType,
68853 + IN PRXWI_STRUC pRxWI);
68854 +//
68855 +// prototype in wpa.c
68856 +//
68857 +BOOLEAN WpaMsgTypeSubst(
68858 + IN UCHAR EAPType,
68859 + OUT INT *MsgType);
68860 +
68861 +VOID WpaPskStateMachineInit(
68862 + IN PRTMP_ADAPTER pAd,
68863 + IN STATE_MACHINE *S,
68864 + OUT STATE_MACHINE_FUNC Trans[]);
68865 +
68866 +VOID WpaEAPOLKeyAction(
68867 + IN PRTMP_ADAPTER pAd,
68868 + IN MLME_QUEUE_ELEM *Elem);
68869 +
68870 +VOID WpaPairMsg1Action(
68871 + IN PRTMP_ADAPTER pAd,
68872 + IN MLME_QUEUE_ELEM *Elem);
68873 +
68874 +VOID WpaPairMsg3Action(
68875 + IN PRTMP_ADAPTER pAd,
68876 + IN MLME_QUEUE_ELEM *Elem);
68877 +
68878 +VOID WpaGroupMsg1Action(
68879 + IN PRTMP_ADAPTER pAd,
68880 + IN MLME_QUEUE_ELEM *Elem);
68881 +
68882 +VOID WpaMacHeaderInit(
68883 + IN PRTMP_ADAPTER pAd,
68884 + IN OUT PHEADER_802_11 pHdr80211,
68885 + IN UCHAR wep,
68886 + IN PUCHAR pAddr1);
68887 +
68888 +VOID Wpa2PairMsg1Action(
68889 + IN PRTMP_ADAPTER pAd,
68890 + IN MLME_QUEUE_ELEM *Elem);
68891 +
68892 +VOID Wpa2PairMsg3Action(
68893 + IN PRTMP_ADAPTER pAd,
68894 + IN MLME_QUEUE_ELEM *Elem);
68895 +
68896 +BOOLEAN ParseKeyData(
68897 + IN PRTMP_ADAPTER pAd,
68898 + IN PUCHAR pKeyData,
68899 + IN UCHAR KeyDataLen,
68900 + IN UCHAR bPairewise);
68901 +
68902 +VOID RTMPToWirelessSta(
68903 + IN PRTMP_ADAPTER pAd,
68904 + IN PUCHAR pHeader802_3,
68905 + IN UINT HdrLen,
68906 + IN PUCHAR pData,
68907 + IN UINT DataLen,
68908 + IN BOOLEAN is4wayFrame);
68909 +
68910 +VOID HMAC_SHA1(
68911 + IN UCHAR *text,
68912 + IN UINT text_len,
68913 + IN UCHAR *key,
68914 + IN UINT key_len,
68915 + IN UCHAR *digest);
68916 +
68917 +VOID PRF(
68918 + IN UCHAR *key,
68919 + IN INT key_len,
68920 + IN UCHAR *prefix,
68921 + IN INT prefix_len,
68922 + IN UCHAR *data,
68923 + IN INT data_len,
68924 + OUT UCHAR *output,
68925 + IN INT len);
68926 +
68927 +VOID CCKMPRF(
68928 + IN UCHAR *key,
68929 + IN INT key_len,
68930 + IN UCHAR *data,
68931 + IN INT data_len,
68932 + OUT UCHAR *output,
68933 + IN INT len);
68934 +
68935 +VOID WpaCountPTK(
68936 + IN PRTMP_ADAPTER pAd,
68937 + IN UCHAR *PMK,
68938 + IN UCHAR *ANonce,
68939 + IN UCHAR *AA,
68940 + IN UCHAR *SNonce,
68941 + IN UCHAR *SA,
68942 + OUT UCHAR *output,
68943 + IN UINT len);
68944 +
68945 +VOID GenRandom(
68946 + IN PRTMP_ADAPTER pAd,
68947 + IN UCHAR *macAddr,
68948 + OUT UCHAR *random);
68949 +
68950 +//
68951 +// prototype in aironet.c
68952 +//
68953 +VOID AironetStateMachineInit(
68954 + IN PRTMP_ADAPTER pAd,
68955 + IN STATE_MACHINE *S,
68956 + OUT STATE_MACHINE_FUNC Trans[]);
68957 +
68958 +VOID AironetMsgAction(
68959 + IN PRTMP_ADAPTER pAd,
68960 + IN MLME_QUEUE_ELEM *Elem);
68961 +
68962 +VOID AironetRequestAction(
68963 + IN PRTMP_ADAPTER pAd,
68964 + IN MLME_QUEUE_ELEM *Elem);
68965 +
68966 +VOID ChannelLoadRequestAction(
68967 + IN PRTMP_ADAPTER pAd,
68968 + IN UCHAR Index);
68969 +
68970 +VOID NoiseHistRequestAction(
68971 + IN PRTMP_ADAPTER pAd,
68972 + IN UCHAR Index);
68973 +
68974 +VOID BeaconRequestAction(
68975 + IN PRTMP_ADAPTER pAd,
68976 + IN UCHAR Index);
68977 +
68978 +VOID AironetReportAction(
68979 + IN PRTMP_ADAPTER pAd,
68980 + IN MLME_QUEUE_ELEM *Elem);
68981 +
68982 +VOID ChannelLoadReportAction(
68983 + IN PRTMP_ADAPTER pAd,
68984 + IN UCHAR Index);
68985 +
68986 +VOID NoiseHistReportAction(
68987 + IN PRTMP_ADAPTER pAd,
68988 + IN UCHAR Index);
68989 +
68990 +VOID AironetFinalReportAction(
68991 + IN PRTMP_ADAPTER pAd);
68992 +
68993 +VOID BeaconReportAction(
68994 + IN PRTMP_ADAPTER pAd,
68995 + IN UCHAR Index);
68996 +
68997 +VOID AironetAddBeaconReport(
68998 + IN PRTMP_ADAPTER pAd,
68999 + IN ULONG Index,
69000 + IN PMLME_QUEUE_ELEM pElem);
69001 +
69002 +VOID AironetCreateBeaconReportFromBssTable(
69003 + IN PRTMP_ADAPTER pAd);
69004 +
69005 +VOID DBGPRINT_TX_RING(
69006 + IN PRTMP_ADAPTER pAd,
69007 + IN UCHAR QueIdx);
69008 +
69009 +VOID DBGPRINT_RX_RING(
69010 + IN PRTMP_ADAPTER pAd);
69011 +
69012 +CHAR ConvertToRssi(
69013 + IN PRTMP_ADAPTER pAd,
69014 + IN CHAR Rssi,
69015 + IN UCHAR RssiNumber);
69016 +
69017 +
69018 +#ifdef DOT11N_DRAFT3
69019 +VOID BuildEffectedChannelList(
69020 + IN PRTMP_ADAPTER pAd);
69021 +#endif // DOT11N_DRAFT3 //
69022 +
69023 +
69024 +VOID APAsicEvaluateRxAnt(
69025 + IN PRTMP_ADAPTER pAd);
69026 +
69027 +
69028 +VOID APAsicRxAntEvalTimeout(
69029 + IN PRTMP_ADAPTER pAd);
69030 +
69031 +//
69032 +// function prototype in cmm_wpa.c
69033 +//
69034 +BOOLEAN RTMPCheckWPAframe(
69035 + IN PRTMP_ADAPTER pAd,
69036 + IN PMAC_TABLE_ENTRY pEntry,
69037 + IN PUCHAR pData,
69038 + IN ULONG DataByteCount,
69039 + IN UCHAR FromWhichBSSID);
69040 +
69041 +VOID AES_GTK_KEY_UNWRAP(
69042 + IN UCHAR *key,
69043 + OUT UCHAR *plaintext,
69044 + IN UCHAR c_len,
69045 + IN UCHAR *ciphertext);
69046 +
69047 +BOOLEAN RTMPCheckRSNIE(
69048 + IN PRTMP_ADAPTER pAd,
69049 + IN PUCHAR pData,
69050 + IN UCHAR DataLen,
69051 + IN MAC_TABLE_ENTRY *pEntry,
69052 + OUT UCHAR *Offset);
69053 +
69054 +BOOLEAN RTMPParseEapolKeyData(
69055 + IN PRTMP_ADAPTER pAd,
69056 + IN PUCHAR pKeyData,
69057 + IN UCHAR KeyDataLen,
69058 + IN UCHAR GroupKeyIndex,
69059 + IN UCHAR MsgType,
69060 + IN BOOLEAN bWPA2,
69061 + IN MAC_TABLE_ENTRY *pEntry);
69062 +
69063 +VOID ConstructEapolMsg(
69064 + IN PRTMP_ADAPTER pAd,
69065 + IN UCHAR PeerAuthMode,
69066 + IN UCHAR PeerWepStatus,
69067 + IN UCHAR MyGroupKeyWepStatus,
69068 + IN UCHAR MsgType,
69069 + IN UCHAR DefaultKeyIdx,
69070 + IN UCHAR *ReplayCounter,
69071 + IN UCHAR *KeyNonce,
69072 + IN UCHAR *TxRSC,
69073 + IN UCHAR *PTK,
69074 + IN UCHAR *GTK,
69075 + IN UCHAR *RSNIE,
69076 + IN UCHAR RSNIE_Len,
69077 + OUT PEAPOL_PACKET pMsg);
69078 +
69079 +VOID CalculateMIC(
69080 + IN PRTMP_ADAPTER pAd,
69081 + IN UCHAR PeerWepStatus,
69082 + IN UCHAR *PTK,
69083 + OUT PEAPOL_PACKET pMsg);
69084 +
69085 +NDIS_STATUS RTMPSoftDecryptBroadCastData(
69086 + IN PRTMP_ADAPTER pAd,
69087 + IN RX_BLK *pRxBlk,
69088 + IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
69089 + IN PCIPHER_KEY pShard_key);
69090 +
69091 +VOID ConstructEapolKeyData(
69092 + IN PRTMP_ADAPTER pAd,
69093 + IN UCHAR PeerAuthMode,
69094 + IN UCHAR PeerWepStatus,
69095 + IN UCHAR GroupKeyWepStatus,
69096 + IN UCHAR MsgType,
69097 + IN UCHAR DefaultKeyIdx,
69098 + IN BOOLEAN bWPA2Capable,
69099 + IN UCHAR *PTK,
69100 + IN UCHAR *GTK,
69101 + IN UCHAR *RSNIE,
69102 + IN UCHAR RSNIE_LEN,
69103 + OUT PEAPOL_PACKET pMsg);
69104 +
69105 +VOID RTMPMakeRSNIE(
69106 + IN PRTMP_ADAPTER pAd,
69107 + IN UINT AuthMode,
69108 + IN UINT WepStatus,
69109 + IN UCHAR apidx);
69110 +
69111 +//
69112 +// function prototype in ap_wpa.c
69113 +//
69114 +
69115 +BOOLEAN APWpaMsgTypeSubst(
69116 + IN UCHAR EAPType,
69117 + OUT INT *MsgType) ;
69118 +
69119 +MAC_TABLE_ENTRY *PACInquiry(
69120 + IN PRTMP_ADAPTER pAd,
69121 + IN ULONG Wcid);
69122 +
69123 +BOOLEAN RTMPCheckMcast(
69124 + IN PRTMP_ADAPTER pAd,
69125 + IN PEID_STRUCT eid_ptr,
69126 + IN MAC_TABLE_ENTRY *pEntry);
69127 +
69128 +BOOLEAN RTMPCheckUcast(
69129 + IN PRTMP_ADAPTER pAd,
69130 + IN PEID_STRUCT eid_ptr,
69131 + IN MAC_TABLE_ENTRY *pEntry);
69132 +
69133 +BOOLEAN RTMPCheckAUTH(
69134 + IN PRTMP_ADAPTER pAd,
69135 + IN PEID_STRUCT eid_ptr,
69136 + IN MAC_TABLE_ENTRY *pEntry);
69137 +
69138 +VOID WPAStart4WayHS(
69139 + IN PRTMP_ADAPTER pAd,
69140 + IN MAC_TABLE_ENTRY *pEntry,
69141 + IN ULONG TimeInterval);
69142 +
69143 +VOID WPAStart2WayGroupHS(
69144 + IN PRTMP_ADAPTER pAd,
69145 + IN MAC_TABLE_ENTRY *pEntry);
69146 +
69147 +VOID APWpaEAPPacketAction(
69148 + IN PRTMP_ADAPTER pAd,
69149 + IN MLME_QUEUE_ELEM *Elem);
69150 +
69151 +VOID APWpaEAPOLStartAction(
69152 + IN PRTMP_ADAPTER pAd,
69153 + IN MLME_QUEUE_ELEM *Elem);
69154 +
69155 +VOID APWpaEAPOLLogoffAction(
69156 + IN PRTMP_ADAPTER pAd,
69157 + IN MLME_QUEUE_ELEM *Elem);
69158 +
69159 +VOID APWpaEAPOLKeyAction(
69160 + IN PRTMP_ADAPTER pAd,
69161 + IN MLME_QUEUE_ELEM *Elem);
69162 +
69163 +VOID APWpaEAPOLASFAlertAction(
69164 + IN PRTMP_ADAPTER pAd,
69165 + IN MLME_QUEUE_ELEM *Elem);
69166 +
69167 +VOID HandleCounterMeasure(
69168 + IN PRTMP_ADAPTER pAd,
69169 + IN MAC_TABLE_ENTRY *pEntry);
69170 +
69171 +VOID PeerPairMsg2Action(
69172 + IN PRTMP_ADAPTER pAd,
69173 + IN MAC_TABLE_ENTRY *pEntry,
69174 + IN MLME_QUEUE_ELEM *Elem);
69175 +
69176 +VOID PeerPairMsg4Action(
69177 + IN PRTMP_ADAPTER pAd,
69178 + IN MAC_TABLE_ENTRY *pEntry,
69179 + IN MLME_QUEUE_ELEM *Elem);
69180 +
69181 +VOID CMTimerExec(
69182 + IN PVOID SystemSpecific1,
69183 + IN PVOID FunctionContext,
69184 + IN PVOID SystemSpecific2,
69185 + IN PVOID SystemSpecific3);
69186 +
69187 +VOID WPARetryExec(
69188 + IN PVOID SystemSpecific1,
69189 + IN PVOID FunctionContext,
69190 + IN PVOID SystemSpecific2,
69191 + IN PVOID SystemSpecific3);
69192 +
69193 +VOID EnqueueStartForPSKExec(
69194 + IN PVOID SystemSpecific1,
69195 + IN PVOID FunctionContext,
69196 + IN PVOID SystemSpecific2,
69197 + IN PVOID SystemSpecific3);
69198 +
69199 +VOID RTMPHandleSTAKey(
69200 + IN PRTMP_ADAPTER pAdapter,
69201 + IN MAC_TABLE_ENTRY *pEntry,
69202 + IN MLME_QUEUE_ELEM *Elem);
69203 +
69204 +#if 0 // merge into PeerPairMsg4Action
69205 +VOID Wpa1PeerPairMsg4Action(
69206 + IN PRTMP_ADAPTER pAd,
69207 + IN MAC_TABLE_ENTRY *pEntry,
69208 + IN MLME_QUEUE_ELEM *Elem);
69209 +
69210 +VOID Wpa2PeerPairMsg4Action(
69211 + IN PRTMP_ADAPTER pAd,
69212 + IN PMAC_TABLE_ENTRY pEntry,
69213 + IN MLME_QUEUE_ELEM *Elem);
69214 +#endif // 0 //
69215 +
69216 +VOID PeerGroupMsg2Action(
69217 + IN PRTMP_ADAPTER pAd,
69218 + IN PMAC_TABLE_ENTRY pEntry,
69219 + IN VOID *Msg,
69220 + IN UINT MsgLen);
69221 +
69222 +#if 0 // replaced by WPAStart2WayGroupHS
69223 +NDIS_STATUS APWpaHardTransmit(
69224 + IN PRTMP_ADAPTER pAd,
69225 + IN PMAC_TABLE_ENTRY pEntry);
69226 +#endif // 0 //
69227 +
69228 +VOID PairDisAssocAction(
69229 + IN PRTMP_ADAPTER pAd,
69230 + IN PMAC_TABLE_ENTRY pEntry,
69231 + IN USHORT Reason);
69232 +
69233 +VOID MlmeDeAuthAction(
69234 + IN PRTMP_ADAPTER pAd,
69235 + IN PMAC_TABLE_ENTRY pEntry,
69236 + IN USHORT Reason);
69237 +
69238 +VOID GREKEYPeriodicExec(
69239 + IN PVOID SystemSpecific1,
69240 + IN PVOID FunctionContext,
69241 + IN PVOID SystemSpecific2,
69242 + IN PVOID SystemSpecific3);
69243 +
69244 +VOID CountGTK(
69245 + IN UCHAR *PMK,
69246 + IN UCHAR *GNonce,
69247 + IN UCHAR *AA,
69248 + OUT UCHAR *output,
69249 + IN UINT len);
69250 +
69251 +VOID GetSmall(
69252 + IN PVOID pSrc1,
69253 + IN PVOID pSrc2,
69254 + OUT PUCHAR out,
69255 + IN ULONG Length);
69256 +
69257 +VOID GetLarge(
69258 + IN PVOID pSrc1,
69259 + IN PVOID pSrc2,
69260 + OUT PUCHAR out,
69261 + IN ULONG Length);
69262 +
69263 +VOID APGenRandom(
69264 + IN PRTMP_ADAPTER pAd,
69265 + OUT UCHAR *random);
69266 +
69267 +VOID AES_GTK_KEY_WRAP(
69268 + IN UCHAR *key,
69269 + IN UCHAR *plaintext,
69270 + IN UCHAR p_len,
69271 + OUT UCHAR *ciphertext);
69272 +
69273 +VOID WpaSend(
69274 + IN PRTMP_ADAPTER pAdapter,
69275 + IN PUCHAR pPacket,
69276 + IN ULONG Len);
69277 +
69278 +VOID APToWirelessSta(
69279 + IN PRTMP_ADAPTER pAd,
69280 + IN MAC_TABLE_ENTRY *pEntry,
69281 + IN PUCHAR pHeader802_3,
69282 + IN UINT HdrLen,
69283 + IN PUCHAR pData,
69284 + IN UINT DataLen,
69285 + IN BOOLEAN bClearFrame);
69286 +
69287 +VOID RTMPAddPMKIDCache(
69288 + IN PRTMP_ADAPTER pAd,
69289 + IN INT apidx,
69290 + IN PUCHAR pAddr,
69291 + IN UCHAR *PMKID,
69292 + IN UCHAR *PMK);
69293 +
69294 +INT RTMPSearchPMKIDCache(
69295 + IN PRTMP_ADAPTER pAd,
69296 + IN INT apidx,
69297 + IN PUCHAR pAddr);
69298 +
69299 +VOID RTMPDeletePMKIDCache(
69300 + IN PRTMP_ADAPTER pAd,
69301 + IN INT apidx,
69302 + IN INT idx);
69303 +
69304 +VOID RTMPMaintainPMKIDCache(
69305 + IN PRTMP_ADAPTER pAd);
69306 +
69307 +VOID RTMPSendTriggerFrame(
69308 + IN PRTMP_ADAPTER pAd,
69309 + IN PVOID pBuffer,
69310 + IN ULONG Length,
69311 + IN UCHAR TxRate,
69312 + IN BOOLEAN bQosNull);
69313 +
69314 +
69315 +//typedef void (*TIMER_FUNCTION)(unsigned long);
69316 +
69317 +
69318 +/* timeout -- ms */
69319 +VOID RTMP_SetPeriodicTimer(
69320 + IN NDIS_MINIPORT_TIMER *pTimer,
69321 + IN unsigned long timeout);
69322 +
69323 +VOID RTMP_OS_Init_Timer(
69324 + IN PRTMP_ADAPTER pAd,
69325 + IN NDIS_MINIPORT_TIMER *pTimer,
69326 + IN TIMER_FUNCTION function,
69327 + IN PVOID data);
69328 +
69329 +VOID RTMP_OS_Add_Timer(
69330 + IN NDIS_MINIPORT_TIMER *pTimer,
69331 + IN unsigned long timeout);
69332 +
69333 +VOID RTMP_OS_Mod_Timer(
69334 + IN NDIS_MINIPORT_TIMER *pTimer,
69335 + IN unsigned long timeout);
69336 +
69337 +
69338 +VOID RTMP_OS_Del_Timer(
69339 + IN NDIS_MINIPORT_TIMER *pTimer,
69340 + OUT BOOLEAN *pCancelled);
69341 +
69342 +
69343 +VOID RTMP_OS_Release_Packet(
69344 + IN PRTMP_ADAPTER pAd,
69345 + IN PQUEUE_ENTRY pEntry);
69346 +
69347 +VOID RTMPusecDelay(
69348 + IN ULONG usec);
69349 +
69350 +NDIS_STATUS os_alloc_mem(
69351 + IN PRTMP_ADAPTER pAd,
69352 + OUT PUCHAR *mem,
69353 + IN ULONG size);
69354 +
69355 +NDIS_STATUS os_free_mem(
69356 + IN PRTMP_ADAPTER pAd,
69357 + IN PUCHAR mem);
69358 +
69359 +
69360 +void RTMP_AllocateSharedMemory(
69361 + IN PRTMP_ADAPTER pAd,
69362 + IN ULONG Length,
69363 + IN BOOLEAN Cached,
69364 + OUT PVOID *VirtualAddress,
69365 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69366 +
69367 +VOID RTMPFreeTxRxRingMemory(
69368 + IN PRTMP_ADAPTER pAd);
69369 +
69370 +NDIS_STATUS AdapterBlockAllocateMemory(
69371 + IN PVOID handle,
69372 + OUT PVOID *ppAd);
69373 +
69374 +void RTMP_AllocateTxDescMemory(
69375 + IN PRTMP_ADAPTER pAd,
69376 + IN UINT Index,
69377 + IN ULONG Length,
69378 + IN BOOLEAN Cached,
69379 + OUT PVOID *VirtualAddress,
69380 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69381 +
69382 +void RTMP_AllocateFirstTxBuffer(
69383 + IN PRTMP_ADAPTER pAd,
69384 + IN UINT Index,
69385 + IN ULONG Length,
69386 + IN BOOLEAN Cached,
69387 + OUT PVOID *VirtualAddress,
69388 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69389 +
69390 +void RTMP_AllocateMgmtDescMemory(
69391 + IN PRTMP_ADAPTER pAd,
69392 + IN ULONG Length,
69393 + IN BOOLEAN Cached,
69394 + OUT PVOID *VirtualAddress,
69395 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69396 +
69397 +void RTMP_AllocateRxDescMemory(
69398 + IN PRTMP_ADAPTER pAd,
69399 + IN ULONG Length,
69400 + IN BOOLEAN Cached,
69401 + OUT PVOID *VirtualAddress,
69402 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69403 +
69404 +PNDIS_PACKET RTMP_AllocateRxPacketBuffer(
69405 + IN PRTMP_ADAPTER pAd,
69406 + IN ULONG Length,
69407 + IN BOOLEAN Cached,
69408 + OUT PVOID *VirtualAddress,
69409 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
69410 +
69411 +PNDIS_PACKET RTMP_AllocateTxPacketBuffer(
69412 + IN PRTMP_ADAPTER pAd,
69413 + IN ULONG Length,
69414 + IN BOOLEAN Cached,
69415 + OUT PVOID *VirtualAddress);
69416 +
69417 +PNDIS_PACKET RTMP_AllocateFragPacketBuffer(
69418 + IN PRTMP_ADAPTER pAd,
69419 + IN ULONG Length);
69420 +
69421 +void RTMP_QueryPacketInfo(
69422 + IN PNDIS_PACKET pPacket,
69423 + OUT PACKET_INFO *pPacketInfo,
69424 + OUT PUCHAR *pSrcBufVA,
69425 + OUT UINT *pSrcBufLen);
69426 +
69427 +void RTMP_QueryNextPacketInfo(
69428 + IN PNDIS_PACKET *ppPacket,
69429 + OUT PACKET_INFO *pPacketInfo,
69430 + OUT PUCHAR *pSrcBufVA,
69431 + OUT UINT *pSrcBufLen);
69432 +
69433 +
69434 +BOOLEAN RTMP_FillTxBlkInfo(
69435 + IN RTMP_ADAPTER *pAd,
69436 + IN TX_BLK *pTxBlk);
69437 +
69438 +
69439 +PRTMP_SCATTER_GATHER_LIST
69440 +rt_get_sg_list_from_packet(PNDIS_PACKET pPacket, RTMP_SCATTER_GATHER_LIST *sg);
69441 +
69442 +
69443 + void announce_802_3_packet(
69444 + IN PRTMP_ADAPTER pAd,
69445 + IN PNDIS_PACKET pPacket);
69446 +
69447 +
69448 +UINT BA_Reorder_AMSDU_Annnounce(
69449 + IN PRTMP_ADAPTER pAd,
69450 + IN PNDIS_PACKET pPacket);
69451 +
69452 +
69453 +UINT Handle_AMSDU_Packet(
69454 + IN PRTMP_ADAPTER pAd,
69455 + IN PUCHAR pData,
69456 + IN ULONG DataSize,
69457 + IN UCHAR FromWhichBSSID);
69458 +
69459 +
69460 +void convert_802_11_to_802_3_packet(
69461 + IN PRTMP_ADAPTER pAd,
69462 + IN PNDIS_PACKET pPacket,
69463 + IN PUCHAR p8023hdr,
69464 + IN PUCHAR pData,
69465 + IN ULONG DataSize,
69466 + IN UCHAR FromWhichBSSID);
69467 +
69468 +
69469 +PNET_DEV get_netdev_from_bssid(
69470 + IN PRTMP_ADAPTER pAd,
69471 + IN UCHAR FromWhichBSSID);
69472 +
69473 +
69474 +PNDIS_PACKET duplicate_pkt(
69475 + IN PRTMP_ADAPTER pAd,
69476 + IN PUCHAR pHeader802_3,
69477 + IN UINT HdrLen,
69478 + IN PUCHAR pData,
69479 + IN ULONG DataSize,
69480 + IN UCHAR FromWhichBSSID);
69481 +
69482 +
69483 +PNDIS_PACKET duplicate_pkt_with_TKIP_MIC(
69484 + IN PRTMP_ADAPTER pAd,
69485 + IN PNDIS_PACKET pOldPkt);
69486 +
69487 +PNDIS_PACKET duplicate_pkt_with_VLAN(
69488 + IN PRTMP_ADAPTER pAd,
69489 + IN PUCHAR pHeader802_3,
69490 + IN UINT HdrLen,
69491 + IN PUCHAR pData,
69492 + IN ULONG DataSize,
69493 + IN UCHAR FromWhichBSSID);
69494 +
69495 +PNDIS_PACKET duplicate_pkt_with_WPI(
69496 + IN PRTMP_ADAPTER pAd,
69497 + IN PNDIS_PACKET pPacket,
69498 + IN UINT32 ext_head_len,
69499 + IN UINT32 ext_tail_len);
69500 +
69501 +UCHAR VLAN_8023_Header_Copy(
69502 + IN PRTMP_ADAPTER pAd,
69503 + IN PUCHAR pHeader802_3,
69504 + IN UINT HdrLen,
69505 + OUT PUCHAR pData,
69506 + IN UCHAR FromWhichBSSID);
69507 +
69508 +#ifdef DOT11_N_SUPPORT
69509 +void ba_flush_reordering_timeout_mpdus(
69510 + IN PRTMP_ADAPTER pAd,
69511 + IN PBA_REC_ENTRY pBAEntry,
69512 + IN ULONG Now32);
69513 +
69514 +
69515 +VOID BAOriSessionSetUp(
69516 + IN PRTMP_ADAPTER pAd,
69517 + IN MAC_TABLE_ENTRY *pEntry,
69518 + IN UCHAR TID,
69519 + IN USHORT TimeOut,
69520 + IN ULONG DelayTime,
69521 + IN BOOLEAN isForced);
69522 +
69523 +VOID BASessionTearDownALL(
69524 + IN OUT PRTMP_ADAPTER pAd,
69525 + IN UCHAR Wcid);
69526 +#endif // DOT11_N_SUPPORT //
69527 +
69528 +BOOLEAN OS_Need_Clone_Packet(void);
69529 +
69530 +
69531 +VOID build_tx_packet(
69532 + IN PRTMP_ADAPTER pAd,
69533 + IN PNDIS_PACKET pPacket,
69534 + IN PUCHAR pFrame,
69535 + IN ULONG FrameLen);
69536 +
69537 +
69538 +VOID BAOriSessionTearDown(
69539 + IN OUT PRTMP_ADAPTER pAd,
69540 + IN UCHAR Wcid,
69541 + IN UCHAR TID,
69542 + IN BOOLEAN bPassive,
69543 + IN BOOLEAN bForceSend);
69544 +
69545 +VOID BARecSessionTearDown(
69546 + IN OUT PRTMP_ADAPTER pAd,
69547 + IN UCHAR Wcid,
69548 + IN UCHAR TID,
69549 + IN BOOLEAN bPassive);
69550 +
69551 +BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
69552 +void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
69553 +
69554 +ULONG AutoChBssInsertEntry(
69555 + IN PRTMP_ADAPTER pAd,
69556 + IN PUCHAR pBssid,
69557 + IN CHAR Ssid[],
69558 + IN UCHAR SsidLen,
69559 + IN UCHAR ChannelNo,
69560 + IN CHAR Rssi);
69561 +
69562 +void AutoChBssTableInit(
69563 + IN PRTMP_ADAPTER pAd);
69564 +
69565 +void ChannelInfoInit(
69566 + IN PRTMP_ADAPTER pAd);
69567 +
69568 +void AutoChBssTableDestroy(
69569 + IN PRTMP_ADAPTER pAd);
69570 +
69571 +void ChannelInfoDestroy(
69572 + IN PRTMP_ADAPTER pAd);
69573 +
69574 +UCHAR New_ApAutoSelectChannel(
69575 + IN PRTMP_ADAPTER pAd);
69576 +
69577 +BOOLEAN rtstrmactohex(
69578 + IN char *s1,
69579 + IN char *s2);
69580 +
69581 +BOOLEAN rtstrcasecmp(
69582 + IN char *s1,
69583 + IN char *s2);
69584 +
69585 +char *rtstrstruncasecmp(
69586 + IN char *s1,
69587 + IN char *s2);
69588 +
69589 +char *rtstrstr(
69590 + IN const char * s1,
69591 + IN const char * s2);
69592 +
69593 +char *rstrtok(
69594 + IN char * s,
69595 + IN const char * ct);
69596 +
69597 +int rtinet_aton(
69598 + const char *cp,
69599 + unsigned int *addr);
69600 +
69601 +////////// common ioctl functions //////////
69602 +INT Set_DriverVersion_Proc(
69603 + IN PRTMP_ADAPTER pAd,
69604 + IN PUCHAR arg);
69605 +
69606 +INT Set_CountryRegion_Proc(
69607 + IN PRTMP_ADAPTER pAd,
69608 + IN PUCHAR arg);
69609 +
69610 +INT Set_CountryRegionABand_Proc(
69611 + IN PRTMP_ADAPTER pAd,
69612 + IN PUCHAR arg);
69613 +
69614 +INT Set_WirelessMode_Proc(
69615 + IN PRTMP_ADAPTER pAd,
69616 + IN PUCHAR arg);
69617 +
69618 +INT Set_Channel_Proc(
69619 + IN PRTMP_ADAPTER pAd,
69620 + IN PUCHAR arg);
69621 +
69622 +INT Set_ShortSlot_Proc(
69623 + IN PRTMP_ADAPTER pAd,
69624 + IN PUCHAR arg);
69625 +
69626 +INT Set_TxPower_Proc(
69627 + IN PRTMP_ADAPTER pAd,
69628 + IN PUCHAR arg);
69629 +
69630 +INT Set_BGProtection_Proc(
69631 + IN PRTMP_ADAPTER pAd,
69632 + IN PUCHAR arg);
69633 +
69634 +INT Set_TxPreamble_Proc(
69635 + IN PRTMP_ADAPTER pAd,
69636 + IN PUCHAR arg);
69637 +
69638 +INT Set_RTSThreshold_Proc(
69639 + IN PRTMP_ADAPTER pAd,
69640 + IN PUCHAR arg);
69641 +
69642 +INT Set_FragThreshold_Proc(
69643 + IN PRTMP_ADAPTER pAd,
69644 + IN PUCHAR arg);
69645 +
69646 +INT Set_TxBurst_Proc(
69647 + IN PRTMP_ADAPTER pAd,
69648 + IN PUCHAR arg);
69649 +
69650 +#ifdef AGGREGATION_SUPPORT
69651 +INT Set_PktAggregate_Proc(
69652 + IN PRTMP_ADAPTER pAd,
69653 + IN PUCHAR arg);
69654 +#endif
69655 +
69656 +INT Set_IEEE80211H_Proc(
69657 + IN PRTMP_ADAPTER pAd,
69658 + IN PUCHAR arg);
69659 +
69660 +#ifdef DBG
69661 +INT Set_Debug_Proc(
69662 + IN PRTMP_ADAPTER pAd,
69663 + IN PUCHAR arg);
69664 +#endif
69665 +
69666 +INT Show_DescInfo_Proc(
69667 + IN PRTMP_ADAPTER pAd,
69668 + IN PUCHAR arg);
69669 +
69670 +INT Set_ResetStatCounter_Proc(
69671 + IN PRTMP_ADAPTER pAd,
69672 + IN PUCHAR arg);
69673 +
69674 +#ifdef DOT11_N_SUPPORT
69675 +INT Set_BASetup_Proc(
69676 + IN PRTMP_ADAPTER pAd,
69677 + IN PUCHAR arg);
69678 +
69679 +INT Set_BADecline_Proc(
69680 + IN PRTMP_ADAPTER pAd,
69681 + IN PUCHAR arg);
69682 +
69683 +INT Set_BAOriTearDown_Proc(
69684 + IN PRTMP_ADAPTER pAd,
69685 + IN PUCHAR arg);
69686 +
69687 +INT Set_BARecTearDown_Proc(
69688 + IN PRTMP_ADAPTER pAd,
69689 + IN PUCHAR arg);
69690 +
69691 +INT Set_HtBw_Proc(
69692 + IN PRTMP_ADAPTER pAd,
69693 + IN PUCHAR arg);
69694 +
69695 +INT Set_HtMcs_Proc(
69696 + IN PRTMP_ADAPTER pAd,
69697 + IN PUCHAR arg);
69698 +
69699 +INT Set_HtGi_Proc(
69700 + IN PRTMP_ADAPTER pAd,
69701 + IN PUCHAR arg);
69702 +
69703 +INT Set_HtOpMode_Proc(
69704 + IN PRTMP_ADAPTER pAd,
69705 + IN PUCHAR arg);
69706 +
69707 +INT Set_HtStbc_Proc(
69708 + IN PRTMP_ADAPTER pAd,
69709 + IN PUCHAR arg);
69710 +
69711 +INT Set_HtHtc_Proc(
69712 + IN PRTMP_ADAPTER pAd,
69713 + IN PUCHAR arg);
69714 +
69715 +INT Set_HtExtcha_Proc(
69716 + IN PRTMP_ADAPTER pAd,
69717 + IN PUCHAR arg);
69718 +
69719 +INT Set_HtMpduDensity_Proc(
69720 + IN PRTMP_ADAPTER pAd,
69721 + IN PUCHAR arg);
69722 +
69723 +INT Set_HtBaWinSize_Proc(
69724 + IN PRTMP_ADAPTER pAd,
69725 + IN PUCHAR arg);
69726 +
69727 +INT Set_HtRdg_Proc(
69728 + IN PRTMP_ADAPTER pAd,
69729 + IN PUCHAR arg);
69730 +
69731 +INT Set_HtLinkAdapt_Proc(
69732 + IN PRTMP_ADAPTER pAd,
69733 + IN PUCHAR arg);
69734 +
69735 +INT Set_HtAmsdu_Proc(
69736 + IN PRTMP_ADAPTER pAd,
69737 + IN PUCHAR arg);
69738 +
69739 +INT Set_HtAutoBa_Proc(
69740 + IN PRTMP_ADAPTER pAd,
69741 + IN PUCHAR arg);
69742 +
69743 +INT Set_HtProtect_Proc(
69744 + IN PRTMP_ADAPTER pAd,
69745 + IN PUCHAR arg);
69746 +
69747 +INT Set_HtMimoPs_Proc(
69748 + IN PRTMP_ADAPTER pAd,
69749 + IN PUCHAR arg);
69750 +
69751 +
69752 +INT Set_ForceShortGI_Proc(
69753 + IN PRTMP_ADAPTER pAd,
69754 + IN PUCHAR arg);
69755 +
69756 +INT Set_ForceGF_Proc(
69757 + IN PRTMP_ADAPTER pAd,
69758 + IN PUCHAR arg);
69759 +
69760 +INT SetCommonHT(
69761 + IN PRTMP_ADAPTER pAd);
69762 +
69763 +INT Set_SendPSMPAction_Proc(
69764 + IN PRTMP_ADAPTER pAd,
69765 + IN PUCHAR arg);
69766 +
69767 +INT Set_HtMIMOPSmode_Proc(
69768 + IN PRTMP_ADAPTER pAd,
69769 + IN PUCHAR arg);
69770 +
69771 +
69772 +INT Set_HtTxBASize_Proc(
69773 + IN PRTMP_ADAPTER pAd,
69774 + IN PUCHAR arg);
69775 +#endif // DOT11_N_SUPPORT //
69776 +
69777 +
69778 +
69779 +#ifdef CONFIG_STA_SUPPORT
69780 +//Dls , kathy
69781 +VOID RTMPSendDLSTearDownFrame(
69782 + IN PRTMP_ADAPTER pAd,
69783 + IN PUCHAR pDA);
69784 +
69785 +#ifdef DOT11_N_SUPPORT
69786 +//Block ACK
69787 +VOID QueryBATABLE(
69788 + IN PRTMP_ADAPTER pAd,
69789 + OUT PQUERYBA_TABLE pBAT);
69790 +#endif // DOT11_N_SUPPORT //
69791 +
69792 +#ifdef WPA_SUPPLICANT_SUPPORT
69793 +INT WpaCheckEapCode(
69794 + IN PRTMP_ADAPTER pAd,
69795 + IN PUCHAR pFrame,
69796 + IN USHORT FrameLen,
69797 + IN USHORT OffSet);
69798 +
69799 +VOID WpaSendMicFailureToWpaSupplicant(
69800 + IN PRTMP_ADAPTER pAd,
69801 + IN BOOLEAN bUnicast);
69802 +
69803 +VOID SendAssocIEsToWpaSupplicant(
69804 + IN PRTMP_ADAPTER pAd);
69805 +#endif // WPA_SUPPLICANT_SUPPORT //
69806 +
69807 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
69808 +int wext_notify_event_assoc(
69809 + IN RTMP_ADAPTER *pAd);
69810 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
69811 +
69812 +#endif // CONFIG_STA_SUPPORT //
69813 +
69814 +
69815 +
69816 +#ifdef DOT11_N_SUPPORT
69817 +VOID Handle_BSS_Width_Trigger_Events(
69818 + IN PRTMP_ADAPTER pAd);
69819 +
69820 +void build_ext_channel_switch_ie(
69821 + IN PRTMP_ADAPTER pAd,
69822 + IN HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE *pIE);
69823 +#endif // DOT11_N_SUPPORT //
69824 +
69825 +
69826 +BOOLEAN APRxDoneInterruptHandle(
69827 + IN PRTMP_ADAPTER pAd);
69828 +
69829 +BOOLEAN STARxDoneInterruptHandle(
69830 + IN PRTMP_ADAPTER pAd,
69831 + IN BOOLEAN argc);
69832 +
69833 +#ifdef DOT11_N_SUPPORT
69834 +// AMPDU packet indication
69835 +VOID Indicate_AMPDU_Packet(
69836 + IN PRTMP_ADAPTER pAd,
69837 + IN RX_BLK *pRxBlk,
69838 + IN UCHAR FromWhichBSSID);
69839 +
69840 +// AMSDU packet indication
69841 +VOID Indicate_AMSDU_Packet(
69842 + IN PRTMP_ADAPTER pAd,
69843 + IN RX_BLK *pRxBlk,
69844 + IN UCHAR FromWhichBSSID);
69845 +#endif // DOT11_N_SUPPORT //
69846 +
69847 +// Normal legacy Rx packet indication
69848 +VOID Indicate_Legacy_Packet(
69849 + IN PRTMP_ADAPTER pAd,
69850 + IN RX_BLK *pRxBlk,
69851 + IN UCHAR FromWhichBSSID);
69852 +
69853 +VOID Indicate_EAPOL_Packet(
69854 + IN PRTMP_ADAPTER pAd,
69855 + IN RX_BLK *pRxBlk,
69856 + IN UCHAR FromWhichBSSID);
69857 +
69858 +void update_os_packet_info(
69859 + IN PRTMP_ADAPTER pAd,
69860 + IN RX_BLK *pRxBlk,
69861 + IN UCHAR FromWhichBSSID);
69862 +
69863 +void wlan_802_11_to_802_3_packet(
69864 + IN PRTMP_ADAPTER pAd,
69865 + IN RX_BLK *pRxBlk,
69866 + IN PUCHAR pHeader802_3,
69867 + IN UCHAR FromWhichBSSID);
69868 +
69869 +UINT deaggregate_AMSDU_announce(
69870 + IN PRTMP_ADAPTER pAd,
69871 + PNDIS_PACKET pPacket,
69872 + IN PUCHAR pData,
69873 + IN ULONG DataSize);
69874 +
69875 +
69876 +#ifdef CONFIG_STA_SUPPORT
69877 +// remove LLC and get 802_3 Header
69878 +#define RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3) \
69879 +{ \
69880 + PUCHAR _pRemovedLLCSNAP = NULL, _pDA, _pSA; \
69881 + \
69882 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH)) \
69883 + { \
69884 + _pDA = _pRxBlk->pHeader->Addr3; \
69885 + _pSA = (PUCHAR)_pRxBlk->pHeader + sizeof(HEADER_802_11); \
69886 + } \
69887 + else \
69888 + { \
69889 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA)) \
69890 + { \
69891 + _pDA = _pRxBlk->pHeader->Addr1; \
69892 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS)) \
69893 + _pSA = _pRxBlk->pHeader->Addr2; \
69894 + else \
69895 + _pSA = _pRxBlk->pHeader->Addr3; \
69896 + } \
69897 + else \
69898 + { \
69899 + _pDA = _pRxBlk->pHeader->Addr1; \
69900 + _pSA = _pRxBlk->pHeader->Addr2; \
69901 + } \
69902 + } \
69903 + \
69904 + CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData, \
69905 + _pRxBlk->DataSize, _pRemovedLLCSNAP); \
69906 +}
69907 +#endif // CONFIG_STA_SUPPORT //
69908 +
69909 +
69910 +BOOLEAN APFowardWirelessStaToWirelessSta(
69911 + IN PRTMP_ADAPTER pAd,
69912 + IN PNDIS_PACKET pPacket,
69913 + IN ULONG FromWhichBSSID);
69914 +
69915 +VOID Announce_or_Forward_802_3_Packet(
69916 + IN PRTMP_ADAPTER pAd,
69917 + IN PNDIS_PACKET pPacket,
69918 + IN UCHAR FromWhichBSSID);
69919 +
69920 +VOID Sta_Announce_or_Forward_802_3_Packet(
69921 + IN PRTMP_ADAPTER pAd,
69922 + IN PNDIS_PACKET pPacket,
69923 + IN UCHAR FromWhichBSSID);
69924 +
69925 +
69926 +#ifdef CONFIG_STA_SUPPORT
69927 +#define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
69928 + Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
69929 + //announce_802_3_packet(_pAd, _pPacket);
69930 +#endif // CONFIG_STA_SUPPORT //
69931 +
69932 +
69933 +PNDIS_PACKET DuplicatePacket(
69934 + IN PRTMP_ADAPTER pAd,
69935 + IN PNDIS_PACKET pPacket,
69936 + IN UCHAR FromWhichBSSID);
69937 +
69938 +
69939 +PNDIS_PACKET ClonePacket(
69940 + IN PRTMP_ADAPTER pAd,
69941 + IN PNDIS_PACKET pPacket,
69942 + IN PUCHAR pData,
69943 + IN ULONG DataSize);
69944 +
69945 +
69946 +// Normal, AMPDU or AMSDU
69947 +VOID CmmRxnonRalinkFrameIndicate(
69948 + IN PRTMP_ADAPTER pAd,
69949 + IN RX_BLK *pRxBlk,
69950 + IN UCHAR FromWhichBSSID);
69951 +
69952 +VOID CmmRxRalinkFrameIndicate(
69953 + IN PRTMP_ADAPTER pAd,
69954 + IN MAC_TABLE_ENTRY *pEntry,
69955 + IN RX_BLK *pRxBlk,
69956 + IN UCHAR FromWhichBSSID);
69957 +
69958 +VOID Update_Rssi_Sample(
69959 + IN PRTMP_ADAPTER pAd,
69960 + IN RSSI_SAMPLE *pRssi,
69961 + IN PRXWI_STRUC pRxWI);
69962 +
69963 +PNDIS_PACKET GetPacketFromRxRing(
69964 + IN PRTMP_ADAPTER pAd,
69965 + OUT PRT28XX_RXD_STRUC pSaveRxD,
69966 + OUT BOOLEAN *pbReschedule,
69967 + IN OUT UINT32 *pRxPending);
69968 +
69969 +PNDIS_PACKET RTMPDeFragmentDataFrame(
69970 + IN PRTMP_ADAPTER pAd,
69971 + IN RX_BLK *pRxBlk);
69972 +
69973 +////////////////////////////////////////
69974 +
69975 +
69976 +
69977 +
69978 +
69979 +#ifdef SNMP_SUPPORT
69980 +//for snmp , kathy
69981 +typedef struct _DefaultKeyIdxValue
69982 +{
69983 + UCHAR KeyIdx;
69984 + UCHAR Value[16];
69985 +} DefaultKeyIdxValue, *PDefaultKeyIdxValue;
69986 +#endif
69987 +
69988 +
69989 +#ifdef CONFIG_STA_SUPPORT
69990 +enum {
69991 + DIDmsg_lnxind_wlansniffrm = 0x00000044,
69992 + DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
69993 + DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
69994 + DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
69995 + DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
69996 + DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
69997 + DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
69998 + DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
69999 + DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
70000 + DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
70001 + DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
70002 +};
70003 +enum {
70004 + P80211ENUM_msgitem_status_no_value = 0x00
70005 +};
70006 +enum {
70007 + P80211ENUM_truth_false = 0x00,
70008 + P80211ENUM_truth_true = 0x01
70009 +};
70010 +
70011 +/* Definition from madwifi */
70012 +typedef struct {
70013 + UINT32 did;
70014 + UINT16 status;
70015 + UINT16 len;
70016 + UINT32 data;
70017 +} p80211item_uint32_t;
70018 +
70019 +typedef struct {
70020 + UINT32 msgcode;
70021 + UINT32 msglen;
70022 +#define WLAN_DEVNAMELEN_MAX 16
70023 + UINT8 devname[WLAN_DEVNAMELEN_MAX];
70024 + p80211item_uint32_t hosttime;
70025 + p80211item_uint32_t mactime;
70026 + p80211item_uint32_t channel;
70027 + p80211item_uint32_t rssi;
70028 + p80211item_uint32_t sq;
70029 + p80211item_uint32_t signal;
70030 + p80211item_uint32_t noise;
70031 + p80211item_uint32_t rate;
70032 + p80211item_uint32_t istx;
70033 + p80211item_uint32_t frmlen;
70034 +} wlan_ng_prism2_header;
70035 +
70036 +/* The radio capture header precedes the 802.11 header. */
70037 +typedef struct PACKED _ieee80211_radiotap_header {
70038 + UINT8 it_version; /* Version 0. Only increases
70039 + * for drastic changes,
70040 + * introduction of compatible
70041 + * new fields does not count.
70042 + */
70043 + UINT8 it_pad;
70044 + UINT16 it_len; /* length of the whole
70045 + * header in bytes, including
70046 + * it_version, it_pad,
70047 + * it_len, and data fields.
70048 + */
70049 + UINT32 it_present; /* A bitmap telling which
70050 + * fields are present. Set bit 31
70051 + * (0x80000000) to extend the
70052 + * bitmap by another 32 bits.
70053 + * Additional extensions are made
70054 + * by setting bit 31.
70055 + */
70056 +}ieee80211_radiotap_header ;
70057 +
70058 +enum ieee80211_radiotap_type {
70059 + IEEE80211_RADIOTAP_TSFT = 0,
70060 + IEEE80211_RADIOTAP_FLAGS = 1,
70061 + IEEE80211_RADIOTAP_RATE = 2,
70062 + IEEE80211_RADIOTAP_CHANNEL = 3,
70063 + IEEE80211_RADIOTAP_FHSS = 4,
70064 + IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
70065 + IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
70066 + IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
70067 + IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
70068 + IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
70069 + IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
70070 + IEEE80211_RADIOTAP_ANTENNA = 11,
70071 + IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
70072 + IEEE80211_RADIOTAP_DB_ANTNOISE = 13
70073 +};
70074 +
70075 +#define WLAN_RADIOTAP_PRESENT ( \
70076 + (1 << IEEE80211_RADIOTAP_TSFT) | \
70077 + (1 << IEEE80211_RADIOTAP_FLAGS) | \
70078 + (1 << IEEE80211_RADIOTAP_RATE) | \
70079 + 0)
70080 +
70081 +typedef struct _wlan_radiotap_header {
70082 + ieee80211_radiotap_header wt_ihdr;
70083 + INT64 wt_tsft;
70084 + UINT8 wt_flags;
70085 + UINT8 wt_rate;
70086 +} wlan_radiotap_header;
70087 +/* Definition from madwifi */
70088 +
70089 +void send_monitor_packets(
70090 + IN PRTMP_ADAPTER pAd,
70091 + IN RX_BLK *pRxBlk);
70092 +
70093 +#if WIRELESS_EXT >= 12
70094 +// This function will be called when query /proc
70095 +struct iw_statistics *rt28xx_get_wireless_stats(
70096 + IN struct net_device *net_dev);
70097 +#endif
70098 +
70099 +VOID RTMPSetDesiredRates(
70100 + IN PRTMP_ADAPTER pAdapter,
70101 + IN LONG Rates);
70102 +#endif // CONFIG_STA_SUPPORT //
70103 +
70104 +INT Set_FixedTxMode_Proc(
70105 + IN PRTMP_ADAPTER pAd,
70106 + IN PUCHAR arg);
70107 +
70108 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
70109 +INT Set_OpMode_Proc(
70110 + IN PRTMP_ADAPTER pAd,
70111 + IN PUCHAR arg);
70112 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
70113 +
70114 +static inline char* GetPhyMode(
70115 + int Mode)
70116 +{
70117 + switch(Mode)
70118 + {
70119 + case MODE_CCK:
70120 + return "CCK";
70121 +
70122 + case MODE_OFDM:
70123 + return "OFDM";
70124 +#ifdef DOT11_N_SUPPORT
70125 + case MODE_HTMIX:
70126 + return "HTMIX";
70127 +
70128 + case MODE_HTGREENFIELD:
70129 + return "GREEN";
70130 +#endif // DOT11_N_SUPPORT //
70131 + default:
70132 + return "N/A";
70133 + }
70134 +}
70135 +
70136 +
70137 +static inline char* GetBW(
70138 + int BW)
70139 +{
70140 + switch(BW)
70141 + {
70142 + case BW_10:
70143 + return "10M";
70144 +
70145 + case BW_20:
70146 + return "20M";
70147 +#ifdef DOT11_N_SUPPORT
70148 + case BW_40:
70149 + return "40M";
70150 +#endif // DOT11_N_SUPPORT //
70151 + default:
70152 + return "N/A";
70153 + }
70154 +}
70155 +
70156 +
70157 +VOID RT28xxThreadTerminate(
70158 + IN RTMP_ADAPTER *pAd);
70159 +
70160 +BOOLEAN RT28XXChipsetCheck(
70161 + IN void *_dev_p);
70162 +
70163 +BOOLEAN RT28XXNetDevInit(
70164 + IN void *_dev_p,
70165 + IN struct net_device *net_dev,
70166 + IN RTMP_ADAPTER *pAd);
70167 +
70168 +BOOLEAN RT28XXProbePostConfig(
70169 + IN void *_dev_p,
70170 + IN RTMP_ADAPTER *pAd,
70171 + IN INT32 argc);
70172 +
70173 +VOID RT28XXDMADisable(
70174 + IN RTMP_ADAPTER *pAd);
70175 +
70176 +VOID RT28XXDMAEnable(
70177 + IN RTMP_ADAPTER *pAd);
70178 +
70179 +VOID RT28xx_UpdateBeaconToAsic(
70180 + IN RTMP_ADAPTER * pAd,
70181 + IN INT apidx,
70182 + IN ULONG BeaconLen,
70183 + IN ULONG UpdatePos);
70184 +
70185 +INT rt28xx_ioctl(
70186 + IN struct net_device *net_dev,
70187 + IN OUT struct ifreq *rq,
70188 + IN INT cmd);
70189 +
70190 +
70191 +#ifdef CONFIG_STA_SUPPORT
70192 +INT rt28xx_sta_ioctl(
70193 + IN struct net_device *net_dev,
70194 + IN OUT struct ifreq *rq,
70195 + IN INT cmd);
70196 +#endif // CONFIG_STA_SUPPORT //
70197 +
70198 +BOOLEAN RT28XXSecurityKeyAdd(
70199 + IN PRTMP_ADAPTER pAd,
70200 + IN ULONG apidx,
70201 + IN ULONG KeyIdx,
70202 + IN MAC_TABLE_ENTRY *pEntry);
70203 +
70204 +////////////////////////////////////////
70205 +PNDIS_PACKET GetPacketFromRxRing(
70206 + IN PRTMP_ADAPTER pAd,
70207 + OUT PRT28XX_RXD_STRUC pSaveRxD,
70208 + OUT BOOLEAN *pbReschedule,
70209 + IN OUT UINT32 *pRxPending);
70210 +
70211 +
70212 +void kill_thread_task(PRTMP_ADAPTER pAd);
70213 +
70214 +void tbtt_tasklet(unsigned long data);
70215 +
70216 +
70217 +VOID AsicTurnOffRFClk(
70218 + IN PRTMP_ADAPTER pAd,
70219 + IN UCHAR Channel);
70220 +
70221 +VOID AsicTurnOnRFClk(
70222 + IN PRTMP_ADAPTER pAd,
70223 + IN UCHAR Channel);
70224 +
70225 +#ifdef RT2870
70226 +//
70227 +// Function Prototype in rtusb_bulk.c
70228 +//
70229 +VOID RTUSBInitTxDesc(
70230 + IN PRTMP_ADAPTER pAd,
70231 + IN PTX_CONTEXT pTxContext,
70232 + IN UCHAR BulkOutPipeId,
70233 + IN usb_complete_t Func);
70234 +
70235 +VOID RTUSBInitHTTxDesc(
70236 + IN PRTMP_ADAPTER pAd,
70237 + IN PHT_TX_CONTEXT pTxContext,
70238 + IN UCHAR BulkOutPipeId,
70239 + IN ULONG BulkOutSize,
70240 + IN usb_complete_t Func);
70241 +
70242 +VOID RTUSBInitRxDesc(
70243 + IN PRTMP_ADAPTER pAd,
70244 + IN PRX_CONTEXT pRxContext);
70245 +
70246 +VOID RTUSBCleanUpDataBulkOutQueue(
70247 + IN PRTMP_ADAPTER pAd);
70248 +
70249 +VOID RTUSBCancelPendingBulkOutIRP(
70250 + IN PRTMP_ADAPTER pAd);
70251 +
70252 +VOID RTUSBBulkOutDataPacket(
70253 + IN PRTMP_ADAPTER pAd,
70254 + IN UCHAR BulkOutPipeId,
70255 + IN UCHAR Index);
70256 +
70257 +VOID RTUSBBulkOutNullFrame(
70258 + IN PRTMP_ADAPTER pAd);
70259 +
70260 +VOID RTUSBBulkOutRTSFrame(
70261 + IN PRTMP_ADAPTER pAd);
70262 +
70263 +VOID RTUSBCancelPendingBulkInIRP(
70264 + IN PRTMP_ADAPTER pAd);
70265 +
70266 +VOID RTUSBCancelPendingIRPs(
70267 + IN PRTMP_ADAPTER pAd);
70268 +
70269 +VOID RTUSBBulkOutMLMEPacket(
70270 + IN PRTMP_ADAPTER pAd,
70271 + IN UCHAR Index);
70272 +
70273 +VOID RTUSBBulkOutPsPoll(
70274 + IN PRTMP_ADAPTER pAd);
70275 +
70276 +VOID RTUSBCleanUpMLMEBulkOutQueue(
70277 + IN PRTMP_ADAPTER pAd);
70278 +
70279 +VOID RTUSBKickBulkOut(
70280 + IN PRTMP_ADAPTER pAd);
70281 +
70282 +VOID RTUSBBulkReceive(
70283 + IN PRTMP_ADAPTER pAd);
70284 +
70285 +VOID DoBulkIn(
70286 + IN RTMP_ADAPTER *pAd);
70287 +
70288 +VOID RTUSBInitRxDesc(
70289 + IN PRTMP_ADAPTER pAd,
70290 + IN PRX_CONTEXT pRxContext);
70291 +
70292 +VOID RTUSBBulkRxHandle(
70293 + IN unsigned long data);
70294 +
70295 +//
70296 +// Function Prototype in rtusb_io.c
70297 +//
70298 +NTSTATUS RTUSBMultiRead(
70299 + IN PRTMP_ADAPTER pAd,
70300 + IN USHORT Offset,
70301 + OUT PUCHAR pData,
70302 + IN USHORT length);
70303 +
70304 +NTSTATUS RTUSBMultiWrite(
70305 + IN PRTMP_ADAPTER pAd,
70306 + IN USHORT Offset,
70307 + IN PUCHAR pData,
70308 + IN USHORT length);
70309 +
70310 +NTSTATUS RTUSBMultiWrite_OneByte(
70311 + IN PRTMP_ADAPTER pAd,
70312 + IN USHORT Offset,
70313 + IN PUCHAR pData);
70314 +
70315 +NTSTATUS RTUSBReadBBPRegister(
70316 + IN PRTMP_ADAPTER pAd,
70317 + IN UCHAR Id,
70318 + IN PUCHAR pValue);
70319 +
70320 +NTSTATUS RTUSBWriteBBPRegister(
70321 + IN PRTMP_ADAPTER pAd,
70322 + IN UCHAR Id,
70323 + IN UCHAR Value);
70324 +
70325 +NTSTATUS RTUSBWriteRFRegister(
70326 + IN PRTMP_ADAPTER pAd,
70327 + IN UINT32 Value);
70328 +
70329 +NTSTATUS RT30xxWriteRFRegister(
70330 + IN PRTMP_ADAPTER pAd,
70331 + IN UCHAR RegID,
70332 + IN UCHAR Value);
70333 +
70334 +NTSTATUS RT30xxReadRFRegister(
70335 + IN PRTMP_ADAPTER pAd,
70336 + IN UCHAR RegID,
70337 + IN PUCHAR pValue);
70338 +
70339 +NTSTATUS RTUSB_VendorRequest(
70340 + IN PRTMP_ADAPTER pAd,
70341 + IN UINT32 TransferFlags,
70342 + IN UCHAR ReservedBits,
70343 + IN UCHAR Request,
70344 + IN USHORT Value,
70345 + IN USHORT Index,
70346 + IN PVOID TransferBuffer,
70347 + IN UINT32 TransferBufferLength);
70348 +
70349 +NTSTATUS RTUSBReadEEPROM(
70350 + IN PRTMP_ADAPTER pAd,
70351 + IN USHORT Offset,
70352 + OUT PUCHAR pData,
70353 + IN USHORT length);
70354 +
70355 +NTSTATUS RTUSBWriteEEPROM(
70356 + IN PRTMP_ADAPTER pAd,
70357 + IN USHORT Offset,
70358 + IN PUCHAR pData,
70359 + IN USHORT length);
70360 +
70361 +VOID RTUSBPutToSleep(
70362 + IN PRTMP_ADAPTER pAd);
70363 +
70364 +NTSTATUS RTUSBWakeUp(
70365 + IN PRTMP_ADAPTER pAd);
70366 +
70367 +VOID RTUSBInitializeCmdQ(
70368 + IN PCmdQ cmdq);
70369 +
70370 +NDIS_STATUS RTUSBEnqueueCmdFromNdis(
70371 + IN PRTMP_ADAPTER pAd,
70372 + IN NDIS_OID Oid,
70373 + IN BOOLEAN SetInformation,
70374 + IN PVOID pInformationBuffer,
70375 + IN UINT32 InformationBufferLength);
70376 +
70377 +NDIS_STATUS RTUSBEnqueueInternalCmd(
70378 + IN PRTMP_ADAPTER pAd,
70379 + IN NDIS_OID Oid,
70380 + IN PVOID pInformationBuffer,
70381 + IN UINT32 InformationBufferLength);
70382 +
70383 +VOID RTUSBDequeueCmd(
70384 + IN PCmdQ cmdq,
70385 + OUT PCmdQElmt *pcmdqelmt);
70386 +
70387 +INT RTUSBCmdThread(
70388 + IN OUT PVOID Context);
70389 +
70390 +INT TimerQThread(
70391 + IN OUT PVOID Context);
70392 +
70393 +RT2870_TIMER_ENTRY *RT2870_TimerQ_Insert(
70394 + IN RTMP_ADAPTER *pAd,
70395 + IN RALINK_TIMER_STRUCT *pTimer);
70396 +
70397 +BOOLEAN RT2870_TimerQ_Remove(
70398 + IN RTMP_ADAPTER *pAd,
70399 + IN RALINK_TIMER_STRUCT *pTimer);
70400 +
70401 +void RT2870_TimerQ_Exit(
70402 + IN RTMP_ADAPTER *pAd);
70403 +
70404 +void RT2870_TimerQ_Init(
70405 + IN RTMP_ADAPTER *pAd);
70406 +
70407 +VOID RT2870_BssBeaconExit(
70408 + IN RTMP_ADAPTER *pAd);
70409 +
70410 +VOID RT2870_BssBeaconStop(
70411 + IN RTMP_ADAPTER *pAd);
70412 +
70413 +VOID RT2870_BssBeaconStart(
70414 + IN RTMP_ADAPTER * pAd);
70415 +
70416 +VOID RT2870_BssBeaconInit(
70417 + IN RTMP_ADAPTER *pAd);
70418 +
70419 +VOID RT2870_WatchDog(
70420 + IN RTMP_ADAPTER *pAd);
70421 +
70422 +NTSTATUS RTUSBWriteMACRegister(
70423 + IN PRTMP_ADAPTER pAd,
70424 + IN USHORT Offset,
70425 + IN UINT32 Value);
70426 +
70427 +NTSTATUS RTUSBReadMACRegister(
70428 + IN PRTMP_ADAPTER pAd,
70429 + IN USHORT Offset,
70430 + OUT PUINT32 pValue);
70431 +
70432 +NTSTATUS RTUSBSingleWrite(
70433 + IN RTMP_ADAPTER *pAd,
70434 + IN USHORT Offset,
70435 + IN USHORT Value);
70436 +
70437 +NTSTATUS RTUSBFirmwareRun(
70438 + IN PRTMP_ADAPTER pAd);
70439 +
70440 +NTSTATUS RTUSBFirmwareWrite(
70441 + IN PRTMP_ADAPTER pAd,
70442 + IN PUCHAR pFwImage,
70443 + IN ULONG FwLen);
70444 +
70445 +NTSTATUS RTUSBFirmwareOpmode(
70446 + IN PRTMP_ADAPTER pAd,
70447 + OUT PUINT32 pValue);
70448 +
70449 +NTSTATUS RTUSBVenderReset(
70450 + IN PRTMP_ADAPTER pAd);
70451 +
70452 +NDIS_STATUS RTUSBSetHardWareRegister(
70453 + IN PRTMP_ADAPTER pAdapter,
70454 + IN PVOID pBuf);
70455 +
70456 +NDIS_STATUS RTUSBQueryHardWareRegister(
70457 + IN PRTMP_ADAPTER pAdapter,
70458 + IN PVOID pBuf);
70459 +
70460 +VOID CMDHandler(
70461 + IN PRTMP_ADAPTER pAd);
70462 +
70463 +
70464 +NDIS_STATUS CreateThreads(
70465 + IN struct net_device *net_dev );
70466 +
70467 +
70468 +VOID MacTableInitialize(
70469 + IN PRTMP_ADAPTER pAd);
70470 +
70471 +VOID MlmeSetPsm(
70472 + IN PRTMP_ADAPTER pAd,
70473 + IN USHORT psm);
70474 +
70475 +NDIS_STATUS RTMPWPAAddKeyProc(
70476 + IN PRTMP_ADAPTER pAd,
70477 + IN PVOID pBuf);
70478 +
70479 +VOID AsicRxAntEvalAction(
70480 + IN PRTMP_ADAPTER pAd);
70481 +
70482 +#if 0 // Mark because not used in RT28xx.
70483 +NTSTATUS RTUSBRxPacket(
70484 + IN PRTMP_ADAPTER pAd,
70485 + IN BOOLEAN bBulkReceive);
70486 +
70487 +VOID RTUSBDequeueMLMEPacket(
70488 + IN PRTMP_ADAPTER pAd);
70489 +
70490 +VOID RTUSBCleanUpMLMEWaitQueue(
70491 + IN PRTMP_ADAPTER pAd);
70492 +#endif
70493 +
70494 +void append_pkt(
70495 + IN PRTMP_ADAPTER pAd,
70496 + IN PUCHAR pHeader802_3,
70497 + IN UINT HdrLen,
70498 + IN PUCHAR pData,
70499 + IN ULONG DataSize,
70500 + OUT PNDIS_PACKET *ppPacket);
70501 +
70502 +UINT deaggregate_AMSDU_announce(
70503 + IN PRTMP_ADAPTER pAd,
70504 + PNDIS_PACKET pPacket,
70505 + IN PUCHAR pData,
70506 + IN ULONG DataSize);
70507 +
70508 +NDIS_STATUS RTMPCheckRxError(
70509 + IN PRTMP_ADAPTER pAd,
70510 + IN PHEADER_802_11 pHeader,
70511 + IN PRXWI_STRUC pRxWI,
70512 + IN PRT28XX_RXD_STRUC pRxINFO);
70513 +
70514 +
70515 +VOID RTUSBMlmeHardTransmit(
70516 + IN PRTMP_ADAPTER pAd,
70517 + IN PMGMT_STRUC pMgmt);
70518 +
70519 +INT MlmeThread(
70520 + IN PVOID Context);
70521 +
70522 +#if 0
70523 +VOID RTUSBResumeMsduTransmission(
70524 + IN PRTMP_ADAPTER pAd);
70525 +
70526 +VOID RTUSBSuspendMsduTransmission(
70527 + IN PRTMP_ADAPTER pAd);
70528 +#endif
70529 +
70530 +//
70531 +// Function Prototype in rtusb_data.c
70532 +//
70533 +NDIS_STATUS RTUSBFreeDescriptorRequest(
70534 + IN PRTMP_ADAPTER pAd,
70535 + IN UCHAR BulkOutPipeId,
70536 + IN UINT32 NumberRequired);
70537 +
70538 +
70539 +BOOLEAN RTUSBNeedQueueBackForAgg(
70540 + IN RTMP_ADAPTER *pAd,
70541 + IN UCHAR BulkOutPipeId);
70542 +
70543 +
70544 +VOID RTMPWriteTxInfo(
70545 + IN PRTMP_ADAPTER pAd,
70546 + IN PTXINFO_STRUC pTxInfo,
70547 + IN USHORT USBDMApktLen,
70548 + IN BOOLEAN bWiv,
70549 + IN UCHAR QueueSel,
70550 + IN UCHAR NextValid,
70551 + IN UCHAR TxBurst);
70552 +
70553 +//
70554 +// Function Prototype in cmm_data_2870.c
70555 +//
70556 +USHORT RtmpUSB_WriteSubTxResource(
70557 + IN PRTMP_ADAPTER pAd,
70558 + IN TX_BLK *pTxBlk,
70559 + IN BOOLEAN bIsLast,
70560 + OUT USHORT *FreeNumber);
70561 +
70562 +USHORT RtmpUSB_WriteSingleTxResource(
70563 + IN PRTMP_ADAPTER pAd,
70564 + IN TX_BLK *pTxBlk,
70565 + IN BOOLEAN bIsLast,
70566 + OUT USHORT *FreeNumber);
70567 +
70568 +USHORT RtmpUSB_WriteFragTxResource(
70569 + IN PRTMP_ADAPTER pAd,
70570 + IN TX_BLK *pTxBlk,
70571 + IN UCHAR fragNum,
70572 + OUT USHORT *FreeNumber);
70573 +
70574 +USHORT RtmpUSB_WriteMultiTxResource(
70575 + IN PRTMP_ADAPTER pAd,
70576 + IN TX_BLK *pTxBlk,
70577 + IN UCHAR frameNum,
70578 + OUT USHORT *FreeNumber);
70579 +
70580 +VOID RtmpUSB_FinalWriteTxResource(
70581 + IN PRTMP_ADAPTER pAd,
70582 + IN TX_BLK *pTxBlk,
70583 + IN USHORT totalMPDUSize,
70584 + IN USHORT TxIdx);
70585 +
70586 +VOID RtmpUSBDataLastTxIdx(
70587 + IN PRTMP_ADAPTER pAd,
70588 + IN UCHAR QueIdx,
70589 + IN USHORT TxIdx);
70590 +
70591 +VOID RtmpUSBDataKickOut(
70592 + IN PRTMP_ADAPTER pAd,
70593 + IN TX_BLK *pTxBlk,
70594 + IN UCHAR QueIdx);
70595 +
70596 +
70597 +int RtmpUSBMgmtKickOut(
70598 + IN RTMP_ADAPTER *pAd,
70599 + IN UCHAR QueIdx,
70600 + IN PNDIS_PACKET pPacket,
70601 + IN PUCHAR pSrcBufVA,
70602 + IN UINT SrcBufLen);
70603 +
70604 +VOID RtmpUSBNullFrameKickOut(
70605 + IN RTMP_ADAPTER *pAd,
70606 + IN UCHAR QueIdx,
70607 + IN UCHAR *pNullFrame,
70608 + IN UINT32 frameLen);
70609 +
70610 +VOID RT28xxUsbStaAsicForceWakeup(
70611 + IN PRTMP_ADAPTER pAd,
70612 + IN BOOLEAN bFromTx);
70613 +
70614 +VOID RT28xxUsbStaAsicSleepThenAutoWakeup(
70615 + IN PRTMP_ADAPTER pAd,
70616 + IN USHORT TbttNumToNextWakeUp);
70617 +
70618 +VOID RT28xxUsbMlmeRadioOn(
70619 + IN PRTMP_ADAPTER pAd);
70620 +
70621 +VOID RT28xxUsbMlmeRadioOFF(
70622 + IN PRTMP_ADAPTER pAd);
70623 +#endif // RT2870 //
70624 +
70625 +////////////////////////////////////////
70626 +
70627 +VOID QBSS_LoadInit(
70628 + IN RTMP_ADAPTER *pAd);
70629 +
70630 +UINT32 QBSS_LoadElementAppend(
70631 + IN RTMP_ADAPTER *pAd,
70632 + OUT UINT8 *buf_p);
70633 +
70634 +VOID QBSS_LoadUpdate(
70635 + IN RTMP_ADAPTER *pAd);
70636 +
70637 +///////////////////////////////////////
70638 +INT RTMPShowCfgValue(
70639 + IN PRTMP_ADAPTER pAd,
70640 + IN PUCHAR pName,
70641 + IN PUCHAR pBuf);
70642 +
70643 +PCHAR RTMPGetRalinkAuthModeStr(
70644 + IN NDIS_802_11_AUTHENTICATION_MODE authMode);
70645 +
70646 +PCHAR RTMPGetRalinkEncryModeStr(
70647 + IN USHORT encryMode);
70648 +//////////////////////////////////////
70649 +
70650 +#ifdef CONFIG_STA_SUPPORT
70651 +VOID AsicStaBbpTuning(
70652 + IN PRTMP_ADAPTER pAd);
70653 +
70654 +BOOLEAN StaAddMacTableEntry(
70655 + IN PRTMP_ADAPTER pAd,
70656 + IN PMAC_TABLE_ENTRY pEntry,
70657 + IN UCHAR MaxSupportedRateIn500Kbps,
70658 + IN HT_CAPABILITY_IE *pHtCapability,
70659 + IN UCHAR HtCapabilityLen,
70660 + IN USHORT CapabilityInfo);
70661 +#endif // CONFIG_STA_SUPPORT //
70662 +
70663 +void RTMP_IndicateMediaState(
70664 + IN PRTMP_ADAPTER pAd);
70665 +
70666 +VOID ReSyncBeaconTime(
70667 + IN PRTMP_ADAPTER pAd);
70668 +
70669 +VOID RTMPSetAGCInitValue(
70670 + IN PRTMP_ADAPTER pAd,
70671 + IN UCHAR BandWidth);
70672 +
70673 +int rt28xx_close(IN PNET_DEV dev);
70674 +int rt28xx_open(IN PNET_DEV dev);
70675 +
70676 +__inline INT VIRTUAL_IF_UP(PRTMP_ADAPTER pAd)
70677 +{
70678 +extern VOID MeshMakeBeacon(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
70679 +extern VOID MeshUpdateBeaconFrame(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
70680 +
70681 + if (VIRTUAL_IF_NUM(pAd) == 0)
70682 + {
70683 + if (rt28xx_open(pAd->net_dev) != 0)
70684 + return -1;
70685 + }
70686 + else
70687 + {
70688 + }
70689 + VIRTUAL_IF_INC(pAd);
70690 + return 0;
70691 +}
70692 +
70693 +__inline VOID VIRTUAL_IF_DOWN(PRTMP_ADAPTER pAd)
70694 +{
70695 + VIRTUAL_IF_DEC(pAd);
70696 + if (VIRTUAL_IF_NUM(pAd) == 0)
70697 + rt28xx_close(pAd->net_dev);
70698 + return;
70699 +}
70700 +
70701 +
70702 +#endif // __RTMP_H__
70703 +
70704 --- /dev/null
70705 +++ b/drivers/staging/rt2870/rtmp_type.h
70706 @@ -0,0 +1,94 @@
70707 +/*
70708 + *************************************************************************
70709 + * Ralink Tech Inc.
70710 + * 5F., No.36, Taiyuan St., Jhubei City,
70711 + * Hsinchu County 302,
70712 + * Taiwan, R.O.C.
70713 + *
70714 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
70715 + *
70716 + * This program is free software; you can redistribute it and/or modify *
70717 + * it under the terms of the GNU General Public License as published by *
70718 + * the Free Software Foundation; either version 2 of the License, or *
70719 + * (at your option) any later version. *
70720 + * *
70721 + * This program is distributed in the hope that it will be useful, *
70722 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
70723 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
70724 + * GNU General Public License for more details. *
70725 + * *
70726 + * You should have received a copy of the GNU General Public License *
70727 + * along with this program; if not, write to the *
70728 + * Free Software Foundation, Inc., *
70729 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
70730 + * *
70731 + *************************************************************************
70732 +
70733 + Module Name:
70734 + rtmp_type.h
70735 +
70736 + Abstract:
70737 +
70738 + Revision History:
70739 + Who When What
70740 + -------- ---------- ----------------------------------------------
70741 + Name Date Modification logs
70742 + Paul Lin 1-2-2004
70743 +*/
70744 +#ifndef __RTMP_TYPE_H__
70745 +#define __RTMP_TYPE_H__
70746 +
70747 +#define PACKED __attribute__ ((packed))
70748 +
70749 +// Put platform dependent declaration here
70750 +// For example, linux type definition
70751 +typedef unsigned char UINT8;
70752 +typedef unsigned short UINT16;
70753 +typedef unsigned int UINT32;
70754 +typedef unsigned long long UINT64;
70755 +typedef int INT32;
70756 +typedef long long INT64;
70757 +
70758 +typedef unsigned char * PUINT8;
70759 +typedef unsigned short * PUINT16;
70760 +typedef unsigned int * PUINT32;
70761 +typedef unsigned long long * PUINT64;
70762 +typedef int * PINT32;
70763 +typedef long long * PINT64;
70764 +
70765 +typedef signed char CHAR;
70766 +typedef signed short SHORT;
70767 +typedef signed int INT;
70768 +typedef signed long LONG;
70769 +typedef signed long long LONGLONG;
70770 +
70771 +
70772 +typedef unsigned char UCHAR;
70773 +typedef unsigned short USHORT;
70774 +typedef unsigned int UINT;
70775 +typedef unsigned long ULONG;
70776 +typedef unsigned long long ULONGLONG;
70777 +
70778 +typedef unsigned char BOOLEAN;
70779 +typedef void VOID;
70780 +
70781 +typedef VOID * PVOID;
70782 +typedef CHAR * PCHAR;
70783 +typedef UCHAR * PUCHAR;
70784 +typedef USHORT * PUSHORT;
70785 +typedef LONG * PLONG;
70786 +typedef ULONG * PULONG;
70787 +typedef UINT * PUINT;
70788 +
70789 +typedef unsigned int NDIS_MEDIA_STATE;
70790 +
70791 +typedef union _LARGE_INTEGER {
70792 + struct {
70793 + UINT LowPart;
70794 + INT32 HighPart;
70795 + } u;
70796 + INT64 QuadPart;
70797 +} LARGE_INTEGER;
70798 +
70799 +#endif // __RTMP_TYPE_H__
70800 +
70801 --- /dev/null
70802 +++ b/drivers/staging/rt2870/rt_profile.c
70803 @@ -0,0 +1,2016 @@
70804 +/*
70805 + *************************************************************************
70806 + * Ralink Tech Inc.
70807 + * 5F., No.36, Taiyuan St., Jhubei City,
70808 + * Hsinchu County 302,
70809 + * Taiwan, R.O.C.
70810 + *
70811 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
70812 + *
70813 + * This program is free software; you can redistribute it and/or modify *
70814 + * it under the terms of the GNU General Public License as published by *
70815 + * the Free Software Foundation; either version 2 of the License, or *
70816 + * (at your option) any later version. *
70817 + * *
70818 + * This program is distributed in the hope that it will be useful, *
70819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
70820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
70821 + * GNU General Public License for more details. *
70822 + * *
70823 + * You should have received a copy of the GNU General Public License *
70824 + * along with this program; if not, write to the *
70825 + * Free Software Foundation, Inc., *
70826 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
70827 + * *
70828 + *************************************************************************
70829 + */
70830 +
70831 +#include "rt_config.h"
70832 +
70833 +#ifdef DOT11_N_SUPPORT
70834 +static void HTParametersHook(
70835 + IN PRTMP_ADAPTER pAd,
70836 + IN CHAR *pValueStr,
70837 + IN CHAR *pInput);
70838 +#endif // DOT11_N_SUPPORT //
70839 +
70840 +#define ETH_MAC_ADDR_STR_LEN 17 // in format of xx:xx:xx:xx:xx:xx
70841 +
70842 +// We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
70843 +BOOLEAN rtstrmactohex(char *s1, char *s2)
70844 +{
70845 + int i = 0;
70846 + char *ptokS = s1, *ptokE = s1;
70847 +
70848 + if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
70849 + return FALSE;
70850 +
70851 + while((*ptokS) != '\0')
70852 + {
70853 + if((ptokE = strchr(ptokS, ':')) != NULL)
70854 + *ptokE++ = '\0';
70855 + if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
70856 + break; // fail
70857 + AtoH(ptokS, &s2[i++], 1);
70858 + ptokS = ptokE;
70859 + if (i == 6)
70860 + break; // parsing finished
70861 + }
70862 +
70863 + return ( i == 6 ? TRUE : FALSE);
70864 +
70865 +}
70866 +
70867 +
70868 +// we assume the s1 and s2 both are strings.
70869 +BOOLEAN rtstrcasecmp(char *s1, char *s2)
70870 +{
70871 + char *p1 = s1, *p2 = s2;
70872 +
70873 + if (strlen(s1) != strlen(s2))
70874 + return FALSE;
70875 +
70876 + while(*p1 != '\0')
70877 + {
70878 + if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
70879 + return FALSE;
70880 + p1++;
70881 + p2++;
70882 + }
70883 +
70884 + return TRUE;
70885 +}
70886 +
70887 +// we assume the s1 (buffer) and s2 (key) both are strings.
70888 +char * rtstrstruncasecmp(char * s1, char * s2)
70889 +{
70890 + INT l1, l2, i;
70891 + char temp1, temp2;
70892 +
70893 + l2 = strlen(s2);
70894 + if (!l2)
70895 + return (char *) s1;
70896 +
70897 + l1 = strlen(s1);
70898 +
70899 + while (l1 >= l2)
70900 + {
70901 + l1--;
70902 +
70903 + for(i=0; i<l2; i++)
70904 + {
70905 + temp1 = *(s1+i);
70906 + temp2 = *(s2+i);
70907 +
70908 + if (('a' <= temp1) && (temp1 <= 'z'))
70909 + temp1 = 'A'+(temp1-'a');
70910 + if (('a' <= temp2) && (temp2 <= 'z'))
70911 + temp2 = 'A'+(temp2-'a');
70912 +
70913 + if (temp1 != temp2)
70914 + break;
70915 + }
70916 +
70917 + if (i == l2)
70918 + return (char *) s1;
70919 +
70920 + s1++;
70921 + }
70922 +
70923 + return NULL; // not found
70924 +}
70925 +
70926 +//add by kathy
70927 +
70928 + /**
70929 + * strstr - Find the first substring in a %NUL terminated string
70930 + * @s1: The string to be searched
70931 + * @s2: The string to search for
70932 + */
70933 +char * rtstrstr(const char * s1,const char * s2)
70934 +{
70935 + INT l1, l2;
70936 +
70937 + l2 = strlen(s2);
70938 + if (!l2)
70939 + return (char *) s1;
70940 +
70941 + l1 = strlen(s1);
70942 +
70943 + while (l1 >= l2)
70944 + {
70945 + l1--;
70946 + if (!memcmp(s1,s2,l2))
70947 + return (char *) s1;
70948 + s1++;
70949 + }
70950 +
70951 + return NULL;
70952 +}
70953 +
70954 +/**
70955 + * rstrtok - Split a string into tokens
70956 + * @s: The string to be searched
70957 + * @ct: The characters to search for
70958 + * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
70959 + */
70960 +char * __rstrtok;
70961 +char * rstrtok(char * s,const char * ct)
70962 +{
70963 + char *sbegin, *send;
70964 +
70965 + sbegin = s ? s : __rstrtok;
70966 + if (!sbegin)
70967 + {
70968 + return NULL;
70969 + }
70970 +
70971 + sbegin += strspn(sbegin,ct);
70972 + if (*sbegin == '\0')
70973 + {
70974 + __rstrtok = NULL;
70975 + return( NULL );
70976 + }
70977 +
70978 + send = strpbrk( sbegin, ct);
70979 + if (send && *send != '\0')
70980 + *send++ = '\0';
70981 +
70982 + __rstrtok = send;
70983 +
70984 + return (sbegin);
70985 +}
70986 +
70987 +/**
70988 + * delimitcnt - return the count of a given delimiter in a given string.
70989 + * @s: The string to be searched.
70990 + * @ct: The delimiter to search for.
70991 + * Notice : We suppose the delimiter is a single-char string(for example : ";").
70992 + */
70993 +INT delimitcnt(char * s,const char * ct)
70994 +{
70995 + INT count = 0;
70996 + /* point to the beginning of the line */
70997 + const char *token = s;
70998 +
70999 + for ( ;; )
71000 + {
71001 + token = strpbrk(token, ct); /* search for delimiters */
71002 +
71003 + if ( token == NULL )
71004 + {
71005 + /* advanced to the terminating null character */
71006 + break;
71007 + }
71008 + /* skip the delimiter */
71009 + ++token;
71010 +
71011 + /*
71012 + * Print the found text: use len with %.*s to specify field width.
71013 + */
71014 +
71015 + /* accumulate delimiter count */
71016 + ++count;
71017 + }
71018 + return count;
71019 +}
71020 +
71021 +/*
71022 + * converts the Internet host address from the standard numbers-and-dots notation
71023 + * into binary data.
71024 + * returns nonzero if the address is valid, zero if not.
71025 + */
71026 +int rtinet_aton(const char *cp, unsigned int *addr)
71027 +{
71028 + unsigned int val;
71029 + int base, n;
71030 + char c;
71031 + unsigned int parts[4];
71032 + unsigned int *pp = parts;
71033 +
71034 + for (;;)
71035 + {
71036 + /*
71037 + * Collect number up to ``.''.
71038 + * Values are specified as for C:
71039 + * 0x=hex, 0=octal, other=decimal.
71040 + */
71041 + val = 0;
71042 + base = 10;
71043 + if (*cp == '0')
71044 + {
71045 + if (*++cp == 'x' || *cp == 'X')
71046 + base = 16, cp++;
71047 + else
71048 + base = 8;
71049 + }
71050 + while ((c = *cp) != '\0')
71051 + {
71052 + if (isdigit((unsigned char) c))
71053 + {
71054 + val = (val * base) + (c - '0');
71055 + cp++;
71056 + continue;
71057 + }
71058 + if (base == 16 && isxdigit((unsigned char) c))
71059 + {
71060 + val = (val << 4) +
71061 + (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
71062 + cp++;
71063 + continue;
71064 + }
71065 + break;
71066 + }
71067 + if (*cp == '.')
71068 + {
71069 + /*
71070 + * Internet format: a.b.c.d a.b.c (with c treated as 16-bits)
71071 + * a.b (with b treated as 24 bits)
71072 + */
71073 + if (pp >= parts + 3 || val > 0xff)
71074 + return 0;
71075 + *pp++ = val, cp++;
71076 + }
71077 + else
71078 + break;
71079 + }
71080 +
71081 + /*
71082 + * Check for trailing junk.
71083 + */
71084 + while (*cp)
71085 + if (!isspace((unsigned char) *cp++))
71086 + return 0;
71087 +
71088 + /*
71089 + * Concoct the address according to the number of parts specified.
71090 + */
71091 + n = pp - parts + 1;
71092 + switch (n)
71093 + {
71094 +
71095 + case 1: /* a -- 32 bits */
71096 + break;
71097 +
71098 + case 2: /* a.b -- 8.24 bits */
71099 + if (val > 0xffffff)
71100 + return 0;
71101 + val |= parts[0] << 24;
71102 + break;
71103 +
71104 + case 3: /* a.b.c -- 8.8.16 bits */
71105 + if (val > 0xffff)
71106 + return 0;
71107 + val |= (parts[0] << 24) | (parts[1] << 16);
71108 + break;
71109 +
71110 + case 4: /* a.b.c.d -- 8.8.8.8 bits */
71111 + if (val > 0xff)
71112 + return 0;
71113 + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
71114 + break;
71115 + }
71116 +
71117 + *addr = htonl(val);
71118 + return 1;
71119 +
71120 +}
71121 +
71122 +/*
71123 + ========================================================================
71124 +
71125 + Routine Description:
71126 + Find key section for Get key parameter.
71127 +
71128 + Arguments:
71129 + buffer Pointer to the buffer to start find the key section
71130 + section the key of the secion to be find
71131 +
71132 + Return Value:
71133 + NULL Fail
71134 + Others Success
71135 + ========================================================================
71136 +*/
71137 +PUCHAR RTMPFindSection(
71138 + IN PCHAR buffer)
71139 +{
71140 + CHAR temp_buf[32];
71141 + PUCHAR ptr;
71142 +
71143 + strcpy(temp_buf, "Default");
71144 +
71145 + if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
71146 + return (ptr+strlen("\n"));
71147 + else
71148 + return NULL;
71149 +}
71150 +
71151 +/*
71152 + ========================================================================
71153 +
71154 + Routine Description:
71155 + Get key parameter.
71156 +
71157 + Arguments:
71158 + key Pointer to key string
71159 + dest Pointer to destination
71160 + destsize The datasize of the destination
71161 + buffer Pointer to the buffer to start find the key
71162 +
71163 + Return Value:
71164 + TRUE Success
71165 + FALSE Fail
71166 +
71167 + Note:
71168 + This routine get the value with the matched key (case case-sensitive)
71169 + ========================================================================
71170 +*/
71171 +INT RTMPGetKeyParameter(
71172 + IN PCHAR key,
71173 + OUT PCHAR dest,
71174 + IN INT destsize,
71175 + IN PCHAR buffer)
71176 +{
71177 + UCHAR *temp_buf1 = NULL;
71178 + UCHAR *temp_buf2 = NULL;
71179 + CHAR *start_ptr;
71180 + CHAR *end_ptr;
71181 + CHAR *ptr;
71182 + CHAR *offset = 0;
71183 + INT len;
71184 +
71185 + //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
71186 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
71187 +
71188 + if(temp_buf1 == NULL)
71189 + return (FALSE);
71190 +
71191 + //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
71192 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
71193 + if(temp_buf2 == NULL)
71194 + {
71195 + os_free_mem(NULL, temp_buf1);
71196 + return (FALSE);
71197 + }
71198 +
71199 + //find section
71200 + if((offset = RTMPFindSection(buffer)) == NULL)
71201 + {
71202 + os_free_mem(NULL, temp_buf1);
71203 + os_free_mem(NULL, temp_buf2);
71204 + return (FALSE);
71205 + }
71206 +
71207 + strcpy(temp_buf1, "\n");
71208 + strcat(temp_buf1, key);
71209 + strcat(temp_buf1, "=");
71210 +
71211 + //search key
71212 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
71213 + {
71214 + os_free_mem(NULL, temp_buf1);
71215 + os_free_mem(NULL, temp_buf2);
71216 + return (FALSE);
71217 + }
71218 +
71219 + start_ptr+=strlen("\n");
71220 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
71221 + end_ptr=start_ptr+strlen(start_ptr);
71222 +
71223 + if (end_ptr<start_ptr)
71224 + {
71225 + os_free_mem(NULL, temp_buf1);
71226 + os_free_mem(NULL, temp_buf2);
71227 + return (FALSE);
71228 + }
71229 +
71230 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
71231 + temp_buf2[end_ptr-start_ptr]='\0';
71232 + len = strlen(temp_buf2);
71233 + strcpy(temp_buf1, temp_buf2);
71234 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
71235 + {
71236 + os_free_mem(NULL, temp_buf1);
71237 + os_free_mem(NULL, temp_buf2);
71238 + return (FALSE);
71239 + }
71240 +
71241 + strcpy(temp_buf2, start_ptr+1);
71242 + ptr = temp_buf2;
71243 + //trim space or tab
71244 + while(*ptr != 0x00)
71245 + {
71246 + if( (*ptr == ' ') || (*ptr == '\t') )
71247 + ptr++;
71248 + else
71249 + break;
71250 + }
71251 +
71252 + len = strlen(ptr);
71253 + memset(dest, 0x00, destsize);
71254 + strncpy(dest, ptr, len >= destsize ? destsize: len);
71255 +
71256 + os_free_mem(NULL, temp_buf1);
71257 + os_free_mem(NULL, temp_buf2);
71258 + return TRUE;
71259 +}
71260 +
71261 +/*
71262 + ========================================================================
71263 +
71264 + Routine Description:
71265 + Get key parameter.
71266 +
71267 + Arguments:
71268 + key Pointer to key string
71269 + dest Pointer to destination
71270 + destsize The datasize of the destination
71271 + buffer Pointer to the buffer to start find the key
71272 +
71273 + Return Value:
71274 + TRUE Success
71275 + FALSE Fail
71276 +
71277 + Note:
71278 + This routine get the value with the matched key (case case-sensitive).
71279 + It is called for parsing SSID and any key string.
71280 + ========================================================================
71281 +*/
71282 +INT RTMPGetCriticalParameter(
71283 + IN PCHAR key,
71284 + OUT PCHAR dest,
71285 + IN INT destsize,
71286 + IN PCHAR buffer)
71287 +{
71288 + UCHAR *temp_buf1 = NULL;
71289 + UCHAR *temp_buf2 = NULL;
71290 + CHAR *start_ptr;
71291 + CHAR *end_ptr;
71292 + CHAR *ptr;
71293 + CHAR *offset = 0;
71294 + INT len;
71295 +
71296 + //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
71297 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
71298 +
71299 + if(temp_buf1 == NULL)
71300 + return (FALSE);
71301 +
71302 + //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
71303 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
71304 + if(temp_buf2 == NULL)
71305 + {
71306 + os_free_mem(NULL, temp_buf1);
71307 + return (FALSE);
71308 + }
71309 +
71310 + //find section
71311 + if((offset = RTMPFindSection(buffer)) == NULL)
71312 + {
71313 + os_free_mem(NULL, temp_buf1);
71314 + os_free_mem(NULL, temp_buf2);
71315 + return (FALSE);
71316 + }
71317 +
71318 + strcpy(temp_buf1, "\n");
71319 + strcat(temp_buf1, key);
71320 + strcat(temp_buf1, "=");
71321 +
71322 + //search key
71323 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
71324 + {
71325 + os_free_mem(NULL, temp_buf1);
71326 + os_free_mem(NULL, temp_buf2);
71327 + return (FALSE);
71328 + }
71329 +
71330 + start_ptr+=strlen("\n");
71331 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
71332 + end_ptr=start_ptr+strlen(start_ptr);
71333 +
71334 + if (end_ptr<start_ptr)
71335 + {
71336 + os_free_mem(NULL, temp_buf1);
71337 + os_free_mem(NULL, temp_buf2);
71338 + return (FALSE);
71339 + }
71340 +
71341 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
71342 + temp_buf2[end_ptr-start_ptr]='\0';
71343 + len = strlen(temp_buf2);
71344 + strcpy(temp_buf1, temp_buf2);
71345 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
71346 + {
71347 + os_free_mem(NULL, temp_buf1);
71348 + os_free_mem(NULL, temp_buf2);
71349 + return (FALSE);
71350 + }
71351 +
71352 + strcpy(temp_buf2, start_ptr+1);
71353 + ptr = temp_buf2;
71354 +
71355 + //trim tab
71356 + /* We cannot trim space(' ') for SSID and key string. */
71357 + while(*ptr != 0x00)
71358 + {
71359 + //if( (*ptr == ' ') || (*ptr == '\t') )
71360 + if( (*ptr == '\t') )
71361 + ptr++;
71362 + else
71363 + break;
71364 + }
71365 +
71366 + len = strlen(ptr);
71367 + memset(dest, 0x00, destsize);
71368 + strncpy(dest, ptr, len >= destsize ? destsize: len);
71369 +
71370 + os_free_mem(NULL, temp_buf1);
71371 + os_free_mem(NULL, temp_buf2);
71372 + return TRUE;
71373 +}
71374 +
71375 +/*
71376 + ========================================================================
71377 +
71378 + Routine Description:
71379 + Get multiple key parameter.
71380 +
71381 + Arguments:
71382 + key Pointer to key string
71383 + dest Pointer to destination
71384 + destsize The datasize of the destination
71385 + buffer Pointer to the buffer to start find the key
71386 +
71387 + Return Value:
71388 + TRUE Success
71389 + FALSE Fail
71390 +
71391 + Note:
71392 + This routine get the value with the matched key (case case-sensitive)
71393 + ========================================================================
71394 +*/
71395 +INT RTMPGetKeyParameterWithOffset(
71396 + IN PCHAR key,
71397 + OUT PCHAR dest,
71398 + OUT USHORT *end_offset,
71399 + IN INT destsize,
71400 + IN PCHAR buffer,
71401 + IN BOOLEAN bTrimSpace)
71402 +{
71403 + UCHAR *temp_buf1 = NULL;
71404 + UCHAR *temp_buf2 = NULL;
71405 + CHAR *start_ptr;
71406 + CHAR *end_ptr;
71407 + CHAR *ptr;
71408 + CHAR *offset = 0;
71409 + INT len;
71410 +
71411 + if (*end_offset >= MAX_INI_BUFFER_SIZE)
71412 + return (FALSE);
71413 +
71414 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
71415 +
71416 + if(temp_buf1 == NULL)
71417 + return (FALSE);
71418 +
71419 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
71420 + if(temp_buf2 == NULL)
71421 + {
71422 + os_free_mem(NULL, temp_buf1);
71423 + return (FALSE);
71424 + }
71425 +
71426 + //find section
71427 + if(*end_offset == 0)
71428 + {
71429 + if ((offset = RTMPFindSection(buffer)) == NULL)
71430 + {
71431 + os_free_mem(NULL, temp_buf1);
71432 + os_free_mem(NULL, temp_buf2);
71433 + return (FALSE);
71434 + }
71435 + }
71436 + else
71437 + offset = buffer + (*end_offset);
71438 +
71439 + strcpy(temp_buf1, "\n");
71440 + strcat(temp_buf1, key);
71441 + strcat(temp_buf1, "=");
71442 +
71443 + //search key
71444 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
71445 + {
71446 + os_free_mem(NULL, temp_buf1);
71447 + os_free_mem(NULL, temp_buf2);
71448 + return (FALSE);
71449 + }
71450 +
71451 + start_ptr+=strlen("\n");
71452 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
71453 + end_ptr=start_ptr+strlen(start_ptr);
71454 +
71455 + if (end_ptr<start_ptr)
71456 + {
71457 + os_free_mem(NULL, temp_buf1);
71458 + os_free_mem(NULL, temp_buf2);
71459 + return (FALSE);
71460 + }
71461 +
71462 + *end_offset = end_ptr - buffer;
71463 +
71464 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
71465 + temp_buf2[end_ptr-start_ptr]='\0';
71466 + len = strlen(temp_buf2);
71467 + strcpy(temp_buf1, temp_buf2);
71468 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
71469 + {
71470 + os_free_mem(NULL, temp_buf1);
71471 + os_free_mem(NULL, temp_buf2);
71472 + return (FALSE);
71473 + }
71474 +
71475 + strcpy(temp_buf2, start_ptr+1);
71476 + ptr = temp_buf2;
71477 + //trim space or tab
71478 + while(*ptr != 0x00)
71479 + {
71480 + if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
71481 + ptr++;
71482 + else
71483 + break;
71484 + }
71485 +
71486 + len = strlen(ptr);
71487 + memset(dest, 0x00, destsize);
71488 + strncpy(dest, ptr, len >= destsize ? destsize: len);
71489 +
71490 + os_free_mem(NULL, temp_buf1);
71491 + os_free_mem(NULL, temp_buf2);
71492 + return TRUE;
71493 +}
71494 +
71495 +
71496 +static int rtmp_parse_key_buffer_from_file(IN PRTMP_ADAPTER pAd,IN char *buffer,IN ULONG KeyType,IN INT BSSIdx,IN INT KeyIdx)
71497 +{
71498 + PUCHAR keybuff;
71499 + INT i = BSSIdx, idx = KeyIdx;
71500 + ULONG KeyLen;
71501 + UCHAR CipherAlg = CIPHER_WEP64;
71502 +
71503 + keybuff = buffer;
71504 + KeyLen = strlen(keybuff);
71505 +
71506 + if (KeyType == 1)
71507 + {//Ascii
71508 + if( (KeyLen == 5) || (KeyLen == 13))
71509 + {
71510 + pAd->SharedKey[i][idx].KeyLen = KeyLen;
71511 + NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen);
71512 + if (KeyLen == 5)
71513 + CipherAlg = CIPHER_WEP64;
71514 + else
71515 + CipherAlg = CIPHER_WEP128;
71516 + pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
71517 +
71518 + DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
71519 + return 1;
71520 + }
71521 + else
71522 + {//Invalid key length
71523 + DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen));
71524 + return 0;
71525 + }
71526 + }
71527 + else
71528 + {//Hex type
71529 + if( (KeyLen == 10) || (KeyLen == 26))
71530 + {
71531 + pAd->SharedKey[i][idx].KeyLen = KeyLen / 2;
71532 + AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2);
71533 + if (KeyLen == 10)
71534 + CipherAlg = CIPHER_WEP64;
71535 + else
71536 + CipherAlg = CIPHER_WEP128;
71537 + pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
71538 +
71539 + DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
71540 + return 1;
71541 + }
71542 + else
71543 + {//Invalid key length
71544 + DBGPRINT(RT_DEBUG_ERROR, ("I/F(ra%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen));
71545 + return 0;
71546 + }
71547 + }
71548 +}
71549 +static void rtmp_read_key_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
71550 +{
71551 + char tok_str[16];
71552 + PUCHAR macptr;
71553 + INT i = 0, idx;
71554 + ULONG KeyType[MAX_MBSSID_NUM];
71555 + ULONG KeyIdx;
71556 +
71557 + NdisZeroMemory(KeyType, MAX_MBSSID_NUM);
71558 +
71559 + //DefaultKeyID
71560 + if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer))
71561 + {
71562 +
71563 +#ifdef CONFIG_STA_SUPPORT
71564 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71565 + {
71566 + KeyIdx = simple_strtol(tmpbuf, 0, 10);
71567 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
71568 + pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
71569 + else
71570 + pAd->StaCfg.DefaultKeyId = 0;
71571 +
71572 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
71573 + }
71574 +#endif // CONFIG_STA_SUPPORT //
71575 + }
71576 +
71577 +
71578 + for (idx = 0; idx < 4; idx++)
71579 + {
71580 + sprintf(tok_str, "Key%dType", idx + 1);
71581 + //Key1Type
71582 + if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer))
71583 + {
71584 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
71585 + {
71586 + KeyType[i] = simple_strtol(macptr, 0, 10);
71587 + }
71588 +
71589 +#ifdef CONFIG_STA_SUPPORT
71590 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71591 + {
71592 + sprintf(tok_str, "Key%dStr", idx + 1);
71593 + if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))
71594 + {
71595 + rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
71596 + }
71597 + }
71598 +#endif // CONFIG_STA_SUPPORT //
71599 + }
71600 + }
71601 +}
71602 +
71603 +
71604 +#ifdef CONFIG_STA_SUPPORT
71605 +static void rtmp_read_sta_wmm_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
71606 +{
71607 + PUCHAR macptr;
71608 + INT i=0;
71609 + BOOLEAN bWmmEnable = FALSE;
71610 +
71611 + //WmmCapable
71612 + if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer))
71613 + {
71614 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
71615 + {
71616 + pAd->CommonCfg.bWmmCapable = TRUE;
71617 + bWmmEnable = TRUE;
71618 + }
71619 + else //Disable
71620 + {
71621 + pAd->CommonCfg.bWmmCapable = FALSE;
71622 + }
71623 +
71624 + DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
71625 + }
71626 +
71627 +#ifdef QOS_DLS_SUPPORT
71628 + //DLSCapable
71629 + if(RTMPGetKeyParameter("DLSCapable", tmpbuf, 32, buffer))
71630 + {
71631 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
71632 + {
71633 + pAd->CommonCfg.bDLSCapable = TRUE;
71634 + }
71635 + else //Disable
71636 + {
71637 + pAd->CommonCfg.bDLSCapable = FALSE;
71638 + }
71639 +
71640 + DBGPRINT(RT_DEBUG_TRACE, ("bDLSCapable=%d\n", pAd->CommonCfg.bDLSCapable));
71641 + }
71642 +#endif // QOS_DLS_SUPPORT //
71643 +
71644 + //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
71645 + if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer))
71646 + {
71647 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
71648 + {
71649 + pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
71650 +
71651 + DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
71652 + }
71653 + }
71654 +
71655 + if (bWmmEnable)
71656 + {
71657 + //APSDCapable
71658 + if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))
71659 + {
71660 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
71661 + pAd->CommonCfg.bAPSDCapable = TRUE;
71662 + else
71663 + pAd->CommonCfg.bAPSDCapable = FALSE;
71664 +
71665 + DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
71666 + }
71667 +
71668 + //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
71669 + if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))
71670 + {
71671 + BOOLEAN apsd_ac[4];
71672 +
71673 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
71674 + {
71675 + apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
71676 +
71677 + DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d %d\n", i, apsd_ac[i]));
71678 + }
71679 +
71680 + pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
71681 + pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
71682 + pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
71683 + pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
71684 + }
71685 + }
71686 +
71687 +}
71688 +#endif // CONFIG_STA_SUPPORT //
71689 +
71690 +
71691 +NDIS_STATUS RTMPReadParametersHook(
71692 + IN PRTMP_ADAPTER pAd)
71693 +{
71694 + PUCHAR src = NULL;
71695 + struct file *srcf;
71696 + INT retval, orgfsuid, orgfsgid;
71697 + mm_segment_t orgfs;
71698 + CHAR *buffer;
71699 + CHAR *tmpbuf;
71700 + ULONG RtsThresh;
71701 + ULONG FragThresh;
71702 +#ifdef CONFIG_STA_SUPPORT
71703 + UCHAR keyMaterial[40];
71704 +#endif // CONFIG_STA_SUPPORT //
71705 +
71706 +
71707 + PUCHAR macptr;
71708 + INT i = 0;
71709 +
71710 + buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
71711 + if(buffer == NULL)
71712 + return NDIS_STATUS_FAILURE;
71713 +
71714 + tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
71715 + if(tmpbuf == NULL)
71716 + {
71717 + kfree(buffer);
71718 + return NDIS_STATUS_FAILURE;
71719 + }
71720 +
71721 +#ifdef CONFIG_STA_SUPPORT
71722 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71723 + src = STA_PROFILE_PATH;
71724 +#endif // CONFIG_STA_SUPPORT //
71725 +#ifdef MULTIPLE_CARD_SUPPORT
71726 + src = pAd->MC_FileName;
71727 +#endif // MULTIPLE_CARD_SUPPORT //
71728 +
71729 + // Save uid and gid used for filesystem access.
71730 + // Set user and group to 0 (root)
71731 + orgfsuid = current->fsuid;
71732 + orgfsgid = current->fsgid;
71733 + current->fsuid=current->fsgid = 0;
71734 + orgfs = get_fs();
71735 + set_fs(KERNEL_DS);
71736 +
71737 + if (src && *src)
71738 + {
71739 + srcf = filp_open(src, O_RDONLY, 0);
71740 + if (IS_ERR(srcf))
71741 + {
71742 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
71743 + }
71744 + else
71745 + {
71746 + // The object must have a read method
71747 + if (srcf->f_op && srcf->f_op->read)
71748 + {
71749 + memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
71750 + retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
71751 + if (retval < 0)
71752 + {
71753 + DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));
71754 + }
71755 + else
71756 + {
71757 + // set file parameter to portcfg
71758 + //CountryRegion
71759 + if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))
71760 + {
71761 + pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);
71762 + DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
71763 + }
71764 + //CountryRegionABand
71765 + if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))
71766 + {
71767 + pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);
71768 + DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
71769 + }
71770 + //CountryCode
71771 + if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))
71772 + {
71773 + NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
71774 +#ifdef CONFIG_STA_SUPPORT
71775 +#ifdef EXT_BUILD_CHANNEL_LIST
71776 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71777 + NdisMoveMemory(pAd->StaCfg.StaOriCountryCode, tmpbuf , 2);
71778 +#endif // EXT_BUILD_CHANNEL_LIST //
71779 +#endif // CONFIG_STA_SUPPORT //
71780 + if (strlen(pAd->CommonCfg.CountryCode) != 0)
71781 + {
71782 + pAd->CommonCfg.bCountryFlag = TRUE;
71783 + }
71784 + DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
71785 + }
71786 + //ChannelGeography
71787 + if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))
71788 + {
71789 + UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
71790 + if (Geography <= BOTH)
71791 + {
71792 + pAd->CommonCfg.Geography = Geography;
71793 + pAd->CommonCfg.CountryCode[2] =
71794 + (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
71795 +#ifdef CONFIG_STA_SUPPORT
71796 +#ifdef EXT_BUILD_CHANNEL_LIST
71797 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71798 + pAd->StaCfg.StaOriGeography = pAd->CommonCfg.Geography;
71799 +#endif // EXT_BUILD_CHANNEL_LIST //
71800 +#endif // CONFIG_STA_SUPPORT //
71801 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
71802 + }
71803 + }
71804 + else
71805 + {
71806 + pAd->CommonCfg.Geography = BOTH;
71807 + pAd->CommonCfg.CountryCode[2] = ' ';
71808 + }
71809 +
71810 +
71811 +#ifdef CONFIG_STA_SUPPORT
71812 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71813 + {
71814 + //SSID
71815 + if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))
71816 + {
71817 + if (strlen(tmpbuf) <= 32)
71818 + {
71819 + pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
71820 + NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
71821 + NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
71822 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
71823 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
71824 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
71825 + pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
71826 + NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
71827 + NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
71828 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __FUNCTION__, tmpbuf));
71829 + }
71830 + }
71831 + }
71832 +#endif // CONFIG_STA_SUPPORT //
71833 +
71834 +#ifdef CONFIG_STA_SUPPORT
71835 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71836 + {
71837 + //NetworkType
71838 + if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, buffer))
71839 + {
71840 + pAd->bConfigChanged = TRUE;
71841 + if (strcmp(tmpbuf, "Adhoc") == 0)
71842 + pAd->StaCfg.BssType = BSS_ADHOC;
71843 + else //Default Infrastructure mode
71844 + pAd->StaCfg.BssType = BSS_INFRA;
71845 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
71846 + pAd->StaCfg.WpaState = SS_NOTUSE;
71847 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __FUNCTION__, pAd->StaCfg.BssType));
71848 + }
71849 + }
71850 +#endif // CONFIG_STA_SUPPORT //
71851 + //Channel
71852 + if(RTMPGetKeyParameter("Channel", tmpbuf, 10, buffer))
71853 + {
71854 + pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
71855 + DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
71856 + }
71857 + //WirelessMode
71858 + if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, buffer))
71859 + {
71860 + int value = 0, maxPhyMode = PHY_11G;
71861 +
71862 +#ifdef DOT11_N_SUPPORT
71863 + maxPhyMode = PHY_11N_5G;
71864 +#endif // DOT11_N_SUPPORT //
71865 +
71866 + value = simple_strtol(tmpbuf, 0, 10);
71867 +
71868 + if (value <= maxPhyMode)
71869 + {
71870 + pAd->CommonCfg.PhyMode = value;
71871 + }
71872 + DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
71873 + }
71874 + //BasicRate
71875 + if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, buffer))
71876 + {
71877 + pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
71878 + DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
71879 + }
71880 + //BeaconPeriod
71881 + if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, buffer))
71882 + {
71883 + pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
71884 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
71885 + }
71886 + //TxPower
71887 + if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, buffer))
71888 + {
71889 + pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
71890 +#ifdef CONFIG_STA_SUPPORT
71891 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
71892 + pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
71893 +#endif // CONFIG_STA_SUPPORT //
71894 + DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
71895 + }
71896 + //BGProtection
71897 + if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, buffer))
71898 + {
71899 + switch (simple_strtol(tmpbuf, 0, 10))
71900 + {
71901 + case 1: //Always On
71902 + pAd->CommonCfg.UseBGProtection = 1;
71903 + break;
71904 + case 2: //Always OFF
71905 + pAd->CommonCfg.UseBGProtection = 2;
71906 + break;
71907 + case 0: //AUTO
71908 + default:
71909 + pAd->CommonCfg.UseBGProtection = 0;
71910 + break;
71911 + }
71912 + DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
71913 + }
71914 + //OLBCDetection
71915 + if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, buffer))
71916 + {
71917 + switch (simple_strtol(tmpbuf, 0, 10))
71918 + {
71919 + case 1: //disable OLBC Detection
71920 + pAd->CommonCfg.DisableOLBCDetect = 1;
71921 + break;
71922 + case 0: //enable OLBC Detection
71923 + pAd->CommonCfg.DisableOLBCDetect = 0;
71924 + break;
71925 + default:
71926 + pAd->CommonCfg.DisableOLBCDetect= 0;
71927 + break;
71928 + }
71929 + DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
71930 + }
71931 + //TxPreamble
71932 + if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, buffer))
71933 + {
71934 + switch (simple_strtol(tmpbuf, 0, 10))
71935 + {
71936 + case Rt802_11PreambleShort:
71937 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
71938 + break;
71939 + case Rt802_11PreambleLong:
71940 + default:
71941 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
71942 + break;
71943 + }
71944 + DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
71945 + }
71946 + //RTSThreshold
71947 + if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, buffer))
71948 + {
71949 + RtsThresh = simple_strtol(tmpbuf, 0, 10);
71950 + if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
71951 + pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
71952 + else
71953 + pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
71954 +
71955 + DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
71956 + }
71957 + //FragThreshold
71958 + if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, buffer))
71959 + {
71960 + FragThresh = simple_strtol(tmpbuf, 0, 10);
71961 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
71962 +
71963 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
71964 + { //illegal FragThresh so we set it to default
71965 + pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
71966 + pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
71967 + }
71968 + else if (FragThresh % 2 == 1)
71969 + {
71970 + // The length of each fragment shall always be an even number of octets, except for the last fragment
71971 + // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
71972 + pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
71973 + }
71974 + else
71975 + {
71976 + pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
71977 + }
71978 + //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
71979 + DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
71980 + }
71981 + //TxBurst
71982 + if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, buffer))
71983 + {
71984 +//#ifdef WIFI_TEST
71985 +// pAd->CommonCfg.bEnableTxBurst = FALSE;
71986 +//#else
71987 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
71988 + pAd->CommonCfg.bEnableTxBurst = TRUE;
71989 + else //Disable
71990 + pAd->CommonCfg.bEnableTxBurst = FALSE;
71991 +//#endif
71992 + DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
71993 + }
71994 +
71995 +#ifdef AGGREGATION_SUPPORT
71996 + //PktAggregate
71997 + if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, buffer))
71998 + {
71999 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72000 + pAd->CommonCfg.bAggregationCapable = TRUE;
72001 + else //Disable
72002 + pAd->CommonCfg.bAggregationCapable = FALSE;
72003 +#ifdef PIGGYBACK_SUPPORT
72004 + pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
72005 +#endif // PIGGYBACK_SUPPORT //
72006 + DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
72007 + }
72008 +#else
72009 + pAd->CommonCfg.bAggregationCapable = FALSE;
72010 + pAd->CommonCfg.bPiggyBackCapable = FALSE;
72011 +#endif // AGGREGATION_SUPPORT //
72012 +
72013 + // WmmCapable
72014 +
72015 +#ifdef CONFIG_STA_SUPPORT
72016 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72017 + rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, buffer);
72018 +#endif // CONFIG_STA_SUPPORT //
72019 +
72020 + //ShortSlot
72021 + if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, buffer))
72022 + {
72023 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72024 + pAd->CommonCfg.bUseShortSlotTime = TRUE;
72025 + else //Disable
72026 + pAd->CommonCfg.bUseShortSlotTime = FALSE;
72027 +
72028 + DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
72029 + }
72030 + //IEEE80211H
72031 + if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, buffer))
72032 + {
72033 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
72034 + {
72035 + if(simple_strtol(macptr, 0, 10) != 0) //Enable
72036 + pAd->CommonCfg.bIEEE80211H = TRUE;
72037 + else //Disable
72038 + pAd->CommonCfg.bIEEE80211H = FALSE;
72039 +
72040 + DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
72041 + }
72042 + }
72043 + //CSPeriod
72044 + if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, buffer))
72045 + {
72046 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72047 + pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
72048 + else
72049 + pAd->CommonCfg.RadarDetect.CSPeriod = 0;
72050 +
72051 + DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
72052 + }
72053 +
72054 + //RDRegion
72055 + if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, buffer))
72056 + {
72057 + if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
72058 + {
72059 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W53;
72060 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 15;
72061 + }
72062 + else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
72063 + {
72064 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W56;
72065 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72066 + }
72067 + else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
72068 + {
72069 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP;
72070 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
72071 + }
72072 + else if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
72073 + {
72074 + pAd->CommonCfg.RadarDetect.RDDurRegion = FCC;
72075 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
72076 + }
72077 + else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
72078 + {
72079 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72080 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72081 + }
72082 + else
72083 + {
72084 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72085 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72086 + }
72087 +
72088 + DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pAd->CommonCfg.RadarDetect.RDDurRegion));
72089 + }
72090 + else
72091 + {
72092 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72093 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72094 + }
72095 +
72096 + //WirelessEvent
72097 + if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, buffer))
72098 + {
72099 +#if WIRELESS_EXT >= 15
72100 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72101 + pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
72102 + else
72103 + pAd->CommonCfg.bWirelessEvent = 0; // disable
72104 +#else
72105 + pAd->CommonCfg.bWirelessEvent = 0; // disable
72106 +#endif
72107 + DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
72108 + }
72109 + if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, buffer))
72110 + {
72111 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72112 + pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
72113 + else
72114 + pAd->CommonCfg.bWiFiTest = 0; // disable
72115 +
72116 + DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
72117 + }
72118 + //AuthMode
72119 + if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, buffer))
72120 + {
72121 +#ifdef CONFIG_STA_SUPPORT
72122 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72123 + {
72124 + if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
72125 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
72126 + else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
72127 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
72128 + else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
72129 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
72130 + else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
72131 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
72132 + else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
72133 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
72134 +#ifdef WPA_SUPPLICANT_SUPPORT
72135 + else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
72136 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
72137 + else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
72138 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
72139 +#endif // WPA_SUPPLICANT_SUPPORT //
72140 + else
72141 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
72142 +
72143 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
72144 +
72145 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __FUNCTION__, pAd->StaCfg.WepStatus));
72146 + }
72147 +#endif // CONFIG_STA_SUPPORT //
72148 + }
72149 + //EncrypType
72150 + if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, buffer))
72151 + {
72152 +
72153 +#ifdef CONFIG_STA_SUPPORT
72154 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72155 + {
72156 + if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
72157 + pAd->StaCfg.WepStatus = Ndis802_11WEPEnabled;
72158 + else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
72159 + pAd->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
72160 + else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
72161 + pAd->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
72162 + else
72163 + pAd->StaCfg.WepStatus = Ndis802_11WEPDisabled;
72164 +
72165 + // Update all wepstatus related
72166 + pAd->StaCfg.PairCipher = pAd->StaCfg.WepStatus;
72167 + pAd->StaCfg.GroupCipher = pAd->StaCfg.WepStatus;
72168 + pAd->StaCfg.OrigWepStatus = pAd->StaCfg.WepStatus;
72169 + pAd->StaCfg.bMixCipher = FALSE;
72170 +
72171 + //RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
72172 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __FUNCTION__, pAd->StaCfg.WepStatus));
72173 + }
72174 +#endif // CONFIG_STA_SUPPORT //
72175 + }
72176 +
72177 +
72178 +
72179 +#ifdef CONFIG_STA_SUPPORT
72180 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72181 + {
72182 + if(RTMPGetCriticalParameter("WPAPSK", tmpbuf, 512, buffer))
72183 + {
72184 + int err=0;
72185 +
72186 + tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
72187 +
72188 + if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
72189 + (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
72190 + (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
72191 + )
72192 + {
72193 + err = 1;
72194 + }
72195 + else if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) < 64))
72196 + {
72197 + PasswordHash((char *)tmpbuf, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, keyMaterial);
72198 + NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
72199 +
72200 + }
72201 + else if (strlen(tmpbuf) == 64)
72202 + {
72203 + AtoH(tmpbuf, keyMaterial, 32);
72204 + NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
72205 + }
72206 + else
72207 + {
72208 + err = 1;
72209 + DBGPRINT(RT_DEBUG_ERROR, ("%s::(WPAPSK key-string required 8 ~ 64 characters!)\n", __FUNCTION__));
72210 + }
72211 +
72212 + if (err == 0)
72213 + {
72214 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
72215 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
72216 + {
72217 + // Start STA supplicant state machine
72218 + pAd->StaCfg.WpaState = SS_START;
72219 + }
72220 + else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
72221 + {
72222 + /*
72223 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
72224 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
72225 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
72226 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
72227 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
72228 +
72229 + // Decide its ChiperAlg
72230 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
72231 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
72232 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
72233 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
72234 + else
72235 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
72236 + */
72237 + pAd->StaCfg.WpaState = SS_NOTUSE;
72238 + }
72239 +
72240 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __FUNCTION__, tmpbuf));
72241 + }
72242 + }
72243 + }
72244 +#endif // CONFIG_STA_SUPPORT //
72245 +
72246 + //DefaultKeyID, KeyType, KeyStr
72247 + rtmp_read_key_parms_from_file(pAd, tmpbuf, buffer);
72248 +
72249 +
72250 + //HSCounter
72251 + /*if(RTMPGetKeyParameter("HSCounter", tmpbuf, 10, buffer))
72252 + {
72253 + switch (simple_strtol(tmpbuf, 0, 10))
72254 + {
72255 + case 1: //Enable
72256 + pAd->CommonCfg.bEnableHSCounter = TRUE;
72257 + break;
72258 + case 0: //Disable
72259 + default:
72260 + pAd->CommonCfg.bEnableHSCounter = FALSE;
72261 + break;
72262 + }
72263 + DBGPRINT(RT_DEBUG_TRACE, "HSCounter=%d\n", pAd->CommonCfg.bEnableHSCounter);
72264 + }*/
72265 +
72266 +#ifdef DOT11_N_SUPPORT
72267 + HTParametersHook(pAd, tmpbuf, buffer);
72268 +#endif // DOT11_N_SUPPORT //
72269 +
72270 +
72271 +#ifdef CARRIER_DETECTION_SUPPORT
72272 + //CarrierDetect
72273 + if(RTMPGetKeyParameter("CarrierDetect", tmpbuf, 128, buffer))
72274 + {
72275 + if ((strncmp(tmpbuf, "0", 1) == 0))
72276 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
72277 + else if ((strncmp(tmpbuf, "1", 1) == 0))
72278 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
72279 + else
72280 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
72281 +
72282 + DBGPRINT(RT_DEBUG_TRACE, ("CarrierDetect.Enable=%d\n", pAd->CommonCfg.CarrierDetect.Enable));
72283 + }
72284 + else
72285 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
72286 +#endif // CARRIER_DETECTION_SUPPORT //
72287 +
72288 +#ifdef CONFIG_STA_SUPPORT
72289 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72290 + {
72291 + //PSMode
72292 + if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, buffer))
72293 + {
72294 + if (pAd->StaCfg.BssType == BSS_INFRA)
72295 + {
72296 + if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
72297 + {
72298 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
72299 + // to exclude certain situations.
72300 + // MlmeSetPsm(pAd, PWR_SAVE);
72301 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
72302 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
72303 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
72304 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
72305 + pAd->StaCfg.DefaultListenCount = 5;
72306 + }
72307 + else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
72308 + || (strcmp(tmpbuf, "FAST_PSP") == 0))
72309 + {
72310 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
72311 + // to exclude certain situations.
72312 + // MlmeSetPsmBit(pAd, PWR_SAVE);
72313 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
72314 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
72315 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
72316 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
72317 + pAd->StaCfg.DefaultListenCount = 3;
72318 + }
72319 + else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
72320 + || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
72321 + {
72322 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
72323 + // to exclude certain situations.
72324 + // MlmeSetPsmBit(pAd, PWR_SAVE);
72325 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
72326 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
72327 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
72328 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
72329 + pAd->StaCfg.DefaultListenCount = 3;
72330 + }
72331 + else
72332 + { //Default Ndis802_11PowerModeCAM
72333 + // clear PSM bit immediately
72334 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
72335 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
72336 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
72337 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
72338 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
72339 + }
72340 + DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
72341 + }
72342 + }
72343 + // FastRoaming
72344 + if (RTMPGetKeyParameter("FastRoaming", tmpbuf, 32, buffer))
72345 + {
72346 + if (simple_strtol(tmpbuf, 0, 10) == 0)
72347 + pAd->StaCfg.bFastRoaming = FALSE;
72348 + else
72349 + pAd->StaCfg.bFastRoaming = TRUE;
72350 +
72351 + DBGPRINT(RT_DEBUG_TRACE, ("FastRoaming=%d\n", pAd->StaCfg.bFastRoaming));
72352 + }
72353 + // RoamThreshold
72354 + if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, buffer))
72355 + {
72356 + long lInfo = simple_strtol(tmpbuf, 0, 10);
72357 +
72358 + if (lInfo > 90 || lInfo < 60)
72359 + pAd->StaCfg.dBmToRoam = -70;
72360 + else
72361 + pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
72362 +
72363 + DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d dBm\n", pAd->StaCfg.dBmToRoam));
72364 + }
72365 +
72366 + if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, buffer))
72367 + {
72368 + if(simple_strtol(tmpbuf, 0, 10) == 0)
72369 + pAd->StaCfg.bTGnWifiTest = FALSE;
72370 + else
72371 + pAd->StaCfg.bTGnWifiTest = TRUE;
72372 + DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
72373 + }
72374 + }
72375 +#endif // CONFIG_STA_SUPPORT //
72376 +
72377 +
72378 +
72379 + }
72380 + }
72381 + else
72382 + {
72383 + DBGPRINT(RT_DEBUG_TRACE, ("--> %s does not have a write method\n", src));
72384 + }
72385 +
72386 + retval=filp_close(srcf,NULL);
72387 +
72388 + if (retval)
72389 + {
72390 + DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
72391 + }
72392 + }
72393 + }
72394 +
72395 + set_fs(orgfs);
72396 + current->fsuid = orgfsuid;
72397 + current->fsgid = orgfsgid;
72398 +
72399 + kfree(buffer);
72400 + kfree(tmpbuf);
72401 +
72402 + return (NDIS_STATUS_SUCCESS);
72403 +}
72404 +
72405 +#ifdef DOT11_N_SUPPORT
72406 +static void HTParametersHook(
72407 + IN PRTMP_ADAPTER pAd,
72408 + IN CHAR *pValueStr,
72409 + IN CHAR *pInput)
72410 +{
72411 +
72412 + INT Value;
72413 +
72414 + if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput))
72415 + {
72416 + Value = simple_strtol(pValueStr, 0, 10);
72417 + if (Value == 0)
72418 + {
72419 + pAd->CommonCfg.bHTProtect = FALSE;
72420 + }
72421 + else
72422 + {
72423 + pAd->CommonCfg.bHTProtect = TRUE;
72424 + }
72425 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection = %s\n", (Value==0) ? "Disable" : "Enable"));
72426 + }
72427 +
72428 + if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput))
72429 + {
72430 + Value = simple_strtol(pValueStr, 0, 10);
72431 + if (Value == 0)
72432 + {
72433 + pAd->CommonCfg.bMIMOPSEnable = FALSE;
72434 + }
72435 + else
72436 + {
72437 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
72438 + }
72439 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable = %s\n", (Value==0) ? "Disable" : "Enable"));
72440 + }
72441 +
72442 +
72443 + if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput))
72444 + {
72445 + Value = simple_strtol(pValueStr, 0, 10);
72446 + if (Value > MMPS_ENABLE)
72447 + {
72448 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
72449 + }
72450 + else
72451 + {
72452 + //TODO: add mimo power saving mechanism
72453 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
72454 + //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
72455 + }
72456 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode = %d\n", Value));
72457 + }
72458 +
72459 + if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput))
72460 + {
72461 + Value = simple_strtol(pValueStr, 0, 10);
72462 + if (Value == 0)
72463 + {
72464 + pAd->CommonCfg.bBADecline = FALSE;
72465 + }
72466 + else
72467 + {
72468 + pAd->CommonCfg.bBADecline = TRUE;
72469 + }
72470 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline = %s\n", (Value==0) ? "Disable" : "Enable"));
72471 + }
72472 +
72473 +
72474 + if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput))
72475 + {
72476 + Value = simple_strtol(pValueStr, 0, 10);
72477 + if (Value == 0)
72478 + {
72479 + pAd->CommonCfg.bDisableReordering = FALSE;
72480 + }
72481 + else
72482 + {
72483 + pAd->CommonCfg.bDisableReordering = TRUE;
72484 + }
72485 + DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering = %s\n", (Value==0) ? "Disable" : "Enable"));
72486 + }
72487 +
72488 + if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput))
72489 + {
72490 + Value = simple_strtol(pValueStr, 0, 10);
72491 + if (Value == 0)
72492 + {
72493 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
72494 + }
72495 + else
72496 + {
72497 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
72498 + }
72499 + pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
72500 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA = %s\n", (Value==0) ? "Disable" : "Enable"));
72501 + }
72502 +
72503 + // Tx_+HTC frame
72504 + if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput))
72505 + {
72506 + Value = simple_strtol(pValueStr, 0, 10);
72507 + if (Value == 0)
72508 + {
72509 + pAd->HTCEnable = FALSE;
72510 + }
72511 + else
72512 + {
72513 + pAd->HTCEnable = TRUE;
72514 + }
72515 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
72516 + }
72517 +
72518 + // Enable HT Link Adaptation Control
72519 + if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput))
72520 + {
72521 + Value = simple_strtol(pValueStr, 0, 10);
72522 + if (Value == 0)
72523 + {
72524 + pAd->bLinkAdapt = FALSE;
72525 + }
72526 + else
72527 + {
72528 + pAd->HTCEnable = TRUE;
72529 + pAd->bLinkAdapt = TRUE;
72530 + }
72531 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
72532 + }
72533 +
72534 + // Reverse Direction Mechanism
72535 + if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput))
72536 + {
72537 + Value = simple_strtol(pValueStr, 0, 10);
72538 + if (Value == 0)
72539 + {
72540 + pAd->CommonCfg.bRdg = FALSE;
72541 + }
72542 + else
72543 + {
72544 + pAd->HTCEnable = TRUE;
72545 + pAd->CommonCfg.bRdg = TRUE;
72546 + }
72547 + DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
72548 + }
72549 +
72550 +
72551 +
72552 +
72553 + // Tx A-MSUD ?
72554 + if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput))
72555 + {
72556 + Value = simple_strtol(pValueStr, 0, 10);
72557 + if (Value == 0)
72558 + {
72559 + pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
72560 + }
72561 + else
72562 + {
72563 + pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
72564 + }
72565 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
72566 + }
72567 +
72568 + // MPDU Density
72569 + if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput))
72570 + {
72571 + Value = simple_strtol(pValueStr, 0, 10);
72572 + if (Value <=7 && Value >= 0)
72573 + {
72574 + pAd->CommonCfg.BACapability.field.MpduDensity = Value;
72575 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", Value));
72576 + }
72577 + else
72578 + {
72579 + pAd->CommonCfg.BACapability.field.MpduDensity = 4;
72580 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
72581 + }
72582 + }
72583 +
72584 + // Max Rx BA Window Size
72585 + if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput))
72586 + {
72587 + Value = simple_strtol(pValueStr, 0, 10);
72588 +
72589 + if (Value >=1 && Value <= 64)
72590 + {
72591 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
72592 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
72593 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", Value));
72594 + }
72595 + else
72596 + {
72597 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
72598 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
72599 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
72600 + }
72601 +
72602 + }
72603 +
72604 + // Guard Interval
72605 + if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput))
72606 + {
72607 + Value = simple_strtol(pValueStr, 0, 10);
72608 +
72609 + if (Value == GI_400)
72610 + {
72611 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
72612 + }
72613 + else
72614 + {
72615 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
72616 + }
72617 +
72618 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
72619 + }
72620 +
72621 + // HT Operation Mode : Mixed Mode , Green Field
72622 + if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput))
72623 + {
72624 + Value = simple_strtol(pValueStr, 0, 10);
72625 +
72626 + if (Value == HTMODE_GF)
72627 + {
72628 +
72629 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
72630 + }
72631 + else
72632 + {
72633 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
72634 + }
72635 +
72636 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
72637 + }
72638 +
72639 + // Fixed Tx mode : CCK, OFDM
72640 + if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput))
72641 + {
72642 + UCHAR fix_tx_mode;
72643 +
72644 +#ifdef CONFIG_STA_SUPPORT
72645 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72646 + {
72647 + fix_tx_mode = FIXED_TXMODE_HT;
72648 +
72649 + if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
72650 + {
72651 + fix_tx_mode = FIXED_TXMODE_OFDM;
72652 + }
72653 + else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
72654 + {
72655 + fix_tx_mode = FIXED_TXMODE_CCK;
72656 + }
72657 + else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
72658 + {
72659 + fix_tx_mode = FIXED_TXMODE_HT;
72660 + }
72661 + else
72662 + {
72663 + Value = simple_strtol(pValueStr, 0, 10);
72664 + // 1 : CCK
72665 + // 2 : OFDM
72666 + // otherwise : HT
72667 + if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
72668 + fix_tx_mode = Value;
72669 + else
72670 + fix_tx_mode = FIXED_TXMODE_HT;
72671 + }
72672 +
72673 + pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
72674 + DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
72675 +
72676 + }
72677 +#endif // CONFIG_STA_SUPPORT //
72678 + }
72679 +
72680 +
72681 + // Channel Width
72682 + if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput))
72683 + {
72684 + Value = simple_strtol(pValueStr, 0, 10);
72685 +
72686 + if (Value == BW_40)
72687 + {
72688 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
72689 + }
72690 + else
72691 + {
72692 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
72693 + }
72694 +
72695 +#ifdef MCAST_RATE_SPECIFIC
72696 + pAd->CommonCfg.MCastPhyMode.field.BW = pAd->CommonCfg.RegTransmitSetting.field.BW;
72697 +#endif // MCAST_RATE_SPECIFIC //
72698 +
72699 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
72700 + }
72701 +
72702 + if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput))
72703 + {
72704 + Value = simple_strtol(pValueStr, 0, 10);
72705 +
72706 + if (Value == 0)
72707 + {
72708 +
72709 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
72710 + }
72711 + else
72712 + {
72713 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
72714 + }
72715 +
72716 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
72717 + }
72718 +
72719 + // MSC
72720 + if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput))
72721 + {
72722 +
72723 +#ifdef CONFIG_STA_SUPPORT
72724 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72725 + {
72726 + Value = simple_strtol(pValueStr, 0, 10);
72727 +
72728 +// if ((Value >= 0 && Value <= 15) || (Value == 32))
72729 + if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
72730 + {
72731 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = Value;
72732 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
72733 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
72734 + }
72735 + else
72736 + {
72737 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
72738 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
72739 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
72740 + }
72741 + }
72742 +#endif // CONFIG_STA_SUPPORT //
72743 + }
72744 +
72745 + // STBC
72746 + if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput))
72747 + {
72748 + Value = simple_strtol(pValueStr, 0, 10);
72749 + if (Value == STBC_USE)
72750 + {
72751 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
72752 + }
72753 + else
72754 + {
72755 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
72756 + }
72757 + DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
72758 + }
72759 +
72760 + // 40_Mhz_Intolerant
72761 + if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput))
72762 + {
72763 + Value = simple_strtol(pValueStr, 0, 10);
72764 + if (Value == 0)
72765 + {
72766 + pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
72767 + }
72768 + else
72769 + {
72770 + pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
72771 + }
72772 + DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
72773 + }
72774 + //HT_TxStream
72775 + if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput))
72776 + {
72777 + switch (simple_strtol(pValueStr, 0, 10))
72778 + {
72779 + case 1:
72780 + pAd->CommonCfg.TxStream = 1;
72781 + break;
72782 + case 2:
72783 + pAd->CommonCfg.TxStream = 2;
72784 + break;
72785 + case 3: // 3*3
72786 + default:
72787 + pAd->CommonCfg.TxStream = 3;
72788 +
72789 + if (pAd->MACVersion < RALINK_2883_VERSION)
72790 + pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
72791 + break;
72792 + }
72793 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
72794 + }
72795 + //HT_RxStream
72796 + if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput))
72797 + {
72798 + switch (simple_strtol(pValueStr, 0, 10))
72799 + {
72800 + case 1:
72801 + pAd->CommonCfg.RxStream = 1;
72802 + break;
72803 + case 2:
72804 + pAd->CommonCfg.RxStream = 2;
72805 + break;
72806 + case 3:
72807 + default:
72808 + pAd->CommonCfg.RxStream = 3;
72809 +
72810 + if (pAd->MACVersion < RALINK_2883_VERSION)
72811 + pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
72812 + break;
72813 + }
72814 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));
72815 + }
72816 +
72817 +}
72818 +#endif // DOT11_N_SUPPORT //
72819 +
72820 --- /dev/null
72821 +++ b/drivers/staging/rt2870/spectrum_def.h
72822 @@ -0,0 +1,95 @@
72823 +/*
72824 + *************************************************************************
72825 + * Ralink Tech Inc.
72826 + * 5F., No.36, Taiyuan St., Jhubei City,
72827 + * Hsinchu County 302,
72828 + * Taiwan, R.O.C.
72829 + *
72830 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
72831 + *
72832 + * This program is free software; you can redistribute it and/or modify *
72833 + * it under the terms of the GNU General Public License as published by *
72834 + * the Free Software Foundation; either version 2 of the License, or *
72835 + * (at your option) any later version. *
72836 + * *
72837 + * This program is distributed in the hope that it will be useful, *
72838 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
72839 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
72840 + * GNU General Public License for more details. *
72841 + * *
72842 + * You should have received a copy of the GNU General Public License *
72843 + * along with this program; if not, write to the *
72844 + * Free Software Foundation, Inc., *
72845 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
72846 + * *
72847 + *************************************************************************
72848 +
72849 + Module Name:
72850 + spectrum_def.h
72851 +
72852 + Abstract:
72853 + Handle association related requests either from WSTA or from local MLME
72854 +
72855 + Revision History:
72856 + Who When What
72857 + --------- ---------- ----------------------------------------------
72858 + Fonchi Wu 2008 created for 802.11h
72859 + */
72860 +
72861 +#ifndef __SPECTRUM_DEF_H__
72862 +#define __SPECTRUM_DEF_H__
72863 +
72864 +#define MAX_MEASURE_REQ_TAB_SIZE 3
72865 +#define MAX_HASH_MEASURE_REQ_TAB_SIZE MAX_MEASURE_REQ_TAB_SIZE
72866 +
72867 +#define MAX_TPC_REQ_TAB_SIZE 3
72868 +#define MAX_HASH_TPC_REQ_TAB_SIZE MAX_TPC_REQ_TAB_SIZE
72869 +
72870 +#define MIN_RCV_PWR 100 /* Negative value ((dBm) */
72871 +
72872 +#define RM_TPC_REQ 0
72873 +#define RM_MEASURE_REQ 1
72874 +
72875 +#define RM_BASIC 0
72876 +#define RM_CCA 1
72877 +#define RM_RPI_HISTOGRAM 2
72878 +
72879 +#define TPC_REQ_AGE_OUT 500 /* ms */
72880 +#define MQ_REQ_AGE_OUT 500 /* ms */
72881 +
72882 +#define TPC_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_HASH_TPC_REQ_TAB_SIZE)
72883 +#define MQ_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_MEASURE_REQ_TAB_SIZE)
72884 +
72885 +typedef struct _MEASURE_REQ_ENTRY
72886 +{
72887 + struct _MEASURE_REQ_ENTRY *pNext;
72888 + ULONG lastTime;
72889 + BOOLEAN Valid;
72890 + UINT8 DialogToken;
72891 + UINT8 MeasureDialogToken[3]; // 0:basic measure, 1: CCA measure, 2: RPI_Histogram measure.
72892 +} MEASURE_REQ_ENTRY, *PMEASURE_REQ_ENTRY;
72893 +
72894 +typedef struct _MEASURE_REQ_TAB
72895 +{
72896 + UCHAR Size;
72897 + PMEASURE_REQ_ENTRY Hash[MAX_HASH_MEASURE_REQ_TAB_SIZE];
72898 + MEASURE_REQ_ENTRY Content[MAX_MEASURE_REQ_TAB_SIZE];
72899 +} MEASURE_REQ_TAB, *PMEASURE_REQ_TAB;
72900 +
72901 +typedef struct _TPC_REQ_ENTRY
72902 +{
72903 + struct _TPC_REQ_ENTRY *pNext;
72904 + ULONG lastTime;
72905 + BOOLEAN Valid;
72906 + UINT8 DialogToken;
72907 +} TPC_REQ_ENTRY, *PTPC_REQ_ENTRY;
72908 +
72909 +typedef struct _TPC_REQ_TAB
72910 +{
72911 + UCHAR Size;
72912 + PTPC_REQ_ENTRY Hash[MAX_HASH_TPC_REQ_TAB_SIZE];
72913 + TPC_REQ_ENTRY Content[MAX_TPC_REQ_TAB_SIZE];
72914 +} TPC_REQ_TAB, *PTPC_REQ_TAB;
72915 +
72916 +#endif // __SPECTRUM_DEF_H__ //
72917 +
72918 --- /dev/null
72919 +++ b/drivers/staging/rt2870/spectrum.h
72920 @@ -0,0 +1,322 @@
72921 +/*
72922 + *************************************************************************
72923 + * Ralink Tech Inc.
72924 + * 5F., No.36, Taiyuan St., Jhubei City,
72925 + * Hsinchu County 302,
72926 + * Taiwan, R.O.C.
72927 + *
72928 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
72929 + *
72930 + * This program is free software; you can redistribute it and/or modify *
72931 + * it under the terms of the GNU General Public License as published by *
72932 + * the Free Software Foundation; either version 2 of the License, or *
72933 + * (at your option) any later version. *
72934 + * *
72935 + * This program is distributed in the hope that it will be useful, *
72936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
72937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
72938 + * GNU General Public License for more details. *
72939 + * *
72940 + * You should have received a copy of the GNU General Public License *
72941 + * along with this program; if not, write to the *
72942 + * Free Software Foundation, Inc., *
72943 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
72944 + * *
72945 + *************************************************************************
72946 + */
72947 +
72948 +#ifndef __SPECTRUM_H__
72949 +#define __SPECTRUM_H__
72950 +
72951 +#include "rtmp_type.h"
72952 +#include "spectrum_def.h"
72953 +
72954 +typedef struct PACKED _TPC_REPORT_INFO
72955 +{
72956 + UINT8 TxPwr;
72957 + UINT8 LinkMargin;
72958 +} TPC_REPORT_INFO, *PTPC_REPORT_INFO;
72959 +
72960 +typedef struct PACKED _CH_SW_ANN_INFO
72961 +{
72962 + UINT8 ChSwMode;
72963 + UINT8 Channel;
72964 + UINT8 ChSwCnt;
72965 +} CH_SW_ANN_INFO, *PCH_SW_ANN_INFO;
72966 +
72967 +typedef union PACKED _MEASURE_REQ_MODE
72968 +{
72969 +#ifdef RT_BIG_ENDIAN
72970 + struct PACKED
72971 + {
72972 + UINT8 Rev1:4;
72973 + UINT8 Report:1;
72974 + UINT8 Request:1;
72975 + UINT8 Enable:1;
72976 + UINT8 Rev0:1;
72977 + } field;
72978 +#else
72979 + struct PACKED
72980 + {
72981 + UINT8 Rev0:1;
72982 + UINT8 Enable:1;
72983 + UINT8 Request:1;
72984 + UINT8 Report:1;
72985 + UINT8 Rev1:4;
72986 + } field;
72987 +#endif // RT_BIG_ENDIAN //
72988 + UINT8 word;
72989 +} MEASURE_REQ_MODE, *PMEASURE_REQ_MODE;
72990 +
72991 +typedef struct PACKED _MEASURE_REQ
72992 +{
72993 + UINT8 ChNum;
72994 + UINT64 MeasureStartTime;
72995 + UINT16 MeasureDuration;
72996 +} MEASURE_REQ, *PMEASURE_REQ;
72997 +
72998 +typedef struct PACKED _MEASURE_REQ_INFO
72999 +{
73000 + UINT8 Token;
73001 + MEASURE_REQ_MODE ReqMode;
73002 + UINT8 ReqType;
73003 + MEASURE_REQ MeasureReq;
73004 +} MEASURE_REQ_INFO, *PMEASURE_REQ_INFO;
73005 +
73006 +typedef union PACKED _MEASURE_BASIC_REPORT_MAP
73007 +{
73008 +#ifdef RT_BIG_ENDIAN
73009 + struct PACKED
73010 + {
73011 + UINT8 Rev:3;
73012 + UINT8 Unmeasure:1;
73013 + UINT8 Radar:1;
73014 + UINT8 UnidentifiedSignal:1;
73015 + UINT8 OfdmPreamble:1;
73016 + UINT8 BSS:1;
73017 + } field;
73018 +#else
73019 + struct PACKED
73020 + {
73021 + UINT8 BSS:1;
73022 + UINT8 OfdmPreamble:1;
73023 + UINT8 UnidentifiedSignal:1;
73024 + UINT8 Radar:1;
73025 + UINT8 Unmeasure:1;
73026 + UINT8 Rev:3;
73027 + } field;
73028 +#endif // RT_BIG_ENDIAN //
73029 + UINT8 word;
73030 +} MEASURE_BASIC_REPORT_MAP, *PMEASURE_BASIC_REPORT_MAP;
73031 +
73032 +typedef struct PACKED _MEASURE_BASIC_REPORT
73033 +{
73034 + UINT8 ChNum;
73035 + UINT64 MeasureStartTime;
73036 + UINT16 MeasureDuration;
73037 + MEASURE_BASIC_REPORT_MAP Map;
73038 +} MEASURE_BASIC_REPORT, *PMEASURE_BASIC_REPORT;
73039 +
73040 +typedef struct PACKED _MEASURE_CCA_REPORT
73041 +{
73042 + UINT8 ChNum;
73043 + UINT64 MeasureStartTime;
73044 + UINT16 MeasureDuration;
73045 + UINT8 CCA_Busy_Fraction;
73046 +} MEASURE_CCA_REPORT, *PMEASURE_CCA_REPORT;
73047 +
73048 +typedef struct PACKED _MEASURE_RPI_REPORT
73049 +{
73050 + UINT8 ChNum;
73051 + UINT64 MeasureStartTime;
73052 + UINT16 MeasureDuration;
73053 + UINT8 RPI_Density[8];
73054 +} MEASURE_RPI_REPORT, *PMEASURE_RPI_REPORT;
73055 +
73056 +typedef union PACKED _MEASURE_REPORT_MODE
73057 +{
73058 + struct PACKED
73059 + {
73060 +#ifdef RT_BIG_ENDIAN
73061 + UINT8 Rev:5;
73062 + UINT8 Refused:1;
73063 + UINT8 Incapable:1;
73064 + UINT8 Late:1;
73065 +#else
73066 + UINT8 Late:1;
73067 + UINT8 Incapable:1;
73068 + UINT8 Refused:1;
73069 + UINT8 Rev:5;
73070 +#endif // RT_BIG_ENDIAN //
73071 + } field;
73072 + UINT8 word;
73073 +} MEASURE_REPORT_MODE, *PMEASURE_REPORT_MODE;
73074 +
73075 +typedef struct PACKED _MEASURE_REPORT_INFO
73076 +{
73077 + UINT8 Token;
73078 + MEASURE_REPORT_MODE ReportMode;
73079 + UINT8 ReportType;
73080 + UINT8 Octect[0];
73081 +} MEASURE_REPORT_INFO, *PMEASURE_REPORT_INFO;
73082 +
73083 +typedef struct PACKED _QUIET_INFO
73084 +{
73085 + UINT8 QuietCnt;
73086 + UINT8 QuietPeriod;
73087 + UINT8 QuietDuration;
73088 + UINT8 QuietOffset;
73089 +} QUIET_INFO, *PQUIET_INFO;
73090 +
73091 +/*
73092 + ==========================================================================
73093 + Description:
73094 + Prepare Measurement request action frame and enqueue it into
73095 + management queue waiting for transmition.
73096 +
73097 + Parametrs:
73098 + 1. the destination mac address of the frame.
73099 +
73100 + Return : None.
73101 + ==========================================================================
73102 + */
73103 +VOID EnqueueMeasurementReq(
73104 + IN PRTMP_ADAPTER pAd,
73105 + IN PUCHAR pDA,
73106 + IN UINT8 MeasureToken,
73107 + IN UINT8 MeasureReqMode,
73108 + IN UINT8 MeasureReqType,
73109 + IN UINT8 MeasureCh,
73110 + IN UINT16 MeasureDuration);
73111 +
73112 +/*
73113 + ==========================================================================
73114 + Description:
73115 + Prepare Measurement report action frame and enqueue it into
73116 + management queue waiting for transmition.
73117 +
73118 + Parametrs:
73119 + 1. the destination mac address of the frame.
73120 +
73121 + Return : None.
73122 + ==========================================================================
73123 + */
73124 +VOID EnqueueMeasurementRep(
73125 + IN PRTMP_ADAPTER pAd,
73126 + IN PUCHAR pDA,
73127 + IN UINT8 DialogToken,
73128 + IN UINT8 MeasureToken,
73129 + IN UINT8 MeasureReqMode,
73130 + IN UINT8 MeasureReqType,
73131 + IN UINT8 ReportInfoLen,
73132 + IN PUINT8 pReportInfo);
73133 +
73134 +/*
73135 + ==========================================================================
73136 + Description:
73137 + Prepare TPC Request action frame and enqueue it into
73138 + management queue waiting for transmition.
73139 +
73140 + Parametrs:
73141 + 1. the destination mac address of the frame.
73142 +
73143 + Return : None.
73144 + ==========================================================================
73145 + */
73146 +VOID EnqueueTPCReq(
73147 + IN PRTMP_ADAPTER pAd,
73148 + IN PUCHAR pDA,
73149 + IN UCHAR DialogToken);
73150 +
73151 +/*
73152 + ==========================================================================
73153 + Description:
73154 + Prepare TPC Report action frame and enqueue it into
73155 + management queue waiting for transmition.
73156 +
73157 + Parametrs:
73158 + 1. the destination mac address of the frame.
73159 +
73160 + Return : None.
73161 + ==========================================================================
73162 + */
73163 +VOID EnqueueTPCRep(
73164 + IN PRTMP_ADAPTER pAd,
73165 + IN PUCHAR pDA,
73166 + IN UINT8 DialogToken,
73167 + IN UINT8 TxPwr,
73168 + IN UINT8 LinkMargin);
73169 +
73170 +/*
73171 + ==========================================================================
73172 + Description:
73173 + Prepare Channel Switch Announcement action frame and enqueue it into
73174 + management queue waiting for transmition.
73175 +
73176 + Parametrs:
73177 + 1. the destination mac address of the frame.
73178 + 2. Channel switch announcement mode.
73179 + 2. a New selected channel.
73180 +
73181 + Return : None.
73182 + ==========================================================================
73183 + */
73184 +VOID EnqueueChSwAnn(
73185 + IN PRTMP_ADAPTER pAd,
73186 + IN PUCHAR pDA,
73187 + IN UINT8 ChSwMode,
73188 + IN UINT8 NewCh);
73189 +
73190 +/*
73191 + ==========================================================================
73192 + Description:
73193 + Spectrun action frames Handler such as channel switch annoucement,
73194 + measurement report, measurement request actions frames.
73195 +
73196 + Parametrs:
73197 + Elme - MLME message containing the received frame
73198 +
73199 + Return : None.
73200 + ==========================================================================
73201 + */
73202 +VOID PeerSpectrumAction(
73203 + IN PRTMP_ADAPTER pAd,
73204 + IN MLME_QUEUE_ELEM *Elem);
73205 +
73206 +/*
73207 + ==========================================================================
73208 + Description:
73209 +
73210 + Parametrs:
73211 +
73212 + Return : None.
73213 + ==========================================================================
73214 + */
73215 +INT Set_MeasureReq_Proc(
73216 + IN PRTMP_ADAPTER pAd,
73217 + IN PUCHAR arg);
73218 +
73219 +INT Set_TpcReq_Proc(
73220 + IN PRTMP_ADAPTER pAd,
73221 + IN PUCHAR arg);
73222 +
73223 +VOID MeasureReqTabInit(
73224 + IN PRTMP_ADAPTER pAd);
73225 +
73226 +VOID MeasureReqTabExit(
73227 + IN PRTMP_ADAPTER pAd);
73228 +
73229 +VOID TpcReqTabInit(
73230 + IN PRTMP_ADAPTER pAd);
73231 +
73232 +VOID TpcReqTabExit(
73233 + IN PRTMP_ADAPTER pAd);
73234 +
73235 +VOID NotifyChSwAnnToPeerAPs(
73236 + IN PRTMP_ADAPTER pAd,
73237 + IN PUCHAR pRA,
73238 + IN PUCHAR pTA,
73239 + IN UINT8 ChSwMode,
73240 + IN UINT8 Channel);
73241 +#endif // __SPECTRUM_H__ //
73242 +
73243 --- /dev/null
73244 +++ b/drivers/staging/rt2870/sta/aironet.c
73245 @@ -0,0 +1,1312 @@
73246 +/*
73247 + *************************************************************************
73248 + * Ralink Tech Inc.
73249 + * 5F., No.36, Taiyuan St., Jhubei City,
73250 + * Hsinchu County 302,
73251 + * Taiwan, R.O.C.
73252 + *
73253 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
73254 + *
73255 + * This program is free software; you can redistribute it and/or modify *
73256 + * it under the terms of the GNU General Public License as published by *
73257 + * the Free Software Foundation; either version 2 of the License, or *
73258 + * (at your option) any later version. *
73259 + * *
73260 + * This program is distributed in the hope that it will be useful, *
73261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
73262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
73263 + * GNU General Public License for more details. *
73264 + * *
73265 + * You should have received a copy of the GNU General Public License *
73266 + * along with this program; if not, write to the *
73267 + * Free Software Foundation, Inc., *
73268 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
73269 + * *
73270 + *************************************************************************
73271 +
73272 + Module Name:
73273 + aironet.c
73274 +
73275 + Abstract:
73276 +
73277 + Revision History:
73278 + Who When What
73279 + -------- ---------- ----------------------------------------------
73280 + Paul Lin 04-06-15 Initial
73281 +*/
73282 +#include "../rt_config.h"
73283 +
73284 +/*
73285 + ==========================================================================
73286 + Description:
73287 + association state machine init, including state transition and timer init
73288 + Parameters:
73289 + S - pointer to the association state machine
73290 + ==========================================================================
73291 + */
73292 +VOID AironetStateMachineInit(
73293 + IN PRTMP_ADAPTER pAd,
73294 + IN STATE_MACHINE *S,
73295 + OUT STATE_MACHINE_FUNC Trans[])
73296 +{
73297 + StateMachineInit(S, Trans, MAX_AIRONET_STATE, MAX_AIRONET_MSG, (STATE_MACHINE_FUNC)Drop, AIRONET_IDLE, AIRONET_MACHINE_BASE);
73298 + StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_MSG, (STATE_MACHINE_FUNC)AironetMsgAction);
73299 + StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_SCAN_REQ, (STATE_MACHINE_FUNC)AironetRequestAction);
73300 + StateMachineSetAction(S, AIRONET_SCANNING, MT2_AIRONET_SCAN_DONE, (STATE_MACHINE_FUNC)AironetReportAction);
73301 +}
73302 +
73303 +/*
73304 + ==========================================================================
73305 + Description:
73306 + This is state machine function.
73307 + When receiving EAPOL packets which is for 802.1x key management.
73308 + Use both in WPA, and WPAPSK case.
73309 + In this function, further dispatch to different functions according to the received packet. 3 categories are :
73310 + 1. normal 4-way pairwisekey and 2-way groupkey handshake
73311 + 2. MIC error (Countermeasures attack) report packet from STA.
73312 + 3. Request for pairwise/group key update from STA
73313 + Return:
73314 + ==========================================================================
73315 +*/
73316 +VOID AironetMsgAction(
73317 + IN PRTMP_ADAPTER pAd,
73318 + IN MLME_QUEUE_ELEM *Elem)
73319 +{
73320 + USHORT Length;
73321 + UCHAR Index, i;
73322 + PUCHAR pData;
73323 + PAIRONET_RM_REQUEST_FRAME pRMReq;
73324 + PRM_REQUEST_ACTION pReqElem;
73325 +
73326 + DBGPRINT(RT_DEBUG_TRACE, ("-----> AironetMsgAction\n"));
73327 +
73328 + // 0. Get Aironet IAPP header first
73329 + pRMReq = (PAIRONET_RM_REQUEST_FRAME) &Elem->Msg[LENGTH_802_11];
73330 + pData = (PUCHAR) &Elem->Msg[LENGTH_802_11];
73331 +
73332 + // 1. Change endian format form network to little endian
73333 + Length = be2cpu16(pRMReq->IAPP.Length);
73334 +
73335 + // 2.0 Sanity check, this should only happen when CCX 2.0 support is enabled
73336 + if (pAd->StaCfg.CCXEnable != TRUE)
73337 + return;
73338 +
73339 + // 2.1 Radio measurement must be on
73340 + if (pAd->StaCfg.CCXControl.field.RMEnable != 1)
73341 + return;
73342 +
73343 + // 2.2. Debug print all bit information
73344 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP ID & Length %d\n", Length));
73345 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Type %x\n", pRMReq->IAPP.Type));
73346 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP SubType %x\n", pRMReq->IAPP.SubType));
73347 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Dialog Token %x\n", pRMReq->IAPP.Token));
73348 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Activation Delay %x\n", pRMReq->Delay));
73349 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Measurement Offset %x\n", pRMReq->Offset));
73350 +
73351 + // 3. Check IAPP frame type, it must be 0x32 for Cisco Aironet extension
73352 + if (pRMReq->IAPP.Type != AIRONET_IAPP_TYPE)
73353 + {
73354 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP type for Cisco Aironet extension\n"));
73355 + return;
73356 + }
73357 +
73358 + // 4. Check IAPP frame subtype, it must be 0x01 for Cisco Aironet extension request.
73359 + // Since we are acting as client only, we will disregards reply subtype.
73360 + if (pRMReq->IAPP.SubType != AIRONET_IAPP_SUBTYPE_REQUEST)
73361 + {
73362 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP subtype for Cisco Aironet extension\n"));
73363 + return;
73364 + }
73365 +
73366 + // 5. Verify Destination MAC and Source MAC, both should be all zeros.
73367 + if (! MAC_ADDR_EQUAL(pRMReq->IAPP.DA, ZERO_MAC_ADDR))
73368 + {
73369 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP DA for Cisco Aironet extension, it's not Zero\n"));
73370 + return;
73371 + }
73372 +
73373 + if (! MAC_ADDR_EQUAL(pRMReq->IAPP.SA, ZERO_MAC_ADDR))
73374 + {
73375 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP SA for Cisco Aironet extension, it's not Zero\n"));
73376 + return;
73377 + }
73378 +
73379 + // 6. Reinit all report related fields
73380 + NdisZeroMemory(pAd->StaCfg.FrameReportBuf, 2048);
73381 + NdisZeroMemory(pAd->StaCfg.BssReportOffset, sizeof(USHORT) * MAX_LEN_OF_BSS_TABLE);
73382 + NdisZeroMemory(pAd->StaCfg.MeasurementRequest, sizeof(RM_REQUEST_ACTION) * 4);
73383 +
73384 + // 7. Point to the start of first element report element
73385 + pAd->StaCfg.FrameReportLen = LENGTH_802_11 + sizeof(AIRONET_IAPP_HEADER);
73386 + DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));
73387 + pAd->StaCfg.LastBssIndex = 0xff;
73388 + pAd->StaCfg.RMReqCnt = 0;
73389 + pAd->StaCfg.ParallelReq = FALSE;
73390 + pAd->StaCfg.ParallelDuration = 0;
73391 + pAd->StaCfg.ParallelChannel = 0;
73392 + pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;
73393 + pAd->StaCfg.CurrentRMReqIdx = 0;
73394 + pAd->StaCfg.CLBusyBytes = 0;
73395 + // Reset the statistics
73396 + for (i = 0; i < 8; i++)
73397 + pAd->StaCfg.RPIDensity[i] = 0;
73398 +
73399 + Index = 0;
73400 +
73401 + // 8. Save dialog token for report
73402 + pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;
73403 +
73404 + // Save Activation delay & measurement offset, Not really needed
73405 +
73406 + // 9. Point to the first request element
73407 + pData += sizeof(AIRONET_RM_REQUEST_FRAME);
73408 + // Length should exclude the CISCO Aironet SNAP header
73409 + Length -= (sizeof(AIRONET_RM_REQUEST_FRAME) - LENGTH_802_1_H);
73410 +
73411 + // 10. Start Parsing the Measurement elements.
73412 + // Be careful about multiple MR elements within one frames.
73413 + while (Length > 0)
73414 + {
73415 + pReqElem = (PRM_REQUEST_ACTION) pData;
73416 + switch (pReqElem->ReqElem.Eid)
73417 + {
73418 + case IE_MEASUREMENT_REQUEST:
73419 + // From the example, it seems we only need to support one request in one frame
73420 + // There is no multiple request in one frame.
73421 + // Besides, looks like we need to take care the measurement request only.
73422 + // The measurement request is always 4 bytes.
73423 +
73424 + // Start parsing this type of request.
73425 + // 0. Eid is IE_MEASUREMENT_REQUEST
73426 + // 1. Length didn't include Eid and Length field, it always be 8.
73427 + // 2. Measurement Token, we nned to save it for the corresponding report.
73428 + // 3. Measurement Mode, Although there are definitions, but we din't see value other than
73429 + // 0 from test specs examples.
73430 + // 4. Measurement Type, this is what we need to do.
73431 + switch (pReqElem->ReqElem.Type)
73432 + {
73433 + case MSRN_TYPE_CHANNEL_LOAD_REQ:
73434 + case MSRN_TYPE_NOISE_HIST_REQ:
73435 + case MSRN_TYPE_BEACON_REQ:
73436 + // Check the Enable non-serving channel measurement control
73437 + if (pAd->StaCfg.CCXControl.field.DCRMEnable == 0)
73438 + {
73439 + // Check channel before enqueue the action
73440 + if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)
73441 + break;
73442 + }
73443 + else
73444 + {
73445 + // If off channel measurement, check the TU duration limit
73446 + if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)
73447 + if (pReqElem->Measurement.Duration > pAd->StaCfg.CCXControl.field.TuLimit)
73448 + break;
73449 + }
73450 +
73451 + // Save requests and execute actions later
73452 + NdisMoveMemory(&pAd->StaCfg.MeasurementRequest[Index], pReqElem, sizeof(RM_REQUEST_ACTION));
73453 + Index += 1;
73454 + break;
73455 +
73456 + case MSRN_TYPE_FRAME_REQ:
73457 + // Since it's option, we will support later
73458 + // FrameRequestAction(pAd, pData);
73459 + break;
73460 +
73461 + default:
73462 + break;
73463 + }
73464 +
73465 + // Point to next Measurement request
73466 + pData += sizeof(RM_REQUEST_ACTION);
73467 + Length -= sizeof(RM_REQUEST_ACTION);
73468 + break;
73469 +
73470 + // We accept request only, all others are dropped
73471 + case IE_MEASUREMENT_REPORT:
73472 + case IE_AP_TX_POWER:
73473 + case IE_MEASUREMENT_CAPABILITY:
73474 + default:
73475 + return;
73476 + }
73477 + }
73478 +
73479 + // 11. Update some flags and index
73480 + pAd->StaCfg.RMReqCnt = Index;
73481 +
73482 + if (Index)
73483 + {
73484 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);
73485 + RT28XX_MLME_HANDLER(pAd);
73486 + }
73487 +
73488 + DBGPRINT(RT_DEBUG_TRACE, ("<----- AironetMsgAction\n"));
73489 +}
73490 +
73491 +/*
73492 + ========================================================================
73493 +
73494 + Routine Description:
73495 +
73496 + Arguments:
73497 +
73498 + Return Value:
73499 + None
73500 +
73501 + Note:
73502 +
73503 + ========================================================================
73504 +*/
73505 +VOID AironetRequestAction(
73506 + IN PRTMP_ADAPTER pAd,
73507 + IN MLME_QUEUE_ELEM *Elem)
73508 +{
73509 + PRM_REQUEST_ACTION pReq;
73510 +
73511 + // 1. Point to next request element
73512 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
73513 +
73514 + // 2. Parse measurement type and call appropriate functions
73515 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
73516 + // Channel Load measurement request
73517 + ChannelLoadRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73518 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
73519 + // Noise Histogram measurement request
73520 + NoiseHistRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73521 + else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)
73522 + // Beacon measurement request
73523 + BeaconRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73524 + else
73525 + // Unknown. Do nothing and return, this should never happen
73526 + return;
73527 +
73528 + // 3. Peek into the next request, if it's parallel, we will update the scan time to the largest one
73529 + if ((pAd->StaCfg.CurrentRMReqIdx + 1) < pAd->StaCfg.RMReqCnt)
73530 + {
73531 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx + 1];
73532 + // Check for parallel bit
73533 + if ((pReq->ReqElem.Mode & 0x01) && (pReq->Measurement.Channel == pAd->StaCfg.CCXScanChannel))
73534 + {
73535 + // Update parallel mode request information
73536 + pAd->StaCfg.ParallelReq = TRUE;
73537 + pAd->StaCfg.CCXScanTime = ((pReq->Measurement.Duration > pAd->StaCfg.CCXScanTime) ?
73538 + (pReq->Measurement.Duration) : (pAd->StaCfg.CCXScanTime));
73539 + }
73540 + }
73541 +
73542 + // 4. Call RT28XX_MLME_HANDLER to execute the request mlme commands, Scan request is the only one used
73543 + RT28XX_MLME_HANDLER(pAd);
73544 +
73545 +}
73546 +
73547 +
73548 +/*
73549 + ========================================================================
73550 +
73551 + Routine Description:
73552 + Prepare channel load report action, special scan operation added
73553 + to support
73554 +
73555 + Arguments:
73556 + pAd Pointer to our adapter
73557 + pData Start from element ID
73558 +
73559 + Return Value:
73560 + None
73561 +
73562 + Note:
73563 +
73564 + ========================================================================
73565 +*/
73566 +VOID ChannelLoadRequestAction(
73567 + IN PRTMP_ADAPTER pAd,
73568 + IN UCHAR Index)
73569 +{
73570 + PRM_REQUEST_ACTION pReq;
73571 + MLME_SCAN_REQ_STRUCT ScanReq;
73572 + UCHAR ZeroSsid[32];
73573 + NDIS_STATUS NStatus;
73574 + PUCHAR pOutBuffer = NULL;
73575 + PHEADER_802_11 pNullFrame;
73576 +
73577 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction ----->\n"));
73578 +
73579 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
73580 + NdisZeroMemory(ZeroSsid, 32);
73581 +
73582 + // Prepare for special scan request
73583 + // The scan definition is different with our Active, Passive scan definition.
73584 + // For CCX2, Active means send out probe request with broadcast BSSID.
73585 + // Passive means no probe request sent, only listen to the beacons.
73586 + // The channel scanned is fixed as specified, no need to scan all channels.
73587 + // The scan wait time is specified in the request too.
73588 + // Passive scan Mode
73589 +
73590 + // Control state machine is not idle, reject the request
73591 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
73592 + return;
73593 +
73594 + // Fill out stuff for scan request
73595 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_CHANNEL_LOAD);
73596 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
73597 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
73598 +
73599 + // Reset some internal control flags to make sure this scan works.
73600 + BssTableInit(&pAd->StaCfg.CCXBssTab);
73601 + pAd->StaCfg.ScanCnt = 0;
73602 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
73603 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
73604 +
73605 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));
73606 +
73607 + // If it's non serving channel scan, send out a null frame with PSM bit on.
73608 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
73609 + {
73610 + // Use MLME enqueue method
73611 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
73612 + if (NStatus != NDIS_STATUS_SUCCESS)
73613 + return;
73614 +
73615 + pNullFrame = (PHEADER_802_11) pOutBuffer;;
73616 + // Make the power save Null frame with PSM bit on
73617 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
73618 + pNullFrame->Duration = 0;
73619 + pNullFrame->FC.Type = BTYPE_DATA;
73620 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
73621 +
73622 + // Send using priority queue
73623 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
73624 + MlmeFreeMemory(pAd, pOutBuffer);
73625 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
73626 + RTMPusecDelay(5000);
73627 + }
73628 +
73629 + pAd->StaCfg.CCXReqType = MSRN_TYPE_CHANNEL_LOAD_REQ;
73630 + pAd->StaCfg.CLBusyBytes = 0;
73631 + // Enable Rx with promiscuous reception
73632 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);
73633 +
73634 + // Set channel load measurement flag
73635 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
73636 +
73637 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
73638 +
73639 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction <-----\n"));
73640 +}
73641 +
73642 +/*
73643 + ========================================================================
73644 +
73645 + Routine Description:
73646 + Prepare noise histogram report action, special scan operation added
73647 + to support
73648 +
73649 + Arguments:
73650 + pAd Pointer to our adapter
73651 + pData Start from element ID
73652 +
73653 + Return Value:
73654 + None
73655 +
73656 + Note:
73657 +
73658 + ========================================================================
73659 +*/
73660 +VOID NoiseHistRequestAction(
73661 + IN PRTMP_ADAPTER pAd,
73662 + IN UCHAR Index)
73663 +{
73664 + PRM_REQUEST_ACTION pReq;
73665 + MLME_SCAN_REQ_STRUCT ScanReq;
73666 + UCHAR ZeroSsid[32], i;
73667 + NDIS_STATUS NStatus;
73668 + PUCHAR pOutBuffer = NULL;
73669 + PHEADER_802_11 pNullFrame;
73670 +
73671 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction ----->\n"));
73672 +
73673 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
73674 + NdisZeroMemory(ZeroSsid, 32);
73675 +
73676 + // Prepare for special scan request
73677 + // The scan definition is different with our Active, Passive scan definition.
73678 + // For CCX2, Active means send out probe request with broadcast BSSID.
73679 + // Passive means no probe request sent, only listen to the beacons.
73680 + // The channel scanned is fixed as specified, no need to scan all channels.
73681 + // The scan wait time is specified in the request too.
73682 + // Passive scan Mode
73683 +
73684 + // Control state machine is not idle, reject the request
73685 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
73686 + return;
73687 +
73688 + // Fill out stuff for scan request
73689 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_NOISE);
73690 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
73691 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
73692 +
73693 + // Reset some internal control flags to make sure this scan works.
73694 + BssTableInit(&pAd->StaCfg.CCXBssTab);
73695 + pAd->StaCfg.ScanCnt = 0;
73696 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
73697 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
73698 + pAd->StaCfg.CCXReqType = MSRN_TYPE_NOISE_HIST_REQ;
73699 +
73700 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));
73701 +
73702 + // If it's non serving channel scan, send out a null frame with PSM bit on.
73703 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
73704 + {
73705 + // Use MLME enqueue method
73706 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
73707 + if (NStatus != NDIS_STATUS_SUCCESS)
73708 + return;
73709 +
73710 + pNullFrame = (PHEADER_802_11) pOutBuffer;
73711 + // Make the power save Null frame with PSM bit on
73712 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
73713 + pNullFrame->Duration = 0;
73714 + pNullFrame->FC.Type = BTYPE_DATA;
73715 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
73716 +
73717 + // Send using priority queue
73718 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
73719 + MlmeFreeMemory(pAd, pOutBuffer);
73720 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
73721 + RTMPusecDelay(5000);
73722 + }
73723 +
73724 + // Reset the statistics
73725 + for (i = 0; i < 8; i++)
73726 + pAd->StaCfg.RPIDensity[i] = 0;
73727 +
73728 + // Enable Rx with promiscuous reception
73729 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);
73730 +
73731 + // Set channel load measurement flag
73732 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
73733 +
73734 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
73735 +
73736 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction <-----\n"));
73737 +}
73738 +
73739 +/*
73740 + ========================================================================
73741 +
73742 + Routine Description:
73743 + Prepare Beacon report action, special scan operation added
73744 + to support
73745 +
73746 + Arguments:
73747 + pAd Pointer to our adapter
73748 + pData Start from element ID
73749 +
73750 + Return Value:
73751 + None
73752 +
73753 + Note:
73754 +
73755 + ========================================================================
73756 +*/
73757 +VOID BeaconRequestAction(
73758 + IN PRTMP_ADAPTER pAd,
73759 + IN UCHAR Index)
73760 +{
73761 + PRM_REQUEST_ACTION pReq;
73762 + NDIS_STATUS NStatus;
73763 + PUCHAR pOutBuffer = NULL;
73764 + PHEADER_802_11 pNullFrame;
73765 + MLME_SCAN_REQ_STRUCT ScanReq;
73766 + UCHAR ZeroSsid[32];
73767 +
73768 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction ----->\n"));
73769 +
73770 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
73771 + NdisZeroMemory(ZeroSsid, 32);
73772 +
73773 + // Prepare for special scan request
73774 + // The scan definition is different with our Active, Passive scan definition.
73775 + // For CCX2, Active means send out probe request with broadcast BSSID.
73776 + // Passive means no probe request sent, only listen to the beacons.
73777 + // The channel scanned is fixed as specified, no need to scan all channels.
73778 + // The scan wait time is specified in the request too.
73779 + if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_PASSIVE)
73780 + {
73781 + // Passive scan Mode
73782 + DBGPRINT(RT_DEBUG_TRACE, ("Passive Scan Mode!\n"));
73783 +
73784 + // Control state machine is not idle, reject the request
73785 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
73786 + return;
73787 +
73788 + // Fill out stuff for scan request
73789 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_PASSIVE);
73790 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
73791 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
73792 +
73793 + // Reset some internal control flags to make sure this scan works.
73794 + BssTableInit(&pAd->StaCfg.CCXBssTab);
73795 + pAd->StaCfg.ScanCnt = 0;
73796 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
73797 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
73798 + pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;
73799 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));
73800 +
73801 + // If it's non serving channel scan, send out a null frame with PSM bit on.
73802 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
73803 + {
73804 + // Use MLME enqueue method
73805 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
73806 + if (NStatus != NDIS_STATUS_SUCCESS)
73807 + return;
73808 +
73809 + pNullFrame = (PHEADER_802_11) pOutBuffer;
73810 + // Make the power save Null frame with PSM bit on
73811 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
73812 + pNullFrame->Duration = 0;
73813 + pNullFrame->FC.Type = BTYPE_DATA;
73814 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
73815 +
73816 + // Send using priority queue
73817 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
73818 + MlmeFreeMemory(pAd, pOutBuffer);
73819 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
73820 + RTMPusecDelay(5000);
73821 + }
73822 +
73823 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
73824 + }
73825 + else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_ACTIVE)
73826 + {
73827 + // Active scan Mode
73828 + DBGPRINT(RT_DEBUG_TRACE, ("Active Scan Mode!\n"));
73829 +
73830 + // Control state machine is not idle, reject the request
73831 + if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
73832 + return;
73833 +
73834 + // Fill out stuff for scan request
73835 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_ACTIVE);
73836 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
73837 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
73838 +
73839 + // Reset some internal control flags to make sure this scan works.
73840 + BssTableInit(&pAd->StaCfg.CCXBssTab);
73841 + pAd->StaCfg.ScanCnt = 0;
73842 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
73843 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
73844 + pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;
73845 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));
73846 +
73847 + // If it's non serving channel scan, send out a null frame with PSM bit on.
73848 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
73849 + {
73850 + // Use MLME enqueue method
73851 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
73852 + if (NStatus != NDIS_STATUS_SUCCESS)
73853 + return;
73854 +
73855 + pNullFrame = (PHEADER_802_11) pOutBuffer;
73856 + // Make the power save Null frame with PSM bit on
73857 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
73858 + pNullFrame->Duration = 0;
73859 + pNullFrame->FC.Type = BTYPE_DATA;
73860 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
73861 +
73862 + // Send using priority queue
73863 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
73864 + MlmeFreeMemory(pAd, pOutBuffer);
73865 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
73866 + RTMPusecDelay(5000);
73867 + }
73868 +
73869 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
73870 + }
73871 + else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_BEACON_TABLE)
73872 + {
73873 + // Beacon report Mode, report all the APS in current bss table
73874 + DBGPRINT(RT_DEBUG_TRACE, ("Beacon Report Mode!\n"));
73875 +
73876 + // Copy current BSS table to CCX table, we can omit this step later on.
73877 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab, &pAd->ScanTab, sizeof(BSS_TABLE));
73878 +
73879 + // Create beacon report from Bss table
73880 + AironetCreateBeaconReportFromBssTable(pAd);
73881 +
73882 + // Set state to scanning
73883 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
73884 +
73885 + // Enqueue report request
73886 + // Cisco scan request is finished, prepare beacon report
73887 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
73888 + }
73889 + else
73890 + {
73891 + // Wrong scan Mode
73892 + DBGPRINT(RT_DEBUG_TRACE, ("Wrong Scan Mode!\n"));
73893 + }
73894 +
73895 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction <-----\n"));
73896 +}
73897 +
73898 +/*
73899 + ========================================================================
73900 +
73901 + Routine Description:
73902 +
73903 + Arguments:
73904 +
73905 + Return Value:
73906 + None
73907 +
73908 + Note:
73909 +
73910 + ========================================================================
73911 +*/
73912 +VOID AironetReportAction(
73913 + IN PRTMP_ADAPTER pAd,
73914 + IN MLME_QUEUE_ELEM *Elem)
73915 +{
73916 + PRM_REQUEST_ACTION pReq;
73917 + ULONG Now32;
73918 +
73919 + NdisGetSystemUpTime(&Now32);
73920 + pAd->StaCfg.LastBeaconRxTime = Now32;
73921 +
73922 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
73923 +
73924 + DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction ----->\n"));
73925 +
73926 + // 1. Parse measurement type and call appropriate functions
73927 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
73928 + // Channel Load measurement request
73929 + ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73930 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
73931 + // Noise Histogram measurement request
73932 + NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73933 + else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)
73934 + // Beacon measurement request
73935 + BeaconReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73936 + else
73937 + // Unknown. Do nothing and return
73938 + ;
73939 +
73940 + // 2. Point to the correct index of action element, start from 0
73941 + pAd->StaCfg.CurrentRMReqIdx++;
73942 +
73943 + // 3. Check for parallel actions
73944 + if (pAd->StaCfg.ParallelReq == TRUE)
73945 + {
73946 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
73947 +
73948 + // Process next action right away
73949 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
73950 + // Channel Load measurement request
73951 + ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73952 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
73953 + // Noise Histogram measurement request
73954 + NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
73955 +
73956 + pAd->StaCfg.ParallelReq = FALSE;
73957 + pAd->StaCfg.CurrentRMReqIdx++;
73958 + }
73959 +
73960 + if (pAd->StaCfg.CurrentRMReqIdx >= pAd->StaCfg.RMReqCnt)
73961 + {
73962 + // 4. There is no more unprocessed measurement request, go for transmit this report
73963 + AironetFinalReportAction(pAd);
73964 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
73965 + }
73966 + else
73967 + {
73968 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
73969 +
73970 + if (pReq->Measurement.Channel != pAd->CommonCfg.Channel)
73971 + {
73972 + RTMPusecDelay(100000);
73973 + }
73974 +
73975 + // 5. There are more requests to be measure
73976 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);
73977 + RT28XX_MLME_HANDLER(pAd);
73978 + }
73979 +
73980 + DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction <-----\n"));
73981 +}
73982 +
73983 +/*
73984 + ========================================================================
73985 +
73986 + Routine Description:
73987 +
73988 + Arguments:
73989 +
73990 + Return Value:
73991 + None
73992 +
73993 + Note:
73994 +
73995 + ========================================================================
73996 +*/
73997 +VOID AironetFinalReportAction(
73998 + IN PRTMP_ADAPTER pAd)
73999 +{
74000 + PUCHAR pDest;
74001 + PAIRONET_IAPP_HEADER pIAPP;
74002 + PHEADER_802_11 pHeader;
74003 + UCHAR AckRate = RATE_2;
74004 + USHORT AckDuration = 0;
74005 + NDIS_STATUS NStatus;
74006 + PUCHAR pOutBuffer = NULL;
74007 + ULONG FrameLen = 0;
74008 +
74009 + DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction ----->\n"));
74010 +
74011 + // 0. Set up the frame pointer, Frame was inited at the end of message action
74012 + pDest = &pAd->StaCfg.FrameReportBuf[LENGTH_802_11];
74013 +
74014 + // 1. Update report IAPP fields
74015 + pIAPP = (PAIRONET_IAPP_HEADER) pDest;
74016 +
74017 + // 2. Copy Cisco SNAP header
74018 + NdisMoveMemory(pIAPP->CiscoSnapHeader, SNAP_AIRONET, LENGTH_802_1_H);
74019 +
74020 + // 3. network order for this 16bit length
74021 + pIAPP->Length = cpu2be16(pAd->StaCfg.FrameReportLen - LENGTH_802_11 - LENGTH_802_1_H);
74022 +
74023 + // 3.1 sanity check the report length, ignore it if there is nothing to report
74024 + if (be2cpu16(pIAPP->Length) <= 18)
74025 + return;
74026 +
74027 + // 4. Type must be 0x32
74028 + pIAPP->Type = AIRONET_IAPP_TYPE;
74029 +
74030 + // 5. SubType for report must be 0x81
74031 + pIAPP->SubType = AIRONET_IAPP_SUBTYPE_REPORT;
74032 +
74033 + // 6. DA is not used and must be zero, although the whole frame was cleared at the start of function
74034 + // We will do it again here. We can use BSSID instead
74035 + COPY_MAC_ADDR(pIAPP->DA, pAd->CommonCfg.Bssid);
74036 +
74037 + // 7. SA is the client reporting which must be our MAC
74038 + COPY_MAC_ADDR(pIAPP->SA, pAd->CurrentAddress);
74039 +
74040 + // 8. Copy the saved dialog token
74041 + pIAPP->Token = pAd->StaCfg.IAPPToken;
74042 +
74043 + // 9. Make the Report frame 802.11 header
74044 + // Reuse function in wpa.c
74045 + pHeader = (PHEADER_802_11) pAd->StaCfg.FrameReportBuf;
74046 + pAd->Sequence ++;
74047 + WpaMacHeaderInit(pAd, pHeader, 0, pAd->CommonCfg.Bssid);
74048 +
74049 + // ACK size is 14 include CRC, and its rate is based on real time information
74050 + AckRate = pAd->CommonCfg.ExpectedACKRate[pAd->CommonCfg.MlmeRate];
74051 + AckDuration = RTMPCalcDuration(pAd, AckRate, 14);
74052 + pHeader->Duration = pAd->CommonCfg.Dsifs + AckDuration;
74053 +
74054 + // Use MLME enqueue method
74055 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
74056 + if (NStatus != NDIS_STATUS_SUCCESS)
74057 + return;
74058 +
74059 + // 10. Prepare report frame with dynamic outbuffer. Just simply copy everything.
74060 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
74061 + pAd->StaCfg.FrameReportLen, pAd->StaCfg.FrameReportBuf,
74062 + END_OF_ARGS);
74063 +
74064 + // 11. Send using priority queue
74065 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
74066 + MlmeFreeMemory(pAd, pOutBuffer);
74067 +
74068 + pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED;
74069 +
74070 + DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction <-----\n"));
74071 +}
74072 +
74073 +/*
74074 + ========================================================================
74075 +
74076 + Routine Description:
74077 +
74078 + Arguments:
74079 +
74080 + Return Value:
74081 + None
74082 +
74083 + Note:
74084 +
74085 + ========================================================================
74086 +*/
74087 +VOID ChannelLoadReportAction(
74088 + IN PRTMP_ADAPTER pAd,
74089 + IN UCHAR Index)
74090 +{
74091 + PMEASUREMENT_REPORT_ELEMENT pReport;
74092 + PCHANNEL_LOAD_REPORT pLoad;
74093 + PUCHAR pDest;
74094 + UCHAR CCABusyFraction;
74095 +
74096 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction ----->\n"));
74097 +
74098 + // Disable Rx with promiscuous reception, make it back to normal
74099 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
74100 +
74101 + // 0. Setup pointer for processing beacon & probe response
74102 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
74103 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
74104 +
74105 + // 1. Fill Measurement report element field.
74106 + pReport->Eid = IE_MEASUREMENT_REPORT;
74107 + // Fixed Length at 9, not include Eid and length fields
74108 + pReport->Length = 9;
74109 + pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;
74110 + pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;
74111 + pReport->Type = MSRN_TYPE_CHANNEL_LOAD_REQ;
74112 +
74113 + // 2. Fill channel report measurement data
74114 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74115 + pLoad = (PCHANNEL_LOAD_REPORT) pDest;
74116 + pLoad->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;
74117 + pLoad->Spare = 0;
74118 + pLoad->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;
74119 +
74120 + // 3. Calculate the CCA Busy Fraction
74121 + // (Bytes + ACK size) * 8 / Tx speed * 255 / 1000 / measurement duration, use 24 us Tx speed
74122 + // = (Bytes + ACK) / 12 / duration
74123 + // 9 is the good value for pAd->StaCfg.CLFactor
74124 + // CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 9 / pLoad->Duration);
74125 + CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / pAd->StaCfg.CLFactor / pLoad->Duration);
74126 + if (CCABusyFraction < 10)
74127 + CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 3 / pLoad->Duration) + 1;
74128 +
74129 + pLoad->CCABusy = CCABusyFraction;
74130 + DBGPRINT(RT_DEBUG_TRACE, ("CLBusyByte %ld, Duration %d, Result, %d\n", pAd->StaCfg.CLBusyBytes, pLoad->Duration, CCABusyFraction));
74131 +
74132 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));
74133 + pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(CHANNEL_LOAD_REPORT));
74134 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));
74135 +
74136 + // 4. Clear channel load measurement flag
74137 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
74138 +
74139 + // 5. reset to idle state
74140 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
74141 +
74142 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction <-----\n"));
74143 +}
74144 +
74145 +/*
74146 + ========================================================================
74147 +
74148 + Routine Description:
74149 +
74150 + Arguments:
74151 +
74152 + Return Value:
74153 + None
74154 +
74155 + Note:
74156 +
74157 + ========================================================================
74158 +*/
74159 +VOID NoiseHistReportAction(
74160 + IN PRTMP_ADAPTER pAd,
74161 + IN UCHAR Index)
74162 +{
74163 + PMEASUREMENT_REPORT_ELEMENT pReport;
74164 + PNOISE_HIST_REPORT pNoise;
74165 + PUCHAR pDest;
74166 + UCHAR i,NoiseCnt;
74167 + USHORT TotalRPICnt, TotalRPISum;
74168 +
74169 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction ----->\n"));
74170 +
74171 + // 0. Disable Rx with promiscuous reception, make it back to normal
74172 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
74173 + // 1. Setup pointer for processing beacon & probe response
74174 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
74175 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
74176 +
74177 + // 2. Fill Measurement report element field.
74178 + pReport->Eid = IE_MEASUREMENT_REPORT;
74179 + // Fixed Length at 16, not include Eid and length fields
74180 + pReport->Length = 16;
74181 + pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;
74182 + pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;
74183 + pReport->Type = MSRN_TYPE_NOISE_HIST_REQ;
74184 +
74185 + // 3. Fill noise histogram report measurement data
74186 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74187 + pNoise = (PNOISE_HIST_REPORT) pDest;
74188 + pNoise->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;
74189 + pNoise->Spare = 0;
74190 + pNoise->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;
74191 + // 4. Fill Noise histogram, the total RPI counts should be 0.4 * TU
74192 + // We estimate 4000 normal packets received durning 10 seconds test.
74193 + // Adjust it if required.
74194 + // 3 is a good value for pAd->StaCfg.NHFactor
74195 + // TotalRPICnt = pNoise->Duration * 3 / 10;
74196 + TotalRPICnt = pNoise->Duration * pAd->StaCfg.NHFactor / 10;
74197 + TotalRPISum = 0;
74198 +
74199 + for (i = 0; i < 8; i++)
74200 + {
74201 + TotalRPISum += pAd->StaCfg.RPIDensity[i];
74202 + DBGPRINT(RT_DEBUG_TRACE, ("RPI %d Conuts %d\n", i, pAd->StaCfg.RPIDensity[i]));
74203 + }
74204 +
74205 + // Double check if the counter is larger than our expectation.
74206 + // We will replace it with the total number plus a fraction.
74207 + if (TotalRPISum > TotalRPICnt)
74208 + TotalRPICnt = TotalRPISum + pNoise->Duration / 20;
74209 +
74210 + DBGPRINT(RT_DEBUG_TRACE, ("Total RPI Conuts %d\n", TotalRPICnt));
74211 +
74212 + // 5. Initialize noise count for the total summation of 0xff
74213 + NoiseCnt = 0;
74214 + for (i = 1; i < 8; i++)
74215 + {
74216 + pNoise->Density[i] = (UCHAR) (pAd->StaCfg.RPIDensity[i] * 255 / TotalRPICnt);
74217 + if ((pNoise->Density[i] == 0) && (pAd->StaCfg.RPIDensity[i] != 0))
74218 + pNoise->Density[i]++;
74219 + NoiseCnt += pNoise->Density[i];
74220 + DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[%d] = 0x%02x\n", i, pNoise->Density[i]));
74221 + }
74222 +
74223 + // 6. RPI[0] represents the rest of counts
74224 + pNoise->Density[0] = 0xff - NoiseCnt;
74225 + DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[0] = 0x%02x\n", pNoise->Density[0]));
74226 +
74227 + pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(NOISE_HIST_REPORT));
74228 +
74229 + // 7. Clear channel load measurement flag
74230 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
74231 +
74232 + // 8. reset to idle state
74233 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
74234 +
74235 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction <-----\n"));
74236 +}
74237 +
74238 +/*
74239 + ========================================================================
74240 +
74241 + Routine Description:
74242 + Prepare Beacon report action,
74243 +
74244 + Arguments:
74245 + pAd Pointer to our adapter
74246 +
74247 + Return Value:
74248 + None
74249 +
74250 + Note:
74251 +
74252 + ========================================================================
74253 +*/
74254 +VOID BeaconReportAction(
74255 + IN PRTMP_ADAPTER pAd,
74256 + IN UCHAR Index)
74257 +{
74258 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction ----->\n"));
74259 +
74260 + // Looks like we don't have anything thing need to do here.
74261 + // All measurement report already finished in AddBeaconReport
74262 + // The length is in the FrameReportLen
74263 +
74264 + // reset Beacon index for next beacon request
74265 + pAd->StaCfg.LastBssIndex = 0xff;
74266 +
74267 + // reset to idle state
74268 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
74269 +
74270 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction <-----\n"));
74271 +}
74272 +
74273 +/*
74274 + ========================================================================
74275 +
74276 + Routine Description:
74277 +
74278 + Arguments:
74279 + Index Current BSSID in CCXBsstab entry index
74280 +
74281 + Return Value:
74282 +
74283 + Note:
74284 +
74285 + ========================================================================
74286 +*/
74287 +VOID AironetAddBeaconReport(
74288 + IN PRTMP_ADAPTER pAd,
74289 + IN ULONG Index,
74290 + IN PMLME_QUEUE_ELEM pElem)
74291 +{
74292 + PVOID pMsg;
74293 + PUCHAR pSrc, pDest;
74294 + UCHAR ReqIdx;
74295 + ULONG MsgLen;
74296 + USHORT Length;
74297 + PFRAME_802_11 pFrame;
74298 + PMEASUREMENT_REPORT_ELEMENT pReport;
74299 + PEID_STRUCT pEid;
74300 + PBEACON_REPORT pBeaconReport;
74301 + PBSS_ENTRY pBss;
74302 +
74303 + // 0. Setup pointer for processing beacon & probe response
74304 + pMsg = pElem->Msg;
74305 + MsgLen = pElem->MsgLen;
74306 + pFrame = (PFRAME_802_11) pMsg;
74307 + pSrc = pFrame->Octet; // Start from AP TSF
74308 + pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];
74309 + ReqIdx = pAd->StaCfg.CurrentRMReqIdx;
74310 +
74311 + // 1 Check the Index, if we already create this entry, only update the average RSSI
74312 + if ((Index <= pAd->StaCfg.LastBssIndex) && (pAd->StaCfg.LastBssIndex != 0xff))
74313 + {
74314 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.BssReportOffset[Index]];
74315 + // Point to bss report information
74316 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74317 + pBeaconReport = (PBEACON_REPORT) pDest;
74318 +
74319 + // Update Rx power, in dBm
74320 + // Get the original RSSI readback from BBP
74321 + pBeaconReport->RxPower += pAd->BbpRssiToDbmDelta;
74322 + // Average the Rssi reading
74323 + pBeaconReport->RxPower = (pBeaconReport->RxPower + pBss->Rssi) / 2;
74324 + // Get to dBm format
74325 + pBeaconReport->RxPower -= pAd->BbpRssiToDbmDelta;
74326 +
74327 + DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",
74328 + pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],
74329 + pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
74330 + DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld] Rssi %d, Avg Rssi %d\n", Index, (pBss->Rssi - pAd->BbpRssiToDbmDelta), pBeaconReport->RxPower - 256));
74331 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.BssReportOffset[Index]));
74332 +
74333 + // Update other information here
74334 +
74335 + // Done
74336 + return;
74337 + }
74338 +
74339 + // 2. Update reported Index
74340 + pAd->StaCfg.LastBssIndex = Index;
74341 +
74342 + // 3. Setup the buffer address for copying this BSSID into reporting frame
74343 + // The offset should start after 802.11 header and report frame header.
74344 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
74345 +
74346 + // 4. Save the start offset of each Bss in report frame
74347 + pAd->StaCfg.BssReportOffset[Index] = pAd->StaCfg.FrameReportLen;
74348 +
74349 + // 5. Fill Measurement report fields
74350 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
74351 + pReport->Eid = IE_MEASUREMENT_REPORT;
74352 + pReport->Length = 0;
74353 + pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;
74354 + pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;
74355 + pReport->Type = MSRN_TYPE_BEACON_REQ;
74356 + Length = sizeof(MEASUREMENT_REPORT_ELEMENT);
74357 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74358 +
74359 + // 6. Start thebeacon report format
74360 + pBeaconReport = (PBEACON_REPORT) pDest;
74361 + pDest += sizeof(BEACON_REPORT);
74362 + Length += sizeof(BEACON_REPORT);
74363 +
74364 + // 7. Copy Channel number
74365 + pBeaconReport->Channel = pBss->Channel;
74366 + pBeaconReport->Spare = 0;
74367 + pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;
74368 + pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);
74369 + // 8. Rx power, in dBm
74370 + pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;
74371 +
74372 + DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",
74373 + pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],
74374 + pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
74375 + DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld], Rssi %d\n", Index, pBeaconReport->RxPower - 256));
74376 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.FrameReportLen));
74377 +
74378 + pBeaconReport->BeaconInterval = pBss->BeaconPeriod;
74379 + COPY_MAC_ADDR(pBeaconReport->BSSID, pFrame->Hdr.Addr3);
74380 + NdisMoveMemory(pBeaconReport->ParentTSF, pSrc, 4);
74381 + NdisMoveMemory(pBeaconReport->TargetTSF, &pElem->TimeStamp.u.LowPart, 4);
74382 + NdisMoveMemory(&pBeaconReport->TargetTSF[4], &pElem->TimeStamp.u.HighPart, 4);
74383 +
74384 + // 9. Skip the beacon frame and offset to start of capabilityinfo since we already processed capabilityinfo
74385 + pSrc += (TIMESTAMP_LEN + 2);
74386 + pBeaconReport->CapabilityInfo = *(USHORT *)pSrc;
74387 +
74388 + // 10. Point to start of element ID
74389 + pSrc += 2;
74390 + pEid = (PEID_STRUCT) pSrc;
74391 +
74392 + // 11. Start process all variable Eid oayload and add the appropriate to the frame report
74393 + while (((PUCHAR) pEid + pEid->Len + 1) < ((PUCHAR) pFrame + MsgLen))
74394 + {
74395 + // Only limited EID are required to report for CCX 2. It includes SSID, Supported rate,
74396 + // FH paramenter set, DS parameter set, CF parameter set, IBSS parameter set,
74397 + // TIM (report first 4 bytes only, radio measurement capability
74398 + switch (pEid->Eid)
74399 + {
74400 + case IE_SSID:
74401 + case IE_SUPP_RATES:
74402 + case IE_FH_PARM:
74403 + case IE_DS_PARM:
74404 + case IE_CF_PARM:
74405 + case IE_IBSS_PARM:
74406 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
74407 + pDest += (pEid->Len + 2);
74408 + Length += (pEid->Len + 2);
74409 + break;
74410 +
74411 + case IE_MEASUREMENT_CAPABILITY:
74412 + // Since this IE is duplicated with WPA security IE, we has to do sanity check before
74413 + // recognize it.
74414 + // 1. It also has fixed 6 bytes IE length.
74415 + if (pEid->Len != 6)
74416 + break;
74417 + // 2. Check the Cisco Aironet OUI
74418 + if (NdisEqualMemory(CISCO_OUI, (pSrc + 2), 3))
74419 + {
74420 + // Matched, this is what we want
74421 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
74422 + pDest += (pEid->Len + 2);
74423 + Length += (pEid->Len + 2);
74424 + }
74425 + break;
74426 +
74427 + case IE_TIM:
74428 + if (pEid->Len > 4)
74429 + {
74430 + // May truncate and report the first 4 bytes only, with the eid & len, total should be 6
74431 + NdisMoveMemory(pDest, pEid, 6);
74432 + pDest += 6;
74433 + Length += 6;
74434 + }
74435 + else
74436 + {
74437 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
74438 + pDest += (pEid->Len + 2);
74439 + Length += (pEid->Len + 2);
74440 + }
74441 + break;
74442 +
74443 + default:
74444 + break;
74445 + }
74446 + // 12. Move to next element ID
74447 + pSrc += (2 + pEid->Len);
74448 + pEid = (PEID_STRUCT) pSrc;
74449 + }
74450 +
74451 + // 13. Update the length in the header, not include EID and length
74452 + pReport->Length = Length - 4;
74453 +
74454 + // 14. Update the frame report buffer data length
74455 + pAd->StaCfg.FrameReportLen += Length;
74456 + DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));
74457 +}
74458 +
74459 +/*
74460 + ========================================================================
74461 +
74462 + Routine Description:
74463 +
74464 + Arguments:
74465 + Index Current BSSID in CCXBsstab entry index
74466 +
74467 + Return Value:
74468 +
74469 + Note:
74470 +
74471 + ========================================================================
74472 +*/
74473 +VOID AironetCreateBeaconReportFromBssTable(
74474 + IN PRTMP_ADAPTER pAd)
74475 +{
74476 + PMEASUREMENT_REPORT_ELEMENT pReport;
74477 + PBEACON_REPORT pBeaconReport;
74478 + UCHAR Index, ReqIdx;
74479 + USHORT Length;
74480 + PUCHAR pDest;
74481 + PBSS_ENTRY pBss;
74482 +
74483 + // 0. setup base pointer
74484 + ReqIdx = pAd->StaCfg.CurrentRMReqIdx;
74485 +
74486 + for (Index = 0; Index < pAd->StaCfg.CCXBssTab.BssNr; Index++)
74487 + {
74488 + // 1. Setup the buffer address for copying this BSSID into reporting frame
74489 + // The offset should start after 802.11 header and report frame header.
74490 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
74491 + pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];
74492 + Length = 0;
74493 +
74494 + // 2. Fill Measurement report fields
74495 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
74496 + pReport->Eid = IE_MEASUREMENT_REPORT;
74497 + pReport->Length = 0;
74498 + pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;
74499 + pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;
74500 + pReport->Type = MSRN_TYPE_BEACON_REQ;
74501 + Length = sizeof(MEASUREMENT_REPORT_ELEMENT);
74502 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74503 +
74504 + // 3. Start the beacon report format
74505 + pBeaconReport = (PBEACON_REPORT) pDest;
74506 + pDest += sizeof(BEACON_REPORT);
74507 + Length += sizeof(BEACON_REPORT);
74508 +
74509 + // 4. Copy Channel number
74510 + pBeaconReport->Channel = pBss->Channel;
74511 + pBeaconReport->Spare = 0;
74512 + pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;
74513 + pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);
74514 + pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;
74515 + pBeaconReport->BeaconInterval = pBss->BeaconPeriod;
74516 + pBeaconReport->CapabilityInfo = pBss->CapabilityInfo;
74517 + COPY_MAC_ADDR(pBeaconReport->BSSID, pBss->Bssid);
74518 + NdisMoveMemory(pBeaconReport->ParentTSF, pBss->PTSF, 4);
74519 + NdisMoveMemory(pBeaconReport->TargetTSF, pBss->TTSF, 8);
74520 +
74521 + // 5. Create SSID
74522 + *pDest++ = 0x00;
74523 + *pDest++ = pBss->SsidLen;
74524 + NdisMoveMemory(pDest, pBss->Ssid, pBss->SsidLen);
74525 + pDest += pBss->SsidLen;
74526 + Length += (2 + pBss->SsidLen);
74527 +
74528 + // 6. Create SupportRates
74529 + *pDest++ = 0x01;
74530 + *pDest++ = pBss->SupRateLen;
74531 + NdisMoveMemory(pDest, pBss->SupRate, pBss->SupRateLen);
74532 + pDest += pBss->SupRateLen;
74533 + Length += (2 + pBss->SupRateLen);
74534 +
74535 + // 7. DS Parameter
74536 + *pDest++ = 0x03;
74537 + *pDest++ = 1;
74538 + *pDest++ = pBss->Channel;
74539 + Length += 3;
74540 +
74541 + // 8. IBSS parameter if presents
74542 + if (pBss->BssType == BSS_ADHOC)
74543 + {
74544 + *pDest++ = 0x06;
74545 + *pDest++ = 2;
74546 + *(PUSHORT) pDest = pBss->AtimWin;
74547 + pDest += 2;
74548 + Length += 4;
74549 + }
74550 +
74551 + // 9. Update length field, not include EID and length
74552 + pReport->Length = Length - 4;
74553 +
74554 + // 10. Update total frame size
74555 + pAd->StaCfg.FrameReportLen += Length;
74556 + }
74557 +}
74558 --- /dev/null
74559 +++ b/drivers/staging/rt2870/sta/assoc.c
74560 @@ -0,0 +1,2039 @@
74561 +/*
74562 + *************************************************************************
74563 + * Ralink Tech Inc.
74564 + * 5F., No.36, Taiyuan St., Jhubei City,
74565 + * Hsinchu County 302,
74566 + * Taiwan, R.O.C.
74567 + *
74568 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
74569 + *
74570 + * This program is free software; you can redistribute it and/or modify *
74571 + * it under the terms of the GNU General Public License as published by *
74572 + * the Free Software Foundation; either version 2 of the License, or *
74573 + * (at your option) any later version. *
74574 + * *
74575 + * This program is distributed in the hope that it will be useful, *
74576 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
74577 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
74578 + * GNU General Public License for more details. *
74579 + * *
74580 + * You should have received a copy of the GNU General Public License *
74581 + * along with this program; if not, write to the *
74582 + * Free Software Foundation, Inc., *
74583 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
74584 + * *
74585 + *************************************************************************
74586 +
74587 + Module Name:
74588 + assoc.c
74589 +
74590 + Abstract:
74591 +
74592 + Revision History:
74593 + Who When What
74594 + -------- ---------- ----------------------------------------------
74595 + John 2004-9-3 porting from RT2500
74596 +*/
74597 +#include "../rt_config.h"
74598 +
74599 +UCHAR CipherWpaTemplate[] = {
74600 + 0xdd, // WPA IE
74601 + 0x16, // Length
74602 + 0x00, 0x50, 0xf2, 0x01, // oui
74603 + 0x01, 0x00, // Version
74604 + 0x00, 0x50, 0xf2, 0x02, // Multicast
74605 + 0x01, 0x00, // Number of unicast
74606 + 0x00, 0x50, 0xf2, 0x02, // unicast
74607 + 0x01, 0x00, // number of authentication method
74608 + 0x00, 0x50, 0xf2, 0x01 // authentication
74609 + };
74610 +
74611 +UCHAR CipherWpa2Template[] = {
74612 + 0x30, // RSN IE
74613 + 0x14, // Length
74614 + 0x01, 0x00, // Version
74615 + 0x00, 0x0f, 0xac, 0x02, // group cipher, TKIP
74616 + 0x01, 0x00, // number of pairwise
74617 + 0x00, 0x0f, 0xac, 0x02, // unicast
74618 + 0x01, 0x00, // number of authentication method
74619 + 0x00, 0x0f, 0xac, 0x02, // authentication
74620 + 0x00, 0x00, // RSN capability
74621 + };
74622 +
74623 +UCHAR Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02};
74624 +
74625 +/*
74626 + ==========================================================================
74627 + Description:
74628 + association state machine init, including state transition and timer init
74629 + Parameters:
74630 + S - pointer to the association state machine
74631 +
74632 + IRQL = PASSIVE_LEVEL
74633 +
74634 + ==========================================================================
74635 + */
74636 +VOID AssocStateMachineInit(
74637 + IN PRTMP_ADAPTER pAd,
74638 + IN STATE_MACHINE *S,
74639 + OUT STATE_MACHINE_FUNC Trans[])
74640 +{
74641 + StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, (STATE_MACHINE_FUNC)Drop, ASSOC_IDLE, ASSOC_MACHINE_BASE);
74642 +
74643 + // first column
74644 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)MlmeAssocReqAction);
74645 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)MlmeReassocReqAction);
74646 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)MlmeDisassocReqAction);
74647 + StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
74648 +
74649 + // second column
74650 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
74651 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
74652 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
74653 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
74654 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);
74655 + //
74656 + // Patch 3Com AP MOde:3CRWE454G72
74657 + // We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp.
74658 + //
74659 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);
74660 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, (STATE_MACHINE_FUNC)AssocTimeoutAction);
74661 +
74662 + // third column
74663 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
74664 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
74665 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
74666 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
74667 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);
74668 + //
74669 + // Patch, AP doesn't send Reassociate Rsp frame to Station.
74670 + //
74671 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);
74672 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, (STATE_MACHINE_FUNC)ReassocTimeoutAction);
74673 +
74674 + // fourth column
74675 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
74676 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
74677 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
74678 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
74679 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, (STATE_MACHINE_FUNC)DisassocTimeoutAction);
74680 +
74681 + // initialize the timer
74682 + RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer, GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);
74683 + RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer, GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);
74684 + RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer, GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);
74685 +}
74686 +
74687 +/*
74688 + ==========================================================================
74689 + Description:
74690 + Association timeout procedure. After association timeout, this function
74691 + will be called and it will put a message into the MLME queue
74692 + Parameters:
74693 + Standard timer parameters
74694 +
74695 + IRQL = DISPATCH_LEVEL
74696 +
74697 + ==========================================================================
74698 + */
74699 +VOID AssocTimeout(IN PVOID SystemSpecific1,
74700 + IN PVOID FunctionContext,
74701 + IN PVOID SystemSpecific2,
74702 + IN PVOID SystemSpecific3)
74703 +{
74704 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
74705 +
74706 + // Do nothing if the driver is starting halt state.
74707 + // This might happen when timer already been fired before cancel timer with mlmehalt
74708 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
74709 + return;
74710 +
74711 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);
74712 + RT28XX_MLME_HANDLER(pAd);
74713 +}
74714 +
74715 +/*
74716 + ==========================================================================
74717 + Description:
74718 + Reassociation timeout procedure. After reassociation timeout, this
74719 + function will be called and put a message into the MLME queue
74720 + Parameters:
74721 + Standard timer parameters
74722 +
74723 + IRQL = DISPATCH_LEVEL
74724 +
74725 + ==========================================================================
74726 + */
74727 +VOID ReassocTimeout(IN PVOID SystemSpecific1,
74728 + IN PVOID FunctionContext,
74729 + IN PVOID SystemSpecific2,
74730 + IN PVOID SystemSpecific3)
74731 +{
74732 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
74733 +
74734 + // Do nothing if the driver is starting halt state.
74735 + // This might happen when timer already been fired before cancel timer with mlmehalt
74736 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
74737 + return;
74738 +
74739 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);
74740 + RT28XX_MLME_HANDLER(pAd);
74741 +}
74742 +
74743 +/*
74744 + ==========================================================================
74745 + Description:
74746 + Disassociation timeout procedure. After disassociation timeout, this
74747 + function will be called and put a message into the MLME queue
74748 + Parameters:
74749 + Standard timer parameters
74750 +
74751 + IRQL = DISPATCH_LEVEL
74752 +
74753 + ==========================================================================
74754 + */
74755 +VOID DisassocTimeout(IN PVOID SystemSpecific1,
74756 + IN PVOID FunctionContext,
74757 + IN PVOID SystemSpecific2,
74758 + IN PVOID SystemSpecific3)
74759 +{
74760 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
74761 +
74762 + // Do nothing if the driver is starting halt state.
74763 + // This might happen when timer already been fired before cancel timer with mlmehalt
74764 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
74765 + return;
74766 +
74767 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);
74768 + RT28XX_MLME_HANDLER(pAd);
74769 +}
74770 +
74771 +/*
74772 + ==========================================================================
74773 + Description:
74774 + mlme assoc req handling procedure
74775 + Parameters:
74776 + Adapter - Adapter pointer
74777 + Elem - MLME Queue Element
74778 + Pre:
74779 + the station has been authenticated and the following information is stored in the config
74780 + -# SSID
74781 + -# supported rates and their length
74782 + -# listen interval (Adapter->StaCfg.default_listen_count)
74783 + -# Transmit power (Adapter->StaCfg.tx_power)
74784 + Post :
74785 + -# An association request frame is generated and sent to the air
74786 + -# Association timer starts
74787 + -# Association state -> ASSOC_WAIT_RSP
74788 +
74789 + IRQL = DISPATCH_LEVEL
74790 +
74791 + ==========================================================================
74792 + */
74793 +VOID MlmeAssocReqAction(
74794 + IN PRTMP_ADAPTER pAd,
74795 + IN MLME_QUEUE_ELEM *Elem)
74796 +{
74797 + UCHAR ApAddr[6];
74798 + HEADER_802_11 AssocHdr;
74799 + UCHAR Ccx2Len = 5;
74800 + UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
74801 + USHORT ListenIntv;
74802 + ULONG Timeout;
74803 + USHORT CapabilityInfo;
74804 + BOOLEAN TimerCancelled;
74805 + PUCHAR pOutBuffer = NULL;
74806 + NDIS_STATUS NStatus;
74807 + ULONG FrameLen = 0;
74808 + ULONG tmp;
74809 + USHORT VarIesOffset;
74810 + UCHAR CkipFlag;
74811 + UCHAR CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH];
74812 + UCHAR AironetCkipIe = IE_AIRONET_CKIP;
74813 + UCHAR AironetCkipLen = CKIP_NEGOTIATION_LENGTH;
74814 + UCHAR AironetIPAddressIE = IE_AIRONET_IPADDRESS;
74815 + UCHAR AironetIPAddressLen = AIRONET_IPADDRESS_LENGTH;
74816 + UCHAR AironetIPAddressBuffer[AIRONET_IPADDRESS_LENGTH] = {0x00, 0x40, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
74817 + USHORT Status;
74818 +
74819 + // Block all authentication request durning WPA block period
74820 + if (pAd->StaCfg.bBlockAssoc == TRUE)
74821 + {
74822 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block Assoc request durning WPA block period!\n"));
74823 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
74824 + Status = MLME_STATE_MACHINE_REJECT;
74825 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
74826 + }
74827 + // check sanity first
74828 + else if (MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
74829 + {
74830 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
74831 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
74832 +
74833 + // Get an unused nonpaged memory
74834 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
74835 + if (NStatus != NDIS_STATUS_SUCCESS)
74836 + {
74837 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));
74838 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
74839 + Status = MLME_FAIL_NO_RESOURCE;
74840 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
74841 + return;
74842 + }
74843 +
74844 + // Add by James 03/06/27
74845 + pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
74846 + // Association don't need to report MAC address
74847 + pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =
74848 + NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_LISTENINTERVAL;
74849 + pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities = CapabilityInfo;
74850 + pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval = ListenIntv;
74851 + // Only reassociate need this
74852 + //COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr);
74853 + pAd->StaCfg.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
74854 +
74855 + NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);
74856 + // First add SSID
74857 + VarIesOffset = 0;
74858 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe, 1);
74859 + VarIesOffset += 1;
74860 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SsidLen, 1);
74861 + VarIesOffset += 1;
74862 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
74863 + VarIesOffset += pAd->MlmeAux.SsidLen;
74864 +
74865 + // Second add Supported rates
74866 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe, 1);
74867 + VarIesOffset += 1;
74868 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SupRateLen, 1);
74869 + VarIesOffset += 1;
74870 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);
74871 + VarIesOffset += pAd->MlmeAux.SupRateLen;
74872 + // End Add by James
74873 +
74874 + if ((pAd->CommonCfg.Channel > 14) &&
74875 + (pAd->CommonCfg.bIEEE80211H == TRUE))
74876 + CapabilityInfo |= 0x0100;
74877 +
74878 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));
74879 + MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, ApAddr);
74880 +
74881 + // Build basic frame first
74882 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
74883 + sizeof(HEADER_802_11), &AssocHdr,
74884 + 2, &CapabilityInfo,
74885 + 2, &ListenIntv,
74886 + 1, &SsidIe,
74887 + 1, &pAd->MlmeAux.SsidLen,
74888 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
74889 + 1, &SupRateIe,
74890 + 1, &pAd->MlmeAux.SupRateLen,
74891 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
74892 + END_OF_ARGS);
74893 +
74894 + if (pAd->MlmeAux.ExtRateLen != 0)
74895 + {
74896 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
74897 + 1, &ExtRateIe,
74898 + 1, &pAd->MlmeAux.ExtRateLen,
74899 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
74900 + END_OF_ARGS);
74901 + FrameLen += tmp;
74902 + }
74903 +
74904 +#ifdef DOT11_N_SUPPORT
74905 + // HT
74906 + if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
74907 + {
74908 + ULONG TmpLen;
74909 + UCHAR HtLen;
74910 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
74911 + if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)
74912 + {
74913 + HtLen = SIZE_HT_CAP_IE + 4;
74914 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
74915 + 1, &WpaIe,
74916 + 1, &HtLen,
74917 + 4, &BROADCOM[0],
74918 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
74919 + END_OF_ARGS);
74920 + }
74921 + else
74922 + {
74923 +#ifdef RT_BIG_ENDIAN
74924 + HT_CAPABILITY_IE HtCapabilityTmp;
74925 +#endif
74926 +
74927 +#ifndef RT_BIG_ENDIAN
74928 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
74929 + 1, &HtCapIe,
74930 + 1, &pAd->MlmeAux.HtCapabilityLen,
74931 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
74932 + END_OF_ARGS);
74933 +#else
74934 + NdisZeroMemory(&HtCapabilityTmp, sizeof(HT_CAPABILITY_IE));
74935 + NdisMoveMemory(&HtCapabilityTmp, &pAd->MlmeAux.HtCapability, pAd->MlmeAux.HtCapabilityLen);
74936 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
74937 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
74938 +
74939 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
74940 + 1, &HtCapIe,
74941 + 1, &pAd->MlmeAux.HtCapabilityLen,
74942 + pAd->MlmeAux.HtCapabilityLen,&HtCapabilityTmp,
74943 + END_OF_ARGS);
74944 +#endif
74945 + }
74946 + FrameLen += TmpLen;
74947 + }
74948 +#endif // DOT11_N_SUPPORT //
74949 +
74950 + // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION
74951 + // Case I: (Aggregation + Piggy-Back)
74952 + // 1. user enable aggregation, AND
74953 + // 2. Mac support piggy-back
74954 + // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON
74955 + // Case II: (Aggregation)
74956 + // 1. user enable aggregation, AND
74957 + // 2. AP annouces it's AGGREGATION-capable in BEACON
74958 + if (pAd->CommonCfg.bAggregationCapable)
74959 + {
74960 + if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))
74961 + {
74962 + ULONG TmpLen;
74963 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};
74964 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
74965 + 9, RalinkIe,
74966 + END_OF_ARGS);
74967 + FrameLen += TmpLen;
74968 + }
74969 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
74970 + {
74971 + ULONG TmpLen;
74972 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
74973 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
74974 + 9, RalinkIe,
74975 + END_OF_ARGS);
74976 + FrameLen += TmpLen;
74977 + }
74978 + }
74979 + else
74980 + {
74981 + ULONG TmpLen;
74982 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06, 0x00, 0x00, 0x00};
74983 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
74984 + 9, RalinkIe,
74985 + END_OF_ARGS);
74986 + FrameLen += TmpLen;
74987 + }
74988 +
74989 + if (pAd->MlmeAux.APEdcaParm.bValid)
74990 + {
74991 + if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)
74992 + {
74993 + QBSS_STA_INFO_PARM QosInfo;
74994 +
74995 + NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));
74996 + QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
74997 + QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
74998 + QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
74999 + QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
75000 + QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;
75001 + WmeIe[8] |= *(PUCHAR)&QosInfo;
75002 + }
75003 + else
75004 + {
75005 + // The Parameter Set Count is set to ¡§0¡¨ in the association request frames
75006 + // WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f);
75007 + }
75008 +
75009 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75010 + 9, &WmeIe[0],
75011 + END_OF_ARGS);
75012 + FrameLen += tmp;
75013 + }
75014 +
75015 + //
75016 + // Let WPA(#221) Element ID on the end of this association frame.
75017 + // Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp.
75018 + // For example: Put Vendor Specific IE on the front of WPA IE.
75019 + // This happens on AP (Model No:Linksys WRK54G)
75020 + //
75021 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
75022 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
75023 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
75024 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
75025 + )
75026 + )
75027 + {
75028 + UCHAR RSNIe = IE_WPA;
75029 +
75030 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
75031 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
75032 + {
75033 + RSNIe = IE_WPA2;
75034 + }
75035 +
75036 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
75037 +
75038 + // Check for WPA PMK cache list
75039 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
75040 + {
75041 + INT idx;
75042 + BOOLEAN FoundPMK = FALSE;
75043 + // Search chched PMKID, append it if existed
75044 + for (idx = 0; idx < PMKID_NO; idx++)
75045 + {
75046 + if (NdisEqualMemory(ApAddr, &pAd->StaCfg.SavedPMK[idx].BSSID, 6))
75047 + {
75048 + FoundPMK = TRUE;
75049 + break;
75050 + }
75051 + }
75052 +
75053 + if (FoundPMK)
75054 + {
75055 + // Set PMK number
75056 + *(PUSHORT) &pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len] = 1;
75057 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len + 2], &pAd->StaCfg.SavedPMK[idx].PMKID, 16);
75058 + pAd->StaCfg.RSNIE_Len += 18;
75059 + }
75060 + }
75061 +
75062 + {
75063 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75064 + 1, &RSNIe,
75065 + 1, &pAd->StaCfg.RSNIE_Len,
75066 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
75067 + END_OF_ARGS);
75068 + }
75069 +
75070 + FrameLen += tmp;
75071 +
75072 + {
75073 + // Append Variable IE
75074 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &RSNIe, 1);
75075 + VarIesOffset += 1;
75076 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->StaCfg.RSNIE_Len, 1);
75077 + VarIesOffset += 1;
75078 + }
75079 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
75080 + VarIesOffset += pAd->StaCfg.RSNIE_Len;
75081 +
75082 + // Set Variable IEs Length
75083 + pAd->StaCfg.ReqVarIELen = VarIesOffset;
75084 + }
75085 +
75086 + // We have update that at PeerBeaconAtJoinRequest()
75087 + CkipFlag = pAd->StaCfg.CkipFlag;
75088 + if (CkipFlag != 0)
75089 + {
75090 + NdisZeroMemory(CkipNegotiationBuffer, CKIP_NEGOTIATION_LENGTH);
75091 + CkipNegotiationBuffer[2] = 0x66;
75092 + // Make it try KP & MIC, since we have to follow the result from AssocRsp
75093 + CkipNegotiationBuffer[8] = 0x18;
75094 + CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH - 1] = 0x22;
75095 + CkipFlag = 0x18;
75096 +
75097 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75098 + 1, &AironetCkipIe,
75099 + 1, &AironetCkipLen,
75100 + AironetCkipLen, CkipNegotiationBuffer,
75101 + END_OF_ARGS);
75102 + FrameLen += tmp;
75103 + }
75104 +
75105 + // Add CCX v2 request if CCX2 admin state is on
75106 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
75107 + {
75108 +
75109 + //
75110 + // Add AironetIPAddressIE for Cisco CCX 2.X
75111 + // Add CCX Version
75112 + //
75113 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75114 + 1, &AironetIPAddressIE,
75115 + 1, &AironetIPAddressLen,
75116 + AironetIPAddressLen, AironetIPAddressBuffer,
75117 + 1, &Ccx2Ie,
75118 + 1, &Ccx2Len,
75119 + Ccx2Len, Ccx2IeInfo,
75120 + END_OF_ARGS);
75121 + FrameLen += tmp;
75122 +
75123 + //
75124 + // Add CipherSuite CCKM or LeapTkip if setting.
75125 + //
75126 +#ifdef LEAP_SUPPORT
75127 + if (LEAP_CCKM_ON(pAd))
75128 + {
75129 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75130 + CipherSuiteCiscoCCKMLen, CipherSuiteCiscoCCKM,
75131 + END_OF_ARGS);
75132 + FrameLen += tmp;
75133 +
75134 + // Third add RSN
75135 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, CipherSuiteCiscoCCKM, CipherSuiteCiscoCCKMLen); //Save CipherSuite
75136 + VarIesOffset += CipherSuiteCiscoCCKMLen;
75137 + }
75138 + else if ((pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP) && (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled))
75139 + {
75140 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75141 + CipherSuiteCCXTkipLen, CipherSuiteCCXTkip,
75142 + END_OF_ARGS);
75143 + FrameLen += tmp;
75144 +
75145 + // Third add RSN
75146 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, CipherSuiteCCXTkip, CipherSuiteCCXTkipLen);
75147 + VarIesOffset += CipherSuiteCCXTkipLen;
75148 + }
75149 +#endif // LEAP_SUPPORT //
75150 +
75151 + // Add by James 03/06/27
75152 + // Set Variable IEs Length
75153 + pAd->StaCfg.ReqVarIELen = VarIesOffset;
75154 + pAd->StaCfg.AssocInfo.RequestIELength = VarIesOffset;
75155 +
75156 + // OffsetResponseIEs follow ReqVarIE
75157 + pAd->StaCfg.AssocInfo.OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAd->StaCfg.ReqVarIELen;
75158 + // End Add by James
75159 + }
75160 +
75161 +
75162 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
75163 + MlmeFreeMemory(pAd, pOutBuffer);
75164 +
75165 + RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout);
75166 + pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;
75167 + }
75168 + else
75169 + {
75170 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!!!!!! \n"));
75171 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75172 + Status = MLME_INVALID_FORMAT;
75173 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
75174 + }
75175 +
75176 +}
75177 +
75178 +/*
75179 + ==========================================================================
75180 + Description:
75181 + mlme reassoc req handling procedure
75182 + Parameters:
75183 + Elem -
75184 + Pre:
75185 + -# SSID (Adapter->StaCfg.ssid[])
75186 + -# BSSID (AP address, Adapter->StaCfg.bssid)
75187 + -# Supported rates (Adapter->StaCfg.supported_rates[])
75188 + -# Supported rates length (Adapter->StaCfg.supported_rates_len)
75189 + -# Tx power (Adapter->StaCfg.tx_power)
75190 +
75191 + IRQL = DISPATCH_LEVEL
75192 +
75193 + ==========================================================================
75194 + */
75195 +VOID MlmeReassocReqAction(
75196 + IN PRTMP_ADAPTER pAd,
75197 + IN MLME_QUEUE_ELEM *Elem)
75198 +{
75199 + UCHAR ApAddr[6];
75200 + HEADER_802_11 ReassocHdr;
75201 + UCHAR Ccx2Len = 5;
75202 + UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
75203 + USHORT CapabilityInfo, ListenIntv;
75204 + ULONG Timeout;
75205 + ULONG FrameLen = 0;
75206 + BOOLEAN TimerCancelled;
75207 + NDIS_STATUS NStatus;
75208 + ULONG tmp;
75209 + PUCHAR pOutBuffer = NULL;
75210 +//CCX 2.X
75211 +#ifdef LEAP_SUPPORT
75212 + UCHAR CkipFlag;
75213 + UCHAR CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH];
75214 + UCHAR AironetCkipIe = IE_AIRONET_CKIP;
75215 + UCHAR AironetCkipLen = CKIP_NEGOTIATION_LENGTH;
75216 + UCHAR AironetIPAddressIE = IE_AIRONET_IPADDRESS;
75217 + UCHAR AironetIPAddressLen = AIRONET_IPADDRESS_LENGTH;
75218 + UCHAR AironetIPAddressBuffer[AIRONET_IPADDRESS_LENGTH] = {0x00, 0x40, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
75219 + UCHAR AironetCCKMReassocIE = IE_AIRONET_CCKMREASSOC;
75220 + UCHAR AironetCCKMReassocLen = AIRONET_CCKMREASSOC_LENGTH;
75221 + UCHAR AironetCCKMReassocBuffer[AIRONET_CCKMREASSOC_LENGTH];
75222 + UCHAR AironetOUI[] = {0x00, 0x40, 0x96, 0x00};
75223 + UCHAR MICMN[16];
75224 + UCHAR CalcMicBuffer[80];
75225 + ULONG CalcMicBufferLen = 0;
75226 +#endif // LEAP_SUPPORT //
75227 + USHORT Status;
75228 +
75229 + // Block all authentication request durning WPA block period
75230 + if (pAd->StaCfg.bBlockAssoc == TRUE)
75231 + {
75232 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block ReAssoc request durning WPA block period!\n"));
75233 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75234 + Status = MLME_STATE_MACHINE_REJECT;
75235 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
75236 + }
75237 + // the parameters are the same as the association
75238 + else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
75239 + {
75240 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
75241 +
75242 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
75243 + if(NStatus != NDIS_STATUS_SUCCESS)
75244 + {
75245 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() allocate memory failed \n"));
75246 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75247 + Status = MLME_FAIL_NO_RESOURCE;
75248 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
75249 + return;
75250 + }
75251 +
75252 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
75253 +
75254 + // make frame, use bssid as the AP address??
75255 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send RE-ASSOC request...\n"));
75256 + MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0, ApAddr, ApAddr);
75257 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
75258 + sizeof(HEADER_802_11), &ReassocHdr,
75259 + 2, &CapabilityInfo,
75260 + 2, &ListenIntv,
75261 + MAC_ADDR_LEN, ApAddr,
75262 + 1, &SsidIe,
75263 + 1, &pAd->MlmeAux.SsidLen,
75264 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
75265 + 1, &SupRateIe,
75266 + 1, &pAd->MlmeAux.SupRateLen,
75267 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
75268 + END_OF_ARGS);
75269 +
75270 + if (pAd->MlmeAux.ExtRateLen != 0)
75271 + {
75272 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75273 + 1, &ExtRateIe,
75274 + 1, &pAd->MlmeAux.ExtRateLen,
75275 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
75276 + END_OF_ARGS);
75277 + FrameLen += tmp;
75278 + }
75279 +
75280 + if (pAd->MlmeAux.APEdcaParm.bValid)
75281 + {
75282 + if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)
75283 + {
75284 + QBSS_STA_INFO_PARM QosInfo;
75285 +
75286 + NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));
75287 + QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
75288 + QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
75289 + QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
75290 + QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
75291 + QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;
75292 + WmeIe[8] |= *(PUCHAR)&QosInfo;
75293 + }
75294 +
75295 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75296 + 9, &WmeIe[0],
75297 + END_OF_ARGS);
75298 + FrameLen += tmp;
75299 + }
75300 +
75301 +#ifdef DOT11_N_SUPPORT
75302 + // HT
75303 + if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
75304 + {
75305 + ULONG TmpLen;
75306 + UCHAR HtLen;
75307 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
75308 + if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)
75309 + {
75310 + HtLen = SIZE_HT_CAP_IE + 4;
75311 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
75312 + 1, &WpaIe,
75313 + 1, &HtLen,
75314 + 4, &BROADCOM[0],
75315 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
75316 + END_OF_ARGS);
75317 + }
75318 + else
75319 + {
75320 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
75321 + 1, &HtCapIe,
75322 + 1, &pAd->MlmeAux.HtCapabilityLen,
75323 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
75324 + END_OF_ARGS);
75325 + }
75326 + FrameLen += TmpLen;
75327 + }
75328 +#endif // DOT11_N_SUPPORT //
75329 +
75330 + // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION
75331 + // Case I: (Aggregation + Piggy-Back)
75332 + // 1. user enable aggregation, AND
75333 + // 2. Mac support piggy-back
75334 + // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON
75335 + // Case II: (Aggregation)
75336 + // 1. user enable aggregation, AND
75337 + // 2. AP annouces it's AGGREGATION-capable in BEACON
75338 + if (pAd->CommonCfg.bAggregationCapable)
75339 + {
75340 + if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))
75341 + {
75342 + ULONG TmpLen;
75343 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};
75344 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75345 + 9, RalinkIe,
75346 + END_OF_ARGS);
75347 + FrameLen += TmpLen;
75348 + }
75349 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
75350 + {
75351 + ULONG TmpLen;
75352 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
75353 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75354 + 9, RalinkIe,
75355 + END_OF_ARGS);
75356 + FrameLen += TmpLen;
75357 + }
75358 + }
75359 + else
75360 + {
75361 + ULONG TmpLen;
75362 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04, 0x00, 0x00, 0x00};
75363 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75364 + 9, RalinkIe,
75365 + END_OF_ARGS);
75366 + FrameLen += TmpLen;
75367 + }
75368 +#ifdef LEAP_SUPPORT
75369 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
75370 + {
75371 + CkipFlag = pAd->StaCfg.CkipFlag; // We have update that at PeerBeaconAtJoinRequest()
75372 + if (CkipFlag != 0)
75373 + {
75374 + NdisZeroMemory(CkipNegotiationBuffer, CKIP_NEGOTIATION_LENGTH);
75375 + CkipNegotiationBuffer[2] = 0x66;
75376 + // Make it try KP & MIC, since we have to follow the result from AssocRsp
75377 + CkipNegotiationBuffer[8] = 0x18;
75378 + CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH - 1] = 0x22;
75379 +
75380 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75381 + 1, &AironetCkipIe,
75382 + 1, &AironetCkipLen,
75383 + AironetCkipLen, CkipNegotiationBuffer,
75384 + END_OF_ARGS);
75385 + FrameLen += tmp;
75386 + }
75387 +
75388 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75389 + 1, &AironetIPAddressIE,
75390 + 1, &AironetIPAddressLen,
75391 + AironetIPAddressLen, AironetIPAddressBuffer,
75392 + END_OF_ARGS);
75393 + FrameLen += tmp;
75394 +
75395 + //
75396 + // The RN is incremented before each reassociation request.
75397 + //
75398 + pAd->StaCfg.CCKMRN++;
75399 + //
75400 + // Calculate MIC = hmac-md5(krk, STA-ID|BSSID|RSNIE|TSF|RN);
75401 + //
75402 + COPY_MAC_ADDR(CalcMicBuffer, pAd->CurrentAddress);
75403 + CalcMicBufferLen = MAC_ADDR_LEN;
75404 + COPY_MAC_ADDR(CalcMicBuffer + CalcMicBufferLen, pAd->MlmeAux.Bssid);
75405 + CalcMicBufferLen += MAC_ADDR_LEN;
75406 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, CipherSuiteCiscoCCKM, CipherSuiteCiscoCCKMLen);
75407 + CalcMicBufferLen += CipherSuiteCiscoCCKMLen;
75408 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, (PUCHAR) &pAd->StaCfg.CCKMBeaconAtJoinTimeStamp, sizeof(pAd->StaCfg.CCKMBeaconAtJoinTimeStamp));
75409 + CalcMicBufferLen += sizeof(pAd->StaCfg.CCKMBeaconAtJoinTimeStamp);
75410 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, (PUCHAR)&pAd->StaCfg.CCKMRN, sizeof(pAd->StaCfg.CCKMRN));
75411 + CalcMicBufferLen += sizeof(pAd->StaCfg.CCKMRN);
75412 + hmac_md5(pAd->StaCfg.KRK, LEN_EAP_MICK, CalcMicBuffer, CalcMicBufferLen, MICMN);
75413 +
75414 + //
75415 + // fill up CCKM reassociation request element
75416 + //
75417 + NdisMoveMemory(AironetCCKMReassocBuffer, AironetOUI, 4);
75418 + NdisMoveMemory(AironetCCKMReassocBuffer + 4, (PUCHAR)&pAd->StaCfg.CCKMBeaconAtJoinTimeStamp, 8);
75419 + NdisMoveMemory(AironetCCKMReassocBuffer + 12, (PUCHAR) &pAd->StaCfg.CCKMRN, 4);
75420 + NdisMoveMemory(AironetCCKMReassocBuffer +16, MICMN, 8);
75421 +
75422 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75423 + 1, &AironetCCKMReassocIE,
75424 + 1, &AironetCCKMReassocLen,
75425 + AironetCCKMReassocLen, AironetCCKMReassocBuffer,
75426 + END_OF_ARGS);
75427 + FrameLen += tmp;
75428 +
75429 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75430 + CipherSuiteCiscoCCKMLen,CipherSuiteCiscoCCKM,
75431 + END_OF_ARGS);
75432 + FrameLen += tmp;
75433 + }
75434 +#endif // LEAP_SUPPORT //
75435 +
75436 + // Add CCX v2 request if CCX2 admin state is on
75437 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
75438 + {
75439 + //
75440 + // Add CCX Version
75441 + //
75442 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75443 + 1, &Ccx2Ie,
75444 + 1, &Ccx2Len,
75445 + Ccx2Len, Ccx2IeInfo,
75446 + END_OF_ARGS);
75447 + FrameLen += tmp;
75448 + }
75449 +
75450 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
75451 + MlmeFreeMemory(pAd, pOutBuffer);
75452 +
75453 + RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */
75454 + pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;
75455 + }
75456 + else
75457 + {
75458 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!!!! \n"));
75459 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75460 + Status = MLME_INVALID_FORMAT;
75461 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
75462 + }
75463 +}
75464 +
75465 +/*
75466 + ==========================================================================
75467 + Description:
75468 + Upper layer issues disassoc request
75469 + Parameters:
75470 + Elem -
75471 +
75472 + IRQL = PASSIVE_LEVEL
75473 +
75474 + ==========================================================================
75475 + */
75476 +VOID MlmeDisassocReqAction(
75477 + IN PRTMP_ADAPTER pAd,
75478 + IN MLME_QUEUE_ELEM *Elem)
75479 +{
75480 + PMLME_DISASSOC_REQ_STRUCT pDisassocReq;
75481 + HEADER_802_11 DisassocHdr;
75482 + PHEADER_802_11 pDisassocHdr;
75483 + PUCHAR pOutBuffer = NULL;
75484 + ULONG FrameLen = 0;
75485 + NDIS_STATUS NStatus;
75486 + BOOLEAN TimerCancelled;
75487 + ULONG Timeout = 0;
75488 + USHORT Status;
75489 +
75490 +#ifdef QOS_DLS_SUPPORT
75491 + // send DLS-TEAR_DOWN message,
75492 + if (pAd->CommonCfg.bDLSCapable)
75493 + {
75494 + UCHAR i;
75495 +
75496 + // tear down local dls table entry
75497 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
75498 + {
75499 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
75500 + {
75501 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
75502 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
75503 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
75504 + }
75505 + }
75506 +
75507 + // tear down peer dls table entry
75508 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
75509 + {
75510 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
75511 + {
75512 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
75513 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
75514 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
75515 + }
75516 + }
75517 + }
75518 +#endif // QOS_DLS_SUPPORT //
75519 +
75520 + // skip sanity check
75521 + pDisassocReq = (PMLME_DISASSOC_REQ_STRUCT)(Elem->Msg);
75522 +
75523 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
75524 + if (NStatus != NDIS_STATUS_SUCCESS)
75525 + {
75526 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n"));
75527 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75528 + Status = MLME_FAIL_NO_RESOURCE;
75529 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
75530 + return;
75531 + }
75532 +
75533 +
75534 +
75535 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled);
75536 +
75537 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send DISASSOC request[BSSID::%02x:%02x:%02x:%02x:%02x:%02x (Reason=%d)\n",
75538 + pDisassocReq->Addr[0], pDisassocReq->Addr[1], pDisassocReq->Addr[2],
75539 + pDisassocReq->Addr[3], pDisassocReq->Addr[4], pDisassocReq->Addr[5], pDisassocReq->Reason));
75540 + MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); // patch peap ttls switching issue
75541 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
75542 + sizeof(HEADER_802_11),&DisassocHdr,
75543 + 2, &pDisassocReq->Reason,
75544 + END_OF_ARGS);
75545 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
75546 +
75547 + // To patch Instance and Buffalo(N) AP
75548 + // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine
75549 + // Therefore, we send both of them.
75550 + pDisassocHdr = (PHEADER_802_11)pOutBuffer;
75551 + pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
75552 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
75553 +
75554 + MlmeFreeMemory(pAd, pOutBuffer);
75555 +
75556 + pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;
75557 + COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr);
75558 +
75559 + RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */
75560 + pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;
75561 +
75562 +#ifdef WPA_SUPPLICANT_SUPPORT
75563 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
75564 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
75565 + {
75566 + union iwreq_data wrqu;
75567 + //send disassociate event to wpa_supplicant
75568 + memset(&wrqu, 0, sizeof(wrqu));
75569 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
75570 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
75571 + }
75572 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75573 +#endif // WPA_SUPPLICANT_SUPPORT //
75574 +
75575 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
75576 + {
75577 + union iwreq_data wrqu;
75578 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
75579 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
75580 + }
75581 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75582 +
75583 +}
75584 +
75585 +/*
75586 + ==========================================================================
75587 + Description:
75588 + peer sends assoc rsp back
75589 + Parameters:
75590 + Elme - MLME message containing the received frame
75591 +
75592 + IRQL = DISPATCH_LEVEL
75593 +
75594 + ==========================================================================
75595 + */
75596 +VOID PeerAssocRspAction(
75597 + IN PRTMP_ADAPTER pAd,
75598 + IN MLME_QUEUE_ELEM *Elem)
75599 +{
75600 + USHORT CapabilityInfo, Status, Aid;
75601 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
75602 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
75603 + UCHAR Addr2[MAC_ADDR_LEN];
75604 + BOOLEAN TimerCancelled;
75605 + UCHAR CkipFlag;
75606 + EDCA_PARM EdcaParm;
75607 + HT_CAPABILITY_IE HtCapability;
75608 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
75609 + UCHAR HtCapabilityLen;
75610 + UCHAR AddHtInfoLen;
75611 + UCHAR NewExtChannelOffset = 0xff;
75612 +
75613 + if (PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,
75614 + &HtCapability,&AddHtInfo, &HtCapabilityLen,&AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))
75615 + {
75616 + // The frame is for me ?
75617 + if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid))
75618 + {
75619 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n", Status));
75620 +#ifdef DOT11_N_SUPPORT
75621 + 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));
75622 +#endif // DOT11_N_SUPPORT //
75623 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
75624 + if(Status == MLME_SUCCESS)
75625 + {
75626 + UCHAR MaxSupportedRateIn500Kbps = 0;
75627 + UCHAR idx;
75628 +
75629 + // supported rates array may not be sorted. sort it and find the maximum rate
75630 + for (idx=0; idx<SupRateLen; idx++)
75631 + {
75632 + if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))
75633 + MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;
75634 + }
75635 +
75636 + for (idx=0; idx<ExtRateLen; idx++)
75637 + {
75638 + if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))
75639 + MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;
75640 + }
75641 + // go to procedure listed on page 376
75642 + AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,
75643 + &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);
75644 +
75645 + StaAddMacTableEntry(pAd, &pAd->MacTab.Content[BSSID_WCID], MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo);
75646 +
75647 + pAd->StaCfg.CkipFlag = CkipFlag;
75648 + if (CkipFlag & 0x18)
75649 + {
75650 + NdisZeroMemory(pAd->StaCfg.TxSEQ, 4);
75651 + NdisZeroMemory(pAd->StaCfg.RxSEQ, 4);
75652 + NdisZeroMemory(pAd->StaCfg.CKIPMIC, 4);
75653 + pAd->StaCfg.GIV[0] = RandomByte(pAd);
75654 + pAd->StaCfg.GIV[1] = RandomByte(pAd);
75655 + pAd->StaCfg.GIV[2] = RandomByte(pAd);
75656 + pAd->StaCfg.bCkipOn = TRUE;
75657 + DBGPRINT(RT_DEBUG_TRACE, ("<CCX> pAd->StaCfg.CkipFlag = 0x%02x\n", pAd->StaCfg.CkipFlag));
75658 + }
75659 + }
75660 + else
75661 + {
75662 + // Faile on Association, we need to check the status code
75663 + // Is that a Rogue AP?
75664 +#ifdef LEAP_SUPPORT
75665 + if ((pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP) && (Status == MLME_ALG_NOT_SUPPORT))
75666 + { //Possibly Rogue AP
75667 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, pAd->MlmeAux.Bssid, LEAP_REASON_INVALID_AUTH);
75668 + }
75669 +#endif // LEAP_SUPPORT //
75670 + }
75671 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75672 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
75673 + }
75674 + }
75675 + else
75676 + {
75677 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerAssocRspAction() sanity check fail\n"));
75678 + }
75679 +}
75680 +
75681 +/*
75682 + ==========================================================================
75683 + Description:
75684 + peer sends reassoc rsp
75685 + Parametrs:
75686 + Elem - MLME message cntaining the received frame
75687 +
75688 + IRQL = DISPATCH_LEVEL
75689 +
75690 + ==========================================================================
75691 + */
75692 +VOID PeerReassocRspAction(
75693 + IN PRTMP_ADAPTER pAd,
75694 + IN MLME_QUEUE_ELEM *Elem)
75695 +{
75696 + USHORT CapabilityInfo;
75697 + USHORT Status;
75698 + USHORT Aid;
75699 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
75700 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
75701 + UCHAR Addr2[MAC_ADDR_LEN];
75702 + UCHAR CkipFlag;
75703 + BOOLEAN TimerCancelled;
75704 + EDCA_PARM EdcaParm;
75705 + HT_CAPABILITY_IE HtCapability;
75706 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
75707 + UCHAR HtCapabilityLen;
75708 + UCHAR AddHtInfoLen;
75709 + UCHAR NewExtChannelOffset = 0xff;
75710 +
75711 + if(PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,
75712 + &HtCapability, &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))
75713 + {
75714 + if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) // The frame is for me ?
75715 + {
75716 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - receive REASSOC_RSP to me (status=%d)\n", Status));
75717 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
75718 +
75719 + if(Status == MLME_SUCCESS)
75720 + {
75721 + // go to procedure listed on page 376
75722 + AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,
75723 + &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);
75724 +
75725 +#ifdef WPA_SUPPLICANT_SUPPORT
75726 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
75727 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
75728 + {
75729 + union iwreq_data wrqu;
75730 +
75731 + SendAssocIEsToWpaSupplicant(pAd);
75732 + memset(&wrqu, 0, sizeof(wrqu));
75733 + wrqu.data.flags = RT_ASSOC_EVENT_FLAG;
75734 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
75735 + }
75736 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75737 +#endif // WPA_SUPPLICANT_SUPPORT //
75738 +
75739 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
75740 + {
75741 + union iwreq_data wrqu;
75742 + wext_notify_event_assoc(pAd);
75743 +
75744 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
75745 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
75746 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
75747 +
75748 + }
75749 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75750 +
75751 + }
75752 +
75753 + //
75754 + // Cisco Leap CCKM supported Re-association.
75755 + //
75756 +#ifdef LEAP_SUPPORT
75757 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
75758 + {
75759 + if (CCKMAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen) == TRUE)
75760 + {
75761 + pAd->StaCfg.CkipFlag = CkipFlag;
75762 + if (CkipFlag & 0x18)
75763 + {
75764 + NdisZeroMemory(pAd->StaCfg.TxSEQ, 4);
75765 + NdisZeroMemory(pAd->StaCfg.RxSEQ, 4);
75766 + NdisZeroMemory(pAd->StaCfg.CKIPMIC, 4);
75767 + pAd->StaCfg.GIV[0] = RandomByte(pAd);
75768 + pAd->StaCfg.GIV[1] = RandomByte(pAd);
75769 + pAd->StaCfg.GIV[2] = RandomByte(pAd);
75770 + pAd->StaCfg.bCkipOn = TRUE;
75771 + DBGPRINT(RT_DEBUG_TRACE, ("<CCX> pAd->StaCfg.CkipFlag = 0x%02x\n", pAd->StaCfg.CkipFlag));
75772 + }
75773 +
75774 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75775 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
75776 + }
75777 + else
75778 + {
75779 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - CCKMAssocRspSanity() sanity check fail\n"));
75780 + }
75781 + }
75782 + else
75783 +#endif // LEAP_SUPPORT //
75784 + {
75785 + // CkipFlag is no use for reassociate
75786 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75787 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
75788 + }
75789 + }
75790 + }
75791 + else
75792 + {
75793 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerReassocRspAction() sanity check fail\n"));
75794 + }
75795 +
75796 +}
75797 +
75798 +/*
75799 + ==========================================================================
75800 + Description:
75801 + procedures on IEEE 802.11/1999 p.376
75802 + Parametrs:
75803 +
75804 + IRQL = DISPATCH_LEVEL
75805 +
75806 + ==========================================================================
75807 + */
75808 +VOID AssocPostProc(
75809 + IN PRTMP_ADAPTER pAd,
75810 + IN PUCHAR pAddr2,
75811 + IN USHORT CapabilityInfo,
75812 + IN USHORT Aid,
75813 + IN UCHAR SupRate[],
75814 + IN UCHAR SupRateLen,
75815 + IN UCHAR ExtRate[],
75816 + IN UCHAR ExtRateLen,
75817 + IN PEDCA_PARM pEdcaParm,
75818 + IN HT_CAPABILITY_IE *pHtCapability,
75819 + IN UCHAR HtCapabilityLen,
75820 + IN ADD_HT_INFO_IE *pAddHtInfo) // AP might use this additional ht info IE
75821 +{
75822 + ULONG Idx;
75823 +
75824 + pAd->MlmeAux.BssType = BSS_INFRA;
75825 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2);
75826 + pAd->MlmeAux.Aid = Aid;
75827 + pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
75828 +#ifdef DOT11_N_SUPPORT
75829 + // Some HT AP might lost WMM IE. We add WMM ourselves. beacuase HT requires QoS on.
75830 + if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE))
75831 + {
75832 + pEdcaParm->bValid = TRUE;
75833 + pEdcaParm->Aifsn[0] = 3;
75834 + pEdcaParm->Aifsn[1] = 7;
75835 + pEdcaParm->Aifsn[2] = 2;
75836 + pEdcaParm->Aifsn[3] = 2;
75837 +
75838 + pEdcaParm->Cwmin[0] = 4;
75839 + pEdcaParm->Cwmin[1] = 4;
75840 + pEdcaParm->Cwmin[2] = 3;
75841 + pEdcaParm->Cwmin[3] = 2;
75842 +
75843 + pEdcaParm->Cwmax[0] = 10;
75844 + pEdcaParm->Cwmax[1] = 10;
75845 + pEdcaParm->Cwmax[2] = 4;
75846 + pEdcaParm->Cwmax[3] = 3;
75847 +
75848 + pEdcaParm->Txop[0] = 0;
75849 + pEdcaParm->Txop[1] = 0;
75850 + pEdcaParm->Txop[2] = 96;
75851 + pEdcaParm->Txop[3] = 48;
75852 +
75853 + }
75854 +#endif // DOT11_N_SUPPORT //
75855 +
75856 + NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM));
75857 +
75858 + // filter out un-supported rates
75859 + pAd->MlmeAux.SupRateLen = SupRateLen;
75860 + NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
75861 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
75862 +
75863 + // filter out un-supported rates
75864 + pAd->MlmeAux.ExtRateLen = ExtRateLen;
75865 + NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
75866 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
75867 +
75868 +#ifdef DOT11_N_SUPPORT
75869 + if (HtCapabilityLen > 0)
75870 + {
75871 + RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo);
75872 + }
75873 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n", pAd->MacTab.Content[BSSID_WCID].AMsduSize, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
75874 +
75875 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n",
75876 + pAd->MacTab.Content[BSSID_WCID].MmpsMode, pAd->MacTab.Content[BSSID_WCID].AMsduSize));
75877 +#endif // DOT11_N_SUPPORT //
75878 +
75879 + // Set New WPA information
75880 + Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);
75881 + if (Idx == BSS_NOT_FOUND)
75882 + {
75883 + DBGPRINT_ERR(("ASSOC - Can't find BSS after receiving Assoc response\n"));
75884 + }
75885 + else
75886 + {
75887 + // Init variable
75888 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;
75889 + NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, MAX_LEN_OF_RSNIE);
75890 +
75891 + // Store appropriate RSN_IE for WPA SM negotiation later
75892 + if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0))
75893 + {
75894 + PUCHAR pVIE;
75895 + USHORT len;
75896 + PEID_STRUCT pEid;
75897 +
75898 + pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs;
75899 + len = pAd->ScanTab.BssEntry[Idx].VarIELen;
75900 +
75901 + while (len > 0)
75902 + {
75903 + pEid = (PEID_STRUCT) pVIE;
75904 + // For WPA/WPAPSK
75905 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
75906 + && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
75907 + {
75908 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));
75909 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);
75910 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n"));
75911 + }
75912 + // For WPA2/WPA2PSK
75913 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
75914 + && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
75915 + {
75916 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));
75917 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);
75918 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n"));
75919 + }
75920 +
75921 + pVIE += (pEid->Len + 2);
75922 + len -= (pEid->Len + 2);
75923 + }
75924 + }
75925 +
75926 + if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0)
75927 + {
75928 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> no RSN_IE \n"));
75929 + }
75930 + else
75931 + {
75932 + hex_dump("RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
75933 + }
75934 + }
75935 +}
75936 +
75937 +/*
75938 + ==========================================================================
75939 + Description:
75940 + left part of IEEE 802.11/1999 p.374
75941 + Parameters:
75942 + Elem - MLME message containing the received frame
75943 +
75944 + IRQL = DISPATCH_LEVEL
75945 +
75946 + ==========================================================================
75947 + */
75948 +VOID PeerDisassocAction(
75949 + IN PRTMP_ADAPTER pAd,
75950 + IN MLME_QUEUE_ELEM *Elem)
75951 +{
75952 + UCHAR Addr2[MAC_ADDR_LEN];
75953 + USHORT Reason;
75954 +
75955 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n"));
75956 + if(PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))
75957 + {
75958 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() Reason = %d\n", Reason));
75959 + if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2))
75960 + {
75961 +
75962 + if (pAd->CommonCfg.bWirelessEvent)
75963 + {
75964 + RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
75965 + }
75966 +
75967 +
75968 +#ifdef LEAP_SUPPORT
75969 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
75970 + {
75971 + // Cisco_LEAP has start a timer
75972 + // We should cancel it if using LEAP
75973 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &TimerCancelled);
75974 + //Check is it mach the LEAP Authentication failed as possible a Rogue AP
75975 + //on it's PortSecured not equal to WPA_802_1X_PORT_SECURED while process the Association.
75976 + if ((pAd->Mlme.LeapMachine.CurrState != LEAP_IDLE) && (pAd->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
75977 + {
75978 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_AUTH_TIMEOUT);
75979 + }
75980 + }
75981 +#endif // LEAP_SUPPORT //
75982 + //
75983 + // Get Current System time and Turn on AdjacentAPReport
75984 + //
75985 + NdisGetSystemUpTime(&pAd->StaCfg.CCXAdjacentAPLinkDownTime);
75986 + pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE;
75987 + LinkDown(pAd, TRUE);
75988 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75989 +
75990 +#ifdef WPA_SUPPLICANT_SUPPORT
75991 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
75992 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
75993 + {
75994 + union iwreq_data wrqu;
75995 + //send disassociate event to wpa_supplicant
75996 + memset(&wrqu, 0, sizeof(wrqu));
75997 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
75998 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
75999 + }
76000 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76001 +#endif // WPA_SUPPLICANT_SUPPORT //
76002 +
76003 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76004 + {
76005 + union iwreq_data wrqu;
76006 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
76007 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
76008 + }
76009 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76010 + }
76011 + }
76012 + else
76013 + {
76014 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() sanity check fail\n"));
76015 + }
76016 +
76017 +}
76018 +
76019 +/*
76020 + ==========================================================================
76021 + Description:
76022 + what the state machine will do after assoc timeout
76023 + Parameters:
76024 + Elme -
76025 +
76026 + IRQL = DISPATCH_LEVEL
76027 +
76028 + ==========================================================================
76029 + */
76030 +VOID AssocTimeoutAction(
76031 + IN PRTMP_ADAPTER pAd,
76032 + IN MLME_QUEUE_ELEM *Elem)
76033 +{
76034 + USHORT Status;
76035 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n"));
76036 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76037 + Status = MLME_REJ_TIMEOUT;
76038 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76039 +}
76040 +
76041 +/*
76042 + ==========================================================================
76043 + Description:
76044 + what the state machine will do after reassoc timeout
76045 +
76046 + IRQL = DISPATCH_LEVEL
76047 +
76048 + ==========================================================================
76049 + */
76050 +VOID ReassocTimeoutAction(
76051 + IN PRTMP_ADAPTER pAd,
76052 + IN MLME_QUEUE_ELEM *Elem)
76053 +{
76054 + USHORT Status;
76055 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n"));
76056 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76057 + Status = MLME_REJ_TIMEOUT;
76058 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76059 +}
76060 +
76061 +/*
76062 + ==========================================================================
76063 + Description:
76064 + what the state machine will do after disassoc timeout
76065 +
76066 + IRQL = DISPATCH_LEVEL
76067 +
76068 + ==========================================================================
76069 + */
76070 +VOID DisassocTimeoutAction(
76071 + IN PRTMP_ADAPTER pAd,
76072 + IN MLME_QUEUE_ELEM *Elem)
76073 +{
76074 + USHORT Status;
76075 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n"));
76076 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76077 + Status = MLME_SUCCESS;
76078 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
76079 +}
76080 +
76081 +VOID InvalidStateWhenAssoc(
76082 + IN PRTMP_ADAPTER pAd,
76083 + IN MLME_QUEUE_ELEM *Elem)
76084 +{
76085 + USHORT Status;
76086 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n",
76087 + pAd->Mlme.AssocMachine.CurrState));
76088 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76089 + Status = MLME_STATE_MACHINE_REJECT;
76090 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76091 +}
76092 +
76093 +VOID InvalidStateWhenReassoc(
76094 + IN PRTMP_ADAPTER pAd,
76095 + IN MLME_QUEUE_ELEM *Elem)
76096 +{
76097 + USHORT Status;
76098 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n",
76099 + pAd->Mlme.AssocMachine.CurrState));
76100 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76101 + Status = MLME_STATE_MACHINE_REJECT;
76102 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76103 +}
76104 +
76105 +VOID InvalidStateWhenDisassociate(
76106 + IN PRTMP_ADAPTER pAd,
76107 + IN MLME_QUEUE_ELEM *Elem)
76108 +{
76109 + USHORT Status;
76110 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n",
76111 + pAd->Mlme.AssocMachine.CurrState));
76112 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76113 + Status = MLME_STATE_MACHINE_REJECT;
76114 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
76115 +}
76116 +
76117 +/*
76118 + ==========================================================================
76119 + Description:
76120 + right part of IEEE 802.11/1999 page 374
76121 + Note:
76122 + This event should never cause ASSOC state machine perform state
76123 + transition, and has no relationship with CNTL machine. So we separate
76124 + this routine as a service outside of ASSOC state transition table.
76125 +
76126 + IRQL = DISPATCH_LEVEL
76127 +
76128 + ==========================================================================
76129 + */
76130 +VOID Cls3errAction(
76131 + IN PRTMP_ADAPTER pAd,
76132 + IN PUCHAR pAddr)
76133 +{
76134 + HEADER_802_11 DisassocHdr;
76135 + PHEADER_802_11 pDisassocHdr;
76136 + PUCHAR pOutBuffer = NULL;
76137 + ULONG FrameLen = 0;
76138 + NDIS_STATUS NStatus;
76139 + USHORT Reason = REASON_CLS3ERR;
76140 +
76141 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
76142 + if (NStatus != NDIS_STATUS_SUCCESS)
76143 + return;
76144 +
76145 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Class 3 Error, Send DISASSOC frame\n"));
76146 + MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); // patch peap ttls switching issue
76147 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76148 + sizeof(HEADER_802_11),&DisassocHdr,
76149 + 2, &Reason,
76150 + END_OF_ARGS);
76151 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76152 +
76153 + // To patch Instance and Buffalo(N) AP
76154 + // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine
76155 + // Therefore, we send both of them.
76156 + pDisassocHdr = (PHEADER_802_11)pOutBuffer;
76157 + pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
76158 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76159 +
76160 + MlmeFreeMemory(pAd, pOutBuffer);
76161 +
76162 + pAd->StaCfg.DisassocReason = REASON_CLS3ERR;
76163 + COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr);
76164 +}
76165 +
76166 + /*
76167 + ==========================================================================
76168 + Description:
76169 + Switch between WEP and CKIP upon new association up.
76170 + Parameters:
76171 +
76172 + IRQL = DISPATCH_LEVEL
76173 +
76174 + ==========================================================================
76175 + */
76176 +VOID SwitchBetweenWepAndCkip(
76177 + IN PRTMP_ADAPTER pAd)
76178 +{
76179 + int i;
76180 + SHAREDKEY_MODE_STRUC csr1;
76181 +
76182 + // if KP is required. change the CipherAlg in hardware shard key table from WEP
76183 + // to CKIP. else remain as WEP
76184 + if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10))
76185 + {
76186 + // modify hardware key table so that MAC use correct algorithm to decrypt RX
76187 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);
76188 + if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP64)
76189 + csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP64;
76190 + else if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP128)
76191 + csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP128;
76192 +
76193 + if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP64)
76194 + csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP64;
76195 + else if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP128)
76196 + csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP128;
76197 +
76198 + if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP64)
76199 + csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP64;
76200 + else if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP128)
76201 + csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP128;
76202 +
76203 + if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP64)
76204 + csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP64;
76205 + else if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP128)
76206 + csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP128;
76207 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);
76208 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));
76209 +
76210 + // modify software key table so that driver can specify correct algorithm in TXD upon TX
76211 + for (i=0; i<SHARE_KEY_NUM; i++)
76212 + {
76213 + if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP64)
76214 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP64;
76215 + else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP128)
76216 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP128;
76217 + }
76218 + }
76219 +
76220 + // else if KP NOT inused. change the CipherAlg in hardware shard key table from CKIP
76221 + // to WEP.
76222 + else
76223 + {
76224 + // modify hardware key table so that MAC use correct algorithm to decrypt RX
76225 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);
76226 + if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP64)
76227 + csr1.field.Bss0Key0CipherAlg = CIPHER_WEP64;
76228 + else if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP128)
76229 + csr1.field.Bss0Key0CipherAlg = CIPHER_WEP128;
76230 +
76231 + if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP64)
76232 + csr1.field.Bss0Key1CipherAlg = CIPHER_WEP64;
76233 + else if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP128)
76234 + csr1.field.Bss0Key1CipherAlg = CIPHER_WEP128;
76235 +
76236 + if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP64)
76237 + csr1.field.Bss0Key2CipherAlg = CIPHER_WEP64;
76238 + else if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP128)
76239 + csr1.field.Bss0Key2CipherAlg = CIPHER_WEP128;
76240 +
76241 + if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP64)
76242 + csr1.field.Bss0Key3CipherAlg = CIPHER_WEP64;
76243 + else if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP128)
76244 + csr1.field.Bss0Key3CipherAlg = CIPHER_WEP128;
76245 +
76246 + // modify software key table so that driver can specify correct algorithm in TXD upon TX
76247 + for (i=0; i<SHARE_KEY_NUM; i++)
76248 + {
76249 + if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP64)
76250 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP64;
76251 + else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP128)
76252 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP128;
76253 + }
76254 +
76255 + //
76256 + // On WPA-NONE, must update CipherAlg.
76257 + // Because the OID_802_11_WEP_STATUS was been set after OID_802_11_ADD_KEY
76258 + // and CipherAlg will be CIPHER_NONE by Windows ZeroConfig.
76259 + // So we need to update CipherAlg after connect.
76260 + //
76261 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
76262 + {
76263 + for (i = 0; i < SHARE_KEY_NUM; i++)
76264 + {
76265 + if (pAd->SharedKey[BSS0][i].KeyLen != 0)
76266 + {
76267 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
76268 + {
76269 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_TKIP;
76270 + }
76271 + else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
76272 + {
76273 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_AES;
76274 + }
76275 + }
76276 + else
76277 + {
76278 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
76279 + }
76280 + }
76281 +
76282 + csr1.field.Bss0Key0CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
76283 + csr1.field.Bss0Key1CipherAlg = pAd->SharedKey[BSS0][1].CipherAlg;
76284 + csr1.field.Bss0Key2CipherAlg = pAd->SharedKey[BSS0][2].CipherAlg;
76285 + csr1.field.Bss0Key3CipherAlg = pAd->SharedKey[BSS0][3].CipherAlg;
76286 + }
76287 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);
76288 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));
76289 + }
76290 +}
76291 +
76292 +#ifdef WPA_SUPPLICANT_SUPPORT
76293 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
76294 +VOID SendAssocIEsToWpaSupplicant(
76295 + IN PRTMP_ADAPTER pAd)
76296 +{
76297 + union iwreq_data wrqu;
76298 + unsigned char custom[IW_CUSTOM_MAX] = {0};
76299 +
76300 + if ((pAd->StaCfg.ReqVarIELen + 17) <= IW_CUSTOM_MAX)
76301 + {
76302 + sprintf(custom, "ASSOCINFO_ReqIEs=");
76303 + NdisMoveMemory(custom+17, pAd->StaCfg.ReqVarIEs, pAd->StaCfg.ReqVarIELen);
76304 + memset(&wrqu, 0, sizeof(wrqu));
76305 + wrqu.data.length = pAd->StaCfg.ReqVarIELen + 17;
76306 + wrqu.data.flags = RT_REQIE_EVENT_FLAG;
76307 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
76308 +
76309 + memset(&wrqu, 0, sizeof(wrqu));
76310 + wrqu.data.flags = RT_ASSOCINFO_EVENT_FLAG;
76311 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
76312 + }
76313 + else
76314 + DBGPRINT(RT_DEBUG_TRACE, ("pAd->StaCfg.ReqVarIELen + 17 > MAX_CUSTOM_LEN\n"));
76315 +
76316 + return;
76317 +}
76318 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76319 +#endif // WPA_SUPPLICANT_SUPPORT //
76320 +
76321 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76322 +int wext_notify_event_assoc(
76323 + IN RTMP_ADAPTER *pAd)
76324 +{
76325 + union iwreq_data wrqu;
76326 + char custom[IW_CUSTOM_MAX] = {0};
76327 +
76328 +#if WIRELESS_EXT > 17
76329 + if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX)
76330 + {
76331 + wrqu.data.length = pAd->StaCfg.ReqVarIELen;
76332 + memcpy(custom, pAd->StaCfg.ReqVarIEs, pAd->StaCfg.ReqVarIELen);
76333 + wireless_send_event(pAd->net_dev, IWEVASSOCREQIE, &wrqu, custom);
76334 + }
76335 + else
76336 + DBGPRINT(RT_DEBUG_TRACE, ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n"));
76337 +#else
76338 + if (((pAd->StaCfg.ReqVarIELen*2) + 17) <= IW_CUSTOM_MAX)
76339 + {
76340 + UCHAR idx;
76341 + wrqu.data.length = (pAd->StaCfg.ReqVarIELen*2) + 17;
76342 + sprintf(custom, "ASSOCINFO(ReqIEs=");
76343 + for (idx=0; idx<pAd->StaCfg.ReqVarIELen; idx++)
76344 + sprintf(custom, "%s%02x", custom, pAd->StaCfg.ReqVarIEs[idx]);
76345 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
76346 + }
76347 + else
76348 + DBGPRINT(RT_DEBUG_TRACE, ("(pAd->StaCfg.ReqVarIELen*2) + 17 > MAX_CUSTOM_LEN\n"));
76349 +#endif
76350 +
76351 + return 0;
76352 +
76353 +}
76354 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76355 +
76356 +
76357 +BOOLEAN StaAddMacTableEntry(
76358 + IN PRTMP_ADAPTER pAd,
76359 + IN PMAC_TABLE_ENTRY pEntry,
76360 + IN UCHAR MaxSupportedRateIn500Kbps,
76361 + IN HT_CAPABILITY_IE *pHtCapability,
76362 + IN UCHAR HtCapabilityLen,
76363 + IN USHORT CapabilityInfo)
76364 +{
76365 + UCHAR MaxSupportedRate = RATE_11;
76366 +
76367 + if (ADHOC_ON(pAd))
76368 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
76369 +
76370 + switch (MaxSupportedRateIn500Kbps)
76371 + {
76372 + case 108: MaxSupportedRate = RATE_54; break;
76373 + case 96: MaxSupportedRate = RATE_48; break;
76374 + case 72: MaxSupportedRate = RATE_36; break;
76375 + case 48: MaxSupportedRate = RATE_24; break;
76376 + case 36: MaxSupportedRate = RATE_18; break;
76377 + case 24: MaxSupportedRate = RATE_12; break;
76378 + case 18: MaxSupportedRate = RATE_9; break;
76379 + case 12: MaxSupportedRate = RATE_6; break;
76380 + case 22: MaxSupportedRate = RATE_11; break;
76381 + case 11: MaxSupportedRate = RATE_5_5; break;
76382 + case 4: MaxSupportedRate = RATE_2; break;
76383 + case 2: MaxSupportedRate = RATE_1; break;
76384 + default: MaxSupportedRate = RATE_11; break;
76385 + }
76386 +
76387 + if ((pAd->CommonCfg.PhyMode == PHY_11G) && (MaxSupportedRate < RATE_FIRST_OFDM_RATE))
76388 + return FALSE;
76389 +
76390 +#ifdef DOT11_N_SUPPORT
76391 + // 11n only
76392 + if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))&& (HtCapabilityLen == 0))
76393 + return FALSE;
76394 +#endif // DOT11_N_SUPPORT //
76395 +
76396 + if (!pEntry)
76397 + return FALSE;
76398 +
76399 + NdisAcquireSpinLock(&pAd->MacTabLock);
76400 + if (pEntry)
76401 + {
76402 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
76403 + if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) ||
76404 + (pAd->CommonCfg.PhyMode == PHY_11B))
76405 + {
76406 + pEntry->RateLen = 4;
76407 + if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE)
76408 + MaxSupportedRate = RATE_11;
76409 + }
76410 + else
76411 + pEntry->RateLen = 12;
76412 +
76413 + pEntry->MaxHTPhyMode.word = 0;
76414 + pEntry->MinHTPhyMode.word = 0;
76415 + pEntry->HTPhyMode.word = 0;
76416 + pEntry->MaxSupportedRate = MaxSupportedRate;
76417 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
76418 + {
76419 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
76420 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
76421 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
76422 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
76423 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
76424 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
76425 + }
76426 + else
76427 + {
76428 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
76429 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
76430 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
76431 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
76432 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
76433 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
76434 + }
76435 + pEntry->CapabilityInfo = CapabilityInfo;
76436 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE);
76437 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE);
76438 + }
76439 +
76440 +#ifdef DOT11_N_SUPPORT
76441 + // If this Entry supports 802.11n, upgrade to HT rate.
76442 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
76443 + {
76444 + UCHAR j, bitmask; //k,bitmask;
76445 + CHAR i;
76446 +
76447 + if (ADHOC_ON(pAd))
76448 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
76449 + if ((pHtCapability->HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
76450 + {
76451 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
76452 + }
76453 + else
76454 + {
76455 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
76456 + pAd->MacTab.fAnyStationNonGF = TRUE;
76457 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
76458 + }
76459 +
76460 + if ((pHtCapability->HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
76461 + {
76462 + pEntry->MaxHTPhyMode.field.BW= BW_40;
76463 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(pHtCapability->HtCapInfo.ShortGIfor40));
76464 + }
76465 + else
76466 + {
76467 + pEntry->MaxHTPhyMode.field.BW = BW_20;
76468 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(pHtCapability->HtCapInfo.ShortGIfor20));
76469 + pAd->MacTab.fAnyStation20Only = TRUE;
76470 + }
76471 +
76472 + // 3*3
76473 + if (pAd->MACVersion >= RALINK_2883_VERSION && pAd->MACVersion < RALINK_3070_VERSION)
76474 + pEntry->MaxHTPhyMode.field.TxBF = pAd->CommonCfg.RegTransmitSetting.field.TxBF;
76475 +
76476 + // find max fixed rate
76477 + for (i=23; i>=0; i--) // 3*3
76478 + {
76479 + j = i/8;
76480 + bitmask = (1<<(i-(j*8)));
76481 + if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask) && (pHtCapability->MCSSet[j] & bitmask))
76482 + {
76483 + pEntry->MaxHTPhyMode.field.MCS = i;
76484 + break;
76485 + }
76486 + if (i==0)
76487 + break;
76488 + }
76489 +
76490 +
76491 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
76492 + {
76493 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
76494 + {
76495 + // Fix MCS as HT Duplicated Mode
76496 + pEntry->MaxHTPhyMode.field.BW = 1;
76497 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
76498 + pEntry->MaxHTPhyMode.field.STBC = 0;
76499 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
76500 + pEntry->MaxHTPhyMode.field.MCS = 32;
76501 + }
76502 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
76503 + {
76504 + // STA supports fixed MCS
76505 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
76506 + }
76507 + }
76508 +
76509 + pEntry->MaxHTPhyMode.field.STBC = (pHtCapability->HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
76510 + pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity;
76511 + pEntry->MaxRAmpduFactor = pHtCapability->HtCapParm.MaxRAmpduFactor;
76512 + pEntry->MmpsMode = (UCHAR)pHtCapability->HtCapInfo.MimoPs;
76513 + pEntry->AMsduSize = (UCHAR)pHtCapability->HtCapInfo.AMsduSize;
76514 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
76515 +
76516 + if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE))
76517 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED);
76518 + if (pHtCapability->HtCapInfo.ShortGIfor20)
76519 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
76520 + if (pHtCapability->HtCapInfo.ShortGIfor40)
76521 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
76522 + if (pHtCapability->HtCapInfo.TxSTBC)
76523 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
76524 + if (pHtCapability->HtCapInfo.RxSTBC)
76525 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
76526 + if (pHtCapability->ExtHtCapInfo.PlusHTC)
76527 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
76528 + if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport)
76529 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
76530 + if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03)
76531 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
76532 + }
76533 + else
76534 + {
76535 + pAd->MacTab.fAnyStationIsLegacy = TRUE;
76536 + }
76537 +
76538 + NdisMoveMemory(&pEntry->HTCapability, pHtCapability, sizeof(HT_CAPABILITY_IE));
76539 +#endif // DOT11_N_SUPPORT //
76540 +
76541 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
76542 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
76543 +
76544 + // Set asic auto fall back
76545 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
76546 + {
76547 + PUCHAR pTable;
76548 + UCHAR TableSize = 0;
76549 +
76550 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
76551 + pEntry->bAutoTxRateSwitch = TRUE;
76552 + }
76553 + else
76554 + {
76555 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
76556 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
76557 + pEntry->bAutoTxRateSwitch = FALSE;
76558 +
76559 + // If the legacy mode is set, overwrite the transmit setting of this entry.
76560 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
76561 + }
76562 +
76563 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
76564 + pEntry->Sst = SST_ASSOC;
76565 + pEntry->AuthState = AS_AUTH_OPEN;
76566 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
76567 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
76568 +
76569 + NdisReleaseSpinLock(&pAd->MacTabLock);
76570 +
76571 +#ifdef WPA_SUPPLICANT_SUPPORT
76572 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
76573 + if (pAd->StaCfg.WpaSupplicantUP)
76574 + {
76575 + union iwreq_data wrqu;
76576 +
76577 + SendAssocIEsToWpaSupplicant(pAd);
76578 + memset(&wrqu, 0, sizeof(wrqu));
76579 + wrqu.data.flags = RT_ASSOC_EVENT_FLAG;
76580 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
76581 + }
76582 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76583 +#endif // WPA_SUPPLICANT_SUPPORT //
76584 +
76585 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76586 + {
76587 + union iwreq_data wrqu;
76588 + wext_notify_event_assoc(pAd);
76589 +
76590 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
76591 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
76592 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
76593 +
76594 + }
76595 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76596 + return TRUE;
76597 +}
76598 +
76599 +
76600 --- /dev/null
76601 +++ b/drivers/staging/rt2870/sta/auth.c
76602 @@ -0,0 +1,474 @@
76603 +/*
76604 + *************************************************************************
76605 + * Ralink Tech Inc.
76606 + * 5F., No.36, Taiyuan St., Jhubei City,
76607 + * Hsinchu County 302,
76608 + * Taiwan, R.O.C.
76609 + *
76610 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
76611 + *
76612 + * This program is free software; you can redistribute it and/or modify *
76613 + * it under the terms of the GNU General Public License as published by *
76614 + * the Free Software Foundation; either version 2 of the License, or *
76615 + * (at your option) any later version. *
76616 + * *
76617 + * This program is distributed in the hope that it will be useful, *
76618 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
76619 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
76620 + * GNU General Public License for more details. *
76621 + * *
76622 + * You should have received a copy of the GNU General Public License *
76623 + * along with this program; if not, write to the *
76624 + * Free Software Foundation, Inc., *
76625 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
76626 + * *
76627 + *************************************************************************
76628 +
76629 + Module Name:
76630 + auth.c
76631 +
76632 + Abstract:
76633 +
76634 + Revision History:
76635 + Who When What
76636 + -------- ---------- ----------------------------------------------
76637 + John 2004-9-3 porting from RT2500
76638 +*/
76639 +#include "../rt_config.h"
76640 +
76641 +/*
76642 + ==========================================================================
76643 + Description:
76644 + authenticate state machine init, including state transition and timer init
76645 + Parameters:
76646 + Sm - pointer to the auth state machine
76647 + Note:
76648 + The state machine looks like this
76649 +
76650 + AUTH_REQ_IDLE AUTH_WAIT_SEQ2 AUTH_WAIT_SEQ4
76651 + MT2_MLME_AUTH_REQ mlme_auth_req_action invalid_state_when_auth invalid_state_when_auth
76652 + MT2_PEER_AUTH_EVEN drop peer_auth_even_at_seq2_action peer_auth_even_at_seq4_action
76653 + MT2_AUTH_TIMEOUT Drop auth_timeout_action auth_timeout_action
76654 +
76655 + IRQL = PASSIVE_LEVEL
76656 +
76657 + ==========================================================================
76658 + */
76659 +
76660 +void AuthStateMachineInit(
76661 + IN PRTMP_ADAPTER pAd,
76662 + IN STATE_MACHINE *Sm,
76663 + OUT STATE_MACHINE_FUNC Trans[])
76664 +{
76665 + StateMachineInit(Sm, Trans, MAX_AUTH_STATE, MAX_AUTH_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_REQ_IDLE, AUTH_MACHINE_BASE);
76666 +
76667 + // the first column
76668 + StateMachineSetAction(Sm, AUTH_REQ_IDLE, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)MlmeAuthReqAction);
76669 +
76670 + // the second column
76671 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);
76672 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq2Action);
76673 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);
76674 +
76675 + // the third column
76676 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);
76677 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq4Action);
76678 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);
76679 +
76680 + RTMPInitTimer(pAd, &pAd->MlmeAux.AuthTimer, GET_TIMER_FUNCTION(AuthTimeout), pAd, FALSE);
76681 +}
76682 +
76683 +/*
76684 + ==========================================================================
76685 + Description:
76686 + function to be executed at timer thread when auth timer expires
76687 +
76688 + IRQL = DISPATCH_LEVEL
76689 +
76690 + ==========================================================================
76691 + */
76692 +VOID AuthTimeout(
76693 + IN PVOID SystemSpecific1,
76694 + IN PVOID FunctionContext,
76695 + IN PVOID SystemSpecific2,
76696 + IN PVOID SystemSpecific3)
76697 +{
76698 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
76699 +
76700 + DBGPRINT(RT_DEBUG_TRACE,("AUTH - AuthTimeout\n"));
76701 +
76702 + // Do nothing if the driver is starting halt state.
76703 + // This might happen when timer already been fired before cancel timer with mlmehalt
76704 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
76705 + return;
76706 +
76707 + // send a de-auth to reset AP's state machine (Patch AP-Dir635)
76708 + if (pAd->Mlme.AuthMachine.CurrState == AUTH_WAIT_SEQ2)
76709 + Cls2errAction(pAd, pAd->MlmeAux.Bssid);
76710 +
76711 +
76712 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_AUTH_TIMEOUT, 0, NULL);
76713 + RT28XX_MLME_HANDLER(pAd);
76714 +}
76715 +
76716 +
76717 +/*
76718 + ==========================================================================
76719 + Description:
76720 +
76721 + IRQL = DISPATCH_LEVEL
76722 +
76723 + ==========================================================================
76724 + */
76725 +VOID MlmeAuthReqAction(
76726 + IN PRTMP_ADAPTER pAd,
76727 + IN MLME_QUEUE_ELEM *Elem)
76728 +{
76729 + UCHAR Addr[6];
76730 + USHORT Alg, Seq, Status;
76731 + ULONG Timeout;
76732 + HEADER_802_11 AuthHdr;
76733 + BOOLEAN TimerCancelled;
76734 + NDIS_STATUS NStatus;
76735 + PUCHAR pOutBuffer = NULL;
76736 + ULONG FrameLen = 0;
76737 +
76738 + // Block all authentication request durning WPA block period
76739 + if (pAd->StaCfg.bBlockAssoc == TRUE)
76740 + {
76741 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Block Auth request durning WPA block period!\n"));
76742 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76743 + Status = MLME_STATE_MACHINE_REJECT;
76744 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76745 + }
76746 + else if(MlmeAuthReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr, &Timeout, &Alg))
76747 + {
76748 + // reset timer
76749 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
76750 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, Addr);
76751 + pAd->MlmeAux.Alg = Alg;
76752 + Seq = 1;
76753 + Status = MLME_SUCCESS;
76754 +
76755 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
76756 + if(NStatus != NDIS_STATUS_SUCCESS)
76757 + {
76758 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeAuthReqAction(Alg:%d) allocate memory failed\n", Alg));
76759 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76760 + Status = MLME_FAIL_NO_RESOURCE;
76761 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76762 + return;
76763 + }
76764 +
76765 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#1 (Alg=%d)...\n", Alg));
76766 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr, pAd->MlmeAux.Bssid);
76767 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76768 + sizeof(HEADER_802_11),&AuthHdr,
76769 + 2, &Alg,
76770 + 2, &Seq,
76771 + 2, &Status,
76772 + END_OF_ARGS);
76773 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76774 + MlmeFreeMemory(pAd, pOutBuffer);
76775 +
76776 + RTMPSetTimer(&pAd->MlmeAux.AuthTimer, Timeout);
76777 + pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ2;
76778 + }
76779 + else
76780 + {
76781 + DBGPRINT_ERR(("AUTH - MlmeAuthReqAction() sanity check failed\n"));
76782 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76783 + Status = MLME_INVALID_FORMAT;
76784 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76785 + }
76786 +}
76787 +
76788 +/*
76789 + ==========================================================================
76790 + Description:
76791 +
76792 + IRQL = DISPATCH_LEVEL
76793 +
76794 + ==========================================================================
76795 + */
76796 +VOID PeerAuthRspAtSeq2Action(
76797 + IN PRTMP_ADAPTER pAd,
76798 + IN MLME_QUEUE_ELEM *Elem)
76799 +{
76800 + UCHAR Addr2[MAC_ADDR_LEN];
76801 + USHORT Seq, Status, RemoteStatus, Alg;
76802 + UCHAR ChlgText[CIPHER_TEXT_LEN];
76803 + UCHAR CyperChlgText[CIPHER_TEXT_LEN + 8 + 8];
76804 + UCHAR Element[2];
76805 + HEADER_802_11 AuthHdr;
76806 + BOOLEAN TimerCancelled;
76807 + PUCHAR pOutBuffer = NULL;
76808 + NDIS_STATUS NStatus;
76809 + ULONG FrameLen = 0;
76810 + USHORT Status2;
76811 +
76812 + if (PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))
76813 + {
76814 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 2)
76815 + {
76816 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#2 to me (Alg=%d, Status=%d)\n", Alg, Status));
76817 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
76818 +
76819 + if (Status == MLME_SUCCESS)
76820 + {
76821 + // Authentication Mode "LEAP" has allow for CCX 1.X
76822 + if ((pAd->MlmeAux.Alg == Ndis802_11AuthModeOpen)
76823 +#ifdef LEAP_SUPPORT
76824 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
76825 +#endif // LEAP_SUPPORT //
76826 + )
76827 + {
76828 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76829 +#ifdef LEAP_SUPPORT
76830 + pAd->Mlme.LeapMachine.CurrState = LEAP_IDLE;
76831 +#endif // LEAP_SUPPORT //
76832 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76833 + }
76834 + else
76835 + {
76836 + // 2. shared key, need to be challenged
76837 + Seq++;
76838 + RemoteStatus = MLME_SUCCESS;
76839 +
76840 + // Get an unused nonpaged memory
76841 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
76842 + if(NStatus != NDIS_STATUS_SUCCESS)
76843 + {
76844 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq2Action() allocate memory fail\n"));
76845 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76846 + Status2 = MLME_FAIL_NO_RESOURCE;
76847 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status2);
76848 + return;
76849 + }
76850 +
76851 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#3...\n"));
76852 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr2, pAd->MlmeAux.Bssid);
76853 + AuthHdr.FC.Wep = 1;
76854 + // Encrypt challenge text & auth information
76855 + RTMPInitWepEngine(
76856 + pAd,
76857 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
76858 + pAd->StaCfg.DefaultKeyId,
76859 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen,
76860 + CyperChlgText);
76861 +
76862 + Alg = cpu2le16(*(USHORT *)&Alg);
76863 + Seq = cpu2le16(*(USHORT *)&Seq);
76864 + RemoteStatus= cpu2le16(*(USHORT *)&RemoteStatus);
76865 +
76866 + RTMPEncryptData(pAd, (PUCHAR) &Alg, CyperChlgText + 4, 2);
76867 + RTMPEncryptData(pAd, (PUCHAR) &Seq, CyperChlgText + 6, 2);
76868 + RTMPEncryptData(pAd, (PUCHAR) &RemoteStatus, CyperChlgText + 8, 2);
76869 + Element[0] = 16;
76870 + Element[1] = 128;
76871 + RTMPEncryptData(pAd, Element, CyperChlgText + 10, 2);
76872 + RTMPEncryptData(pAd, ChlgText, CyperChlgText + 12, 128);
76873 + RTMPSetICV(pAd, CyperChlgText + 140);
76874 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76875 + sizeof(HEADER_802_11), &AuthHdr,
76876 + CIPHER_TEXT_LEN + 16, CyperChlgText,
76877 + END_OF_ARGS);
76878 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76879 + MlmeFreeMemory(pAd, pOutBuffer);
76880 +
76881 + RTMPSetTimer(&pAd->MlmeAux.AuthTimer, AUTH_TIMEOUT);
76882 + pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ4;
76883 + }
76884 + }
76885 + else
76886 + {
76887 +#ifdef LEAP_SUPPORT
76888 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
76889 + {
76890 + //Invalid Authentication possible rogue AP
76891 + //Add this Ap to Rogue AP.
76892 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_INVALID_AUTH);
76893 + }
76894 +#endif // LEAP_SUPPORT //
76895 + pAd->StaCfg.AuthFailReason = Status;
76896 + COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
76897 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76898 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76899 + }
76900 + }
76901 + }
76902 + else
76903 + {
76904 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthSanity() sanity check fail\n"));
76905 + }
76906 +}
76907 +
76908 +/*
76909 + ==========================================================================
76910 + Description:
76911 +
76912 + IRQL = DISPATCH_LEVEL
76913 +
76914 + ==========================================================================
76915 + */
76916 +VOID PeerAuthRspAtSeq4Action(
76917 + IN PRTMP_ADAPTER pAd,
76918 + IN MLME_QUEUE_ELEM *Elem)
76919 +{
76920 + UCHAR Addr2[MAC_ADDR_LEN];
76921 + USHORT Alg, Seq, Status;
76922 + CHAR ChlgText[CIPHER_TEXT_LEN];
76923 + BOOLEAN TimerCancelled;
76924 +
76925 + if(PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))
76926 + {
76927 + if(MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 4)
76928 + {
76929 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#4 to me\n"));
76930 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
76931 +
76932 + if (Status != MLME_SUCCESS)
76933 + {
76934 + pAd->StaCfg.AuthFailReason = Status;
76935 + COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
76936 + }
76937 +
76938 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76939 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
76940 + }
76941 + }
76942 + else
76943 + {
76944 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq4Action() sanity check fail\n"));
76945 + }
76946 +}
76947 +
76948 +/*
76949 + ==========================================================================
76950 + Description:
76951 +
76952 + IRQL = DISPATCH_LEVEL
76953 +
76954 + ==========================================================================
76955 + */
76956 +VOID MlmeDeauthReqAction(
76957 + IN PRTMP_ADAPTER pAd,
76958 + IN MLME_QUEUE_ELEM *Elem)
76959 +{
76960 + MLME_DEAUTH_REQ_STRUCT *pInfo;
76961 + HEADER_802_11 DeauthHdr;
76962 + PUCHAR pOutBuffer = NULL;
76963 + NDIS_STATUS NStatus;
76964 + ULONG FrameLen = 0;
76965 + USHORT Status;
76966 +
76967 + pInfo = (MLME_DEAUTH_REQ_STRUCT *)Elem->Msg;
76968 +
76969 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
76970 + if (NStatus != NDIS_STATUS_SUCCESS)
76971 + {
76972 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeDeauthReqAction() allocate memory fail\n"));
76973 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76974 + Status = MLME_FAIL_NO_RESOURCE;
76975 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);
76976 + return;
76977 + }
76978 +
76979 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send DE-AUTH request (Reason=%d)...\n", pInfo->Reason));
76980 + MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pInfo->Addr, pAd->MlmeAux.Bssid);
76981 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76982 + sizeof(HEADER_802_11),&DeauthHdr,
76983 + 2, &pInfo->Reason,
76984 + END_OF_ARGS);
76985 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76986 + MlmeFreeMemory(pAd, pOutBuffer);
76987 +
76988 + pAd->StaCfg.DeauthReason = pInfo->Reason;
76989 + COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pInfo->Addr);
76990 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
76991 + Status = MLME_SUCCESS;
76992 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);
76993 +
76994 + // send wireless event - for deauthentication
76995 + if (pAd->CommonCfg.bWirelessEvent)
76996 + RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
76997 +}
76998 +
76999 +/*
77000 + ==========================================================================
77001 + Description:
77002 +
77003 + IRQL = DISPATCH_LEVEL
77004 +
77005 + ==========================================================================
77006 + */
77007 +VOID AuthTimeoutAction(
77008 + IN PRTMP_ADAPTER pAd,
77009 + IN MLME_QUEUE_ELEM *Elem)
77010 +{
77011 + USHORT Status;
77012 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeoutAction\n"));
77013 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77014 + Status = MLME_REJ_TIMEOUT;
77015 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77016 +}
77017 +
77018 +/*
77019 + ==========================================================================
77020 + Description:
77021 +
77022 + IRQL = DISPATCH_LEVEL
77023 +
77024 + ==========================================================================
77025 + */
77026 +VOID InvalidStateWhenAuth(
77027 + IN PRTMP_ADAPTER pAd,
77028 + IN MLME_QUEUE_ELEM *Elem)
77029 +{
77030 + USHORT Status;
77031 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - InvalidStateWhenAuth (state=%ld), reset AUTH state machine\n", pAd->Mlme.AuthMachine.CurrState));
77032 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77033 + Status = MLME_STATE_MACHINE_REJECT;
77034 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77035 +}
77036 +
77037 +/*
77038 + ==========================================================================
77039 + Description:
77040 + Some STA/AP
77041 + Note:
77042 + This action should never trigger AUTH state transition, therefore we
77043 + separate it from AUTH state machine, and make it as a standalone service
77044 +
77045 + IRQL = DISPATCH_LEVEL
77046 +
77047 + ==========================================================================
77048 + */
77049 +VOID Cls2errAction(
77050 + IN PRTMP_ADAPTER pAd,
77051 + IN PUCHAR pAddr)
77052 +{
77053 + HEADER_802_11 DeauthHdr;
77054 + PUCHAR pOutBuffer = NULL;
77055 + NDIS_STATUS NStatus;
77056 + ULONG FrameLen = 0;
77057 + USHORT Reason = REASON_CLS2ERR;
77058 +
77059 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
77060 + if (NStatus != NDIS_STATUS_SUCCESS)
77061 + return;
77062 +
77063 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Class 2 error, Send DEAUTH frame...\n"));
77064 + MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pAddr, pAd->MlmeAux.Bssid);
77065 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77066 + sizeof(HEADER_802_11),&DeauthHdr,
77067 + 2, &Reason,
77068 + END_OF_ARGS);
77069 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77070 + MlmeFreeMemory(pAd, pOutBuffer);
77071 +
77072 + pAd->StaCfg.DeauthReason = Reason;
77073 + COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pAddr);
77074 +}
77075 +
77076 +
77077 --- /dev/null
77078 +++ b/drivers/staging/rt2870/sta/auth_rsp.c
77079 @@ -0,0 +1,166 @@
77080 +/*
77081 + *************************************************************************
77082 + * Ralink Tech Inc.
77083 + * 5F., No.36, Taiyuan St., Jhubei City,
77084 + * Hsinchu County 302,
77085 + * Taiwan, R.O.C.
77086 + *
77087 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
77088 + *
77089 + * This program is free software; you can redistribute it and/or modify *
77090 + * it under the terms of the GNU General Public License as published by *
77091 + * the Free Software Foundation; either version 2 of the License, or *
77092 + * (at your option) any later version. *
77093 + * *
77094 + * This program is distributed in the hope that it will be useful, *
77095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
77096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
77097 + * GNU General Public License for more details. *
77098 + * *
77099 + * You should have received a copy of the GNU General Public License *
77100 + * along with this program; if not, write to the *
77101 + * Free Software Foundation, Inc., *
77102 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
77103 + * *
77104 + *************************************************************************
77105 +
77106 + Module Name:
77107 + auth_rsp.c
77108 +
77109 + Abstract:
77110 +
77111 + Revision History:
77112 + Who When What
77113 + -------- ---------- ----------------------------------------------
77114 + John 2004-10-1 copy from RT2560
77115 +*/
77116 +#include "../rt_config.h"
77117 +
77118 +/*
77119 + ==========================================================================
77120 + Description:
77121 + authentication state machine init procedure
77122 + Parameters:
77123 + Sm - the state machine
77124 +
77125 + IRQL = PASSIVE_LEVEL
77126 +
77127 + ==========================================================================
77128 + */
77129 +VOID AuthRspStateMachineInit(
77130 + IN PRTMP_ADAPTER pAd,
77131 + IN PSTATE_MACHINE Sm,
77132 + IN STATE_MACHINE_FUNC Trans[])
77133 +{
77134 + StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_RSP_IDLE, AUTH_RSP_MACHINE_BASE);
77135 +
77136 + // column 1
77137 + StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
77138 +
77139 + // column 2
77140 + StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
77141 +
77142 +}
77143 +
77144 +/*
77145 + ==========================================================================
77146 + Description:
77147 +
77148 + IRQL = DISPATCH_LEVEL
77149 +
77150 + ==========================================================================
77151 +*/
77152 +VOID PeerAuthSimpleRspGenAndSend(
77153 + IN PRTMP_ADAPTER pAd,
77154 + IN PHEADER_802_11 pHdr80211,
77155 + IN USHORT Alg,
77156 + IN USHORT Seq,
77157 + IN USHORT Reason,
77158 + IN USHORT Status)
77159 +{
77160 + HEADER_802_11 AuthHdr;
77161 + ULONG FrameLen = 0;
77162 + PUCHAR pOutBuffer = NULL;
77163 + NDIS_STATUS NStatus;
77164 +
77165 + if (Reason != MLME_SUCCESS)
77166 + {
77167 + DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n"));
77168 + return;
77169 + }
77170 +
77171 + //Get an unused nonpaged memory
77172 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
77173 + if (NStatus != NDIS_STATUS_SUCCESS)
77174 + return;
77175 +
77176 + DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n"));
77177 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2, pAd->MlmeAux.Bssid);
77178 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77179 + sizeof(HEADER_802_11), &AuthHdr,
77180 + 2, &Alg,
77181 + 2, &Seq,
77182 + 2, &Reason,
77183 + END_OF_ARGS);
77184 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77185 + MlmeFreeMemory(pAd, pOutBuffer);
77186 +}
77187 +
77188 +/*
77189 + ==========================================================================
77190 + Description:
77191 +
77192 + IRQL = DISPATCH_LEVEL
77193 +
77194 + ==========================================================================
77195 +*/
77196 +VOID PeerDeauthAction(
77197 + IN PRTMP_ADAPTER pAd,
77198 + IN PMLME_QUEUE_ELEM Elem)
77199 +{
77200 + UCHAR Addr2[MAC_ADDR_LEN];
77201 + USHORT Reason;
77202 +
77203 + if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))
77204 + {
77205 + if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid))
77206 + {
77207 + DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n", Reason));
77208 +
77209 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
77210 + {
77211 + union iwreq_data wrqu;
77212 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
77213 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
77214 + }
77215 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77216 +
77217 +
77218 + // send wireless event - for deauthentication
77219 + if (pAd->CommonCfg.bWirelessEvent)
77220 + RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
77221 +
77222 + LinkDown(pAd, TRUE);
77223 +
77224 + // Authentication Mode Cisco_LEAP has start a timer
77225 + // We should cancel it if using LEAP
77226 +#ifdef LEAP_SUPPORT
77227 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
77228 + {
77229 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &TimerCancelled);
77230 + //Check is it mach the LEAP Authentication failed as possible a Rogue AP
77231 + //on it's PortSecured not equal to WPA_802_1X_PORT_SECURED while process the Authenticaton.
77232 + if ((pAd->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED) && (pAd->Mlme.LeapMachine.CurrState != LEAP_IDLE))
77233 + {
77234 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_AUTH_TIMEOUT);
77235 + }
77236 + }
77237 +#endif // LEAP_SUPPORT //
77238 + }
77239 + }
77240 + else
77241 + {
77242 + DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - PeerDeauthAction() sanity check fail\n"));
77243 + }
77244 +}
77245 +
77246 --- /dev/null
77247 +++ b/drivers/staging/rt2870/sta/connect.c
77248 @@ -0,0 +1,2822 @@
77249 +/*
77250 + *************************************************************************
77251 + * Ralink Tech Inc.
77252 + * 5F., No.36, Taiyuan St., Jhubei City,
77253 + * Hsinchu County 302,
77254 + * Taiwan, R.O.C.
77255 + *
77256 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
77257 + *
77258 + * This program is free software; you can redistribute it and/or modify *
77259 + * it under the terms of the GNU General Public License as published by *
77260 + * the Free Software Foundation; either version 2 of the License, or *
77261 + * (at your option) any later version. *
77262 + * *
77263 + * This program is distributed in the hope that it will be useful, *
77264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
77265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
77266 + * GNU General Public License for more details. *
77267 + * *
77268 + * You should have received a copy of the GNU General Public License *
77269 + * along with this program; if not, write to the *
77270 + * Free Software Foundation, Inc., *
77271 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
77272 + * *
77273 + *************************************************************************
77274 +
77275 + Module Name:
77276 + connect.c
77277 +
77278 + Abstract:
77279 +
77280 + Revision History:
77281 + Who When What
77282 + -------- ---------- ----------------------------------------------
77283 + John 2004-08-08 Major modification from RT2560
77284 +*/
77285 +#include "../rt_config.h"
77286 +
77287 +UCHAR CipherSuiteWpaNoneTkip[] = {
77288 + 0x00, 0x50, 0xf2, 0x01, // oui
77289 + 0x01, 0x00, // Version
77290 + 0x00, 0x50, 0xf2, 0x02, // Multicast
77291 + 0x01, 0x00, // Number of unicast
77292 + 0x00, 0x50, 0xf2, 0x02, // unicast
77293 + 0x01, 0x00, // number of authentication method
77294 + 0x00, 0x50, 0xf2, 0x00 // authentication
77295 + };
77296 +UCHAR CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));
77297 +
77298 +UCHAR CipherSuiteWpaNoneAes[] = {
77299 + 0x00, 0x50, 0xf2, 0x01, // oui
77300 + 0x01, 0x00, // Version
77301 + 0x00, 0x50, 0xf2, 0x04, // Multicast
77302 + 0x01, 0x00, // Number of unicast
77303 + 0x00, 0x50, 0xf2, 0x04, // unicast
77304 + 0x01, 0x00, // number of authentication method
77305 + 0x00, 0x50, 0xf2, 0x00 // authentication
77306 + };
77307 +UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));
77308 +
77309 +// The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,
77310 +// or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS
77311 +// All settings successfuly negotiated furing MLME state machines become final settings
77312 +// and are copied to pAd->StaActive
77313 +#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
77314 +{ \
77315 + (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
77316 + NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
77317 + COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
77318 + (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
77319 + (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
77320 + (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
77321 + (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
77322 + (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
77323 + (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
77324 + (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
77325 + (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
77326 + (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
77327 + NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
77328 + (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
77329 + NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
77330 + NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\
77331 + NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\
77332 + NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\
77333 + COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
77334 + (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
77335 + (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
77336 + COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
77337 + (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
77338 +}
77339 +
77340 +/*
77341 + ==========================================================================
77342 + Description:
77343 +
77344 + IRQL = PASSIVE_LEVEL
77345 +
77346 + ==========================================================================
77347 +*/
77348 +VOID MlmeCntlInit(
77349 + IN PRTMP_ADAPTER pAd,
77350 + IN STATE_MACHINE *S,
77351 + OUT STATE_MACHINE_FUNC Trans[])
77352 +{
77353 + // Control state machine differs from other state machines, the interface
77354 + // follows the standard interface
77355 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77356 +}
77357 +
77358 +/*
77359 + ==========================================================================
77360 + Description:
77361 +
77362 + IRQL = DISPATCH_LEVEL
77363 +
77364 + ==========================================================================
77365 +*/
77366 +VOID MlmeCntlMachinePerformAction(
77367 + IN PRTMP_ADAPTER pAd,
77368 + IN STATE_MACHINE *S,
77369 + IN MLME_QUEUE_ELEM *Elem)
77370 +{
77371 + switch(pAd->Mlme.CntlMachine.CurrState)
77372 + {
77373 + case CNTL_IDLE:
77374 + CntlIdleProc(pAd, Elem);
77375 + break;
77376 + case CNTL_WAIT_DISASSOC:
77377 + CntlWaitDisassocProc(pAd, Elem);
77378 + break;
77379 + case CNTL_WAIT_JOIN:
77380 + CntlWaitJoinProc(pAd, Elem);
77381 + break;
77382 +
77383 + // CNTL_WAIT_REASSOC is the only state in CNTL machine that does
77384 + // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".
77385 + // Therefore not protected by NDIS's "only one outstanding OID request"
77386 + // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.
77387 + // Current approach is to block new SET request at RTMPSetInformation()
77388 + // when CntlMachine.CurrState is not CNTL_IDLE
77389 + case CNTL_WAIT_REASSOC:
77390 + CntlWaitReassocProc(pAd, Elem);
77391 + break;
77392 +
77393 + case CNTL_WAIT_START:
77394 + CntlWaitStartProc(pAd, Elem);
77395 + break;
77396 + case CNTL_WAIT_AUTH:
77397 + CntlWaitAuthProc(pAd, Elem);
77398 + break;
77399 + case CNTL_WAIT_AUTH2:
77400 + CntlWaitAuthProc2(pAd, Elem);
77401 + break;
77402 + case CNTL_WAIT_ASSOC:
77403 + CntlWaitAssocProc(pAd, Elem);
77404 + break;
77405 +
77406 + case CNTL_WAIT_OID_LIST_SCAN:
77407 + if(Elem->MsgType == MT2_SCAN_CONF)
77408 + {
77409 + // Resume TxRing after SCANING complete. We hope the out-of-service time
77410 + // won't be too long to let upper layer time-out the waiting frames
77411 + RTMPResumeMsduTransmission(pAd);
77412 + if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
77413 + {
77414 + // Cisco scan request is finished, prepare beacon report
77415 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
77416 + }
77417 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77418 +
77419 + //
77420 + // Set LED status to previous status.
77421 + //
77422 + if (pAd->bLedOnScanning)
77423 + {
77424 + pAd->bLedOnScanning = FALSE;
77425 + RTMPSetLED(pAd, pAd->LedStatus);
77426 + }
77427 +#ifdef DOT11N_DRAFT3
77428 + // AP sent a 2040Coexistence mgmt frame, then station perform a scan, and then send back the respone.
77429 + if (pAd->CommonCfg.BSSCoexist2040.field.InfoReq == 1)
77430 + {
77431 + Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
77432 + }
77433 +#endif // DOT11N_DRAFT3 //
77434 + }
77435 + break;
77436 +
77437 + case CNTL_WAIT_OID_DISASSOC:
77438 + if (Elem->MsgType == MT2_DISASSOC_CONF)
77439 + {
77440 + LinkDown(pAd, FALSE);
77441 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77442 + }
77443 + break;
77444 +#ifdef RT2870
77445 + //
77446 + // This state is for that we want to connect to an AP but
77447 + // it didn't find on BSS List table. So we need to scan the air first,
77448 + // after that we can try to connect to the desired AP if available.
77449 + //
77450 + case CNTL_WAIT_SCAN_FOR_CONNECT:
77451 + if(Elem->MsgType == MT2_SCAN_CONF)
77452 + {
77453 + // Resume TxRing after SCANING complete. We hope the out-of-service time
77454 + // won't be too long to let upper layer time-out the waiting frames
77455 + RTMPResumeMsduTransmission(pAd);
77456 +#ifdef CCX_SUPPORT
77457 + if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
77458 + {
77459 + // Cisco scan request is finished, prepare beacon report
77460 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
77461 + }
77462 +#endif // CCX_SUPPORT //
77463 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77464 +
77465 + //
77466 + // Check if we can connect to.
77467 + //
77468 + BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
77469 + if (pAd->MlmeAux.SsidBssTab.BssNr > 0)
77470 + {
77471 + MlmeAutoReconnectLastSSID(pAd);
77472 + }
77473 + }
77474 + break;
77475 +#endif // RT2870 //
77476 + default:
77477 + DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));
77478 + break;
77479 + }
77480 +}
77481 +
77482 +
77483 +/*
77484 + ==========================================================================
77485 + Description:
77486 +
77487 + IRQL = DISPATCH_LEVEL
77488 +
77489 + ==========================================================================
77490 +*/
77491 +VOID CntlIdleProc(
77492 + IN PRTMP_ADAPTER pAd,
77493 + IN MLME_QUEUE_ELEM *Elem)
77494 +{
77495 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
77496 +
77497 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
77498 + return;
77499 +
77500 + switch(Elem->MsgType)
77501 + {
77502 + case OID_802_11_SSID:
77503 + CntlOidSsidProc(pAd, Elem);
77504 + break;
77505 +
77506 + case OID_802_11_BSSID:
77507 + CntlOidRTBssidProc(pAd,Elem);
77508 + break;
77509 +
77510 + case OID_802_11_BSSID_LIST_SCAN:
77511 + CntlOidScanProc(pAd,Elem);
77512 + break;
77513 +
77514 + case OID_802_11_DISASSOCIATE:
77515 +#ifdef RALINK_ATE
77516 + if(ATE_ON(pAd))
77517 + {
77518 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
77519 + break;
77520 + }
77521 +#endif // RALINK_ATE //
77522 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
77523 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
77524 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
77525 +#ifdef WPA_SUPPLICANT_SUPPORT
77526 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)
77527 +#endif // WPA_SUPPLICANT_SUPPORT //
77528 + {
77529 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
77530 + // Since calling this indicate user don't want to connect to that SSID anymore.
77531 + pAd->MlmeAux.AutoReconnectSsidLen= 32;
77532 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
77533 + }
77534 + break;
77535 +
77536 + case MT2_MLME_ROAMING_REQ:
77537 + CntlMlmeRoamingProc(pAd, Elem);
77538 + break;
77539 +
77540 + case OID_802_11_MIC_FAILURE_REPORT_FRAME:
77541 + WpaMicFailureReportFrame(pAd, Elem);
77542 + break;
77543 +
77544 +#ifdef QOS_DLS_SUPPORT
77545 + case RT_OID_802_11_SET_DLS_PARAM:
77546 + CntlOidDLSSetupProc(pAd, Elem);
77547 + break;
77548 +#endif // QOS_DLS_SUPPORT //
77549 +
77550 + default:
77551 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));
77552 + break;
77553 + }
77554 +}
77555 +
77556 +VOID CntlOidScanProc(
77557 + IN PRTMP_ADAPTER pAd,
77558 + IN MLME_QUEUE_ELEM *Elem)
77559 +{
77560 + MLME_SCAN_REQ_STRUCT ScanReq;
77561 + ULONG BssIdx = BSS_NOT_FOUND;
77562 + BSS_ENTRY CurrBss;
77563 +
77564 +#ifdef RALINK_ATE
77565 +/* Disable scanning when ATE is running. */
77566 + if (ATE_ON(pAd))
77567 + return;
77568 +#endif // RALINK_ATE //
77569 +
77570 +
77571 + // record current BSS if network is connected.
77572 + // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
77573 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
77574 + {
77575 + BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);
77576 + if (BssIdx != BSS_NOT_FOUND)
77577 + {
77578 + NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
77579 + }
77580 + }
77581 +
77582 + // clean up previous SCAN result, add current BSS back to table if any
77583 + BssTableInit(&pAd->ScanTab);
77584 + if (BssIdx != BSS_NOT_FOUND)
77585 + {
77586 + // DDK Note: If the NIC is associated with a particular BSSID and SSID
77587 + // that are not contained in the list of BSSIDs generated by this scan, the
77588 + // BSSID description of the currently associated BSSID and SSID should be
77589 + // appended to the list of BSSIDs in the NIC's database.
77590 + // To ensure this, we append this BSS as the first entry in SCAN result
77591 + NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));
77592 + pAd->ScanTab.BssNr = 1;
77593 + }
77594 +
77595 + ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE);
77596 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
77597 + sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
77598 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
77599 +}
77600 +
77601 +/*
77602 + ==========================================================================
77603 + Description:
77604 + Before calling this routine, user desired SSID should already been
77605 + recorded in CommonCfg.Ssid[]
77606 + IRQL = DISPATCH_LEVEL
77607 +
77608 + ==========================================================================
77609 +*/
77610 +VOID CntlOidSsidProc(
77611 + IN PRTMP_ADAPTER pAd,
77612 + IN MLME_QUEUE_ELEM * Elem)
77613 +{
77614 + PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;
77615 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
77616 + ULONG Now;
77617 +
77618 + // Step 1. record the desired user settings to MlmeAux
77619 + NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
77620 + NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
77621 + pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength;
77622 + NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
77623 + pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
77624 +
77625 +
77626 + //
77627 + // Update Reconnect Ssid, that user desired to connect.
77628 + //
77629 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
77630 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
77631 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
77632 +
77633 + // step 2. find all matching BSS in the lastest SCAN result (inBssTab)
77634 + // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order
77635 + BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
77636 +
77637 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
77638 + pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));
77639 + NdisGetSystemUpTime(&Now);
77640 +
77641 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
77642 + (pAd->CommonCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) &&
77643 + NdisEqualMemory(pAd->CommonCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->CommonCfg.SsidLen) &&
77644 + MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid))
77645 + {
77646 + // Case 1. already connected with an AP who has the desired SSID
77647 + // with highest RSSI
77648 +
77649 + // Add checking Mode "LEAP" for CCX 1.0
77650 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
77651 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
77652 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
77653 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
77654 +#ifdef LEAP_SUPPORT
77655 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
77656 +#endif // LEAP_SUPPORT //
77657 + ) &&
77658 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
77659 + {
77660 + // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo
77661 + // connection process
77662 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
77663 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
77664 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
77665 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
77666 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
77667 + }
77668 + else if (pAd->bConfigChanged == TRUE)
77669 + {
77670 + // case 1.2 Important Config has changed, we have to reconnect to the same AP
77671 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
77672 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
77673 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
77674 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
77675 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
77676 + }
77677 + else
77678 + {
77679 + // case 1.3. already connected to the SSID with highest RSSI.
77680 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
77681 + //
77682 + // (HCT 12.1) 1c_wlan_mediaevents required
77683 + // media connect events are indicated when associating with the same AP
77684 + //
77685 + if (INFRA_ON(pAd))
77686 + {
77687 + //
77688 + // Since MediaState already is NdisMediaStateConnected
77689 + // We just indicate the connect event again to meet the WHQL required.
77690 + //
77691 + pAd->IndicateMediaState = NdisMediaStateConnected;
77692 + RTMP_IndicateMediaState(pAd);
77693 + pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
77694 + }
77695 +
77696 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77697 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
77698 + {
77699 + union iwreq_data wrqu;
77700 +
77701 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
77702 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
77703 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
77704 +
77705 + }
77706 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77707 + }
77708 + }
77709 + else if (INFRA_ON(pAd))
77710 + {
77711 + //
77712 + // For RT61
77713 + // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
77714 + // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect
77715 + // But media status is connected, so the SSID not report correctly.
77716 + //
77717 + if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen))
77718 + {
77719 + //
77720 + // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.
77721 + //
77722 + pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
77723 + }
77724 + // case 2. active INFRA association existent
77725 + // roaming is done within miniport driver, nothing to do with configuration
77726 + // utility. so upon a new SET(OID_802_11_SSID) is received, we just
77727 + // disassociate with the current associated AP,
77728 + // then perform a new association with this new SSID, no matter the
77729 + // new/old SSID are the same or not.
77730 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
77731 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
77732 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
77733 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
77734 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
77735 + }
77736 + else
77737 + {
77738 + if (ADHOC_ON(pAd))
77739 + {
77740 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
77741 + LinkDown(pAd, FALSE);
77742 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
77743 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
77744 + RTMP_IndicateMediaState(pAd);
77745 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
77746 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
77747 + }
77748 +
77749 + if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
77750 + (pAd->StaCfg.bAutoReconnect == TRUE) &&
77751 + (pAd->MlmeAux.BssType == BSS_INFRA) &&
77752 + (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)
77753 + )
77754 + {
77755 + MLME_SCAN_REQ_STRUCT ScanReq;
77756 +
77757 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
77758 + ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
77759 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
77760 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
77761 + // Reset Missed scan number
77762 + pAd->StaCfg.LastScanTime = Now;
77763 + }
77764 + else
77765 + {
77766 + pAd->MlmeAux.BssIdx = 0;
77767 + IterateOnBssTab(pAd);
77768 + }
77769 + }
77770 +}
77771 +
77772 +
77773 +/*
77774 + ==========================================================================
77775 + Description:
77776 +
77777 + IRQL = DISPATCH_LEVEL
77778 +
77779 + ==========================================================================
77780 +*/
77781 +VOID CntlOidRTBssidProc(
77782 + IN PRTMP_ADAPTER pAd,
77783 + IN MLME_QUEUE_ELEM * Elem)
77784 +{
77785 + ULONG BssIdx;
77786 + PUCHAR pOidBssid = (PUCHAR)Elem->Msg;
77787 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
77788 + MLME_JOIN_REQ_STRUCT JoinReq;
77789 +
77790 +#ifdef RALINK_ATE
77791 +/* No need to perform this routine when ATE is running. */
77792 + if (ATE_ON(pAd))
77793 + return;
77794 +#endif // RALINK_ATE //
77795 +
77796 + // record user desired settings
77797 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
77798 + pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
77799 +
77800 + //
77801 + // Update Reconnect Ssid, that user desired to connect.
77802 + //
77803 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
77804 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
77805 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
77806 +
77807 + // find the desired BSS in the latest SCAN result table
77808 + BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
77809 + if (BssIdx == BSS_NOT_FOUND)
77810 + {
77811 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
77812 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77813 + return;
77814 + }
77815 +
77816 + // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?
77817 + // Because we need this entry to become the JOIN target in later on SYNC state machine
77818 + pAd->MlmeAux.BssIdx = 0;
77819 + pAd->MlmeAux.SsidBssTab.BssNr = 1;
77820 + NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
77821 +
77822 + //pAd->MlmeAux.AutoReconnectSsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
77823 + //NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->ScanTab.BssEntry[BssIdx].SsidLen);
77824 +
77825 + // Add SSID into MlmeAux for site surey joining hidden SSID
77826 + //pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
77827 + //NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->MlmeAux.SsidLen);
77828 +
77829 + // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP
77830 + // we just follow normal procedure. The reason of user doing this may because he/she changed
77831 + // AP to another channel, but we still received BEACON from it thus don't claim Link Down.
77832 + // Since user knows he's changed AP channel, he'll re-connect again. By skipping the following
77833 + // checking, we'll disassociate then re-do normal association with this AP at the new channel.
77834 + // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do
77835 + // connection when setting the same BSSID.
77836 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
77837 + MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid))
77838 + {
77839 + // already connected to the same BSSID, go back to idle state directly
77840 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));
77841 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
77842 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
77843 + {
77844 + union iwreq_data wrqu;
77845 +
77846 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
77847 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
77848 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
77849 +
77850 + }
77851 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77852 + }
77853 + else
77854 + {
77855 + if (INFRA_ON(pAd))
77856 + {
77857 + // disassoc from current AP first
77858 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n"));
77859 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
77860 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
77861 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
77862 +
77863 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
77864 + }
77865 + else
77866 + {
77867 + if (ADHOC_ON(pAd))
77868 + {
77869 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - drop current ADHOC\n"));
77870 + LinkDown(pAd, FALSE);
77871 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
77872 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
77873 + RTMP_IndicateMediaState(pAd);
77874 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
77875 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
77876 + }
77877 +
77878 + // Change the wepstatus to original wepstatus
77879 + pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
77880 + pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
77881 + pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
77882 +
77883 + // Check cipher suite, AP must have more secured cipher than station setting
77884 + // Set the Pairwise and Group cipher to match the intended AP setting
77885 + // We can only connect to AP with less secured cipher setting
77886 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
77887 + {
77888 + pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;
77889 +
77890 + if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)
77891 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;
77892 + else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
77893 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;
77894 + else // There is no PairCipher Aux, downgrade our capability to TKIP
77895 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
77896 + }
77897 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
77898 + {
77899 + pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;
77900 +
77901 + if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)
77902 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;
77903 + else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
77904 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;
77905 + else // There is no PairCipher Aux, downgrade our capability to TKIP
77906 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
77907 +
77908 + // RSN capability
77909 + pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;
77910 + }
77911 +
77912 + // Set Mix cipher flag
77913 + pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
77914 + if (pAd->StaCfg.bMixCipher == TRUE)
77915 + {
77916 + // If mix cipher, re-build RSNIE
77917 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
77918 + }
77919 + // No active association, join the BSS immediately
77920 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
77921 + pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]));
77922 +
77923 + JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
77924 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);
77925 +
77926 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
77927 + }
77928 + }
77929 +}
77930 +
77931 +// Roaming is the only external request triggering CNTL state machine
77932 +// despite of other "SET OID" operation. All "SET OID" related oerations
77933 +// happen in sequence, because no other SET OID will be sent to this device
77934 +// until the the previous SET operation is complete (successful o failed).
77935 +// So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?
77936 +// or been corrupted by other "SET OID"?
77937 +//
77938 +// IRQL = DISPATCH_LEVEL
77939 +VOID CntlMlmeRoamingProc(
77940 + IN PRTMP_ADAPTER pAd,
77941 + IN MLME_QUEUE_ELEM *Elem)
77942 +{
77943 + // TODO:
77944 + // AP in different channel may show lower RSSI than actual value??
77945 + // should we add a weighting factor to compensate it?
77946 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - Roaming in MlmeAux.RoamTab...\n"));
77947 +
77948 + NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));
77949 + pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
77950 +
77951 + BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
77952 + pAd->MlmeAux.BssIdx = 0;
77953 + IterateOnBssTab(pAd);
77954 +}
77955 +
77956 +#ifdef QOS_DLS_SUPPORT
77957 +/*
77958 + ==========================================================================
77959 + Description:
77960 +
77961 + IRQL = DISPATCH_LEVEL
77962 +
77963 + ==========================================================================
77964 +*/
77965 +VOID CntlOidDLSSetupProc(
77966 + IN PRTMP_ADAPTER pAd,
77967 + IN MLME_QUEUE_ELEM *Elem)
77968 +{
77969 + PRT_802_11_DLS pDLS = (PRT_802_11_DLS)Elem->Msg;
77970 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
77971 + INT i;
77972 + USHORT reason = REASON_UNSPECIFY;
77973 +
77974 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - (OID set %02x:%02x:%02x:%02x:%02x:%02x with Valid=%d, Status=%d, TimeOut=%d, CountDownTimer=%d)\n",
77975 + pDLS->MacAddr[0], pDLS->MacAddr[1], pDLS->MacAddr[2], pDLS->MacAddr[3], pDLS->MacAddr[4], pDLS->MacAddr[5],
77976 + pDLS->Valid, pDLS->Status, pDLS->TimeOut, pDLS->CountDownTimer));
77977 +
77978 + if (!pAd->CommonCfg.bDLSCapable)
77979 + return;
77980 +
77981 + // DLS will not be supported when Adhoc mode
77982 + if (INFRA_ON(pAd))
77983 + {
77984 + for (i = 0; i < MAX_NUM_OF_DLS_ENTRY; i++)
77985 + {
77986 + if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
77987 + (pDLS->TimeOut == pAd->StaCfg.DLSEntry[i].TimeOut) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
77988 + {
77989 + // 1. Same setting, just drop it
77990 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - setting unchanged\n"));
77991 + break;
77992 + }
77993 + else if (!pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
77994 + MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
77995 + {
77996 + // 2. Disable DLS link case, just tear down DLS link
77997 + reason = REASON_QOS_UNWANTED_MECHANISM;
77998 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
77999 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
78000 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78001 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78002 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - start tear down procedure\n"));
78003 + break;
78004 + }
78005 + else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && !pAd->StaCfg.DLSEntry[i].Valid)
78006 + {
78007 + // 3. Enable case, start DLS setup procedure
78008 + NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
78009 +
78010 + //Update countdown timer
78011 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
78012 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78013 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78014 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS setup case\n"));
78015 + break;
78016 + }
78017 + else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78018 + (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && !MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78019 + {
78020 + // 4. update mac case, tear down old DLS and setup new DLS
78021 + reason = REASON_QOS_UNWANTED_MECHANISM;
78022 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
78023 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
78024 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78025 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78026 + NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
78027 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78028 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78029 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS tear down and restart case\n"));
78030 + break;
78031 + }
78032 + else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78033 + MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr) && (pAd->StaCfg.DLSEntry[i].TimeOut != pDLS->TimeOut))
78034 + {
78035 + // 5. update timeout case, start DLS setup procedure (no tear down)
78036 + pAd->StaCfg.DLSEntry[i].TimeOut = pDLS->TimeOut;
78037 + //Update countdown timer
78038 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
78039 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78040 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78041 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS update timeout case\n"));
78042 + break;
78043 + }
78044 + else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78045 + (pAd->StaCfg.DLSEntry[i].Status != DLS_FINISH) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78046 + {
78047 + // 6. re-setup case, start DLS setup procedure (no tear down)
78048 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78049 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78050 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS retry setup procedure\n"));
78051 + break;
78052 + }
78053 + else
78054 + {
78055 + DBGPRINT(RT_DEBUG_WARN,("CNTL - DLS not changed in entry - %d - Valid=%d, Status=%d, TimeOut=%d\n",
78056 + i, pAd->StaCfg.DLSEntry[i].Valid, pAd->StaCfg.DLSEntry[i].Status, pAd->StaCfg.DLSEntry[i].TimeOut));
78057 + }
78058 + }
78059 + }
78060 +}
78061 +#endif // QOS_DLS_SUPPORT //
78062 +
78063 +/*
78064 + ==========================================================================
78065 + Description:
78066 +
78067 + IRQL = DISPATCH_LEVEL
78068 +
78069 + ==========================================================================
78070 +*/
78071 +VOID CntlWaitDisassocProc(
78072 + IN PRTMP_ADAPTER pAd,
78073 + IN MLME_QUEUE_ELEM *Elem)
78074 +{
78075 + MLME_START_REQ_STRUCT StartReq;
78076 +
78077 + if (Elem->MsgType == MT2_DISASSOC_CONF)
78078 + {
78079 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
78080 +
78081 + if (pAd->CommonCfg.bWirelessEvent)
78082 + {
78083 + RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
78084 + }
78085 +
78086 + LinkDown(pAd, FALSE);
78087 +
78088 + // case 1. no matching BSS, and user wants ADHOC, so we just start a new one
78089 + if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC))
78090 + {
78091 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
78092 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
78093 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
78094 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
78095 + }
78096 + // case 2. try each matched BSS
78097 + else
78098 + {
78099 + pAd->MlmeAux.BssIdx = 0;
78100 +
78101 + IterateOnBssTab(pAd);
78102 + }
78103 + }
78104 +}
78105 +
78106 +/*
78107 + ==========================================================================
78108 + Description:
78109 +
78110 + IRQL = DISPATCH_LEVEL
78111 +
78112 + ==========================================================================
78113 +*/
78114 +VOID CntlWaitJoinProc(
78115 + IN PRTMP_ADAPTER pAd,
78116 + IN MLME_QUEUE_ELEM *Elem)
78117 +{
78118 + USHORT Reason;
78119 + MLME_AUTH_REQ_STRUCT AuthReq;
78120 +
78121 + if (Elem->MsgType == MT2_JOIN_CONF)
78122 + {
78123 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
78124 + if (Reason == MLME_SUCCESS)
78125 + {
78126 + // 1. joined an IBSS, we are pretty much done here
78127 + if (pAd->MlmeAux.BssType == BSS_ADHOC)
78128 + {
78129 + //
78130 + // 5G bands rules of Japan:
78131 + // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
78132 + //
78133 + if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
78134 + RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
78135 + )
78136 + {
78137 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78138 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
78139 + return;
78140 + }
78141 +
78142 + LinkUp(pAd, BSS_ADHOC);
78143 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78144 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
78145 + pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
78146 + pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
78147 +
78148 + pAd->IndicateMediaState = NdisMediaStateConnected;
78149 + pAd->ExtraInfo = GENERAL_LINK_UP;
78150 + }
78151 + // 2. joined a new INFRA network, start from authentication
78152 + else
78153 + {
78154 +#ifdef LEAP_SUPPORT
78155 + // Add AuthMode "LEAP" for CCX 1.X
78156 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
78157 + {
78158 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
78159 + }
78160 + else
78161 +#endif // LEAP_SUPPORT //
78162 + {
78163 + // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
78164 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
78165 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
78166 + {
78167 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
78168 + }
78169 + else
78170 + {
78171 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
78172 + }
78173 + }
78174 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
78175 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
78176 +
78177 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;
78178 + }
78179 + }
78180 + else
78181 + {
78182 + // 3. failed, try next BSS
78183 + pAd->MlmeAux.BssIdx++;
78184 + IterateOnBssTab(pAd);
78185 + }
78186 + }
78187 +}
78188 +
78189 +
78190 +/*
78191 + ==========================================================================
78192 + Description:
78193 +
78194 + IRQL = DISPATCH_LEVEL
78195 +
78196 + ==========================================================================
78197 +*/
78198 +VOID CntlWaitStartProc(
78199 + IN PRTMP_ADAPTER pAd,
78200 + IN MLME_QUEUE_ELEM *Elem)
78201 +{
78202 + USHORT Result;
78203 +
78204 + if (Elem->MsgType == MT2_START_CONF)
78205 + {
78206 + NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
78207 + if (Result == MLME_SUCCESS)
78208 + {
78209 + //
78210 + // 5G bands rules of Japan:
78211 + // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
78212 + //
78213 + if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
78214 + RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
78215 + )
78216 + {
78217 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78218 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
78219 + return;
78220 + }
78221 +#ifdef DOT11_N_SUPPORT
78222 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
78223 + {
78224 + N_ChannelCheck(pAd);
78225 + SetCommonHT(pAd);
78226 + NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, &pAd->CommonCfg.AddHTInfo, sizeof(ADD_HT_INFO_IE));
78227 + RTMPCheckHt(pAd, BSSID_WCID, &pAd->CommonCfg.HtCapability, &pAd->CommonCfg.AddHTInfo);
78228 + pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
78229 + NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], 16);
78230 + NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], &pAd->CommonCfg.HtCapability.MCSSet[0], 16);
78231 + COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
78232 +
78233 + if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
78234 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
78235 + {
78236 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel + 2;
78237 + }
78238 + else if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
78239 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
78240 + {
78241 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel - 2;
78242 + }
78243 + }
78244 + else
78245 +#endif // DOT11_N_SUPPORT //
78246 + {
78247 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
78248 + }
78249 + LinkUp(pAd, BSS_ADHOC);
78250 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78251 + // Before send beacon, driver need do radar detection
78252 + if ((pAd->CommonCfg.Channel > 14 )
78253 + && (pAd->CommonCfg.bIEEE80211H == 1)
78254 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
78255 + {
78256 + pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;
78257 + pAd->CommonCfg.RadarDetect.RDCount = 0;
78258 +#ifdef DFS_SUPPORT
78259 + BbpRadarDetectionStart(pAd);
78260 +#endif // DFS_SUPPORT //
78261 + }
78262 +
78263 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
78264 + pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
78265 + pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
78266 + }
78267 + else
78268 + {
78269 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Start IBSS fail. BUG!!!!!\n"));
78270 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78271 + }
78272 + }
78273 +}
78274 +
78275 +/*
78276 + ==========================================================================
78277 + Description:
78278 +
78279 + IRQL = DISPATCH_LEVEL
78280 +
78281 + ==========================================================================
78282 +*/
78283 +VOID CntlWaitAuthProc(
78284 + IN PRTMP_ADAPTER pAd,
78285 + IN MLME_QUEUE_ELEM *Elem)
78286 +{
78287 + USHORT Reason;
78288 + MLME_ASSOC_REQ_STRUCT AssocReq;
78289 + MLME_AUTH_REQ_STRUCT AuthReq;
78290 +
78291 + if (Elem->MsgType == MT2_AUTH_CONF)
78292 + {
78293 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
78294 + if (Reason == MLME_SUCCESS)
78295 + {
78296 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
78297 + AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
78298 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
78299 +
78300 +#ifdef LEAP_SUPPORT
78301 + //
78302 + // Cisco Leap CCKM supported Re-association.
78303 + //
78304 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
78305 + {
78306 + //if CCKM is turn on , that's mean Fast Reauthentication
78307 + //Use CCKM Reassociation instead of normal association for Fast Roaming.
78308 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
78309 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
78310 +
78311 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
78312 + }
78313 + else
78314 +#endif // LEAP_SUPPORT //
78315 + {
78316 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
78317 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
78318 +
78319 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
78320 + }
78321 + }
78322 + else
78323 + {
78324 + // This fail may because of the AP already keep us in its MAC table without
78325 + // ageing-out. The previous authentication attempt must have let it remove us.
78326 + // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
78327 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));
78328 +#ifdef LEAP_SUPPORT
78329 + //Add AuthMode "LEAP" for CCX 1.X
78330 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
78331 + {
78332 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
78333 + }
78334 + else
78335 +#endif // LEAP_SUPPORT //
78336 + {
78337 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
78338 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
78339 + {
78340 + // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
78341 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
78342 + }
78343 + else
78344 + {
78345 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
78346 + }
78347 + }
78348 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
78349 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
78350 +
78351 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
78352 + }
78353 + }
78354 +}
78355 +
78356 +/*
78357 + ==========================================================================
78358 + Description:
78359 +
78360 + IRQL = DISPATCH_LEVEL
78361 +
78362 + ==========================================================================
78363 +*/
78364 +VOID CntlWaitAuthProc2(
78365 + IN PRTMP_ADAPTER pAd,
78366 + IN MLME_QUEUE_ELEM *Elem)
78367 +{
78368 + USHORT Reason;
78369 + MLME_ASSOC_REQ_STRUCT AssocReq;
78370 + MLME_AUTH_REQ_STRUCT AuthReq;
78371 +
78372 + if (Elem->MsgType == MT2_AUTH_CONF)
78373 + {
78374 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
78375 + if (Reason == MLME_SUCCESS)
78376 + {
78377 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
78378 + AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
78379 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
78380 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
78381 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
78382 +
78383 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
78384 + }
78385 + else
78386 + {
78387 +#ifdef LEAP_SUPPORT
78388 + // Process LEAP first, since it use different control variable
78389 + // We don't want to affect other poven operation
78390 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
78391 + {
78392 + // LEAP Auth not success, try next BSS
78393 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - *LEAP* AUTH FAIL, give up; try next BSS\n"));
78394 + DBGPRINT(RT_DEBUG_TRACE, ("Total match BSSID [=%d]\n", pAd->MlmeAux.SsidBssTab.BssNr));
78395 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78396 + pAd->MlmeAux.BssIdx++;
78397 + IterateOnBssTab(pAd);
78398 + }
78399 + else
78400 +#endif // LEAP_SUPPORT //
78401 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&
78402 + (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))
78403 + {
78404 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try OPEN system...\n"));
78405 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
78406 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
78407 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
78408 +
78409 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
78410 + }
78411 + else
78412 + {
78413 + // not success, try next BSS
78414 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, give up; try next BSS\n"));
78415 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????
78416 + pAd->MlmeAux.BssIdx++;
78417 + IterateOnBssTab(pAd);
78418 + }
78419 + }
78420 + }
78421 +}
78422 +
78423 +/*
78424 + ==========================================================================
78425 + Description:
78426 +
78427 + IRQL = DISPATCH_LEVEL
78428 +
78429 + ==========================================================================
78430 +*/
78431 +VOID CntlWaitAssocProc(
78432 + IN PRTMP_ADAPTER pAd,
78433 + IN MLME_QUEUE_ELEM *Elem)
78434 +{
78435 + USHORT Reason;
78436 +
78437 + if (Elem->MsgType == MT2_ASSOC_CONF)
78438 + {
78439 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
78440 + if (Reason == MLME_SUCCESS)
78441 + {
78442 + LinkUp(pAd, BSS_INFRA);
78443 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78444 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association successful on BSS #%ld\n",pAd->MlmeAux.BssIdx));
78445 +
78446 + if (pAd->CommonCfg.bWirelessEvent)
78447 + {
78448 + RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
78449 + }
78450 + }
78451 + else
78452 + {
78453 + // not success, try next BSS
78454 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association fails on BSS #%ld\n",pAd->MlmeAux.BssIdx));
78455 + pAd->MlmeAux.BssIdx++;
78456 + IterateOnBssTab(pAd);
78457 + }
78458 + }
78459 +}
78460 +
78461 +/*
78462 + ==========================================================================
78463 + Description:
78464 +
78465 + IRQL = DISPATCH_LEVEL
78466 +
78467 + ==========================================================================
78468 +*/
78469 +VOID CntlWaitReassocProc(
78470 + IN PRTMP_ADAPTER pAd,
78471 + IN MLME_QUEUE_ELEM *Elem)
78472 +{
78473 + USHORT Result;
78474 +
78475 + if (Elem->MsgType == MT2_REASSOC_CONF)
78476 + {
78477 + NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
78478 + if (Result == MLME_SUCCESS)
78479 + {
78480 + //
78481 + // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC
78482 + //
78483 + LinkUp(pAd, BSS_INFRA);
78484 +
78485 + // send wireless event - for association
78486 + if (pAd->CommonCfg.bWirelessEvent)
78487 + RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
78488 +
78489 +
78490 +#ifdef LEAP_SUPPORT
78491 + if (LEAP_CCKM_ON(pAd))
78492 + {
78493 + STA_PORT_SECURED(pAd);
78494 + pAd->StaCfg.WpaState = SS_FINISH;
78495 + }
78496 +#endif // LEAP_SUPPORT //
78497 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78498 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
78499 + }
78500 + else
78501 + {
78502 + // reassoc failed, try to pick next BSS in the BSS Table
78503 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
78504 + pAd->MlmeAux.RoamIdx++;
78505 + IterateOnBssTab2(pAd);
78506 + }
78507 + }
78508 +}
78509 +
78510 +
78511 +VOID AdhocTurnOnQos(
78512 + IN PRTMP_ADAPTER pAd)
78513 +{
78514 +#define AC0_DEF_TXOP 0
78515 +#define AC1_DEF_TXOP 0
78516 +#define AC2_DEF_TXOP 94
78517 +#define AC3_DEF_TXOP 47
78518 +
78519 + // Turn on QOs if use HT rate.
78520 + if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
78521 + {
78522 + pAd->CommonCfg.APEdcaParm.bValid = TRUE;
78523 + pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
78524 + pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
78525 + pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
78526 + pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
78527 +
78528 + pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
78529 + pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
78530 + pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
78531 + pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
78532 +
78533 + pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
78534 + pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
78535 + pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
78536 + pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
78537 +
78538 + pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
78539 + pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
78540 + pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
78541 + pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
78542 + }
78543 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
78544 +}
78545 +
78546 +/*
78547 + ==========================================================================
78548 + Description:
78549 +
78550 + IRQL = DISPATCH_LEVEL
78551 +
78552 + ==========================================================================
78553 +*/
78554 +VOID LinkUp(
78555 + IN PRTMP_ADAPTER pAd,
78556 + IN UCHAR BssType)
78557 +{
78558 + ULONG Now;
78559 + UINT32 Data;
78560 + BOOLEAN Cancelled;
78561 + UCHAR Value = 0, idx;
78562 + MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
78563 +
78564 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
78565 +
78566 + //
78567 + // ASSOC - DisassocTimeoutAction
78568 + // CNTL - Dis-associate successful
78569 + // !!! LINK DOWN !!!
78570 + // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
78571 + //
78572 + // To prevent DisassocTimeoutAction to call Link down after we link up,
78573 + // cancel the DisassocTimer no matter what it start or not.
78574 + //
78575 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
78576 +
78577 + COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
78578 +
78579 +#ifdef DOT11_N_SUPPORT
78580 + COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
78581 +#endif // DOT11_N_SUPPORT //
78582 + // It's quite difficult to tell if a newly added KEY is WEP or CKIP until a new BSS
78583 + // is formed (either ASSOC/RE-ASSOC done or IBSS started. LinkUP should be a safe place
78584 + // to examine if cipher algorithm switching is required.
78585 + //rt2860b. Don't know why need this
78586 + SwitchBetweenWepAndCkip(pAd);
78587 +
78588 +
78589 + if (BssType == BSS_ADHOC)
78590 + {
78591 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
78592 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
78593 +
78594 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
78595 + // No carrier detection when adhoc
78596 + // CarrierDetectionStop(pAd);
78597 + pAd->CommonCfg.CarrierDetect.CD_State = CD_NORMAL;
78598 +#endif // CARRIER_DETECTION_SUPPORT //
78599 +
78600 +#ifdef DOT11_N_SUPPORT
78601 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
78602 + AdhocTurnOnQos(pAd);
78603 +#endif // DOT11_N_SUPPORT //
78604 +
78605 + DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));
78606 + }
78607 + else
78608 + {
78609 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
78610 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
78611 +
78612 + DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n" ));
78613 + }
78614 +
78615 + // 3*3
78616 + // reset Tx beamforming bit
78617 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
78618 + Value &= (~0x01);
78619 + Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
78620 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
78621 +
78622 +#ifdef DOT11_N_SUPPORT
78623 + // Change to AP channel
78624 + if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
78625 + {
78626 + // Must using 40MHz.
78627 + pAd->CommonCfg.BBPCurrentBW = BW_40;
78628 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
78629 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
78630 +
78631 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
78632 + Value &= (~0x18);
78633 + Value |= 0x10;
78634 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
78635 +
78636 + // RX : control channel at lower
78637 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
78638 + Value &= (~0x20);
78639 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
78640 +
78641 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
78642 + Data &= 0xfffffffe;
78643 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
78644 +
78645 + if (pAd->MACVersion == 0x28600100)
78646 + {
78647 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
78648 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
78649 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
78650 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
78651 + }
78652 +
78653 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
78654 + }
78655 + else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
78656 + {
78657 + // Must using 40MHz.
78658 + pAd->CommonCfg.BBPCurrentBW = BW_40;
78659 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
78660 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
78661 +
78662 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
78663 + Value &= (~0x18);
78664 + Value |= 0x10;
78665 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
78666 +
78667 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
78668 + Data |= 0x1;
78669 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
78670 +
78671 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
78672 + Value |= (0x20);
78673 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
78674 +
78675 + if (pAd->MACVersion == 0x28600100)
78676 + {
78677 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
78678 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
78679 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
78680 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
78681 + }
78682 +
78683 + DBGPRINT(RT_DEBUG_TRACE, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
78684 + }
78685 + else
78686 +#endif // DOT11_N_SUPPORT //
78687 + {
78688 + pAd->CommonCfg.BBPCurrentBW = BW_20;
78689 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
78690 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
78691 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
78692 +
78693 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
78694 + Value &= (~0x18);
78695 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
78696 +
78697 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
78698 + Data &= 0xfffffffe;
78699 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
78700 +
78701 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
78702 + Value &= (~0x20);
78703 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
78704 +
78705 + if (pAd->MACVersion == 0x28600100)
78706 + {
78707 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
78708 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
78709 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
78710 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
78711 + }
78712 +
78713 + DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n" ));
78714 + }
78715 +
78716 + RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
78717 + //
78718 + // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission
78719 + //
78720 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
78721 +
78722 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
78723 + BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
78724 +
78725 +#ifdef DOT11_N_SUPPORT
78726 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (Density =%d, )\n", pAd->MacTab.Content[BSSID_WCID].MpduDensity));
78727 +#endif // DOT11_N_SUPPORT //
78728 +
78729 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
78730 +
78731 + AsicSetSlotTime(pAd, TRUE);
78732 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
78733 +
78734 + // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit
78735 + AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, FALSE);
78736 +
78737 +#ifdef DOT11_N_SUPPORT
78738 + if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))
78739 + {
78740 + // Update HT protectionfor based on AP's operating mode.
78741 + if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
78742 + {
78743 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
78744 + }
78745 + else
78746 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
78747 + }
78748 +#endif // DOT11_N_SUPPORT //
78749 +
78750 + NdisZeroMemory(&pAd->DrsCounters, sizeof(COUNTER_DRS));
78751 +
78752 + NdisGetSystemUpTime(&Now);
78753 + pAd->StaCfg.LastBeaconRxTime = Now; // last RX timestamp
78754 +
78755 + if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
78756 + CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo))
78757 + {
78758 + MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
78759 + }
78760 +
78761 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
78762 +
78763 + if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)
78764 + {
78765 +#ifdef DFS_SUPPORT
78766 + RadarDetectionStop(pAd);
78767 +#endif // DFS_SUPPORT //
78768 + }
78769 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
78770 +
78771 + if (BssType == BSS_ADHOC)
78772 + {
78773 + MakeIbssBeacon(pAd);
78774 + if ((pAd->CommonCfg.Channel > 14)
78775 + && (pAd->CommonCfg.bIEEE80211H == 1)
78776 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
78777 + {
78778 + ; //Do nothing
78779 + }
78780 + else
78781 + {
78782 + AsicEnableIbssSync(pAd);
78783 + }
78784 +
78785 + // In ad hoc mode, use MAC table from index 1.
78786 + // 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.
78787 + RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
78788 + RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
78789 +
78790 + // If WEP is enabled, add key material and cipherAlg into Asic
78791 + // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
78792 +
78793 + if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
78794 + {
78795 + PUCHAR Key;
78796 + UCHAR CipherAlg;
78797 +
78798 + for (idx=0; idx < SHARE_KEY_NUM; idx++)
78799 + {
78800 + CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
78801 + Key = pAd->SharedKey[BSS0][idx].Key;
78802 +
78803 + if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
78804 + {
78805 + // Set key material and cipherAlg to Asic
78806 + AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
78807 +
78808 + if (idx == pAd->StaCfg.DefaultKeyId)
78809 + {
78810 + // Update WCID attribute table and IVEIV table for this group key table
78811 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
78812 + }
78813 + }
78814 +
78815 +
78816 + }
78817 + }
78818 + // If WPANone is enabled, add key material and cipherAlg into Asic
78819 + // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
78820 + else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
78821 + {
78822 + pAd->StaCfg.DefaultKeyId = 0; // always be zero
78823 +
78824 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
78825 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
78826 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
78827 +
78828 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
78829 + {
78830 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
78831 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
78832 + }
78833 +
78834 + // Decide its ChiperAlg
78835 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
78836 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
78837 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
78838 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
78839 + else
78840 + {
78841 + DBGPRINT(RT_DEBUG_TRACE, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd->StaCfg.PairCipher));
78842 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
78843 + }
78844 +
78845 + // Set key material and cipherAlg to Asic
78846 + AsicAddSharedKeyEntry(pAd,
78847 + BSS0,
78848 + 0,
78849 + pAd->SharedKey[BSS0][0].CipherAlg,
78850 + pAd->SharedKey[BSS0][0].Key,
78851 + pAd->SharedKey[BSS0][0].TxMic,
78852 + pAd->SharedKey[BSS0][0].RxMic);
78853 +
78854 + // Update WCID attribute table and IVEIV table for this group key table
78855 + RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pAd->SharedKey[BSS0][0].CipherAlg, NULL);
78856 +
78857 + }
78858 +
78859 + }
78860 + else // BSS_INFRA
78861 + {
78862 + // Check the new SSID with last SSID
78863 + while (Cancelled == TRUE)
78864 + {
78865 + if (pAd->CommonCfg.LastSsidLen == pAd->CommonCfg.SsidLen)
78866 + {
78867 + if (RTMPCompareMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen) == 0)
78868 + {
78869 + // Link to the old one no linkdown is required.
78870 + break;
78871 + }
78872 + }
78873 + // Send link down event before set to link up
78874 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
78875 + RTMP_IndicateMediaState(pAd);
78876 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
78877 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
78878 + break;
78879 + }
78880 +
78881 + //
78882 + // On WPA mode, Remove All Keys if not connect to the last BSSID
78883 + // Key will be set after 4-way handshake.
78884 + //
78885 + if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
78886 + {
78887 + ULONG IV;
78888 +
78889 + // Remove all WPA keys
78890 + RTMPWPARemoveAllKeys(pAd);
78891 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
78892 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
78893 +
78894 + // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP
78895 + // If IV related values are too large in GroupMsg2, AP would ignore this message.
78896 + IV = 0;
78897 + IV |= (pAd->StaCfg.DefaultKeyId << 30);
78898 + AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
78899 + }
78900 + // NOTE:
78901 + // the decision of using "short slot time" or not may change dynamically due to
78902 + // new STA association to the AP. so we have to decide that upon parsing BEACON, not here
78903 +
78904 + // NOTE:
78905 + // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically
78906 + // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here
78907 +
78908 + ComposePsPoll(pAd);
78909 + ComposeNullFrame(pAd);
78910 +
78911 + AsicEnableBssSync(pAd);
78912 +
78913 + // Add BSSID to WCID search table
78914 + AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
78915 +
78916 + NdisAcquireSpinLock(&pAd->MacTabLock);
78917 + // add this BSSID entry into HASH table
78918 + {
78919 + UCHAR HashIdx;
78920 +
78921 + //pEntry = &pAd->MacTab.Content[BSSID_WCID];
78922 + HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
78923 + if (pAd->MacTab.Hash[HashIdx] == NULL)
78924 + {
78925 + pAd->MacTab.Hash[HashIdx] = pEntry;
78926 + }
78927 + else
78928 + {
78929 + pCurrEntry = pAd->MacTab.Hash[HashIdx];
78930 + while (pCurrEntry->pNext != NULL)
78931 + pCurrEntry = pCurrEntry->pNext;
78932 + pCurrEntry->pNext = pEntry;
78933 + }
78934 + }
78935 + NdisReleaseSpinLock(&pAd->MacTabLock);
78936 +
78937 +
78938 + // If WEP is enabled, add paiewise and shared key
78939 +#ifdef WPA_SUPPLICANT_SUPPORT
78940 + if (((pAd->StaCfg.WpaSupplicantUP)&&
78941 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&
78942 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
78943 + ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&
78944 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))
78945 +#else
78946 + if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
78947 +#endif // WPA_SUPPLICANT_SUPPORT //
78948 + {
78949 + PUCHAR Key;
78950 + UCHAR CipherAlg;
78951 +
78952 + for (idx=0; idx < SHARE_KEY_NUM; idx++)
78953 + {
78954 + CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
78955 + Key = pAd->SharedKey[BSS0][idx].Key;
78956 +
78957 + if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
78958 + {
78959 + // Set key material and cipherAlg to Asic
78960 + AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
78961 +
78962 + if (idx == pAd->StaCfg.DefaultKeyId)
78963 + {
78964 + // Assign group key info
78965 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
78966 +
78967 + // Assign pairwise key info
78968 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);
78969 + }
78970 + }
78971 + }
78972 + }
78973 +
78974 + // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode
78975 + // should wait until at least 2 active nodes in this BSSID.
78976 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
78977 +
78978 + // For GUI ++
78979 + if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
78980 + {
78981 + pAd->IndicateMediaState = NdisMediaStateConnected;
78982 + pAd->ExtraInfo = GENERAL_LINK_UP;
78983 + RTMP_IndicateMediaState(pAd);
78984 + }
78985 + // --
78986 +
78987 + // Add BSSID in my MAC Table.
78988 + NdisAcquireSpinLock(&pAd->MacTabLock);
78989 + RTMPMoveMemory(pAd->MacTab.Content[BSSID_WCID].Addr, pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
78990 + pAd->MacTab.Content[BSSID_WCID].Aid = BSSID_WCID;
78991 + pAd->MacTab.Content[BSSID_WCID].pAd = pAd;
78992 + pAd->MacTab.Content[BSSID_WCID].ValidAsCLI = TRUE; //Although this is bssid..still set ValidAsCl
78993 + pAd->MacTab.Size = 1; // infra mode always set MACtab size =1.
78994 + pAd->MacTab.Content[BSSID_WCID].Sst = SST_ASSOC;
78995 + pAd->MacTab.Content[BSSID_WCID].AuthState = SST_ASSOC;
78996 + pAd->MacTab.Content[BSSID_WCID].WepStatus = pAd->StaCfg.WepStatus;
78997 + NdisReleaseSpinLock(&pAd->MacTabLock);
78998 +
78999 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
79000 + pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
79001 +
79002 + MlmeUpdateTxRates(pAd, TRUE, BSS0);
79003 +#ifdef DOT11_N_SUPPORT
79004 + MlmeUpdateHtTxRates(pAd, BSS0);
79005 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));
79006 +#endif // DOT11_N_SUPPORT //
79007 +
79008 + //
79009 + // Report Adjacent AP report.
79010 + //
79011 +#ifdef LEAP_SUPPORT
79012 + CCXAdjacentAPReport(pAd);
79013 +#endif // LEAP_SUPPORT //
79014 +
79015 + if (pAd->CommonCfg.bAggregationCapable)
79016 + {
79017 + if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)
79018 + {
79019 +
79020 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
79021 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79022 + RTMPSetPiggyBack(pAd, TRUE);
79023 + DBGPRINT(RT_DEBUG_TRACE, ("Turn on Piggy-Back\n"));
79024 + }
79025 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
79026 + {
79027 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79028 + }
79029 + }
79030 +
79031 + if (pAd->MlmeAux.APRalinkIe != 0x0)
79032 + {
79033 +#ifdef DOT11_N_SUPPORT
79034 + if (CLIENT_STATUS_TEST_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RDG_CAPABLE))
79035 + {
79036 + AsicEnableRDG(pAd);
79037 + }
79038 +#endif // DOT11_N_SUPPORT //
79039 + OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
79040 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
79041 + }
79042 + else
79043 + {
79044 + OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
79045 + CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
79046 + }
79047 + }
79048 +
79049 +#ifdef DOT11_N_SUPPORT
79050 + 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));
79051 +#endif // DOT11_N_SUPPORT //
79052 +
79053 + // Set LED
79054 + RTMPSetLED(pAd, LED_LINK_UP);
79055 +
79056 + pAd->Mlme.PeriodicRound = 0;
79057 + pAd->Mlme.OneSecPeriodicRound = 0;
79058 + pAd->bConfigChanged = FALSE; // Reset config flag
79059 + pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
79060 +
79061 + // Set asic auto fall back
79062 + {
79063 + PUCHAR pTable;
79064 + UCHAR TableSize = 0;
79065 +
79066 + MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], &pTable, &TableSize, &pAd->CommonCfg.TxRateIndex);
79067 + AsicUpdateAutoFallBackTable(pAd, pTable);
79068 + }
79069 +
79070 + NdisAcquireSpinLock(&pAd->MacTabLock);
79071 + pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
79072 + pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
79073 + if (pAd->StaCfg.bAutoTxRateSwitch == FALSE)
79074 + {
79075 + pEntry->bAutoTxRateSwitch = FALSE;
79076 +#ifdef DOT11_N_SUPPORT
79077 + if (pEntry->HTPhyMode.field.MCS == 32)
79078 + pEntry->HTPhyMode.field.ShortGI = GI_800;
79079 +
79080 + if ((pEntry->HTPhyMode.field.MCS > MCS_7) || (pEntry->HTPhyMode.field.MCS == 32))
79081 + pEntry->HTPhyMode.field.STBC = STBC_NONE;
79082 +#endif // DOT11_N_SUPPORT //
79083 + // If the legacy mode is set, overwrite the transmit setting of this entry.
79084 + if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
79085 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
79086 + }
79087 + else
79088 + pEntry->bAutoTxRateSwitch = TRUE;
79089 + NdisReleaseSpinLock(&pAd->MacTabLock);
79090 +
79091 + // Let Link Status Page display first initial rate.
79092 + pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
79093 + // Select DAC according to HT or Legacy
79094 + if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00)
79095 + {
79096 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
79097 + Value &= (~0x18);
79098 + if (pAd->Antenna.field.TxPath == 2)
79099 + {
79100 + Value |= 0x10;
79101 + }
79102 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
79103 + }
79104 + else
79105 + {
79106 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
79107 + Value &= (~0x18);
79108 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
79109 + }
79110 +
79111 +#ifdef DOT11_N_SUPPORT
79112 + if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
79113 + {
79114 + }
79115 + else if (pEntry->MaxRAmpduFactor == 0)
79116 + {
79117 + // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.
79118 + // Because our Init value is 1 at MACRegTable.
79119 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
79120 + }
79121 +#endif // DOT11_N_SUPPORT //
79122 +
79123 + // Patch for Marvel AP to gain high throughput
79124 + // Need to set as following,
79125 + // 1. Set txop in register-EDCA_AC0_CFG as 0x60
79126 + // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero
79127 + // 3. PBF_MAX_PCNT as 0x1F3FBF9F
79128 + // 4. kick per two packets when dequeue
79129 + //
79130 + // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable
79131 + //
79132 + // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.
79133 +#ifdef DOT11_N_SUPPORT
79134 + if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
79135 + || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))
79136 + {
79137 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
79138 + Data &= 0xFFFFFF00;
79139 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
79140 +
79141 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
79142 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
79143 + }
79144 + else
79145 +#endif // DOT11_N_SUPPORT //
79146 + if (pAd->CommonCfg.bEnableTxBurst)
79147 + {
79148 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
79149 + Data &= 0xFFFFFF00;
79150 + Data |= 0x60;
79151 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
79152 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
79153 +
79154 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
79155 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
79156 + }
79157 + else
79158 + {
79159 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
79160 + Data &= 0xFFFFFF00;
79161 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
79162 +
79163 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
79164 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
79165 + }
79166 +
79167 +#ifdef DOT11_N_SUPPORT
79168 + // Re-check to turn on TX burst or not.
79169 + if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) && ((STA_WEP_ON(pAd))||(STA_TKIP_ON(pAd))))
79170 + {
79171 + pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
79172 + if (pAd->CommonCfg.bEnableTxBurst)
79173 + {
79174 + UINT32 MACValue = 0;
79175 + // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.
79176 + // I didn't change PBF_MAX_PCNT setting.
79177 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
79178 + MACValue &= 0xFFFFFF00;
79179 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
79180 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
79181 + }
79182 + }
79183 + else
79184 + {
79185 + pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
79186 + }
79187 +#endif // DOT11_N_SUPPORT //
79188 +
79189 + pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
79190 + COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
79191 + DBGPRINT(RT_DEBUG_TRACE, ("!!!pAd->bNextDisableRxBA= %d \n", pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
79192 + // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap
79193 + // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.
79194 + // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.
79195 +
79196 + if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled)
79197 + {
79198 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
79199 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
79200 + }
79201 +
79202 + NdisAcquireSpinLock(&pAd->MacTabLock);
79203 + pEntry->PortSecured = pAd->StaCfg.PortSecured;
79204 + NdisReleaseSpinLock(&pAd->MacTabLock);
79205 +
79206 + //
79207 + // Patch Atheros AP TX will breakdown issue.
79208 + // AP Model: DLink DWL-8200AP
79209 + //
79210 + if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && STA_TKIP_ON(pAd))
79211 + {
79212 + RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
79213 + }
79214 + else
79215 + {
79216 + RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
79217 + }
79218 +
79219 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
79220 +
79221 +
79222 +#ifdef DOT11_N_SUPPORT
79223 +#ifdef DOT11N_DRAFT3
79224 + if ((pAd->CommonCfg.BACapability.field.b2040CoexistScanSup) && (pAd->CommonCfg.Channel <= 11))
79225 + {
79226 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SCAN_2040);
79227 + BuildEffectedChannelList(pAd);
79228 + }
79229 +#endif // DOT11N_DRAFT3 //
79230 +#endif // DOT11_N_SUPPORT //
79231 +}
79232 +
79233 +/*
79234 + ==========================================================================
79235 +
79236 + Routine Description:
79237 + Disconnect current BSSID
79238 +
79239 + Arguments:
79240 + pAd - Pointer to our adapter
79241 + IsReqFromAP - Request from AP
79242 +
79243 + Return Value:
79244 + None
79245 +
79246 + IRQL = DISPATCH_LEVEL
79247 +
79248 + Note:
79249 + We need more information to know it's this requst from AP.
79250 + If yes! we need to do extra handling, for example, remove the WPA key.
79251 + Otherwise on 4-way handshaking will faied, since the WPA key didn't be
79252 + remove while auto reconnect.
79253 + Disconnect request from AP, it means we will start afresh 4-way handshaking
79254 + on WPA mode.
79255 +
79256 + ==========================================================================
79257 +*/
79258 +VOID LinkDown(
79259 + IN PRTMP_ADAPTER pAd,
79260 + IN BOOLEAN IsReqFromAP)
79261 +{
79262 + UCHAR i, ByteValue = 0;
79263 +
79264 + // Do nothing if monitor mode is on
79265 + if (MONITOR_ON(pAd))
79266 + return;
79267 +
79268 +#ifdef RALINK_ATE
79269 + // Nothing to do in ATE mode.
79270 + if (ATE_ON(pAd))
79271 + return;
79272 +#endif // RALINK_ATE //
79273 +
79274 + if (pAd->CommonCfg.bWirelessEvent)
79275 + {
79276 + RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
79277 + }
79278 +
79279 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
79280 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79281 +
79282 + if (ADHOC_ON(pAd)) // Adhoc mode link down
79283 + {
79284 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
79285 +
79286 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
79287 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
79288 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
79289 + RTMP_IndicateMediaState(pAd);
79290 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
79291 + BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
79292 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));
79293 + }
79294 + else // Infra structure mode
79295 + {
79296 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
79297 +
79298 +#ifdef QOS_DLS_SUPPORT
79299 + // DLS tear down frame must be sent before link down
79300 + // send DLS-TEAR_DOWN message
79301 + if (pAd->CommonCfg.bDLSCapable)
79302 + {
79303 + // tear down local dls table entry
79304 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
79305 + {
79306 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
79307 + {
79308 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
79309 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
79310 + }
79311 + }
79312 +
79313 + // tear down peer dls table entry
79314 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
79315 + {
79316 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
79317 + {
79318 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
79319 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
79320 + }
79321 + }
79322 + }
79323 +#endif // QOS_DLS_SUPPORT //
79324 +
79325 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
79326 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
79327 +
79328 + // Saved last SSID for linkup comparison
79329 + pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
79330 + NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen);
79331 + COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
79332 + if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)
79333 + {
79334 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
79335 + RTMP_IndicateMediaState(pAd);
79336 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
79337 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
79338 + pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
79339 + }
79340 + else
79341 + {
79342 + //
79343 + // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.
79344 + // Otherwise lost beacon or receive De-Authentication from AP,
79345 + // then we should delete BSSID from BssTable.
79346 + // If we don't delete from entry, roaming will fail.
79347 + //
79348 + BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
79349 + }
79350 +
79351 + // restore back to -
79352 + // 1. long slot (20 us) or short slot (9 us) time
79353 + // 2. turn on/off RTS/CTS and/or CTS-to-self protection
79354 + // 3. short preamble
79355 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
79356 +
79357 + if (pAd->StaCfg.CCXAdjacentAPReportFlag == TRUE)
79358 + {
79359 + //
79360 + // Record current AP's information.
79361 + // for later used reporting Adjacent AP report.
79362 + //
79363 + pAd->StaCfg.CCXAdjacentAPChannel = pAd->CommonCfg.Channel;
79364 + pAd->StaCfg.CCXAdjacentAPSsidLen = pAd->CommonCfg.SsidLen;
79365 + NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);
79366 + COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);
79367 + }
79368 +
79369 +#ifdef EXT_BUILD_CHANNEL_LIST
79370 + // Country IE of the AP will be evaluated and will be used.
79371 + if (pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None)
79372 + {
79373 + NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pAd->StaCfg.StaOriCountryCode[0], 2);
79374 + pAd->CommonCfg.Geography = pAd->StaCfg.StaOriGeography;
79375 + BuildChannelListEx(pAd);
79376 + }
79377 +#endif // EXT_BUILD_CHANNEL_LIST //
79378 +
79379 + }
79380 +
79381 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
79382 + {
79383 + if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
79384 + MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, pAd->MacTab.Content[i].Addr);
79385 + }
79386 +
79387 + pAd->StaCfg.CCXQosECWMin = 4;
79388 + pAd->StaCfg.CCXQosECWMax = 10;
79389 +
79390 + AsicSetSlotTime(pAd, TRUE); //FALSE);
79391 + AsicSetEdcaParm(pAd, NULL);
79392 +
79393 + // Set LED
79394 + RTMPSetLED(pAd, LED_LINK_DOWN);
79395 + pAd->LedIndicatorStregth = 0xF0;
79396 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
79397 +
79398 + AsicDisableSync(pAd);
79399 +
79400 + pAd->Mlme.PeriodicRound = 0;
79401 + pAd->Mlme.OneSecPeriodicRound = 0;
79402 +
79403 + if (pAd->StaCfg.BssType == BSS_INFRA)
79404 + {
79405 + // Remove StaCfg Information after link down
79406 + NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
79407 + NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
79408 + pAd->CommonCfg.SsidLen = 0;
79409 + }
79410 +#ifdef DOT11_N_SUPPORT
79411 + NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(HT_CAPABILITY_IE));
79412 + NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(ADD_HT_INFO_IE));
79413 + pAd->MlmeAux.HtCapabilityLen = 0;
79414 + pAd->MlmeAux.NewExtChannelOffset = 0xff;
79415 +#endif // DOT11_N_SUPPORT //
79416 +
79417 + // Reset WPA-PSK state. Only reset when supplicant enabled
79418 + if (pAd->StaCfg.WpaState != SS_NOTUSE)
79419 + {
79420 + pAd->StaCfg.WpaState = SS_START;
79421 + // Clear Replay counter
79422 + NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
79423 +
79424 +#ifdef QOS_DLS_SUPPORT
79425 + if (pAd->CommonCfg.bDLSCapable)
79426 + NdisZeroMemory(pAd->StaCfg.DlsReplayCounter, 8);
79427 +#endif // QOS_DLS_SUPPORT //
79428 + }
79429 +
79430 +
79431 + //
79432 + // if link down come from AP, we need to remove all WPA keys on WPA mode.
79433 + // otherwise will cause 4-way handshaking failed, since the WPA key not empty.
79434 + //
79435 + if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
79436 + {
79437 + // Remove all WPA keys
79438 + RTMPWPARemoveAllKeys(pAd);
79439 + }
79440 +
79441 + // 802.1x port control
79442 +#ifdef WPA_SUPPLICANT_SUPPORT
79443 + // Prevent clear PortSecured here with static WEP
79444 + // NetworkManger set security policy first then set SSID to connect AP.
79445 + if (pAd->StaCfg.WpaSupplicantUP &&
79446 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
79447 + (pAd->StaCfg.IEEE8021X == FALSE))
79448 + {
79449 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
79450 + }
79451 + else
79452 +#endif // WPA_SUPPLICANT_SUPPORT //
79453 + {
79454 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
79455 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
79456 + }
79457 +
79458 + NdisAcquireSpinLock(&pAd->MacTabLock);
79459 + pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
79460 + NdisReleaseSpinLock(&pAd->MacTabLock);
79461 +
79462 + pAd->StaCfg.MicErrCnt = 0;
79463 +
79464 + // Turn off Ckip control flag
79465 + pAd->StaCfg.bCkipOn = FALSE;
79466 + pAd->StaCfg.CCXEnable = FALSE;
79467 +
79468 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
79469 + // Update extra information to link is up
79470 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
79471 +
79472 + //pAd->StaCfg.AdhocBOnlyJoined = FALSE;
79473 + //pAd->StaCfg.AdhocBGJoined = FALSE;
79474 + //pAd->StaCfg.Adhoc20NJoined = FALSE;
79475 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
79476 +
79477 + // Reset the Current AP's IP address
79478 + NdisZeroMemory(pAd->StaCfg.AironetIPAddress, 4);
79479 +#ifdef RT2870
79480 + pAd->bUsbTxBulkAggre = FALSE;
79481 +#endif // RT2870 //
79482 +
79483 + // Clean association information
79484 + NdisZeroMemory(&pAd->StaCfg.AssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
79485 + pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
79486 + pAd->StaCfg.ReqVarIELen = 0;
79487 + pAd->StaCfg.ResVarIELen = 0;
79488 +
79489 + //
79490 + // Reset RSSI value after link down
79491 + //
79492 + pAd->StaCfg.RssiSample.AvgRssi0 = 0;
79493 + pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
79494 + pAd->StaCfg.RssiSample.AvgRssi1 = 0;
79495 + pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
79496 + pAd->StaCfg.RssiSample.AvgRssi2 = 0;
79497 + pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
79498 +
79499 + // Restore MlmeRate
79500 + pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
79501 + pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
79502 +
79503 +#ifdef DOT11_N_SUPPORT
79504 + //
79505 + // After Link down, reset piggy-back setting in ASIC. Disable RDG.
79506 + //
79507 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
79508 + {
79509 + pAd->CommonCfg.BBPCurrentBW = BW_20;
79510 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
79511 + ByteValue &= (~0x18);
79512 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
79513 + }
79514 +#endif // DOT11_N_SUPPORT //
79515 + // Reset DAC
79516 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
79517 + ByteValue &= (~0x18);
79518 + if (pAd->Antenna.field.TxPath == 2)
79519 + {
79520 + ByteValue |= 0x10;
79521 + }
79522 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
79523 +
79524 + RTMPSetPiggyBack(pAd,FALSE);
79525 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
79526 +
79527 +#ifdef DOT11_N_SUPPORT
79528 + pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
79529 +#endif // DOT11_N_SUPPORT //
79530 +
79531 + // Restore all settings in the following.
79532 + AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);
79533 + AsicDisableRDG(pAd);
79534 + pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
79535 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
79536 +
79537 +#ifdef DOT11_N_SUPPORT
79538 +#ifdef DOT11N_DRAFT3
79539 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SCAN_2040);
79540 + pAd->CommonCfg.BSSCoexist2040.word = 0;
79541 + TriEventInit(pAd);
79542 + for (i = 0; i < (pAd->ChannelListNum - 1); i++)
79543 + {
79544 + pAd->ChannelList[i].bEffectedChannel = FALSE;
79545 + }
79546 +#endif // DOT11N_DRAFT3 //
79547 +#endif // DOT11_N_SUPPORT //
79548 +
79549 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
79550 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
79551 +
79552 +#ifdef WPA_SUPPLICANT_SUPPORT
79553 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
79554 + if (pAd->StaCfg.WpaSupplicantUP) {
79555 + union iwreq_data wrqu;
79556 + //send disassociate event to wpa_supplicant
79557 + memset(&wrqu, 0, sizeof(wrqu));
79558 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
79559 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
79560 + }
79561 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
79562 +#endif // WPA_SUPPLICANT_SUPPORT //
79563 +
79564 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
79565 + {
79566 + union iwreq_data wrqu;
79567 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
79568 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
79569 + }
79570 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
79571 +}
79572 +
79573 +/*
79574 + ==========================================================================
79575 + Description:
79576 +
79577 + IRQL = DISPATCH_LEVEL
79578 +
79579 + ==========================================================================
79580 +*/
79581 +VOID IterateOnBssTab(
79582 + IN PRTMP_ADAPTER pAd)
79583 +{
79584 + MLME_START_REQ_STRUCT StartReq;
79585 + MLME_JOIN_REQ_STRUCT JoinReq;
79586 + ULONG BssIdx;
79587 +
79588 + // Change the wepstatus to original wepstatus
79589 + pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
79590 + pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
79591 + pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
79592 +
79593 + BssIdx = pAd->MlmeAux.BssIdx;
79594 + if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)
79595 + {
79596 + // Check cipher suite, AP must have more secured cipher than station setting
79597 + // Set the Pairwise and Group cipher to match the intended AP setting
79598 + // We can only connect to AP with less secured cipher setting
79599 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
79600 + {
79601 + pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;
79602 +
79603 + if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)
79604 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;
79605 + else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
79606 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;
79607 + else // There is no PairCipher Aux, downgrade our capability to TKIP
79608 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
79609 + }
79610 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
79611 + {
79612 + pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;
79613 +
79614 + if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)
79615 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;
79616 + else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
79617 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;
79618 + else // There is no PairCipher Aux, downgrade our capability to TKIP
79619 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
79620 +
79621 + // RSN capability
79622 + pAd->StaCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;
79623 + }
79624 +
79625 + // Set Mix cipher flag
79626 + pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
79627 + if (pAd->StaCfg.bMixCipher == TRUE)
79628 + {
79629 + // If mix cipher, re-build RSNIE
79630 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
79631 + }
79632 +
79633 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr));
79634 + JoinParmFill(pAd, &JoinReq, BssIdx);
79635 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT),
79636 + &JoinReq);
79637 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
79638 + }
79639 + else if (pAd->StaCfg.BssType == BSS_ADHOC)
79640 + {
79641 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
79642 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
79643 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
79644 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
79645 + }
79646 + else // no more BSS
79647 + {
79648 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All roaming failed, stay @ ch #%d\n", pAd->CommonCfg.Channel));
79649 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
79650 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
79651 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79652 + }
79653 +}
79654 +
79655 +// for re-association only
79656 +// IRQL = DISPATCH_LEVEL
79657 +VOID IterateOnBssTab2(
79658 + IN PRTMP_ADAPTER pAd)
79659 +{
79660 + MLME_REASSOC_REQ_STRUCT ReassocReq;
79661 + ULONG BssIdx;
79662 + BSS_ENTRY *pBss;
79663 +
79664 + BssIdx = pAd->MlmeAux.RoamIdx;
79665 + pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
79666 +
79667 + if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)
79668 + {
79669 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr));
79670 +
79671 + AsicSwitchChannel(pAd, pBss->Channel, FALSE);
79672 + AsicLockChannel(pAd, pBss->Channel);
79673 +
79674 + // reassociate message has the same structure as associate message
79675 + AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,
79676 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
79677 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
79678 + sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);
79679 +
79680 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
79681 + }
79682 + else // no more BSS
79683 + {
79684 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All fast roaming failed, back to ch #%d\n",pAd->CommonCfg.Channel));
79685 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
79686 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
79687 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79688 + }
79689 +}
79690 +
79691 +/*
79692 + ==========================================================================
79693 + Description:
79694 +
79695 + IRQL = DISPATCH_LEVEL
79696 +
79697 + ==========================================================================
79698 +*/
79699 +VOID JoinParmFill(
79700 + IN PRTMP_ADAPTER pAd,
79701 + IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
79702 + IN ULONG BssIdx)
79703 +{
79704 + JoinReq->BssIdx = BssIdx;
79705 +}
79706 +
79707 +/*
79708 + ==========================================================================
79709 + Description:
79710 +
79711 + IRQL = DISPATCH_LEVEL
79712 +
79713 + ==========================================================================
79714 +*/
79715 +VOID ScanParmFill(
79716 + IN PRTMP_ADAPTER pAd,
79717 + IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
79718 + IN CHAR Ssid[],
79719 + IN UCHAR SsidLen,
79720 + IN UCHAR BssType,
79721 + IN UCHAR ScanType)
79722 +{
79723 + NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
79724 + ScanReq->SsidLen = SsidLen;
79725 + NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
79726 + ScanReq->BssType = BssType;
79727 + ScanReq->ScanType = ScanType;
79728 +}
79729 +
79730 +#ifdef QOS_DLS_SUPPORT
79731 +/*
79732 + ==========================================================================
79733 + Description:
79734 +
79735 + IRQL = DISPATCH_LEVEL
79736 +
79737 + ==========================================================================
79738 +*/
79739 +VOID DlsParmFill(
79740 + IN PRTMP_ADAPTER pAd,
79741 + IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
79742 + IN PRT_802_11_DLS pDls,
79743 + IN USHORT reason)
79744 +{
79745 + pDlsReq->pDLS = pDls;
79746 + pDlsReq->Reason = reason;
79747 +}
79748 +#endif // QOS_DLS_SUPPORT //
79749 +
79750 +/*
79751 + ==========================================================================
79752 + Description:
79753 +
79754 + IRQL = DISPATCH_LEVEL
79755 +
79756 + ==========================================================================
79757 +*/
79758 +VOID StartParmFill(
79759 + IN PRTMP_ADAPTER pAd,
79760 + IN OUT MLME_START_REQ_STRUCT *StartReq,
79761 + IN CHAR Ssid[],
79762 + IN UCHAR SsidLen)
79763 +{
79764 + ASSERT(SsidLen <= MAX_LEN_OF_SSID);
79765 + NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
79766 + StartReq->SsidLen = SsidLen;
79767 +}
79768 +
79769 +/*
79770 + ==========================================================================
79771 + Description:
79772 +
79773 + IRQL = DISPATCH_LEVEL
79774 +
79775 + ==========================================================================
79776 +*/
79777 +VOID AuthParmFill(
79778 + IN PRTMP_ADAPTER pAd,
79779 + IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
79780 + IN PUCHAR pAddr,
79781 + IN USHORT Alg)
79782 +{
79783 + COPY_MAC_ADDR(AuthReq->Addr, pAddr);
79784 + AuthReq->Alg = Alg;
79785 + AuthReq->Timeout = AUTH_TIMEOUT;
79786 +}
79787 +
79788 +/*
79789 + ==========================================================================
79790 + Description:
79791 +
79792 + IRQL = DISPATCH_LEVEL
79793 +
79794 + ==========================================================================
79795 + */
79796 +
79797 +
79798 +#ifdef RT2870
79799 +
79800 +VOID MlmeCntlConfirm(
79801 + IN PRTMP_ADAPTER pAd,
79802 + IN ULONG MsgType,
79803 + IN USHORT Msg)
79804 +{
79805 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(USHORT), &Msg);
79806 +}
79807 +
79808 +VOID ComposePsPoll(
79809 + IN PRTMP_ADAPTER pAd)
79810 +{
79811 + PTXINFO_STRUC pTxInfo;
79812 + PTXWI_STRUC pTxWI;
79813 +
79814 + DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
79815 + NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
79816 +
79817 + pAd->PsPollFrame.FC.PwrMgmt = 0;
79818 + pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
79819 + pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
79820 + pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
79821 + COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
79822 + COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
79823 +
79824 + RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0], 100);
79825 + pTxInfo = (PTXINFO_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0];
79826 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(PSPOLL_FRAME)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
79827 + pTxWI = (PTXWI_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
79828 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(PSPOLL_FRAME)),
79829 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
79830 + RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
79831 + // Append 4 extra zero bytes.
79832 + pAd->PsPollContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(PSPOLL_FRAME) + 4;
79833 +}
79834 +
79835 +// IRQL = DISPATCH_LEVEL
79836 +VOID ComposeNullFrame(
79837 + IN PRTMP_ADAPTER pAd)
79838 +{
79839 + PTXINFO_STRUC pTxInfo;
79840 + PTXWI_STRUC pTxWI;
79841 +
79842 + NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));
79843 + pAd->NullFrame.FC.Type = BTYPE_DATA;
79844 + pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
79845 + pAd->NullFrame.FC.ToDs = 1;
79846 + COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
79847 + COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
79848 + COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
79849 + RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], 100);
79850 + pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
79851 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
79852 + pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
79853 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
79854 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
79855 + RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
79856 + pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
79857 +}
79858 +#endif // RT2870 //
79859 +
79860 +
79861 +/*
79862 + ==========================================================================
79863 + Description:
79864 + Pre-build a BEACON frame in the shared memory
79865 +
79866 + IRQL = PASSIVE_LEVEL
79867 + IRQL = DISPATCH_LEVEL
79868 +
79869 + ==========================================================================
79870 +*/
79871 +ULONG MakeIbssBeacon(
79872 + IN PRTMP_ADAPTER pAd)
79873 +{
79874 + UCHAR DsLen = 1, IbssLen = 2;
79875 + UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};
79876 + HEADER_802_11 BcnHdr;
79877 + USHORT CapabilityInfo;
79878 + LARGE_INTEGER FakeTimestamp;
79879 + ULONG FrameLen = 0;
79880 + PTXWI_STRUC pTxWI = &pAd->BeaconTxWI;
79881 + CHAR *pBeaconFrame = pAd->BeaconBuf;
79882 + BOOLEAN Privacy;
79883 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
79884 + UCHAR SupRateLen = 0;
79885 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
79886 + UCHAR ExtRateLen = 0;
79887 + UCHAR RSNIe = IE_WPA;
79888 +
79889 + if ((pAd->CommonCfg.PhyMode == PHY_11B) && (pAd->CommonCfg.Channel <= 14))
79890 + {
79891 + SupRate[0] = 0x82; // 1 mbps
79892 + SupRate[1] = 0x84; // 2 mbps
79893 + SupRate[2] = 0x8b; // 5.5 mbps
79894 + SupRate[3] = 0x96; // 11 mbps
79895 + SupRateLen = 4;
79896 + ExtRateLen = 0;
79897 + }
79898 + else if (pAd->CommonCfg.Channel > 14)
79899 + {
79900 + SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
79901 + SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
79902 + SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
79903 + SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
79904 + SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
79905 + SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
79906 + SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
79907 + SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
79908 + SupRateLen = 8;
79909 + ExtRateLen = 0;
79910 +
79911 + //
79912 + // Also Update MlmeRate & RtsRate for G only & A only
79913 + //
79914 + pAd->CommonCfg.MlmeRate = RATE_6;
79915 + pAd->CommonCfg.RtsRate = RATE_6;
79916 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
79917 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
79918 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
79919 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
79920 + }
79921 + else
79922 + {
79923 + SupRate[0] = 0x82; // 1 mbps
79924 + SupRate[1] = 0x84; // 2 mbps
79925 + SupRate[2] = 0x8b; // 5.5 mbps
79926 + SupRate[3] = 0x96; // 11 mbps
79927 + SupRateLen = 4;
79928 +
79929 + ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,
79930 + ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
79931 + ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,
79932 + ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
79933 + ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,
79934 + ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
79935 + ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
79936 + ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
79937 + ExtRateLen = 8;
79938 + }
79939 +
79940 + pAd->StaActive.SupRateLen = SupRateLen;
79941 + NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
79942 + pAd->StaActive.ExtRateLen = ExtRateLen;
79943 + NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
79944 +
79945 + // compose IBSS beacon frame
79946 + MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->CommonCfg.Bssid);
79947 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
79948 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
79949 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
79950 + CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
79951 +
79952 + MakeOutgoingFrame(pBeaconFrame, &FrameLen,
79953 + sizeof(HEADER_802_11), &BcnHdr,
79954 + TIMESTAMP_LEN, &FakeTimestamp,
79955 + 2, &pAd->CommonCfg.BeaconPeriod,
79956 + 2, &CapabilityInfo,
79957 + 1, &SsidIe,
79958 + 1, &pAd->CommonCfg.SsidLen,
79959 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
79960 + 1, &SupRateIe,
79961 + 1, &SupRateLen,
79962 + SupRateLen, SupRate,
79963 + 1, &DsIe,
79964 + 1, &DsLen,
79965 + 1, &pAd->CommonCfg.Channel,
79966 + 1, &IbssIe,
79967 + 1, &IbssLen,
79968 + 2, &pAd->StaActive.AtimWin,
79969 + END_OF_ARGS);
79970 +
79971 + // add ERP_IE and EXT_RAE IE of in 802.11g
79972 + if (ExtRateLen)
79973 + {
79974 + ULONG tmp;
79975 +
79976 + MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
79977 + 3, LocalErpIe,
79978 + 1, &ExtRateIe,
79979 + 1, &ExtRateLen,
79980 + ExtRateLen, ExtRate,
79981 + END_OF_ARGS);
79982 + FrameLen += tmp;
79983 + }
79984 +
79985 + // If adhoc secruity is set for WPA-None, append the cipher suite IE
79986 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
79987 + {
79988 + ULONG tmp;
79989 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
79990 +
79991 + MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
79992 + 1, &RSNIe,
79993 + 1, &pAd->StaCfg.RSNIE_Len,
79994 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
79995 + END_OF_ARGS);
79996 + FrameLen += tmp;
79997 + }
79998 +
79999 +#ifdef DOT11_N_SUPPORT
80000 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80001 + {
80002 + ULONG TmpLen;
80003 + UCHAR HtLen, HtLen1;
80004 +
80005 +#ifdef RT_BIG_ENDIAN
80006 + HT_CAPABILITY_IE HtCapabilityTmp;
80007 + ADD_HT_INFO_IE addHTInfoTmp;
80008 + USHORT b2lTmp, b2lTmp2;
80009 +#endif
80010 +
80011 + // add HT Capability IE
80012 + HtLen = sizeof(pAd->CommonCfg.HtCapability);
80013 + HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
80014 +#ifndef RT_BIG_ENDIAN
80015 + MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
80016 + 1, &HtCapIe,
80017 + 1, &HtLen,
80018 + HtLen, &pAd->CommonCfg.HtCapability,
80019 + 1, &AddHtInfoIe,
80020 + 1, &HtLen1,
80021 + HtLen1, &pAd->CommonCfg.AddHTInfo,
80022 + END_OF_ARGS);
80023 +#else
80024 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
80025 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
80026 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
80027 +
80028 + NdisMoveMemory(&addHTInfoTmp, &pAd->CommonCfg.AddHTInfo, HtLen1);
80029 + *(USHORT *)(&addHTInfoTmp.AddHtInfo2) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo2));
80030 + *(USHORT *)(&addHTInfoTmp.AddHtInfo3) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo3));
80031 +
80032 + MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
80033 + 1, &HtCapIe,
80034 + 1, &HtLen,
80035 + HtLen, &HtCapabilityTmp,
80036 + 1, &AddHtInfoIe,
80037 + 1, &HtLen1,
80038 + HtLen1, &addHTInfoTmp,
80039 + END_OF_ARGS);
80040 +#endif
80041 + FrameLen += TmpLen;
80042 + }
80043 +#endif // DOT11_N_SUPPORT //
80044 +
80045 + //beacon use reserved WCID 0xff
80046 + if (pAd->CommonCfg.Channel > 14)
80047 + {
80048 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
80049 + PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
80050 + }
80051 + else
80052 + {
80053 + // Set to use 1Mbps for Adhoc beacon.
80054 + HTTRANSMIT_SETTING Transmit;
80055 + Transmit.word = 0;
80056 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
80057 + PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);
80058 + }
80059 +
80060 +#ifdef RT_BIG_ENDIAN
80061 + RTMPFrameEndianChange(pAd, pBeaconFrame, DIR_WRITE, FALSE);
80062 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
80063 +#endif
80064 +
80065 + DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
80066 + FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));
80067 + return FrameLen;
80068 +}
80069 +
80070 +
80071 --- /dev/null
80072 +++ b/drivers/staging/rt2870/sta/dls.c
80073 @@ -0,0 +1,2210 @@
80074 +/*
80075 + *************************************************************************
80076 + * Ralink Tech Inc.
80077 + * 5F., No.36, Taiyuan St., Jhubei City,
80078 + * Hsinchu County 302,
80079 + * Taiwan, R.O.C.
80080 + *
80081 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
80082 + *
80083 + * This program is free software; you can redistribute it and/or modify *
80084 + * it under the terms of the GNU General Public License as published by *
80085 + * the Free Software Foundation; either version 2 of the License, or *
80086 + * (at your option) any later version. *
80087 + * *
80088 + * This program is distributed in the hope that it will be useful, *
80089 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
80090 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
80091 + * GNU General Public License for more details. *
80092 + * *
80093 + * You should have received a copy of the GNU General Public License *
80094 + * along with this program; if not, write to the *
80095 + * Free Software Foundation, Inc., *
80096 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
80097 + * *
80098 + *************************************************************************
80099 +
80100 + Module Name:
80101 + dls.c
80102 +
80103 + Abstract:
80104 + Handle WMM-DLS state machine
80105 +
80106 + Revision History:
80107 + Who When What
80108 + -------- ---------- ----------------------------------------------
80109 + Rory Chen 02-14-2006
80110 + Arvin Tai 06-03-2008 Modified for RT28xx
80111 + */
80112 +
80113 +#include "../rt_config.h"
80114 +
80115 +/*
80116 + ==========================================================================
80117 + Description:
80118 + dls state machine init, including state transition and timer init
80119 + Parameters:
80120 + Sm - pointer to the dls state machine
80121 + Note:
80122 + The state machine looks like this
80123 +
80124 + DLS_IDLE
80125 + MT2_MLME_DLS_REQUEST MlmeDlsReqAction
80126 + MT2_PEER_DLS_REQUEST PeerDlsReqAction
80127 + MT2_PEER_DLS_RESPONSE PeerDlsRspAction
80128 + MT2_MLME_DLS_TEARDOWN MlmeTearDownAction
80129 + MT2_PEER_DLS_TEARDOWN PeerTearDownAction
80130 +
80131 + IRQL = PASSIVE_LEVEL
80132 +
80133 + ==========================================================================
80134 + */
80135 +void DlsStateMachineInit(
80136 + IN PRTMP_ADAPTER pAd,
80137 + IN STATE_MACHINE *Sm,
80138 + OUT STATE_MACHINE_FUNC Trans[])
80139 +{
80140 + UCHAR i;
80141 +
80142 + StateMachineInit(Sm, (STATE_MACHINE_FUNC*)Trans, MAX_DLS_STATE, MAX_DLS_MSG, (STATE_MACHINE_FUNC)Drop, DLS_IDLE, DLS_MACHINE_BASE);
80143 +
80144 + // the first column
80145 + StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_REQ, (STATE_MACHINE_FUNC)MlmeDlsReqAction);
80146 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_REQ, (STATE_MACHINE_FUNC)PeerDlsReqAction);
80147 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_RSP, (STATE_MACHINE_FUNC)PeerDlsRspAction);
80148 + StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_TEAR_DOWN, (STATE_MACHINE_FUNC)MlmeDlsTearDownAction);
80149 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_TEAR_DOWN, (STATE_MACHINE_FUNC)PeerDlsTearDownAction);
80150 +
80151 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
80152 + {
80153 + pAd->StaCfg.DLSEntry[i].pAd = pAd;
80154 + RTMPInitTimer(pAd, &pAd->StaCfg.DLSEntry[i].Timer, GET_TIMER_FUNCTION(DlsTimeoutAction), pAd, FALSE);
80155 + }
80156 +}
80157 +
80158 +/*
80159 + ==========================================================================
80160 + Description:
80161 +
80162 + IRQL = DISPATCH_LEVEL
80163 +
80164 + ==========================================================================
80165 + */
80166 +VOID MlmeDlsReqAction(
80167 + IN PRTMP_ADAPTER pAd,
80168 + IN MLME_QUEUE_ELEM *Elem)
80169 +{
80170 + PUCHAR pOutBuffer = NULL;
80171 + NDIS_STATUS NStatus;
80172 + ULONG FrameLen = 0;
80173 + HEADER_802_11 DlsReqHdr;
80174 + PRT_802_11_DLS pDLS = NULL;
80175 + UCHAR Category = CATEGORY_DLS;
80176 + UCHAR Action = ACTION_DLS_REQUEST;
80177 + ULONG tmp;
80178 + USHORT reason;
80179 + ULONG Timeout;
80180 + BOOLEAN TimerCancelled;
80181 +
80182 + if(!MlmeDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, &pDLS, &reason))
80183 + return;
80184 +
80185 + DBGPRINT(RT_DEBUG_TRACE,("DLS - MlmeDlsReqAction() \n"));
80186 +
80187 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
80188 + if (NStatus != NDIS_STATUS_SUCCESS)
80189 + {
80190 + DBGPRINT(RT_DEBUG_ERROR,("DLS - MlmeDlsReqAction() allocate memory failed \n"));
80191 + return;
80192 + }
80193 +
80194 + ActHeaderInit(pAd, &DlsReqHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
80195 +
80196 + // Build basic frame first
80197 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
80198 + sizeof(HEADER_802_11), &DlsReqHdr,
80199 + 1, &Category,
80200 + 1, &Action,
80201 + 6, &pDLS->MacAddr,
80202 + 6, pAd->CurrentAddress,
80203 + 2, &pAd->StaActive.CapabilityInfo,
80204 + 2, &pDLS->TimeOut,
80205 + 1, &SupRateIe,
80206 + 1, &pAd->MlmeAux.SupRateLen,
80207 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
80208 + END_OF_ARGS);
80209 +
80210 + if (pAd->MlmeAux.ExtRateLen != 0)
80211 + {
80212 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80213 + 1, &ExtRateIe,
80214 + 1, &pAd->MlmeAux.ExtRateLen,
80215 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
80216 + END_OF_ARGS);
80217 + FrameLen += tmp;
80218 + }
80219 +
80220 +#ifdef DOT11_N_SUPPORT
80221 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80222 + {
80223 + UCHAR HtLen;
80224 +
80225 +#ifdef RT_BIG_ENDIAN
80226 + HT_CAPABILITY_IE HtCapabilityTmp;
80227 +#endif
80228 +
80229 + // add HT Capability IE
80230 + HtLen = sizeof(HT_CAPABILITY_IE);
80231 +#ifndef RT_BIG_ENDIAN
80232 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80233 + 1, &HtCapIe,
80234 + 1, &HtLen,
80235 + HtLen, &pAd->CommonCfg.HtCapability,
80236 + END_OF_ARGS);
80237 +#else
80238 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
80239 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
80240 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
80241 +
80242 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80243 + 1, &HtCapIe,
80244 + 1, &HtLen,
80245 + HtLen, &HtCapabilityTmp,
80246 + END_OF_ARGS);
80247 +#endif
80248 + FrameLen = FrameLen + tmp;
80249 + }
80250 +#endif // DOT11_N_SUPPORT //
80251 +
80252 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
80253 + Timeout = DLS_TIMEOUT;
80254 + RTMPSetTimer(&pDLS->Timer, Timeout);
80255 +
80256 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
80257 + MlmeFreeMemory(pAd, pOutBuffer);
80258 +}
80259 +
80260 +/*
80261 + ==========================================================================
80262 + Description:
80263 +
80264 + IRQL = DISPATCH_LEVEL
80265 +
80266 + ==========================================================================
80267 + */
80268 +VOID PeerDlsReqAction(
80269 + IN PRTMP_ADAPTER pAd,
80270 + IN MLME_QUEUE_ELEM *Elem)
80271 +{
80272 + PUCHAR pOutBuffer = NULL;
80273 + NDIS_STATUS NStatus;
80274 + ULONG FrameLen = 0;
80275 + USHORT StatusCode = MLME_SUCCESS;
80276 + HEADER_802_11 DlsRspHdr;
80277 + UCHAR Category = CATEGORY_DLS;
80278 + UCHAR Action = ACTION_DLS_RESPONSE;
80279 + ULONG tmp;
80280 + USHORT CapabilityInfo;
80281 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
80282 + USHORT DLSTimeOut;
80283 + SHORT i;
80284 + ULONG Timeout;
80285 + BOOLEAN TimerCancelled;
80286 + PRT_802_11_DLS pDLS = NULL;
80287 + UCHAR MaxSupportedRateIn500Kbps = 0;
80288 + UCHAR SupportedRatesLen;
80289 + UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
80290 + UCHAR HtCapabilityLen;
80291 + HT_CAPABILITY_IE HtCapability;
80292 +
80293 + if (!PeerDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &DLSTimeOut,
80294 + &SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen, &HtCapability))
80295 + return;
80296 +
80297 + // supported rates array may not be sorted. sort it and find the maximum rate
80298 + for (i = 0; i < SupportedRatesLen; i++)
80299 + {
80300 + if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
80301 + MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
80302 + }
80303 +
80304 + 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]));
80305 +
80306 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
80307 + if (NStatus != NDIS_STATUS_SUCCESS)
80308 + {
80309 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsReqAction() allocate memory failed \n"));
80310 + return;
80311 + }
80312 +
80313 + if (!INFRA_ON(pAd))
80314 + {
80315 + StatusCode = MLME_REQUEST_DECLINED;
80316 + }
80317 + else if (!pAd->CommonCfg.bWmmCapable)
80318 + {
80319 + StatusCode = MLME_DEST_STA_IS_NOT_A_QSTA;
80320 + }
80321 + else if (!pAd->CommonCfg.bDLSCapable)
80322 + {
80323 + StatusCode = MLME_REQUEST_DECLINED;
80324 + }
80325 + else
80326 + {
80327 + // find table to update parameters
80328 + for (i = (MAX_NUM_OF_DLS_ENTRY-1); i >= 0; i--)
80329 + {
80330 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
80331 + {
80332 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
80333 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
80334 + else
80335 + {
80336 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
80337 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
80338 + }
80339 +
80340 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
80341 + pAd->StaCfg.DLSEntry[i].TimeOut = DLSTimeOut;
80342 + pAd->StaCfg.DLSEntry[i].CountDownTimer = DLSTimeOut;
80343 + if (HtCapabilityLen != 0)
80344 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
80345 + else
80346 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
80347 + pDLS = &pAd->StaCfg.DLSEntry[i];
80348 + break;
80349 + }
80350 + }
80351 +
80352 + // can not find in table, create a new one
80353 + if (i < 0)
80354 + {
80355 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsReqAction() can not find same entry \n"));
80356 + for (i=(MAX_NUM_OF_DLS_ENTRY - 1); i >= MAX_NUM_OF_INIT_DLS_ENTRY; i--)
80357 + {
80358 + if (!pAd->StaCfg.DLSEntry[i].Valid)
80359 + {
80360 + MAC_TABLE_ENTRY *pEntry;
80361 + UCHAR MaxSupportedRate = RATE_11;
80362 +
80363 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
80364 + {
80365 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
80366 + }
80367 + else
80368 + {
80369 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
80370 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
80371 + }
80372 +
80373 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
80374 + pAd->StaCfg.DLSEntry[i].Valid = TRUE;
80375 + pAd->StaCfg.DLSEntry[i].TimeOut = DLSTimeOut;
80376 + pAd->StaCfg.DLSEntry[i].CountDownTimer = DLSTimeOut;
80377 + NdisMoveMemory(pAd->StaCfg.DLSEntry[i].MacAddr, SA, MAC_ADDR_LEN);
80378 + if (HtCapabilityLen != 0)
80379 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
80380 + else
80381 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
80382 + pDLS = &pAd->StaCfg.DLSEntry[i];
80383 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
80384 +
80385 + switch (MaxSupportedRateIn500Kbps)
80386 + {
80387 + case 108: MaxSupportedRate = RATE_54; break;
80388 + case 96: MaxSupportedRate = RATE_48; break;
80389 + case 72: MaxSupportedRate = RATE_36; break;
80390 + case 48: MaxSupportedRate = RATE_24; break;
80391 + case 36: MaxSupportedRate = RATE_18; break;
80392 + case 24: MaxSupportedRate = RATE_12; break;
80393 + case 18: MaxSupportedRate = RATE_9; break;
80394 + case 12: MaxSupportedRate = RATE_6; break;
80395 + case 22: MaxSupportedRate = RATE_11; break;
80396 + case 11: MaxSupportedRate = RATE_5_5; break;
80397 + case 4: MaxSupportedRate = RATE_2; break;
80398 + case 2: MaxSupportedRate = RATE_1; break;
80399 + default: MaxSupportedRate = RATE_11; break;
80400 + }
80401 +
80402 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
80403 +
80404 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
80405 + {
80406 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
80407 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80408 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
80409 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80410 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
80411 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80412 + }
80413 + else
80414 + {
80415 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
80416 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80417 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
80418 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80419 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
80420 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80421 + }
80422 +
80423 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80424 + pEntry->MinHTPhyMode.field.BW = BW_20;
80425 +
80426 +#ifdef DOT11_N_SUPPORT
80427 + pEntry->HTCapability.MCSSet[0] = 0;
80428 + pEntry->HTCapability.MCSSet[1] = 0;
80429 +
80430 + // If this Entry supports 802.11n, upgrade to HT rate.
80431 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80432 + {
80433 + UCHAR j, bitmask; //k,bitmask;
80434 + CHAR ii;
80435 +
80436 + DBGPRINT(RT_DEBUG_OFF, ("DLS - PeerDlsReqAction() Receive Peer HT Capable STA from %02x:%02x:%02x:%02x:%02x:%02x\n",
80437 + SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
80438 +
80439 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
80440 + {
80441 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
80442 + }
80443 + else
80444 + {
80445 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
80446 + pAd->MacTab.fAnyStationNonGF = TRUE;
80447 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
80448 + }
80449 +
80450 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
80451 + {
80452 + pEntry->MaxHTPhyMode.field.BW= BW_40;
80453 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
80454 + }
80455 + else
80456 + {
80457 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80458 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
80459 + pAd->MacTab.fAnyStation20Only = TRUE;
80460 + }
80461 +
80462 + // find max fixed rate
80463 + for (ii=15; ii>=0; ii--)
80464 + {
80465 + j = ii/8;
80466 + bitmask = (1<<(ii-(j*8)));
80467 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
80468 + {
80469 + pEntry->MaxHTPhyMode.field.MCS = ii;
80470 + break;
80471 + }
80472 + if (ii==0)
80473 + break;
80474 + }
80475 +
80476 +
80477 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
80478 + {
80479 +
80480 + printk("@@@ pAd->CommonCfg.RegTransmitSetting.field.MCS = %d\n",
80481 + pAd->StaCfg.DesiredTransmitSetting.field.MCS);
80482 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
80483 + {
80484 + // Fix MCS as HT Duplicated Mode
80485 + pEntry->MaxHTPhyMode.field.BW = 1;
80486 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
80487 + pEntry->MaxHTPhyMode.field.STBC = 0;
80488 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
80489 + pEntry->MaxHTPhyMode.field.MCS = 32;
80490 + }
80491 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
80492 + {
80493 + // STA supports fixed MCS
80494 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
80495 + }
80496 + }
80497 +
80498 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
80499 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
80500 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
80501 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
80502 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
80503 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
80504 +
80505 + if (HtCapability.HtCapInfo.ShortGIfor20)
80506 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
80507 + if (HtCapability.HtCapInfo.ShortGIfor40)
80508 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
80509 + if (HtCapability.HtCapInfo.TxSTBC)
80510 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
80511 + if (HtCapability.HtCapInfo.RxSTBC)
80512 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
80513 + if (HtCapability.ExtHtCapInfo.PlusHTC)
80514 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
80515 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
80516 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
80517 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
80518 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
80519 +
80520 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
80521 + }
80522 +#endif // DOT11_N_SUPPORT //
80523 +
80524 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
80525 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
80526 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
80527 +
80528 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
80529 + {
80530 + PUCHAR pTable;
80531 + UCHAR TableSize = 0;
80532 +
80533 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
80534 + pEntry->bAutoTxRateSwitch = TRUE;
80535 + }
80536 + else
80537 + {
80538 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
80539 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
80540 + pEntry->bAutoTxRateSwitch = FALSE;
80541 +
80542 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
80543 + }
80544 + pEntry->RateLen = SupportedRatesLen;
80545 +
80546 + break;
80547 + }
80548 + }
80549 + }
80550 + StatusCode = MLME_SUCCESS;
80551 +
80552 + // can not find in table, create a new one
80553 + if (i < 0)
80554 + {
80555 + StatusCode = MLME_QOS_UNSPECIFY;
80556 + 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));
80557 + }
80558 + else
80559 + {
80560 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsReqAction() use entry(%d) %02x:%02x:%02x:%02x:%02x:%02x\n",
80561 + i, SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
80562 + }
80563 + }
80564 +
80565 + ActHeaderInit(pAd, &DlsRspHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
80566 +
80567 + // Build basic frame first
80568 + if (StatusCode == MLME_SUCCESS)
80569 + {
80570 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
80571 + sizeof(HEADER_802_11), &DlsRspHdr,
80572 + 1, &Category,
80573 + 1, &Action,
80574 + 2, &StatusCode,
80575 + 6, SA,
80576 + 6, pAd->CurrentAddress,
80577 + 2, &pAd->StaActive.CapabilityInfo,
80578 + 1, &SupRateIe,
80579 + 1, &pAd->MlmeAux.SupRateLen,
80580 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
80581 + END_OF_ARGS);
80582 +
80583 + if (pAd->MlmeAux.ExtRateLen != 0)
80584 + {
80585 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80586 + 1, &ExtRateIe,
80587 + 1, &pAd->MlmeAux.ExtRateLen,
80588 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
80589 + END_OF_ARGS);
80590 + FrameLen += tmp;
80591 + }
80592 +
80593 +#ifdef DOT11_N_SUPPORT
80594 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80595 + {
80596 + UCHAR HtLen;
80597 +
80598 +#ifdef RT_BIG_ENDIAN
80599 + HT_CAPABILITY_IE HtCapabilityTmp;
80600 +#endif
80601 +
80602 + // add HT Capability IE
80603 + HtLen = sizeof(HT_CAPABILITY_IE);
80604 +#ifndef RT_BIG_ENDIAN
80605 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80606 + 1, &HtCapIe,
80607 + 1, &HtLen,
80608 + HtLen, &pAd->CommonCfg.HtCapability,
80609 + END_OF_ARGS);
80610 +#else
80611 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
80612 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
80613 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
80614 +
80615 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
80616 + 1, &HtCapIe,
80617 + 1, &HtLen,
80618 + HtLen, &HtCapabilityTmp,
80619 + END_OF_ARGS);
80620 +#endif
80621 + FrameLen = FrameLen + tmp;
80622 + }
80623 +#endif // DOT11_N_SUPPORT //
80624 +
80625 + if (pDLS && (pDLS->Status != DLS_FINISH))
80626 + {
80627 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
80628 + Timeout = DLS_TIMEOUT;
80629 + RTMPSetTimer(&pDLS->Timer, Timeout);
80630 + }
80631 + }
80632 + else
80633 + {
80634 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
80635 + sizeof(HEADER_802_11), &DlsRspHdr,
80636 + 1, &Category,
80637 + 1, &Action,
80638 + 2, &StatusCode,
80639 + 6, SA,
80640 + 6, pAd->CurrentAddress,
80641 + END_OF_ARGS);
80642 + }
80643 +
80644 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
80645 + MlmeFreeMemory(pAd, pOutBuffer);
80646 +}
80647 +
80648 +/*
80649 + ==========================================================================
80650 + Description:
80651 +
80652 + IRQL = DISPATCH_LEVEL
80653 +
80654 + ==========================================================================
80655 + */
80656 +VOID PeerDlsRspAction(
80657 + IN PRTMP_ADAPTER pAd,
80658 + IN MLME_QUEUE_ELEM *Elem)
80659 +{
80660 + USHORT CapabilityInfo;
80661 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
80662 + USHORT StatusCode;
80663 + SHORT i;
80664 + BOOLEAN TimerCancelled;
80665 + UCHAR MaxSupportedRateIn500Kbps = 0;
80666 + UCHAR SupportedRatesLen;
80667 + UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
80668 + UCHAR HtCapabilityLen;
80669 + HT_CAPABILITY_IE HtCapability;
80670 +
80671 + if (!pAd->CommonCfg.bDLSCapable)
80672 + return;
80673 +
80674 + if (!INFRA_ON(pAd))
80675 + return;
80676 +
80677 + if (!PeerDlsRspSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &StatusCode,
80678 + &SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen, &HtCapability))
80679 + return;
80680 +
80681 + // supported rates array may not be sorted. sort it and find the maximum rate
80682 + for (i=0; i<SupportedRatesLen; i++)
80683 + {
80684 + if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
80685 + MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
80686 + }
80687 +
80688 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x with StatusCode=%d, CapabilityInfo=0x%x\n",
80689 + SA[0], SA[1], SA[2], SA[3], SA[4], SA[5], StatusCode, CapabilityInfo));
80690 +
80691 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
80692 + {
80693 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
80694 + {
80695 + if (StatusCode == MLME_SUCCESS)
80696 + {
80697 + MAC_TABLE_ENTRY *pEntry;
80698 + UCHAR MaxSupportedRate = RATE_11;
80699 +
80700 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
80701 +
80702 + switch (MaxSupportedRateIn500Kbps)
80703 + {
80704 + case 108: MaxSupportedRate = RATE_54; break;
80705 + case 96: MaxSupportedRate = RATE_48; break;
80706 + case 72: MaxSupportedRate = RATE_36; break;
80707 + case 48: MaxSupportedRate = RATE_24; break;
80708 + case 36: MaxSupportedRate = RATE_18; break;
80709 + case 24: MaxSupportedRate = RATE_12; break;
80710 + case 18: MaxSupportedRate = RATE_9; break;
80711 + case 12: MaxSupportedRate = RATE_6; break;
80712 + case 22: MaxSupportedRate = RATE_11; break;
80713 + case 11: MaxSupportedRate = RATE_5_5; break;
80714 + case 4: MaxSupportedRate = RATE_2; break;
80715 + case 2: MaxSupportedRate = RATE_1; break;
80716 + default: MaxSupportedRate = RATE_11; break;
80717 + }
80718 +
80719 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
80720 +
80721 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
80722 + {
80723 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
80724 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80725 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
80726 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80727 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
80728 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80729 + }
80730 + else
80731 + {
80732 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
80733 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80734 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
80735 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80736 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
80737 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80738 + }
80739 +
80740 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80741 + pEntry->MinHTPhyMode.field.BW = BW_20;
80742 +
80743 +#ifdef DOT11_N_SUPPORT
80744 + pEntry->HTCapability.MCSSet[0] = 0;
80745 + pEntry->HTCapability.MCSSet[1] = 0;
80746 +
80747 + // If this Entry supports 802.11n, upgrade to HT rate.
80748 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80749 + {
80750 + UCHAR j, bitmask; //k,bitmask;
80751 + CHAR ii;
80752 +
80753 + DBGPRINT(RT_DEBUG_OFF, ("DLS - PeerDlsRspAction Receive Peer HT Capable STA from %02x:%02x:%02x:%02x:%02x:%02x\n",
80754 + SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
80755 +
80756 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
80757 + {
80758 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
80759 + }
80760 + else
80761 + {
80762 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
80763 + pAd->MacTab.fAnyStationNonGF = TRUE;
80764 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
80765 + }
80766 +
80767 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
80768 + {
80769 + pEntry->MaxHTPhyMode.field.BW= BW_40;
80770 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
80771 + }
80772 + else
80773 + {
80774 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80775 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
80776 + pAd->MacTab.fAnyStation20Only = TRUE;
80777 + }
80778 +
80779 + // find max fixed rate
80780 + for (ii=15; ii>=0; ii--)
80781 + {
80782 + j = ii/8;
80783 + bitmask = (1<<(ii-(j*8)));
80784 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
80785 + {
80786 + pEntry->MaxHTPhyMode.field.MCS = ii;
80787 + break;
80788 + }
80789 + if (ii==0)
80790 + break;
80791 + }
80792 +
80793 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
80794 + {
80795 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
80796 + {
80797 + // Fix MCS as HT Duplicated Mode
80798 + pEntry->MaxHTPhyMode.field.BW = 1;
80799 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
80800 + pEntry->MaxHTPhyMode.field.STBC = 0;
80801 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
80802 + pEntry->MaxHTPhyMode.field.MCS = 32;
80803 + }
80804 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
80805 + {
80806 + // STA supports fixed MCS
80807 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
80808 + }
80809 + }
80810 +
80811 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
80812 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
80813 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
80814 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
80815 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
80816 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
80817 +
80818 + if (HtCapability.HtCapInfo.ShortGIfor20)
80819 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
80820 + if (HtCapability.HtCapInfo.ShortGIfor40)
80821 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
80822 + if (HtCapability.HtCapInfo.TxSTBC)
80823 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
80824 + if (HtCapability.HtCapInfo.RxSTBC)
80825 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
80826 + if (HtCapability.ExtHtCapInfo.PlusHTC)
80827 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
80828 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
80829 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
80830 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
80831 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
80832 +
80833 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
80834 + }
80835 +#endif // DOT11_N_SUPPORT //
80836 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
80837 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
80838 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
80839 +
80840 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
80841 + {
80842 + PUCHAR pTable;
80843 + UCHAR TableSize = 0;
80844 +
80845 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
80846 + pEntry->bAutoTxRateSwitch = TRUE;
80847 + }
80848 + else
80849 + {
80850 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
80851 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
80852 + pEntry->bAutoTxRateSwitch = FALSE;
80853 +
80854 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
80855 + }
80856 + pEntry->RateLen = SupportedRatesLen;
80857 +
80858 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
80859 + {
80860 + // If support WPA or WPA2, start STAKey hand shake,
80861 + // If failed hand shake, just tear down peer DLS
80862 + if (RTMPSendSTAKeyRequest(pAd, pAd->StaCfg.DLSEntry[i].MacAddr) != NDIS_STATUS_SUCCESS)
80863 + {
80864 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
80865 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
80866 +
80867 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
80868 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
80869 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
80870 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
80871 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed when call RTMPSendSTAKeyRequest \n"));
80872 + }
80873 + else
80874 + {
80875 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
80876 + DBGPRINT(RT_DEBUG_TRACE,("DLS - waiting for STAKey handshake procedure\n"));
80877 + }
80878 + }
80879 + else
80880 + {
80881 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
80882 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
80883 + 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]));
80884 + }
80885 +
80886 + //initialize seq no for DLS frames.
80887 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
80888 + if (HtCapabilityLen != 0)
80889 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
80890 + else
80891 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
80892 + }
80893 + else
80894 + {
80895 + // DLS setup procedure failed.
80896 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
80897 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
80898 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
80899 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed with StatusCode=%d \n", StatusCode));
80900 + }
80901 + }
80902 + }
80903 +
80904 + if (i >= MAX_NUM_OF_INIT_DLS_ENTRY)
80905 + {
80906 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() update timeout value \n"));
80907 + for (i=(MAX_NUM_OF_DLS_ENTRY-1); i>=MAX_NUM_OF_INIT_DLS_ENTRY; i--)
80908 + {
80909 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
80910 + {
80911 + if (StatusCode == MLME_SUCCESS)
80912 + {
80913 + MAC_TABLE_ENTRY *pEntry;
80914 + UCHAR MaxSupportedRate = RATE_11;
80915 +
80916 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
80917 +
80918 + switch (MaxSupportedRateIn500Kbps)
80919 + {
80920 + case 108: MaxSupportedRate = RATE_54; break;
80921 + case 96: MaxSupportedRate = RATE_48; break;
80922 + case 72: MaxSupportedRate = RATE_36; break;
80923 + case 48: MaxSupportedRate = RATE_24; break;
80924 + case 36: MaxSupportedRate = RATE_18; break;
80925 + case 24: MaxSupportedRate = RATE_12; break;
80926 + case 18: MaxSupportedRate = RATE_9; break;
80927 + case 12: MaxSupportedRate = RATE_6; break;
80928 + case 22: MaxSupportedRate = RATE_11; break;
80929 + case 11: MaxSupportedRate = RATE_5_5; break;
80930 + case 4: MaxSupportedRate = RATE_2; break;
80931 + case 2: MaxSupportedRate = RATE_1; break;
80932 + default: MaxSupportedRate = RATE_11; break;
80933 + }
80934 +
80935 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
80936 +
80937 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
80938 + {
80939 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
80940 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80941 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
80942 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80943 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
80944 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
80945 + }
80946 + else
80947 + {
80948 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
80949 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80950 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
80951 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80952 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
80953 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
80954 + }
80955 +
80956 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80957 + pEntry->MinHTPhyMode.field.BW = BW_20;
80958 +
80959 +#ifdef DOT11_N_SUPPORT
80960 + pEntry->HTCapability.MCSSet[0] = 0;
80961 + pEntry->HTCapability.MCSSet[1] = 0;
80962 +
80963 + // If this Entry supports 802.11n, upgrade to HT rate.
80964 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80965 + {
80966 + UCHAR j, bitmask; //k,bitmask;
80967 + CHAR ii;
80968 +
80969 + DBGPRINT(RT_DEBUG_OFF, ("DLS - PeerDlsRspAction Receive Peer HT Capable STA from %02x:%02x:%02x:%02x:%02x:%02x\n",
80970 + SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
80971 +
80972 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
80973 + {
80974 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
80975 + }
80976 + else
80977 + {
80978 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
80979 + pAd->MacTab.fAnyStationNonGF = TRUE;
80980 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
80981 + }
80982 +
80983 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
80984 + {
80985 + pEntry->MaxHTPhyMode.field.BW= BW_40;
80986 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
80987 + }
80988 + else
80989 + {
80990 + pEntry->MaxHTPhyMode.field.BW = BW_20;
80991 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
80992 + pAd->MacTab.fAnyStation20Only = TRUE;
80993 + }
80994 +
80995 + // find max fixed rate
80996 + for (ii=15; ii>=0; ii--)
80997 + {
80998 + j = ii/8;
80999 + bitmask = (1<<(ii-(j*8)));
81000 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
81001 + {
81002 + pEntry->MaxHTPhyMode.field.MCS = ii;
81003 + break;
81004 + }
81005 + if (ii==0)
81006 + break;
81007 + }
81008 +
81009 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
81010 + {
81011 + printk("@@@ pAd->CommonCfg.RegTransmitSetting.field.MCS = %d\n",
81012 + pAd->StaCfg.DesiredTransmitSetting.field.MCS);
81013 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
81014 + {
81015 + // Fix MCS as HT Duplicated Mode
81016 + pEntry->MaxHTPhyMode.field.BW = 1;
81017 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81018 + pEntry->MaxHTPhyMode.field.STBC = 0;
81019 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
81020 + pEntry->MaxHTPhyMode.field.MCS = 32;
81021 + }
81022 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
81023 + {
81024 + // STA supports fixed MCS
81025 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81026 + }
81027 + }
81028 +
81029 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
81030 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
81031 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
81032 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
81033 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
81034 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81035 +
81036 + if (HtCapability.HtCapInfo.ShortGIfor20)
81037 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
81038 + if (HtCapability.HtCapInfo.ShortGIfor40)
81039 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
81040 + if (HtCapability.HtCapInfo.TxSTBC)
81041 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
81042 + if (HtCapability.HtCapInfo.RxSTBC)
81043 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
81044 + if (HtCapability.ExtHtCapInfo.PlusHTC)
81045 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
81046 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
81047 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
81048 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
81049 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
81050 +
81051 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
81052 + }
81053 +#endif // DOT11_N_SUPPORT //
81054 +
81055 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81056 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
81057 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
81058 +
81059 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
81060 + {
81061 + PUCHAR pTable;
81062 + UCHAR TableSize = 0;
81063 +
81064 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
81065 + pEntry->bAutoTxRateSwitch = TRUE;
81066 + }
81067 + else
81068 + {
81069 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
81070 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81071 + pEntry->bAutoTxRateSwitch = FALSE;
81072 +
81073 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
81074 + }
81075 + pEntry->RateLen = SupportedRatesLen;
81076 +
81077 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
81078 + {
81079 + // If support WPA or WPA2, start STAKey hand shake,
81080 + // If failed hand shake, just tear down peer DLS
81081 + if (RTMPSendSTAKeyRequest(pAd, pAd->StaCfg.DLSEntry[i].MacAddr) != NDIS_STATUS_SUCCESS)
81082 + {
81083 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81084 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
81085 +
81086 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81087 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81088 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81089 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81090 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed when call RTMPSendSTAKeyRequest \n"));
81091 + }
81092 + else
81093 + {
81094 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
81095 + DBGPRINT(RT_DEBUG_TRACE,("DLS - waiting for STAKey handshake procedure\n"));
81096 + }
81097 + }
81098 + else
81099 + {
81100 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81101 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81102 + 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]));
81103 + }
81104 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
81105 + if (HtCapabilityLen != 0)
81106 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
81107 + else
81108 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
81109 + }
81110 + else
81111 + {
81112 + // DLS setup procedure failed.
81113 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81114 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81115 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81116 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed with StatusCode=%d \n", StatusCode));
81117 + }
81118 + }
81119 + }
81120 + }
81121 +}
81122 +
81123 +/*
81124 + ==========================================================================
81125 + Description:
81126 +
81127 + IRQL = DISPATCH_LEVEL
81128 +
81129 + ==========================================================================
81130 + */
81131 +VOID MlmeDlsTearDownAction(
81132 + IN PRTMP_ADAPTER pAd,
81133 + IN MLME_QUEUE_ELEM *Elem)
81134 +{
81135 + PUCHAR pOutBuffer = NULL;
81136 + NDIS_STATUS NStatus;
81137 + ULONG FrameLen = 0;
81138 + UCHAR Category = CATEGORY_DLS;
81139 + UCHAR Action = ACTION_DLS_TEARDOWN;
81140 + USHORT ReasonCode = REASON_QOS_UNSPECIFY;
81141 + HEADER_802_11 DlsTearDownHdr;
81142 + PRT_802_11_DLS pDLS;
81143 + BOOLEAN TimerCancelled;
81144 + UCHAR i;
81145 +
81146 + if(!MlmeDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, &pDLS, &ReasonCode))
81147 + return;
81148 +
81149 + DBGPRINT(RT_DEBUG_TRACE,("DLS - MlmeDlsTearDownAction() with ReasonCode=%d \n", ReasonCode));
81150 +
81151 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
81152 + if (NStatus != NDIS_STATUS_SUCCESS)
81153 + {
81154 + DBGPRINT(RT_DEBUG_ERROR,("DLS - MlmeDlsTearDownAction() allocate memory failed \n"));
81155 + return;
81156 + }
81157 +
81158 + ActHeaderInit(pAd, &DlsTearDownHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
81159 +
81160 + // Build basic frame first
81161 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81162 + sizeof(HEADER_802_11), &DlsTearDownHdr,
81163 + 1, &Category,
81164 + 1, &Action,
81165 + 6, &pDLS->MacAddr,
81166 + 6, pAd->CurrentAddress,
81167 + 2, &ReasonCode,
81168 + END_OF_ARGS);
81169 +
81170 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
81171 + MlmeFreeMemory(pAd, pOutBuffer);
81172 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
81173 +
81174 + // Remove key in local dls table entry
81175 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81176 + {
81177 + if (MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
81178 + {
81179 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81180 + }
81181 + }
81182 +
81183 + // clear peer dls table entry
81184 + for (i = MAX_NUM_OF_INIT_DLS_ENTRY; i < MAX_NUM_OF_DLS_ENTRY; i++)
81185 + {
81186 + if (MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
81187 + {
81188 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81189 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81190 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81191 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81192 + }
81193 + }
81194 +}
81195 +
81196 +/*
81197 + ==========================================================================
81198 + Description:
81199 +
81200 + IRQL = DISPATCH_LEVEL
81201 +
81202 + ==========================================================================
81203 + */
81204 +VOID PeerDlsTearDownAction(
81205 + IN PRTMP_ADAPTER pAd,
81206 + IN MLME_QUEUE_ELEM *Elem)
81207 +{
81208 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
81209 + USHORT ReasonCode;
81210 + UINT i;
81211 + BOOLEAN TimerCancelled;
81212 +
81213 + if (!pAd->CommonCfg.bDLSCapable)
81214 + return;
81215 +
81216 + if (!INFRA_ON(pAd))
81217 + return;
81218 +
81219 + if (!PeerDlsTearDownSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &ReasonCode))
81220 + return;
81221 +
81222 + 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));
81223 +
81224 + // clear local dls table entry
81225 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81226 + {
81227 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
81228 + {
81229 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81230 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81231 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81232 + //AsicDelWcidTab(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
81233 + //AsicRemovePairwiseKeyEntry(pAd, BSS0, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
81234 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81235 + }
81236 + }
81237 +
81238 + // clear peer dls table entry
81239 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
81240 + {
81241 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
81242 + {
81243 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81244 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81245 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81246 + //AsicDelWcidTab(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
81247 + //AsicRemovePairwiseKeyEntry(pAd, BSS0, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
81248 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81249 + }
81250 + }
81251 +}
81252 +
81253 +/*
81254 + ==========================================================================
81255 + Description:
81256 +
81257 + IRQL = DISPATCH_LEVEL
81258 +
81259 + ==========================================================================
81260 + */
81261 +VOID RTMPCheckDLSTimeOut(
81262 + IN PRTMP_ADAPTER pAd)
81263 +{
81264 + ULONG i;
81265 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81266 + USHORT reason = REASON_QOS_UNSPECIFY;
81267 +
81268 + if (! pAd->CommonCfg.bDLSCapable)
81269 + return;
81270 +
81271 + if (! INFRA_ON(pAd))
81272 + return;
81273 +
81274 + // If timeout value is equaled to zero, it means always not be timeout.
81275 +
81276 + // update local dls table entry
81277 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81278 + {
81279 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81280 + && (pAd->StaCfg.DLSEntry[i].TimeOut != 0))
81281 + {
81282 + pAd->StaCfg.DLSEntry[i].CountDownTimer --;
81283 +
81284 + if (pAd->StaCfg.DLSEntry[i].CountDownTimer == 0)
81285 + {
81286 + reason = REASON_QOS_REQUEST_TIMEOUT;
81287 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81288 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81289 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81290 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81291 + }
81292 + }
81293 + }
81294 +
81295 + // update peer dls table entry
81296 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
81297 + {
81298 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81299 + && (pAd->StaCfg.DLSEntry[i].TimeOut != 0))
81300 + {
81301 + pAd->StaCfg.DLSEntry[i].CountDownTimer --;
81302 +
81303 + if (pAd->StaCfg.DLSEntry[i].CountDownTimer == 0)
81304 + {
81305 + reason = REASON_QOS_REQUEST_TIMEOUT;
81306 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81307 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81308 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81309 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81310 + }
81311 + }
81312 + }
81313 +}
81314 +
81315 +/*
81316 + ==========================================================================
81317 + Description:
81318 +
81319 + IRQL = DISPATCH_LEVEL
81320 +
81321 + ==========================================================================
81322 + */
81323 +BOOLEAN RTMPRcvFrameDLSCheck(
81324 + IN PRTMP_ADAPTER pAd,
81325 + IN PHEADER_802_11 pHeader,
81326 + IN ULONG Len,
81327 + IN PRT28XX_RXD_STRUC pRxD)
81328 +{
81329 + ULONG i;
81330 + BOOLEAN bFindEntry = FALSE;
81331 + BOOLEAN bSTAKeyFrame = FALSE;
81332 + PEAPOL_PACKET pEap;
81333 + PUCHAR pProto, pAddr = NULL;
81334 + PUCHAR pSTAKey = NULL;
81335 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
81336 + UCHAR Mic[16], OldMic[16];
81337 + UCHAR digest[80];
81338 + UCHAR DlsPTK[80];
81339 + UCHAR temp[64];
81340 + BOOLEAN TimerCancelled;
81341 + CIPHER_KEY PairwiseKey;
81342 +
81343 +
81344 + if (! pAd->CommonCfg.bDLSCapable)
81345 + return bSTAKeyFrame;
81346 +
81347 + if (! INFRA_ON(pAd))
81348 + return bSTAKeyFrame;
81349 +
81350 + if (! (pHeader->FC.SubType & 0x08))
81351 + return bSTAKeyFrame;
81352 +
81353 + if (Len < LENGTH_802_11 + 6 + 2 + 2)
81354 + return bSTAKeyFrame;
81355 +
81356 + pProto = (PUCHAR)pHeader + LENGTH_802_11 + 2 + 6; // QOS Control field , 0xAA 0xAA 0xAA 0x00 0x00 0x00
81357 + pAddr = pHeader->Addr2;
81358 +
81359 + // L2PAD bit on will pad 2 bytes at LLC
81360 + if (pRxD->L2PAD)
81361 + {
81362 + pProto += 2;
81363 + }
81364 +
81365 + if (RTMPEqualMemory(EAPOL, pProto, 2) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
81366 + {
81367 + pEap = (PEAPOL_PACKET) (pProto + 2);
81368 +
81369 + 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,
81370 + (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE + 16),
81371 + pEap->KeyDesc.KeyInfo.KeyMic,
81372 + pEap->KeyDesc.KeyInfo.Install,
81373 + pEap->KeyDesc.KeyInfo.KeyAck,
81374 + pEap->KeyDesc.KeyInfo.Secure,
81375 + pEap->KeyDesc.KeyInfo.EKD_DL,
81376 + pEap->KeyDesc.KeyInfo.Error,
81377 + pEap->KeyDesc.KeyInfo.Request));
81378 +
81379 + if ((Len >= (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE + 16)) && pEap->KeyDesc.KeyInfo.KeyMic
81380 + && pEap->KeyDesc.KeyInfo.Install && pEap->KeyDesc.KeyInfo.KeyAck && pEap->KeyDesc.KeyInfo.Secure
81381 + && pEap->KeyDesc.KeyInfo.EKD_DL && !pEap->KeyDesc.KeyInfo.Error && !pEap->KeyDesc.KeyInfo.Request)
81382 + {
81383 + // First validate replay counter, only accept message with larger replay counter
81384 + // Let equal pass, some AP start with all zero replay counter
81385 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
81386 + if ((RTMPCompareMemory(pEap->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1) &&
81387 + (RTMPCompareMemory(pEap->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
81388 + return bSTAKeyFrame;
81389 +
81390 + //RTMPMoveMemory(pAd->StaCfg.ReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
81391 + RTMPMoveMemory(pAd->StaCfg.DlsReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
81392 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Sniff replay counter (%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x) Len=%ld, KeyDataLen=%d\n",
81393 + pAd->StaCfg.ReplayCounter[0], pAd->StaCfg.ReplayCounter[1], pAd->StaCfg.ReplayCounter[2],
81394 + pAd->StaCfg.ReplayCounter[3], pAd->StaCfg.ReplayCounter[4], pAd->StaCfg.ReplayCounter[5],
81395 + pAd->StaCfg.ReplayCounter[6], pAd->StaCfg.ReplayCounter[7], Len, pEap->KeyDesc.KeyData[1]));
81396 +
81397 + // put these code segment to get the replay counter
81398 + if (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
81399 + return bSTAKeyFrame;
81400 +
81401 + // Check MIC value
81402 + // Save the MIC and replace with zero
81403 + // use proprietary PTK
81404 + NdisZeroMemory(temp, 64);
81405 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
81406 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
81407 +
81408 + NdisMoveMemory(OldMic, pEap->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
81409 + NdisZeroMemory(pEap->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
81410 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
81411 + {
81412 + // AES
81413 + HMAC_SHA1((PUCHAR) pEap, pEap->Body_Len[1] + 4, DlsPTK, LEN_EAP_MICK, digest);
81414 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
81415 + }
81416 + else
81417 + {
81418 + hmac_md5(DlsPTK, LEN_EAP_MICK, (PUCHAR) pEap, pEap->Body_Len[1] + 4, Mic);
81419 + }
81420 +
81421 + if (!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
81422 + {
81423 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in Msg1 of STAKey handshake! \n"));
81424 + return bSTAKeyFrame;
81425 + }
81426 + else
81427 + DBGPRINT(RT_DEBUG_TRACE, ("MIC VALID in Msg1 of STAKey handshake! \n"));
81428 +#if 1
81429 + if ((pEap->KeyDesc.KeyData[0] == 0xDD) && (pEap->KeyDesc.KeyData[2] == 0x00) && (pEap->KeyDesc.KeyData[3] == 0x0C)
81430 + && (pEap->KeyDesc.KeyData[4] == 0x43) && (pEap->KeyDesc.KeyData[5] == 0x02))
81431 + {
81432 + pAddr = pEap->KeyDesc.KeyData + 8; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2)
81433 + pSTAKey = pEap->KeyDesc.KeyData + 14; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2), STAKey_Mac_Addr(6)
81434 +
81435 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 from %02x:%02x:%02x:%02x:%02x:%02x Len=%ld, KeyDataLen=%d\n",
81436 + pAddr[0], pAddr[1], pAddr[2], pAddr[3], pAddr[4], pAddr[5], Len, pEap->KeyDesc.KeyData[1]));
81437 +
81438 + bSTAKeyFrame = TRUE;
81439 + }
81440 +#else
81441 + if ((pEap->KeyDesc.KeyData[0] == 0xDD) && (pEap->KeyDesc.KeyData[2] == 0x00) && (pEap->KeyDesc.KeyData[3] == 0x0F)
81442 + && (pEap->KeyDesc.KeyData[4] == 0xAC) && (pEap->KeyDesc.KeyData[5] == 0x02))
81443 + {
81444 + pAddr = pEap->KeyDesc.KeyData + 8; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2)
81445 + pSTAKey = pEap->KeyDesc.KeyData + 14; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2), STAKey_Mac_Addr(6)
81446 +
81447 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 from %02x:%02x:%02x:%02x:%02x:%02x Len=%d, KeyDataLen=%d\n",
81448 + pAddr[0], pAddr[1], pAddr[2], pAddr[3], pAddr[4], pAddr[5], Len, pEap->KeyDesc.KeyData[1]));
81449 +
81450 + bSTAKeyFrame = TRUE;
81451 + }
81452 +#endif
81453 +
81454 + }
81455 + else if (Len >= (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE))
81456 + {
81457 +#if 0
81458 + RTMPMoveMemory(pAd->StaCfg.ReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
81459 +
81460 +#endif
81461 + RTMPMoveMemory(pAd->StaCfg.DlsReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
81462 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Sniff replay counter 2(%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x) Len=%ld, KeyDataLen=%d\n",
81463 + pAd->StaCfg.ReplayCounter[0], pAd->StaCfg.ReplayCounter[1], pAd->StaCfg.ReplayCounter[2],
81464 + pAd->StaCfg.ReplayCounter[3], pAd->StaCfg.ReplayCounter[4], pAd->StaCfg.ReplayCounter[5],
81465 + pAd->StaCfg.ReplayCounter[6], pAd->StaCfg.ReplayCounter[7], Len, pEap->KeyDesc.KeyData[1]));
81466 +
81467 + }
81468 + }
81469 +
81470 + // If timeout value is equaled to zero, it means always not be timeout.
81471 + // update local dls table entry
81472 + for (i= 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81473 + {
81474 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(pAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
81475 + {
81476 + if (bSTAKeyFrame)
81477 + {
81478 + PMAC_TABLE_ENTRY pEntry;
81479 +
81480 + // STAKey frame, add pairwise key table
81481 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81482 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81483 +
81484 + PairwiseKey.KeyLen = LEN_TKIP_EK;
81485 + NdisMoveMemory(PairwiseKey.Key, &pSTAKey[0], LEN_TKIP_EK);
81486 + NdisMoveMemory(PairwiseKey.TxMic, &pSTAKey[16], LEN_TKIP_RXMICK);
81487 + NdisMoveMemory(PairwiseKey.RxMic, &pSTAKey[24], LEN_TKIP_TXMICK);
81488 +
81489 + PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg;
81490 +
81491 + pEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
81492 + //AsicAddKeyEntry(pAd, (USHORT)(i + 2), BSS0, 0, &PairwiseKey, TRUE, TRUE); // reserve 0 for multicast, 1 for unicast
81493 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
81494 + // Add Pair-wise key to Asic
81495 +#ifdef RT2870
81496 + {
81497 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
81498 + COPY_MAC_ADDR(KeyInfo.MacAddr,pAd->StaCfg.DLSEntry[i].MacAddr);
81499 + KeyInfo.MacTabMatchWCID=pAd->StaCfg.DLSEntry[i].MacTabMatchWCID;
81500 + NdisMoveMemory(&KeyInfo.CipherKey, &PairwiseKey,sizeof(CIPHER_KEY));
81501 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_KEY_TABLE, &KeyInfo, sizeof(RT_ADD_PAIRWISE_KEY_ENTRY));
81502 + }
81503 + {
81504 + PMAC_TABLE_ENTRY pDLSEntry;
81505 + pDLSEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
81506 + pDLSEntry->PairwiseKey.CipherAlg=PairwiseKey.CipherAlg;
81507 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_RX_WCID_TABLE, pDLSEntry, sizeof(MAC_TABLE_ENTRY));
81508 + }
81509 +#endif // RT2870 //
81510 + NdisMoveMemory(&pEntry->PairwiseKey, &PairwiseKey, sizeof(CIPHER_KEY));
81511 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 (Peer STA MAC Address STAKey) \n"));
81512 +
81513 + RTMPSendSTAKeyHandShake(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
81514 +
81515 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Finish STAKey handshake procedure (Initiator side)\n"));
81516 + }
81517 + else
81518 + {
81519 + // Data frame, update timeout value
81520 + if (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81521 + {
81522 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
81523 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
81524 + }
81525 + }
81526 +
81527 + bFindEntry = TRUE;
81528 + }
81529 + }
81530 +
81531 + // update peer dls table entry
81532 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
81533 + {
81534 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(pAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
81535 + {
81536 + if (bSTAKeyFrame)
81537 + {
81538 + PMAC_TABLE_ENTRY pEntry = NULL;
81539 +
81540 + // STAKey frame, add pairwise key table, and send STAkey Msg-2
81541 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81542 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81543 +
81544 + PairwiseKey.KeyLen = LEN_TKIP_EK;
81545 + NdisMoveMemory(PairwiseKey.Key, &pSTAKey[0], LEN_TKIP_EK);
81546 + NdisMoveMemory(PairwiseKey.TxMic, &pSTAKey[16], LEN_TKIP_RXMICK);
81547 + NdisMoveMemory(PairwiseKey.RxMic, &pSTAKey[24], LEN_TKIP_TXMICK);
81548 +
81549 + PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg;
81550 +
81551 + pEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
81552 + //AsicAddKeyEntry(pAd, (USHORT)(i + 2), BSS0, 0, &PairwiseKey, TRUE, TRUE); // reserve 0 for multicast, 1 for unicast
81553 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
81554 + // Add Pair-wise key to Asic
81555 +#ifdef RT2870
81556 + {
81557 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
81558 + COPY_MAC_ADDR(KeyInfo.MacAddr,pAd->StaCfg.DLSEntry[i].MacAddr);
81559 + KeyInfo.MacTabMatchWCID=pAd->StaCfg.DLSEntry[i].MacTabMatchWCID;
81560 + NdisMoveMemory(&KeyInfo.CipherKey, &PairwiseKey,sizeof(CIPHER_KEY));
81561 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_KEY_TABLE, &KeyInfo, sizeof(RT_ADD_PAIRWISE_KEY_ENTRY));
81562 + }
81563 + {
81564 + PMAC_TABLE_ENTRY pDLSEntry;
81565 + pDLSEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
81566 + pDLSEntry->PairwiseKey.CipherAlg=PairwiseKey.CipherAlg;
81567 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_RX_WCID_TABLE, pDLSEntry, sizeof(MAC_TABLE_ENTRY));
81568 + }
81569 +#endif // RT2870 //
81570 + NdisMoveMemory(&pEntry->PairwiseKey, &PairwiseKey, sizeof(CIPHER_KEY));
81571 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 (Initiator STA MAC Address STAKey)\n"));
81572 +
81573 + // If support WPA or WPA2, start STAKey hand shake,
81574 + // If failed hand shake, just tear down peer DLS
81575 + if (RTMPSendSTAKeyHandShake(pAd, pAddr) != NDIS_STATUS_SUCCESS)
81576 + {
81577 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81578 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
81579 +
81580 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81581 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81582 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81583 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81584 + }
81585 + else
81586 + {
81587 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Finish STAKey handshake procedure (Peer side)\n"));
81588 + }
81589 + }
81590 + else
81591 + {
81592 + // Data frame, update timeout value
81593 + if (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81594 + {
81595 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
81596 + }
81597 + }
81598 +
81599 + bFindEntry = TRUE;
81600 + }
81601 + }
81602 +
81603 +
81604 + return bSTAKeyFrame;
81605 +}
81606 +
81607 +/*
81608 + ========================================================================
81609 +
81610 + Routine Description:
81611 + Check if the frame can be sent through DLS direct link interface
81612 +
81613 + Arguments:
81614 + pAd Pointer to adapter
81615 +
81616 + Return Value:
81617 + DLS entry index
81618 +
81619 + Note:
81620 +
81621 + ========================================================================
81622 +*/
81623 +INT RTMPCheckDLSFrame(
81624 + IN PRTMP_ADAPTER pAd,
81625 + IN PUCHAR pDA)
81626 +{
81627 + INT rval = -1;
81628 + INT i;
81629 +
81630 + if (!pAd->CommonCfg.bDLSCapable)
81631 + return rval;
81632 +
81633 + if (!INFRA_ON(pAd))
81634 + return rval;
81635 +
81636 + do{
81637 + // check local dls table entry
81638 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81639 + {
81640 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
81641 + MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
81642 + {
81643 + rval = i;
81644 + break;
81645 + }
81646 + }
81647 +
81648 + // check peer dls table entry
81649 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
81650 + {
81651 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
81652 + MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
81653 + {
81654 + rval = i;
81655 + break;
81656 + }
81657 + }
81658 + } while (FALSE);
81659 +
81660 + return rval;
81661 +}
81662 +
81663 +/*
81664 + ==========================================================================
81665 + Description:
81666 +
81667 + IRQL = DISPATCH_LEVEL
81668 +
81669 + ==========================================================================
81670 + */
81671 +VOID RTMPSendDLSTearDownFrame(
81672 + IN PRTMP_ADAPTER pAd,
81673 + IN PUCHAR pDA)
81674 +{
81675 + PUCHAR pOutBuffer = NULL;
81676 + NDIS_STATUS NStatus;
81677 + HEADER_802_11 DlsTearDownHdr;
81678 + ULONG FrameLen = 0;
81679 + USHORT Reason = REASON_QOS_QSTA_LEAVING_QBSS;
81680 + UCHAR Category = CATEGORY_DLS;
81681 + UCHAR Action = ACTION_DLS_TEARDOWN;
81682 + UCHAR i = 0;
81683 +
81684 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
81685 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
81686 + return;
81687 +
81688 + DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame \n"));
81689 +
81690 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
81691 + if (NStatus != NDIS_STATUS_SUCCESS)
81692 + {
81693 + DBGPRINT(RT_DEBUG_ERROR,("ASSOC - RTMPSendDLSTearDownFrame() allocate memory failed \n"));
81694 + return;
81695 + }
81696 +
81697 + ActHeaderInit(pAd, &DlsTearDownHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
81698 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81699 + sizeof(HEADER_802_11), &DlsTearDownHdr,
81700 + 1, &Category,
81701 + 1, &Action,
81702 + 6, pDA,
81703 + 6, pAd->CurrentAddress,
81704 + 2, &Reason,
81705 + END_OF_ARGS);
81706 +
81707 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
81708 + MlmeFreeMemory(pAd, pOutBuffer);
81709 +
81710 + // Remove key in local dls table entry
81711 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81712 + {
81713 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81714 + && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
81715 + {
81716 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81717 + }
81718 + }
81719 +
81720 + // Remove key in peer dls table entry
81721 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
81722 + {
81723 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
81724 + && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
81725 + {
81726 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
81727 + }
81728 + }
81729 +
81730 + DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame and remove key in (i=%d) \n", i));
81731 +}
81732 +
81733 +/*
81734 + ==========================================================================
81735 + Description:
81736 +
81737 + IRQL = DISPATCH_LEVEL
81738 +
81739 + ==========================================================================
81740 + */
81741 +NDIS_STATUS RTMPSendSTAKeyRequest(
81742 + IN PRTMP_ADAPTER pAd,
81743 + IN PUCHAR pDA)
81744 +{
81745 + UCHAR Header802_3[14];
81746 + NDIS_STATUS NStatus;
81747 + ULONG FrameLen = 0;
81748 + EAPOL_PACKET Packet;
81749 + UCHAR Mic[16];
81750 + UCHAR digest[80];
81751 + PUCHAR pOutBuffer = NULL;
81752 + PNDIS_PACKET pNdisPacket;
81753 + UCHAR temp[64];
81754 + UCHAR DlsPTK[80];
81755 +
81756 + 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]));
81757 +
81758 + pAd->Sequence ++;
81759 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
81760 +
81761 + // Zero message body
81762 + NdisZeroMemory(&Packet, sizeof(Packet));
81763 + Packet.ProVer = EAPOL_VER;
81764 + Packet.ProType = EAPOLKey;
81765 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE andPeer MAC address
81766 +
81767 + // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE)
81768 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
81769 + {
81770 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
81771 + }
81772 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
81773 + {
81774 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
81775 + }
81776 +
81777 + // Key descriptor version
81778 + Packet.KeyDesc.KeyInfo.KeyDescVer =
81779 + (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
81780 +
81781 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
81782 + Packet.KeyDesc.KeyInfo.Secure = 1;
81783 + Packet.KeyDesc.KeyInfo.Request = 1;
81784 +
81785 + Packet.KeyDesc.KeyDataLen[1] = 12;
81786 +
81787 + // use our own OUI to distinguish proprietary with standard.
81788 + Packet.KeyDesc.KeyData[0] = 0xDD;
81789 + Packet.KeyDesc.KeyData[1] = 0x0A;
81790 + Packet.KeyDesc.KeyData[2] = 0x00;
81791 + Packet.KeyDesc.KeyData[3] = 0x0C;
81792 + Packet.KeyDesc.KeyData[4] = 0x43;
81793 + Packet.KeyDesc.KeyData[5] = 0x03;
81794 + NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN);
81795 +
81796 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY);
81797 +
81798 + // Allocate buffer for transmitting message
81799 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
81800 + if (NStatus != NDIS_STATUS_SUCCESS)
81801 + return NStatus;
81802 +
81803 + // Prepare EAPOL frame for MIC calculation
81804 + // Be careful, only EAPOL frame is counted for MIC calculation
81805 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81806 + Packet.Body_Len[1] + 4, &Packet,
81807 + END_OF_ARGS);
81808 +
81809 + // use proprietary PTK
81810 + NdisZeroMemory(temp, 64);
81811 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
81812 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
81813 +
81814 + // calculate MIC
81815 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
81816 + {
81817 + // AES
81818 + NdisZeroMemory(digest, sizeof(digest));
81819 + HMAC_SHA1(pOutBuffer, FrameLen, DlsPTK, LEN_EAP_MICK, digest);
81820 + NdisMoveMemory(Packet.KeyDesc.KeyMic, digest, LEN_KEY_DESC_MIC);
81821 + }
81822 + else
81823 + {
81824 + NdisZeroMemory(Mic, sizeof(Mic));
81825 + hmac_md5(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
81826 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
81827 + }
81828 +
81829 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81830 + sizeof(Header802_3), Header802_3,
81831 + Packet.Body_Len[1] + 4, &Packet,
81832 + END_OF_ARGS);
81833 +
81834 + NStatus = RTMPAllocateNdisPacket(pAd, &pNdisPacket, NULL, 0, pOutBuffer, FrameLen);
81835 + if (NStatus == NDIS_STATUS_SUCCESS)
81836 + {
81837 + RTMP_SET_PACKET_WCID(pNdisPacket, BSSID_WCID);
81838 + STASendPacket(pAd, pNdisPacket);
81839 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
81840 + }
81841 +
81842 + MlmeFreeMemory(pAd, pOutBuffer);
81843 +
81844 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSendSTAKeyRequest- Send STAKey request (NStatus=%x, FrameLen=%ld)\n", NStatus, FrameLen));
81845 +
81846 + return NStatus;
81847 +}
81848 +
81849 +/*
81850 + ==========================================================================
81851 + Description:
81852 +
81853 + IRQL = DISPATCH_LEVEL
81854 +
81855 + ==========================================================================
81856 + */
81857 +NDIS_STATUS RTMPSendSTAKeyHandShake(
81858 + IN PRTMP_ADAPTER pAd,
81859 + IN PUCHAR pDA)
81860 +{
81861 + UCHAR Header802_3[14];
81862 + NDIS_STATUS NStatus;
81863 + ULONG FrameLen = 0;
81864 + EAPOL_PACKET Packet;
81865 + UCHAR Mic[16];
81866 + UCHAR digest[80];
81867 + PUCHAR pOutBuffer = NULL;
81868 + PNDIS_PACKET pNdisPacket;
81869 + UCHAR temp[64];
81870 + UCHAR DlsPTK[80]; // Due to dirver can not get PTK, use proprietary PTK
81871 +
81872 + 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]));
81873 +
81874 + pAd->Sequence ++;
81875 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
81876 +
81877 + // Zero message body
81878 + NdisZeroMemory(&Packet, sizeof(Packet));
81879 + Packet.ProVer = EAPOL_VER;
81880 + Packet.ProType = EAPOLKey;
81881 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE and Peer MAC address
81882 +
81883 + // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE)
81884 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
81885 + {
81886 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
81887 + }
81888 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
81889 + {
81890 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
81891 + }
81892 +
81893 + // Key descriptor version
81894 + Packet.KeyDesc.KeyInfo.KeyDescVer =
81895 + (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
81896 +
81897 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
81898 + Packet.KeyDesc.KeyInfo.Secure = 1;
81899 +
81900 + Packet.KeyDesc.KeyDataLen[1] = 12;
81901 +
81902 + // use our own OUI to distinguish proprietary with standard.
81903 + Packet.KeyDesc.KeyData[0] = 0xDD;
81904 + Packet.KeyDesc.KeyData[1] = 0x0A;
81905 + Packet.KeyDesc.KeyData[2] = 0x00;
81906 + Packet.KeyDesc.KeyData[3] = 0x0C;
81907 + Packet.KeyDesc.KeyData[4] = 0x43;
81908 + Packet.KeyDesc.KeyData[5] = 0x03;
81909 + NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN);
81910 +
81911 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY);
81912 +
81913 + // Allocate buffer for transmitting message
81914 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
81915 + if (NStatus != NDIS_STATUS_SUCCESS)
81916 + return NStatus;
81917 +
81918 + // Prepare EAPOL frame for MIC calculation
81919 + // Be careful, only EAPOL frame is counted for MIC calculation
81920 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81921 + Packet.Body_Len[1] + 4, &Packet,
81922 + END_OF_ARGS);
81923 +
81924 + // use proprietary PTK
81925 + NdisZeroMemory(temp, 64);
81926 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
81927 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
81928 +
81929 + // calculate MIC
81930 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
81931 + {
81932 + // AES
81933 + NdisZeroMemory(digest, sizeof(digest));
81934 + HMAC_SHA1(pOutBuffer, FrameLen, DlsPTK, LEN_EAP_MICK, digest);
81935 + NdisMoveMemory(Packet.KeyDesc.KeyMic, digest, LEN_KEY_DESC_MIC);
81936 + }
81937 + else
81938 + {
81939 + NdisZeroMemory(Mic, sizeof(Mic));
81940 + hmac_md5(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
81941 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
81942 + }
81943 +
81944 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81945 + sizeof(Header802_3), Header802_3,
81946 + Packet.Body_Len[1] + 4, &Packet,
81947 + END_OF_ARGS);
81948 +
81949 + NStatus = RTMPAllocateNdisPacket(pAd, &pNdisPacket, NULL, 0, pOutBuffer, FrameLen);
81950 + if (NStatus == NDIS_STATUS_SUCCESS)
81951 + {
81952 + RTMP_SET_PACKET_WCID(pNdisPacket, BSSID_WCID);
81953 + STASendPacket(pAd, pNdisPacket);
81954 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
81955 + }
81956 +
81957 + MlmeFreeMemory(pAd, pOutBuffer);
81958 +
81959 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSendSTAKeyHandShake- Send STAKey Message-2 (NStatus=%x, FrameLen=%ld)\n", NStatus, FrameLen));
81960 +
81961 + return NStatus;
81962 +}
81963 +
81964 +VOID DlsTimeoutAction(
81965 + IN PVOID SystemSpecific1,
81966 + IN PVOID FunctionContext,
81967 + IN PVOID SystemSpecific2,
81968 + IN PVOID SystemSpecific3)
81969 +{
81970 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81971 + USHORT reason;
81972 + PRT_802_11_DLS pDLS = (PRT_802_11_DLS)FunctionContext;
81973 + PRTMP_ADAPTER pAd = pDLS->pAd;
81974 +
81975 + DBGPRINT(RT_DEBUG_TRACE, ("DlsTimeout - Tear down DLS links (%02x:%02x:%02x:%02x:%02x:%02x)\n",
81976 + pDLS->MacAddr[0], pDLS->MacAddr[1], pDLS->MacAddr[2], pDLS->MacAddr[3], pDLS->MacAddr[4], pDLS->MacAddr[5]));
81977 +
81978 + if ((pDLS) && (pDLS->Valid))
81979 + {
81980 + reason = REASON_QOS_REQUEST_TIMEOUT;
81981 + pDLS->Valid = FALSE;
81982 + pDLS->Status = DLS_NONE;
81983 + DlsParmFill(pAd, &MlmeDlsReq, pDLS, reason);
81984 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81985 + RT28XX_MLME_HANDLER(pAd);
81986 + }
81987 +}
81988 +
81989 +/*
81990 +================================================================
81991 +Description : because DLS and CLI share the same WCID table in ASIC.
81992 +Mesh entry also insert to pAd->MacTab.content[]. Such is marked as ValidAsDls = TRUE.
81993 +Also fills the pairwise key.
81994 +Because front MAX_AID_BA entries have direct mapping to BAEntry, which is only used as CLI. So we insert Dls
81995 +from index MAX_AID_BA.
81996 +================================================================
81997 +*/
81998 +MAC_TABLE_ENTRY *MacTableInsertDlsEntry(
81999 + IN PRTMP_ADAPTER pAd,
82000 + IN PUCHAR pAddr,
82001 + IN UINT DlsEntryIdx)
82002 +{
82003 + PMAC_TABLE_ENTRY pEntry = NULL;
82004 +
82005 + DBGPRINT(RT_DEBUG_TRACE, ("====> MacTableInsertDlsEntry\n"));
82006 + // if FULL, return
82007 + if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE)
82008 + return NULL;
82009 +
82010 + do
82011 + {
82012 + if((pEntry = DlsEntryTableLookup(pAd, pAddr, TRUE)) != NULL)
82013 + break;
82014 +
82015 + // allocate one MAC entry
82016 + pEntry = MacTableInsertEntry(pAd, pAddr, DlsEntryIdx + MIN_NET_DEVICE_FOR_DLS, TRUE);
82017 + if (pEntry)
82018 + {
82019 + pAd->StaCfg.DLSEntry[DlsEntryIdx].MacTabMatchWCID = pEntry->Aid;
82020 + pEntry->MatchDlsEntryIdx = DlsEntryIdx;
82021 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
82022 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
82023 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
82024 +
82025 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableInsertDlsEntry - allocate entry #%d, Total= %d\n",pEntry->Aid, pAd->MacTab.Size));
82026 +
82027 + // If legacy WEP is used, set pair-wise cipherAlg into WCID attribute table for this entry
82028 + if ((pEntry->ValidAsDls) && (pEntry->WepStatus == Ndis802_11WEPEnabled))
82029 + {
82030 + UCHAR KeyIdx = 0;
82031 + UCHAR CipherAlg = 0;
82032 +
82033 + KeyIdx = pAd->StaCfg.DefaultKeyId;
82034 +
82035 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
82036 +
82037 + RTMPAddWcidAttributeEntry(pAd,
82038 + BSS0,
82039 + pAd->StaCfg.DefaultKeyId,
82040 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
82041 + pEntry);
82042 + }
82043 +
82044 + break;
82045 + }
82046 + } while(FALSE);
82047 +
82048 + DBGPRINT(RT_DEBUG_TRACE, ("<==== MacTableInsertDlsEntry\n"));
82049 +
82050 + return pEntry;
82051 +}
82052 +
82053 +
82054 +/*
82055 + ==========================================================================
82056 + Description:
82057 + Delete all Mesh Entry in pAd->MacTab
82058 + ==========================================================================
82059 + */
82060 +BOOLEAN MacTableDeleteDlsEntry(
82061 + IN PRTMP_ADAPTER pAd,
82062 + IN USHORT wcid,
82063 + IN PUCHAR pAddr)
82064 +{
82065 + DBGPRINT(RT_DEBUG_TRACE, ("====> MacTableDeleteDlsEntry\n"));
82066 +
82067 + if (!VALID_WCID(wcid))
82068 + return FALSE;
82069 +
82070 + MacTableDeleteEntry(pAd, wcid, pAddr);
82071 +
82072 + DBGPRINT(RT_DEBUG_TRACE, ("<==== MacTableDeleteDlsEntry\n"));
82073 +
82074 + return TRUE;
82075 +}
82076 +
82077 +MAC_TABLE_ENTRY *DlsEntryTableLookup(
82078 + IN PRTMP_ADAPTER pAd,
82079 + IN PUCHAR pAddr,
82080 + IN BOOLEAN bResetIdelCount)
82081 +{
82082 + ULONG HashIdx;
82083 + MAC_TABLE_ENTRY *pEntry = NULL;
82084 +
82085 + RTMP_SEM_LOCK(&pAd->MacTabLock);
82086 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
82087 + pEntry = pAd->MacTab.Hash[HashIdx];
82088 +
82089 + while (pEntry)
82090 + {
82091 + if ((pEntry->ValidAsDls == TRUE)
82092 + && MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
82093 + {
82094 + if(bResetIdelCount)
82095 + pEntry->NoDataIdleCount = 0;
82096 + break;
82097 + }
82098 + else
82099 + pEntry = pEntry->pNext;
82100 + }
82101 +
82102 + RTMP_SEM_UNLOCK(&pAd->MacTabLock);
82103 + return pEntry;
82104 +}
82105 +
82106 +MAC_TABLE_ENTRY *DlsEntryTableLookupByWcid(
82107 + IN PRTMP_ADAPTER pAd,
82108 + IN UCHAR wcid,
82109 + IN PUCHAR pAddr,
82110 + IN BOOLEAN bResetIdelCount)
82111 +{
82112 + ULONG DLsIndex;
82113 + PMAC_TABLE_ENTRY pCurEntry = NULL;
82114 + PMAC_TABLE_ENTRY pEntry = NULL;
82115 +
82116 + if (!VALID_WCID(wcid))
82117 + return NULL;
82118 +
82119 + RTMP_SEM_LOCK(&pAd->MacTabLock);
82120 +
82121 + do
82122 + {
82123 + pCurEntry = &pAd->MacTab.Content[wcid];
82124 +
82125 + DLsIndex = 0xff;
82126 + if ((pCurEntry) && (pCurEntry->ValidAsDls== TRUE))
82127 + {
82128 + DLsIndex = pCurEntry->MatchDlsEntryIdx;
82129 + }
82130 +
82131 + if (DLsIndex == 0xff)
82132 + break;
82133 +
82134 + if (MAC_ADDR_EQUAL(pCurEntry->Addr, pAddr))
82135 + {
82136 + if(bResetIdelCount)
82137 + pCurEntry->NoDataIdleCount = 0;
82138 + pEntry = pCurEntry;
82139 + break;
82140 + }
82141 + } while(FALSE);
82142 +
82143 + RTMP_SEM_UNLOCK(&pAd->MacTabLock);
82144 +
82145 + return pEntry;
82146 +}
82147 +
82148 +INT Set_DlsEntryInfo_Display_Proc(
82149 + IN PRTMP_ADAPTER pAd,
82150 + IN PUCHAR arg)
82151 +{
82152 + INT i;
82153 +
82154 + printk("\n%-19s%-8s\n", "MAC", "TIMEOUT\n");
82155 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
82156 + {
82157 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
82158 + {
82159 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[pAd->StaCfg.DLSEntry[i].MacTabMatchWCID];
82160 +
82161 + printk("%02x:%02x:%02x:%02x:%02x:%02x ",
82162 + pAd->StaCfg.DLSEntry[i].MacAddr[0], pAd->StaCfg.DLSEntry[i].MacAddr[1], pAd->StaCfg.DLSEntry[i].MacAddr[2],
82163 + pAd->StaCfg.DLSEntry[i].MacAddr[3], pAd->StaCfg.DLSEntry[i].MacAddr[4], pAd->StaCfg.DLSEntry[i].MacAddr[5]);
82164 + printk("%-8d\n", pAd->StaCfg.DLSEntry[i].TimeOut);
82165 +
82166 + printk("\n");
82167 + printk("\n%-19s%-4s%-4s%-4s%-4s%-7s%-7s%-7s","MAC", "AID", "BSS", "PSM", "WMM", "RSSI0", "RSSI1", "RSSI2");
82168 +#ifdef DOT11_N_SUPPORT
82169 + printk("%-8s%-10s%-6s%-6s%-6s%-6s", "MIMOPS", "PhMd", "BW", "MCS", "SGI", "STBC");
82170 +#endif // DOT11_N_SUPPORT //
82171 + printk("\n%02X:%02X:%02X:%02X:%02X:%02X ",
82172 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
82173 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
82174 + printk("%-4d", (int)pEntry->Aid);
82175 + printk("%-4d", (int)pEntry->apidx);
82176 + printk("%-4d", (int)pEntry->PsMode);
82177 + printk("%-4d", (int)CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE));
82178 + printk("%-7d", pEntry->RssiSample.AvgRssi0);
82179 + printk("%-7d", pEntry->RssiSample.AvgRssi1);
82180 + printk("%-7d", pEntry->RssiSample.AvgRssi2);
82181 +#ifdef DOT11_N_SUPPORT
82182 + printk("%-8d", (int)pEntry->MmpsMode);
82183 + printk("%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
82184 + printk("%-6s", GetBW(pEntry->HTPhyMode.field.BW));
82185 + printk("%-6d", pEntry->HTPhyMode.field.MCS);
82186 + printk("%-6d", pEntry->HTPhyMode.field.ShortGI);
82187 + printk("%-6d", pEntry->HTPhyMode.field.STBC);
82188 +#endif // DOT11_N_SUPPORT //
82189 + printk("%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
82190 + (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
82191 + printk("\n");
82192 +
82193 + }
82194 + }
82195 +
82196 + return TRUE;
82197 +}
82198 +
82199 +INT Set_DlsAddEntry_Proc(
82200 + IN PRTMP_ADAPTER pAd,
82201 + IN PUCHAR arg)
82202 +{
82203 + UCHAR mac[MAC_ADDR_LEN];
82204 + USHORT Timeout;
82205 + char *token, sepValue[] = ":", DASH = '-';
82206 + INT i;
82207 + RT_802_11_DLS Dls;
82208 +
82209 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and timeout value in decimal format.
82210 + return FALSE;
82211 +
82212 + token = strchr(arg, DASH);
82213 + if ((token != NULL) && (strlen(token)>1))
82214 + {
82215 + Timeout = simple_strtol((token+1), 0, 10);
82216 +
82217 + *token = '\0';
82218 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
82219 + {
82220 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
82221 + return FALSE;
82222 + AtoH(token, (PUCHAR)(&mac[i]), 1);
82223 + }
82224 + if(i != 6)
82225 + return FALSE;
82226 +
82227 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%d", mac[0], mac[1],
82228 + mac[2], mac[3], mac[4], mac[5], (int)Timeout);
82229 +
82230 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
82231 + Dls.TimeOut = Timeout;
82232 + COPY_MAC_ADDR(Dls.MacAddr, mac);
82233 + Dls.Valid = 1;
82234 +
82235 + MlmeEnqueue(pAd,
82236 + MLME_CNTL_STATE_MACHINE,
82237 + RT_OID_802_11_SET_DLS_PARAM,
82238 + sizeof(RT_802_11_DLS),
82239 + &Dls);
82240 +
82241 + return TRUE;
82242 + }
82243 +
82244 + return FALSE;
82245 +
82246 +}
82247 +
82248 +INT Set_DlsTearDownEntry_Proc(
82249 + IN PRTMP_ADAPTER pAd,
82250 + IN PUCHAR arg)
82251 +{
82252 + UCHAR macAddr[MAC_ADDR_LEN];
82253 + CHAR *value;
82254 + INT i;
82255 + RT_802_11_DLS Dls;
82256 +
82257 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
82258 + return FALSE;
82259 +
82260 + for (i=0, value = rstrtok(arg,":"); value; value = rstrtok(NULL,":"))
82261 + {
82262 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
82263 + return FALSE; //Invalid
82264 +
82265 + AtoH(value, &macAddr[i++], 2);
82266 + }
82267 +
82268 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x", macAddr[0], macAddr[1],
82269 + macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
82270 +
82271 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
82272 + COPY_MAC_ADDR(Dls.MacAddr, macAddr);
82273 + Dls.Valid = 0;
82274 +
82275 + MlmeEnqueue(pAd,
82276 + MLME_CNTL_STATE_MACHINE,
82277 + RT_OID_802_11_SET_DLS_PARAM,
82278 + sizeof(RT_802_11_DLS),
82279 + &Dls);
82280 +
82281 + return TRUE;
82282 +}
82283 +
82284 --- /dev/null
82285 +++ b/drivers/staging/rt2870/sta_ioctl.c
82286 @@ -0,0 +1,7068 @@
82287 +/*
82288 + *************************************************************************
82289 + * Ralink Tech Inc.
82290 + * 5F., No.36, Taiyuan St., Jhubei City,
82291 + * Hsinchu County 302,
82292 + * Taiwan, R.O.C.
82293 + *
82294 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
82295 + *
82296 + * This program is free software; you can redistribute it and/or modify *
82297 + * it under the terms of the GNU General Public License as published by *
82298 + * the Free Software Foundation; either version 2 of the License, or *
82299 + * (at your option) any later version. *
82300 + * *
82301 + * This program is distributed in the hope that it will be useful, *
82302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
82303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
82304 + * GNU General Public License for more details. *
82305 + * *
82306 + * You should have received a copy of the GNU General Public License *
82307 + * along with this program; if not, write to the *
82308 + * Free Software Foundation, Inc., *
82309 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
82310 + * *
82311 + *************************************************************************
82312 +
82313 + Module Name:
82314 + sta_ioctl.c
82315 +
82316 + Abstract:
82317 + IOCTL related subroutines
82318 +
82319 + Revision History:
82320 + Who When What
82321 + -------- ---------- ----------------------------------------------
82322 + Rory Chen 01-03-2003 created
82323 + Rory Chen 02-14-2005 modify to support RT61
82324 +*/
82325 +
82326 +#include "rt_config.h"
82327 +
82328 +#ifdef DBG
82329 +extern ULONG RTDebugLevel;
82330 +#endif
82331 +
82332 +#define NR_WEP_KEYS 4
82333 +#define WEP_SMALL_KEY_LEN (40/8)
82334 +#define WEP_LARGE_KEY_LEN (104/8)
82335 +
82336 +#define GROUP_KEY_NO 4
82337 +
82338 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
82339 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_A, _B, _C, _D, _E)
82340 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_A, _B, _C, _D, _E)
82341 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_A, _B, _C, _D, _E, _F)
82342 +#else
82343 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_B, _C, _D, _E)
82344 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_B, _C, _D, _E)
82345 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_B, _C, _D, _E, _F)
82346 +#endif
82347 +
82348 +extern UCHAR CipherWpa2Template[];
82349 +extern UCHAR CipherWpaPskTkip[];
82350 +extern UCHAR CipherWpaPskTkipLen;
82351 +
82352 +typedef struct PACKED _RT_VERSION_INFO{
82353 + UCHAR DriverVersionW;
82354 + UCHAR DriverVersionX;
82355 + UCHAR DriverVersionY;
82356 + UCHAR DriverVersionZ;
82357 + UINT DriverBuildYear;
82358 + UINT DriverBuildMonth;
82359 + UINT DriverBuildDay;
82360 +} RT_VERSION_INFO, *PRT_VERSION_INFO;
82361 +
82362 +struct iw_priv_args privtab[] = {
82363 +{ RTPRIV_IOCTL_SET,
82364 + IW_PRIV_TYPE_CHAR | 1024, 0,
82365 + "set"},
82366 +
82367 +{ RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
82368 + ""},
82369 +{ RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
82370 + ""},
82371 +/* --- sub-ioctls definitions --- */
82372 + { SHOW_CONN_STATUS,
82373 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
82374 + { SHOW_DRVIER_VERION,
82375 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
82376 + { SHOW_BA_INFO,
82377 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
82378 + { SHOW_DESC_INFO,
82379 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
82380 + { RAIO_OFF,
82381 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
82382 + { RAIO_ON,
82383 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
82384 +#ifdef QOS_DLS_SUPPORT
82385 + { SHOW_DLS_ENTRY_INFO,
82386 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
82387 +#endif // QOS_DLS_SUPPORT //
82388 + { SHOW_CFG_VALUE,
82389 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
82390 + { SHOW_ADHOC_ENTRY_INFO,
82391 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
82392 +
82393 +/* --- sub-ioctls relations --- */
82394 +
82395 +#ifdef DBG
82396 +{ RTPRIV_IOCTL_BBP,
82397 + IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
82398 + "bbp"},
82399 +{ RTPRIV_IOCTL_MAC,
82400 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
82401 + "mac"},
82402 +{ RTPRIV_IOCTL_E2P,
82403 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
82404 + "e2p"},
82405 +#endif /* DBG */
82406 +
82407 +{ RTPRIV_IOCTL_STATISTICS,
82408 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
82409 + "stat"},
82410 +{ RTPRIV_IOCTL_GSITESURVEY,
82411 + 0, IW_PRIV_TYPE_CHAR | 1024,
82412 + "get_site_survey"},
82413 +};
82414 +
82415 +INT Set_SSID_Proc(
82416 + IN PRTMP_ADAPTER pAdapter,
82417 + IN PUCHAR arg);
82418 +
82419 +#ifdef WMM_SUPPORT
82420 +INT Set_WmmCapable_Proc(
82421 + IN PRTMP_ADAPTER pAd,
82422 + IN PUCHAR arg);
82423 +#endif
82424 +
82425 +INT Set_NetworkType_Proc(
82426 + IN PRTMP_ADAPTER pAdapter,
82427 + IN PUCHAR arg);
82428 +
82429 +INT Set_AuthMode_Proc(
82430 + IN PRTMP_ADAPTER pAdapter,
82431 + IN PUCHAR arg);
82432 +
82433 +INT Set_EncrypType_Proc(
82434 + IN PRTMP_ADAPTER pAdapter,
82435 + IN PUCHAR arg);
82436 +
82437 +INT Set_DefaultKeyID_Proc(
82438 + IN PRTMP_ADAPTER pAdapter,
82439 + IN PUCHAR arg);
82440 +
82441 +INT Set_Key1_Proc(
82442 + IN PRTMP_ADAPTER pAdapter,
82443 + IN PUCHAR arg);
82444 +
82445 +INT Set_Key2_Proc(
82446 + IN PRTMP_ADAPTER pAdapter,
82447 + IN PUCHAR arg);
82448 +
82449 +INT Set_Key3_Proc(
82450 + IN PRTMP_ADAPTER pAdapter,
82451 + IN PUCHAR arg);
82452 +
82453 +INT Set_Key4_Proc(
82454 + IN PRTMP_ADAPTER pAdapter,
82455 + IN PUCHAR arg);
82456 +
82457 +INT Set_WPAPSK_Proc(
82458 + IN PRTMP_ADAPTER pAdapter,
82459 + IN PUCHAR arg);
82460 +
82461 +
82462 +INT Set_PSMode_Proc(
82463 + IN PRTMP_ADAPTER pAdapter,
82464 + IN PUCHAR arg);
82465 +
82466 +#ifdef WPA_SUPPLICANT_SUPPORT
82467 +INT Set_Wpa_Support(
82468 + IN PRTMP_ADAPTER pAd,
82469 + IN PUCHAR arg);
82470 +#endif // WPA_SUPPLICANT_SUPPORT //
82471 +
82472 +#ifdef DBG
82473 +VOID RTMPIoctlBBP(
82474 + IN PRTMP_ADAPTER pAdapter,
82475 + IN struct iwreq *wrq);
82476 +
82477 +VOID RTMPIoctlMAC(
82478 + IN PRTMP_ADAPTER pAdapter,
82479 + IN struct iwreq *wrq);
82480 +
82481 +VOID RTMPIoctlE2PROM(
82482 + IN PRTMP_ADAPTER pAdapter,
82483 + IN struct iwreq *wrq);
82484 +#endif // DBG //
82485 +
82486 +
82487 +NDIS_STATUS RTMPWPANoneAddKeyProc(
82488 + IN PRTMP_ADAPTER pAd,
82489 + IN PVOID pBuf);
82490 +
82491 +INT Set_FragTest_Proc(
82492 + IN PRTMP_ADAPTER pAdapter,
82493 + IN PUCHAR arg);
82494 +
82495 +#ifdef DOT11_N_SUPPORT
82496 +INT Set_TGnWifiTest_Proc(
82497 + IN PRTMP_ADAPTER pAd,
82498 + IN PUCHAR arg);
82499 +#endif // DOT11_N_SUPPORT //
82500 +
82501 +INT Set_LongRetryLimit_Proc(
82502 + IN PRTMP_ADAPTER pAdapter,
82503 + IN PUCHAR arg);
82504 +
82505 +INT Set_ShortRetryLimit_Proc(
82506 + IN PRTMP_ADAPTER pAdapter,
82507 + IN PUCHAR arg);
82508 +
82509 +#ifdef EXT_BUILD_CHANNEL_LIST
82510 +INT Set_Ieee80211dClientMode_Proc(
82511 + IN PRTMP_ADAPTER pAdapter,
82512 + IN PUCHAR arg);
82513 +#endif // EXT_BUILD_CHANNEL_LIST //
82514 +
82515 +#ifdef CARRIER_DETECTION_SUPPORT
82516 +INT Set_CarrierDetect_Proc(
82517 + IN PRTMP_ADAPTER pAd,
82518 + IN PUCHAR arg);
82519 +#endif // CARRIER_DETECTION_SUPPORT //
82520 +
82521 +INT Show_Adhoc_MacTable_Proc(
82522 + IN PRTMP_ADAPTER pAd,
82523 + IN PCHAR extra);
82524 +
82525 +static struct {
82526 + CHAR *name;
82527 + INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
82528 +} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
82529 + {"DriverVersion", Set_DriverVersion_Proc},
82530 + {"CountryRegion", Set_CountryRegion_Proc},
82531 + {"CountryRegionABand", Set_CountryRegionABand_Proc},
82532 + {"SSID", Set_SSID_Proc},
82533 + {"WirelessMode", Set_WirelessMode_Proc},
82534 + {"TxBurst", Set_TxBurst_Proc},
82535 + {"TxPreamble", Set_TxPreamble_Proc},
82536 + {"TxPower", Set_TxPower_Proc},
82537 + {"Channel", Set_Channel_Proc},
82538 + {"BGProtection", Set_BGProtection_Proc},
82539 + {"RTSThreshold", Set_RTSThreshold_Proc},
82540 + {"FragThreshold", Set_FragThreshold_Proc},
82541 +#ifdef DOT11_N_SUPPORT
82542 + {"HtBw", Set_HtBw_Proc},
82543 + {"HtMcs", Set_HtMcs_Proc},
82544 + {"HtGi", Set_HtGi_Proc},
82545 + {"HtOpMode", Set_HtOpMode_Proc},
82546 + {"HtExtcha", Set_HtExtcha_Proc},
82547 + {"HtMpduDensity", Set_HtMpduDensity_Proc},
82548 + {"HtBaWinSize", Set_HtBaWinSize_Proc},
82549 + {"HtRdg", Set_HtRdg_Proc},
82550 + {"HtAmsdu", Set_HtAmsdu_Proc},
82551 + {"HtAutoBa", Set_HtAutoBa_Proc},
82552 + {"HtBaDecline", Set_BADecline_Proc},
82553 + {"HtProtect", Set_HtProtect_Proc},
82554 + {"HtMimoPs", Set_HtMimoPs_Proc},
82555 +#endif // DOT11_N_SUPPORT //
82556 +
82557 +#ifdef AGGREGATION_SUPPORT
82558 + {"PktAggregate", Set_PktAggregate_Proc},
82559 +#endif
82560 +
82561 +#ifdef WMM_SUPPORT
82562 + {"WmmCapable", Set_WmmCapable_Proc},
82563 +#endif
82564 + {"IEEE80211H", Set_IEEE80211H_Proc},
82565 + {"NetworkType", Set_NetworkType_Proc},
82566 + {"AuthMode", Set_AuthMode_Proc},
82567 + {"EncrypType", Set_EncrypType_Proc},
82568 + {"DefaultKeyID", Set_DefaultKeyID_Proc},
82569 + {"Key1", Set_Key1_Proc},
82570 + {"Key2", Set_Key2_Proc},
82571 + {"Key3", Set_Key3_Proc},
82572 + {"Key4", Set_Key4_Proc},
82573 + {"WPAPSK", Set_WPAPSK_Proc},
82574 + {"ResetCounter", Set_ResetStatCounter_Proc},
82575 + {"PSMode", Set_PSMode_Proc},
82576 +#ifdef DBG
82577 + {"Debug", Set_Debug_Proc},
82578 +#endif
82579 +
82580 +#ifdef RALINK_ATE
82581 + {"ATE", Set_ATE_Proc},
82582 + {"ATEDA", Set_ATE_DA_Proc},
82583 + {"ATESA", Set_ATE_SA_Proc},
82584 + {"ATEBSSID", Set_ATE_BSSID_Proc},
82585 + {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
82586 + {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
82587 + {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
82588 + {"ATETXANT", Set_ATE_TX_Antenna_Proc},
82589 + {"ATERXANT", Set_ATE_RX_Antenna_Proc},
82590 + {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
82591 + {"ATETXBW", Set_ATE_TX_BW_Proc},
82592 + {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
82593 + {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
82594 + {"ATETXMCS", Set_ATE_TX_MCS_Proc},
82595 + {"ATETXMODE", Set_ATE_TX_MODE_Proc},
82596 + {"ATETXGI", Set_ATE_TX_GI_Proc},
82597 + {"ATERXFER", Set_ATE_RX_FER_Proc},
82598 + {"ATERRF", Set_ATE_Read_RF_Proc},
82599 + {"ATEWRF1", Set_ATE_Write_RF1_Proc},
82600 + {"ATEWRF2", Set_ATE_Write_RF2_Proc},
82601 + {"ATEWRF3", Set_ATE_Write_RF3_Proc},
82602 + {"ATEWRF4", Set_ATE_Write_RF4_Proc},
82603 + {"ATELDE2P", Set_ATE_Load_E2P_Proc},
82604 + {"ATERE2P", Set_ATE_Read_E2P_Proc},
82605 + {"ATESHOW", Set_ATE_Show_Proc},
82606 + {"ATEHELP", Set_ATE_Help_Proc},
82607 +
82608 +#ifdef RALINK_28xx_QA
82609 + {"TxStop", Set_TxStop_Proc},
82610 + {"RxStop", Set_RxStop_Proc},
82611 +#endif // RALINK_28xx_QA //
82612 +#endif // RALINK_ATE //
82613 +
82614 +#ifdef WPA_SUPPLICANT_SUPPORT
82615 + {"WpaSupport", Set_Wpa_Support},
82616 +#endif // WPA_SUPPLICANT_SUPPORT //
82617 +
82618 +
82619 +
82620 + {"FixedTxMode", Set_FixedTxMode_Proc},
82621 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
82622 + {"OpMode", Set_OpMode_Proc},
82623 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
82624 +#ifdef DOT11_N_SUPPORT
82625 + {"TGnWifiTest", Set_TGnWifiTest_Proc},
82626 + {"ForceGF", Set_ForceGF_Proc},
82627 +#endif // DOT11_N_SUPPORT //
82628 +#ifdef QOS_DLS_SUPPORT
82629 + {"DlsAddEntry", Set_DlsAddEntry_Proc},
82630 + {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
82631 +#endif // QOS_DLS_SUPPORT //
82632 + {"LongRetry", Set_LongRetryLimit_Proc},
82633 + {"ShortRetry", Set_ShortRetryLimit_Proc},
82634 +#ifdef EXT_BUILD_CHANNEL_LIST
82635 + {"11dClientMode", Set_Ieee80211dClientMode_Proc},
82636 +#endif // EXT_BUILD_CHANNEL_LIST //
82637 +#ifdef CARRIER_DETECTION_SUPPORT
82638 + {"CarrierDetect", Set_CarrierDetect_Proc},
82639 +#endif // CARRIER_DETECTION_SUPPORT //
82640 +
82641 + {NULL,}
82642 +};
82643 +
82644 +
82645 +VOID RTMPAddKey(
82646 + IN PRTMP_ADAPTER pAd,
82647 + IN PNDIS_802_11_KEY pKey)
82648 +{
82649 + ULONG KeyIdx;
82650 + MAC_TABLE_ENTRY *pEntry;
82651 +
82652 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
82653 +
82654 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
82655 + {
82656 + if (pKey->KeyIndex & 0x80000000)
82657 + {
82658 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
82659 + {
82660 + NdisZeroMemory(pAd->StaCfg.PMK, 32);
82661 + NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
82662 + goto end;
82663 + }
82664 + // Update PTK
82665 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
82666 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
82667 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
82668 +#ifdef WPA_SUPPLICANT_SUPPORT
82669 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
82670 + {
82671 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
82672 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
82673 + }
82674 + else
82675 +#endif // WPA_SUPPLICANT_SUPPORT //
82676 + {
82677 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
82678 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
82679 + }
82680 +
82681 + // Decide its ChiperAlg
82682 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
82683 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
82684 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
82685 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
82686 + else
82687 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
82688 +
82689 + // Update these related information to MAC_TABLE_ENTRY
82690 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
82691 + NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
82692 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
82693 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
82694 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
82695 +
82696 + // Update pairwise key information to ASIC Shared Key Table
82697 + AsicAddSharedKeyEntry(pAd,
82698 + BSS0,
82699 + 0,
82700 + pAd->SharedKey[BSS0][0].CipherAlg,
82701 + pAd->SharedKey[BSS0][0].Key,
82702 + pAd->SharedKey[BSS0][0].TxMic,
82703 + pAd->SharedKey[BSS0][0].RxMic);
82704 +
82705 + // Update ASIC WCID attribute table and IVEIV table
82706 + RTMPAddWcidAttributeEntry(pAd,
82707 + BSS0,
82708 + 0,
82709 + pAd->SharedKey[BSS0][0].CipherAlg,
82710 + pEntry);
82711 +
82712 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
82713 + {
82714 + // set 802.1x port control
82715 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
82716 + STA_PORT_SECURED(pAd);
82717 +
82718 + // Indicate Connected for GUI
82719 + pAd->IndicateMediaState = NdisMediaStateConnected;
82720 + }
82721 + }
82722 + else
82723 + {
82724 + // Update GTK
82725 + pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
82726 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
82727 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
82728 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
82729 +#ifdef WPA_SUPPLICANT_SUPPORT
82730 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
82731 + {
82732 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
82733 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
82734 + }
82735 + else
82736 +#endif // WPA_SUPPLICANT_SUPPORT //
82737 + {
82738 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
82739 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
82740 + }
82741 +
82742 + // Update Shared Key CipherAlg
82743 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
82744 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
82745 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
82746 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
82747 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
82748 +
82749 + // Update group key information to ASIC Shared Key Table
82750 + AsicAddSharedKeyEntry(pAd,
82751 + BSS0,
82752 + pAd->StaCfg.DefaultKeyId,
82753 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
82754 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
82755 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
82756 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
82757 +
82758 + // Update ASIC WCID attribute table and IVEIV table
82759 + RTMPAddWcidAttributeEntry(pAd,
82760 + BSS0,
82761 + pAd->StaCfg.DefaultKeyId,
82762 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
82763 + NULL);
82764 +
82765 + // set 802.1x port control
82766 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
82767 + STA_PORT_SECURED(pAd);
82768 +
82769 + // Indicate Connected for GUI
82770 + pAd->IndicateMediaState = NdisMediaStateConnected;
82771 + }
82772 + }
82773 + else // dynamic WEP from wpa_supplicant
82774 + {
82775 + UCHAR CipherAlg;
82776 + PUCHAR Key;
82777 +
82778 + if(pKey->KeyLength == 32)
82779 + goto end;
82780 +
82781 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
82782 +
82783 + if (KeyIdx < 4)
82784 + {
82785 + // it is a default shared key, for Pairwise key setting
82786 + if (pKey->KeyIndex & 0x80000000)
82787 + {
82788 + pEntry = MacTableLookup(pAd, pKey->BSSID);
82789 +
82790 + if (pEntry)
82791 + {
82792 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
82793 +
82794 + // set key material and key length
82795 + pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
82796 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
82797 +
82798 + // set Cipher type
82799 + if (pKey->KeyLength == 5)
82800 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
82801 + else
82802 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
82803 +
82804 + // Add Pair-wise key to Asic
82805 + AsicAddPairwiseKeyEntry(
82806 + pAd,
82807 + pEntry->Addr,
82808 + (UCHAR)pEntry->Aid,
82809 + &pEntry->PairwiseKey);
82810 +
82811 + // update WCID attribute table and IVEIV table for this entry
82812 + RTMPAddWcidAttributeEntry(
82813 + pAd,
82814 + BSS0,
82815 + KeyIdx, // The value may be not zero
82816 + pEntry->PairwiseKey.CipherAlg,
82817 + pEntry);
82818 +
82819 + }
82820 + }
82821 + else
82822 + {
82823 + // Default key for tx (shared key)
82824 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
82825 +
82826 + // set key material and key length
82827 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
82828 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
82829 +
82830 + // Set Ciper type
82831 + if (pKey->KeyLength == 5)
82832 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
82833 + else
82834 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
82835 +
82836 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
82837 + Key = pAd->SharedKey[BSS0][KeyIdx].Key;
82838 +
82839 + // Set Group key material to Asic
82840 + AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
82841 +
82842 + // Update WCID attribute table and IVEIV table for this group key table
82843 + RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
82844 +
82845 + }
82846 + }
82847 + }
82848 +end:
82849 + return;
82850 +}
82851 +
82852 +char * rtstrchr(const char * s, int c)
82853 +{
82854 + for(; *s != (char) c; ++s)
82855 + if (*s == '\0')
82856 + return NULL;
82857 + return (char *) s;
82858 +}
82859 +
82860 +/*
82861 +This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
82862 +*/
82863 +
82864 +int
82865 +rt_ioctl_giwname(struct net_device *dev,
82866 + struct iw_request_info *info,
82867 + char *name, char *extra)
82868 +{
82869 +// PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
82870 +
82871 +#ifdef RT2870
82872 + strncpy(name, "RT2870 Wireless", IFNAMSIZ);
82873 +#endif // RT2870 //
82874 + return 0;
82875 +}
82876 +
82877 +int rt_ioctl_siwfreq(struct net_device *dev,
82878 + struct iw_request_info *info,
82879 + struct iw_freq *freq, char *extra)
82880 +{
82881 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
82882 + int chan = -1;
82883 +
82884 + //check if the interface is down
82885 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
82886 + {
82887 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
82888 + return -ENETDOWN;
82889 + }
82890 +
82891 +
82892 + if (freq->e > 1)
82893 + return -EINVAL;
82894 +
82895 + if((freq->e == 0) && (freq->m <= 1000))
82896 + chan = freq->m; // Setting by channel number
82897 + else
82898 + MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
82899 +
82900 + if (ChannelSanity(pAdapter, chan) == TRUE)
82901 + {
82902 + pAdapter->CommonCfg.Channel = chan;
82903 + DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
82904 + }
82905 + else
82906 + return -EINVAL;
82907 +
82908 + return 0;
82909 +}
82910 +int rt_ioctl_giwfreq(struct net_device *dev,
82911 + struct iw_request_info *info,
82912 + struct iw_freq *freq, char *extra)
82913 +{
82914 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
82915 + PRTMP_ADAPTER pAdapter = NULL;
82916 + UCHAR ch;
82917 + ULONG m;
82918 +
82919 + if (dev->priv_flags == INT_MAIN)
82920 + {
82921 + pAdapter = dev->priv;
82922 + }
82923 + else
82924 + {
82925 + pVirtualAd = dev->priv;
82926 + if (pVirtualAd && pVirtualAd->RtmpDev)
82927 + pAdapter = pVirtualAd->RtmpDev->priv;
82928 + }
82929 +
82930 + if (pAdapter == NULL)
82931 + {
82932 + /* if 1st open fail, pAd will be free;
82933 + So the net_dev->priv will be NULL in 2rd open */
82934 + return -ENETDOWN;
82935 + }
82936 +
82937 + ch = pAdapter->CommonCfg.Channel;
82938 +
82939 + DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
82940 +
82941 + MAP_CHANNEL_ID_TO_KHZ(ch, m);
82942 + freq->m = m * 100;
82943 + freq->e = 1;
82944 + return 0;
82945 +}
82946 +
82947 +int rt_ioctl_siwmode(struct net_device *dev,
82948 + struct iw_request_info *info,
82949 + __u32 *mode, char *extra)
82950 +{
82951 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
82952 +
82953 + //check if the interface is down
82954 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
82955 + {
82956 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
82957 + return -ENETDOWN;
82958 + }
82959 +
82960 + switch (*mode)
82961 + {
82962 + case IW_MODE_ADHOC:
82963 + Set_NetworkType_Proc(pAdapter, "Adhoc");
82964 + break;
82965 + case IW_MODE_INFRA:
82966 + Set_NetworkType_Proc(pAdapter, "Infra");
82967 + break;
82968 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
82969 + case IW_MODE_MONITOR:
82970 + Set_NetworkType_Proc(pAdapter, "Monitor");
82971 + break;
82972 +#endif
82973 + default:
82974 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
82975 + return -EINVAL;
82976 + }
82977 +
82978 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
82979 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
82980 +
82981 + return 0;
82982 +}
82983 +
82984 +int rt_ioctl_giwmode(struct net_device *dev,
82985 + struct iw_request_info *info,
82986 + __u32 *mode, char *extra)
82987 +{
82988 + PRTMP_ADAPTER pAdapter = NULL;
82989 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
82990 +
82991 + if (dev->priv_flags == INT_MAIN)
82992 + {
82993 + pAdapter = dev->priv;
82994 + }
82995 + else
82996 + {
82997 + pVirtualAd = dev->priv;
82998 + if (pVirtualAd && pVirtualAd->RtmpDev)
82999 + pAdapter = pVirtualAd->RtmpDev->priv;
83000 + }
83001 +
83002 + if (pAdapter == NULL)
83003 + {
83004 + /* if 1st open fail, pAd will be free;
83005 + So the net_dev->priv will be NULL in 2rd open */
83006 + return -ENETDOWN;
83007 + }
83008 +
83009 + if (ADHOC_ON(pAdapter))
83010 + *mode = IW_MODE_ADHOC;
83011 + else if (INFRA_ON(pAdapter))
83012 + *mode = IW_MODE_INFRA;
83013 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
83014 + else if (MONITOR_ON(pAdapter))
83015 + {
83016 + *mode = IW_MODE_MONITOR;
83017 + }
83018 +#endif
83019 + else
83020 + *mode = IW_MODE_AUTO;
83021 +
83022 + DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
83023 + return 0;
83024 +}
83025 +
83026 +int rt_ioctl_siwsens(struct net_device *dev,
83027 + struct iw_request_info *info,
83028 + char *name, char *extra)
83029 +{
83030 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83031 +
83032 + //check if the interface is down
83033 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83034 + {
83035 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83036 + return -ENETDOWN;
83037 + }
83038 +
83039 + return 0;
83040 +}
83041 +
83042 +int rt_ioctl_giwsens(struct net_device *dev,
83043 + struct iw_request_info *info,
83044 + char *name, char *extra)
83045 +{
83046 + return 0;
83047 +}
83048 +
83049 +int rt_ioctl_giwrange(struct net_device *dev,
83050 + struct iw_request_info *info,
83051 + struct iw_point *data, char *extra)
83052 +{
83053 + PRTMP_ADAPTER pAdapter = NULL;
83054 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83055 + struct iw_range *range = (struct iw_range *) extra;
83056 + u16 val;
83057 + int i;
83058 +
83059 + if (dev->priv_flags == INT_MAIN)
83060 + {
83061 + pAdapter = dev->priv;
83062 + }
83063 + else
83064 + {
83065 + pVirtualAd = dev->priv;
83066 + if (pVirtualAd && pVirtualAd->RtmpDev)
83067 + pAdapter = pVirtualAd->RtmpDev->priv;
83068 + }
83069 +
83070 + if (pAdapter == NULL)
83071 + {
83072 + /* if 1st open fail, pAd will be free;
83073 + So the net_dev->priv will be NULL in 2rd open */
83074 + return -ENETDOWN;
83075 + }
83076 +
83077 + DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
83078 + data->length = sizeof(struct iw_range);
83079 + memset(range, 0, sizeof(struct iw_range));
83080 +
83081 + range->txpower_capa = IW_TXPOW_DBM;
83082 +
83083 + if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
83084 + {
83085 + range->min_pmp = 1 * 1024;
83086 + range->max_pmp = 65535 * 1024;
83087 + range->min_pmt = 1 * 1024;
83088 + range->max_pmt = 1000 * 1024;
83089 + range->pmp_flags = IW_POWER_PERIOD;
83090 + range->pmt_flags = IW_POWER_TIMEOUT;
83091 + range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
83092 + IW_POWER_UNICAST_R | IW_POWER_ALL_R;
83093 + }
83094 +
83095 + range->we_version_compiled = WIRELESS_EXT;
83096 + range->we_version_source = 14;
83097 +
83098 + range->retry_capa = IW_RETRY_LIMIT;
83099 + range->retry_flags = IW_RETRY_LIMIT;
83100 + range->min_retry = 0;
83101 + range->max_retry = 255;
83102 +
83103 + range->num_channels = pAdapter->ChannelListNum;
83104 +
83105 + val = 0;
83106 + for (i = 1; i <= range->num_channels; i++)
83107 + {
83108 + u32 m;
83109 + range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
83110 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
83111 + range->freq[val].m = m * 100; /* HZ */
83112 +
83113 + range->freq[val].e = 1;
83114 + val++;
83115 + if (val == IW_MAX_FREQUENCIES)
83116 + break;
83117 + }
83118 + range->num_frequency = val;
83119 +
83120 + range->max_qual.qual = 100; /* what is correct max? This was not
83121 + * documented exactly. At least
83122 + * 69 has been observed. */
83123 + range->max_qual.level = 0; /* dB */
83124 + range->max_qual.noise = 0; /* dB */
83125 +
83126 + /* What would be suitable values for "average/typical" qual? */
83127 + range->avg_qual.qual = 20;
83128 + range->avg_qual.level = -60;
83129 + range->avg_qual.noise = -95;
83130 + range->sensitivity = 3;
83131 +
83132 + range->max_encoding_tokens = NR_WEP_KEYS;
83133 + range->num_encoding_sizes = 2;
83134 + range->encoding_size[0] = 5;
83135 + range->encoding_size[1] = 13;
83136 +
83137 + range->min_rts = 0;
83138 + range->max_rts = 2347;
83139 + range->min_frag = 256;
83140 + range->max_frag = 2346;
83141 +
83142 +#if WIRELESS_EXT > 17
83143 + /* IW_ENC_CAPA_* bit field */
83144 + range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
83145 + IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
83146 +#endif
83147 +
83148 + return 0;
83149 +}
83150 +
83151 +int rt_ioctl_siwap(struct net_device *dev,
83152 + struct iw_request_info *info,
83153 + struct sockaddr *ap_addr, char *extra)
83154 +{
83155 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83156 + NDIS_802_11_MAC_ADDRESS Bssid;
83157 +
83158 + //check if the interface is down
83159 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83160 + {
83161 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83162 + return -ENETDOWN;
83163 + }
83164 +
83165 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
83166 + {
83167 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
83168 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
83169 + }
83170 +
83171 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
83172 + // this request, because this request is initiated by NDIS.
83173 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
83174 + // Prevent to connect AP again in STAMlmePeriodicExec
83175 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
83176 +
83177 + memset(Bssid, 0, MAC_ADDR_LEN);
83178 + memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
83179 + MlmeEnqueue(pAdapter,
83180 + MLME_CNTL_STATE_MACHINE,
83181 + OID_802_11_BSSID,
83182 + sizeof(NDIS_802_11_MAC_ADDRESS),
83183 + (VOID *)&Bssid);
83184 +
83185 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
83186 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
83187 +
83188 + return 0;
83189 +}
83190 +
83191 +int rt_ioctl_giwap(struct net_device *dev,
83192 + struct iw_request_info *info,
83193 + struct sockaddr *ap_addr, char *extra)
83194 +{
83195 + PRTMP_ADAPTER pAdapter = NULL;
83196 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83197 +
83198 + if (dev->priv_flags == INT_MAIN)
83199 + {
83200 + pAdapter = dev->priv;
83201 + }
83202 + else
83203 + {
83204 + pVirtualAd = dev->priv;
83205 + if (pVirtualAd && pVirtualAd->RtmpDev)
83206 + pAdapter = pVirtualAd->RtmpDev->priv;
83207 + }
83208 +
83209 + if (pAdapter == NULL)
83210 + {
83211 + /* if 1st open fail, pAd will be free;
83212 + So the net_dev->priv will be NULL in 2rd open */
83213 + return -ENETDOWN;
83214 + }
83215 +
83216 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
83217 + {
83218 + ap_addr->sa_family = ARPHRD_ETHER;
83219 + memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
83220 + }
83221 +#ifdef WPA_SUPPLICANT_SUPPORT
83222 + // Add for RT2870
83223 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
83224 + {
83225 + ap_addr->sa_family = ARPHRD_ETHER;
83226 + memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
83227 + }
83228 +#endif // WPA_SUPPLICANT_SUPPORT //
83229 + else
83230 + {
83231 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
83232 + return -ENOTCONN;
83233 + }
83234 +
83235 + return 0;
83236 +}
83237 +
83238 +/*
83239 + * Units are in db above the noise floor. That means the
83240 + * rssi values reported in the tx/rx descriptors in the
83241 + * driver are the SNR expressed in db.
83242 + *
83243 + * If you assume that the noise floor is -95, which is an
83244 + * excellent assumption 99.5 % of the time, then you can
83245 + * derive the absolute signal level (i.e. -95 + rssi).
83246 + * There are some other slight factors to take into account
83247 + * depending on whether the rssi measurement is from 11b,
83248 + * 11g, or 11a. These differences are at most 2db and
83249 + * can be documented.
83250 + *
83251 + * NB: various calculations are based on the orinoco/wavelan
83252 + * drivers for compatibility
83253 + */
83254 +static void set_quality(PRTMP_ADAPTER pAdapter,
83255 + struct iw_quality *iq,
83256 + signed char rssi)
83257 +{
83258 + __u8 ChannelQuality;
83259 +
83260 + // Normalize Rssi
83261 + if (rssi >= -50)
83262 + ChannelQuality = 100;
83263 + else if (rssi >= -80) // between -50 ~ -80dbm
83264 + ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
83265 + else if (rssi >= -90) // between -80 ~ -90dbm
83266 + ChannelQuality = (__u8)((rssi + 90) * 26)/10;
83267 + else
83268 + ChannelQuality = 0;
83269 +
83270 + iq->qual = (__u8)ChannelQuality;
83271 +
83272 + iq->level = (__u8)(rssi);
83273 + iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
83274 + iq->noise += 256 - 143;
83275 + iq->updated = pAdapter->iw_stats.qual.updated;
83276 +}
83277 +
83278 +int rt_ioctl_iwaplist(struct net_device *dev,
83279 + struct iw_request_info *info,
83280 + struct iw_point *data, char *extra)
83281 +{
83282 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83283 +
83284 + struct sockaddr addr[IW_MAX_AP];
83285 + struct iw_quality qual[IW_MAX_AP];
83286 + int i;
83287 +
83288 + //check if the interface is down
83289 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83290 + {
83291 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83292 + data->length = 0;
83293 + return 0;
83294 + //return -ENETDOWN;
83295 + }
83296 +
83297 + for (i = 0; i <IW_MAX_AP ; i++)
83298 + {
83299 + if (i >= pAdapter->ScanTab.BssNr)
83300 + break;
83301 + addr[i].sa_family = ARPHRD_ETHER;
83302 + memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
83303 + set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
83304 + }
83305 + data->length = i;
83306 + memcpy(extra, &addr, i*sizeof(addr[0]));
83307 + data->flags = 1; /* signal quality present (sort of) */
83308 + memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
83309 +
83310 + return 0;
83311 +}
83312 +
83313 +#ifdef SIOCGIWSCAN
83314 +int rt_ioctl_siwscan(struct net_device *dev,
83315 + struct iw_request_info *info,
83316 + struct iw_point *data, char *extra)
83317 +{
83318 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83319 +
83320 + ULONG Now;
83321 + int Status = NDIS_STATUS_SUCCESS;
83322 +
83323 + //check if the interface is down
83324 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83325 + {
83326 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83327 + return -ENETDOWN;
83328 + }
83329 +
83330 + if (MONITOR_ON(pAdapter))
83331 + {
83332 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
83333 + return -EINVAL;
83334 + }
83335 +
83336 +
83337 +#ifdef WPA_SUPPLICANT_SUPPORT
83338 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
83339 + {
83340 + pAdapter->StaCfg.WpaSupplicantScanCount++;
83341 + }
83342 +#endif // WPA_SUPPLICANT_SUPPORT //
83343 +
83344 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
83345 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
83346 + return 0;
83347 + do{
83348 + Now = jiffies;
83349 +
83350 +#ifdef WPA_SUPPLICANT_SUPPORT
83351 + if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
83352 + (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
83353 + {
83354 + DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
83355 + Status = NDIS_STATUS_SUCCESS;
83356 + break;
83357 + }
83358 +#endif // WPA_SUPPLICANT_SUPPORT //
83359 +
83360 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
83361 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
83362 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
83363 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
83364 + {
83365 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
83366 + Status = NDIS_STATUS_SUCCESS;
83367 + break;
83368 + }
83369 +
83370 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
83371 + {
83372 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
83373 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
83374 + }
83375 +
83376 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
83377 + // this request, because this request is initiated by NDIS.
83378 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
83379 + // Reset allowed scan retries
83380 + pAdapter->StaCfg.ScanCnt = 0;
83381 + pAdapter->StaCfg.LastScanTime = Now;
83382 +
83383 + MlmeEnqueue(pAdapter,
83384 + MLME_CNTL_STATE_MACHINE,
83385 + OID_802_11_BSSID_LIST_SCAN,
83386 + 0,
83387 + NULL);
83388 +
83389 + Status = NDIS_STATUS_SUCCESS;
83390 + RT28XX_MLME_HANDLER(pAdapter);
83391 + }while(0);
83392 + return 0;
83393 +}
83394 +
83395 +int rt_ioctl_giwscan(struct net_device *dev,
83396 + struct iw_request_info *info,
83397 + struct iw_point *data, char *extra)
83398 +{
83399 +
83400 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83401 + int i=0;
83402 + char *current_ev = extra, *previous_ev = extra;
83403 + char *end_buf;
83404 + char *current_val, custom[MAX_CUSTOM_LEN] = {0};
83405 +#ifndef IWEVGENIE
83406 + char idx;
83407 +#endif // IWEVGENIE //
83408 + struct iw_event iwe;
83409 +
83410 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
83411 + {
83412 + /*
83413 + * Still scanning, indicate the caller should try again.
83414 + */
83415 + return -EAGAIN;
83416 + }
83417 +
83418 +
83419 +#ifdef WPA_SUPPLICANT_SUPPORT
83420 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
83421 + {
83422 + pAdapter->StaCfg.WpaSupplicantScanCount = 0;
83423 + }
83424 +#endif // WPA_SUPPLICANT_SUPPORT //
83425 +
83426 + if (pAdapter->ScanTab.BssNr == 0)
83427 + {
83428 + data->length = 0;
83429 + return 0;
83430 + }
83431 +
83432 +#if WIRELESS_EXT >= 17
83433 + if (data->length > 0)
83434 + end_buf = extra + data->length;
83435 + else
83436 + end_buf = extra + IW_SCAN_MAX_DATA;
83437 +#else
83438 + end_buf = extra + IW_SCAN_MAX_DATA;
83439 +#endif
83440 +
83441 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
83442 + {
83443 + if (current_ev >= end_buf)
83444 + {
83445 +#if WIRELESS_EXT >= 17
83446 + return -E2BIG;
83447 +#else
83448 + break;
83449 +#endif
83450 + }
83451 +
83452 + //MAC address
83453 + //================================
83454 + memset(&iwe, 0, sizeof(iwe));
83455 + iwe.cmd = SIOCGIWAP;
83456 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
83457 + memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
83458 +
83459 + previous_ev = current_ev;
83460 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
83461 + if (current_ev == previous_ev)
83462 +#if WIRELESS_EXT >= 17
83463 + return -E2BIG;
83464 +#else
83465 + break;
83466 +#endif
83467 +
83468 + //ESSID
83469 + //================================
83470 + memset(&iwe, 0, sizeof(iwe));
83471 + iwe.cmd = SIOCGIWESSID;
83472 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
83473 + iwe.u.data.flags = 1;
83474 +
83475 + previous_ev = current_ev;
83476 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
83477 + if (current_ev == previous_ev)
83478 +#if WIRELESS_EXT >= 17
83479 + return -E2BIG;
83480 +#else
83481 + break;
83482 +#endif
83483 +
83484 + //Network Type
83485 + //================================
83486 + memset(&iwe, 0, sizeof(iwe));
83487 + iwe.cmd = SIOCGIWMODE;
83488 + if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
83489 + {
83490 + iwe.u.mode = IW_MODE_ADHOC;
83491 + }
83492 + else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
83493 + {
83494 + iwe.u.mode = IW_MODE_INFRA;
83495 + }
83496 + else
83497 + {
83498 + iwe.u.mode = IW_MODE_AUTO;
83499 + }
83500 + iwe.len = IW_EV_UINT_LEN;
83501 +
83502 + previous_ev = current_ev;
83503 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
83504 + if (current_ev == previous_ev)
83505 +#if WIRELESS_EXT >= 17
83506 + return -E2BIG;
83507 +#else
83508 + break;
83509 +#endif
83510 +
83511 + //Channel and Frequency
83512 + //================================
83513 + memset(&iwe, 0, sizeof(iwe));
83514 + iwe.cmd = SIOCGIWFREQ;
83515 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
83516 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
83517 + else
83518 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
83519 + iwe.u.freq.e = 0;
83520 + iwe.u.freq.i = 0;
83521 +
83522 + previous_ev = current_ev;
83523 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
83524 + if (current_ev == previous_ev)
83525 +#if WIRELESS_EXT >= 17
83526 + return -E2BIG;
83527 +#else
83528 + break;
83529 +#endif
83530 +
83531 + //Add quality statistics
83532 + //================================
83533 + memset(&iwe, 0, sizeof(iwe));
83534 + iwe.cmd = IWEVQUAL;
83535 + iwe.u.qual.level = 0;
83536 + iwe.u.qual.noise = 0;
83537 + set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
83538 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
83539 + if (current_ev == previous_ev)
83540 +#if WIRELESS_EXT >= 17
83541 + return -E2BIG;
83542 +#else
83543 + break;
83544 +#endif
83545 +
83546 + //Encyption key
83547 + //================================
83548 + memset(&iwe, 0, sizeof(iwe));
83549 + iwe.cmd = SIOCGIWENCODE;
83550 + if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
83551 + iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
83552 + else
83553 + iwe.u.data.flags = IW_ENCODE_DISABLED;
83554 +
83555 + previous_ev = current_ev;
83556 + 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);
83557 + if (current_ev == previous_ev)
83558 +#if WIRELESS_EXT >= 17
83559 + return -E2BIG;
83560 +#else
83561 + break;
83562 +#endif
83563 +
83564 + //Bit Rate
83565 + //================================
83566 + if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
83567 + {
83568 + UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
83569 + memset(&iwe, 0, sizeof(iwe));
83570 + iwe.cmd = SIOCGIWRATE;
83571 + current_val = current_ev + IW_EV_LCP_LEN;
83572 + if (tmpRate == 0x82)
83573 + iwe.u.bitrate.value = 1 * 1000000;
83574 + else if (tmpRate == 0x84)
83575 + iwe.u.bitrate.value = 2 * 1000000;
83576 + else if (tmpRate == 0x8B)
83577 + iwe.u.bitrate.value = 5.5 * 1000000;
83578 + else if (tmpRate == 0x96)
83579 + iwe.u.bitrate.value = 11 * 1000000;
83580 + else
83581 + iwe.u.bitrate.value = (tmpRate/2) * 1000000;
83582 +
83583 + iwe.u.bitrate.disabled = 0;
83584 + current_val = IWE_STREAM_ADD_VALUE(info, current_ev,
83585 + current_val, end_buf, &iwe,
83586 + IW_EV_PARAM_LEN);
83587 +
83588 + if((current_val-current_ev)>IW_EV_LCP_LEN)
83589 + current_ev = current_val;
83590 + else
83591 +#if WIRELESS_EXT >= 17
83592 + return -E2BIG;
83593 +#else
83594 + break;
83595 +#endif
83596 + }
83597 +
83598 +#ifdef IWEVGENIE
83599 + //WPA IE
83600 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
83601 + {
83602 + memset(&iwe, 0, sizeof(iwe));
83603 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
83604 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
83605 + pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
83606 + iwe.cmd = IWEVGENIE;
83607 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
83608 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
83609 + if (current_ev == previous_ev)
83610 +#if WIRELESS_EXT >= 17
83611 + return -E2BIG;
83612 +#else
83613 + break;
83614 +#endif
83615 + }
83616 +
83617 + //WPA2 IE
83618 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
83619 + {
83620 + memset(&iwe, 0, sizeof(iwe));
83621 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
83622 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
83623 + pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
83624 + iwe.cmd = IWEVGENIE;
83625 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
83626 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
83627 + if (current_ev == previous_ev)
83628 +#if WIRELESS_EXT >= 17
83629 + return -E2BIG;
83630 +#else
83631 + break;
83632 +#endif
83633 + }
83634 +#else
83635 + //WPA IE
83636 + //================================
83637 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
83638 + {
83639 + NdisZeroMemory(&iwe, sizeof(iwe));
83640 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
83641 + iwe.cmd = IWEVCUSTOM;
83642 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
83643 + NdisMoveMemory(custom, "wpa_ie=", 7);
83644 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
83645 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
83646 + previous_ev = current_ev;
83647 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
83648 + if (current_ev == previous_ev)
83649 +#if WIRELESS_EXT >= 17
83650 + return -E2BIG;
83651 +#else
83652 + break;
83653 +#endif
83654 + }
83655 +
83656 + //WPA2 IE
83657 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
83658 + {
83659 + NdisZeroMemory(&iwe, sizeof(iwe));
83660 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
83661 + iwe.cmd = IWEVCUSTOM;
83662 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
83663 + NdisMoveMemory(custom, "rsn_ie=", 7);
83664 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
83665 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
83666 + previous_ev = current_ev;
83667 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
83668 + if (current_ev == previous_ev)
83669 +#if WIRELESS_EXT >= 17
83670 + return -E2BIG;
83671 +#else
83672 + break;
83673 +#endif
83674 + }
83675 +#endif // IWEVGENIE //
83676 + }
83677 +
83678 + data->length = current_ev - extra;
83679 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
83680 + DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
83681 + return 0;
83682 +}
83683 +#endif
83684 +
83685 +int rt_ioctl_siwessid(struct net_device *dev,
83686 + struct iw_request_info *info,
83687 + struct iw_point *data, char *essid)
83688 +{
83689 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83690 +
83691 + //check if the interface is down
83692 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83693 + {
83694 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83695 + return -ENETDOWN;
83696 + }
83697 +
83698 + if (data->flags)
83699 + {
83700 + PCHAR pSsidString = NULL;
83701 +
83702 + // Includes null character.
83703 + if (data->length > (IW_ESSID_MAX_SIZE + 1))
83704 + return -E2BIG;
83705 +
83706 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
83707 + if (pSsidString)
83708 + {
83709 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
83710 + NdisMoveMemory(pSsidString, essid, data->length);
83711 + if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
83712 + return -EINVAL;
83713 + }
83714 + else
83715 + return -ENOMEM;
83716 + }
83717 + else
83718 + {
83719 + // ANY ssid
83720 + if (Set_SSID_Proc(pAdapter, "") == FALSE)
83721 + return -EINVAL;
83722 + }
83723 + return 0;
83724 +}
83725 +
83726 +int rt_ioctl_giwessid(struct net_device *dev,
83727 + struct iw_request_info *info,
83728 + struct iw_point *data, char *essid)
83729 +{
83730 + PRTMP_ADAPTER pAdapter = NULL;
83731 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83732 +
83733 + if (dev->priv_flags == INT_MAIN)
83734 + {
83735 + pAdapter = dev->priv;
83736 + }
83737 + else
83738 + {
83739 + pVirtualAd = dev->priv;
83740 + if (pVirtualAd && pVirtualAd->RtmpDev)
83741 + pAdapter = pVirtualAd->RtmpDev->priv;
83742 + }
83743 +
83744 + if (pAdapter == NULL)
83745 + {
83746 + /* if 1st open fail, pAd will be free;
83747 + So the net_dev->priv will be NULL in 2rd open */
83748 + return -ENETDOWN;
83749 + }
83750 +
83751 + data->flags = 1;
83752 + if (MONITOR_ON(pAdapter))
83753 + {
83754 + data->length = 0;
83755 + return 0;
83756 + }
83757 +
83758 + if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
83759 + {
83760 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
83761 + data->length = pAdapter->CommonCfg.SsidLen;
83762 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
83763 + }
83764 +#ifdef RT2870
83765 +#ifdef WPA_SUPPLICANT_SUPPORT
83766 + // Add for RT2870
83767 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
83768 + {
83769 + data->length = pAdapter->CommonCfg.SsidLen;
83770 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
83771 + }
83772 +#endif // WPA_SUPPLICANT_SUPPORT //
83773 +#endif // RT2870 //
83774 + else
83775 + {//the ANY ssid was specified
83776 + data->length = 0;
83777 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
83778 + }
83779 +
83780 + return 0;
83781 +
83782 +}
83783 +
83784 +int rt_ioctl_siwnickn(struct net_device *dev,
83785 + struct iw_request_info *info,
83786 + struct iw_point *data, char *nickname)
83787 +{
83788 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83789 +
83790 + //check if the interface is down
83791 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83792 + {
83793 + DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
83794 + return -ENETDOWN;
83795 + }
83796 +
83797 + if (data->length > IW_ESSID_MAX_SIZE)
83798 + return -EINVAL;
83799 +
83800 + memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
83801 + memcpy(pAdapter->nickname, nickname, data->length);
83802 +
83803 +
83804 + return 0;
83805 +}
83806 +
83807 +int rt_ioctl_giwnickn(struct net_device *dev,
83808 + struct iw_request_info *info,
83809 + struct iw_point *data, char *nickname)
83810 +{
83811 + PRTMP_ADAPTER pAdapter = NULL;
83812 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83813 +
83814 + if (dev->priv_flags == INT_MAIN)
83815 + {
83816 + pAdapter = dev->priv;
83817 + }
83818 + else
83819 + {
83820 + pVirtualAd = dev->priv;
83821 + if (pVirtualAd && pVirtualAd->RtmpDev)
83822 + pAdapter = pVirtualAd->RtmpDev->priv;
83823 + }
83824 +
83825 + if (pAdapter == NULL)
83826 + {
83827 + /* if 1st open fail, pAd will be free;
83828 + So the net_dev->priv will be NULL in 2rd open */
83829 + return -ENETDOWN;
83830 + }
83831 +
83832 + if (data->length > strlen(pAdapter->nickname) + 1)
83833 + data->length = strlen(pAdapter->nickname) + 1;
83834 + if (data->length > 0) {
83835 + memcpy(nickname, pAdapter->nickname, data->length-1);
83836 + nickname[data->length-1] = '\0';
83837 + }
83838 + return 0;
83839 +}
83840 +
83841 +int rt_ioctl_siwrts(struct net_device *dev,
83842 + struct iw_request_info *info,
83843 + struct iw_param *rts, char *extra)
83844 +{
83845 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83846 + u16 val;
83847 +
83848 + //check if the interface is down
83849 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83850 + {
83851 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83852 + return -ENETDOWN;
83853 + }
83854 +
83855 + if (rts->disabled)
83856 + val = MAX_RTS_THRESHOLD;
83857 + else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
83858 + return -EINVAL;
83859 + else if (rts->value == 0)
83860 + val = MAX_RTS_THRESHOLD;
83861 + else
83862 + val = rts->value;
83863 +
83864 + if (val != pAdapter->CommonCfg.RtsThreshold)
83865 + pAdapter->CommonCfg.RtsThreshold = val;
83866 +
83867 + return 0;
83868 +}
83869 +
83870 +int rt_ioctl_giwrts(struct net_device *dev,
83871 + struct iw_request_info *info,
83872 + struct iw_param *rts, char *extra)
83873 +{
83874 + PRTMP_ADAPTER pAdapter = NULL;
83875 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83876 +
83877 + if (dev->priv_flags == INT_MAIN)
83878 + {
83879 + pAdapter = dev->priv;
83880 + }
83881 + else
83882 + {
83883 + pVirtualAd = dev->priv;
83884 + if (pVirtualAd && pVirtualAd->RtmpDev)
83885 + pAdapter = pVirtualAd->RtmpDev->priv;
83886 + }
83887 +
83888 + if (pAdapter == NULL)
83889 + {
83890 + /* if 1st open fail, pAd will be free;
83891 + So the net_dev->priv will be NULL in 2rd open */
83892 + return -ENETDOWN;
83893 + }
83894 +
83895 + //check if the interface is down
83896 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83897 + {
83898 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83899 + return -ENETDOWN;
83900 + }
83901 +
83902 + rts->value = pAdapter->CommonCfg.RtsThreshold;
83903 + rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
83904 + rts->fixed = 1;
83905 +
83906 + return 0;
83907 +}
83908 +
83909 +int rt_ioctl_siwfrag(struct net_device *dev,
83910 + struct iw_request_info *info,
83911 + struct iw_param *frag, char *extra)
83912 +{
83913 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83914 + u16 val;
83915 +
83916 + //check if the interface is down
83917 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83918 + {
83919 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83920 + return -ENETDOWN;
83921 + }
83922 +
83923 + if (frag->disabled)
83924 + val = MAX_FRAG_THRESHOLD;
83925 + else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
83926 + val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
83927 + else if (frag->value == 0)
83928 + val = MAX_FRAG_THRESHOLD;
83929 + else
83930 + return -EINVAL;
83931 +
83932 + pAdapter->CommonCfg.FragmentThreshold = val;
83933 + return 0;
83934 +}
83935 +
83936 +int rt_ioctl_giwfrag(struct net_device *dev,
83937 + struct iw_request_info *info,
83938 + struct iw_param *frag, char *extra)
83939 +{
83940 + PRTMP_ADAPTER pAdapter = NULL;
83941 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83942 +
83943 + if (dev->priv_flags == INT_MAIN)
83944 + {
83945 + pAdapter = dev->priv;
83946 + }
83947 + else
83948 + {
83949 + pVirtualAd = dev->priv;
83950 + if (pVirtualAd && pVirtualAd->RtmpDev)
83951 + pAdapter = pVirtualAd->RtmpDev->priv;
83952 + }
83953 +
83954 + if (pAdapter == NULL)
83955 + {
83956 + /* if 1st open fail, pAd will be free;
83957 + So the net_dev->priv will be NULL in 2rd open */
83958 + return -ENETDOWN;
83959 + }
83960 +
83961 + //check if the interface is down
83962 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83963 + {
83964 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83965 + return -ENETDOWN;
83966 + }
83967 +
83968 + frag->value = pAdapter->CommonCfg.FragmentThreshold;
83969 + frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
83970 + frag->fixed = 1;
83971 +
83972 + return 0;
83973 +}
83974 +
83975 +#define MAX_WEP_KEY_SIZE 13
83976 +#define MIN_WEP_KEY_SIZE 5
83977 +int rt_ioctl_siwencode(struct net_device *dev,
83978 + struct iw_request_info *info,
83979 + struct iw_point *erq, char *extra)
83980 +{
83981 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
83982 +
83983 + //check if the interface is down
83984 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83985 + {
83986 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83987 + return -ENETDOWN;
83988 + }
83989 +
83990 + if ((erq->length == 0) &&
83991 + (erq->flags & IW_ENCODE_DISABLED))
83992 + {
83993 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
83994 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
83995 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
83996 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
83997 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
83998 + goto done;
83999 + }
84000 + else if ((erq->length == 0) &&
84001 + (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
84002 + {
84003 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84004 + STA_PORT_SECURED(pAdapter);
84005 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
84006 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
84007 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
84008 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84009 + if (erq->flags & IW_ENCODE_RESTRICTED)
84010 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
84011 + else
84012 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
84013 + goto done;
84014 + }
84015 +
84016 + if (erq->length > 0)
84017 + {
84018 + int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
84019 + /* Check the size of the key */
84020 + if (erq->length > MAX_WEP_KEY_SIZE) {
84021 + return -EINVAL;
84022 + }
84023 + /* Check key index */
84024 + if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
84025 + {
84026 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
84027 + keyIdx, pAdapter->StaCfg.DefaultKeyId));
84028 +
84029 + //Using default key
84030 + keyIdx = pAdapter->StaCfg.DefaultKeyId;
84031 + }
84032 +
84033 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
84034 +
84035 + if (erq->length == MAX_WEP_KEY_SIZE)
84036 + {
84037 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
84038 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
84039 + }
84040 + else if (erq->length == MIN_WEP_KEY_SIZE)
84041 + {
84042 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
84043 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
84044 + }
84045 + else
84046 + /* Disable the key */
84047 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
84048 +
84049 + /* Check if the key is not marked as invalid */
84050 + if(!(erq->flags & IW_ENCODE_NOKEY)) {
84051 + /* Copy the key in the driver */
84052 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
84053 + }
84054 + }
84055 + else
84056 + {
84057 + /* Do we want to just set the transmit key index ? */
84058 + int index = (erq->flags & IW_ENCODE_INDEX) - 1;
84059 + if ((index >= 0) && (index < 4))
84060 + {
84061 + pAdapter->StaCfg.DefaultKeyId = index;
84062 + }
84063 + else
84064 + /* Don't complain if only change the mode */
84065 + if(!erq->flags & IW_ENCODE_MODE) {
84066 + return -EINVAL;
84067 + }
84068 + }
84069 +
84070 +done:
84071 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
84072 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
84073 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
84074 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
84075 + return 0;
84076 +}
84077 +
84078 +int
84079 +rt_ioctl_giwencode(struct net_device *dev,
84080 + struct iw_request_info *info,
84081 + struct iw_point *erq, char *key)
84082 +{
84083 + int kid;
84084 + PRTMP_ADAPTER pAdapter = NULL;
84085 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
84086 +
84087 + if (dev->priv_flags == INT_MAIN)
84088 + {
84089 + pAdapter = dev->priv;
84090 + }
84091 + else
84092 + {
84093 + pVirtualAd = dev->priv;
84094 + if (pVirtualAd && pVirtualAd->RtmpDev)
84095 + pAdapter = pVirtualAd->RtmpDev->priv;
84096 + }
84097 +
84098 + if (pAdapter == NULL)
84099 + {
84100 + /* if 1st open fail, pAd will be free;
84101 + So the net_dev->priv will be NULL in 2rd open */
84102 + return -ENETDOWN;
84103 + }
84104 +
84105 + //check if the interface is down
84106 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84107 + {
84108 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84109 + return -ENETDOWN;
84110 + }
84111 +
84112 + kid = erq->flags & IW_ENCODE_INDEX;
84113 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
84114 +
84115 + if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
84116 + {
84117 + erq->length = 0;
84118 + erq->flags = IW_ENCODE_DISABLED;
84119 + }
84120 + else if ((kid > 0) && (kid <=4))
84121 + {
84122 + // copy wep key
84123 + erq->flags = kid ; /* NB: base 1 */
84124 + if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
84125 + erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
84126 + memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
84127 + //if ((kid == pAdapter->PortCfg.DefaultKeyId))
84128 + //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
84129 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84130 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84131 + else
84132 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84133 +
84134 + }
84135 + else if (kid == 0)
84136 + {
84137 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84138 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84139 + else
84140 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84141 + erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
84142 + memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
84143 + // copy default key ID
84144 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84145 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84146 + else
84147 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84148 + erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
84149 + erq->flags |= IW_ENCODE_ENABLED; /* XXX */
84150 + }
84151 +
84152 + return 0;
84153 +
84154 +}
84155 +
84156 +static int
84157 +rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
84158 + void *w, char *extra)
84159 +{
84160 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
84161 + PRTMP_ADAPTER pAdapter;
84162 + POS_COOKIE pObj;
84163 + char *this_char = extra;
84164 + char *value;
84165 + int Status=0;
84166 +
84167 + if (dev->priv_flags == INT_MAIN)
84168 + {
84169 + pAdapter = dev->priv;
84170 + }
84171 + else
84172 + {
84173 + pVirtualAd = dev->priv;
84174 + pAdapter = pVirtualAd->RtmpDev->priv;
84175 + }
84176 + pObj = (POS_COOKIE) pAdapter->OS_Cookie;
84177 +
84178 + if (pAdapter == NULL)
84179 + {
84180 + /* if 1st open fail, pAd will be free;
84181 + So the net_dev->priv will be NULL in 2rd open */
84182 + return -ENETDOWN;
84183 + }
84184 +
84185 + {
84186 + pObj->ioctl_if_type = INT_MAIN;
84187 + pObj->ioctl_if = MAIN_MBSSID;
84188 + }
84189 +
84190 + //check if the interface is down
84191 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84192 + {
84193 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84194 + return -ENETDOWN;
84195 + }
84196 +
84197 + if (!*this_char)
84198 + return -EINVAL;
84199 +
84200 + if ((value = rtstrchr(this_char, '=')) != NULL)
84201 + *value++ = 0;
84202 +
84203 + if (!value)
84204 + return -EINVAL;
84205 +
84206 + // reject setting nothing besides ANY ssid(ssidLen=0)
84207 + if (!*value && (strcmp(this_char, "SSID") != 0))
84208 + return -EINVAL;
84209 +
84210 + for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
84211 + {
84212 + if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
84213 + {
84214 + if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
84215 + { //FALSE:Set private failed then return Invalid argument
84216 + Status = -EINVAL;
84217 + }
84218 + break; //Exit for loop.
84219 + }
84220 + }
84221 +
84222 + if(PRTMP_PRIVATE_SET_PROC->name == NULL)
84223 + { //Not found argument
84224 + Status = -EINVAL;
84225 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
84226 + }
84227 +
84228 + return Status;
84229 +}
84230 +
84231 +
84232 +static int
84233 +rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
84234 + struct iw_point *wrq, char *extra)
84235 +{
84236 + INT Status = 0;
84237 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
84238 +
84239 + if (extra == NULL)
84240 + {
84241 + wrq->length = 0;
84242 + return -EIO;
84243 + }
84244 +
84245 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
84246 + sprintf(extra, "\n\n");
84247 +
84248 +#ifdef RALINK_ATE
84249 + if (ATE_ON(pAd))
84250 + {
84251 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
84252 + //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
84253 + }
84254 + else
84255 +#endif // RALINK_ATE //
84256 + {
84257 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
84258 + sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
84259 + }
84260 + sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
84261 + sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
84262 + sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
84263 + sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
84264 +
84265 + sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
84266 + sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
84267 + sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
84268 + sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
84269 +
84270 + sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
84271 +#ifdef RALINK_ATE
84272 + if (ATE_ON(pAd))
84273 + {
84274 + if (pAd->ate.RxAntennaSel == 0)
84275 + {
84276 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
84277 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
84278 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
84279 + }
84280 + else
84281 + {
84282 + sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
84283 + }
84284 + }
84285 + else
84286 +#endif // RALINK_ATE //
84287 + {
84288 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
84289 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
84290 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
84291 + }
84292 +#ifdef WPA_SUPPLICANT_SUPPORT
84293 + sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
84294 +#endif // WPA_SUPPLICANT_SUPPORT //
84295 +
84296 +
84297 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84298 + DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
84299 +
84300 + return Status;
84301 +}
84302 +
84303 +#ifdef DOT11_N_SUPPORT
84304 +void getBaInfo(
84305 + IN PRTMP_ADAPTER pAd,
84306 + IN PUCHAR pOutBuf)
84307 +{
84308 + INT i, j;
84309 + BA_ORI_ENTRY *pOriBAEntry;
84310 + BA_REC_ENTRY *pRecBAEntry;
84311 +
84312 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
84313 + {
84314 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
84315 + if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
84316 + || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
84317 + {
84318 + sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
84319 + pOutBuf,
84320 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
84321 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
84322 +
84323 + sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
84324 + for (j=0; j < NUM_OF_TID; j++)
84325 + {
84326 + if (pEntry->BARecWcidArray[j] != 0)
84327 + {
84328 + pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
84329 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
84330 + }
84331 + }
84332 + sprintf(pOutBuf, "%s\n", pOutBuf);
84333 +
84334 + sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
84335 + for (j=0; j < NUM_OF_TID; j++)
84336 + {
84337 + if (pEntry->BAOriWcidArray[j] != 0)
84338 + {
84339 + pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
84340 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
84341 + }
84342 + }
84343 + sprintf(pOutBuf, "%s\n\n", pOutBuf);
84344 + }
84345 + if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
84346 + break;
84347 + }
84348 +
84349 + return;
84350 +}
84351 +#endif // DOT11_N_SUPPORT //
84352 +
84353 +static int
84354 +rt_private_show(struct net_device *dev, struct iw_request_info *info,
84355 + struct iw_point *wrq, char *extra)
84356 +{
84357 + INT Status = 0;
84358 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
84359 + PRTMP_ADAPTER pAd;
84360 + POS_COOKIE pObj;
84361 + u32 subcmd = wrq->flags;
84362 +
84363 + if (dev->priv_flags == INT_MAIN)
84364 + pAd = dev->priv;
84365 + else
84366 + {
84367 + pVirtualAd = dev->priv;
84368 + pAd = pVirtualAd->RtmpDev->priv;
84369 + }
84370 + pObj = (POS_COOKIE) pAd->OS_Cookie;
84371 +
84372 + if (pAd == NULL)
84373 + {
84374 + /* if 1st open fail, pAd will be free;
84375 + So the net_dev->priv will be NULL in 2rd open */
84376 + return -ENETDOWN;
84377 + }
84378 +
84379 + if (extra == NULL)
84380 + {
84381 + wrq->length = 0;
84382 + return -EIO;
84383 + }
84384 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
84385 +
84386 + {
84387 + pObj->ioctl_if_type = INT_MAIN;
84388 + pObj->ioctl_if = MAIN_MBSSID;
84389 + }
84390 +
84391 + switch(subcmd)
84392 + {
84393 +
84394 + case SHOW_CONN_STATUS:
84395 + if (MONITOR_ON(pAd))
84396 + {
84397 +#ifdef DOT11_N_SUPPORT
84398 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
84399 + pAd->CommonCfg.RegTransmitSetting.field.BW)
84400 + sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
84401 + else
84402 +#endif // DOT11_N_SUPPORT //
84403 + sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
84404 + }
84405 + else
84406 + {
84407 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
84408 + {
84409 + if (INFRA_ON(pAd))
84410 + {
84411 + sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
84412 + pAd->CommonCfg.Ssid,
84413 + pAd->CommonCfg.Bssid[0],
84414 + pAd->CommonCfg.Bssid[1],
84415 + pAd->CommonCfg.Bssid[2],
84416 + pAd->CommonCfg.Bssid[3],
84417 + pAd->CommonCfg.Bssid[4],
84418 + pAd->CommonCfg.Bssid[5]);
84419 + DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
84420 + }
84421 + else if (ADHOC_ON(pAd))
84422 + sprintf(extra, "Connected\n");
84423 + }
84424 + else
84425 + {
84426 + sprintf(extra, "Disconnected\n");
84427 + DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
84428 + }
84429 + }
84430 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84431 + break;
84432 + case SHOW_DRVIER_VERION:
84433 + sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
84434 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84435 + break;
84436 +#ifdef DOT11_N_SUPPORT
84437 + case SHOW_BA_INFO:
84438 + getBaInfo(pAd, extra);
84439 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84440 + break;
84441 +#endif // DOT11_N_SUPPORT //
84442 + case SHOW_DESC_INFO:
84443 + {
84444 + Show_DescInfo_Proc(pAd, NULL);
84445 + wrq->length = 0; // 1: size of '\0'
84446 + }
84447 + break;
84448 + case RAIO_OFF:
84449 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
84450 + {
84451 + sprintf(extra, "Scanning\n");
84452 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84453 + break;
84454 + }
84455 + pAd->StaCfg.bSwRadio = FALSE;
84456 + if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
84457 + {
84458 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
84459 + if (pAd->StaCfg.bRadio == FALSE)
84460 + {
84461 + MlmeRadioOff(pAd);
84462 + // Update extra information
84463 + pAd->ExtraInfo = SW_RADIO_OFF;
84464 + }
84465 + }
84466 + sprintf(extra, "Radio Off\n");
84467 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84468 + break;
84469 + case RAIO_ON:
84470 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
84471 + {
84472 + sprintf(extra, "Scanning\n");
84473 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84474 + break;
84475 + }
84476 + pAd->StaCfg.bSwRadio = TRUE;
84477 + //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
84478 + {
84479 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
84480 + if (pAd->StaCfg.bRadio == TRUE)
84481 + {
84482 + MlmeRadioOn(pAd);
84483 + // Update extra information
84484 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
84485 + }
84486 + }
84487 + sprintf(extra, "Radio On\n");
84488 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84489 + break;
84490 +
84491 +
84492 +#ifdef QOS_DLS_SUPPORT
84493 + case SHOW_DLS_ENTRY_INFO:
84494 + {
84495 + Set_DlsEntryInfo_Display_Proc(pAd, NULL);
84496 + wrq->length = 0; // 1: size of '\0'
84497 + }
84498 + break;
84499 +#endif // QOS_DLS_SUPPORT //
84500 +
84501 + case SHOW_CFG_VALUE:
84502 + {
84503 + Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
84504 + if (Status == 0)
84505 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84506 + }
84507 + break;
84508 + case SHOW_ADHOC_ENTRY_INFO:
84509 + Show_Adhoc_MacTable_Proc(pAd, extra);
84510 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
84511 + break;
84512 + default:
84513 + DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __FUNCTION__, subcmd));
84514 + break;
84515 + }
84516 +
84517 + return Status;
84518 +}
84519 +
84520 +#ifdef SIOCSIWMLME
84521 +int rt_ioctl_siwmlme(struct net_device *dev,
84522 + struct iw_request_info *info,
84523 + union iwreq_data *wrqu,
84524 + char *extra)
84525 +{
84526 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
84527 + struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
84528 + MLME_QUEUE_ELEM MsgElem;
84529 + MLME_DISASSOC_REQ_STRUCT DisAssocReq;
84530 + MLME_DEAUTH_REQ_STRUCT DeAuthReq;
84531 +
84532 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __FUNCTION__));
84533 +
84534 + if (pMlme == NULL)
84535 + return -EINVAL;
84536 +
84537 + switch(pMlme->cmd)
84538 + {
84539 +#ifdef IW_MLME_DEAUTH
84540 + case IW_MLME_DEAUTH:
84541 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __FUNCTION__));
84542 + COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
84543 + DeAuthReq.Reason = pMlme->reason_code;
84544 + MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
84545 + NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
84546 + MlmeDeauthReqAction(pAd, &MsgElem);
84547 + if (INFRA_ON(pAd))
84548 + {
84549 + LinkDown(pAd, FALSE);
84550 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
84551 + }
84552 + break;
84553 +#endif // IW_MLME_DEAUTH //
84554 +#ifdef IW_MLME_DISASSOC
84555 + case IW_MLME_DISASSOC:
84556 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __FUNCTION__));
84557 + COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
84558 + DisAssocReq.Reason = pMlme->reason_code;
84559 +
84560 + MsgElem.Machine = ASSOC_STATE_MACHINE;
84561 + MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
84562 + MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
84563 + NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
84564 +
84565 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
84566 + MlmeDisassocReqAction(pAd, &MsgElem);
84567 + break;
84568 +#endif // IW_MLME_DISASSOC //
84569 + default:
84570 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __FUNCTION__));
84571 + break;
84572 + }
84573 +
84574 + return 0;
84575 +}
84576 +#endif // SIOCSIWMLME //
84577 +
84578 +#if WIRELESS_EXT > 17
84579 +int rt_ioctl_siwauth(struct net_device *dev,
84580 + struct iw_request_info *info,
84581 + union iwreq_data *wrqu, char *extra)
84582 +{
84583 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
84584 + struct iw_param *param = &wrqu->param;
84585 +
84586 + //check if the interface is down
84587 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84588 + {
84589 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84590 + return -ENETDOWN;
84591 + }
84592 + switch (param->flags & IW_AUTH_INDEX) {
84593 + case IW_AUTH_WPA_VERSION:
84594 + if (param->value == IW_AUTH_WPA_VERSION_WPA)
84595 + {
84596 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
84597 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
84598 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
84599 + }
84600 + else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
84601 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
84602 +
84603 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
84604 + break;
84605 + case IW_AUTH_CIPHER_PAIRWISE:
84606 + if (param->value == IW_AUTH_CIPHER_NONE)
84607 + {
84608 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
84609 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84610 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
84611 + }
84612 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
84613 + param->value == IW_AUTH_CIPHER_WEP104)
84614 + {
84615 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
84616 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84617 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
84618 +#ifdef WPA_SUPPLICANT_SUPPORT
84619 + pAdapter->StaCfg.IEEE8021X = FALSE;
84620 +#endif // WPA_SUPPLICANT_SUPPORT //
84621 + }
84622 + else if (param->value == IW_AUTH_CIPHER_TKIP)
84623 + {
84624 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
84625 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84626 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
84627 + }
84628 + else if (param->value == IW_AUTH_CIPHER_CCMP)
84629 + {
84630 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
84631 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84632 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
84633 + }
84634 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __FUNCTION__, param->value));
84635 + break;
84636 + case IW_AUTH_CIPHER_GROUP:
84637 + if (param->value == IW_AUTH_CIPHER_NONE)
84638 + {
84639 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
84640 + }
84641 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
84642 + param->value == IW_AUTH_CIPHER_WEP104)
84643 + {
84644 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
84645 + }
84646 + else if (param->value == IW_AUTH_CIPHER_TKIP)
84647 + {
84648 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
84649 + }
84650 + else if (param->value == IW_AUTH_CIPHER_CCMP)
84651 + {
84652 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
84653 + }
84654 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __FUNCTION__, param->value));
84655 + break;
84656 + case IW_AUTH_KEY_MGMT:
84657 + if (param->value == IW_AUTH_KEY_MGMT_802_1X)
84658 + {
84659 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
84660 + {
84661 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
84662 +#ifdef WPA_SUPPLICANT_SUPPORT
84663 + pAdapter->StaCfg.IEEE8021X = FALSE;
84664 +#endif // WPA_SUPPLICANT_SUPPORT //
84665 + }
84666 + else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
84667 + {
84668 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
84669 +#ifdef WPA_SUPPLICANT_SUPPORT
84670 + pAdapter->StaCfg.IEEE8021X = FALSE;
84671 +#endif // WPA_SUPPLICANT_SUPPORT //
84672 + }
84673 +#ifdef WPA_SUPPLICANT_SUPPORT
84674 + else
84675 + // WEP 1x
84676 + pAdapter->StaCfg.IEEE8021X = TRUE;
84677 +#endif // WPA_SUPPLICANT_SUPPORT //
84678 + }
84679 + else if (param->value == 0)
84680 + {
84681 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84682 + STA_PORT_SECURED(pAdapter);
84683 + }
84684 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __FUNCTION__, param->value));
84685 + break;
84686 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
84687 + break;
84688 + case IW_AUTH_PRIVACY_INVOKED:
84689 + /*if (param->value == 0)
84690 + {
84691 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
84692 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
84693 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84694 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
84695 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
84696 + }*/
84697 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __FUNCTION__, param->value));
84698 + break;
84699 + case IW_AUTH_DROP_UNENCRYPTED:
84700 + if (param->value != 0)
84701 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
84702 + else
84703 + {
84704 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84705 + STA_PORT_SECURED(pAdapter);
84706 + }
84707 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
84708 + break;
84709 + case IW_AUTH_80211_AUTH_ALG:
84710 + if (param->value & IW_AUTH_ALG_SHARED_KEY)
84711 + {
84712 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
84713 + }
84714 + else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
84715 + {
84716 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
84717 + }
84718 + else
84719 + return -EINVAL;
84720 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __FUNCTION__, param->value));
84721 + break;
84722 + case IW_AUTH_WPA_ENABLED:
84723 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __FUNCTION__, param->value));
84724 + break;
84725 + default:
84726 + return -EOPNOTSUPP;
84727 +}
84728 +
84729 + return 0;
84730 +}
84731 +
84732 +int rt_ioctl_giwauth(struct net_device *dev,
84733 + struct iw_request_info *info,
84734 + union iwreq_data *wrqu, char *extra)
84735 +{
84736 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
84737 + struct iw_param *param = &wrqu->param;
84738 +
84739 + //check if the interface is down
84740 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84741 + {
84742 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84743 + return -ENETDOWN;
84744 + }
84745 +
84746 + switch (param->flags & IW_AUTH_INDEX) {
84747 + case IW_AUTH_DROP_UNENCRYPTED:
84748 + param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
84749 + break;
84750 +
84751 + case IW_AUTH_80211_AUTH_ALG:
84752 + param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
84753 + break;
84754 +
84755 + case IW_AUTH_WPA_ENABLED:
84756 + param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
84757 + break;
84758 +
84759 + default:
84760 + return -EOPNOTSUPP;
84761 + }
84762 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
84763 + return 0;
84764 +}
84765 +
84766 +void fnSetCipherKey(
84767 + IN PRTMP_ADAPTER pAdapter,
84768 + IN INT keyIdx,
84769 + IN UCHAR CipherAlg,
84770 + IN BOOLEAN bGTK,
84771 + IN struct iw_encode_ext *ext)
84772 +{
84773 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
84774 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
84775 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
84776 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
84777 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
84778 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
84779 +
84780 + // Update group key information to ASIC Shared Key Table
84781 + AsicAddSharedKeyEntry(pAdapter,
84782 + BSS0,
84783 + keyIdx,
84784 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
84785 + pAdapter->SharedKey[BSS0][keyIdx].Key,
84786 + pAdapter->SharedKey[BSS0][keyIdx].TxMic,
84787 + pAdapter->SharedKey[BSS0][keyIdx].RxMic);
84788 +
84789 + if (bGTK)
84790 + // Update ASIC WCID attribute table and IVEIV table
84791 + RTMPAddWcidAttributeEntry(pAdapter,
84792 + BSS0,
84793 + keyIdx,
84794 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
84795 + NULL);
84796 + else
84797 + // Update ASIC WCID attribute table and IVEIV table
84798 + RTMPAddWcidAttributeEntry(pAdapter,
84799 + BSS0,
84800 + keyIdx,
84801 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
84802 + &pAdapter->MacTab.Content[BSSID_WCID]);
84803 +}
84804 +
84805 +int rt_ioctl_siwencodeext(struct net_device *dev,
84806 + struct iw_request_info *info,
84807 + union iwreq_data *wrqu,
84808 + char *extra)
84809 + {
84810 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
84811 + struct iw_point *encoding = &wrqu->encoding;
84812 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
84813 + int keyIdx, alg = ext->alg;
84814 +
84815 + //check if the interface is down
84816 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84817 + {
84818 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84819 + return -ENETDOWN;
84820 + }
84821 +
84822 + if (encoding->flags & IW_ENCODE_DISABLED)
84823 + {
84824 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
84825 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
84826 + AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
84827 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
84828 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
84829 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
84830 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
84831 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __FUNCTION__, encoding->flags));
84832 + }
84833 + else
84834 + {
84835 + // Get Key Index and convet to our own defined key index
84836 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
84837 + if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
84838 + return -EINVAL;
84839 +
84840 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
84841 + {
84842 + pAdapter->StaCfg.DefaultKeyId = keyIdx;
84843 + DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __FUNCTION__, pAdapter->StaCfg.DefaultKeyId));
84844 + }
84845 +
84846 + switch (alg) {
84847 + case IW_ENCODE_ALG_NONE:
84848 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __FUNCTION__));
84849 + break;
84850 + case IW_ENCODE_ALG_WEP:
84851 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __FUNCTION__, ext->key_len, keyIdx));
84852 + if (ext->key_len == MAX_WEP_KEY_SIZE)
84853 + {
84854 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
84855 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
84856 + }
84857 + else if (ext->key_len == MIN_WEP_KEY_SIZE)
84858 + {
84859 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
84860 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
84861 + }
84862 + else
84863 + return -EINVAL;
84864 +
84865 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
84866 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
84867 +
84868 + if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
84869 + pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
84870 + {
84871 + // Set Group key material to Asic
84872 + AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
84873 +
84874 + // Update WCID attribute table and IVEIV table for this group key table
84875 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
84876 +
84877 + STA_PORT_SECURED(pAdapter);
84878 +
84879 + // Indicate Connected for GUI
84880 + pAdapter->IndicateMediaState = NdisMediaStateConnected;
84881 + }
84882 + break;
84883 + case IW_ENCODE_ALG_TKIP:
84884 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __FUNCTION__, keyIdx, ext->key_len));
84885 + if (ext->key_len == 32)
84886 + {
84887 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
84888 + {
84889 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
84890 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
84891 + {
84892 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84893 + STA_PORT_SECURED(pAdapter);
84894 + }
84895 + }
84896 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
84897 + {
84898 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
84899 +
84900 + // set 802.1x port control
84901 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84902 + STA_PORT_SECURED(pAdapter);
84903 + }
84904 + }
84905 + else
84906 + return -EINVAL;
84907 + break;
84908 + case IW_ENCODE_ALG_CCMP:
84909 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
84910 + {
84911 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
84912 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
84913 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84914 + STA_PORT_SECURED(pAdapter);
84915 + }
84916 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
84917 + {
84918 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
84919 +
84920 + // set 802.1x port control
84921 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84922 + STA_PORT_SECURED(pAdapter);
84923 + }
84924 + break;
84925 + default:
84926 + return -EINVAL;
84927 + }
84928 + }
84929 +
84930 + return 0;
84931 +}
84932 +
84933 +int
84934 +rt_ioctl_giwencodeext(struct net_device *dev,
84935 + struct iw_request_info *info,
84936 + union iwreq_data *wrqu, char *extra)
84937 +{
84938 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
84939 + PCHAR pKey = NULL;
84940 + struct iw_point *encoding = &wrqu->encoding;
84941 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
84942 + int idx, max_key_len;
84943 +
84944 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
84945 +
84946 + max_key_len = encoding->length - sizeof(*ext);
84947 + if (max_key_len < 0)
84948 + return -EINVAL;
84949 +
84950 + idx = encoding->flags & IW_ENCODE_INDEX;
84951 + if (idx)
84952 + {
84953 + if (idx < 1 || idx > 4)
84954 + return -EINVAL;
84955 + idx--;
84956 +
84957 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
84958 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
84959 + {
84960 + if (idx != pAd->StaCfg.DefaultKeyId)
84961 + {
84962 + ext->key_len = 0;
84963 + return 0;
84964 + }
84965 + }
84966 + }
84967 + else
84968 + idx = pAd->StaCfg.DefaultKeyId;
84969 +
84970 + encoding->flags = idx + 1;
84971 + memset(ext, 0, sizeof(*ext));
84972 +
84973 + ext->key_len = 0;
84974 + switch(pAd->StaCfg.WepStatus) {
84975 + case Ndis802_11WEPDisabled:
84976 + ext->alg = IW_ENCODE_ALG_NONE;
84977 + encoding->flags |= IW_ENCODE_DISABLED;
84978 + break;
84979 + case Ndis802_11WEPEnabled:
84980 + ext->alg = IW_ENCODE_ALG_WEP;
84981 + if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
84982 + return -E2BIG;
84983 + else
84984 + {
84985 + ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
84986 + pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
84987 + }
84988 + break;
84989 + case Ndis802_11Encryption2Enabled:
84990 + case Ndis802_11Encryption3Enabled:
84991 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
84992 + ext->alg = IW_ENCODE_ALG_TKIP;
84993 + else
84994 + ext->alg = IW_ENCODE_ALG_CCMP;
84995 +
84996 + if (max_key_len < 32)
84997 + return -E2BIG;
84998 + else
84999 + {
85000 + ext->key_len = 32;
85001 + pKey = &pAd->StaCfg.PMK[0];
85002 + }
85003 + break;
85004 + default:
85005 + return -EINVAL;
85006 + }
85007 +
85008 + if (ext->key_len && pKey)
85009 + {
85010 + encoding->flags |= IW_ENCODE_ENABLED;
85011 + memcpy(ext->key, pKey, ext->key_len);
85012 + }
85013 +
85014 + return 0;
85015 +}
85016 +
85017 +#ifdef SIOCSIWGENIE
85018 +int rt_ioctl_siwgenie(struct net_device *dev,
85019 + struct iw_request_info *info,
85020 + union iwreq_data *wrqu, char *extra)
85021 +{
85022 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
85023 +
85024 + if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
85025 + (wrqu->data.length && extra == NULL))
85026 + return -EINVAL;
85027 +
85028 + if (wrqu->data.length)
85029 + {
85030 + pAd->StaCfg.RSNIE_Len = wrqu->data.length;
85031 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
85032 + }
85033 + else
85034 + {
85035 + pAd->StaCfg.RSNIE_Len = 0;
85036 + NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
85037 + }
85038 +
85039 + return 0;
85040 +}
85041 +#endif // SIOCSIWGENIE //
85042 +
85043 +int rt_ioctl_giwgenie(struct net_device *dev,
85044 + struct iw_request_info *info,
85045 + union iwreq_data *wrqu, char *extra)
85046 +{
85047 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
85048 +
85049 + if ((pAd->StaCfg.RSNIE_Len == 0) ||
85050 + (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
85051 + {
85052 + wrqu->data.length = 0;
85053 + return 0;
85054 + }
85055 +
85056 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
85057 +#ifdef SIOCSIWGENIE
85058 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
85059 + {
85060 + if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
85061 + return -E2BIG;
85062 +
85063 + wrqu->data.length = pAd->StaCfg.RSNIE_Len;
85064 + memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
85065 + }
85066 + else
85067 +#endif // SIOCSIWGENIE //
85068 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
85069 + {
85070 + UCHAR RSNIe = IE_WPA;
85071 +
85072 + if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
85073 + return -E2BIG;
85074 + wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
85075 +
85076 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
85077 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
85078 + RSNIe = IE_RSN;
85079 +
85080 + extra[0] = (char)RSNIe;
85081 + extra[1] = pAd->StaCfg.RSNIE_Len;
85082 + memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
85083 + }
85084 +
85085 + return 0;
85086 +}
85087 +
85088 +int rt_ioctl_siwpmksa(struct net_device *dev,
85089 + struct iw_request_info *info,
85090 + union iwreq_data *wrqu,
85091 + char *extra)
85092 +{
85093 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
85094 + struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
85095 + INT CachedIdx = 0, idx = 0;
85096 +
85097 + if (pPmksa == NULL)
85098 + return -EINVAL;
85099 +
85100 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
85101 + switch(pPmksa->cmd)
85102 + {
85103 + case IW_PMKSA_FLUSH:
85104 + NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
85105 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
85106 + break;
85107 + case IW_PMKSA_REMOVE:
85108 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
85109 + {
85110 + // compare the BSSID
85111 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
85112 + {
85113 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
85114 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
85115 + for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
85116 + {
85117 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
85118 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
85119 + }
85120 + pAd->StaCfg.SavedPMKNum--;
85121 + break;
85122 + }
85123 + }
85124 +
85125 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
85126 + break;
85127 + case IW_PMKSA_ADD:
85128 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
85129 + {
85130 + // compare the BSSID
85131 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
85132 + break;
85133 + }
85134 +
85135 + // Found, replace it
85136 + if (CachedIdx < PMKID_NO)
85137 + {
85138 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
85139 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
85140 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
85141 + pAd->StaCfg.SavedPMKNum++;
85142 + }
85143 + // Not found, replace the last one
85144 + else
85145 + {
85146 + // Randomly replace one
85147 + CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
85148 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
85149 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
85150 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
85151 + }
85152 +
85153 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
85154 + break;
85155 + default:
85156 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
85157 + break;
85158 + }
85159 +
85160 + return 0;
85161 +}
85162 +#endif // #if WIRELESS_EXT > 17
85163 +
85164 +#ifdef DBG
85165 +static int
85166 +rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
85167 + struct iw_point *wrq, char *extra)
85168 + {
85169 + CHAR *this_char;
85170 + CHAR *value = NULL;
85171 + UCHAR regBBP = 0;
85172 +// CHAR arg[255]={0};
85173 + UINT32 bbpId;
85174 + UINT32 bbpValue;
85175 + BOOLEAN bIsPrintAllBBP = FALSE;
85176 + INT Status = 0;
85177 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
85178 +
85179 +
85180 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
85181 +
85182 + if (wrq->length > 1) //No parameters.
85183 + {
85184 + sprintf(extra, "\n");
85185 +
85186 + //Parsing Read or Write
85187 + this_char = wrq->pointer;
85188 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
85189 + if (!*this_char)
85190 + goto next;
85191 +
85192 + if ((value = rtstrchr(this_char, '=')) != NULL)
85193 + *value++ = 0;
85194 +
85195 + if (!value || !*value)
85196 + { //Read
85197 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
85198 + if (sscanf(this_char, "%d", &(bbpId)) == 1)
85199 + {
85200 + if (bbpId <= 136)
85201 + {
85202 +#ifdef RALINK_ATE
85203 + if (ATE_ON(pAdapter))
85204 + {
85205 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85206 + }
85207 + else
85208 +#endif // RALINK_ATE //
85209 + {
85210 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85211 + }
85212 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
85213 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85214 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
85215 + }
85216 + else
85217 + {//Invalid parametes, so default printk all bbp
85218 + bIsPrintAllBBP = TRUE;
85219 + goto next;
85220 + }
85221 + }
85222 + else
85223 + { //Invalid parametes, so default printk all bbp
85224 + bIsPrintAllBBP = TRUE;
85225 + goto next;
85226 + }
85227 + }
85228 + else
85229 + { //Write
85230 + if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
85231 + {
85232 + if (bbpId <= 136)
85233 + {
85234 +#ifdef RALINK_ATE
85235 + if (ATE_ON(pAdapter))
85236 + {
85237 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
85238 + //Read it back for showing
85239 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85240 + }
85241 + else
85242 +#endif // RALINK_ATE //
85243 + {
85244 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
85245 + //Read it back for showing
85246 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85247 + }
85248 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
85249 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85250 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
85251 + }
85252 + else
85253 + {//Invalid parametes, so default printk all bbp
85254 + bIsPrintAllBBP = TRUE;
85255 + goto next;
85256 + }
85257 + }
85258 + else
85259 + { //Invalid parametes, so default printk all bbp
85260 + bIsPrintAllBBP = TRUE;
85261 + goto next;
85262 + }
85263 + }
85264 + }
85265 + else
85266 + bIsPrintAllBBP = TRUE;
85267 +
85268 +next:
85269 + if (bIsPrintAllBBP)
85270 + {
85271 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
85272 + sprintf(extra, "\n");
85273 + for (bbpId = 0; bbpId <= 136; bbpId++)
85274 + {
85275 + if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
85276 + break;
85277 +#ifdef RALINK_ATE
85278 + if (ATE_ON(pAdapter))
85279 + {
85280 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85281 + }
85282 + else
85283 +#endif // RALINK_ATE //
85284 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
85285 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
85286 + if (bbpId%5 == 4)
85287 + sprintf(extra+strlen(extra), "\n");
85288 + }
85289 +
85290 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85291 + DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
85292 + }
85293 +
85294 + DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
85295 +
85296 + return Status;
85297 +}
85298 +#endif // DBG //
85299 +
85300 +int rt_ioctl_siwrate(struct net_device *dev,
85301 + struct iw_request_info *info,
85302 + union iwreq_data *wrqu, char *extra)
85303 +{
85304 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
85305 + UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
85306 +
85307 + //check if the interface is down
85308 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85309 + {
85310 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
85311 + return -ENETDOWN;
85312 + }
85313 +
85314 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
85315 + /* rate = -1 => auto rate
85316 + rate = X, fixed = 1 => (fixed rate X)
85317 + */
85318 + if (rate == -1)
85319 + {
85320 + //Auto Rate
85321 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
85322 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
85323 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
85324 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
85325 + RTMPSetDesiredRates(pAd, -1);
85326 +
85327 +#ifdef DOT11_N_SUPPORT
85328 + SetCommonHT(pAd);
85329 +#endif // DOT11_N_SUPPORT //
85330 + }
85331 + else
85332 + {
85333 + if (fixed)
85334 + {
85335 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
85336 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
85337 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
85338 + RTMPSetDesiredRates(pAd, rate);
85339 + else
85340 + {
85341 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
85342 +#ifdef DOT11_N_SUPPORT
85343 + SetCommonHT(pAd);
85344 +#endif // DOT11_N_SUPPORT //
85345 + }
85346 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
85347 + }
85348 + else
85349 + {
85350 + // TODO: rate = X, fixed = 0 => (rates <= X)
85351 + return -EOPNOTSUPP;
85352 + }
85353 + }
85354 +
85355 + return 0;
85356 +}
85357 +
85358 +int rt_ioctl_giwrate(struct net_device *dev,
85359 + struct iw_request_info *info,
85360 + union iwreq_data *wrqu, char *extra)
85361 +{
85362 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
85363 + int rate_index = 0, rate_count = 0;
85364 + HTTRANSMIT_SETTING ht_setting;
85365 + __s32 ralinkrate[] =
85366 + {2, 4, 11, 22, // CCK
85367 + 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
85368 + 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
85369 + 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
85370 + 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
85371 + 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
85372 + 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
85373 + 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
85374 + 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
85375 + 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
85376 +
85377 + rate_count = sizeof(ralinkrate)/sizeof(__s32);
85378 + //check if the interface is down
85379 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85380 + {
85381 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
85382 + return -ENETDOWN;
85383 + }
85384 +
85385 + if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
85386 + (INFRA_ON(pAd)) &&
85387 + ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
85388 + ht_setting.word = pAd->StaCfg.HTPhyMode.word;
85389 + else
85390 + ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
85391 +
85392 +#ifdef DOT11_N_SUPPORT
85393 + if (ht_setting.field.MODE >= MODE_HTMIX)
85394 + {
85395 +// rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
85396 + rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
85397 + }
85398 + else
85399 +#endif // DOT11_N_SUPPORT //
85400 + if (ht_setting.field.MODE == MODE_OFDM)
85401 + rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
85402 + else if (ht_setting.field.MODE == MODE_CCK)
85403 + rate_index = (UCHAR)(ht_setting.field.MCS);
85404 +
85405 + if (rate_index < 0)
85406 + rate_index = 0;
85407 +
85408 + if (rate_index > rate_count)
85409 + rate_index = rate_count;
85410 +
85411 + wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
85412 + wrqu->bitrate.disabled = 0;
85413 +
85414 + return 0;
85415 +}
85416 +
85417 +static const iw_handler rt_handler[] =
85418 +{
85419 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
85420 + (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
85421 + (iw_handler) NULL, /* SIOCSIWNWID */
85422 + (iw_handler) NULL, /* SIOCGIWNWID */
85423 + (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
85424 + (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
85425 + (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
85426 + (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
85427 + (iw_handler) NULL, /* SIOCSIWSENS */
85428 + (iw_handler) NULL, /* SIOCGIWSENS */
85429 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
85430 + (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
85431 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
85432 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
85433 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
85434 + (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
85435 + (iw_handler) NULL, /* SIOCSIWSPY */
85436 + (iw_handler) NULL, /* SIOCGIWSPY */
85437 + (iw_handler) NULL, /* SIOCSIWTHRSPY */
85438 + (iw_handler) NULL, /* SIOCGIWTHRSPY */
85439 + (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
85440 + (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
85441 +#ifdef SIOCSIWMLME
85442 + (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
85443 +#else
85444 + (iw_handler) NULL, /* SIOCSIWMLME */
85445 +#endif // SIOCSIWMLME //
85446 + (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
85447 +#ifdef SIOCGIWSCAN
85448 + (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
85449 + (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
85450 +#else
85451 + (iw_handler) NULL, /* SIOCSIWSCAN */
85452 + (iw_handler) NULL, /* SIOCGIWSCAN */
85453 +#endif /* SIOCGIWSCAN */
85454 + (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
85455 + (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
85456 + (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
85457 + (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
85458 + (iw_handler) NULL, /* -- hole -- */
85459 + (iw_handler) NULL, /* -- hole -- */
85460 + (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
85461 + (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
85462 + (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
85463 + (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
85464 + (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
85465 + (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
85466 + (iw_handler) NULL, /* SIOCSIWTXPOW */
85467 + (iw_handler) NULL, /* SIOCGIWTXPOW */
85468 + (iw_handler) NULL, /* SIOCSIWRETRY */
85469 + (iw_handler) NULL, /* SIOCGIWRETRY */
85470 + (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
85471 + (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
85472 + (iw_handler) NULL, /* SIOCSIWPOWER */
85473 + (iw_handler) NULL, /* SIOCGIWPOWER */
85474 + (iw_handler) NULL, /* -- hole -- */
85475 + (iw_handler) NULL, /* -- hole -- */
85476 +#if WIRELESS_EXT > 17
85477 + (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
85478 + (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
85479 + (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
85480 + (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
85481 + (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
85482 + (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
85483 + (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
85484 +#endif
85485 +};
85486 +
85487 +static const iw_handler rt_priv_handlers[] = {
85488 + (iw_handler) NULL, /* + 0x00 */
85489 + (iw_handler) NULL, /* + 0x01 */
85490 +#ifndef CONFIG_AP_SUPPORT
85491 + (iw_handler) rt_ioctl_setparam, /* + 0x02 */
85492 +#else
85493 + (iw_handler) NULL, /* + 0x02 */
85494 +#endif // CONFIG_AP_SUPPORT //
85495 +#ifdef DBG
85496 + (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
85497 +#else
85498 + (iw_handler) NULL, /* + 0x03 */
85499 +#endif
85500 + (iw_handler) NULL, /* + 0x04 */
85501 + (iw_handler) NULL, /* + 0x05 */
85502 + (iw_handler) NULL, /* + 0x06 */
85503 + (iw_handler) NULL, /* + 0x07 */
85504 + (iw_handler) NULL, /* + 0x08 */
85505 + (iw_handler) rt_private_get_statistics, /* + 0x09 */
85506 + (iw_handler) NULL, /* + 0x0A */
85507 + (iw_handler) NULL, /* + 0x0B */
85508 + (iw_handler) NULL, /* + 0x0C */
85509 + (iw_handler) NULL, /* + 0x0D */
85510 + (iw_handler) NULL, /* + 0x0E */
85511 + (iw_handler) NULL, /* + 0x0F */
85512 + (iw_handler) NULL, /* + 0x10 */
85513 + (iw_handler) rt_private_show, /* + 0x11 */
85514 + (iw_handler) NULL, /* + 0x12 */
85515 + (iw_handler) NULL, /* + 0x13 */
85516 + (iw_handler) NULL, /* + 0x15 */
85517 + (iw_handler) NULL, /* + 0x17 */
85518 + (iw_handler) NULL, /* + 0x18 */
85519 +};
85520 +
85521 +const struct iw_handler_def rt28xx_iw_handler_def =
85522 +{
85523 +#define N(a) (sizeof (a) / sizeof (a[0]))
85524 + .standard = (iw_handler *) rt_handler,
85525 + .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
85526 + .private = (iw_handler *) rt_priv_handlers,
85527 + .num_private = N(rt_priv_handlers),
85528 + .private_args = (struct iw_priv_args *) privtab,
85529 + .num_private_args = N(privtab),
85530 +#if IW_HANDLER_VERSION >= 7
85531 + .get_wireless_stats = rt28xx_get_wireless_stats,
85532 +#endif
85533 +};
85534 +
85535 +INT RTMPSetInformation(
85536 + IN PRTMP_ADAPTER pAdapter,
85537 + IN OUT struct ifreq *rq,
85538 + IN INT cmd)
85539 +{
85540 + struct iwreq *wrq = (struct iwreq *) rq;
85541 + NDIS_802_11_SSID Ssid;
85542 + NDIS_802_11_MAC_ADDRESS Bssid;
85543 + RT_802_11_PHY_MODE PhyMode;
85544 + RT_802_11_STA_CONFIG StaConfig;
85545 + NDIS_802_11_RATES aryRates;
85546 + RT_802_11_PREAMBLE Preamble;
85547 + NDIS_802_11_WEP_STATUS WepStatus;
85548 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
85549 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
85550 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
85551 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
85552 + NDIS_802_11_POWER_MODE PowerMode;
85553 + PNDIS_802_11_KEY pKey = NULL;
85554 + PNDIS_802_11_WEP pWepKey =NULL;
85555 + PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
85556 + NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
85557 + NDIS_802_11_NETWORK_TYPE NetType;
85558 + ULONG Now;
85559 + UINT KeyIdx = 0;
85560 + INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
85561 + ULONG PowerTemp;
85562 + BOOLEAN RadioState;
85563 + BOOLEAN StateMachineTouched = FALSE;
85564 +#ifdef DOT11_N_SUPPORT
85565 + OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
85566 +#endif // DOT11_N_SUPPORT //
85567 +#ifdef WPA_SUPPLICANT_SUPPORT
85568 + PNDIS_802_11_PMKID pPmkId = NULL;
85569 + BOOLEAN IEEE8021xState = FALSE;
85570 + BOOLEAN IEEE8021x_required_keys = FALSE;
85571 + UCHAR wpa_supplicant_enable = 0;
85572 +#endif // WPA_SUPPLICANT_SUPPORT //
85573 +
85574 +#ifdef SNMP_SUPPORT
85575 + TX_RTY_CFG_STRUC tx_rty_cfg;
85576 + ULONG ShortRetryLimit, LongRetryLimit;
85577 + UCHAR ctmp;
85578 +#endif // SNMP_SUPPORT //
85579 +
85580 +
85581 +
85582 +#ifdef DOT11_N_SUPPORT
85583 + MaxPhyMode = PHY_11N_5G;
85584 +#endif // DOT11_N_SUPPORT //
85585 +
85586 +
85587 + DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
85588 + switch(cmd & 0x7FFF) {
85589 + case RT_OID_802_11_COUNTRY_REGION:
85590 + if (wrq->u.data.length < sizeof(UCHAR))
85591 + Status = -EINVAL;
85592 + // Only avaliable when EEPROM not programming
85593 + else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
85594 + {
85595 + ULONG Country;
85596 + UCHAR TmpPhy;
85597 +
85598 + Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
85599 + pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
85600 + pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
85601 + TmpPhy = pAdapter->CommonCfg.PhyMode;
85602 + pAdapter->CommonCfg.PhyMode = 0xff;
85603 + // Build all corresponding channel information
85604 + RTMPSetPhyMode(pAdapter, TmpPhy);
85605 +#ifdef DOT11_N_SUPPORT
85606 + SetCommonHT(pAdapter);
85607 +#endif // DOT11_N_SUPPORT //
85608 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
85609 + pAdapter->CommonCfg.CountryRegion));
85610 + }
85611 + break;
85612 + case OID_802_11_BSSID_LIST_SCAN:
85613 + #ifdef RALINK_ATE
85614 + if (ATE_ON(pAdapter))
85615 + {
85616 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
85617 + break;
85618 + }
85619 +#endif // RALINK_ATE //
85620 + Now = jiffies;
85621 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
85622 +
85623 + if (MONITOR_ON(pAdapter))
85624 + {
85625 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
85626 + break;
85627 + }
85628 +
85629 + //Benson add 20080527, when radio off, sta don't need to scan
85630 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
85631 + break;
85632 +
85633 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
85634 + {
85635 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
85636 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
85637 + Status = NDIS_STATUS_SUCCESS;
85638 + break;
85639 + }
85640 +
85641 + if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
85642 + {
85643 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
85644 + Status = NDIS_STATUS_SUCCESS;
85645 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
85646 + break;
85647 + }
85648 +
85649 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
85650 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
85651 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
85652 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
85653 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
85654 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
85655 + {
85656 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
85657 + Status = NDIS_STATUS_SUCCESS;
85658 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
85659 + break;
85660 + }
85661 +
85662 +
85663 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
85664 + {
85665 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
85666 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
85667 + }
85668 +
85669 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
85670 + // this request, because this request is initiated by NDIS.
85671 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
85672 + // Reset allowed scan retries
85673 + pAdapter->StaCfg.ScanCnt = 0;
85674 + pAdapter->StaCfg.LastScanTime = Now;
85675 +
85676 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
85677 + RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
85678 + MlmeEnqueue(pAdapter,
85679 + MLME_CNTL_STATE_MACHINE,
85680 + OID_802_11_BSSID_LIST_SCAN,
85681 + 0,
85682 + NULL);
85683 +
85684 + Status = NDIS_STATUS_SUCCESS;
85685 + StateMachineTouched = TRUE;
85686 + break;
85687 + case OID_802_11_SSID:
85688 + if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
85689 + Status = -EINVAL;
85690 + else
85691 + {
85692 + PCHAR pSsidString = NULL;
85693 + Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
85694 +
85695 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
85696 + if (Ssid.SsidLength > MAX_LEN_OF_SSID)
85697 + Status = -EINVAL;
85698 + else
85699 + {
85700 + if (Ssid.SsidLength == 0)
85701 + {
85702 + Set_SSID_Proc(pAdapter, "");
85703 + }
85704 + else
85705 + {
85706 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
85707 + if (pSsidString)
85708 + {
85709 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
85710 + NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
85711 + Set_SSID_Proc(pAdapter, pSsidString);
85712 + kfree(pSsidString);
85713 + }
85714 + else
85715 + Status = -ENOMEM;
85716 + }
85717 + }
85718 + }
85719 + break;
85720 + case OID_802_11_BSSID:
85721 +#ifdef RALINK_ATE
85722 + if (ATE_ON(pAdapter))
85723 + {
85724 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
85725 + break;
85726 + }
85727 +#endif // RALINK_ATE //
85728 + if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
85729 + Status = -EINVAL;
85730 + else
85731 + {
85732 + Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
85733 +
85734 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
85735 + // this request, because this request is initiated by NDIS.
85736 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
85737 +
85738 + // Prevent to connect AP again in STAMlmePeriodicExec
85739 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
85740 +
85741 + // Reset allowed scan retries
85742 + pAdapter->StaCfg.ScanCnt = 0;
85743 +
85744 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
85745 + {
85746 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
85747 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
85748 + }
85749 + MlmeEnqueue(pAdapter,
85750 + MLME_CNTL_STATE_MACHINE,
85751 + OID_802_11_BSSID,
85752 + sizeof(NDIS_802_11_MAC_ADDRESS),
85753 + (VOID *)&Bssid);
85754 + Status = NDIS_STATUS_SUCCESS;
85755 + StateMachineTouched = TRUE;
85756 +
85757 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
85758 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
85759 + }
85760 + break;
85761 + case RT_OID_802_11_RADIO:
85762 + if (wrq->u.data.length != sizeof(BOOLEAN))
85763 + Status = -EINVAL;
85764 + else
85765 + {
85766 + Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
85767 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
85768 + if (pAdapter->StaCfg.bSwRadio != RadioState)
85769 + {
85770 + pAdapter->StaCfg.bSwRadio = RadioState;
85771 + if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
85772 + {
85773 + pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
85774 + if (pAdapter->StaCfg.bRadio == TRUE)
85775 + {
85776 + MlmeRadioOn(pAdapter);
85777 + // Update extra information
85778 + pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
85779 + }
85780 + else
85781 + {
85782 + MlmeRadioOff(pAdapter);
85783 + // Update extra information
85784 + pAdapter->ExtraInfo = SW_RADIO_OFF;
85785 + }
85786 + }
85787 + }
85788 + }
85789 + break;
85790 + case RT_OID_802_11_PHY_MODE:
85791 + if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
85792 + Status = -EINVAL;
85793 + else
85794 + {
85795 + Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
85796 + if (PhyMode <= MaxPhyMode)
85797 + {
85798 + RTMPSetPhyMode(pAdapter, PhyMode);
85799 +#ifdef DOT11_N_SUPPORT
85800 + SetCommonHT(pAdapter);
85801 +#endif // DOT11_N_SUPPORT //
85802 + }
85803 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
85804 + }
85805 + break;
85806 + case RT_OID_802_11_STA_CONFIG:
85807 + if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
85808 + Status = -EINVAL;
85809 + else
85810 + {
85811 + Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
85812 + pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
85813 + pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
85814 + pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
85815 + if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
85816 + (StaConfig.AdhocMode <= MaxPhyMode))
85817 + {
85818 + // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
85819 + // if setting changed, need to reset current TX rate as well as BEACON frame format
85820 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
85821 + {
85822 + pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
85823 + RTMPSetPhyMode(pAdapter, PhyMode);
85824 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
85825 + MakeIbssBeacon(pAdapter); // re-build BEACON frame
85826 + AsicEnableIbssSync(pAdapter); // copy to on-chip memory
85827 + }
85828 + }
85829 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
85830 + pAdapter->CommonCfg.bEnableTxBurst,
85831 + pAdapter->CommonCfg.UseBGProtection,
85832 + pAdapter->CommonCfg.bUseShortSlotTime));
85833 + }
85834 + break;
85835 + case OID_802_11_DESIRED_RATES:
85836 + if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
85837 + Status = -EINVAL;
85838 + else
85839 + {
85840 + Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
85841 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
85842 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
85843 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
85844 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
85845 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
85846 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
85847 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
85848 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
85849 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
85850 + }
85851 + break;
85852 + case RT_OID_802_11_PREAMBLE:
85853 + if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
85854 + Status = -EINVAL;
85855 + else
85856 + {
85857 + Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
85858 + if (Preamble == Rt802_11PreambleShort)
85859 + {
85860 + pAdapter->CommonCfg.TxPreamble = Preamble;
85861 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
85862 + }
85863 + else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
85864 + {
85865 + // if user wants AUTO, initialize to LONG here, then change according to AP's
85866 + // capability upon association.
85867 + pAdapter->CommonCfg.TxPreamble = Preamble;
85868 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
85869 + }
85870 + else
85871 + {
85872 + Status = -EINVAL;
85873 + break;
85874 + }
85875 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
85876 + }
85877 + break;
85878 + case OID_802_11_WEP_STATUS:
85879 + if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
85880 + Status = -EINVAL;
85881 + else
85882 + {
85883 + Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
85884 + // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
85885 + if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
85886 + {
85887 + if (pAdapter->StaCfg.WepStatus != WepStatus)
85888 + {
85889 + // Config has changed
85890 + pAdapter->bConfigChanged = TRUE;
85891 + }
85892 + pAdapter->StaCfg.WepStatus = WepStatus;
85893 + pAdapter->StaCfg.OrigWepStatus = WepStatus;
85894 + pAdapter->StaCfg.PairCipher = WepStatus;
85895 + pAdapter->StaCfg.GroupCipher = WepStatus;
85896 + }
85897 + else
85898 + {
85899 + Status = -EINVAL;
85900 + break;
85901 + }
85902 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
85903 + }
85904 + break;
85905 + case OID_802_11_AUTHENTICATION_MODE:
85906 + if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
85907 + Status = -EINVAL;
85908 + else
85909 + {
85910 + Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
85911 + if (AuthMode > Ndis802_11AuthModeMax)
85912 + {
85913 + Status = -EINVAL;
85914 + break;
85915 + }
85916 + else
85917 + {
85918 + if (pAdapter->StaCfg.AuthMode != AuthMode)
85919 + {
85920 + // Config has changed
85921 + pAdapter->bConfigChanged = TRUE;
85922 + }
85923 + pAdapter->StaCfg.AuthMode = AuthMode;
85924 + }
85925 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
85926 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
85927 + }
85928 + break;
85929 + case OID_802_11_INFRASTRUCTURE_MODE:
85930 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
85931 + Status = -EINVAL;
85932 + else
85933 + {
85934 + Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
85935 +
85936 + if (BssType == Ndis802_11IBSS)
85937 + Set_NetworkType_Proc(pAdapter, "Adhoc");
85938 + else if (BssType == Ndis802_11Infrastructure)
85939 + Set_NetworkType_Proc(pAdapter, "Infra");
85940 + else if (BssType == Ndis802_11Monitor)
85941 + Set_NetworkType_Proc(pAdapter, "Monitor");
85942 + else
85943 + {
85944 + Status = -EINVAL;
85945 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
85946 + }
85947 + }
85948 + break;
85949 + case OID_802_11_REMOVE_WEP:
85950 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
85951 + if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
85952 + {
85953 + Status = -EINVAL;
85954 + }
85955 + else
85956 + {
85957 + KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
85958 +
85959 + if (KeyIdx & 0x80000000)
85960 + {
85961 + // Should never set default bit when remove key
85962 + Status = -EINVAL;
85963 + }
85964 + else
85965 + {
85966 + KeyIdx = KeyIdx & 0x0fffffff;
85967 + if (KeyIdx >= 4){
85968 + Status = -EINVAL;
85969 + }
85970 + else
85971 + {
85972 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
85973 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
85974 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
85975 + }
85976 + }
85977 + }
85978 + break;
85979 + case RT_OID_802_11_RESET_COUNTERS:
85980 + NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
85981 + NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
85982 + NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
85983 + pAdapter->Counters8023.RxNoBuffer = 0;
85984 + pAdapter->Counters8023.GoodReceives = 0;
85985 + pAdapter->Counters8023.RxNoBuffer = 0;
85986 +#ifdef RT2870
85987 + pAdapter->BulkOutComplete = 0;
85988 + pAdapter->BulkOutCompleteOther= 0;
85989 + pAdapter->BulkOutCompleteCancel = 0;
85990 + pAdapter->BulkOutReq = 0;
85991 + pAdapter->BulkInReq= 0;
85992 + pAdapter->BulkInComplete = 0;
85993 + pAdapter->BulkInCompleteFail = 0;
85994 +#endif // RT2870 //
85995 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
85996 + break;
85997 + case OID_802_11_RTS_THRESHOLD:
85998 + if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
85999 + Status = -EINVAL;
86000 + else
86001 + {
86002 + Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
86003 + if (RtsThresh > MAX_RTS_THRESHOLD)
86004 + Status = -EINVAL;
86005 + else
86006 + pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
86007 + }
86008 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
86009 + break;
86010 + case OID_802_11_FRAGMENTATION_THRESHOLD:
86011 + if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
86012 + Status = -EINVAL;
86013 + else
86014 + {
86015 + Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
86016 + pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
86017 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
86018 + {
86019 + if (FragThresh == 0)
86020 + {
86021 + pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
86022 + pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
86023 + }
86024 + else
86025 + Status = -EINVAL;
86026 + }
86027 + else
86028 + pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
86029 + }
86030 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
86031 + break;
86032 + case OID_802_11_POWER_MODE:
86033 + if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
86034 + Status = -EINVAL;
86035 + else
86036 + {
86037 + Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
86038 + if (PowerMode == Ndis802_11PowerModeCAM)
86039 + Set_PSMode_Proc(pAdapter, "CAM");
86040 + else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
86041 + Set_PSMode_Proc(pAdapter, "Max_PSP");
86042 + else if (PowerMode == Ndis802_11PowerModeFast_PSP)
86043 + Set_PSMode_Proc(pAdapter, "Fast_PSP");
86044 + else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
86045 + Set_PSMode_Proc(pAdapter, "Legacy_PSP");
86046 + else
86047 + Status = -EINVAL;
86048 + }
86049 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
86050 + break;
86051 + case RT_OID_802_11_TX_POWER_LEVEL_1:
86052 + if (wrq->u.data.length < sizeof(ULONG))
86053 + Status = -EINVAL;
86054 + else
86055 + {
86056 + Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
86057 + if (PowerTemp > 100)
86058 + PowerTemp = 0xffffffff; // AUTO
86059 + pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
86060 + pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
86061 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
86062 + }
86063 + break;
86064 + case OID_802_11_NETWORK_TYPE_IN_USE:
86065 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
86066 + Status = -EINVAL;
86067 + else
86068 + {
86069 + Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
86070 +
86071 + if (NetType == Ndis802_11DS)
86072 + RTMPSetPhyMode(pAdapter, PHY_11B);
86073 + else if (NetType == Ndis802_11OFDM24)
86074 + RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
86075 + else if (NetType == Ndis802_11OFDM5)
86076 + RTMPSetPhyMode(pAdapter, PHY_11A);
86077 + else
86078 + Status = -EINVAL;
86079 +#ifdef DOT11_N_SUPPORT
86080 + if (Status == NDIS_STATUS_SUCCESS)
86081 + SetCommonHT(pAdapter);
86082 +#endif // DOT11_N_SUPPORT //
86083 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
86084 + }
86085 + break;
86086 + // For WPA PSK PMK key
86087 + case RT_OID_802_11_ADD_WPA:
86088 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86089 + if(pKey == NULL)
86090 + {
86091 + Status = -ENOMEM;
86092 + break;
86093 + }
86094 +
86095 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
86096 + if (pKey->Length != wrq->u.data.length)
86097 + {
86098 + Status = -EINVAL;
86099 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
86100 + }
86101 + else
86102 + {
86103 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
86104 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
86105 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
86106 + {
86107 + Status = -EOPNOTSUPP;
86108 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
86109 + }
86110 + else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
86111 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
86112 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
86113 + {
86114 + NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
86115 + // Use RaConfig as PSK agent.
86116 + // Start STA supplicant state machine
86117 + if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
86118 + pAdapter->StaCfg.WpaState = SS_START;
86119 +
86120 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
86121 + }
86122 + else
86123 + {
86124 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
86125 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
86126 + }
86127 + }
86128 + kfree(pKey);
86129 + break;
86130 + case OID_802_11_REMOVE_KEY:
86131 + pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86132 + if(pRemoveKey == NULL)
86133 + {
86134 + Status = -ENOMEM;
86135 + break;
86136 + }
86137 +
86138 + Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
86139 + if (pRemoveKey->Length != wrq->u.data.length)
86140 + {
86141 + Status = -EINVAL;
86142 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
86143 + }
86144 + else
86145 + {
86146 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
86147 + {
86148 + RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
86149 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
86150 + }
86151 + else
86152 + {
86153 + KeyIdx = pRemoveKey->KeyIndex;
86154 +
86155 + if (KeyIdx & 0x80000000)
86156 + {
86157 + // Should never set default bit when remove key
86158 + Status = -EINVAL;
86159 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
86160 + }
86161 + else
86162 + {
86163 + KeyIdx = KeyIdx & 0x0fffffff;
86164 + if (KeyIdx > 3)
86165 + {
86166 + Status = -EINVAL;
86167 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
86168 + }
86169 + else
86170 + {
86171 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
86172 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
86173 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
86174 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
86175 + }
86176 + }
86177 + }
86178 + }
86179 + kfree(pRemoveKey);
86180 + break;
86181 + // New for WPA
86182 + case OID_802_11_ADD_KEY:
86183 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86184 + if(pKey == NULL)
86185 + {
86186 + Status = -ENOMEM;
86187 + break;
86188 + }
86189 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
86190 + if (pKey->Length != wrq->u.data.length)
86191 + {
86192 + Status = -EINVAL;
86193 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
86194 + }
86195 + else
86196 + {
86197 + RTMPAddKey(pAdapter, pKey);
86198 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
86199 + }
86200 + kfree(pKey);
86201 + break;
86202 + case OID_802_11_CONFIGURATION:
86203 + if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
86204 + Status = -EINVAL;
86205 + else
86206 + {
86207 + Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
86208 + pConfig = &Config;
86209 +
86210 + if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
86211 + pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
86212 +
86213 + pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
86214 + MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
86215 + //
86216 + // Save the channel on MlmeAux for CntlOidRTBssidProc used.
86217 + //
86218 + pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
86219 +
86220 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
86221 + pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
86222 + // Config has changed
86223 + pAdapter->bConfigChanged = TRUE;
86224 + }
86225 + break;
86226 +#ifdef DOT11_N_SUPPORT
86227 + case RT_OID_802_11_SET_HT_PHYMODE:
86228 + if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
86229 + Status = -EINVAL;
86230 + else
86231 + {
86232 + POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
86233 +
86234 + Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
86235 + DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
86236 + pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
86237 + pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
86238 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
86239 + RTMPSetHT(pAdapter, pHTPhyMode);
86240 + }
86241 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
86242 + pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
86243 + pAdapter->StaCfg.HTPhyMode.field.STBC));
86244 + break;
86245 +#endif // DOT11_N_SUPPORT //
86246 + case RT_OID_802_11_SET_APSD_SETTING:
86247 + if (wrq->u.data.length != sizeof(ULONG))
86248 + Status = -EINVAL;
86249 + else
86250 + {
86251 + ULONG apsd ;
86252 + Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
86253 +
86254 + /*-------------------------------------------------------------------
86255 + |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
86256 + ---------------------------------------------------------------------
86257 + | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
86258 + ---------------------------------------------------------------------*/
86259 + pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
86260 + pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
86261 + pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
86262 + pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
86263 + pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
86264 + pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
86265 +
86266 + 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,
86267 + pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
86268 + }
86269 + break;
86270 +
86271 + case RT_OID_802_11_SET_APSD_PSM:
86272 + if (wrq->u.data.length != sizeof(ULONG))
86273 + Status = -EINVAL;
86274 + else
86275 + {
86276 + // Driver needs to notify AP when PSM changes
86277 + Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
86278 + if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
86279 + {
86280 + MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
86281 + RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
86282 + }
86283 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
86284 + }
86285 + break;
86286 +#ifdef QOS_DLS_SUPPORT
86287 + case RT_OID_802_11_SET_DLS:
86288 + if (wrq->u.data.length != sizeof(ULONG))
86289 + Status = -EINVAL;
86290 + else
86291 + {
86292 + BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
86293 + Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
86294 + if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
86295 + {
86296 + int i;
86297 + // tear down local dls table entry
86298 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
86299 + {
86300 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
86301 + {
86302 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
86303 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
86304 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
86305 + }
86306 + }
86307 +
86308 + // tear down peer dls table entry
86309 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
86310 + {
86311 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
86312 + {
86313 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
86314 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
86315 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
86316 + }
86317 + }
86318 + }
86319 +
86320 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
86321 + }
86322 + break;
86323 +
86324 + case RT_OID_802_11_SET_DLS_PARAM:
86325 + if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
86326 + Status = -EINVAL;
86327 + else
86328 + {
86329 + RT_802_11_DLS Dls;
86330 +
86331 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
86332 + RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
86333 + MlmeEnqueue(pAdapter,
86334 + MLME_CNTL_STATE_MACHINE,
86335 + RT_OID_802_11_SET_DLS_PARAM,
86336 + sizeof(RT_802_11_DLS),
86337 + &Dls);
86338 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
86339 + }
86340 + break;
86341 +#endif // QOS_DLS_SUPPORT //
86342 + case RT_OID_802_11_SET_WMM:
86343 + if (wrq->u.data.length != sizeof(BOOLEAN))
86344 + Status = -EINVAL;
86345 + else
86346 + {
86347 + Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
86348 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
86349 + }
86350 + break;
86351 +
86352 + case OID_802_11_DISASSOCIATE:
86353 +#ifdef RALINK_ATE
86354 + if (ATE_ON(pAdapter))
86355 + {
86356 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
86357 + break;
86358 + }
86359 +#endif // RALINK_ATE //
86360 + //
86361 + // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
86362 + // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
86363 + // when query OID_802_11_BSSID_LIST.
86364 + //
86365 + // TRUE: NumberOfItems will set to 0.
86366 + // FALSE: NumberOfItems no change.
86367 + //
86368 + pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
86369 + // Set to immediately send the media disconnect event
86370 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
86371 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
86372 +
86373 + if (INFRA_ON(pAdapter))
86374 + {
86375 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
86376 + {
86377 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
86378 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
86379 + }
86380 +
86381 + MlmeEnqueue(pAdapter,
86382 + MLME_CNTL_STATE_MACHINE,
86383 + OID_802_11_DISASSOCIATE,
86384 + 0,
86385 + NULL);
86386 +
86387 + StateMachineTouched = TRUE;
86388 + }
86389 + break;
86390 +
86391 +#ifdef DOT11_N_SUPPORT
86392 + case RT_OID_802_11_SET_IMME_BA_CAP:
86393 + if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
86394 + Status = -EINVAL;
86395 + else
86396 + {
86397 + OID_BACAP_STRUC Orde ;
86398 + Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
86399 + if (Orde.Policy > BA_NOTUSE)
86400 + {
86401 + Status = NDIS_STATUS_INVALID_DATA;
86402 + }
86403 + else if (Orde.Policy == BA_NOTUSE)
86404 + {
86405 + pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
86406 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
86407 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
86408 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
86409 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
86410 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
86411 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
86412 + // UPdata to HT IE
86413 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
86414 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
86415 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
86416 + }
86417 + else
86418 + {
86419 + pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
86420 + pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
86421 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
86422 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
86423 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
86424 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
86425 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
86426 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
86427 +
86428 + // UPdata to HT IE
86429 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
86430 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
86431 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
86432 +
86433 + if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
86434 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
86435 +
86436 + }
86437 +
86438 + pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
86439 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
86440 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
86441 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
86442 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
86443 + }
86444 +
86445 + break;
86446 + case RT_OID_802_11_ADD_IMME_BA:
86447 + DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
86448 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
86449 + Status = -EINVAL;
86450 + else
86451 + {
86452 + UCHAR index;
86453 + OID_ADD_BA_ENTRY BA;
86454 + MAC_TABLE_ENTRY *pEntry;
86455 +
86456 + Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
86457 + if (BA.TID > 15)
86458 + {
86459 + Status = NDIS_STATUS_INVALID_DATA;
86460 + break;
86461 + }
86462 + else
86463 + {
86464 + //BATableInsertEntry
86465 + //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
86466 + index = BA.TID;
86467 + // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
86468 + pEntry = MacTableLookup(pAdapter, BA.MACAddr);
86469 + if (!pEntry)
86470 + {
86471 + DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
86472 + break;
86473 + }
86474 + if (BA.IsRecipient == FALSE)
86475 + {
86476 + if (pEntry->bIAmBadAtheros == TRUE)
86477 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
86478 +
86479 + BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
86480 + }
86481 + else
86482 + {
86483 + //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
86484 + }
86485 +
86486 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
86487 + BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
86488 + , BA.MACAddr[4], BA.MACAddr[5]));
86489 + }
86490 + }
86491 + break;
86492 +
86493 + case RT_OID_802_11_TEAR_IMME_BA:
86494 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
86495 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
86496 + Status = -EINVAL;
86497 + else
86498 + {
86499 + POID_ADD_BA_ENTRY pBA;
86500 + MAC_TABLE_ENTRY *pEntry;
86501 +
86502 + pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86503 +
86504 + if (pBA == NULL)
86505 + {
86506 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
86507 + Status = NDIS_STATUS_FAILURE;
86508 + }
86509 + else
86510 + {
86511 + Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
86512 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
86513 +
86514 + if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
86515 + {
86516 + Status = NDIS_STATUS_INVALID_DATA;
86517 + break;
86518 + }
86519 +
86520 + if (pBA->IsRecipient == FALSE)
86521 + {
86522 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
86523 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
86524 + if (pEntry)
86525 + {
86526 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
86527 + BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
86528 + }
86529 + else
86530 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
86531 + }
86532 + else
86533 + {
86534 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
86535 + if (pEntry)
86536 + {
86537 + BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
86538 + }
86539 + else
86540 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
86541 + }
86542 + kfree(pBA);
86543 + }
86544 + }
86545 + break;
86546 +#endif // DOT11_N_SUPPORT //
86547 +
86548 + // For WPA_SUPPLICANT to set static wep key
86549 + case OID_802_11_ADD_WEP:
86550 + pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86551 +
86552 + if(pWepKey == NULL)
86553 + {
86554 + Status = -ENOMEM;
86555 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
86556 + break;
86557 + }
86558 + Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
86559 + if (Status)
86560 + {
86561 + Status = -EINVAL;
86562 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
86563 + }
86564 + else
86565 + {
86566 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
86567 + // KeyIdx must be 0 ~ 3
86568 + if (KeyIdx > 4)
86569 + {
86570 + Status = -EINVAL;
86571 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
86572 + }
86573 + else
86574 + {
86575 + UCHAR CipherAlg = 0;
86576 + PUCHAR Key;
86577 +
86578 + // set key material and key length
86579 + NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
86580 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
86581 + NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
86582 +
86583 + switch(pWepKey->KeyLength)
86584 + {
86585 + case 5:
86586 + CipherAlg = CIPHER_WEP64;
86587 + break;
86588 + case 13:
86589 + CipherAlg = CIPHER_WEP128;
86590 + break;
86591 + default:
86592 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
86593 + Status = -EINVAL;
86594 + break;
86595 + }
86596 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
86597 +
86598 + // Default key for tx (shared key)
86599 + if (pWepKey->KeyIndex & 0x80000000)
86600 + {
86601 +#ifdef WPA_SUPPLICANT_SUPPORT
86602 + // set key material and key length
86603 + NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
86604 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
86605 + NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
86606 + pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
86607 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
86608 +#endif // WPA_SUPPLICANT_SUPPORT //
86609 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
86610 + }
86611 +
86612 +#ifdef WPA_SUPPLICANT_SUPPORT
86613 + if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
86614 + (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
86615 + {
86616 + Key = pWepKey->KeyMaterial;
86617 +
86618 + // Set Group key material to Asic
86619 + AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
86620 +
86621 + // Update WCID attribute table and IVEIV table for this group key table
86622 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
86623 +
86624 + STA_PORT_SECURED(pAdapter);
86625 +
86626 + // Indicate Connected for GUI
86627 + pAdapter->IndicateMediaState = NdisMediaStateConnected;
86628 + }
86629 + else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
86630 +#endif // WPA_SUPPLICANT_SUPPORT
86631 + {
86632 + Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
86633 +
86634 + // Set key material and cipherAlg to Asic
86635 + AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
86636 +
86637 + if (pWepKey->KeyIndex & 0x80000000)
86638 + {
86639 + PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
86640 + // Assign group key info
86641 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
86642 + // Assign pairwise key info
86643 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
86644 + }
86645 + }
86646 + 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"));
86647 + }
86648 + }
86649 + kfree(pWepKey);
86650 + break;
86651 +#ifdef WPA_SUPPLICANT_SUPPORT
86652 + case OID_SET_COUNTERMEASURES:
86653 + if (wrq->u.data.length != sizeof(int))
86654 + Status = -EINVAL;
86655 + else
86656 + {
86657 + int enabled = 0;
86658 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
86659 + if (enabled == 1)
86660 + pAdapter->StaCfg.bBlockAssoc = TRUE;
86661 + else
86662 + // WPA MIC error should block association attempt for 60 seconds
86663 + pAdapter->StaCfg.bBlockAssoc = FALSE;
86664 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
86665 + }
86666 + break;
86667 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
86668 + if (wrq->u.data.length != sizeof(UCHAR))
86669 + Status = -EINVAL;
86670 + else
86671 + {
86672 + Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
86673 + pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
86674 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
86675 + }
86676 + break;
86677 + case OID_802_11_DEAUTHENTICATION:
86678 + if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
86679 + Status = -EINVAL;
86680 + else
86681 + {
86682 + MLME_DEAUTH_REQ_STRUCT *pInfo;
86683 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
86684 +
86685 + pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
86686 + Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
86687 + MlmeDeauthReqAction(pAdapter, MsgElem);
86688 + kfree(MsgElem);
86689 +
86690 + if (INFRA_ON(pAdapter))
86691 + {
86692 + LinkDown(pAdapter, FALSE);
86693 + pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
86694 + }
86695 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
86696 + }
86697 + break;
86698 + case OID_802_11_DROP_UNENCRYPTED:
86699 + if (wrq->u.data.length != sizeof(int))
86700 + Status = -EINVAL;
86701 + else
86702 + {
86703 + int enabled = 0;
86704 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
86705 + if (enabled == 1)
86706 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
86707 + else
86708 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
86709 + NdisAcquireSpinLock(&pAdapter->MacTabLock);
86710 + pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
86711 + NdisReleaseSpinLock(&pAdapter->MacTabLock);
86712 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
86713 + }
86714 + break;
86715 + case OID_802_11_SET_IEEE8021X:
86716 + if (wrq->u.data.length != sizeof(BOOLEAN))
86717 + Status = -EINVAL;
86718 + else
86719 + {
86720 + Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
86721 + pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
86722 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
86723 + }
86724 + break;
86725 + case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
86726 + if (wrq->u.data.length != sizeof(BOOLEAN))
86727 + Status = -EINVAL;
86728 + else
86729 + {
86730 + Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
86731 + pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
86732 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
86733 + }
86734 + break;
86735 + case OID_802_11_PMKID:
86736 + pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86737 +
86738 + if(pPmkId == NULL) {
86739 + Status = -ENOMEM;
86740 + break;
86741 + }
86742 + Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
86743 +
86744 + // check the PMKID information
86745 + if (pPmkId->BSSIDInfoCount == 0)
86746 + NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
86747 + else
86748 + {
86749 + PBSSID_INFO pBssIdInfo;
86750 + UINT BssIdx;
86751 + UINT CachedIdx;
86752 +
86753 + for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
86754 + {
86755 + // point to the indexed BSSID_INFO structure
86756 + pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
86757 + // Find the entry in the saved data base.
86758 + for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
86759 + {
86760 + // compare the BSSID
86761 + if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
86762 + break;
86763 + }
86764 +
86765 + // Found, replace it
86766 + if (CachedIdx < PMKID_NO)
86767 + {
86768 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
86769 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
86770 + pAdapter->StaCfg.SavedPMKNum++;
86771 + }
86772 + // Not found, replace the last one
86773 + else
86774 + {
86775 + // Randomly replace one
86776 + CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
86777 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
86778 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
86779 + }
86780 + }
86781 + }
86782 + if(pPmkId)
86783 + kfree(pPmkId);
86784 + break;
86785 +#endif // WPA_SUPPLICANT_SUPPORT //
86786 +
86787 +
86788 +
86789 +#ifdef SNMP_SUPPORT
86790 + case OID_802_11_SHORTRETRYLIMIT:
86791 + if (wrq->u.data.length != sizeof(ULONG))
86792 + Status = -EINVAL;
86793 + else
86794 + {
86795 + Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
86796 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
86797 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
86798 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
86799 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
86800 + }
86801 + break;
86802 +
86803 + case OID_802_11_LONGRETRYLIMIT:
86804 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
86805 + if (wrq->u.data.length != sizeof(ULONG))
86806 + Status = -EINVAL;
86807 + else
86808 + {
86809 + Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
86810 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
86811 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
86812 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
86813 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
86814 + }
86815 + break;
86816 +
86817 + case OID_802_11_WEPDEFAULTKEYVALUE:
86818 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
86819 + pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
86820 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
86821 + //pKey = &WepKey;
86822 +
86823 + if ( pKey->Length != wrq->u.data.length)
86824 + {
86825 + Status = -EINVAL;
86826 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
86827 + }
86828 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
86829 + DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
86830 +
86831 + // it is a shared key
86832 + if (KeyIdx > 4)
86833 + Status = -EINVAL;
86834 + else
86835 + {
86836 + pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
86837 + NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
86838 + if (pKey->KeyIndex & 0x80000000)
86839 + {
86840 + // Default key for tx (shared key)
86841 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
86842 + }
86843 + //RestartAPIsRequired = TRUE;
86844 + }
86845 + break;
86846 +
86847 +
86848 + case OID_802_11_WEPDEFAULTKEYID:
86849 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
86850 +
86851 + if (wrq->u.data.length != sizeof(UCHAR))
86852 + Status = -EINVAL;
86853 + else
86854 + Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
86855 +
86856 + break;
86857 +
86858 +
86859 + case OID_802_11_CURRENTCHANNEL:
86860 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
86861 + if (wrq->u.data.length != sizeof(UCHAR))
86862 + Status = -EINVAL;
86863 + else
86864 + {
86865 + Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
86866 + sprintf(&ctmp,"%d", ctmp);
86867 + Set_Channel_Proc(pAdapter, &ctmp);
86868 + }
86869 + break;
86870 +#endif
86871 +
86872 +
86873 +
86874 + default:
86875 + DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
86876 + Status = -EOPNOTSUPP;
86877 + break;
86878 + }
86879 +
86880 +
86881 + return Status;
86882 +}
86883 +
86884 +INT RTMPQueryInformation(
86885 + IN PRTMP_ADAPTER pAdapter,
86886 + IN OUT struct ifreq *rq,
86887 + IN INT cmd)
86888 +{
86889 + struct iwreq *wrq = (struct iwreq *) rq;
86890 + NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
86891 + PNDIS_WLAN_BSSID_EX pBss;
86892 + NDIS_802_11_SSID Ssid;
86893 + NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
86894 + RT_802_11_LINK_STATUS *pLinkStatus = NULL;
86895 + RT_802_11_STA_CONFIG *pStaConfig = NULL;
86896 + NDIS_802_11_STATISTICS *pStatistics = NULL;
86897 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
86898 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
86899 + NDIS_802_11_POWER_MODE PowerMode;
86900 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
86901 + RT_802_11_PREAMBLE PreamType;
86902 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
86903 + NDIS_802_11_WEP_STATUS WepStatus;
86904 + NDIS_MEDIA_STATE MediaState;
86905 + ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
86906 + USHORT BssLen = 0;
86907 + PUCHAR pBuf = NULL, pPtr;
86908 + INT Status = NDIS_STATUS_SUCCESS;
86909 + UINT we_version_compiled;
86910 + UCHAR i, Padding = 0;
86911 + BOOLEAN RadioState;
86912 + UCHAR driverVersion[8];
86913 + OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
86914 +
86915 +
86916 +#ifdef SNMP_SUPPORT
86917 + //for snmp, kathy
86918 + DefaultKeyIdxValue *pKeyIdxValue;
86919 + INT valueLen;
86920 + TX_RTY_CFG_STRUC tx_rty_cfg;
86921 + ULONG ShortRetryLimit, LongRetryLimit;
86922 + UCHAR tmp[64];
86923 +#endif //SNMP
86924 +
86925 + switch(cmd)
86926 + {
86927 + case RT_OID_DEVICE_NAME:
86928 + wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
86929 + Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
86930 + break;
86931 + case RT_OID_VERSION_INFO:
86932 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
86933 + wrq->u.data.length = 8*sizeof(UCHAR);
86934 + sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
86935 + driverVersion[7] = '\0';
86936 + if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
86937 + {
86938 + Status = -EFAULT;
86939 + }
86940 + break;
86941 +#ifdef RALINK_ATE
86942 + case RT_QUERY_ATE_TXDONE_COUNT:
86943 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
86944 + wrq->u.data.length = sizeof(UINT32);
86945 + if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
86946 + {
86947 + Status = -EFAULT;
86948 + }
86949 + break;
86950 +#endif // RALINK_ATE //
86951 + case OID_802_11_BSSID_LIST:
86952 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
86953 + {
86954 + /*
86955 + * Still scanning, indicate the caller should try again.
86956 + */
86957 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
86958 + return -EAGAIN;
86959 + }
86960 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
86961 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
86962 + // Claculate total buffer size required
86963 + BssBufSize = sizeof(ULONG);
86964 +
86965 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
86966 + {
86967 + // Align pointer to 4 bytes boundary.
86968 + //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
86969 + //if (Padding == 4)
86970 + // Padding = 0;
86971 + BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
86972 + }
86973 +
86974 + // For safety issue, we add 256 bytes just in case
86975 + BssBufSize += 256;
86976 + // Allocate the same size as passed from higher layer
86977 + pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
86978 + if(pBuf == NULL)
86979 + {
86980 + Status = -ENOMEM;
86981 + break;
86982 + }
86983 + // Init 802_11_BSSID_LIST_EX structure
86984 + NdisZeroMemory(pBuf, BssBufSize);
86985 + pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
86986 + pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
86987 +
86988 + // Calculate total buffer length
86989 + BssLen = 4; // Consist of NumberOfItems
86990 + // Point to start of NDIS_WLAN_BSSID_EX
86991 + // pPtr = pBuf + sizeof(ULONG);
86992 + pPtr = (PUCHAR) &pBssidList->Bssid[0];
86993 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
86994 + {
86995 + pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
86996 + NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
86997 + if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
86998 + {
86999 + //
87000 + // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
87001 + // and then failed to send EAPOl farame.
87002 + //
87003 + if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
87004 + {
87005 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
87006 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
87007 + }
87008 + else
87009 + pBss->Ssid.SsidLength = 0;
87010 + }
87011 + else
87012 + {
87013 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
87014 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
87015 + }
87016 + pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
87017 + pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
87018 + pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
87019 + pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
87020 + pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
87021 + pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
87022 +
87023 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
87024 +
87025 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
87026 + pBss->InfrastructureMode = Ndis802_11Infrastructure;
87027 + else
87028 + pBss->InfrastructureMode = Ndis802_11IBSS;
87029 +
87030 + NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
87031 + NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
87032 + pAdapter->ScanTab.BssEntry[i].ExtRate,
87033 + pAdapter->ScanTab.BssEntry[i].ExtRateLen);
87034 +
87035 + if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
87036 + {
87037 + pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
87038 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
87039 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
87040 + }
87041 + else
87042 + {
87043 + pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
87044 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
87045 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
87046 + NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
87047 + pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
87048 + }
87049 + pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
87050 +
87051 +#if WIRELESS_EXT < 17
87052 + if ((BssLen + pBss->Length) < wrq->u.data.length)
87053 + BssLen += pBss->Length;
87054 + else
87055 + {
87056 + pBssidList->NumberOfItems = i;
87057 + break;
87058 + }
87059 +#else
87060 + BssLen += pBss->Length;
87061 +#endif
87062 + }
87063 +
87064 +#if WIRELESS_EXT < 17
87065 + wrq->u.data.length = BssLen;
87066 +#else
87067 + if (BssLen > wrq->u.data.length)
87068 + {
87069 + kfree(pBssidList);
87070 + return -E2BIG;
87071 + }
87072 + else
87073 + wrq->u.data.length = BssLen;
87074 +#endif
87075 + Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
87076 + kfree(pBssidList);
87077 + break;
87078 + case OID_802_3_CURRENT_ADDRESS:
87079 + wrq->u.data.length = MAC_ADDR_LEN;
87080 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
87081 + break;
87082 + case OID_GEN_MEDIA_CONNECT_STATUS:
87083 + if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
87084 + MediaState = NdisMediaStateConnected;
87085 + else
87086 + MediaState = NdisMediaStateDisconnected;
87087 +
87088 + wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
87089 + Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
87090 + break;
87091 + case OID_802_11_BSSID:
87092 +#ifdef RALINK_ATE
87093 + if (ATE_ON(pAdapter))
87094 + {
87095 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
87096 + Status = NDIS_STATUS_RESOURCES;
87097 + break;
87098 + }
87099 +#endif // RALINK_ATE //
87100 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
87101 + {
87102 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
87103 +
87104 + }
87105 + else
87106 + {
87107 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
87108 + Status = -ENOTCONN;
87109 + }
87110 + break;
87111 + case OID_802_11_SSID:
87112 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
87113 + NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
87114 + Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
87115 + memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
87116 + wrq->u.data.length = sizeof(NDIS_802_11_SSID);
87117 + Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
87118 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
87119 + break;
87120 + case RT_OID_802_11_QUERY_LINK_STATUS:
87121 + pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
87122 + if (pLinkStatus)
87123 + {
87124 + pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
87125 + pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
87126 + pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
87127 + pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
87128 + pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
87129 + wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
87130 + Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
87131 + kfree(pLinkStatus);
87132 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
87133 + }
87134 + else
87135 + {
87136 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
87137 + Status = -EFAULT;
87138 + }
87139 + break;
87140 + case OID_802_11_CONFIGURATION:
87141 + pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
87142 + if (pConfiguration)
87143 + {
87144 + pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
87145 + pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
87146 + pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
87147 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
87148 + wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
87149 + Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
87150 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
87151 + pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
87152 + kfree(pConfiguration);
87153 + }
87154 + else
87155 + {
87156 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
87157 + Status = -EFAULT;
87158 + }
87159 + break;
87160 + case RT_OID_802_11_SNR_0:
87161 + if ((pAdapter->StaCfg.LastSNR0 > 0))
87162 + {
87163 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
87164 + wrq->u.data.length = sizeof(ulInfo);
87165 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87166 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
87167 + }
87168 + else
87169 + Status = -EFAULT;
87170 + break;
87171 + case RT_OID_802_11_SNR_1:
87172 + if ((pAdapter->Antenna.field.RxPath > 1) &&
87173 + (pAdapter->StaCfg.LastSNR1 > 0))
87174 + {
87175 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
87176 + wrq->u.data.length = sizeof(ulInfo);
87177 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87178 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
87179 + }
87180 + else
87181 + Status = -EFAULT;
87182 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
87183 + break;
87184 + case OID_802_11_RSSI_TRIGGER:
87185 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
87186 + wrq->u.data.length = sizeof(ulInfo);
87187 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87188 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
87189 + break;
87190 + case OID_802_11_RSSI:
87191 + case RT_OID_802_11_RSSI:
87192 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
87193 + wrq->u.data.length = sizeof(ulInfo);
87194 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87195 + break;
87196 + case RT_OID_802_11_RSSI_1:
87197 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
87198 + wrq->u.data.length = sizeof(ulInfo);
87199 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87200 + break;
87201 + case RT_OID_802_11_RSSI_2:
87202 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
87203 + wrq->u.data.length = sizeof(ulInfo);
87204 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87205 + break;
87206 + case OID_802_11_STATISTICS:
87207 + pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
87208 + if (pStatistics)
87209 + {
87210 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
87211 + // add the most up-to-date h/w raw counters into software counters
87212 + NICUpdateRawCounters(pAdapter);
87213 +
87214 + // Sanity check for calculation of sucessful count
87215 + if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
87216 + pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
87217 +
87218 + pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
87219 + pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
87220 + pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
87221 + pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
87222 + pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
87223 + pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
87224 + pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
87225 + pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
87226 + pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
87227 + pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
87228 + pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
87229 +#ifdef DBG
87230 + pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
87231 +#else
87232 + pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
87233 + pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
87234 +#endif
87235 + wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
87236 + Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
87237 + kfree(pStatistics);
87238 + }
87239 + else
87240 + {
87241 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
87242 + Status = -EFAULT;
87243 + }
87244 + break;
87245 + case OID_GEN_RCV_OK:
87246 + ulInfo = pAdapter->Counters8023.GoodReceives;
87247 + wrq->u.data.length = sizeof(ulInfo);
87248 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87249 + break;
87250 + case OID_GEN_RCV_NO_BUFFER:
87251 + ulInfo = pAdapter->Counters8023.RxNoBuffer;
87252 + wrq->u.data.length = sizeof(ulInfo);
87253 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87254 + break;
87255 + case RT_OID_802_11_PHY_MODE:
87256 + ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
87257 + wrq->u.data.length = sizeof(ulInfo);
87258 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87259 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
87260 + break;
87261 + case RT_OID_802_11_STA_CONFIG:
87262 + pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
87263 + if (pStaConfig)
87264 + {
87265 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
87266 + pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
87267 + pStaConfig->EnableTurboRate = 0;
87268 + pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
87269 + pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
87270 + //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
87271 + pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
87272 + pStaConfig->Rsv1 = 0;
87273 + pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
87274 + wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
87275 + Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
87276 + kfree(pStaConfig);
87277 + }
87278 + else
87279 + {
87280 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
87281 + Status = -EFAULT;
87282 + }
87283 + break;
87284 + case OID_802_11_RTS_THRESHOLD:
87285 + RtsThresh = pAdapter->CommonCfg.RtsThreshold;
87286 + wrq->u.data.length = sizeof(RtsThresh);
87287 + Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
87288 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
87289 + break;
87290 + case OID_802_11_FRAGMENTATION_THRESHOLD:
87291 + FragThresh = pAdapter->CommonCfg.FragmentThreshold;
87292 + if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
87293 + FragThresh = 0;
87294 + wrq->u.data.length = sizeof(FragThresh);
87295 + Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
87296 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
87297 + break;
87298 + case OID_802_11_POWER_MODE:
87299 + PowerMode = pAdapter->StaCfg.WindowsPowerMode;
87300 + wrq->u.data.length = sizeof(PowerMode);
87301 + Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
87302 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
87303 + break;
87304 + case RT_OID_802_11_RADIO:
87305 + RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
87306 + wrq->u.data.length = sizeof(RadioState);
87307 + Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
87308 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
87309 + break;
87310 + case OID_802_11_INFRASTRUCTURE_MODE:
87311 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
87312 + BssType = Ndis802_11IBSS;
87313 + else if (pAdapter->StaCfg.BssType == BSS_INFRA)
87314 + BssType = Ndis802_11Infrastructure;
87315 + else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
87316 + BssType = Ndis802_11Monitor;
87317 + else
87318 + BssType = Ndis802_11AutoUnknown;
87319 +
87320 + wrq->u.data.length = sizeof(BssType);
87321 + Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
87322 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
87323 + break;
87324 + case RT_OID_802_11_PREAMBLE:
87325 + PreamType = pAdapter->CommonCfg.TxPreamble;
87326 + wrq->u.data.length = sizeof(PreamType);
87327 + Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
87328 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
87329 + break;
87330 + case OID_802_11_AUTHENTICATION_MODE:
87331 + AuthMode = pAdapter->StaCfg.AuthMode;
87332 + wrq->u.data.length = sizeof(AuthMode);
87333 + Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
87334 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
87335 + break;
87336 + case OID_802_11_WEP_STATUS:
87337 + WepStatus = pAdapter->StaCfg.WepStatus;
87338 + wrq->u.data.length = sizeof(WepStatus);
87339 + Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
87340 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
87341 + break;
87342 + case OID_802_11_TX_POWER_LEVEL:
87343 + wrq->u.data.length = sizeof(ULONG);
87344 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
87345 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
87346 + break;
87347 + case RT_OID_802_11_TX_POWER_LEVEL_1:
87348 + wrq->u.data.length = sizeof(ULONG);
87349 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
87350 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
87351 + break;
87352 + case OID_802_11_NETWORK_TYPES_SUPPORTED:
87353 + if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
87354 + {
87355 + NetworkTypeList[0] = 3; // NumberOfItems = 3
87356 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
87357 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
87358 + NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
87359 + wrq->u.data.length = 16;
87360 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
87361 + }
87362 + else
87363 + {
87364 + NetworkTypeList[0] = 2; // NumberOfItems = 2
87365 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
87366 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
87367 + wrq->u.data.length = 12;
87368 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
87369 + }
87370 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
87371 + break;
87372 + case OID_802_11_NETWORK_TYPE_IN_USE:
87373 + wrq->u.data.length = sizeof(ULONG);
87374 + if (pAdapter->CommonCfg.PhyMode == PHY_11A)
87375 + ulInfo = Ndis802_11OFDM5;
87376 + else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
87377 + ulInfo = Ndis802_11OFDM24;
87378 + else
87379 + ulInfo = Ndis802_11DS;
87380 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87381 + break;
87382 + case RT_OID_802_11_QUERY_LAST_RX_RATE:
87383 + ulInfo = (ULONG)pAdapter->LastRxRate;
87384 + wrq->u.data.length = sizeof(ulInfo);
87385 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87386 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
87387 + break;
87388 + case RT_OID_802_11_QUERY_LAST_TX_RATE:
87389 + //ulInfo = (ULONG)pAdapter->LastTxRate;
87390 + ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
87391 + wrq->u.data.length = sizeof(ulInfo);
87392 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87393 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
87394 + break;
87395 + case RT_OID_802_11_QUERY_EEPROM_VERSION:
87396 + wrq->u.data.length = sizeof(ULONG);
87397 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
87398 + break;
87399 + case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
87400 + wrq->u.data.length = sizeof(ULONG);
87401 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
87402 + break;
87403 + case RT_OID_802_11_QUERY_NOISE_LEVEL:
87404 + wrq->u.data.length = sizeof(UCHAR);
87405 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
87406 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
87407 + break;
87408 + case RT_OID_802_11_EXTRA_INFO:
87409 + wrq->u.data.length = sizeof(ULONG);
87410 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
87411 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
87412 + break;
87413 + case RT_OID_WE_VERSION_COMPILED:
87414 + wrq->u.data.length = sizeof(UINT);
87415 + we_version_compiled = WIRELESS_EXT;
87416 + Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
87417 + break;
87418 + case RT_OID_802_11_QUERY_APSD_SETTING:
87419 + apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
87420 + | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
87421 +
87422 + wrq->u.data.length = sizeof(ULONG);
87423 + Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
87424 + 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",
87425 + apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
87426 + break;
87427 + case RT_OID_802_11_QUERY_APSD_PSM:
87428 + wrq->u.data.length = sizeof(ULONG);
87429 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
87430 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
87431 + break;
87432 + case RT_OID_802_11_QUERY_WMM:
87433 + wrq->u.data.length = sizeof(BOOLEAN);
87434 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
87435 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
87436 + break;
87437 +#ifdef WPA_SUPPLICANT_SUPPORT
87438 + case RT_OID_NEW_DRIVER:
87439 + {
87440 + UCHAR enabled = 1;
87441 + wrq->u.data.length = sizeof(UCHAR);
87442 + Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
87443 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
87444 + }
87445 + break;
87446 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
87447 + wrq->u.data.length = sizeof(UCHAR);
87448 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
87449 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
87450 + break;
87451 +#endif // WPA_SUPPLICANT_SUPPORT //
87452 +
87453 + case RT_OID_DRIVER_DEVICE_NAME:
87454 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
87455 + wrq->u.data.length = 16;
87456 + if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
87457 + {
87458 + Status = -EFAULT;
87459 + }
87460 + break;
87461 + case RT_OID_802_11_QUERY_HT_PHYMODE:
87462 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
87463 + if (pHTPhyMode)
87464 + {
87465 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
87466 + pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
87467 + pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
87468 + pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
87469 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
87470 + pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
87471 +
87472 + pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
87473 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
87474 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
87475 + {
87476 + Status = -EFAULT;
87477 + }
87478 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
87479 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
87480 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
87481 + }
87482 + else
87483 + {
87484 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
87485 + Status = -EFAULT;
87486 + }
87487 + break;
87488 + case RT_OID_802_11_COUNTRY_REGION:
87489 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
87490 + wrq->u.data.length = sizeof(ulInfo);
87491 + ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
87492 + ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
87493 + if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
87494 + {
87495 + Status = -EFAULT;
87496 + }
87497 + break;
87498 + case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
87499 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
87500 + if (pHTPhyMode)
87501 + {
87502 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
87503 + pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
87504 + pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
87505 + pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
87506 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
87507 + pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
87508 +
87509 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
87510 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
87511 + {
87512 + Status = -EFAULT;
87513 + }
87514 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
87515 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
87516 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
87517 + }
87518 + else
87519 + {
87520 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
87521 + Status = -EFAULT;
87522 + }
87523 + break;
87524 + case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
87525 + wrq->u.data.length = sizeof(UCHAR);
87526 + i = 0;
87527 +#ifdef MULTIPLE_CARD_SUPPORT
87528 + i = 1;
87529 +#endif // MULTIPLE_CARD_SUPPORT //
87530 + if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
87531 + {
87532 + Status = -EFAULT;
87533 + }
87534 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
87535 + break;
87536 +#ifdef SNMP_SUPPORT
87537 + case RT_OID_802_11_MAC_ADDRESS:
87538 + wrq->u.data.length = MAC_ADDR_LEN;
87539 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
87540 + break;
87541 +
87542 + case RT_OID_802_11_MANUFACTUREROUI:
87543 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
87544 + wrq->u.data.length = ManufacturerOUI_LEN;
87545 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
87546 + break;
87547 +
87548 + case RT_OID_802_11_MANUFACTURERNAME:
87549 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
87550 + wrq->u.data.length = strlen(ManufacturerNAME);
87551 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
87552 + break;
87553 +
87554 + case RT_OID_802_11_RESOURCETYPEIDNAME:
87555 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
87556 + wrq->u.data.length = strlen(ResourceTypeIdName);
87557 + Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
87558 + break;
87559 +
87560 + case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
87561 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
87562 + ulInfo = 1; // 1 is support wep else 2 is not support.
87563 + wrq->u.data.length = sizeof(ulInfo);
87564 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87565 + break;
87566 +
87567 + case RT_OID_802_11_POWERMANAGEMENTMODE:
87568 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
87569 + if (pAdapter->StaCfg.Psm == PSMP_ACTION)
87570 + ulInfo = 1; // 1 is power active else 2 is power save.
87571 + else
87572 + ulInfo = 2;
87573 +
87574 + wrq->u.data.length = sizeof(ulInfo);
87575 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87576 + break;
87577 +
87578 + case OID_802_11_WEPDEFAULTKEYVALUE:
87579 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
87580 + //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
87581 + pKeyIdxValue = wrq->u.data.pointer;
87582 + DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
87583 + valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
87584 + NdisMoveMemory(pKeyIdxValue->Value,
87585 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
87586 + valueLen);
87587 + pKeyIdxValue->Value[valueLen]='\0';
87588 +
87589 + wrq->u.data.length = sizeof(DefaultKeyIdxValue);
87590 +
87591 + Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
87592 + 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,
87593 + pAdapter->SharedKey[BSS0][0].Key[0],
87594 + pAdapter->SharedKey[BSS0][1].Key[0],
87595 + pAdapter->SharedKey[BSS0][2].Key[0],
87596 + pAdapter->SharedKey[BSS0][3].Key[0]));
87597 + break;
87598 +
87599 + case OID_802_11_WEPDEFAULTKEYID:
87600 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
87601 + wrq->u.data.length = sizeof(UCHAR);
87602 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
87603 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
87604 + break;
87605 +
87606 + case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
87607 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
87608 + wrq->u.data.length = sizeof(UCHAR);
87609 + Status = copy_to_user(wrq->u.data.pointer,
87610 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
87611 + wrq->u.data.length);
87612 + break;
87613 +
87614 + case OID_802_11_SHORTRETRYLIMIT:
87615 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
87616 + wrq->u.data.length = sizeof(ULONG);
87617 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
87618 + ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
87619 + DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
87620 + Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
87621 + break;
87622 +
87623 + case OID_802_11_LONGRETRYLIMIT:
87624 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
87625 + wrq->u.data.length = sizeof(ULONG);
87626 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
87627 + LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
87628 + DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
87629 + Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
87630 + break;
87631 +
87632 + case RT_OID_802_11_PRODUCTID:
87633 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
87634 +
87635 +#ifdef RT2870
87636 + sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
87637 +
87638 +#endif // RT2870 //
87639 + wrq->u.data.length = strlen(tmp);
87640 + Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
87641 + break;
87642 +
87643 + case RT_OID_802_11_MANUFACTUREID:
87644 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
87645 + wrq->u.data.length = strlen(ManufacturerNAME);
87646 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
87647 + break;
87648 +
87649 + case OID_802_11_CURRENTCHANNEL:
87650 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
87651 + wrq->u.data.length = sizeof(UCHAR);
87652 + DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
87653 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
87654 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
87655 + break;
87656 +#endif //SNMP_SUPPORT
87657 +
87658 + case OID_802_11_BUILD_CHANNEL_EX:
87659 + {
87660 + UCHAR value;
87661 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
87662 + wrq->u.data.length = sizeof(UCHAR);
87663 +#ifdef EXT_BUILD_CHANNEL_LIST
87664 + DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
87665 + value = 1;
87666 +#else
87667 + DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
87668 + value = 0;
87669 +#endif // EXT_BUILD_CHANNEL_LIST //
87670 + Status = copy_to_user(wrq->u.data.pointer, &value, 1);
87671 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
87672 + }
87673 + break;
87674 +
87675 + case OID_802_11_GET_CH_LIST:
87676 + {
87677 + PRT_CHANNEL_LIST_INFO pChListBuf;
87678 +
87679 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
87680 + if (pAdapter->ChannelListNum == 0)
87681 + {
87682 + wrq->u.data.length = 0;
87683 + break;
87684 + }
87685 +
87686 + pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
87687 + if (pChListBuf == NULL)
87688 + {
87689 + wrq->u.data.length = 0;
87690 + break;
87691 + }
87692 +
87693 + pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
87694 + for (i = 0; i < pChListBuf->ChannelListNum; i++)
87695 + pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
87696 +
87697 + wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
87698 + Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
87699 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
87700 +
87701 + if (pChListBuf)
87702 + kfree(pChListBuf);
87703 + }
87704 + break;
87705 +
87706 + case OID_802_11_GET_COUNTRY_CODE:
87707 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
87708 + wrq->u.data.length = 2;
87709 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
87710 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
87711 + break;
87712 +
87713 + case OID_802_11_GET_CHANNEL_GEOGRAPHY:
87714 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
87715 + wrq->u.data.length = 1;
87716 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
87717 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
87718 + break;
87719 +
87720 +
87721 +#ifdef QOS_DLS_SUPPORT
87722 + case RT_OID_802_11_QUERY_DLS:
87723 + wrq->u.data.length = sizeof(BOOLEAN);
87724 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
87725 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
87726 + break;
87727 +
87728 + case RT_OID_802_11_QUERY_DLS_PARAM:
87729 + {
87730 + PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
87731 + if (pDlsInfo == NULL)
87732 + break;
87733 +
87734 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
87735 + {
87736 + RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
87737 + }
87738 +
87739 + pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
87740 + wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
87741 + Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
87742 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
87743 +
87744 + if (pDlsInfo)
87745 + kfree(pDlsInfo);
87746 + }
87747 + break;
87748 +#endif // QOS_DLS_SUPPORT //
87749 + default:
87750 + DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
87751 + Status = -EOPNOTSUPP;
87752 + break;
87753 + }
87754 + return Status;
87755 +}
87756 +
87757 +INT rt28xx_sta_ioctl(
87758 + IN struct net_device *net_dev,
87759 + IN OUT struct ifreq *rq,
87760 + IN INT cmd)
87761 +{
87762 + POS_COOKIE pObj;
87763 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
87764 + RTMP_ADAPTER *pAd = NULL;
87765 + struct iwreq *wrq = (struct iwreq *) rq;
87766 + BOOLEAN StateMachineTouched = FALSE;
87767 + INT Status = NDIS_STATUS_SUCCESS;
87768 + USHORT subcmd;
87769 +
87770 + if (net_dev->priv_flags == INT_MAIN)
87771 + {
87772 + pAd = net_dev->priv;
87773 + }
87774 + else
87775 + {
87776 + pVirtualAd = net_dev->priv;
87777 + pAd = pVirtualAd->RtmpDev->priv;
87778 + }
87779 + pObj = (POS_COOKIE) pAd->OS_Cookie;
87780 +
87781 + if (pAd == NULL)
87782 + {
87783 + /* if 1st open fail, pAd will be free;
87784 + So the net_dev->priv will be NULL in 2rd open */
87785 + return -ENETDOWN;
87786 + }
87787 +
87788 + //check if the interface is down
87789 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
87790 + {
87791 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
87792 + if (wrq->u.data.pointer == NULL)
87793 + {
87794 + return Status;
87795 + }
87796 +
87797 + if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
87798 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
87799 + {
87800 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
87801 + return -ENETDOWN;
87802 + }
87803 + }
87804 +
87805 + { // determine this ioctl command is comming from which interface.
87806 + pObj->ioctl_if_type = INT_MAIN;
87807 + pObj->ioctl_if = MAIN_MBSSID;
87808 + }
87809 +
87810 + switch(cmd)
87811 + {
87812 +#ifdef RALINK_ATE
87813 +#ifdef RALINK_28xx_QA
87814 + case RTPRIV_IOCTL_ATE:
87815 + {
87816 + RtmpDoAte(pAd, wrq);
87817 + }
87818 + break;
87819 +#endif // RALINK_28xx_QA //
87820 +#endif // RALINK_ATE //
87821 + case SIOCGIFHWADDR:
87822 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
87823 + memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
87824 + break;
87825 + case SIOCGIWNAME:
87826 + {
87827 + char *name=&wrq->u.name[0];
87828 + rt_ioctl_giwname(net_dev, NULL, name, NULL);
87829 + break;
87830 + }
87831 + case SIOCGIWESSID: //Get ESSID
87832 + {
87833 + struct iw_point *essid=&wrq->u.essid;
87834 + rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
87835 + break;
87836 + }
87837 + case SIOCSIWESSID: //Set ESSID
87838 + {
87839 + struct iw_point *essid=&wrq->u.essid;
87840 + rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
87841 + break;
87842 + }
87843 + case SIOCSIWNWID: // set network id (the cell)
87844 + case SIOCGIWNWID: // get network id
87845 + Status = -EOPNOTSUPP;
87846 + break;
87847 + case SIOCSIWFREQ: //set channel/frequency (Hz)
87848 + {
87849 + struct iw_freq *freq=&wrq->u.freq;
87850 + rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
87851 + break;
87852 + }
87853 + case SIOCGIWFREQ: // get channel/frequency (Hz)
87854 + {
87855 + struct iw_freq *freq=&wrq->u.freq;
87856 + rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
87857 + break;
87858 + }
87859 + case SIOCSIWNICKN: //set node name/nickname
87860 + {
87861 + struct iw_point *data=&wrq->u.data;
87862 + rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
87863 + break;
87864 + }
87865 + case SIOCGIWNICKN: //get node name/nickname
87866 + {
87867 + struct iw_point *data=&wrq->u.data;
87868 + rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
87869 + break;
87870 + }
87871 + case SIOCGIWRATE: //get default bit rate (bps)
87872 + rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
87873 + break;
87874 + case SIOCSIWRATE: //set default bit rate (bps)
87875 + rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
87876 + break;
87877 + case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
87878 + {
87879 + struct iw_param *rts=&wrq->u.rts;
87880 + rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
87881 + break;
87882 + }
87883 + case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
87884 + {
87885 + struct iw_param *rts=&wrq->u.rts;
87886 + rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
87887 + break;
87888 + }
87889 + case SIOCGIWFRAG: //get fragmentation thr (bytes)
87890 + {
87891 + struct iw_param *frag=&wrq->u.frag;
87892 + rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
87893 + break;
87894 + }
87895 + case SIOCSIWFRAG: //set fragmentation thr (bytes)
87896 + {
87897 + struct iw_param *frag=&wrq->u.frag;
87898 + rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
87899 + break;
87900 + }
87901 + case SIOCGIWENCODE: //get encoding token & mode
87902 + {
87903 + struct iw_point *erq=&wrq->u.encoding;
87904 + if(erq->pointer)
87905 + rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
87906 + break;
87907 + }
87908 + case SIOCSIWENCODE: //set encoding token & mode
87909 + {
87910 + struct iw_point *erq=&wrq->u.encoding;
87911 + if(erq->pointer)
87912 + rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
87913 + break;
87914 + }
87915 + case SIOCGIWAP: //get access point MAC addresses
87916 + {
87917 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
87918 + rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
87919 + break;
87920 + }
87921 + case SIOCSIWAP: //set access point MAC addresses
87922 + {
87923 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
87924 + rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
87925 + break;
87926 + }
87927 + case SIOCGIWMODE: //get operation mode
87928 + {
87929 + __u32 *mode=&wrq->u.mode;
87930 + rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
87931 + break;
87932 + }
87933 + case SIOCSIWMODE: //set operation mode
87934 + {
87935 + __u32 *mode=&wrq->u.mode;
87936 + rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
87937 + break;
87938 + }
87939 + case SIOCGIWSENS: //get sensitivity (dBm)
87940 + case SIOCSIWSENS: //set sensitivity (dBm)
87941 + case SIOCGIWPOWER: //get Power Management settings
87942 + case SIOCSIWPOWER: //set Power Management settings
87943 + case SIOCGIWTXPOW: //get transmit power (dBm)
87944 + case SIOCSIWTXPOW: //set transmit power (dBm)
87945 + case SIOCGIWRANGE: //Get range of parameters
87946 + case SIOCGIWRETRY: //get retry limits and lifetime
87947 + case SIOCSIWRETRY: //set retry limits and lifetime
87948 + Status = -EOPNOTSUPP;
87949 + break;
87950 + case RT_PRIV_IOCTL:
87951 + subcmd = wrq->u.data.flags;
87952 + if( subcmd & OID_GET_SET_TOGGLE)
87953 + Status = RTMPSetInformation(pAd, rq, subcmd);
87954 + else
87955 + Status = RTMPQueryInformation(pAd, rq, subcmd);
87956 + break;
87957 + case SIOCGIWPRIV:
87958 + if (wrq->u.data.pointer)
87959 + {
87960 + if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
87961 + break;
87962 + wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
87963 + if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
87964 + Status = -EFAULT;
87965 + }
87966 + break;
87967 + case RTPRIV_IOCTL_SET:
87968 + if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
87969 + break;
87970 + rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
87971 + break;
87972 + case RTPRIV_IOCTL_GSITESURVEY:
87973 + RTMPIoctlGetSiteSurvey(pAd, wrq);
87974 + break;
87975 +#ifdef DBG
87976 + case RTPRIV_IOCTL_MAC:
87977 + RTMPIoctlMAC(pAd, wrq);
87978 + break;
87979 + case RTPRIV_IOCTL_E2P:
87980 + RTMPIoctlE2PROM(pAd, wrq);
87981 + break;
87982 +#endif // DBG //
87983 + case SIOCETHTOOL:
87984 + break;
87985 + default:
87986 + DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
87987 + Status = -EOPNOTSUPP;
87988 + break;
87989 + }
87990 +
87991 + if(StateMachineTouched) // Upper layer sent a MLME-related operations
87992 + RT28XX_MLME_HANDLER(pAd);
87993 +
87994 + return Status;
87995 +}
87996 +
87997 +/*
87998 + ==========================================================================
87999 + Description:
88000 + Set SSID
88001 + Return:
88002 + TRUE if all parameters are OK, FALSE otherwise
88003 + ==========================================================================
88004 +*/
88005 +INT Set_SSID_Proc(
88006 + IN PRTMP_ADAPTER pAdapter,
88007 + IN PUCHAR arg)
88008 +{
88009 + NDIS_802_11_SSID Ssid, *pSsid=NULL;
88010 + BOOLEAN StateMachineTouched = FALSE;
88011 + int success = TRUE;
88012 +
88013 + if( strlen(arg) <= MAX_LEN_OF_SSID)
88014 + {
88015 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
88016 + if (strlen(arg) != 0)
88017 + {
88018 + NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
88019 + Ssid.SsidLength = strlen(arg);
88020 + }
88021 + else //ANY ssid
88022 + {
88023 + Ssid.SsidLength = 0;
88024 + memcpy(Ssid.Ssid, "", 0);
88025 + pAdapter->StaCfg.BssType = BSS_INFRA;
88026 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
88027 + pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
88028 + }
88029 + pSsid = &Ssid;
88030 +
88031 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
88032 + {
88033 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
88034 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
88035 + }
88036 +
88037 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
88038 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
88039 + pAdapter->bConfigChanged = TRUE;
88040 +
88041 + MlmeEnqueue(pAdapter,
88042 + MLME_CNTL_STATE_MACHINE,
88043 + OID_802_11_SSID,
88044 + sizeof(NDIS_802_11_SSID),
88045 + (VOID *)pSsid);
88046 +
88047 + StateMachineTouched = TRUE;
88048 + DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
88049 + }
88050 + else
88051 + success = FALSE;
88052 +
88053 + if (StateMachineTouched) // Upper layer sent a MLME-related operations
88054 + RT28XX_MLME_HANDLER(pAdapter);
88055 +
88056 + return success;
88057 +}
88058 +
88059 +#ifdef WMM_SUPPORT
88060 +/*
88061 + ==========================================================================
88062 + Description:
88063 + Set WmmCapable Enable or Disable
88064 + Return:
88065 + TRUE if all parameters are OK, FALSE otherwise
88066 + ==========================================================================
88067 +*/
88068 +INT Set_WmmCapable_Proc(
88069 + IN PRTMP_ADAPTER pAd,
88070 + IN PUCHAR arg)
88071 +{
88072 + BOOLEAN bWmmCapable;
88073 +
88074 + bWmmCapable = simple_strtol(arg, 0, 10);
88075 +
88076 + if ((bWmmCapable == 1)
88077 +#ifdef RT2870
88078 + && (pAd->NumberOfPipes >= 5)
88079 +#endif // RT2870 //
88080 + )
88081 + pAd->CommonCfg.bWmmCapable = TRUE;
88082 + else if (bWmmCapable == 0)
88083 + pAd->CommonCfg.bWmmCapable = FALSE;
88084 + else
88085 + return FALSE; //Invalid argument
88086 +
88087 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
88088 + pAd->CommonCfg.bWmmCapable));
88089 +
88090 + return TRUE;
88091 +}
88092 +#endif // WMM_SUPPORT //
88093 +
88094 +/*
88095 + ==========================================================================
88096 + Description:
88097 + Set Network Type(Infrastructure/Adhoc mode)
88098 + Return:
88099 + TRUE if all parameters are OK, FALSE otherwise
88100 + ==========================================================================
88101 +*/
88102 +INT Set_NetworkType_Proc(
88103 + IN PRTMP_ADAPTER pAdapter,
88104 + IN PUCHAR arg)
88105 +{
88106 + UINT32 Value = 0;
88107 +
88108 + if (strcmp(arg, "Adhoc") == 0)
88109 + {
88110 + if (pAdapter->StaCfg.BssType != BSS_ADHOC)
88111 + {
88112 + // Config has changed
88113 + pAdapter->bConfigChanged = TRUE;
88114 + if (MONITOR_ON(pAdapter))
88115 + {
88116 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
88117 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
88118 + Value &= (~0x80);
88119 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
88120 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88121 + pAdapter->StaCfg.bAutoReconnect = TRUE;
88122 + LinkDown(pAdapter, FALSE);
88123 + }
88124 + if (INFRA_ON(pAdapter))
88125 + {
88126 + //BOOLEAN Cancelled;
88127 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
88128 + // Since calling this indicate user don't want to connect to that SSID anymore.
88129 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
88130 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
88131 +
88132 + LinkDown(pAdapter, FALSE);
88133 +
88134 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
88135 + }
88136 + }
88137 + pAdapter->StaCfg.BssType = BSS_ADHOC;
88138 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
88139 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
88140 + }
88141 + else if (strcmp(arg, "Infra") == 0)
88142 + {
88143 + if (pAdapter->StaCfg.BssType != BSS_INFRA)
88144 + {
88145 + // Config has changed
88146 + pAdapter->bConfigChanged = TRUE;
88147 + if (MONITOR_ON(pAdapter))
88148 + {
88149 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
88150 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
88151 + Value &= (~0x80);
88152 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
88153 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88154 + pAdapter->StaCfg.bAutoReconnect = TRUE;
88155 + LinkDown(pAdapter, FALSE);
88156 + }
88157 + if (ADHOC_ON(pAdapter))
88158 + {
88159 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
88160 + // Since calling this indicate user don't want to connect to that SSID anymore.
88161 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
88162 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
88163 +
88164 + LinkDown(pAdapter, FALSE);
88165 + }
88166 + }
88167 + pAdapter->StaCfg.BssType = BSS_INFRA;
88168 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
88169 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
88170 +
88171 + pAdapter->StaCfg.BssType = BSS_INFRA;
88172 + }
88173 + else if (strcmp(arg, "Monitor") == 0)
88174 + {
88175 + UCHAR bbpValue = 0;
88176 + BCN_TIME_CFG_STRUC csr;
88177 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
88178 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
88179 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88180 + // disable all periodic state machine
88181 + pAdapter->StaCfg.bAutoReconnect = FALSE;
88182 + // reset all mlme state machine
88183 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
88184 + DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
88185 + if (pAdapter->CommonCfg.CentralChannel == 0)
88186 + {
88187 +#ifdef DOT11_N_SUPPORT
88188 + if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
88189 + pAdapter->CommonCfg.CentralChannel = 36;
88190 + else
88191 +#endif // DOT11_N_SUPPORT //
88192 + pAdapter->CommonCfg.CentralChannel = 6;
88193 + }
88194 +#ifdef DOT11_N_SUPPORT
88195 + else
88196 + N_ChannelCheck(pAdapter);
88197 +#endif // DOT11_N_SUPPORT //
88198 +
88199 +#ifdef DOT11_N_SUPPORT
88200 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
88201 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
88202 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
88203 + {
88204 + // 40MHz ,control channel at lower
88205 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
88206 + bbpValue &= (~0x18);
88207 + bbpValue |= 0x10;
88208 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
88209 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
88210 + // RX : control channel at lower
88211 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
88212 + bbpValue &= (~0x20);
88213 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
88214 +
88215 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
88216 + Value &= 0xfffffffe;
88217 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
88218 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
88219 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
88220 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
88221 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
88222 + pAdapter->CommonCfg.Channel,
88223 + pAdapter->CommonCfg.CentralChannel));
88224 + }
88225 + else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
88226 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
88227 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
88228 + {
88229 + // 40MHz ,control channel at upper
88230 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
88231 + bbpValue &= (~0x18);
88232 + bbpValue |= 0x10;
88233 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
88234 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
88235 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
88236 + Value |= 0x1;
88237 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
88238 +
88239 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
88240 + bbpValue |= (0x20);
88241 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
88242 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
88243 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
88244 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
88245 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
88246 + pAdapter->CommonCfg.Channel,
88247 + pAdapter->CommonCfg.CentralChannel));
88248 + }
88249 + else
88250 +#endif // DOT11_N_SUPPORT //
88251 + {
88252 + // 20MHz
88253 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
88254 + bbpValue &= (~0x18);
88255 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
88256 + pAdapter->CommonCfg.BBPCurrentBW = BW_20;
88257 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
88258 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
88259 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
88260 + }
88261 + // Enable Rx with promiscuous reception
88262 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
88263 + // ASIC supporsts sniffer function with replacing RSSI with timestamp.
88264 + //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
88265 + //Value |= (0x80);
88266 + //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
88267 + // disable sync
88268 + RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
88269 + csr.field.bBeaconGen = 0;
88270 + csr.field.bTBTTEnable = 0;
88271 + csr.field.TsfSyncMode = 0;
88272 + RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
88273 +
88274 + pAdapter->StaCfg.BssType = BSS_MONITOR;
88275 + pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
88276 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
88277 + }
88278 +
88279 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
88280 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
88281 +
88282 + DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
88283 +
88284 + return TRUE;
88285 +}
88286 +
88287 +/*
88288 + ==========================================================================
88289 + Description:
88290 + Set Authentication mode
88291 + Return:
88292 + TRUE if all parameters are OK, FALSE otherwise
88293 + ==========================================================================
88294 +*/
88295 +INT Set_AuthMode_Proc(
88296 + IN PRTMP_ADAPTER pAdapter,
88297 + IN PUCHAR arg)
88298 +{
88299 + if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
88300 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
88301 + else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
88302 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
88303 + else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
88304 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
88305 + else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
88306 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
88307 + else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
88308 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
88309 + else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
88310 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
88311 +#ifdef WPA_SUPPLICANT_SUPPORT
88312 + else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
88313 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
88314 + else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
88315 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
88316 +#endif // WPA_SUPPLICANT_SUPPORT //
88317 + else
88318 + return FALSE;
88319 +
88320 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
88321 +
88322 + DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
88323 +
88324 + return TRUE;
88325 +}
88326 +
88327 +/*
88328 + ==========================================================================
88329 + Description:
88330 + Set Encryption Type
88331 + Return:
88332 + TRUE if all parameters are OK, FALSE otherwise
88333 + ==========================================================================
88334 +*/
88335 +INT Set_EncrypType_Proc(
88336 + IN PRTMP_ADAPTER pAdapter,
88337 + IN PUCHAR arg)
88338 +{
88339 + if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
88340 + {
88341 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88342 + return TRUE; // do nothing
88343 +
88344 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
88345 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
88346 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
88347 + }
88348 + else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
88349 + {
88350 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88351 + return TRUE; // do nothing
88352 +
88353 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
88354 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
88355 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
88356 + }
88357 + else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
88358 + {
88359 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
88360 + return TRUE; // do nothing
88361 +
88362 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
88363 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
88364 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
88365 + }
88366 + else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
88367 + {
88368 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
88369 + return TRUE; // do nothing
88370 +
88371 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
88372 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
88373 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
88374 + }
88375 + else
88376 + return FALSE;
88377 +
88378 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
88379 +
88380 + DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
88381 +
88382 + return TRUE;
88383 +}
88384 +
88385 +/*
88386 + ==========================================================================
88387 + Description:
88388 + Set Default Key ID
88389 + Return:
88390 + TRUE if all parameters are OK, FALSE otherwise
88391 + ==========================================================================
88392 +*/
88393 +INT Set_DefaultKeyID_Proc(
88394 + IN PRTMP_ADAPTER pAdapter,
88395 + IN PUCHAR arg)
88396 +{
88397 + ULONG KeyIdx;
88398 +
88399 + KeyIdx = simple_strtol(arg, 0, 10);
88400 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
88401 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
88402 + else
88403 + return FALSE; //Invalid argument
88404 +
88405 + DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
88406 +
88407 + return TRUE;
88408 +}
88409 +
88410 +/*
88411 + ==========================================================================
88412 + Description:
88413 + Set WEP KEY1
88414 + Return:
88415 + TRUE if all parameters are OK, FALSE otherwise
88416 + ==========================================================================
88417 +*/
88418 +INT Set_Key1_Proc(
88419 + IN PRTMP_ADAPTER pAdapter,
88420 + IN PUCHAR arg)
88421 +{
88422 + int KeyLen;
88423 + int i;
88424 + UCHAR CipherAlg=CIPHER_WEP64;
88425 +
88426 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88427 + return TRUE; // do nothing
88428 +
88429 + KeyLen = strlen(arg);
88430 +
88431 + switch (KeyLen)
88432 + {
88433 + case 5: //wep 40 Ascii type
88434 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
88435 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
88436 + CipherAlg = CIPHER_WEP64;
88437 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
88438 + break;
88439 + case 10: //wep 40 Hex type
88440 + for(i=0; i < KeyLen; i++)
88441 + {
88442 + if( !isxdigit(*(arg+i)) )
88443 + return FALSE; //Not Hex value;
88444 + }
88445 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
88446 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
88447 + CipherAlg = CIPHER_WEP64;
88448 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
88449 + break;
88450 + case 13: //wep 104 Ascii type
88451 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
88452 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
88453 + CipherAlg = CIPHER_WEP128;
88454 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
88455 + break;
88456 + case 26: //wep 104 Hex type
88457 + for(i=0; i < KeyLen; i++)
88458 + {
88459 + if( !isxdigit(*(arg+i)) )
88460 + return FALSE; //Not Hex value;
88461 + }
88462 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
88463 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
88464 + CipherAlg = CIPHER_WEP128;
88465 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
88466 + break;
88467 + default: //Invalid argument
88468 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
88469 + return FALSE;
88470 + }
88471 +
88472 + pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
88473 +
88474 + // Set keys (into ASIC)
88475 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88476 + ; // not support
88477 + else // Old WEP stuff
88478 + {
88479 + AsicAddSharedKeyEntry(pAdapter,
88480 + 0,
88481 + 0,
88482 + pAdapter->SharedKey[BSS0][0].CipherAlg,
88483 + pAdapter->SharedKey[BSS0][0].Key,
88484 + NULL,
88485 + NULL);
88486 + }
88487 +
88488 + return TRUE;
88489 +}
88490 +/*
88491 + ==========================================================================
88492 +
88493 + Description:
88494 + Set WEP KEY2
88495 + Return:
88496 + TRUE if all parameters are OK, FALSE otherwise
88497 + ==========================================================================
88498 +*/
88499 +INT Set_Key2_Proc(
88500 + IN PRTMP_ADAPTER pAdapter,
88501 + IN PUCHAR arg)
88502 +{
88503 + int KeyLen;
88504 + int i;
88505 + UCHAR CipherAlg=CIPHER_WEP64;
88506 +
88507 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88508 + return TRUE; // do nothing
88509 +
88510 + KeyLen = strlen(arg);
88511 +
88512 + switch (KeyLen)
88513 + {
88514 + case 5: //wep 40 Ascii type
88515 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
88516 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
88517 + CipherAlg = CIPHER_WEP64;
88518 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
88519 + break;
88520 + case 10: //wep 40 Hex type
88521 + for(i=0; i < KeyLen; i++)
88522 + {
88523 + if( !isxdigit(*(arg+i)) )
88524 + return FALSE; //Not Hex value;
88525 + }
88526 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
88527 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
88528 + CipherAlg = CIPHER_WEP64;
88529 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
88530 + break;
88531 + case 13: //wep 104 Ascii type
88532 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
88533 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
88534 + CipherAlg = CIPHER_WEP128;
88535 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
88536 + break;
88537 + case 26: //wep 104 Hex type
88538 + for(i=0; i < KeyLen; i++)
88539 + {
88540 + if( !isxdigit(*(arg+i)) )
88541 + return FALSE; //Not Hex value;
88542 + }
88543 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
88544 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
88545 + CipherAlg = CIPHER_WEP128;
88546 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
88547 + break;
88548 + default: //Invalid argument
88549 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
88550 + return FALSE;
88551 + }
88552 + pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
88553 +
88554 + // Set keys (into ASIC)
88555 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88556 + ; // not support
88557 + else // Old WEP stuff
88558 + {
88559 + AsicAddSharedKeyEntry(pAdapter,
88560 + 0,
88561 + 1,
88562 + pAdapter->SharedKey[BSS0][1].CipherAlg,
88563 + pAdapter->SharedKey[BSS0][1].Key,
88564 + NULL,
88565 + NULL);
88566 + }
88567 +
88568 + return TRUE;
88569 +}
88570 +/*
88571 + ==========================================================================
88572 + Description:
88573 + Set WEP KEY3
88574 + Return:
88575 + TRUE if all parameters are OK, FALSE otherwise
88576 + ==========================================================================
88577 +*/
88578 +INT Set_Key3_Proc(
88579 + IN PRTMP_ADAPTER pAdapter,
88580 + IN PUCHAR arg)
88581 +{
88582 + int KeyLen;
88583 + int i;
88584 + UCHAR CipherAlg=CIPHER_WEP64;
88585 +
88586 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88587 + return TRUE; // do nothing
88588 +
88589 + KeyLen = strlen(arg);
88590 +
88591 + switch (KeyLen)
88592 + {
88593 + case 5: //wep 40 Ascii type
88594 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
88595 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
88596 + CipherAlg = CIPHER_WEP64;
88597 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
88598 + break;
88599 + case 10: //wep 40 Hex type
88600 + for(i=0; i < KeyLen; i++)
88601 + {
88602 + if( !isxdigit(*(arg+i)) )
88603 + return FALSE; //Not Hex value;
88604 + }
88605 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
88606 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
88607 + CipherAlg = CIPHER_WEP64;
88608 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
88609 + break;
88610 + case 13: //wep 104 Ascii type
88611 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
88612 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
88613 + CipherAlg = CIPHER_WEP128;
88614 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
88615 + break;
88616 + case 26: //wep 104 Hex type
88617 + for(i=0; i < KeyLen; i++)
88618 + {
88619 + if( !isxdigit(*(arg+i)) )
88620 + return FALSE; //Not Hex value;
88621 + }
88622 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
88623 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
88624 + CipherAlg = CIPHER_WEP128;
88625 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
88626 + break;
88627 + default: //Invalid argument
88628 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
88629 + return FALSE;
88630 + }
88631 + pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
88632 +
88633 + // Set keys (into ASIC)
88634 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88635 + ; // not support
88636 + else // Old WEP stuff
88637 + {
88638 + AsicAddSharedKeyEntry(pAdapter,
88639 + 0,
88640 + 2,
88641 + pAdapter->SharedKey[BSS0][2].CipherAlg,
88642 + pAdapter->SharedKey[BSS0][2].Key,
88643 + NULL,
88644 + NULL);
88645 + }
88646 +
88647 + return TRUE;
88648 +}
88649 +/*
88650 + ==========================================================================
88651 + Description:
88652 + Set WEP KEY4
88653 + Return:
88654 + TRUE if all parameters are OK, FALSE otherwise
88655 + ==========================================================================
88656 +*/
88657 +INT Set_Key4_Proc(
88658 + IN PRTMP_ADAPTER pAdapter,
88659 + IN PUCHAR arg)
88660 +{
88661 + int KeyLen;
88662 + int i;
88663 + UCHAR CipherAlg=CIPHER_WEP64;
88664 +
88665 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88666 + return TRUE; // do nothing
88667 +
88668 + KeyLen = strlen(arg);
88669 +
88670 + switch (KeyLen)
88671 + {
88672 + case 5: //wep 40 Ascii type
88673 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
88674 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
88675 + CipherAlg = CIPHER_WEP64;
88676 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
88677 + break;
88678 + case 10: //wep 40 Hex type
88679 + for(i=0; i < KeyLen; i++)
88680 + {
88681 + if( !isxdigit(*(arg+i)) )
88682 + return FALSE; //Not Hex value;
88683 + }
88684 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
88685 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
88686 + CipherAlg = CIPHER_WEP64;
88687 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
88688 + break;
88689 + case 13: //wep 104 Ascii type
88690 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
88691 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
88692 + CipherAlg = CIPHER_WEP128;
88693 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
88694 + break;
88695 + case 26: //wep 104 Hex type
88696 + for(i=0; i < KeyLen; i++)
88697 + {
88698 + if( !isxdigit(*(arg+i)) )
88699 + return FALSE; //Not Hex value;
88700 + }
88701 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
88702 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
88703 + CipherAlg = CIPHER_WEP128;
88704 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
88705 + break;
88706 + default: //Invalid argument
88707 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
88708 + return FALSE;
88709 + }
88710 + pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
88711 +
88712 + // Set keys (into ASIC)
88713 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
88714 + ; // not support
88715 + else // Old WEP stuff
88716 + {
88717 + AsicAddSharedKeyEntry(pAdapter,
88718 + 0,
88719 + 3,
88720 + pAdapter->SharedKey[BSS0][3].CipherAlg,
88721 + pAdapter->SharedKey[BSS0][3].Key,
88722 + NULL,
88723 + NULL);
88724 + }
88725 +
88726 + return TRUE;
88727 +}
88728 +
88729 +/*
88730 + ==========================================================================
88731 + Description:
88732 + Set WPA PSK key
88733 + Return:
88734 + TRUE if all parameters are OK, FALSE otherwise
88735 + ==========================================================================
88736 +*/
88737 +INT Set_WPAPSK_Proc(
88738 + IN PRTMP_ADAPTER pAdapter,
88739 + IN PUCHAR arg)
88740 +{
88741 + UCHAR keyMaterial[40];
88742 +
88743 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
88744 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
88745 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
88746 + )
88747 + return TRUE; // do nothing
88748 +
88749 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
88750 +
88751 + NdisZeroMemory(keyMaterial, 40);
88752 +
88753 + if ((strlen(arg) < 8) || (strlen(arg) > 64))
88754 + {
88755 + DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
88756 + return FALSE;
88757 + }
88758 +
88759 + if (strlen(arg) == 64)
88760 + {
88761 + AtoH(arg, keyMaterial, 32);
88762 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
88763 +
88764 + }
88765 + else
88766 + {
88767 + PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
88768 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
88769 + }
88770 +
88771 +
88772 +
88773 + if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
88774 + pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
88775 + {
88776 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
88777 + }
88778 + else
88779 + {
88780 + // Start STA supplicant state machine
88781 + pAdapter->StaCfg.WpaState = SS_START;
88782 + }
88783 +
88784 + return TRUE;
88785 +}
88786 +
88787 +/*
88788 + ==========================================================================
88789 + Description:
88790 + Set Power Saving mode
88791 + Return:
88792 + TRUE if all parameters are OK, FALSE otherwise
88793 + ==========================================================================
88794 +*/
88795 +INT Set_PSMode_Proc(
88796 + IN PRTMP_ADAPTER pAdapter,
88797 + IN PUCHAR arg)
88798 +{
88799 + if (pAdapter->StaCfg.BssType == BSS_INFRA)
88800 + {
88801 + if ((strcmp(arg, "Max_PSP") == 0) ||
88802 + (strcmp(arg, "max_psp") == 0) ||
88803 + (strcmp(arg, "MAX_PSP") == 0))
88804 + {
88805 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
88806 + // to exclude certain situations.
88807 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
88808 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
88809 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
88810 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
88811 + pAdapter->StaCfg.DefaultListenCount = 5;
88812 +
88813 + }
88814 + else if ((strcmp(arg, "Fast_PSP") == 0) ||
88815 + (strcmp(arg, "fast_psp") == 0) ||
88816 + (strcmp(arg, "FAST_PSP") == 0))
88817 + {
88818 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
88819 + // to exclude certain situations.
88820 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
88821 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
88822 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
88823 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
88824 + pAdapter->StaCfg.DefaultListenCount = 3;
88825 + }
88826 + else if ((strcmp(arg, "Legacy_PSP") == 0) ||
88827 + (strcmp(arg, "legacy_psp") == 0) ||
88828 + (strcmp(arg, "LEGACY_PSP") == 0))
88829 + {
88830 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
88831 + // to exclude certain situations.
88832 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
88833 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
88834 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
88835 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
88836 + pAdapter->StaCfg.DefaultListenCount = 3;
88837 + }
88838 + else
88839 + {
88840 + //Default Ndis802_11PowerModeCAM
88841 + // clear PSM bit immediately
88842 + MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
88843 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
88844 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
88845 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
88846 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
88847 + }
88848 +
88849 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
88850 + }
88851 + else
88852 + return FALSE;
88853 +
88854 +
88855 + return TRUE;
88856 +}
88857 +
88858 +#ifdef WPA_SUPPLICANT_SUPPORT
88859 +/*
88860 + ==========================================================================
88861 + Description:
88862 + Set WpaSupport flag.
88863 + Value:
88864 + 0: Driver ignore wpa_supplicant.
88865 + 1: wpa_supplicant initiates scanning and AP selection.
88866 + 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
88867 + Return:
88868 + TRUE if all parameters are OK, FALSE otherwise
88869 + ==========================================================================
88870 +*/
88871 +INT Set_Wpa_Support(
88872 + IN PRTMP_ADAPTER pAd,
88873 + IN PUCHAR arg)
88874 +{
88875 +
88876 + if ( simple_strtol(arg, 0, 10) == 0)
88877 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
88878 + else if ( simple_strtol(arg, 0, 10) == 1)
88879 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
88880 + else if ( simple_strtol(arg, 0, 10) == 2)
88881 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
88882 + else
88883 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
88884 +
88885 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
88886 +
88887 + return TRUE;
88888 +}
88889 +#endif // WPA_SUPPLICANT_SUPPORT //
88890 +
88891 +#ifdef DBG
88892 +/*
88893 + ==========================================================================
88894 + Description:
88895 + Read / Write MAC
88896 + Arguments:
88897 + pAdapter Pointer to our adapter
88898 + wrq Pointer to the ioctl argument
88899 +
88900 + Return Value:
88901 + None
88902 +
88903 + Note:
88904 + Usage:
88905 + 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
88906 + 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
88907 + ==========================================================================
88908 +*/
88909 +VOID RTMPIoctlMAC(
88910 + IN PRTMP_ADAPTER pAdapter,
88911 + IN struct iwreq *wrq)
88912 +{
88913 + CHAR *this_char;
88914 + CHAR *value;
88915 + INT j = 0, k = 0;
88916 + CHAR msg[1024];
88917 + CHAR arg[255];
88918 + ULONG macAddr = 0;
88919 + UCHAR temp[16], temp2[16];
88920 + UINT32 macValue = 0;
88921 + INT Status;
88922 +
88923 +
88924 + memset(msg, 0x00, 1024);
88925 + if (wrq->u.data.length > 1) //No parameters.
88926 + {
88927 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
88928 + sprintf(msg, "\n");
88929 +
88930 + //Parsing Read or Write
88931 + this_char = arg;
88932 + if (!*this_char)
88933 + goto next;
88934 +
88935 + if ((value = rtstrchr(this_char, '=')) != NULL)
88936 + *value++ = 0;
88937 +
88938 + if (!value || !*value)
88939 + { //Read
88940 + // Sanity check
88941 + if(strlen(this_char) > 4)
88942 + goto next;
88943 +
88944 + j = strlen(this_char);
88945 + while(j-- > 0)
88946 + {
88947 + if(this_char[j] > 'f' || this_char[j] < '0')
88948 + return;
88949 + }
88950 +
88951 + // Mac Addr
88952 + k = j = strlen(this_char);
88953 + while(j-- > 0)
88954 + {
88955 + this_char[4-k+j] = this_char[j];
88956 + }
88957 +
88958 + while(k < 4)
88959 + this_char[3-k++]='0';
88960 + this_char[4]='\0';
88961 +
88962 + if(strlen(this_char) == 4)
88963 + {
88964 + AtoH(this_char, temp, 2);
88965 + macAddr = *temp*256 + temp[1];
88966 + if (macAddr < 0xFFFF)
88967 + {
88968 + RTMP_IO_READ32(pAdapter, macAddr, &macValue);
88969 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
88970 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
88971 + }
88972 + else
88973 + {//Invalid parametes, so default printk all bbp
88974 + goto next;
88975 + }
88976 + }
88977 + }
88978 + else
88979 + { //Write
88980 + memcpy(&temp2, value, strlen(value));
88981 + temp2[strlen(value)] = '\0';
88982 +
88983 + // Sanity check
88984 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
88985 + goto next;
88986 +
88987 + j = strlen(this_char);
88988 + while(j-- > 0)
88989 + {
88990 + if(this_char[j] > 'f' || this_char[j] < '0')
88991 + return;
88992 + }
88993 +
88994 + j = strlen(temp2);
88995 + while(j-- > 0)
88996 + {
88997 + if(temp2[j] > 'f' || temp2[j] < '0')
88998 + return;
88999 + }
89000 +
89001 + //MAC Addr
89002 + k = j = strlen(this_char);
89003 + while(j-- > 0)
89004 + {
89005 + this_char[4-k+j] = this_char[j];
89006 + }
89007 +
89008 + while(k < 4)
89009 + this_char[3-k++]='0';
89010 + this_char[4]='\0';
89011 +
89012 + //MAC value
89013 + k = j = strlen(temp2);
89014 + while(j-- > 0)
89015 + {
89016 + temp2[8-k+j] = temp2[j];
89017 + }
89018 +
89019 + while(k < 8)
89020 + temp2[7-k++]='0';
89021 + temp2[8]='\0';
89022 +
89023 + {
89024 + AtoH(this_char, temp, 2);
89025 + macAddr = *temp*256 + temp[1];
89026 +
89027 + AtoH(temp2, temp, 4);
89028 + macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
89029 +
89030 + // debug mode
89031 + if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
89032 + {
89033 + // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
89034 + if (macValue & 0x000000ff)
89035 + {
89036 + pAdapter->BbpTuning.bEnable = TRUE;
89037 + DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
89038 + }
89039 + else
89040 + {
89041 + UCHAR R66;
89042 + pAdapter->BbpTuning.bEnable = FALSE;
89043 + R66 = 0x26 + GET_LNA_GAIN(pAdapter);
89044 +#ifdef RALINK_ATE
89045 + if (ATE_ON(pAdapter))
89046 + {
89047 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
89048 + }
89049 + else
89050 +#endif // RALINK_ATE //
89051 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
89052 + DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
89053 + }
89054 + return;
89055 + }
89056 +
89057 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
89058 +
89059 + RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
89060 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
89061 + }
89062 + }
89063 + }
89064 +next:
89065 + if(strlen(msg) == 1)
89066 + sprintf(msg+strlen(msg), "===>Error command format!");
89067 +
89068 + // Copy the information into the user buffer
89069 + wrq->u.data.length = strlen(msg);
89070 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
89071 +
89072 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
89073 +}
89074 +
89075 +/*
89076 + ==========================================================================
89077 + Description:
89078 + Read / Write E2PROM
89079 + Arguments:
89080 + pAdapter Pointer to our adapter
89081 + wrq Pointer to the ioctl argument
89082 +
89083 + Return Value:
89084 + None
89085 +
89086 + Note:
89087 + Usage:
89088 + 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
89089 + 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
89090 + ==========================================================================
89091 +*/
89092 +VOID RTMPIoctlE2PROM(
89093 + IN PRTMP_ADAPTER pAdapter,
89094 + IN struct iwreq *wrq)
89095 +{
89096 + CHAR *this_char;
89097 + CHAR *value;
89098 + INT j = 0, k = 0;
89099 + CHAR msg[1024];
89100 + CHAR arg[255];
89101 + USHORT eepAddr = 0;
89102 + UCHAR temp[16], temp2[16];
89103 + USHORT eepValue;
89104 + int Status;
89105 +
89106 +
89107 + memset(msg, 0x00, 1024);
89108 + if (wrq->u.data.length > 1) //No parameters.
89109 + {
89110 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
89111 + sprintf(msg, "\n");
89112 +
89113 + //Parsing Read or Write
89114 + this_char = arg;
89115 +
89116 +
89117 + if (!*this_char)
89118 + goto next;
89119 +
89120 + if ((value = rtstrchr(this_char, '=')) != NULL)
89121 + *value++ = 0;
89122 +
89123 + if (!value || !*value)
89124 + { //Read
89125 +
89126 + // Sanity check
89127 + if(strlen(this_char) > 4)
89128 + goto next;
89129 +
89130 + j = strlen(this_char);
89131 + while(j-- > 0)
89132 + {
89133 + if(this_char[j] > 'f' || this_char[j] < '0')
89134 + return;
89135 + }
89136 +
89137 + // E2PROM addr
89138 + k = j = strlen(this_char);
89139 + while(j-- > 0)
89140 + {
89141 + this_char[4-k+j] = this_char[j];
89142 + }
89143 +
89144 + while(k < 4)
89145 + this_char[3-k++]='0';
89146 + this_char[4]='\0';
89147 +
89148 + if(strlen(this_char) == 4)
89149 + {
89150 + AtoH(this_char, temp, 2);
89151 + eepAddr = *temp*256 + temp[1];
89152 + if (eepAddr < 0xFFFF)
89153 + {
89154 + RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
89155 + sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
89156 + }
89157 + else
89158 + {//Invalid parametes, so default printk all bbp
89159 + goto next;
89160 + }
89161 + }
89162 + }
89163 + else
89164 + { //Write
89165 + memcpy(&temp2, value, strlen(value));
89166 + temp2[strlen(value)] = '\0';
89167 +
89168 + // Sanity check
89169 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
89170 + goto next;
89171 +
89172 + j = strlen(this_char);
89173 + while(j-- > 0)
89174 + {
89175 + if(this_char[j] > 'f' || this_char[j] < '0')
89176 + return;
89177 + }
89178 + j = strlen(temp2);
89179 + while(j-- > 0)
89180 + {
89181 + if(temp2[j] > 'f' || temp2[j] < '0')
89182 + return;
89183 + }
89184 +
89185 + //MAC Addr
89186 + k = j = strlen(this_char);
89187 + while(j-- > 0)
89188 + {
89189 + this_char[4-k+j] = this_char[j];
89190 + }
89191 +
89192 + while(k < 4)
89193 + this_char[3-k++]='0';
89194 + this_char[4]='\0';
89195 +
89196 + //MAC value
89197 + k = j = strlen(temp2);
89198 + while(j-- > 0)
89199 + {
89200 + temp2[4-k+j] = temp2[j];
89201 + }
89202 +
89203 + while(k < 4)
89204 + temp2[3-k++]='0';
89205 + temp2[4]='\0';
89206 +
89207 + AtoH(this_char, temp, 2);
89208 + eepAddr = *temp*256 + temp[1];
89209 +
89210 + AtoH(temp2, temp, 2);
89211 + eepValue = *temp*256 + temp[1];
89212 +
89213 + RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
89214 + sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
89215 + }
89216 + }
89217 +next:
89218 + if(strlen(msg) == 1)
89219 + sprintf(msg+strlen(msg), "===>Error command format!");
89220 +
89221 +
89222 + // Copy the information into the user buffer
89223 + wrq->u.data.length = strlen(msg);
89224 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
89225 +
89226 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
89227 +}
89228 +#endif // DBG //
89229 +
89230 +
89231 +
89232 +
89233 +INT Set_TGnWifiTest_Proc(
89234 + IN PRTMP_ADAPTER pAd,
89235 + IN PUCHAR arg)
89236 +{
89237 + if (simple_strtol(arg, 0, 10) == 0)
89238 + pAd->StaCfg.bTGnWifiTest = FALSE;
89239 + else
89240 + pAd->StaCfg.bTGnWifiTest = TRUE;
89241 +
89242 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
89243 + return TRUE;
89244 +}
89245 +
89246 +INT Set_LongRetryLimit_Proc(
89247 + IN PRTMP_ADAPTER pAdapter,
89248 + IN PUCHAR arg)
89249 +{
89250 + TX_RTY_CFG_STRUC tx_rty_cfg;
89251 + UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
89252 +
89253 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
89254 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
89255 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
89256 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
89257 + return TRUE;
89258 +}
89259 +
89260 +INT Set_ShortRetryLimit_Proc(
89261 + IN PRTMP_ADAPTER pAdapter,
89262 + IN PUCHAR arg)
89263 +{
89264 + TX_RTY_CFG_STRUC tx_rty_cfg;
89265 + UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
89266 +
89267 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
89268 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
89269 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
89270 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
89271 + return TRUE;
89272 +}
89273 +
89274 +#ifdef EXT_BUILD_CHANNEL_LIST
89275 +INT Set_Ieee80211dClientMode_Proc(
89276 + IN PRTMP_ADAPTER pAdapter,
89277 + IN PUCHAR arg)
89278 +{
89279 + if (simple_strtol(arg, 0, 10) == 0)
89280 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
89281 + else if (simple_strtol(arg, 0, 10) == 1)
89282 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
89283 + else if (simple_strtol(arg, 0, 10) == 2)
89284 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
89285 + else
89286 + return FALSE;
89287 +
89288 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
89289 + return TRUE;
89290 +}
89291 +#endif // EXT_BUILD_CHANNEL_LIST //
89292 +
89293 +#ifdef CARRIER_DETECTION_SUPPORT
89294 +INT Set_CarrierDetect_Proc(
89295 + IN PRTMP_ADAPTER pAd,
89296 + IN PUCHAR arg)
89297 +{
89298 + if (simple_strtol(arg, 0, 10) == 0)
89299 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
89300 + else
89301 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
89302 +
89303 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
89304 + return TRUE;
89305 +}
89306 +#endif // CARRIER_DETECTION_SUPPORT //
89307 +
89308 +
89309 +INT Show_Adhoc_MacTable_Proc(
89310 + IN PRTMP_ADAPTER pAd,
89311 + IN PCHAR extra)
89312 +{
89313 + INT i;
89314 +
89315 + sprintf(extra, "\n");
89316 +
89317 +#ifdef DOT11_N_SUPPORT
89318 + sprintf(extra, "%sHT Operating Mode : %d\n", extra, pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
89319 +#endif // DOT11_N_SUPPORT //
89320 +
89321 + sprintf(extra, "%s\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n", extra,
89322 + "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
89323 +
89324 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
89325 + {
89326 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
89327 +
89328 + if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
89329 + break;
89330 + if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
89331 + {
89332 + sprintf(extra, "%s%02X:%02X:%02X:%02X:%02X:%02X ", extra,
89333 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
89334 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
89335 + sprintf(extra, "%s%-4d", extra, (int)pEntry->Aid);
89336 + sprintf(extra, "%s%-4d", extra, (int)pEntry->apidx);
89337 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi0);
89338 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi1);
89339 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi2);
89340 + sprintf(extra, "%s%-10s", extra, GetPhyMode(pEntry->HTPhyMode.field.MODE));
89341 + sprintf(extra, "%s%-6s", extra, GetBW(pEntry->HTPhyMode.field.BW));
89342 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.MCS);
89343 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.ShortGI);
89344 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.STBC);
89345 + sprintf(extra, "%s%-10d, %d, %d%%\n", extra, pEntry->DebugFIFOCount, pEntry->DebugTxCount,
89346 + (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
89347 + sprintf(extra, "%s\n", extra);
89348 + }
89349 + }
89350 +
89351 + return TRUE;
89352 +}
89353 +
89354 +
89355 --- /dev/null
89356 +++ b/drivers/staging/rt2870/sta_ioctl.c.patch
89357 @@ -0,0 +1,18 @@
89358 +--- sta_ioctl.c 2008-09-19 14:37:52.000000000 +0800
89359 ++++ sta_ioctl.c.fc9 2008-09-19 14:38:20.000000000 +0800
89360 +@@ -49,15 +49,9 @@
89361 +
89362 + #define GROUP_KEY_NO 4
89363 +
89364 +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
89365 + #define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_A, _B, _C, _D, _E)
89366 + #define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_A, _B, _C, _D, _E)
89367 + #define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_A, _B, _C, _D, _E, _F)
89368 +-#else
89369 +-#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_B, _C, _D, _E)
89370 +-#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_B, _C, _D, _E)
89371 +-#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_B, _C, _D, _E, _F)
89372 +-#endif
89373 +
89374 + extern UCHAR CipherWpa2Template[];
89375 + extern UCHAR CipherWpaPskTkip[];
89376 --- /dev/null
89377 +++ b/drivers/staging/rt2870/sta/rtmp_data.c
89378 @@ -0,0 +1,2619 @@
89379 +/*
89380 + *************************************************************************
89381 + * Ralink Tech Inc.
89382 + * 5F., No.36, Taiyuan St., Jhubei City,
89383 + * Hsinchu County 302,
89384 + * Taiwan, R.O.C.
89385 + *
89386 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
89387 + *
89388 + * This program is free software; you can redistribute it and/or modify *
89389 + * it under the terms of the GNU General Public License as published by *
89390 + * the Free Software Foundation; either version 2 of the License, or *
89391 + * (at your option) any later version. *
89392 + * *
89393 + * This program is distributed in the hope that it will be useful, *
89394 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
89395 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
89396 + * GNU General Public License for more details. *
89397 + * *
89398 + * You should have received a copy of the GNU General Public License *
89399 + * along with this program; if not, write to the *
89400 + * Free Software Foundation, Inc., *
89401 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
89402 + * *
89403 + *************************************************************************
89404 +
89405 + Module Name:
89406 + rtmp_data.c
89407 +
89408 + Abstract:
89409 + Data path subroutines
89410 +
89411 + Revision History:
89412 + Who When What
89413 + -------- ---------- ----------------------------------------------
89414 + John Aug/17/04 major modification for RT2561/2661
89415 + Jan Lee Mar/17/06 major modification for RT2860 New Ring Design
89416 +*/
89417 +#include "../rt_config.h"
89418 +
89419 +
89420 +VOID STARxEAPOLFrameIndicate(
89421 + IN PRTMP_ADAPTER pAd,
89422 + IN MAC_TABLE_ENTRY *pEntry,
89423 + IN RX_BLK *pRxBlk,
89424 + IN UCHAR FromWhichBSSID)
89425 +{
89426 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
89427 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
89428 + UCHAR *pTmpBuf;
89429 +
89430 +#ifdef WPA_SUPPLICANT_SUPPORT
89431 + if (pAd->StaCfg.WpaSupplicantUP)
89432 + {
89433 + // All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon)
89434 + // TBD : process fragmented EAPol frames
89435 + {
89436 + // In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable
89437 + if ( pAd->StaCfg.IEEE8021X == TRUE &&
89438 + (EAP_CODE_SUCCESS == WpaCheckEapCode(pAd, pRxBlk->pData, pRxBlk->DataSize, LENGTH_802_1_H)))
89439 + {
89440 + PUCHAR Key;
89441 + UCHAR CipherAlg;
89442 + int idx = 0;
89443 +
89444 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("Receive EAP-SUCCESS Packet\n"));
89445 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
89446 + STA_PORT_SECURED(pAd);
89447 +
89448 + if (pAd->StaCfg.IEEE8021x_required_keys == FALSE)
89449 + {
89450 + idx = pAd->StaCfg.DesireSharedKeyId;
89451 + CipherAlg = pAd->StaCfg.DesireSharedKey[idx].CipherAlg;
89452 + Key = pAd->StaCfg.DesireSharedKey[idx].Key;
89453 +
89454 + if (pAd->StaCfg.DesireSharedKey[idx].KeyLen > 0)
89455 + {
89456 +#ifdef RT2870
89457 + union
89458 + {
89459 + char buf[sizeof(NDIS_802_11_WEP)+MAX_LEN_OF_KEY- 1];
89460 + NDIS_802_11_WEP keyinfo;
89461 + } WepKey;
89462 + int len;
89463 +
89464 +
89465 + NdisZeroMemory(&WepKey, sizeof(WepKey));
89466 + len =pAd->StaCfg.DesireSharedKey[idx].KeyLen;
89467 +
89468 + NdisMoveMemory(WepKey.keyinfo.KeyMaterial,
89469 + pAd->StaCfg.DesireSharedKey[idx].Key,
89470 + pAd->StaCfg.DesireSharedKey[idx].KeyLen);
89471 +
89472 + WepKey.keyinfo.KeyIndex = 0x80000000 + idx;
89473 + WepKey.keyinfo.KeyLength = len;
89474 + pAd->SharedKey[BSS0][idx].KeyLen =(UCHAR) (len <= 5 ? 5 : 13);
89475 +
89476 + pAd->IndicateMediaState = NdisMediaStateConnected;
89477 + pAd->ExtraInfo = GENERAL_LINK_UP;
89478 + // need to enqueue cmd to thread
89479 + RTUSBEnqueueCmdFromNdis(pAd, OID_802_11_ADD_WEP, TRUE, &WepKey, sizeof(WepKey.keyinfo) + len - 1);
89480 +#endif // RT2870 //
89481 + // For Preventing ShardKey Table is cleared by remove key procedure.
89482 + pAd->SharedKey[BSS0][idx].CipherAlg = CipherAlg;
89483 + pAd->SharedKey[BSS0][idx].KeyLen = pAd->StaCfg.DesireSharedKey[idx].KeyLen;
89484 + NdisMoveMemory(pAd->SharedKey[BSS0][idx].Key,
89485 + pAd->StaCfg.DesireSharedKey[idx].Key,
89486 + pAd->StaCfg.DesireSharedKey[idx].KeyLen);
89487 + }
89488 + }
89489 + }
89490 +
89491 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
89492 + return;
89493 + }
89494 + }
89495 + else
89496 +#endif // WPA_SUPPLICANT_SUPPORT //
89497 + {
89498 + // Special DATA frame that has to pass to MLME
89499 + // 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process
89500 + // 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process
89501 + {
89502 + pTmpBuf = pRxBlk->pData - LENGTH_802_11;
89503 + NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11);
89504 + REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pTmpBuf, pRxBlk->DataSize + LENGTH_802_11, pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
89505 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! report EAPOL/AIRONET DATA to MLME (len=%d) !!!\n", pRxBlk->DataSize));
89506 + }
89507 + }
89508 +
89509 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
89510 + return;
89511 +
89512 +}
89513 +
89514 +VOID STARxDataFrameAnnounce(
89515 + IN PRTMP_ADAPTER pAd,
89516 + IN MAC_TABLE_ENTRY *pEntry,
89517 + IN RX_BLK *pRxBlk,
89518 + IN UCHAR FromWhichBSSID)
89519 +{
89520 +
89521 + // non-EAP frame
89522 + if (!RTMPCheckWPAframe(pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID))
89523 + {
89524 + {
89525 + // drop all non-EAP DATA frame before
89526 + // this client's Port-Access-Control is secured
89527 + if (pRxBlk->pHeader->FC.Wep)
89528 + {
89529 + // unsupported cipher suite
89530 + if (pAd->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
89531 + {
89532 + // release packet
89533 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
89534 + return;
89535 + }
89536 + }
89537 + else
89538 + {
89539 + // encryption in-use but receive a non-EAPOL clear text frame, drop it
89540 + if ((pAd->StaCfg.WepStatus != Ndis802_11EncryptionDisabled) &&
89541 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
89542 + {
89543 + // release packet
89544 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
89545 + return;
89546 + }
89547 + }
89548 + }
89549 + RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP);
89550 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK))
89551 + {
89552 + // Normal legacy, AMPDU or AMSDU
89553 + CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, FromWhichBSSID);
89554 +
89555 + }
89556 + else
89557 + {
89558 + // ARALINK
89559 + CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
89560 + }
89561 +#ifdef QOS_DLS_SUPPORT
89562 + RX_BLK_CLEAR_FLAG(pRxBlk, fRX_DLS);
89563 +#endif // QOS_DLS_SUPPORT //
89564 + }
89565 + else
89566 + {
89567 + RX_BLK_SET_FLAG(pRxBlk, fRX_EAP);
89568 +#ifdef DOT11_N_SUPPORT
89569 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))
89570 + {
89571 + Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
89572 + }
89573 + else
89574 +#endif // DOT11_N_SUPPORT //
89575 + {
89576 + // Determin the destination of the EAP frame
89577 + // to WPA state machine or upper layer
89578 + STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
89579 + }
89580 + }
89581 +}
89582 +
89583 +
89584 +// For TKIP frame, calculate the MIC value
89585 +BOOLEAN STACheckTkipMICValue(
89586 + IN PRTMP_ADAPTER pAd,
89587 + IN MAC_TABLE_ENTRY *pEntry,
89588 + IN RX_BLK *pRxBlk)
89589 +{
89590 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
89591 + UCHAR *pData = pRxBlk->pData;
89592 + USHORT DataSize = pRxBlk->DataSize;
89593 + UCHAR UserPriority = pRxBlk->UserPriority;
89594 + PCIPHER_KEY pWpaKey;
89595 + UCHAR *pDA, *pSA;
89596 +
89597 + pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex];
89598 +
89599 + pDA = pHeader->Addr1;
89600 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA))
89601 + {
89602 + pSA = pHeader->Addr3;
89603 + }
89604 + else
89605 + {
89606 + pSA = pHeader->Addr2;
89607 + }
89608 +
89609 + if (RTMPTkipCompareMICValue(pAd,
89610 + pData,
89611 + pDA,
89612 + pSA,
89613 + pWpaKey->RxMic,
89614 + UserPriority,
89615 + DataSize) == FALSE)
89616 + {
89617 + DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error 2\n"));
89618 +
89619 +#ifdef WPA_SUPPLICANT_SUPPORT
89620 + if (pAd->StaCfg.WpaSupplicantUP)
89621 + {
89622 + WpaSendMicFailureToWpaSupplicant(pAd, (pWpaKey->Type == PAIRWISEKEY) ? TRUE : FALSE);
89623 + }
89624 + else
89625 +#endif // WPA_SUPPLICANT_SUPPORT //
89626 + {
89627 + RTMPReportMicError(pAd, pWpaKey);
89628 + }
89629 +
89630 + // release packet
89631 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
89632 + return FALSE;
89633 + }
89634 +
89635 + return TRUE;
89636 +}
89637 +
89638 +
89639 +//
89640 +// All Rx routines use RX_BLK structure to hande rx events
89641 +// It is very important to build pRxBlk attributes
89642 +// 1. pHeader pointer to 802.11 Header
89643 +// 2. pData pointer to payload including LLC (just skip Header)
89644 +// 3. set payload size including LLC to DataSize
89645 +// 4. set some flags with RX_BLK_SET_FLAG()
89646 +//
89647 +VOID STAHandleRxDataFrame(
89648 + IN PRTMP_ADAPTER pAd,
89649 + IN RX_BLK *pRxBlk)
89650 +{
89651 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
89652 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
89653 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
89654 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
89655 + BOOLEAN bFragment = FALSE;
89656 + MAC_TABLE_ENTRY *pEntry = NULL;
89657 + UCHAR FromWhichBSSID = BSS0;
89658 + UCHAR UserPriority = 0;
89659 +
89660 + {
89661 + // before LINK UP, all DATA frames are rejected
89662 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
89663 + {
89664 + // release packet
89665 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89666 + return;
89667 + }
89668 +
89669 +#ifdef QOS_DLS_SUPPORT
89670 + //if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
89671 + if (RTMPRcvFrameDLSCheck(pAd, pHeader, pRxWI->MPDUtotalByteCount, pRxD))
89672 + {
89673 + return;
89674 + }
89675 +#endif // QOS_DLS_SUPPORT //
89676 +
89677 + // Drop not my BSS frames
89678 + if (pRxD->MyBss == 0)
89679 + {
89680 + {
89681 + // release packet
89682 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89683 + return;
89684 + }
89685 + }
89686 +
89687 + pAd->RalinkCounters.RxCountSinceLastNULL++;
89688 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable && (pHeader->FC.SubType & 0x08))
89689 + {
89690 + UCHAR *pData;
89691 + DBGPRINT(RT_DEBUG_TRACE,("bAPSDCapable\n"));
89692 +
89693 + // Qos bit 4
89694 + pData = (PUCHAR)pHeader + LENGTH_802_11;
89695 + if ((*pData >> 4) & 0x01)
89696 + {
89697 + DBGPRINT(RT_DEBUG_TRACE,("RxDone- Rcv EOSP frame, driver may fall into sleep\n"));
89698 + pAd->CommonCfg.bInServicePeriod = FALSE;
89699 +
89700 + // Force driver to fall into sleep mode when rcv EOSP frame
89701 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
89702 + {
89703 + USHORT TbttNumToNextWakeUp;
89704 + USHORT NextDtim = pAd->StaCfg.DtimPeriod;
89705 + ULONG Now;
89706 +
89707 + NdisGetSystemUpTime(&Now);
89708 + NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod;
89709 +
89710 + TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
89711 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
89712 + TbttNumToNextWakeUp = NextDtim;
89713 +
89714 + MlmeSetPsmBit(pAd, PWR_SAVE);
89715 + // if WMM-APSD is failed, try to disable following line
89716 + AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
89717 + }
89718 + }
89719 +
89720 + if ((pHeader->FC.MoreData) && (pAd->CommonCfg.bInServicePeriod))
89721 + {
89722 + DBGPRINT(RT_DEBUG_TRACE,("Sending another trigger frame when More Data bit is set to 1\n"));
89723 + }
89724 + }
89725 +
89726 + // Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame
89727 + if ((pHeader->FC.SubType & 0x04)) // bit 2 : no DATA
89728 + {
89729 + // release packet
89730 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89731 + return;
89732 + }
89733 +
89734 + // Drop not my BSS frame (we can not only check the MyBss bit in RxD)
89735 +#ifdef QOS_DLS_SUPPORT
89736 + if (!pAd->CommonCfg.bDLSCapable)
89737 + {
89738 +#endif // QOS_DLS_SUPPORT //
89739 + if (INFRA_ON(pAd))
89740 + {
89741 + // Infrastructure mode, check address 2 for BSSID
89742 + if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6))
89743 + {
89744 + // Receive frame not my BSSID
89745 + // release packet
89746 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89747 + return;
89748 + }
89749 + }
89750 + else // Ad-Hoc mode or Not associated
89751 + {
89752 + // Ad-Hoc mode, check address 3 for BSSID
89753 + if (!RTMPEqualMemory(&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6))
89754 + {
89755 + // Receive frame not my BSSID
89756 + // release packet
89757 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89758 + return;
89759 + }
89760 + }
89761 +#ifdef QOS_DLS_SUPPORT
89762 + }
89763 +#endif // QOS_DLS_SUPPORT //
89764 +
89765 + //
89766 + // find pEntry
89767 + //
89768 + if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)
89769 + {
89770 + pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
89771 + }
89772 + else
89773 + {
89774 + // 1. release packet if infra mode
89775 + // 2. new a pEntry if ad-hoc mode
89776 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89777 + return;
89778 + }
89779 +
89780 + // infra or ad-hoc
89781 + if (INFRA_ON(pAd))
89782 + {
89783 + RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);
89784 +#ifdef QOS_DLS_SUPPORT
89785 + if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
89786 + RX_BLK_SET_FLAG(pRxBlk, fRX_DLS);
89787 + else
89788 +#endif // QOS_DLS_SUPPORT //
89789 + ASSERT(pRxWI->WirelessCliID == BSSID_WCID);
89790 + }
89791 +
89792 + // check Atheros Client
89793 + if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) && (pHeader->FC.Retry ))
89794 + {
89795 + pEntry->bIAmBadAtheros = TRUE;
89796 + pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE;
89797 + pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE;
89798 + if (!STA_AES_ON(pAd))
89799 + {
89800 + AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, FALSE);
89801 + }
89802 + }
89803 + }
89804 +
89805 + pRxBlk->pData = (UCHAR *)pHeader;
89806 +
89807 + //
89808 + // update RxBlk->pData, DataSize
89809 + // 802.11 Header, QOS, HTC, Hw Padding
89810 + //
89811 +
89812 + // 1. skip 802.11 HEADER
89813 + {
89814 + pRxBlk->pData += LENGTH_802_11;
89815 + pRxBlk->DataSize -= LENGTH_802_11;
89816 + }
89817 +
89818 + // 2. QOS
89819 + if (pHeader->FC.SubType & 0x08)
89820 + {
89821 + RX_BLK_SET_FLAG(pRxBlk, fRX_QOS);
89822 + UserPriority = *(pRxBlk->pData) & 0x0f;
89823 + // bit 7 in QoS Control field signals the HT A-MSDU format
89824 + if ((*pRxBlk->pData) & 0x80)
89825 + {
89826 + RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU);
89827 + }
89828 +
89829 + // skip QOS contorl field
89830 + pRxBlk->pData += 2;
89831 + pRxBlk->DataSize -=2;
89832 + }
89833 + pRxBlk->UserPriority = UserPriority;
89834 +
89835 + // 3. Order bit: A-Ralink or HTC+
89836 + if (pHeader->FC.Order)
89837 + {
89838 +#ifdef AGGREGATION_SUPPORT
89839 + if ((pRxWI->PHYMODE <= MODE_OFDM) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)))
89840 + {
89841 + RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK);
89842 + }
89843 + else
89844 +#endif
89845 + {
89846 +#ifdef DOT11_N_SUPPORT
89847 + RX_BLK_SET_FLAG(pRxBlk, fRX_HTC);
89848 + // skip HTC contorl field
89849 + pRxBlk->pData += 4;
89850 + pRxBlk->DataSize -= 4;
89851 +#endif // DOT11_N_SUPPORT //
89852 + }
89853 + }
89854 +
89855 + // 4. skip HW padding
89856 + if (pRxD->L2PAD)
89857 + {
89858 + // just move pData pointer
89859 + // because DataSize excluding HW padding
89860 + RX_BLK_SET_FLAG(pRxBlk, fRX_PAD);
89861 + pRxBlk->pData += 2;
89862 + }
89863 +
89864 +#ifdef DOT11_N_SUPPORT
89865 + if (pRxD->BA)
89866 + {
89867 + RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU);
89868 + }
89869 +#endif // DOT11_N_SUPPORT //
89870 +
89871 +
89872 + //
89873 + // Case I Process Broadcast & Multicast data frame
89874 + //
89875 + if (pRxD->Bcast || pRxD->Mcast)
89876 + {
89877 + INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);
89878 +
89879 + // Drop Mcast/Bcast frame with fragment bit on
89880 + if (pHeader->FC.MoreFrag)
89881 + {
89882 + // release packet
89883 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89884 + return;
89885 + }
89886 +
89887 + // Filter out Bcast frame which AP relayed for us
89888 + if (pHeader->FC.FrDs && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress))
89889 + {
89890 + // release packet
89891 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89892 + return;
89893 + }
89894 +
89895 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
89896 + return;
89897 + }
89898 + else if (pRxD->U2M)
89899 + {
89900 + pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
89901 +
89902 +
89903 +#ifdef QOS_DLS_SUPPORT
89904 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_DLS))
89905 + {
89906 + MAC_TABLE_ENTRY *pDlsEntry = NULL;
89907 +
89908 + pDlsEntry = DlsEntryTableLookupByWcid(pAd, pRxWI->WirelessCliID, pHeader->Addr2, TRUE);
89909 + if(pDlsEntry)
89910 + Update_Rssi_Sample(pAd, &pDlsEntry->RssiSample, pRxWI);
89911 + }
89912 + else
89913 +#endif // QOS_DLS_SUPPORT //
89914 + if (ADHOC_ON(pAd))
89915 + {
89916 + pEntry = MacTableLookup(pAd, pHeader->Addr2);
89917 + if (pEntry)
89918 + Update_Rssi_Sample(pAd, &pEntry->RssiSample, pRxWI);
89919 + }
89920 +
89921 +
89922 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
89923 +
89924 + pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
89925 + pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
89926 +
89927 + pAd->RalinkCounters.OneSecRxOkDataCnt++;
89928 +
89929 +
89930 + if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0)))
89931 + {
89932 + // re-assemble the fragmented packets
89933 + // return complete frame (pRxPacket) or NULL
89934 + bFragment = TRUE;
89935 + pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk);
89936 + }
89937 +
89938 + if (pRxPacket)
89939 + {
89940 + pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
89941 +
89942 + // process complete frame
89943 + if (bFragment && (pRxD->Decrypted) && (pEntry->WepStatus == Ndis802_11Encryption2Enabled))
89944 + {
89945 + // Minus MIC length
89946 + pRxBlk->DataSize -= 8;
89947 +
89948 + // For TKIP frame, calculate the MIC value
89949 + if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == FALSE)
89950 + {
89951 + return;
89952 + }
89953 + }
89954 +
89955 + STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, FromWhichBSSID);
89956 + return;
89957 + }
89958 + else
89959 + {
89960 + // just return
89961 + // because RTMPDeFragmentDataFrame() will release rx packet,
89962 + // if packet is fragmented
89963 + return;
89964 + }
89965 + }
89966 +
89967 + ASSERT(0);
89968 + // release packet
89969 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
89970 +}
89971 +
89972 +VOID STAHandleRxMgmtFrame(
89973 + IN PRTMP_ADAPTER pAd,
89974 + IN RX_BLK *pRxBlk)
89975 +{
89976 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
89977 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
89978 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
89979 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
89980 +
89981 + do
89982 + {
89983 +
89984 + // We should collect RSSI not only U2M data but also my beacon
89985 + if ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2)))
89986 + {
89987 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
89988 +
89989 + pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
89990 + pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
89991 + }
89992 +
89993 + // First check the size, it MUST not exceed the mlme queue size
89994 + if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE)
89995 + {
89996 + DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount));
89997 + break;
89998 + }
89999 +
90000 + REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, pRxWI->MPDUtotalByteCount,
90001 + pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
90002 + } while (FALSE);
90003 +
90004 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
90005 +}
90006 +
90007 +VOID STAHandleRxControlFrame(
90008 + IN PRTMP_ADAPTER pAd,
90009 + IN RX_BLK *pRxBlk)
90010 +{
90011 +#ifdef DOT11_N_SUPPORT
90012 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
90013 +#endif // DOT11_N_SUPPORT //
90014 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
90015 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
90016 +
90017 + switch (pHeader->FC.SubType)
90018 + {
90019 + case SUBTYPE_BLOCK_ACK_REQ:
90020 +#ifdef DOT11_N_SUPPORT
90021 + {
90022 + CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, (pRxWI->MPDUtotalByteCount), (PFRAME_BA_REQ)pHeader);
90023 + }
90024 + break;
90025 +#endif // DOT11_N_SUPPORT //
90026 + case SUBTYPE_BLOCK_ACK:
90027 + case SUBTYPE_ACK:
90028 + default:
90029 + break;
90030 + }
90031 +
90032 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90033 +}
90034 +
90035 +
90036 +/*
90037 + ========================================================================
90038 +
90039 + Routine Description:
90040 + Process RxDone interrupt, running in DPC level
90041 +
90042 + Arguments:
90043 + pAd Pointer to our adapter
90044 +
90045 + Return Value:
90046 + None
90047 +
90048 + IRQL = DISPATCH_LEVEL
90049 +
90050 + Note:
90051 + This routine has to maintain Rx ring read pointer.
90052 + Need to consider QOS DATA format when converting to 802.3
90053 + ========================================================================
90054 +*/
90055 +BOOLEAN STARxDoneInterruptHandle(
90056 + IN PRTMP_ADAPTER pAd,
90057 + IN BOOLEAN argc)
90058 +{
90059 + NDIS_STATUS Status;
90060 + UINT32 RxProcessed, RxPending;
90061 + BOOLEAN bReschedule = FALSE;
90062 + RT28XX_RXD_STRUC *pRxD;
90063 + UCHAR *pData;
90064 + PRXWI_STRUC pRxWI;
90065 + PNDIS_PACKET pRxPacket;
90066 + PHEADER_802_11 pHeader;
90067 + RX_BLK RxCell;
90068 +
90069 + RxProcessed = RxPending = 0;
90070 +
90071 + // process whole rx ring
90072 + while (1)
90073 + {
90074 +
90075 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF |
90076 + fRTMP_ADAPTER_RESET_IN_PROGRESS |
90077 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
90078 + fRTMP_ADAPTER_NIC_NOT_EXIST) ||
90079 + !RTMP_TEST_FLAG(pAd,fRTMP_ADAPTER_START_UP))
90080 + {
90081 + break;
90082 + }
90083 +
90084 +
90085 + RxProcessed ++; // test
90086 +
90087 + // 1. allocate a new data packet into rx ring to replace received packet
90088 + // then processing the received packet
90089 + // 2. the callee must take charge of release of packet
90090 + // 3. As far as driver is concerned ,
90091 + // the rx packet must
90092 + // a. be indicated to upper layer or
90093 + // b. be released if it is discarded
90094 + pRxPacket = GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, &RxPending);
90095 + if (pRxPacket == NULL)
90096 + {
90097 + // no more packet to process
90098 + break;
90099 + }
90100 +
90101 + // get rx ring descriptor
90102 + pRxD = &(RxCell.RxD);
90103 + // get rx data buffer
90104 + pData = GET_OS_PKT_DATAPTR(pRxPacket);
90105 + pRxWI = (PRXWI_STRUC) pData;
90106 + pHeader = (PHEADER_802_11) (pData+RXWI_SIZE) ;
90107 +
90108 +#ifdef RT_BIG_ENDIAN
90109 + RTMPFrameEndianChange(pAd, (PUCHAR)pHeader, DIR_READ, TRUE);
90110 + RTMPWIEndianChange((PUCHAR)pRxWI, TYPE_RXWI);
90111 +#endif
90112 +
90113 + // build RxCell
90114 + RxCell.pRxWI = pRxWI;
90115 + RxCell.pHeader = pHeader;
90116 + RxCell.pRxPacket = pRxPacket;
90117 + RxCell.pData = (UCHAR *) pHeader;
90118 + RxCell.DataSize = pRxWI->MPDUtotalByteCount;
90119 + RxCell.Flags = 0;
90120 +
90121 + // Increase Total receive byte counter after real data received no mater any error or not
90122 + pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount;
90123 + pAd->RalinkCounters.RxCount ++;
90124 +
90125 + INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);
90126 +
90127 + if (pRxWI->MPDUtotalByteCount < 14)
90128 + Status = NDIS_STATUS_FAILURE;
90129 +
90130 + if (MONITOR_ON(pAd))
90131 + {
90132 + send_monitor_packets(pAd, &RxCell);
90133 + break;
90134 + }
90135 + /* RT2870 invokes STARxDoneInterruptHandle() in rtusb_bulk.c */
90136 +#ifdef RALINK_ATE
90137 + if (ATE_ON(pAd))
90138 + {
90139 + pAd->ate.RxCntPerSec++;
90140 + ATESampleRssi(pAd, pRxWI);
90141 +#ifdef RALINK_28xx_QA
90142 + if (pAd->ate.bQARxStart == TRUE)
90143 + {
90144 + /* (*pRxD) has been swapped in GetPacketFromRxRing() */
90145 + ATE_QA_Statistics(pAd, pRxWI, pRxD, pHeader);
90146 + }
90147 +#endif // RALINK_28xx_QA //
90148 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
90149 + continue;
90150 + }
90151 +#endif // RALINK_ATE //
90152 +
90153 + // Check for all RxD errors
90154 + Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);
90155 +
90156 + // Handle the received frame
90157 + if (Status == NDIS_STATUS_SUCCESS)
90158 + {
90159 + switch (pHeader->FC.Type)
90160 + {
90161 + // CASE I, receive a DATA frame
90162 + case BTYPE_DATA:
90163 + {
90164 + // process DATA frame
90165 + STAHandleRxDataFrame(pAd, &RxCell);
90166 + }
90167 + break;
90168 + // CASE II, receive a MGMT frame
90169 + case BTYPE_MGMT:
90170 + {
90171 + STAHandleRxMgmtFrame(pAd, &RxCell);
90172 + }
90173 + break;
90174 + // CASE III. receive a CNTL frame
90175 + case BTYPE_CNTL:
90176 + {
90177 + STAHandleRxControlFrame(pAd, &RxCell);
90178 + }
90179 + break;
90180 + // discard other type
90181 + default:
90182 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90183 + break;
90184 + }
90185 + }
90186 + else
90187 + {
90188 + pAd->Counters8023.RxErrors++;
90189 + // discard this frame
90190 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90191 + }
90192 + }
90193 +
90194 + return bReschedule;
90195 +}
90196 +
90197 +/*
90198 + ========================================================================
90199 +
90200 + Routine Description:
90201 + Arguments:
90202 + pAd Pointer to our adapter
90203 +
90204 + IRQL = DISPATCH_LEVEL
90205 +
90206 + ========================================================================
90207 +*/
90208 +VOID RTMPHandleTwakeupInterrupt(
90209 + IN PRTMP_ADAPTER pAd)
90210 +{
90211 + AsicForceWakeup(pAd, FALSE);
90212 +}
90213 +
90214 +/*
90215 +========================================================================
90216 +Routine Description:
90217 + Early checking and OS-depened parsing for Tx packet send to our STA driver.
90218 +
90219 +Arguments:
90220 + NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd.
90221 + PPNDIS_PACKET ppPacketArray The packet array need to do transmission.
90222 + UINT NumberOfPackets Number of packet in packet array.
90223 +
90224 +Return Value:
90225 + NONE
90226 +
90227 +Note:
90228 + This function do early checking and classification for send-out packet.
90229 + You only can put OS-depened & STA related code in here.
90230 +========================================================================
90231 +*/
90232 +VOID STASendPackets(
90233 + IN NDIS_HANDLE MiniportAdapterContext,
90234 + IN PPNDIS_PACKET ppPacketArray,
90235 + IN UINT NumberOfPackets)
90236 +{
90237 + UINT Index;
90238 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) MiniportAdapterContext;
90239 + PNDIS_PACKET pPacket;
90240 + BOOLEAN allowToSend = FALSE;
90241 +
90242 +
90243 + for (Index = 0; Index < NumberOfPackets; Index++)
90244 + {
90245 + pPacket = ppPacketArray[Index];
90246 +
90247 + do
90248 + {
90249 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
90250 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
90251 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
90252 + {
90253 + // Drop send request since hardware is in reset state
90254 + break;
90255 + }
90256 + else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd))
90257 + {
90258 + // Drop send request since there are no physical connection yet
90259 + break;
90260 + }
90261 + else
90262 + {
90263 + // Record that orignal packet source is from NDIS layer,so that
90264 + // later on driver knows how to release this NDIS PACKET
90265 +#ifdef QOS_DLS_SUPPORT
90266 + MAC_TABLE_ENTRY *pEntry;
90267 + PUCHAR pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
90268 +
90269 + pEntry = MacTableLookup(pAd, pSrcBufVA);
90270 + if (pEntry && (pEntry->ValidAsDls == TRUE))
90271 + {
90272 + RTMP_SET_PACKET_WCID(pPacket, pEntry->Aid);
90273 + }
90274 + else
90275 +#endif // QOS_DLS_SUPPORT //
90276 + RTMP_SET_PACKET_WCID(pPacket, 0); // this field is useless when in STA mode
90277 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
90278 + NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING);
90279 + pAd->RalinkCounters.PendingNdisPacketCount++;
90280 +
90281 + allowToSend = TRUE;
90282 + }
90283 + } while(FALSE);
90284 +
90285 + if (allowToSend == TRUE)
90286 + STASendPacket(pAd, pPacket);
90287 + else
90288 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90289 + }
90290 +
90291 + // Dequeue outgoing frames from TxSwQueue[] and process it
90292 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
90293 +
90294 +}
90295 +
90296 +
90297 +/*
90298 +========================================================================
90299 +Routine Description:
90300 + This routine is used to do packet parsing and classification for Tx packet
90301 + to STA device, and it will en-queue packets to our TxSwQueue depends on AC
90302 + class.
90303 +
90304 +Arguments:
90305 + pAd Pointer to our adapter
90306 + pPacket Pointer to send packet
90307 +
90308 +Return Value:
90309 + NDIS_STATUS_SUCCESS If succes to queue the packet into TxSwQueue.
90310 + NDIS_STATUS_FAILURE If failed to do en-queue.
90311 +
90312 +Note:
90313 + You only can put OS-indepened & STA related code in here.
90314 +========================================================================
90315 +*/
90316 +NDIS_STATUS STASendPacket(
90317 + IN PRTMP_ADAPTER pAd,
90318 + IN PNDIS_PACKET pPacket)
90319 +{
90320 + PACKET_INFO PacketInfo;
90321 + PUCHAR pSrcBufVA;
90322 + UINT SrcBufLen;
90323 + UINT AllowFragSize;
90324 + UCHAR NumberOfFrag;
90325 +// UCHAR RTSRequired;
90326 + UCHAR QueIdx, UserPriority;
90327 + MAC_TABLE_ENTRY *pEntry = NULL;
90328 + unsigned int IrqFlags;
90329 + UCHAR FlgIsIP = 0;
90330 + UCHAR Rate;
90331 +
90332 + // Prepare packet information structure for buffer descriptor
90333 + // chained within a single NDIS packet.
90334 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
90335 +
90336 + if (pSrcBufVA == NULL)
90337 + {
90338 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> pSrcBufVA == NULL !!!SrcBufLen=%x\n",SrcBufLen));
90339 + // Resourece is low, system did not allocate virtual address
90340 + // return NDIS_STATUS_FAILURE directly to upper layer
90341 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90342 + return NDIS_STATUS_FAILURE;
90343 + }
90344 +
90345 +
90346 + if (SrcBufLen < 14)
90347 + {
90348 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> Ndis Packet buffer error !!!\n"));
90349 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90350 + return (NDIS_STATUS_FAILURE);
90351 + }
90352 +
90353 + // In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry.
90354 + // Note multicast packets in adhoc also use BSSID_WCID index.
90355 + {
90356 + if(INFRA_ON(pAd))
90357 + {
90358 +#ifdef QOS_DLS_SUPPORT
90359 + USHORT tmpWcid;
90360 +
90361 + tmpWcid = RTMP_GET_PACKET_WCID(pPacket);
90362 + if (VALID_WCID(tmpWcid) &&
90363 + (pAd->MacTab.Content[tmpWcid].ValidAsDls== TRUE))
90364 + {
90365 + pEntry = &pAd->MacTab.Content[tmpWcid];
90366 + Rate = pAd->MacTab.Content[tmpWcid].CurrTxRate;
90367 + }
90368 + else
90369 +#endif // QOS_DLS_SUPPORT //
90370 + {
90371 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
90372 + RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID);
90373 + Rate = pAd->CommonCfg.TxRate;
90374 + }
90375 + }
90376 + else if (ADHOC_ON(pAd))
90377 + {
90378 + if (*pSrcBufVA & 0x01)
90379 + {
90380 + RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID);
90381 + pEntry = &pAd->MacTab.Content[MCAST_WCID];
90382 + }
90383 + else
90384 + {
90385 + pEntry = MacTableLookup(pAd, pSrcBufVA);
90386 + }
90387 + Rate = pAd->CommonCfg.TxRate;
90388 + }
90389 + }
90390 +
90391 + if (!pEntry)
90392 + {
90393 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket->Cannot find pEntry(%2x:%2x:%2x:%2x:%2x:%2x) in MacTab!\n", PRINT_MAC(pSrcBufVA)));
90394 + // Resourece is low, system did not allocate virtual address
90395 + // return NDIS_STATUS_FAILURE directly to upper layer
90396 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90397 + return NDIS_STATUS_FAILURE;
90398 + }
90399 +
90400 + if (ADHOC_ON(pAd)
90401 + )
90402 + {
90403 + RTMP_SET_PACKET_WCID(pPacket, (UCHAR)pEntry->Aid);
90404 + }
90405 +
90406 + //
90407 + // Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags.
90408 + // Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL).
90409 + RTMPCheckEtherType(pAd, pPacket);
90410 +
90411 +
90412 +
90413 + //
90414 + // WPA 802.1x secured port control - drop all non-802.1x frame before port secured
90415 + //
90416 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
90417 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
90418 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
90419 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
90420 +#ifdef WPA_SUPPLICANT_SUPPORT
90421 + || (pAd->StaCfg.IEEE8021X == TRUE)
90422 +#endif // WPA_SUPPLICANT_SUPPORT //
90423 +#ifdef LEAP_SUPPORT
90424 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
90425 +#endif // LEAP_SUPPORT //
90426 + )
90427 + && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) || (pAd->StaCfg.MicErrCnt >= 2))
90428 + && (RTMP_GET_PACKET_EAPOL(pPacket)== FALSE)
90429 + )
90430 + {
90431 + DBGPRINT(RT_DEBUG_TRACE,("STASendPacket --> Drop packet before port secured !!!\n"));
90432 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90433 +
90434 + return (NDIS_STATUS_FAILURE);
90435 + }
90436 +
90437 +
90438 + // STEP 1. Decide number of fragments required to deliver this MSDU.
90439 + // The estimation here is not very accurate because difficult to
90440 + // take encryption overhead into consideration here. The result
90441 + // "NumberOfFrag" is then just used to pre-check if enough free
90442 + // TXD are available to hold this MSDU.
90443 +
90444 +
90445 + if (*pSrcBufVA & 0x01) // fragmentation not allowed on multicast & broadcast
90446 + NumberOfFrag = 1;
90447 + else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))
90448 + NumberOfFrag = 1; // Aggregation overwhelms fragmentation
90449 + else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED))
90450 + NumberOfFrag = 1; // Aggregation overwhelms fragmentation
90451 +#ifdef DOT11_N_SUPPORT
90452 + else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD))
90453 + NumberOfFrag = 1; // MIMO RATE overwhelms fragmentation
90454 +#endif // DOT11_N_SUPPORT //
90455 + else
90456 + {
90457 + // The calculated "NumberOfFrag" is a rough estimation because of various
90458 + // encryption/encapsulation overhead not taken into consideration. This number is just
90459 + // used to make sure enough free TXD are available before fragmentation takes place.
90460 + // In case the actual required number of fragments of an NDIS packet
90461 + // excceeds "NumberOfFrag"caculated here and not enough free TXD available, the
90462 + // last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of
90463 + // resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should
90464 + // rarely happen and the penalty is just like a TX RETRY fail. Affordable.
90465 +
90466 + AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
90467 + NumberOfFrag = ((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) / AllowFragSize) + 1;
90468 + // To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size
90469 + if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) % AllowFragSize) == 0)
90470 + {
90471 + NumberOfFrag--;
90472 + }
90473 + }
90474 +
90475 + // Save fragment number to Ndis packet reserved field
90476 + RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag);
90477 +
90478 +
90479 + // STEP 2. Check the requirement of RTS:
90480 + // If multiple fragment required, RTS is required only for the first fragment
90481 + // if the fragment size large than RTS threshold
90482 + // For RT28xx, Let ASIC send RTS/CTS
90483 + RTMP_SET_PACKET_RTS(pPacket, 0);
90484 + RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate);
90485 +
90486 + //
90487 + // STEP 3. Traffic classification. outcome = <UserPriority, QueIdx>
90488 + //
90489 + UserPriority = 0;
90490 + QueIdx = QID_AC_BE;
90491 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
90492 + CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE))
90493 + {
90494 + USHORT Protocol;
90495 + UCHAR LlcSnapLen = 0, Byte0, Byte1;
90496 + do
90497 + {
90498 + // get Ethernet protocol field
90499 + Protocol = (USHORT)((pSrcBufVA[12] << 8) + pSrcBufVA[13]);
90500 + if (Protocol <= 1500)
90501 + {
90502 + // get Ethernet protocol field from LLC/SNAP
90503 + if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
90504 + break;
90505 +
90506 + Protocol = (USHORT)((Byte0 << 8) + Byte1);
90507 + LlcSnapLen = 8;
90508 + }
90509 +
90510 + // always AC_BE for non-IP packet
90511 + if (Protocol != 0x0800)
90512 + break;
90513 +
90514 + // get IP header
90515 + if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
90516 + break;
90517 +
90518 + // return AC_BE if packet is not IPv4
90519 + if ((Byte0 & 0xf0) != 0x40)
90520 + break;
90521 +
90522 + FlgIsIP = 1;
90523 + UserPriority = (Byte1 & 0xe0) >> 5;
90524 + QueIdx = MapUserPriorityToAccessCategory[UserPriority];
90525 +
90526 + // TODO: have to check ACM bit. apply TSPEC if ACM is ON
90527 + // TODO: downgrade UP & QueIdx before passing ACM
90528 + if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx])
90529 + {
90530 + UserPriority = 0;
90531 + QueIdx = QID_AC_BE;
90532 + }
90533 + } while (FALSE);
90534 + }
90535 +
90536 + RTMP_SET_PACKET_UP(pPacket, UserPriority);
90537 +
90538 +
90539 +
90540 + // Make sure SendTxWait queue resource won't be used by other threads
90541 + RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
90542 + if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE)
90543 + {
90544 + RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
90545 +#ifdef BLOCK_NET_IF
90546 + StopNetIfQueue(pAd, QueIdx, pPacket);
90547 +#endif // BLOCK_NET_IF //
90548 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
90549 +
90550 + return NDIS_STATUS_FAILURE;
90551 + }
90552 + else
90553 + {
90554 + InsertTailQueue(&pAd->TxSwQueue[QueIdx], PACKET_TO_QUEUE_ENTRY(pPacket));
90555 + }
90556 + RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
90557 +
90558 +#ifdef DOT11_N_SUPPORT
90559 + if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE)&&
90560 + IS_HT_STA(pEntry))
90561 + {
90562 + //PMAC_TABLE_ENTRY pMacEntry = &pAd->MacTab.Content[BSSID_WCID];
90563 + if (((pEntry->TXBAbitmap & (1<<UserPriority)) == 0) &&
90564 + ((pEntry->BADeclineBitmap & (1<<UserPriority)) == 0) &&
90565 + (pEntry->PortSecured == WPA_802_1X_PORT_SECURED)
90566 + // For IOT compatibility, if
90567 + // 1. It is Ralink chip or
90568 + // 2. It is OPEN or AES mode,
90569 + // then BA session can be bulit.
90570 + && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) ||
90571 + (pEntry->WepStatus == Ndis802_11WEPDisabled || pEntry->WepStatus == Ndis802_11Encryption3Enabled))
90572 + )
90573 + {
90574 + BAOriSessionSetUp(pAd, pEntry, 0, 0, 10, FALSE);
90575 + }
90576 + }
90577 +#endif // DOT11_N_SUPPORT //
90578 +
90579 + pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; // TODO: for debug only. to be removed
90580 + return NDIS_STATUS_SUCCESS;
90581 +}
90582 +
90583 +
90584 +/*
90585 + ========================================================================
90586 +
90587 + Routine Description:
90588 + This subroutine will scan through releative ring descriptor to find
90589 + out avaliable free ring descriptor and compare with request size.
90590 +
90591 + Arguments:
90592 + pAd Pointer to our adapter
90593 + QueIdx Selected TX Ring
90594 +
90595 + Return Value:
90596 + NDIS_STATUS_FAILURE Not enough free descriptor
90597 + NDIS_STATUS_SUCCESS Enough free descriptor
90598 +
90599 + IRQL = PASSIVE_LEVEL
90600 + IRQL = DISPATCH_LEVEL
90601 +
90602 + Note:
90603 +
90604 + ========================================================================
90605 +*/
90606 +
90607 +#ifdef RT2870
90608 +/*
90609 + Actually, this function used to check if the TxHardware Queue still has frame need to send.
90610 + If no frame need to send, go to sleep, else, still wake up.
90611 +*/
90612 +NDIS_STATUS RTMPFreeTXDRequest(
90613 + IN PRTMP_ADAPTER pAd,
90614 + IN UCHAR QueIdx,
90615 + IN UCHAR NumberRequired,
90616 + IN PUCHAR FreeNumberIs)
90617 +{
90618 + //ULONG FreeNumber = 0;
90619 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
90620 + unsigned long IrqFlags;
90621 + HT_TX_CONTEXT *pHTTXContext;
90622 +
90623 + switch (QueIdx)
90624 + {
90625 + case QID_AC_BK:
90626 + case QID_AC_BE:
90627 + case QID_AC_VI:
90628 + case QID_AC_VO:
90629 + case QID_HCCA:
90630 + {
90631 + pHTTXContext = &pAd->TxContext[QueIdx];
90632 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
90633 + if ((pHTTXContext->CurWritePosition != pHTTXContext->ENextBulkOutPosition) ||
90634 + (pHTTXContext->IRPPending == TRUE))
90635 + {
90636 + Status = NDIS_STATUS_FAILURE;
90637 + }
90638 + else
90639 + {
90640 + Status = NDIS_STATUS_SUCCESS;
90641 + }
90642 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
90643 + }
90644 + break;
90645 +
90646 + case QID_MGMT:
90647 + if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE)
90648 + Status = NDIS_STATUS_FAILURE;
90649 + else
90650 + Status = NDIS_STATUS_SUCCESS;
90651 + break;
90652 +
90653 + default:
90654 + DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));
90655 + break;
90656 + }
90657 +
90658 + return (Status);
90659 +
90660 +}
90661 +#endif // RT2870 //
90662 +
90663 +
90664 +VOID RTMPSendDisassociationFrame(
90665 + IN PRTMP_ADAPTER pAd)
90666 +{
90667 +}
90668 +
90669 +VOID RTMPSendNullFrame(
90670 + IN PRTMP_ADAPTER pAd,
90671 + IN UCHAR TxRate,
90672 + IN BOOLEAN bQosNull)
90673 +{
90674 + UCHAR NullFrame[48];
90675 + ULONG Length;
90676 + PHEADER_802_11 pHeader_802_11;
90677 +
90678 +
90679 +#ifdef RALINK_ATE
90680 + if(ATE_ON(pAd))
90681 + {
90682 + return;
90683 + }
90684 +#endif // RALINK_ATE //
90685 +
90686 + // WPA 802.1x secured port control
90687 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
90688 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
90689 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
90690 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
90691 +#ifdef WPA_SUPPLICANT_SUPPORT
90692 + || (pAd->StaCfg.IEEE8021X == TRUE)
90693 +#endif
90694 + ) &&
90695 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
90696 + {
90697 + return;
90698 + }
90699 +
90700 + NdisZeroMemory(NullFrame, 48);
90701 + Length = sizeof(HEADER_802_11);
90702 +
90703 + pHeader_802_11 = (PHEADER_802_11) NullFrame;
90704 +
90705 + pHeader_802_11->FC.Type = BTYPE_DATA;
90706 + pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC;
90707 + pHeader_802_11->FC.ToDs = 1;
90708 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
90709 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
90710 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
90711 +
90712 + if (pAd->CommonCfg.bAPSDForcePowerSave)
90713 + {
90714 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
90715 + }
90716 + else
90717 + {
90718 + pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE) ? 1: 0;
90719 + }
90720 + pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14);
90721 +
90722 + pAd->Sequence++;
90723 + pHeader_802_11->Sequence = pAd->Sequence;
90724 +
90725 + // Prepare QosNull function frame
90726 + if (bQosNull)
90727 + {
90728 + pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL;
90729 +
90730 + // copy QOS control bytes
90731 + NullFrame[Length] = 0;
90732 + NullFrame[Length+1] = 0;
90733 + Length += 2;// if pad with 2 bytes for alignment, APSD will fail
90734 + }
90735 +
90736 + HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length);
90737 +
90738 +}
90739 +
90740 +// IRQL = DISPATCH_LEVEL
90741 +VOID RTMPSendRTSFrame(
90742 + IN PRTMP_ADAPTER pAd,
90743 + IN PUCHAR pDA,
90744 + IN unsigned int NextMpduSize,
90745 + IN UCHAR TxRate,
90746 + IN UCHAR RTSRate,
90747 + IN USHORT AckDuration,
90748 + IN UCHAR QueIdx,
90749 + IN UCHAR FrameGap)
90750 +{
90751 +}
90752 +
90753 +
90754 +
90755 +// --------------------------------------------------------
90756 +// FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM
90757 +// Find the WPA key, either Group or Pairwise Key
90758 +// LEAP + TKIP also use WPA key.
90759 +// --------------------------------------------------------
90760 +// Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst
90761 +// In Cisco CCX 2.0 Leap Authentication
90762 +// WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey
90763 +// Instead of the SharedKey, SharedKey Length may be Zero.
90764 +VOID STAFindCipherAlgorithm(
90765 + IN PRTMP_ADAPTER pAd,
90766 + IN TX_BLK *pTxBlk)
90767 +{
90768 + NDIS_802_11_ENCRYPTION_STATUS Cipher; // To indicate cipher used for this packet
90769 + UCHAR CipherAlg = CIPHER_NONE; // cipher alogrithm
90770 + UCHAR KeyIdx = 0xff;
90771 + PUCHAR pSrcBufVA;
90772 + PCIPHER_KEY pKey = NULL;
90773 +
90774 + pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket);
90775 +
90776 + {
90777 + // Select Cipher
90778 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
90779 + Cipher = pAd->StaCfg.GroupCipher; // Cipher for Multicast or Broadcast
90780 + else
90781 + Cipher = pAd->StaCfg.PairCipher; // Cipher for Unicast
90782 +
90783 + if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
90784 + {
90785 + ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= CIPHER_CKIP128);
90786 +
90787 + // 4-way handshaking frame must be clear
90788 + if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) && (pAd->SharedKey[BSS0][0].CipherAlg) &&
90789 + (pAd->SharedKey[BSS0][0].KeyLen))
90790 + {
90791 + CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
90792 + KeyIdx = 0;
90793 + }
90794 + }
90795 + else if (Cipher == Ndis802_11Encryption1Enabled)
90796 + {
90797 +#ifdef LEAP_SUPPORT
90798 + if (pAd->StaCfg.CkipFlag & 0x10) // Cisco CKIP KP is on
90799 + {
90800 + if (LEAP_CCKM_ON(pAd))
90801 + {
90802 + if (((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))))
90803 + KeyIdx = 1;
90804 + else
90805 + KeyIdx = 0;
90806 + }
90807 + else
90808 + KeyIdx = pAd->StaCfg.DefaultKeyId;
90809 + }
90810 + else if (pAd->StaCfg.CkipFlag & 0x08) // only CKIP CMIC
90811 + KeyIdx = pAd->StaCfg.DefaultKeyId;
90812 + else if (LEAP_CCKM_ON(pAd))
90813 + {
90814 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
90815 + KeyIdx = 1;
90816 + else
90817 + KeyIdx = 0;
90818 + }
90819 + else // standard WEP64 or WEP128
90820 +#endif // LEAP_SUPPORT //
90821 + KeyIdx = pAd->StaCfg.DefaultKeyId;
90822 + }
90823 + else if ((Cipher == Ndis802_11Encryption2Enabled) ||
90824 + (Cipher == Ndis802_11Encryption3Enabled))
90825 + {
90826 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) // multicast
90827 + KeyIdx = pAd->StaCfg.DefaultKeyId;
90828 + else if (pAd->SharedKey[BSS0][0].KeyLen)
90829 + KeyIdx = 0;
90830 + else
90831 + KeyIdx = pAd->StaCfg.DefaultKeyId;
90832 + }
90833 +
90834 + if (KeyIdx == 0xff)
90835 + CipherAlg = CIPHER_NONE;
90836 + else if ((Cipher == Ndis802_11EncryptionDisabled) || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0))
90837 + CipherAlg = CIPHER_NONE;
90838 +#ifdef WPA_SUPPLICANT_SUPPORT
90839 + else if ( pAd->StaCfg.WpaSupplicantUP &&
90840 + (Cipher == Ndis802_11Encryption1Enabled) &&
90841 + (pAd->StaCfg.IEEE8021X == TRUE) &&
90842 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
90843 + CipherAlg = CIPHER_NONE;
90844 +#endif // WPA_SUPPLICANT_SUPPORT //
90845 + else
90846 + {
90847 + //Header_802_11.FC.Wep = 1;
90848 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
90849 + pKey = &pAd->SharedKey[BSS0][KeyIdx];
90850 + }
90851 + }
90852 +
90853 + pTxBlk->CipherAlg = CipherAlg;
90854 + pTxBlk->pKey = pKey;
90855 +}
90856 +
90857 +
90858 +VOID STABuildCommon802_11Header(
90859 + IN PRTMP_ADAPTER pAd,
90860 + IN TX_BLK *pTxBlk)
90861 +{
90862 +
90863 + HEADER_802_11 *pHeader_802_11;
90864 +#ifdef QOS_DLS_SUPPORT
90865 + BOOLEAN bDLSFrame = FALSE;
90866 + INT DlsEntryIndex = 0;
90867 +#endif // QOS_DLS_SUPPORT //
90868 +
90869 + //
90870 + // MAKE A COMMON 802.11 HEADER
90871 + //
90872 +
90873 + // normal wlan header size : 24 octets
90874 + pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
90875 +
90876 + pHeader_802_11 = (HEADER_802_11 *) &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
90877 +
90878 + NdisZeroMemory(pHeader_802_11, sizeof(HEADER_802_11));
90879 +
90880 + pHeader_802_11->FC.FrDs = 0;
90881 + pHeader_802_11->FC.Type = BTYPE_DATA;
90882 + pHeader_802_11->FC.SubType = ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : SUBTYPE_DATA);
90883 +
90884 +#ifdef QOS_DLS_SUPPORT
90885 + if (INFRA_ON(pAd))
90886 + {
90887 + // Check if the frame can be sent through DLS direct link interface
90888 + // If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
90889 + DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
90890 + if (DlsEntryIndex >= 0)
90891 + bDLSFrame = TRUE;
90892 + else
90893 + bDLSFrame = FALSE;
90894 + }
90895 +#endif // QOS_DLS_SUPPORT //
90896 +
90897 + if (pTxBlk->pMacEntry)
90898 + {
90899 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS))
90900 + {
90901 + pHeader_802_11->Sequence = pTxBlk->pMacEntry->NonQosDataSeq;
90902 + pTxBlk->pMacEntry->NonQosDataSeq = (pTxBlk->pMacEntry->NonQosDataSeq+1) & MAXSEQ;
90903 + }
90904 + else
90905 + {
90906 + pHeader_802_11->Sequence = pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority];
90907 + pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = (pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
90908 + }
90909 + }
90910 + else
90911 + {
90912 + pHeader_802_11->Sequence = pAd->Sequence;
90913 + pAd->Sequence = (pAd->Sequence+1) & MAXSEQ; // next sequence
90914 + }
90915 +
90916 + pHeader_802_11->Frag = 0;
90917 +
90918 + pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
90919 +
90920 + {
90921 + if (INFRA_ON(pAd))
90922 + {
90923 +#ifdef QOS_DLS_SUPPORT
90924 + if (bDLSFrame)
90925 + {
90926 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
90927 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
90928 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
90929 + pHeader_802_11->FC.ToDs = 0;
90930 + }
90931 + else
90932 +#endif // QOS_DLS_SUPPORT //
90933 + {
90934 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
90935 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
90936 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pTxBlk->pSrcBufHeader);
90937 + pHeader_802_11->FC.ToDs = 1;
90938 + }
90939 + }
90940 + else if (ADHOC_ON(pAd))
90941 + {
90942 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
90943 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
90944 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
90945 + pHeader_802_11->FC.ToDs = 0;
90946 + }
90947 + }
90948 +
90949 + if (pTxBlk->CipherAlg != CIPHER_NONE)
90950 + pHeader_802_11->FC.Wep = 1;
90951 +
90952 + // -----------------------------------------------------------------
90953 + // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
90954 + // -----------------------------------------------------------------
90955 + if (pAd->CommonCfg.bAPSDForcePowerSave)
90956 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
90957 + else
90958 + pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
90959 +}
90960 +
90961 +#ifdef DOT11_N_SUPPORT
90962 +VOID STABuildCache802_11Header(
90963 + IN RTMP_ADAPTER *pAd,
90964 + IN TX_BLK *pTxBlk,
90965 + IN UCHAR *pHeader)
90966 +{
90967 + MAC_TABLE_ENTRY *pMacEntry;
90968 + PHEADER_802_11 pHeader80211;
90969 +
90970 + pHeader80211 = (PHEADER_802_11)pHeader;
90971 + pMacEntry = pTxBlk->pMacEntry;
90972 +
90973 + //
90974 + // Update the cached 802.11 HEADER
90975 + //
90976 +
90977 + // normal wlan header size : 24 octets
90978 + pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
90979 +
90980 + // More Bit
90981 + pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
90982 +
90983 + // Sequence
90984 + pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority];
90985 + pMacEntry->TxSeq[pTxBlk->UserPriority] = (pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
90986 +
90987 + {
90988 + // Check if the frame can be sent through DLS direct link interface
90989 + // If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
90990 +#ifdef QOS_DLS_SUPPORT
90991 + BOOLEAN bDLSFrame = FALSE;
90992 + INT DlsEntryIndex = 0;
90993 +
90994 + DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
90995 + if (DlsEntryIndex >= 0)
90996 + bDLSFrame = TRUE;
90997 + else
90998 + bDLSFrame = FALSE;
90999 +#endif // QOS_DLS_SUPPORT //
91000 +
91001 + // The addr3 of normal packet send from DS is Dest Mac address.
91002 +#ifdef QOS_DLS_SUPPORT
91003 + if (bDLSFrame)
91004 + {
91005 + COPY_MAC_ADDR(pHeader80211->Addr1, pTxBlk->pSrcBufHeader);
91006 + COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
91007 + pHeader80211->FC.ToDs = 0;
91008 + }
91009 + else
91010 +#endif // QOS_DLS_SUPPORT //
91011 + if (ADHOC_ON(pAd))
91012 + COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
91013 + else
91014 + COPY_MAC_ADDR(pHeader80211->Addr3, pTxBlk->pSrcBufHeader);
91015 + }
91016 +
91017 + // -----------------------------------------------------------------
91018 + // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
91019 + // -----------------------------------------------------------------
91020 + if (pAd->CommonCfg.bAPSDForcePowerSave)
91021 + pHeader80211->FC.PwrMgmt = PWR_SAVE;
91022 + else
91023 + pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
91024 +}
91025 +#endif // DOT11_N_SUPPORT //
91026 +
91027 +static inline PUCHAR STA_Build_ARalink_Frame_Header(
91028 + IN RTMP_ADAPTER *pAd,
91029 + IN TX_BLK *pTxBlk)
91030 +{
91031 + PUCHAR pHeaderBufPtr;
91032 + HEADER_802_11 *pHeader_802_11;
91033 + PNDIS_PACKET pNextPacket;
91034 + UINT32 nextBufLen;
91035 + PQUEUE_ENTRY pQEntry;
91036 +
91037 + STAFindCipherAlgorithm(pAd, pTxBlk);
91038 + STABuildCommon802_11Header(pAd, pTxBlk);
91039 +
91040 +
91041 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91042 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
91043 +
91044 + // steal "order" bit to mark "aggregation"
91045 + pHeader_802_11->FC.Order = 1;
91046 +
91047 + // skip common header
91048 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
91049 +
91050 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
91051 + {
91052 + //
91053 + // build QOS Control bytes
91054 + //
91055 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
91056 +
91057 + *(pHeaderBufPtr+1) = 0;
91058 + pHeaderBufPtr +=2;
91059 + pTxBlk->MpduHeaderLen += 2;
91060 + }
91061 +
91062 + // padding at front of LLC header. LLC header should at 4-bytes aligment.
91063 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
91064 + pHeaderBufPtr = (PCHAR)ROUND_UP(pHeaderBufPtr, 4);
91065 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
91066 +
91067 + // For RA Aggregation,
91068 + // put the 2nd MSDU length(extra 2-byte field) after QOS_CONTROL in little endian format
91069 + pQEntry = pTxBlk->TxPacketList.Head;
91070 + pNextPacket = QUEUE_ENTRY_TO_PKT(pQEntry);
91071 + nextBufLen = GET_OS_PKT_LEN(pNextPacket);
91072 + if (RTMP_GET_PACKET_VLAN(pNextPacket))
91073 + nextBufLen -= LENGTH_802_1Q;
91074 +
91075 + *pHeaderBufPtr = (UCHAR)nextBufLen & 0xff;
91076 + *(pHeaderBufPtr+1) = (UCHAR)(nextBufLen >> 8);
91077 +
91078 + pHeaderBufPtr += 2;
91079 + pTxBlk->MpduHeaderLen += 2;
91080 +
91081 + return pHeaderBufPtr;
91082 +
91083 +}
91084 +
91085 +#ifdef DOT11_N_SUPPORT
91086 +static inline PUCHAR STA_Build_AMSDU_Frame_Header(
91087 + IN RTMP_ADAPTER *pAd,
91088 + IN TX_BLK *pTxBlk)
91089 +{
91090 + PUCHAR pHeaderBufPtr;//, pSaveBufPtr;
91091 + HEADER_802_11 *pHeader_802_11;
91092 +
91093 +
91094 + STAFindCipherAlgorithm(pAd, pTxBlk);
91095 + STABuildCommon802_11Header(pAd, pTxBlk);
91096 +
91097 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91098 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
91099 +
91100 + // skip common header
91101 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
91102 +
91103 + //
91104 + // build QOS Control bytes
91105 + //
91106 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
91107 +
91108 + //
91109 + // A-MSDU packet
91110 + //
91111 + *pHeaderBufPtr |= 0x80;
91112 +
91113 + *(pHeaderBufPtr+1) = 0;
91114 + pHeaderBufPtr +=2;
91115 + pTxBlk->MpduHeaderLen += 2;
91116 +
91117 + //pSaveBufPtr = pHeaderBufPtr;
91118 +
91119 + //
91120 + // padding at front of LLC header
91121 + // LLC header should locate at 4-octets aligment
91122 + //
91123 + // @@@ MpduHeaderLen excluding padding @@@
91124 + //
91125 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
91126 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
91127 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
91128 +
91129 + return pHeaderBufPtr;
91130 +
91131 +}
91132 +
91133 +
91134 +VOID STA_AMPDU_Frame_Tx(
91135 + IN PRTMP_ADAPTER pAd,
91136 + IN TX_BLK *pTxBlk)
91137 +{
91138 + HEADER_802_11 *pHeader_802_11;
91139 + PUCHAR pHeaderBufPtr;
91140 + USHORT FreeNumber;
91141 + MAC_TABLE_ENTRY *pMacEntry;
91142 + BOOLEAN bVLANPkt;
91143 + PQUEUE_ENTRY pQEntry;
91144 +
91145 + ASSERT(pTxBlk);
91146 +
91147 + while(pTxBlk->TxPacketList.Head)
91148 + {
91149 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91150 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91151 + if ( RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
91152 + {
91153 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
91154 + continue;
91155 + }
91156 +
91157 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
91158 +
91159 + pMacEntry = pTxBlk->pMacEntry;
91160 + if (pMacEntry->isCached)
91161 + {
91162 + // NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]!!!!
91163 + NdisMoveMemory((PUCHAR)&pTxBlk->HeaderBuf[TXINFO_SIZE], (PUCHAR)&pMacEntry->CachedBuf[0], TXWI_SIZE + sizeof(HEADER_802_11));
91164 + pHeaderBufPtr = (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]);
91165 + STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr);
91166 + }
91167 + else
91168 + {
91169 + STAFindCipherAlgorithm(pAd, pTxBlk);
91170 + STABuildCommon802_11Header(pAd, pTxBlk);
91171 +
91172 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91173 + }
91174 +
91175 +
91176 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
91177 +
91178 + // skip common header
91179 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
91180 +
91181 + //
91182 + // build QOS Control bytes
91183 + //
91184 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
91185 + *(pHeaderBufPtr+1) = 0;
91186 + pHeaderBufPtr +=2;
91187 + pTxBlk->MpduHeaderLen += 2;
91188 +
91189 + //
91190 + // build HTC+
91191 + // HTC control filed following QoS field
91192 + //
91193 + if ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, fCLIENT_STATUS_RDG_CAPABLE))
91194 + {
91195 + if (pMacEntry->isCached == FALSE)
91196 + {
91197 + // mark HTC bit
91198 + pHeader_802_11->FC.Order = 1;
91199 +
91200 + NdisZeroMemory(pHeaderBufPtr, 4);
91201 + *(pHeaderBufPtr+3) |= 0x80;
91202 + }
91203 + pHeaderBufPtr += 4;
91204 + pTxBlk->MpduHeaderLen += 4;
91205 + }
91206 +
91207 + //pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE;
91208 + ASSERT(pTxBlk->MpduHeaderLen >= 24);
91209 +
91210 + // skip 802.3 header
91211 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
91212 + pTxBlk->SrcBufLen -= LENGTH_802_3;
91213 +
91214 + // skip vlan tag
91215 + if (bVLANPkt)
91216 + {
91217 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
91218 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
91219 + }
91220 +
91221 + //
91222 + // padding at front of LLC header
91223 + // LLC header should locate at 4-octets aligment
91224 + //
91225 + // @@@ MpduHeaderLen excluding padding @@@
91226 + //
91227 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
91228 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
91229 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
91230 +
91231 + {
91232 +
91233 + //
91234 + // Insert LLC-SNAP encapsulation - 8 octets
91235 + //
91236 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
91237 + if (pTxBlk->pExtraLlcSnapEncap)
91238 + {
91239 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
91240 + pHeaderBufPtr += 6;
91241 + // get 2 octets (TypeofLen)
91242 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
91243 + pHeaderBufPtr += 2;
91244 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
91245 + }
91246 +
91247 + }
91248 +
91249 + if (pMacEntry->isCached)
91250 + {
91251 + RTMPWriteTxWI_Cache(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91252 + }
91253 + else
91254 + {
91255 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91256 +
91257 + NdisZeroMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), sizeof(pMacEntry->CachedBuf));
91258 + NdisMoveMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), (pHeaderBufPtr - (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE])));
91259 + pMacEntry->isCached = TRUE;
91260 + }
91261 +
91262 + // calculate Transmitted AMPDU count and ByteCount
91263 + {
91264 + pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.LowPart ++;
91265 + pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.QuadPart += pTxBlk->SrcBufLen;
91266 + }
91267 +
91268 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
91269 +
91270 + HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
91271 +
91272 + //
91273 + // Kick out Tx
91274 + //
91275 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
91276 +
91277 + pAd->RalinkCounters.KickTxCount++;
91278 + pAd->RalinkCounters.OneSecTxDoneCount++;
91279 + }
91280 +
91281 +}
91282 +
91283 +
91284 +VOID STA_AMSDU_Frame_Tx(
91285 + IN PRTMP_ADAPTER pAd,
91286 + IN TX_BLK *pTxBlk)
91287 +{
91288 + PUCHAR pHeaderBufPtr;
91289 + USHORT FreeNumber;
91290 + USHORT subFramePayloadLen = 0; // AMSDU Subframe length without AMSDU-Header / Padding.
91291 + USHORT totalMPDUSize=0;
91292 + UCHAR *subFrameHeader;
91293 + UCHAR padding = 0;
91294 + USHORT FirstTx = 0, LastTxIdx = 0;
91295 + BOOLEAN bVLANPkt;
91296 + int frameNum = 0;
91297 + PQUEUE_ENTRY pQEntry;
91298 +
91299 +
91300 + ASSERT(pTxBlk);
91301 +
91302 + ASSERT((pTxBlk->TxPacketList.Number > 1));
91303 +
91304 + while(pTxBlk->TxPacketList.Head)
91305 + {
91306 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91307 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91308 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
91309 + {
91310 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
91311 + continue;
91312 + }
91313 +
91314 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
91315 +
91316 + // skip 802.3 header
91317 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
91318 + pTxBlk->SrcBufLen -= LENGTH_802_3;
91319 +
91320 + // skip vlan tag
91321 + if (bVLANPkt)
91322 + {
91323 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
91324 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
91325 + }
91326 +
91327 + if (frameNum == 0)
91328 + {
91329 + pHeaderBufPtr = STA_Build_AMSDU_Frame_Header(pAd, pTxBlk);
91330 +
91331 + // NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled.
91332 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91333 + }
91334 + else
91335 + {
91336 + pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
91337 + padding = ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen, 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen);
91338 + NdisZeroMemory(pHeaderBufPtr, padding + LENGTH_AMSDU_SUBFRAMEHEAD);
91339 + pHeaderBufPtr += padding;
91340 + pTxBlk->MpduHeaderLen = padding;
91341 + }
91342 +
91343 + //
91344 + // A-MSDU subframe
91345 + // DA(6)+SA(6)+Length(2) + LLC/SNAP Encap
91346 + //
91347 + subFrameHeader = pHeaderBufPtr;
91348 + subFramePayloadLen = pTxBlk->SrcBufLen;
91349 +
91350 + NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12);
91351 +
91352 +
91353 + pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD;
91354 + pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD;
91355 +
91356 +
91357 + //
91358 + // Insert LLC-SNAP encapsulation - 8 octets
91359 + //
91360 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
91361 +
91362 + subFramePayloadLen = pTxBlk->SrcBufLen;
91363 +
91364 + if (pTxBlk->pExtraLlcSnapEncap)
91365 + {
91366 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
91367 + pHeaderBufPtr += 6;
91368 + // get 2 octets (TypeofLen)
91369 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
91370 + pHeaderBufPtr += 2;
91371 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
91372 + subFramePayloadLen += LENGTH_802_1_H;
91373 + }
91374 +
91375 + // update subFrame Length field
91376 + subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8;
91377 + subFrameHeader[13] = subFramePayloadLen & 0xFF;
91378 +
91379 + totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
91380 +
91381 + if (frameNum ==0)
91382 + FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
91383 + else
91384 + LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
91385 +
91386 + frameNum++;
91387 +
91388 + pAd->RalinkCounters.KickTxCount++;
91389 + pAd->RalinkCounters.OneSecTxDoneCount++;
91390 +
91391 + // calculate Transmitted AMSDU Count and ByteCount
91392 + {
91393 + pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart ++;
91394 + pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += totalMPDUSize;
91395 + }
91396 +
91397 + }
91398 +
91399 + HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
91400 + HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
91401 +
91402 + //
91403 + // Kick out Tx
91404 + //
91405 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
91406 +}
91407 +#endif // DOT11_N_SUPPORT //
91408 +
91409 +VOID STA_Legacy_Frame_Tx(
91410 + IN PRTMP_ADAPTER pAd,
91411 + IN TX_BLK *pTxBlk)
91412 +{
91413 + HEADER_802_11 *pHeader_802_11;
91414 + PUCHAR pHeaderBufPtr;
91415 + USHORT FreeNumber;
91416 + BOOLEAN bVLANPkt;
91417 + PQUEUE_ENTRY pQEntry;
91418 +
91419 + ASSERT(pTxBlk);
91420 +
91421 +
91422 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91423 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91424 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
91425 + {
91426 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
91427 + return;
91428 + }
91429 +
91430 + if (pTxBlk->TxFrameType == TX_MCAST_FRAME)
91431 + {
91432 + INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount);
91433 + }
91434 +
91435 + if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket))
91436 + TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired);
91437 + else
91438 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired);
91439 +
91440 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
91441 +
91442 + if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate)
91443 + pTxBlk->TxRate = pAd->CommonCfg.MinTxRate;
91444 +
91445 + STAFindCipherAlgorithm(pAd, pTxBlk);
91446 + STABuildCommon802_11Header(pAd, pTxBlk);
91447 +
91448 +
91449 + // skip 802.3 header
91450 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
91451 + pTxBlk->SrcBufLen -= LENGTH_802_3;
91452 +
91453 + // skip vlan tag
91454 + if (bVLANPkt)
91455 + {
91456 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
91457 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
91458 + }
91459 +
91460 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91461 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
91462 +
91463 + // skip common header
91464 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
91465 +
91466 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
91467 + {
91468 + //
91469 + // build QOS Control bytes
91470 + //
91471 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
91472 + *(pHeaderBufPtr+1) = 0;
91473 + pHeaderBufPtr +=2;
91474 + pTxBlk->MpduHeaderLen += 2;
91475 + }
91476 +
91477 + // The remaining content of MPDU header should locate at 4-octets aligment
91478 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
91479 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
91480 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
91481 +
91482 + {
91483 +
91484 + //
91485 + // Insert LLC-SNAP encapsulation - 8 octets
91486 + //
91487 + //
91488 + // if original Ethernet frame contains no LLC/SNAP,
91489 + // then an extra LLC/SNAP encap is required
91490 + //
91491 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
91492 + if (pTxBlk->pExtraLlcSnapEncap)
91493 + {
91494 + UCHAR vlan_size;
91495 +
91496 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
91497 + pHeaderBufPtr += 6;
91498 + // skip vlan tag
91499 + vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
91500 + // get 2 octets (TypeofLen)
91501 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
91502 + pHeaderBufPtr += 2;
91503 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
91504 + }
91505 +
91506 + }
91507 +
91508 + //
91509 + // prepare for TXWI
91510 + // use Wcid as Key Index
91511 + //
91512 +
91513 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91514 +
91515 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
91516 +
91517 + HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
91518 +
91519 + pAd->RalinkCounters.KickTxCount++;
91520 + pAd->RalinkCounters.OneSecTxDoneCount++;
91521 +
91522 + //
91523 + // Kick out Tx
91524 + //
91525 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
91526 +}
91527 +
91528 +
91529 +VOID STA_ARalink_Frame_Tx(
91530 + IN PRTMP_ADAPTER pAd,
91531 + IN TX_BLK *pTxBlk)
91532 +{
91533 + PUCHAR pHeaderBufPtr;
91534 + USHORT FreeNumber;
91535 + USHORT totalMPDUSize=0;
91536 + USHORT FirstTx, LastTxIdx;
91537 + int frameNum = 0;
91538 + BOOLEAN bVLANPkt;
91539 + PQUEUE_ENTRY pQEntry;
91540 +
91541 +
91542 + ASSERT(pTxBlk);
91543 +
91544 + ASSERT((pTxBlk->TxPacketList.Number== 2));
91545 +
91546 +
91547 + FirstTx = LastTxIdx = 0; // Is it ok init they as 0?
91548 + while(pTxBlk->TxPacketList.Head)
91549 + {
91550 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91551 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91552 +
91553 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
91554 + {
91555 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
91556 + continue;
91557 + }
91558 +
91559 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
91560 +
91561 + // skip 802.3 header
91562 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
91563 + pTxBlk->SrcBufLen -= LENGTH_802_3;
91564 +
91565 + // skip vlan tag
91566 + if (bVLANPkt)
91567 + {
91568 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
91569 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
91570 + }
91571 +
91572 + if (frameNum == 0)
91573 + { // For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header
91574 +
91575 + pHeaderBufPtr = STA_Build_ARalink_Frame_Header(pAd, pTxBlk);
91576 +
91577 + // It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount
91578 + // will be updated after final frame was handled.
91579 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91580 +
91581 +
91582 + //
91583 + // Insert LLC-SNAP encapsulation - 8 octets
91584 + //
91585 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
91586 +
91587 + if (pTxBlk->pExtraLlcSnapEncap)
91588 + {
91589 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
91590 + pHeaderBufPtr += 6;
91591 + // get 2 octets (TypeofLen)
91592 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
91593 + pHeaderBufPtr += 2;
91594 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
91595 + }
91596 + }
91597 + else
91598 + { // For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0.
91599 +
91600 + pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
91601 + pTxBlk->MpduHeaderLen = 0;
91602 +
91603 + // A-Ralink sub-sequent frame header is the same as 802.3 header.
91604 + // DA(6)+SA(6)+FrameType(2)
91605 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, 12);
91606 + pHeaderBufPtr += 12;
91607 + // get 2 octets (TypeofLen)
91608 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
91609 + pHeaderBufPtr += 2;
91610 + pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD;
91611 + }
91612 +
91613 + totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
91614 +
91615 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
91616 + if (frameNum ==0)
91617 + FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
91618 + else
91619 + LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
91620 +
91621 + frameNum++;
91622 +
91623 + pAd->RalinkCounters.OneSecTxAggregationCount++;
91624 + pAd->RalinkCounters.KickTxCount++;
91625 + pAd->RalinkCounters.OneSecTxDoneCount++;
91626 +
91627 + }
91628 +
91629 + HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
91630 + HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
91631 +
91632 + //
91633 + // Kick out Tx
91634 + //
91635 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
91636 +
91637 +}
91638 +
91639 +
91640 +VOID STA_Fragment_Frame_Tx(
91641 + IN RTMP_ADAPTER *pAd,
91642 + IN TX_BLK *pTxBlk)
91643 +{
91644 + HEADER_802_11 *pHeader_802_11;
91645 + PUCHAR pHeaderBufPtr;
91646 + USHORT FreeNumber;
91647 + UCHAR fragNum = 0;
91648 + PACKET_INFO PacketInfo;
91649 + USHORT EncryptionOverhead = 0;
91650 + UINT32 FreeMpduSize, SrcRemainingBytes;
91651 + USHORT AckDuration;
91652 + UINT NextMpduSize;
91653 + BOOLEAN bVLANPkt;
91654 + PQUEUE_ENTRY pQEntry;
91655 +
91656 +
91657 + ASSERT(pTxBlk);
91658 +
91659 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91660 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91661 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
91662 + {
91663 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
91664 + return;
91665 + }
91666 +
91667 + ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag));
91668 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
91669 +
91670 + STAFindCipherAlgorithm(pAd, pTxBlk);
91671 + STABuildCommon802_11Header(pAd, pTxBlk);
91672 +
91673 + if (pTxBlk->CipherAlg == CIPHER_TKIP)
91674 + {
91675 + pTxBlk->pPacket = duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket);
91676 + if (pTxBlk->pPacket == NULL)
91677 + return;
91678 + RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
91679 + }
91680 +
91681 + // skip 802.3 header
91682 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
91683 + pTxBlk->SrcBufLen -= LENGTH_802_3;
91684 +
91685 +
91686 + // skip vlan tag
91687 + if (bVLANPkt)
91688 + {
91689 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
91690 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
91691 + }
91692 +
91693 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91694 + pHeader_802_11 = (HEADER_802_11 *)pHeaderBufPtr;
91695 +
91696 +
91697 + // skip common header
91698 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
91699 +
91700 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
91701 + {
91702 + //
91703 + // build QOS Control bytes
91704 + //
91705 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
91706 +
91707 + *(pHeaderBufPtr+1) = 0;
91708 + pHeaderBufPtr +=2;
91709 + pTxBlk->MpduHeaderLen += 2;
91710 + }
91711 +
91712 + //
91713 + // padding at front of LLC header
91714 + // LLC header should locate at 4-octets aligment
91715 + //
91716 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
91717 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
91718 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
91719 +
91720 +
91721 +
91722 + //
91723 + // Insert LLC-SNAP encapsulation - 8 octets
91724 + //
91725 + //
91726 + // if original Ethernet frame contains no LLC/SNAP,
91727 + // then an extra LLC/SNAP encap is required
91728 + //
91729 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
91730 + if (pTxBlk->pExtraLlcSnapEncap)
91731 + {
91732 + UCHAR vlan_size;
91733 +
91734 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
91735 + pHeaderBufPtr += 6;
91736 + // skip vlan tag
91737 + vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
91738 + // get 2 octets (TypeofLen)
91739 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
91740 + pHeaderBufPtr += 2;
91741 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
91742 + }
91743 +
91744 +
91745 + // If TKIP is used and fragmentation is required. Driver has to
91746 + // append TKIP MIC at tail of the scatter buffer
91747 + // MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC
91748 + if (pTxBlk->CipherAlg == CIPHER_TKIP)
91749 + {
91750 +
91751 + // NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust
91752 + // to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress.
91753 + NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, &pAd->PrivateInfo.Tx.MIC[0], 8);
91754 + //skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8);
91755 + pTxBlk->SrcBufLen += 8;
91756 + pTxBlk->TotalFrameLen += 8;
91757 + pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;
91758 + }
91759 +
91760 + //
91761 + // calcuate the overhead bytes that encryption algorithm may add. This
91762 + // affects the calculate of "duration" field
91763 + //
91764 + if ((pTxBlk->CipherAlg == CIPHER_WEP64) || (pTxBlk->CipherAlg == CIPHER_WEP128))
91765 + EncryptionOverhead = 8; //WEP: IV[4] + ICV[4];
91766 + else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC)
91767 + EncryptionOverhead = 12;//TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength
91768 + else if (pTxBlk->CipherAlg == CIPHER_TKIP)
91769 + EncryptionOverhead = 20;//TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8]
91770 + else if (pTxBlk->CipherAlg == CIPHER_AES)
91771 + EncryptionOverhead = 16; // AES: IV[4] + EIV[4] + MIC[8]
91772 + else
91773 + EncryptionOverhead = 0;
91774 +
91775 + // decide how much time an ACK/CTS frame will consume in the air
91776 + AckDuration = RTMPCalcDuration(pAd, pAd->CommonCfg.ExpectedACKRate[pTxBlk->TxRate], 14);
91777 +
91778 + // Init the total payload length of this frame.
91779 + SrcRemainingBytes = pTxBlk->SrcBufLen;
91780 +
91781 + pTxBlk->TotalFragNum = 0xff;
91782 +
91783 + do {
91784 +
91785 + FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC;
91786 +
91787 + FreeMpduSize -= pTxBlk->MpduHeaderLen;
91788 +
91789 + if (SrcRemainingBytes <= FreeMpduSize)
91790 + { // this is the last or only fragment
91791 +
91792 + pTxBlk->SrcBufLen = SrcRemainingBytes;
91793 +
91794 + pHeader_802_11->FC.MoreFrag = 0;
91795 + pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + AckDuration;
91796 +
91797 + // Indicate the lower layer that this's the last fragment.
91798 + pTxBlk->TotalFragNum = fragNum;
91799 + }
91800 + else
91801 + { // more fragment is required
91802 +
91803 + pTxBlk->SrcBufLen = FreeMpduSize;
91804 +
91805 + NextMpduSize = min(((UINT)SrcRemainingBytes - pTxBlk->SrcBufLen), ((UINT)pAd->CommonCfg.FragmentThreshold));
91806 + pHeader_802_11->FC.MoreFrag = 1;
91807 + pHeader_802_11->Duration = (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + RTMPCalcDuration(pAd, pTxBlk->TxRate, NextMpduSize + EncryptionOverhead);
91808 + }
91809 +
91810 + if (fragNum == 0)
91811 + pTxBlk->FrameGap = IFS_HTTXOP;
91812 + else
91813 + pTxBlk->FrameGap = IFS_SIFS;
91814 +
91815 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
91816 +
91817 + HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber);
91818 +
91819 + pAd->RalinkCounters.KickTxCount++;
91820 + pAd->RalinkCounters.OneSecTxDoneCount++;
91821 +
91822 + // Update the frame number, remaining size of the NDIS packet payload.
91823 +
91824 + // space for 802.11 header.
91825 + if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap)
91826 + pTxBlk->MpduHeaderLen -= LENGTH_802_1_H;
91827 +
91828 + fragNum++;
91829 + SrcRemainingBytes -= pTxBlk->SrcBufLen;
91830 + pTxBlk->pSrcBufData += pTxBlk->SrcBufLen;
91831 +
91832 + pHeader_802_11->Frag++; // increase Frag #
91833 +
91834 + }while(SrcRemainingBytes > 0);
91835 +
91836 + //
91837 + // Kick out Tx
91838 + //
91839 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
91840 +}
91841 +
91842 +
91843 +#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \
91844 + while(_pTxBlk->TxPacketList.Head) \
91845 + { \
91846 + _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \
91847 + RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \
91848 + }
91849 +
91850 +
91851 +/*
91852 + ========================================================================
91853 +
91854 + Routine Description:
91855 + Copy frame from waiting queue into relative ring buffer and set
91856 + appropriate ASIC register to kick hardware encryption before really
91857 + sent out to air.
91858 +
91859 + Arguments:
91860 + pAd Pointer to our adapter
91861 + PNDIS_PACKET Pointer to outgoing Ndis frame
91862 + NumberOfFrag Number of fragment required
91863 +
91864 + Return Value:
91865 + None
91866 +
91867 + IRQL = DISPATCH_LEVEL
91868 +
91869 + Note:
91870 +
91871 + ========================================================================
91872 +*/
91873 +NDIS_STATUS STAHardTransmit(
91874 + IN PRTMP_ADAPTER pAd,
91875 + IN TX_BLK *pTxBlk,
91876 + IN UCHAR QueIdx)
91877 +{
91878 + NDIS_PACKET *pPacket;
91879 + PQUEUE_ENTRY pQEntry;
91880 +
91881 + // ---------------------------------------------
91882 + // STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION.
91883 + // ---------------------------------------------
91884 + //
91885 + ASSERT(pTxBlk->TxPacketList.Number);
91886 + if (pTxBlk->TxPacketList.Head == NULL)
91887 + {
91888 + DBGPRINT(RT_DEBUG_ERROR, ("pTxBlk->TotalFrameNum == %ld!\n", pTxBlk->TxPacketList.Number));
91889 + return NDIS_STATUS_FAILURE;
91890 + }
91891 +
91892 + pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head);
91893 +
91894 +#if 0 //def CARRIER_DETECTION_SUPPORT // Roger sync Carrier
91895 + if ((pAd->CommonCfg.CarrierDetect.Enable == TRUE) && (isCarrierDetectExist(pAd) == TRUE))
91896 + {
91897 + DBGPRINT(RT_DEBUG_INFO,("STAHardTransmit --> radar detect not in normal mode !!!\n"));
91898 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91899 + return (NDIS_STATUS_FAILURE);
91900 + }
91901 +#endif // CARRIER_DETECTION_SUPPORT //
91902 +
91903 + // ------------------------------------------------------------------
91904 + // STEP 1. WAKE UP PHY
91905 + // outgoing frame always wakeup PHY to prevent frame lost and
91906 + // turn off PSM bit to improve performance
91907 + // ------------------------------------------------------------------
91908 + // not to change PSM bit, just send this frame out?
91909 + if ((pAd->StaCfg.Psm == PWR_SAVE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
91910 + {
91911 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicForceWakeup At HardTx\n"));
91912 + AsicForceWakeup(pAd, TRUE);
91913 + }
91914 +
91915 + // It should not change PSM bit, when APSD turn on.
91916 + if ((!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE))
91917 + || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
91918 + || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket)))
91919 + {
91920 + if ((pAd->StaCfg.Psm == PWR_SAVE) &&
91921 + (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP))
91922 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
91923 + }
91924 +
91925 + switch (pTxBlk->TxFrameType)
91926 + {
91927 +#ifdef DOT11_N_SUPPORT
91928 + case TX_AMPDU_FRAME:
91929 + STA_AMPDU_Frame_Tx(pAd, pTxBlk);
91930 + break;
91931 + case TX_AMSDU_FRAME:
91932 + STA_AMSDU_Frame_Tx(pAd, pTxBlk);
91933 + break;
91934 +#endif // DOT11_N_SUPPORT //
91935 + case TX_LEGACY_FRAME:
91936 + STA_Legacy_Frame_Tx(pAd, pTxBlk);
91937 + break;
91938 + case TX_MCAST_FRAME:
91939 + STA_Legacy_Frame_Tx(pAd, pTxBlk);
91940 + break;
91941 + case TX_RALINK_FRAME:
91942 + STA_ARalink_Frame_Tx(pAd, pTxBlk);
91943 + break;
91944 + case TX_FRAG_FRAME:
91945 + STA_Fragment_Frame_Tx(pAd, pTxBlk);
91946 + break;
91947 + default:
91948 + {
91949 + // It should not happened!
91950 + DBGPRINT(RT_DEBUG_ERROR, ("Send a pacekt was not classified!! It should not happen!\n"));
91951 + while(pTxBlk->TxPacketList.Number)
91952 + {
91953 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
91954 + pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
91955 + if (pPacket)
91956 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91957 + }
91958 + }
91959 + break;
91960 + }
91961 +
91962 + return (NDIS_STATUS_SUCCESS);
91963 +
91964 +}
91965 +
91966 +ULONG HashBytesPolynomial(UCHAR *value, unsigned int len)
91967 +{
91968 + unsigned char *word = value;
91969 + unsigned int ret = 0;
91970 + unsigned int i;
91971 +
91972 + for(i=0; i < len; i++)
91973 + {
91974 + int mod = i % 32;
91975 + ret ^=(unsigned int) (word[i]) << mod;
91976 + ret ^=(unsigned int) (word[i]) >> (32 - mod);
91977 + }
91978 + return ret;
91979 +}
91980 +
91981 +VOID Sta_Announce_or_Forward_802_3_Packet(
91982 + IN PRTMP_ADAPTER pAd,
91983 + IN PNDIS_PACKET pPacket,
91984 + IN UCHAR FromWhichBSSID)
91985 +{
91986 + if (TRUE
91987 + )
91988 + {
91989 + announce_802_3_packet(pAd, pPacket);
91990 + }
91991 + else
91992 + {
91993 + // release packet
91994 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91995 + }
91996 +}
91997 +
91998 --- /dev/null
91999 +++ b/drivers/staging/rt2870/sta/sanity.c
92000 @@ -0,0 +1,420 @@
92001 +/*
92002 + *************************************************************************
92003 + * Ralink Tech Inc.
92004 + * 5F., No.36, Taiyuan St., Jhubei City,
92005 + * Hsinchu County 302,
92006 + * Taiwan, R.O.C.
92007 + *
92008 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
92009 + *
92010 + * This program is free software; you can redistribute it and/or modify *
92011 + * it under the terms of the GNU General Public License as published by *
92012 + * the Free Software Foundation; either version 2 of the License, or *
92013 + * (at your option) any later version. *
92014 + * *
92015 + * This program is distributed in the hope that it will be useful, *
92016 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
92017 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
92018 + * GNU General Public License for more details. *
92019 + * *
92020 + * You should have received a copy of the GNU General Public License *
92021 + * along with this program; if not, write to the *
92022 + * Free Software Foundation, Inc., *
92023 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
92024 + * *
92025 + *************************************************************************
92026 +
92027 + Module Name:
92028 + sanity.c
92029 +
92030 + Abstract:
92031 +
92032 + Revision History:
92033 + Who When What
92034 + -------- ---------- ----------------------------------------------
92035 + John Chang 2004-09-01 add WMM support
92036 +*/
92037 +#include "../rt_config.h"
92038 +
92039 +extern UCHAR CISCO_OUI[];
92040 +
92041 +extern UCHAR WPA_OUI[];
92042 +extern UCHAR RSN_OUI[];
92043 +extern UCHAR WME_INFO_ELEM[];
92044 +extern UCHAR WME_PARM_ELEM[];
92045 +extern UCHAR Ccx2QosInfo[];
92046 +extern UCHAR RALINK_OUI[];
92047 +extern UCHAR BROADCOM_OUI[];
92048 +
92049 +/*
92050 + ==========================================================================
92051 + Description:
92052 + MLME message sanity check
92053 + Return:
92054 + TRUE if all parameters are OK, FALSE otherwise
92055 + ==========================================================================
92056 + */
92057 +BOOLEAN MlmeStartReqSanity(
92058 + IN PRTMP_ADAPTER pAd,
92059 + IN VOID *Msg,
92060 + IN ULONG MsgLen,
92061 + OUT CHAR Ssid[],
92062 + OUT UCHAR *pSsidLen)
92063 +{
92064 + MLME_START_REQ_STRUCT *Info;
92065 +
92066 + Info = (MLME_START_REQ_STRUCT *)(Msg);
92067 +
92068 + if (Info->SsidLen > MAX_LEN_OF_SSID)
92069 + {
92070 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqSanity fail - wrong SSID length\n"));
92071 + return FALSE;
92072 + }
92073 +
92074 + *pSsidLen = Info->SsidLen;
92075 + NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
92076 +
92077 + return TRUE;
92078 +}
92079 +
92080 +/*
92081 + ==========================================================================
92082 + Description:
92083 + MLME message sanity check
92084 + Return:
92085 + TRUE if all parameters are OK, FALSE otherwise
92086 +
92087 + IRQL = DISPATCH_LEVEL
92088 +
92089 + ==========================================================================
92090 + */
92091 +BOOLEAN PeerAssocRspSanity(
92092 + IN PRTMP_ADAPTER pAd,
92093 + IN VOID *pMsg,
92094 + IN ULONG MsgLen,
92095 + OUT PUCHAR pAddr2,
92096 + OUT USHORT *pCapabilityInfo,
92097 + OUT USHORT *pStatus,
92098 + OUT USHORT *pAid,
92099 + OUT UCHAR SupRate[],
92100 + OUT UCHAR *pSupRateLen,
92101 + OUT UCHAR ExtRate[],
92102 + OUT UCHAR *pExtRateLen,
92103 + OUT HT_CAPABILITY_IE *pHtCapability,
92104 + OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
92105 + OUT UCHAR *pHtCapabilityLen,
92106 + OUT UCHAR *pAddHtInfoLen,
92107 + OUT UCHAR *pNewExtChannelOffset,
92108 + OUT PEDCA_PARM pEdcaParm,
92109 + OUT UCHAR *pCkipFlag)
92110 +{
92111 + CHAR IeType, *Ptr;
92112 + PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
92113 + PEID_STRUCT pEid;
92114 + ULONG Length = 0;
92115 +
92116 + *pNewExtChannelOffset = 0xff;
92117 + *pHtCapabilityLen = 0;
92118 + *pAddHtInfoLen = 0;
92119 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
92120 + Ptr = pFrame->Octet;
92121 + Length += LENGTH_802_11;
92122 +
92123 + NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);
92124 + Length += 2;
92125 + NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);
92126 + Length += 2;
92127 + *pCkipFlag = 0;
92128 + *pExtRateLen = 0;
92129 + pEdcaParm->bValid = FALSE;
92130 +
92131 + if (*pStatus != MLME_SUCCESS)
92132 + return TRUE;
92133 +
92134 + NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
92135 + Length += 2;
92136 +
92137 + // Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform
92138 + *pAid = (*pAid) & 0x3fff; // AID is low 14-bit
92139 +
92140 + // -- get supported rates from payload and advance the pointer
92141 + IeType = pFrame->Octet[6];
92142 + *pSupRateLen = pFrame->Octet[7];
92143 + if ((IeType != IE_SUPP_RATES) || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES))
92144 + {
92145 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));
92146 + return FALSE;
92147 + }
92148 + else
92149 + NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);
92150 +
92151 + Length = Length + 2 + *pSupRateLen;
92152 +
92153 + // many AP implement proprietary IEs in non-standard order, we'd better
92154 + // tolerate mis-ordered IEs to get best compatibility
92155 + pEid = (PEID_STRUCT) &pFrame->Octet[8 + (*pSupRateLen)];
92156 +
92157 + // get variable fields from payload and advance the pointer
92158 + while ((Length + 2 + pEid->Len) <= MsgLen)
92159 + {
92160 + switch (pEid->Eid)
92161 + {
92162 + case IE_EXT_SUPP_RATES:
92163 + if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
92164 + {
92165 + NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
92166 + *pExtRateLen = pEid->Len;
92167 + }
92168 + break;
92169 +
92170 + case IE_HT_CAP:
92171 + case IE_HT_CAP2:
92172 + if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!
92173 + {
92174 + NdisMoveMemory(pHtCapability, pEid->Octet, SIZE_HT_CAP_IE);
92175 +
92176 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
92177 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
92178 +
92179 + *pHtCapabilityLen = SIZE_HT_CAP_IE;
92180 + }
92181 + else
92182 + {
92183 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));
92184 + }
92185 +
92186 + break;
92187 +#ifdef DOT11_N_SUPPORT
92188 + case IE_ADD_HT:
92189 + case IE_ADD_HT2:
92190 + if (pEid->Len >= sizeof(ADD_HT_INFO_IE))
92191 + {
92192 + // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only
92193 + // copy first sizeof(ADD_HT_INFO_IE)
92194 + NdisMoveMemory(pAddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));
92195 +
92196 + *(USHORT *)(&pAddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo2));
92197 + *(USHORT *)(&pAddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo3));
92198 +
92199 + *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;
92200 + }
92201 + else
92202 + {
92203 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));
92204 + }
92205 +
92206 + break;
92207 + case IE_SECONDARY_CH_OFFSET:
92208 + if (pEid->Len == 1)
92209 + {
92210 + *pNewExtChannelOffset = pEid->Octet[0];
92211 + }
92212 + else
92213 + {
92214 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
92215 + }
92216 +#endif // DOT11_N_SUPPORT //
92217 + break;
92218 + case IE_AIRONET_CKIP:
92219 + // 0. Check Aironet IE length, it must be larger or equal to 28
92220 + // Cisco's AP VxWork version(will not be supported) used this IE length as 28
92221 + // Cisco's AP IOS version used this IE length as 30
92222 + if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
92223 + break;
92224 +
92225 + // 1. Copy CKIP flag byte to buffer for process
92226 + *pCkipFlag = *(pEid->Octet + 8);
92227 + break;
92228 +
92229 + case IE_AIRONET_IPADDRESS:
92230 + if (pEid->Len != 0x0A)
92231 + break;
92232 +
92233 + // Get Cisco Aironet IP information
92234 + if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
92235 + NdisMoveMemory(pAd->StaCfg.AironetIPAddress, pEid->Octet + 4, 4);
92236 + break;
92237 +
92238 + // CCX2, WMM use the same IE value
92239 + // case IE_CCX_V2:
92240 + case IE_VENDOR_SPECIFIC:
92241 + // handle WME PARAMTER ELEMENT
92242 + if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))
92243 + {
92244 + PUCHAR ptr;
92245 + int i;
92246 +
92247 + // parsing EDCA parameters
92248 + pEdcaParm->bValid = TRUE;
92249 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
92250 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
92251 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
92252 + //pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80;
92253 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
92254 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
92255 + ptr = &pEid->Octet[8];
92256 + for (i=0; i<4; i++)
92257 + {
92258 + UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX
92259 + pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM
92260 + pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN
92261 + pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin
92262 + pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax
92263 + pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us
92264 + ptr += 4; // point to next AC
92265 + }
92266 + }
92267 +
92268 + // handle CCX IE
92269 + else
92270 + {
92271 + // 0. Check the size and CCX admin control
92272 + if (pAd->StaCfg.CCXControl.field.Enable == 0)
92273 + break;
92274 + if (pEid->Len != 5)
92275 + break;
92276 +
92277 + // Turn CCX2 if matched
92278 + if (NdisEqualMemory(pEid->Octet, Ccx2IeInfo, 5) == 1)
92279 + pAd->StaCfg.CCXEnable = TRUE;
92280 + break;
92281 + }
92282 + break;
92283 +
92284 + default:
92285 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity - ignore unrecognized EID = %d\n", pEid->Eid));
92286 + break;
92287 + }
92288 +
92289 + Length = Length + 2 + pEid->Len;
92290 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
92291 + }
92292 +
92293 + // Force CCX2 enable to TRUE for those AP didn't replay CCX v2 IE, we still force it to be on
92294 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
92295 + pAd->StaCfg.CCXEnable = TRUE;
92296 +
92297 + return TRUE;
92298 +}
92299 +
92300 +/*
92301 + ==========================================================================
92302 + Description:
92303 + MLME message sanity check
92304 + Return:
92305 + TRUE if all parameters are OK, FALSE otherwise
92306 +
92307 + IRQL = DISPATCH_LEVEL
92308 +
92309 + ==========================================================================
92310 + */
92311 +BOOLEAN PeerProbeReqSanity(
92312 + IN PRTMP_ADAPTER pAd,
92313 + IN VOID *Msg,
92314 + IN ULONG MsgLen,
92315 + OUT PUCHAR pAddr2,
92316 + OUT CHAR Ssid[],
92317 + OUT UCHAR *pSsidLen)
92318 +{
92319 + UCHAR Idx;
92320 + UCHAR RateLen;
92321 + CHAR IeType;
92322 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
92323 +
92324 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
92325 +
92326 + if ((pFrame->Octet[0] != IE_SSID) || (pFrame->Octet[1] > MAX_LEN_OF_SSID))
92327 + {
92328 + DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",pFrame->Octet[0],pFrame->Octet[1]));
92329 + return FALSE;
92330 + }
92331 +
92332 + *pSsidLen = pFrame->Octet[1];
92333 + NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);
92334 +
92335 + Idx = *pSsidLen + 2;
92336 +
92337 + // -- get supported rates from payload and advance the pointer
92338 + IeType = pFrame->Octet[Idx];
92339 + RateLen = pFrame->Octet[Idx + 1];
92340 + if (IeType != IE_SUPP_RATES)
92341 + {
92342 + DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",pFrame->Octet[Idx],pFrame->Octet[Idx+1]));
92343 + return FALSE;
92344 + }
92345 + else
92346 + {
92347 + if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))
92348 + return (FALSE);
92349 + }
92350 +
92351 + return TRUE;
92352 +}
92353 +
92354 +/*
92355 + ==========================================================================
92356 + Description:
92357 +
92358 + IRQL = DISPATCH_LEVEL
92359 +
92360 + ==========================================================================
92361 + */
92362 +BOOLEAN GetTimBit(
92363 + IN CHAR *Ptr,
92364 + IN USHORT Aid,
92365 + OUT UCHAR *TimLen,
92366 + OUT UCHAR *BcastFlag,
92367 + OUT UCHAR *DtimCount,
92368 + OUT UCHAR *DtimPeriod,
92369 + OUT UCHAR *MessageToMe)
92370 +{
92371 + UCHAR BitCntl, N1, N2, MyByte, MyBit;
92372 + CHAR *IdxPtr;
92373 +
92374 + IdxPtr = Ptr;
92375 +
92376 + IdxPtr ++;
92377 + *TimLen = *IdxPtr;
92378 +
92379 + // get DTIM Count from TIM element
92380 + IdxPtr ++;
92381 + *DtimCount = *IdxPtr;
92382 +
92383 + // get DTIM Period from TIM element
92384 + IdxPtr++;
92385 + *DtimPeriod = *IdxPtr;
92386 +
92387 + // get Bitmap Control from TIM element
92388 + IdxPtr++;
92389 + BitCntl = *IdxPtr;
92390 +
92391 + if ((*DtimCount == 0) && (BitCntl & 0x01))
92392 + *BcastFlag = TRUE;
92393 + else
92394 + *BcastFlag = FALSE;
92395 +
92396 + // Parse Partial Virtual Bitmap from TIM element
92397 + N1 = BitCntl & 0xfe; // N1 is the first bitmap byte#
92398 + N2 = *TimLen - 4 + N1; // N2 is the last bitmap byte#
92399 +
92400 + if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))
92401 + *MessageToMe = FALSE;
92402 + else
92403 + {
92404 + MyByte = (Aid >> 3) - N1; // my byte position in the bitmap byte-stream
92405 + MyBit = Aid % 16 - ((MyByte & 0x01)? 8:0);
92406 +
92407 + IdxPtr += (MyByte + 1);
92408 +
92409 + //if (*IdxPtr)
92410 + // DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr));
92411 +
92412 + if (*IdxPtr & (0x01 << MyBit))
92413 + *MessageToMe = TRUE;
92414 + else
92415 + *MessageToMe = FALSE;
92416 + }
92417 +
92418 + return TRUE;
92419 +}
92420 +
92421 --- /dev/null
92422 +++ b/drivers/staging/rt2870/sta/sync.c
92423 @@ -0,0 +1,1753 @@
92424 +/*
92425 + *************************************************************************
92426 + * Ralink Tech Inc.
92427 + * 5F., No.36, Taiyuan St., Jhubei City,
92428 + * Hsinchu County 302,
92429 + * Taiwan, R.O.C.
92430 + *
92431 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
92432 + *
92433 + * This program is free software; you can redistribute it and/or modify *
92434 + * it under the terms of the GNU General Public License as published by *
92435 + * the Free Software Foundation; either version 2 of the License, or *
92436 + * (at your option) any later version. *
92437 + * *
92438 + * This program is distributed in the hope that it will be useful, *
92439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
92440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
92441 + * GNU General Public License for more details. *
92442 + * *
92443 + * You should have received a copy of the GNU General Public License *
92444 + * along with this program; if not, write to the *
92445 + * Free Software Foundation, Inc., *
92446 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
92447 + * *
92448 + *************************************************************************
92449 +
92450 + Module Name:
92451 + sync.c
92452 +
92453 + Abstract:
92454 +
92455 + Revision History:
92456 + Who When What
92457 + -------- ---------- ----------------------------------------------
92458 + John Chang 2004-09-01 modified for rt2561/2661
92459 + Jan Lee 2006-08-01 modified for rt2860 for 802.11n
92460 +*/
92461 +#include "../rt_config.h"
92462 +
92463 +#define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) // 2 sec
92464 +
92465 +/*
92466 + ==========================================================================
92467 + Description:
92468 + The sync state machine,
92469 + Parameters:
92470 + Sm - pointer to the state machine
92471 + Note:
92472 + the state machine looks like the following
92473 +
92474 + ==========================================================================
92475 + */
92476 +VOID SyncStateMachineInit(
92477 + IN PRTMP_ADAPTER pAd,
92478 + IN STATE_MACHINE *Sm,
92479 + OUT STATE_MACHINE_FUNC Trans[])
92480 +{
92481 + StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG, (STATE_MACHINE_FUNC)Drop, SYNC_IDLE, SYNC_MACHINE_BASE);
92482 +
92483 + // column 1
92484 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)MlmeScanReqAction);
92485 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)MlmeJoinReqAction);
92486 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)MlmeStartReqAction);
92487 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeacon);
92488 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ, (STATE_MACHINE_FUNC)PeerProbeReqAction);
92489 +
92490 + //column 2
92491 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
92492 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
92493 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
92494 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtJoinAction);
92495 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT, (STATE_MACHINE_FUNC)BeaconTimeoutAtJoinAction);
92496 +
92497 + // column 3
92498 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
92499 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
92500 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
92501 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
92502 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
92503 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT, (STATE_MACHINE_FUNC)ScanTimeoutAction);
92504 +
92505 + // timer init
92506 + RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer, GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE);
92507 + RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer, GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE);
92508 +}
92509 +
92510 +/*
92511 + ==========================================================================
92512 + Description:
92513 + Beacon timeout handler, executed in timer thread
92514 +
92515 + IRQL = DISPATCH_LEVEL
92516 +
92517 + ==========================================================================
92518 + */
92519 +VOID BeaconTimeout(
92520 + IN PVOID SystemSpecific1,
92521 + IN PVOID FunctionContext,
92522 + IN PVOID SystemSpecific2,
92523 + IN PVOID SystemSpecific3)
92524 +{
92525 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
92526 +
92527 + DBGPRINT(RT_DEBUG_TRACE,("SYNC - BeaconTimeout\n"));
92528 +
92529 + // Do nothing if the driver is starting halt state.
92530 + // This might happen when timer already been fired before cancel timer with mlmehalt
92531 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
92532 + return;
92533 +
92534 +#ifdef DOT11_N_SUPPORT
92535 + if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
92536 + )
92537 + {
92538 + UCHAR BBPValue = 0;
92539 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
92540 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
92541 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
92542 + BBPValue &= (~0x18);
92543 + BBPValue |= 0x10;
92544 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
92545 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
92546 + }
92547 +#endif // DOT11_N_SUPPORT //
92548 +
92549 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL);
92550 + RT28XX_MLME_HANDLER(pAd);
92551 +}
92552 +
92553 +/*
92554 + ==========================================================================
92555 + Description:
92556 + Scan timeout handler, executed in timer thread
92557 +
92558 + IRQL = DISPATCH_LEVEL
92559 +
92560 + ==========================================================================
92561 + */
92562 +VOID ScanTimeout(
92563 + IN PVOID SystemSpecific1,
92564 + IN PVOID FunctionContext,
92565 + IN PVOID SystemSpecific2,
92566 + IN PVOID SystemSpecific3)
92567 +{
92568 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
92569 +
92570 +
92571 + // Do nothing if the driver is starting halt state.
92572 + // This might happen when timer already been fired before cancel timer with mlmehalt
92573 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
92574 + return;
92575 +
92576 + if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL))
92577 + {
92578 + RT28XX_MLME_HANDLER(pAd);
92579 + }
92580 + else
92581 + {
92582 + // To prevent SyncMachine.CurrState is SCAN_LISTEN forever.
92583 + pAd->MlmeAux.Channel = 0;
92584 + ScanNextChannel(pAd);
92585 + if (pAd->CommonCfg.bWirelessEvent)
92586 + {
92587 + RTMPSendWirelessEvent(pAd, IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
92588 + }
92589 + }
92590 +}
92591 +
92592 +/*
92593 + ==========================================================================
92594 + Description:
92595 + MLME SCAN req state machine procedure
92596 + ==========================================================================
92597 + */
92598 +VOID MlmeScanReqAction(
92599 + IN PRTMP_ADAPTER pAd,
92600 + IN MLME_QUEUE_ELEM *Elem)
92601 +{
92602 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0;
92603 + BOOLEAN TimerCancelled;
92604 + ULONG Now;
92605 + USHORT Status;
92606 + PHEADER_802_11 pHdr80211;
92607 + PUCHAR pOutBuffer = NULL;
92608 + NDIS_STATUS NStatus;
92609 +
92610 + // Check the total scan tries for one single OID command
92611 + // If this is the CCX 2.0 Case, skip that!
92612 + if ( !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
92613 + {
92614 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeScanReqAction before Startup\n"));
92615 + return;
92616 + }
92617 +
92618 + // Increase the scan retry counters.
92619 + pAd->StaCfg.ScanCnt++;
92620 +
92621 +
92622 + // first check the parameter sanity
92623 + if (MlmeScanReqSanity(pAd,
92624 + Elem->Msg,
92625 + Elem->MsgLen,
92626 + &BssType,
92627 + Ssid,
92628 + &SsidLen,
92629 + &ScanType))
92630 + {
92631 +
92632 + // Check for channel load and noise hist request
92633 + // Suspend MSDU only at scan request, not the last two mentioned
92634 + if ((ScanType == SCAN_CISCO_NOISE) || (ScanType == SCAN_CISCO_CHANNEL_LOAD))
92635 + {
92636 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
92637 + RTMPSuspendMsduTransmission(pAd); // Suspend MSDU transmission here
92638 + }
92639 + else
92640 + {
92641 + // Suspend MSDU transmission here
92642 + RTMPSuspendMsduTransmission(pAd);
92643 + }
92644 +
92645 + //
92646 + // To prevent data lost.
92647 + // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.
92648 + // And should send an NULL data with turned PSM bit off to AP, when scan progress done
92649 + //
92650 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))
92651 + {
92652 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);
92653 + if (NStatus == NDIS_STATUS_SUCCESS)
92654 + {
92655 + pHdr80211 = (PHEADER_802_11) pOutBuffer;
92656 + MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
92657 + pHdr80211->Duration = 0;
92658 + pHdr80211->FC.Type = BTYPE_DATA;
92659 + pHdr80211->FC.PwrMgmt = PWR_SAVE;
92660 +
92661 + // Send using priority queue
92662 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
92663 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n"));
92664 + MlmeFreeMemory(pAd, pOutBuffer);
92665 + RTMPusecDelay(5000);
92666 + }
92667 + }
92668 +
92669 + NdisGetSystemUpTime(&Now);
92670 + pAd->StaCfg.LastScanTime = Now;
92671 + // reset all the timers
92672 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
92673 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
92674 +
92675 + // record desired BSS parameters
92676 + pAd->MlmeAux.BssType = BssType;
92677 + pAd->MlmeAux.ScanType = ScanType;
92678 + pAd->MlmeAux.SsidLen = SsidLen;
92679 + NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
92680 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
92681 +
92682 + // start from the first channel
92683 + pAd->MlmeAux.Channel = FirstChannel(pAd);
92684 +
92685 + // Change the scan channel when dealing with CCX beacon report
92686 + if ((ScanType == SCAN_CISCO_PASSIVE) || (ScanType == SCAN_CISCO_ACTIVE) ||
92687 + (ScanType == SCAN_CISCO_CHANNEL_LOAD) || (ScanType == SCAN_CISCO_NOISE))
92688 + pAd->MlmeAux.Channel = pAd->StaCfg.CCXScanChannel;
92689 +
92690 + // Let BBP register at 20MHz to do scan
92691 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
92692 + BBPValue &= (~0x18);
92693 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
92694 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
92695 + ScanNextChannel(pAd);
92696 + }
92697 + else
92698 + {
92699 + DBGPRINT_ERR(("SYNC - MlmeScanReqAction() sanity check fail\n"));
92700 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
92701 + Status = MLME_INVALID_FORMAT;
92702 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
92703 + }
92704 +}
92705 +
92706 +/*
92707 + ==========================================================================
92708 + Description:
92709 + MLME JOIN req state machine procedure
92710 + ==========================================================================
92711 + */
92712 +VOID MlmeJoinReqAction(
92713 + IN PRTMP_ADAPTER pAd,
92714 + IN MLME_QUEUE_ELEM *Elem)
92715 +{
92716 + UCHAR BBPValue = 0;
92717 + BSS_ENTRY *pBss;
92718 + BOOLEAN TimerCancelled;
92719 + HEADER_802_11 Hdr80211;
92720 + NDIS_STATUS NStatus;
92721 + ULONG FrameLen = 0;
92722 + PUCHAR pOutBuffer = NULL;
92723 + PUCHAR pSupRate = NULL;
92724 + UCHAR SupRateLen;
92725 + PUCHAR pExtRate = NULL;
92726 + UCHAR ExtRateLen;
92727 + UCHAR ASupRate[] = {0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C};
92728 + UCHAR ASupRateLen = sizeof(ASupRate)/sizeof(UCHAR);
92729 + MLME_JOIN_REQ_STRUCT *pInfo = (MLME_JOIN_REQ_STRUCT *)(Elem->Msg);
92730 +
92731 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx));
92732 +
92733 +
92734 + // reset all the timers
92735 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
92736 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
92737 +
92738 + pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx];
92739 +
92740 + // record the desired SSID & BSSID we're waiting for
92741 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid);
92742 +
92743 + // If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again.
92744 + if (pBss->Hidden == 0)
92745 + {
92746 + NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen);
92747 + pAd->MlmeAux.SsidLen = pBss->SsidLen;
92748 + }
92749 +
92750 + pAd->MlmeAux.BssType = pBss->BssType;
92751 + pAd->MlmeAux.Channel = pBss->Channel;
92752 + pAd->MlmeAux.CentralChannel = pBss->CentralChannel;
92753 +
92754 +#ifdef EXT_BUILD_CHANNEL_LIST
92755 + // Country IE of the AP will be evaluated and will be used.
92756 + if ((pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None) &&
92757 + (pBss->bHasCountryIE == TRUE))
92758 + {
92759 + NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pBss->CountryString[0], 2);
92760 + if (pBss->CountryString[2] == 'I')
92761 + pAd->CommonCfg.Geography = IDOR;
92762 + else if (pBss->CountryString[2] == 'O')
92763 + pAd->CommonCfg.Geography = ODOR;
92764 + else
92765 + pAd->CommonCfg.Geography = BOTH;
92766 + BuildChannelListEx(pAd);
92767 + }
92768 +#endif // EXT_BUILD_CHANNEL_LIST //
92769 +
92770 + // Let BBP register at 20MHz to do scan
92771 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
92772 + BBPValue &= (~0x18);
92773 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
92774 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
92775 +
92776 + // switch channel and waiting for beacon timer
92777 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
92778 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
92779 + RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT);
92780 +
92781 + do
92782 + {
92783 + if (((pAd->CommonCfg.bIEEE80211H == 1) &&
92784 + (pAd->MlmeAux.Channel > 14) &&
92785 + RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
92786 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
92787 + || (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
92788 +#endif // CARRIER_DETECTION_SUPPORT //
92789 + )
92790 + {
92791 + //
92792 + // We can't send any Probe request frame to meet 802.11h.
92793 + //
92794 + if (pBss->Hidden == 0)
92795 + break;
92796 + }
92797 +
92798 + //
92799 + // send probe request
92800 + //
92801 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
92802 + if (NStatus == NDIS_STATUS_SUCCESS)
92803 + {
92804 + if (pAd->MlmeAux.Channel <= 14)
92805 + {
92806 + pSupRate = pAd->CommonCfg.SupRate;
92807 + SupRateLen = pAd->CommonCfg.SupRateLen;
92808 + pExtRate = pAd->CommonCfg.ExtRate;
92809 + ExtRateLen = pAd->CommonCfg.ExtRateLen;
92810 + }
92811 + else
92812 + {
92813 + //
92814 + // Overwrite Support Rate, CCK rate are not allowed
92815 + //
92816 + pSupRate = ASupRate;
92817 + SupRateLen = ASupRateLen;
92818 + ExtRateLen = 0;
92819 + }
92820 +
92821 + if (pAd->MlmeAux.BssType == BSS_INFRA)
92822 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, pAd->MlmeAux.Bssid, pAd->MlmeAux.Bssid);
92823 + else
92824 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
92825 +
92826 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
92827 + sizeof(HEADER_802_11), &Hdr80211,
92828 + 1, &SsidIe,
92829 + 1, &pAd->MlmeAux.SsidLen,
92830 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
92831 + 1, &SupRateIe,
92832 + 1, &SupRateLen,
92833 + SupRateLen, pSupRate,
92834 + END_OF_ARGS);
92835 +
92836 + if (ExtRateLen)
92837 + {
92838 + ULONG Tmp;
92839 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
92840 + 1, &ExtRateIe,
92841 + 1, &ExtRateLen,
92842 + ExtRateLen, pExtRate,
92843 + END_OF_ARGS);
92844 + FrameLen += Tmp;
92845 + }
92846 +
92847 +
92848 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
92849 + MlmeFreeMemory(pAd, pOutBuffer);
92850 + }
92851 + } while (FALSE);
92852 +
92853 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Switch to ch %d, Wait BEACON from %02x:%02x:%02x:%02x:%02x:%02x\n",
92854 + pBss->Channel, pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2], pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
92855 +
92856 + pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON;
92857 +}
92858 +
92859 +/*
92860 + ==========================================================================
92861 + Description:
92862 + MLME START Request state machine procedure, starting an IBSS
92863 + ==========================================================================
92864 + */
92865 +VOID MlmeStartReqAction(
92866 + IN PRTMP_ADAPTER pAd,
92867 + IN MLME_QUEUE_ELEM *Elem)
92868 +{
92869 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen;
92870 + BOOLEAN TimerCancelled;
92871 +
92872 + // New for WPA security suites
92873 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
92874 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
92875 + LARGE_INTEGER TimeStamp;
92876 + BOOLEAN Privacy;
92877 + USHORT Status;
92878 +
92879 + // Init Variable IE structure
92880 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
92881 + pVIE->Length = 0;
92882 + TimeStamp.u.LowPart = 0;
92883 + TimeStamp.u.HighPart = 0;
92884 +
92885 + if (MlmeStartReqSanity(pAd, Elem->Msg, Elem->MsgLen, Ssid, &SsidLen))
92886 + {
92887 + // reset all the timers
92888 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
92889 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
92890 +
92891 + //
92892 + // Start a new IBSS. All IBSS parameters are decided now....
92893 + //
92894 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n"));
92895 + pAd->MlmeAux.BssType = BSS_ADHOC;
92896 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
92897 + pAd->MlmeAux.SsidLen = SsidLen;
92898 +
92899 + // generate a radom number as BSSID
92900 + MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid);
92901 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - generate a radom number as BSSID \n"));
92902 +
92903 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
92904 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
92905 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
92906 + pAd->MlmeAux.CapabilityInfo = CAP_GENERATE(0,1,Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 1, 0);
92907 + pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod;
92908 + pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin;
92909 + pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;
92910 +
92911 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
92912 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel;
92913 +
92914 + pAd->MlmeAux.SupRateLen= pAd->CommonCfg.SupRateLen;
92915 + NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
92916 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
92917 + pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen;
92918 + NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
92919 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
92920 +#ifdef DOT11_N_SUPPORT
92921 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
92922 + {
92923 + RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy, &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0], &pAd->MlmeAux.HtCapability, &pAd->MlmeAux.AddHtInfo);
92924 + pAd->MlmeAux.HtCapabilityLen = sizeof(HT_CAPABILITY_IE);
92925 + // Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here.
92926 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n"));
92927 + }
92928 + else
92929 +#endif // DOT11_N_SUPPORT //
92930 + {
92931 + pAd->MlmeAux.HtCapabilityLen = 0;
92932 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
92933 + }
92934 + // temporarily not support QOS in IBSS
92935 + NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
92936 + NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
92937 + NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
92938 +
92939 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
92940 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
92941 +
92942 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n",
92943 + pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
92944 +
92945 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
92946 + Status = MLME_SUCCESS;
92947 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
92948 + }
92949 + else
92950 + {
92951 + DBGPRINT_ERR(("SYNC - MlmeStartReqAction() sanity check fail.\n"));
92952 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
92953 + Status = MLME_INVALID_FORMAT;
92954 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
92955 + }
92956 +}
92957 +
92958 +/*
92959 + ==========================================================================
92960 + Description:
92961 + peer sends beacon back when scanning
92962 + ==========================================================================
92963 + */
92964 +VOID PeerBeaconAtScanAction(
92965 + IN PRTMP_ADAPTER pAd,
92966 + IN MLME_QUEUE_ELEM *Elem)
92967 +{
92968 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
92969 + UCHAR Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel,
92970 + SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe;
92971 + CF_PARM CfParm;
92972 + USHORT BeaconPeriod, AtimWin, CapabilityInfo;
92973 + PFRAME_802_11 pFrame;
92974 + LARGE_INTEGER TimeStamp;
92975 + UCHAR Erp;
92976 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
92977 + UCHAR SupRateLen, ExtRateLen;
92978 + USHORT LenVIE;
92979 + UCHAR CkipFlag;
92980 + UCHAR AironetCellPowerLimit;
92981 + EDCA_PARM EdcaParm;
92982 + QBSS_LOAD_PARM QbssLoad;
92983 + QOS_CAPABILITY_PARM QosCapability;
92984 + ULONG RalinkIe;
92985 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
92986 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
92987 + HT_CAPABILITY_IE HtCapability;
92988 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
92989 + UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
92990 + UCHAR AddHtInfoLen;
92991 + UCHAR NewExtChannelOffset = 0xff;
92992 +
92993 +
92994 + // NdisFillMemory(Ssid, MAX_LEN_OF_SSID, 0x00);
92995 + pFrame = (PFRAME_802_11) Elem->Msg;
92996 + // Init Variable IE structure
92997 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
92998 + pVIE->Length = 0;
92999 +#ifdef DOT11_N_SUPPORT
93000 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
93001 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
93002 +#endif // DOT11_N_SUPPORT //
93003 +
93004 + if (PeerBeaconAndProbeRspSanity(pAd,
93005 + Elem->Msg,
93006 + Elem->MsgLen,
93007 + Elem->Channel,
93008 + Addr2,
93009 + Bssid,
93010 + Ssid,
93011 + &SsidLen,
93012 + &BssType,
93013 + &BeaconPeriod,
93014 + &Channel,
93015 + &NewChannel,
93016 + &TimeStamp,
93017 + &CfParm,
93018 + &AtimWin,
93019 + &CapabilityInfo,
93020 + &Erp,
93021 + &DtimCount,
93022 + &DtimPeriod,
93023 + &BcastFlag,
93024 + &MessageToMe,
93025 + SupRate,
93026 + &SupRateLen,
93027 + ExtRate,
93028 + &ExtRateLen,
93029 + &CkipFlag,
93030 + &AironetCellPowerLimit,
93031 + &EdcaParm,
93032 + &QbssLoad,
93033 + &QosCapability,
93034 + &RalinkIe,
93035 + &HtCapabilityLen,
93036 + &PreNHtCapabilityLen,
93037 + &HtCapability,
93038 + &AddHtInfoLen,
93039 + &AddHtInfo,
93040 + &NewExtChannelOffset,
93041 + &LenVIE,
93042 + pVIE))
93043 + {
93044 + ULONG Idx;
93045 + CHAR Rssi = 0;
93046 +
93047 + Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
93048 + if (Idx != BSS_NOT_FOUND)
93049 + Rssi = pAd->ScanTab.BssEntry[Idx].Rssi;
93050 +
93051 + Rssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
93052 +
93053 +
93054 +#ifdef DOT11_N_SUPPORT
93055 + if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
93056 + HtCapabilityLen = SIZE_HT_CAP_IE;
93057 +#endif // DOT11_N_SUPPORT //
93058 + if ((pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) && (Channel == pAd->StaCfg.CCXScanChannel))
93059 + {
93060 + Idx = BssTableSetEntry(pAd, &pAd->StaCfg.CCXBssTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
93061 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen,ExtRate, ExtRateLen, &HtCapability,
93062 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
93063 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
93064 + if (Idx != BSS_NOT_FOUND)
93065 + {
93066 + NdisMoveMemory(pAd->StaCfg.CCXBssTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
93067 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
93068 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
93069 + if (pAd->StaCfg.CCXReqType == MSRN_TYPE_BEACON_REQ)
93070 + AironetAddBeaconReport(pAd, Idx, Elem);
93071 + }
93072 + }
93073 + else
93074 + {
93075 + Idx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
93076 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
93077 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
93078 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
93079 +#ifdef DOT11_N_SUPPORT
93080 +#ifdef DOT11N_DRAFT3
93081 + if (pAd->ChannelList[pAd->CommonCfg.ChannelListIdx].bEffectedChannel == TRUE)
93082 + {
93083 + UCHAR RegClass;
93084 + PeerBeaconAndProbeRspSanity2(pAd, Elem->Msg, Elem->MsgLen, &RegClass);
93085 + TriEventTableSetEntry(pAd, &pAd->CommonCfg.TriggerEventTab, Bssid, &HtCapability, HtCapabilityLen, RegClass, Channel);
93086 + }
93087 +#endif // DOT11N_DRAFT3 //
93088 +#endif // DOT11_N_SUPPORT //
93089 + if (Idx != BSS_NOT_FOUND)
93090 + {
93091 + NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
93092 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
93093 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
93094 + }
93095 + }
93096 + }
93097 + // sanity check fail, ignored
93098 +}
93099 +
93100 +/*
93101 + ==========================================================================
93102 + Description:
93103 + When waiting joining the (I)BSS, beacon received from external
93104 + ==========================================================================
93105 + */
93106 +VOID PeerBeaconAtJoinAction(
93107 + IN PRTMP_ADAPTER pAd,
93108 + IN MLME_QUEUE_ELEM *Elem)
93109 +{
93110 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
93111 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe,
93112 + DtimCount, DtimPeriod, BcastFlag, NewChannel;
93113 + LARGE_INTEGER TimeStamp;
93114 + USHORT BeaconPeriod, AtimWin, CapabilityInfo;
93115 + CF_PARM Cf;
93116 + BOOLEAN TimerCancelled;
93117 + UCHAR Erp;
93118 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
93119 + UCHAR SupRateLen, ExtRateLen;
93120 + UCHAR CkipFlag;
93121 + USHORT LenVIE;
93122 + UCHAR AironetCellPowerLimit;
93123 + EDCA_PARM EdcaParm;
93124 + QBSS_LOAD_PARM QbssLoad;
93125 + QOS_CAPABILITY_PARM QosCapability;
93126 + USHORT Status;
93127 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
93128 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
93129 + ULONG RalinkIe;
93130 + ULONG Idx;
93131 + HT_CAPABILITY_IE HtCapability;
93132 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
93133 + UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
93134 + UCHAR AddHtInfoLen;
93135 + UCHAR NewExtChannelOffset = 0xff;
93136 +#ifdef DOT11_N_SUPPORT
93137 + UCHAR CentralChannel;
93138 +#endif // DOT11_N_SUPPORT //
93139 +
93140 + // Init Variable IE structure
93141 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
93142 + pVIE->Length = 0;
93143 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
93144 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
93145 +
93146 +
93147 + if (PeerBeaconAndProbeRspSanity(pAd,
93148 + Elem->Msg,
93149 + Elem->MsgLen,
93150 + Elem->Channel,
93151 + Addr2,
93152 + Bssid,
93153 + Ssid,
93154 + &SsidLen,
93155 + &BssType,
93156 + &BeaconPeriod,
93157 + &Channel,
93158 + &NewChannel,
93159 + &TimeStamp,
93160 + &Cf,
93161 + &AtimWin,
93162 + &CapabilityInfo,
93163 + &Erp,
93164 + &DtimCount,
93165 + &DtimPeriod,
93166 + &BcastFlag,
93167 + &MessageToMe,
93168 + SupRate,
93169 + &SupRateLen,
93170 + ExtRate,
93171 + &ExtRateLen,
93172 + &CkipFlag,
93173 + &AironetCellPowerLimit,
93174 + &EdcaParm,
93175 + &QbssLoad,
93176 + &QosCapability,
93177 + &RalinkIe,
93178 + &HtCapabilityLen,
93179 + &PreNHtCapabilityLen,
93180 + &HtCapability,
93181 + &AddHtInfoLen,
93182 + &AddHtInfo,
93183 + &NewExtChannelOffset,
93184 + &LenVIE,
93185 + pVIE))
93186 + {
93187 + // Disqualify 11b only adhoc when we are in 11g only adhoc mode
93188 + if ((BssType == BSS_ADHOC) && (pAd->CommonCfg.PhyMode == PHY_11G) && ((SupRateLen+ExtRateLen)< 12))
93189 + return;
93190 +
93191 + // BEACON from desired BSS/IBSS found. We should be able to decide most
93192 + // BSS parameters here.
93193 + // Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATEION?
93194 + // Do we need to receover back all parameters belonging to previous BSS?
93195 + // A. Should be not. There's no back-door recover to previous AP. It still need
93196 + // a new JOIN-AUTH-ASSOC sequence.
93197 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid))
93198 + {
93199 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n", Channel));
93200 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
93201 +
93202 + // Update RSSI to prevent No signal display when cards first initialized
93203 + pAd->StaCfg.RssiSample.LastRssi0 = ConvertToRssi(pAd, Elem->Rssi0, RSSI_0);
93204 + pAd->StaCfg.RssiSample.LastRssi1 = ConvertToRssi(pAd, Elem->Rssi1, RSSI_1);
93205 + pAd->StaCfg.RssiSample.LastRssi2 = ConvertToRssi(pAd, Elem->Rssi2, RSSI_2);
93206 + pAd->StaCfg.RssiSample.AvgRssi0 = pAd->StaCfg.RssiSample.LastRssi0;
93207 + pAd->StaCfg.RssiSample.AvgRssi0X8 = pAd->StaCfg.RssiSample.AvgRssi0 << 3;
93208 + pAd->StaCfg.RssiSample.AvgRssi1 = pAd->StaCfg.RssiSample.LastRssi1;
93209 + pAd->StaCfg.RssiSample.AvgRssi1X8 = pAd->StaCfg.RssiSample.AvgRssi1 << 3;
93210 + pAd->StaCfg.RssiSample.AvgRssi2 = pAd->StaCfg.RssiSample.LastRssi2;
93211 + pAd->StaCfg.RssiSample.AvgRssi2X8 = pAd->StaCfg.RssiSample.AvgRssi2 << 3;
93212 +
93213 + //
93214 + // We need to check if SSID only set to any, then we can record the current SSID.
93215 + // Otherwise will cause hidden SSID association failed.
93216 + //
93217 + if (pAd->MlmeAux.SsidLen == 0)
93218 + {
93219 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
93220 + pAd->MlmeAux.SsidLen = SsidLen;
93221 + }
93222 + else
93223 + {
93224 + Idx = BssSsidTableSearch(&pAd->ScanTab, Bssid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Channel);
93225 +
93226 + if (Idx != BSS_NOT_FOUND)
93227 + {
93228 + //
93229 + // Multiple SSID case, used correct CapabilityInfo
93230 + //
93231 + CapabilityInfo = pAd->ScanTab.BssEntry[Idx].CapabilityInfo;
93232 + }
93233 + }
93234 + NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN);
93235 + pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
93236 + pAd->MlmeAux.BssType = BssType;
93237 + pAd->MlmeAux.BeaconPeriod = BeaconPeriod;
93238 + pAd->MlmeAux.Channel = Channel;
93239 + pAd->MlmeAux.AtimWin = AtimWin;
93240 + pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod;
93241 + pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;
93242 + pAd->MlmeAux.APRalinkIe = RalinkIe;
93243 +
93244 + // Copy AP's supported rate to MlmeAux for creating assoication request
93245 + // Also filter out not supported rate
93246 + pAd->MlmeAux.SupRateLen = SupRateLen;
93247 + NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
93248 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
93249 + pAd->MlmeAux.ExtRateLen = ExtRateLen;
93250 + NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
93251 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
93252 +
93253 + NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, 16);
93254 +#ifdef DOT11_N_SUPPORT
93255 + pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
93256 + pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen;
93257 +
93258 + // filter out un-supported ht rates
93259 + if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
93260 + {
93261 + RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
93262 + RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo, &AddHtInfo, SIZE_ADD_HT_INFO_IE);
93263 +
93264 + // StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability
93265 + NdisMoveMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, HtCapability.MCSSet, 16);
93266 + pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
93267 + pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE;
93268 + pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
93269 + if (PreNHtCapabilityLen > 0)
93270 + pAd->StaActive.SupportedPhyInfo.bPreNHt = TRUE;
93271 + RTMPCheckHt(pAd, BSSID_WCID, &HtCapability, &AddHtInfo);
93272 + // Copy AP Parameter to StaActive. This is also in LinkUp.
93273 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n",
93274 + pAd->StaActive.SupportedHtPhy.MpduDensity, pAd->StaActive.SupportedHtPhy.MaxRAmpduFactor, HtCapability.HtCapInfo.ChannelWidth));
93275 +
93276 + if (AddHtInfoLen > 0)
93277 + {
93278 + CentralChannel = AddHtInfo.ControlChan;
93279 + // Check again the Bandwidth capability of this AP.
93280 + if ((AddHtInfo.ControlChan > 2)&& (AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
93281 + {
93282 + CentralChannel = AddHtInfo.ControlChan - 2;
93283 + }
93284 + else if ((AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
93285 + {
93286 + CentralChannel = AddHtInfo.ControlChan + 2;
93287 + }
93288 +
93289 + // Check Error .
93290 + if (pAd->MlmeAux.CentralChannel != CentralChannel)
93291 + DBGPRINT(RT_DEBUG_ERROR, ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n", CentralChannel, AddHtInfo.ControlChan, pAd->MlmeAux.CentralChannel));
93292 +
93293 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n", CentralChannel, AddHtInfo.ControlChan));
93294 +
93295 + }
93296 +
93297 + }
93298 + else
93299 +#endif // DOT11_N_SUPPORT //
93300 + {
93301 + // To prevent error, let legacy AP must have same CentralChannel and Channel.
93302 + if ((HtCapabilityLen == 0) && (PreNHtCapabilityLen == 0))
93303 + pAd->MlmeAux.CentralChannel = pAd->MlmeAux.Channel;
93304 +
93305 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
93306 + RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
93307 + RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo, SIZE_ADD_HT_INFO_IE);
93308 + }
93309 +
93310 + RTMPUpdateMlmeRate(pAd);
93311 +
93312 + // copy QOS related information
93313 + if ((pAd->CommonCfg.bWmmCapable)
93314 +#ifdef DOT11_N_SUPPORT
93315 + || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
93316 +#endif // DOT11_N_SUPPORT //
93317 + )
93318 + {
93319 + NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, &EdcaParm, sizeof(EDCA_PARM));
93320 + NdisMoveMemory(&pAd->MlmeAux.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
93321 + NdisMoveMemory(&pAd->MlmeAux.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
93322 + }
93323 + else
93324 + {
93325 + NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
93326 + NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
93327 + NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
93328 + }
93329 +
93330 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n",
93331 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
93332 +
93333 +#ifdef LEAP_SUPPORT
93334 + // Update CkipFlag
93335 + pAd->StaCfg.CkipFlag = CkipFlag;
93336 +
93337 + // Keep TimeStamp for Re-Association used.
93338 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
93339 + pAd->StaCfg.CCKMBeaconAtJoinTimeStamp = TimeStamp;
93340 +#endif // LEAP_SUPPORT //
93341 +
93342 + if (AironetCellPowerLimit != 0xFF)
93343 + {
93344 + //We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power
93345 + ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
93346 + }
93347 + else //Used the default TX Power Percentage.
93348 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
93349 +
93350 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93351 + Status = MLME_SUCCESS;
93352 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
93353 + }
93354 + // not to me BEACON, ignored
93355 + }
93356 + // sanity check fail, ignore this frame
93357 +}
93358 +
93359 +/*
93360 + ==========================================================================
93361 + Description:
93362 + receive BEACON from peer
93363 +
93364 + IRQL = DISPATCH_LEVEL
93365 +
93366 + ==========================================================================
93367 + */
93368 +VOID PeerBeacon(
93369 + IN PRTMP_ADAPTER pAd,
93370 + IN MLME_QUEUE_ELEM *Elem)
93371 +{
93372 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
93373 + CHAR Ssid[MAX_LEN_OF_SSID];
93374 + CF_PARM CfParm;
93375 + UCHAR SsidLen, MessageToMe=0, BssType, Channel, NewChannel, index=0;
93376 + UCHAR DtimCount=0, DtimPeriod=0, BcastFlag=0;
93377 + USHORT CapabilityInfo, AtimWin, BeaconPeriod;
93378 + LARGE_INTEGER TimeStamp;
93379 + USHORT TbttNumToNextWakeUp;
93380 + UCHAR Erp;
93381 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
93382 + UCHAR SupRateLen, ExtRateLen;
93383 + UCHAR CkipFlag;
93384 + USHORT LenVIE;
93385 + UCHAR AironetCellPowerLimit;
93386 + EDCA_PARM EdcaParm;
93387 + QBSS_LOAD_PARM QbssLoad;
93388 + QOS_CAPABILITY_PARM QosCapability;
93389 + ULONG RalinkIe;
93390 + // New for WPA security suites
93391 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
93392 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
93393 + HT_CAPABILITY_IE HtCapability;
93394 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
93395 + UCHAR HtCapabilityLen, PreNHtCapabilityLen;
93396 + UCHAR AddHtInfoLen;
93397 + UCHAR NewExtChannelOffset = 0xff;
93398 +
93399 +
93400 +#ifdef RALINK_ATE
93401 + if (ATE_ON(pAd))
93402 + {
93403 + return;
93404 + }
93405 +#endif // RALINK_ATE //
93406 +
93407 + if (!(INFRA_ON(pAd) || ADHOC_ON(pAd)
93408 + ))
93409 + return;
93410 +
93411 + // Init Variable IE structure
93412 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
93413 + pVIE->Length = 0;
93414 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
93415 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
93416 +
93417 + if (PeerBeaconAndProbeRspSanity(pAd,
93418 + Elem->Msg,
93419 + Elem->MsgLen,
93420 + Elem->Channel,
93421 + Addr2,
93422 + Bssid,
93423 + Ssid,
93424 + &SsidLen,
93425 + &BssType,
93426 + &BeaconPeriod,
93427 + &Channel,
93428 + &NewChannel,
93429 + &TimeStamp,
93430 + &CfParm,
93431 + &AtimWin,
93432 + &CapabilityInfo,
93433 + &Erp,
93434 + &DtimCount,
93435 + &DtimPeriod,
93436 + &BcastFlag,
93437 + &MessageToMe,
93438 + SupRate,
93439 + &SupRateLen,
93440 + ExtRate,
93441 + &ExtRateLen,
93442 + &CkipFlag,
93443 + &AironetCellPowerLimit,
93444 + &EdcaParm,
93445 + &QbssLoad,
93446 + &QosCapability,
93447 + &RalinkIe,
93448 + &HtCapabilityLen,
93449 + &PreNHtCapabilityLen,
93450 + &HtCapability,
93451 + &AddHtInfoLen,
93452 + &AddHtInfo,
93453 + &NewExtChannelOffset,
93454 + &LenVIE,
93455 + pVIE))
93456 + {
93457 + BOOLEAN is_my_bssid, is_my_ssid;
93458 + ULONG Bssidx, Now;
93459 + BSS_ENTRY *pBss;
93460 + CHAR RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
93461 +
93462 + is_my_bssid = MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid)? TRUE : FALSE;
93463 + is_my_ssid = SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen)? TRUE:FALSE;
93464 +
93465 +
93466 + // ignore BEACON not for my SSID
93467 + if ((! is_my_ssid) && (! is_my_bssid))
93468 + return;
93469 +
93470 + // It means STA waits disassoc completely from this AP, ignores this beacon.
93471 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC)
93472 + return;
93473 +
93474 +#ifdef DOT11_N_SUPPORT
93475 + // Copy Control channel for this BSSID.
93476 + if (AddHtInfoLen != 0)
93477 + Channel = AddHtInfo.ControlChan;
93478 +
93479 + if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
93480 + HtCapabilityLen = SIZE_HT_CAP_IE;
93481 +#endif // DOT11_N_SUPPORT //
93482 +
93483 + //
93484 + // Housekeeping "SsidBssTab" table for later-on ROAMing usage.
93485 + //
93486 + Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
93487 + if (Bssidx == BSS_NOT_FOUND)
93488 + {
93489 + // discover new AP of this network, create BSS entry
93490 + Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
93491 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,
93492 + &HtCapability, &AddHtInfo,HtCapabilityLen,AddHtInfoLen,NewExtChannelOffset, Channel,
93493 + RealRssi, TimeStamp, CkipFlag, &EdcaParm, &QosCapability,
93494 + &QbssLoad, LenVIE, pVIE);
93495 + if (Bssidx == BSS_NOT_FOUND) // return if BSS table full
93496 + return;
93497 +
93498 + NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF, &Elem->Msg[24], 4);
93499 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
93500 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
93501 +
93502 +
93503 +
93504 + }
93505 +
93506 + if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
93507 + {
93508 + // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
93509 + // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
93510 + AsicSwitchChannel(pAd, 1, FALSE);
93511 + AsicLockChannel(pAd, 1);
93512 + LinkDown(pAd, FALSE);
93513 + MlmeQueueInit(&pAd->Mlme.Queue);
93514 + BssTableInit(&pAd->ScanTab);
93515 + RTMPusecDelay(1000000); // use delay to prevent STA do reassoc
93516 +
93517 + // channel sanity check
93518 + for (index = 0 ; index < pAd->ChannelListNum; index++)
93519 + {
93520 + if (pAd->ChannelList[index].Channel == NewChannel)
93521 + {
93522 + pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
93523 + pAd->CommonCfg.Channel = NewChannel;
93524 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
93525 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
93526 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
93527 + break;
93528 + }
93529 + }
93530 +
93531 + if (index >= pAd->ChannelListNum)
93532 + {
93533 + DBGPRINT_ERR(("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
93534 + }
93535 + }
93536 +
93537 + // if the ssid matched & bssid unmatched, we should select the bssid with large value.
93538 + // This might happened when two STA start at the same time
93539 + if ((! is_my_bssid) && ADHOC_ON(pAd))
93540 + {
93541 + INT i;
93542 +
93543 + // Add the safeguard against the mismatch of adhoc wep status
93544 + if (pAd->StaCfg.WepStatus != pAd->ScanTab.BssEntry[Bssidx].WepStatus)
93545 + {
93546 + return;
93547 + }
93548 +
93549 + // collapse into the ADHOC network which has bigger BSSID value.
93550 + for (i = 0; i < 6; i++)
93551 + {
93552 + if (Bssid[i] > pAd->CommonCfg.Bssid[i])
93553 + {
93554 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - merge to the IBSS with bigger BSSID=%02x:%02x:%02x:%02x:%02x:%02x\n",
93555 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
93556 + AsicDisableSync(pAd);
93557 + COPY_MAC_ADDR(pAd->CommonCfg.Bssid, Bssid);
93558 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
93559 + MakeIbssBeacon(pAd); // re-build BEACON frame
93560 + AsicEnableIbssSync(pAd); // copy BEACON frame to on-chip memory
93561 + is_my_bssid = TRUE;
93562 + break;
93563 + }
93564 + else if (Bssid[i] < pAd->CommonCfg.Bssid[i])
93565 + break;
93566 + }
93567 + }
93568 +
93569 +
93570 + NdisGetSystemUpTime(&Now);
93571 + pBss = &pAd->ScanTab.BssEntry[Bssidx];
93572 + pBss->Rssi = RealRssi; // lastest RSSI
93573 + pBss->LastBeaconRxTime = Now; // last RX timestamp
93574 +
93575 + //
93576 + // BEACON from my BSSID - either IBSS or INFRA network
93577 + //
93578 + if (is_my_bssid)
93579 + {
93580 + RXWI_STRUC RxWI;
93581 +
93582 + pAd->StaCfg.DtimCount = DtimCount;
93583 + pAd->StaCfg.DtimPeriod = DtimPeriod;
93584 + pAd->StaCfg.LastBeaconRxTime = Now;
93585 +
93586 +
93587 + RxWI.RSSI0 = Elem->Rssi0;
93588 + RxWI.RSSI1 = Elem->Rssi1;
93589 + RxWI.RSSI2 = Elem->Rssi2;
93590 +
93591 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI);
93592 + if (AironetCellPowerLimit != 0xFF)
93593 + {
93594 + //
93595 + // We get the Cisco (ccx) "TxPower Limit" required
93596 + // Changed to appropriate TxPower Limit for Ciso Compatible Extensions
93597 + //
93598 + ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
93599 + }
93600 + else
93601 + {
93602 + //
93603 + // AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist.
93604 + // Used the default TX Power Percentage, that set from UI.
93605 + //
93606 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
93607 + }
93608 +
93609 + if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo)))
93610 + {
93611 + UCHAR MaxSupportedRateIn500Kbps = 0;
93612 + UCHAR idx;
93613 + MAC_TABLE_ENTRY *pEntry;
93614 +
93615 + // supported rates array may not be sorted. sort it and find the maximum rate
93616 + for (idx=0; idx<SupRateLen; idx++)
93617 + {
93618 + if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))
93619 + MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;
93620 + }
93621 +
93622 + for (idx=0; idx<ExtRateLen; idx++)
93623 + {
93624 + if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))
93625 + MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;
93626 + }
93627 +
93628 + // look up the existing table
93629 + pEntry = MacTableLookup(pAd, Addr2);
93630 +
93631 + // Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon.
93632 + // To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station.
93633 + if ((ADHOC_ON(pAd) && (Elem->Wcid == RESERVED_WCID)) ||
93634 + (pEntry && ((pEntry->LastBeaconRxTime + ADHOC_ENTRY_BEACON_LOST_TIME) < Now)))
93635 + {
93636 + if (pEntry == NULL)
93637 + // Another adhoc joining, add to our MAC table.
93638 + pEntry = MacTableInsertEntry(pAd, Addr2, BSS0, FALSE);
93639 +
93640 + if (StaAddMacTableEntry(pAd, pEntry, MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo) == FALSE)
93641 + {
93642 + DBGPRINT(RT_DEBUG_TRACE, ("ADHOC - Add Entry failed.\n"));
93643 + return;
93644 + }
93645 +
93646 + if (pEntry &&
93647 + (Elem->Wcid == RESERVED_WCID))
93648 + {
93649 + idx = pAd->StaCfg.DefaultKeyId;
93650 + RT28XX_STA_SECURITY_INFO_ADD(pAd, BSS0, idx, pEntry);
93651 + }
93652 + }
93653 +
93654 + if (pEntry && pEntry->ValidAsCLI)
93655 + pEntry->LastBeaconRxTime = Now;
93656 +
93657 + // At least another peer in this IBSS, declare MediaState as CONNECTED
93658 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
93659 + {
93660 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
93661 +
93662 + pAd->IndicateMediaState = NdisMediaStateConnected;
93663 + RTMP_IndicateMediaState(pAd);
93664 + pAd->ExtraInfo = GENERAL_LINK_UP;
93665 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
93666 +
93667 + // 2003/03/12 - john
93668 + // Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that
93669 + // "site survey" result should always include the current connected network.
93670 + //
93671 + Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
93672 + if (Bssidx == BSS_NOT_FOUND)
93673 + {
93674 + Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
93675 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
93676 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, RealRssi, TimeStamp, 0,
93677 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
93678 + }
93679 + DBGPRINT(RT_DEBUG_TRACE, ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n"));
93680 + }
93681 + }
93682 +
93683 + if (INFRA_ON(pAd))
93684 + {
93685 + BOOLEAN bUseShortSlot, bUseBGProtection;
93686 +
93687 + // decide to use/change to -
93688 + // 1. long slot (20 us) or short slot (9 us) time
93689 + // 2. turn on/off RTS/CTS and/or CTS-to-self protection
93690 + // 3. short preamble
93691 +
93692 + //bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo);
93693 + bUseShortSlot = CAP_IS_SHORT_SLOT(CapabilityInfo);
93694 + if (bUseShortSlot != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))
93695 + AsicSetSlotTime(pAd, bUseShortSlot);
93696 +
93697 + bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || // always use
93698 + ((pAd->CommonCfg.UseBGProtection == 0) && ERP_IS_USE_PROTECTION(Erp));
93699 +
93700 + if (pAd->CommonCfg.Channel > 14) // always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP
93701 + bUseBGProtection = FALSE;
93702 +
93703 + if (bUseBGProtection != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
93704 + {
93705 + if (bUseBGProtection)
93706 + {
93707 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
93708 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),FALSE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
93709 + }
93710 + else
93711 + {
93712 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
93713 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),TRUE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
93714 + }
93715 +
93716 + DBGPRINT(RT_DEBUG_WARN, ("SYNC - AP changed B/G protection to %d\n", bUseBGProtection));
93717 + }
93718 +
93719 +#ifdef DOT11_N_SUPPORT
93720 + // check Ht protection mode. and adhere to the Non-GF device indication by AP.
93721 + if ((AddHtInfoLen != 0) &&
93722 + ((AddHtInfo.AddHtInfo2.OperaionMode != pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode) ||
93723 + (AddHtInfo.AddHtInfo2.NonGfPresent != pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent)))
93724 + {
93725 + pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent = AddHtInfo.AddHtInfo2.NonGfPresent;
93726 + pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode = AddHtInfo.AddHtInfo2.OperaionMode;
93727 + if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
93728 + {
93729 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
93730 + }
93731 + else
93732 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
93733 +
93734 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP changed N OperaionMode to %d\n", pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode));
93735 + }
93736 +#endif // DOT11_N_SUPPORT //
93737 +
93738 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED) &&
93739 + ERP_IS_USE_BARKER_PREAMBLE(Erp))
93740 + {
93741 + MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
93742 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP forced to use LONG preamble\n"));
93743 + }
93744 +
93745 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
93746 + (EdcaParm.bValid == TRUE) &&
93747 + (EdcaParm.EdcaUpdateCount != pAd->CommonCfg.APEdcaParm.EdcaUpdateCount))
93748 + {
93749 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP change EDCA parameters(from %d to %d)\n",
93750 + pAd->CommonCfg.APEdcaParm.EdcaUpdateCount,
93751 + EdcaParm.EdcaUpdateCount));
93752 + AsicSetEdcaParm(pAd, &EdcaParm);
93753 + }
93754 +
93755 + // copy QOS related information
93756 + NdisMoveMemory(&pAd->CommonCfg.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
93757 + NdisMoveMemory(&pAd->CommonCfg.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
93758 + }
93759 +
93760 + // only INFRASTRUCTURE mode support power-saving feature
93761 + if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE)) || (pAd->CommonCfg.bAPSDForcePowerSave))
93762 + {
93763 + UCHAR FreeNumber;
93764 + // 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL
93765 + // 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE
93766 + // 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE
93767 + // 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE
93768 + // 5. otherwise, put PHY back to sleep to save battery.
93769 + if (MessageToMe)
93770 + {
93771 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable &&
93772 + pAd->CommonCfg.bAPSDAC_BE && pAd->CommonCfg.bAPSDAC_BK && pAd->CommonCfg.bAPSDAC_VI && pAd->CommonCfg.bAPSDAC_VO)
93773 + {
93774 + pAd->CommonCfg.bNeedSendTriggerFrame = TRUE;
93775 + }
93776 + else
93777 + RT28XX_PS_POLL_ENQUEUE(pAd);
93778 + }
93779 + else if (BcastFlag && (DtimCount == 0) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM))
93780 + {
93781 + }
93782 + else if ((pAd->TxSwQueue[QID_AC_BK].Number != 0) ||
93783 + (pAd->TxSwQueue[QID_AC_BE].Number != 0) ||
93784 + (pAd->TxSwQueue[QID_AC_VI].Number != 0) ||
93785 + (pAd->TxSwQueue[QID_AC_VO].Number != 0) ||
93786 + (RTMPFreeTXDRequest(pAd, QID_AC_BK, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
93787 + (RTMPFreeTXDRequest(pAd, QID_AC_BE, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
93788 + (RTMPFreeTXDRequest(pAd, QID_AC_VI, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
93789 + (RTMPFreeTXDRequest(pAd, QID_AC_VO, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
93790 + (RTMPFreeTXDRequest(pAd, QID_MGMT, MGMT_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS))
93791 + {
93792 + // TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme
93793 + // can we cheat here (i.e. just check MGMT & AC_BE) for better performance?
93794 + }
93795 + else
93796 + {
93797 + USHORT NextDtim = DtimCount;
93798 +
93799 + if (NextDtim == 0)
93800 + NextDtim = DtimPeriod;
93801 +
93802 + TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
93803 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
93804 + TbttNumToNextWakeUp = NextDtim;
93805 +
93806 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
93807 + {
93808 + AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
93809 + }
93810 + }
93811 + }
93812 + }
93813 + // not my BSSID, ignore it
93814 + }
93815 + // sanity check fail, ignore this frame
93816 +}
93817 +
93818 +/*
93819 + ==========================================================================
93820 + Description:
93821 + Receive PROBE REQ from remote peer when operating in IBSS mode
93822 + ==========================================================================
93823 + */
93824 +VOID PeerProbeReqAction(
93825 + IN PRTMP_ADAPTER pAd,
93826 + IN MLME_QUEUE_ELEM *Elem)
93827 +{
93828 + UCHAR Addr2[MAC_ADDR_LEN];
93829 + CHAR Ssid[MAX_LEN_OF_SSID];
93830 + UCHAR SsidLen;
93831 +#ifdef DOT11_N_SUPPORT
93832 + UCHAR HtLen, AddHtLen, NewExtLen;
93833 +#endif // DOT11_N_SUPPORT //
93834 + HEADER_802_11 ProbeRspHdr;
93835 + NDIS_STATUS NStatus;
93836 + PUCHAR pOutBuffer = NULL;
93837 + ULONG FrameLen = 0;
93838 + LARGE_INTEGER FakeTimestamp;
93839 + UCHAR DsLen = 1, IbssLen = 2;
93840 + UCHAR LocalErpIe[3] = {IE_ERP, 1, 0};
93841 + BOOLEAN Privacy;
93842 + USHORT CapabilityInfo;
93843 + UCHAR RSNIe = IE_WPA;
93844 +
93845 + if (! ADHOC_ON(pAd))
93846 + return;
93847 +
93848 + if (PeerProbeReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen))
93849 + {
93850 + if ((SsidLen == 0) || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))
93851 + {
93852 + // allocate and send out ProbeRsp frame
93853 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
93854 + if (NStatus != NDIS_STATUS_SUCCESS)
93855 + return;
93856 +
93857 + //pAd->StaCfg.AtimWin = 0; // ??????
93858 +
93859 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
93860 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
93861 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
93862 + CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
93863 +
93864 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
93865 + sizeof(HEADER_802_11), &ProbeRspHdr,
93866 + TIMESTAMP_LEN, &FakeTimestamp,
93867 + 2, &pAd->CommonCfg.BeaconPeriod,
93868 + 2, &CapabilityInfo,
93869 + 1, &SsidIe,
93870 + 1, &pAd->CommonCfg.SsidLen,
93871 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
93872 + 1, &SupRateIe,
93873 + 1, &pAd->StaActive.SupRateLen,
93874 + pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
93875 + 1, &DsIe,
93876 + 1, &DsLen,
93877 + 1, &pAd->CommonCfg.Channel,
93878 + 1, &IbssIe,
93879 + 1, &IbssLen,
93880 + 2, &pAd->StaActive.AtimWin,
93881 + END_OF_ARGS);
93882 +
93883 + if (pAd->StaActive.ExtRateLen)
93884 + {
93885 + ULONG tmp;
93886 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
93887 + 3, LocalErpIe,
93888 + 1, &ExtRateIe,
93889 + 1, &pAd->StaActive.ExtRateLen,
93890 + pAd->StaActive.ExtRateLen, &pAd->StaActive.ExtRate,
93891 + END_OF_ARGS);
93892 + FrameLen += tmp;
93893 + }
93894 +
93895 + // If adhoc secruity is set for WPA-None, append the cipher suite IE
93896 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
93897 + {
93898 + ULONG tmp;
93899 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
93900 + 1, &RSNIe,
93901 + 1, &pAd->StaCfg.RSNIE_Len,
93902 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
93903 + END_OF_ARGS);
93904 + FrameLen += tmp;
93905 + }
93906 +#ifdef DOT11_N_SUPPORT
93907 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
93908 + {
93909 + ULONG TmpLen;
93910 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
93911 + HtLen = sizeof(pAd->CommonCfg.HtCapability);
93912 + AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo);
93913 + NewExtLen = 1;
93914 + //New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame
93915 + if (pAd->bBroadComHT == TRUE)
93916 + {
93917 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
93918 + 1, &WpaIe,
93919 + 4, &BROADCOM[0],
93920 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
93921 + END_OF_ARGS);
93922 + }
93923 + else
93924 + {
93925 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
93926 + 1, &HtCapIe,
93927 + 1, &HtLen,
93928 + sizeof(HT_CAPABILITY_IE), &pAd->CommonCfg.HtCapability,
93929 + 1, &AddHtInfoIe,
93930 + 1, &AddHtLen,
93931 + sizeof(ADD_HT_INFO_IE), &pAd->CommonCfg.AddHTInfo,
93932 + 1, &NewExtChanIe,
93933 + 1, &NewExtLen,
93934 + sizeof(NEW_EXT_CHAN_IE), &pAd->CommonCfg.NewExtChanOffset,
93935 + END_OF_ARGS);
93936 + }
93937 + FrameLen += TmpLen;
93938 + }
93939 +#endif // DOT11_N_SUPPORT //
93940 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
93941 + MlmeFreeMemory(pAd, pOutBuffer);
93942 + }
93943 + }
93944 +}
93945 +
93946 +VOID BeaconTimeoutAtJoinAction(
93947 + IN PRTMP_ADAPTER pAd,
93948 + IN MLME_QUEUE_ELEM *Elem)
93949 +{
93950 + USHORT Status;
93951 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n"));
93952 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93953 + Status = MLME_REJ_TIMEOUT;
93954 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
93955 +}
93956 +
93957 +/*
93958 + ==========================================================================
93959 + Description:
93960 + Scan timeout procedure. basically add channel index by 1 and rescan
93961 + ==========================================================================
93962 + */
93963 +VOID ScanTimeoutAction(
93964 + IN PRTMP_ADAPTER pAd,
93965 + IN MLME_QUEUE_ELEM *Elem)
93966 +{
93967 + pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel);
93968 +
93969 + // Only one channel scanned for CISCO beacon request
93970 + if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) ||
93971 + (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) ||
93972 + (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) ||
93973 + (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD))
93974 + pAd->MlmeAux.Channel = 0;
93975 +
93976 + // this routine will stop if pAd->MlmeAux.Channel == 0
93977 + ScanNextChannel(pAd);
93978 +}
93979 +
93980 +/*
93981 + ==========================================================================
93982 + Description:
93983 + ==========================================================================
93984 + */
93985 +VOID InvalidStateWhenScan(
93986 + IN PRTMP_ADAPTER pAd,
93987 + IN MLME_QUEUE_ELEM *Elem)
93988 +{
93989 + USHORT Status;
93990 + DBGPRINT(RT_DEBUG_TRACE, ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
93991 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93992 + Status = MLME_STATE_MACHINE_REJECT;
93993 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
93994 +}
93995 +
93996 +/*
93997 + ==========================================================================
93998 + Description:
93999 + ==========================================================================
94000 + */
94001 +VOID InvalidStateWhenJoin(
94002 + IN PRTMP_ADAPTER pAd,
94003 + IN MLME_QUEUE_ELEM *Elem)
94004 +{
94005 + USHORT Status;
94006 + DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
94007 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
94008 + Status = MLME_STATE_MACHINE_REJECT;
94009 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
94010 +}
94011 +
94012 +/*
94013 + ==========================================================================
94014 + Description:
94015 + ==========================================================================
94016 + */
94017 +VOID InvalidStateWhenStart(
94018 + IN PRTMP_ADAPTER pAd,
94019 + IN MLME_QUEUE_ELEM *Elem)
94020 +{
94021 + USHORT Status;
94022 + DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
94023 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
94024 + Status = MLME_STATE_MACHINE_REJECT;
94025 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
94026 +}
94027 +
94028 +/*
94029 + ==========================================================================
94030 + Description:
94031 +
94032 + IRQL = DISPATCH_LEVEL
94033 +
94034 + ==========================================================================
94035 + */
94036 +VOID EnqueuePsPoll(
94037 + IN PRTMP_ADAPTER pAd)
94038 +{
94039 +#ifdef RALINK_ATE
94040 + if (ATE_ON(pAd))
94041 + {
94042 + return;
94043 + }
94044 +#endif // RALINK_ATE //
94045 +
94046 +
94047 + if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP)
94048 + pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE;
94049 + MiniportMMRequest(pAd, 0, (PUCHAR)&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
94050 +}
94051 +
94052 +
94053 +/*
94054 + ==========================================================================
94055 + Description:
94056 + ==========================================================================
94057 + */
94058 +VOID EnqueueProbeRequest(
94059 + IN PRTMP_ADAPTER pAd)
94060 +{
94061 + NDIS_STATUS NState;
94062 + PUCHAR pOutBuffer;
94063 + ULONG FrameLen = 0;
94064 + HEADER_802_11 Hdr80211;
94065 +
94066 + DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n"));
94067 +
94068 + NState = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
94069 + if (NState == NDIS_STATUS_SUCCESS)
94070 + {
94071 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
94072 +
94073 + // this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse
94074 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94075 + sizeof(HEADER_802_11), &Hdr80211,
94076 + 1, &SsidIe,
94077 + 1, &pAd->CommonCfg.SsidLen,
94078 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
94079 + 1, &SupRateIe,
94080 + 1, &pAd->StaActive.SupRateLen,
94081 + pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
94082 + END_OF_ARGS);
94083 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
94084 + MlmeFreeMemory(pAd, pOutBuffer);
94085 + }
94086 +
94087 +}
94088 +
94089 +#ifdef DOT11_N_SUPPORT
94090 +#ifdef DOT11N_DRAFT3
94091 +VOID BuildEffectedChannelList(
94092 + IN PRTMP_ADAPTER pAd)
94093 +{
94094 + UCHAR EChannel[11];
94095 + UCHAR i, j, k;
94096 + UCHAR UpperChannel = 0, LowerChannel = 0;
94097 +
94098 + RTMPZeroMemory(EChannel, 11);
94099 + i = 0;
94100 + // Find upper channel and lower channel.
94101 + if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
94102 + {
94103 + UpperChannel = pAd->CommonCfg.Channel;
94104 + LowerChannel = pAd->CommonCfg.CentralChannel;
94105 + }
94106 + else if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
94107 + {
94108 + UpperChannel = pAd->CommonCfg.CentralChannel;
94109 + LowerChannel = pAd->CommonCfg.Channel;
94110 + }
94111 + else
94112 + {
94113 + return;
94114 + }
94115 +
94116 + // Record channels that is below lower channel..
94117 + if (LowerChannel > 1)
94118 + {
94119 + EChannel[0] = LowerChannel - 1;
94120 + i = 1;
94121 + if (LowerChannel > 2)
94122 + {
94123 + EChannel[1] = LowerChannel - 2;
94124 + i = 2;
94125 + if (LowerChannel > 3)
94126 + {
94127 + EChannel[2] = LowerChannel - 3;
94128 + i = 3;
94129 + }
94130 + }
94131 + }
94132 + // Record channels that is between lower channel and upper channel.
94133 + for (k = LowerChannel;k < UpperChannel;k++)
94134 + {
94135 + EChannel[i] = k;
94136 + i++;
94137 + }
94138 + // Record channels that is above upper channel..
94139 + if (LowerChannel < 11)
94140 + {
94141 + EChannel[i] = UpperChannel + 1;
94142 + i++;
94143 + if (LowerChannel < 10)
94144 + {
94145 + EChannel[i] = LowerChannel + 2;
94146 + i++;
94147 + if (LowerChannel < 9)
94148 + {
94149 + EChannel[i] = LowerChannel + 3;
94150 + i++;
94151 + }
94152 + }
94153 + }
94154 + //
94155 + for (j = 0;j < i;j++)
94156 + {
94157 + for (k = 0;k < pAd->ChannelListNum;k++)
94158 + {
94159 + if (pAd->ChannelList[k].Channel == EChannel[j])
94160 + {
94161 + pAd->ChannelList[k].bEffectedChannel = TRUE;
94162 + DBGPRINT(RT_DEBUG_TRACE,(" EffectedChannel( =%d)\n", EChannel[j]));
94163 + break;
94164 + }
94165 + }
94166 + }
94167 +}
94168 +#endif // DOT11N_DRAFT3 //
94169 +#endif // DOT11_N_SUPPORT //
94170 +
94171 +BOOLEAN ScanRunning(
94172 + IN PRTMP_ADAPTER pAd)
94173 +{
94174 + return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE;
94175 +}
94176 +
94177 --- /dev/null
94178 +++ b/drivers/staging/rt2870/sta/wpa.c
94179 @@ -0,0 +1,2107 @@
94180 +/*
94181 + *************************************************************************
94182 + * Ralink Tech Inc.
94183 + * 5F., No.36, Taiyuan St., Jhubei City,
94184 + * Hsinchu County 302,
94185 + * Taiwan, R.O.C.
94186 + *
94187 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
94188 + *
94189 + * This program is free software; you can redistribute it and/or modify *
94190 + * it under the terms of the GNU General Public License as published by *
94191 + * the Free Software Foundation; either version 2 of the License, or *
94192 + * (at your option) any later version. *
94193 + * *
94194 + * This program is distributed in the hope that it will be useful, *
94195 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
94196 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
94197 + * GNU General Public License for more details. *
94198 + * *
94199 + * You should have received a copy of the GNU General Public License *
94200 + * along with this program; if not, write to the *
94201 + * Free Software Foundation, Inc., *
94202 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
94203 + * *
94204 + *************************************************************************
94205 +
94206 + Module Name:
94207 + wpa.c
94208 +
94209 + Abstract:
94210 +
94211 + Revision History:
94212 + Who When What
94213 + -------- ---------- ----------------------------------------------
94214 + Jan Lee 03-07-22 Initial
94215 + Paul Lin 03-11-28 Modify for supplicant
94216 +*/
94217 +#include "../rt_config.h"
94218 +
94219 +#define WPARSNIE 0xdd
94220 +#define WPA2RSNIE 0x30
94221 +
94222 +//extern UCHAR BIT8[];
94223 +UCHAR CipherWpaPskTkip[] = {
94224 + 0xDD, 0x16, // RSN IE
94225 + 0x00, 0x50, 0xf2, 0x01, // oui
94226 + 0x01, 0x00, // Version
94227 + 0x00, 0x50, 0xf2, 0x02, // Multicast
94228 + 0x01, 0x00, // Number of unicast
94229 + 0x00, 0x50, 0xf2, 0x02, // unicast
94230 + 0x01, 0x00, // number of authentication method
94231 + 0x00, 0x50, 0xf2, 0x02 // authentication
94232 + };
94233 +UCHAR CipherWpaPskTkipLen = (sizeof(CipherWpaPskTkip) / sizeof(UCHAR));
94234 +
94235 +UCHAR CipherWpaPskAes[] = {
94236 + 0xDD, 0x16, // RSN IE
94237 + 0x00, 0x50, 0xf2, 0x01, // oui
94238 + 0x01, 0x00, // Version
94239 + 0x00, 0x50, 0xf2, 0x04, // Multicast
94240 + 0x01, 0x00, // Number of unicast
94241 + 0x00, 0x50, 0xf2, 0x04, // unicast
94242 + 0x01, 0x00, // number of authentication method
94243 + 0x00, 0x50, 0xf2, 0x02 // authentication
94244 + };
94245 +UCHAR CipherWpaPskAesLen = (sizeof(CipherWpaPskAes) / sizeof(UCHAR));
94246 +
94247 +UCHAR CipherSuiteCiscoCCKM[] = {
94248 + 0xDD, 0x16, // RSN IE
94249 + 0x00, 0x50, 0xf2, 0x01, // oui
94250 + 0x01, 0x00, // Version
94251 + 0x00, 0x40, 0x96, 0x01, // Multicast
94252 + 0x01, 0x00, // Number of uicast
94253 + 0x00, 0x40, 0x96, 0x01, // unicast
94254 + 0x01, 0x00, // number of authentication method
94255 + 0x00, 0x40, 0x96, 0x00 // Authentication
94256 + };
94257 +UCHAR CipherSuiteCiscoCCKMLen = (sizeof(CipherSuiteCiscoCCKM) / sizeof(UCHAR));
94258 +
94259 +UCHAR CipherSuiteCiscoCCKM24[] = {
94260 + 0xDD, 0x18, // RSN IE
94261 + 0x00, 0x50, 0xf2, 0x01, // oui
94262 + 0x01, 0x00, // Version
94263 + 0x00, 0x40, 0x96, 0x01, // Multicast
94264 + 0x01, 0x00, // Number of uicast
94265 + 0x00, 0x40, 0x96, 0x01, // unicast
94266 + 0x01, 0x00, // number of authentication method
94267 + 0x00, 0x40, 0x96, 0x00,
94268 + 0x28, 0x00// Authentication
94269 + };
94270 +
94271 +UCHAR CipherSuiteCiscoCCKM24Len = (sizeof(CipherSuiteCiscoCCKM24) / sizeof(UCHAR));
94272 +
94273 +UCHAR CipherSuiteCCXTkip[] = {
94274 + 0xDD, 0x16, // RSN IE
94275 + 0x00, 0x50, 0xf2, 0x01, // oui
94276 + 0x01, 0x00, // Version
94277 + 0x00, 0x50, 0xf2, 0x02, // Multicast
94278 + 0x01, 0x00, // Number of unicast
94279 + 0x00, 0x50, 0xf2, 0x02, // unicast
94280 + 0x01, 0x00, // number of authentication method
94281 + 0x00, 0x50, 0xf2, 0x01 // authentication
94282 + };
94283 +UCHAR CipherSuiteCCXTkipLen = (sizeof(CipherSuiteCCXTkip) / sizeof(UCHAR));
94284 +
94285 +UCHAR CCX_LLC_HDR[] = {0xAA, 0xAA, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02};
94286 +UCHAR LLC_NORMAL[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
94287 +
94288 +UCHAR EAPOL_FRAME[] = {0x88, 0x8E};
94289 +
94290 +BOOLEAN CheckRSNIE(
94291 + IN PRTMP_ADAPTER pAd,
94292 + IN PUCHAR pData,
94293 + IN UCHAR DataLen,
94294 + OUT UCHAR *Offset);
94295 +
94296 +void inc_byte_array(UCHAR *counter, int len);
94297 +
94298 +/*
94299 + ========================================================================
94300 +
94301 + Routine Description:
94302 + Classify WPA EAP message type
94303 +
94304 + Arguments:
94305 + EAPType Value of EAP message type
94306 + MsgType Internal Message definition for MLME state machine
94307 +
94308 + Return Value:
94309 + TRUE Found appropriate message type
94310 + FALSE No appropriate message type
94311 +
94312 + IRQL = DISPATCH_LEVEL
94313 +
94314 + Note:
94315 + All these constants are defined in wpa.h
94316 + For supplicant, there is only EAPOL Key message avaliable
94317 +
94318 + ========================================================================
94319 +*/
94320 +BOOLEAN WpaMsgTypeSubst(
94321 + IN UCHAR EAPType,
94322 + OUT INT *MsgType)
94323 +{
94324 + switch (EAPType)
94325 + {
94326 + case EAPPacket:
94327 + *MsgType = MT2_EAPPacket;
94328 + break;
94329 + case EAPOLStart:
94330 + *MsgType = MT2_EAPOLStart;
94331 + break;
94332 + case EAPOLLogoff:
94333 + *MsgType = MT2_EAPOLLogoff;
94334 + break;
94335 + case EAPOLKey:
94336 + *MsgType = MT2_EAPOLKey;
94337 + break;
94338 + case EAPOLASFAlert:
94339 + *MsgType = MT2_EAPOLASFAlert;
94340 + break;
94341 + default:
94342 + return FALSE;
94343 + }
94344 + return TRUE;
94345 +}
94346 +
94347 +/*
94348 + ==========================================================================
94349 + Description:
94350 + association state machine init, including state transition and timer init
94351 + Parameters:
94352 + S - pointer to the association state machine
94353 + ==========================================================================
94354 + */
94355 +VOID WpaPskStateMachineInit(
94356 + IN PRTMP_ADAPTER pAd,
94357 + IN STATE_MACHINE *S,
94358 + OUT STATE_MACHINE_FUNC Trans[])
94359 +{
94360 + StateMachineInit(S, Trans, MAX_WPA_PSK_STATE, MAX_WPA_PSK_MSG, (STATE_MACHINE_FUNC)Drop, WPA_PSK_IDLE, WPA_MACHINE_BASE);
94361 + StateMachineSetAction(S, WPA_PSK_IDLE, MT2_EAPOLKey, (STATE_MACHINE_FUNC)WpaEAPOLKeyAction);
94362 +}
94363 +
94364 +/*
94365 + ==========================================================================
94366 + Description:
94367 + This is state machine function.
94368 + When receiving EAPOL packets which is for 802.1x key management.
94369 + Use both in WPA, and WPAPSK case.
94370 + In this function, further dispatch to different functions according to the received packet. 3 categories are :
94371 + 1. normal 4-way pairwisekey and 2-way groupkey handshake
94372 + 2. MIC error (Countermeasures attack) report packet from STA.
94373 + 3. Request for pairwise/group key update from STA
94374 + Return:
94375 + ==========================================================================
94376 +*/
94377 +VOID WpaEAPOLKeyAction(
94378 + IN PRTMP_ADAPTER pAd,
94379 + IN MLME_QUEUE_ELEM *Elem)
94380 +
94381 +{
94382 + INT MsgType = EAPOL_MSG_INVALID;
94383 + PKEY_DESCRIPTER pKeyDesc;
94384 + PHEADER_802_11 pHeader; //red
94385 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
94386 + UCHAR EapolVr;
94387 + KEY_INFO peerKeyInfo;
94388 +
94389 + DBGPRINT(RT_DEBUG_TRACE, ("-----> WpaEAPOLKeyAction\n"));
94390 +
94391 + // Get 802.11 header first
94392 + pHeader = (PHEADER_802_11) Elem->Msg;
94393 +
94394 + // Get EAPoL-Key Descriptor
94395 + pKeyDesc = (PKEY_DESCRIPTER) &Elem->Msg[(LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H)];
94396 +
94397 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
94398 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pKeyDesc->KeyInfo, sizeof(KEY_INFO));
94399 +
94400 + *((USHORT *)&peerKeyInfo) = cpu2le16(*((USHORT *)&peerKeyInfo));
94401 +
94402 +
94403 + // 1. Check EAPOL frame version and type
94404 + EapolVr = (UCHAR) Elem->Msg[LENGTH_802_11+LENGTH_802_1_H];
94405 +
94406 + if (((EapolVr != EAPOL_VER) && (EapolVr != EAPOL_VER2)) || ((pKeyDesc->Type != WPA1_KEY_DESC) && (pKeyDesc->Type != WPA2_KEY_DESC)))
94407 + {
94408 + DBGPRINT(RT_DEBUG_ERROR, ("Key descripter does not match with WPA rule\n"));
94409 + return;
94410 + }
94411 +
94412 + // First validate replay counter, only accept message with larger replay counter
94413 + // Let equal pass, some AP start with all zero replay counter
94414 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
94415 +
94416 + if((RTMPCompareMemory(pKeyDesc->ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1) &&
94417 + (RTMPCompareMemory(pKeyDesc->ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
94418 + {
94419 + DBGPRINT(RT_DEBUG_ERROR, (" ReplayCounter not match \n"));
94420 + return;
94421 + }
94422 +
94423 + // Process WPA2PSK frame
94424 + if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
94425 + {
94426 + if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
94427 + (peerKeyInfo.EKD_DL == 0) &&
94428 + (peerKeyInfo.KeyAck == 1) &&
94429 + (peerKeyInfo.KeyMic == 0) &&
94430 + (peerKeyInfo.Secure == 0) &&
94431 + (peerKeyInfo.Error == 0) &&
94432 + (peerKeyInfo.Request == 0))
94433 + {
94434 + MsgType = EAPOL_PAIR_MSG_1;
94435 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));
94436 + } else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
94437 + (peerKeyInfo.EKD_DL == 1) &&
94438 + (peerKeyInfo.KeyAck == 1) &&
94439 + (peerKeyInfo.KeyMic == 1) &&
94440 + (peerKeyInfo.Secure == 1) &&
94441 + (peerKeyInfo.Error == 0) &&
94442 + (peerKeyInfo.Request == 0))
94443 + {
94444 + MsgType = EAPOL_PAIR_MSG_3;
94445 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));
94446 + } else if((peerKeyInfo.KeyType == GROUPKEY) &&
94447 + (peerKeyInfo.EKD_DL == 1) &&
94448 + (peerKeyInfo.KeyAck == 1) &&
94449 + (peerKeyInfo.KeyMic == 1) &&
94450 + (peerKeyInfo.Secure == 1) &&
94451 + (peerKeyInfo.Error == 0) &&
94452 + (peerKeyInfo.Request == 0))
94453 + {
94454 + MsgType = EAPOL_GROUP_MSG_1;
94455 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));
94456 + }
94457 +
94458 + // We will assume link is up (assoc suceess and port not secured).
94459 + // All state has to be able to process message from previous state
94460 + switch(pAd->StaCfg.WpaState)
94461 + {
94462 + case SS_START:
94463 + if(MsgType == EAPOL_PAIR_MSG_1)
94464 + {
94465 + Wpa2PairMsg1Action(pAd, Elem);
94466 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94467 + }
94468 + break;
94469 +
94470 + case SS_WAIT_MSG_3:
94471 + if(MsgType == EAPOL_PAIR_MSG_1)
94472 + {
94473 + Wpa2PairMsg1Action(pAd, Elem);
94474 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94475 + }
94476 + else if(MsgType == EAPOL_PAIR_MSG_3)
94477 + {
94478 + Wpa2PairMsg3Action(pAd, Elem);
94479 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
94480 + }
94481 + break;
94482 +
94483 + case SS_WAIT_GROUP: // When doing group key exchange
94484 + case SS_FINISH: // This happened when update group key
94485 + if(MsgType == EAPOL_PAIR_MSG_1)
94486 + {
94487 + // Reset port secured variable
94488 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
94489 + Wpa2PairMsg1Action(pAd, Elem);
94490 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94491 + }
94492 + else if(MsgType == EAPOL_PAIR_MSG_3)
94493 + {
94494 + // Reset port secured variable
94495 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
94496 + Wpa2PairMsg3Action(pAd, Elem);
94497 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
94498 + }
94499 + else if(MsgType == EAPOL_GROUP_MSG_1)
94500 + {
94501 + WpaGroupMsg1Action(pAd, Elem);
94502 + pAd->StaCfg.WpaState = SS_FINISH;
94503 + }
94504 + break;
94505 +
94506 + default:
94507 + break;
94508 + }
94509 + }
94510 + // Process WPAPSK Frame
94511 + // Classify message Type, either pairwise message 1, 3, or group message 1 for supplicant
94512 + else if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
94513 + {
94514 + if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
94515 + (peerKeyInfo.KeyIndex == 0) &&
94516 + (peerKeyInfo.KeyAck == 1) &&
94517 + (peerKeyInfo.KeyMic == 0) &&
94518 + (peerKeyInfo.Secure == 0) &&
94519 + (peerKeyInfo.Error == 0) &&
94520 + (peerKeyInfo.Request == 0))
94521 + {
94522 + MsgType = EAPOL_PAIR_MSG_1;
94523 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));
94524 + }
94525 + else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
94526 + (peerKeyInfo.KeyIndex == 0) &&
94527 + (peerKeyInfo.KeyAck == 1) &&
94528 + (peerKeyInfo.KeyMic == 1) &&
94529 + (peerKeyInfo.Secure == 0) &&
94530 + (peerKeyInfo.Error == 0) &&
94531 + (peerKeyInfo.Request == 0))
94532 + {
94533 + MsgType = EAPOL_PAIR_MSG_3;
94534 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));
94535 + }
94536 + else if((peerKeyInfo.KeyType == GROUPKEY) &&
94537 + (peerKeyInfo.KeyIndex != 0) &&
94538 + (peerKeyInfo.KeyAck == 1) &&
94539 + (peerKeyInfo.KeyMic == 1) &&
94540 + (peerKeyInfo.Secure == 1) &&
94541 + (peerKeyInfo.Error == 0) &&
94542 + (peerKeyInfo.Request == 0))
94543 + {
94544 + MsgType = EAPOL_GROUP_MSG_1;
94545 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));
94546 + }
94547 +
94548 + // We will assume link is up (assoc suceess and port not secured).
94549 + // All state has to be able to process message from previous state
94550 + switch(pAd->StaCfg.WpaState)
94551 + {
94552 + case SS_START:
94553 + if(MsgType == EAPOL_PAIR_MSG_1)
94554 + {
94555 + WpaPairMsg1Action(pAd, Elem);
94556 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94557 + }
94558 + break;
94559 +
94560 + case SS_WAIT_MSG_3:
94561 + if(MsgType == EAPOL_PAIR_MSG_1)
94562 + {
94563 + WpaPairMsg1Action(pAd, Elem);
94564 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94565 + }
94566 + else if(MsgType == EAPOL_PAIR_MSG_3)
94567 + {
94568 + WpaPairMsg3Action(pAd, Elem);
94569 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
94570 + }
94571 + break;
94572 +
94573 + case SS_WAIT_GROUP: // When doing group key exchange
94574 + case SS_FINISH: // This happened when update group key
94575 + if(MsgType == EAPOL_PAIR_MSG_1)
94576 + {
94577 + WpaPairMsg1Action(pAd, Elem);
94578 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
94579 + // Reset port secured variable
94580 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
94581 + }
94582 + else if(MsgType == EAPOL_PAIR_MSG_3)
94583 + {
94584 + WpaPairMsg3Action(pAd, Elem);
94585 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
94586 + // Reset port secured variable
94587 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
94588 + }
94589 + else if(MsgType == EAPOL_GROUP_MSG_1)
94590 + {
94591 + WpaGroupMsg1Action(pAd, Elem);
94592 + pAd->StaCfg.WpaState = SS_FINISH;
94593 + }
94594 + break;
94595 +
94596 + default:
94597 + break;
94598 + }
94599 + }
94600 +
94601 + DBGPRINT(RT_DEBUG_TRACE, ("<----- WpaEAPOLKeyAction\n"));
94602 +}
94603 +
94604 +/*
94605 + ========================================================================
94606 +
94607 + Routine Description:
94608 + Process Pairwise key 4-way handshaking
94609 +
94610 + Arguments:
94611 + pAd Pointer to our adapter
94612 + Elem Message body
94613 +
94614 + Return Value:
94615 + None
94616 +
94617 + Note:
94618 +
94619 + ========================================================================
94620 +*/
94621 +VOID WpaPairMsg1Action(
94622 + IN PRTMP_ADAPTER pAd,
94623 + IN MLME_QUEUE_ELEM *Elem)
94624 +{
94625 + PHEADER_802_11 pHeader;
94626 + UCHAR *mpool, *PTK, *digest;
94627 + PUCHAR pOutBuffer = NULL;
94628 + UCHAR Header802_3[14];
94629 + ULONG FrameLen = 0;
94630 + PEAPOL_PACKET pMsg1;
94631 + EAPOL_PACKET Packet;
94632 + UCHAR Mic[16];
94633 +
94634 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action ----->\n"));
94635 +
94636 + // allocate memory pool
94637 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);
94638 +
94639 + if (mpool == NULL)
94640 + return;
94641 +
94642 + // PTK Len = 80.
94643 + PTK = (UCHAR *) ROUND_UP(mpool, 4);
94644 + // digest Len = 80.
94645 + digest = (UCHAR *) ROUND_UP(PTK + 80, 4);
94646 +
94647 + pHeader = (PHEADER_802_11) Elem->Msg;
94648 +
94649 + // Process message 1 from authenticator
94650 + pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
94651 +
94652 + // 1. Save Replay counter, it will use to verify message 3 and construct message 2
94653 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
94654 +
94655 + // 2. Save ANonce
94656 + NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);
94657 +
94658 + // Generate random SNonce
94659 + GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);
94660 +
94661 + // Calc PTK(ANonce, SNonce)
94662 + WpaCountPTK(pAd,
94663 + pAd->StaCfg.PMK,
94664 + pAd->StaCfg.ANonce,
94665 + pAd->CommonCfg.Bssid,
94666 + pAd->StaCfg.SNonce,
94667 + pAd->CurrentAddress,
94668 + PTK,
94669 + LEN_PTK);
94670 +
94671 + // Save key to PTK entry
94672 + NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);
94673 +
94674 + // init 802.3 header and Fill Packet
94675 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
94676 +
94677 + // Zero Message 2 body
94678 + NdisZeroMemory(&Packet, sizeof(Packet));
94679 + Packet.ProVer = EAPOL_VER;
94680 + Packet.ProType = EAPOLKey;
94681 + //
94682 + // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
94683 + //
94684 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
94685 + // 1. Key descriptor version and appropriate RSN IE
94686 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
94687 + {
94688 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
94689 + }
94690 + else // TKIP
94691 + {
94692 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
94693 + }
94694 +
94695 + // fill in Data Material and its length
94696 + Packet.KeyDesc.KeyData[0] = IE_WPA;
94697 + Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;
94698 + Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;
94699 + NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
94700 +
94701 + // Update packet length after decide Key data payload
94702 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];
94703 +
94704 + // Update Key length
94705 + Packet.KeyDesc.KeyLength[0] = pMsg1->KeyDesc.KeyLength[0];
94706 + Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];
94707 + // 2. Key Type PeerKey
94708 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
94709 +
94710 + // 3. KeyMic field presented
94711 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
94712 +
94713 + //Convert to little-endian format.
94714 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
94715 +
94716 +
94717 + // 4. Fill SNonce
94718 + NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);
94719 +
94720 + // 5. Key Replay Count
94721 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
94722 +
94723 + // Send EAPOL(0, 1, 0, 0, 0, P, 0, SNonce, MIC, RSN_IE)
94724 + // Out buffer for transmitting message 2
94725 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
94726 + if(pOutBuffer == NULL)
94727 + {
94728 + os_free_mem(pAd, mpool);
94729 + return;
94730 + }
94731 + // Prepare EAPOL frame for MIC calculation
94732 + // Be careful, only EAPOL frame is counted for MIC calculation
94733 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94734 + Packet.Body_Len[1] + 4, &Packet,
94735 + END_OF_ARGS);
94736 +
94737 + // 6. Prepare and Fill MIC value
94738 + NdisZeroMemory(Mic, sizeof(Mic));
94739 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
94740 + { // AES
94741 +
94742 + HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
94743 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
94744 + }
94745 + else
94746 + { // TKIP
94747 + hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
94748 + }
94749 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
94750 +
94751 + //hex_dump("MIC", Mic, LEN_KEY_DESC_MIC);
94752 +
94753 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94754 + LENGTH_802_3, &Header802_3,
94755 + Packet.Body_Len[1] + 4, &Packet,
94756 + END_OF_ARGS);
94757 +
94758 +
94759 + // 5. Copy frame to Tx ring and send Msg 2 to authenticator
94760 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
94761 +
94762 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
94763 + os_free_mem(pAd, (PUCHAR)mpool);
94764 +
94765 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action <-----\n"));
94766 +}
94767 +
94768 +VOID Wpa2PairMsg1Action(
94769 + IN PRTMP_ADAPTER pAd,
94770 + IN MLME_QUEUE_ELEM *Elem)
94771 +{
94772 + PHEADER_802_11 pHeader;
94773 + UCHAR *mpool, *PTK, *digest;
94774 + PUCHAR pOutBuffer = NULL;
94775 + UCHAR Header802_3[14];
94776 + ULONG FrameLen = 0;
94777 + PEAPOL_PACKET pMsg1;
94778 + EAPOL_PACKET Packet;
94779 + UCHAR Mic[16];
94780 +
94781 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action ----->\n"));
94782 +
94783 + // allocate memory pool
94784 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);
94785 +
94786 + if (mpool == NULL)
94787 + return;
94788 +
94789 + // PTK Len = 80.
94790 + PTK = (UCHAR *) ROUND_UP(mpool, 4);
94791 + // digest Len = 80.
94792 + digest = (UCHAR *) ROUND_UP(PTK + 80, 4);
94793 +
94794 + pHeader = (PHEADER_802_11) Elem->Msg;
94795 +
94796 + // Process message 1 from authenticator
94797 + pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
94798 +
94799 + // 1. Save Replay counter, it will use to verify message 3 and construct message 2
94800 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
94801 +
94802 + // 2. Save ANonce
94803 + NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);
94804 +
94805 + // Generate random SNonce
94806 + GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);
94807 +
94808 + if(pMsg1->KeyDesc.KeyDataLen[1] > 0 )
94809 + {
94810 + // cached PMKID
94811 + }
94812 +
94813 + // Calc PTK(ANonce, SNonce)
94814 + WpaCountPTK(pAd,
94815 + pAd->StaCfg.PMK,
94816 + pAd->StaCfg.ANonce,
94817 + pAd->CommonCfg.Bssid,
94818 + pAd->StaCfg.SNonce,
94819 + pAd->CurrentAddress,
94820 + PTK,
94821 + LEN_PTK);
94822 +
94823 + // Save key to PTK entry
94824 + NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);
94825 +
94826 + // init 802.3 header and Fill Packet
94827 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
94828 +
94829 + // Zero message 2 body
94830 + NdisZeroMemory(&Packet, sizeof(Packet));
94831 + Packet.ProVer = EAPOL_VER;
94832 + Packet.ProType = EAPOLKey;
94833 + //
94834 + // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
94835 + //
94836 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
94837 +
94838 + // 1. Key descriptor version and appropriate RSN IE
94839 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
94840 + {
94841 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
94842 + }
94843 + else // TKIP
94844 + {
94845 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
94846 + }
94847 +
94848 + // fill in Data Material and its length
94849 + Packet.KeyDesc.KeyData[0] = IE_WPA2;
94850 + Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;
94851 + Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;
94852 + NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
94853 +
94854 + // Update packet length after decide Key data payload
94855 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];
94856 +
94857 + // 2. Key Type PeerKey
94858 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
94859 +
94860 + // 3. KeyMic field presented
94861 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
94862 +
94863 + // Update Key Length
94864 + Packet.KeyDesc.KeyLength[0] = 0;
94865 + Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];
94866 +
94867 + // 4. Fill SNonce
94868 + NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);
94869 +
94870 + // 5. Key Replay Count
94871 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
94872 +
94873 + // Convert to little-endian format.
94874 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
94875 +
94876 + // Send EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
94877 + // Out buffer for transmitting message 2
94878 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
94879 + if(pOutBuffer == NULL)
94880 + {
94881 + os_free_mem(pAd, mpool);
94882 + return;
94883 + }
94884 +
94885 + // Prepare EAPOL frame for MIC calculation
94886 + // Be careful, only EAPOL frame is counted for MIC calculation
94887 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94888 + Packet.Body_Len[1] + 4, &Packet,
94889 + END_OF_ARGS);
94890 +
94891 + // 6. Prepare and Fill MIC value
94892 + NdisZeroMemory(Mic, sizeof(Mic));
94893 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
94894 + {
94895 + // AES
94896 + HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
94897 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
94898 + }
94899 + else
94900 + {
94901 + hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
94902 + }
94903 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
94904 +
94905 +
94906 + // Make Transmitting frame
94907 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94908 + LENGTH_802_3, &Header802_3,
94909 + Packet.Body_Len[1] + 4, &Packet,
94910 + END_OF_ARGS);
94911 +
94912 +
94913 + // 5. Copy frame to Tx ring
94914 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
94915 +
94916 + MlmeFreeMemory(pAd, pOutBuffer);
94917 + os_free_mem(pAd, mpool);
94918 +
94919 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action <-----\n"));
94920 +
94921 +}
94922 +
94923 +/*
94924 + ========================================================================
94925 +
94926 + Routine Description:
94927 + Process Pairwise key 4-way handshaking
94928 +
94929 + Arguments:
94930 + pAd Pointer to our adapter
94931 + Elem Message body
94932 +
94933 + Return Value:
94934 + None
94935 +
94936 + Note:
94937 +
94938 + ========================================================================
94939 +*/
94940 +VOID WpaPairMsg3Action(
94941 + IN PRTMP_ADAPTER pAd,
94942 + IN MLME_QUEUE_ELEM *Elem)
94943 +
94944 +{
94945 + PHEADER_802_11 pHeader;
94946 + PUCHAR pOutBuffer = NULL;
94947 + UCHAR Header802_3[14];
94948 + ULONG FrameLen = 0;
94949 + EAPOL_PACKET Packet;
94950 + PEAPOL_PACKET pMsg3;
94951 + UCHAR Mic[16], OldMic[16];
94952 + MAC_TABLE_ENTRY *pEntry = NULL;
94953 + UCHAR skip_offset;
94954 + KEY_INFO peerKeyInfo;
94955 +
94956 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action ----->\n"));
94957 +
94958 + // Record 802.11 header & the received EAPOL packet Msg3
94959 + pHeader = (PHEADER_802_11) Elem->Msg;
94960 + pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
94961 +
94962 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
94963 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));
94964 +
94965 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
94966 +
94967 +
94968 + // 1. Verify cipher type match
94969 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))
94970 + {
94971 + return;
94972 + }
94973 + else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
94974 + {
94975 + return;
94976 + }
94977 +
94978 + // Verify RSN IE
94979 + //if (!RTMPEqualMemory(pMsg3->KeyDesc.KeyData, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len))
94980 + if (!CheckRSNIE(pAd, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1], &skip_offset))
94981 + {
94982 + DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in Msg 3 of WPA1 4-way handshake!! \n"));
94983 + hex_dump("The original RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
94984 + hex_dump("The received RSN_IE", pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);
94985 + return;
94986 + }
94987 + else
94988 + DBGPRINT(RT_DEBUG_TRACE, ("RSN_IE VALID in Msg 3 of WPA1 4-way handshake!! \n"));
94989 +
94990 +
94991 + // 2. Check MIC value
94992 + // Save the MIC and replace with zero
94993 + NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
94994 + NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
94995 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
94996 + {
94997 + // AES
94998 + UCHAR digest[80];
94999 +
95000 + HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95001 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95002 + }
95003 + else // TKIP
95004 + {
95005 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);
95006 + }
95007 +
95008 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
95009 + {
95010 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));
95011 + return;
95012 + }
95013 + else
95014 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));
95015 +
95016 + // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger
95017 + if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
95018 + return;
95019 +
95020 + // Update new replay counter
95021 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95022 +
95023 + // 4. Double check ANonce
95024 + if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))
95025 + return;
95026 +
95027 + // init 802.3 header and Fill Packet
95028 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
95029 +
95030 + // Zero Message 4 body
95031 + NdisZeroMemory(&Packet, sizeof(Packet));
95032 + Packet.ProVer = EAPOL_VER;
95033 + Packet.ProType = EAPOLKey;
95034 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
95035 +
95036 + //
95037 + // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)
95038 + //
95039 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
95040 +
95041 + // Key descriptor version and appropriate RSN IE
95042 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
95043 +
95044 + // Update Key Length
95045 + Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];
95046 + Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];
95047 +
95048 + // Key Type PeerKey
95049 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
95050 +
95051 + // KeyMic field presented
95052 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
95053 +
95054 + // In Msg3, KeyInfo.secure =0 if Group Key HS to come. 1 if no group key HS
95055 + // Station sends Msg4 KeyInfo.secure should be the same as that in Msg.3
95056 + Packet.KeyDesc.KeyInfo.Secure= peerKeyInfo.Secure;
95057 +
95058 + // Convert to little-endian format.
95059 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
95060 +
95061 + // Key Replay count
95062 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95063 +
95064 + // Out buffer for transmitting message 4
95065 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
95066 + if(pOutBuffer == NULL)
95067 + return;
95068 +
95069 + // Prepare EAPOL frame for MIC calculation
95070 + // Be careful, only EAPOL frame is counted for MIC calculation
95071 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95072 + Packet.Body_Len[1] + 4, &Packet,
95073 + END_OF_ARGS);
95074 +
95075 + // Prepare and Fill MIC value
95076 + NdisZeroMemory(Mic, sizeof(Mic));
95077 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95078 + {
95079 + // AES
95080 + UCHAR digest[80];
95081 +
95082 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95083 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95084 + }
95085 + else
95086 + {
95087 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
95088 + }
95089 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
95090 +
95091 + // Update PTK
95092 + // Prepare pair-wise key information into shared key table
95093 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
95094 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
95095 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
95096 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
95097 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
95098 +
95099 + // Decide its ChiperAlg
95100 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
95101 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
95102 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
95103 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
95104 + else
95105 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
95106 +
95107 + // Update these related information to MAC_TABLE_ENTRY
95108 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
95109 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
95110 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
95111 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
95112 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
95113 +
95114 + // Update pairwise key information to ASIC Shared Key Table
95115 + AsicAddSharedKeyEntry(pAd,
95116 + BSS0,
95117 + 0,
95118 + pAd->SharedKey[BSS0][0].CipherAlg,
95119 + pAd->SharedKey[BSS0][0].Key,
95120 + pAd->SharedKey[BSS0][0].TxMic,
95121 + pAd->SharedKey[BSS0][0].RxMic);
95122 +
95123 + // Update ASIC WCID attribute table and IVEIV table
95124 + RTMPAddWcidAttributeEntry(pAd,
95125 + BSS0,
95126 + 0,
95127 + pAd->SharedKey[BSS0][0].CipherAlg,
95128 + pEntry);
95129 +
95130 + // Make transmitting frame
95131 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95132 + LENGTH_802_3, &Header802_3,
95133 + Packet.Body_Len[1] + 4, &Packet,
95134 + END_OF_ARGS);
95135 +
95136 +
95137 + // Copy frame to Tx ring and Send Message 4 to authenticator
95138 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
95139 +
95140 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
95141 +
95142 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action <-----\n"));
95143 +}
95144 +
95145 +VOID Wpa2PairMsg3Action(
95146 + IN PRTMP_ADAPTER pAd,
95147 + IN MLME_QUEUE_ELEM *Elem)
95148 +
95149 +{
95150 + PHEADER_802_11 pHeader;
95151 + PUCHAR pOutBuffer = NULL;
95152 + UCHAR Header802_3[14];
95153 + ULONG FrameLen = 0;
95154 + EAPOL_PACKET Packet;
95155 + PEAPOL_PACKET pMsg3;
95156 + UCHAR Mic[16], OldMic[16];
95157 + UCHAR *mpool, *KEYDATA, *digest;
95158 + UCHAR Key[32];
95159 + MAC_TABLE_ENTRY *pEntry = NULL;
95160 + KEY_INFO peerKeyInfo;
95161 +
95162 + // allocate memory
95163 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);
95164 +
95165 + if(mpool == NULL)
95166 + return;
95167 +
95168 + // KEYDATA Len = 512.
95169 + KEYDATA = (UCHAR *) ROUND_UP(mpool, 4);
95170 + // digest Len = 80.
95171 + digest = (UCHAR *) ROUND_UP(KEYDATA + 512, 4);
95172 +
95173 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg3Action ----->\n"));
95174 +
95175 + pHeader = (PHEADER_802_11) Elem->Msg;
95176 +
95177 + // Process message 3 frame.
95178 + pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
95179 +
95180 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
95181 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));
95182 +
95183 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
95184 +
95185 + // 1. Verify cipher type match
95186 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer!= 2))
95187 + {
95188 + os_free_mem(pAd, (PUCHAR)mpool);
95189 + return;
95190 + }
95191 + else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
95192 + {
95193 + os_free_mem(pAd, (PUCHAR)mpool);
95194 + return;
95195 + }
95196 +
95197 + // 2. Check MIC value
95198 + // Save the MIC and replace with zero
95199 + NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
95200 + NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
95201 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95202 + {
95203 + // AES
95204 + HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95205 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95206 + }
95207 + else
95208 + {
95209 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);
95210 + }
95211 +
95212 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
95213 + {
95214 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));
95215 + os_free_mem(pAd, (PUCHAR)mpool);
95216 + return;
95217 + }
95218 + else
95219 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));
95220 +
95221 + // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger
95222 + if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
95223 + {
95224 + os_free_mem(pAd, (PUCHAR)mpool);
95225 + return;
95226 + }
95227 +
95228 + // Update new replay counter
95229 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95230 +
95231 + // 4. Double check ANonce
95232 + if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))
95233 + {
95234 + os_free_mem(pAd, (PUCHAR)mpool);
95235 + return;
95236 + }
95237 +
95238 + // Obtain GTK
95239 + // 5. Decrypt GTK from Key Data
95240 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("EKD = %d\n", peerKeyInfo.EKD_DL));
95241 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95242 + {
95243 + // Decrypt AES GTK
95244 + AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pMsg3->KeyDesc.KeyDataLen[1],pMsg3->KeyDesc.KeyData);
95245 + }
95246 + else // TKIP
95247 + {
95248 + INT i;
95249 + // Decrypt TKIP GTK
95250 + // Construct 32 bytes RC4 Key
95251 + NdisMoveMemory(Key, pMsg3->KeyDesc.KeyIv, 16);
95252 + NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);
95253 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
95254 + //discard first 256 bytes
95255 + for(i = 0; i < 256; i++)
95256 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
95257 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
95258 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);
95259 + }
95260 +
95261 + if (!ParseKeyData(pAd, KEYDATA, pMsg3->KeyDesc.KeyDataLen[1], 1))
95262 + {
95263 + os_free_mem(pAd, (PUCHAR)mpool);
95264 + return;
95265 + }
95266 +
95267 + // Update GTK to ASIC
95268 + // Update group key information to ASIC Shared Key Table
95269 + AsicAddSharedKeyEntry(pAd,
95270 + BSS0,
95271 + pAd->StaCfg.DefaultKeyId,
95272 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
95273 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
95274 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
95275 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
95276 +
95277 + // Update ASIC WCID attribute table and IVEIV table
95278 + RTMPAddWcidAttributeEntry(pAd,
95279 + BSS0,
95280 + pAd->StaCfg.DefaultKeyId,
95281 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
95282 + NULL);
95283 +
95284 + // init 802.3 header and Fill Packet
95285 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
95286 +
95287 + // Zero message 4 body
95288 + NdisZeroMemory(&Packet, sizeof(Packet));
95289 + Packet.ProVer = EAPOL_VER;
95290 + Packet.ProType = EAPOLKey;
95291 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
95292 +
95293 + //
95294 + // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)
95295 + //
95296 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
95297 +
95298 + // Key descriptor version and appropriate RSN IE
95299 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
95300 +
95301 + // Update Key Length
95302 + Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];
95303 + Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];
95304 +
95305 + // Key Type PeerKey
95306 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
95307 +
95308 + // KeyMic field presented
95309 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
95310 + Packet.KeyDesc.KeyInfo.Secure = 1;
95311 +
95312 + // Convert to little-endian format.
95313 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
95314 +
95315 + // Key Replay count
95316 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95317 +
95318 + // Out buffer for transmitting message 4
95319 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
95320 + if(pOutBuffer == NULL)
95321 + {
95322 + os_free_mem(pAd, (PUCHAR)mpool);
95323 + return;
95324 + }
95325 +
95326 + // Prepare EAPOL frame for MIC calculation
95327 + // Be careful, only EAPOL frame is counted for MIC calculation
95328 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95329 + Packet.Body_Len[1] + 4, &Packet,
95330 + END_OF_ARGS);
95331 +
95332 + // Prepare and Fill MIC value
95333 + NdisZeroMemory(Mic, sizeof(Mic));
95334 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95335 + {
95336 + // AES
95337 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95338 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95339 + }
95340 + else
95341 + {
95342 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
95343 + }
95344 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
95345 +
95346 + // Update PTK
95347 + // Prepare pair-wise key information into shared key table
95348 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
95349 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
95350 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
95351 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
95352 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
95353 +
95354 + // Decide its ChiperAlg
95355 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
95356 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
95357 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
95358 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
95359 + else
95360 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
95361 +
95362 + // Update these related information to MAC_TABLE_ENTRY
95363 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
95364 + NdisMoveMemory(&pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
95365 + NdisMoveMemory(&pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
95366 + NdisMoveMemory(&pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
95367 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
95368 +
95369 + // Update pairwise key information to ASIC Shared Key Table
95370 + AsicAddSharedKeyEntry(pAd,
95371 + BSS0,
95372 + 0,
95373 + pAd->SharedKey[BSS0][0].CipherAlg,
95374 + pAd->SharedKey[BSS0][0].Key,
95375 + pAd->SharedKey[BSS0][0].TxMic,
95376 + pAd->SharedKey[BSS0][0].RxMic);
95377 +
95378 + // Update ASIC WCID attribute table and IVEIV table
95379 + RTMPAddWcidAttributeEntry(pAd,
95380 + BSS0,
95381 + 0,
95382 + pAd->SharedKey[BSS0][0].CipherAlg,
95383 + pEntry);
95384 +
95385 + // Make Transmitting frame
95386 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95387 + LENGTH_802_3, &Header802_3,
95388 + Packet.Body_Len[1] + 4, &Packet,
95389 + END_OF_ARGS);
95390 +
95391 +
95392 + // Copy frame to Tx ring and Send Message 4 to authenticator
95393 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
95394 +
95395 + // set 802.1x port control
95396 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
95397 + STA_PORT_SECURED(pAd);
95398 +
95399 + // Indicate Connected for GUI
95400 + pAd->IndicateMediaState = NdisMediaStateConnected;
95401 +
95402 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
95403 + os_free_mem(pAd, (PUCHAR)mpool);
95404 +
95405 +
95406 + // send wireless event - for set key done WPA2
95407 + if (pAd->CommonCfg.bWirelessEvent)
95408 + RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pEntry->Addr, BSS0, 0);
95409 +
95410 + DBGPRINT(RT_DEBUG_ERROR, ("Wpa2PairMsg3Action <-----\n"));
95411 +
95412 +}
95413 +
95414 +/*
95415 + ========================================================================
95416 +
95417 + Routine Description:
95418 + Process Group key 2-way handshaking
95419 +
95420 + Arguments:
95421 + pAd Pointer to our adapter
95422 + Elem Message body
95423 +
95424 + Return Value:
95425 + None
95426 +
95427 + Note:
95428 +
95429 + ========================================================================
95430 +*/
95431 +VOID WpaGroupMsg1Action(
95432 + IN PRTMP_ADAPTER pAd,
95433 + IN MLME_QUEUE_ELEM *Elem)
95434 +
95435 +{
95436 + PUCHAR pOutBuffer = NULL;
95437 + UCHAR Header802_3[14];
95438 + ULONG FrameLen = 0;
95439 + EAPOL_PACKET Packet;
95440 + PEAPOL_PACKET pGroup;
95441 + UCHAR *mpool, *digest, *KEYDATA;
95442 + UCHAR Mic[16], OldMic[16];
95443 + UCHAR GTK[32], Key[32];
95444 + KEY_INFO peerKeyInfo;
95445 +
95446 + // allocate memory
95447 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);
95448 +
95449 + if(mpool == NULL)
95450 + return;
95451 +
95452 + // digest Len = 80.
95453 + digest = (UCHAR *) ROUND_UP(mpool, 4);
95454 + // KEYDATA Len = 512.
95455 + KEYDATA = (UCHAR *) ROUND_UP(digest + 80, 4);
95456 +
95457 + DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action ----->\n"));
95458 +
95459 + // Process Group Message 1 frame. skip 802.11 header(24) & LLC_SNAP header(8)
95460 + pGroup = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
95461 +
95462 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
95463 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pGroup->KeyDesc.KeyInfo, sizeof(KEY_INFO));
95464 +
95465 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
95466 +
95467 + // 0. Check cipher type match
95468 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))
95469 + {
95470 + os_free_mem(pAd, (PUCHAR)mpool);
95471 + return;
95472 + }
95473 + else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
95474 + {
95475 + os_free_mem(pAd, (PUCHAR)mpool);
95476 + return;
95477 + }
95478 +
95479 + // 1. Verify Replay counter
95480 + // Check Replay Counter, it has to be larger than last one. No need to be exact one larger
95481 + if(RTMPCompareMemory(pGroup->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
95482 + {
95483 + os_free_mem(pAd, (PUCHAR)mpool);
95484 + return;
95485 + }
95486 +
95487 + // Update new replay counter
95488 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95489 +
95490 + // 2. Verify MIC is valid
95491 + // Save the MIC and replace with zero
95492 + NdisMoveMemory(OldMic, pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
95493 + NdisZeroMemory(pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
95494 +
95495 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95496 + { // AES
95497 + HMAC_SHA1((PUCHAR) pGroup, pGroup->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95498 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95499 + }
95500 + else
95501 + { // TKIP
95502 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pGroup, pGroup->Body_Len[1] + 4, Mic);
95503 + }
95504 +
95505 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
95506 + {
95507 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in group msg 1 of 2-way handshake!!!!!!!!!! \n"));
95508 + MlmeFreeMemory(pAd, (PUCHAR)mpool);
95509 + return;
95510 + }
95511 + else
95512 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in group msg 1 of 2-way handshake!!!!!!!!!! \n"));
95513 +
95514 +
95515 + // 3. Decrypt GTK from Key Data
95516 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95517 + {
95518 + // Decrypt AES GTK
95519 + AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pGroup->KeyDesc.KeyDataLen[1], pGroup->KeyDesc.KeyData);
95520 + }
95521 + else // TKIP
95522 + {
95523 + INT i;
95524 +
95525 + // Decrypt TKIP GTK
95526 + // Construct 32 bytes RC4 Key
95527 + NdisMoveMemory(Key, pGroup->KeyDesc.KeyIv, 16);
95528 + NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);
95529 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
95530 + //discard first 256 bytes
95531 + for(i = 0; i < 256; i++)
95532 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
95533 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
95534 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pGroup->KeyDesc.KeyData, pGroup->KeyDesc.KeyDataLen[1]);
95535 + }
95536 +
95537 + // Process decrypted key data material
95538 + // Parse keyData to handle KDE format for WPA2PSK
95539 + if (peerKeyInfo.EKD_DL)
95540 + {
95541 + if (!ParseKeyData(pAd, KEYDATA, pGroup->KeyDesc.KeyDataLen[1], 0))
95542 + {
95543 + os_free_mem(pAd, (PUCHAR)mpool);
95544 + return;
95545 + }
95546 + }
95547 + else // WPAPSK
95548 + {
95549 + // set key material, TxMic and RxMic for WPAPSK
95550 + NdisMoveMemory(GTK, KEYDATA, 32);
95551 + NdisMoveMemory(pAd->StaCfg.GTK, GTK, 32);
95552 + pAd->StaCfg.DefaultKeyId = peerKeyInfo.KeyIndex;
95553 +
95554 + // Prepare pair-wise key information into shared key table
95555 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
95556 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
95557 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, GTK, LEN_TKIP_EK);
95558 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, &GTK[16], LEN_TKIP_RXMICK);
95559 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, &GTK[24], LEN_TKIP_TXMICK);
95560 +
95561 + // Update Shared Key CipherAlg
95562 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
95563 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
95564 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
95565 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
95566 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
95567 + else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled)
95568 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_WEP64;
95569 + else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
95570 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_WEP128;
95571 +
95572 + //hex_dump("Group Key :", pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, LEN_TKIP_EK);
95573 + }
95574 +
95575 + // Update group key information to ASIC Shared Key Table
95576 + AsicAddSharedKeyEntry(pAd,
95577 + BSS0,
95578 + pAd->StaCfg.DefaultKeyId,
95579 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
95580 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
95581 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
95582 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
95583 +
95584 + // Update ASIC WCID attribute table and IVEIV table
95585 + RTMPAddWcidAttributeEntry(pAd,
95586 + BSS0,
95587 + pAd->StaCfg.DefaultKeyId,
95588 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
95589 + NULL);
95590 +
95591 + // set 802.1x port control
95592 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
95593 + STA_PORT_SECURED(pAd);
95594 +
95595 + // Indicate Connected for GUI
95596 + pAd->IndicateMediaState = NdisMediaStateConnected;
95597 +
95598 + // init header and Fill Packet
95599 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
95600 +
95601 + // Zero Group message 1 body
95602 + NdisZeroMemory(&Packet, sizeof(Packet));
95603 + Packet.ProVer = EAPOL_VER;
95604 + Packet.ProType = EAPOLKey;
95605 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
95606 +
95607 + //
95608 + // Group Message 2 as EAPOL-Key(1,0,0,0,G,0,0,MIC,0)
95609 + //
95610 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
95611 + {
95612 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
95613 + }
95614 + else
95615 + {
95616 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
95617 + }
95618 +
95619 + // Key descriptor version and appropriate RSN IE
95620 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
95621 +
95622 + // Update Key Length
95623 + Packet.KeyDesc.KeyLength[0] = pGroup->KeyDesc.KeyLength[0];
95624 + Packet.KeyDesc.KeyLength[1] = pGroup->KeyDesc.KeyLength[1];
95625 +
95626 + // Key Index as G-Msg 1
95627 + if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
95628 + Packet.KeyDesc.KeyInfo.KeyIndex = peerKeyInfo.KeyIndex;
95629 +
95630 + // Key Type Group key
95631 + Packet.KeyDesc.KeyInfo.KeyType = GROUPKEY;
95632 +
95633 + // KeyMic field presented
95634 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
95635 +
95636 + // Secure bit
95637 + Packet.KeyDesc.KeyInfo.Secure = 1;
95638 +
95639 + // Convert to little-endian format.
95640 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
95641 +
95642 + // Key Replay count
95643 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95644 +
95645 + // Out buffer for transmitting group message 2
95646 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
95647 + if(pOutBuffer == NULL)
95648 + {
95649 + MlmeFreeMemory(pAd, (PUCHAR)mpool);
95650 + return;
95651 + }
95652 +
95653 + // Prepare EAPOL frame for MIC calculation
95654 + // Be careful, only EAPOL frame is counted for MIC calculation
95655 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95656 + Packet.Body_Len[1] + 4, &Packet,
95657 + END_OF_ARGS);
95658 +
95659 + // Prepare and Fill MIC value
95660 + NdisZeroMemory(Mic, sizeof(Mic));
95661 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95662 + {
95663 + // AES
95664 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
95665 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95666 + }
95667 + else
95668 + {
95669 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
95670 + }
95671 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
95672 +
95673 +
95674 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95675 + LENGTH_802_3, &Header802_3,
95676 + Packet.Body_Len[1] + 4, &Packet,
95677 + END_OF_ARGS);
95678 +
95679 +
95680 + // 5. Copy frame to Tx ring and prepare for encryption
95681 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);
95682 +
95683 + // 6 Free allocated memory
95684 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
95685 + os_free_mem(pAd, (PUCHAR)mpool);
95686 +
95687 + // send wireless event - for set key done WPA2
95688 + if (pAd->CommonCfg.bWirelessEvent)
95689 + RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
95690 +
95691 + DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action <-----\n"));
95692 +}
95693 +
95694 +/*
95695 + ========================================================================
95696 +
95697 + Routine Description:
95698 + Init WPA MAC header
95699 +
95700 + Arguments:
95701 + pAd Pointer to our adapter
95702 +
95703 + Return Value:
95704 + None
95705 +
95706 + Note:
95707 +
95708 + ========================================================================
95709 +*/
95710 +VOID WpaMacHeaderInit(
95711 + IN PRTMP_ADAPTER pAd,
95712 + IN OUT PHEADER_802_11 pHdr80211,
95713 + IN UCHAR wep,
95714 + IN PUCHAR pAddr1)
95715 +{
95716 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
95717 + pHdr80211->FC.Type = BTYPE_DATA;
95718 + pHdr80211->FC.ToDs = 1;
95719 + if (wep == 1)
95720 + pHdr80211->FC.Wep = 1;
95721 +
95722 + // Addr1: BSSID, Addr2: SA, Addr3: DA
95723 + COPY_MAC_ADDR(pHdr80211->Addr1, pAddr1);
95724 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
95725 + COPY_MAC_ADDR(pHdr80211->Addr3, pAd->CommonCfg.Bssid);
95726 + pHdr80211->Sequence = pAd->Sequence;
95727 +}
95728 +
95729 +/*
95730 + ========================================================================
95731 +
95732 + Routine Description:
95733 + Copy frame from waiting queue into relative ring buffer and set
95734 + appropriate ASIC register to kick hardware encryption before really
95735 + sent out to air.
95736 +
95737 + Arguments:
95738 + pAd Pointer to our adapter
95739 + PNDIS_PACKET Pointer to outgoing Ndis frame
95740 + NumberOfFrag Number of fragment required
95741 +
95742 + Return Value:
95743 + None
95744 +
95745 + Note:
95746 +
95747 + ========================================================================
95748 +*/
95749 +VOID RTMPToWirelessSta(
95750 + IN PRTMP_ADAPTER pAd,
95751 + IN PUCHAR pHeader802_3,
95752 + IN UINT HdrLen,
95753 + IN PUCHAR pData,
95754 + IN UINT DataLen,
95755 + IN BOOLEAN is4wayFrame)
95756 +
95757 +{
95758 + NDIS_STATUS Status;
95759 + PNDIS_PACKET pPacket;
95760 + UCHAR Index;
95761 +
95762 + do
95763 + {
95764 + // 1. build a NDIS packet and call RTMPSendPacket();
95765 + // be careful about how/when to release this internal allocated NDIS PACKET buffer
95766 + Status = RTMPAllocateNdisPacket(pAd, &pPacket, pHeader802_3, HdrLen, pData, DataLen);
95767 + if (Status != NDIS_STATUS_SUCCESS)
95768 + break;
95769 +
95770 + if (is4wayFrame)
95771 + RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 1);
95772 + else
95773 + RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 0);
95774 +
95775 + // 2. send out the packet
95776 + Status = STASendPacket(pAd, pPacket);
95777 + if(Status == NDIS_STATUS_SUCCESS)
95778 + {
95779 + // Dequeue one frame from TxSwQueue0..3 queue and process it
95780 + // There are three place calling dequeue for TX ring.
95781 + // 1. Here, right after queueing the frame.
95782 + // 2. At the end of TxRingTxDone service routine.
95783 + // 3. Upon NDIS call RTMPSendPackets
95784 + if((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
95785 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)))
95786 + {
95787 + for(Index = 0; Index < 5; Index ++)
95788 + if(pAd->TxSwQueue[Index].Number > 0)
95789 + RTMPDeQueuePacket(pAd, FALSE, Index, MAX_TX_PROCESS);
95790 + }
95791 + }
95792 + } while(FALSE);
95793 +
95794 +}
95795 +
95796 +/*
95797 + ========================================================================
95798 +
95799 + Routine Description:
95800 + Check Sanity RSN IE form AP
95801 +
95802 + Arguments:
95803 +
95804 + Return Value:
95805 +
95806 +
95807 + ========================================================================
95808 +*/
95809 +BOOLEAN CheckRSNIE(
95810 + IN PRTMP_ADAPTER pAd,
95811 + IN PUCHAR pData,
95812 + IN UCHAR DataLen,
95813 + OUT UCHAR *Offset)
95814 +{
95815 + PUCHAR pVIE;
95816 + UCHAR len;
95817 + PEID_STRUCT pEid;
95818 + BOOLEAN result = FALSE;
95819 +
95820 + pVIE = pData;
95821 + len = DataLen;
95822 + *Offset = 0;
95823 +
95824 + while (len > sizeof(RSNIE2))
95825 + {
95826 + pEid = (PEID_STRUCT) pVIE;
95827 + // WPA RSN IE
95828 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
95829 + {
95830 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) &&
95831 + (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&
95832 + (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))
95833 + {
95834 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA/WPAPSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));
95835 + result = TRUE;
95836 + }
95837 +
95838 + *Offset += (pEid->Len + 2);
95839 + }
95840 + // WPA2 RSN IE
95841 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
95842 + {
95843 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) &&
95844 + (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&
95845 + (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))
95846 + {
95847 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));
95848 + result = TRUE;
95849 + }
95850 +
95851 + *Offset += (pEid->Len + 2);
95852 + }
95853 + else
95854 + {
95855 + break;
95856 + }
95857 +
95858 + pVIE += (pEid->Len + 2);
95859 + len -= (pEid->Len + 2);
95860 + }
95861 +
95862 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> skip_offset(%d) \n", *Offset));
95863 +
95864 + return result;
95865 +
95866 +}
95867 +
95868 +
95869 +/*
95870 + ========================================================================
95871 +
95872 + Routine Description:
95873 + Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
95874 + GTK is encaptulated in KDE format at p.83 802.11i D10
95875 +
95876 + Arguments:
95877 +
95878 + Return Value:
95879 +
95880 + Note:
95881 + 802.11i D10
95882 +
95883 + ========================================================================
95884 +*/
95885 +BOOLEAN ParseKeyData(
95886 + IN PRTMP_ADAPTER pAd,
95887 + IN PUCHAR pKeyData,
95888 + IN UCHAR KeyDataLen,
95889 + IN UCHAR bPairewise)
95890 +{
95891 + PKDE_ENCAP pKDE = NULL;
95892 + PUCHAR pMyKeyData = pKeyData;
95893 + UCHAR KeyDataLength = KeyDataLen;
95894 + UCHAR GTKLEN;
95895 + UCHAR skip_offset;
95896 +
95897 + // Verify The RSN IE contained in Pairewise-Msg 3 and skip it
95898 + if (bPairewise)
95899 + {
95900 + // Check RSN IE whether it is WPA2/WPA2PSK
95901 + if (!CheckRSNIE(pAd, pKeyData, KeyDataLen, &skip_offset))
95902 + {
95903 + DBGPRINT(RT_DEBUG_ERROR, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE mismatched \n"));
95904 + hex_dump("Get KEYDATA :", pKeyData, KeyDataLen);
95905 + return FALSE;
95906 + }
95907 + else
95908 + {
95909 + // skip RSN IE
95910 + pMyKeyData += skip_offset;
95911 + KeyDataLength -= skip_offset;
95912 +
95913 + //DBGPRINT(RT_DEBUG_TRACE, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
95914 + }
95915 + }
95916 +
95917 + DBGPRINT(RT_DEBUG_TRACE,("ParseKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
95918 +
95919 + // Parse EKD format
95920 + if (KeyDataLength >= 8)
95921 + {
95922 + pKDE = (PKDE_ENCAP) pMyKeyData;
95923 + }
95924 + else
95925 + {
95926 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KeyDataLength is too short \n"));
95927 + return FALSE;
95928 + }
95929 +
95930 +
95931 + // Sanity check - shared key index should not be 0
95932 + if (pKDE->GTKEncap.Kid == 0)
95933 + {
95934 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index zero \n"));
95935 + return FALSE;
95936 + }
95937 +
95938 + // Sanity check - KED length
95939 + if (KeyDataLength < (pKDE->Len + 2))
95940 + {
95941 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
95942 + return FALSE;
95943 + }
95944 +
95945 + // Get GTK length - refer to IEEE 802.11i-2004 p.82
95946 + GTKLEN = pKDE->Len -6;
95947 +
95948 + if (GTKLEN < MIN_LEN_OF_GTK)
95949 + {
95950 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
95951 + return FALSE;
95952 + }
95953 + else
95954 + DBGPRINT(RT_DEBUG_TRACE, ("GTK Key with KDE formet got index=%d, len=%d \n", pKDE->GTKEncap.Kid, GTKLEN));
95955 +
95956 + // Update GTK
95957 + // set key material, TxMic and RxMic for WPAPSK
95958 + NdisMoveMemory(pAd->StaCfg.GTK, pKDE->GTKEncap.GTK, 32);
95959 + pAd->StaCfg.DefaultKeyId = pKDE->GTKEncap.Kid;
95960 +
95961 + // Update shared key table
95962 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
95963 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
95964 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKDE->GTKEncap.GTK, LEN_TKIP_EK);
95965 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, &pKDE->GTKEncap.GTK[16], LEN_TKIP_RXMICK);
95966 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, &pKDE->GTKEncap.GTK[24], LEN_TKIP_TXMICK);
95967 +
95968 + // Update Shared Key CipherAlg
95969 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
95970 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
95971 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
95972 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
95973 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
95974 + else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled)
95975 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_WEP64;
95976 + else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
95977 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_WEP128;
95978 +
95979 + return TRUE;
95980 +
95981 +}
95982 +
95983 +/*
95984 + ========================================================================
95985 +
95986 + Routine Description:
95987 + Cisco CCKM PRF function
95988 +
95989 + Arguments:
95990 + key Cisco Base Transient Key (BTK)
95991 + key_len The key length of the BTK
95992 + data Ruquest Number(RN) + BSSID
95993 + data_len The length of the data
95994 + output Store for PTK(Pairwise transient keys)
95995 + len The length of the output
95996 + Return Value:
95997 + None
95998 +
95999 + Note:
96000 + 802.1i Annex F.9
96001 +
96002 + ========================================================================
96003 +*/
96004 +VOID CCKMPRF(
96005 + IN UCHAR *key,
96006 + IN INT key_len,
96007 + IN UCHAR *data,
96008 + IN INT data_len,
96009 + OUT UCHAR *output,
96010 + IN INT len)
96011 +{
96012 + INT i;
96013 + UCHAR input[1024];
96014 + INT currentindex = 0;
96015 + INT total_len;
96016 +
96017 + NdisMoveMemory(input, data, data_len);
96018 + total_len = data_len;
96019 + input[total_len] = 0;
96020 + total_len++;
96021 + for (i = 0; i < (len + 19) / 20; i++)
96022 + {
96023 + HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
96024 + currentindex += 20;
96025 + input[total_len - 1]++;
96026 + }
96027 +}
96028 +
96029 +/*
96030 + ========================================================================
96031 +
96032 + Routine Description:
96033 + Process MIC error indication and record MIC error timer.
96034 +
96035 + Arguments:
96036 + pAd Pointer to our adapter
96037 + pWpaKey Pointer to the WPA key structure
96038 +
96039 + Return Value:
96040 + None
96041 +
96042 + IRQL = DISPATCH_LEVEL
96043 +
96044 + Note:
96045 +
96046 + ========================================================================
96047 +*/
96048 +VOID RTMPReportMicError(
96049 + IN PRTMP_ADAPTER pAd,
96050 + IN PCIPHER_KEY pWpaKey)
96051 +{
96052 + ULONG Now;
96053 + UCHAR unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1:0);
96054 +
96055 + // Record Last MIC error time and count
96056 + Now = jiffies;
96057 + if (pAd->StaCfg.MicErrCnt == 0)
96058 + {
96059 + pAd->StaCfg.MicErrCnt++;
96060 + pAd->StaCfg.LastMicErrorTime = Now;
96061 + NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
96062 + }
96063 + else if (pAd->StaCfg.MicErrCnt == 1)
96064 + {
96065 + if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now)
96066 + {
96067 + // Update Last MIC error time, this did not violate two MIC errors within 60 seconds
96068 + pAd->StaCfg.LastMicErrorTime = Now;
96069 + }
96070 + else
96071 + {
96072 +
96073 + if (pAd->CommonCfg.bWirelessEvent)
96074 + RTMPSendWirelessEvent(pAd, IW_COUNTER_MEASURES_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
96075 +
96076 + pAd->StaCfg.LastMicErrorTime = Now;
96077 + // Violate MIC error counts, MIC countermeasures kicks in
96078 + pAd->StaCfg.MicErrCnt++;
96079 + // We shall block all reception
96080 + // We shall clean all Tx ring and disassoicate from AP after next EAPOL frame
96081 + //
96082 + // No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets
96083 + // if pAd->StaCfg.MicErrCnt greater than 2.
96084 + //
96085 + // RTMPRingCleanUp(pAd, QID_AC_BK);
96086 + // RTMPRingCleanUp(pAd, QID_AC_BE);
96087 + // RTMPRingCleanUp(pAd, QID_AC_VI);
96088 + // RTMPRingCleanUp(pAd, QID_AC_VO);
96089 + // RTMPRingCleanUp(pAd, QID_HCCA);
96090 + }
96091 + }
96092 + else
96093 + {
96094 + // MIC error count >= 2
96095 + // This should not happen
96096 + ;
96097 + }
96098 + MlmeEnqueue(pAd,
96099 + MLME_CNTL_STATE_MACHINE,
96100 + OID_802_11_MIC_FAILURE_REPORT_FRAME,
96101 + 1,
96102 + &unicastKey);
96103 +
96104 + if (pAd->StaCfg.MicErrCnt == 2)
96105 + {
96106 + RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100);
96107 + }
96108 +}
96109 +
96110 +
96111 +#ifdef WPA_SUPPLICANT_SUPPORT
96112 +#define LENGTH_EAP_H 4
96113 +// If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)).
96114 +INT WpaCheckEapCode(
96115 + IN PRTMP_ADAPTER pAd,
96116 + IN PUCHAR pFrame,
96117 + IN USHORT FrameLen,
96118 + IN USHORT OffSet)
96119 +{
96120 +
96121 + PUCHAR pData;
96122 + INT result = 0;
96123 +
96124 + if( FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H )
96125 + return result;
96126 +
96127 + pData = pFrame + OffSet; // skip offset bytes
96128 +
96129 + if(*(pData+1) == EAPPacket) // 802.1x header - Packet Type
96130 + {
96131 + result = *(pData+4); // EAP header - Code
96132 + }
96133 +
96134 + return result;
96135 +}
96136 +
96137 +VOID WpaSendMicFailureToWpaSupplicant(
96138 + IN PRTMP_ADAPTER pAd,
96139 + IN BOOLEAN bUnicast)
96140 +{
96141 + union iwreq_data wrqu;
96142 + char custom[IW_CUSTOM_MAX] = {0};
96143 +
96144 + sprintf(custom, "MLME-MICHAELMICFAILURE.indication");
96145 + if (bUnicast)
96146 + sprintf(custom, "%s unicast", custom);
96147 + wrqu.data.length = strlen(custom);
96148 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
96149 +
96150 + return;
96151 +}
96152 +#endif // WPA_SUPPLICANT_SUPPORT //
96153 +
96154 +VOID WpaMicFailureReportFrame(
96155 + IN PRTMP_ADAPTER pAd,
96156 + IN MLME_QUEUE_ELEM *Elem)
96157 +{
96158 + PUCHAR pOutBuffer = NULL;
96159 + UCHAR Header802_3[14];
96160 + ULONG FrameLen = 0;
96161 + EAPOL_PACKET Packet;
96162 + UCHAR Mic[16];
96163 + BOOLEAN bUnicast;
96164 +
96165 + DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n"));
96166 +
96167 + bUnicast = (Elem->Msg[0] == 1 ? TRUE:FALSE);
96168 + pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER);
96169 +
96170 + // init 802.3 header and Fill Packet
96171 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
96172 +
96173 + NdisZeroMemory(&Packet, sizeof(Packet));
96174 + Packet.ProVer = EAPOL_VER;
96175 + Packet.ProType = EAPOLKey;
96176 +
96177 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
96178 +
96179 + // Request field presented
96180 + Packet.KeyDesc.KeyInfo.Request = 1;
96181 +
96182 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96183 + {
96184 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
96185 + }
96186 + else // TKIP
96187 + {
96188 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
96189 + }
96190 +
96191 + Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY);
96192 +
96193 + // KeyMic field presented
96194 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
96195 +
96196 + // Error field presented
96197 + Packet.KeyDesc.KeyInfo.Error = 1;
96198 +
96199 + // Update packet length after decide Key data payload
96200 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE;
96201 +
96202 + // Key Replay Count
96203 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
96204 + inc_byte_array(pAd->StaCfg.ReplayCounter, 8);
96205 +
96206 + // Convert to little-endian format.
96207 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
96208 +
96209 +
96210 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
96211 + if(pOutBuffer == NULL)
96212 + {
96213 + return;
96214 + }
96215 +
96216 + // Prepare EAPOL frame for MIC calculation
96217 + // Be careful, only EAPOL frame is counted for MIC calculation
96218 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96219 + Packet.Body_Len[1] + 4, &Packet,
96220 + END_OF_ARGS);
96221 +
96222 + // Prepare and Fill MIC value
96223 + NdisZeroMemory(Mic, sizeof(Mic));
96224 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96225 + { // AES
96226 + UCHAR digest[20] = {0};
96227 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96228 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96229 + }
96230 + else
96231 + { // TKIP
96232 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
96233 + }
96234 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
96235 +
96236 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96237 + LENGTH_802_3, &Header802_3,
96238 + Packet.Body_Len[1] + 4, &Packet,
96239 + END_OF_ARGS);
96240 +
96241 + // opy frame to Tx ring and send MIC failure report frame to authenticator
96242 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);
96243 +
96244 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
96245 +
96246 + DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n"));
96247 +}
96248 +
96249 +/** from wpa_supplicant
96250 + * inc_byte_array - Increment arbitrary length byte array by one
96251 + * @counter: Pointer to byte array
96252 + * @len: Length of the counter in bytes
96253 + *
96254 + * This function increments the last byte of the counter by one and continues
96255 + * rolling over to more significant bytes if the byte was incremented from
96256 + * 0xff to 0x00.
96257 + */
96258 +void inc_byte_array(UCHAR *counter, int len)
96259 +{
96260 + int pos = len - 1;
96261 + while (pos >= 0) {
96262 + counter[pos]++;
96263 + if (counter[pos] != 0)
96264 + break;
96265 + pos--;
96266 + }
96267 +}
96268 +
96269 +VOID WpaDisassocApAndBlockAssoc(
96270 + IN PVOID SystemSpecific1,
96271 + IN PVOID FunctionContext,
96272 + IN PVOID SystemSpecific2,
96273 + IN PVOID SystemSpecific3)
96274 +{
96275 + RTMP_ADAPTER *pAd = (PRTMP_ADAPTER)FunctionContext;
96276 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
96277 +
96278 + // disassoc from current AP first
96279 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n"));
96280 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_MIC_FAILURE);
96281 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
96282 +
96283 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
96284 + pAd->StaCfg.bBlockAssoc = TRUE;
96285 +}
96286 +
96287 --- /dev/null
96288 +++ b/drivers/staging/rt2870/tmp60
96289 @@ -0,0 +1,7037 @@
96290 +/*
96291 + *************************************************************************
96292 + * Ralink Tech Inc.
96293 + * 5F., No.36, Taiyuan St., Jhubei City,
96294 + * Hsinchu County 302,
96295 + * Taiwan, R.O.C.
96296 + *
96297 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
96298 + *
96299 + * This program is free software; you can redistribute it and/or modify *
96300 + * it under the terms of the GNU General Public License as published by *
96301 + * the Free Software Foundation; either version 2 of the License, or *
96302 + * (at your option) any later version. *
96303 + * *
96304 + * This program is distributed in the hope that it will be useful, *
96305 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
96306 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
96307 + * GNU General Public License for more details. *
96308 + * *
96309 + * You should have received a copy of the GNU General Public License *
96310 + * along with this program; if not, write to the *
96311 + * Free Software Foundation, Inc., *
96312 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
96313 + * *
96314 + *************************************************************************
96315 +
96316 + Module Name:
96317 + sta_ioctl.c
96318 +
96319 + Abstract:
96320 + IOCTL related subroutines
96321 +
96322 + Revision History:
96323 + Who When What
96324 + -------- ---------- ----------------------------------------------
96325 + Rory Chen 01-03-2003 created
96326 + Rory Chen 02-14-2005 modify to support RT61
96327 +*/
96328 +
96329 +#include "rt_config.h"
96330 +
96331 +#ifdef DBG
96332 +extern ULONG RTDebugLevel;
96333 +#endif
96334 +
96335 +#define NR_WEP_KEYS 4
96336 +#define WEP_SMALL_KEY_LEN (40/8)
96337 +#define WEP_LARGE_KEY_LEN (104/8)
96338 +
96339 +#define GROUP_KEY_NO 4
96340 +
96341 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
96342 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_A, _B, _C, _D, _E)
96343 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_A, _B, _C, _D, _E)
96344 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_A, _B, _C, _D, _E, _F)
96345 +#else
96346 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_B, _C, _D, _E)
96347 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_B, _C, _D, _E)
96348 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_B, _C, _D, _E, _F)
96349 +#endif
96350 +
96351 +extern UCHAR CipherWpa2Template[];
96352 +extern UCHAR CipherWpaPskTkip[];
96353 +extern UCHAR CipherWpaPskTkipLen;
96354 +
96355 +typedef struct PACKED _RT_VERSION_INFO{
96356 + UCHAR DriverVersionW;
96357 + UCHAR DriverVersionX;
96358 + UCHAR DriverVersionY;
96359 + UCHAR DriverVersionZ;
96360 + UINT DriverBuildYear;
96361 + UINT DriverBuildMonth;
96362 + UINT DriverBuildDay;
96363 +} RT_VERSION_INFO, *PRT_VERSION_INFO;
96364 +
96365 +struct iw_priv_args privtab[] = {
96366 +{ RTPRIV_IOCTL_SET,
96367 + IW_PRIV_TYPE_CHAR | 1024, 0,
96368 + "set"},
96369 +
96370 +{ RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
96371 + ""},
96372 +{ RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
96373 + ""},
96374 +/* --- sub-ioctls definitions --- */
96375 + { SHOW_CONN_STATUS,
96376 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
96377 + { SHOW_DRVIER_VERION,
96378 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
96379 + { SHOW_BA_INFO,
96380 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
96381 + { SHOW_DESC_INFO,
96382 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
96383 + { RAIO_OFF,
96384 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
96385 + { RAIO_ON,
96386 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
96387 +#ifdef QOS_DLS_SUPPORT
96388 + { SHOW_DLS_ENTRY_INFO,
96389 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
96390 +#endif // QOS_DLS_SUPPORT //
96391 + { SHOW_CFG_VALUE,
96392 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
96393 + { SHOW_ADHOC_ENTRY_INFO,
96394 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
96395 +
96396 +/* --- sub-ioctls relations --- */
96397 +
96398 +#ifdef DBG
96399 +{ RTPRIV_IOCTL_BBP,
96400 + IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
96401 + "bbp"},
96402 +{ RTPRIV_IOCTL_MAC,
96403 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
96404 + "mac"},
96405 +{ RTPRIV_IOCTL_E2P,
96406 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
96407 + "e2p"},
96408 +#endif /* DBG */
96409 +
96410 +{ RTPRIV_IOCTL_STATISTICS,
96411 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
96412 + "stat"},
96413 +{ RTPRIV_IOCTL_GSITESURVEY,
96414 + 0, IW_PRIV_TYPE_CHAR | 1024,
96415 + "get_site_survey"},
96416 +};
96417 +
96418 +INT Set_SSID_Proc(
96419 + IN PRTMP_ADAPTER pAdapter,
96420 + IN PUCHAR arg);
96421 +
96422 +#ifdef WMM_SUPPORT
96423 +INT Set_WmmCapable_Proc(
96424 + IN PRTMP_ADAPTER pAd,
96425 + IN PUCHAR arg);
96426 +#endif
96427 +
96428 +INT Set_NetworkType_Proc(
96429 + IN PRTMP_ADAPTER pAdapter,
96430 + IN PUCHAR arg);
96431 +
96432 +INT Set_AuthMode_Proc(
96433 + IN PRTMP_ADAPTER pAdapter,
96434 + IN PUCHAR arg);
96435 +
96436 +INT Set_EncrypType_Proc(
96437 + IN PRTMP_ADAPTER pAdapter,
96438 + IN PUCHAR arg);
96439 +
96440 +INT Set_DefaultKeyID_Proc(
96441 + IN PRTMP_ADAPTER pAdapter,
96442 + IN PUCHAR arg);
96443 +
96444 +INT Set_Key1_Proc(
96445 + IN PRTMP_ADAPTER pAdapter,
96446 + IN PUCHAR arg);
96447 +
96448 +INT Set_Key2_Proc(
96449 + IN PRTMP_ADAPTER pAdapter,
96450 + IN PUCHAR arg);
96451 +
96452 +INT Set_Key3_Proc(
96453 + IN PRTMP_ADAPTER pAdapter,
96454 + IN PUCHAR arg);
96455 +
96456 +INT Set_Key4_Proc(
96457 + IN PRTMP_ADAPTER pAdapter,
96458 + IN PUCHAR arg);
96459 +
96460 +INT Set_WPAPSK_Proc(
96461 + IN PRTMP_ADAPTER pAdapter,
96462 + IN PUCHAR arg);
96463 +
96464 +
96465 +INT Set_PSMode_Proc(
96466 + IN PRTMP_ADAPTER pAdapter,
96467 + IN PUCHAR arg);
96468 +
96469 +#ifdef WPA_SUPPLICANT_SUPPORT
96470 +INT Set_Wpa_Support(
96471 + IN PRTMP_ADAPTER pAd,
96472 + IN PUCHAR arg);
96473 +#endif // WPA_SUPPLICANT_SUPPORT //
96474 +
96475 +#ifdef DBG
96476 +VOID RTMPIoctlBBP(
96477 + IN PRTMP_ADAPTER pAdapter,
96478 + IN struct iwreq *wrq);
96479 +
96480 +VOID RTMPIoctlMAC(
96481 + IN PRTMP_ADAPTER pAdapter,
96482 + IN struct iwreq *wrq);
96483 +
96484 +VOID RTMPIoctlE2PROM(
96485 + IN PRTMP_ADAPTER pAdapter,
96486 + IN struct iwreq *wrq);
96487 +#endif // DBG //
96488 +
96489 +
96490 +NDIS_STATUS RTMPWPANoneAddKeyProc(
96491 + IN PRTMP_ADAPTER pAd,
96492 + IN PVOID pBuf);
96493 +
96494 +INT Set_FragTest_Proc(
96495 + IN PRTMP_ADAPTER pAdapter,
96496 + IN PUCHAR arg);
96497 +
96498 +#ifdef DOT11_N_SUPPORT
96499 +INT Set_TGnWifiTest_Proc(
96500 + IN PRTMP_ADAPTER pAd,
96501 + IN PUCHAR arg);
96502 +#endif // DOT11_N_SUPPORT //
96503 +
96504 +INT Set_LongRetryLimit_Proc(
96505 + IN PRTMP_ADAPTER pAdapter,
96506 + IN PUCHAR arg);
96507 +
96508 +INT Set_ShortRetryLimit_Proc(
96509 + IN PRTMP_ADAPTER pAdapter,
96510 + IN PUCHAR arg);
96511 +
96512 +#ifdef EXT_BUILD_CHANNEL_LIST
96513 +INT Set_Ieee80211dClientMode_Proc(
96514 + IN PRTMP_ADAPTER pAdapter,
96515 + IN PUCHAR arg);
96516 +#endif // EXT_BUILD_CHANNEL_LIST //
96517 +
96518 +#ifdef CARRIER_DETECTION_SUPPORT
96519 +INT Set_CarrierDetect_Proc(
96520 + IN PRTMP_ADAPTER pAd,
96521 + IN PUCHAR arg);
96522 +#endif // CARRIER_DETECTION_SUPPORT //
96523 +
96524 +INT Show_Adhoc_MacTable_Proc(
96525 + IN PRTMP_ADAPTER pAd,
96526 + IN PCHAR extra);
96527 +
96528 +static struct {
96529 + CHAR *name;
96530 + INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
96531 +} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
96532 + {"DriverVersion", Set_DriverVersion_Proc},
96533 + {"CountryRegion", Set_CountryRegion_Proc},
96534 + {"CountryRegionABand", Set_CountryRegionABand_Proc},
96535 + {"SSID", Set_SSID_Proc},
96536 + {"WirelessMode", Set_WirelessMode_Proc},
96537 + {"TxBurst", Set_TxBurst_Proc},
96538 + {"TxPreamble", Set_TxPreamble_Proc},
96539 + {"TxPower", Set_TxPower_Proc},
96540 + {"Channel", Set_Channel_Proc},
96541 + {"BGProtection", Set_BGProtection_Proc},
96542 + {"RTSThreshold", Set_RTSThreshold_Proc},
96543 + {"FragThreshold", Set_FragThreshold_Proc},
96544 +#ifdef DOT11_N_SUPPORT
96545 + {"HtBw", Set_HtBw_Proc},
96546 + {"HtMcs", Set_HtMcs_Proc},
96547 + {"HtGi", Set_HtGi_Proc},
96548 + {"HtOpMode", Set_HtOpMode_Proc},
96549 + {"HtExtcha", Set_HtExtcha_Proc},
96550 + {"HtMpduDensity", Set_HtMpduDensity_Proc},
96551 + {"HtBaWinSize", Set_HtBaWinSize_Proc},
96552 + {"HtRdg", Set_HtRdg_Proc},
96553 + {"HtAmsdu", Set_HtAmsdu_Proc},
96554 + {"HtAutoBa", Set_HtAutoBa_Proc},
96555 + {"HtBaDecline", Set_BADecline_Proc},
96556 + {"HtProtect", Set_HtProtect_Proc},
96557 + {"HtMimoPs", Set_HtMimoPs_Proc},
96558 +#endif // DOT11_N_SUPPORT //
96559 +
96560 +#ifdef AGGREGATION_SUPPORT
96561 + {"PktAggregate", Set_PktAggregate_Proc},
96562 +#endif
96563 +
96564 +#ifdef WMM_SUPPORT
96565 + {"WmmCapable", Set_WmmCapable_Proc},
96566 +#endif
96567 + {"IEEE80211H", Set_IEEE80211H_Proc},
96568 + {"NetworkType", Set_NetworkType_Proc},
96569 + {"AuthMode", Set_AuthMode_Proc},
96570 + {"EncrypType", Set_EncrypType_Proc},
96571 + {"DefaultKeyID", Set_DefaultKeyID_Proc},
96572 + {"Key1", Set_Key1_Proc},
96573 + {"Key2", Set_Key2_Proc},
96574 + {"Key3", Set_Key3_Proc},
96575 + {"Key4", Set_Key4_Proc},
96576 + {"WPAPSK", Set_WPAPSK_Proc},
96577 + {"ResetCounter", Set_ResetStatCounter_Proc},
96578 + {"PSMode", Set_PSMode_Proc},
96579 +#ifdef DBG
96580 + {"Debug", Set_Debug_Proc},
96581 +#endif
96582 +
96583 +#ifdef RALINK_ATE
96584 + {"ATE", Set_ATE_Proc},
96585 + {"ATEDA", Set_ATE_DA_Proc},
96586 + {"ATESA", Set_ATE_SA_Proc},
96587 + {"ATEBSSID", Set_ATE_BSSID_Proc},
96588 + {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
96589 + {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
96590 + {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
96591 + {"ATETXANT", Set_ATE_TX_Antenna_Proc},
96592 + {"ATERXANT", Set_ATE_RX_Antenna_Proc},
96593 + {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
96594 + {"ATETXBW", Set_ATE_TX_BW_Proc},
96595 + {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
96596 + {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
96597 + {"ATETXMCS", Set_ATE_TX_MCS_Proc},
96598 + {"ATETXMODE", Set_ATE_TX_MODE_Proc},
96599 + {"ATETXGI", Set_ATE_TX_GI_Proc},
96600 + {"ATERXFER", Set_ATE_RX_FER_Proc},
96601 + {"ATERRF", Set_ATE_Read_RF_Proc},
96602 + {"ATEWRF1", Set_ATE_Write_RF1_Proc},
96603 + {"ATEWRF2", Set_ATE_Write_RF2_Proc},
96604 + {"ATEWRF3", Set_ATE_Write_RF3_Proc},
96605 + {"ATEWRF4", Set_ATE_Write_RF4_Proc},
96606 + {"ATELDE2P", Set_ATE_Load_E2P_Proc},
96607 + {"ATERE2P", Set_ATE_Read_E2P_Proc},
96608 + {"ATESHOW", Set_ATE_Show_Proc},
96609 + {"ATEHELP", Set_ATE_Help_Proc},
96610 +
96611 +#ifdef RALINK_28xx_QA
96612 + {"TxStop", Set_TxStop_Proc},
96613 + {"RxStop", Set_RxStop_Proc},
96614 +#endif // RALINK_28xx_QA //
96615 +#endif // RALINK_ATE //
96616 +
96617 +#ifdef WPA_SUPPLICANT_SUPPORT
96618 + {"WpaSupport", Set_Wpa_Support},
96619 +#endif // WPA_SUPPLICANT_SUPPORT //
96620 +
96621 +
96622 +
96623 + {"FixedTxMode", Set_FixedTxMode_Proc},
96624 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
96625 + {"OpMode", Set_OpMode_Proc},
96626 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
96627 +#ifdef DOT11_N_SUPPORT
96628 + {"TGnWifiTest", Set_TGnWifiTest_Proc},
96629 + {"ForceGF", Set_ForceGF_Proc},
96630 +#endif // DOT11_N_SUPPORT //
96631 +#ifdef QOS_DLS_SUPPORT
96632 + {"DlsAddEntry", Set_DlsAddEntry_Proc},
96633 + {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
96634 +#endif // QOS_DLS_SUPPORT //
96635 + {"LongRetry", Set_LongRetryLimit_Proc},
96636 + {"ShortRetry", Set_ShortRetryLimit_Proc},
96637 +#ifdef EXT_BUILD_CHANNEL_LIST
96638 + {"11dClientMode", Set_Ieee80211dClientMode_Proc},
96639 +#endif // EXT_BUILD_CHANNEL_LIST //
96640 +#ifdef CARRIER_DETECTION_SUPPORT
96641 + {"CarrierDetect", Set_CarrierDetect_Proc},
96642 +#endif // CARRIER_DETECTION_SUPPORT //
96643 +
96644 + {NULL,}
96645 +};
96646 +
96647 +
96648 +VOID RTMPAddKey(
96649 + IN PRTMP_ADAPTER pAd,
96650 + IN PNDIS_802_11_KEY pKey)
96651 +{
96652 + ULONG KeyIdx;
96653 + MAC_TABLE_ENTRY *pEntry;
96654 +
96655 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
96656 +
96657 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
96658 + {
96659 + if (pKey->KeyIndex & 0x80000000)
96660 + {
96661 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
96662 + {
96663 + NdisZeroMemory(pAd->StaCfg.PMK, 32);
96664 + NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
96665 + goto end;
96666 + }
96667 + // Update PTK
96668 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
96669 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
96670 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
96671 +#ifdef WPA_SUPPLICANT_SUPPORT
96672 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
96673 + {
96674 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
96675 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
96676 + }
96677 + else
96678 +#endif // WPA_SUPPLICANT_SUPPORT //
96679 + {
96680 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
96681 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
96682 + }
96683 +
96684 + // Decide its ChiperAlg
96685 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
96686 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
96687 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
96688 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
96689 + else
96690 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
96691 +
96692 + // Update these related information to MAC_TABLE_ENTRY
96693 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
96694 + NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
96695 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
96696 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
96697 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
96698 +
96699 + // Update pairwise key information to ASIC Shared Key Table
96700 + AsicAddSharedKeyEntry(pAd,
96701 + BSS0,
96702 + 0,
96703 + pAd->SharedKey[BSS0][0].CipherAlg,
96704 + pAd->SharedKey[BSS0][0].Key,
96705 + pAd->SharedKey[BSS0][0].TxMic,
96706 + pAd->SharedKey[BSS0][0].RxMic);
96707 +
96708 + // Update ASIC WCID attribute table and IVEIV table
96709 + RTMPAddWcidAttributeEntry(pAd,
96710 + BSS0,
96711 + 0,
96712 + pAd->SharedKey[BSS0][0].CipherAlg,
96713 + pEntry);
96714 +
96715 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
96716 + {
96717 + // set 802.1x port control
96718 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
96719 + STA_PORT_SECURED(pAd);
96720 +
96721 + // Indicate Connected for GUI
96722 + pAd->IndicateMediaState = NdisMediaStateConnected;
96723 + }
96724 + }
96725 + else
96726 + {
96727 + // Update GTK
96728 + pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
96729 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
96730 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
96731 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
96732 +#ifdef WPA_SUPPLICANT_SUPPORT
96733 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
96734 + {
96735 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
96736 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
96737 + }
96738 + else
96739 +#endif // WPA_SUPPLICANT_SUPPORT //
96740 + {
96741 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
96742 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
96743 + }
96744 +
96745 + // Update Shared Key CipherAlg
96746 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
96747 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
96748 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
96749 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
96750 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
96751 +
96752 + // Update group key information to ASIC Shared Key Table
96753 + AsicAddSharedKeyEntry(pAd,
96754 + BSS0,
96755 + pAd->StaCfg.DefaultKeyId,
96756 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96757 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
96758 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
96759 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
96760 +
96761 + // Update ASIC WCID attribute table and IVEIV table
96762 + RTMPAddWcidAttributeEntry(pAd,
96763 + BSS0,
96764 + pAd->StaCfg.DefaultKeyId,
96765 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96766 + NULL);
96767 +
96768 + // set 802.1x port control
96769 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
96770 + STA_PORT_SECURED(pAd);
96771 +
96772 + // Indicate Connected for GUI
96773 + pAd->IndicateMediaState = NdisMediaStateConnected;
96774 + }
96775 + }
96776 + else // dynamic WEP from wpa_supplicant
96777 + {
96778 + UCHAR CipherAlg;
96779 + PUCHAR Key;
96780 +
96781 + if(pKey->KeyLength == 32)
96782 + goto end;
96783 +
96784 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
96785 +
96786 + if (KeyIdx < 4)
96787 + {
96788 + // it is a default shared key, for Pairwise key setting
96789 + if (pKey->KeyIndex & 0x80000000)
96790 + {
96791 + pEntry = MacTableLookup(pAd, pKey->BSSID);
96792 +
96793 + if (pEntry)
96794 + {
96795 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
96796 +
96797 + // set key material and key length
96798 + pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
96799 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
96800 +
96801 + // set Cipher type
96802 + if (pKey->KeyLength == 5)
96803 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
96804 + else
96805 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
96806 +
96807 + // Add Pair-wise key to Asic
96808 + AsicAddPairwiseKeyEntry(
96809 + pAd,
96810 + pEntry->Addr,
96811 + (UCHAR)pEntry->Aid,
96812 + &pEntry->PairwiseKey);
96813 +
96814 + // update WCID attribute table and IVEIV table for this entry
96815 + RTMPAddWcidAttributeEntry(
96816 + pAd,
96817 + BSS0,
96818 + KeyIdx, // The value may be not zero
96819 + pEntry->PairwiseKey.CipherAlg,
96820 + pEntry);
96821 +
96822 + }
96823 + }
96824 + else
96825 + {
96826 + // Default key for tx (shared key)
96827 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
96828 +
96829 + // set key material and key length
96830 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
96831 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
96832 +
96833 + // Set Ciper type
96834 + if (pKey->KeyLength == 5)
96835 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
96836 + else
96837 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
96838 +
96839 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
96840 + Key = pAd->SharedKey[BSS0][KeyIdx].Key;
96841 +
96842 + // Set Group key material to Asic
96843 + AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
96844 +
96845 + // Update WCID attribute table and IVEIV table for this group key table
96846 + RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
96847 +
96848 + }
96849 + }
96850 + }
96851 +end:
96852 + return;
96853 +}
96854 +
96855 +char * rtstrchr(const char * s, int c)
96856 +{
96857 + for(; *s != (char) c; ++s)
96858 + if (*s == '\0')
96859 + return NULL;
96860 + return (char *) s;
96861 +}
96862 +
96863 +/*
96864 +This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
96865 +*/
96866 +
96867 +int
96868 +rt_ioctl_giwname(struct net_device *dev,
96869 + struct iw_request_info *info,
96870 + char *name, char *extra)
96871 +{
96872 +// PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
96873 +
96874 +#ifdef RT2870
96875 + strncpy(name, "RT2870 Wireless", IFNAMSIZ);
96876 +#endif // RT2870 //
96877 + return 0;
96878 +}
96879 +
96880 +int rt_ioctl_siwfreq(struct net_device *dev,
96881 + struct iw_request_info *info,
96882 + struct iw_freq *freq, char *extra)
96883 +{
96884 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
96885 + int chan = -1;
96886 +
96887 + //check if the interface is down
96888 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
96889 + {
96890 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
96891 + return -ENETDOWN;
96892 + }
96893 +
96894 +
96895 + if (freq->e > 1)
96896 + return -EINVAL;
96897 +
96898 + if((freq->e == 0) && (freq->m <= 1000))
96899 + chan = freq->m; // Setting by channel number
96900 + else
96901 + MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
96902 +
96903 + if (ChannelSanity(pAdapter, chan) == TRUE)
96904 + {
96905 + pAdapter->CommonCfg.Channel = chan;
96906 + DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
96907 + }
96908 + else
96909 + return -EINVAL;
96910 +
96911 + return 0;
96912 +}
96913 +int rt_ioctl_giwfreq(struct net_device *dev,
96914 + struct iw_request_info *info,
96915 + struct iw_freq *freq, char *extra)
96916 +{
96917 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
96918 + PRTMP_ADAPTER pAdapter = NULL;
96919 + UCHAR ch;
96920 + ULONG m;
96921 +
96922 + if (dev->priv_flags == INT_MAIN)
96923 + {
96924 + pAdapter = dev->priv;
96925 + }
96926 + else
96927 + {
96928 + pVirtualAd = dev->priv;
96929 + if (pVirtualAd && pVirtualAd->RtmpDev)
96930 + pAdapter = pVirtualAd->RtmpDev->priv;
96931 + }
96932 +
96933 + if (pAdapter == NULL)
96934 + {
96935 + /* if 1st open fail, pAd will be free;
96936 + So the net_dev->priv will be NULL in 2rd open */
96937 + return -ENETDOWN;
96938 + }
96939 +
96940 + ch = pAdapter->CommonCfg.Channel;
96941 +
96942 + DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
96943 +
96944 + MAP_CHANNEL_ID_TO_KHZ(ch, m);
96945 + freq->m = m * 100;
96946 + freq->e = 1;
96947 + return 0;
96948 +}
96949 +
96950 +int rt_ioctl_siwmode(struct net_device *dev,
96951 + struct iw_request_info *info,
96952 + __u32 *mode, char *extra)
96953 +{
96954 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
96955 +
96956 + //check if the interface is down
96957 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
96958 + {
96959 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
96960 + return -ENETDOWN;
96961 + }
96962 +
96963 + switch (*mode)
96964 + {
96965 + case IW_MODE_ADHOC:
96966 + Set_NetworkType_Proc(pAdapter, "Adhoc");
96967 + break;
96968 + case IW_MODE_INFRA:
96969 + Set_NetworkType_Proc(pAdapter, "Infra");
96970 + break;
96971 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
96972 + case IW_MODE_MONITOR:
96973 + Set_NetworkType_Proc(pAdapter, "Monitor");
96974 + break;
96975 +#endif
96976 + default:
96977 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
96978 + return -EINVAL;
96979 + }
96980 +
96981 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
96982 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
96983 +
96984 + return 0;
96985 +}
96986 +
96987 +int rt_ioctl_giwmode(struct net_device *dev,
96988 + struct iw_request_info *info,
96989 + __u32 *mode, char *extra)
96990 +{
96991 + PRTMP_ADAPTER pAdapter = NULL;
96992 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
96993 +
96994 + if (dev->priv_flags == INT_MAIN)
96995 + {
96996 + pAdapter = dev->priv;
96997 + }
96998 + else
96999 + {
97000 + pVirtualAd = dev->priv;
97001 + if (pVirtualAd && pVirtualAd->RtmpDev)
97002 + pAdapter = pVirtualAd->RtmpDev->priv;
97003 + }
97004 +
97005 + if (pAdapter == NULL)
97006 + {
97007 + /* if 1st open fail, pAd will be free;
97008 + So the net_dev->priv will be NULL in 2rd open */
97009 + return -ENETDOWN;
97010 + }
97011 +
97012 + if (ADHOC_ON(pAdapter))
97013 + *mode = IW_MODE_ADHOC;
97014 + else if (INFRA_ON(pAdapter))
97015 + *mode = IW_MODE_INFRA;
97016 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
97017 + else if (MONITOR_ON(pAdapter))
97018 + {
97019 + *mode = IW_MODE_MONITOR;
97020 + }
97021 +#endif
97022 + else
97023 + *mode = IW_MODE_AUTO;
97024 +
97025 + DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
97026 + return 0;
97027 +}
97028 +
97029 +int rt_ioctl_siwsens(struct net_device *dev,
97030 + struct iw_request_info *info,
97031 + char *name, char *extra)
97032 +{
97033 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97034 +
97035 + //check if the interface is down
97036 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97037 + {
97038 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97039 + return -ENETDOWN;
97040 + }
97041 +
97042 + return 0;
97043 +}
97044 +
97045 +int rt_ioctl_giwsens(struct net_device *dev,
97046 + struct iw_request_info *info,
97047 + char *name, char *extra)
97048 +{
97049 + return 0;
97050 +}
97051 +
97052 +int rt_ioctl_giwrange(struct net_device *dev,
97053 + struct iw_request_info *info,
97054 + struct iw_point *data, char *extra)
97055 +{
97056 + PRTMP_ADAPTER pAdapter = NULL;
97057 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97058 + struct iw_range *range = (struct iw_range *) extra;
97059 + u16 val;
97060 + int i;
97061 +
97062 + if (dev->priv_flags == INT_MAIN)
97063 + {
97064 + pAdapter = dev->priv;
97065 + }
97066 + else
97067 + {
97068 + pVirtualAd = dev->priv;
97069 + if (pVirtualAd && pVirtualAd->RtmpDev)
97070 + pAdapter = pVirtualAd->RtmpDev->priv;
97071 + }
97072 +
97073 + if (pAdapter == NULL)
97074 + {
97075 + /* if 1st open fail, pAd will be free;
97076 + So the net_dev->priv will be NULL in 2rd open */
97077 + return -ENETDOWN;
97078 + }
97079 +
97080 + DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
97081 + data->length = sizeof(struct iw_range);
97082 + memset(range, 0, sizeof(struct iw_range));
97083 +
97084 + range->txpower_capa = IW_TXPOW_DBM;
97085 +
97086 + if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
97087 + {
97088 + range->min_pmp = 1 * 1024;
97089 + range->max_pmp = 65535 * 1024;
97090 + range->min_pmt = 1 * 1024;
97091 + range->max_pmt = 1000 * 1024;
97092 + range->pmp_flags = IW_POWER_PERIOD;
97093 + range->pmt_flags = IW_POWER_TIMEOUT;
97094 + range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
97095 + IW_POWER_UNICAST_R | IW_POWER_ALL_R;
97096 + }
97097 +
97098 + range->we_version_compiled = WIRELESS_EXT;
97099 + range->we_version_source = 14;
97100 +
97101 + range->retry_capa = IW_RETRY_LIMIT;
97102 + range->retry_flags = IW_RETRY_LIMIT;
97103 + range->min_retry = 0;
97104 + range->max_retry = 255;
97105 +
97106 + range->num_channels = pAdapter->ChannelListNum;
97107 +
97108 + val = 0;
97109 + for (i = 1; i <= range->num_channels; i++)
97110 + {
97111 + u32 m;
97112 + range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
97113 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
97114 + range->freq[val].m = m * 100; /* HZ */
97115 +
97116 + range->freq[val].e = 1;
97117 + val++;
97118 + if (val == IW_MAX_FREQUENCIES)
97119 + break;
97120 + }
97121 + range->num_frequency = val;
97122 +
97123 + range->max_qual.qual = 100; /* what is correct max? This was not
97124 + * documented exactly. At least
97125 + * 69 has been observed. */
97126 + range->max_qual.level = 0; /* dB */
97127 + range->max_qual.noise = 0; /* dB */
97128 +
97129 + /* What would be suitable values for "average/typical" qual? */
97130 + range->avg_qual.qual = 20;
97131 + range->avg_qual.level = -60;
97132 + range->avg_qual.noise = -95;
97133 + range->sensitivity = 3;
97134 +
97135 + range->max_encoding_tokens = NR_WEP_KEYS;
97136 + range->num_encoding_sizes = 2;
97137 + range->encoding_size[0] = 5;
97138 + range->encoding_size[1] = 13;
97139 +
97140 + range->min_rts = 0;
97141 + range->max_rts = 2347;
97142 + range->min_frag = 256;
97143 + range->max_frag = 2346;
97144 +
97145 +#if WIRELESS_EXT > 17
97146 + /* IW_ENC_CAPA_* bit field */
97147 + range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
97148 + IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
97149 +#endif
97150 +
97151 + return 0;
97152 +}
97153 +
97154 +int rt_ioctl_siwap(struct net_device *dev,
97155 + struct iw_request_info *info,
97156 + struct sockaddr *ap_addr, char *extra)
97157 +{
97158 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97159 + NDIS_802_11_MAC_ADDRESS Bssid;
97160 +
97161 + //check if the interface is down
97162 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97163 + {
97164 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97165 + return -ENETDOWN;
97166 + }
97167 +
97168 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
97169 + {
97170 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
97171 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
97172 + }
97173 +
97174 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
97175 + // this request, because this request is initiated by NDIS.
97176 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
97177 + // Prevent to connect AP again in STAMlmePeriodicExec
97178 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
97179 +
97180 + memset(Bssid, 0, MAC_ADDR_LEN);
97181 + memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
97182 + MlmeEnqueue(pAdapter,
97183 + MLME_CNTL_STATE_MACHINE,
97184 + OID_802_11_BSSID,
97185 + sizeof(NDIS_802_11_MAC_ADDRESS),
97186 + (VOID *)&Bssid);
97187 +
97188 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
97189 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
97190 +
97191 + return 0;
97192 +}
97193 +
97194 +int rt_ioctl_giwap(struct net_device *dev,
97195 + struct iw_request_info *info,
97196 + struct sockaddr *ap_addr, char *extra)
97197 +{
97198 + PRTMP_ADAPTER pAdapter = NULL;
97199 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97200 +
97201 + if (dev->priv_flags == INT_MAIN)
97202 + {
97203 + pAdapter = dev->priv;
97204 + }
97205 + else
97206 + {
97207 + pVirtualAd = dev->priv;
97208 + if (pVirtualAd && pVirtualAd->RtmpDev)
97209 + pAdapter = pVirtualAd->RtmpDev->priv;
97210 + }
97211 +
97212 + if (pAdapter == NULL)
97213 + {
97214 + /* if 1st open fail, pAd will be free;
97215 + So the net_dev->priv will be NULL in 2rd open */
97216 + return -ENETDOWN;
97217 + }
97218 +
97219 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
97220 + {
97221 + ap_addr->sa_family = ARPHRD_ETHER;
97222 + memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
97223 + }
97224 +#ifdef WPA_SUPPLICANT_SUPPORT
97225 + // Add for RT2870
97226 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
97227 + {
97228 + ap_addr->sa_family = ARPHRD_ETHER;
97229 + memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
97230 + }
97231 +#endif // WPA_SUPPLICANT_SUPPORT //
97232 + else
97233 + {
97234 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
97235 + return -ENOTCONN;
97236 + }
97237 +
97238 + return 0;
97239 +}
97240 +
97241 +/*
97242 + * Units are in db above the noise floor. That means the
97243 + * rssi values reported in the tx/rx descriptors in the
97244 + * driver are the SNR expressed in db.
97245 + *
97246 + * If you assume that the noise floor is -95, which is an
97247 + * excellent assumption 99.5 % of the time, then you can
97248 + * derive the absolute signal level (i.e. -95 + rssi).
97249 + * There are some other slight factors to take into account
97250 + * depending on whether the rssi measurement is from 11b,
97251 + * 11g, or 11a. These differences are at most 2db and
97252 + * can be documented.
97253 + *
97254 + * NB: various calculations are based on the orinoco/wavelan
97255 + * drivers for compatibility
97256 + */
97257 +static void set_quality(PRTMP_ADAPTER pAdapter,
97258 + struct iw_quality *iq,
97259 + signed char rssi)
97260 +{
97261 + __u8 ChannelQuality;
97262 +
97263 + // Normalize Rssi
97264 + if (rssi >= -50)
97265 + ChannelQuality = 100;
97266 + else if (rssi >= -80) // between -50 ~ -80dbm
97267 + ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
97268 + else if (rssi >= -90) // between -80 ~ -90dbm
97269 + ChannelQuality = (__u8)((rssi + 90) * 26)/10;
97270 + else
97271 + ChannelQuality = 0;
97272 +
97273 + iq->qual = (__u8)ChannelQuality;
97274 +
97275 + iq->level = (__u8)(rssi);
97276 + iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
97277 + iq->noise += 256 - 143;
97278 + iq->updated = pAdapter->iw_stats.qual.updated;
97279 +}
97280 +
97281 +int rt_ioctl_iwaplist(struct net_device *dev,
97282 + struct iw_request_info *info,
97283 + struct iw_point *data, char *extra)
97284 +{
97285 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97286 +
97287 + struct sockaddr addr[IW_MAX_AP];
97288 + struct iw_quality qual[IW_MAX_AP];
97289 + int i;
97290 +
97291 + //check if the interface is down
97292 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97293 + {
97294 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97295 + data->length = 0;
97296 + return 0;
97297 + //return -ENETDOWN;
97298 + }
97299 +
97300 + for (i = 0; i <IW_MAX_AP ; i++)
97301 + {
97302 + if (i >= pAdapter->ScanTab.BssNr)
97303 + break;
97304 + addr[i].sa_family = ARPHRD_ETHER;
97305 + memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
97306 + set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
97307 + }
97308 + data->length = i;
97309 + memcpy(extra, &addr, i*sizeof(addr[0]));
97310 + data->flags = 1; /* signal quality present (sort of) */
97311 + memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
97312 +
97313 + return 0;
97314 +}
97315 +
97316 +#ifdef SIOCGIWSCAN
97317 +int rt_ioctl_siwscan(struct net_device *dev,
97318 + struct iw_request_info *info,
97319 + struct iw_point *data, char *extra)
97320 +{
97321 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97322 +
97323 + ULONG Now;
97324 + int Status = NDIS_STATUS_SUCCESS;
97325 +
97326 + //check if the interface is down
97327 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97328 + {
97329 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97330 + return -ENETDOWN;
97331 + }
97332 +
97333 + if (MONITOR_ON(pAdapter))
97334 + {
97335 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
97336 + return -EINVAL;
97337 + }
97338 +
97339 +
97340 +#ifdef WPA_SUPPLICANT_SUPPORT
97341 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
97342 + {
97343 + pAdapter->StaCfg.WpaSupplicantScanCount++;
97344 + }
97345 +#endif // WPA_SUPPLICANT_SUPPORT //
97346 +
97347 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
97348 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
97349 + return 0;
97350 + do{
97351 + Now = jiffies;
97352 +
97353 +#ifdef WPA_SUPPLICANT_SUPPORT
97354 + if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
97355 + (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
97356 + {
97357 + DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
97358 + Status = NDIS_STATUS_SUCCESS;
97359 + break;
97360 + }
97361 +#endif // WPA_SUPPLICANT_SUPPORT //
97362 +
97363 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
97364 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
97365 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
97366 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
97367 + {
97368 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
97369 + Status = NDIS_STATUS_SUCCESS;
97370 + break;
97371 + }
97372 +
97373 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
97374 + {
97375 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
97376 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
97377 + }
97378 +
97379 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
97380 + // this request, because this request is initiated by NDIS.
97381 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
97382 + // Reset allowed scan retries
97383 + pAdapter->StaCfg.ScanCnt = 0;
97384 + pAdapter->StaCfg.LastScanTime = Now;
97385 +
97386 + MlmeEnqueue(pAdapter,
97387 + MLME_CNTL_STATE_MACHINE,
97388 + OID_802_11_BSSID_LIST_SCAN,
97389 + 0,
97390 + NULL);
97391 +
97392 + Status = NDIS_STATUS_SUCCESS;
97393 + RT28XX_MLME_HANDLER(pAdapter);
97394 + }while(0);
97395 + return 0;
97396 +}
97397 +
97398 +int rt_ioctl_giwscan(struct net_device *dev,
97399 + struct iw_request_info *info,
97400 + struct iw_point *data, char *extra)
97401 +{
97402 +
97403 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97404 + int i=0;
97405 + char *current_ev = extra, *previous_ev = extra;
97406 + char *end_buf;
97407 + char *current_val, custom[MAX_CUSTOM_LEN] = {0};
97408 +#ifndef IWEVGENIE
97409 + char idx;
97410 +#endif // IWEVGENIE //
97411 + struct iw_event iwe;
97412 +
97413 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
97414 + {
97415 + /*
97416 + * Still scanning, indicate the caller should try again.
97417 + */
97418 + return -EAGAIN;
97419 + }
97420 +
97421 +
97422 +#ifdef WPA_SUPPLICANT_SUPPORT
97423 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
97424 + {
97425 + pAdapter->StaCfg.WpaSupplicantScanCount = 0;
97426 + }
97427 +#endif // WPA_SUPPLICANT_SUPPORT //
97428 +
97429 + if (pAdapter->ScanTab.BssNr == 0)
97430 + {
97431 + data->length = 0;
97432 + return 0;
97433 + }
97434 +
97435 +#if WIRELESS_EXT >= 17
97436 + if (data->length > 0)
97437 + end_buf = extra + data->length;
97438 + else
97439 + end_buf = extra + IW_SCAN_MAX_DATA;
97440 +#else
97441 + end_buf = extra + IW_SCAN_MAX_DATA;
97442 +#endif
97443 +
97444 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
97445 + {
97446 + if (current_ev >= end_buf)
97447 + {
97448 +#if WIRELESS_EXT >= 17
97449 + return -E2BIG;
97450 +#else
97451 + break;
97452 +#endif
97453 + }
97454 +
97455 + //MAC address
97456 + //================================
97457 + memset(&iwe, 0, sizeof(iwe));
97458 + iwe.cmd = SIOCGIWAP;
97459 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
97460 + memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
97461 +
97462 + previous_ev = current_ev;
97463 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
97464 + if (current_ev == previous_ev)
97465 +#if WIRELESS_EXT >= 17
97466 + return -E2BIG;
97467 +#else
97468 + break;
97469 +#endif
97470 +
97471 + //ESSID
97472 + //================================
97473 + memset(&iwe, 0, sizeof(iwe));
97474 + iwe.cmd = SIOCGIWESSID;
97475 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
97476 + iwe.u.data.flags = 1;
97477 +
97478 + previous_ev = current_ev;
97479 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
97480 + if (current_ev == previous_ev)
97481 +#if WIRELESS_EXT >= 17
97482 + return -E2BIG;
97483 +#else
97484 + break;
97485 +#endif
97486 +
97487 + //Network Type
97488 + //================================
97489 + memset(&iwe, 0, sizeof(iwe));
97490 + iwe.cmd = SIOCGIWMODE;
97491 + if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
97492 + {
97493 + iwe.u.mode = IW_MODE_ADHOC;
97494 + }
97495 + else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
97496 + {
97497 + iwe.u.mode = IW_MODE_INFRA;
97498 + }
97499 + else
97500 + {
97501 + iwe.u.mode = IW_MODE_AUTO;
97502 + }
97503 + iwe.len = IW_EV_UINT_LEN;
97504 +
97505 + previous_ev = current_ev;
97506 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
97507 + if (current_ev == previous_ev)
97508 +#if WIRELESS_EXT >= 17
97509 + return -E2BIG;
97510 +#else
97511 + break;
97512 +#endif
97513 +
97514 + //Channel and Frequency
97515 + //================================
97516 + memset(&iwe, 0, sizeof(iwe));
97517 + iwe.cmd = SIOCGIWFREQ;
97518 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
97519 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
97520 + else
97521 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
97522 + iwe.u.freq.e = 0;
97523 + iwe.u.freq.i = 0;
97524 +
97525 + previous_ev = current_ev;
97526 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
97527 + if (current_ev == previous_ev)
97528 +#if WIRELESS_EXT >= 17
97529 + return -E2BIG;
97530 +#else
97531 + break;
97532 +#endif
97533 +
97534 + //Add quality statistics
97535 + //================================
97536 + memset(&iwe, 0, sizeof(iwe));
97537 + iwe.cmd = IWEVQUAL;
97538 + iwe.u.qual.level = 0;
97539 + iwe.u.qual.noise = 0;
97540 + set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
97541 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
97542 + if (current_ev == previous_ev)
97543 +#if WIRELESS_EXT >= 17
97544 + return -E2BIG;
97545 +#else
97546 + break;
97547 +#endif
97548 +
97549 + //Encyption key
97550 + //================================
97551 + memset(&iwe, 0, sizeof(iwe));
97552 + iwe.cmd = SIOCGIWENCODE;
97553 + if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
97554 + iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
97555 + else
97556 + iwe.u.data.flags = IW_ENCODE_DISABLED;
97557 +
97558 + previous_ev = current_ev;
97559 + 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);
97560 + if (current_ev == previous_ev)
97561 +#if WIRELESS_EXT >= 17
97562 + return -E2BIG;
97563 +#else
97564 + break;
97565 +#endif
97566 +
97567 + //Bit Rate
97568 + //================================
97569 + if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
97570 + {
97571 + UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
97572 + memset(&iwe, 0, sizeof(iwe));
97573 + iwe.cmd = SIOCGIWRATE;
97574 + current_val = current_ev + IW_EV_LCP_LEN;
97575 + if (tmpRate == 0x82)
97576 + iwe.u.bitrate.value = 1 * 1000000;
97577 + else if (tmpRate == 0x84)
97578 + iwe.u.bitrate.value = 2 * 1000000;
97579 + else if (tmpRate == 0x8B)
97580 + iwe.u.bitrate.value = 5.5 * 1000000;
97581 + else if (tmpRate == 0x96)
97582 + iwe.u.bitrate.value = 11 * 1000000;
97583 + else
97584 + iwe.u.bitrate.value = (tmpRate/2) * 1000000;
97585 +
97586 + iwe.u.bitrate.disabled = 0;
97587 + current_val = IWE_STREAM_ADD_VALUE(info, current_ev,
97588 + current_val, end_buf, &iwe,
97589 + IW_EV_PARAM_LEN);
97590 +
97591 + if((current_val-current_ev)>IW_EV_LCP_LEN)
97592 + current_ev = current_val;
97593 + else
97594 +#if WIRELESS_EXT >= 17
97595 + return -E2BIG;
97596 +#else
97597 + break;
97598 +#endif
97599 + }
97600 +
97601 +#ifdef IWEVGENIE
97602 + //WPA IE
97603 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
97604 + {
97605 + memset(&iwe, 0, sizeof(iwe));
97606 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
97607 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
97608 + pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
97609 + iwe.cmd = IWEVGENIE;
97610 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
97611 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
97612 + if (current_ev == previous_ev)
97613 +#if WIRELESS_EXT >= 17
97614 + return -E2BIG;
97615 +#else
97616 + break;
97617 +#endif
97618 + }
97619 +
97620 + //WPA2 IE
97621 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
97622 + {
97623 + memset(&iwe, 0, sizeof(iwe));
97624 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
97625 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
97626 + pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
97627 + iwe.cmd = IWEVGENIE;
97628 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
97629 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
97630 + if (current_ev == previous_ev)
97631 +#if WIRELESS_EXT >= 17
97632 + return -E2BIG;
97633 +#else
97634 + break;
97635 +#endif
97636 + }
97637 +#else
97638 + //WPA IE
97639 + //================================
97640 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
97641 + {
97642 + NdisZeroMemory(&iwe, sizeof(iwe));
97643 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
97644 + iwe.cmd = IWEVCUSTOM;
97645 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
97646 + NdisMoveMemory(custom, "wpa_ie=", 7);
97647 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
97648 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
97649 + previous_ev = current_ev;
97650 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
97651 + if (current_ev == previous_ev)
97652 +#if WIRELESS_EXT >= 17
97653 + return -E2BIG;
97654 +#else
97655 + break;
97656 +#endif
97657 + }
97658 +
97659 + //WPA2 IE
97660 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
97661 + {
97662 + NdisZeroMemory(&iwe, sizeof(iwe));
97663 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
97664 + iwe.cmd = IWEVCUSTOM;
97665 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
97666 + NdisMoveMemory(custom, "rsn_ie=", 7);
97667 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
97668 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
97669 + previous_ev = current_ev;
97670 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
97671 + if (current_ev == previous_ev)
97672 +#if WIRELESS_EXT >= 17
97673 + return -E2BIG;
97674 +#else
97675 + break;
97676 +#endif
97677 + }
97678 +#endif // IWEVGENIE //
97679 + }
97680 +
97681 + data->length = current_ev - extra;
97682 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
97683 + DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
97684 + return 0;
97685 +}
97686 +#endif
97687 +
97688 +int rt_ioctl_siwessid(struct net_device *dev,
97689 + struct iw_request_info *info,
97690 + struct iw_point *data, char *essid)
97691 +{
97692 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97693 +
97694 + //check if the interface is down
97695 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97696 + {
97697 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97698 + return -ENETDOWN;
97699 + }
97700 +
97701 + if (data->flags)
97702 + {
97703 + PCHAR pSsidString = NULL;
97704 +
97705 + // Includes null character.
97706 + if (data->length > (IW_ESSID_MAX_SIZE + 1))
97707 + return -E2BIG;
97708 +
97709 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
97710 + if (pSsidString)
97711 + {
97712 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
97713 + NdisMoveMemory(pSsidString, essid, data->length);
97714 + if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
97715 + return -EINVAL;
97716 + }
97717 + else
97718 + return -ENOMEM;
97719 + }
97720 + else
97721 + {
97722 + // ANY ssid
97723 + if (Set_SSID_Proc(pAdapter, "") == FALSE)
97724 + return -EINVAL;
97725 + }
97726 + return 0;
97727 +}
97728 +
97729 +int rt_ioctl_giwessid(struct net_device *dev,
97730 + struct iw_request_info *info,
97731 + struct iw_point *data, char *essid)
97732 +{
97733 + PRTMP_ADAPTER pAdapter = NULL;
97734 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97735 +
97736 + if (dev->priv_flags == INT_MAIN)
97737 + {
97738 + pAdapter = dev->priv;
97739 + }
97740 + else
97741 + {
97742 + pVirtualAd = dev->priv;
97743 + if (pVirtualAd && pVirtualAd->RtmpDev)
97744 + pAdapter = pVirtualAd->RtmpDev->priv;
97745 + }
97746 +
97747 + if (pAdapter == NULL)
97748 + {
97749 + /* if 1st open fail, pAd will be free;
97750 + So the net_dev->priv will be NULL in 2rd open */
97751 + return -ENETDOWN;
97752 + }
97753 +
97754 + data->flags = 1;
97755 + if (MONITOR_ON(pAdapter))
97756 + {
97757 + data->length = 0;
97758 + return 0;
97759 + }
97760 +
97761 + if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
97762 + {
97763 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
97764 + data->length = pAdapter->CommonCfg.SsidLen;
97765 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
97766 + }
97767 +#ifdef RT2870
97768 +#ifdef WPA_SUPPLICANT_SUPPORT
97769 + // Add for RT2870
97770 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
97771 + {
97772 + data->length = pAdapter->CommonCfg.SsidLen;
97773 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
97774 + }
97775 +#endif // WPA_SUPPLICANT_SUPPORT //
97776 +#endif // RT2870 //
97777 + else
97778 + {//the ANY ssid was specified
97779 + data->length = 0;
97780 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
97781 + }
97782 +
97783 + return 0;
97784 +
97785 +}
97786 +
97787 +int rt_ioctl_siwnickn(struct net_device *dev,
97788 + struct iw_request_info *info,
97789 + struct iw_point *data, char *nickname)
97790 +{
97791 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97792 +
97793 + //check if the interface is down
97794 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97795 + {
97796 + DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
97797 + return -ENETDOWN;
97798 + }
97799 +
97800 + if (data->length > IW_ESSID_MAX_SIZE)
97801 + return -EINVAL;
97802 +
97803 + memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
97804 + memcpy(pAdapter->nickname, nickname, data->length);
97805 +
97806 +
97807 + return 0;
97808 +}
97809 +
97810 +int rt_ioctl_giwnickn(struct net_device *dev,
97811 + struct iw_request_info *info,
97812 + struct iw_point *data, char *nickname)
97813 +{
97814 + PRTMP_ADAPTER pAdapter = NULL;
97815 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97816 +
97817 + if (dev->priv_flags == INT_MAIN)
97818 + {
97819 + pAdapter = dev->priv;
97820 + }
97821 + else
97822 + {
97823 + pVirtualAd = dev->priv;
97824 + if (pVirtualAd && pVirtualAd->RtmpDev)
97825 + pAdapter = pVirtualAd->RtmpDev->priv;
97826 + }
97827 +
97828 + if (pAdapter == NULL)
97829 + {
97830 + /* if 1st open fail, pAd will be free;
97831 + So the net_dev->priv will be NULL in 2rd open */
97832 + return -ENETDOWN;
97833 + }
97834 +
97835 + if (data->length > strlen(pAdapter->nickname) + 1)
97836 + data->length = strlen(pAdapter->nickname) + 1;
97837 + if (data->length > 0) {
97838 + memcpy(nickname, pAdapter->nickname, data->length-1);
97839 + nickname[data->length-1] = '\0';
97840 + }
97841 + return 0;
97842 +}
97843 +
97844 +int rt_ioctl_siwrts(struct net_device *dev,
97845 + struct iw_request_info *info,
97846 + struct iw_param *rts, char *extra)
97847 +{
97848 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97849 + u16 val;
97850 +
97851 + //check if the interface is down
97852 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97853 + {
97854 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97855 + return -ENETDOWN;
97856 + }
97857 +
97858 + if (rts->disabled)
97859 + val = MAX_RTS_THRESHOLD;
97860 + else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
97861 + return -EINVAL;
97862 + else if (rts->value == 0)
97863 + val = MAX_RTS_THRESHOLD;
97864 + else
97865 + val = rts->value;
97866 +
97867 + if (val != pAdapter->CommonCfg.RtsThreshold)
97868 + pAdapter->CommonCfg.RtsThreshold = val;
97869 +
97870 + return 0;
97871 +}
97872 +
97873 +int rt_ioctl_giwrts(struct net_device *dev,
97874 + struct iw_request_info *info,
97875 + struct iw_param *rts, char *extra)
97876 +{
97877 + PRTMP_ADAPTER pAdapter = NULL;
97878 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97879 +
97880 + if (dev->priv_flags == INT_MAIN)
97881 + {
97882 + pAdapter = dev->priv;
97883 + }
97884 + else
97885 + {
97886 + pVirtualAd = dev->priv;
97887 + if (pVirtualAd && pVirtualAd->RtmpDev)
97888 + pAdapter = pVirtualAd->RtmpDev->priv;
97889 + }
97890 +
97891 + if (pAdapter == NULL)
97892 + {
97893 + /* if 1st open fail, pAd will be free;
97894 + So the net_dev->priv will be NULL in 2rd open */
97895 + return -ENETDOWN;
97896 + }
97897 +
97898 + //check if the interface is down
97899 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97900 + {
97901 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97902 + return -ENETDOWN;
97903 + }
97904 +
97905 + rts->value = pAdapter->CommonCfg.RtsThreshold;
97906 + rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
97907 + rts->fixed = 1;
97908 +
97909 + return 0;
97910 +}
97911 +
97912 +int rt_ioctl_siwfrag(struct net_device *dev,
97913 + struct iw_request_info *info,
97914 + struct iw_param *frag, char *extra)
97915 +{
97916 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97917 + u16 val;
97918 +
97919 + //check if the interface is down
97920 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97921 + {
97922 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97923 + return -ENETDOWN;
97924 + }
97925 +
97926 + if (frag->disabled)
97927 + val = MAX_FRAG_THRESHOLD;
97928 + else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
97929 + val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
97930 + else if (frag->value == 0)
97931 + val = MAX_FRAG_THRESHOLD;
97932 + else
97933 + return -EINVAL;
97934 +
97935 + pAdapter->CommonCfg.FragmentThreshold = val;
97936 + return 0;
97937 +}
97938 +
97939 +int rt_ioctl_giwfrag(struct net_device *dev,
97940 + struct iw_request_info *info,
97941 + struct iw_param *frag, char *extra)
97942 +{
97943 + PRTMP_ADAPTER pAdapter = NULL;
97944 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
97945 +
97946 + if (dev->priv_flags == INT_MAIN)
97947 + {
97948 + pAdapter = dev->priv;
97949 + }
97950 + else
97951 + {
97952 + pVirtualAd = dev->priv;
97953 + if (pVirtualAd && pVirtualAd->RtmpDev)
97954 + pAdapter = pVirtualAd->RtmpDev->priv;
97955 + }
97956 +
97957 + if (pAdapter == NULL)
97958 + {
97959 + /* if 1st open fail, pAd will be free;
97960 + So the net_dev->priv will be NULL in 2rd open */
97961 + return -ENETDOWN;
97962 + }
97963 +
97964 + //check if the interface is down
97965 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97966 + {
97967 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97968 + return -ENETDOWN;
97969 + }
97970 +
97971 + frag->value = pAdapter->CommonCfg.FragmentThreshold;
97972 + frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
97973 + frag->fixed = 1;
97974 +
97975 + return 0;
97976 +}
97977 +
97978 +#define MAX_WEP_KEY_SIZE 13
97979 +#define MIN_WEP_KEY_SIZE 5
97980 +int rt_ioctl_siwencode(struct net_device *dev,
97981 + struct iw_request_info *info,
97982 + struct iw_point *erq, char *extra)
97983 +{
97984 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
97985 +
97986 + //check if the interface is down
97987 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
97988 + {
97989 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
97990 + return -ENETDOWN;
97991 + }
97992 +
97993 + if ((erq->length == 0) &&
97994 + (erq->flags & IW_ENCODE_DISABLED))
97995 + {
97996 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
97997 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
97998 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
97999 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98000 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
98001 + goto done;
98002 + }
98003 + else if ((erq->length == 0) &&
98004 + (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
98005 + {
98006 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98007 + STA_PORT_SECURED(pAdapter);
98008 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
98009 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
98010 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
98011 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98012 + if (erq->flags & IW_ENCODE_RESTRICTED)
98013 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
98014 + else
98015 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
98016 + goto done;
98017 + }
98018 +
98019 + if (erq->length > 0)
98020 + {
98021 + int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
98022 + /* Check the size of the key */
98023 + if (erq->length > MAX_WEP_KEY_SIZE) {
98024 + return -EINVAL;
98025 + }
98026 + /* Check key index */
98027 + if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
98028 + {
98029 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
98030 + keyIdx, pAdapter->StaCfg.DefaultKeyId));
98031 +
98032 + //Using default key
98033 + keyIdx = pAdapter->StaCfg.DefaultKeyId;
98034 + }
98035 +
98036 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
98037 +
98038 + if (erq->length == MAX_WEP_KEY_SIZE)
98039 + {
98040 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
98041 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
98042 + }
98043 + else if (erq->length == MIN_WEP_KEY_SIZE)
98044 + {
98045 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
98046 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
98047 + }
98048 + else
98049 + /* Disable the key */
98050 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
98051 +
98052 + /* Check if the key is not marked as invalid */
98053 + if(!(erq->flags & IW_ENCODE_NOKEY)) {
98054 + /* Copy the key in the driver */
98055 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
98056 + }
98057 + }
98058 + else
98059 + {
98060 + /* Do we want to just set the transmit key index ? */
98061 + int index = (erq->flags & IW_ENCODE_INDEX) - 1;
98062 + if ((index >= 0) && (index < 4))
98063 + {
98064 + pAdapter->StaCfg.DefaultKeyId = index;
98065 + }
98066 + else
98067 + /* Don't complain if only change the mode */
98068 + if(!erq->flags & IW_ENCODE_MODE) {
98069 + return -EINVAL;
98070 + }
98071 + }
98072 +
98073 +done:
98074 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
98075 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
98076 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
98077 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
98078 + return 0;
98079 +}
98080 +
98081 +int
98082 +rt_ioctl_giwencode(struct net_device *dev,
98083 + struct iw_request_info *info,
98084 + struct iw_point *erq, char *key)
98085 +{
98086 + int kid;
98087 + PRTMP_ADAPTER pAdapter = NULL;
98088 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
98089 +
98090 + if (dev->priv_flags == INT_MAIN)
98091 + {
98092 + pAdapter = dev->priv;
98093 + }
98094 + else
98095 + {
98096 + pVirtualAd = dev->priv;
98097 + if (pVirtualAd && pVirtualAd->RtmpDev)
98098 + pAdapter = pVirtualAd->RtmpDev->priv;
98099 + }
98100 +
98101 + if (pAdapter == NULL)
98102 + {
98103 + /* if 1st open fail, pAd will be free;
98104 + So the net_dev->priv will be NULL in 2rd open */
98105 + return -ENETDOWN;
98106 + }
98107 +
98108 + //check if the interface is down
98109 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
98110 + {
98111 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
98112 + return -ENETDOWN;
98113 + }
98114 +
98115 + kid = erq->flags & IW_ENCODE_INDEX;
98116 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
98117 +
98118 + if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
98119 + {
98120 + erq->length = 0;
98121 + erq->flags = IW_ENCODE_DISABLED;
98122 + }
98123 + else if ((kid > 0) && (kid <=4))
98124 + {
98125 + // copy wep key
98126 + erq->flags = kid ; /* NB: base 1 */
98127 + if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
98128 + erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
98129 + memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
98130 + //if ((kid == pAdapter->PortCfg.DefaultKeyId))
98131 + //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
98132 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
98133 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
98134 + else
98135 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
98136 +
98137 + }
98138 + else if (kid == 0)
98139 + {
98140 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
98141 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
98142 + else
98143 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
98144 + erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
98145 + memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
98146 + // copy default key ID
98147 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
98148 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
98149 + else
98150 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
98151 + erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
98152 + erq->flags |= IW_ENCODE_ENABLED; /* XXX */
98153 + }
98154 +
98155 + return 0;
98156 +
98157 +}
98158 +
98159 +static int
98160 +rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
98161 + void *w, char *extra)
98162 +{
98163 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
98164 + PRTMP_ADAPTER pAdapter;
98165 + POS_COOKIE pObj;
98166 + char *this_char = extra;
98167 + char *value;
98168 + int Status=0;
98169 +
98170 + if (dev->priv_flags == INT_MAIN)
98171 + {
98172 + pAdapter = dev->priv;
98173 + }
98174 + else
98175 + {
98176 + pVirtualAd = dev->priv;
98177 + pAdapter = pVirtualAd->RtmpDev->priv;
98178 + }
98179 + pObj = (POS_COOKIE) pAdapter->OS_Cookie;
98180 +
98181 + if (pAdapter == NULL)
98182 + {
98183 + /* if 1st open fail, pAd will be free;
98184 + So the net_dev->priv will be NULL in 2rd open */
98185 + return -ENETDOWN;
98186 + }
98187 +
98188 + {
98189 + pObj->ioctl_if_type = INT_MAIN;
98190 + pObj->ioctl_if = MAIN_MBSSID;
98191 + }
98192 +
98193 + //check if the interface is down
98194 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
98195 + {
98196 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
98197 + return -ENETDOWN;
98198 + }
98199 +
98200 + if (!*this_char)
98201 + return -EINVAL;
98202 +
98203 + if ((value = rtstrchr(this_char, '=')) != NULL)
98204 + *value++ = 0;
98205 +
98206 + if (!value)
98207 + return -EINVAL;
98208 +
98209 + // reject setting nothing besides ANY ssid(ssidLen=0)
98210 + if (!*value && (strcmp(this_char, "SSID") != 0))
98211 + return -EINVAL;
98212 +
98213 + for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
98214 + {
98215 + if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
98216 + {
98217 + if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
98218 + { //FALSE:Set private failed then return Invalid argument
98219 + Status = -EINVAL;
98220 + }
98221 + break; //Exit for loop.
98222 + }
98223 + }
98224 +
98225 + if(PRTMP_PRIVATE_SET_PROC->name == NULL)
98226 + { //Not found argument
98227 + Status = -EINVAL;
98228 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
98229 + }
98230 +
98231 + return Status;
98232 +}
98233 +
98234 +
98235 +static int
98236 +rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
98237 + struct iw_point *wrq, char *extra)
98238 +{
98239 + INT Status = 0;
98240 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
98241 +
98242 + if (extra == NULL)
98243 + {
98244 + wrq->length = 0;
98245 + return -EIO;
98246 + }
98247 +
98248 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
98249 + sprintf(extra, "\n\n");
98250 +
98251 +#ifdef RALINK_ATE
98252 + if (ATE_ON(pAd))
98253 + {
98254 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
98255 + //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
98256 + }
98257 + else
98258 +#endif // RALINK_ATE //
98259 + {
98260 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
98261 + sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
98262 + }
98263 + sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
98264 + sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
98265 + sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
98266 + sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
98267 +
98268 + sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
98269 + sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
98270 + sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
98271 + sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
98272 +
98273 + sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
98274 +#ifdef RALINK_ATE
98275 + if (ATE_ON(pAd))
98276 + {
98277 + if (pAd->ate.RxAntennaSel == 0)
98278 + {
98279 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
98280 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
98281 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
98282 + }
98283 + else
98284 + {
98285 + sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
98286 + }
98287 + }
98288 + else
98289 +#endif // RALINK_ATE //
98290 + {
98291 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
98292 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
98293 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
98294 + }
98295 +#ifdef WPA_SUPPLICANT_SUPPORT
98296 + sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
98297 +#endif // WPA_SUPPLICANT_SUPPORT //
98298 +
98299 +
98300 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98301 + DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
98302 +
98303 + return Status;
98304 +}
98305 +
98306 +#ifdef DOT11_N_SUPPORT
98307 +void getBaInfo(
98308 + IN PRTMP_ADAPTER pAd,
98309 + IN PUCHAR pOutBuf)
98310 +{
98311 + INT i, j;
98312 + BA_ORI_ENTRY *pOriBAEntry;
98313 + BA_REC_ENTRY *pRecBAEntry;
98314 +
98315 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
98316 + {
98317 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
98318 + if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
98319 + || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
98320 + {
98321 + sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
98322 + pOutBuf,
98323 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
98324 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
98325 +
98326 + sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
98327 + for (j=0; j < NUM_OF_TID; j++)
98328 + {
98329 + if (pEntry->BARecWcidArray[j] != 0)
98330 + {
98331 + pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
98332 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
98333 + }
98334 + }
98335 + sprintf(pOutBuf, "%s\n", pOutBuf);
98336 +
98337 + sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
98338 + for (j=0; j < NUM_OF_TID; j++)
98339 + {
98340 + if (pEntry->BAOriWcidArray[j] != 0)
98341 + {
98342 + pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
98343 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
98344 + }
98345 + }
98346 + sprintf(pOutBuf, "%s\n\n", pOutBuf);
98347 + }
98348 + if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
98349 + break;
98350 + }
98351 +
98352 + return;
98353 +}
98354 +#endif // DOT11_N_SUPPORT //
98355 +
98356 +static int
98357 +rt_private_show(struct net_device *dev, struct iw_request_info *info,
98358 + struct iw_point *wrq, char *extra)
98359 +{
98360 + INT Status = 0;
98361 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
98362 + PRTMP_ADAPTER pAd;
98363 + POS_COOKIE pObj;
98364 + u32 subcmd = wrq->flags;
98365 +
98366 + if (dev->priv_flags == INT_MAIN)
98367 + pAd = dev->priv;
98368 + else
98369 + {
98370 + pVirtualAd = dev->priv;
98371 + pAd = pVirtualAd->RtmpDev->priv;
98372 + }
98373 + pObj = (POS_COOKIE) pAd->OS_Cookie;
98374 +
98375 + if (pAd == NULL)
98376 + {
98377 + /* if 1st open fail, pAd will be free;
98378 + So the net_dev->priv will be NULL in 2rd open */
98379 + return -ENETDOWN;
98380 + }
98381 +
98382 + if (extra == NULL)
98383 + {
98384 + wrq->length = 0;
98385 + return -EIO;
98386 + }
98387 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
98388 +
98389 + {
98390 + pObj->ioctl_if_type = INT_MAIN;
98391 + pObj->ioctl_if = MAIN_MBSSID;
98392 + }
98393 +
98394 + switch(subcmd)
98395 + {
98396 +
98397 + case SHOW_CONN_STATUS:
98398 + if (MONITOR_ON(pAd))
98399 + {
98400 +#ifdef DOT11_N_SUPPORT
98401 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
98402 + pAd->CommonCfg.RegTransmitSetting.field.BW)
98403 + sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
98404 + else
98405 +#endif // DOT11_N_SUPPORT //
98406 + sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
98407 + }
98408 + else
98409 + {
98410 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
98411 + {
98412 + if (INFRA_ON(pAd))
98413 + {
98414 + sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
98415 + pAd->CommonCfg.Ssid,
98416 + pAd->CommonCfg.Bssid[0],
98417 + pAd->CommonCfg.Bssid[1],
98418 + pAd->CommonCfg.Bssid[2],
98419 + pAd->CommonCfg.Bssid[3],
98420 + pAd->CommonCfg.Bssid[4],
98421 + pAd->CommonCfg.Bssid[5]);
98422 + DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
98423 + }
98424 + else if (ADHOC_ON(pAd))
98425 + sprintf(extra, "Connected\n");
98426 + }
98427 + else
98428 + {
98429 + sprintf(extra, "Disconnected\n");
98430 + DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
98431 + }
98432 + }
98433 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98434 + break;
98435 + case SHOW_DRVIER_VERION:
98436 + sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
98437 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98438 + break;
98439 +#ifdef DOT11_N_SUPPORT
98440 + case SHOW_BA_INFO:
98441 + getBaInfo(pAd, extra);
98442 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98443 + break;
98444 +#endif // DOT11_N_SUPPORT //
98445 + case SHOW_DESC_INFO:
98446 + {
98447 + Show_DescInfo_Proc(pAd, NULL);
98448 + wrq->length = 0; // 1: size of '\0'
98449 + }
98450 + break;
98451 + case RAIO_OFF:
98452 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
98453 + {
98454 + sprintf(extra, "Scanning\n");
98455 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98456 + break;
98457 + }
98458 + pAd->StaCfg.bSwRadio = FALSE;
98459 + if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
98460 + {
98461 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
98462 + if (pAd->StaCfg.bRadio == FALSE)
98463 + {
98464 + MlmeRadioOff(pAd);
98465 + // Update extra information
98466 + pAd->ExtraInfo = SW_RADIO_OFF;
98467 + }
98468 + }
98469 + sprintf(extra, "Radio Off\n");
98470 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98471 + break;
98472 + case RAIO_ON:
98473 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
98474 + {
98475 + sprintf(extra, "Scanning\n");
98476 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98477 + break;
98478 + }
98479 + pAd->StaCfg.bSwRadio = TRUE;
98480 + //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
98481 + {
98482 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
98483 + if (pAd->StaCfg.bRadio == TRUE)
98484 + {
98485 + MlmeRadioOn(pAd);
98486 + // Update extra information
98487 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
98488 + }
98489 + }
98490 + sprintf(extra, "Radio On\n");
98491 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98492 + break;
98493 +
98494 +
98495 +#ifdef QOS_DLS_SUPPORT
98496 + case SHOW_DLS_ENTRY_INFO:
98497 + {
98498 + Set_DlsEntryInfo_Display_Proc(pAd, NULL);
98499 + wrq->length = 0; // 1: size of '\0'
98500 + }
98501 + break;
98502 +#endif // QOS_DLS_SUPPORT //
98503 +
98504 + case SHOW_CFG_VALUE:
98505 + {
98506 + Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
98507 + if (Status == 0)
98508 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98509 + }
98510 + break;
98511 + case SHOW_ADHOC_ENTRY_INFO:
98512 + Show_Adhoc_MacTable_Proc(pAd, extra);
98513 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
98514 + break;
98515 + default:
98516 + DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __FUNCTION__, subcmd));
98517 + break;
98518 + }
98519 +
98520 + return Status;
98521 +}
98522 +
98523 +#ifdef SIOCSIWMLME
98524 +int rt_ioctl_siwmlme(struct net_device *dev,
98525 + struct iw_request_info *info,
98526 + union iwreq_data *wrqu,
98527 + char *extra)
98528 +{
98529 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
98530 + struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
98531 + MLME_QUEUE_ELEM MsgElem;
98532 + MLME_DISASSOC_REQ_STRUCT DisAssocReq;
98533 + MLME_DEAUTH_REQ_STRUCT DeAuthReq;
98534 +
98535 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __FUNCTION__));
98536 +
98537 + if (pMlme == NULL)
98538 + return -EINVAL;
98539 +
98540 + switch(pMlme->cmd)
98541 + {
98542 +#ifdef IW_MLME_DEAUTH
98543 + case IW_MLME_DEAUTH:
98544 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __FUNCTION__));
98545 + COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
98546 + DeAuthReq.Reason = pMlme->reason_code;
98547 + MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
98548 + NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
98549 + MlmeDeauthReqAction(pAd, &MsgElem);
98550 + if (INFRA_ON(pAd))
98551 + {
98552 + LinkDown(pAd, FALSE);
98553 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
98554 + }
98555 + break;
98556 +#endif // IW_MLME_DEAUTH //
98557 +#ifdef IW_MLME_DISASSOC
98558 + case IW_MLME_DISASSOC:
98559 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __FUNCTION__));
98560 + COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
98561 + DisAssocReq.Reason = pMlme->reason_code;
98562 +
98563 + MsgElem.Machine = ASSOC_STATE_MACHINE;
98564 + MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
98565 + MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
98566 + NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
98567 +
98568 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
98569 + MlmeDisassocReqAction(pAd, &MsgElem);
98570 + break;
98571 +#endif // IW_MLME_DISASSOC //
98572 + default:
98573 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __FUNCTION__));
98574 + break;
98575 + }
98576 +
98577 + return 0;
98578 +}
98579 +#endif // SIOCSIWMLME //
98580 +
98581 +#if WIRELESS_EXT > 17
98582 +int rt_ioctl_siwauth(struct net_device *dev,
98583 + struct iw_request_info *info,
98584 + union iwreq_data *wrqu, char *extra)
98585 +{
98586 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
98587 + struct iw_param *param = &wrqu->param;
98588 +
98589 + //check if the interface is down
98590 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
98591 + {
98592 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
98593 + return -ENETDOWN;
98594 + }
98595 + switch (param->flags & IW_AUTH_INDEX) {
98596 + case IW_AUTH_WPA_VERSION:
98597 + if (param->value == IW_AUTH_WPA_VERSION_WPA)
98598 + {
98599 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
98600 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
98601 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
98602 + }
98603 + else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
98604 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
98605 +
98606 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
98607 + break;
98608 + case IW_AUTH_CIPHER_PAIRWISE:
98609 + if (param->value == IW_AUTH_CIPHER_NONE)
98610 + {
98611 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
98612 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98613 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
98614 + }
98615 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
98616 + param->value == IW_AUTH_CIPHER_WEP104)
98617 + {
98618 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
98619 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98620 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
98621 +#ifdef WPA_SUPPLICANT_SUPPORT
98622 + pAdapter->StaCfg.IEEE8021X = FALSE;
98623 +#endif // WPA_SUPPLICANT_SUPPORT //
98624 + }
98625 + else if (param->value == IW_AUTH_CIPHER_TKIP)
98626 + {
98627 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
98628 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98629 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
98630 + }
98631 + else if (param->value == IW_AUTH_CIPHER_CCMP)
98632 + {
98633 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
98634 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98635 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
98636 + }
98637 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __FUNCTION__, param->value));
98638 + break;
98639 + case IW_AUTH_CIPHER_GROUP:
98640 + if (param->value == IW_AUTH_CIPHER_NONE)
98641 + {
98642 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
98643 + }
98644 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
98645 + param->value == IW_AUTH_CIPHER_WEP104)
98646 + {
98647 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
98648 + }
98649 + else if (param->value == IW_AUTH_CIPHER_TKIP)
98650 + {
98651 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
98652 + }
98653 + else if (param->value == IW_AUTH_CIPHER_CCMP)
98654 + {
98655 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
98656 + }
98657 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __FUNCTION__, param->value));
98658 + break;
98659 + case IW_AUTH_KEY_MGMT:
98660 + if (param->value == IW_AUTH_KEY_MGMT_802_1X)
98661 + {
98662 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
98663 + {
98664 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
98665 +#ifdef WPA_SUPPLICANT_SUPPORT
98666 + pAdapter->StaCfg.IEEE8021X = FALSE;
98667 +#endif // WPA_SUPPLICANT_SUPPORT //
98668 + }
98669 + else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
98670 + {
98671 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
98672 +#ifdef WPA_SUPPLICANT_SUPPORT
98673 + pAdapter->StaCfg.IEEE8021X = FALSE;
98674 +#endif // WPA_SUPPLICANT_SUPPORT //
98675 + }
98676 +#ifdef WPA_SUPPLICANT_SUPPORT
98677 + else
98678 + // WEP 1x
98679 + pAdapter->StaCfg.IEEE8021X = TRUE;
98680 +#endif // WPA_SUPPLICANT_SUPPORT //
98681 + }
98682 + else if (param->value == 0)
98683 + {
98684 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98685 + STA_PORT_SECURED(pAdapter);
98686 + }
98687 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __FUNCTION__, param->value));
98688 + break;
98689 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
98690 + break;
98691 + case IW_AUTH_PRIVACY_INVOKED:
98692 + /*if (param->value == 0)
98693 + {
98694 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
98695 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
98696 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
98697 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
98698 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
98699 + }*/
98700 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __FUNCTION__, param->value));
98701 + break;
98702 + case IW_AUTH_DROP_UNENCRYPTED:
98703 + if (param->value != 0)
98704 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
98705 + else
98706 + {
98707 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98708 + STA_PORT_SECURED(pAdapter);
98709 + }
98710 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
98711 + break;
98712 + case IW_AUTH_80211_AUTH_ALG:
98713 + if (param->value & IW_AUTH_ALG_SHARED_KEY)
98714 + {
98715 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
98716 + }
98717 + else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
98718 + {
98719 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
98720 + }
98721 + else
98722 + return -EINVAL;
98723 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __FUNCTION__, param->value));
98724 + break;
98725 + case IW_AUTH_WPA_ENABLED:
98726 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __FUNCTION__, param->value));
98727 + break;
98728 + default:
98729 + return -EOPNOTSUPP;
98730 +}
98731 +
98732 + return 0;
98733 +}
98734 +
98735 +int rt_ioctl_giwauth(struct net_device *dev,
98736 + struct iw_request_info *info,
98737 + union iwreq_data *wrqu, char *extra)
98738 +{
98739 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
98740 + struct iw_param *param = &wrqu->param;
98741 +
98742 + //check if the interface is down
98743 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
98744 + {
98745 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
98746 + return -ENETDOWN;
98747 + }
98748 +
98749 + switch (param->flags & IW_AUTH_INDEX) {
98750 + case IW_AUTH_DROP_UNENCRYPTED:
98751 + param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
98752 + break;
98753 +
98754 + case IW_AUTH_80211_AUTH_ALG:
98755 + param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
98756 + break;
98757 +
98758 + case IW_AUTH_WPA_ENABLED:
98759 + param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
98760 + break;
98761 +
98762 + default:
98763 + return -EOPNOTSUPP;
98764 + }
98765 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
98766 + return 0;
98767 +}
98768 +
98769 +void fnSetCipherKey(
98770 + IN PRTMP_ADAPTER pAdapter,
98771 + IN INT keyIdx,
98772 + IN UCHAR CipherAlg,
98773 + IN BOOLEAN bGTK,
98774 + IN struct iw_encode_ext *ext)
98775 +{
98776 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
98777 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
98778 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
98779 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
98780 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
98781 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
98782 +
98783 + // Update group key information to ASIC Shared Key Table
98784 + AsicAddSharedKeyEntry(pAdapter,
98785 + BSS0,
98786 + keyIdx,
98787 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
98788 + pAdapter->SharedKey[BSS0][keyIdx].Key,
98789 + pAdapter->SharedKey[BSS0][keyIdx].TxMic,
98790 + pAdapter->SharedKey[BSS0][keyIdx].RxMic);
98791 +
98792 + if (bGTK)
98793 + // Update ASIC WCID attribute table and IVEIV table
98794 + RTMPAddWcidAttributeEntry(pAdapter,
98795 + BSS0,
98796 + keyIdx,
98797 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
98798 + NULL);
98799 + else
98800 + // Update ASIC WCID attribute table and IVEIV table
98801 + RTMPAddWcidAttributeEntry(pAdapter,
98802 + BSS0,
98803 + keyIdx,
98804 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
98805 + &pAdapter->MacTab.Content[BSSID_WCID]);
98806 +}
98807 +
98808 +int rt_ioctl_siwencodeext(struct net_device *dev,
98809 + struct iw_request_info *info,
98810 + union iwreq_data *wrqu,
98811 + char *extra)
98812 + {
98813 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
98814 + struct iw_point *encoding = &wrqu->encoding;
98815 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
98816 + int keyIdx, alg = ext->alg;
98817 +
98818 + //check if the interface is down
98819 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
98820 + {
98821 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
98822 + return -ENETDOWN;
98823 + }
98824 +
98825 + if (encoding->flags & IW_ENCODE_DISABLED)
98826 + {
98827 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
98828 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
98829 + AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
98830 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
98831 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
98832 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
98833 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
98834 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __FUNCTION__, encoding->flags));
98835 + }
98836 + else
98837 + {
98838 + // Get Key Index and convet to our own defined key index
98839 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
98840 + if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
98841 + return -EINVAL;
98842 +
98843 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
98844 + {
98845 + pAdapter->StaCfg.DefaultKeyId = keyIdx;
98846 + DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __FUNCTION__, pAdapter->StaCfg.DefaultKeyId));
98847 + }
98848 +
98849 + switch (alg) {
98850 + case IW_ENCODE_ALG_NONE:
98851 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __FUNCTION__));
98852 + break;
98853 + case IW_ENCODE_ALG_WEP:
98854 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __FUNCTION__, ext->key_len, keyIdx));
98855 + if (ext->key_len == MAX_WEP_KEY_SIZE)
98856 + {
98857 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
98858 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
98859 + }
98860 + else if (ext->key_len == MIN_WEP_KEY_SIZE)
98861 + {
98862 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
98863 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
98864 + }
98865 + else
98866 + return -EINVAL;
98867 +
98868 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
98869 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
98870 + break;
98871 + case IW_ENCODE_ALG_TKIP:
98872 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __FUNCTION__, keyIdx, ext->key_len));
98873 + if (ext->key_len == 32)
98874 + {
98875 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
98876 + {
98877 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
98878 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
98879 + {
98880 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98881 + STA_PORT_SECURED(pAdapter);
98882 + }
98883 + }
98884 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
98885 + {
98886 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
98887 +
98888 + // set 802.1x port control
98889 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98890 + STA_PORT_SECURED(pAdapter);
98891 + }
98892 + }
98893 + else
98894 + return -EINVAL;
98895 + break;
98896 + case IW_ENCODE_ALG_CCMP:
98897 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
98898 + {
98899 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
98900 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
98901 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98902 + STA_PORT_SECURED(pAdapter);
98903 + }
98904 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
98905 + {
98906 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
98907 +
98908 + // set 802.1x port control
98909 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
98910 + STA_PORT_SECURED(pAdapter);
98911 + }
98912 + break;
98913 + default:
98914 + return -EINVAL;
98915 + }
98916 + }
98917 +
98918 + return 0;
98919 +}
98920 +
98921 +int
98922 +rt_ioctl_giwencodeext(struct net_device *dev,
98923 + struct iw_request_info *info,
98924 + union iwreq_data *wrqu, char *extra)
98925 +{
98926 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
98927 + PCHAR pKey = NULL;
98928 + struct iw_point *encoding = &wrqu->encoding;
98929 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
98930 + int idx, max_key_len;
98931 +
98932 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
98933 +
98934 + max_key_len = encoding->length - sizeof(*ext);
98935 + if (max_key_len < 0)
98936 + return -EINVAL;
98937 +
98938 + idx = encoding->flags & IW_ENCODE_INDEX;
98939 + if (idx)
98940 + {
98941 + if (idx < 1 || idx > 4)
98942 + return -EINVAL;
98943 + idx--;
98944 +
98945 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
98946 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
98947 + {
98948 + if (idx != pAd->StaCfg.DefaultKeyId)
98949 + {
98950 + ext->key_len = 0;
98951 + return 0;
98952 + }
98953 + }
98954 + }
98955 + else
98956 + idx = pAd->StaCfg.DefaultKeyId;
98957 +
98958 + encoding->flags = idx + 1;
98959 + memset(ext, 0, sizeof(*ext));
98960 +
98961 + ext->key_len = 0;
98962 + switch(pAd->StaCfg.WepStatus) {
98963 + case Ndis802_11WEPDisabled:
98964 + ext->alg = IW_ENCODE_ALG_NONE;
98965 + encoding->flags |= IW_ENCODE_DISABLED;
98966 + break;
98967 + case Ndis802_11WEPEnabled:
98968 + ext->alg = IW_ENCODE_ALG_WEP;
98969 + if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
98970 + return -E2BIG;
98971 + else
98972 + {
98973 + ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
98974 + pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
98975 + }
98976 + break;
98977 + case Ndis802_11Encryption2Enabled:
98978 + case Ndis802_11Encryption3Enabled:
98979 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
98980 + ext->alg = IW_ENCODE_ALG_TKIP;
98981 + else
98982 + ext->alg = IW_ENCODE_ALG_CCMP;
98983 +
98984 + if (max_key_len < 32)
98985 + return -E2BIG;
98986 + else
98987 + {
98988 + ext->key_len = 32;
98989 + pKey = &pAd->StaCfg.PMK[0];
98990 + }
98991 + break;
98992 + default:
98993 + return -EINVAL;
98994 + }
98995 +
98996 + if (ext->key_len && pKey)
98997 + {
98998 + encoding->flags |= IW_ENCODE_ENABLED;
98999 + memcpy(ext->key, pKey, ext->key_len);
99000 + }
99001 +
99002 + return 0;
99003 +}
99004 +
99005 +#ifdef SIOCSIWGENIE
99006 +int rt_ioctl_siwgenie(struct net_device *dev,
99007 + struct iw_request_info *info,
99008 + union iwreq_data *wrqu, char *extra)
99009 +{
99010 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
99011 +
99012 + if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
99013 + (wrqu->data.length && extra == NULL))
99014 + return -EINVAL;
99015 +
99016 + if (wrqu->data.length)
99017 + {
99018 + pAd->StaCfg.RSNIE_Len = wrqu->data.length;
99019 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
99020 + }
99021 + else
99022 + {
99023 + pAd->StaCfg.RSNIE_Len = 0;
99024 + NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
99025 + }
99026 +
99027 + return 0;
99028 +}
99029 +#endif // SIOCSIWGENIE //
99030 +
99031 +int rt_ioctl_giwgenie(struct net_device *dev,
99032 + struct iw_request_info *info,
99033 + union iwreq_data *wrqu, char *extra)
99034 +{
99035 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
99036 +
99037 + if ((pAd->StaCfg.RSNIE_Len == 0) ||
99038 + (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
99039 + {
99040 + wrqu->data.length = 0;
99041 + return 0;
99042 + }
99043 +
99044 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
99045 +#ifdef SIOCSIWGENIE
99046 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
99047 + {
99048 + if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
99049 + return -E2BIG;
99050 +
99051 + wrqu->data.length = pAd->StaCfg.RSNIE_Len;
99052 + memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
99053 + }
99054 + else
99055 +#endif // SIOCSIWGENIE //
99056 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
99057 + {
99058 + UCHAR RSNIe = IE_WPA;
99059 +
99060 + if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
99061 + return -E2BIG;
99062 + wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
99063 +
99064 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
99065 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
99066 + RSNIe = IE_RSN;
99067 +
99068 + extra[0] = (char)RSNIe;
99069 + extra[1] = pAd->StaCfg.RSNIE_Len;
99070 + memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
99071 + }
99072 +
99073 + return 0;
99074 +}
99075 +
99076 +int rt_ioctl_siwpmksa(struct net_device *dev,
99077 + struct iw_request_info *info,
99078 + union iwreq_data *wrqu,
99079 + char *extra)
99080 +{
99081 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
99082 + struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
99083 + INT CachedIdx = 0, idx = 0;
99084 +
99085 + if (pPmksa == NULL)
99086 + return -EINVAL;
99087 +
99088 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
99089 + switch(pPmksa->cmd)
99090 + {
99091 + case IW_PMKSA_FLUSH:
99092 + NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
99093 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
99094 + break;
99095 + case IW_PMKSA_REMOVE:
99096 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
99097 + {
99098 + // compare the BSSID
99099 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
99100 + {
99101 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
99102 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
99103 + for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
99104 + {
99105 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
99106 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
99107 + }
99108 + pAd->StaCfg.SavedPMKNum--;
99109 + break;
99110 + }
99111 + }
99112 +
99113 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
99114 + break;
99115 + case IW_PMKSA_ADD:
99116 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
99117 + {
99118 + // compare the BSSID
99119 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
99120 + break;
99121 + }
99122 +
99123 + // Found, replace it
99124 + if (CachedIdx < PMKID_NO)
99125 + {
99126 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
99127 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
99128 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
99129 + pAd->StaCfg.SavedPMKNum++;
99130 + }
99131 + // Not found, replace the last one
99132 + else
99133 + {
99134 + // Randomly replace one
99135 + CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
99136 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
99137 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
99138 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
99139 + }
99140 +
99141 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
99142 + break;
99143 + default:
99144 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
99145 + break;
99146 + }
99147 +
99148 + return 0;
99149 +}
99150 +#endif // #if WIRELESS_EXT > 17
99151 +
99152 +#ifdef DBG
99153 +static int
99154 +rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
99155 + struct iw_point *wrq, char *extra)
99156 + {
99157 + CHAR *this_char;
99158 + CHAR *value = NULL;
99159 + UCHAR regBBP = 0;
99160 +// CHAR arg[255]={0};
99161 + UINT32 bbpId;
99162 + UINT32 bbpValue;
99163 + BOOLEAN bIsPrintAllBBP = FALSE;
99164 + INT Status = 0;
99165 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
99166 +
99167 +
99168 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
99169 +
99170 + if (wrq->length > 1) //No parameters.
99171 + {
99172 + sprintf(extra, "\n");
99173 +
99174 + //Parsing Read or Write
99175 + this_char = wrq->pointer;
99176 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
99177 + if (!*this_char)
99178 + goto next;
99179 +
99180 + if ((value = rtstrchr(this_char, '=')) != NULL)
99181 + *value++ = 0;
99182 +
99183 + if (!value || !*value)
99184 + { //Read
99185 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
99186 + if (sscanf(this_char, "%d", &(bbpId)) == 1)
99187 + {
99188 + if (bbpId <= 136)
99189 + {
99190 +#ifdef RALINK_ATE
99191 + if (ATE_ON(pAdapter))
99192 + {
99193 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99194 + }
99195 + else
99196 +#endif // RALINK_ATE //
99197 + {
99198 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99199 + }
99200 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
99201 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
99202 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
99203 + }
99204 + else
99205 + {//Invalid parametes, so default printk all bbp
99206 + bIsPrintAllBBP = TRUE;
99207 + goto next;
99208 + }
99209 + }
99210 + else
99211 + { //Invalid parametes, so default printk all bbp
99212 + bIsPrintAllBBP = TRUE;
99213 + goto next;
99214 + }
99215 + }
99216 + else
99217 + { //Write
99218 + if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
99219 + {
99220 + if (bbpId <= 136)
99221 + {
99222 +#ifdef RALINK_ATE
99223 + if (ATE_ON(pAdapter))
99224 + {
99225 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
99226 + //Read it back for showing
99227 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99228 + }
99229 + else
99230 +#endif // RALINK_ATE //
99231 + {
99232 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
99233 + //Read it back for showing
99234 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99235 + }
99236 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
99237 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
99238 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
99239 + }
99240 + else
99241 + {//Invalid parametes, so default printk all bbp
99242 + bIsPrintAllBBP = TRUE;
99243 + goto next;
99244 + }
99245 + }
99246 + else
99247 + { //Invalid parametes, so default printk all bbp
99248 + bIsPrintAllBBP = TRUE;
99249 + goto next;
99250 + }
99251 + }
99252 + }
99253 + else
99254 + bIsPrintAllBBP = TRUE;
99255 +
99256 +next:
99257 + if (bIsPrintAllBBP)
99258 + {
99259 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
99260 + sprintf(extra, "\n");
99261 + for (bbpId = 0; bbpId <= 136; bbpId++)
99262 + {
99263 + if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
99264 + break;
99265 +#ifdef RALINK_ATE
99266 + if (ATE_ON(pAdapter))
99267 + {
99268 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99269 + }
99270 + else
99271 +#endif // RALINK_ATE //
99272 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
99273 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
99274 + if (bbpId%5 == 4)
99275 + sprintf(extra+strlen(extra), "\n");
99276 + }
99277 +
99278 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
99279 + DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
99280 + }
99281 +
99282 + DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
99283 +
99284 + return Status;
99285 +}
99286 +#endif // DBG //
99287 +
99288 +int rt_ioctl_siwrate(struct net_device *dev,
99289 + struct iw_request_info *info,
99290 + union iwreq_data *wrqu, char *extra)
99291 +{
99292 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
99293 + UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
99294 +
99295 + //check if the interface is down
99296 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
99297 + {
99298 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
99299 + return -ENETDOWN;
99300 + }
99301 +
99302 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
99303 + /* rate = -1 => auto rate
99304 + rate = X, fixed = 1 => (fixed rate X)
99305 + */
99306 + if (rate == -1)
99307 + {
99308 + //Auto Rate
99309 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
99310 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
99311 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
99312 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
99313 + RTMPSetDesiredRates(pAd, -1);
99314 +
99315 +#ifdef DOT11_N_SUPPORT
99316 + SetCommonHT(pAd);
99317 +#endif // DOT11_N_SUPPORT //
99318 + }
99319 + else
99320 + {
99321 + if (fixed)
99322 + {
99323 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
99324 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
99325 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
99326 + RTMPSetDesiredRates(pAd, rate);
99327 + else
99328 + {
99329 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
99330 +#ifdef DOT11_N_SUPPORT
99331 + SetCommonHT(pAd);
99332 +#endif // DOT11_N_SUPPORT //
99333 + }
99334 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
99335 + }
99336 + else
99337 + {
99338 + // TODO: rate = X, fixed = 0 => (rates <= X)
99339 + return -EOPNOTSUPP;
99340 + }
99341 + }
99342 +
99343 + return 0;
99344 +}
99345 +
99346 +int rt_ioctl_giwrate(struct net_device *dev,
99347 + struct iw_request_info *info,
99348 + union iwreq_data *wrqu, char *extra)
99349 +{
99350 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
99351 + int rate_index = 0, rate_count = 0;
99352 + HTTRANSMIT_SETTING ht_setting;
99353 + __s32 ralinkrate[] =
99354 + {2, 4, 11, 22, // CCK
99355 + 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
99356 + 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
99357 + 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
99358 + 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
99359 + 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
99360 + 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
99361 + 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
99362 + 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
99363 + 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
99364 +
99365 + rate_count = sizeof(ralinkrate)/sizeof(__s32);
99366 + //check if the interface is down
99367 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
99368 + {
99369 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
99370 + return -ENETDOWN;
99371 + }
99372 +
99373 + if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
99374 + (INFRA_ON(pAd)) &&
99375 + ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
99376 + ht_setting.word = pAd->StaCfg.HTPhyMode.word;
99377 + else
99378 + ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
99379 +
99380 +#ifdef DOT11_N_SUPPORT
99381 + if (ht_setting.field.MODE >= MODE_HTMIX)
99382 + {
99383 +// rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
99384 + rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
99385 + }
99386 + else
99387 +#endif // DOT11_N_SUPPORT //
99388 + if (ht_setting.field.MODE == MODE_OFDM)
99389 + rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
99390 + else if (ht_setting.field.MODE == MODE_CCK)
99391 + rate_index = (UCHAR)(ht_setting.field.MCS);
99392 +
99393 + if (rate_index < 0)
99394 + rate_index = 0;
99395 +
99396 + if (rate_index > rate_count)
99397 + rate_index = rate_count;
99398 +
99399 + wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
99400 + wrqu->bitrate.disabled = 0;
99401 +
99402 + return 0;
99403 +}
99404 +
99405 +static const iw_handler rt_handler[] =
99406 +{
99407 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
99408 + (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
99409 + (iw_handler) NULL, /* SIOCSIWNWID */
99410 + (iw_handler) NULL, /* SIOCGIWNWID */
99411 + (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
99412 + (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
99413 + (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
99414 + (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
99415 + (iw_handler) NULL, /* SIOCSIWSENS */
99416 + (iw_handler) NULL, /* SIOCGIWSENS */
99417 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
99418 + (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
99419 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
99420 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
99421 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
99422 + (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
99423 + (iw_handler) NULL, /* SIOCSIWSPY */
99424 + (iw_handler) NULL, /* SIOCGIWSPY */
99425 + (iw_handler) NULL, /* SIOCSIWTHRSPY */
99426 + (iw_handler) NULL, /* SIOCGIWTHRSPY */
99427 + (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
99428 + (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
99429 +#ifdef SIOCSIWMLME
99430 + (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
99431 +#else
99432 + (iw_handler) NULL, /* SIOCSIWMLME */
99433 +#endif // SIOCSIWMLME //
99434 + (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
99435 +#ifdef SIOCGIWSCAN
99436 + (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
99437 + (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
99438 +#else
99439 + (iw_handler) NULL, /* SIOCSIWSCAN */
99440 + (iw_handler) NULL, /* SIOCGIWSCAN */
99441 +#endif /* SIOCGIWSCAN */
99442 + (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
99443 + (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
99444 + (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
99445 + (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
99446 + (iw_handler) NULL, /* -- hole -- */
99447 + (iw_handler) NULL, /* -- hole -- */
99448 + (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
99449 + (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
99450 + (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
99451 + (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
99452 + (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
99453 + (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
99454 + (iw_handler) NULL, /* SIOCSIWTXPOW */
99455 + (iw_handler) NULL, /* SIOCGIWTXPOW */
99456 + (iw_handler) NULL, /* SIOCSIWRETRY */
99457 + (iw_handler) NULL, /* SIOCGIWRETRY */
99458 + (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
99459 + (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
99460 + (iw_handler) NULL, /* SIOCSIWPOWER */
99461 + (iw_handler) NULL, /* SIOCGIWPOWER */
99462 + (iw_handler) NULL, /* -- hole -- */
99463 + (iw_handler) NULL, /* -- hole -- */
99464 +#if WIRELESS_EXT > 17
99465 + (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
99466 + (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
99467 + (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
99468 + (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
99469 + (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
99470 + (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
99471 + (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
99472 +#endif
99473 +};
99474 +
99475 +static const iw_handler rt_priv_handlers[] = {
99476 + (iw_handler) NULL, /* + 0x00 */
99477 + (iw_handler) NULL, /* + 0x01 */
99478 +#ifndef CONFIG_AP_SUPPORT
99479 + (iw_handler) rt_ioctl_setparam, /* + 0x02 */
99480 +#else
99481 + (iw_handler) NULL, /* + 0x02 */
99482 +#endif // CONFIG_AP_SUPPORT //
99483 +#ifdef DBG
99484 + (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
99485 +#else
99486 + (iw_handler) NULL, /* + 0x03 */
99487 +#endif
99488 + (iw_handler) NULL, /* + 0x04 */
99489 + (iw_handler) NULL, /* + 0x05 */
99490 + (iw_handler) NULL, /* + 0x06 */
99491 + (iw_handler) NULL, /* + 0x07 */
99492 + (iw_handler) NULL, /* + 0x08 */
99493 + (iw_handler) rt_private_get_statistics, /* + 0x09 */
99494 + (iw_handler) NULL, /* + 0x0A */
99495 + (iw_handler) NULL, /* + 0x0B */
99496 + (iw_handler) NULL, /* + 0x0C */
99497 + (iw_handler) NULL, /* + 0x0D */
99498 + (iw_handler) NULL, /* + 0x0E */
99499 + (iw_handler) NULL, /* + 0x0F */
99500 + (iw_handler) NULL, /* + 0x10 */
99501 + (iw_handler) rt_private_show, /* + 0x11 */
99502 + (iw_handler) NULL, /* + 0x12 */
99503 + (iw_handler) NULL, /* + 0x13 */
99504 + (iw_handler) NULL, /* + 0x15 */
99505 + (iw_handler) NULL, /* + 0x17 */
99506 + (iw_handler) NULL, /* + 0x18 */
99507 +};
99508 +
99509 +const struct iw_handler_def rt28xx_iw_handler_def =
99510 +{
99511 +#define N(a) (sizeof (a) / sizeof (a[0]))
99512 + .standard = (iw_handler *) rt_handler,
99513 + .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
99514 + .private = (iw_handler *) rt_priv_handlers,
99515 + .num_private = N(rt_priv_handlers),
99516 + .private_args = (struct iw_priv_args *) privtab,
99517 + .num_private_args = N(privtab),
99518 +#if IW_HANDLER_VERSION >= 7
99519 + .get_wireless_stats = rt28xx_get_wireless_stats,
99520 +#endif
99521 +};
99522 +
99523 +INT RTMPSetInformation(
99524 + IN PRTMP_ADAPTER pAdapter,
99525 + IN OUT struct ifreq *rq,
99526 + IN INT cmd)
99527 +{
99528 + struct iwreq *wrq = (struct iwreq *) rq;
99529 + NDIS_802_11_SSID Ssid;
99530 + NDIS_802_11_MAC_ADDRESS Bssid;
99531 + RT_802_11_PHY_MODE PhyMode;
99532 + RT_802_11_STA_CONFIG StaConfig;
99533 + NDIS_802_11_RATES aryRates;
99534 + RT_802_11_PREAMBLE Preamble;
99535 + NDIS_802_11_WEP_STATUS WepStatus;
99536 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
99537 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
99538 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
99539 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
99540 + NDIS_802_11_POWER_MODE PowerMode;
99541 + PNDIS_802_11_KEY pKey = NULL;
99542 + PNDIS_802_11_WEP pWepKey =NULL;
99543 + PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
99544 + NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
99545 + NDIS_802_11_NETWORK_TYPE NetType;
99546 + ULONG Now;
99547 + UINT KeyIdx = 0;
99548 + INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
99549 + ULONG PowerTemp;
99550 + BOOLEAN RadioState;
99551 + BOOLEAN StateMachineTouched = FALSE;
99552 +#ifdef DOT11_N_SUPPORT
99553 + OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
99554 +#endif // DOT11_N_SUPPORT //
99555 +#ifdef WPA_SUPPLICANT_SUPPORT
99556 + PNDIS_802_11_PMKID pPmkId = NULL;
99557 + BOOLEAN IEEE8021xState = FALSE;
99558 + BOOLEAN IEEE8021x_required_keys = FALSE;
99559 + UCHAR wpa_supplicant_enable = 0;
99560 +#endif // WPA_SUPPLICANT_SUPPORT //
99561 +
99562 +#ifdef SNMP_SUPPORT
99563 + TX_RTY_CFG_STRUC tx_rty_cfg;
99564 + ULONG ShortRetryLimit, LongRetryLimit;
99565 + UCHAR ctmp;
99566 +#endif // SNMP_SUPPORT //
99567 +
99568 +
99569 +
99570 +#ifdef DOT11_N_SUPPORT
99571 + MaxPhyMode = PHY_11N_5G;
99572 +#endif // DOT11_N_SUPPORT //
99573 +
99574 +
99575 + DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
99576 + switch(cmd & 0x7FFF) {
99577 + case RT_OID_802_11_COUNTRY_REGION:
99578 + if (wrq->u.data.length < sizeof(UCHAR))
99579 + Status = -EINVAL;
99580 + // Only avaliable when EEPROM not programming
99581 + else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
99582 + {
99583 + ULONG Country;
99584 + UCHAR TmpPhy;
99585 +
99586 + Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
99587 + pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
99588 + pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
99589 + TmpPhy = pAdapter->CommonCfg.PhyMode;
99590 + pAdapter->CommonCfg.PhyMode = 0xff;
99591 + // Build all corresponding channel information
99592 + RTMPSetPhyMode(pAdapter, TmpPhy);
99593 +#ifdef DOT11_N_SUPPORT
99594 + SetCommonHT(pAdapter);
99595 +#endif // DOT11_N_SUPPORT //
99596 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
99597 + pAdapter->CommonCfg.CountryRegion));
99598 + }
99599 + break;
99600 + case OID_802_11_BSSID_LIST_SCAN:
99601 + #ifdef RALINK_ATE
99602 + if (ATE_ON(pAdapter))
99603 + {
99604 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
99605 + break;
99606 + }
99607 +#endif // RALINK_ATE //
99608 + Now = jiffies;
99609 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
99610 +
99611 + if (MONITOR_ON(pAdapter))
99612 + {
99613 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
99614 + break;
99615 + }
99616 +
99617 + //Benson add 20080527, when radio off, sta don't need to scan
99618 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
99619 + break;
99620 +
99621 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
99622 + {
99623 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
99624 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
99625 + Status = NDIS_STATUS_SUCCESS;
99626 + break;
99627 + }
99628 +
99629 + if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
99630 + {
99631 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
99632 + Status = NDIS_STATUS_SUCCESS;
99633 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
99634 + break;
99635 + }
99636 +
99637 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
99638 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
99639 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
99640 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
99641 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
99642 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
99643 + {
99644 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
99645 + Status = NDIS_STATUS_SUCCESS;
99646 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
99647 + break;
99648 + }
99649 +
99650 +
99651 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
99652 + {
99653 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
99654 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
99655 + }
99656 +
99657 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
99658 + // this request, because this request is initiated by NDIS.
99659 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
99660 + // Reset allowed scan retries
99661 + pAdapter->StaCfg.ScanCnt = 0;
99662 + pAdapter->StaCfg.LastScanTime = Now;
99663 +
99664 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
99665 + RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
99666 + MlmeEnqueue(pAdapter,
99667 + MLME_CNTL_STATE_MACHINE,
99668 + OID_802_11_BSSID_LIST_SCAN,
99669 + 0,
99670 + NULL);
99671 +
99672 + Status = NDIS_STATUS_SUCCESS;
99673 + StateMachineTouched = TRUE;
99674 + break;
99675 + case OID_802_11_SSID:
99676 + if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
99677 + Status = -EINVAL;
99678 + else
99679 + {
99680 + PCHAR pSsidString = NULL;
99681 + Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
99682 +
99683 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
99684 + if (Ssid.SsidLength > MAX_LEN_OF_SSID)
99685 + Status = -EINVAL;
99686 + else
99687 + {
99688 + if (Ssid.SsidLength == 0)
99689 + {
99690 + Set_SSID_Proc(pAdapter, "");
99691 + }
99692 + else
99693 + {
99694 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
99695 + if (pSsidString)
99696 + {
99697 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
99698 + NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
99699 + Set_SSID_Proc(pAdapter, pSsidString);
99700 + kfree(pSsidString);
99701 + }
99702 + else
99703 + Status = -ENOMEM;
99704 + }
99705 + }
99706 + }
99707 + break;
99708 + case OID_802_11_BSSID:
99709 +#ifdef RALINK_ATE
99710 + if (ATE_ON(pAdapter))
99711 + {
99712 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
99713 + break;
99714 + }
99715 +#endif // RALINK_ATE //
99716 + if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
99717 + Status = -EINVAL;
99718 + else
99719 + {
99720 + Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
99721 +
99722 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
99723 + // this request, because this request is initiated by NDIS.
99724 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
99725 +
99726 + // Prevent to connect AP again in STAMlmePeriodicExec
99727 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
99728 +
99729 + // Reset allowed scan retries
99730 + pAdapter->StaCfg.ScanCnt = 0;
99731 +
99732 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
99733 + {
99734 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
99735 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
99736 + }
99737 + MlmeEnqueue(pAdapter,
99738 + MLME_CNTL_STATE_MACHINE,
99739 + OID_802_11_BSSID,
99740 + sizeof(NDIS_802_11_MAC_ADDRESS),
99741 + (VOID *)&Bssid);
99742 + Status = NDIS_STATUS_SUCCESS;
99743 + StateMachineTouched = TRUE;
99744 +
99745 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
99746 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
99747 + }
99748 + break;
99749 + case RT_OID_802_11_RADIO:
99750 + if (wrq->u.data.length != sizeof(BOOLEAN))
99751 + Status = -EINVAL;
99752 + else
99753 + {
99754 + Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
99755 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
99756 + if (pAdapter->StaCfg.bSwRadio != RadioState)
99757 + {
99758 + pAdapter->StaCfg.bSwRadio = RadioState;
99759 + if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
99760 + {
99761 + pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
99762 + if (pAdapter->StaCfg.bRadio == TRUE)
99763 + {
99764 + MlmeRadioOn(pAdapter);
99765 + // Update extra information
99766 + pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
99767 + }
99768 + else
99769 + {
99770 + MlmeRadioOff(pAdapter);
99771 + // Update extra information
99772 + pAdapter->ExtraInfo = SW_RADIO_OFF;
99773 + }
99774 + }
99775 + }
99776 + }
99777 + break;
99778 + case RT_OID_802_11_PHY_MODE:
99779 + if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
99780 + Status = -EINVAL;
99781 + else
99782 + {
99783 + Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
99784 + if (PhyMode <= MaxPhyMode)
99785 + {
99786 + RTMPSetPhyMode(pAdapter, PhyMode);
99787 +#ifdef DOT11_N_SUPPORT
99788 + SetCommonHT(pAdapter);
99789 +#endif // DOT11_N_SUPPORT //
99790 + }
99791 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
99792 + }
99793 + break;
99794 + case RT_OID_802_11_STA_CONFIG:
99795 + if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
99796 + Status = -EINVAL;
99797 + else
99798 + {
99799 + Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
99800 + pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
99801 + pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
99802 + pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
99803 + if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
99804 + (StaConfig.AdhocMode <= MaxPhyMode))
99805 + {
99806 + // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
99807 + // if setting changed, need to reset current TX rate as well as BEACON frame format
99808 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
99809 + {
99810 + pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
99811 + RTMPSetPhyMode(pAdapter, PhyMode);
99812 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
99813 + MakeIbssBeacon(pAdapter); // re-build BEACON frame
99814 + AsicEnableIbssSync(pAdapter); // copy to on-chip memory
99815 + }
99816 + }
99817 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
99818 + pAdapter->CommonCfg.bEnableTxBurst,
99819 + pAdapter->CommonCfg.UseBGProtection,
99820 + pAdapter->CommonCfg.bUseShortSlotTime));
99821 + }
99822 + break;
99823 + case OID_802_11_DESIRED_RATES:
99824 + if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
99825 + Status = -EINVAL;
99826 + else
99827 + {
99828 + Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
99829 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
99830 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
99831 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
99832 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
99833 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
99834 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
99835 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
99836 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
99837 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
99838 + }
99839 + break;
99840 + case RT_OID_802_11_PREAMBLE:
99841 + if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
99842 + Status = -EINVAL;
99843 + else
99844 + {
99845 + Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
99846 + if (Preamble == Rt802_11PreambleShort)
99847 + {
99848 + pAdapter->CommonCfg.TxPreamble = Preamble;
99849 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
99850 + }
99851 + else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
99852 + {
99853 + // if user wants AUTO, initialize to LONG here, then change according to AP's
99854 + // capability upon association.
99855 + pAdapter->CommonCfg.TxPreamble = Preamble;
99856 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
99857 + }
99858 + else
99859 + {
99860 + Status = -EINVAL;
99861 + break;
99862 + }
99863 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
99864 + }
99865 + break;
99866 + case OID_802_11_WEP_STATUS:
99867 + if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
99868 + Status = -EINVAL;
99869 + else
99870 + {
99871 + Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
99872 + // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
99873 + if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
99874 + {
99875 + if (pAdapter->StaCfg.WepStatus != WepStatus)
99876 + {
99877 + // Config has changed
99878 + pAdapter->bConfigChanged = TRUE;
99879 + }
99880 + pAdapter->StaCfg.WepStatus = WepStatus;
99881 + pAdapter->StaCfg.OrigWepStatus = WepStatus;
99882 + pAdapter->StaCfg.PairCipher = WepStatus;
99883 + pAdapter->StaCfg.GroupCipher = WepStatus;
99884 + }
99885 + else
99886 + {
99887 + Status = -EINVAL;
99888 + break;
99889 + }
99890 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
99891 + }
99892 + break;
99893 + case OID_802_11_AUTHENTICATION_MODE:
99894 + if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
99895 + Status = -EINVAL;
99896 + else
99897 + {
99898 + Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
99899 + if (AuthMode > Ndis802_11AuthModeMax)
99900 + {
99901 + Status = -EINVAL;
99902 + break;
99903 + }
99904 + else
99905 + {
99906 + if (pAdapter->StaCfg.AuthMode != AuthMode)
99907 + {
99908 + // Config has changed
99909 + pAdapter->bConfigChanged = TRUE;
99910 + }
99911 + pAdapter->StaCfg.AuthMode = AuthMode;
99912 + }
99913 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
99914 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
99915 + }
99916 + break;
99917 + case OID_802_11_INFRASTRUCTURE_MODE:
99918 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
99919 + Status = -EINVAL;
99920 + else
99921 + {
99922 + Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
99923 +
99924 + if (BssType == Ndis802_11IBSS)
99925 + Set_NetworkType_Proc(pAdapter, "Adhoc");
99926 + else if (BssType == Ndis802_11Infrastructure)
99927 + Set_NetworkType_Proc(pAdapter, "Infra");
99928 + else if (BssType == Ndis802_11Monitor)
99929 + Set_NetworkType_Proc(pAdapter, "Monitor");
99930 + else
99931 + {
99932 + Status = -EINVAL;
99933 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
99934 + }
99935 + }
99936 + break;
99937 + case OID_802_11_REMOVE_WEP:
99938 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
99939 + if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
99940 + {
99941 + Status = -EINVAL;
99942 + }
99943 + else
99944 + {
99945 + KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
99946 +
99947 + if (KeyIdx & 0x80000000)
99948 + {
99949 + // Should never set default bit when remove key
99950 + Status = -EINVAL;
99951 + }
99952 + else
99953 + {
99954 + KeyIdx = KeyIdx & 0x0fffffff;
99955 + if (KeyIdx >= 4){
99956 + Status = -EINVAL;
99957 + }
99958 + else
99959 + {
99960 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
99961 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
99962 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
99963 + }
99964 + }
99965 + }
99966 + break;
99967 + case RT_OID_802_11_RESET_COUNTERS:
99968 + NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
99969 + NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
99970 + NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
99971 + pAdapter->Counters8023.RxNoBuffer = 0;
99972 + pAdapter->Counters8023.GoodReceives = 0;
99973 + pAdapter->Counters8023.RxNoBuffer = 0;
99974 +#ifdef RT2870
99975 + pAdapter->BulkOutComplete = 0;
99976 + pAdapter->BulkOutCompleteOther= 0;
99977 + pAdapter->BulkOutCompleteCancel = 0;
99978 + pAdapter->BulkOutReq = 0;
99979 + pAdapter->BulkInReq= 0;
99980 + pAdapter->BulkInComplete = 0;
99981 + pAdapter->BulkInCompleteFail = 0;
99982 +#endif // RT2870 //
99983 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
99984 + break;
99985 + case OID_802_11_RTS_THRESHOLD:
99986 + if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
99987 + Status = -EINVAL;
99988 + else
99989 + {
99990 + Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
99991 + if (RtsThresh > MAX_RTS_THRESHOLD)
99992 + Status = -EINVAL;
99993 + else
99994 + pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
99995 + }
99996 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
99997 + break;
99998 + case OID_802_11_FRAGMENTATION_THRESHOLD:
99999 + if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
100000 + Status = -EINVAL;
100001 + else
100002 + {
100003 + Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
100004 + pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
100005 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
100006 + {
100007 + if (FragThresh == 0)
100008 + {
100009 + pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
100010 + pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
100011 + }
100012 + else
100013 + Status = -EINVAL;
100014 + }
100015 + else
100016 + pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
100017 + }
100018 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
100019 + break;
100020 + case OID_802_11_POWER_MODE:
100021 + if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
100022 + Status = -EINVAL;
100023 + else
100024 + {
100025 + Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
100026 + if (PowerMode == Ndis802_11PowerModeCAM)
100027 + Set_PSMode_Proc(pAdapter, "CAM");
100028 + else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
100029 + Set_PSMode_Proc(pAdapter, "Max_PSP");
100030 + else if (PowerMode == Ndis802_11PowerModeFast_PSP)
100031 + Set_PSMode_Proc(pAdapter, "Fast_PSP");
100032 + else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
100033 + Set_PSMode_Proc(pAdapter, "Legacy_PSP");
100034 + else
100035 + Status = -EINVAL;
100036 + }
100037 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
100038 + break;
100039 + case RT_OID_802_11_TX_POWER_LEVEL_1:
100040 + if (wrq->u.data.length < sizeof(ULONG))
100041 + Status = -EINVAL;
100042 + else
100043 + {
100044 + Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
100045 + if (PowerTemp > 100)
100046 + PowerTemp = 0xffffffff; // AUTO
100047 + pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
100048 + pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
100049 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
100050 + }
100051 + break;
100052 + case OID_802_11_NETWORK_TYPE_IN_USE:
100053 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
100054 + Status = -EINVAL;
100055 + else
100056 + {
100057 + Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
100058 +
100059 + if (NetType == Ndis802_11DS)
100060 + RTMPSetPhyMode(pAdapter, PHY_11B);
100061 + else if (NetType == Ndis802_11OFDM24)
100062 + RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
100063 + else if (NetType == Ndis802_11OFDM5)
100064 + RTMPSetPhyMode(pAdapter, PHY_11A);
100065 + else
100066 + Status = -EINVAL;
100067 +#ifdef DOT11_N_SUPPORT
100068 + if (Status == NDIS_STATUS_SUCCESS)
100069 + SetCommonHT(pAdapter);
100070 +#endif // DOT11_N_SUPPORT //
100071 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
100072 + }
100073 + break;
100074 + // For WPA PSK PMK key
100075 + case RT_OID_802_11_ADD_WPA:
100076 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100077 + if(pKey == NULL)
100078 + {
100079 + Status = -ENOMEM;
100080 + break;
100081 + }
100082 +
100083 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
100084 + if (pKey->Length != wrq->u.data.length)
100085 + {
100086 + Status = -EINVAL;
100087 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
100088 + }
100089 + else
100090 + {
100091 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
100092 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
100093 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
100094 + {
100095 + Status = -EOPNOTSUPP;
100096 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
100097 + }
100098 + else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
100099 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
100100 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
100101 + {
100102 + NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
100103 + // Use RaConfig as PSK agent.
100104 + // Start STA supplicant state machine
100105 + if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
100106 + pAdapter->StaCfg.WpaState = SS_START;
100107 +
100108 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
100109 + }
100110 + else
100111 + {
100112 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
100113 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
100114 + }
100115 + }
100116 + kfree(pKey);
100117 + break;
100118 + case OID_802_11_REMOVE_KEY:
100119 + pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100120 + if(pRemoveKey == NULL)
100121 + {
100122 + Status = -ENOMEM;
100123 + break;
100124 + }
100125 +
100126 + Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
100127 + if (pRemoveKey->Length != wrq->u.data.length)
100128 + {
100129 + Status = -EINVAL;
100130 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
100131 + }
100132 + else
100133 + {
100134 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
100135 + {
100136 + RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
100137 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
100138 + }
100139 + else
100140 + {
100141 + KeyIdx = pRemoveKey->KeyIndex;
100142 +
100143 + if (KeyIdx & 0x80000000)
100144 + {
100145 + // Should never set default bit when remove key
100146 + Status = -EINVAL;
100147 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
100148 + }
100149 + else
100150 + {
100151 + KeyIdx = KeyIdx & 0x0fffffff;
100152 + if (KeyIdx > 3)
100153 + {
100154 + Status = -EINVAL;
100155 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
100156 + }
100157 + else
100158 + {
100159 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
100160 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
100161 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
100162 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
100163 + }
100164 + }
100165 + }
100166 + }
100167 + kfree(pRemoveKey);
100168 + break;
100169 + // New for WPA
100170 + case OID_802_11_ADD_KEY:
100171 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100172 + if(pKey == NULL)
100173 + {
100174 + Status = -ENOMEM;
100175 + break;
100176 + }
100177 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
100178 + if (pKey->Length != wrq->u.data.length)
100179 + {
100180 + Status = -EINVAL;
100181 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
100182 + }
100183 + else
100184 + {
100185 + RTMPAddKey(pAdapter, pKey);
100186 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
100187 + }
100188 + kfree(pKey);
100189 + break;
100190 + case OID_802_11_CONFIGURATION:
100191 + if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
100192 + Status = -EINVAL;
100193 + else
100194 + {
100195 + Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
100196 + pConfig = &Config;
100197 +
100198 + if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
100199 + pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
100200 +
100201 + pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
100202 + MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
100203 + //
100204 + // Save the channel on MlmeAux for CntlOidRTBssidProc used.
100205 + //
100206 + pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
100207 +
100208 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
100209 + pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
100210 + // Config has changed
100211 + pAdapter->bConfigChanged = TRUE;
100212 + }
100213 + break;
100214 +#ifdef DOT11_N_SUPPORT
100215 + case RT_OID_802_11_SET_HT_PHYMODE:
100216 + if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
100217 + Status = -EINVAL;
100218 + else
100219 + {
100220 + POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
100221 +
100222 + Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
100223 + DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
100224 + pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
100225 + pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
100226 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
100227 + RTMPSetHT(pAdapter, pHTPhyMode);
100228 + }
100229 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
100230 + pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
100231 + pAdapter->StaCfg.HTPhyMode.field.STBC));
100232 + break;
100233 +#endif // DOT11_N_SUPPORT //
100234 + case RT_OID_802_11_SET_APSD_SETTING:
100235 + if (wrq->u.data.length != sizeof(ULONG))
100236 + Status = -EINVAL;
100237 + else
100238 + {
100239 + ULONG apsd ;
100240 + Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
100241 +
100242 + /*-------------------------------------------------------------------
100243 + |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
100244 + ---------------------------------------------------------------------
100245 + | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
100246 + ---------------------------------------------------------------------*/
100247 + pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
100248 + pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
100249 + pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
100250 + pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
100251 + pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
100252 + pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
100253 +
100254 + 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,
100255 + pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
100256 + }
100257 + break;
100258 +
100259 + case RT_OID_802_11_SET_APSD_PSM:
100260 + if (wrq->u.data.length != sizeof(ULONG))
100261 + Status = -EINVAL;
100262 + else
100263 + {
100264 + // Driver needs to notify AP when PSM changes
100265 + Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
100266 + if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
100267 + {
100268 + MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
100269 + RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
100270 + }
100271 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
100272 + }
100273 + break;
100274 +#ifdef QOS_DLS_SUPPORT
100275 + case RT_OID_802_11_SET_DLS:
100276 + if (wrq->u.data.length != sizeof(ULONG))
100277 + Status = -EINVAL;
100278 + else
100279 + {
100280 + BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
100281 + Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
100282 + if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
100283 + {
100284 + int i;
100285 + // tear down local dls table entry
100286 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
100287 + {
100288 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
100289 + {
100290 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
100291 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
100292 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
100293 + }
100294 + }
100295 +
100296 + // tear down peer dls table entry
100297 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
100298 + {
100299 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
100300 + {
100301 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
100302 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
100303 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
100304 + }
100305 + }
100306 + }
100307 +
100308 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
100309 + }
100310 + break;
100311 +
100312 + case RT_OID_802_11_SET_DLS_PARAM:
100313 + if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
100314 + Status = -EINVAL;
100315 + else
100316 + {
100317 + RT_802_11_DLS Dls;
100318 +
100319 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
100320 + RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
100321 + MlmeEnqueue(pAdapter,
100322 + MLME_CNTL_STATE_MACHINE,
100323 + RT_OID_802_11_SET_DLS_PARAM,
100324 + sizeof(RT_802_11_DLS),
100325 + &Dls);
100326 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
100327 + }
100328 + break;
100329 +#endif // QOS_DLS_SUPPORT //
100330 + case RT_OID_802_11_SET_WMM:
100331 + if (wrq->u.data.length != sizeof(BOOLEAN))
100332 + Status = -EINVAL;
100333 + else
100334 + {
100335 + Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
100336 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
100337 + }
100338 + break;
100339 +
100340 + case OID_802_11_DISASSOCIATE:
100341 +#ifdef RALINK_ATE
100342 + if (ATE_ON(pAdapter))
100343 + {
100344 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
100345 + break;
100346 + }
100347 +#endif // RALINK_ATE //
100348 + //
100349 + // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
100350 + // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
100351 + // when query OID_802_11_BSSID_LIST.
100352 + //
100353 + // TRUE: NumberOfItems will set to 0.
100354 + // FALSE: NumberOfItems no change.
100355 + //
100356 + pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
100357 + // Set to immediately send the media disconnect event
100358 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
100359 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
100360 +
100361 + if (INFRA_ON(pAdapter))
100362 + {
100363 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
100364 + {
100365 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
100366 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
100367 + }
100368 +
100369 + MlmeEnqueue(pAdapter,
100370 + MLME_CNTL_STATE_MACHINE,
100371 + OID_802_11_DISASSOCIATE,
100372 + 0,
100373 + NULL);
100374 +
100375 + StateMachineTouched = TRUE;
100376 + }
100377 + break;
100378 +
100379 +#ifdef DOT11_N_SUPPORT
100380 + case RT_OID_802_11_SET_IMME_BA_CAP:
100381 + if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
100382 + Status = -EINVAL;
100383 + else
100384 + {
100385 + OID_BACAP_STRUC Orde ;
100386 + Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
100387 + if (Orde.Policy > BA_NOTUSE)
100388 + {
100389 + Status = NDIS_STATUS_INVALID_DATA;
100390 + }
100391 + else if (Orde.Policy == BA_NOTUSE)
100392 + {
100393 + pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
100394 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
100395 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
100396 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
100397 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
100398 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
100399 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
100400 + // UPdata to HT IE
100401 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
100402 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
100403 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
100404 + }
100405 + else
100406 + {
100407 + pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
100408 + pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
100409 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
100410 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
100411 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
100412 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
100413 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
100414 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
100415 +
100416 + // UPdata to HT IE
100417 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
100418 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
100419 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
100420 +
100421 + if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
100422 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
100423 +
100424 + }
100425 +
100426 + pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
100427 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
100428 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
100429 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
100430 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
100431 + }
100432 +
100433 + break;
100434 + case RT_OID_802_11_ADD_IMME_BA:
100435 + DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
100436 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
100437 + Status = -EINVAL;
100438 + else
100439 + {
100440 + UCHAR index;
100441 + OID_ADD_BA_ENTRY BA;
100442 + MAC_TABLE_ENTRY *pEntry;
100443 +
100444 + Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
100445 + if (BA.TID > 15)
100446 + {
100447 + Status = NDIS_STATUS_INVALID_DATA;
100448 + break;
100449 + }
100450 + else
100451 + {
100452 + //BATableInsertEntry
100453 + //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
100454 + index = BA.TID;
100455 + // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
100456 + pEntry = MacTableLookup(pAdapter, BA.MACAddr);
100457 + if (!pEntry)
100458 + {
100459 + DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
100460 + break;
100461 + }
100462 + if (BA.IsRecipient == FALSE)
100463 + {
100464 + if (pEntry->bIAmBadAtheros == TRUE)
100465 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
100466 +
100467 + BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
100468 + }
100469 + else
100470 + {
100471 + //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
100472 + }
100473 +
100474 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
100475 + BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
100476 + , BA.MACAddr[4], BA.MACAddr[5]));
100477 + }
100478 + }
100479 + break;
100480 +
100481 + case RT_OID_802_11_TEAR_IMME_BA:
100482 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
100483 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
100484 + Status = -EINVAL;
100485 + else
100486 + {
100487 + POID_ADD_BA_ENTRY pBA;
100488 + MAC_TABLE_ENTRY *pEntry;
100489 +
100490 + pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100491 +
100492 + if (pBA == NULL)
100493 + {
100494 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
100495 + Status = NDIS_STATUS_FAILURE;
100496 + }
100497 + else
100498 + {
100499 + Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
100500 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
100501 +
100502 + if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
100503 + {
100504 + Status = NDIS_STATUS_INVALID_DATA;
100505 + break;
100506 + }
100507 +
100508 + if (pBA->IsRecipient == FALSE)
100509 + {
100510 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
100511 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
100512 + if (pEntry)
100513 + {
100514 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
100515 + BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
100516 + }
100517 + else
100518 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
100519 + }
100520 + else
100521 + {
100522 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
100523 + if (pEntry)
100524 + {
100525 + BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
100526 + }
100527 + else
100528 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
100529 + }
100530 + kfree(pBA);
100531 + }
100532 + }
100533 + break;
100534 +#endif // DOT11_N_SUPPORT //
100535 +
100536 + // For WPA_SUPPLICANT to set static wep key
100537 + case OID_802_11_ADD_WEP:
100538 + pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100539 +
100540 + if(pWepKey == NULL)
100541 + {
100542 + Status = -ENOMEM;
100543 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
100544 + break;
100545 + }
100546 + Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
100547 + if (Status)
100548 + {
100549 + Status = -EINVAL;
100550 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
100551 + }
100552 + else
100553 + {
100554 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
100555 + // KeyIdx must be 0 ~ 3
100556 + if (KeyIdx > 4)
100557 + {
100558 + Status = -EINVAL;
100559 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
100560 + }
100561 + else
100562 + {
100563 + UCHAR CipherAlg = 0;
100564 + PUCHAR Key;
100565 +
100566 + // set key material and key length
100567 + NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
100568 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
100569 + NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
100570 +
100571 + switch(pWepKey->KeyLength)
100572 + {
100573 + case 5:
100574 + CipherAlg = CIPHER_WEP64;
100575 + break;
100576 + case 13:
100577 + CipherAlg = CIPHER_WEP128;
100578 + break;
100579 + default:
100580 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
100581 + Status = -EINVAL;
100582 + break;
100583 + }
100584 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
100585 +
100586 + // Default key for tx (shared key)
100587 + if (pWepKey->KeyIndex & 0x80000000)
100588 + {
100589 +#ifdef WPA_SUPPLICANT_SUPPORT
100590 + // set key material and key length
100591 + NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
100592 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
100593 + NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
100594 + pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
100595 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
100596 +#endif // WPA_SUPPLICANT_SUPPORT //
100597 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
100598 + }
100599 +
100600 +#ifdef WPA_SUPPLICANT_SUPPORT
100601 + if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
100602 +#endif // WPA_SUPPLICANT_SUPPORT
100603 + {
100604 + Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
100605 +
100606 + // Set key material and cipherAlg to Asic
100607 + AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
100608 +
100609 + if (pWepKey->KeyIndex & 0x80000000)
100610 + {
100611 + PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
100612 + // Assign group key info
100613 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
100614 + // Assign pairwise key info
100615 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
100616 + }
100617 + }
100618 + 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"));
100619 + }
100620 + }
100621 + kfree(pWepKey);
100622 + break;
100623 +#ifdef WPA_SUPPLICANT_SUPPORT
100624 + case OID_SET_COUNTERMEASURES:
100625 + if (wrq->u.data.length != sizeof(int))
100626 + Status = -EINVAL;
100627 + else
100628 + {
100629 + int enabled = 0;
100630 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
100631 + if (enabled == 1)
100632 + pAdapter->StaCfg.bBlockAssoc = TRUE;
100633 + else
100634 + // WPA MIC error should block association attempt for 60 seconds
100635 + pAdapter->StaCfg.bBlockAssoc = FALSE;
100636 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
100637 + }
100638 + break;
100639 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
100640 + if (wrq->u.data.length != sizeof(UCHAR))
100641 + Status = -EINVAL;
100642 + else
100643 + {
100644 + Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
100645 + pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
100646 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
100647 + }
100648 + break;
100649 + case OID_802_11_DEAUTHENTICATION:
100650 + if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
100651 + Status = -EINVAL;
100652 + else
100653 + {
100654 + MLME_DEAUTH_REQ_STRUCT *pInfo;
100655 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
100656 +
100657 + pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
100658 + Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
100659 + MlmeDeauthReqAction(pAdapter, MsgElem);
100660 + kfree(MsgElem);
100661 +
100662 + if (INFRA_ON(pAdapter))
100663 + {
100664 + LinkDown(pAdapter, FALSE);
100665 + pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
100666 + }
100667 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
100668 + }
100669 + break;
100670 + case OID_802_11_DROP_UNENCRYPTED:
100671 + if (wrq->u.data.length != sizeof(int))
100672 + Status = -EINVAL;
100673 + else
100674 + {
100675 + int enabled = 0;
100676 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
100677 + if (enabled == 1)
100678 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
100679 + else
100680 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
100681 + NdisAcquireSpinLock(&pAdapter->MacTabLock);
100682 + pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
100683 + NdisReleaseSpinLock(&pAdapter->MacTabLock);
100684 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
100685 + }
100686 + break;
100687 + case OID_802_11_SET_IEEE8021X:
100688 + if (wrq->u.data.length != sizeof(BOOLEAN))
100689 + Status = -EINVAL;
100690 + else
100691 + {
100692 + Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
100693 + pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
100694 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
100695 + }
100696 + break;
100697 + case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
100698 + if (wrq->u.data.length != sizeof(BOOLEAN))
100699 + Status = -EINVAL;
100700 + else
100701 + {
100702 + Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
100703 + pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
100704 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
100705 + }
100706 + break;
100707 + case OID_802_11_PMKID:
100708 + pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
100709 +
100710 + if(pPmkId == NULL) {
100711 + Status = -ENOMEM;
100712 + break;
100713 + }
100714 + Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
100715 +
100716 + // check the PMKID information
100717 + if (pPmkId->BSSIDInfoCount == 0)
100718 + NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
100719 + else
100720 + {
100721 + PBSSID_INFO pBssIdInfo;
100722 + UINT BssIdx;
100723 + UINT CachedIdx;
100724 +
100725 + for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
100726 + {
100727 + // point to the indexed BSSID_INFO structure
100728 + pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
100729 + // Find the entry in the saved data base.
100730 + for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
100731 + {
100732 + // compare the BSSID
100733 + if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
100734 + break;
100735 + }
100736 +
100737 + // Found, replace it
100738 + if (CachedIdx < PMKID_NO)
100739 + {
100740 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
100741 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
100742 + pAdapter->StaCfg.SavedPMKNum++;
100743 + }
100744 + // Not found, replace the last one
100745 + else
100746 + {
100747 + // Randomly replace one
100748 + CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
100749 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
100750 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
100751 + }
100752 + }
100753 + }
100754 + if(pPmkId)
100755 + kfree(pPmkId);
100756 + break;
100757 +#endif // WPA_SUPPLICANT_SUPPORT //
100758 +
100759 +
100760 +
100761 +#ifdef SNMP_SUPPORT
100762 + case OID_802_11_SHORTRETRYLIMIT:
100763 + if (wrq->u.data.length != sizeof(ULONG))
100764 + Status = -EINVAL;
100765 + else
100766 + {
100767 + Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
100768 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
100769 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
100770 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
100771 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
100772 + }
100773 + break;
100774 +
100775 + case OID_802_11_LONGRETRYLIMIT:
100776 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
100777 + if (wrq->u.data.length != sizeof(ULONG))
100778 + Status = -EINVAL;
100779 + else
100780 + {
100781 + Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
100782 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
100783 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
100784 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
100785 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
100786 + }
100787 + break;
100788 +
100789 + case OID_802_11_WEPDEFAULTKEYVALUE:
100790 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
100791 + pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
100792 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
100793 + //pKey = &WepKey;
100794 +
100795 + if ( pKey->Length != wrq->u.data.length)
100796 + {
100797 + Status = -EINVAL;
100798 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
100799 + }
100800 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
100801 + DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
100802 +
100803 + // it is a shared key
100804 + if (KeyIdx > 4)
100805 + Status = -EINVAL;
100806 + else
100807 + {
100808 + pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
100809 + NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
100810 + if (pKey->KeyIndex & 0x80000000)
100811 + {
100812 + // Default key for tx (shared key)
100813 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
100814 + }
100815 + //RestartAPIsRequired = TRUE;
100816 + }
100817 + break;
100818 +
100819 +
100820 + case OID_802_11_WEPDEFAULTKEYID:
100821 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
100822 +
100823 + if (wrq->u.data.length != sizeof(UCHAR))
100824 + Status = -EINVAL;
100825 + else
100826 + Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
100827 +
100828 + break;
100829 +
100830 +
100831 + case OID_802_11_CURRENTCHANNEL:
100832 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
100833 + if (wrq->u.data.length != sizeof(UCHAR))
100834 + Status = -EINVAL;
100835 + else
100836 + {
100837 + Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
100838 + sprintf(&ctmp,"%d", ctmp);
100839 + Set_Channel_Proc(pAdapter, &ctmp);
100840 + }
100841 + break;
100842 +#endif
100843 +
100844 +
100845 +
100846 + default:
100847 + DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
100848 + Status = -EOPNOTSUPP;
100849 + break;
100850 + }
100851 +
100852 +
100853 + return Status;
100854 +}
100855 +
100856 +INT RTMPQueryInformation(
100857 + IN PRTMP_ADAPTER pAdapter,
100858 + IN OUT struct ifreq *rq,
100859 + IN INT cmd)
100860 +{
100861 + struct iwreq *wrq = (struct iwreq *) rq;
100862 + NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
100863 + PNDIS_WLAN_BSSID_EX pBss;
100864 + NDIS_802_11_SSID Ssid;
100865 + NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
100866 + RT_802_11_LINK_STATUS *pLinkStatus = NULL;
100867 + RT_802_11_STA_CONFIG *pStaConfig = NULL;
100868 + NDIS_802_11_STATISTICS *pStatistics = NULL;
100869 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
100870 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
100871 + NDIS_802_11_POWER_MODE PowerMode;
100872 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
100873 + RT_802_11_PREAMBLE PreamType;
100874 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
100875 + NDIS_802_11_WEP_STATUS WepStatus;
100876 + NDIS_MEDIA_STATE MediaState;
100877 + ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
100878 + USHORT BssLen = 0;
100879 + PUCHAR pBuf = NULL, pPtr;
100880 + INT Status = NDIS_STATUS_SUCCESS;
100881 + UINT we_version_compiled;
100882 + UCHAR i, Padding = 0;
100883 + BOOLEAN RadioState;
100884 + UCHAR driverVersion[8];
100885 + OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
100886 +
100887 +
100888 +#ifdef SNMP_SUPPORT
100889 + //for snmp, kathy
100890 + DefaultKeyIdxValue *pKeyIdxValue;
100891 + INT valueLen;
100892 + TX_RTY_CFG_STRUC tx_rty_cfg;
100893 + ULONG ShortRetryLimit, LongRetryLimit;
100894 + UCHAR tmp[64];
100895 +#endif //SNMP
100896 +
100897 + switch(cmd)
100898 + {
100899 + case RT_OID_DEVICE_NAME:
100900 + wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
100901 + Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
100902 + break;
100903 + case RT_OID_VERSION_INFO:
100904 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
100905 + wrq->u.data.length = 8*sizeof(UCHAR);
100906 + sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
100907 + driverVersion[7] = '\0';
100908 + if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
100909 + {
100910 + Status = -EFAULT;
100911 + }
100912 + break;
100913 +#ifdef RALINK_ATE
100914 + case RT_QUERY_ATE_TXDONE_COUNT:
100915 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
100916 + wrq->u.data.length = sizeof(UINT32);
100917 + if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
100918 + {
100919 + Status = -EFAULT;
100920 + }
100921 + break;
100922 +#endif // RALINK_ATE //
100923 + case OID_802_11_BSSID_LIST:
100924 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
100925 + {
100926 + /*
100927 + * Still scanning, indicate the caller should try again.
100928 + */
100929 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
100930 + return -EAGAIN;
100931 + }
100932 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
100933 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
100934 + // Claculate total buffer size required
100935 + BssBufSize = sizeof(ULONG);
100936 +
100937 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
100938 + {
100939 + // Align pointer to 4 bytes boundary.
100940 + //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
100941 + //if (Padding == 4)
100942 + // Padding = 0;
100943 + BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
100944 + }
100945 +
100946 + // For safety issue, we add 256 bytes just in case
100947 + BssBufSize += 256;
100948 + // Allocate the same size as passed from higher layer
100949 + pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
100950 + if(pBuf == NULL)
100951 + {
100952 + Status = -ENOMEM;
100953 + break;
100954 + }
100955 + // Init 802_11_BSSID_LIST_EX structure
100956 + NdisZeroMemory(pBuf, BssBufSize);
100957 + pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
100958 + pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
100959 +
100960 + // Calculate total buffer length
100961 + BssLen = 4; // Consist of NumberOfItems
100962 + // Point to start of NDIS_WLAN_BSSID_EX
100963 + // pPtr = pBuf + sizeof(ULONG);
100964 + pPtr = (PUCHAR) &pBssidList->Bssid[0];
100965 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
100966 + {
100967 + pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
100968 + NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
100969 + if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
100970 + {
100971 + //
100972 + // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
100973 + // and then failed to send EAPOl farame.
100974 + //
100975 + if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
100976 + {
100977 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
100978 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
100979 + }
100980 + else
100981 + pBss->Ssid.SsidLength = 0;
100982 + }
100983 + else
100984 + {
100985 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
100986 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
100987 + }
100988 + pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
100989 + pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
100990 + pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
100991 + pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
100992 + pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
100993 + pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
100994 +
100995 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
100996 +
100997 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
100998 + pBss->InfrastructureMode = Ndis802_11Infrastructure;
100999 + else
101000 + pBss->InfrastructureMode = Ndis802_11IBSS;
101001 +
101002 + NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
101003 + NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
101004 + pAdapter->ScanTab.BssEntry[i].ExtRate,
101005 + pAdapter->ScanTab.BssEntry[i].ExtRateLen);
101006 +
101007 + if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
101008 + {
101009 + pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
101010 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
101011 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
101012 + }
101013 + else
101014 + {
101015 + pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
101016 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
101017 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
101018 + NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
101019 + pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
101020 + }
101021 + pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
101022 +
101023 +#if WIRELESS_EXT < 17
101024 + if ((BssLen + pBss->Length) < wrq->u.data.length)
101025 + BssLen += pBss->Length;
101026 + else
101027 + {
101028 + pBssidList->NumberOfItems = i;
101029 + break;
101030 + }
101031 +#else
101032 + BssLen += pBss->Length;
101033 +#endif
101034 + }
101035 +
101036 +#if WIRELESS_EXT < 17
101037 + wrq->u.data.length = BssLen;
101038 +#else
101039 + if (BssLen > wrq->u.data.length)
101040 + {
101041 + kfree(pBssidList);
101042 + return -E2BIG;
101043 + }
101044 + else
101045 + wrq->u.data.length = BssLen;
101046 +#endif
101047 + Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
101048 + kfree(pBssidList);
101049 + break;
101050 + case OID_802_3_CURRENT_ADDRESS:
101051 + wrq->u.data.length = MAC_ADDR_LEN;
101052 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
101053 + break;
101054 + case OID_GEN_MEDIA_CONNECT_STATUS:
101055 + if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
101056 + MediaState = NdisMediaStateConnected;
101057 + else
101058 + MediaState = NdisMediaStateDisconnected;
101059 +
101060 + wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
101061 + Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
101062 + break;
101063 + case OID_802_11_BSSID:
101064 +#ifdef RALINK_ATE
101065 + if (ATE_ON(pAdapter))
101066 + {
101067 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
101068 + Status = NDIS_STATUS_RESOURCES;
101069 + break;
101070 + }
101071 +#endif // RALINK_ATE //
101072 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
101073 + {
101074 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
101075 +
101076 + }
101077 + else
101078 + {
101079 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
101080 + Status = -ENOTCONN;
101081 + }
101082 + break;
101083 + case OID_802_11_SSID:
101084 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
101085 + NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
101086 + Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
101087 + memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
101088 + wrq->u.data.length = sizeof(NDIS_802_11_SSID);
101089 + Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
101090 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
101091 + break;
101092 + case RT_OID_802_11_QUERY_LINK_STATUS:
101093 + pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
101094 + if (pLinkStatus)
101095 + {
101096 + pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
101097 + pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
101098 + pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
101099 + pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
101100 + pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
101101 + wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
101102 + Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
101103 + kfree(pLinkStatus);
101104 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
101105 + }
101106 + else
101107 + {
101108 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
101109 + Status = -EFAULT;
101110 + }
101111 + break;
101112 + case OID_802_11_CONFIGURATION:
101113 + pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
101114 + if (pConfiguration)
101115 + {
101116 + pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
101117 + pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
101118 + pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
101119 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
101120 + wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
101121 + Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
101122 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
101123 + pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
101124 + kfree(pConfiguration);
101125 + }
101126 + else
101127 + {
101128 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
101129 + Status = -EFAULT;
101130 + }
101131 + break;
101132 + case RT_OID_802_11_SNR_0:
101133 + if ((pAdapter->StaCfg.LastSNR0 > 0))
101134 + {
101135 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
101136 + wrq->u.data.length = sizeof(ulInfo);
101137 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101138 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
101139 + }
101140 + else
101141 + Status = -EFAULT;
101142 + break;
101143 + case RT_OID_802_11_SNR_1:
101144 + if ((pAdapter->Antenna.field.RxPath > 1) &&
101145 + (pAdapter->StaCfg.LastSNR1 > 0))
101146 + {
101147 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
101148 + wrq->u.data.length = sizeof(ulInfo);
101149 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101150 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
101151 + }
101152 + else
101153 + Status = -EFAULT;
101154 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
101155 + break;
101156 + case OID_802_11_RSSI_TRIGGER:
101157 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
101158 + wrq->u.data.length = sizeof(ulInfo);
101159 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101160 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
101161 + break;
101162 + case OID_802_11_RSSI:
101163 + case RT_OID_802_11_RSSI:
101164 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
101165 + wrq->u.data.length = sizeof(ulInfo);
101166 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101167 + break;
101168 + case RT_OID_802_11_RSSI_1:
101169 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
101170 + wrq->u.data.length = sizeof(ulInfo);
101171 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101172 + break;
101173 + case RT_OID_802_11_RSSI_2:
101174 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
101175 + wrq->u.data.length = sizeof(ulInfo);
101176 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101177 + break;
101178 + case OID_802_11_STATISTICS:
101179 + pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
101180 + if (pStatistics)
101181 + {
101182 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
101183 + // add the most up-to-date h/w raw counters into software counters
101184 + NICUpdateRawCounters(pAdapter);
101185 +
101186 + // Sanity check for calculation of sucessful count
101187 + if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
101188 + pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
101189 +
101190 + pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
101191 + pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
101192 + pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
101193 + pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
101194 + pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
101195 + pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
101196 + pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
101197 + pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
101198 + pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
101199 + pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
101200 + pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
101201 +#ifdef DBG
101202 + pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
101203 +#else
101204 + pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
101205 + pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
101206 +#endif
101207 + wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
101208 + Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
101209 + kfree(pStatistics);
101210 + }
101211 + else
101212 + {
101213 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
101214 + Status = -EFAULT;
101215 + }
101216 + break;
101217 + case OID_GEN_RCV_OK:
101218 + ulInfo = pAdapter->Counters8023.GoodReceives;
101219 + wrq->u.data.length = sizeof(ulInfo);
101220 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101221 + break;
101222 + case OID_GEN_RCV_NO_BUFFER:
101223 + ulInfo = pAdapter->Counters8023.RxNoBuffer;
101224 + wrq->u.data.length = sizeof(ulInfo);
101225 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101226 + break;
101227 + case RT_OID_802_11_PHY_MODE:
101228 + ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
101229 + wrq->u.data.length = sizeof(ulInfo);
101230 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101231 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
101232 + break;
101233 + case RT_OID_802_11_STA_CONFIG:
101234 + pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
101235 + if (pStaConfig)
101236 + {
101237 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
101238 + pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
101239 + pStaConfig->EnableTurboRate = 0;
101240 + pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
101241 + pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
101242 + //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
101243 + pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
101244 + pStaConfig->Rsv1 = 0;
101245 + pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
101246 + wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
101247 + Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
101248 + kfree(pStaConfig);
101249 + }
101250 + else
101251 + {
101252 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
101253 + Status = -EFAULT;
101254 + }
101255 + break;
101256 + case OID_802_11_RTS_THRESHOLD:
101257 + RtsThresh = pAdapter->CommonCfg.RtsThreshold;
101258 + wrq->u.data.length = sizeof(RtsThresh);
101259 + Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
101260 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
101261 + break;
101262 + case OID_802_11_FRAGMENTATION_THRESHOLD:
101263 + FragThresh = pAdapter->CommonCfg.FragmentThreshold;
101264 + if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
101265 + FragThresh = 0;
101266 + wrq->u.data.length = sizeof(FragThresh);
101267 + Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
101268 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
101269 + break;
101270 + case OID_802_11_POWER_MODE:
101271 + PowerMode = pAdapter->StaCfg.WindowsPowerMode;
101272 + wrq->u.data.length = sizeof(PowerMode);
101273 + Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
101274 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
101275 + break;
101276 + case RT_OID_802_11_RADIO:
101277 + RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
101278 + wrq->u.data.length = sizeof(RadioState);
101279 + Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
101280 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
101281 + break;
101282 + case OID_802_11_INFRASTRUCTURE_MODE:
101283 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
101284 + BssType = Ndis802_11IBSS;
101285 + else if (pAdapter->StaCfg.BssType == BSS_INFRA)
101286 + BssType = Ndis802_11Infrastructure;
101287 + else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
101288 + BssType = Ndis802_11Monitor;
101289 + else
101290 + BssType = Ndis802_11AutoUnknown;
101291 +
101292 + wrq->u.data.length = sizeof(BssType);
101293 + Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
101294 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
101295 + break;
101296 + case RT_OID_802_11_PREAMBLE:
101297 + PreamType = pAdapter->CommonCfg.TxPreamble;
101298 + wrq->u.data.length = sizeof(PreamType);
101299 + Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
101300 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
101301 + break;
101302 + case OID_802_11_AUTHENTICATION_MODE:
101303 + AuthMode = pAdapter->StaCfg.AuthMode;
101304 + wrq->u.data.length = sizeof(AuthMode);
101305 + Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
101306 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
101307 + break;
101308 + case OID_802_11_WEP_STATUS:
101309 + WepStatus = pAdapter->StaCfg.WepStatus;
101310 + wrq->u.data.length = sizeof(WepStatus);
101311 + Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
101312 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
101313 + break;
101314 + case OID_802_11_TX_POWER_LEVEL:
101315 + wrq->u.data.length = sizeof(ULONG);
101316 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
101317 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
101318 + break;
101319 + case RT_OID_802_11_TX_POWER_LEVEL_1:
101320 + wrq->u.data.length = sizeof(ULONG);
101321 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
101322 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
101323 + break;
101324 + case OID_802_11_NETWORK_TYPES_SUPPORTED:
101325 + if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
101326 + {
101327 + NetworkTypeList[0] = 3; // NumberOfItems = 3
101328 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
101329 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
101330 + NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
101331 + wrq->u.data.length = 16;
101332 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
101333 + }
101334 + else
101335 + {
101336 + NetworkTypeList[0] = 2; // NumberOfItems = 2
101337 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
101338 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
101339 + wrq->u.data.length = 12;
101340 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
101341 + }
101342 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
101343 + break;
101344 + case OID_802_11_NETWORK_TYPE_IN_USE:
101345 + wrq->u.data.length = sizeof(ULONG);
101346 + if (pAdapter->CommonCfg.PhyMode == PHY_11A)
101347 + ulInfo = Ndis802_11OFDM5;
101348 + else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
101349 + ulInfo = Ndis802_11OFDM24;
101350 + else
101351 + ulInfo = Ndis802_11DS;
101352 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101353 + break;
101354 + case RT_OID_802_11_QUERY_LAST_RX_RATE:
101355 + ulInfo = (ULONG)pAdapter->LastRxRate;
101356 + wrq->u.data.length = sizeof(ulInfo);
101357 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101358 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
101359 + break;
101360 + case RT_OID_802_11_QUERY_LAST_TX_RATE:
101361 + //ulInfo = (ULONG)pAdapter->LastTxRate;
101362 + ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
101363 + wrq->u.data.length = sizeof(ulInfo);
101364 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101365 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
101366 + break;
101367 + case RT_OID_802_11_QUERY_EEPROM_VERSION:
101368 + wrq->u.data.length = sizeof(ULONG);
101369 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
101370 + break;
101371 + case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
101372 + wrq->u.data.length = sizeof(ULONG);
101373 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
101374 + break;
101375 + case RT_OID_802_11_QUERY_NOISE_LEVEL:
101376 + wrq->u.data.length = sizeof(UCHAR);
101377 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
101378 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
101379 + break;
101380 + case RT_OID_802_11_EXTRA_INFO:
101381 + wrq->u.data.length = sizeof(ULONG);
101382 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
101383 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
101384 + break;
101385 + case RT_OID_WE_VERSION_COMPILED:
101386 + wrq->u.data.length = sizeof(UINT);
101387 + we_version_compiled = WIRELESS_EXT;
101388 + Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
101389 + break;
101390 + case RT_OID_802_11_QUERY_APSD_SETTING:
101391 + apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
101392 + | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
101393 +
101394 + wrq->u.data.length = sizeof(ULONG);
101395 + Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
101396 + 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",
101397 + apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
101398 + break;
101399 + case RT_OID_802_11_QUERY_APSD_PSM:
101400 + wrq->u.data.length = sizeof(ULONG);
101401 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
101402 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
101403 + break;
101404 + case RT_OID_802_11_QUERY_WMM:
101405 + wrq->u.data.length = sizeof(BOOLEAN);
101406 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
101407 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
101408 + break;
101409 +#ifdef WPA_SUPPLICANT_SUPPORT
101410 + case RT_OID_NEW_DRIVER:
101411 + {
101412 + UCHAR enabled = 1;
101413 + wrq->u.data.length = sizeof(UCHAR);
101414 + Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
101415 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
101416 + }
101417 + break;
101418 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
101419 + wrq->u.data.length = sizeof(UCHAR);
101420 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
101421 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
101422 + break;
101423 +#endif // WPA_SUPPLICANT_SUPPORT //
101424 +
101425 + case RT_OID_DRIVER_DEVICE_NAME:
101426 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
101427 + wrq->u.data.length = 16;
101428 + if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
101429 + {
101430 + Status = -EFAULT;
101431 + }
101432 + break;
101433 + case RT_OID_802_11_QUERY_HT_PHYMODE:
101434 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
101435 + if (pHTPhyMode)
101436 + {
101437 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
101438 + pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
101439 + pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
101440 + pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
101441 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
101442 + pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
101443 +
101444 + pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
101445 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
101446 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
101447 + {
101448 + Status = -EFAULT;
101449 + }
101450 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
101451 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
101452 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
101453 + }
101454 + else
101455 + {
101456 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
101457 + Status = -EFAULT;
101458 + }
101459 + break;
101460 + case RT_OID_802_11_COUNTRY_REGION:
101461 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
101462 + wrq->u.data.length = sizeof(ulInfo);
101463 + ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
101464 + ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
101465 + if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
101466 + {
101467 + Status = -EFAULT;
101468 + }
101469 + break;
101470 + case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
101471 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
101472 + if (pHTPhyMode)
101473 + {
101474 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
101475 + pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
101476 + pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
101477 + pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
101478 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
101479 + pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
101480 +
101481 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
101482 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
101483 + {
101484 + Status = -EFAULT;
101485 + }
101486 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
101487 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
101488 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
101489 + }
101490 + else
101491 + {
101492 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
101493 + Status = -EFAULT;
101494 + }
101495 + break;
101496 + case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
101497 + wrq->u.data.length = sizeof(UCHAR);
101498 + i = 0;
101499 +#ifdef MULTIPLE_CARD_SUPPORT
101500 + i = 1;
101501 +#endif // MULTIPLE_CARD_SUPPORT //
101502 + if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
101503 + {
101504 + Status = -EFAULT;
101505 + }
101506 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
101507 + break;
101508 +#ifdef SNMP_SUPPORT
101509 + case RT_OID_802_11_MAC_ADDRESS:
101510 + wrq->u.data.length = MAC_ADDR_LEN;
101511 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
101512 + break;
101513 +
101514 + case RT_OID_802_11_MANUFACTUREROUI:
101515 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
101516 + wrq->u.data.length = ManufacturerOUI_LEN;
101517 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
101518 + break;
101519 +
101520 + case RT_OID_802_11_MANUFACTURERNAME:
101521 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
101522 + wrq->u.data.length = strlen(ManufacturerNAME);
101523 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
101524 + break;
101525 +
101526 + case RT_OID_802_11_RESOURCETYPEIDNAME:
101527 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
101528 + wrq->u.data.length = strlen(ResourceTypeIdName);
101529 + Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
101530 + break;
101531 +
101532 + case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
101533 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
101534 + ulInfo = 1; // 1 is support wep else 2 is not support.
101535 + wrq->u.data.length = sizeof(ulInfo);
101536 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101537 + break;
101538 +
101539 + case RT_OID_802_11_POWERMANAGEMENTMODE:
101540 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
101541 + if (pAdapter->StaCfg.Psm == PSMP_ACTION)
101542 + ulInfo = 1; // 1 is power active else 2 is power save.
101543 + else
101544 + ulInfo = 2;
101545 +
101546 + wrq->u.data.length = sizeof(ulInfo);
101547 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
101548 + break;
101549 +
101550 + case OID_802_11_WEPDEFAULTKEYVALUE:
101551 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
101552 + //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
101553 + pKeyIdxValue = wrq->u.data.pointer;
101554 + DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
101555 + valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
101556 + NdisMoveMemory(pKeyIdxValue->Value,
101557 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
101558 + valueLen);
101559 + pKeyIdxValue->Value[valueLen]='\0';
101560 +
101561 + wrq->u.data.length = sizeof(DefaultKeyIdxValue);
101562 +
101563 + Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
101564 + 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,
101565 + pAdapter->SharedKey[BSS0][0].Key[0],
101566 + pAdapter->SharedKey[BSS0][1].Key[0],
101567 + pAdapter->SharedKey[BSS0][2].Key[0],
101568 + pAdapter->SharedKey[BSS0][3].Key[0]));
101569 + break;
101570 +
101571 + case OID_802_11_WEPDEFAULTKEYID:
101572 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
101573 + wrq->u.data.length = sizeof(UCHAR);
101574 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
101575 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
101576 + break;
101577 +
101578 + case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
101579 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
101580 + wrq->u.data.length = sizeof(UCHAR);
101581 + Status = copy_to_user(wrq->u.data.pointer,
101582 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
101583 + wrq->u.data.length);
101584 + break;
101585 +
101586 + case OID_802_11_SHORTRETRYLIMIT:
101587 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
101588 + wrq->u.data.length = sizeof(ULONG);
101589 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
101590 + ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
101591 + DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
101592 + Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
101593 + break;
101594 +
101595 + case OID_802_11_LONGRETRYLIMIT:
101596 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
101597 + wrq->u.data.length = sizeof(ULONG);
101598 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
101599 + LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
101600 + DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
101601 + Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
101602 + break;
101603 +
101604 + case RT_OID_802_11_PRODUCTID:
101605 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
101606 +
101607 +#ifdef RT2870
101608 + sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
101609 +
101610 +#endif // RT2870 //
101611 + wrq->u.data.length = strlen(tmp);
101612 + Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
101613 + break;
101614 +
101615 + case RT_OID_802_11_MANUFACTUREID:
101616 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
101617 + wrq->u.data.length = strlen(ManufacturerNAME);
101618 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
101619 + break;
101620 +
101621 + case OID_802_11_CURRENTCHANNEL:
101622 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
101623 + wrq->u.data.length = sizeof(UCHAR);
101624 + DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
101625 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
101626 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
101627 + break;
101628 +#endif //SNMP_SUPPORT
101629 +
101630 + case OID_802_11_BUILD_CHANNEL_EX:
101631 + {
101632 + UCHAR value;
101633 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
101634 + wrq->u.data.length = sizeof(UCHAR);
101635 +#ifdef EXT_BUILD_CHANNEL_LIST
101636 + DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
101637 + value = 1;
101638 +#else
101639 + DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
101640 + value = 0;
101641 +#endif // EXT_BUILD_CHANNEL_LIST //
101642 + Status = copy_to_user(wrq->u.data.pointer, &value, 1);
101643 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
101644 + }
101645 + break;
101646 +
101647 + case OID_802_11_GET_CH_LIST:
101648 + {
101649 + PRT_CHANNEL_LIST_INFO pChListBuf;
101650 +
101651 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
101652 + if (pAdapter->ChannelListNum == 0)
101653 + {
101654 + wrq->u.data.length = 0;
101655 + break;
101656 + }
101657 +
101658 + pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
101659 + if (pChListBuf == NULL)
101660 + {
101661 + wrq->u.data.length = 0;
101662 + break;
101663 + }
101664 +
101665 + pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
101666 + for (i = 0; i < pChListBuf->ChannelListNum; i++)
101667 + pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
101668 +
101669 + wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
101670 + Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
101671 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
101672 +
101673 + if (pChListBuf)
101674 + kfree(pChListBuf);
101675 + }
101676 + break;
101677 +
101678 + case OID_802_11_GET_COUNTRY_CODE:
101679 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
101680 + wrq->u.data.length = 2;
101681 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
101682 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
101683 + break;
101684 +
101685 + case OID_802_11_GET_CHANNEL_GEOGRAPHY:
101686 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
101687 + wrq->u.data.length = 1;
101688 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
101689 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
101690 + break;
101691 +
101692 +
101693 +#ifdef QOS_DLS_SUPPORT
101694 + case RT_OID_802_11_QUERY_DLS:
101695 + wrq->u.data.length = sizeof(BOOLEAN);
101696 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
101697 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
101698 + break;
101699 +
101700 + case RT_OID_802_11_QUERY_DLS_PARAM:
101701 + {
101702 + PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
101703 + if (pDlsInfo == NULL)
101704 + break;
101705 +
101706 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
101707 + {
101708 + RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
101709 + }
101710 +
101711 + pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
101712 + wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
101713 + Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
101714 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
101715 +
101716 + if (pDlsInfo)
101717 + kfree(pDlsInfo);
101718 + }
101719 + break;
101720 +#endif // QOS_DLS_SUPPORT //
101721 + default:
101722 + DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
101723 + Status = -EOPNOTSUPP;
101724 + break;
101725 + }
101726 + return Status;
101727 +}
101728 +
101729 +INT rt28xx_sta_ioctl(
101730 + IN struct net_device *net_dev,
101731 + IN OUT struct ifreq *rq,
101732 + IN INT cmd)
101733 +{
101734 + POS_COOKIE pObj;
101735 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
101736 + RTMP_ADAPTER *pAd = NULL;
101737 + struct iwreq *wrq = (struct iwreq *) rq;
101738 + BOOLEAN StateMachineTouched = FALSE;
101739 + INT Status = NDIS_STATUS_SUCCESS;
101740 + USHORT subcmd;
101741 +
101742 + if (net_dev->priv_flags == INT_MAIN)
101743 + {
101744 + pAd = net_dev->priv;
101745 + }
101746 + else
101747 + {
101748 + pVirtualAd = net_dev->priv;
101749 + pAd = pVirtualAd->RtmpDev->priv;
101750 + }
101751 + pObj = (POS_COOKIE) pAd->OS_Cookie;
101752 +
101753 + if (pAd == NULL)
101754 + {
101755 + /* if 1st open fail, pAd will be free;
101756 + So the net_dev->priv will be NULL in 2rd open */
101757 + return -ENETDOWN;
101758 + }
101759 +
101760 + //check if the interface is down
101761 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
101762 + {
101763 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
101764 + if (wrq->u.data.pointer == NULL)
101765 + {
101766 + return Status;
101767 + }
101768 +
101769 + if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
101770 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
101771 + {
101772 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
101773 + return -ENETDOWN;
101774 + }
101775 + }
101776 +
101777 + { // determine this ioctl command is comming from which interface.
101778 + pObj->ioctl_if_type = INT_MAIN;
101779 + pObj->ioctl_if = MAIN_MBSSID;
101780 + }
101781 +
101782 + switch(cmd)
101783 + {
101784 +#ifdef RALINK_ATE
101785 +#ifdef RALINK_28xx_QA
101786 + case RTPRIV_IOCTL_ATE:
101787 + {
101788 + RtmpDoAte(pAd, wrq);
101789 + }
101790 + break;
101791 +#endif // RALINK_28xx_QA //
101792 +#endif // RALINK_ATE //
101793 + case SIOCGIFHWADDR:
101794 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
101795 + memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
101796 + break;
101797 + case SIOCGIWNAME:
101798 + {
101799 + char *name=&wrq->u.name[0];
101800 + rt_ioctl_giwname(net_dev, NULL, name, NULL);
101801 + break;
101802 + }
101803 + case SIOCGIWESSID: //Get ESSID
101804 + {
101805 + struct iw_point *essid=&wrq->u.essid;
101806 + rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
101807 + break;
101808 + }
101809 + case SIOCSIWESSID: //Set ESSID
101810 + {
101811 + struct iw_point *essid=&wrq->u.essid;
101812 + rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
101813 + break;
101814 + }
101815 + case SIOCSIWNWID: // set network id (the cell)
101816 + case SIOCGIWNWID: // get network id
101817 + Status = -EOPNOTSUPP;
101818 + break;
101819 + case SIOCSIWFREQ: //set channel/frequency (Hz)
101820 + {
101821 + struct iw_freq *freq=&wrq->u.freq;
101822 + rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
101823 + break;
101824 + }
101825 + case SIOCGIWFREQ: // get channel/frequency (Hz)
101826 + {
101827 + struct iw_freq *freq=&wrq->u.freq;
101828 + rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
101829 + break;
101830 + }
101831 + case SIOCSIWNICKN: //set node name/nickname
101832 + {
101833 + struct iw_point *data=&wrq->u.data;
101834 + rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
101835 + break;
101836 + }
101837 + case SIOCGIWNICKN: //get node name/nickname
101838 + {
101839 + struct iw_point *data=&wrq->u.data;
101840 + rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
101841 + break;
101842 + }
101843 + case SIOCGIWRATE: //get default bit rate (bps)
101844 + rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
101845 + break;
101846 + case SIOCSIWRATE: //set default bit rate (bps)
101847 + rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
101848 + break;
101849 + case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
101850 + {
101851 + struct iw_param *rts=&wrq->u.rts;
101852 + rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
101853 + break;
101854 + }
101855 + case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
101856 + {
101857 + struct iw_param *rts=&wrq->u.rts;
101858 + rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
101859 + break;
101860 + }
101861 + case SIOCGIWFRAG: //get fragmentation thr (bytes)
101862 + {
101863 + struct iw_param *frag=&wrq->u.frag;
101864 + rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
101865 + break;
101866 + }
101867 + case SIOCSIWFRAG: //set fragmentation thr (bytes)
101868 + {
101869 + struct iw_param *frag=&wrq->u.frag;
101870 + rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
101871 + break;
101872 + }
101873 + case SIOCGIWENCODE: //get encoding token & mode
101874 + {
101875 + struct iw_point *erq=&wrq->u.encoding;
101876 + if(erq->pointer)
101877 + rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
101878 + break;
101879 + }
101880 + case SIOCSIWENCODE: //set encoding token & mode
101881 + {
101882 + struct iw_point *erq=&wrq->u.encoding;
101883 + if(erq->pointer)
101884 + rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
101885 + break;
101886 + }
101887 + case SIOCGIWAP: //get access point MAC addresses
101888 + {
101889 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
101890 + rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
101891 + break;
101892 + }
101893 + case SIOCSIWAP: //set access point MAC addresses
101894 + {
101895 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
101896 + rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
101897 + break;
101898 + }
101899 + case SIOCGIWMODE: //get operation mode
101900 + {
101901 + __u32 *mode=&wrq->u.mode;
101902 + rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
101903 + break;
101904 + }
101905 + case SIOCSIWMODE: //set operation mode
101906 + {
101907 + __u32 *mode=&wrq->u.mode;
101908 + rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
101909 + break;
101910 + }
101911 + case SIOCGIWSENS: //get sensitivity (dBm)
101912 + case SIOCSIWSENS: //set sensitivity (dBm)
101913 + case SIOCGIWPOWER: //get Power Management settings
101914 + case SIOCSIWPOWER: //set Power Management settings
101915 + case SIOCGIWTXPOW: //get transmit power (dBm)
101916 + case SIOCSIWTXPOW: //set transmit power (dBm)
101917 + case SIOCGIWRANGE: //Get range of parameters
101918 + case SIOCGIWRETRY: //get retry limits and lifetime
101919 + case SIOCSIWRETRY: //set retry limits and lifetime
101920 + Status = -EOPNOTSUPP;
101921 + break;
101922 + case RT_PRIV_IOCTL:
101923 + subcmd = wrq->u.data.flags;
101924 + if( subcmd & OID_GET_SET_TOGGLE)
101925 + Status = RTMPSetInformation(pAd, rq, subcmd);
101926 + else
101927 + Status = RTMPQueryInformation(pAd, rq, subcmd);
101928 + break;
101929 + case SIOCGIWPRIV:
101930 + if (wrq->u.data.pointer)
101931 + {
101932 + if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
101933 + break;
101934 + wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
101935 + if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
101936 + Status = -EFAULT;
101937 + }
101938 + break;
101939 + case RTPRIV_IOCTL_SET:
101940 + if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
101941 + break;
101942 + rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
101943 + break;
101944 + case RTPRIV_IOCTL_GSITESURVEY:
101945 + RTMPIoctlGetSiteSurvey(pAd, wrq);
101946 + break;
101947 +#ifdef DBG
101948 + case RTPRIV_IOCTL_MAC:
101949 + RTMPIoctlMAC(pAd, wrq);
101950 + break;
101951 + case RTPRIV_IOCTL_E2P:
101952 + RTMPIoctlE2PROM(pAd, wrq);
101953 + break;
101954 +#endif // DBG //
101955 + case SIOCETHTOOL:
101956 + break;
101957 + default:
101958 + DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
101959 + Status = -EOPNOTSUPP;
101960 + break;
101961 + }
101962 +
101963 + if(StateMachineTouched) // Upper layer sent a MLME-related operations
101964 + RT28XX_MLME_HANDLER(pAd);
101965 +
101966 + return Status;
101967 +}
101968 +
101969 +/*
101970 + ==========================================================================
101971 + Description:
101972 + Set SSID
101973 + Return:
101974 + TRUE if all parameters are OK, FALSE otherwise
101975 + ==========================================================================
101976 +*/
101977 +INT Set_SSID_Proc(
101978 + IN PRTMP_ADAPTER pAdapter,
101979 + IN PUCHAR arg)
101980 +{
101981 + NDIS_802_11_SSID Ssid, *pSsid=NULL;
101982 + BOOLEAN StateMachineTouched = FALSE;
101983 + int success = TRUE;
101984 +
101985 + if( strlen(arg) <= MAX_LEN_OF_SSID)
101986 + {
101987 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
101988 + if (strlen(arg) != 0)
101989 + {
101990 + NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
101991 + Ssid.SsidLength = strlen(arg);
101992 + }
101993 + else //ANY ssid
101994 + {
101995 + Ssid.SsidLength = 0;
101996 + memcpy(Ssid.Ssid, "", 0);
101997 + pAdapter->StaCfg.BssType = BSS_INFRA;
101998 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
101999 + pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
102000 + }
102001 + pSsid = &Ssid;
102002 +
102003 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
102004 + {
102005 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
102006 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
102007 + }
102008 +
102009 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
102010 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
102011 + pAdapter->bConfigChanged = TRUE;
102012 +
102013 + MlmeEnqueue(pAdapter,
102014 + MLME_CNTL_STATE_MACHINE,
102015 + OID_802_11_SSID,
102016 + sizeof(NDIS_802_11_SSID),
102017 + (VOID *)pSsid);
102018 +
102019 + StateMachineTouched = TRUE;
102020 + DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
102021 + }
102022 + else
102023 + success = FALSE;
102024 +
102025 + if (StateMachineTouched) // Upper layer sent a MLME-related operations
102026 + RT28XX_MLME_HANDLER(pAdapter);
102027 +
102028 + return success;
102029 +}
102030 +
102031 +#ifdef WMM_SUPPORT
102032 +/*
102033 + ==========================================================================
102034 + Description:
102035 + Set WmmCapable Enable or Disable
102036 + Return:
102037 + TRUE if all parameters are OK, FALSE otherwise
102038 + ==========================================================================
102039 +*/
102040 +INT Set_WmmCapable_Proc(
102041 + IN PRTMP_ADAPTER pAd,
102042 + IN PUCHAR arg)
102043 +{
102044 + BOOLEAN bWmmCapable;
102045 +
102046 + bWmmCapable = simple_strtol(arg, 0, 10);
102047 +
102048 + if ((bWmmCapable == 1)
102049 +#ifdef RT2870
102050 + && (pAd->NumberOfPipes >= 5)
102051 +#endif // RT2870 //
102052 + )
102053 + pAd->CommonCfg.bWmmCapable = TRUE;
102054 + else if (bWmmCapable == 0)
102055 + pAd->CommonCfg.bWmmCapable = FALSE;
102056 + else
102057 + return FALSE; //Invalid argument
102058 +
102059 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
102060 + pAd->CommonCfg.bWmmCapable));
102061 +
102062 + return TRUE;
102063 +}
102064 +#endif // WMM_SUPPORT //
102065 +
102066 +/*
102067 + ==========================================================================
102068 + Description:
102069 + Set Network Type(Infrastructure/Adhoc mode)
102070 + Return:
102071 + TRUE if all parameters are OK, FALSE otherwise
102072 + ==========================================================================
102073 +*/
102074 +INT Set_NetworkType_Proc(
102075 + IN PRTMP_ADAPTER pAdapter,
102076 + IN PUCHAR arg)
102077 +{
102078 + UINT32 Value = 0;
102079 +
102080 + if (strcmp(arg, "Adhoc") == 0)
102081 + {
102082 + if (pAdapter->StaCfg.BssType != BSS_ADHOC)
102083 + {
102084 + // Config has changed
102085 + pAdapter->bConfigChanged = TRUE;
102086 + if (MONITOR_ON(pAdapter))
102087 + {
102088 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
102089 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
102090 + Value &= (~0x80);
102091 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
102092 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
102093 + pAdapter->StaCfg.bAutoReconnect = TRUE;
102094 + LinkDown(pAdapter, FALSE);
102095 + }
102096 + if (INFRA_ON(pAdapter))
102097 + {
102098 + //BOOLEAN Cancelled;
102099 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
102100 + // Since calling this indicate user don't want to connect to that SSID anymore.
102101 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
102102 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
102103 +
102104 + LinkDown(pAdapter, FALSE);
102105 +
102106 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
102107 + }
102108 + }
102109 + pAdapter->StaCfg.BssType = BSS_ADHOC;
102110 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
102111 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
102112 + }
102113 + else if (strcmp(arg, "Infra") == 0)
102114 + {
102115 + if (pAdapter->StaCfg.BssType != BSS_INFRA)
102116 + {
102117 + // Config has changed
102118 + pAdapter->bConfigChanged = TRUE;
102119 + if (MONITOR_ON(pAdapter))
102120 + {
102121 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
102122 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
102123 + Value &= (~0x80);
102124 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
102125 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
102126 + pAdapter->StaCfg.bAutoReconnect = TRUE;
102127 + LinkDown(pAdapter, FALSE);
102128 + }
102129 + if (ADHOC_ON(pAdapter))
102130 + {
102131 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
102132 + // Since calling this indicate user don't want to connect to that SSID anymore.
102133 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
102134 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
102135 +
102136 + LinkDown(pAdapter, FALSE);
102137 + }
102138 + }
102139 + pAdapter->StaCfg.BssType = BSS_INFRA;
102140 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
102141 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
102142 +
102143 + pAdapter->StaCfg.BssType = BSS_INFRA;
102144 + }
102145 + else if (strcmp(arg, "Monitor") == 0)
102146 + {
102147 + UCHAR bbpValue = 0;
102148 + BCN_TIME_CFG_STRUC csr;
102149 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
102150 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
102151 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
102152 + // disable all periodic state machine
102153 + pAdapter->StaCfg.bAutoReconnect = FALSE;
102154 + // reset all mlme state machine
102155 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
102156 + DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
102157 + if (pAdapter->CommonCfg.CentralChannel == 0)
102158 + {
102159 +#ifdef DOT11_N_SUPPORT
102160 + if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
102161 + pAdapter->CommonCfg.CentralChannel = 36;
102162 + else
102163 +#endif // DOT11_N_SUPPORT //
102164 + pAdapter->CommonCfg.CentralChannel = 6;
102165 + }
102166 +#ifdef DOT11_N_SUPPORT
102167 + else
102168 + N_ChannelCheck(pAdapter);
102169 +#endif // DOT11_N_SUPPORT //
102170 +
102171 +#ifdef DOT11_N_SUPPORT
102172 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
102173 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
102174 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
102175 + {
102176 + // 40MHz ,control channel at lower
102177 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
102178 + bbpValue &= (~0x18);
102179 + bbpValue |= 0x10;
102180 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
102181 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
102182 + // RX : control channel at lower
102183 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
102184 + bbpValue &= (~0x20);
102185 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
102186 +
102187 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
102188 + Value &= 0xfffffffe;
102189 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
102190 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
102191 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
102192 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
102193 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
102194 + pAdapter->CommonCfg.Channel,
102195 + pAdapter->CommonCfg.CentralChannel));
102196 + }
102197 + else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
102198 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
102199 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
102200 + {
102201 + // 40MHz ,control channel at upper
102202 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
102203 + bbpValue &= (~0x18);
102204 + bbpValue |= 0x10;
102205 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
102206 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
102207 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
102208 + Value |= 0x1;
102209 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
102210 +
102211 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
102212 + bbpValue |= (0x20);
102213 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
102214 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
102215 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
102216 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
102217 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
102218 + pAdapter->CommonCfg.Channel,
102219 + pAdapter->CommonCfg.CentralChannel));
102220 + }
102221 + else
102222 +#endif // DOT11_N_SUPPORT //
102223 + {
102224 + // 20MHz
102225 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
102226 + bbpValue &= (~0x18);
102227 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
102228 + pAdapter->CommonCfg.BBPCurrentBW = BW_20;
102229 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
102230 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
102231 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
102232 + }
102233 + // Enable Rx with promiscuous reception
102234 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
102235 + // ASIC supporsts sniffer function with replacing RSSI with timestamp.
102236 + //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
102237 + //Value |= (0x80);
102238 + //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
102239 + // disable sync
102240 + RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
102241 + csr.field.bBeaconGen = 0;
102242 + csr.field.bTBTTEnable = 0;
102243 + csr.field.TsfSyncMode = 0;
102244 + RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
102245 +
102246 + pAdapter->StaCfg.BssType = BSS_MONITOR;
102247 + pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
102248 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
102249 + }
102250 +
102251 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
102252 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
102253 +
102254 + DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
102255 +
102256 + return TRUE;
102257 +}
102258 +
102259 +/*
102260 + ==========================================================================
102261 + Description:
102262 + Set Authentication mode
102263 + Return:
102264 + TRUE if all parameters are OK, FALSE otherwise
102265 + ==========================================================================
102266 +*/
102267 +INT Set_AuthMode_Proc(
102268 + IN PRTMP_ADAPTER pAdapter,
102269 + IN PUCHAR arg)
102270 +{
102271 + if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
102272 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
102273 + else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
102274 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
102275 + else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
102276 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
102277 + else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
102278 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
102279 + else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
102280 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
102281 + else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
102282 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
102283 +#ifdef WPA_SUPPLICANT_SUPPORT
102284 + else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
102285 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
102286 + else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
102287 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
102288 +#endif // WPA_SUPPLICANT_SUPPORT //
102289 + else
102290 + return FALSE;
102291 +
102292 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
102293 +
102294 + DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
102295 +
102296 + return TRUE;
102297 +}
102298 +
102299 +/*
102300 + ==========================================================================
102301 + Description:
102302 + Set Encryption Type
102303 + Return:
102304 + TRUE if all parameters are OK, FALSE otherwise
102305 + ==========================================================================
102306 +*/
102307 +INT Set_EncrypType_Proc(
102308 + IN PRTMP_ADAPTER pAdapter,
102309 + IN PUCHAR arg)
102310 +{
102311 + if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
102312 + {
102313 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102314 + return TRUE; // do nothing
102315 +
102316 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
102317 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
102318 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
102319 + }
102320 + else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
102321 + {
102322 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102323 + return TRUE; // do nothing
102324 +
102325 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
102326 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
102327 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
102328 + }
102329 + else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
102330 + {
102331 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
102332 + return TRUE; // do nothing
102333 +
102334 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
102335 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
102336 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
102337 + }
102338 + else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
102339 + {
102340 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
102341 + return TRUE; // do nothing
102342 +
102343 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
102344 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
102345 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
102346 + }
102347 + else
102348 + return FALSE;
102349 +
102350 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
102351 +
102352 + DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
102353 +
102354 + return TRUE;
102355 +}
102356 +
102357 +/*
102358 + ==========================================================================
102359 + Description:
102360 + Set Default Key ID
102361 + Return:
102362 + TRUE if all parameters are OK, FALSE otherwise
102363 + ==========================================================================
102364 +*/
102365 +INT Set_DefaultKeyID_Proc(
102366 + IN PRTMP_ADAPTER pAdapter,
102367 + IN PUCHAR arg)
102368 +{
102369 + ULONG KeyIdx;
102370 +
102371 + KeyIdx = simple_strtol(arg, 0, 10);
102372 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
102373 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
102374 + else
102375 + return FALSE; //Invalid argument
102376 +
102377 + DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
102378 +
102379 + return TRUE;
102380 +}
102381 +
102382 +/*
102383 + ==========================================================================
102384 + Description:
102385 + Set WEP KEY1
102386 + Return:
102387 + TRUE if all parameters are OK, FALSE otherwise
102388 + ==========================================================================
102389 +*/
102390 +INT Set_Key1_Proc(
102391 + IN PRTMP_ADAPTER pAdapter,
102392 + IN PUCHAR arg)
102393 +{
102394 + int KeyLen;
102395 + int i;
102396 + UCHAR CipherAlg=CIPHER_WEP64;
102397 +
102398 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102399 + return TRUE; // do nothing
102400 +
102401 + KeyLen = strlen(arg);
102402 +
102403 + switch (KeyLen)
102404 + {
102405 + case 5: //wep 40 Ascii type
102406 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
102407 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
102408 + CipherAlg = CIPHER_WEP64;
102409 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
102410 + break;
102411 + case 10: //wep 40 Hex type
102412 + for(i=0; i < KeyLen; i++)
102413 + {
102414 + if( !isxdigit(*(arg+i)) )
102415 + return FALSE; //Not Hex value;
102416 + }
102417 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
102418 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
102419 + CipherAlg = CIPHER_WEP64;
102420 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
102421 + break;
102422 + case 13: //wep 104 Ascii type
102423 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
102424 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
102425 + CipherAlg = CIPHER_WEP128;
102426 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
102427 + break;
102428 + case 26: //wep 104 Hex type
102429 + for(i=0; i < KeyLen; i++)
102430 + {
102431 + if( !isxdigit(*(arg+i)) )
102432 + return FALSE; //Not Hex value;
102433 + }
102434 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
102435 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
102436 + CipherAlg = CIPHER_WEP128;
102437 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
102438 + break;
102439 + default: //Invalid argument
102440 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
102441 + return FALSE;
102442 + }
102443 +
102444 + pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
102445 +
102446 + // Set keys (into ASIC)
102447 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102448 + ; // not support
102449 + else // Old WEP stuff
102450 + {
102451 + AsicAddSharedKeyEntry(pAdapter,
102452 + 0,
102453 + 0,
102454 + pAdapter->SharedKey[BSS0][0].CipherAlg,
102455 + pAdapter->SharedKey[BSS0][0].Key,
102456 + NULL,
102457 + NULL);
102458 + }
102459 +
102460 + return TRUE;
102461 +}
102462 +/*
102463 + ==========================================================================
102464 +
102465 + Description:
102466 + Set WEP KEY2
102467 + Return:
102468 + TRUE if all parameters are OK, FALSE otherwise
102469 + ==========================================================================
102470 +*/
102471 +INT Set_Key2_Proc(
102472 + IN PRTMP_ADAPTER pAdapter,
102473 + IN PUCHAR arg)
102474 +{
102475 + int KeyLen;
102476 + int i;
102477 + UCHAR CipherAlg=CIPHER_WEP64;
102478 +
102479 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102480 + return TRUE; // do nothing
102481 +
102482 + KeyLen = strlen(arg);
102483 +
102484 + switch (KeyLen)
102485 + {
102486 + case 5: //wep 40 Ascii type
102487 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
102488 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
102489 + CipherAlg = CIPHER_WEP64;
102490 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
102491 + break;
102492 + case 10: //wep 40 Hex type
102493 + for(i=0; i < KeyLen; i++)
102494 + {
102495 + if( !isxdigit(*(arg+i)) )
102496 + return FALSE; //Not Hex value;
102497 + }
102498 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
102499 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
102500 + CipherAlg = CIPHER_WEP64;
102501 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
102502 + break;
102503 + case 13: //wep 104 Ascii type
102504 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
102505 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
102506 + CipherAlg = CIPHER_WEP128;
102507 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
102508 + break;
102509 + case 26: //wep 104 Hex type
102510 + for(i=0; i < KeyLen; i++)
102511 + {
102512 + if( !isxdigit(*(arg+i)) )
102513 + return FALSE; //Not Hex value;
102514 + }
102515 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
102516 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
102517 + CipherAlg = CIPHER_WEP128;
102518 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
102519 + break;
102520 + default: //Invalid argument
102521 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
102522 + return FALSE;
102523 + }
102524 + pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
102525 +
102526 + // Set keys (into ASIC)
102527 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102528 + ; // not support
102529 + else // Old WEP stuff
102530 + {
102531 + AsicAddSharedKeyEntry(pAdapter,
102532 + 0,
102533 + 1,
102534 + pAdapter->SharedKey[BSS0][1].CipherAlg,
102535 + pAdapter->SharedKey[BSS0][1].Key,
102536 + NULL,
102537 + NULL);
102538 + }
102539 +
102540 + return TRUE;
102541 +}
102542 +/*
102543 + ==========================================================================
102544 + Description:
102545 + Set WEP KEY3
102546 + Return:
102547 + TRUE if all parameters are OK, FALSE otherwise
102548 + ==========================================================================
102549 +*/
102550 +INT Set_Key3_Proc(
102551 + IN PRTMP_ADAPTER pAdapter,
102552 + IN PUCHAR arg)
102553 +{
102554 + int KeyLen;
102555 + int i;
102556 + UCHAR CipherAlg=CIPHER_WEP64;
102557 +
102558 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102559 + return TRUE; // do nothing
102560 +
102561 + KeyLen = strlen(arg);
102562 +
102563 + switch (KeyLen)
102564 + {
102565 + case 5: //wep 40 Ascii type
102566 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
102567 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
102568 + CipherAlg = CIPHER_WEP64;
102569 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
102570 + break;
102571 + case 10: //wep 40 Hex type
102572 + for(i=0; i < KeyLen; i++)
102573 + {
102574 + if( !isxdigit(*(arg+i)) )
102575 + return FALSE; //Not Hex value;
102576 + }
102577 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
102578 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
102579 + CipherAlg = CIPHER_WEP64;
102580 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
102581 + break;
102582 + case 13: //wep 104 Ascii type
102583 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
102584 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
102585 + CipherAlg = CIPHER_WEP128;
102586 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
102587 + break;
102588 + case 26: //wep 104 Hex type
102589 + for(i=0; i < KeyLen; i++)
102590 + {
102591 + if( !isxdigit(*(arg+i)) )
102592 + return FALSE; //Not Hex value;
102593 + }
102594 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
102595 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
102596 + CipherAlg = CIPHER_WEP128;
102597 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
102598 + break;
102599 + default: //Invalid argument
102600 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
102601 + return FALSE;
102602 + }
102603 + pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
102604 +
102605 + // Set keys (into ASIC)
102606 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102607 + ; // not support
102608 + else // Old WEP stuff
102609 + {
102610 + AsicAddSharedKeyEntry(pAdapter,
102611 + 0,
102612 + 2,
102613 + pAdapter->SharedKey[BSS0][2].CipherAlg,
102614 + pAdapter->SharedKey[BSS0][2].Key,
102615 + NULL,
102616 + NULL);
102617 + }
102618 +
102619 + return TRUE;
102620 +}
102621 +/*
102622 + ==========================================================================
102623 + Description:
102624 + Set WEP KEY4
102625 + Return:
102626 + TRUE if all parameters are OK, FALSE otherwise
102627 + ==========================================================================
102628 +*/
102629 +INT Set_Key4_Proc(
102630 + IN PRTMP_ADAPTER pAdapter,
102631 + IN PUCHAR arg)
102632 +{
102633 + int KeyLen;
102634 + int i;
102635 + UCHAR CipherAlg=CIPHER_WEP64;
102636 +
102637 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102638 + return TRUE; // do nothing
102639 +
102640 + KeyLen = strlen(arg);
102641 +
102642 + switch (KeyLen)
102643 + {
102644 + case 5: //wep 40 Ascii type
102645 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
102646 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
102647 + CipherAlg = CIPHER_WEP64;
102648 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
102649 + break;
102650 + case 10: //wep 40 Hex type
102651 + for(i=0; i < KeyLen; i++)
102652 + {
102653 + if( !isxdigit(*(arg+i)) )
102654 + return FALSE; //Not Hex value;
102655 + }
102656 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
102657 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
102658 + CipherAlg = CIPHER_WEP64;
102659 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
102660 + break;
102661 + case 13: //wep 104 Ascii type
102662 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
102663 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
102664 + CipherAlg = CIPHER_WEP128;
102665 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
102666 + break;
102667 + case 26: //wep 104 Hex type
102668 + for(i=0; i < KeyLen; i++)
102669 + {
102670 + if( !isxdigit(*(arg+i)) )
102671 + return FALSE; //Not Hex value;
102672 + }
102673 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
102674 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
102675 + CipherAlg = CIPHER_WEP128;
102676 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
102677 + break;
102678 + default: //Invalid argument
102679 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
102680 + return FALSE;
102681 + }
102682 + pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
102683 +
102684 + // Set keys (into ASIC)
102685 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
102686 + ; // not support
102687 + else // Old WEP stuff
102688 + {
102689 + AsicAddSharedKeyEntry(pAdapter,
102690 + 0,
102691 + 3,
102692 + pAdapter->SharedKey[BSS0][3].CipherAlg,
102693 + pAdapter->SharedKey[BSS0][3].Key,
102694 + NULL,
102695 + NULL);
102696 + }
102697 +
102698 + return TRUE;
102699 +}
102700 +
102701 +/*
102702 + ==========================================================================
102703 + Description:
102704 + Set WPA PSK key
102705 + Return:
102706 + TRUE if all parameters are OK, FALSE otherwise
102707 + ==========================================================================
102708 +*/
102709 +INT Set_WPAPSK_Proc(
102710 + IN PRTMP_ADAPTER pAdapter,
102711 + IN PUCHAR arg)
102712 +{
102713 + UCHAR keyMaterial[40];
102714 +
102715 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
102716 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
102717 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
102718 + )
102719 + return TRUE; // do nothing
102720 +
102721 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
102722 +
102723 + NdisZeroMemory(keyMaterial, 40);
102724 +
102725 + if ((strlen(arg) < 8) || (strlen(arg) > 64))
102726 + {
102727 + DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
102728 + return FALSE;
102729 + }
102730 +
102731 + if (strlen(arg) == 64)
102732 + {
102733 + AtoH(arg, keyMaterial, 32);
102734 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
102735 +
102736 + }
102737 + else
102738 + {
102739 + PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
102740 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
102741 + }
102742 +
102743 +
102744 +
102745 + if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
102746 + pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
102747 + {
102748 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
102749 + }
102750 + else
102751 + {
102752 + // Start STA supplicant state machine
102753 + pAdapter->StaCfg.WpaState = SS_START;
102754 + }
102755 +
102756 + return TRUE;
102757 +}
102758 +
102759 +/*
102760 + ==========================================================================
102761 + Description:
102762 + Set Power Saving mode
102763 + Return:
102764 + TRUE if all parameters are OK, FALSE otherwise
102765 + ==========================================================================
102766 +*/
102767 +INT Set_PSMode_Proc(
102768 + IN PRTMP_ADAPTER pAdapter,
102769 + IN PUCHAR arg)
102770 +{
102771 + if (pAdapter->StaCfg.BssType == BSS_INFRA)
102772 + {
102773 + if ((strcmp(arg, "Max_PSP") == 0) ||
102774 + (strcmp(arg, "max_psp") == 0) ||
102775 + (strcmp(arg, "MAX_PSP") == 0))
102776 + {
102777 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
102778 + // to exclude certain situations.
102779 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
102780 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
102781 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
102782 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
102783 + pAdapter->StaCfg.DefaultListenCount = 5;
102784 +
102785 + }
102786 + else if ((strcmp(arg, "Fast_PSP") == 0) ||
102787 + (strcmp(arg, "fast_psp") == 0) ||
102788 + (strcmp(arg, "FAST_PSP") == 0))
102789 + {
102790 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
102791 + // to exclude certain situations.
102792 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
102793 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
102794 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
102795 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
102796 + pAdapter->StaCfg.DefaultListenCount = 3;
102797 + }
102798 + else if ((strcmp(arg, "Legacy_PSP") == 0) ||
102799 + (strcmp(arg, "legacy_psp") == 0) ||
102800 + (strcmp(arg, "LEGACY_PSP") == 0))
102801 + {
102802 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
102803 + // to exclude certain situations.
102804 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
102805 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
102806 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
102807 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
102808 + pAdapter->StaCfg.DefaultListenCount = 3;
102809 + }
102810 + else
102811 + {
102812 + //Default Ndis802_11PowerModeCAM
102813 + // clear PSM bit immediately
102814 + MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
102815 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
102816 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
102817 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
102818 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
102819 + }
102820 +
102821 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
102822 + }
102823 + else
102824 + return FALSE;
102825 +
102826 +
102827 + return TRUE;
102828 +}
102829 +
102830 +#ifdef WPA_SUPPLICANT_SUPPORT
102831 +/*
102832 + ==========================================================================
102833 + Description:
102834 + Set WpaSupport flag.
102835 + Value:
102836 + 0: Driver ignore wpa_supplicant.
102837 + 1: wpa_supplicant initiates scanning and AP selection.
102838 + 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
102839 + Return:
102840 + TRUE if all parameters are OK, FALSE otherwise
102841 + ==========================================================================
102842 +*/
102843 +INT Set_Wpa_Support(
102844 + IN PRTMP_ADAPTER pAd,
102845 + IN PUCHAR arg)
102846 +{
102847 +
102848 + if ( simple_strtol(arg, 0, 10) == 0)
102849 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
102850 + else if ( simple_strtol(arg, 0, 10) == 1)
102851 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
102852 + else if ( simple_strtol(arg, 0, 10) == 2)
102853 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
102854 + else
102855 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
102856 +
102857 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
102858 +
102859 + return TRUE;
102860 +}
102861 +#endif // WPA_SUPPLICANT_SUPPORT //
102862 +
102863 +#ifdef DBG
102864 +/*
102865 + ==========================================================================
102866 + Description:
102867 + Read / Write MAC
102868 + Arguments:
102869 + pAdapter Pointer to our adapter
102870 + wrq Pointer to the ioctl argument
102871 +
102872 + Return Value:
102873 + None
102874 +
102875 + Note:
102876 + Usage:
102877 + 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
102878 + 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
102879 + ==========================================================================
102880 +*/
102881 +VOID RTMPIoctlMAC(
102882 + IN PRTMP_ADAPTER pAdapter,
102883 + IN struct iwreq *wrq)
102884 +{
102885 + CHAR *this_char;
102886 + CHAR *value;
102887 + INT j = 0, k = 0;
102888 + CHAR msg[1024];
102889 + CHAR arg[255];
102890 + ULONG macAddr = 0;
102891 + UCHAR temp[16], temp2[16];
102892 + UINT32 macValue = 0;
102893 + INT Status;
102894 +
102895 +
102896 + memset(msg, 0x00, 1024);
102897 + if (wrq->u.data.length > 1) //No parameters.
102898 + {
102899 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
102900 + sprintf(msg, "\n");
102901 +
102902 + //Parsing Read or Write
102903 + this_char = arg;
102904 + if (!*this_char)
102905 + goto next;
102906 +
102907 + if ((value = rtstrchr(this_char, '=')) != NULL)
102908 + *value++ = 0;
102909 +
102910 + if (!value || !*value)
102911 + { //Read
102912 + // Sanity check
102913 + if(strlen(this_char) > 4)
102914 + goto next;
102915 +
102916 + j = strlen(this_char);
102917 + while(j-- > 0)
102918 + {
102919 + if(this_char[j] > 'f' || this_char[j] < '0')
102920 + return;
102921 + }
102922 +
102923 + // Mac Addr
102924 + k = j = strlen(this_char);
102925 + while(j-- > 0)
102926 + {
102927 + this_char[4-k+j] = this_char[j];
102928 + }
102929 +
102930 + while(k < 4)
102931 + this_char[3-k++]='0';
102932 + this_char[4]='\0';
102933 +
102934 + if(strlen(this_char) == 4)
102935 + {
102936 + AtoH(this_char, temp, 2);
102937 + macAddr = *temp*256 + temp[1];
102938 + if (macAddr < 0xFFFF)
102939 + {
102940 + RTMP_IO_READ32(pAdapter, macAddr, &macValue);
102941 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
102942 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
102943 + }
102944 + else
102945 + {//Invalid parametes, so default printk all bbp
102946 + goto next;
102947 + }
102948 + }
102949 + }
102950 + else
102951 + { //Write
102952 + memcpy(&temp2, value, strlen(value));
102953 + temp2[strlen(value)] = '\0';
102954 +
102955 + // Sanity check
102956 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
102957 + goto next;
102958 +
102959 + j = strlen(this_char);
102960 + while(j-- > 0)
102961 + {
102962 + if(this_char[j] > 'f' || this_char[j] < '0')
102963 + return;
102964 + }
102965 +
102966 + j = strlen(temp2);
102967 + while(j-- > 0)
102968 + {
102969 + if(temp2[j] > 'f' || temp2[j] < '0')
102970 + return;
102971 + }
102972 +
102973 + //MAC Addr
102974 + k = j = strlen(this_char);
102975 + while(j-- > 0)
102976 + {
102977 + this_char[4-k+j] = this_char[j];
102978 + }
102979 +
102980 + while(k < 4)
102981 + this_char[3-k++]='0';
102982 + this_char[4]='\0';
102983 +
102984 + //MAC value
102985 + k = j = strlen(temp2);
102986 + while(j-- > 0)
102987 + {
102988 + temp2[8-k+j] = temp2[j];
102989 + }
102990 +
102991 + while(k < 8)
102992 + temp2[7-k++]='0';
102993 + temp2[8]='\0';
102994 +
102995 + {
102996 + AtoH(this_char, temp, 2);
102997 + macAddr = *temp*256 + temp[1];
102998 +
102999 + AtoH(temp2, temp, 4);
103000 + macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
103001 +
103002 + // debug mode
103003 + if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
103004 + {
103005 + // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
103006 + if (macValue & 0x000000ff)
103007 + {
103008 + pAdapter->BbpTuning.bEnable = TRUE;
103009 + DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
103010 + }
103011 + else
103012 + {
103013 + UCHAR R66;
103014 + pAdapter->BbpTuning.bEnable = FALSE;
103015 + R66 = 0x26 + GET_LNA_GAIN(pAdapter);
103016 +#ifdef RALINK_ATE
103017 + if (ATE_ON(pAdapter))
103018 + {
103019 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
103020 + }
103021 + else
103022 +#endif // RALINK_ATE //
103023 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
103024 + DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
103025 + }
103026 + return;
103027 + }
103028 +
103029 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
103030 +
103031 + RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
103032 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
103033 + }
103034 + }
103035 + }
103036 +next:
103037 + if(strlen(msg) == 1)
103038 + sprintf(msg+strlen(msg), "===>Error command format!");
103039 +
103040 + // Copy the information into the user buffer
103041 + wrq->u.data.length = strlen(msg);
103042 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
103043 +
103044 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
103045 +}
103046 +
103047 +/*
103048 + ==========================================================================
103049 + Description:
103050 + Read / Write E2PROM
103051 + Arguments:
103052 + pAdapter Pointer to our adapter
103053 + wrq Pointer to the ioctl argument
103054 +
103055 + Return Value:
103056 + None
103057 +
103058 + Note:
103059 + Usage:
103060 + 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
103061 + 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
103062 + ==========================================================================
103063 +*/
103064 +VOID RTMPIoctlE2PROM(
103065 + IN PRTMP_ADAPTER pAdapter,
103066 + IN struct iwreq *wrq)
103067 +{
103068 + CHAR *this_char;
103069 + CHAR *value;
103070 + INT j = 0, k = 0;
103071 + CHAR msg[1024];
103072 + CHAR arg[255];
103073 + USHORT eepAddr = 0;
103074 + UCHAR temp[16], temp2[16];
103075 + USHORT eepValue;
103076 + int Status;
103077 +
103078 +
103079 + memset(msg, 0x00, 1024);
103080 + if (wrq->u.data.length > 1) //No parameters.
103081 + {
103082 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
103083 + sprintf(msg, "\n");
103084 +
103085 + //Parsing Read or Write
103086 + this_char = arg;
103087 +
103088 +
103089 + if (!*this_char)
103090 + goto next;
103091 +
103092 + if ((value = rtstrchr(this_char, '=')) != NULL)
103093 + *value++ = 0;
103094 +
103095 + if (!value || !*value)
103096 + { //Read
103097 +
103098 + // Sanity check
103099 + if(strlen(this_char) > 4)
103100 + goto next;
103101 +
103102 + j = strlen(this_char);
103103 + while(j-- > 0)
103104 + {
103105 + if(this_char[j] > 'f' || this_char[j] < '0')
103106 + return;
103107 + }
103108 +
103109 + // E2PROM addr
103110 + k = j = strlen(this_char);
103111 + while(j-- > 0)
103112 + {
103113 + this_char[4-k+j] = this_char[j];
103114 + }
103115 +
103116 + while(k < 4)
103117 + this_char[3-k++]='0';
103118 + this_char[4]='\0';
103119 +
103120 + if(strlen(this_char) == 4)
103121 + {
103122 + AtoH(this_char, temp, 2);
103123 + eepAddr = *temp*256 + temp[1];
103124 + if (eepAddr < 0xFFFF)
103125 + {
103126 + RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
103127 + sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
103128 + }
103129 + else
103130 + {//Invalid parametes, so default printk all bbp
103131 + goto next;
103132 + }
103133 + }
103134 + }
103135 + else
103136 + { //Write
103137 + memcpy(&temp2, value, strlen(value));
103138 + temp2[strlen(value)] = '\0';
103139 +
103140 + // Sanity check
103141 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
103142 + goto next;
103143 +
103144 + j = strlen(this_char);
103145 + while(j-- > 0)
103146 + {
103147 + if(this_char[j] > 'f' || this_char[j] < '0')
103148 + return;
103149 + }
103150 + j = strlen(temp2);
103151 + while(j-- > 0)
103152 + {
103153 + if(temp2[j] > 'f' || temp2[j] < '0')
103154 + return;
103155 + }
103156 +
103157 + //MAC Addr
103158 + k = j = strlen(this_char);
103159 + while(j-- > 0)
103160 + {
103161 + this_char[4-k+j] = this_char[j];
103162 + }
103163 +
103164 + while(k < 4)
103165 + this_char[3-k++]='0';
103166 + this_char[4]='\0';
103167 +
103168 + //MAC value
103169 + k = j = strlen(temp2);
103170 + while(j-- > 0)
103171 + {
103172 + temp2[4-k+j] = temp2[j];
103173 + }
103174 +
103175 + while(k < 4)
103176 + temp2[3-k++]='0';
103177 + temp2[4]='\0';
103178 +
103179 + AtoH(this_char, temp, 2);
103180 + eepAddr = *temp*256 + temp[1];
103181 +
103182 + AtoH(temp2, temp, 2);
103183 + eepValue = *temp*256 + temp[1];
103184 +
103185 + RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
103186 + sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
103187 + }
103188 + }
103189 +next:
103190 + if(strlen(msg) == 1)
103191 + sprintf(msg+strlen(msg), "===>Error command format!");
103192 +
103193 +
103194 + // Copy the information into the user buffer
103195 + wrq->u.data.length = strlen(msg);
103196 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
103197 +
103198 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
103199 +}
103200 +#endif // DBG //
103201 +
103202 +
103203 +
103204 +
103205 +INT Set_TGnWifiTest_Proc(
103206 + IN PRTMP_ADAPTER pAd,
103207 + IN PUCHAR arg)
103208 +{
103209 + if (simple_strtol(arg, 0, 10) == 0)
103210 + pAd->StaCfg.bTGnWifiTest = FALSE;
103211 + else
103212 + pAd->StaCfg.bTGnWifiTest = TRUE;
103213 +
103214 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
103215 + return TRUE;
103216 +}
103217 +
103218 +INT Set_LongRetryLimit_Proc(
103219 + IN PRTMP_ADAPTER pAdapter,
103220 + IN PUCHAR arg)
103221 +{
103222 + TX_RTY_CFG_STRUC tx_rty_cfg;
103223 + UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
103224 +
103225 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
103226 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
103227 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
103228 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
103229 + return TRUE;
103230 +}
103231 +
103232 +INT Set_ShortRetryLimit_Proc(
103233 + IN PRTMP_ADAPTER pAdapter,
103234 + IN PUCHAR arg)
103235 +{
103236 + TX_RTY_CFG_STRUC tx_rty_cfg;
103237 + UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
103238 +
103239 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
103240 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
103241 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
103242 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
103243 + return TRUE;
103244 +}
103245 +
103246 +#ifdef EXT_BUILD_CHANNEL_LIST
103247 +INT Set_Ieee80211dClientMode_Proc(
103248 + IN PRTMP_ADAPTER pAdapter,
103249 + IN PUCHAR arg)
103250 +{
103251 + if (simple_strtol(arg, 0, 10) == 0)
103252 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
103253 + else if (simple_strtol(arg, 0, 10) == 1)
103254 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
103255 + else if (simple_strtol(arg, 0, 10) == 2)
103256 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
103257 + else
103258 + return FALSE;
103259 +
103260 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
103261 + return TRUE;
103262 +}
103263 +#endif // EXT_BUILD_CHANNEL_LIST //
103264 +
103265 +#ifdef CARRIER_DETECTION_SUPPORT
103266 +INT Set_CarrierDetect_Proc(
103267 + IN PRTMP_ADAPTER pAd,
103268 + IN PUCHAR arg)
103269 +{
103270 + if (simple_strtol(arg, 0, 10) == 0)
103271 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
103272 + else
103273 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
103274 +
103275 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
103276 + return TRUE;
103277 +}
103278 +#endif // CARRIER_DETECTION_SUPPORT //
103279 +
103280 +
103281 +INT Show_Adhoc_MacTable_Proc(
103282 + IN PRTMP_ADAPTER pAd,
103283 + IN PCHAR extra)
103284 +{
103285 + INT i;
103286 +
103287 + sprintf(extra, "\n");
103288 +
103289 +#ifdef DOT11_N_SUPPORT
103290 + sprintf(extra, "%sHT Operating Mode : %d\n", extra, pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
103291 +#endif // DOT11_N_SUPPORT //
103292 +
103293 + sprintf(extra, "%s\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n", extra,
103294 + "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
103295 +
103296 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
103297 + {
103298 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
103299 +
103300 + if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
103301 + break;
103302 + if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
103303 + {
103304 + sprintf(extra, "%s%02X:%02X:%02X:%02X:%02X:%02X ", extra,
103305 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
103306 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
103307 + sprintf(extra, "%s%-4d", extra, (int)pEntry->Aid);
103308 + sprintf(extra, "%s%-4d", extra, (int)pEntry->apidx);
103309 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi0);
103310 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi1);
103311 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi2);
103312 + sprintf(extra, "%s%-10s", extra, GetPhyMode(pEntry->HTPhyMode.field.MODE));
103313 + sprintf(extra, "%s%-6s", extra, GetBW(pEntry->HTPhyMode.field.BW));
103314 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.MCS);
103315 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.ShortGI);
103316 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.STBC);
103317 + sprintf(extra, "%s%-10d, %d, %d%%\n", extra, pEntry->DebugFIFOCount, pEntry->DebugTxCount,
103318 + (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
103319 + sprintf(extra, "%s\n", extra);
103320 + }
103321 + }
103322 +
103323 + return TRUE;
103324 +}
103325 +
103326 +
103327 --- /dev/null
103328 +++ b/drivers/staging/rt2870/tmp61
103329 @@ -0,0 +1,7037 @@
103330 +/*
103331 + *************************************************************************
103332 + * Ralink Tech Inc.
103333 + * 5F., No.36, Taiyuan St., Jhubei City,
103334 + * Hsinchu County 302,
103335 + * Taiwan, R.O.C.
103336 + *
103337 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
103338 + *
103339 + * This program is free software; you can redistribute it and/or modify *
103340 + * it under the terms of the GNU General Public License as published by *
103341 + * the Free Software Foundation; either version 2 of the License, or *
103342 + * (at your option) any later version. *
103343 + * *
103344 + * This program is distributed in the hope that it will be useful, *
103345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
103346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
103347 + * GNU General Public License for more details. *
103348 + * *
103349 + * You should have received a copy of the GNU General Public License *
103350 + * along with this program; if not, write to the *
103351 + * Free Software Foundation, Inc., *
103352 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
103353 + * *
103354 + *************************************************************************
103355 +
103356 + Module Name:
103357 + sta_ioctl.c
103358 +
103359 + Abstract:
103360 + IOCTL related subroutines
103361 +
103362 + Revision History:
103363 + Who When What
103364 + -------- ---------- ----------------------------------------------
103365 + Rory Chen 01-03-2003 created
103366 + Rory Chen 02-14-2005 modify to support RT61
103367 +*/
103368 +
103369 +#include "rt_config.h"
103370 +
103371 +#ifdef DBG
103372 +extern ULONG RTDebugLevel;
103373 +#endif
103374 +
103375 +#define NR_WEP_KEYS 4
103376 +#define WEP_SMALL_KEY_LEN (40/8)
103377 +#define WEP_LARGE_KEY_LEN (104/8)
103378 +
103379 +#define GROUP_KEY_NO 4
103380 +
103381 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
103382 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_A, _B, _C, _D, _E)
103383 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_A, _B, _C, _D, _E)
103384 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_A, _B, _C, _D, _E, _F)
103385 +#else
103386 +#define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_B, _C, _D, _E)
103387 +#define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_B, _C, _D, _E)
103388 +#define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_B, _C, _D, _E, _F)
103389 +#endif
103390 +
103391 +extern UCHAR CipherWpa2Template[];
103392 +extern UCHAR CipherWpaPskTkip[];
103393 +extern UCHAR CipherWpaPskTkipLen;
103394 +
103395 +typedef struct PACKED _RT_VERSION_INFO{
103396 + UCHAR DriverVersionW;
103397 + UCHAR DriverVersionX;
103398 + UCHAR DriverVersionY;
103399 + UCHAR DriverVersionZ;
103400 + UINT DriverBuildYear;
103401 + UINT DriverBuildMonth;
103402 + UINT DriverBuildDay;
103403 +} RT_VERSION_INFO, *PRT_VERSION_INFO;
103404 +
103405 +struct iw_priv_args privtab[] = {
103406 +{ RTPRIV_IOCTL_SET,
103407 + IW_PRIV_TYPE_CHAR | 1024, 0,
103408 + "set"},
103409 +
103410 +{ RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
103411 + ""},
103412 +{ RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
103413 + ""},
103414 +/* --- sub-ioctls definitions --- */
103415 + { SHOW_CONN_STATUS,
103416 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
103417 + { SHOW_DRVIER_VERION,
103418 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
103419 + { SHOW_BA_INFO,
103420 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
103421 + { SHOW_DESC_INFO,
103422 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
103423 + { RAIO_OFF,
103424 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
103425 + { RAIO_ON,
103426 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
103427 +#ifdef QOS_DLS_SUPPORT
103428 + { SHOW_DLS_ENTRY_INFO,
103429 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
103430 +#endif // QOS_DLS_SUPPORT //
103431 + { SHOW_CFG_VALUE,
103432 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
103433 + { SHOW_ADHOC_ENTRY_INFO,
103434 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
103435 +
103436 +/* --- sub-ioctls relations --- */
103437 +
103438 +#ifdef DBG
103439 +{ RTPRIV_IOCTL_BBP,
103440 + IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
103441 + "bbp"},
103442 +{ RTPRIV_IOCTL_MAC,
103443 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
103444 + "mac"},
103445 +{ RTPRIV_IOCTL_E2P,
103446 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
103447 + "e2p"},
103448 +#endif /* DBG */
103449 +
103450 +{ RTPRIV_IOCTL_STATISTICS,
103451 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
103452 + "stat"},
103453 +{ RTPRIV_IOCTL_GSITESURVEY,
103454 + 0, IW_PRIV_TYPE_CHAR | 1024,
103455 + "get_site_survey"},
103456 +};
103457 +
103458 +INT Set_SSID_Proc(
103459 + IN PRTMP_ADAPTER pAdapter,
103460 + IN PUCHAR arg);
103461 +
103462 +#ifdef WMM_SUPPORT
103463 +INT Set_WmmCapable_Proc(
103464 + IN PRTMP_ADAPTER pAd,
103465 + IN PUCHAR arg);
103466 +#endif
103467 +
103468 +INT Set_NetworkType_Proc(
103469 + IN PRTMP_ADAPTER pAdapter,
103470 + IN PUCHAR arg);
103471 +
103472 +INT Set_AuthMode_Proc(
103473 + IN PRTMP_ADAPTER pAdapter,
103474 + IN PUCHAR arg);
103475 +
103476 +INT Set_EncrypType_Proc(
103477 + IN PRTMP_ADAPTER pAdapter,
103478 + IN PUCHAR arg);
103479 +
103480 +INT Set_DefaultKeyID_Proc(
103481 + IN PRTMP_ADAPTER pAdapter,
103482 + IN PUCHAR arg);
103483 +
103484 +INT Set_Key1_Proc(
103485 + IN PRTMP_ADAPTER pAdapter,
103486 + IN PUCHAR arg);
103487 +
103488 +INT Set_Key2_Proc(
103489 + IN PRTMP_ADAPTER pAdapter,
103490 + IN PUCHAR arg);
103491 +
103492 +INT Set_Key3_Proc(
103493 + IN PRTMP_ADAPTER pAdapter,
103494 + IN PUCHAR arg);
103495 +
103496 +INT Set_Key4_Proc(
103497 + IN PRTMP_ADAPTER pAdapter,
103498 + IN PUCHAR arg);
103499 +
103500 +INT Set_WPAPSK_Proc(
103501 + IN PRTMP_ADAPTER pAdapter,
103502 + IN PUCHAR arg);
103503 +
103504 +
103505 +INT Set_PSMode_Proc(
103506 + IN PRTMP_ADAPTER pAdapter,
103507 + IN PUCHAR arg);
103508 +
103509 +#ifdef WPA_SUPPLICANT_SUPPORT
103510 +INT Set_Wpa_Support(
103511 + IN PRTMP_ADAPTER pAd,
103512 + IN PUCHAR arg);
103513 +#endif // WPA_SUPPLICANT_SUPPORT //
103514 +
103515 +#ifdef DBG
103516 +VOID RTMPIoctlBBP(
103517 + IN PRTMP_ADAPTER pAdapter,
103518 + IN struct iwreq *wrq);
103519 +
103520 +VOID RTMPIoctlMAC(
103521 + IN PRTMP_ADAPTER pAdapter,
103522 + IN struct iwreq *wrq);
103523 +
103524 +VOID RTMPIoctlE2PROM(
103525 + IN PRTMP_ADAPTER pAdapter,
103526 + IN struct iwreq *wrq);
103527 +#endif // DBG //
103528 +
103529 +
103530 +NDIS_STATUS RTMPWPANoneAddKeyProc(
103531 + IN PRTMP_ADAPTER pAd,
103532 + IN PVOID pBuf);
103533 +
103534 +INT Set_FragTest_Proc(
103535 + IN PRTMP_ADAPTER pAdapter,
103536 + IN PUCHAR arg);
103537 +
103538 +#ifdef DOT11_N_SUPPORT
103539 +INT Set_TGnWifiTest_Proc(
103540 + IN PRTMP_ADAPTER pAd,
103541 + IN PUCHAR arg);
103542 +#endif // DOT11_N_SUPPORT //
103543 +
103544 +INT Set_LongRetryLimit_Proc(
103545 + IN PRTMP_ADAPTER pAdapter,
103546 + IN PUCHAR arg);
103547 +
103548 +INT Set_ShortRetryLimit_Proc(
103549 + IN PRTMP_ADAPTER pAdapter,
103550 + IN PUCHAR arg);
103551 +
103552 +#ifdef EXT_BUILD_CHANNEL_LIST
103553 +INT Set_Ieee80211dClientMode_Proc(
103554 + IN PRTMP_ADAPTER pAdapter,
103555 + IN PUCHAR arg);
103556 +#endif // EXT_BUILD_CHANNEL_LIST //
103557 +
103558 +#ifdef CARRIER_DETECTION_SUPPORT
103559 +INT Set_CarrierDetect_Proc(
103560 + IN PRTMP_ADAPTER pAd,
103561 + IN PUCHAR arg);
103562 +#endif // CARRIER_DETECTION_SUPPORT //
103563 +
103564 +INT Show_Adhoc_MacTable_Proc(
103565 + IN PRTMP_ADAPTER pAd,
103566 + IN PCHAR extra);
103567 +
103568 +static struct {
103569 + CHAR *name;
103570 + INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
103571 +} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
103572 + {"DriverVersion", Set_DriverVersion_Proc},
103573 + {"CountryRegion", Set_CountryRegion_Proc},
103574 + {"CountryRegionABand", Set_CountryRegionABand_Proc},
103575 + {"SSID", Set_SSID_Proc},
103576 + {"WirelessMode", Set_WirelessMode_Proc},
103577 + {"TxBurst", Set_TxBurst_Proc},
103578 + {"TxPreamble", Set_TxPreamble_Proc},
103579 + {"TxPower", Set_TxPower_Proc},
103580 + {"Channel", Set_Channel_Proc},
103581 + {"BGProtection", Set_BGProtection_Proc},
103582 + {"RTSThreshold", Set_RTSThreshold_Proc},
103583 + {"FragThreshold", Set_FragThreshold_Proc},
103584 +#ifdef DOT11_N_SUPPORT
103585 + {"HtBw", Set_HtBw_Proc},
103586 + {"HtMcs", Set_HtMcs_Proc},
103587 + {"HtGi", Set_HtGi_Proc},
103588 + {"HtOpMode", Set_HtOpMode_Proc},
103589 + {"HtExtcha", Set_HtExtcha_Proc},
103590 + {"HtMpduDensity", Set_HtMpduDensity_Proc},
103591 + {"HtBaWinSize", Set_HtBaWinSize_Proc},
103592 + {"HtRdg", Set_HtRdg_Proc},
103593 + {"HtAmsdu", Set_HtAmsdu_Proc},
103594 + {"HtAutoBa", Set_HtAutoBa_Proc},
103595 + {"HtBaDecline", Set_BADecline_Proc},
103596 + {"HtProtect", Set_HtProtect_Proc},
103597 + {"HtMimoPs", Set_HtMimoPs_Proc},
103598 +#endif // DOT11_N_SUPPORT //
103599 +
103600 +#ifdef AGGREGATION_SUPPORT
103601 + {"PktAggregate", Set_PktAggregate_Proc},
103602 +#endif
103603 +
103604 +#ifdef WMM_SUPPORT
103605 + {"WmmCapable", Set_WmmCapable_Proc},
103606 +#endif
103607 + {"IEEE80211H", Set_IEEE80211H_Proc},
103608 + {"NetworkType", Set_NetworkType_Proc},
103609 + {"AuthMode", Set_AuthMode_Proc},
103610 + {"EncrypType", Set_EncrypType_Proc},
103611 + {"DefaultKeyID", Set_DefaultKeyID_Proc},
103612 + {"Key1", Set_Key1_Proc},
103613 + {"Key2", Set_Key2_Proc},
103614 + {"Key3", Set_Key3_Proc},
103615 + {"Key4", Set_Key4_Proc},
103616 + {"WPAPSK", Set_WPAPSK_Proc},
103617 + {"ResetCounter", Set_ResetStatCounter_Proc},
103618 + {"PSMode", Set_PSMode_Proc},
103619 +#ifdef DBG
103620 + {"Debug", Set_Debug_Proc},
103621 +#endif
103622 +
103623 +#ifdef RALINK_ATE
103624 + {"ATE", Set_ATE_Proc},
103625 + {"ATEDA", Set_ATE_DA_Proc},
103626 + {"ATESA", Set_ATE_SA_Proc},
103627 + {"ATEBSSID", Set_ATE_BSSID_Proc},
103628 + {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
103629 + {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
103630 + {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
103631 + {"ATETXANT", Set_ATE_TX_Antenna_Proc},
103632 + {"ATERXANT", Set_ATE_RX_Antenna_Proc},
103633 + {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
103634 + {"ATETXBW", Set_ATE_TX_BW_Proc},
103635 + {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
103636 + {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
103637 + {"ATETXMCS", Set_ATE_TX_MCS_Proc},
103638 + {"ATETXMODE", Set_ATE_TX_MODE_Proc},
103639 + {"ATETXGI", Set_ATE_TX_GI_Proc},
103640 + {"ATERXFER", Set_ATE_RX_FER_Proc},
103641 + {"ATERRF", Set_ATE_Read_RF_Proc},
103642 + {"ATEWRF1", Set_ATE_Write_RF1_Proc},
103643 + {"ATEWRF2", Set_ATE_Write_RF2_Proc},
103644 + {"ATEWRF3", Set_ATE_Write_RF3_Proc},
103645 + {"ATEWRF4", Set_ATE_Write_RF4_Proc},
103646 + {"ATELDE2P", Set_ATE_Load_E2P_Proc},
103647 + {"ATERE2P", Set_ATE_Read_E2P_Proc},
103648 + {"ATESHOW", Set_ATE_Show_Proc},
103649 + {"ATEHELP", Set_ATE_Help_Proc},
103650 +
103651 +#ifdef RALINK_28xx_QA
103652 + {"TxStop", Set_TxStop_Proc},
103653 + {"RxStop", Set_RxStop_Proc},
103654 +#endif // RALINK_28xx_QA //
103655 +#endif // RALINK_ATE //
103656 +
103657 +#ifdef WPA_SUPPLICANT_SUPPORT
103658 + {"WpaSupport", Set_Wpa_Support},
103659 +#endif // WPA_SUPPLICANT_SUPPORT //
103660 +
103661 +
103662 +
103663 + {"FixedTxMode", Set_FixedTxMode_Proc},
103664 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
103665 + {"OpMode", Set_OpMode_Proc},
103666 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
103667 +#ifdef DOT11_N_SUPPORT
103668 + {"TGnWifiTest", Set_TGnWifiTest_Proc},
103669 + {"ForceGF", Set_ForceGF_Proc},
103670 +#endif // DOT11_N_SUPPORT //
103671 +#ifdef QOS_DLS_SUPPORT
103672 + {"DlsAddEntry", Set_DlsAddEntry_Proc},
103673 + {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
103674 +#endif // QOS_DLS_SUPPORT //
103675 + {"LongRetry", Set_LongRetryLimit_Proc},
103676 + {"ShortRetry", Set_ShortRetryLimit_Proc},
103677 +#ifdef EXT_BUILD_CHANNEL_LIST
103678 + {"11dClientMode", Set_Ieee80211dClientMode_Proc},
103679 +#endif // EXT_BUILD_CHANNEL_LIST //
103680 +#ifdef CARRIER_DETECTION_SUPPORT
103681 + {"CarrierDetect", Set_CarrierDetect_Proc},
103682 +#endif // CARRIER_DETECTION_SUPPORT //
103683 +
103684 + {NULL,}
103685 +};
103686 +
103687 +
103688 +VOID RTMPAddKey(
103689 + IN PRTMP_ADAPTER pAd,
103690 + IN PNDIS_802_11_KEY pKey)
103691 +{
103692 + ULONG KeyIdx;
103693 + MAC_TABLE_ENTRY *pEntry;
103694 +
103695 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
103696 +
103697 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
103698 + {
103699 + if (pKey->KeyIndex & 0x80000000)
103700 + {
103701 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
103702 + {
103703 + NdisZeroMemory(pAd->StaCfg.PMK, 32);
103704 + NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
103705 + goto end;
103706 + }
103707 + // Update PTK
103708 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
103709 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
103710 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
103711 +#ifdef WPA_SUPPLICANT_SUPPORT
103712 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
103713 + {
103714 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
103715 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
103716 + }
103717 + else
103718 +#endif // WPA_SUPPLICANT_SUPPORT //
103719 + {
103720 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
103721 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
103722 + }
103723 +
103724 + // Decide its ChiperAlg
103725 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
103726 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
103727 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
103728 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
103729 + else
103730 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
103731 +
103732 + // Update these related information to MAC_TABLE_ENTRY
103733 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
103734 + NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
103735 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
103736 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
103737 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
103738 +
103739 + // Update pairwise key information to ASIC Shared Key Table
103740 + AsicAddSharedKeyEntry(pAd,
103741 + BSS0,
103742 + 0,
103743 + pAd->SharedKey[BSS0][0].CipherAlg,
103744 + pAd->SharedKey[BSS0][0].Key,
103745 + pAd->SharedKey[BSS0][0].TxMic,
103746 + pAd->SharedKey[BSS0][0].RxMic);
103747 +
103748 + // Update ASIC WCID attribute table and IVEIV table
103749 + RTMPAddWcidAttributeEntry(pAd,
103750 + BSS0,
103751 + 0,
103752 + pAd->SharedKey[BSS0][0].CipherAlg,
103753 + pEntry);
103754 +
103755 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
103756 + {
103757 + // set 802.1x port control
103758 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
103759 + STA_PORT_SECURED(pAd);
103760 +
103761 + // Indicate Connected for GUI
103762 + pAd->IndicateMediaState = NdisMediaStateConnected;
103763 + }
103764 + }
103765 + else
103766 + {
103767 + // Update GTK
103768 + pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
103769 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
103770 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
103771 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
103772 +#ifdef WPA_SUPPLICANT_SUPPORT
103773 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
103774 + {
103775 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
103776 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
103777 + }
103778 + else
103779 +#endif // WPA_SUPPLICANT_SUPPORT //
103780 + {
103781 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
103782 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
103783 + }
103784 +
103785 + // Update Shared Key CipherAlg
103786 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
103787 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
103788 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
103789 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
103790 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
103791 +
103792 + // Update group key information to ASIC Shared Key Table
103793 + AsicAddSharedKeyEntry(pAd,
103794 + BSS0,
103795 + pAd->StaCfg.DefaultKeyId,
103796 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
103797 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
103798 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
103799 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
103800 +
103801 + // Update ASIC WCID attribute table and IVEIV table
103802 + RTMPAddWcidAttributeEntry(pAd,
103803 + BSS0,
103804 + pAd->StaCfg.DefaultKeyId,
103805 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
103806 + NULL);
103807 +
103808 + // set 802.1x port control
103809 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
103810 + STA_PORT_SECURED(pAd);
103811 +
103812 + // Indicate Connected for GUI
103813 + pAd->IndicateMediaState = NdisMediaStateConnected;
103814 + }
103815 + }
103816 + else // dynamic WEP from wpa_supplicant
103817 + {
103818 + UCHAR CipherAlg;
103819 + PUCHAR Key;
103820 +
103821 + if(pKey->KeyLength == 32)
103822 + goto end;
103823 +
103824 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
103825 +
103826 + if (KeyIdx < 4)
103827 + {
103828 + // it is a default shared key, for Pairwise key setting
103829 + if (pKey->KeyIndex & 0x80000000)
103830 + {
103831 + pEntry = MacTableLookup(pAd, pKey->BSSID);
103832 +
103833 + if (pEntry)
103834 + {
103835 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
103836 +
103837 + // set key material and key length
103838 + pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
103839 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
103840 +
103841 + // set Cipher type
103842 + if (pKey->KeyLength == 5)
103843 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
103844 + else
103845 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
103846 +
103847 + // Add Pair-wise key to Asic
103848 + AsicAddPairwiseKeyEntry(
103849 + pAd,
103850 + pEntry->Addr,
103851 + (UCHAR)pEntry->Aid,
103852 + &pEntry->PairwiseKey);
103853 +
103854 + // update WCID attribute table and IVEIV table for this entry
103855 + RTMPAddWcidAttributeEntry(
103856 + pAd,
103857 + BSS0,
103858 + KeyIdx, // The value may be not zero
103859 + pEntry->PairwiseKey.CipherAlg,
103860 + pEntry);
103861 +
103862 + }
103863 + }
103864 + else
103865 + {
103866 + // Default key for tx (shared key)
103867 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
103868 +
103869 + // set key material and key length
103870 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
103871 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
103872 +
103873 + // Set Ciper type
103874 + if (pKey->KeyLength == 5)
103875 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
103876 + else
103877 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
103878 +
103879 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
103880 + Key = pAd->SharedKey[BSS0][KeyIdx].Key;
103881 +
103882 + // Set Group key material to Asic
103883 + AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
103884 +
103885 + // Update WCID attribute table and IVEIV table for this group key table
103886 + RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
103887 +
103888 + }
103889 + }
103890 + }
103891 +end:
103892 + return;
103893 +}
103894 +
103895 +char * rtstrchr(const char * s, int c)
103896 +{
103897 + for(; *s != (char) c; ++s)
103898 + if (*s == '\0')
103899 + return NULL;
103900 + return (char *) s;
103901 +}
103902 +
103903 +/*
103904 +This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
103905 +*/
103906 +
103907 +int
103908 +rt_ioctl_giwname(struct net_device *dev,
103909 + struct iw_request_info *info,
103910 + char *name, char *extra)
103911 +{
103912 +// PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
103913 +
103914 +#ifdef RT2870
103915 + strncpy(name, "RT2870 Wireless", IFNAMSIZ);
103916 +#endif // RT2870 //
103917 + return 0;
103918 +}
103919 +
103920 +int rt_ioctl_siwfreq(struct net_device *dev,
103921 + struct iw_request_info *info,
103922 + struct iw_freq *freq, char *extra)
103923 +{
103924 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
103925 + int chan = -1;
103926 +
103927 + //check if the interface is down
103928 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
103929 + {
103930 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
103931 + return -ENETDOWN;
103932 + }
103933 +
103934 +
103935 + if (freq->e > 1)
103936 + return -EINVAL;
103937 +
103938 + if((freq->e == 0) && (freq->m <= 1000))
103939 + chan = freq->m; // Setting by channel number
103940 + else
103941 + MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
103942 +
103943 + if (ChannelSanity(pAdapter, chan) == TRUE)
103944 + {
103945 + pAdapter->CommonCfg.Channel = chan;
103946 + DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
103947 + }
103948 + else
103949 + return -EINVAL;
103950 +
103951 + return 0;
103952 +}
103953 +int rt_ioctl_giwfreq(struct net_device *dev,
103954 + struct iw_request_info *info,
103955 + struct iw_freq *freq, char *extra)
103956 +{
103957 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
103958 + PRTMP_ADAPTER pAdapter = NULL;
103959 + UCHAR ch;
103960 + ULONG m;
103961 +
103962 + if (dev->priv_flags == INT_MAIN)
103963 + {
103964 + pAdapter = dev->priv;
103965 + }
103966 + else
103967 + {
103968 + pVirtualAd = dev->priv;
103969 + if (pVirtualAd && pVirtualAd->RtmpDev)
103970 + pAdapter = pVirtualAd->RtmpDev->priv;
103971 + }
103972 +
103973 + if (pAdapter == NULL)
103974 + {
103975 + /* if 1st open fail, pAd will be free;
103976 + So the net_dev->priv will be NULL in 2rd open */
103977 + return -ENETDOWN;
103978 + }
103979 +
103980 + ch = pAdapter->CommonCfg.Channel;
103981 +
103982 + DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
103983 +
103984 + MAP_CHANNEL_ID_TO_KHZ(ch, m);
103985 + freq->m = m * 100;
103986 + freq->e = 1;
103987 + return 0;
103988 +}
103989 +
103990 +int rt_ioctl_siwmode(struct net_device *dev,
103991 + struct iw_request_info *info,
103992 + __u32 *mode, char *extra)
103993 +{
103994 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
103995 +
103996 + //check if the interface is down
103997 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
103998 + {
103999 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104000 + return -ENETDOWN;
104001 + }
104002 +
104003 + switch (*mode)
104004 + {
104005 + case IW_MODE_ADHOC:
104006 + Set_NetworkType_Proc(pAdapter, "Adhoc");
104007 + break;
104008 + case IW_MODE_INFRA:
104009 + Set_NetworkType_Proc(pAdapter, "Infra");
104010 + break;
104011 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
104012 + case IW_MODE_MONITOR:
104013 + Set_NetworkType_Proc(pAdapter, "Monitor");
104014 + break;
104015 +#endif
104016 + default:
104017 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
104018 + return -EINVAL;
104019 + }
104020 +
104021 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
104022 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
104023 +
104024 + return 0;
104025 +}
104026 +
104027 +int rt_ioctl_giwmode(struct net_device *dev,
104028 + struct iw_request_info *info,
104029 + __u32 *mode, char *extra)
104030 +{
104031 + PRTMP_ADAPTER pAdapter = NULL;
104032 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104033 +
104034 + if (dev->priv_flags == INT_MAIN)
104035 + {
104036 + pAdapter = dev->priv;
104037 + }
104038 + else
104039 + {
104040 + pVirtualAd = dev->priv;
104041 + if (pVirtualAd && pVirtualAd->RtmpDev)
104042 + pAdapter = pVirtualAd->RtmpDev->priv;
104043 + }
104044 +
104045 + if (pAdapter == NULL)
104046 + {
104047 + /* if 1st open fail, pAd will be free;
104048 + So the net_dev->priv will be NULL in 2rd open */
104049 + return -ENETDOWN;
104050 + }
104051 +
104052 + if (ADHOC_ON(pAdapter))
104053 + *mode = IW_MODE_ADHOC;
104054 + else if (INFRA_ON(pAdapter))
104055 + *mode = IW_MODE_INFRA;
104056 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
104057 + else if (MONITOR_ON(pAdapter))
104058 + {
104059 + *mode = IW_MODE_MONITOR;
104060 + }
104061 +#endif
104062 + else
104063 + *mode = IW_MODE_AUTO;
104064 +
104065 + DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
104066 + return 0;
104067 +}
104068 +
104069 +int rt_ioctl_siwsens(struct net_device *dev,
104070 + struct iw_request_info *info,
104071 + char *name, char *extra)
104072 +{
104073 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104074 +
104075 + //check if the interface is down
104076 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104077 + {
104078 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104079 + return -ENETDOWN;
104080 + }
104081 +
104082 + return 0;
104083 +}
104084 +
104085 +int rt_ioctl_giwsens(struct net_device *dev,
104086 + struct iw_request_info *info,
104087 + char *name, char *extra)
104088 +{
104089 + return 0;
104090 +}
104091 +
104092 +int rt_ioctl_giwrange(struct net_device *dev,
104093 + struct iw_request_info *info,
104094 + struct iw_point *data, char *extra)
104095 +{
104096 + PRTMP_ADAPTER pAdapter = NULL;
104097 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104098 + struct iw_range *range = (struct iw_range *) extra;
104099 + u16 val;
104100 + int i;
104101 +
104102 + if (dev->priv_flags == INT_MAIN)
104103 + {
104104 + pAdapter = dev->priv;
104105 + }
104106 + else
104107 + {
104108 + pVirtualAd = dev->priv;
104109 + if (pVirtualAd && pVirtualAd->RtmpDev)
104110 + pAdapter = pVirtualAd->RtmpDev->priv;
104111 + }
104112 +
104113 + if (pAdapter == NULL)
104114 + {
104115 + /* if 1st open fail, pAd will be free;
104116 + So the net_dev->priv will be NULL in 2rd open */
104117 + return -ENETDOWN;
104118 + }
104119 +
104120 + DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
104121 + data->length = sizeof(struct iw_range);
104122 + memset(range, 0, sizeof(struct iw_range));
104123 +
104124 + range->txpower_capa = IW_TXPOW_DBM;
104125 +
104126 + if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
104127 + {
104128 + range->min_pmp = 1 * 1024;
104129 + range->max_pmp = 65535 * 1024;
104130 + range->min_pmt = 1 * 1024;
104131 + range->max_pmt = 1000 * 1024;
104132 + range->pmp_flags = IW_POWER_PERIOD;
104133 + range->pmt_flags = IW_POWER_TIMEOUT;
104134 + range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
104135 + IW_POWER_UNICAST_R | IW_POWER_ALL_R;
104136 + }
104137 +
104138 + range->we_version_compiled = WIRELESS_EXT;
104139 + range->we_version_source = 14;
104140 +
104141 + range->retry_capa = IW_RETRY_LIMIT;
104142 + range->retry_flags = IW_RETRY_LIMIT;
104143 + range->min_retry = 0;
104144 + range->max_retry = 255;
104145 +
104146 + range->num_channels = pAdapter->ChannelListNum;
104147 +
104148 + val = 0;
104149 + for (i = 1; i <= range->num_channels; i++)
104150 + {
104151 + u32 m;
104152 + range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
104153 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
104154 + range->freq[val].m = m * 100; /* HZ */
104155 +
104156 + range->freq[val].e = 1;
104157 + val++;
104158 + if (val == IW_MAX_FREQUENCIES)
104159 + break;
104160 + }
104161 + range->num_frequency = val;
104162 +
104163 + range->max_qual.qual = 100; /* what is correct max? This was not
104164 + * documented exactly. At least
104165 + * 69 has been observed. */
104166 + range->max_qual.level = 0; /* dB */
104167 + range->max_qual.noise = 0; /* dB */
104168 +
104169 + /* What would be suitable values for "average/typical" qual? */
104170 + range->avg_qual.qual = 20;
104171 + range->avg_qual.level = -60;
104172 + range->avg_qual.noise = -95;
104173 + range->sensitivity = 3;
104174 +
104175 + range->max_encoding_tokens = NR_WEP_KEYS;
104176 + range->num_encoding_sizes = 2;
104177 + range->encoding_size[0] = 5;
104178 + range->encoding_size[1] = 13;
104179 +
104180 + range->min_rts = 0;
104181 + range->max_rts = 2347;
104182 + range->min_frag = 256;
104183 + range->max_frag = 2346;
104184 +
104185 +#if WIRELESS_EXT > 17
104186 + /* IW_ENC_CAPA_* bit field */
104187 + range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
104188 + IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
104189 +#endif
104190 +
104191 + return 0;
104192 +}
104193 +
104194 +int rt_ioctl_siwap(struct net_device *dev,
104195 + struct iw_request_info *info,
104196 + struct sockaddr *ap_addr, char *extra)
104197 +{
104198 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104199 + NDIS_802_11_MAC_ADDRESS Bssid;
104200 +
104201 + //check if the interface is down
104202 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104203 + {
104204 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104205 + return -ENETDOWN;
104206 + }
104207 +
104208 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
104209 + {
104210 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
104211 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
104212 + }
104213 +
104214 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
104215 + // this request, because this request is initiated by NDIS.
104216 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
104217 + // Prevent to connect AP again in STAMlmePeriodicExec
104218 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
104219 +
104220 + memset(Bssid, 0, MAC_ADDR_LEN);
104221 + memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
104222 + MlmeEnqueue(pAdapter,
104223 + MLME_CNTL_STATE_MACHINE,
104224 + OID_802_11_BSSID,
104225 + sizeof(NDIS_802_11_MAC_ADDRESS),
104226 + (VOID *)&Bssid);
104227 +
104228 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
104229 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
104230 +
104231 + return 0;
104232 +}
104233 +
104234 +int rt_ioctl_giwap(struct net_device *dev,
104235 + struct iw_request_info *info,
104236 + struct sockaddr *ap_addr, char *extra)
104237 +{
104238 + PRTMP_ADAPTER pAdapter = NULL;
104239 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104240 +
104241 + if (dev->priv_flags == INT_MAIN)
104242 + {
104243 + pAdapter = dev->priv;
104244 + }
104245 + else
104246 + {
104247 + pVirtualAd = dev->priv;
104248 + if (pVirtualAd && pVirtualAd->RtmpDev)
104249 + pAdapter = pVirtualAd->RtmpDev->priv;
104250 + }
104251 +
104252 + if (pAdapter == NULL)
104253 + {
104254 + /* if 1st open fail, pAd will be free;
104255 + So the net_dev->priv will be NULL in 2rd open */
104256 + return -ENETDOWN;
104257 + }
104258 +
104259 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
104260 + {
104261 + ap_addr->sa_family = ARPHRD_ETHER;
104262 + memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
104263 + }
104264 +#ifdef WPA_SUPPLICANT_SUPPORT
104265 + // Add for RT2870
104266 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
104267 + {
104268 + ap_addr->sa_family = ARPHRD_ETHER;
104269 + memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
104270 + }
104271 +#endif // WPA_SUPPLICANT_SUPPORT //
104272 + else
104273 + {
104274 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
104275 + return -ENOTCONN;
104276 + }
104277 +
104278 + return 0;
104279 +}
104280 +
104281 +/*
104282 + * Units are in db above the noise floor. That means the
104283 + * rssi values reported in the tx/rx descriptors in the
104284 + * driver are the SNR expressed in db.
104285 + *
104286 + * If you assume that the noise floor is -95, which is an
104287 + * excellent assumption 99.5 % of the time, then you can
104288 + * derive the absolute signal level (i.e. -95 + rssi).
104289 + * There are some other slight factors to take into account
104290 + * depending on whether the rssi measurement is from 11b,
104291 + * 11g, or 11a. These differences are at most 2db and
104292 + * can be documented.
104293 + *
104294 + * NB: various calculations are based on the orinoco/wavelan
104295 + * drivers for compatibility
104296 + */
104297 +static void set_quality(PRTMP_ADAPTER pAdapter,
104298 + struct iw_quality *iq,
104299 + signed char rssi)
104300 +{
104301 + __u8 ChannelQuality;
104302 +
104303 + // Normalize Rssi
104304 + if (rssi >= -50)
104305 + ChannelQuality = 100;
104306 + else if (rssi >= -80) // between -50 ~ -80dbm
104307 + ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
104308 + else if (rssi >= -90) // between -80 ~ -90dbm
104309 + ChannelQuality = (__u8)((rssi + 90) * 26)/10;
104310 + else
104311 + ChannelQuality = 0;
104312 +
104313 + iq->qual = (__u8)ChannelQuality;
104314 +
104315 + iq->level = (__u8)(rssi);
104316 + iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
104317 + iq->noise += 256 - 143;
104318 + iq->updated = pAdapter->iw_stats.qual.updated;
104319 +}
104320 +
104321 +int rt_ioctl_iwaplist(struct net_device *dev,
104322 + struct iw_request_info *info,
104323 + struct iw_point *data, char *extra)
104324 +{
104325 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104326 +
104327 + struct sockaddr addr[IW_MAX_AP];
104328 + struct iw_quality qual[IW_MAX_AP];
104329 + int i;
104330 +
104331 + //check if the interface is down
104332 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104333 + {
104334 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104335 + data->length = 0;
104336 + return 0;
104337 + //return -ENETDOWN;
104338 + }
104339 +
104340 + for (i = 0; i <IW_MAX_AP ; i++)
104341 + {
104342 + if (i >= pAdapter->ScanTab.BssNr)
104343 + break;
104344 + addr[i].sa_family = ARPHRD_ETHER;
104345 + memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
104346 + set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
104347 + }
104348 + data->length = i;
104349 + memcpy(extra, &addr, i*sizeof(addr[0]));
104350 + data->flags = 1; /* signal quality present (sort of) */
104351 + memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
104352 +
104353 + return 0;
104354 +}
104355 +
104356 +#ifdef SIOCGIWSCAN
104357 +int rt_ioctl_siwscan(struct net_device *dev,
104358 + struct iw_request_info *info,
104359 + struct iw_point *data, char *extra)
104360 +{
104361 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104362 +
104363 + ULONG Now;
104364 + int Status = NDIS_STATUS_SUCCESS;
104365 +
104366 + //check if the interface is down
104367 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104368 + {
104369 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104370 + return -ENETDOWN;
104371 + }
104372 +
104373 + if (MONITOR_ON(pAdapter))
104374 + {
104375 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
104376 + return -EINVAL;
104377 + }
104378 +
104379 +
104380 +#ifdef WPA_SUPPLICANT_SUPPORT
104381 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
104382 + {
104383 + pAdapter->StaCfg.WpaSupplicantScanCount++;
104384 + }
104385 +#endif // WPA_SUPPLICANT_SUPPORT //
104386 +
104387 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
104388 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
104389 + return 0;
104390 + do{
104391 + Now = jiffies;
104392 +
104393 +#ifdef WPA_SUPPLICANT_SUPPORT
104394 + if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
104395 + (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
104396 + {
104397 + DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
104398 + Status = NDIS_STATUS_SUCCESS;
104399 + break;
104400 + }
104401 +#endif // WPA_SUPPLICANT_SUPPORT //
104402 +
104403 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
104404 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
104405 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
104406 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
104407 + {
104408 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
104409 + Status = NDIS_STATUS_SUCCESS;
104410 + break;
104411 + }
104412 +
104413 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
104414 + {
104415 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
104416 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
104417 + }
104418 +
104419 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
104420 + // this request, because this request is initiated by NDIS.
104421 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
104422 + // Reset allowed scan retries
104423 + pAdapter->StaCfg.ScanCnt = 0;
104424 + pAdapter->StaCfg.LastScanTime = Now;
104425 +
104426 + MlmeEnqueue(pAdapter,
104427 + MLME_CNTL_STATE_MACHINE,
104428 + OID_802_11_BSSID_LIST_SCAN,
104429 + 0,
104430 + NULL);
104431 +
104432 + Status = NDIS_STATUS_SUCCESS;
104433 + RT28XX_MLME_HANDLER(pAdapter);
104434 + }while(0);
104435 + return 0;
104436 +}
104437 +
104438 +int rt_ioctl_giwscan(struct net_device *dev,
104439 + struct iw_request_info *info,
104440 + struct iw_point *data, char *extra)
104441 +{
104442 +
104443 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104444 + int i=0;
104445 + char *current_ev = extra, *previous_ev = extra;
104446 + char *end_buf;
104447 + char *current_val, custom[MAX_CUSTOM_LEN] = {0};
104448 +#ifndef IWEVGENIE
104449 + char idx;
104450 +#endif // IWEVGENIE //
104451 + struct iw_event iwe;
104452 +
104453 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
104454 + {
104455 + /*
104456 + * Still scanning, indicate the caller should try again.
104457 + */
104458 + return -EAGAIN;
104459 + }
104460 +
104461 +
104462 +#ifdef WPA_SUPPLICANT_SUPPORT
104463 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
104464 + {
104465 + pAdapter->StaCfg.WpaSupplicantScanCount = 0;
104466 + }
104467 +#endif // WPA_SUPPLICANT_SUPPORT //
104468 +
104469 + if (pAdapter->ScanTab.BssNr == 0)
104470 + {
104471 + data->length = 0;
104472 + return 0;
104473 + }
104474 +
104475 +#if WIRELESS_EXT >= 17
104476 + if (data->length > 0)
104477 + end_buf = extra + data->length;
104478 + else
104479 + end_buf = extra + IW_SCAN_MAX_DATA;
104480 +#else
104481 + end_buf = extra + IW_SCAN_MAX_DATA;
104482 +#endif
104483 +
104484 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
104485 + {
104486 + if (current_ev >= end_buf)
104487 + {
104488 +#if WIRELESS_EXT >= 17
104489 + return -E2BIG;
104490 +#else
104491 + break;
104492 +#endif
104493 + }
104494 +
104495 + //MAC address
104496 + //================================
104497 + memset(&iwe, 0, sizeof(iwe));
104498 + iwe.cmd = SIOCGIWAP;
104499 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
104500 + memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
104501 +
104502 + previous_ev = current_ev;
104503 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
104504 + if (current_ev == previous_ev)
104505 +#if WIRELESS_EXT >= 17
104506 + return -E2BIG;
104507 +#else
104508 + break;
104509 +#endif
104510 +
104511 + //ESSID
104512 + //================================
104513 + memset(&iwe, 0, sizeof(iwe));
104514 + iwe.cmd = SIOCGIWESSID;
104515 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
104516 + iwe.u.data.flags = 1;
104517 +
104518 + previous_ev = current_ev;
104519 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
104520 + if (current_ev == previous_ev)
104521 +#if WIRELESS_EXT >= 17
104522 + return -E2BIG;
104523 +#else
104524 + break;
104525 +#endif
104526 +
104527 + //Network Type
104528 + //================================
104529 + memset(&iwe, 0, sizeof(iwe));
104530 + iwe.cmd = SIOCGIWMODE;
104531 + if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
104532 + {
104533 + iwe.u.mode = IW_MODE_ADHOC;
104534 + }
104535 + else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
104536 + {
104537 + iwe.u.mode = IW_MODE_INFRA;
104538 + }
104539 + else
104540 + {
104541 + iwe.u.mode = IW_MODE_AUTO;
104542 + }
104543 + iwe.len = IW_EV_UINT_LEN;
104544 +
104545 + previous_ev = current_ev;
104546 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
104547 + if (current_ev == previous_ev)
104548 +#if WIRELESS_EXT >= 17
104549 + return -E2BIG;
104550 +#else
104551 + break;
104552 +#endif
104553 +
104554 + //Channel and Frequency
104555 + //================================
104556 + memset(&iwe, 0, sizeof(iwe));
104557 + iwe.cmd = SIOCGIWFREQ;
104558 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
104559 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
104560 + else
104561 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
104562 + iwe.u.freq.e = 0;
104563 + iwe.u.freq.i = 0;
104564 +
104565 + previous_ev = current_ev;
104566 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
104567 + if (current_ev == previous_ev)
104568 +#if WIRELESS_EXT >= 17
104569 + return -E2BIG;
104570 +#else
104571 + break;
104572 +#endif
104573 +
104574 + //Add quality statistics
104575 + //================================
104576 + memset(&iwe, 0, sizeof(iwe));
104577 + iwe.cmd = IWEVQUAL;
104578 + iwe.u.qual.level = 0;
104579 + iwe.u.qual.noise = 0;
104580 + set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
104581 + current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
104582 + if (current_ev == previous_ev)
104583 +#if WIRELESS_EXT >= 17
104584 + return -E2BIG;
104585 +#else
104586 + break;
104587 +#endif
104588 +
104589 + //Encyption key
104590 + //================================
104591 + memset(&iwe, 0, sizeof(iwe));
104592 + iwe.cmd = SIOCGIWENCODE;
104593 + if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
104594 + iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
104595 + else
104596 + iwe.u.data.flags = IW_ENCODE_DISABLED;
104597 +
104598 + previous_ev = current_ev;
104599 + 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);
104600 + if (current_ev == previous_ev)
104601 +#if WIRELESS_EXT >= 17
104602 + return -E2BIG;
104603 +#else
104604 + break;
104605 +#endif
104606 +
104607 + //Bit Rate
104608 + //================================
104609 + if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
104610 + {
104611 + UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
104612 + memset(&iwe, 0, sizeof(iwe));
104613 + iwe.cmd = SIOCGIWRATE;
104614 + current_val = current_ev + IW_EV_LCP_LEN;
104615 + if (tmpRate == 0x82)
104616 + iwe.u.bitrate.value = 1 * 1000000;
104617 + else if (tmpRate == 0x84)
104618 + iwe.u.bitrate.value = 2 * 1000000;
104619 + else if (tmpRate == 0x8B)
104620 + iwe.u.bitrate.value = 5.5 * 1000000;
104621 + else if (tmpRate == 0x96)
104622 + iwe.u.bitrate.value = 11 * 1000000;
104623 + else
104624 + iwe.u.bitrate.value = (tmpRate/2) * 1000000;
104625 +
104626 + iwe.u.bitrate.disabled = 0;
104627 + current_val = IWE_STREAM_ADD_VALUE(info, current_ev,
104628 + current_val, end_buf, &iwe,
104629 + IW_EV_PARAM_LEN);
104630 +
104631 + if((current_val-current_ev)>IW_EV_LCP_LEN)
104632 + current_ev = current_val;
104633 + else
104634 +#if WIRELESS_EXT >= 17
104635 + return -E2BIG;
104636 +#else
104637 + break;
104638 +#endif
104639 + }
104640 +
104641 +#ifdef IWEVGENIE
104642 + //WPA IE
104643 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
104644 + {
104645 + memset(&iwe, 0, sizeof(iwe));
104646 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
104647 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
104648 + pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
104649 + iwe.cmd = IWEVGENIE;
104650 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
104651 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
104652 + if (current_ev == previous_ev)
104653 +#if WIRELESS_EXT >= 17
104654 + return -E2BIG;
104655 +#else
104656 + break;
104657 +#endif
104658 + }
104659 +
104660 + //WPA2 IE
104661 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
104662 + {
104663 + memset(&iwe, 0, sizeof(iwe));
104664 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
104665 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
104666 + pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
104667 + iwe.cmd = IWEVGENIE;
104668 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
104669 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
104670 + if (current_ev == previous_ev)
104671 +#if WIRELESS_EXT >= 17
104672 + return -E2BIG;
104673 +#else
104674 + break;
104675 +#endif
104676 + }
104677 +#else
104678 + //WPA IE
104679 + //================================
104680 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
104681 + {
104682 + NdisZeroMemory(&iwe, sizeof(iwe));
104683 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
104684 + iwe.cmd = IWEVCUSTOM;
104685 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
104686 + NdisMoveMemory(custom, "wpa_ie=", 7);
104687 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
104688 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
104689 + previous_ev = current_ev;
104690 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
104691 + if (current_ev == previous_ev)
104692 +#if WIRELESS_EXT >= 17
104693 + return -E2BIG;
104694 +#else
104695 + break;
104696 +#endif
104697 + }
104698 +
104699 + //WPA2 IE
104700 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
104701 + {
104702 + NdisZeroMemory(&iwe, sizeof(iwe));
104703 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
104704 + iwe.cmd = IWEVCUSTOM;
104705 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
104706 + NdisMoveMemory(custom, "rsn_ie=", 7);
104707 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
104708 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
104709 + previous_ev = current_ev;
104710 + current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
104711 + if (current_ev == previous_ev)
104712 +#if WIRELESS_EXT >= 17
104713 + return -E2BIG;
104714 +#else
104715 + break;
104716 +#endif
104717 + }
104718 +#endif // IWEVGENIE //
104719 + }
104720 +
104721 + data->length = current_ev - extra;
104722 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
104723 + DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
104724 + return 0;
104725 +}
104726 +#endif
104727 +
104728 +int rt_ioctl_siwessid(struct net_device *dev,
104729 + struct iw_request_info *info,
104730 + struct iw_point *data, char *essid)
104731 +{
104732 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104733 +
104734 + //check if the interface is down
104735 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104736 + {
104737 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104738 + return -ENETDOWN;
104739 + }
104740 +
104741 + if (data->flags)
104742 + {
104743 + PCHAR pSsidString = NULL;
104744 +
104745 + // Includes null character.
104746 + if (data->length > (IW_ESSID_MAX_SIZE + 1))
104747 + return -E2BIG;
104748 +
104749 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
104750 + if (pSsidString)
104751 + {
104752 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
104753 + NdisMoveMemory(pSsidString, essid, data->length);
104754 + if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
104755 + return -EINVAL;
104756 + }
104757 + else
104758 + return -ENOMEM;
104759 + }
104760 + else
104761 + {
104762 + // ANY ssid
104763 + if (Set_SSID_Proc(pAdapter, "") == FALSE)
104764 + return -EINVAL;
104765 + }
104766 + return 0;
104767 +}
104768 +
104769 +int rt_ioctl_giwessid(struct net_device *dev,
104770 + struct iw_request_info *info,
104771 + struct iw_point *data, char *essid)
104772 +{
104773 + PRTMP_ADAPTER pAdapter = NULL;
104774 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104775 +
104776 + if (dev->priv_flags == INT_MAIN)
104777 + {
104778 + pAdapter = dev->priv;
104779 + }
104780 + else
104781 + {
104782 + pVirtualAd = dev->priv;
104783 + if (pVirtualAd && pVirtualAd->RtmpDev)
104784 + pAdapter = pVirtualAd->RtmpDev->priv;
104785 + }
104786 +
104787 + if (pAdapter == NULL)
104788 + {
104789 + /* if 1st open fail, pAd will be free;
104790 + So the net_dev->priv will be NULL in 2rd open */
104791 + return -ENETDOWN;
104792 + }
104793 +
104794 + data->flags = 1;
104795 + if (MONITOR_ON(pAdapter))
104796 + {
104797 + data->length = 0;
104798 + return 0;
104799 + }
104800 +
104801 + if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
104802 + {
104803 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
104804 + data->length = pAdapter->CommonCfg.SsidLen;
104805 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
104806 + }
104807 +#ifdef RT2870
104808 +#ifdef WPA_SUPPLICANT_SUPPORT
104809 + // Add for RT2870
104810 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
104811 + {
104812 + data->length = pAdapter->CommonCfg.SsidLen;
104813 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
104814 + }
104815 +#endif // WPA_SUPPLICANT_SUPPORT //
104816 +#endif // RT2870 //
104817 + else
104818 + {//the ANY ssid was specified
104819 + data->length = 0;
104820 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
104821 + }
104822 +
104823 + return 0;
104824 +
104825 +}
104826 +
104827 +int rt_ioctl_siwnickn(struct net_device *dev,
104828 + struct iw_request_info *info,
104829 + struct iw_point *data, char *nickname)
104830 +{
104831 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104832 +
104833 + //check if the interface is down
104834 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104835 + {
104836 + DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
104837 + return -ENETDOWN;
104838 + }
104839 +
104840 + if (data->length > IW_ESSID_MAX_SIZE)
104841 + return -EINVAL;
104842 +
104843 + memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
104844 + memcpy(pAdapter->nickname, nickname, data->length);
104845 +
104846 +
104847 + return 0;
104848 +}
104849 +
104850 +int rt_ioctl_giwnickn(struct net_device *dev,
104851 + struct iw_request_info *info,
104852 + struct iw_point *data, char *nickname)
104853 +{
104854 + PRTMP_ADAPTER pAdapter = NULL;
104855 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104856 +
104857 + if (dev->priv_flags == INT_MAIN)
104858 + {
104859 + pAdapter = dev->priv;
104860 + }
104861 + else
104862 + {
104863 + pVirtualAd = dev->priv;
104864 + if (pVirtualAd && pVirtualAd->RtmpDev)
104865 + pAdapter = pVirtualAd->RtmpDev->priv;
104866 + }
104867 +
104868 + if (pAdapter == NULL)
104869 + {
104870 + /* if 1st open fail, pAd will be free;
104871 + So the net_dev->priv will be NULL in 2rd open */
104872 + return -ENETDOWN;
104873 + }
104874 +
104875 + if (data->length > strlen(pAdapter->nickname) + 1)
104876 + data->length = strlen(pAdapter->nickname) + 1;
104877 + if (data->length > 0) {
104878 + memcpy(nickname, pAdapter->nickname, data->length-1);
104879 + nickname[data->length-1] = '\0';
104880 + }
104881 + return 0;
104882 +}
104883 +
104884 +int rt_ioctl_siwrts(struct net_device *dev,
104885 + struct iw_request_info *info,
104886 + struct iw_param *rts, char *extra)
104887 +{
104888 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104889 + u16 val;
104890 +
104891 + //check if the interface is down
104892 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104893 + {
104894 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104895 + return -ENETDOWN;
104896 + }
104897 +
104898 + if (rts->disabled)
104899 + val = MAX_RTS_THRESHOLD;
104900 + else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
104901 + return -EINVAL;
104902 + else if (rts->value == 0)
104903 + val = MAX_RTS_THRESHOLD;
104904 + else
104905 + val = rts->value;
104906 +
104907 + if (val != pAdapter->CommonCfg.RtsThreshold)
104908 + pAdapter->CommonCfg.RtsThreshold = val;
104909 +
104910 + return 0;
104911 +}
104912 +
104913 +int rt_ioctl_giwrts(struct net_device *dev,
104914 + struct iw_request_info *info,
104915 + struct iw_param *rts, char *extra)
104916 +{
104917 + PRTMP_ADAPTER pAdapter = NULL;
104918 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104919 +
104920 + if (dev->priv_flags == INT_MAIN)
104921 + {
104922 + pAdapter = dev->priv;
104923 + }
104924 + else
104925 + {
104926 + pVirtualAd = dev->priv;
104927 + if (pVirtualAd && pVirtualAd->RtmpDev)
104928 + pAdapter = pVirtualAd->RtmpDev->priv;
104929 + }
104930 +
104931 + if (pAdapter == NULL)
104932 + {
104933 + /* if 1st open fail, pAd will be free;
104934 + So the net_dev->priv will be NULL in 2rd open */
104935 + return -ENETDOWN;
104936 + }
104937 +
104938 + //check if the interface is down
104939 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104940 + {
104941 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104942 + return -ENETDOWN;
104943 + }
104944 +
104945 + rts->value = pAdapter->CommonCfg.RtsThreshold;
104946 + rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
104947 + rts->fixed = 1;
104948 +
104949 + return 0;
104950 +}
104951 +
104952 +int rt_ioctl_siwfrag(struct net_device *dev,
104953 + struct iw_request_info *info,
104954 + struct iw_param *frag, char *extra)
104955 +{
104956 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
104957 + u16 val;
104958 +
104959 + //check if the interface is down
104960 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
104961 + {
104962 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
104963 + return -ENETDOWN;
104964 + }
104965 +
104966 + if (frag->disabled)
104967 + val = MAX_FRAG_THRESHOLD;
104968 + else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
104969 + val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
104970 + else if (frag->value == 0)
104971 + val = MAX_FRAG_THRESHOLD;
104972 + else
104973 + return -EINVAL;
104974 +
104975 + pAdapter->CommonCfg.FragmentThreshold = val;
104976 + return 0;
104977 +}
104978 +
104979 +int rt_ioctl_giwfrag(struct net_device *dev,
104980 + struct iw_request_info *info,
104981 + struct iw_param *frag, char *extra)
104982 +{
104983 + PRTMP_ADAPTER pAdapter = NULL;
104984 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
104985 +
104986 + if (dev->priv_flags == INT_MAIN)
104987 + {
104988 + pAdapter = dev->priv;
104989 + }
104990 + else
104991 + {
104992 + pVirtualAd = dev->priv;
104993 + if (pVirtualAd && pVirtualAd->RtmpDev)
104994 + pAdapter = pVirtualAd->RtmpDev->priv;
104995 + }
104996 +
104997 + if (pAdapter == NULL)
104998 + {
104999 + /* if 1st open fail, pAd will be free;
105000 + So the net_dev->priv will be NULL in 2rd open */
105001 + return -ENETDOWN;
105002 + }
105003 +
105004 + //check if the interface is down
105005 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105006 + {
105007 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105008 + return -ENETDOWN;
105009 + }
105010 +
105011 + frag->value = pAdapter->CommonCfg.FragmentThreshold;
105012 + frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
105013 + frag->fixed = 1;
105014 +
105015 + return 0;
105016 +}
105017 +
105018 +#define MAX_WEP_KEY_SIZE 13
105019 +#define MIN_WEP_KEY_SIZE 5
105020 +int rt_ioctl_siwencode(struct net_device *dev,
105021 + struct iw_request_info *info,
105022 + struct iw_point *erq, char *extra)
105023 +{
105024 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
105025 +
105026 + //check if the interface is down
105027 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105028 + {
105029 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105030 + return -ENETDOWN;
105031 + }
105032 +
105033 + if ((erq->length == 0) &&
105034 + (erq->flags & IW_ENCODE_DISABLED))
105035 + {
105036 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
105037 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
105038 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
105039 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105040 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
105041 + goto done;
105042 + }
105043 + else if ((erq->length == 0) &&
105044 + (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
105045 + {
105046 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105047 + STA_PORT_SECURED(pAdapter);
105048 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
105049 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
105050 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
105051 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105052 + if (erq->flags & IW_ENCODE_RESTRICTED)
105053 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
105054 + else
105055 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
105056 + goto done;
105057 + }
105058 +
105059 + if (erq->length > 0)
105060 + {
105061 + int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
105062 + /* Check the size of the key */
105063 + if (erq->length > MAX_WEP_KEY_SIZE) {
105064 + return -EINVAL;
105065 + }
105066 + /* Check key index */
105067 + if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
105068 + {
105069 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
105070 + keyIdx, pAdapter->StaCfg.DefaultKeyId));
105071 +
105072 + //Using default key
105073 + keyIdx = pAdapter->StaCfg.DefaultKeyId;
105074 + }
105075 +
105076 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
105077 +
105078 + if (erq->length == MAX_WEP_KEY_SIZE)
105079 + {
105080 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
105081 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
105082 + }
105083 + else if (erq->length == MIN_WEP_KEY_SIZE)
105084 + {
105085 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
105086 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
105087 + }
105088 + else
105089 + /* Disable the key */
105090 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
105091 +
105092 + /* Check if the key is not marked as invalid */
105093 + if(!(erq->flags & IW_ENCODE_NOKEY)) {
105094 + /* Copy the key in the driver */
105095 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
105096 + }
105097 + }
105098 + else
105099 + {
105100 + /* Do we want to just set the transmit key index ? */
105101 + int index = (erq->flags & IW_ENCODE_INDEX) - 1;
105102 + if ((index >= 0) && (index < 4))
105103 + {
105104 + pAdapter->StaCfg.DefaultKeyId = index;
105105 + }
105106 + else
105107 + /* Don't complain if only change the mode */
105108 + if(!erq->flags & IW_ENCODE_MODE) {
105109 + return -EINVAL;
105110 + }
105111 + }
105112 +
105113 +done:
105114 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
105115 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
105116 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
105117 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
105118 + return 0;
105119 +}
105120 +
105121 +int
105122 +rt_ioctl_giwencode(struct net_device *dev,
105123 + struct iw_request_info *info,
105124 + struct iw_point *erq, char *key)
105125 +{
105126 + int kid;
105127 + PRTMP_ADAPTER pAdapter = NULL;
105128 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
105129 +
105130 + if (dev->priv_flags == INT_MAIN)
105131 + {
105132 + pAdapter = dev->priv;
105133 + }
105134 + else
105135 + {
105136 + pVirtualAd = dev->priv;
105137 + if (pVirtualAd && pVirtualAd->RtmpDev)
105138 + pAdapter = pVirtualAd->RtmpDev->priv;
105139 + }
105140 +
105141 + if (pAdapter == NULL)
105142 + {
105143 + /* if 1st open fail, pAd will be free;
105144 + So the net_dev->priv will be NULL in 2rd open */
105145 + return -ENETDOWN;
105146 + }
105147 +
105148 + //check if the interface is down
105149 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105150 + {
105151 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105152 + return -ENETDOWN;
105153 + }
105154 +
105155 + kid = erq->flags & IW_ENCODE_INDEX;
105156 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
105157 +
105158 + if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
105159 + {
105160 + erq->length = 0;
105161 + erq->flags = IW_ENCODE_DISABLED;
105162 + }
105163 + else if ((kid > 0) && (kid <=4))
105164 + {
105165 + // copy wep key
105166 + erq->flags = kid ; /* NB: base 1 */
105167 + if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
105168 + erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
105169 + memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
105170 + //if ((kid == pAdapter->PortCfg.DefaultKeyId))
105171 + //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
105172 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
105173 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
105174 + else
105175 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
105176 +
105177 + }
105178 + else if (kid == 0)
105179 + {
105180 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
105181 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
105182 + else
105183 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
105184 + erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
105185 + memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
105186 + // copy default key ID
105187 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
105188 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
105189 + else
105190 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
105191 + erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
105192 + erq->flags |= IW_ENCODE_ENABLED; /* XXX */
105193 + }
105194 +
105195 + return 0;
105196 +
105197 +}
105198 +
105199 +static int
105200 +rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
105201 + void *w, char *extra)
105202 +{
105203 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
105204 + PRTMP_ADAPTER pAdapter;
105205 + POS_COOKIE pObj;
105206 + char *this_char = extra;
105207 + char *value;
105208 + int Status=0;
105209 +
105210 + if (dev->priv_flags == INT_MAIN)
105211 + {
105212 + pAdapter = dev->priv;
105213 + }
105214 + else
105215 + {
105216 + pVirtualAd = dev->priv;
105217 + pAdapter = pVirtualAd->RtmpDev->priv;
105218 + }
105219 + pObj = (POS_COOKIE) pAdapter->OS_Cookie;
105220 +
105221 + if (pAdapter == NULL)
105222 + {
105223 + /* if 1st open fail, pAd will be free;
105224 + So the net_dev->priv will be NULL in 2rd open */
105225 + return -ENETDOWN;
105226 + }
105227 +
105228 + {
105229 + pObj->ioctl_if_type = INT_MAIN;
105230 + pObj->ioctl_if = MAIN_MBSSID;
105231 + }
105232 +
105233 + //check if the interface is down
105234 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105235 + {
105236 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105237 + return -ENETDOWN;
105238 + }
105239 +
105240 + if (!*this_char)
105241 + return -EINVAL;
105242 +
105243 + if ((value = rtstrchr(this_char, '=')) != NULL)
105244 + *value++ = 0;
105245 +
105246 + if (!value)
105247 + return -EINVAL;
105248 +
105249 + // reject setting nothing besides ANY ssid(ssidLen=0)
105250 + if (!*value && (strcmp(this_char, "SSID") != 0))
105251 + return -EINVAL;
105252 +
105253 + for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
105254 + {
105255 + if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
105256 + {
105257 + if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
105258 + { //FALSE:Set private failed then return Invalid argument
105259 + Status = -EINVAL;
105260 + }
105261 + break; //Exit for loop.
105262 + }
105263 + }
105264 +
105265 + if(PRTMP_PRIVATE_SET_PROC->name == NULL)
105266 + { //Not found argument
105267 + Status = -EINVAL;
105268 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
105269 + }
105270 +
105271 + return Status;
105272 +}
105273 +
105274 +
105275 +static int
105276 +rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
105277 + struct iw_point *wrq, char *extra)
105278 +{
105279 + INT Status = 0;
105280 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
105281 +
105282 + if (extra == NULL)
105283 + {
105284 + wrq->length = 0;
105285 + return -EIO;
105286 + }
105287 +
105288 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
105289 + sprintf(extra, "\n\n");
105290 +
105291 +#ifdef RALINK_ATE
105292 + if (ATE_ON(pAd))
105293 + {
105294 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
105295 + //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
105296 + }
105297 + else
105298 +#endif // RALINK_ATE //
105299 + {
105300 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
105301 + sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
105302 + }
105303 + sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
105304 + sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
105305 + sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
105306 + sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
105307 +
105308 + sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
105309 + sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
105310 + sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
105311 + sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
105312 +
105313 + sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
105314 +#ifdef RALINK_ATE
105315 + if (ATE_ON(pAd))
105316 + {
105317 + if (pAd->ate.RxAntennaSel == 0)
105318 + {
105319 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
105320 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
105321 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
105322 + }
105323 + else
105324 + {
105325 + sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
105326 + }
105327 + }
105328 + else
105329 +#endif // RALINK_ATE //
105330 + {
105331 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
105332 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
105333 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
105334 + }
105335 +#ifdef WPA_SUPPLICANT_SUPPORT
105336 + sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
105337 +#endif // WPA_SUPPLICANT_SUPPORT //
105338 +
105339 +
105340 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105341 + DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
105342 +
105343 + return Status;
105344 +}
105345 +
105346 +#ifdef DOT11_N_SUPPORT
105347 +void getBaInfo(
105348 + IN PRTMP_ADAPTER pAd,
105349 + IN PUCHAR pOutBuf)
105350 +{
105351 + INT i, j;
105352 + BA_ORI_ENTRY *pOriBAEntry;
105353 + BA_REC_ENTRY *pRecBAEntry;
105354 +
105355 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
105356 + {
105357 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
105358 + if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
105359 + || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
105360 + {
105361 + sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
105362 + pOutBuf,
105363 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
105364 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
105365 +
105366 + sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
105367 + for (j=0; j < NUM_OF_TID; j++)
105368 + {
105369 + if (pEntry->BARecWcidArray[j] != 0)
105370 + {
105371 + pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
105372 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
105373 + }
105374 + }
105375 + sprintf(pOutBuf, "%s\n", pOutBuf);
105376 +
105377 + sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
105378 + for (j=0; j < NUM_OF_TID; j++)
105379 + {
105380 + if (pEntry->BAOriWcidArray[j] != 0)
105381 + {
105382 + pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
105383 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
105384 + }
105385 + }
105386 + sprintf(pOutBuf, "%s\n\n", pOutBuf);
105387 + }
105388 + if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
105389 + break;
105390 + }
105391 +
105392 + return;
105393 +}
105394 +#endif // DOT11_N_SUPPORT //
105395 +
105396 +static int
105397 +rt_private_show(struct net_device *dev, struct iw_request_info *info,
105398 + struct iw_point *wrq, char *extra)
105399 +{
105400 + INT Status = 0;
105401 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
105402 + PRTMP_ADAPTER pAd;
105403 + POS_COOKIE pObj;
105404 + u32 subcmd = wrq->flags;
105405 +
105406 + if (dev->priv_flags == INT_MAIN)
105407 + pAd = dev->priv;
105408 + else
105409 + {
105410 + pVirtualAd = dev->priv;
105411 + pAd = pVirtualAd->RtmpDev->priv;
105412 + }
105413 + pObj = (POS_COOKIE) pAd->OS_Cookie;
105414 +
105415 + if (pAd == NULL)
105416 + {
105417 + /* if 1st open fail, pAd will be free;
105418 + So the net_dev->priv will be NULL in 2rd open */
105419 + return -ENETDOWN;
105420 + }
105421 +
105422 + if (extra == NULL)
105423 + {
105424 + wrq->length = 0;
105425 + return -EIO;
105426 + }
105427 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
105428 +
105429 + {
105430 + pObj->ioctl_if_type = INT_MAIN;
105431 + pObj->ioctl_if = MAIN_MBSSID;
105432 + }
105433 +
105434 + switch(subcmd)
105435 + {
105436 +
105437 + case SHOW_CONN_STATUS:
105438 + if (MONITOR_ON(pAd))
105439 + {
105440 +#ifdef DOT11_N_SUPPORT
105441 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
105442 + pAd->CommonCfg.RegTransmitSetting.field.BW)
105443 + sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
105444 + else
105445 +#endif // DOT11_N_SUPPORT //
105446 + sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
105447 + }
105448 + else
105449 + {
105450 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
105451 + {
105452 + if (INFRA_ON(pAd))
105453 + {
105454 + sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
105455 + pAd->CommonCfg.Ssid,
105456 + pAd->CommonCfg.Bssid[0],
105457 + pAd->CommonCfg.Bssid[1],
105458 + pAd->CommonCfg.Bssid[2],
105459 + pAd->CommonCfg.Bssid[3],
105460 + pAd->CommonCfg.Bssid[4],
105461 + pAd->CommonCfg.Bssid[5]);
105462 + DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
105463 + }
105464 + else if (ADHOC_ON(pAd))
105465 + sprintf(extra, "Connected\n");
105466 + }
105467 + else
105468 + {
105469 + sprintf(extra, "Disconnected\n");
105470 + DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
105471 + }
105472 + }
105473 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105474 + break;
105475 + case SHOW_DRVIER_VERION:
105476 + sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
105477 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105478 + break;
105479 +#ifdef DOT11_N_SUPPORT
105480 + case SHOW_BA_INFO:
105481 + getBaInfo(pAd, extra);
105482 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105483 + break;
105484 +#endif // DOT11_N_SUPPORT //
105485 + case SHOW_DESC_INFO:
105486 + {
105487 + Show_DescInfo_Proc(pAd, NULL);
105488 + wrq->length = 0; // 1: size of '\0'
105489 + }
105490 + break;
105491 + case RAIO_OFF:
105492 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
105493 + {
105494 + sprintf(extra, "Scanning\n");
105495 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105496 + break;
105497 + }
105498 + pAd->StaCfg.bSwRadio = FALSE;
105499 + if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
105500 + {
105501 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
105502 + if (pAd->StaCfg.bRadio == FALSE)
105503 + {
105504 + MlmeRadioOff(pAd);
105505 + // Update extra information
105506 + pAd->ExtraInfo = SW_RADIO_OFF;
105507 + }
105508 + }
105509 + sprintf(extra, "Radio Off\n");
105510 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105511 + break;
105512 + case RAIO_ON:
105513 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
105514 + {
105515 + sprintf(extra, "Scanning\n");
105516 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105517 + break;
105518 + }
105519 + pAd->StaCfg.bSwRadio = TRUE;
105520 + //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
105521 + {
105522 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
105523 + if (pAd->StaCfg.bRadio == TRUE)
105524 + {
105525 + MlmeRadioOn(pAd);
105526 + // Update extra information
105527 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
105528 + }
105529 + }
105530 + sprintf(extra, "Radio On\n");
105531 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105532 + break;
105533 +
105534 +
105535 +#ifdef QOS_DLS_SUPPORT
105536 + case SHOW_DLS_ENTRY_INFO:
105537 + {
105538 + Set_DlsEntryInfo_Display_Proc(pAd, NULL);
105539 + wrq->length = 0; // 1: size of '\0'
105540 + }
105541 + break;
105542 +#endif // QOS_DLS_SUPPORT //
105543 +
105544 + case SHOW_CFG_VALUE:
105545 + {
105546 + Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
105547 + if (Status == 0)
105548 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105549 + }
105550 + break;
105551 + case SHOW_ADHOC_ENTRY_INFO:
105552 + Show_Adhoc_MacTable_Proc(pAd, extra);
105553 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
105554 + break;
105555 + default:
105556 + DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __FUNCTION__, subcmd));
105557 + break;
105558 + }
105559 +
105560 + return Status;
105561 +}
105562 +
105563 +#ifdef SIOCSIWMLME
105564 +int rt_ioctl_siwmlme(struct net_device *dev,
105565 + struct iw_request_info *info,
105566 + union iwreq_data *wrqu,
105567 + char *extra)
105568 +{
105569 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
105570 + struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
105571 + MLME_QUEUE_ELEM MsgElem;
105572 + MLME_DISASSOC_REQ_STRUCT DisAssocReq;
105573 + MLME_DEAUTH_REQ_STRUCT DeAuthReq;
105574 +
105575 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __FUNCTION__));
105576 +
105577 + if (pMlme == NULL)
105578 + return -EINVAL;
105579 +
105580 + switch(pMlme->cmd)
105581 + {
105582 +#ifdef IW_MLME_DEAUTH
105583 + case IW_MLME_DEAUTH:
105584 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __FUNCTION__));
105585 + COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
105586 + DeAuthReq.Reason = pMlme->reason_code;
105587 + MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
105588 + NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
105589 + MlmeDeauthReqAction(pAd, &MsgElem);
105590 + if (INFRA_ON(pAd))
105591 + {
105592 + LinkDown(pAd, FALSE);
105593 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
105594 + }
105595 + break;
105596 +#endif // IW_MLME_DEAUTH //
105597 +#ifdef IW_MLME_DISASSOC
105598 + case IW_MLME_DISASSOC:
105599 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __FUNCTION__));
105600 + COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
105601 + DisAssocReq.Reason = pMlme->reason_code;
105602 +
105603 + MsgElem.Machine = ASSOC_STATE_MACHINE;
105604 + MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
105605 + MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
105606 + NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
105607 +
105608 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
105609 + MlmeDisassocReqAction(pAd, &MsgElem);
105610 + break;
105611 +#endif // IW_MLME_DISASSOC //
105612 + default:
105613 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __FUNCTION__));
105614 + break;
105615 + }
105616 +
105617 + return 0;
105618 +}
105619 +#endif // SIOCSIWMLME //
105620 +
105621 +#if WIRELESS_EXT > 17
105622 +int rt_ioctl_siwauth(struct net_device *dev,
105623 + struct iw_request_info *info,
105624 + union iwreq_data *wrqu, char *extra)
105625 +{
105626 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
105627 + struct iw_param *param = &wrqu->param;
105628 +
105629 + //check if the interface is down
105630 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105631 + {
105632 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105633 + return -ENETDOWN;
105634 + }
105635 + switch (param->flags & IW_AUTH_INDEX) {
105636 + case IW_AUTH_WPA_VERSION:
105637 + if (param->value == IW_AUTH_WPA_VERSION_WPA)
105638 + {
105639 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
105640 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
105641 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
105642 + }
105643 + else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
105644 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
105645 +
105646 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
105647 + break;
105648 + case IW_AUTH_CIPHER_PAIRWISE:
105649 + if (param->value == IW_AUTH_CIPHER_NONE)
105650 + {
105651 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
105652 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105653 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
105654 + }
105655 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
105656 + param->value == IW_AUTH_CIPHER_WEP104)
105657 + {
105658 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
105659 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105660 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
105661 +#ifdef WPA_SUPPLICANT_SUPPORT
105662 + pAdapter->StaCfg.IEEE8021X = FALSE;
105663 +#endif // WPA_SUPPLICANT_SUPPORT //
105664 + }
105665 + else if (param->value == IW_AUTH_CIPHER_TKIP)
105666 + {
105667 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
105668 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105669 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
105670 + }
105671 + else if (param->value == IW_AUTH_CIPHER_CCMP)
105672 + {
105673 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
105674 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105675 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
105676 + }
105677 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __FUNCTION__, param->value));
105678 + break;
105679 + case IW_AUTH_CIPHER_GROUP:
105680 + if (param->value == IW_AUTH_CIPHER_NONE)
105681 + {
105682 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
105683 + }
105684 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
105685 + param->value == IW_AUTH_CIPHER_WEP104)
105686 + {
105687 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
105688 + }
105689 + else if (param->value == IW_AUTH_CIPHER_TKIP)
105690 + {
105691 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
105692 + }
105693 + else if (param->value == IW_AUTH_CIPHER_CCMP)
105694 + {
105695 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
105696 + }
105697 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __FUNCTION__, param->value));
105698 + break;
105699 + case IW_AUTH_KEY_MGMT:
105700 + if (param->value == IW_AUTH_KEY_MGMT_802_1X)
105701 + {
105702 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
105703 + {
105704 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
105705 +#ifdef WPA_SUPPLICANT_SUPPORT
105706 + pAdapter->StaCfg.IEEE8021X = FALSE;
105707 +#endif // WPA_SUPPLICANT_SUPPORT //
105708 + }
105709 + else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
105710 + {
105711 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
105712 +#ifdef WPA_SUPPLICANT_SUPPORT
105713 + pAdapter->StaCfg.IEEE8021X = FALSE;
105714 +#endif // WPA_SUPPLICANT_SUPPORT //
105715 + }
105716 +#ifdef WPA_SUPPLICANT_SUPPORT
105717 + else
105718 + // WEP 1x
105719 + pAdapter->StaCfg.IEEE8021X = TRUE;
105720 +#endif // WPA_SUPPLICANT_SUPPORT //
105721 + }
105722 + else if (param->value == 0)
105723 + {
105724 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105725 + STA_PORT_SECURED(pAdapter);
105726 + }
105727 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __FUNCTION__, param->value));
105728 + break;
105729 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
105730 + break;
105731 + case IW_AUTH_PRIVACY_INVOKED:
105732 + /*if (param->value == 0)
105733 + {
105734 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
105735 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
105736 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
105737 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
105738 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
105739 + }*/
105740 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __FUNCTION__, param->value));
105741 + break;
105742 + case IW_AUTH_DROP_UNENCRYPTED:
105743 + if (param->value != 0)
105744 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
105745 + else
105746 + {
105747 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105748 + STA_PORT_SECURED(pAdapter);
105749 + }
105750 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
105751 + break;
105752 + case IW_AUTH_80211_AUTH_ALG:
105753 + if (param->value & IW_AUTH_ALG_SHARED_KEY)
105754 + {
105755 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
105756 + }
105757 + else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
105758 + {
105759 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
105760 + }
105761 + else
105762 + return -EINVAL;
105763 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __FUNCTION__, param->value));
105764 + break;
105765 + case IW_AUTH_WPA_ENABLED:
105766 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __FUNCTION__, param->value));
105767 + break;
105768 + default:
105769 + return -EOPNOTSUPP;
105770 +}
105771 +
105772 + return 0;
105773 +}
105774 +
105775 +int rt_ioctl_giwauth(struct net_device *dev,
105776 + struct iw_request_info *info,
105777 + union iwreq_data *wrqu, char *extra)
105778 +{
105779 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
105780 + struct iw_param *param = &wrqu->param;
105781 +
105782 + //check if the interface is down
105783 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105784 + {
105785 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105786 + return -ENETDOWN;
105787 + }
105788 +
105789 + switch (param->flags & IW_AUTH_INDEX) {
105790 + case IW_AUTH_DROP_UNENCRYPTED:
105791 + param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
105792 + break;
105793 +
105794 + case IW_AUTH_80211_AUTH_ALG:
105795 + param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
105796 + break;
105797 +
105798 + case IW_AUTH_WPA_ENABLED:
105799 + param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
105800 + break;
105801 +
105802 + default:
105803 + return -EOPNOTSUPP;
105804 + }
105805 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
105806 + return 0;
105807 +}
105808 +
105809 +void fnSetCipherKey(
105810 + IN PRTMP_ADAPTER pAdapter,
105811 + IN INT keyIdx,
105812 + IN UCHAR CipherAlg,
105813 + IN BOOLEAN bGTK,
105814 + IN struct iw_encode_ext *ext)
105815 +{
105816 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
105817 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
105818 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
105819 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
105820 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
105821 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
105822 +
105823 + // Update group key information to ASIC Shared Key Table
105824 + AsicAddSharedKeyEntry(pAdapter,
105825 + BSS0,
105826 + keyIdx,
105827 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
105828 + pAdapter->SharedKey[BSS0][keyIdx].Key,
105829 + pAdapter->SharedKey[BSS0][keyIdx].TxMic,
105830 + pAdapter->SharedKey[BSS0][keyIdx].RxMic);
105831 +
105832 + if (bGTK)
105833 + // Update ASIC WCID attribute table and IVEIV table
105834 + RTMPAddWcidAttributeEntry(pAdapter,
105835 + BSS0,
105836 + keyIdx,
105837 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
105838 + NULL);
105839 + else
105840 + // Update ASIC WCID attribute table and IVEIV table
105841 + RTMPAddWcidAttributeEntry(pAdapter,
105842 + BSS0,
105843 + keyIdx,
105844 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
105845 + &pAdapter->MacTab.Content[BSSID_WCID]);
105846 +}
105847 +
105848 +int rt_ioctl_siwencodeext(struct net_device *dev,
105849 + struct iw_request_info *info,
105850 + union iwreq_data *wrqu,
105851 + char *extra)
105852 + {
105853 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
105854 + struct iw_point *encoding = &wrqu->encoding;
105855 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
105856 + int keyIdx, alg = ext->alg;
105857 +
105858 + //check if the interface is down
105859 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
105860 + {
105861 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
105862 + return -ENETDOWN;
105863 + }
105864 +
105865 + if (encoding->flags & IW_ENCODE_DISABLED)
105866 + {
105867 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
105868 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
105869 + AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
105870 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
105871 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
105872 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
105873 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
105874 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __FUNCTION__, encoding->flags));
105875 + }
105876 + else
105877 + {
105878 + // Get Key Index and convet to our own defined key index
105879 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
105880 + if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
105881 + return -EINVAL;
105882 +
105883 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
105884 + {
105885 + pAdapter->StaCfg.DefaultKeyId = keyIdx;
105886 + DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __FUNCTION__, pAdapter->StaCfg.DefaultKeyId));
105887 + }
105888 +
105889 + switch (alg) {
105890 + case IW_ENCODE_ALG_NONE:
105891 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __FUNCTION__));
105892 + break;
105893 + case IW_ENCODE_ALG_WEP:
105894 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __FUNCTION__, ext->key_len, keyIdx));
105895 + if (ext->key_len == MAX_WEP_KEY_SIZE)
105896 + {
105897 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
105898 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
105899 + }
105900 + else if (ext->key_len == MIN_WEP_KEY_SIZE)
105901 + {
105902 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
105903 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
105904 + }
105905 + else
105906 + return -EINVAL;
105907 +
105908 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
105909 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
105910 + break;
105911 + case IW_ENCODE_ALG_TKIP:
105912 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __FUNCTION__, keyIdx, ext->key_len));
105913 + if (ext->key_len == 32)
105914 + {
105915 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
105916 + {
105917 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
105918 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
105919 + {
105920 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105921 + STA_PORT_SECURED(pAdapter);
105922 + }
105923 + }
105924 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
105925 + {
105926 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
105927 +
105928 + // set 802.1x port control
105929 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105930 + STA_PORT_SECURED(pAdapter);
105931 + }
105932 + }
105933 + else
105934 + return -EINVAL;
105935 + break;
105936 + case IW_ENCODE_ALG_CCMP:
105937 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
105938 + {
105939 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
105940 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
105941 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105942 + STA_PORT_SECURED(pAdapter);
105943 + }
105944 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
105945 + {
105946 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
105947 +
105948 + // set 802.1x port control
105949 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
105950 + STA_PORT_SECURED(pAdapter);
105951 + }
105952 + break;
105953 + default:
105954 + return -EINVAL;
105955 + }
105956 + }
105957 +
105958 + return 0;
105959 +}
105960 +
105961 +int
105962 +rt_ioctl_giwencodeext(struct net_device *dev,
105963 + struct iw_request_info *info,
105964 + union iwreq_data *wrqu, char *extra)
105965 +{
105966 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
105967 + PCHAR pKey = NULL;
105968 + struct iw_point *encoding = &wrqu->encoding;
105969 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
105970 + int idx, max_key_len;
105971 +
105972 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
105973 +
105974 + max_key_len = encoding->length - sizeof(*ext);
105975 + if (max_key_len < 0)
105976 + return -EINVAL;
105977 +
105978 + idx = encoding->flags & IW_ENCODE_INDEX;
105979 + if (idx)
105980 + {
105981 + if (idx < 1 || idx > 4)
105982 + return -EINVAL;
105983 + idx--;
105984 +
105985 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
105986 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
105987 + {
105988 + if (idx != pAd->StaCfg.DefaultKeyId)
105989 + {
105990 + ext->key_len = 0;
105991 + return 0;
105992 + }
105993 + }
105994 + }
105995 + else
105996 + idx = pAd->StaCfg.DefaultKeyId;
105997 +
105998 + encoding->flags = idx + 1;
105999 + memset(ext, 0, sizeof(*ext));
106000 +
106001 + ext->key_len = 0;
106002 + switch(pAd->StaCfg.WepStatus) {
106003 + case Ndis802_11WEPDisabled:
106004 + ext->alg = IW_ENCODE_ALG_NONE;
106005 + encoding->flags |= IW_ENCODE_DISABLED;
106006 + break;
106007 + case Ndis802_11WEPEnabled:
106008 + ext->alg = IW_ENCODE_ALG_WEP;
106009 + if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
106010 + return -E2BIG;
106011 + else
106012 + {
106013 + ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
106014 + pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
106015 + }
106016 + break;
106017 + case Ndis802_11Encryption2Enabled:
106018 + case Ndis802_11Encryption3Enabled:
106019 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
106020 + ext->alg = IW_ENCODE_ALG_TKIP;
106021 + else
106022 + ext->alg = IW_ENCODE_ALG_CCMP;
106023 +
106024 + if (max_key_len < 32)
106025 + return -E2BIG;
106026 + else
106027 + {
106028 + ext->key_len = 32;
106029 + pKey = &pAd->StaCfg.PMK[0];
106030 + }
106031 + break;
106032 + default:
106033 + return -EINVAL;
106034 + }
106035 +
106036 + if (ext->key_len && pKey)
106037 + {
106038 + encoding->flags |= IW_ENCODE_ENABLED;
106039 + memcpy(ext->key, pKey, ext->key_len);
106040 + }
106041 +
106042 + return 0;
106043 +}
106044 +
106045 +#ifdef SIOCSIWGENIE
106046 +int rt_ioctl_siwgenie(struct net_device *dev,
106047 + struct iw_request_info *info,
106048 + union iwreq_data *wrqu, char *extra)
106049 +{
106050 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
106051 +
106052 + if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
106053 + (wrqu->data.length && extra == NULL))
106054 + return -EINVAL;
106055 +
106056 + if (wrqu->data.length)
106057 + {
106058 + pAd->StaCfg.RSNIE_Len = wrqu->data.length;
106059 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
106060 + }
106061 + else
106062 + {
106063 + pAd->StaCfg.RSNIE_Len = 0;
106064 + NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
106065 + }
106066 +
106067 + return 0;
106068 +}
106069 +#endif // SIOCSIWGENIE //
106070 +
106071 +int rt_ioctl_giwgenie(struct net_device *dev,
106072 + struct iw_request_info *info,
106073 + union iwreq_data *wrqu, char *extra)
106074 +{
106075 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
106076 +
106077 + if ((pAd->StaCfg.RSNIE_Len == 0) ||
106078 + (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
106079 + {
106080 + wrqu->data.length = 0;
106081 + return 0;
106082 + }
106083 +
106084 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
106085 +#ifdef SIOCSIWGENIE
106086 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
106087 + {
106088 + if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
106089 + return -E2BIG;
106090 +
106091 + wrqu->data.length = pAd->StaCfg.RSNIE_Len;
106092 + memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
106093 + }
106094 + else
106095 +#endif // SIOCSIWGENIE //
106096 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
106097 + {
106098 + UCHAR RSNIe = IE_WPA;
106099 +
106100 + if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
106101 + return -E2BIG;
106102 + wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
106103 +
106104 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
106105 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
106106 + RSNIe = IE_RSN;
106107 +
106108 + extra[0] = (char)RSNIe;
106109 + extra[1] = pAd->StaCfg.RSNIE_Len;
106110 + memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
106111 + }
106112 +
106113 + return 0;
106114 +}
106115 +
106116 +int rt_ioctl_siwpmksa(struct net_device *dev,
106117 + struct iw_request_info *info,
106118 + union iwreq_data *wrqu,
106119 + char *extra)
106120 +{
106121 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
106122 + struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
106123 + INT CachedIdx = 0, idx = 0;
106124 +
106125 + if (pPmksa == NULL)
106126 + return -EINVAL;
106127 +
106128 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
106129 + switch(pPmksa->cmd)
106130 + {
106131 + case IW_PMKSA_FLUSH:
106132 + NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
106133 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
106134 + break;
106135 + case IW_PMKSA_REMOVE:
106136 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
106137 + {
106138 + // compare the BSSID
106139 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
106140 + {
106141 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
106142 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
106143 + for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
106144 + {
106145 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
106146 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
106147 + }
106148 + pAd->StaCfg.SavedPMKNum--;
106149 + break;
106150 + }
106151 + }
106152 +
106153 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
106154 + break;
106155 + case IW_PMKSA_ADD:
106156 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
106157 + {
106158 + // compare the BSSID
106159 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
106160 + break;
106161 + }
106162 +
106163 + // Found, replace it
106164 + if (CachedIdx < PMKID_NO)
106165 + {
106166 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
106167 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
106168 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
106169 + pAd->StaCfg.SavedPMKNum++;
106170 + }
106171 + // Not found, replace the last one
106172 + else
106173 + {
106174 + // Randomly replace one
106175 + CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
106176 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
106177 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
106178 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
106179 + }
106180 +
106181 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
106182 + break;
106183 + default:
106184 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
106185 + break;
106186 + }
106187 +
106188 + return 0;
106189 +}
106190 +#endif // #if WIRELESS_EXT > 17
106191 +
106192 +#ifdef DBG
106193 +static int
106194 +rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
106195 + struct iw_point *wrq, char *extra)
106196 + {
106197 + CHAR *this_char;
106198 + CHAR *value = NULL;
106199 + UCHAR regBBP = 0;
106200 +// CHAR arg[255]={0};
106201 + UINT32 bbpId;
106202 + UINT32 bbpValue;
106203 + BOOLEAN bIsPrintAllBBP = FALSE;
106204 + INT Status = 0;
106205 + PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
106206 +
106207 +
106208 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
106209 +
106210 + if (wrq->length > 1) //No parameters.
106211 + {
106212 + sprintf(extra, "\n");
106213 +
106214 + //Parsing Read or Write
106215 + this_char = wrq->pointer;
106216 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
106217 + if (!*this_char)
106218 + goto next;
106219 +
106220 + if ((value = rtstrchr(this_char, '=')) != NULL)
106221 + *value++ = 0;
106222 +
106223 + if (!value || !*value)
106224 + { //Read
106225 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
106226 + if (sscanf(this_char, "%d", &(bbpId)) == 1)
106227 + {
106228 + if (bbpId <= 136)
106229 + {
106230 +#ifdef RALINK_ATE
106231 + if (ATE_ON(pAdapter))
106232 + {
106233 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106234 + }
106235 + else
106236 +#endif // RALINK_ATE //
106237 + {
106238 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106239 + }
106240 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
106241 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
106242 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
106243 + }
106244 + else
106245 + {//Invalid parametes, so default printk all bbp
106246 + bIsPrintAllBBP = TRUE;
106247 + goto next;
106248 + }
106249 + }
106250 + else
106251 + { //Invalid parametes, so default printk all bbp
106252 + bIsPrintAllBBP = TRUE;
106253 + goto next;
106254 + }
106255 + }
106256 + else
106257 + { //Write
106258 + if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
106259 + {
106260 + if (bbpId <= 136)
106261 + {
106262 +#ifdef RALINK_ATE
106263 + if (ATE_ON(pAdapter))
106264 + {
106265 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
106266 + //Read it back for showing
106267 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106268 + }
106269 + else
106270 +#endif // RALINK_ATE //
106271 + {
106272 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
106273 + //Read it back for showing
106274 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106275 + }
106276 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
106277 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
106278 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
106279 + }
106280 + else
106281 + {//Invalid parametes, so default printk all bbp
106282 + bIsPrintAllBBP = TRUE;
106283 + goto next;
106284 + }
106285 + }
106286 + else
106287 + { //Invalid parametes, so default printk all bbp
106288 + bIsPrintAllBBP = TRUE;
106289 + goto next;
106290 + }
106291 + }
106292 + }
106293 + else
106294 + bIsPrintAllBBP = TRUE;
106295 +
106296 +next:
106297 + if (bIsPrintAllBBP)
106298 + {
106299 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
106300 + sprintf(extra, "\n");
106301 + for (bbpId = 0; bbpId <= 136; bbpId++)
106302 + {
106303 + if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
106304 + break;
106305 +#ifdef RALINK_ATE
106306 + if (ATE_ON(pAdapter))
106307 + {
106308 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106309 + }
106310 + else
106311 +#endif // RALINK_ATE //
106312 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
106313 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
106314 + if (bbpId%5 == 4)
106315 + sprintf(extra+strlen(extra), "\n");
106316 + }
106317 +
106318 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
106319 + DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
106320 + }
106321 +
106322 + DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
106323 +
106324 + return Status;
106325 +}
106326 +#endif // DBG //
106327 +
106328 +int rt_ioctl_siwrate(struct net_device *dev,
106329 + struct iw_request_info *info,
106330 + union iwreq_data *wrqu, char *extra)
106331 +{
106332 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
106333 + UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
106334 +
106335 + //check if the interface is down
106336 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
106337 + {
106338 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
106339 + return -ENETDOWN;
106340 + }
106341 +
106342 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
106343 + /* rate = -1 => auto rate
106344 + rate = X, fixed = 1 => (fixed rate X)
106345 + */
106346 + if (rate == -1)
106347 + {
106348 + //Auto Rate
106349 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
106350 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
106351 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
106352 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
106353 + RTMPSetDesiredRates(pAd, -1);
106354 +
106355 +#ifdef DOT11_N_SUPPORT
106356 + SetCommonHT(pAd);
106357 +#endif // DOT11_N_SUPPORT //
106358 + }
106359 + else
106360 + {
106361 + if (fixed)
106362 + {
106363 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
106364 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
106365 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
106366 + RTMPSetDesiredRates(pAd, rate);
106367 + else
106368 + {
106369 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
106370 +#ifdef DOT11_N_SUPPORT
106371 + SetCommonHT(pAd);
106372 +#endif // DOT11_N_SUPPORT //
106373 + }
106374 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
106375 + }
106376 + else
106377 + {
106378 + // TODO: rate = X, fixed = 0 => (rates <= X)
106379 + return -EOPNOTSUPP;
106380 + }
106381 + }
106382 +
106383 + return 0;
106384 +}
106385 +
106386 +int rt_ioctl_giwrate(struct net_device *dev,
106387 + struct iw_request_info *info,
106388 + union iwreq_data *wrqu, char *extra)
106389 +{
106390 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) dev->priv;
106391 + int rate_index = 0, rate_count = 0;
106392 + HTTRANSMIT_SETTING ht_setting;
106393 + __s32 ralinkrate[] =
106394 + {2, 4, 11, 22, // CCK
106395 + 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
106396 + 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
106397 + 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
106398 + 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
106399 + 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
106400 + 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
106401 + 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
106402 + 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
106403 + 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
106404 +
106405 + rate_count = sizeof(ralinkrate)/sizeof(__s32);
106406 + //check if the interface is down
106407 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
106408 + {
106409 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
106410 + return -ENETDOWN;
106411 + }
106412 +
106413 + if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
106414 + (INFRA_ON(pAd)) &&
106415 + ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
106416 + ht_setting.word = pAd->StaCfg.HTPhyMode.word;
106417 + else
106418 + ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
106419 +
106420 +#ifdef DOT11_N_SUPPORT
106421 + if (ht_setting.field.MODE >= MODE_HTMIX)
106422 + {
106423 +// rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
106424 + rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
106425 + }
106426 + else
106427 +#endif // DOT11_N_SUPPORT //
106428 + if (ht_setting.field.MODE == MODE_OFDM)
106429 + rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
106430 + else if (ht_setting.field.MODE == MODE_CCK)
106431 + rate_index = (UCHAR)(ht_setting.field.MCS);
106432 +
106433 + if (rate_index < 0)
106434 + rate_index = 0;
106435 +
106436 + if (rate_index > rate_count)
106437 + rate_index = rate_count;
106438 +
106439 + wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
106440 + wrqu->bitrate.disabled = 0;
106441 +
106442 + return 0;
106443 +}
106444 +
106445 +static const iw_handler rt_handler[] =
106446 +{
106447 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
106448 + (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
106449 + (iw_handler) NULL, /* SIOCSIWNWID */
106450 + (iw_handler) NULL, /* SIOCGIWNWID */
106451 + (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
106452 + (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
106453 + (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
106454 + (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
106455 + (iw_handler) NULL, /* SIOCSIWSENS */
106456 + (iw_handler) NULL, /* SIOCGIWSENS */
106457 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
106458 + (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
106459 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
106460 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
106461 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
106462 + (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
106463 + (iw_handler) NULL, /* SIOCSIWSPY */
106464 + (iw_handler) NULL, /* SIOCGIWSPY */
106465 + (iw_handler) NULL, /* SIOCSIWTHRSPY */
106466 + (iw_handler) NULL, /* SIOCGIWTHRSPY */
106467 + (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
106468 + (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
106469 +#ifdef SIOCSIWMLME
106470 + (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
106471 +#else
106472 + (iw_handler) NULL, /* SIOCSIWMLME */
106473 +#endif // SIOCSIWMLME //
106474 + (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
106475 +#ifdef SIOCGIWSCAN
106476 + (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
106477 + (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
106478 +#else
106479 + (iw_handler) NULL, /* SIOCSIWSCAN */
106480 + (iw_handler) NULL, /* SIOCGIWSCAN */
106481 +#endif /* SIOCGIWSCAN */
106482 + (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
106483 + (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
106484 + (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
106485 + (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
106486 + (iw_handler) NULL, /* -- hole -- */
106487 + (iw_handler) NULL, /* -- hole -- */
106488 + (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
106489 + (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
106490 + (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
106491 + (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
106492 + (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
106493 + (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
106494 + (iw_handler) NULL, /* SIOCSIWTXPOW */
106495 + (iw_handler) NULL, /* SIOCGIWTXPOW */
106496 + (iw_handler) NULL, /* SIOCSIWRETRY */
106497 + (iw_handler) NULL, /* SIOCGIWRETRY */
106498 + (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
106499 + (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
106500 + (iw_handler) NULL, /* SIOCSIWPOWER */
106501 + (iw_handler) NULL, /* SIOCGIWPOWER */
106502 + (iw_handler) NULL, /* -- hole -- */
106503 + (iw_handler) NULL, /* -- hole -- */
106504 +#if WIRELESS_EXT > 17
106505 + (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
106506 + (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
106507 + (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
106508 + (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
106509 + (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
106510 + (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
106511 + (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
106512 +#endif
106513 +};
106514 +
106515 +static const iw_handler rt_priv_handlers[] = {
106516 + (iw_handler) NULL, /* + 0x00 */
106517 + (iw_handler) NULL, /* + 0x01 */
106518 +#ifndef CONFIG_AP_SUPPORT
106519 + (iw_handler) rt_ioctl_setparam, /* + 0x02 */
106520 +#else
106521 + (iw_handler) NULL, /* + 0x02 */
106522 +#endif // CONFIG_AP_SUPPORT //
106523 +#ifdef DBG
106524 + (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
106525 +#else
106526 + (iw_handler) NULL, /* + 0x03 */
106527 +#endif
106528 + (iw_handler) NULL, /* + 0x04 */
106529 + (iw_handler) NULL, /* + 0x05 */
106530 + (iw_handler) NULL, /* + 0x06 */
106531 + (iw_handler) NULL, /* + 0x07 */
106532 + (iw_handler) NULL, /* + 0x08 */
106533 + (iw_handler) rt_private_get_statistics, /* + 0x09 */
106534 + (iw_handler) NULL, /* + 0x0A */
106535 + (iw_handler) NULL, /* + 0x0B */
106536 + (iw_handler) NULL, /* + 0x0C */
106537 + (iw_handler) NULL, /* + 0x0D */
106538 + (iw_handler) NULL, /* + 0x0E */
106539 + (iw_handler) NULL, /* + 0x0F */
106540 + (iw_handler) NULL, /* + 0x10 */
106541 + (iw_handler) rt_private_show, /* + 0x11 */
106542 + (iw_handler) NULL, /* + 0x12 */
106543 + (iw_handler) NULL, /* + 0x13 */
106544 + (iw_handler) NULL, /* + 0x15 */
106545 + (iw_handler) NULL, /* + 0x17 */
106546 + (iw_handler) NULL, /* + 0x18 */
106547 +};
106548 +
106549 +const struct iw_handler_def rt28xx_iw_handler_def =
106550 +{
106551 +#define N(a) (sizeof (a) / sizeof (a[0]))
106552 + .standard = (iw_handler *) rt_handler,
106553 + .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
106554 + .private = (iw_handler *) rt_priv_handlers,
106555 + .num_private = N(rt_priv_handlers),
106556 + .private_args = (struct iw_priv_args *) privtab,
106557 + .num_private_args = N(privtab),
106558 +#if IW_HANDLER_VERSION >= 7
106559 + .get_wireless_stats = rt28xx_get_wireless_stats,
106560 +#endif
106561 +};
106562 +
106563 +INT RTMPSetInformation(
106564 + IN PRTMP_ADAPTER pAdapter,
106565 + IN OUT struct ifreq *rq,
106566 + IN INT cmd)
106567 +{
106568 + struct iwreq *wrq = (struct iwreq *) rq;
106569 + NDIS_802_11_SSID Ssid;
106570 + NDIS_802_11_MAC_ADDRESS Bssid;
106571 + RT_802_11_PHY_MODE PhyMode;
106572 + RT_802_11_STA_CONFIG StaConfig;
106573 + NDIS_802_11_RATES aryRates;
106574 + RT_802_11_PREAMBLE Preamble;
106575 + NDIS_802_11_WEP_STATUS WepStatus;
106576 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
106577 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
106578 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
106579 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
106580 + NDIS_802_11_POWER_MODE PowerMode;
106581 + PNDIS_802_11_KEY pKey = NULL;
106582 + PNDIS_802_11_WEP pWepKey =NULL;
106583 + PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
106584 + NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
106585 + NDIS_802_11_NETWORK_TYPE NetType;
106586 + ULONG Now;
106587 + UINT KeyIdx = 0;
106588 + INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
106589 + ULONG PowerTemp;
106590 + BOOLEAN RadioState;
106591 + BOOLEAN StateMachineTouched = FALSE;
106592 +#ifdef DOT11_N_SUPPORT
106593 + OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
106594 +#endif // DOT11_N_SUPPORT //
106595 +#ifdef WPA_SUPPLICANT_SUPPORT
106596 + PNDIS_802_11_PMKID pPmkId = NULL;
106597 + BOOLEAN IEEE8021xState = FALSE;
106598 + BOOLEAN IEEE8021x_required_keys = FALSE;
106599 + UCHAR wpa_supplicant_enable = 0;
106600 +#endif // WPA_SUPPLICANT_SUPPORT //
106601 +
106602 +#ifdef SNMP_SUPPORT
106603 + TX_RTY_CFG_STRUC tx_rty_cfg;
106604 + ULONG ShortRetryLimit, LongRetryLimit;
106605 + UCHAR ctmp;
106606 +#endif // SNMP_SUPPORT //
106607 +
106608 +
106609 +
106610 +#ifdef DOT11_N_SUPPORT
106611 + MaxPhyMode = PHY_11N_5G;
106612 +#endif // DOT11_N_SUPPORT //
106613 +
106614 +
106615 + DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
106616 + switch(cmd & 0x7FFF) {
106617 + case RT_OID_802_11_COUNTRY_REGION:
106618 + if (wrq->u.data.length < sizeof(UCHAR))
106619 + Status = -EINVAL;
106620 + // Only avaliable when EEPROM not programming
106621 + else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
106622 + {
106623 + ULONG Country;
106624 + UCHAR TmpPhy;
106625 +
106626 + Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
106627 + pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
106628 + pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
106629 + TmpPhy = pAdapter->CommonCfg.PhyMode;
106630 + pAdapter->CommonCfg.PhyMode = 0xff;
106631 + // Build all corresponding channel information
106632 + RTMPSetPhyMode(pAdapter, TmpPhy);
106633 +#ifdef DOT11_N_SUPPORT
106634 + SetCommonHT(pAdapter);
106635 +#endif // DOT11_N_SUPPORT //
106636 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
106637 + pAdapter->CommonCfg.CountryRegion));
106638 + }
106639 + break;
106640 + case OID_802_11_BSSID_LIST_SCAN:
106641 + #ifdef RALINK_ATE
106642 + if (ATE_ON(pAdapter))
106643 + {
106644 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
106645 + break;
106646 + }
106647 +#endif // RALINK_ATE //
106648 + Now = jiffies;
106649 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
106650 +
106651 + if (MONITOR_ON(pAdapter))
106652 + {
106653 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
106654 + break;
106655 + }
106656 +
106657 + //Benson add 20080527, when radio off, sta don't need to scan
106658 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
106659 + break;
106660 +
106661 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
106662 + {
106663 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
106664 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
106665 + Status = NDIS_STATUS_SUCCESS;
106666 + break;
106667 + }
106668 +
106669 + if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
106670 + {
106671 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
106672 + Status = NDIS_STATUS_SUCCESS;
106673 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
106674 + break;
106675 + }
106676 +
106677 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
106678 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
106679 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
106680 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
106681 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
106682 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
106683 + {
106684 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
106685 + Status = NDIS_STATUS_SUCCESS;
106686 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
106687 + break;
106688 + }
106689 +
106690 +
106691 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
106692 + {
106693 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
106694 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
106695 + }
106696 +
106697 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
106698 + // this request, because this request is initiated by NDIS.
106699 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
106700 + // Reset allowed scan retries
106701 + pAdapter->StaCfg.ScanCnt = 0;
106702 + pAdapter->StaCfg.LastScanTime = Now;
106703 +
106704 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
106705 + RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
106706 + MlmeEnqueue(pAdapter,
106707 + MLME_CNTL_STATE_MACHINE,
106708 + OID_802_11_BSSID_LIST_SCAN,
106709 + 0,
106710 + NULL);
106711 +
106712 + Status = NDIS_STATUS_SUCCESS;
106713 + StateMachineTouched = TRUE;
106714 + break;
106715 + case OID_802_11_SSID:
106716 + if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
106717 + Status = -EINVAL;
106718 + else
106719 + {
106720 + PCHAR pSsidString = NULL;
106721 + Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
106722 +
106723 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
106724 + if (Ssid.SsidLength > MAX_LEN_OF_SSID)
106725 + Status = -EINVAL;
106726 + else
106727 + {
106728 + if (Ssid.SsidLength == 0)
106729 + {
106730 + Set_SSID_Proc(pAdapter, "");
106731 + }
106732 + else
106733 + {
106734 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
106735 + if (pSsidString)
106736 + {
106737 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
106738 + NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
106739 + Set_SSID_Proc(pAdapter, pSsidString);
106740 + kfree(pSsidString);
106741 + }
106742 + else
106743 + Status = -ENOMEM;
106744 + }
106745 + }
106746 + }
106747 + break;
106748 + case OID_802_11_BSSID:
106749 +#ifdef RALINK_ATE
106750 + if (ATE_ON(pAdapter))
106751 + {
106752 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
106753 + break;
106754 + }
106755 +#endif // RALINK_ATE //
106756 + if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
106757 + Status = -EINVAL;
106758 + else
106759 + {
106760 + Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
106761 +
106762 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
106763 + // this request, because this request is initiated by NDIS.
106764 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
106765 +
106766 + // Prevent to connect AP again in STAMlmePeriodicExec
106767 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
106768 +
106769 + // Reset allowed scan retries
106770 + pAdapter->StaCfg.ScanCnt = 0;
106771 +
106772 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
106773 + {
106774 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
106775 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
106776 + }
106777 + MlmeEnqueue(pAdapter,
106778 + MLME_CNTL_STATE_MACHINE,
106779 + OID_802_11_BSSID,
106780 + sizeof(NDIS_802_11_MAC_ADDRESS),
106781 + (VOID *)&Bssid);
106782 + Status = NDIS_STATUS_SUCCESS;
106783 + StateMachineTouched = TRUE;
106784 +
106785 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
106786 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
106787 + }
106788 + break;
106789 + case RT_OID_802_11_RADIO:
106790 + if (wrq->u.data.length != sizeof(BOOLEAN))
106791 + Status = -EINVAL;
106792 + else
106793 + {
106794 + Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
106795 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
106796 + if (pAdapter->StaCfg.bSwRadio != RadioState)
106797 + {
106798 + pAdapter->StaCfg.bSwRadio = RadioState;
106799 + if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
106800 + {
106801 + pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
106802 + if (pAdapter->StaCfg.bRadio == TRUE)
106803 + {
106804 + MlmeRadioOn(pAdapter);
106805 + // Update extra information
106806 + pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
106807 + }
106808 + else
106809 + {
106810 + MlmeRadioOff(pAdapter);
106811 + // Update extra information
106812 + pAdapter->ExtraInfo = SW_RADIO_OFF;
106813 + }
106814 + }
106815 + }
106816 + }
106817 + break;
106818 + case RT_OID_802_11_PHY_MODE:
106819 + if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
106820 + Status = -EINVAL;
106821 + else
106822 + {
106823 + Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
106824 + if (PhyMode <= MaxPhyMode)
106825 + {
106826 + RTMPSetPhyMode(pAdapter, PhyMode);
106827 +#ifdef DOT11_N_SUPPORT
106828 + SetCommonHT(pAdapter);
106829 +#endif // DOT11_N_SUPPORT //
106830 + }
106831 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
106832 + }
106833 + break;
106834 + case RT_OID_802_11_STA_CONFIG:
106835 + if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
106836 + Status = -EINVAL;
106837 + else
106838 + {
106839 + Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
106840 + pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
106841 + pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
106842 + pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
106843 + if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
106844 + (StaConfig.AdhocMode <= MaxPhyMode))
106845 + {
106846 + // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
106847 + // if setting changed, need to reset current TX rate as well as BEACON frame format
106848 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
106849 + {
106850 + pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
106851 + RTMPSetPhyMode(pAdapter, PhyMode);
106852 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
106853 + MakeIbssBeacon(pAdapter); // re-build BEACON frame
106854 + AsicEnableIbssSync(pAdapter); // copy to on-chip memory
106855 + }
106856 + }
106857 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
106858 + pAdapter->CommonCfg.bEnableTxBurst,
106859 + pAdapter->CommonCfg.UseBGProtection,
106860 + pAdapter->CommonCfg.bUseShortSlotTime));
106861 + }
106862 + break;
106863 + case OID_802_11_DESIRED_RATES:
106864 + if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
106865 + Status = -EINVAL;
106866 + else
106867 + {
106868 + Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
106869 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
106870 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
106871 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
106872 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
106873 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
106874 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
106875 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
106876 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
106877 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
106878 + }
106879 + break;
106880 + case RT_OID_802_11_PREAMBLE:
106881 + if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
106882 + Status = -EINVAL;
106883 + else
106884 + {
106885 + Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
106886 + if (Preamble == Rt802_11PreambleShort)
106887 + {
106888 + pAdapter->CommonCfg.TxPreamble = Preamble;
106889 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
106890 + }
106891 + else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
106892 + {
106893 + // if user wants AUTO, initialize to LONG here, then change according to AP's
106894 + // capability upon association.
106895 + pAdapter->CommonCfg.TxPreamble = Preamble;
106896 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
106897 + }
106898 + else
106899 + {
106900 + Status = -EINVAL;
106901 + break;
106902 + }
106903 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
106904 + }
106905 + break;
106906 + case OID_802_11_WEP_STATUS:
106907 + if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
106908 + Status = -EINVAL;
106909 + else
106910 + {
106911 + Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
106912 + // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
106913 + if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
106914 + {
106915 + if (pAdapter->StaCfg.WepStatus != WepStatus)
106916 + {
106917 + // Config has changed
106918 + pAdapter->bConfigChanged = TRUE;
106919 + }
106920 + pAdapter->StaCfg.WepStatus = WepStatus;
106921 + pAdapter->StaCfg.OrigWepStatus = WepStatus;
106922 + pAdapter->StaCfg.PairCipher = WepStatus;
106923 + pAdapter->StaCfg.GroupCipher = WepStatus;
106924 + }
106925 + else
106926 + {
106927 + Status = -EINVAL;
106928 + break;
106929 + }
106930 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
106931 + }
106932 + break;
106933 + case OID_802_11_AUTHENTICATION_MODE:
106934 + if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
106935 + Status = -EINVAL;
106936 + else
106937 + {
106938 + Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
106939 + if (AuthMode > Ndis802_11AuthModeMax)
106940 + {
106941 + Status = -EINVAL;
106942 + break;
106943 + }
106944 + else
106945 + {
106946 + if (pAdapter->StaCfg.AuthMode != AuthMode)
106947 + {
106948 + // Config has changed
106949 + pAdapter->bConfigChanged = TRUE;
106950 + }
106951 + pAdapter->StaCfg.AuthMode = AuthMode;
106952 + }
106953 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
106954 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
106955 + }
106956 + break;
106957 + case OID_802_11_INFRASTRUCTURE_MODE:
106958 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
106959 + Status = -EINVAL;
106960 + else
106961 + {
106962 + Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
106963 +
106964 + if (BssType == Ndis802_11IBSS)
106965 + Set_NetworkType_Proc(pAdapter, "Adhoc");
106966 + else if (BssType == Ndis802_11Infrastructure)
106967 + Set_NetworkType_Proc(pAdapter, "Infra");
106968 + else if (BssType == Ndis802_11Monitor)
106969 + Set_NetworkType_Proc(pAdapter, "Monitor");
106970 + else
106971 + {
106972 + Status = -EINVAL;
106973 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
106974 + }
106975 + }
106976 + break;
106977 + case OID_802_11_REMOVE_WEP:
106978 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
106979 + if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
106980 + {
106981 + Status = -EINVAL;
106982 + }
106983 + else
106984 + {
106985 + KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
106986 +
106987 + if (KeyIdx & 0x80000000)
106988 + {
106989 + // Should never set default bit when remove key
106990 + Status = -EINVAL;
106991 + }
106992 + else
106993 + {
106994 + KeyIdx = KeyIdx & 0x0fffffff;
106995 + if (KeyIdx >= 4){
106996 + Status = -EINVAL;
106997 + }
106998 + else
106999 + {
107000 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
107001 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
107002 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
107003 + }
107004 + }
107005 + }
107006 + break;
107007 + case RT_OID_802_11_RESET_COUNTERS:
107008 + NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
107009 + NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
107010 + NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
107011 + pAdapter->Counters8023.RxNoBuffer = 0;
107012 + pAdapter->Counters8023.GoodReceives = 0;
107013 + pAdapter->Counters8023.RxNoBuffer = 0;
107014 +#ifdef RT2870
107015 + pAdapter->BulkOutComplete = 0;
107016 + pAdapter->BulkOutCompleteOther= 0;
107017 + pAdapter->BulkOutCompleteCancel = 0;
107018 + pAdapter->BulkOutReq = 0;
107019 + pAdapter->BulkInReq= 0;
107020 + pAdapter->BulkInComplete = 0;
107021 + pAdapter->BulkInCompleteFail = 0;
107022 +#endif // RT2870 //
107023 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
107024 + break;
107025 + case OID_802_11_RTS_THRESHOLD:
107026 + if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
107027 + Status = -EINVAL;
107028 + else
107029 + {
107030 + Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
107031 + if (RtsThresh > MAX_RTS_THRESHOLD)
107032 + Status = -EINVAL;
107033 + else
107034 + pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
107035 + }
107036 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
107037 + break;
107038 + case OID_802_11_FRAGMENTATION_THRESHOLD:
107039 + if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
107040 + Status = -EINVAL;
107041 + else
107042 + {
107043 + Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
107044 + pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
107045 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
107046 + {
107047 + if (FragThresh == 0)
107048 + {
107049 + pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
107050 + pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
107051 + }
107052 + else
107053 + Status = -EINVAL;
107054 + }
107055 + else
107056 + pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
107057 + }
107058 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
107059 + break;
107060 + case OID_802_11_POWER_MODE:
107061 + if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
107062 + Status = -EINVAL;
107063 + else
107064 + {
107065 + Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
107066 + if (PowerMode == Ndis802_11PowerModeCAM)
107067 + Set_PSMode_Proc(pAdapter, "CAM");
107068 + else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
107069 + Set_PSMode_Proc(pAdapter, "Max_PSP");
107070 + else if (PowerMode == Ndis802_11PowerModeFast_PSP)
107071 + Set_PSMode_Proc(pAdapter, "Fast_PSP");
107072 + else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
107073 + Set_PSMode_Proc(pAdapter, "Legacy_PSP");
107074 + else
107075 + Status = -EINVAL;
107076 + }
107077 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
107078 + break;
107079 + case RT_OID_802_11_TX_POWER_LEVEL_1:
107080 + if (wrq->u.data.length < sizeof(ULONG))
107081 + Status = -EINVAL;
107082 + else
107083 + {
107084 + Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
107085 + if (PowerTemp > 100)
107086 + PowerTemp = 0xffffffff; // AUTO
107087 + pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
107088 + pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
107089 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
107090 + }
107091 + break;
107092 + case OID_802_11_NETWORK_TYPE_IN_USE:
107093 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
107094 + Status = -EINVAL;
107095 + else
107096 + {
107097 + Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
107098 +
107099 + if (NetType == Ndis802_11DS)
107100 + RTMPSetPhyMode(pAdapter, PHY_11B);
107101 + else if (NetType == Ndis802_11OFDM24)
107102 + RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
107103 + else if (NetType == Ndis802_11OFDM5)
107104 + RTMPSetPhyMode(pAdapter, PHY_11A);
107105 + else
107106 + Status = -EINVAL;
107107 +#ifdef DOT11_N_SUPPORT
107108 + if (Status == NDIS_STATUS_SUCCESS)
107109 + SetCommonHT(pAdapter);
107110 +#endif // DOT11_N_SUPPORT //
107111 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
107112 + }
107113 + break;
107114 + // For WPA PSK PMK key
107115 + case RT_OID_802_11_ADD_WPA:
107116 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107117 + if(pKey == NULL)
107118 + {
107119 + Status = -ENOMEM;
107120 + break;
107121 + }
107122 +
107123 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
107124 + if (pKey->Length != wrq->u.data.length)
107125 + {
107126 + Status = -EINVAL;
107127 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
107128 + }
107129 + else
107130 + {
107131 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
107132 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
107133 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
107134 + {
107135 + Status = -EOPNOTSUPP;
107136 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
107137 + }
107138 + else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
107139 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
107140 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
107141 + {
107142 + NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
107143 + // Use RaConfig as PSK agent.
107144 + // Start STA supplicant state machine
107145 + if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
107146 + pAdapter->StaCfg.WpaState = SS_START;
107147 +
107148 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
107149 + }
107150 + else
107151 + {
107152 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
107153 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
107154 + }
107155 + }
107156 + kfree(pKey);
107157 + break;
107158 + case OID_802_11_REMOVE_KEY:
107159 + pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107160 + if(pRemoveKey == NULL)
107161 + {
107162 + Status = -ENOMEM;
107163 + break;
107164 + }
107165 +
107166 + Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
107167 + if (pRemoveKey->Length != wrq->u.data.length)
107168 + {
107169 + Status = -EINVAL;
107170 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
107171 + }
107172 + else
107173 + {
107174 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
107175 + {
107176 + RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
107177 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
107178 + }
107179 + else
107180 + {
107181 + KeyIdx = pRemoveKey->KeyIndex;
107182 +
107183 + if (KeyIdx & 0x80000000)
107184 + {
107185 + // Should never set default bit when remove key
107186 + Status = -EINVAL;
107187 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
107188 + }
107189 + else
107190 + {
107191 + KeyIdx = KeyIdx & 0x0fffffff;
107192 + if (KeyIdx > 3)
107193 + {
107194 + Status = -EINVAL;
107195 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
107196 + }
107197 + else
107198 + {
107199 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
107200 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
107201 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
107202 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
107203 + }
107204 + }
107205 + }
107206 + }
107207 + kfree(pRemoveKey);
107208 + break;
107209 + // New for WPA
107210 + case OID_802_11_ADD_KEY:
107211 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107212 + if(pKey == NULL)
107213 + {
107214 + Status = -ENOMEM;
107215 + break;
107216 + }
107217 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
107218 + if (pKey->Length != wrq->u.data.length)
107219 + {
107220 + Status = -EINVAL;
107221 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
107222 + }
107223 + else
107224 + {
107225 + RTMPAddKey(pAdapter, pKey);
107226 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
107227 + }
107228 + kfree(pKey);
107229 + break;
107230 + case OID_802_11_CONFIGURATION:
107231 + if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
107232 + Status = -EINVAL;
107233 + else
107234 + {
107235 + Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
107236 + pConfig = &Config;
107237 +
107238 + if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
107239 + pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
107240 +
107241 + pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
107242 + MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
107243 + //
107244 + // Save the channel on MlmeAux for CntlOidRTBssidProc used.
107245 + //
107246 + pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
107247 +
107248 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
107249 + pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
107250 + // Config has changed
107251 + pAdapter->bConfigChanged = TRUE;
107252 + }
107253 + break;
107254 +#ifdef DOT11_N_SUPPORT
107255 + case RT_OID_802_11_SET_HT_PHYMODE:
107256 + if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
107257 + Status = -EINVAL;
107258 + else
107259 + {
107260 + POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
107261 +
107262 + Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
107263 + DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
107264 + pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
107265 + pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
107266 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
107267 + RTMPSetHT(pAdapter, pHTPhyMode);
107268 + }
107269 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
107270 + pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
107271 + pAdapter->StaCfg.HTPhyMode.field.STBC));
107272 + break;
107273 +#endif // DOT11_N_SUPPORT //
107274 + case RT_OID_802_11_SET_APSD_SETTING:
107275 + if (wrq->u.data.length != sizeof(ULONG))
107276 + Status = -EINVAL;
107277 + else
107278 + {
107279 + ULONG apsd ;
107280 + Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
107281 +
107282 + /*-------------------------------------------------------------------
107283 + |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
107284 + ---------------------------------------------------------------------
107285 + | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
107286 + ---------------------------------------------------------------------*/
107287 + pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
107288 + pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
107289 + pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
107290 + pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
107291 + pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
107292 + pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
107293 +
107294 + 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,
107295 + pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
107296 + }
107297 + break;
107298 +
107299 + case RT_OID_802_11_SET_APSD_PSM:
107300 + if (wrq->u.data.length != sizeof(ULONG))
107301 + Status = -EINVAL;
107302 + else
107303 + {
107304 + // Driver needs to notify AP when PSM changes
107305 + Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
107306 + if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
107307 + {
107308 + MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
107309 + RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
107310 + }
107311 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
107312 + }
107313 + break;
107314 +#ifdef QOS_DLS_SUPPORT
107315 + case RT_OID_802_11_SET_DLS:
107316 + if (wrq->u.data.length != sizeof(ULONG))
107317 + Status = -EINVAL;
107318 + else
107319 + {
107320 + BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
107321 + Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
107322 + if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
107323 + {
107324 + int i;
107325 + // tear down local dls table entry
107326 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
107327 + {
107328 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
107329 + {
107330 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
107331 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
107332 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
107333 + }
107334 + }
107335 +
107336 + // tear down peer dls table entry
107337 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
107338 + {
107339 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
107340 + {
107341 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
107342 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
107343 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
107344 + }
107345 + }
107346 + }
107347 +
107348 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
107349 + }
107350 + break;
107351 +
107352 + case RT_OID_802_11_SET_DLS_PARAM:
107353 + if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
107354 + Status = -EINVAL;
107355 + else
107356 + {
107357 + RT_802_11_DLS Dls;
107358 +
107359 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
107360 + RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
107361 + MlmeEnqueue(pAdapter,
107362 + MLME_CNTL_STATE_MACHINE,
107363 + RT_OID_802_11_SET_DLS_PARAM,
107364 + sizeof(RT_802_11_DLS),
107365 + &Dls);
107366 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
107367 + }
107368 + break;
107369 +#endif // QOS_DLS_SUPPORT //
107370 + case RT_OID_802_11_SET_WMM:
107371 + if (wrq->u.data.length != sizeof(BOOLEAN))
107372 + Status = -EINVAL;
107373 + else
107374 + {
107375 + Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
107376 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
107377 + }
107378 + break;
107379 +
107380 + case OID_802_11_DISASSOCIATE:
107381 +#ifdef RALINK_ATE
107382 + if (ATE_ON(pAdapter))
107383 + {
107384 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
107385 + break;
107386 + }
107387 +#endif // RALINK_ATE //
107388 + //
107389 + // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
107390 + // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
107391 + // when query OID_802_11_BSSID_LIST.
107392 + //
107393 + // TRUE: NumberOfItems will set to 0.
107394 + // FALSE: NumberOfItems no change.
107395 + //
107396 + pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
107397 + // Set to immediately send the media disconnect event
107398 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
107399 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
107400 +
107401 + if (INFRA_ON(pAdapter))
107402 + {
107403 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
107404 + {
107405 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
107406 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
107407 + }
107408 +
107409 + MlmeEnqueue(pAdapter,
107410 + MLME_CNTL_STATE_MACHINE,
107411 + OID_802_11_DISASSOCIATE,
107412 + 0,
107413 + NULL);
107414 +
107415 + StateMachineTouched = TRUE;
107416 + }
107417 + break;
107418 +
107419 +#ifdef DOT11_N_SUPPORT
107420 + case RT_OID_802_11_SET_IMME_BA_CAP:
107421 + if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
107422 + Status = -EINVAL;
107423 + else
107424 + {
107425 + OID_BACAP_STRUC Orde ;
107426 + Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
107427 + if (Orde.Policy > BA_NOTUSE)
107428 + {
107429 + Status = NDIS_STATUS_INVALID_DATA;
107430 + }
107431 + else if (Orde.Policy == BA_NOTUSE)
107432 + {
107433 + pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
107434 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
107435 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
107436 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
107437 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
107438 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
107439 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
107440 + // UPdata to HT IE
107441 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
107442 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
107443 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
107444 + }
107445 + else
107446 + {
107447 + pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
107448 + pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
107449 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
107450 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
107451 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
107452 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
107453 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
107454 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
107455 +
107456 + // UPdata to HT IE
107457 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
107458 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
107459 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
107460 +
107461 + if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
107462 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
107463 +
107464 + }
107465 +
107466 + pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
107467 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
107468 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
107469 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
107470 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
107471 + }
107472 +
107473 + break;
107474 + case RT_OID_802_11_ADD_IMME_BA:
107475 + DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
107476 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
107477 + Status = -EINVAL;
107478 + else
107479 + {
107480 + UCHAR index;
107481 + OID_ADD_BA_ENTRY BA;
107482 + MAC_TABLE_ENTRY *pEntry;
107483 +
107484 + Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
107485 + if (BA.TID > 15)
107486 + {
107487 + Status = NDIS_STATUS_INVALID_DATA;
107488 + break;
107489 + }
107490 + else
107491 + {
107492 + //BATableInsertEntry
107493 + //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
107494 + index = BA.TID;
107495 + // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
107496 + pEntry = MacTableLookup(pAdapter, BA.MACAddr);
107497 + if (!pEntry)
107498 + {
107499 + DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
107500 + break;
107501 + }
107502 + if (BA.IsRecipient == FALSE)
107503 + {
107504 + if (pEntry->bIAmBadAtheros == TRUE)
107505 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
107506 +
107507 + BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
107508 + }
107509 + else
107510 + {
107511 + //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
107512 + }
107513 +
107514 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
107515 + BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
107516 + , BA.MACAddr[4], BA.MACAddr[5]));
107517 + }
107518 + }
107519 + break;
107520 +
107521 + case RT_OID_802_11_TEAR_IMME_BA:
107522 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
107523 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
107524 + Status = -EINVAL;
107525 + else
107526 + {
107527 + POID_ADD_BA_ENTRY pBA;
107528 + MAC_TABLE_ENTRY *pEntry;
107529 +
107530 + pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107531 +
107532 + if (pBA == NULL)
107533 + {
107534 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
107535 + Status = NDIS_STATUS_FAILURE;
107536 + }
107537 + else
107538 + {
107539 + Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
107540 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
107541 +
107542 + if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
107543 + {
107544 + Status = NDIS_STATUS_INVALID_DATA;
107545 + break;
107546 + }
107547 +
107548 + if (pBA->IsRecipient == FALSE)
107549 + {
107550 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
107551 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
107552 + if (pEntry)
107553 + {
107554 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
107555 + BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
107556 + }
107557 + else
107558 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
107559 + }
107560 + else
107561 + {
107562 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
107563 + if (pEntry)
107564 + {
107565 + BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
107566 + }
107567 + else
107568 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
107569 + }
107570 + kfree(pBA);
107571 + }
107572 + }
107573 + break;
107574 +#endif // DOT11_N_SUPPORT //
107575 +
107576 + // For WPA_SUPPLICANT to set static wep key
107577 + case OID_802_11_ADD_WEP:
107578 + pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107579 +
107580 + if(pWepKey == NULL)
107581 + {
107582 + Status = -ENOMEM;
107583 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
107584 + break;
107585 + }
107586 + Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
107587 + if (Status)
107588 + {
107589 + Status = -EINVAL;
107590 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
107591 + }
107592 + else
107593 + {
107594 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
107595 + // KeyIdx must be 0 ~ 3
107596 + if (KeyIdx > 4)
107597 + {
107598 + Status = -EINVAL;
107599 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
107600 + }
107601 + else
107602 + {
107603 + UCHAR CipherAlg = 0;
107604 + PUCHAR Key;
107605 +
107606 + // set key material and key length
107607 + NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
107608 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
107609 + NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
107610 +
107611 + switch(pWepKey->KeyLength)
107612 + {
107613 + case 5:
107614 + CipherAlg = CIPHER_WEP64;
107615 + break;
107616 + case 13:
107617 + CipherAlg = CIPHER_WEP128;
107618 + break;
107619 + default:
107620 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
107621 + Status = -EINVAL;
107622 + break;
107623 + }
107624 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
107625 +
107626 + // Default key for tx (shared key)
107627 + if (pWepKey->KeyIndex & 0x80000000)
107628 + {
107629 +#ifdef WPA_SUPPLICANT_SUPPORT
107630 + // set key material and key length
107631 + NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
107632 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
107633 + NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
107634 + pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
107635 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
107636 +#endif // WPA_SUPPLICANT_SUPPORT //
107637 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
107638 + }
107639 +
107640 +#ifdef WPA_SUPPLICANT_SUPPORT
107641 + if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
107642 +#endif // WPA_SUPPLICANT_SUPPORT
107643 + {
107644 + Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
107645 +
107646 + // Set key material and cipherAlg to Asic
107647 + AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
107648 +
107649 + if (pWepKey->KeyIndex & 0x80000000)
107650 + {
107651 + PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
107652 + // Assign group key info
107653 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
107654 + // Assign pairwise key info
107655 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
107656 + }
107657 + }
107658 + 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"));
107659 + }
107660 + }
107661 + kfree(pWepKey);
107662 + break;
107663 +#ifdef WPA_SUPPLICANT_SUPPORT
107664 + case OID_SET_COUNTERMEASURES:
107665 + if (wrq->u.data.length != sizeof(int))
107666 + Status = -EINVAL;
107667 + else
107668 + {
107669 + int enabled = 0;
107670 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
107671 + if (enabled == 1)
107672 + pAdapter->StaCfg.bBlockAssoc = TRUE;
107673 + else
107674 + // WPA MIC error should block association attempt for 60 seconds
107675 + pAdapter->StaCfg.bBlockAssoc = FALSE;
107676 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
107677 + }
107678 + break;
107679 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
107680 + if (wrq->u.data.length != sizeof(UCHAR))
107681 + Status = -EINVAL;
107682 + else
107683 + {
107684 + Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
107685 + pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
107686 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
107687 + }
107688 + break;
107689 + case OID_802_11_DEAUTHENTICATION:
107690 + if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
107691 + Status = -EINVAL;
107692 + else
107693 + {
107694 + MLME_DEAUTH_REQ_STRUCT *pInfo;
107695 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
107696 +
107697 + pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
107698 + Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
107699 + MlmeDeauthReqAction(pAdapter, MsgElem);
107700 + kfree(MsgElem);
107701 +
107702 + if (INFRA_ON(pAdapter))
107703 + {
107704 + LinkDown(pAdapter, FALSE);
107705 + pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
107706 + }
107707 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
107708 + }
107709 + break;
107710 + case OID_802_11_DROP_UNENCRYPTED:
107711 + if (wrq->u.data.length != sizeof(int))
107712 + Status = -EINVAL;
107713 + else
107714 + {
107715 + int enabled = 0;
107716 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
107717 + if (enabled == 1)
107718 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
107719 + else
107720 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
107721 + NdisAcquireSpinLock(&pAdapter->MacTabLock);
107722 + pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
107723 + NdisReleaseSpinLock(&pAdapter->MacTabLock);
107724 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
107725 + }
107726 + break;
107727 + case OID_802_11_SET_IEEE8021X:
107728 + if (wrq->u.data.length != sizeof(BOOLEAN))
107729 + Status = -EINVAL;
107730 + else
107731 + {
107732 + Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
107733 + pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
107734 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
107735 + }
107736 + break;
107737 + case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
107738 + if (wrq->u.data.length != sizeof(BOOLEAN))
107739 + Status = -EINVAL;
107740 + else
107741 + {
107742 + Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
107743 + pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
107744 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
107745 + }
107746 + break;
107747 + case OID_802_11_PMKID:
107748 + pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
107749 +
107750 + if(pPmkId == NULL) {
107751 + Status = -ENOMEM;
107752 + break;
107753 + }
107754 + Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
107755 +
107756 + // check the PMKID information
107757 + if (pPmkId->BSSIDInfoCount == 0)
107758 + NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
107759 + else
107760 + {
107761 + PBSSID_INFO pBssIdInfo;
107762 + UINT BssIdx;
107763 + UINT CachedIdx;
107764 +
107765 + for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
107766 + {
107767 + // point to the indexed BSSID_INFO structure
107768 + pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
107769 + // Find the entry in the saved data base.
107770 + for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
107771 + {
107772 + // compare the BSSID
107773 + if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
107774 + break;
107775 + }
107776 +
107777 + // Found, replace it
107778 + if (CachedIdx < PMKID_NO)
107779 + {
107780 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
107781 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
107782 + pAdapter->StaCfg.SavedPMKNum++;
107783 + }
107784 + // Not found, replace the last one
107785 + else
107786 + {
107787 + // Randomly replace one
107788 + CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
107789 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
107790 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
107791 + }
107792 + }
107793 + }
107794 + if(pPmkId)
107795 + kfree(pPmkId);
107796 + break;
107797 +#endif // WPA_SUPPLICANT_SUPPORT //
107798 +
107799 +
107800 +
107801 +#ifdef SNMP_SUPPORT
107802 + case OID_802_11_SHORTRETRYLIMIT:
107803 + if (wrq->u.data.length != sizeof(ULONG))
107804 + Status = -EINVAL;
107805 + else
107806 + {
107807 + Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
107808 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
107809 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
107810 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
107811 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
107812 + }
107813 + break;
107814 +
107815 + case OID_802_11_LONGRETRYLIMIT:
107816 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
107817 + if (wrq->u.data.length != sizeof(ULONG))
107818 + Status = -EINVAL;
107819 + else
107820 + {
107821 + Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
107822 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
107823 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
107824 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
107825 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
107826 + }
107827 + break;
107828 +
107829 + case OID_802_11_WEPDEFAULTKEYVALUE:
107830 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
107831 + pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
107832 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
107833 + //pKey = &WepKey;
107834 +
107835 + if ( pKey->Length != wrq->u.data.length)
107836 + {
107837 + Status = -EINVAL;
107838 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
107839 + }
107840 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
107841 + DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
107842 +
107843 + // it is a shared key
107844 + if (KeyIdx > 4)
107845 + Status = -EINVAL;
107846 + else
107847 + {
107848 + pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
107849 + NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
107850 + if (pKey->KeyIndex & 0x80000000)
107851 + {
107852 + // Default key for tx (shared key)
107853 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
107854 + }
107855 + //RestartAPIsRequired = TRUE;
107856 + }
107857 + break;
107858 +
107859 +
107860 + case OID_802_11_WEPDEFAULTKEYID:
107861 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
107862 +
107863 + if (wrq->u.data.length != sizeof(UCHAR))
107864 + Status = -EINVAL;
107865 + else
107866 + Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
107867 +
107868 + break;
107869 +
107870 +
107871 + case OID_802_11_CURRENTCHANNEL:
107872 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
107873 + if (wrq->u.data.length != sizeof(UCHAR))
107874 + Status = -EINVAL;
107875 + else
107876 + {
107877 + Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
107878 + sprintf(&ctmp,"%d", ctmp);
107879 + Set_Channel_Proc(pAdapter, &ctmp);
107880 + }
107881 + break;
107882 +#endif
107883 +
107884 +
107885 +
107886 + default:
107887 + DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
107888 + Status = -EOPNOTSUPP;
107889 + break;
107890 + }
107891 +
107892 +
107893 + return Status;
107894 +}
107895 +
107896 +INT RTMPQueryInformation(
107897 + IN PRTMP_ADAPTER pAdapter,
107898 + IN OUT struct ifreq *rq,
107899 + IN INT cmd)
107900 +{
107901 + struct iwreq *wrq = (struct iwreq *) rq;
107902 + NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
107903 + PNDIS_WLAN_BSSID_EX pBss;
107904 + NDIS_802_11_SSID Ssid;
107905 + NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
107906 + RT_802_11_LINK_STATUS *pLinkStatus = NULL;
107907 + RT_802_11_STA_CONFIG *pStaConfig = NULL;
107908 + NDIS_802_11_STATISTICS *pStatistics = NULL;
107909 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
107910 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
107911 + NDIS_802_11_POWER_MODE PowerMode;
107912 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
107913 + RT_802_11_PREAMBLE PreamType;
107914 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
107915 + NDIS_802_11_WEP_STATUS WepStatus;
107916 + NDIS_MEDIA_STATE MediaState;
107917 + ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
107918 + USHORT BssLen = 0;
107919 + PUCHAR pBuf = NULL, pPtr;
107920 + INT Status = NDIS_STATUS_SUCCESS;
107921 + UINT we_version_compiled;
107922 + UCHAR i, Padding = 0;
107923 + BOOLEAN RadioState;
107924 + UCHAR driverVersion[8];
107925 + OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
107926 +
107927 +
107928 +#ifdef SNMP_SUPPORT
107929 + //for snmp, kathy
107930 + DefaultKeyIdxValue *pKeyIdxValue;
107931 + INT valueLen;
107932 + TX_RTY_CFG_STRUC tx_rty_cfg;
107933 + ULONG ShortRetryLimit, LongRetryLimit;
107934 + UCHAR tmp[64];
107935 +#endif //SNMP
107936 +
107937 + switch(cmd)
107938 + {
107939 + case RT_OID_DEVICE_NAME:
107940 + wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
107941 + Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
107942 + break;
107943 + case RT_OID_VERSION_INFO:
107944 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
107945 + wrq->u.data.length = 8*sizeof(UCHAR);
107946 + sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
107947 + driverVersion[7] = '\0';
107948 + if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
107949 + {
107950 + Status = -EFAULT;
107951 + }
107952 + break;
107953 +#ifdef RALINK_ATE
107954 + case RT_QUERY_ATE_TXDONE_COUNT:
107955 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
107956 + wrq->u.data.length = sizeof(UINT32);
107957 + if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
107958 + {
107959 + Status = -EFAULT;
107960 + }
107961 + break;
107962 +#endif // RALINK_ATE //
107963 + case OID_802_11_BSSID_LIST:
107964 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
107965 + {
107966 + /*
107967 + * Still scanning, indicate the caller should try again.
107968 + */
107969 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
107970 + return -EAGAIN;
107971 + }
107972 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
107973 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
107974 + // Claculate total buffer size required
107975 + BssBufSize = sizeof(ULONG);
107976 +
107977 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
107978 + {
107979 + // Align pointer to 4 bytes boundary.
107980 + //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
107981 + //if (Padding == 4)
107982 + // Padding = 0;
107983 + BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
107984 + }
107985 +
107986 + // For safety issue, we add 256 bytes just in case
107987 + BssBufSize += 256;
107988 + // Allocate the same size as passed from higher layer
107989 + pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
107990 + if(pBuf == NULL)
107991 + {
107992 + Status = -ENOMEM;
107993 + break;
107994 + }
107995 + // Init 802_11_BSSID_LIST_EX structure
107996 + NdisZeroMemory(pBuf, BssBufSize);
107997 + pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
107998 + pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
107999 +
108000 + // Calculate total buffer length
108001 + BssLen = 4; // Consist of NumberOfItems
108002 + // Point to start of NDIS_WLAN_BSSID_EX
108003 + // pPtr = pBuf + sizeof(ULONG);
108004 + pPtr = (PUCHAR) &pBssidList->Bssid[0];
108005 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
108006 + {
108007 + pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
108008 + NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
108009 + if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
108010 + {
108011 + //
108012 + // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
108013 + // and then failed to send EAPOl farame.
108014 + //
108015 + if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
108016 + {
108017 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
108018 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
108019 + }
108020 + else
108021 + pBss->Ssid.SsidLength = 0;
108022 + }
108023 + else
108024 + {
108025 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
108026 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
108027 + }
108028 + pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
108029 + pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
108030 + pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
108031 + pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
108032 + pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
108033 + pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
108034 +
108035 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
108036 +
108037 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
108038 + pBss->InfrastructureMode = Ndis802_11Infrastructure;
108039 + else
108040 + pBss->InfrastructureMode = Ndis802_11IBSS;
108041 +
108042 + NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
108043 + NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
108044 + pAdapter->ScanTab.BssEntry[i].ExtRate,
108045 + pAdapter->ScanTab.BssEntry[i].ExtRateLen);
108046 +
108047 + if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
108048 + {
108049 + pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
108050 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
108051 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
108052 + }
108053 + else
108054 + {
108055 + pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
108056 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
108057 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
108058 + NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
108059 + pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
108060 + }
108061 + pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
108062 +
108063 +#if WIRELESS_EXT < 17
108064 + if ((BssLen + pBss->Length) < wrq->u.data.length)
108065 + BssLen += pBss->Length;
108066 + else
108067 + {
108068 + pBssidList->NumberOfItems = i;
108069 + break;
108070 + }
108071 +#else
108072 + BssLen += pBss->Length;
108073 +#endif
108074 + }
108075 +
108076 +#if WIRELESS_EXT < 17
108077 + wrq->u.data.length = BssLen;
108078 +#else
108079 + if (BssLen > wrq->u.data.length)
108080 + {
108081 + kfree(pBssidList);
108082 + return -E2BIG;
108083 + }
108084 + else
108085 + wrq->u.data.length = BssLen;
108086 +#endif
108087 + Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
108088 + kfree(pBssidList);
108089 + break;
108090 + case OID_802_3_CURRENT_ADDRESS:
108091 + wrq->u.data.length = MAC_ADDR_LEN;
108092 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
108093 + break;
108094 + case OID_GEN_MEDIA_CONNECT_STATUS:
108095 + if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
108096 + MediaState = NdisMediaStateConnected;
108097 + else
108098 + MediaState = NdisMediaStateDisconnected;
108099 +
108100 + wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
108101 + Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
108102 + break;
108103 + case OID_802_11_BSSID:
108104 +#ifdef RALINK_ATE
108105 + if (ATE_ON(pAdapter))
108106 + {
108107 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
108108 + Status = NDIS_STATUS_RESOURCES;
108109 + break;
108110 + }
108111 +#endif // RALINK_ATE //
108112 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
108113 + {
108114 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
108115 +
108116 + }
108117 + else
108118 + {
108119 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
108120 + Status = -ENOTCONN;
108121 + }
108122 + break;
108123 + case OID_802_11_SSID:
108124 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
108125 + NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
108126 + Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
108127 + memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
108128 + wrq->u.data.length = sizeof(NDIS_802_11_SSID);
108129 + Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
108130 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
108131 + break;
108132 + case RT_OID_802_11_QUERY_LINK_STATUS:
108133 + pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
108134 + if (pLinkStatus)
108135 + {
108136 + pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
108137 + pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
108138 + pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
108139 + pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
108140 + pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
108141 + wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
108142 + Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
108143 + kfree(pLinkStatus);
108144 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
108145 + }
108146 + else
108147 + {
108148 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
108149 + Status = -EFAULT;
108150 + }
108151 + break;
108152 + case OID_802_11_CONFIGURATION:
108153 + pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
108154 + if (pConfiguration)
108155 + {
108156 + pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
108157 + pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
108158 + pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
108159 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
108160 + wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
108161 + Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
108162 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
108163 + pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
108164 + kfree(pConfiguration);
108165 + }
108166 + else
108167 + {
108168 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
108169 + Status = -EFAULT;
108170 + }
108171 + break;
108172 + case RT_OID_802_11_SNR_0:
108173 + if ((pAdapter->StaCfg.LastSNR0 > 0))
108174 + {
108175 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
108176 + wrq->u.data.length = sizeof(ulInfo);
108177 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108178 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
108179 + }
108180 + else
108181 + Status = -EFAULT;
108182 + break;
108183 + case RT_OID_802_11_SNR_1:
108184 + if ((pAdapter->Antenna.field.RxPath > 1) &&
108185 + (pAdapter->StaCfg.LastSNR1 > 0))
108186 + {
108187 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
108188 + wrq->u.data.length = sizeof(ulInfo);
108189 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108190 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
108191 + }
108192 + else
108193 + Status = -EFAULT;
108194 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
108195 + break;
108196 + case OID_802_11_RSSI_TRIGGER:
108197 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
108198 + wrq->u.data.length = sizeof(ulInfo);
108199 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108200 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
108201 + break;
108202 + case OID_802_11_RSSI:
108203 + case RT_OID_802_11_RSSI:
108204 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
108205 + wrq->u.data.length = sizeof(ulInfo);
108206 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108207 + break;
108208 + case RT_OID_802_11_RSSI_1:
108209 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
108210 + wrq->u.data.length = sizeof(ulInfo);
108211 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108212 + break;
108213 + case RT_OID_802_11_RSSI_2:
108214 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
108215 + wrq->u.data.length = sizeof(ulInfo);
108216 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108217 + break;
108218 + case OID_802_11_STATISTICS:
108219 + pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
108220 + if (pStatistics)
108221 + {
108222 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
108223 + // add the most up-to-date h/w raw counters into software counters
108224 + NICUpdateRawCounters(pAdapter);
108225 +
108226 + // Sanity check for calculation of sucessful count
108227 + if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
108228 + pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
108229 +
108230 + pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
108231 + pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
108232 + pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
108233 + pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
108234 + pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
108235 + pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
108236 + pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
108237 + pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
108238 + pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
108239 + pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
108240 + pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
108241 +#ifdef DBG
108242 + pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
108243 +#else
108244 + pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
108245 + pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
108246 +#endif
108247 + wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
108248 + Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
108249 + kfree(pStatistics);
108250 + }
108251 + else
108252 + {
108253 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
108254 + Status = -EFAULT;
108255 + }
108256 + break;
108257 + case OID_GEN_RCV_OK:
108258 + ulInfo = pAdapter->Counters8023.GoodReceives;
108259 + wrq->u.data.length = sizeof(ulInfo);
108260 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108261 + break;
108262 + case OID_GEN_RCV_NO_BUFFER:
108263 + ulInfo = pAdapter->Counters8023.RxNoBuffer;
108264 + wrq->u.data.length = sizeof(ulInfo);
108265 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108266 + break;
108267 + case RT_OID_802_11_PHY_MODE:
108268 + ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
108269 + wrq->u.data.length = sizeof(ulInfo);
108270 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108271 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
108272 + break;
108273 + case RT_OID_802_11_STA_CONFIG:
108274 + pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
108275 + if (pStaConfig)
108276 + {
108277 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
108278 + pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
108279 + pStaConfig->EnableTurboRate = 0;
108280 + pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
108281 + pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
108282 + //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
108283 + pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
108284 + pStaConfig->Rsv1 = 0;
108285 + pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
108286 + wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
108287 + Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
108288 + kfree(pStaConfig);
108289 + }
108290 + else
108291 + {
108292 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
108293 + Status = -EFAULT;
108294 + }
108295 + break;
108296 + case OID_802_11_RTS_THRESHOLD:
108297 + RtsThresh = pAdapter->CommonCfg.RtsThreshold;
108298 + wrq->u.data.length = sizeof(RtsThresh);
108299 + Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
108300 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
108301 + break;
108302 + case OID_802_11_FRAGMENTATION_THRESHOLD:
108303 + FragThresh = pAdapter->CommonCfg.FragmentThreshold;
108304 + if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
108305 + FragThresh = 0;
108306 + wrq->u.data.length = sizeof(FragThresh);
108307 + Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
108308 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
108309 + break;
108310 + case OID_802_11_POWER_MODE:
108311 + PowerMode = pAdapter->StaCfg.WindowsPowerMode;
108312 + wrq->u.data.length = sizeof(PowerMode);
108313 + Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
108314 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
108315 + break;
108316 + case RT_OID_802_11_RADIO:
108317 + RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
108318 + wrq->u.data.length = sizeof(RadioState);
108319 + Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
108320 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
108321 + break;
108322 + case OID_802_11_INFRASTRUCTURE_MODE:
108323 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
108324 + BssType = Ndis802_11IBSS;
108325 + else if (pAdapter->StaCfg.BssType == BSS_INFRA)
108326 + BssType = Ndis802_11Infrastructure;
108327 + else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
108328 + BssType = Ndis802_11Monitor;
108329 + else
108330 + BssType = Ndis802_11AutoUnknown;
108331 +
108332 + wrq->u.data.length = sizeof(BssType);
108333 + Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
108334 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
108335 + break;
108336 + case RT_OID_802_11_PREAMBLE:
108337 + PreamType = pAdapter->CommonCfg.TxPreamble;
108338 + wrq->u.data.length = sizeof(PreamType);
108339 + Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
108340 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
108341 + break;
108342 + case OID_802_11_AUTHENTICATION_MODE:
108343 + AuthMode = pAdapter->StaCfg.AuthMode;
108344 + wrq->u.data.length = sizeof(AuthMode);
108345 + Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
108346 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
108347 + break;
108348 + case OID_802_11_WEP_STATUS:
108349 + WepStatus = pAdapter->StaCfg.WepStatus;
108350 + wrq->u.data.length = sizeof(WepStatus);
108351 + Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
108352 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
108353 + break;
108354 + case OID_802_11_TX_POWER_LEVEL:
108355 + wrq->u.data.length = sizeof(ULONG);
108356 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
108357 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
108358 + break;
108359 + case RT_OID_802_11_TX_POWER_LEVEL_1:
108360 + wrq->u.data.length = sizeof(ULONG);
108361 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
108362 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
108363 + break;
108364 + case OID_802_11_NETWORK_TYPES_SUPPORTED:
108365 + if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
108366 + {
108367 + NetworkTypeList[0] = 3; // NumberOfItems = 3
108368 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
108369 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
108370 + NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
108371 + wrq->u.data.length = 16;
108372 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
108373 + }
108374 + else
108375 + {
108376 + NetworkTypeList[0] = 2; // NumberOfItems = 2
108377 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
108378 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
108379 + wrq->u.data.length = 12;
108380 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
108381 + }
108382 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
108383 + break;
108384 + case OID_802_11_NETWORK_TYPE_IN_USE:
108385 + wrq->u.data.length = sizeof(ULONG);
108386 + if (pAdapter->CommonCfg.PhyMode == PHY_11A)
108387 + ulInfo = Ndis802_11OFDM5;
108388 + else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
108389 + ulInfo = Ndis802_11OFDM24;
108390 + else
108391 + ulInfo = Ndis802_11DS;
108392 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108393 + break;
108394 + case RT_OID_802_11_QUERY_LAST_RX_RATE:
108395 + ulInfo = (ULONG)pAdapter->LastRxRate;
108396 + wrq->u.data.length = sizeof(ulInfo);
108397 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108398 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
108399 + break;
108400 + case RT_OID_802_11_QUERY_LAST_TX_RATE:
108401 + //ulInfo = (ULONG)pAdapter->LastTxRate;
108402 + ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
108403 + wrq->u.data.length = sizeof(ulInfo);
108404 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108405 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
108406 + break;
108407 + case RT_OID_802_11_QUERY_EEPROM_VERSION:
108408 + wrq->u.data.length = sizeof(ULONG);
108409 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
108410 + break;
108411 + case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
108412 + wrq->u.data.length = sizeof(ULONG);
108413 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
108414 + break;
108415 + case RT_OID_802_11_QUERY_NOISE_LEVEL:
108416 + wrq->u.data.length = sizeof(UCHAR);
108417 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
108418 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
108419 + break;
108420 + case RT_OID_802_11_EXTRA_INFO:
108421 + wrq->u.data.length = sizeof(ULONG);
108422 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
108423 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
108424 + break;
108425 + case RT_OID_WE_VERSION_COMPILED:
108426 + wrq->u.data.length = sizeof(UINT);
108427 + we_version_compiled = WIRELESS_EXT;
108428 + Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
108429 + break;
108430 + case RT_OID_802_11_QUERY_APSD_SETTING:
108431 + apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
108432 + | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
108433 +
108434 + wrq->u.data.length = sizeof(ULONG);
108435 + Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
108436 + 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",
108437 + apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
108438 + break;
108439 + case RT_OID_802_11_QUERY_APSD_PSM:
108440 + wrq->u.data.length = sizeof(ULONG);
108441 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
108442 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
108443 + break;
108444 + case RT_OID_802_11_QUERY_WMM:
108445 + wrq->u.data.length = sizeof(BOOLEAN);
108446 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
108447 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
108448 + break;
108449 +#ifdef WPA_SUPPLICANT_SUPPORT
108450 + case RT_OID_NEW_DRIVER:
108451 + {
108452 + UCHAR enabled = 1;
108453 + wrq->u.data.length = sizeof(UCHAR);
108454 + Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
108455 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
108456 + }
108457 + break;
108458 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
108459 + wrq->u.data.length = sizeof(UCHAR);
108460 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
108461 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
108462 + break;
108463 +#endif // WPA_SUPPLICANT_SUPPORT //
108464 +
108465 + case RT_OID_DRIVER_DEVICE_NAME:
108466 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
108467 + wrq->u.data.length = 16;
108468 + if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
108469 + {
108470 + Status = -EFAULT;
108471 + }
108472 + break;
108473 + case RT_OID_802_11_QUERY_HT_PHYMODE:
108474 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
108475 + if (pHTPhyMode)
108476 + {
108477 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
108478 + pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
108479 + pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
108480 + pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
108481 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
108482 + pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
108483 +
108484 + pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
108485 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
108486 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
108487 + {
108488 + Status = -EFAULT;
108489 + }
108490 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
108491 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
108492 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
108493 + }
108494 + else
108495 + {
108496 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
108497 + Status = -EFAULT;
108498 + }
108499 + break;
108500 + case RT_OID_802_11_COUNTRY_REGION:
108501 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
108502 + wrq->u.data.length = sizeof(ulInfo);
108503 + ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
108504 + ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
108505 + if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
108506 + {
108507 + Status = -EFAULT;
108508 + }
108509 + break;
108510 + case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
108511 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
108512 + if (pHTPhyMode)
108513 + {
108514 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
108515 + pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
108516 + pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
108517 + pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
108518 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
108519 + pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
108520 +
108521 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
108522 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
108523 + {
108524 + Status = -EFAULT;
108525 + }
108526 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
108527 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
108528 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
108529 + }
108530 + else
108531 + {
108532 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
108533 + Status = -EFAULT;
108534 + }
108535 + break;
108536 + case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
108537 + wrq->u.data.length = sizeof(UCHAR);
108538 + i = 0;
108539 +#ifdef MULTIPLE_CARD_SUPPORT
108540 + i = 1;
108541 +#endif // MULTIPLE_CARD_SUPPORT //
108542 + if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
108543 + {
108544 + Status = -EFAULT;
108545 + }
108546 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
108547 + break;
108548 +#ifdef SNMP_SUPPORT
108549 + case RT_OID_802_11_MAC_ADDRESS:
108550 + wrq->u.data.length = MAC_ADDR_LEN;
108551 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
108552 + break;
108553 +
108554 + case RT_OID_802_11_MANUFACTUREROUI:
108555 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
108556 + wrq->u.data.length = ManufacturerOUI_LEN;
108557 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
108558 + break;
108559 +
108560 + case RT_OID_802_11_MANUFACTURERNAME:
108561 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
108562 + wrq->u.data.length = strlen(ManufacturerNAME);
108563 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
108564 + break;
108565 +
108566 + case RT_OID_802_11_RESOURCETYPEIDNAME:
108567 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
108568 + wrq->u.data.length = strlen(ResourceTypeIdName);
108569 + Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
108570 + break;
108571 +
108572 + case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
108573 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
108574 + ulInfo = 1; // 1 is support wep else 2 is not support.
108575 + wrq->u.data.length = sizeof(ulInfo);
108576 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108577 + break;
108578 +
108579 + case RT_OID_802_11_POWERMANAGEMENTMODE:
108580 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
108581 + if (pAdapter->StaCfg.Psm == PSMP_ACTION)
108582 + ulInfo = 1; // 1 is power active else 2 is power save.
108583 + else
108584 + ulInfo = 2;
108585 +
108586 + wrq->u.data.length = sizeof(ulInfo);
108587 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
108588 + break;
108589 +
108590 + case OID_802_11_WEPDEFAULTKEYVALUE:
108591 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
108592 + //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
108593 + pKeyIdxValue = wrq->u.data.pointer;
108594 + DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
108595 + valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
108596 + NdisMoveMemory(pKeyIdxValue->Value,
108597 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
108598 + valueLen);
108599 + pKeyIdxValue->Value[valueLen]='\0';
108600 +
108601 + wrq->u.data.length = sizeof(DefaultKeyIdxValue);
108602 +
108603 + Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
108604 + 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,
108605 + pAdapter->SharedKey[BSS0][0].Key[0],
108606 + pAdapter->SharedKey[BSS0][1].Key[0],
108607 + pAdapter->SharedKey[BSS0][2].Key[0],
108608 + pAdapter->SharedKey[BSS0][3].Key[0]));
108609 + break;
108610 +
108611 + case OID_802_11_WEPDEFAULTKEYID:
108612 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
108613 + wrq->u.data.length = sizeof(UCHAR);
108614 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
108615 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
108616 + break;
108617 +
108618 + case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
108619 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
108620 + wrq->u.data.length = sizeof(UCHAR);
108621 + Status = copy_to_user(wrq->u.data.pointer,
108622 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
108623 + wrq->u.data.length);
108624 + break;
108625 +
108626 + case OID_802_11_SHORTRETRYLIMIT:
108627 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
108628 + wrq->u.data.length = sizeof(ULONG);
108629 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
108630 + ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
108631 + DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
108632 + Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
108633 + break;
108634 +
108635 + case OID_802_11_LONGRETRYLIMIT:
108636 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
108637 + wrq->u.data.length = sizeof(ULONG);
108638 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
108639 + LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
108640 + DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
108641 + Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
108642 + break;
108643 +
108644 + case RT_OID_802_11_PRODUCTID:
108645 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
108646 +
108647 +#ifdef RT2870
108648 + sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
108649 +
108650 +#endif // RT2870 //
108651 + wrq->u.data.length = strlen(tmp);
108652 + Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
108653 + break;
108654 +
108655 + case RT_OID_802_11_MANUFACTUREID:
108656 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
108657 + wrq->u.data.length = strlen(ManufacturerNAME);
108658 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
108659 + break;
108660 +
108661 + case OID_802_11_CURRENTCHANNEL:
108662 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
108663 + wrq->u.data.length = sizeof(UCHAR);
108664 + DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
108665 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
108666 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
108667 + break;
108668 +#endif //SNMP_SUPPORT
108669 +
108670 + case OID_802_11_BUILD_CHANNEL_EX:
108671 + {
108672 + UCHAR value;
108673 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
108674 + wrq->u.data.length = sizeof(UCHAR);
108675 +#ifdef EXT_BUILD_CHANNEL_LIST
108676 + DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
108677 + value = 1;
108678 +#else
108679 + DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
108680 + value = 0;
108681 +#endif // EXT_BUILD_CHANNEL_LIST //
108682 + Status = copy_to_user(wrq->u.data.pointer, &value, 1);
108683 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
108684 + }
108685 + break;
108686 +
108687 + case OID_802_11_GET_CH_LIST:
108688 + {
108689 + PRT_CHANNEL_LIST_INFO pChListBuf;
108690 +
108691 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
108692 + if (pAdapter->ChannelListNum == 0)
108693 + {
108694 + wrq->u.data.length = 0;
108695 + break;
108696 + }
108697 +
108698 + pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
108699 + if (pChListBuf == NULL)
108700 + {
108701 + wrq->u.data.length = 0;
108702 + break;
108703 + }
108704 +
108705 + pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
108706 + for (i = 0; i < pChListBuf->ChannelListNum; i++)
108707 + pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
108708 +
108709 + wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
108710 + Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
108711 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
108712 +
108713 + if (pChListBuf)
108714 + kfree(pChListBuf);
108715 + }
108716 + break;
108717 +
108718 + case OID_802_11_GET_COUNTRY_CODE:
108719 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
108720 + wrq->u.data.length = 2;
108721 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
108722 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
108723 + break;
108724 +
108725 + case OID_802_11_GET_CHANNEL_GEOGRAPHY:
108726 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
108727 + wrq->u.data.length = 1;
108728 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
108729 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
108730 + break;
108731 +
108732 +
108733 +#ifdef QOS_DLS_SUPPORT
108734 + case RT_OID_802_11_QUERY_DLS:
108735 + wrq->u.data.length = sizeof(BOOLEAN);
108736 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
108737 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
108738 + break;
108739 +
108740 + case RT_OID_802_11_QUERY_DLS_PARAM:
108741 + {
108742 + PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
108743 + if (pDlsInfo == NULL)
108744 + break;
108745 +
108746 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
108747 + {
108748 + RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
108749 + }
108750 +
108751 + pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
108752 + wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
108753 + Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
108754 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
108755 +
108756 + if (pDlsInfo)
108757 + kfree(pDlsInfo);
108758 + }
108759 + break;
108760 +#endif // QOS_DLS_SUPPORT //
108761 + default:
108762 + DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
108763 + Status = -EOPNOTSUPP;
108764 + break;
108765 + }
108766 + return Status;
108767 +}
108768 +
108769 +INT rt28xx_sta_ioctl(
108770 + IN struct net_device *net_dev,
108771 + IN OUT struct ifreq *rq,
108772 + IN INT cmd)
108773 +{
108774 + POS_COOKIE pObj;
108775 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
108776 + RTMP_ADAPTER *pAd = NULL;
108777 + struct iwreq *wrq = (struct iwreq *) rq;
108778 + BOOLEAN StateMachineTouched = FALSE;
108779 + INT Status = NDIS_STATUS_SUCCESS;
108780 + USHORT subcmd;
108781 +
108782 + if (net_dev->priv_flags == INT_MAIN)
108783 + {
108784 + pAd = net_dev->priv;
108785 + }
108786 + else
108787 + {
108788 + pVirtualAd = net_dev->priv;
108789 + pAd = pVirtualAd->RtmpDev->priv;
108790 + }
108791 + pObj = (POS_COOKIE) pAd->OS_Cookie;
108792 +
108793 + if (pAd == NULL)
108794 + {
108795 + /* if 1st open fail, pAd will be free;
108796 + So the net_dev->priv will be NULL in 2rd open */
108797 + return -ENETDOWN;
108798 + }
108799 +
108800 + //check if the interface is down
108801 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
108802 + {
108803 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
108804 + if (wrq->u.data.pointer == NULL)
108805 + {
108806 + return Status;
108807 + }
108808 +
108809 + if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
108810 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
108811 + {
108812 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
108813 + return -ENETDOWN;
108814 + }
108815 + }
108816 +
108817 + { // determine this ioctl command is comming from which interface.
108818 + pObj->ioctl_if_type = INT_MAIN;
108819 + pObj->ioctl_if = MAIN_MBSSID;
108820 + }
108821 +
108822 + switch(cmd)
108823 + {
108824 +#ifdef RALINK_ATE
108825 +#ifdef RALINK_28xx_QA
108826 + case RTPRIV_IOCTL_ATE:
108827 + {
108828 + RtmpDoAte(pAd, wrq);
108829 + }
108830 + break;
108831 +#endif // RALINK_28xx_QA //
108832 +#endif // RALINK_ATE //
108833 + case SIOCGIFHWADDR:
108834 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
108835 + memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
108836 + break;
108837 + case SIOCGIWNAME:
108838 + {
108839 + char *name=&wrq->u.name[0];
108840 + rt_ioctl_giwname(net_dev, NULL, name, NULL);
108841 + break;
108842 + }
108843 + case SIOCGIWESSID: //Get ESSID
108844 + {
108845 + struct iw_point *essid=&wrq->u.essid;
108846 + rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
108847 + break;
108848 + }
108849 + case SIOCSIWESSID: //Set ESSID
108850 + {
108851 + struct iw_point *essid=&wrq->u.essid;
108852 + rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
108853 + break;
108854 + }
108855 + case SIOCSIWNWID: // set network id (the cell)
108856 + case SIOCGIWNWID: // get network id
108857 + Status = -EOPNOTSUPP;
108858 + break;
108859 + case SIOCSIWFREQ: //set channel/frequency (Hz)
108860 + {
108861 + struct iw_freq *freq=&wrq->u.freq;
108862 + rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
108863 + break;
108864 + }
108865 + case SIOCGIWFREQ: // get channel/frequency (Hz)
108866 + {
108867 + struct iw_freq *freq=&wrq->u.freq;
108868 + rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
108869 + break;
108870 + }
108871 + case SIOCSIWNICKN: //set node name/nickname
108872 + {
108873 + struct iw_point *data=&wrq->u.data;
108874 + rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
108875 + break;
108876 + }
108877 + case SIOCGIWNICKN: //get node name/nickname
108878 + {
108879 + struct iw_point *data=&wrq->u.data;
108880 + rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
108881 + break;
108882 + }
108883 + case SIOCGIWRATE: //get default bit rate (bps)
108884 + rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
108885 + break;
108886 + case SIOCSIWRATE: //set default bit rate (bps)
108887 + rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
108888 + break;
108889 + case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
108890 + {
108891 + struct iw_param *rts=&wrq->u.rts;
108892 + rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
108893 + break;
108894 + }
108895 + case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
108896 + {
108897 + struct iw_param *rts=&wrq->u.rts;
108898 + rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
108899 + break;
108900 + }
108901 + case SIOCGIWFRAG: //get fragmentation thr (bytes)
108902 + {
108903 + struct iw_param *frag=&wrq->u.frag;
108904 + rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
108905 + break;
108906 + }
108907 + case SIOCSIWFRAG: //set fragmentation thr (bytes)
108908 + {
108909 + struct iw_param *frag=&wrq->u.frag;
108910 + rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
108911 + break;
108912 + }
108913 + case SIOCGIWENCODE: //get encoding token & mode
108914 + {
108915 + struct iw_point *erq=&wrq->u.encoding;
108916 + if(erq->pointer)
108917 + rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
108918 + break;
108919 + }
108920 + case SIOCSIWENCODE: //set encoding token & mode
108921 + {
108922 + struct iw_point *erq=&wrq->u.encoding;
108923 + if(erq->pointer)
108924 + rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
108925 + break;
108926 + }
108927 + case SIOCGIWAP: //get access point MAC addresses
108928 + {
108929 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
108930 + rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
108931 + break;
108932 + }
108933 + case SIOCSIWAP: //set access point MAC addresses
108934 + {
108935 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
108936 + rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
108937 + break;
108938 + }
108939 + case SIOCGIWMODE: //get operation mode
108940 + {
108941 + __u32 *mode=&wrq->u.mode;
108942 + rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
108943 + break;
108944 + }
108945 + case SIOCSIWMODE: //set operation mode
108946 + {
108947 + __u32 *mode=&wrq->u.mode;
108948 + rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
108949 + break;
108950 + }
108951 + case SIOCGIWSENS: //get sensitivity (dBm)
108952 + case SIOCSIWSENS: //set sensitivity (dBm)
108953 + case SIOCGIWPOWER: //get Power Management settings
108954 + case SIOCSIWPOWER: //set Power Management settings
108955 + case SIOCGIWTXPOW: //get transmit power (dBm)
108956 + case SIOCSIWTXPOW: //set transmit power (dBm)
108957 + case SIOCGIWRANGE: //Get range of parameters
108958 + case SIOCGIWRETRY: //get retry limits and lifetime
108959 + case SIOCSIWRETRY: //set retry limits and lifetime
108960 + Status = -EOPNOTSUPP;
108961 + break;
108962 + case RT_PRIV_IOCTL:
108963 + subcmd = wrq->u.data.flags;
108964 + if( subcmd & OID_GET_SET_TOGGLE)
108965 + Status = RTMPSetInformation(pAd, rq, subcmd);
108966 + else
108967 + Status = RTMPQueryInformation(pAd, rq, subcmd);
108968 + break;
108969 + case SIOCGIWPRIV:
108970 + if (wrq->u.data.pointer)
108971 + {
108972 + if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
108973 + break;
108974 + wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
108975 + if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
108976 + Status = -EFAULT;
108977 + }
108978 + break;
108979 + case RTPRIV_IOCTL_SET:
108980 + if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
108981 + break;
108982 + rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
108983 + break;
108984 + case RTPRIV_IOCTL_GSITESURVEY:
108985 + RTMPIoctlGetSiteSurvey(pAd, wrq);
108986 + break;
108987 +#ifdef DBG
108988 + case RTPRIV_IOCTL_MAC:
108989 + RTMPIoctlMAC(pAd, wrq);
108990 + break;
108991 + case RTPRIV_IOCTL_E2P:
108992 + RTMPIoctlE2PROM(pAd, wrq);
108993 + break;
108994 +#endif // DBG //
108995 + case SIOCETHTOOL:
108996 + break;
108997 + default:
108998 + DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
108999 + Status = -EOPNOTSUPP;
109000 + break;
109001 + }
109002 +
109003 + if(StateMachineTouched) // Upper layer sent a MLME-related operations
109004 + RT28XX_MLME_HANDLER(pAd);
109005 +
109006 + return Status;
109007 +}
109008 +
109009 +/*
109010 + ==========================================================================
109011 + Description:
109012 + Set SSID
109013 + Return:
109014 + TRUE if all parameters are OK, FALSE otherwise
109015 + ==========================================================================
109016 +*/
109017 +INT Set_SSID_Proc(
109018 + IN PRTMP_ADAPTER pAdapter,
109019 + IN PUCHAR arg)
109020 +{
109021 + NDIS_802_11_SSID Ssid, *pSsid=NULL;
109022 + BOOLEAN StateMachineTouched = FALSE;
109023 + int success = TRUE;
109024 +
109025 + if( strlen(arg) <= MAX_LEN_OF_SSID)
109026 + {
109027 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
109028 + if (strlen(arg) != 0)
109029 + {
109030 + NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
109031 + Ssid.SsidLength = strlen(arg);
109032 + }
109033 + else //ANY ssid
109034 + {
109035 + Ssid.SsidLength = 0;
109036 + memcpy(Ssid.Ssid, "", 0);
109037 + pAdapter->StaCfg.BssType = BSS_INFRA;
109038 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
109039 + pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
109040 + }
109041 + pSsid = &Ssid;
109042 +
109043 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
109044 + {
109045 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
109046 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
109047 + }
109048 +
109049 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
109050 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
109051 + pAdapter->bConfigChanged = TRUE;
109052 +
109053 + MlmeEnqueue(pAdapter,
109054 + MLME_CNTL_STATE_MACHINE,
109055 + OID_802_11_SSID,
109056 + sizeof(NDIS_802_11_SSID),
109057 + (VOID *)pSsid);
109058 +
109059 + StateMachineTouched = TRUE;
109060 + DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
109061 + }
109062 + else
109063 + success = FALSE;
109064 +
109065 + if (StateMachineTouched) // Upper layer sent a MLME-related operations
109066 + RT28XX_MLME_HANDLER(pAdapter);
109067 +
109068 + return success;
109069 +}
109070 +
109071 +#ifdef WMM_SUPPORT
109072 +/*
109073 + ==========================================================================
109074 + Description:
109075 + Set WmmCapable Enable or Disable
109076 + Return:
109077 + TRUE if all parameters are OK, FALSE otherwise
109078 + ==========================================================================
109079 +*/
109080 +INT Set_WmmCapable_Proc(
109081 + IN PRTMP_ADAPTER pAd,
109082 + IN PUCHAR arg)
109083 +{
109084 + BOOLEAN bWmmCapable;
109085 +
109086 + bWmmCapable = simple_strtol(arg, 0, 10);
109087 +
109088 + if ((bWmmCapable == 1)
109089 +#ifdef RT2870
109090 + && (pAd->NumberOfPipes >= 5)
109091 +#endif // RT2870 //
109092 + )
109093 + pAd->CommonCfg.bWmmCapable = TRUE;
109094 + else if (bWmmCapable == 0)
109095 + pAd->CommonCfg.bWmmCapable = FALSE;
109096 + else
109097 + return FALSE; //Invalid argument
109098 +
109099 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
109100 + pAd->CommonCfg.bWmmCapable));
109101 +
109102 + return TRUE;
109103 +}
109104 +#endif // WMM_SUPPORT //
109105 +
109106 +/*
109107 + ==========================================================================
109108 + Description:
109109 + Set Network Type(Infrastructure/Adhoc mode)
109110 + Return:
109111 + TRUE if all parameters are OK, FALSE otherwise
109112 + ==========================================================================
109113 +*/
109114 +INT Set_NetworkType_Proc(
109115 + IN PRTMP_ADAPTER pAdapter,
109116 + IN PUCHAR arg)
109117 +{
109118 + UINT32 Value = 0;
109119 +
109120 + if (strcmp(arg, "Adhoc") == 0)
109121 + {
109122 + if (pAdapter->StaCfg.BssType != BSS_ADHOC)
109123 + {
109124 + // Config has changed
109125 + pAdapter->bConfigChanged = TRUE;
109126 + if (MONITOR_ON(pAdapter))
109127 + {
109128 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
109129 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
109130 + Value &= (~0x80);
109131 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
109132 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
109133 + pAdapter->StaCfg.bAutoReconnect = TRUE;
109134 + LinkDown(pAdapter, FALSE);
109135 + }
109136 + if (INFRA_ON(pAdapter))
109137 + {
109138 + //BOOLEAN Cancelled;
109139 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
109140 + // Since calling this indicate user don't want to connect to that SSID anymore.
109141 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
109142 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
109143 +
109144 + LinkDown(pAdapter, FALSE);
109145 +
109146 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
109147 + }
109148 + }
109149 + pAdapter->StaCfg.BssType = BSS_ADHOC;
109150 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
109151 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
109152 + }
109153 + else if (strcmp(arg, "Infra") == 0)
109154 + {
109155 + if (pAdapter->StaCfg.BssType != BSS_INFRA)
109156 + {
109157 + // Config has changed
109158 + pAdapter->bConfigChanged = TRUE;
109159 + if (MONITOR_ON(pAdapter))
109160 + {
109161 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
109162 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
109163 + Value &= (~0x80);
109164 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
109165 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
109166 + pAdapter->StaCfg.bAutoReconnect = TRUE;
109167 + LinkDown(pAdapter, FALSE);
109168 + }
109169 + if (ADHOC_ON(pAdapter))
109170 + {
109171 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
109172 + // Since calling this indicate user don't want to connect to that SSID anymore.
109173 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
109174 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
109175 +
109176 + LinkDown(pAdapter, FALSE);
109177 + }
109178 + }
109179 + pAdapter->StaCfg.BssType = BSS_INFRA;
109180 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
109181 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
109182 +
109183 + pAdapter->StaCfg.BssType = BSS_INFRA;
109184 + }
109185 + else if (strcmp(arg, "Monitor") == 0)
109186 + {
109187 + UCHAR bbpValue = 0;
109188 + BCN_TIME_CFG_STRUC csr;
109189 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
109190 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
109191 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
109192 + // disable all periodic state machine
109193 + pAdapter->StaCfg.bAutoReconnect = FALSE;
109194 + // reset all mlme state machine
109195 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
109196 + DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
109197 + if (pAdapter->CommonCfg.CentralChannel == 0)
109198 + {
109199 +#ifdef DOT11_N_SUPPORT
109200 + if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
109201 + pAdapter->CommonCfg.CentralChannel = 36;
109202 + else
109203 +#endif // DOT11_N_SUPPORT //
109204 + pAdapter->CommonCfg.CentralChannel = 6;
109205 + }
109206 +#ifdef DOT11_N_SUPPORT
109207 + else
109208 + N_ChannelCheck(pAdapter);
109209 +#endif // DOT11_N_SUPPORT //
109210 +
109211 +#ifdef DOT11_N_SUPPORT
109212 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
109213 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
109214 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
109215 + {
109216 + // 40MHz ,control channel at lower
109217 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
109218 + bbpValue &= (~0x18);
109219 + bbpValue |= 0x10;
109220 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
109221 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
109222 + // RX : control channel at lower
109223 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
109224 + bbpValue &= (~0x20);
109225 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
109226 +
109227 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
109228 + Value &= 0xfffffffe;
109229 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
109230 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
109231 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
109232 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
109233 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
109234 + pAdapter->CommonCfg.Channel,
109235 + pAdapter->CommonCfg.CentralChannel));
109236 + }
109237 + else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
109238 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
109239 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
109240 + {
109241 + // 40MHz ,control channel at upper
109242 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
109243 + bbpValue &= (~0x18);
109244 + bbpValue |= 0x10;
109245 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
109246 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
109247 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
109248 + Value |= 0x1;
109249 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
109250 +
109251 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
109252 + bbpValue |= (0x20);
109253 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
109254 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
109255 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
109256 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
109257 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
109258 + pAdapter->CommonCfg.Channel,
109259 + pAdapter->CommonCfg.CentralChannel));
109260 + }
109261 + else
109262 +#endif // DOT11_N_SUPPORT //
109263 + {
109264 + // 20MHz
109265 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
109266 + bbpValue &= (~0x18);
109267 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
109268 + pAdapter->CommonCfg.BBPCurrentBW = BW_20;
109269 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
109270 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
109271 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
109272 + }
109273 + // Enable Rx with promiscuous reception
109274 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
109275 + // ASIC supporsts sniffer function with replacing RSSI with timestamp.
109276 + //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
109277 + //Value |= (0x80);
109278 + //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
109279 + // disable sync
109280 + RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
109281 + csr.field.bBeaconGen = 0;
109282 + csr.field.bTBTTEnable = 0;
109283 + csr.field.TsfSyncMode = 0;
109284 + RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
109285 +
109286 + pAdapter->StaCfg.BssType = BSS_MONITOR;
109287 + pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
109288 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
109289 + }
109290 +
109291 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
109292 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
109293 +
109294 + DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
109295 +
109296 + return TRUE;
109297 +}
109298 +
109299 +/*
109300 + ==========================================================================
109301 + Description:
109302 + Set Authentication mode
109303 + Return:
109304 + TRUE if all parameters are OK, FALSE otherwise
109305 + ==========================================================================
109306 +*/
109307 +INT Set_AuthMode_Proc(
109308 + IN PRTMP_ADAPTER pAdapter,
109309 + IN PUCHAR arg)
109310 +{
109311 + if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
109312 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
109313 + else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
109314 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
109315 + else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
109316 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
109317 + else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
109318 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
109319 + else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
109320 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
109321 + else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
109322 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
109323 +#ifdef WPA_SUPPLICANT_SUPPORT
109324 + else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
109325 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
109326 + else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
109327 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
109328 +#endif // WPA_SUPPLICANT_SUPPORT //
109329 + else
109330 + return FALSE;
109331 +
109332 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
109333 +
109334 + DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
109335 +
109336 + return TRUE;
109337 +}
109338 +
109339 +/*
109340 + ==========================================================================
109341 + Description:
109342 + Set Encryption Type
109343 + Return:
109344 + TRUE if all parameters are OK, FALSE otherwise
109345 + ==========================================================================
109346 +*/
109347 +INT Set_EncrypType_Proc(
109348 + IN PRTMP_ADAPTER pAdapter,
109349 + IN PUCHAR arg)
109350 +{
109351 + if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
109352 + {
109353 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109354 + return TRUE; // do nothing
109355 +
109356 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
109357 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
109358 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
109359 + }
109360 + else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
109361 + {
109362 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109363 + return TRUE; // do nothing
109364 +
109365 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
109366 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
109367 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
109368 + }
109369 + else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
109370 + {
109371 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
109372 + return TRUE; // do nothing
109373 +
109374 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
109375 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
109376 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
109377 + }
109378 + else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
109379 + {
109380 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
109381 + return TRUE; // do nothing
109382 +
109383 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
109384 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
109385 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
109386 + }
109387 + else
109388 + return FALSE;
109389 +
109390 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
109391 +
109392 + DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
109393 +
109394 + return TRUE;
109395 +}
109396 +
109397 +/*
109398 + ==========================================================================
109399 + Description:
109400 + Set Default Key ID
109401 + Return:
109402 + TRUE if all parameters are OK, FALSE otherwise
109403 + ==========================================================================
109404 +*/
109405 +INT Set_DefaultKeyID_Proc(
109406 + IN PRTMP_ADAPTER pAdapter,
109407 + IN PUCHAR arg)
109408 +{
109409 + ULONG KeyIdx;
109410 +
109411 + KeyIdx = simple_strtol(arg, 0, 10);
109412 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
109413 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
109414 + else
109415 + return FALSE; //Invalid argument
109416 +
109417 + DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
109418 +
109419 + return TRUE;
109420 +}
109421 +
109422 +/*
109423 + ==========================================================================
109424 + Description:
109425 + Set WEP KEY1
109426 + Return:
109427 + TRUE if all parameters are OK, FALSE otherwise
109428 + ==========================================================================
109429 +*/
109430 +INT Set_Key1_Proc(
109431 + IN PRTMP_ADAPTER pAdapter,
109432 + IN PUCHAR arg)
109433 +{
109434 + int KeyLen;
109435 + int i;
109436 + UCHAR CipherAlg=CIPHER_WEP64;
109437 +
109438 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109439 + return TRUE; // do nothing
109440 +
109441 + KeyLen = strlen(arg);
109442 +
109443 + switch (KeyLen)
109444 + {
109445 + case 5: //wep 40 Ascii type
109446 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
109447 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
109448 + CipherAlg = CIPHER_WEP64;
109449 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
109450 + break;
109451 + case 10: //wep 40 Hex type
109452 + for(i=0; i < KeyLen; i++)
109453 + {
109454 + if( !isxdigit(*(arg+i)) )
109455 + return FALSE; //Not Hex value;
109456 + }
109457 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
109458 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
109459 + CipherAlg = CIPHER_WEP64;
109460 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
109461 + break;
109462 + case 13: //wep 104 Ascii type
109463 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
109464 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
109465 + CipherAlg = CIPHER_WEP128;
109466 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
109467 + break;
109468 + case 26: //wep 104 Hex type
109469 + for(i=0; i < KeyLen; i++)
109470 + {
109471 + if( !isxdigit(*(arg+i)) )
109472 + return FALSE; //Not Hex value;
109473 + }
109474 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
109475 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
109476 + CipherAlg = CIPHER_WEP128;
109477 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
109478 + break;
109479 + default: //Invalid argument
109480 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
109481 + return FALSE;
109482 + }
109483 +
109484 + pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
109485 +
109486 + // Set keys (into ASIC)
109487 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109488 + ; // not support
109489 + else // Old WEP stuff
109490 + {
109491 + AsicAddSharedKeyEntry(pAdapter,
109492 + 0,
109493 + 0,
109494 + pAdapter->SharedKey[BSS0][0].CipherAlg,
109495 + pAdapter->SharedKey[BSS0][0].Key,
109496 + NULL,
109497 + NULL);
109498 + }
109499 +
109500 + return TRUE;
109501 +}
109502 +/*
109503 + ==========================================================================
109504 +
109505 + Description:
109506 + Set WEP KEY2
109507 + Return:
109508 + TRUE if all parameters are OK, FALSE otherwise
109509 + ==========================================================================
109510 +*/
109511 +INT Set_Key2_Proc(
109512 + IN PRTMP_ADAPTER pAdapter,
109513 + IN PUCHAR arg)
109514 +{
109515 + int KeyLen;
109516 + int i;
109517 + UCHAR CipherAlg=CIPHER_WEP64;
109518 +
109519 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109520 + return TRUE; // do nothing
109521 +
109522 + KeyLen = strlen(arg);
109523 +
109524 + switch (KeyLen)
109525 + {
109526 + case 5: //wep 40 Ascii type
109527 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
109528 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
109529 + CipherAlg = CIPHER_WEP64;
109530 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
109531 + break;
109532 + case 10: //wep 40 Hex type
109533 + for(i=0; i < KeyLen; i++)
109534 + {
109535 + if( !isxdigit(*(arg+i)) )
109536 + return FALSE; //Not Hex value;
109537 + }
109538 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
109539 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
109540 + CipherAlg = CIPHER_WEP64;
109541 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
109542 + break;
109543 + case 13: //wep 104 Ascii type
109544 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
109545 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
109546 + CipherAlg = CIPHER_WEP128;
109547 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
109548 + break;
109549 + case 26: //wep 104 Hex type
109550 + for(i=0; i < KeyLen; i++)
109551 + {
109552 + if( !isxdigit(*(arg+i)) )
109553 + return FALSE; //Not Hex value;
109554 + }
109555 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
109556 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
109557 + CipherAlg = CIPHER_WEP128;
109558 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
109559 + break;
109560 + default: //Invalid argument
109561 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
109562 + return FALSE;
109563 + }
109564 + pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
109565 +
109566 + // Set keys (into ASIC)
109567 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109568 + ; // not support
109569 + else // Old WEP stuff
109570 + {
109571 + AsicAddSharedKeyEntry(pAdapter,
109572 + 0,
109573 + 1,
109574 + pAdapter->SharedKey[BSS0][1].CipherAlg,
109575 + pAdapter->SharedKey[BSS0][1].Key,
109576 + NULL,
109577 + NULL);
109578 + }
109579 +
109580 + return TRUE;
109581 +}
109582 +/*
109583 + ==========================================================================
109584 + Description:
109585 + Set WEP KEY3
109586 + Return:
109587 + TRUE if all parameters are OK, FALSE otherwise
109588 + ==========================================================================
109589 +*/
109590 +INT Set_Key3_Proc(
109591 + IN PRTMP_ADAPTER pAdapter,
109592 + IN PUCHAR arg)
109593 +{
109594 + int KeyLen;
109595 + int i;
109596 + UCHAR CipherAlg=CIPHER_WEP64;
109597 +
109598 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109599 + return TRUE; // do nothing
109600 +
109601 + KeyLen = strlen(arg);
109602 +
109603 + switch (KeyLen)
109604 + {
109605 + case 5: //wep 40 Ascii type
109606 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
109607 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
109608 + CipherAlg = CIPHER_WEP64;
109609 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
109610 + break;
109611 + case 10: //wep 40 Hex type
109612 + for(i=0; i < KeyLen; i++)
109613 + {
109614 + if( !isxdigit(*(arg+i)) )
109615 + return FALSE; //Not Hex value;
109616 + }
109617 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
109618 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
109619 + CipherAlg = CIPHER_WEP64;
109620 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
109621 + break;
109622 + case 13: //wep 104 Ascii type
109623 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
109624 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
109625 + CipherAlg = CIPHER_WEP128;
109626 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
109627 + break;
109628 + case 26: //wep 104 Hex type
109629 + for(i=0; i < KeyLen; i++)
109630 + {
109631 + if( !isxdigit(*(arg+i)) )
109632 + return FALSE; //Not Hex value;
109633 + }
109634 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
109635 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
109636 + CipherAlg = CIPHER_WEP128;
109637 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
109638 + break;
109639 + default: //Invalid argument
109640 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
109641 + return FALSE;
109642 + }
109643 + pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
109644 +
109645 + // Set keys (into ASIC)
109646 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109647 + ; // not support
109648 + else // Old WEP stuff
109649 + {
109650 + AsicAddSharedKeyEntry(pAdapter,
109651 + 0,
109652 + 2,
109653 + pAdapter->SharedKey[BSS0][2].CipherAlg,
109654 + pAdapter->SharedKey[BSS0][2].Key,
109655 + NULL,
109656 + NULL);
109657 + }
109658 +
109659 + return TRUE;
109660 +}
109661 +/*
109662 + ==========================================================================
109663 + Description:
109664 + Set WEP KEY4
109665 + Return:
109666 + TRUE if all parameters are OK, FALSE otherwise
109667 + ==========================================================================
109668 +*/
109669 +INT Set_Key4_Proc(
109670 + IN PRTMP_ADAPTER pAdapter,
109671 + IN PUCHAR arg)
109672 +{
109673 + int KeyLen;
109674 + int i;
109675 + UCHAR CipherAlg=CIPHER_WEP64;
109676 +
109677 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109678 + return TRUE; // do nothing
109679 +
109680 + KeyLen = strlen(arg);
109681 +
109682 + switch (KeyLen)
109683 + {
109684 + case 5: //wep 40 Ascii type
109685 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
109686 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
109687 + CipherAlg = CIPHER_WEP64;
109688 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
109689 + break;
109690 + case 10: //wep 40 Hex type
109691 + for(i=0; i < KeyLen; i++)
109692 + {
109693 + if( !isxdigit(*(arg+i)) )
109694 + return FALSE; //Not Hex value;
109695 + }
109696 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
109697 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
109698 + CipherAlg = CIPHER_WEP64;
109699 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
109700 + break;
109701 + case 13: //wep 104 Ascii type
109702 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
109703 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
109704 + CipherAlg = CIPHER_WEP128;
109705 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
109706 + break;
109707 + case 26: //wep 104 Hex type
109708 + for(i=0; i < KeyLen; i++)
109709 + {
109710 + if( !isxdigit(*(arg+i)) )
109711 + return FALSE; //Not Hex value;
109712 + }
109713 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
109714 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
109715 + CipherAlg = CIPHER_WEP128;
109716 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
109717 + break;
109718 + default: //Invalid argument
109719 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
109720 + return FALSE;
109721 + }
109722 + pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
109723 +
109724 + // Set keys (into ASIC)
109725 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
109726 + ; // not support
109727 + else // Old WEP stuff
109728 + {
109729 + AsicAddSharedKeyEntry(pAdapter,
109730 + 0,
109731 + 3,
109732 + pAdapter->SharedKey[BSS0][3].CipherAlg,
109733 + pAdapter->SharedKey[BSS0][3].Key,
109734 + NULL,
109735 + NULL);
109736 + }
109737 +
109738 + return TRUE;
109739 +}
109740 +
109741 +/*
109742 + ==========================================================================
109743 + Description:
109744 + Set WPA PSK key
109745 + Return:
109746 + TRUE if all parameters are OK, FALSE otherwise
109747 + ==========================================================================
109748 +*/
109749 +INT Set_WPAPSK_Proc(
109750 + IN PRTMP_ADAPTER pAdapter,
109751 + IN PUCHAR arg)
109752 +{
109753 + UCHAR keyMaterial[40];
109754 +
109755 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
109756 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
109757 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
109758 + )
109759 + return TRUE; // do nothing
109760 +
109761 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
109762 +
109763 + NdisZeroMemory(keyMaterial, 40);
109764 +
109765 + if ((strlen(arg) < 8) || (strlen(arg) > 64))
109766 + {
109767 + DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
109768 + return FALSE;
109769 + }
109770 +
109771 + if (strlen(arg) == 64)
109772 + {
109773 + AtoH(arg, keyMaterial, 32);
109774 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
109775 +
109776 + }
109777 + else
109778 + {
109779 + PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
109780 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
109781 + }
109782 +
109783 +
109784 +
109785 + if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
109786 + pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
109787 + {
109788 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
109789 + }
109790 + else
109791 + {
109792 + // Start STA supplicant state machine
109793 + pAdapter->StaCfg.WpaState = SS_START;
109794 + }
109795 +
109796 + return TRUE;
109797 +}
109798 +
109799 +/*
109800 + ==========================================================================
109801 + Description:
109802 + Set Power Saving mode
109803 + Return:
109804 + TRUE if all parameters are OK, FALSE otherwise
109805 + ==========================================================================
109806 +*/
109807 +INT Set_PSMode_Proc(
109808 + IN PRTMP_ADAPTER pAdapter,
109809 + IN PUCHAR arg)
109810 +{
109811 + if (pAdapter->StaCfg.BssType == BSS_INFRA)
109812 + {
109813 + if ((strcmp(arg, "Max_PSP") == 0) ||
109814 + (strcmp(arg, "max_psp") == 0) ||
109815 + (strcmp(arg, "MAX_PSP") == 0))
109816 + {
109817 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
109818 + // to exclude certain situations.
109819 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
109820 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
109821 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
109822 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
109823 + pAdapter->StaCfg.DefaultListenCount = 5;
109824 +
109825 + }
109826 + else if ((strcmp(arg, "Fast_PSP") == 0) ||
109827 + (strcmp(arg, "fast_psp") == 0) ||
109828 + (strcmp(arg, "FAST_PSP") == 0))
109829 + {
109830 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
109831 + // to exclude certain situations.
109832 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
109833 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
109834 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
109835 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
109836 + pAdapter->StaCfg.DefaultListenCount = 3;
109837 + }
109838 + else if ((strcmp(arg, "Legacy_PSP") == 0) ||
109839 + (strcmp(arg, "legacy_psp") == 0) ||
109840 + (strcmp(arg, "LEGACY_PSP") == 0))
109841 + {
109842 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
109843 + // to exclude certain situations.
109844 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
109845 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
109846 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
109847 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
109848 + pAdapter->StaCfg.DefaultListenCount = 3;
109849 + }
109850 + else
109851 + {
109852 + //Default Ndis802_11PowerModeCAM
109853 + // clear PSM bit immediately
109854 + MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
109855 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
109856 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
109857 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
109858 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
109859 + }
109860 +
109861 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
109862 + }
109863 + else
109864 + return FALSE;
109865 +
109866 +
109867 + return TRUE;
109868 +}
109869 +
109870 +#ifdef WPA_SUPPLICANT_SUPPORT
109871 +/*
109872 + ==========================================================================
109873 + Description:
109874 + Set WpaSupport flag.
109875 + Value:
109876 + 0: Driver ignore wpa_supplicant.
109877 + 1: wpa_supplicant initiates scanning and AP selection.
109878 + 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
109879 + Return:
109880 + TRUE if all parameters are OK, FALSE otherwise
109881 + ==========================================================================
109882 +*/
109883 +INT Set_Wpa_Support(
109884 + IN PRTMP_ADAPTER pAd,
109885 + IN PUCHAR arg)
109886 +{
109887 +
109888 + if ( simple_strtol(arg, 0, 10) == 0)
109889 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
109890 + else if ( simple_strtol(arg, 0, 10) == 1)
109891 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
109892 + else if ( simple_strtol(arg, 0, 10) == 2)
109893 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
109894 + else
109895 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
109896 +
109897 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
109898 +
109899 + return TRUE;
109900 +}
109901 +#endif // WPA_SUPPLICANT_SUPPORT //
109902 +
109903 +#ifdef DBG
109904 +/*
109905 + ==========================================================================
109906 + Description:
109907 + Read / Write MAC
109908 + Arguments:
109909 + pAdapter Pointer to our adapter
109910 + wrq Pointer to the ioctl argument
109911 +
109912 + Return Value:
109913 + None
109914 +
109915 + Note:
109916 + Usage:
109917 + 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
109918 + 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
109919 + ==========================================================================
109920 +*/
109921 +VOID RTMPIoctlMAC(
109922 + IN PRTMP_ADAPTER pAdapter,
109923 + IN struct iwreq *wrq)
109924 +{
109925 + CHAR *this_char;
109926 + CHAR *value;
109927 + INT j = 0, k = 0;
109928 + CHAR msg[1024];
109929 + CHAR arg[255];
109930 + ULONG macAddr = 0;
109931 + UCHAR temp[16], temp2[16];
109932 + UINT32 macValue = 0;
109933 + INT Status;
109934 +
109935 +
109936 + memset(msg, 0x00, 1024);
109937 + if (wrq->u.data.length > 1) //No parameters.
109938 + {
109939 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
109940 + sprintf(msg, "\n");
109941 +
109942 + //Parsing Read or Write
109943 + this_char = arg;
109944 + if (!*this_char)
109945 + goto next;
109946 +
109947 + if ((value = rtstrchr(this_char, '=')) != NULL)
109948 + *value++ = 0;
109949 +
109950 + if (!value || !*value)
109951 + { //Read
109952 + // Sanity check
109953 + if(strlen(this_char) > 4)
109954 + goto next;
109955 +
109956 + j = strlen(this_char);
109957 + while(j-- > 0)
109958 + {
109959 + if(this_char[j] > 'f' || this_char[j] < '0')
109960 + return;
109961 + }
109962 +
109963 + // Mac Addr
109964 + k = j = strlen(this_char);
109965 + while(j-- > 0)
109966 + {
109967 + this_char[4-k+j] = this_char[j];
109968 + }
109969 +
109970 + while(k < 4)
109971 + this_char[3-k++]='0';
109972 + this_char[4]='\0';
109973 +
109974 + if(strlen(this_char) == 4)
109975 + {
109976 + AtoH(this_char, temp, 2);
109977 + macAddr = *temp*256 + temp[1];
109978 + if (macAddr < 0xFFFF)
109979 + {
109980 + RTMP_IO_READ32(pAdapter, macAddr, &macValue);
109981 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
109982 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
109983 + }
109984 + else
109985 + {//Invalid parametes, so default printk all bbp
109986 + goto next;
109987 + }
109988 + }
109989 + }
109990 + else
109991 + { //Write
109992 + memcpy(&temp2, value, strlen(value));
109993 + temp2[strlen(value)] = '\0';
109994 +
109995 + // Sanity check
109996 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
109997 + goto next;
109998 +
109999 + j = strlen(this_char);
110000 + while(j-- > 0)
110001 + {
110002 + if(this_char[j] > 'f' || this_char[j] < '0')
110003 + return;
110004 + }
110005 +
110006 + j = strlen(temp2);
110007 + while(j-- > 0)
110008 + {
110009 + if(temp2[j] > 'f' || temp2[j] < '0')
110010 + return;
110011 + }
110012 +
110013 + //MAC Addr
110014 + k = j = strlen(this_char);
110015 + while(j-- > 0)
110016 + {
110017 + this_char[4-k+j] = this_char[j];
110018 + }
110019 +
110020 + while(k < 4)
110021 + this_char[3-k++]='0';
110022 + this_char[4]='\0';
110023 +
110024 + //MAC value
110025 + k = j = strlen(temp2);
110026 + while(j-- > 0)
110027 + {
110028 + temp2[8-k+j] = temp2[j];
110029 + }
110030 +
110031 + while(k < 8)
110032 + temp2[7-k++]='0';
110033 + temp2[8]='\0';
110034 +
110035 + {
110036 + AtoH(this_char, temp, 2);
110037 + macAddr = *temp*256 + temp[1];
110038 +
110039 + AtoH(temp2, temp, 4);
110040 + macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
110041 +
110042 + // debug mode
110043 + if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
110044 + {
110045 + // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
110046 + if (macValue & 0x000000ff)
110047 + {
110048 + pAdapter->BbpTuning.bEnable = TRUE;
110049 + DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
110050 + }
110051 + else
110052 + {
110053 + UCHAR R66;
110054 + pAdapter->BbpTuning.bEnable = FALSE;
110055 + R66 = 0x26 + GET_LNA_GAIN(pAdapter);
110056 +#ifdef RALINK_ATE
110057 + if (ATE_ON(pAdapter))
110058 + {
110059 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
110060 + }
110061 + else
110062 +#endif // RALINK_ATE //
110063 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
110064 + DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
110065 + }
110066 + return;
110067 + }
110068 +
110069 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
110070 +
110071 + RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
110072 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
110073 + }
110074 + }
110075 + }
110076 +next:
110077 + if(strlen(msg) == 1)
110078 + sprintf(msg+strlen(msg), "===>Error command format!");
110079 +
110080 + // Copy the information into the user buffer
110081 + wrq->u.data.length = strlen(msg);
110082 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
110083 +
110084 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
110085 +}
110086 +
110087 +/*
110088 + ==========================================================================
110089 + Description:
110090 + Read / Write E2PROM
110091 + Arguments:
110092 + pAdapter Pointer to our adapter
110093 + wrq Pointer to the ioctl argument
110094 +
110095 + Return Value:
110096 + None
110097 +
110098 + Note:
110099 + Usage:
110100 + 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
110101 + 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
110102 + ==========================================================================
110103 +*/
110104 +VOID RTMPIoctlE2PROM(
110105 + IN PRTMP_ADAPTER pAdapter,
110106 + IN struct iwreq *wrq)
110107 +{
110108 + CHAR *this_char;
110109 + CHAR *value;
110110 + INT j = 0, k = 0;
110111 + CHAR msg[1024];
110112 + CHAR arg[255];
110113 + USHORT eepAddr = 0;
110114 + UCHAR temp[16], temp2[16];
110115 + USHORT eepValue;
110116 + int Status;
110117 +
110118 +
110119 + memset(msg, 0x00, 1024);
110120 + if (wrq->u.data.length > 1) //No parameters.
110121 + {
110122 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
110123 + sprintf(msg, "\n");
110124 +
110125 + //Parsing Read or Write
110126 + this_char = arg;
110127 +
110128 +
110129 + if (!*this_char)
110130 + goto next;
110131 +
110132 + if ((value = rtstrchr(this_char, '=')) != NULL)
110133 + *value++ = 0;
110134 +
110135 + if (!value || !*value)
110136 + { //Read
110137 +
110138 + // Sanity check
110139 + if(strlen(this_char) > 4)
110140 + goto next;
110141 +
110142 + j = strlen(this_char);
110143 + while(j-- > 0)
110144 + {
110145 + if(this_char[j] > 'f' || this_char[j] < '0')
110146 + return;
110147 + }
110148 +
110149 + // E2PROM addr
110150 + k = j = strlen(this_char);
110151 + while(j-- > 0)
110152 + {
110153 + this_char[4-k+j] = this_char[j];
110154 + }
110155 +
110156 + while(k < 4)
110157 + this_char[3-k++]='0';
110158 + this_char[4]='\0';
110159 +
110160 + if(strlen(this_char) == 4)
110161 + {
110162 + AtoH(this_char, temp, 2);
110163 + eepAddr = *temp*256 + temp[1];
110164 + if (eepAddr < 0xFFFF)
110165 + {
110166 + RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
110167 + sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
110168 + }
110169 + else
110170 + {//Invalid parametes, so default printk all bbp
110171 + goto next;
110172 + }
110173 + }
110174 + }
110175 + else
110176 + { //Write
110177 + memcpy(&temp2, value, strlen(value));
110178 + temp2[strlen(value)] = '\0';
110179 +
110180 + // Sanity check
110181 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
110182 + goto next;
110183 +
110184 + j = strlen(this_char);
110185 + while(j-- > 0)
110186 + {
110187 + if(this_char[j] > 'f' || this_char[j] < '0')
110188 + return;
110189 + }
110190 + j = strlen(temp2);
110191 + while(j-- > 0)
110192 + {
110193 + if(temp2[j] > 'f' || temp2[j] < '0')
110194 + return;
110195 + }
110196 +
110197 + //MAC Addr
110198 + k = j = strlen(this_char);
110199 + while(j-- > 0)
110200 + {
110201 + this_char[4-k+j] = this_char[j];
110202 + }
110203 +
110204 + while(k < 4)
110205 + this_char[3-k++]='0';
110206 + this_char[4]='\0';
110207 +
110208 + //MAC value
110209 + k = j = strlen(temp2);
110210 + while(j-- > 0)
110211 + {
110212 + temp2[4-k+j] = temp2[j];
110213 + }
110214 +
110215 + while(k < 4)
110216 + temp2[3-k++]='0';
110217 + temp2[4]='\0';
110218 +
110219 + AtoH(this_char, temp, 2);
110220 + eepAddr = *temp*256 + temp[1];
110221 +
110222 + AtoH(temp2, temp, 2);
110223 + eepValue = *temp*256 + temp[1];
110224 +
110225 + RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
110226 + sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
110227 + }
110228 + }
110229 +next:
110230 + if(strlen(msg) == 1)
110231 + sprintf(msg+strlen(msg), "===>Error command format!");
110232 +
110233 +
110234 + // Copy the information into the user buffer
110235 + wrq->u.data.length = strlen(msg);
110236 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
110237 +
110238 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
110239 +}
110240 +#endif // DBG //
110241 +
110242 +
110243 +
110244 +
110245 +INT Set_TGnWifiTest_Proc(
110246 + IN PRTMP_ADAPTER pAd,
110247 + IN PUCHAR arg)
110248 +{
110249 + if (simple_strtol(arg, 0, 10) == 0)
110250 + pAd->StaCfg.bTGnWifiTest = FALSE;
110251 + else
110252 + pAd->StaCfg.bTGnWifiTest = TRUE;
110253 +
110254 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
110255 + return TRUE;
110256 +}
110257 +
110258 +INT Set_LongRetryLimit_Proc(
110259 + IN PRTMP_ADAPTER pAdapter,
110260 + IN PUCHAR arg)
110261 +{
110262 + TX_RTY_CFG_STRUC tx_rty_cfg;
110263 + UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
110264 +
110265 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
110266 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
110267 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
110268 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
110269 + return TRUE;
110270 +}
110271 +
110272 +INT Set_ShortRetryLimit_Proc(
110273 + IN PRTMP_ADAPTER pAdapter,
110274 + IN PUCHAR arg)
110275 +{
110276 + TX_RTY_CFG_STRUC tx_rty_cfg;
110277 + UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
110278 +
110279 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
110280 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
110281 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
110282 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
110283 + return TRUE;
110284 +}
110285 +
110286 +#ifdef EXT_BUILD_CHANNEL_LIST
110287 +INT Set_Ieee80211dClientMode_Proc(
110288 + IN PRTMP_ADAPTER pAdapter,
110289 + IN PUCHAR arg)
110290 +{
110291 + if (simple_strtol(arg, 0, 10) == 0)
110292 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
110293 + else if (simple_strtol(arg, 0, 10) == 1)
110294 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
110295 + else if (simple_strtol(arg, 0, 10) == 2)
110296 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
110297 + else
110298 + return FALSE;
110299 +
110300 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
110301 + return TRUE;
110302 +}
110303 +#endif // EXT_BUILD_CHANNEL_LIST //
110304 +
110305 +#ifdef CARRIER_DETECTION_SUPPORT
110306 +INT Set_CarrierDetect_Proc(
110307 + IN PRTMP_ADAPTER pAd,
110308 + IN PUCHAR arg)
110309 +{
110310 + if (simple_strtol(arg, 0, 10) == 0)
110311 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
110312 + else
110313 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
110314 +
110315 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
110316 + return TRUE;
110317 +}
110318 +#endif // CARRIER_DETECTION_SUPPORT //
110319 +
110320 +
110321 +INT Show_Adhoc_MacTable_Proc(
110322 + IN PRTMP_ADAPTER pAd,
110323 + IN PCHAR extra)
110324 +{
110325 + INT i;
110326 +
110327 + sprintf(extra, "\n");
110328 +
110329 +#ifdef DOT11_N_SUPPORT
110330 + sprintf(extra, "%sHT Operating Mode : %d\n", extra, pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
110331 +#endif // DOT11_N_SUPPORT //
110332 +
110333 + sprintf(extra, "%s\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n", extra,
110334 + "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
110335 +
110336 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
110337 + {
110338 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
110339 +
110340 + if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
110341 + break;
110342 + if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
110343 + {
110344 + sprintf(extra, "%s%02X:%02X:%02X:%02X:%02X:%02X ", extra,
110345 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
110346 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
110347 + sprintf(extra, "%s%-4d", extra, (int)pEntry->Aid);
110348 + sprintf(extra, "%s%-4d", extra, (int)pEntry->apidx);
110349 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi0);
110350 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi1);
110351 + sprintf(extra, "%s%-7d", extra, pEntry->RssiSample.AvgRssi2);
110352 + sprintf(extra, "%s%-10s", extra, GetPhyMode(pEntry->HTPhyMode.field.MODE));
110353 + sprintf(extra, "%s%-6s", extra, GetBW(pEntry->HTPhyMode.field.BW));
110354 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.MCS);
110355 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.ShortGI);
110356 + sprintf(extra, "%s%-6d", extra, pEntry->HTPhyMode.field.STBC);
110357 + sprintf(extra, "%s%-10d, %d, %d%%\n", extra, pEntry->DebugFIFOCount, pEntry->DebugTxCount,
110358 + (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
110359 + sprintf(extra, "%s\n", extra);
110360 + }
110361 + }
110362 +
110363 + return TRUE;
110364 +}
110365 +
110366 +
110367 --- /dev/null
110368 +++ b/drivers/staging/rt2870/TODO
110369 @@ -0,0 +1,10 @@
110370 +TODO:
110371 + - checkpatch.pl clean
110372 + - sparse clean
110373 + - port to in-kernel 80211 stack
110374 + - remove reading from /etc/ config files
110375 + - review by the wireless developer community
110376 +
110377 +Please send any patches or complaints about this driver to Greg
110378 +Kroah-Hartman <greg@kroah.com> and don't bother the upstream wireless
110379 +kernel developers about it, they want nothing to do with it.
110380 --- /dev/null
110381 +++ b/drivers/staging/rt2870/wpa.h
110382 @@ -0,0 +1,357 @@
110383 +/*
110384 + *************************************************************************
110385 + * Ralink Tech Inc.
110386 + * 5F., No.36, Taiyuan St., Jhubei City,
110387 + * Hsinchu County 302,
110388 + * Taiwan, R.O.C.
110389 + *
110390 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
110391 + *
110392 + * This program is free software; you can redistribute it and/or modify *
110393 + * it under the terms of the GNU General Public License as published by *
110394 + * the Free Software Foundation; either version 2 of the License, or *
110395 + * (at your option) any later version. *
110396 + * *
110397 + * This program is distributed in the hope that it will be useful, *
110398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
110399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
110400 + * GNU General Public License for more details. *
110401 + * *
110402 + * You should have received a copy of the GNU General Public License *
110403 + * along with this program; if not, write to the *
110404 + * Free Software Foundation, Inc., *
110405 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
110406 + * *
110407 + *************************************************************************
110408 +
110409 + Module Name:
110410 + wpa.h
110411 +
110412 + Abstract:
110413 +
110414 + Revision History:
110415 + Who When What
110416 + -------- ---------- ----------------------------------------------
110417 + Name Date Modification logs
110418 +*/
110419 +
110420 +#ifndef __WPA_H__
110421 +#define __WPA_H__
110422 +
110423 +// EAPOL Key descripter frame format related length
110424 +#define LEN_KEY_DESC_NONCE 32
110425 +#define LEN_KEY_DESC_IV 16
110426 +#define LEN_KEY_DESC_RSC 8
110427 +#define LEN_KEY_DESC_ID 8
110428 +#define LEN_KEY_DESC_REPLAY 8
110429 +#define LEN_KEY_DESC_MIC 16
110430 +
110431 +// The length is the EAPoL-Key frame except key data field.
110432 +// Please refer to 802.11i-2004 ,Figure 43u in p.78
110433 +#define LEN_EAPOL_KEY_MSG (sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE)
110434 +
110435 +// EAP Code Type.
110436 +#define EAP_CODE_REQUEST 1
110437 +#define EAP_CODE_RESPONSE 2
110438 +#define EAP_CODE_SUCCESS 3
110439 +#define EAP_CODE_FAILURE 4
110440 +
110441 +// EAPOL frame Protocol Version
110442 +#define EAPOL_VER 1
110443 +#define EAPOL_VER2 2
110444 +
110445 +// EAPOL-KEY Descriptor Type
110446 +#define WPA1_KEY_DESC 0xfe
110447 +#define WPA2_KEY_DESC 0x02
110448 +
110449 +// Key Descriptor Version of Key Information
110450 +#define DESC_TYPE_TKIP 1
110451 +#define DESC_TYPE_AES 2
110452 +#define DESC_TYPE_MESH 3
110453 +
110454 +#define LEN_MSG1_2WAY 0x7f
110455 +#define MAX_LEN_OF_EAP_HS 256
110456 +
110457 +#define LEN_MASTER_KEY 32
110458 +
110459 +// EAPOL EK, MK
110460 +#define LEN_EAP_EK 16
110461 +#define LEN_EAP_MICK 16
110462 +#define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK))
110463 +// TKIP key related
110464 +#define LEN_PMKID 16
110465 +#define LEN_TKIP_EK 16
110466 +#define LEN_TKIP_RXMICK 8
110467 +#define LEN_TKIP_TXMICK 8
110468 +#define LEN_AES_EK 16
110469 +#define LEN_AES_KEY LEN_AES_EK
110470 +#define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
110471 +#define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK))
110472 +#define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK)
110473 +#define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
110474 +#define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY))
110475 +#define MIN_LEN_OF_GTK 5
110476 +
110477 +// RSN IE Length definition
110478 +#define MAX_LEN_OF_RSNIE 90
110479 +#define MIN_LEN_OF_RSNIE 8
110480 +
110481 +//EAP Packet Type
110482 +#define EAPPacket 0
110483 +#define EAPOLStart 1
110484 +#define EAPOLLogoff 2
110485 +#define EAPOLKey 3
110486 +#define EAPOLASFAlert 4
110487 +#define EAPTtypeMax 5
110488 +
110489 +#define EAPOL_MSG_INVALID 0
110490 +#define EAPOL_PAIR_MSG_1 1
110491 +#define EAPOL_PAIR_MSG_2 2
110492 +#define EAPOL_PAIR_MSG_3 3
110493 +#define EAPOL_PAIR_MSG_4 4
110494 +#define EAPOL_GROUP_MSG_1 5
110495 +#define EAPOL_GROUP_MSG_2 6
110496 +
110497 +#define PAIRWISEKEY 1
110498 +#define GROUPKEY 0
110499 +
110500 +// Retry timer counter initial value
110501 +#define PEER_MSG1_RETRY_TIMER_CTR 0
110502 +#define PEER_MSG3_RETRY_TIMER_CTR 10
110503 +#define GROUP_MSG1_RETRY_TIMER_CTR 20
110504 +
110505 +
110506 +#define EAPOL_START_DISABLE 0
110507 +#define EAPOL_START_PSK 1
110508 +#define EAPOL_START_1X 2
110509 +
110510 +#define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
110511 +#define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
110512 +#define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
110513 +#define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
110514 +
110515 +#define ROUND_UP(__x, __y) \
110516 + (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
110517 +
110518 +#define ADD_ONE_To_64BIT_VAR(_V) \
110519 +{ \
110520 + UCHAR cnt = LEN_KEY_DESC_REPLAY; \
110521 + do \
110522 + { \
110523 + cnt--; \
110524 + _V[cnt]++; \
110525 + if (cnt == 0) \
110526 + break; \
110527 + }while (_V[cnt] == 0); \
110528 +}
110529 +
110530 +#define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
110531 +
110532 +// EAPOL Key Information definition within Key descriptor format
110533 +typedef struct PACKED _KEY_INFO
110534 +{
110535 +#ifdef RT_BIG_ENDIAN
110536 + UCHAR KeyAck:1;
110537 + UCHAR Install:1;
110538 + UCHAR KeyIndex:2;
110539 + UCHAR KeyType:1;
110540 + UCHAR KeyDescVer:3;
110541 + UCHAR Rsvd:3;
110542 + UCHAR EKD_DL:1; // EKD for AP; DL for STA
110543 + UCHAR Request:1;
110544 + UCHAR Error:1;
110545 + UCHAR Secure:1;
110546 + UCHAR KeyMic:1;
110547 +#else
110548 + UCHAR KeyMic:1;
110549 + UCHAR Secure:1;
110550 + UCHAR Error:1;
110551 + UCHAR Request:1;
110552 + UCHAR EKD_DL:1; // EKD for AP; DL for STA
110553 + UCHAR Rsvd:3;
110554 + UCHAR KeyDescVer:3;
110555 + UCHAR KeyType:1;
110556 + UCHAR KeyIndex:2;
110557 + UCHAR Install:1;
110558 + UCHAR KeyAck:1;
110559 +#endif
110560 +} KEY_INFO, *PKEY_INFO;
110561 +
110562 +// EAPOL Key descriptor format
110563 +typedef struct PACKED _KEY_DESCRIPTER
110564 +{
110565 + UCHAR Type;
110566 + KEY_INFO KeyInfo;
110567 + UCHAR KeyLength[2];
110568 + UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY];
110569 + UCHAR KeyNonce[LEN_KEY_DESC_NONCE];
110570 + UCHAR KeyIv[LEN_KEY_DESC_IV];
110571 + UCHAR KeyRsc[LEN_KEY_DESC_RSC];
110572 + UCHAR KeyId[LEN_KEY_DESC_ID];
110573 + UCHAR KeyMic[LEN_KEY_DESC_MIC];
110574 + UCHAR KeyDataLen[2];
110575 + UCHAR KeyData[MAX_LEN_OF_RSNIE];
110576 +} KEY_DESCRIPTER, *PKEY_DESCRIPTER;
110577 +
110578 +typedef struct PACKED _EAPOL_PACKET
110579 +{
110580 + UCHAR ProVer;
110581 + UCHAR ProType;
110582 + UCHAR Body_Len[2];
110583 + KEY_DESCRIPTER KeyDesc;
110584 +} EAPOL_PACKET, *PEAPOL_PACKET;
110585 +
110586 +//802.11i D10 page 83
110587 +typedef struct PACKED _GTK_ENCAP
110588 +{
110589 +#ifndef RT_BIG_ENDIAN
110590 + UCHAR Kid:2;
110591 + UCHAR tx:1;
110592 + UCHAR rsv:5;
110593 + UCHAR rsv1;
110594 +#else
110595 + UCHAR rsv:5;
110596 + UCHAR tx:1;
110597 + UCHAR Kid:2;
110598 + UCHAR rsv1;
110599 +#endif
110600 + UCHAR GTK[TKIP_GTK_LENGTH];
110601 +} GTK_ENCAP, *PGTK_ENCAP;
110602 +
110603 +typedef struct PACKED _KDE_ENCAP
110604 +{
110605 + UCHAR Type;
110606 + UCHAR Len;
110607 + UCHAR OUI[3];
110608 + UCHAR DataType;
110609 + GTK_ENCAP GTKEncap;
110610 +} KDE_ENCAP, *PKDE_ENCAP;
110611 +
110612 +// For WPA1
110613 +typedef struct PACKED _RSNIE {
110614 + UCHAR oui[4];
110615 + USHORT version;
110616 + UCHAR mcast[4];
110617 + USHORT ucount;
110618 + struct PACKED {
110619 + UCHAR oui[4];
110620 + }ucast[1];
110621 +} RSNIE, *PRSNIE;
110622 +
110623 +// For WPA2
110624 +typedef struct PACKED _RSNIE2 {
110625 + USHORT version;
110626 + UCHAR mcast[4];
110627 + USHORT ucount;
110628 + struct PACKED {
110629 + UCHAR oui[4];
110630 + }ucast[1];
110631 +} RSNIE2, *PRSNIE2;
110632 +
110633 +// AKM Suite
110634 +typedef struct PACKED _RSNIE_AUTH {
110635 + USHORT acount;
110636 + struct PACKED {
110637 + UCHAR oui[4];
110638 + }auth[1];
110639 +} RSNIE_AUTH,*PRSNIE_AUTH;
110640 +
110641 +typedef union PACKED _RSN_CAPABILITIES {
110642 + struct PACKED {
110643 +#ifdef RT_BIG_ENDIAN
110644 + USHORT Rsvd:10;
110645 + USHORT GTKSA_R_Counter:2;
110646 + USHORT PTKSA_R_Counter:2;
110647 + USHORT No_Pairwise:1;
110648 + USHORT PreAuth:1;
110649 +#else
110650 + USHORT PreAuth:1;
110651 + USHORT No_Pairwise:1;
110652 + USHORT PTKSA_R_Counter:2;
110653 + USHORT GTKSA_R_Counter:2;
110654 + USHORT Rsvd:10;
110655 +#endif
110656 + } field;
110657 + USHORT word;
110658 +} RSN_CAPABILITIES, *PRSN_CAPABILITIES;
110659 +
110660 +typedef struct PACKED _EAP_HDR {
110661 + UCHAR ProVer;
110662 + UCHAR ProType;
110663 + UCHAR Body_Len[2];
110664 + UCHAR code;
110665 + UCHAR identifier;
110666 + UCHAR length[2]; // including code and identifier, followed by length-2 octets of data
110667 +} EAP_HDR, *PEAP_HDR;
110668 +
110669 +// For supplicant state machine states. 802.11i Draft 4.1, p. 97
110670 +// We simplified it
110671 +typedef enum _WpaState
110672 +{
110673 + SS_NOTUSE, // 0
110674 + SS_START, // 1
110675 + SS_WAIT_MSG_3, // 2
110676 + SS_WAIT_GROUP, // 3
110677 + SS_FINISH, // 4
110678 + SS_KEYUPDATE, // 5
110679 +} WPA_STATE;
110680 +
110681 +//
110682 +// The definition of the cipher combination
110683 +//
110684 +// bit3 bit2 bit1 bit0
110685 +// +------------+------------+
110686 +// | WPA | WPA2 |
110687 +// +------+-----+------+-----+
110688 +// | TKIP | AES | TKIP | AES |
110689 +// | 0 | 1 | 1 | 0 | -> 0x06
110690 +// | 0 | 1 | 1 | 1 | -> 0x07
110691 +// | 1 | 0 | 0 | 1 | -> 0x09
110692 +// | 1 | 0 | 1 | 1 | -> 0x0B
110693 +// | 1 | 1 | 0 | 1 | -> 0x0D
110694 +// | 1 | 1 | 1 | 0 | -> 0x0E
110695 +// | 1 | 1 | 1 | 1 | -> 0x0F
110696 +// +------+-----+------+-----+
110697 +//
110698 +typedef enum _WpaMixPairCipher
110699 +{
110700 + MIX_CIPHER_NOTUSE = 0x00,
110701 + WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES
110702 + WPA_AES_WPA2_TKIP = 0x06,
110703 + WPA_AES_WPA2_TKIPAES = 0x07,
110704 + WPA_TKIP_WPA2_AES = 0x09,
110705 + WPA_TKIP_WPA2_TKIPAES = 0x0B,
110706 + WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES
110707 + WPA_TKIPAES_WPA2_AES = 0x0D,
110708 + WPA_TKIPAES_WPA2_TKIP = 0x0E,
110709 + WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
110710 +} WPA_MIX_PAIR_CIPHER;
110711 +
110712 +typedef struct PACKED _RSN_IE_HEADER_STRUCT {
110713 + UCHAR Eid;
110714 + UCHAR Length;
110715 + USHORT Version; // Little endian format
110716 +} RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
110717 +
110718 +// Cipher suite selector types
110719 +typedef struct PACKED _CIPHER_SUITE_STRUCT {
110720 + UCHAR Oui[3];
110721 + UCHAR Type;
110722 +} CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
110723 +
110724 +// Authentication and Key Management suite selector
110725 +typedef struct PACKED _AKM_SUITE_STRUCT {
110726 + UCHAR Oui[3];
110727 + UCHAR Type;
110728 +} AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
110729 +
110730 +// RSN capability
110731 +typedef struct PACKED _RSN_CAPABILITY {
110732 + USHORT Rsv:10;
110733 + USHORT GTKSAReplayCnt:2;
110734 + USHORT PTKSAReplayCnt:2;
110735 + USHORT NoPairwise:1;
110736 + USHORT PreAuth:1;
110737 +} RSN_CAPABILITY, *PRSN_CAPABILITY;
110738 +
110739 +#endif