rt_main_dev.c
来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 1,801 行 · 第 1/4 页
C
1,801 行
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * ************************************************************************* Module Name: rt_main_dev.c Abstract: Create and register network interface. Revision History: Who When What -------- ---------- ---------------------------------------------- Sample Mar/21/07 Merge RT2870 and RT2860 drivers.*/#include "rt_config.h"#define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min#ifdef MULTIPLE_CARD_SUPPORT// record whether the card in the card list is used in the card fileUINT8 MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];// record used card mac address in the card liststatic UINT8 MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];#endif // MULTIPLE_CARD_SUPPORT //#ifdef CONFIG_APSTA_MIXED_SUPPORTUINT32 CW_MAX_IN_BITS;#endif // CONFIG_APSTA_MIXED_SUPPORT ///*---------------------------------------------------------------------*//* Private Variables Used *//*---------------------------------------------------------------------*///static RALINK_TIMER_STRUCT PeriodicTimer;char *mac = ""; // default 00:00:00:00:00:00char *hostname = ""; // default CMPC#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)MODULE_PARM (mac, "s");#elsemodule_param (mac, charp, 0);#endifMODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");/*---------------------------------------------------------------------*//* Prototypes of Functions Used *//*---------------------------------------------------------------------*/#ifdef DOT11_N_SUPPORTextern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);#endif // DOT11_N_SUPPORT //extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);// public function prototypeINT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p, IN UINT argc, OUT PRTMP_ADAPTER *ppAd);// private function prototypestatic int rt28xx_init(IN struct net_device *net_dev);INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1struct net_device *alloc_netdev( int sizeof_priv, const char *mask, void (*setup)(struct net_device *));#endif // LINUX_VERSION_CODE //static void CfgInitHook(PRTMP_ADAPTER pAd);//static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);#ifdef CONFIG_STA_SUPPORTextern const struct iw_handler_def rt28xx_iw_handler_def;#endif // CONFIG_STA_SUPPORT //#ifdef CONFIG_APSTA_MIXED_SUPPORTextern const struct iw_handler_def rt28xx_ap_iw_handler_def;#endif // CONFIG_APSTA_MIXED_SUPPORT //#if WIRELESS_EXT >= 12// This function will be called when query /procstruct iw_statistics *rt28xx_get_wireless_stats( IN struct net_device *net_dev);#endifstruct net_device_stats *RT28xx_get_ether_stats( IN struct net_device *net_dev);/*========================================================================Routine Description: Close raxx interface.Arguments: *net_dev the raxx interface pointerReturn Value: 0 Open OK otherwise Open FailNote: 1. if open fail, kernel will not call the close function. 2. Free memory for (1) Mlme Memory Handler: MlmeHalt() (2) TX & RX: RTMPFreeTxRxRingMemory() (3) BA Reordering: ba_reordering_resource_release()========================================================================*/int MainVirtualIF_close(IN struct net_device *net_dev){ RTMP_ADAPTER *pAd = net_dev->priv; // Sanity check for pAd if (pAd == NULL) return 0; // close ok netif_carrier_off(pAd->net_dev); netif_stop_queue(pAd->net_dev); VIRTUAL_IF_DOWN(pAd); RT_MOD_DEC_USE_COUNT(); return 0; // close ok}/*========================================================================Routine Description: Open raxx interface.Arguments: *net_dev the raxx interface pointerReturn Value: 0 Open OK otherwise Open FailNote: 1. if open fail, kernel will not call the close function. 2. Free memory for (1) Mlme Memory Handler: MlmeHalt() (2) TX & RX: RTMPFreeTxRxRingMemory() (3) BA Reordering: ba_reordering_resource_release()========================================================================*/int MainVirtualIF_open(IN struct net_device *net_dev){ RTMP_ADAPTER *pAd = net_dev->priv; // Sanity check for pAd if (pAd == NULL) return 0; // close ok if (VIRTUAL_IF_UP(pAd) != 0) return -1; // increase MODULE use count RT_MOD_INC_USE_COUNT(); netif_start_queue(net_dev); netif_carrier_on(net_dev); netif_wake_queue(net_dev); return 0;}/*========================================================================Routine Description: Close raxx interface.Arguments: *net_dev the raxx interface pointerReturn Value: 0 Open OK otherwise Open FailNote: 1. if open fail, kernel will not call the close function. 2. Free memory for (1) Mlme Memory Handler: MlmeHalt() (2) TX & RX: RTMPFreeTxRxRingMemory() (3) BA Reordering: ba_reordering_resource_release()========================================================================*/int rt28xx_close(IN PNET_DEV dev){ struct net_device * net_dev = (struct net_device *)dev; RTMP_ADAPTER *pAd = net_dev->priv; BOOLEAN Cancelled = FALSE; UINT32 i = 0;#ifdef RT2870 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup); DECLARE_WAITQUEUE(wait, current); //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);#endif // RT2870 // DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n")); // Sanity check for pAd if (pAd == NULL) return 0; // close ok#ifdef WDS_SUPPORT WdsDown(pAd);#endif // WDS_SUPPORT //#ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // If dirver doesn't wake up firmware here, // NICLoadFirmware will hang forever when interface is up again. if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { AsicForceWakeup(pAd, TRUE); }#ifdef QOS_DLS_SUPPORT // send DLS-TEAR_DOWN message, if (pAd->CommonCfg.bDLSCapable) { UCHAR i; // tear down local dls table entry for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)) { RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr); pAd->StaCfg.DLSEntry[i].Status = DLS_NONE; pAd->StaCfg.DLSEntry[i].Valid = FALSE; } } // tear down peer dls table entry for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)) { RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr); pAd->StaCfg.DLSEntry[i].Status = DLS_NONE; pAd->StaCfg.DLSEntry[i].Valid = FALSE; } } RT28XX_MLME_HANDLER(pAd); }#endif // QOS_DLS_SUPPORT // if (INFRA_ON(pAd) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { MLME_DISASSOC_REQ_STRUCT DisReq; MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid); DisReq.Reason = REASON_DEAUTH_STA_LEAVING; MsgElem->Machine = ASSOC_STATE_MACHINE; MsgElem->MsgType = MT2_MLME_DISASSOC_REQ; MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT); NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT)); // Prevent to connect AP again in STAMlmePeriodicExec pAd->MlmeAux.AutoReconnectSsidLen= 32; NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC; MlmeDisassocReqAction(pAd, MsgElem); kfree(MsgElem); RTMPusecDelay(1000); }#ifdef RT2870 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);#endif // RT2870 //#ifdef CCX_SUPPORT RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);#endif RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled); RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);#ifdef WPA_SUPPLICANT_SUPPORT#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT { union iwreq_data wrqu; // send wireless event to wpa_supplicant for infroming interface down. memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.flags = RT_INTERFACE_DOWN; wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL); }#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //#endif // WPA_SUPPLICANT_SUPPORT // MlmeRadioOff(pAd); }#endif // CONFIG_STA_SUPPORT // RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); for (i = 0 ; i < NUM_OF_TX_RING; i++) { while (pAd->DeQueueRunning[i] == TRUE) { printk("Waiting for TxQueue[%d] done..........\n", i); RTMPusecDelay(1000); } } #ifdef RT2870 // ensure there are no more active urbs. add_wait_queue (&unlink_wakeup, &wait); pAd->wait = &unlink_wakeup; // maybe wait for deletions to finish. i = 0; //while((i < 25) && atomic_read(&pAd->PendingRx) > 0) while(i < 25) { unsigned long IrqFlags; RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); if (pAd->PendingRx == 0) { RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); break; } RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9) msleep(UNLINK_TIMEOUT_MS); //Time in millisecond#else RTMPusecDelay(UNLINK_TIMEOUT_MS*1000); //Time in microsecond#endif i++; } pAd->wait = NULL; remove_wait_queue (&unlink_wakeup, &wait); #endif // RT2870 // //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/#ifdef RT2870 // We need clear timerQ related structure before exits of the timer thread. RT2870_TimerQ_Exit(pAd); // Close kernel threads or tasklets RT28xxThreadTerminate(pAd);#endif // RT2870 // // Stop Mlme state machine MlmeHalt(pAd); // Close kernel threads or tasklets kill_thread_task(pAd);#ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { MacTableReset(pAd); }#endif // CONFIG_STA_SUPPORT // MeasureReqTabExit(pAd); TpcReqTabExit(pAd); // Free Ring or USB buffers RTMPFreeTxRxRingMemory(pAd); RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);#ifdef DOT11_N_SUPPORT // Free BA reorder resource ba_reordering_resource_release(pAd);#endif // DOT11_N_SUPPORT // #ifdef RT2870#ifdef INF_AMAZON_SE if (pAd->UsbVendorReqBuf) os_free_mem(pAd, pAd->UsbVendorReqBuf);#endif // INF_AMAZON_SE //#endif // RT2870 // RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP); return 0; // close ok} /* End of rt28xx_close */static int rt28xx_init(IN struct net_device *net_dev){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->priv; UINT index; UCHAR TmpPhy;// ULONG Value=0; NDIS_STATUS Status;// OID_SET_HT_PHYMODE SetHT;// WPDMA_GLO_CFG_STRUC GloCfg; UINT32 MacCsr0 = 0; UINT32 MacValue = 0; #ifdef RT2870#ifdef INF_AMAZON_SE init_MUTEX(&(pAd->UsbVendorReq_semaphore)); os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1); if (pAd->UsbVendorReqBuf == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n")); goto err0; }#endif // INF_AMAZON_SE //#endif // RT2870 //
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?