⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_usb.c

📁 VIA VT6656 USB linux source code.
💻 C
📖 第 1 页 / 共 5 页
字号:
    pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;    pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;    pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);        return;} //// Initialiation of MAC & BBP registers//static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType){    BYTE            abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};    BYTE            abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};    BYTE            abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};    BYTE            byAntenna;    UINT            ii;    CMD_CARD_INIT   sInitCmd;    NTSTATUS        ntStatus = STATUS_SUCCESS;    RSP_CARD_INIT   sInitRsp;    PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);    BYTE            byTmp;    BYTE            byCalibTXIQ = 0;    BYTE            byCalibTXDC = 0;    BYTE            byCalibRXIQ = 0;        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);	spin_lock_irq(&pDevice->lock);    if (InitType == DEVICE_INIT_COLD) {        memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);        memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);        memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);                        if ( !FIRMWAREbCheckVersion(pDevice) ) {            if (FIRMWAREbDownload(pDevice) == TRUE) {                if (FIRMWAREbBrach2Sram(pDevice) == FALSE) {                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");                  	spin_unlock_irq(&pDevice->lock);                    return FALSE;                }            } else {                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");                spin_unlock_irq(&pDevice->lock);                return FALSE;            }        }        if ( !BBbVT3184Init(pDevice) ) {            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");               spin_unlock_irq(&pDevice->lock);            return FALSE;        }    }    sInitCmd.byInitClass = (BYTE)InitType;    sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;    for(ii=0;ii<6;ii++)        sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];    sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;    sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;    //issue Card_init command to device    ntStatus = CONTROLnsRequestOut(pDevice,                                    MESSAGE_TYPE_CARDINIT,                                    0,                                    0,                                    sizeof(CMD_CARD_INIT),                                    (PBYTE) &(sInitCmd));        if ( ntStatus != STATUS_SUCCESS ) {        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");            spin_unlock_irq(&pDevice->lock);        return FALSE;    }        if (InitType == DEVICE_INIT_COLD) {                ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (PBYTE) &(sInitRsp));                if (ntStatus != STATUS_SUCCESS) {            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");            spin_unlock_irq(&pDevice->lock);            return FALSE;        }        //Local ID for AES functions        ntStatus = CONTROLnsRequestIn(pDevice,                                     MESSAGE_TYPE_READ,                                    MAC_REG_LOCALID,                                    MESSAGE_REQUEST_MACREG,                                    1,                                    &pDevice->byLocalID);                if ( ntStatus != STATUS_SUCCESS ) {            spin_unlock_irq(&pDevice->lock);            return FALSE;        }                // Do MACbSoftwareReset in MACvInitialize        // force CCK        pDevice->bCCK = TRUE;        pDevice->bProtectMode = FALSE;          //Only used in 11g type, sync with ERP IE        pDevice->bNonERPPresent = FALSE;        pDevice->bBarkerPreambleMd = FALSE;        if ( pDevice->bFixRate ) {            pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;        } else {            if ( pDevice->byBBType == BB_TYPE_11B )                 pDevice->wCurrentRate = RATE_11M;            else                pDevice->wCurrentRate = RATE_54M;        }                CHvInitChannelTable(pDevice);                pDevice->byTopOFDMBasicRate = RATE_24M;        pDevice->byTopCCKBasicRate = RATE_1M;        pDevice->byRevId = 0;                   //Target to IF pin while programming to RF chip.        pDevice->byCurPwr = 0xFF;            pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];        pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];        // Load power Table        for (ii=0;ii<14;ii++) {            pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];            if (pDevice->abyCCKPwrTbl[ii] == 0)                pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;            pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];            if (pDevice->abyOFDMPwrTbl[ii] == 0)                pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;        }                //{{ RobertYu: 20041124        pDevice->byOFDMPwrA = 0x34; // same as RFbMA2829SelectChannel        // Load OFDM A Power Table        for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL            pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];            if (pDevice->abyOFDMAPwrTbl[ii] == 0)                pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;        }        //}} RobertYu        byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];        if (byAntenna & EEP_ANTINV)             pDevice->bTxRxAntInv = TRUE;        else            pDevice->bTxRxAntInv = FALSE;        byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);                if (byAntenna == 0) // if not set default is All            byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);                if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {            pDevice->byAntennaCount = 2;            pDevice->byTxAntennaMode = ANT_B;            pDevice->dwTxAntennaSel = 1;            pDevice->dwRxAntennaSel = 1;            if (pDevice->bTxRxAntInv == TRUE)                 pDevice->byRxAntennaMode = ANT_A;            else                 pDevice->byRxAntennaMode = ANT_B;                            if (pDevice->bDiversityRegCtlON)                pDevice->bDiversityEnable = TRUE;            else                pDevice->bDiversityEnable = FALSE;        } else  {            pDevice->bDiversityEnable = FALSE;            pDevice->byAntennaCount = 1;            pDevice->dwTxAntennaSel = 0;            pDevice->dwRxAntennaSel = 0;            if (byAntenna & EEP_ANTENNA_AUX) {                pDevice->byTxAntennaMode = ANT_A;                if (pDevice->bTxRxAntInv == TRUE)                     pDevice->byRxAntennaMode = ANT_B;                else                     pDevice->byRxAntennaMode = ANT_A;            } else {                pDevice->byTxAntennaMode = ANT_B;                if (pDevice->bTxRxAntInv == TRUE)                     pDevice->byRxAntennaMode = ANT_A;                else                     pDevice->byRxAntennaMode = ANT_B;            }        }        pDevice->ulDiversityNValue = 100*255;        pDevice->ulDiversityMValue = 100*16;        pDevice->byTMax = 1;        pDevice->byTMax2 = 4;        pDevice->ulSQ3TH = 0;        pDevice->byTMax3 = 64;        // -----------------------------------------------------------------                //Get Auto Fall Back Type        pDevice->byAutoFBCtrl = AUTO_FB_0;                // Set SCAN Time        pDevice->uScanTime = WLAN_SCAN_MINITIME;                // default Auto Mode        //pDevice->NetworkType = Ndis802_11Automode;        pDevice->eConfigPHYMode = PHY_TYPE_AUTO;        pDevice->byBBType = BB_TYPE_11G;                // initialize BBP registers        pDevice->ulTxPower = 25;        // Get Channel range        pDevice->byMinChannel = 1;        pDevice->byMaxChannel = CB_MAX_CHANNEL;                        // Get RFType        pDevice->byRFType = sInitRsp.byRFType;                if ((pDevice->byRFType & RF_EMU) != 0) {            // force change RevID for VT3253 emu            pDevice->byRevId = 0x80;        }                // Load EEPROM calibrated vt3266 parameters        if (pDevice->byRFType == RF_VT3226D0) {            if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&                 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {                byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];                byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];                byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];                if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {                    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x03); // CR255, Set BB to support TX/RX IQ and DC compensation Mode                    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFB, byCalibTXIQ); // CR251, TX I/Q Imbalance Calibration                    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFC, byCalibTXDC); // CR252, TX DC-Offset Calibration                    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFD, byCalibRXIQ); // CR253, RX I/Q Imbalance Calibration                } else {                // turn off BB Calibration compensation                    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x0); // CR255                }            }        }        pMgmt->uCurrChannel = pDevice->uChannel;        pMgmt->uIBSSChannel = pDevice->uChannel;        CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);                // get Permanent network address        MEMvCopy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6)        MEMvCopy(pDevice->abyCurrentNetAddr, pDevice->abyPermanentNetAddr, U_ETHER_ADDR_LEN);                // if exist SW network address, use SW network address.        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",            pDevice->abyCurrentNetAddr[0],            pDevice->abyCurrentNetAddr[1],            pDevice->abyCurrentNetAddr[2],            pDevice->abyCurrentNetAddr[3],            pDevice->abyCurrentNetAddr[4],            pDevice->abyCurrentNetAddr[5]);    }    // Set BB and packet type at the same time.    // Set Short Slot Time, xIFS, and RSPINF.    if (pDevice->byBBType == BB_TYPE_11A) {        CARDbAddBasicRate(pDevice, RATE_6M);        pDevice->bShortSlotTime = TRUE;    } else {        CARDbAddBasicRate(pDevice, RATE_1M);        pDevice->bShortSlotTime = FALSE;    }    BBvSetShortSlotTime(pDevice);    CARDvSetBSSMode(pDevice);        if (pDevice->bUpdateBBVGA) {        pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];        pDevice->byBBVGANew = pDevice->byBBVGACurrent;        BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);    }        pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];    pDevice->bHWRadioOff = FALSE;    if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {        ntStatus = CONTROLnsRequestIn(pDevice,                                     MESSAGE_TYPE_READ,                                    MAC_REG_GPIOCTL1,                                    MESSAGE_REQUEST_MACREG,                                    1,                                    &byTmp);                if ( ntStatus != STATUS_SUCCESS ) {            spin_unlock_irq(&pDevice->lock);            return FALSE;        }        if ( (byTmp & GPIO3_DATA) == 0 ) {            pDevice->bHWRadioOff = TRUE;            MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);        } else {            MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);            pDevice->bHWRadioOff = FALSE;        }            } //EEP_RADIOCTL_ENABLE        ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);    ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);    MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);            if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {        CARDbRadioPowerOff(pDevice);    } else {        CARDbRadioPowerOn(pDevice);    }    spin_unlock_irq(&pDevice->lock);    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");    return TRUE; }#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)static int vntwusb_found1(struct usb_interface *intf, const struct usb_device_id *id)#else static void *vntwusb_found1(struct usb_device *udev, UINT interface, const struct usb_device_id *id)#endif{#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)   BYTE            fake_mac[U_ETHER_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};//fake MAC address#endif	#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)	struct usb_device *udev = interface_to_usbdev(intf);    int         rc = 0;	#endif	    struct net_device *netdev = NULL;    PSDevice    pDevice = NULL;        printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);    printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");        	pDevice = kmalloc(sizeof(DEVICE_INFO), GFP_KERNEL);	if (pDevice == NULL) {	    printk(KERN_ERR DEVICE_NAME ": allocate usb device failed \n");	    goto err_nomem;	}     memset(pDevice, 0, sizeof(DEVICE_INFO));    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    netdev = alloc_etherdev(0);#else        netdev = init_etherdev(netdev, 0);#endif                if (netdev == NULL) {        printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");        kfree(pDevice);	    goto err_nomem;                    }    pDevice->dev = netdev;    pDevice->usb = udev;    // Chain it all together #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)        SET_MODULE_OWNER(netdev); #endif            // Set initial settings       device_set_options(pDevice);    spin_lock_init(&pDevice->lock);        pDevice->tx_80211 = device_dma0_tx_80211;    pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;    	netdev->priv               = pDevice;        netdev->open               = device_open;    netdev->hard_start_xmit    = device_xmit;    netdev->stop               = device_close;    netdev->get_stats          = device_get_stats;    netdev->set_multicast_list = device_set_multi;    netdev->do_ioctl           = device_ioctl;#ifdef WIRELESS_EXT//2007-0508-01<Add>by MikeLiu  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)	netdev->get_wireless_stats = iwctl_get_wireless_stats;  #endif  #if WIRELESS_EXT > 12	netdev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;//	netdev->wireless_handlers = NULL;	#endif /* WIRELESS_EXT > 12 */#endif /* WIRELESS_EXT */    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)	   //2008-0623-01<Remark>by MikeLiu  //2007-0821-01<Add>by MikeLiu  // #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)         usb_set_intfdata(intf, pDevice);	SET_NETDEV_DEV(netdev, &intf->dev);   //#endif       rc = register_netdev(netdev);    if (rc != 0) {        printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");		free_netdev(netdev);        kfree(pDevice);        return -ENODEV;		    }	//2008-0623-02<Remark>by MikeLiu        //2007-0821-01<Add>by MikeLiu       //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)  	//usb_set_intfdata(intf, pDevice);	//SET_NETDEV_DEV(netdev, &intf->dev);       //#endif   #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)    memcpy(pDevice->dev->dev_addr, fake_mac, U_ETHER_ADDR_LEN); //use fake mac address   #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -