2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
31 Create and register network interface.
35 -------- ---------- ----------------------------------------------
36 Sample Mar/21/07 Merge RT2870 and RT2860 drivers.
39 #include "rt_config.h"
41 #define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min
43 /*---------------------------------------------------------------------*/
44 /* Private Variables Used */
45 /*---------------------------------------------------------------------*/
46 //static RALINK_TIMER_STRUCT PeriodicTimer;
48 char *mac = ""; // default 00:00:00:00:00:00
49 char *hostname = ""; // default CMPC
50 module_param (mac, charp, 0);
51 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
54 /*---------------------------------------------------------------------*/
55 /* Prototypes of Functions Used */
56 /*---------------------------------------------------------------------*/
57 #ifdef DOT11_N_SUPPORT
58 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
59 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
60 #endif // DOT11_N_SUPPORT //
61 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
63 extern void init_thread_task(PRTMP_ADAPTER pAd);
65 // public function prototype
66 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
67 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
69 // private function prototype
70 static int rt28xx_init(IN struct net_device *net_dev);
71 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
73 static void CfgInitHook(PRTMP_ADAPTER pAd);
75 extern const struct iw_handler_def rt28xx_iw_handler_def;
77 #if WIRELESS_EXT >= 12
78 // This function will be called when query /proc
79 struct iw_statistics *rt28xx_get_wireless_stats(
80 IN struct net_device *net_dev);
83 struct net_device_stats *RT28xx_get_ether_stats(
84 IN struct net_device *net_dev);
87 ========================================================================
92 *net_dev the raxx interface pointer
99 1. if open fail, kernel will not call the close function.
101 (1) Mlme Memory Handler: MlmeHalt()
102 (2) TX & RX: RTMPFreeTxRxRingMemory()
103 (3) BA Reordering: ba_reordering_resource_release()
104 ========================================================================
106 int MainVirtualIF_close(IN struct net_device *net_dev)
108 RTMP_ADAPTER *pAd = net_dev->ml_priv;
110 // Sanity check for pAd
112 return 0; // close ok
114 netif_carrier_off(pAd->net_dev);
115 netif_stop_queue(pAd->net_dev);
118 VIRTUAL_IF_DOWN(pAd);
120 RT_MOD_DEC_USE_COUNT();
122 return 0; // close ok
126 ========================================================================
131 *net_dev the raxx interface pointer
138 1. if open fail, kernel will not call the close function.
140 (1) Mlme Memory Handler: MlmeHalt()
141 (2) TX & RX: RTMPFreeTxRxRingMemory()
142 (3) BA Reordering: ba_reordering_resource_release()
143 ========================================================================
145 int MainVirtualIF_open(IN struct net_device *net_dev)
147 RTMP_ADAPTER *pAd = net_dev->ml_priv;
149 // Sanity check for pAd
151 return 0; // close ok
153 if (VIRTUAL_IF_UP(pAd) != 0)
156 // increase MODULE use count
157 RT_MOD_INC_USE_COUNT();
159 netif_start_queue(net_dev);
160 netif_carrier_on(net_dev);
161 netif_wake_queue(net_dev);
167 ========================================================================
169 Close raxx interface.
172 *net_dev the raxx interface pointer
179 1. if open fail, kernel will not call the close function.
181 (1) Mlme Memory Handler: MlmeHalt()
182 (2) TX & RX: RTMPFreeTxRxRingMemory()
183 (3) BA Reordering: ba_reordering_resource_release()
184 ========================================================================
186 int rt28xx_close(IN PNET_DEV dev)
188 struct net_device * net_dev = (struct net_device *)dev;
189 RTMP_ADAPTER *pAd = net_dev->ml_priv;
190 BOOLEAN Cancelled = FALSE;
194 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
196 // Sanity check for pAd
198 return 0; // close ok
200 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
202 // If dirver doesn't wake up firmware here,
203 // NICLoadFirmware will hang forever when interface is up again.
204 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
205 RTMP_SET_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) ||
206 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
208 AsicForceWakeup(pAd, RTMP_HALT);
212 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
214 MLME_DISASSOC_REQ_STRUCT DisReq;
215 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
217 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
218 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
220 MsgElem->Machine = ASSOC_STATE_MACHINE;
221 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
222 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
223 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
225 // Prevent to connect AP again in STAMlmePeriodicExec
226 pAd->MlmeAux.AutoReconnectSsidLen= 32;
227 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
229 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
230 MlmeDisassocReqAction(pAd, MsgElem);
238 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
241 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
242 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
244 #ifdef WPA_SUPPLICANT_SUPPORT
245 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
247 union iwreq_data wrqu;
248 // send wireless event to wpa_supplicant for infroming interface down.
249 memset(&wrqu, 0, sizeof(wrqu));
250 wrqu.data.flags = RT_INTERFACE_DOWN;
251 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
253 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
254 #endif // WPA_SUPPLICANT_SUPPORT //
257 pAd->bPCIclkOff = FALSE;
260 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
262 for (i = 0 ; i < NUM_OF_TX_RING; i++)
264 while (pAd->DeQueueRunning[i] == TRUE)
266 printk("Waiting for TxQueue[%d] done..........\n", i);
271 // Stop Mlme state machine
274 // Close kernel threads or tasklets
275 kill_thread_task(pAd);
277 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
283 MeasureReqTabExit(pAd);
287 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
289 NICDisableInterrupt(pAd);
292 // Disable Rx, register value supposed will remain after reset
296 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
298 // Deregister interrupt function
299 RT28XX_IRQ_RELEASE(net_dev)
300 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
304 // Free Ring or USB buffers
305 RTMPFreeTxRxRingMemory(pAd);
307 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
309 #ifdef DOT11_N_SUPPORT
310 // Free BA reorder resource
311 ba_reordering_resource_release(pAd);
312 #endif // DOT11_N_SUPPORT //
315 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
317 return 0; // close ok
318 } /* End of rt28xx_close */
320 static int rt28xx_init(IN struct net_device *net_dev)
322 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->ml_priv;
329 #ifdef DOT11_N_SUPPORT
330 // Allocate BA Reordering memory
331 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
332 #endif // DOT11_N_SUPPORT //
334 // Make sure MAC gets ready.
338 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
339 pAd->MACVersion = MacCsr0;
341 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
345 } while (index++ < 100);
347 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
350 RT28XXDMADisable(pAd);
353 // Load 8051 firmware
354 Status = NICLoadFirmware(pAd);
355 if (Status != NDIS_STATUS_SUCCESS)
357 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
361 NICLoadRateSwitchingParams(pAd);
363 // Disable interrupts here which is as soon as possible
364 // This statement should never be true. We might consider to remove it later
365 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
367 NICDisableInterrupt(pAd);
370 Status = RTMPAllocTxRxRingMemory(pAd);
371 if (Status != NDIS_STATUS_SUCCESS)
373 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
377 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
382 Status = MlmeInit(pAd);
383 if (Status != NDIS_STATUS_SUCCESS)
385 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
389 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
394 RT28XX_TASK_THREAD_INIT(pAd, Status);
395 if (Status != NDIS_STATUS_SUCCESS)
400 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
401 NdisAllocateSpinLock(&pAd->MacTabLock);
403 MeasureReqTabInit(pAd);
407 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
409 Status = NICInitializeAdapter(pAd, TRUE);
410 if (Status != NDIS_STATUS_SUCCESS)
412 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
413 if (Status != NDIS_STATUS_SUCCESS)
417 // Read parameters from Config File
418 Status = RTMPReadParametersHook(pAd);
420 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
421 if (Status != NDIS_STATUS_SUCCESS)
423 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
429 //Init Ba Capability parameters.
430 #ifdef DOT11_N_SUPPORT
431 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
432 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
433 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
434 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
436 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
437 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
438 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
439 #endif // DOT11_N_SUPPORT //
441 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
443 // We should read EEPROM for all cases. rt2860b
444 NICReadEEPROMParameters(pAd, mac);
446 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
448 NICInitAsicFromEEPROM(pAd); //rt2860b
450 // Set PHY to appropriate mode
451 TmpPhy = pAd->CommonCfg.PhyMode;
452 pAd->CommonCfg.PhyMode = 0xff;
453 RTMPSetPhyMode(pAd, TmpPhy);
454 #ifdef DOT11_N_SUPPORT
456 #endif // DOT11_N_SUPPORT //
458 // No valid channels.
459 if (pAd->ChannelListNum == 0)
461 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
465 #ifdef DOT11_N_SUPPORT
466 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
467 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
468 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
469 #endif // DOT11_N_SUPPORT //
472 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
473 #endif // IKANOS_VX_1X0 //
476 // Initialize RF register to default value
478 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
479 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
481 // 8051 firmware require the signal during booting time.
482 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
484 if (pAd && (Status != NDIS_STATUS_SUCCESS))
487 // Undo everything if it failed
489 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
491 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
496 // Microsoft HCT require driver send a disconnect event after driver initialization.
497 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
498 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
499 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
505 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
514 RTMPFreeTxRxRingMemory(pAd);
517 #ifdef DOT11_N_SUPPORT
518 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
519 #endif // DOT11_N_SUPPORT //
520 RT28XX_IRQ_RELEASE(net_dev);
522 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
523 //net_dev->ml_priv = 0;
525 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
527 } /* End of rt28xx_init */
531 ========================================================================
536 *net_dev the raxx interface pointer
543 ========================================================================
545 int rt28xx_open(IN PNET_DEV dev)
547 struct net_device * net_dev = (struct net_device *)dev;
548 PRTMP_ADAPTER pAd = net_dev->ml_priv;
553 // Sanity check for pAd
556 /* if 1st open fail, pAd will be free;
557 So the net_dev->ml_priv will be NULL in 2rd open */
562 pObj = (POS_COOKIE)pAd->OS_Cookie;
564 // reset Adapter flags
565 RTMP_CLEAR_FLAGS(pAd);
567 // Request interrupt service routine for PCI device
568 // register the interrupt routine with the os
569 RT28XX_IRQ_REQUEST(net_dev);
572 // Init BssTab & ChannelInfo tabbles for auto channel select.
576 if (rt28xx_init(net_dev) == FALSE)
579 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
581 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
582 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
585 // Set up the Mac address
586 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
588 // Init IRQ parameters
589 RT28XX_IRQ_INIT(pAd);
591 // Various AP function init
593 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
595 #ifdef WPA_SUPPLICANT_SUPPORT
596 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
598 union iwreq_data wrqu;
599 // send wireless event to wpa_supplicant for infroming interface down.
600 memset(&wrqu, 0, sizeof(wrqu));
601 wrqu.data.flags = RT_INTERFACE_UP;
602 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
604 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
605 #endif // WPA_SUPPLICANT_SUPPORT //
610 RT28XX_IRQ_ENABLE(pAd);
614 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
618 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
619 printk("0x1300 = %08x\n", reg);
622 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
623 RTMPInitPCIeLinkCtrlValue(pAd);
629 } /* End of rt28xx_open */
631 static const struct net_device_ops rt2860_netdev_ops = {
632 .ndo_open = MainVirtualIF_open,
633 .ndo_stop = MainVirtualIF_close,
634 .ndo_do_ioctl = rt28xx_ioctl,
635 .ndo_get_stats = RT28xx_get_ether_stats,
636 .ndo_validate_addr = NULL,
637 .ndo_set_mac_address = eth_mac_addr,
638 .ndo_change_mtu = eth_change_mtu,
640 .ndo_start_xmit = IKANOS_DataFramesTx,
642 .ndo_start_xmit = rt28xx_send_packets,
646 /* Must not be called for mdev and apdev */
647 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
651 CHAR slot_name[IFNAMSIZ];
652 struct net_device *device;
657 #if WIRELESS_EXT >= 12
658 if (pAd->OpMode == OPMODE_STA)
660 dev->wireless_handlers = &rt28xx_iw_handler_def;
662 #endif //WIRELESS_EXT >= 12
664 #if WIRELESS_EXT < 21
665 dev->get_wireless_stats = rt28xx_get_wireless_stats;
667 dev->priv_flags = INT_MAIN;
668 dev->netdev_ops = &rt2860_netdev_ops;
669 // find available device name
670 for (i = 0; i < 8; i++)
672 sprintf(slot_name, "ra%d", i);
674 device = dev_get_by_name(dev_net(dev), slot_name);
684 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
685 Status = NDIS_STATUS_FAILURE;
689 sprintf(dev->name, "ra%d", i);
690 Status = NDIS_STATUS_SUCCESS;
698 ========================================================================
700 Probe RT28XX chipset.
703 _dev_p Point to the PCI or USB device
704 _dev_id_p Point to the PCI or USB device ID
711 ========================================================================
713 INT __devinit rt28xx_probe(
717 OUT PRTMP_ADAPTER *ppAd)
719 struct net_device *net_dev;
720 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
723 struct pci_dev *dev_p = (struct pci_dev *)_dev_p;
726 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
728 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
731 printk("alloc_netdev failed\n");
736 netif_stop_queue(net_dev);
737 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
738 /* for supporting Network Manager */
739 /* Set the sysfs physical device reference for the network logical device
740 * if set prior to registration will cause a symlink during initialization.
742 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
743 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
745 // Allocate RTMP_ADAPTER miniport adapter structure
746 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
747 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
749 status = RTMPAllocAdapterBlock(handle, &pAd);
750 if (status != NDIS_STATUS_SUCCESS)
751 goto err_out_free_netdev;
753 net_dev->ml_priv = (PVOID)pAd;
754 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
756 RT28XXNetDevInit(_dev_p, net_dev, pAd);
758 pAd->StaCfg.OriDevType = net_dev->type;
761 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
764 pAd->OpMode = OPMODE_STA;
767 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
770 // Register this device
771 status = register_netdev(net_dev);
776 RT28XX_DRVDATA_SET(_dev_p);
779 return 0; // probe ok
782 /* --------------------------- ERROR HANDLE --------------------------- */
784 RTMPFreeAdapter(pAd);
788 free_netdev(net_dev);
791 RT28XX_PUT_DEVICE(dev_p);
793 return -ENODEV; /* probe fail */
794 } /* End of rt28xx_probe */
798 ========================================================================
800 The entry point for Linux kernel sent packet to our driver.
803 sk_buff *skb the pointer refer to a sk_buffer.
809 This function is the entry point of Tx Path for Os delivery packet to
810 our driver. You only can put OS-depened & STA/AP common handle procedures
812 ========================================================================
814 int rt28xx_packet_xmit(struct sk_buff *skb)
816 struct net_device *net_dev = skb->dev;
817 PRTMP_ADAPTER pAd = net_dev->ml_priv;
819 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
821 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
823 // Drop send request since we are in monitor mode
826 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
831 // EapolStart size is 18
834 //printk("bad packet size: %d\n", pkt->len);
835 hex_dump("bad packet", skb->data, skb->len);
836 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
840 RTMP_SET_PACKET_5VT(pPacket, 0);
841 #ifdef CONFIG_5VT_ENHANCE
842 if (*(int*)(skb->cb) == BRIDGE_TAG) {
843 RTMP_SET_PACKET_5VT(pPacket, 1);
847 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
850 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
861 ========================================================================
863 Send a packet to WLAN.
866 skb_p points to our adapter
867 dev_p which WLAN network interface
870 0: transmit successfully
871 otherwise: transmit fail
874 ========================================================================
876 INT rt28xx_send_packets(
877 IN struct sk_buff *skb_p,
878 IN struct net_device *net_dev)
880 RTMP_ADAPTER *pAd = net_dev->ml_priv;
881 if (!(net_dev->flags & IFF_UP))
883 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
887 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
888 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
890 return rt28xx_packet_xmit(skb_p);
892 } /* End of MBSS_VirtualIF_PacketSend */
897 void CfgInitHook(PRTMP_ADAPTER pAd)
899 pAd->bBroadComHT = TRUE;
900 } /* End of CfgInitHook */
903 #if WIRELESS_EXT >= 12
904 // This function will be called when query /proc
905 struct iw_statistics *rt28xx_get_wireless_stats(
906 IN struct net_device *net_dev)
908 PRTMP_ADAPTER pAd = net_dev->ml_priv;
911 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
913 pAd->iw_stats.status = 0; // Status - device dependent for now
916 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
917 if(pAd->iw_stats.qual.qual > 100)
918 pAd->iw_stats.qual.qual = 100;
920 if (pAd->OpMode == OPMODE_STA)
921 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
923 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
925 pAd->iw_stats.qual.noise += 256 - 143;
926 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
928 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
929 #endif // IW_QUAL_DBM //
931 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
932 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
934 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
935 return &pAd->iw_stats;
936 } /* End of rt28xx_get_wireless_stats */
937 #endif // WIRELESS_EXT //
941 void tbtt_tasklet(unsigned long data)
943 #define MAX_TX_IN_TBTT (16)
948 IN struct net_device *net_dev,
949 IN OUT struct ifreq *rq,
952 VIRTUAL_ADAPTER *pVirtualAd = NULL;
953 RTMP_ADAPTER *pAd = NULL;
956 if (net_dev->priv_flags == INT_MAIN)
958 pAd = net_dev->ml_priv;
962 pVirtualAd = net_dev->ml_priv;
963 pAd = pVirtualAd->RtmpDev->ml_priv;
968 /* if 1st open fail, pAd will be free;
969 So the net_dev->ml_priv will be NULL in 2rd open */
973 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
975 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
982 ========================================================================
985 return ethernet statistics counter
988 net_dev Pointer to net_device
995 ========================================================================
997 struct net_device_stats *RT28xx_get_ether_stats(
998 IN struct net_device *net_dev)
1000 RTMP_ADAPTER *pAd = NULL;
1003 pAd = net_dev->ml_priv;
1008 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1009 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1011 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1012 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1014 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1015 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1017 pAd->stats.rx_dropped = 0;
1018 pAd->stats.tx_dropped = 0;
1020 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1021 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1023 pAd->stats.rx_length_errors = 0;
1024 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1025 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1026 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1027 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1028 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1030 // detailed tx_errors
1031 pAd->stats.tx_aborted_errors = 0;
1032 pAd->stats.tx_carrier_errors = 0;
1033 pAd->stats.tx_fifo_errors = 0;
1034 pAd->stats.tx_heartbeat_errors = 0;
1035 pAd->stats.tx_window_errors = 0;
1038 pAd->stats.rx_compressed = 0;
1039 pAd->stats.tx_compressed = 0;