📄 main_usb.c
字号:
//2007-1107-03<Add>by MikeLiu #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) usb_device_reset(pDevice); #endif return 0; #else return pDevice; #endif err_nomem:#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) return -ENOMEM;#else return NULL;#endif }static VOID device_free_tx_bufs(PSDevice pDevice) { PUSB_SEND_CONTEXT pTxContext; int ii; for (ii = 0; ii < pDevice->cbTD; ii++) { pTxContext = pDevice->apTD[ii]; //de-allocate URBs if (pTxContext->pUrb) { vntwusb_unlink_urb(pTxContext->pUrb); usb_free_urb(pTxContext->pUrb); } if (pTxContext) kfree(pTxContext); } return;}static VOID device_free_rx_bufs(PSDevice pDevice) { PRCB pRCB; int ii; for (ii = 0; ii < pDevice->cbRD; ii++) { pRCB = pDevice->apRCB[ii]; //de-allocate URBs if (pRCB->pUrb) { vntwusb_unlink_urb(pRCB->pUrb); usb_free_urb(pRCB->pUrb); } //de-allocate skb if (pRCB->skb) dev_kfree_skb(pRCB->skb); } if (pDevice->pRCBMem) kfree(pDevice->pRCBMem); return;}//2007-1107-02<Add>by MikeLiu#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)static void usb_device_reset(PSDevice pDevice){ int status; status = usb_reset_device(pDevice->usb); if (status) printk("usb_device_reset fail status=%d\n",status); return ;}#endifstatic VOID device_free_int_bufs(PSDevice pDevice) { if (pDevice->intBuf.pDataBuf != NULL) kfree(pDevice->intBuf.pDataBuf); return;}static BOOL device_alloc_bufs(PSDevice pDevice) { PUSB_SEND_CONTEXT pTxContext; PRCB pRCB; int ii; for (ii = 0; ii < pDevice->cbTD; ii++) { pTxContext = kmalloc(sizeof(USB_SEND_CONTEXT), GFP_KERNEL); if (pTxContext == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name); goto free_tx; } pDevice->apTD[ii] = pTxContext; pTxContext->pDevice = (PVOID) pDevice; //allocate URBs pTxContext->pUrb = vntwusb_alloc_urb(0);; if (pTxContext->pUrb == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n"); goto free_tx; } pTxContext->bBoolInUse = FALSE; } // allocate rcb mem pDevice->pRCBMem = kmalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL); if (pDevice->pRCBMem == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name); goto free_tx; } pDevice->FirstRecvFreeList = NULL; pDevice->LastRecvFreeList = NULL; pDevice->FirstRecvMngList = NULL; pDevice->LastRecvMngList = NULL; pDevice->NumRecvFreeList = 0; memset(pDevice->pRCBMem, 0, (sizeof(RCB) * pDevice->cbRD)); pRCB = (PRCB) pDevice->pRCBMem; for (ii = 0; ii < pDevice->cbRD; ii++) { pDevice->apRCB[ii] = pRCB; pRCB->pDevice = (PVOID) pDevice; //allocate URBs pRCB->pUrb = vntwusb_alloc_urb(0); if (pRCB->pUrb == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n"); goto free_rx_tx; } pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pRCB->skb == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n"); goto free_rx_tx; } pRCB->skb->dev = pDevice->dev; pRCB->bBoolInUse = FALSE; EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB); pDevice->NumRecvFreeList++; pRCB++; } pDevice->pControlURB = vntwusb_alloc_urb(0); if (pDevice->pControlURB == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n"); goto free_rx_tx; } pDevice->pInterruptURB = vntwusb_alloc_urb(0); if (pDevice->pInterruptURB == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n"); vntwusb_unlink_urb(pDevice->pControlURB); usb_free_urb(pDevice->pControlURB); goto free_rx_tx; } pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); if (pDevice->intBuf.pDataBuf == NULL) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n"); vntwusb_unlink_urb(pDevice->pControlURB); vntwusb_unlink_urb(pDevice->pInterruptURB); usb_free_urb(pDevice->pControlURB); usb_free_urb(pDevice->pInterruptURB); goto free_rx_tx; } return TRUE; free_rx_tx: device_free_rx_bufs(pDevice); free_tx: device_free_tx_bufs(pDevice); return FALSE;}static BOOL device_init_defrag_cb(PSDevice pDevice) { int i; PSDeFragControlBlock pDeF; /* Init the fragment ctl entries */ for (i = 0; i < CB_MAX_RX_FRAG; i++) { pDeF = &(pDevice->sRxDFCB[i]); if (!device_alloc_frag_buf(pDevice, pDeF)) { DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n", pDevice->dev->name); goto free_frag; }; } pDevice->cbDFCB = CB_MAX_RX_FRAG; pDevice->cbFreeDFCB = pDevice->cbDFCB; return TRUE; free_frag: device_free_frag_bufs(pDevice); return FALSE;} static void device_free_frag_bufs(PSDevice pDevice) { PSDeFragControlBlock pDeF; int i; for (i = 0; i < CB_MAX_RX_FRAG; i++) { pDeF = &(pDevice->sRxDFCB[i]); if (pDeF->skb) dev_kfree_skb(pDeF->skb); }}BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) { pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pDeF->skb == NULL) return FALSE; ASSERT(pDeF->skb); pDeF->skb->dev = pDevice->dev; return TRUE; }/*-----------------------------------------------------------------*/static int device_open(struct net_device *dev) { PSDevice pDevice=(PSDevice) dev->priv;#ifdef WPA_SM_Transtatus extern SWPAResult wpa_Result; memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname)); wpa_Result.proto = 0; wpa_Result.key_mgmt = 0; wpa_Result.eap_type = 0; wpa_Result.authenticated = FALSE;#endif DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n"); pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; if (device_alloc_bufs(pDevice) == FALSE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n"); return -ENOMEM; } if (device_init_defrag_cb(pDevice)== FALSE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragement cb fail \n"); goto free_rx_tx; } MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED); MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES); MP_SET_FLAG(pDevice, fMP_POST_READS); MP_SET_FLAG(pDevice, fMP_POST_WRITES); if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n"); goto free_all; } device_set_multi(pDevice->dev); // Init for Key Management KeyvInitTable(pDevice,&pDevice->sKey); memcpy(pDevice->sMgmtObj.abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN); memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN); pDevice->bStopTx0Pkt = FALSE; pDevice->bStopDataPkt = FALSE; pDevice->bRoaming = FALSE; //DavidWang pDevice->bIsRoaming = FALSE;//DavidWang pDevice->bEnableRoaming = FALSE; if (pDevice->bDiversityRegCtlON) { device_init_diversity_timer(pDevice); } vMgrObjectInit(pDevice); tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice); tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice); tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice); add_timer(&(pDevice->sMgmtObj.sTimerSecondCallback));#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) pDevice->int_interval = 100; //Max 100 microframes.#else pDevice->int_interval = 0x10; //16 microframes interval(~2ms) for usb 2.0#endif pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; pDevice->bIsRxWorkItemQueued = TRUE; pDevice->fKillEventPollingThread = FALSE; pDevice->bEventAvailable = FALSE;#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT pDevice->bwextstep0 = FALSE; pDevice->bwextstep1 = FALSE; pDevice->bwextstep2 = FALSE; pDevice->bwextstep3 = FALSE; pDevice->bWPASuppWextEnabled = FALSE;#endif RXvWorkItem(pDevice); INTvWorkItem(pDevice); // Patch: if WEP key already set by iwconfig but device not yet open if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) { spin_lock_irq(&pDevice->lock); KeybSetDefaultKey( pDevice, &(pDevice->sKey), pDevice->byKeyIndex | (1 << 31), pDevice->uKeyLength, NULL, pDevice->abyKey, KEY_CTL_WEP ); spin_unlock_irq(&pDevice->lock); pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; } if (pDevice->sMgmtObj.eConfigMode == WMAC_CONFIG_AP) { bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL); } else { bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL); bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL); } netif_stop_queue(pDevice->dev); pDevice->flags |= DEVICE_FLAGS_OPENED; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n"); return 0; free_all: device_free_frag_bufs(pDevice);free_rx_tx: device_free_rx_bufs(pDevice); device_free_tx_bufs(pDevice); device_free_int_bufs(pDevice); vntwusb_unlink_urb(pDevice->pControlURB); vntwusb_unlink_urb(pDevice->pInterruptURB); usb_free_urb(pDevice->pControlURB); usb_free_urb(pDevice->pInterruptURB); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n"); return -ENOMEM; }static int device_close(struct net_device *dev) { PSDevice pDevice=(PSDevice) dev->priv; PSMgmtObject pMgmt = &(pDevice->sMgmtObj); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) int uu; #endif DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1 \n"); if (pDevice == NULL) return -ENODEV;//2007-1121-02<Add>by EinsnLiu if (pDevice->bLinkPass) { bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL); mdelay(30); }//End Add#ifdef SndEvt_ToAPI if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) evt_notify(pDevice,0,WMAC_STATE_IDLE);#endif //2007-0821-01<Add>by MikeLiu #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); pMgmt->bShareKeyAlgorithm = FALSE; pDevice->bEncryptionEnable = FALSE; pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; spin_lock_irq(&pDevice->lock); for(uu=0;uu<MAX_KEY_TABLE;uu++) MACvDisableKeyEntry(pDevice,uu); spin_unlock_irq(&pDevice->lock); #endif if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) { MACbShutdown(pDevice); } netif_stop_queue(pDevice->dev); MP_SET_FLAG(pDevice, fMP_DISCONNECTED); MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES); MP_CLEAR_FLAG(pDevice, fMP_POST_READS); pDevice->fKillEventPollingThread = TRUE; del_timer(&pDevice->sTimerCommand); del_timer(&pMgmt->sTimerSecondCallback); //2007-0115-02<Add>by MikeLiu#ifdef TxInSleep del_timer(&pDevice->sTimerTxData);#endif if (pDevice->bDiversityRegCtlON) { del_timer(&pDevice->TimerSQ3Tmax1); del_timer(&pDevice->TimerSQ3Tmax2); del_timer(&pDevice->TimerSQ3Tmax3); } tasklet_kill(&pDevice->RxMngWorkItem); tasklet_kill(&pDevice->ReadWorkItem); tasklet_kill(&pDevice->EventWorkItem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -