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

📄 main_usb.c

📁 VIA VT6656 USB linux source code.
💻 C
📖 第 1 页 / 共 5 页
字号:
   pDevice->bRoaming = FALSE;  //DavidWang   pDevice->bIsRoaming = FALSE;//DavidWang   pDevice->bEnableRoaming = FALSE;       pDevice->bCmdRunning = FALSE;    pDevice->bLinkPass = FALSE;         memset(pMgmt->abyCurrBSSID, 0, 6);     pMgmt->eCurrState = WMAC_STATE_IDLE;    device_free_tx_bufs(pDevice);      device_free_rx_bufs(pDevice);      device_free_int_bufs(pDevice);    device_free_frag_bufs(pDevice);  	vntwusb_unlink_urb(pDevice->pControlURB);	vntwusb_unlink_urb(pDevice->pInterruptURB);    usb_free_urb(pDevice->pControlURB);   	        usb_free_urb(pDevice->pInterruptURB);   	    BSSvClearNodeDBTable(pDevice, 0);    pDevice->flags &=(~DEVICE_FLAGS_OPENED);    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");    return 0;}#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)static void vntwusb_disconnect(struct usb_interface *intf)#else static void vntwusb_disconnect(struct usb_device *udev, void *ptr)#endif{#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)	PSDevice  pDevice = usb_get_intfdata(intf);#else 	PSDevice  pDevice = (PSDevice)ptr;#endif	    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect1.. \n");       if (pDevice == NULL)        return;    #ifdef SndEvt_ToAPI   evt_notify(pDevice,1,WMAC_STATE_IDLE);    mdelay(100);     //wait application layer close safely???#endif#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)	usb_set_intfdata(intf, NULL);#endif	    pDevice->flags |= DEVICE_FLAGS_UNPLUG;    if (pDevice->dev != NULL) {        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unregister_netdev..\n");           unregister_netdev(pDevice->dev);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)        free_netdev(pDevice->dev);#else	    kfree(pDevice->dev);#endif    }	kfree(pDevice);    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect3.. \n");   	}static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {    PSDevice        pDevice=dev->priv;    PBYTE           pbMPDU;    UINT            cbMPDULen = 0;    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");    spin_lock_irq(&pDevice->lock);        if (pDevice->bStopTx0Pkt == TRUE) {        dev_kfree_skb_irq(skb);        spin_unlock_irq(&pDevice->lock);                    return 0;            };                cbMPDULen = skb->len;    pbMPDU = skb->data;            vDMA0_tx_80211(pDevice, skb);    spin_unlock_irq(&pDevice->lock);        return 0;    }static int  device_xmit(struct sk_buff *skb, struct net_device *dev) {    PSDevice    pDevice=dev->priv;    struct net_device_stats* pStats = &pDevice->stats;            spin_lock_irq(&pDevice->lock);        netif_stop_queue(pDevice->dev);            if (pDevice->bLinkPass == FALSE) {        dev_kfree_skb_irq(skb);        spin_unlock_irq(&pDevice->lock);        return 0;    }        if (pDevice->bStopDataPkt == TRUE) {        dev_kfree_skb_irq(skb);        pStats->tx_dropped++;        spin_unlock_irq(&pDevice->lock);                return 0;     }         nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb);    spin_unlock_irq(&pDevice->lock);        return 0;    }static unsigned const ethernet_polynomial = 0x04c11db7U;static inline u32 ether_crc(int length, unsigned char *data){    int crc = -1;        while(--length >= 0) {        unsigned char current_octet = *data++;        int bit;        for (bit = 0; bit < 8; bit++, current_octet >>= 1) {            crc = (crc << 1) ^                ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);        }    }    return crc;} #ifdef SndEvt_ToAPI VOID evt_notify(PSDevice pDevice,int msgtype,int value) { PSEvtSubmit evthdr; PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);  PWLAN_IE_SSID   pItemSSID; PWLAN_INFOR_POOL PItemInforPool =&(pDevice->ItemInforPool) ;		if(pDevice->bEVTDevEnable == TRUE) {  if(pDevice->skbevt != NULL) {                 evthdr = (PSEvtSubmit)pDevice->skbevt->data;                 evthdr->type = msgtype;                 evthdr->value= value;	        evthdr->content_len = 0;	//fill the information pool	         memset(PItemInforPool,0,sizeof(WLAN_INFOR_POOL));	       if((msgtype==0)&&(value==WMAC_STATE_ASSOC)) {          //msgtype=0:link status message		  pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;		  PItemInforPool->byElementID = pItemSSID->byElementID;		  PItemInforPool->ssid_len = pItemSSID->len;		  memcpy(PItemInforPool->SSID,pItemSSID->abySSID,pItemSSID->len);		  PItemInforPool->uChannel = pDevice->uChannel;		  PItemInforPool->SignalStren = pDevice->scStatistic.SignalStren;		  PItemInforPool->LinkQuality = pDevice->scStatistic.LinkQuality;		if(pDevice->bWPADevEnable)    //wpa supplicant is run ?		  PItemInforPool->encryptionmode = pMgmt->eAuthenMode;		else  {                                               //normal mode                       if(pDevice->eEncryptionStatus == Ndis802_11EncryptionDisabled)  //open			PItemInforPool->encryptionmode = WMAC_AUTH_OPEN;		     else  {		           if(pMgmt->bShareKeyAlgorithm == TRUE)			      PItemInforPool->encryptionmode = WMAC_AUTH_WEPSHAREKEY; //wepshare			  else			      PItemInforPool->encryptionmode = WMAC_AUTH_WEPOPENEKEY; //wepopenkey		     }		 }                   evthdr->content_len = sizeof(WLAN_INFOR_POOL);                   memcpy(pDevice->skbevt->data + sizeof(SEvtSubmit),PItemInforPool, evthdr->content_len);	       	}	//                 skb_put(pDevice->skbevt, sizeof(SEvtSubmit)+evthdr->content_len);                 pDevice->skbevt->dev = pDevice->evtdev;//2008-4-3 modify by Chester for wpa #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)	            pDevice->skbevt->mac_header = pDevice->skbevt->data;#else                    pDevice->skbevt->mac.raw = pDevice->skbevt->data;#endif/*//2008-0221-01, <Mark>  by Einsn Liu	  //           pDevice->skbevt->mac.raw = pDevice->skbevt->data;*/                 pDevice->skbevt->pkt_type = PACKET_HOST;                 pDevice->skbevt->protocol = htons(ETH_P_802_2);                 memset(pDevice->skbevt->cb, 0, sizeof(pDevice->skbevt->cb));                 netif_rx(pDevice->skbevt);                 pDevice->skbevt = dev_alloc_skb((int)pDevice->rx_buf_sz);	        pDevice->ulNTYcount++;           } }   return;}#endif static void device_set_multi(struct net_device *dev) {    PSDevice         pDevice = (PSDevice) dev->priv;    PSMgmtObject     pMgmt = &(pDevice->sMgmtObj);        u32              mc_filter[2];    int              ii;              struct dev_mc_list  *mclist;    BYTE             pbyData[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};       BYTE             byTmpMode = 0;     int              rc;	spin_lock_irq(&pDevice->lock);        rc = CONTROLnsRequestIn(pDevice,                             MESSAGE_TYPE_READ,                            MAC_REG_RCR,                            MESSAGE_REQUEST_MACREG,                            1,                            &byTmpMode                            );     if (rc == 0) pDevice->byRxMode = byTmpMode;                                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);                                            if (dev->flags & IFF_PROMISC) {         // Set promiscuous.        DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);        // Unconditionally log net taps.         pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);    }     else if ((dev->mc_count > pDevice->multicast_limit) || (dev->flags & IFF_ALLMULTI)) {        CONTROLnsRequestOut(pDevice,                            MESSAGE_TYPE_WRITE,                            MAC_REG_MAR0,                            MESSAGE_REQUEST_MACREG,                            8,                            pbyData                            );                    pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);    }     else {        memset(mc_filter, 0, sizeof(mc_filter));        for (ii = 0, mclist = dev->mc_list; mclist && ii < dev->mc_count;             ii++, mclist = mclist->next) {                            int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;            mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));        }        for (ii = 0; ii < 4; ii++) {             MACvWriteMultiAddr(pDevice, ii, *((PBYTE)&mc_filter[0] + ii));             MACvWriteMultiAddr(pDevice, ii+ 4, *((PBYTE)&mc_filter[1] + ii));        }                    pDevice->byRxMode &= ~(RCR_UNICAST);                pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);            }    if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {        // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.        pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);        pDevice->byRxMode &= ~(RCR_UNICAST);    }        ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode);    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode);	spin_unlock_irq(&pDevice->lock);        }static struct net_device_stats *device_get_stats(struct net_device *dev) {    PSDevice pDevice=(PSDevice) dev->priv;      return &pDevice->stats;}static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {	PSDevice	        pDevice = (PSDevice)dev->priv;    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);    PSCmdRequest        pReq;    //BOOL                bCommit = FALSE;#ifdef WIRELESS_EXT    	struct iwreq *wrq = (struct iwreq *) rq;	int                 rc =0;#endif //WIRELESS_EXT	            if (pMgmt == NULL) {        rc = -EFAULT;        return rc;    }    #ifdef SndEvt_ToAPI  if((cmd != IOCTL_CMD_SET) &&       //except  IOCTL_CMD_SET       !(pDevice->flags & DEVICE_FLAGS_OPENED)) {  	 rc = -EINVAL;        return rc;    }#endif    switch(cmd) {#ifdef WIRELESS_EXT    //#if WIRELESS_EXT < 13			case SIOCGIWNAME:		rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL); 		break;	case SIOCSIWNWID:        rc = -EOPNOTSUPP;		break;				case SIOCGIWNWID:     //0x8b03  support	#ifdef  WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT          rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);	#else        rc = -EOPNOTSUPP;	#endif		break;						// Set frequency/channel	case SIOCSIWFREQ:	    rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);		break;	    		// Get frequency/channel	case SIOCGIWFREQ:		rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);		break;                			// Set desired network name (ESSID)	case SIOCSIWESSID:			{			char essid[IW_ESSID_MAX_SIZE+1];			if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {				rc = -E2BIG;				break;			}			if (copy_from_user(essid, wrq->u.essid.pointer,					   wrq->u.essid.length)) {				rc = -EFAULT;				break;			}			rc = iwctl_siwessid(dev, NULL,					    &(wrq->u.essid), essid);		}		break;				// Get current network name (ESSID)	case SIOCGIWESSID:			{			char essid[IW_ESSID_MAX_SIZE+1];			if (wrq->u.essid.pointer)				rc = iwctl_giwessid(dev, NULL,						    &(wrq->u.essid), essid);				if (copy_to_user(wrq->u.essid.pointer,						         essid,						         wrq->u.essid.length) )					rc = -EFAULT;		}		break;				case SIOCSIWAP:		rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);		break;					// Get current Access Point (BSSID)	case SIOCGIWAP:		rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);		break;			// Set desired station name	case SIOCSIWNICKN:        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");	        rc = -EOPNOTSUPP;        		break;		// Get current station name	case SIOCGIWNICKN:        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");        rc = -EOPNOTSUPP;        		break;		// Set the desired bit-rate	case SIOCSIWRATE:		rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);		break;		// Get the current bit-rate	case SIOCGIWRATE:			rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);		break;					// Set the desired RTS threshold	case SIOCSIWRTS:		rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);		break;		    	// Get the current RTS threshold	case SIOCGIWRTS:			rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);		break;			// Set the desired fragmentation threshold	case SIOCSIWFRAG:			rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);	

⌨️ 快捷键说明

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