Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[linux-2.6] / drivers / staging / rt2870 / rt_main_dev.c
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27     Module Name:
28     rt_main_dev.c
29
30     Abstract:
31     Create and register network interface.
32
33     Revision History:
34     Who         When            What
35     --------    ----------      ----------------------------------------------
36         Sample          Mar/21/07               Merge RT2870 and RT2860 drivers.
37 */
38
39 #include "rt_config.h"
40
41 #define FORTY_MHZ_INTOLERANT_INTERVAL   (60*1000) // 1 min
42
43 #ifdef MULTIPLE_CARD_SUPPORT
44 // record whether the card in the card list is used in the card file
45 UINT8  MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
46 // record used card mac address in the card list
47 static UINT8  MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
48 #endif // MULTIPLE_CARD_SUPPORT //
49
50 /*---------------------------------------------------------------------*/
51 /* Private Variables Used                                              */
52 /*---------------------------------------------------------------------*/
53 //static RALINK_TIMER_STRUCT     PeriodicTimer;
54
55 char *mac = "";            // default 00:00:00:00:00:00
56 char *hostname = "";
57 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
58 MODULE_PARM (mac, "s");
59 #else
60 module_param (mac, charp, 0);
61 #endif
62 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
63
64
65 /*---------------------------------------------------------------------*/
66 /* Prototypes of Functions Used                                        */
67 /*---------------------------------------------------------------------*/
68 #ifdef DOT11_N_SUPPORT
69 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
70 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
71 #endif // DOT11_N_SUPPORT //
72 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
73
74
75 // public function prototype
76 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
77                                                         IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
78
79 // private function prototype
80 static int rt28xx_init(IN struct net_device *net_dev);
81 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
82
83 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
84 struct net_device *alloc_netdev(
85         int sizeof_priv,
86         const char *mask,
87         void (*setup)(struct net_device *));
88 #endif // LINUX_VERSION_CODE //
89
90 static void CfgInitHook(PRTMP_ADAPTER pAd);
91 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
92
93 #ifdef CONFIG_STA_SUPPORT
94 extern  const struct iw_handler_def rt28xx_iw_handler_def;
95 #endif // CONFIG_STA_SUPPORT //
96
97 #if WIRELESS_EXT >= 12
98 // This function will be called when query /proc
99 struct iw_statistics *rt28xx_get_wireless_stats(
100     IN struct net_device *net_dev);
101 #endif
102
103 struct net_device_stats *RT28xx_get_ether_stats(
104     IN  struct net_device *net_dev);
105
106 /*
107 ========================================================================
108 Routine Description:
109     Close raxx interface.
110
111 Arguments:
112         *net_dev                        the raxx interface pointer
113
114 Return Value:
115     0                                   Open OK
116         otherwise                       Open Fail
117
118 Note:
119         1. if open fail, kernel will not call the close function.
120         2. Free memory for
121                 (1) Mlme Memory Handler:                MlmeHalt()
122                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
123                 (3) BA Reordering:                              ba_reordering_resource_release()
124 ========================================================================
125 */
126 int MainVirtualIF_close(IN struct net_device *net_dev)
127 {
128     RTMP_ADAPTER *pAd = net_dev->ml_priv;
129
130         // Sanity check for pAd
131         if (pAd == NULL)
132                 return 0; // close ok
133
134         netif_carrier_off(pAd->net_dev);
135         netif_stop_queue(pAd->net_dev);
136
137
138
139         VIRTUAL_IF_DOWN(pAd);
140
141         RT_MOD_DEC_USE_COUNT();
142
143         return 0; // close ok
144 }
145
146 /*
147 ========================================================================
148 Routine Description:
149     Open raxx interface.
150
151 Arguments:
152         *net_dev                        the raxx interface pointer
153
154 Return Value:
155     0                                   Open OK
156         otherwise                       Open Fail
157
158 Note:
159         1. if open fail, kernel will not call the close function.
160         2. Free memory for
161                 (1) Mlme Memory Handler:                MlmeHalt()
162                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
163                 (3) BA Reordering:                              ba_reordering_resource_release()
164 ========================================================================
165 */
166 int MainVirtualIF_open(IN struct net_device *net_dev)
167 {
168     RTMP_ADAPTER *pAd = net_dev->ml_priv;
169
170         // Sanity check for pAd
171         if (pAd == NULL)
172                 return 0; // close ok
173
174         if (VIRTUAL_IF_UP(pAd) != 0)
175                 return -1;
176
177         // increase MODULE use count
178         RT_MOD_INC_USE_COUNT();
179
180         netif_start_queue(net_dev);
181         netif_carrier_on(net_dev);
182         netif_wake_queue(net_dev);
183
184         return 0;
185 }
186
187 /*
188 ========================================================================
189 Routine Description:
190     Close raxx interface.
191
192 Arguments:
193         *net_dev                        the raxx interface pointer
194
195 Return Value:
196     0                                   Open OK
197         otherwise                       Open Fail
198
199 Note:
200         1. if open fail, kernel will not call the close function.
201         2. Free memory for
202                 (1) Mlme Memory Handler:                MlmeHalt()
203                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
204                 (3) BA Reordering:                              ba_reordering_resource_release()
205 ========================================================================
206 */
207 int rt28xx_close(IN PNET_DEV dev)
208 {
209         struct net_device * net_dev = (struct net_device *)dev;
210     RTMP_ADAPTER        *pAd = net_dev->ml_priv;
211         BOOLEAN                 Cancelled = FALSE;
212         UINT32                  i = 0;
213 #ifdef RT2870
214         DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
215         DECLARE_WAITQUEUE(wait, current);
216
217         //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
218 #endif // RT2870 //
219
220
221     DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
222
223         // Sanity check for pAd
224         if (pAd == NULL)
225                 return 0; // close ok
226
227
228 #ifdef CONFIG_STA_SUPPORT
229         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
230         {
231
232                 // If dirver doesn't wake up firmware here,
233                 // NICLoadFirmware will hang forever when interface is up again.
234                 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
235         {
236                     AsicForceWakeup(pAd, TRUE);
237         }
238
239 #ifdef QOS_DLS_SUPPORT
240                 // send DLS-TEAR_DOWN message,
241                 if (pAd->CommonCfg.bDLSCapable)
242                 {
243                         UCHAR i;
244
245                         // tear down local dls table entry
246                         for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
247                         {
248                                 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
249                                 {
250                                         RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
251                                         pAd->StaCfg.DLSEntry[i].Status  = DLS_NONE;
252                                         pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
253                                 }
254                         }
255
256                         // tear down peer dls table entry
257                         for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
258                         {
259                                 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
260                                 {
261                                         RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
262                                         pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
263                                         pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
264                                 }
265                         }
266                         RT28XX_MLME_HANDLER(pAd);
267                 }
268 #endif // QOS_DLS_SUPPORT //
269
270                 if (INFRA_ON(pAd) &&
271                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
272                 {
273                         MLME_DISASSOC_REQ_STRUCT        DisReq;
274                         MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
275
276                         COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
277                         DisReq.Reason =  REASON_DEAUTH_STA_LEAVING;
278
279                         MsgElem->Machine = ASSOC_STATE_MACHINE;
280                         MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
281                         MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
282                         NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
283
284                         // Prevent to connect AP again in STAMlmePeriodicExec
285                         pAd->MlmeAux.AutoReconnectSsidLen= 32;
286                         NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
287
288                         pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
289                         MlmeDisassocReqAction(pAd, MsgElem);
290                         kfree(MsgElem);
291
292                         RTMPusecDelay(1000);
293                 }
294
295 #ifdef RT2870
296         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
297 #endif // RT2870 //
298
299 #ifdef CCX_SUPPORT
300                 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
301 #endif
302
303                 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
304                 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
305
306 #ifdef WPA_SUPPLICANT_SUPPORT
307 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
308                 {
309                         union iwreq_data    wrqu;
310                         // send wireless event to wpa_supplicant for infroming interface down.
311                         memset(&wrqu, 0, sizeof(wrqu));
312                         wrqu.data.flags = RT_INTERFACE_DOWN;
313                         wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
314                 }
315 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
316 #endif // WPA_SUPPLICANT_SUPPORT //
317
318                 MlmeRadioOff(pAd);
319         }
320 #endif // CONFIG_STA_SUPPORT //
321
322         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
323
324         for (i = 0 ; i < NUM_OF_TX_RING; i++)
325         {
326                 while (pAd->DeQueueRunning[i] == TRUE)
327                 {
328                         printk("Waiting for TxQueue[%d] done..........\n", i);
329                         RTMPusecDelay(1000);
330                 }
331         }
332
333 #ifdef RT2870
334         // ensure there are no more active urbs.
335         add_wait_queue (&unlink_wakeup, &wait);
336         pAd->wait = &unlink_wakeup;
337
338         // maybe wait for deletions to finish.
339         i = 0;
340         //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
341         while(i < 25)
342         {
343                 unsigned long IrqFlags;
344
345                 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
346                 if (pAd->PendingRx == 0)
347                 {
348                         RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
349                         break;
350                 }
351                 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
352
353 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
354                 msleep(UNLINK_TIMEOUT_MS);      //Time in millisecond
355 #else
356                 RTMPusecDelay(UNLINK_TIMEOUT_MS*1000);  //Time in microsecond
357 #endif
358                 i++;
359         }
360         pAd->wait = NULL;
361         remove_wait_queue (&unlink_wakeup, &wait);
362 #endif // RT2870 //
363
364         //RTUSBCleanUpMLMEWaitQueue(pAd);       /*not used in RT28xx*/
365
366
367 #ifdef RT2870
368         // We need clear timerQ related structure before exits of the timer thread.
369         RT2870_TimerQ_Exit(pAd);
370         // Close kernel threads or tasklets
371         RT28xxThreadTerminate(pAd);
372 #endif // RT2870 //
373
374         // Stop Mlme state machine
375         MlmeHalt(pAd);
376
377         // Close kernel threads or tasklets
378         kill_thread_task(pAd);
379
380
381 #ifdef CONFIG_STA_SUPPORT
382         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
383         {
384                 MacTableReset(pAd);
385         }
386 #endif // CONFIG_STA_SUPPORT //
387
388
389         MeasureReqTabExit(pAd);
390         TpcReqTabExit(pAd);
391
392
393
394
395         // Free Ring or USB buffers
396         RTMPFreeTxRxRingMemory(pAd);
397
398         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
399
400 #ifdef DOT11_N_SUPPORT
401         // Free BA reorder resource
402         ba_reordering_resource_release(pAd);
403 #endif // DOT11_N_SUPPORT //
404
405 #ifdef RT2870
406 #ifdef INF_AMAZON_SE
407         if (pAd->UsbVendorReqBuf)
408                 os_free_mem(pAd, pAd->UsbVendorReqBuf);
409 #endif // INF_AMAZON_SE //
410 #endif // RT2870 //
411
412         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
413
414         return 0; // close ok
415 } /* End of rt28xx_close */
416
417 static int rt28xx_init(IN struct net_device *net_dev)
418 {
419         PRTMP_ADAPTER                   pAd = net_dev->ml_priv;
420         UINT                                    index;
421         UCHAR                                   TmpPhy;
422         NDIS_STATUS                             Status;
423         UINT32          MacCsr0 = 0;
424
425 #ifdef RT2870
426 #ifdef INF_AMAZON_SE
427         init_MUTEX(&(pAd->UsbVendorReq_semaphore));
428         os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
429         if (pAd->UsbVendorReqBuf == NULL)
430         {
431                 DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
432                 goto err0;
433         }
434 #endif // INF_AMAZON_SE //
435 #endif // RT2870 //
436
437 #ifdef DOT11_N_SUPPORT
438         // Allocate BA Reordering memory
439         ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
440 #endif // DOT11_N_SUPPORT //
441
442         // Make sure MAC gets ready.
443         index = 0;
444         do
445         {
446                 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
447                 pAd->MACVersion = MacCsr0;
448
449                 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
450                         break;
451
452                 RTMPusecDelay(10);
453         } while (index++ < 100);
454
455         DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0  [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
456
457         // Disable DMA
458         RT28XXDMADisable(pAd);
459
460
461         // Load 8051 firmware
462         Status = NICLoadFirmware(pAd);
463         if (Status != NDIS_STATUS_SUCCESS)
464         {
465                 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
466                 goto err1;
467         }
468
469         NICLoadRateSwitchingParams(pAd);
470
471         // Disable interrupts here which is as soon as possible
472         // This statement should never be true. We might consider to remove it later
473
474         Status = RTMPAllocTxRxRingMemory(pAd);
475         if (Status != NDIS_STATUS_SUCCESS)
476         {
477                 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
478                 goto err1;
479         }
480
481         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
482
483         // initialize MLME
484         //
485
486         Status = MlmeInit(pAd);
487         if (Status != NDIS_STATUS_SUCCESS)
488         {
489                 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
490                 goto err2;
491         }
492
493         // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
494         //
495         UserCfgInit(pAd);
496
497 #ifdef RT2870
498         // We need init timerQ related structure before create the timer thread.
499         RT2870_TimerQ_Init(pAd);
500 #endif // RT2870 //
501
502         RT28XX_TASK_THREAD_INIT(pAd, Status);
503         if (Status != NDIS_STATUS_SUCCESS)
504                 goto err1;
505
506 //      COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
507 //      pAd->bForcePrintTX = TRUE;
508
509         CfgInitHook(pAd);
510
511
512 #ifdef BLOCK_NET_IF
513         initblockQueueTab(pAd);
514 #endif // BLOCK_NET_IF //
515
516 #ifdef CONFIG_STA_SUPPORT
517         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
518                 NdisAllocateSpinLock(&pAd->MacTabLock);
519 #endif // CONFIG_STA_SUPPORT //
520
521         MeasureReqTabInit(pAd);
522         TpcReqTabInit(pAd);
523
524         //
525         // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
526         //
527         Status = NICInitializeAdapter(pAd, TRUE);
528         if (Status != NDIS_STATUS_SUCCESS)
529         {
530                 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
531                 if (Status != NDIS_STATUS_SUCCESS)
532                 goto err3;
533         }
534
535         // Read parameters from Config File
536         Status = RTMPReadParametersHook(pAd);
537
538         printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
539         if (Status != NDIS_STATUS_SUCCESS)
540         {
541                 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
542                 goto err4;
543         }
544
545 #ifdef RT2870
546         pAd->CommonCfg.bMultipleIRP = FALSE;
547
548         if (pAd->CommonCfg.bMultipleIRP)
549                 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
550         else
551                 pAd->CommonCfg.NumOfBulkInIRP = 1;
552 #endif // RT2870 //
553
554
555         //Init Ba Capability parameters.
556 //      RT28XX_BA_INIT(pAd);
557 #ifdef DOT11_N_SUPPORT
558         pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
559         pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
560         pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
561         pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
562         // UPdata to HT IE
563         pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
564         pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
565         pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
566 #endif // DOT11_N_SUPPORT //
567
568         // after reading Registry, we now know if in AP mode or STA mode
569
570         // Load 8051 firmware; crash when FW image not existent
571         // Status = NICLoadFirmware(pAd);
572         // if (Status != NDIS_STATUS_SUCCESS)
573         //    break;
574
575         printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
576
577         // We should read EEPROM for all cases.  rt2860b
578         NICReadEEPROMParameters(pAd, mac);
579 #ifdef CONFIG_STA_SUPPORT
580 #endif // CONFIG_STA_SUPPORT //
581
582         printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
583
584         NICInitAsicFromEEPROM(pAd); //rt2860b
585
586         // Set PHY to appropriate mode
587         TmpPhy = pAd->CommonCfg.PhyMode;
588         pAd->CommonCfg.PhyMode = 0xff;
589         RTMPSetPhyMode(pAd, TmpPhy);
590 #ifdef DOT11_N_SUPPORT
591         SetCommonHT(pAd);
592 #endif // DOT11_N_SUPPORT //
593
594         // No valid channels.
595         if (pAd->ChannelListNum == 0)
596         {
597                 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
598                 goto err4;
599         }
600
601 #ifdef DOT11_N_SUPPORT
602         printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
603            pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
604            pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
605 #endif // DOT11_N_SUPPORT //
606
607 #ifdef RT2870
608     //Init RT30xx RFRegisters after read RFIC type from EEPROM
609         NICInitRT30xxRFRegisters(pAd);
610 #endif // RT2870 //
611
612 #if 0
613         // Patch cardbus controller if EEPROM said so.
614         if (pAd->bTest1 == FALSE)
615                 RTMPPatchCardBus(pAd);
616 #endif
617
618
619 //              APInitialize(pAd);
620
621 #ifdef IKANOS_VX_1X0
622         VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
623 #endif // IKANOS_VX_1X0 //
624
625                 //
626         // Initialize RF register to default value
627         //
628         AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
629         AsicLockChannel(pAd, pAd->CommonCfg.Channel);
630
631         // 8051 firmware require the signal during booting time.
632         AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
633
634         if (pAd && (Status != NDIS_STATUS_SUCCESS))
635         {
636                 //
637                 // Undo everything if it failed
638                 //
639                 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
640                 {
641 //                      NdisMDeregisterInterrupt(&pAd->Interrupt);
642                         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
643                 }
644 //              RTMPFreeAdapter(pAd); // we will free it in disconnect()
645         }
646         else if (pAd)
647         {
648                 // Microsoft HCT require driver send a disconnect event after driver initialization.
649                 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
650 //              pAd->IndicateMediaState = NdisMediaStateDisconnected;
651                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
652
653                 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
654
655
656 #ifdef RT2870
657                 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
658                 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
659
660                 //
661                 // Support multiple BulkIn IRP,
662                 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
663                 //
664                 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
665                 {
666                         RTUSBBulkReceive(pAd);
667                         DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
668                 }
669 #endif // RT2870 //
670         }// end of else
671
672
673         DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
674
675         return TRUE;
676
677
678 err4:
679 err3:
680         MlmeHalt(pAd);
681 err2:
682         RTMPFreeTxRxRingMemory(pAd);
683 //      RTMPFreeAdapter(pAd);
684 err1:
685
686 #ifdef DOT11_N_SUPPORT
687         os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
688 #endif // DOT11_N_SUPPORT //
689         RT28XX_IRQ_RELEASE(net_dev);
690
691         // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
692         //net_dev->ml_priv = 0;
693 #ifdef INF_AMAZON_SE
694 err0:
695 #endif // INF_AMAZON_SE //
696         printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
697         return FALSE;
698 } /* End of rt28xx_init */
699
700
701 /*
702 ========================================================================
703 Routine Description:
704     Open raxx interface.
705
706 Arguments:
707         *net_dev                        the raxx interface pointer
708
709 Return Value:
710     0                                   Open OK
711         otherwise                       Open Fail
712
713 Note:
714 ========================================================================
715 */
716 int rt28xx_open(IN PNET_DEV dev)
717 {
718         struct net_device * net_dev = (struct net_device *)dev;
719         PRTMP_ADAPTER pAd = net_dev->ml_priv;
720         int retval = 0;
721         POS_COOKIE pObj;
722
723
724         // Sanity check for pAd
725         if (pAd == NULL)
726         {
727                 /* if 1st open fail, pAd will be free;
728                    So the net_dev->ml_priv will be NULL in 2rd open */
729                 return -1;
730         }
731
732 #ifdef CONFIG_APSTA_MIXED_SUPPORT
733         if (pAd->OpMode == OPMODE_AP)
734         {
735                 CW_MAX_IN_BITS = 6;
736         }
737         else if (pAd->OpMode == OPMODE_STA)
738         {
739                 CW_MAX_IN_BITS = 10;
740         }
741
742 #if WIRELESS_EXT >= 12
743         if (net_dev->priv_flags == INT_MAIN)
744         {
745                 if (pAd->OpMode == OPMODE_AP)
746                         net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
747                 else if (pAd->OpMode == OPMODE_STA)
748                         net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
749         }
750 #endif // WIRELESS_EXT >= 12 //
751 #endif // CONFIG_APSTA_MIXED_SUPPORT //
752
753 #ifdef CONFIG_STA_SUPPORT
754 #endif // CONFIG_STA_SUPPORT //
755
756         // Init
757         pObj = (POS_COOKIE)pAd->OS_Cookie;
758
759         // reset Adapter flags
760         RTMP_CLEAR_FLAGS(pAd);
761
762         // Request interrupt service routine for PCI device
763         // register the interrupt routine with the os
764         RT28XX_IRQ_REQUEST(net_dev);
765
766
767         // Init BssTab & ChannelInfo tabbles for auto channel select.
768
769
770         // Chip & other init
771         if (rt28xx_init(net_dev) == FALSE)
772                 goto err;
773
774 #ifdef CONFIG_STA_SUPPORT
775         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
776         {
777                 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
778                 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
779         }
780 #endif // CONFIG_STA_SUPPORT //
781
782         // Set up the Mac address
783         NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
784
785         // Init IRQ parameters
786         RT28XX_IRQ_INIT(pAd);
787
788         // Various AP function init
789
790 #ifdef CONFIG_STA_SUPPORT
791         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
792         {
793 #ifdef WPA_SUPPLICANT_SUPPORT
794 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
795                 {
796                         union iwreq_data    wrqu;
797                         // send wireless event to wpa_supplicant for infroming interface down.
798                         memset(&wrqu, 0, sizeof(wrqu));
799                         wrqu.data.flags = RT_INTERFACE_UP;
800                         wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
801                 }
802 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
803 #endif // WPA_SUPPLICANT_SUPPORT //
804
805         }
806 #endif // CONFIG_STA_SUPPORT //
807
808         // Enable Interrupt
809         RT28XX_IRQ_ENABLE(pAd);
810
811         // Now Enable RxTx
812         RTMPEnableRxTx(pAd);
813         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
814
815         {
816         UINT32 reg = 0;
817         RTMP_IO_READ32(pAd, 0x1300, &reg);  // clear garbage interrupts
818         printk("0x1300 = %08x\n", reg);
819         }
820
821         {
822 //      u32 reg;
823 //      u8  byte;
824 //      u16 tmp;
825
826 //      RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg);
827
828 //      tmp = 0x0805;
829 //      reg  = (reg & 0xffff0000) | tmp;
830 //      RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
831
832         }
833
834 #if 0
835         /*
836          * debugging helper
837          *              show the size of main table in Adapter structure
838          *              MacTab  -- 185K
839          *              BATable -- 137K
840          *              Total   -- 385K  !!!!! (5/26/2006)
841          */
842         printk("sizeof(pAd->MacTab) = %ld\n", sizeof(pAd->MacTab));
843         printk("sizeof(pAd->AccessControlList) = %ld\n", sizeof(pAd->AccessControlList));
844         printk("sizeof(pAd->ApCfg) = %ld\n", sizeof(pAd->ApCfg));
845         printk("sizeof(pAd->BATable) = %ld\n", sizeof(pAd->BATable));
846         BUG();
847 #endif
848
849 #ifdef CONFIG_STA_SUPPORT
850 #endif // CONFIG_STA_SUPPORT //
851
852         return (retval);
853
854 err:
855         return (-1);
856 } /* End of rt28xx_open */
857
858 static const struct net_device_ops rt2870_netdev_ops = {
859         .ndo_open               = MainVirtualIF_open,
860         .ndo_stop               = MainVirtualIF_close,
861         .ndo_do_ioctl           = rt28xx_ioctl,
862         .ndo_get_stats          = RT28xx_get_ether_stats,
863         .ndo_validate_addr      = NULL,
864         .ndo_set_mac_address    = eth_mac_addr,
865         .ndo_change_mtu         = eth_change_mtu,
866 #ifdef IKANOS_VX_1X0
867         .ndo_start_xmit         = IKANOS_DataFramesTx,
868 #else
869         .ndo_start_xmit         = rt28xx_send_packets,
870 #endif
871 };
872
873 /* Must not be called for mdev and apdev */
874 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
875 {
876         NDIS_STATUS Status;
877         INT     i=0;
878         CHAR    slot_name[IFNAMSIZ];
879         struct net_device   *device;
880
881
882         //ether_setup(dev);
883 //      dev->set_multicast_list = ieee80211_set_multicast_list;
884 //      dev->change_mtu = ieee80211_change_mtu;
885 #ifdef CONFIG_STA_SUPPORT
886 #if WIRELESS_EXT >= 12
887         if (pAd->OpMode == OPMODE_STA)
888         {
889                 dev->wireless_handlers = &rt28xx_iw_handler_def;
890         }
891 #endif //WIRELESS_EXT >= 12
892 #endif // CONFIG_STA_SUPPORT //
893
894 #ifdef CONFIG_APSTA_MIXED_SUPPORT
895 #if WIRELESS_EXT >= 12
896         if (pAd->OpMode == OPMODE_AP)
897         {
898                 dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
899         }
900 #endif //WIRELESS_EXT >= 12
901 #endif // CONFIG_APSTA_MIXED_SUPPORT //
902
903 #if WIRELESS_EXT < 21
904                 dev->get_wireless_stats = rt28xx_get_wireless_stats;
905 #endif
906 //      dev->uninit = ieee80211_if_reinit;
907 //      dev->destructor = ieee80211_if_free;
908         dev->priv_flags = INT_MAIN;
909         dev->netdev_ops = &rt2870_netdev_ops;
910         // find available device name
911         for (i = 0; i < 8; i++)
912         {
913 #ifdef MULTIPLE_CARD_SUPPORT
914                 if (pAd->MC_RowID >= 0)
915                         sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
916                 else
917 #endif // MULTIPLE_CARD_SUPPORT //
918                 sprintf(slot_name, "ra%d", i);
919
920 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
921 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
922 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
923         device = dev_get_by_name(dev_net(dev), slot_name);
924 #else
925         device = dev_get_by_name(dev->nd_net, slot_name);
926 #endif
927 #else
928                 device = dev_get_by_name(slot_name);
929 #endif
930                 if (device != NULL) dev_put(device);
931 #else
932                 for (device = dev_base; device != NULL; device = device->next)
933                 {
934                         if (strncmp(device->name, slot_name, 4) == 0)
935                                 break;
936                 }
937 #endif
938                 if(device == NULL)
939                         break;
940         }
941
942         if(i == 8)
943         {
944                 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
945                 Status = NDIS_STATUS_FAILURE;
946         }
947         else
948         {
949 #ifdef MULTIPLE_CARD_SUPPORT
950                 if (pAd->MC_RowID >= 0)
951                 sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
952                 else
953 #endif // MULTIPLE_CARD_SUPPORT //
954                 sprintf(dev->name, "ra%d", i);
955                 Status = NDIS_STATUS_SUCCESS;
956         }
957
958         return Status;
959
960 }
961
962
963 #ifdef MULTIPLE_CARD_SUPPORT
964 /*
965 ========================================================================
966 Routine Description:
967     Get card profile path.
968
969 Arguments:
970     pAd
971
972 Return Value:
973     TRUE                - Find a card profile
974         FALSE           - use default profile
975
976 Note:
977 ========================================================================
978 */
979 extern INT RTMPGetKeyParameter(
980     IN  PCHAR   key,
981     OUT PCHAR   dest,
982     IN  INT     destsize,
983     IN  PCHAR   buffer);
984
985 BOOLEAN RTMP_CardInfoRead(
986         IN      PRTMP_ADAPTER pAd)
987 {
988 #define MC_SELECT_CARDID                0       /* use CARD ID (0 ~ 31) to identify different cards */
989 #define MC_SELECT_MAC                   1       /* use CARD MAC to identify different cards */
990 #define MC_SELECT_CARDTYPE              2       /* use CARD type (abgn or bgn) to identify different cards */
991
992 #define LETTER_CASE_TRANSLATE(txt_p, card_id)                   \
993         {       UINT32 _len; char _char;                                                \
994                 for(_len=0; _len<strlen(card_id); _len++) {             \
995                         _char = *(txt_p + _len);                                        \
996                         if (('A' <= _char) && (_char <= 'Z'))           \
997                                 *(txt_p+_len) = 'a'+(_char-'A');                \
998                 } }
999
1000         struct file *srcf;
1001         INT retval, orgfsuid, orgfsgid;
1002         mm_segment_t orgfs;
1003         CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
1004         BOOLEAN flg_match_ok = FALSE;
1005         INT32 card_select_method;
1006         INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
1007         EEPROM_ANTENNA_STRUC antenna;
1008         USHORT addr01, addr23, addr45;
1009         UINT8 mac[6];
1010         UINT32 data, card_index;
1011         UCHAR *start_ptr;
1012
1013
1014         // init
1015         buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
1016         if (buffer == NULL)
1017         return FALSE;
1018
1019         tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
1020         if(tmpbuf == NULL)
1021         {
1022                 kfree(buffer);
1023         return NDIS_STATUS_FAILURE;
1024         }
1025
1026         orgfsuid = current->fsuid;
1027         orgfsgid = current->fsgid;
1028         current->fsuid = current->fsgid = 0;
1029     orgfs = get_fs();
1030     set_fs(KERNEL_DS);
1031
1032         // get RF IC type
1033         RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
1034
1035         if ((data & 0x30) == 0)
1036                 pAd->EEPROMAddressNum = 6;      // 93C46
1037         else if ((data & 0x30) == 0x10)
1038                 pAd->EEPROMAddressNum = 8;      // 93C66
1039         else
1040                 pAd->EEPROMAddressNum = 8;      // 93C86
1041
1042         //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
1043         RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
1044
1045         if ((antenna.field.RfIcType == RFIC_2850) ||
1046                 (antenna.field.RfIcType == RFIC_2750))
1047         {
1048                 /* ABGN card */
1049                 strcpy(RFIC_word, "abgn");
1050         }
1051         else
1052         {
1053                 /* BGN card */
1054                 strcpy(RFIC_word, "bgn");
1055         }
1056
1057         // get MAC address
1058         //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
1059         //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
1060         //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
1061         RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
1062         RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
1063         RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
1064
1065         mac[0] = (UCHAR)(addr01 & 0xff);
1066         mac[1] = (UCHAR)(addr01 >> 8);
1067         mac[2] = (UCHAR)(addr23 & 0xff);
1068         mac[3] = (UCHAR)(addr23 >> 8);
1069         mac[4] = (UCHAR)(addr45 & 0xff);
1070         mac[5] = (UCHAR)(addr45 >> 8);
1071
1072         // open card information file
1073         srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
1074         if (IS_ERR(srcf))
1075         {
1076                 /* card information file does not exist */
1077                         DBGPRINT(RT_DEBUG_TRACE,
1078                                 ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
1079                 return FALSE;
1080         }
1081
1082         if (srcf->f_op && srcf->f_op->read)
1083         {
1084                 /* card information file exists so reading the card information */
1085                 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
1086                 retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
1087                 if (retval < 0)
1088                 {
1089                         /* read fail */
1090                                 DBGPRINT(RT_DEBUG_TRACE,
1091                                         ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
1092                 }
1093                 else
1094                 {
1095                         /* get card selection method */
1096                         memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
1097                         card_select_method = MC_SELECT_CARDTYPE; // default
1098
1099                         if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
1100                         {
1101                                 if (strcmp(tmpbuf, "CARDID") == 0)
1102                                         card_select_method = MC_SELECT_CARDID;
1103                                 else if (strcmp(tmpbuf, "MAC") == 0)
1104                                         card_select_method = MC_SELECT_MAC;
1105                                 else if (strcmp(tmpbuf, "CARDTYPE") == 0)
1106                                         card_select_method = MC_SELECT_CARDTYPE;
1107                         }
1108
1109                         DBGPRINT(RT_DEBUG_TRACE,
1110                                         ("MC> Card Selection = %d\n", card_select_method));
1111
1112                         // init
1113                         card_free_id = -1;
1114                         card_nouse_id = -1;
1115                         card_same_mac_id = -1;
1116                         card_match_id = -1;
1117
1118                         // search current card information records
1119                         for(card_index=0;
1120                                 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1121                                 card_index++)
1122                         {
1123                                 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1124                                         (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1125                                 {
1126                                         // MAC is all-0 so the entry is available
1127                                         MC_CardUsed[card_index] = 0;
1128
1129                                         if (card_free_id < 0)
1130                                                 card_free_id = card_index; // 1st free entry
1131                                 }
1132                                 else
1133                                 {
1134                                         if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
1135                                         {
1136                                                 // we find the entry with same MAC
1137                                                 if (card_same_mac_id < 0)
1138                                                         card_same_mac_id = card_index; // 1st same entry
1139                                         }
1140                                         else
1141                                         {
1142                                                 // MAC is not all-0 but used flag == 0
1143                                                 if ((MC_CardUsed[card_index] == 0) &&
1144                                                         (card_nouse_id < 0))
1145                                                 {
1146                                                         card_nouse_id = card_index; // 1st available entry
1147                                                 }
1148                                         }
1149                                 }
1150                         }
1151
1152                         DBGPRINT(RT_DEBUG_TRACE,
1153                                         ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1154                                         card_free_id, card_same_mac_id, card_nouse_id));
1155
1156                         if ((card_same_mac_id >= 0) &&
1157                                 ((card_select_method == MC_SELECT_CARDID) ||
1158                                 (card_select_method == MC_SELECT_CARDTYPE)))
1159                         {
1160                                 // same MAC entry is found
1161                                 card_match_id = card_same_mac_id;
1162
1163                                 if (card_select_method == MC_SELECT_CARDTYPE)
1164                                 {
1165                                         // for CARDTYPE
1166                                         sprintf(card_id_buf, "%02dCARDTYPE%s",
1167                                                         card_match_id, RFIC_word);
1168
1169                                         if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1170                                         {
1171                                                 // we found the card ID
1172                                                 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1173                                         }
1174                                 }
1175                         }
1176                         else
1177                         {
1178                                 // the card is 1st plug-in, try to find the match card profile
1179                                 switch(card_select_method)
1180                                 {
1181                                         case MC_SELECT_CARDID: // CARDID
1182                                         default:
1183                                                 if (card_free_id >= 0)
1184                                                         card_match_id = card_free_id;
1185                                                 else
1186                                                         card_match_id = card_nouse_id;
1187                                                 break;
1188
1189                                         case MC_SELECT_MAC: // MAC
1190                                                 sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1191                                                                 mac[0], mac[1], mac[2],
1192                                                                 mac[3], mac[4], mac[5]);
1193
1194                                                 /* try to find the key word in the card file */
1195                                                 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1196                                                 {
1197                                                         LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1198
1199                                                         /* get the row ID (2 ASCII characters) */
1200                                                         start_ptr -= 2;
1201                                                         card_id_buf[0] = *(start_ptr);
1202                                                         card_id_buf[1] = *(start_ptr+1);
1203                                                         card_id_buf[2] = 0x00;
1204
1205                                                         card_match_id = simple_strtol(card_id_buf, 0, 10);
1206                                                 }
1207                                                 break;
1208
1209                                         case MC_SELECT_CARDTYPE: // CARDTYPE
1210                                                 card_nouse_id = -1;
1211
1212                                                 for(card_index=0;
1213                                                         card_index<MAX_NUM_OF_MULTIPLE_CARD;
1214                                                         card_index++)
1215                                                 {
1216                                                         sprintf(card_id_buf, "%02dCARDTYPE%s",
1217                                                                         card_index, RFIC_word);
1218
1219                                                         if ((start_ptr=rtstrstruncasecmp(buffer,
1220                                                                                                                 card_id_buf)) != NULL)
1221                                                         {
1222                                                                 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1223
1224                                                                 if (MC_CardUsed[card_index] == 0)
1225                                                                 {
1226                                                                         /* current the card profile is not used */
1227                                                                         if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1228                                                                                 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1229                                                                         {
1230                                                                                 // find it and no previous card use it
1231                                                                                 card_match_id = card_index;
1232                                                                                 break;
1233                                                                         }
1234                                                                         else
1235                                                                         {
1236                                                                                 // ever a card use it
1237                                                                                 if (card_nouse_id < 0)
1238                                                                                         card_nouse_id = card_index;
1239                                                                         }
1240                                                                 }
1241                                                         }
1242                                                 }
1243
1244                                                 // if not find a free one, use the available one
1245                                                 if (card_match_id < 0)
1246                                                         card_match_id = card_nouse_id;
1247                                                 break;
1248                                 }
1249                         }
1250
1251                         if (card_match_id >= 0)
1252                         {
1253                                 // make up search keyword
1254                                 switch(card_select_method)
1255                                 {
1256                                         case MC_SELECT_CARDID: // CARDID
1257                                                 sprintf(card_id_buf, "%02dCARDID", card_match_id);
1258                                                 break;
1259
1260                                         case MC_SELECT_MAC: // MAC
1261                                                 sprintf(card_id_buf,
1262                                                                 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1263                                                                 card_match_id,
1264                                                                 mac[0], mac[1], mac[2],
1265                                                                 mac[3], mac[4], mac[5]);
1266                                                 break;
1267
1268                                         case MC_SELECT_CARDTYPE: // CARDTYPE
1269                                         default:
1270                                                 sprintf(card_id_buf, "%02dcardtype%s",
1271                                                                 card_match_id, RFIC_word);
1272                                                 break;
1273                                 }
1274
1275                                 DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
1276
1277                                 // read card file path
1278                                 if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
1279                                 {
1280                                         if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
1281                                         {
1282                                                 // backup card information
1283                                                 pAd->MC_RowID = card_match_id; /* base 0 */
1284                                                 MC_CardUsed[card_match_id] = 1;
1285                                                 memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
1286
1287                                                 // backup card file path
1288                                                 NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
1289                                                 pAd->MC_FileName[strlen(tmpbuf)] = '\0';
1290                                                 flg_match_ok = TRUE;
1291
1292                                                 DBGPRINT(RT_DEBUG_TRACE,
1293                                                                 ("Card Profile Name = %s\n", pAd->MC_FileName));
1294                                         }
1295                                         else
1296                                         {
1297                                                 DBGPRINT(RT_DEBUG_ERROR,
1298                                                                 ("Card Profile Name length too large!\n"));
1299                                         }
1300                                 }
1301                                 else
1302                                 {
1303                                         DBGPRINT(RT_DEBUG_ERROR,
1304                                                         ("Can not find search key word in card.dat!\n"));
1305                                 }
1306
1307                                 if ((flg_match_ok != TRUE) &&
1308                                         (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
1309                                 {
1310                                         MC_CardUsed[card_match_id] = 0;
1311                                         memset(MC_CardMac[card_match_id], 0, sizeof(mac));
1312                                 }
1313                         } // if (card_match_id >= 0)
1314                 }
1315         }
1316
1317         // close file
1318         retval = filp_close(srcf, NULL);
1319         set_fs(orgfs);
1320         current->fsuid = orgfsuid;
1321         current->fsgid = orgfsgid;
1322         kfree(buffer);
1323         kfree(tmpbuf);
1324         return flg_match_ok;
1325 }
1326 #endif // MULTIPLE_CARD_SUPPORT //
1327
1328
1329 /*
1330 ========================================================================
1331 Routine Description:
1332     Probe RT28XX chipset.
1333
1334 Arguments:
1335     _dev_p                              Point to the PCI or USB device
1336         _dev_id_p                       Point to the PCI or USB device ID
1337
1338 Return Value:
1339     0                                   Probe OK
1340         -ENODEV                         Probe Fail
1341
1342 Note:
1343 ========================================================================
1344 */
1345 INT __devinit   rt28xx_probe(
1346     IN  void *_dev_p,
1347     IN  void *_dev_id_p,
1348         IN  UINT argc,
1349         OUT PRTMP_ADAPTER *ppAd)
1350 {
1351     struct  net_device  *net_dev;
1352     PRTMP_ADAPTER       pAd = (PRTMP_ADAPTER) NULL;
1353     INT                 status;
1354         PVOID                           handle;
1355 #ifdef RT2870
1356 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)  /* kernel 2.4 series */
1357         struct usb_device *dev_p = (struct usb_device *)_dev_p;
1358 #else
1359         struct usb_interface *intf = (struct usb_interface *)_dev_p;
1360         struct usb_device *dev_p = interface_to_usbdev(intf);
1361
1362         dev_p = usb_get_dev(dev_p);
1363 #endif // LINUX_VERSION_CODE //
1364 #endif // RT2870 //
1365
1366
1367 #ifdef CONFIG_STA_SUPPORT
1368     DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
1369 #endif // CONFIG_STA_SUPPORT //
1370
1371         // Check chipset vendor/product ID
1372 //      if (RT28XXChipsetCheck(_dev_p) == FALSE)
1373 //              goto err_out;
1374
1375 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
1376     net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
1377 #else
1378     net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
1379 #endif
1380     if (net_dev == NULL)
1381     {
1382         printk("alloc_netdev failed\n");
1383
1384 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1385 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1386                 module_put(THIS_MODULE);
1387 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1388 #else
1389                 MOD_DEC_USE_COUNT;
1390 #endif
1391         goto err_out;
1392     }
1393
1394 // sample
1395 //      if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1396 //              goto err_out;
1397
1398 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1399     SET_MODULE_OWNER(net_dev);
1400 #endif
1401
1402         netif_stop_queue(net_dev);
1403 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1404 /* for supporting Network Manager */
1405 /* Set the sysfs physical device reference for the network logical device
1406  * if set prior to registration will cause a symlink during initialization.
1407  */
1408 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1409     SET_NETDEV_DEV(net_dev, &(dev_p->dev));
1410 #endif
1411 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1412
1413         // Allocate RTMP_ADAPTER miniport adapter structure
1414         handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
1415         RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
1416
1417         status = RTMPAllocAdapterBlock(handle, &pAd);
1418         if (status != NDIS_STATUS_SUCCESS)
1419                 goto err_out_free_netdev;
1420
1421         net_dev->ml_priv = (PVOID)pAd;
1422     pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
1423
1424         RT28XXNetDevInit(_dev_p, net_dev, pAd);
1425
1426 #ifdef CONFIG_STA_SUPPORT
1427     pAd->StaCfg.OriDevType = net_dev->type;
1428 #endif // CONFIG_STA_SUPPORT //
1429
1430         // Find and assign a free interface name, raxx
1431 //      RT28XXAvailRANameAssign(net_dev->name);
1432
1433         // Post config
1434 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1435         if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
1436                 goto err_out_unmap;
1437 #else
1438         if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
1439                 goto err_out_unmap;
1440 #endif // LINUX_VERSION_CODE //
1441
1442 #ifdef CONFIG_STA_SUPPORT
1443         pAd->OpMode = OPMODE_STA;
1444 #endif // CONFIG_STA_SUPPORT //
1445
1446
1447 #ifdef MULTIPLE_CARD_SUPPORT
1448         // find its profile path
1449         pAd->MC_RowID = -1; // use default profile path
1450         RTMP_CardInfoRead(pAd);
1451
1452         if (pAd->MC_RowID == -1)
1453 #ifdef CONFIG_STA_SUPPORT
1454                 strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
1455 #endif // CONFIG_STA_SUPPORT //
1456
1457         DBGPRINT(RT_DEBUG_TRACE,
1458                         ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
1459 #endif // MULTIPLE_CARD_SUPPORT //
1460
1461         // sample move
1462         if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
1463                 goto err_out_unmap;
1464
1465     // Register this device
1466     status = register_netdev(net_dev);
1467     if (status)
1468         goto err_out_unmap;
1469
1470     // Set driver data
1471         RT28XX_DRVDATA_SET(_dev_p);
1472
1473
1474
1475         *ppAd = pAd;
1476     return 0; // probe ok
1477
1478
1479         /* --------------------------- ERROR HANDLE --------------------------- */
1480 err_out_unmap:
1481         RTMPFreeAdapter(pAd);
1482         RT28XX_UNMAP();
1483
1484 err_out_free_netdev:
1485 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1486     free_netdev(net_dev);
1487 #else
1488         kfree(net_dev);
1489 #endif
1490
1491 err_out:
1492         RT28XX_PUT_DEVICE(dev_p);
1493
1494 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1495         return (LONG)NULL;
1496 #else
1497     return -ENODEV; /* probe fail */
1498 #endif // LINUX_VERSION_CODE //
1499 } /* End of rt28xx_probe */
1500
1501
1502 /*
1503 ========================================================================
1504 Routine Description:
1505     The entry point for Linux kernel sent packet to our driver.
1506
1507 Arguments:
1508     sk_buff *skb                the pointer refer to a sk_buffer.
1509
1510 Return Value:
1511     0
1512
1513 Note:
1514         This function is the entry point of Tx Path for Os delivery packet to
1515         our driver. You only can put OS-depened & STA/AP common handle procedures
1516         in here.
1517 ========================================================================
1518 */
1519 int rt28xx_packet_xmit(struct sk_buff *skb)
1520 {
1521         struct net_device *net_dev = skb->dev;
1522         PRTMP_ADAPTER pAd = net_dev->ml_priv;
1523         int status = 0;
1524         PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
1525
1526         /* RT2870STA does this in RTMPSendPackets() */
1527 #ifdef RALINK_ATE
1528         if (ATE_ON(pAd))
1529         {
1530                 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
1531                 return 0;
1532         }
1533 #endif // RALINK_ATE //
1534
1535 #ifdef CONFIG_STA_SUPPORT
1536         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1537         {
1538                 // Drop send request since we are in monitor mode
1539                 if (MONITOR_ON(pAd))
1540                 {
1541                         RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1542                         goto done;
1543                 }
1544         }
1545 #endif // CONFIG_STA_SUPPORT //
1546
1547         // EapolStart size is 18
1548         if (skb->len < 14)
1549         {
1550                 //printk("bad packet size: %d\n", pkt->len);
1551                 hex_dump("bad packet", skb->data, skb->len);
1552                 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1553                 goto done;
1554         }
1555
1556 #if 0
1557 //      if ((pkt->data[0] & 0x1) == 0)
1558         {
1559                 //hex_dump(__func__, pkt->data, pkt->len);
1560                 printk("pPacket = %x\n", pPacket);
1561         }
1562 #endif
1563
1564         RTMP_SET_PACKET_5VT(pPacket, 0);
1565 //      MiniportMMRequest(pAd, pkt->data, pkt->len);
1566 #ifdef CONFIG_5VT_ENHANCE
1567     if (*(int*)(skb->cb) == BRIDGE_TAG) {
1568                 RTMP_SET_PACKET_5VT(pPacket, 1);
1569     }
1570 #endif
1571
1572
1573
1574 #ifdef CONFIG_STA_SUPPORT
1575         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1576         {
1577
1578                 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1579         }
1580
1581 #endif // CONFIG_STA_SUPPORT //
1582
1583         status = 0;
1584 done:
1585
1586         return status;
1587 }
1588
1589
1590 /*
1591 ========================================================================
1592 Routine Description:
1593     Send a packet to WLAN.
1594
1595 Arguments:
1596     skb_p           points to our adapter
1597     dev_p           which WLAN network interface
1598
1599 Return Value:
1600     0: transmit successfully
1601     otherwise: transmit fail
1602
1603 Note:
1604 ========================================================================
1605 */
1606 INT rt28xx_send_packets(
1607         IN struct sk_buff               *skb_p,
1608         IN struct net_device    *net_dev)
1609 {
1610     RTMP_ADAPTER *pAd = net_dev->ml_priv;
1611
1612         if (!(net_dev->flags & IFF_UP))
1613         {
1614                 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1615                 return 0;
1616         }
1617
1618         NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1619         RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1620
1621         return rt28xx_packet_xmit(skb_p);
1622 } /* End of MBSS_VirtualIF_PacketSend */
1623
1624
1625
1626
1627 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
1628 //static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
1629 struct net_device *alloc_netdev(
1630         int sizeof_priv,
1631         const char *mask,
1632         void (*setup)(struct net_device *))
1633 {
1634     struct net_device   *dev;
1635     INT                                 alloc_size;
1636
1637
1638     /* ensure 32-byte alignment of the private area */
1639     alloc_size = sizeof (*dev) + sizeof_priv + 31;
1640
1641     dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
1642     if (dev == NULL)
1643     {
1644         DBGPRINT(RT_DEBUG_ERROR,
1645                                 ("alloc_netdev: Unable to allocate device memory.\n"));
1646         return NULL;
1647     }
1648
1649     memset(dev, 0, alloc_size);
1650
1651     if (sizeof_priv)
1652         dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
1653
1654     setup(dev);
1655     strcpy(dev->name, mask);
1656
1657     return dev;
1658 }
1659 #endif // LINUX_VERSION_CODE //
1660
1661
1662 void CfgInitHook(PRTMP_ADAPTER pAd)
1663 {
1664         pAd->bBroadComHT = TRUE;
1665 } /* End of CfgInitHook */
1666
1667
1668 #if 0   // Not used now, should keep it in our source tree??
1669 /*
1670 ========================================================================
1671 Routine Description:
1672     Find and assign a free interface name (raxx).
1673
1674 Arguments:
1675     *name_p                             the interface name pointer
1676
1677 Return Value:
1678         TRUE                            OK
1679         FALSE                           FAIL
1680
1681 Note:
1682 ========================================================================
1683 */
1684 static BOOLEAN RT28XXAvailRANameAssign(
1685         IN CHAR                 *name_p)
1686 {
1687     CHAR                                slot_name[IFNAMSIZ];
1688     struct net_device   *device;
1689         UINT32                          if_id;
1690
1691
1692     for(if_id=0; if_id<8; if_id++)
1693     {
1694         sprintf(slot_name, "ra%d", if_id);
1695
1696         for(device=dev_base; device!=NULL; device=device->next)
1697         {
1698             if (strncmp(device->name, slot_name, 4) == 0)
1699                 break;
1700         }
1701
1702         if (device == NULL)
1703                         break;
1704     }
1705
1706     if (if_id == 8)
1707     {
1708         DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
1709         return FALSE;
1710     }
1711
1712     sprintf(name_p, "ra%d", if_id);
1713         return TRUE;
1714 } /* End of RT28XXAvailRANameAssign */
1715 #endif
1716
1717 #if WIRELESS_EXT >= 12
1718 // This function will be called when query /proc
1719 struct iw_statistics *rt28xx_get_wireless_stats(
1720     IN struct net_device *net_dev)
1721 {
1722         PRTMP_ADAPTER pAd = net_dev->ml_priv;
1723
1724
1725         DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1726
1727         pAd->iw_stats.status = 0; // Status - device dependent for now
1728
1729         // link quality
1730         pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1731         if(pAd->iw_stats.qual.qual > 100)
1732                 pAd->iw_stats.qual.qual = 100;
1733
1734 #ifdef CONFIG_STA_SUPPORT
1735         if (pAd->OpMode == OPMODE_STA)
1736                 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1737 #endif // CONFIG_STA_SUPPORT //
1738
1739         pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1740
1741         pAd->iw_stats.qual.noise += 256 - 143;
1742         pAd->iw_stats.qual.updated = 1;     // Flags to know if updated
1743 #ifdef IW_QUAL_DBM
1744         pAd->iw_stats.qual.updated |= IW_QUAL_DBM;      // Level + Noise are dBm
1745 #endif // IW_QUAL_DBM //
1746
1747         pAd->iw_stats.discard.nwid = 0;     // Rx : Wrong nwid/essid
1748         pAd->iw_stats.miss.beacon = 0;      // Missed beacons/superframe
1749
1750         DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1751         return &pAd->iw_stats;
1752 } /* End of rt28xx_get_wireless_stats */
1753 #endif // WIRELESS_EXT //
1754
1755
1756
1757 void tbtt_tasklet(unsigned long data)
1758 {
1759 #define MAX_TX_IN_TBTT          (16)
1760
1761 }
1762
1763 INT rt28xx_ioctl(
1764         IN      struct net_device       *net_dev,
1765         IN      OUT     struct ifreq    *rq,
1766         IN      INT                                     cmd)
1767 {
1768         VIRTUAL_ADAPTER *pVirtualAd = NULL;
1769         RTMP_ADAPTER    *pAd = NULL;
1770         INT                             ret = 0;
1771
1772         if (net_dev->priv_flags == INT_MAIN)
1773         {
1774                 pAd = net_dev->ml_priv;
1775         }
1776         else
1777         {
1778                 pVirtualAd = net_dev->ml_priv;
1779                 pAd = pVirtualAd->RtmpDev->ml_priv;
1780         }
1781
1782         if (pAd == NULL)
1783         {
1784                 /* if 1st open fail, pAd will be free;
1785                    So the net_dev->ml_priv will be NULL in 2rd open */
1786                 return -ENETDOWN;
1787         }
1788
1789
1790 #ifdef CONFIG_STA_SUPPORT
1791         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1792         {
1793                 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1794         }
1795 #endif // CONFIG_STA_SUPPORT //
1796
1797         return ret;
1798 }
1799
1800 /*
1801     ========================================================================
1802
1803     Routine Description:
1804         return ethernet statistics counter
1805
1806     Arguments:
1807         net_dev                     Pointer to net_device
1808
1809     Return Value:
1810         net_device_stats*
1811
1812     Note:
1813
1814     ========================================================================
1815 */
1816 struct net_device_stats *RT28xx_get_ether_stats(
1817     IN  struct net_device *net_dev)
1818 {
1819     RTMP_ADAPTER *pAd = NULL;
1820
1821         if (net_dev)
1822                 pAd = net_dev->ml_priv;
1823
1824         if (pAd)
1825         {
1826
1827                 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1828                 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1829
1830                 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1831                 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1832
1833                 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1834                 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1835
1836                 pAd->stats.rx_dropped = 0;
1837                 pAd->stats.tx_dropped = 0;
1838
1839             pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart;   // multicast packets received
1840             pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions;  // Collision packets
1841
1842             pAd->stats.rx_length_errors = 0;
1843             pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer;                   // receiver ring buff overflow
1844             pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount;     // recved pkt with crc error
1845             pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors;          // recv'd frame alignment error
1846             pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer;                   // recv'r fifo overrun
1847             pAd->stats.rx_missed_errors = 0;                                            // receiver missed packet
1848
1849             // detailed tx_errors
1850             pAd->stats.tx_aborted_errors = 0;
1851             pAd->stats.tx_carrier_errors = 0;
1852             pAd->stats.tx_fifo_errors = 0;
1853             pAd->stats.tx_heartbeat_errors = 0;
1854             pAd->stats.tx_window_errors = 0;
1855
1856             // for cslip etc
1857             pAd->stats.rx_compressed = 0;
1858             pAd->stats.tx_compressed = 0;
1859
1860                 return &pAd->stats;
1861         }
1862         else
1863         return NULL;
1864 }
1865