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

📄 main_usb.c

📁 VIA VT6656 USB linux source code.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. * All rights reserved. * * This software is copyrighted by and is the sole property of * VIA Networking Technologies, Inc. This software may only be used * in accordance with the corresponding license agreement. Any unauthorized * use, duplication, transmission, distribution, or disclosure of this * software is expressly forbidden. * * This software is provided by VIA Networking Technologies, Inc. "as is" * and any express or implied warranties, including, but not limited to, the * implied warranties of merchantability and fitness for a particular purpose * are disclaimed. In no event shall VIA Networking Technologies, Inc. * be liable for any direct, indirect, incidental, special, exemplary, or * consequential damages.  *  * File: main_usb.c * * Purpose: driver entry for initial, open, close, tx and rx. * * Author: Lyndon Chen * * Date: Dec 8, 2005 * * Functions: *    *   vntwusb_found1 - module initial (insmod) driver entry  *   device_remove1 - module remove entry  *   device_open - allocate dma/descripter resource & initial mac/bbp function *   device_xmit - asynchrous data tx function *   device_set_multi - set mac filter *   device_ioctl - ioctl entry *   device_close - shutdown mac/bbp & free dma/descripter resource *   device_alloc_frag_buf - rx fragement pre-allocated function *   device_free_tx_bufs - free tx buffer function *   device_dma0_tx_80211- tx 802.11 frame via dma0 *   device_dma0_xmit- tx PS bufferred frame via dma0 *   device_init_registers- initial MAC & BBP & RF internal registers. *   device_init_rings- initial tx/rx ring buffer   *   device_init_defrag_cb- initial & allocate de-fragement buffer.  *   device_tx_srv- tx interrupt service function *   * Revision History: */ #undef __NO_VERSION__#if !defined(__DEVICE_H__)#include "device.h"#endif#if !defined(__CARD_H__)#include "card.h"#endif#if !defined(__TBIT_H__)#include "tbit.h"#endif#if !defined(__BASEBAND_H__)#include "baseband.h"#endif#if !defined(__MAC_H__)#include "mac.h"#endif#if !defined(__TETHER_H__)#include "tether.h"#endif#if !defined(__WMGR_H__)#include "wmgr.h"#endif#if !defined(__WCTL_H__)#include "wctl.h"#endif#if !defined(__POWER_H__)#include "power.h"#endif#if !defined(__WCMD_H__)#include "wcmd.h"#endif#if !defined(__IOCMD_H__)#include "iocmd.h"#endif#if !defined(__TCRC_H__)#include "tcrc.h"#endif#if !defined(__RXTX_H__)#include "rxtx.h"#endif#if !defined(__BSSDB_H__)#include "bssdb.h"#endif#if !defined(__HOSTAP_H__)#include "hostap.h"#endif#if !defined(__WPACTL_H__)#include "wpactl.h"#endif#if !defined(__IOCTL_H__)#include "ioctl.h"#endif#if !defined(__IWCTL_H__)#include "iwctl.h"#endif#if !defined(__DPC_H__)#include "dpc.h"#endif#if !defined(__IOCMD_H__)#include "iocmd.h"#endif#if !defined(__DATARATE_H__)#include "datarate.h"#endif                      #if !defined(__RF_H__)#include "rf.h"#endif#if !defined(__FIRMWARE_H__)#include "firmware.h"#endif#if !defined(__MAC_H__)#include "mac.h"#endif#if !defined(__RNDIS_H__)#include "rndis.h"#endif#if !defined(__CONTROL_H__)#include "control.h"#endif#if !defined (_CHANNEL_H_)#include "channel.h"#endif#if !defined(__INT_H__)#include "int.h"#endif/*---------------------  Static Definitions -------------------------*///static int          msglevel                =MSG_LEVEL_DEBUG;static int          msglevel                =MSG_LEVEL_INFO;//// Define module options//// Version Information #define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"MODULE_AUTHOR(DRIVER_AUTHOR);MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)#define DEVICE_PARAM(N,D) \        static int N[MAX_UINTS]=OPTION_DEFAULT;\        module_param_array(N, int, NULL, 0);\        MODULE_PARM_DESC(N, D);#else#define DEVICE_PARAM(N,D) \        static const int N[MAX_UINTS]=OPTION_DEFAULT;\        MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\        MODULE_PARM_DESC(N, D);#endif#define RX_DESC_MIN0     16#define RX_DESC_MAX0     128#define RX_DESC_DEF0     64DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");#define TX_DESC_MIN0     16#define TX_DESC_MAX0     128#define TX_DESC_DEF0     64DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");#define CHANNEL_MIN     1#define CHANNEL_MAX     14#define CHANNEL_DEF     6DEVICE_PARAM(Channel, "Channel number");/* PreambleType[] is the preamble length used for transmit.   0: indicate allows long preamble type   1: indicate allows short preamble type*/#define PREAMBLE_TYPE_DEF     1DEVICE_PARAM(PreambleType, "Preamble Type");#define RTS_THRESH_MIN     512#define RTS_THRESH_MAX     2347#define RTS_THRESH_DEF     2347DEVICE_PARAM(RTSThreshold, "RTS threshold");#define FRAG_THRESH_MIN     256#define FRAG_THRESH_MAX     2346#define FRAG_THRESH_DEF     2346DEVICE_PARAM(FragThreshold, "Fragmentation threshold");#define DATA_RATE_MIN     0#define DATA_RATE_MAX     13#define DATA_RATE_DEF     13/* datarate[] index   0: indicate 1 Mbps   0x02   1: indicate 2 Mbps   0x04   2: indicate 5.5 Mbps 0x0B   3: indicate 11 Mbps  0x16   4: indicate 6 Mbps   0x0c   5: indicate 9 Mbps   0x12   6: indicate 12 Mbps  0x18    7: indicate 18 Mbps  0x24   8: indicate 24 Mbps  0x30   9: indicate 36 Mbps  0x48  10: indicate 48 Mbps  0x60  11: indicate 54 Mbps  0x6c   12: indicate 72 Mbps  0x90  13: indicate auto rate*/DEVICE_PARAM(ConnectionRate, "Connection data rate");#define OP_MODE_MAX     2#define OP_MODE_DEF     0#define OP_MODE_MIN     0DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");/* OpMode[] is used for transmit.   0: indicate infrastruct mode used   1: indicate adhoc mode used   2: indicate AP mode used   */            /* PSMode[]    0: indicate disable power saving mode   1: indicate enable power saving mode   */#define PS_MODE_DEF     0DEVICE_PARAM(PSMode, "Power saving mode");    #define SHORT_RETRY_MIN     0#define SHORT_RETRY_MAX     31#define SHORT_RETRY_DEF     8DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");    #define LONG_RETRY_MIN     0#define LONG_RETRY_MAX     15#define LONG_RETRY_DEF     4DEVICE_PARAM(LongRetryLimit, "long frame retry limits");/* BasebandType[] baseband type selected   0: indicate 802.11a type   1: indicate 802.11b type   2: indicate 802.11g type*/    #define BBP_TYPE_MIN     0#define BBP_TYPE_MAX     2#define BBP_TYPE_DEF     2DEVICE_PARAM(BasebandType, "baseband type");/* 80211hEnable[]    0: indicate disable 802.11h   1: indicate enable 802.11h*/#define X80211h_MODE_DEF     0DEVICE_PARAM(b80211hEnable, "802.11h mode");//// Static vars definitions// static struct usb_device_id vntwusb_table[] = {	{USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},	{}};#ifdef WIRELESS_EXT// Frequency list (map channels to frequencies)/*static const long frequency_list[] = {     2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,    4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,    5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,    5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,    5700, 5745, 5765, 5785, 5805, 5825	};					#ifndef IW_ENCODE_NOKEY#define IW_ENCODE_NOKEY         0x0800 #define IW_ENCODE_MODE  (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)#endif #if WIRELESS_EXT > 12static const struct iw_handler_def	iwctl_handler_def;#else	struct iw_request_info {};#endif	//WIRELESS_EXT > 12*/#endif /* WIRELESS_EXT */	/*---------------------  Static Functions  --------------------------*/#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)static int vntwusb_found1(struct usb_interface *intf, const struct usb_device_id *id);static void vntwusb_disconnect(struct usb_interface *intf);#elsestatic void* vntwusb_found1(struct usb_device *udev, UINT interface, const struct usb_device_id *id);static void vntwusb_disconnect(struct usb_device *udev, void *ptr);#endifstatic struct net_device_stats *device_get_stats(struct net_device *dev);static int  device_open(struct net_device *dev);static int  device_xmit(struct sk_buff *skb, struct net_device *dev);static void device_set_multi(struct net_device *dev);static int  device_close(struct net_device *dev);static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);static BOOL device_init_defrag_cb(PSDevice pDevice);static void device_init_diversity_timer(PSDevice pDevice);static int  device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);static int  ethtool_ioctl(struct net_device *dev, void *useraddr);static void device_free_tx_bufs(PSDevice pDevice);static void device_free_rx_bufs(PSDevice pDevice);static void device_free_int_bufs(PSDevice pDevice);static void device_free_frag_bufs(PSDevice pDevice);static BOOL device_alloc_bufs(PSDevice pDevice);//2007-1107-01<Add>by MikeLiu#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)static void usb_device_reset(PSDevice pDevice);#endif/*---------------------  Export Variables  --------------------------*//*---------------------  Export Functions  --------------------------*/static voiddevice_set_options(PSDevice pDevice) {        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};            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);                pDevice->cbTD = TX_DESC_DEF0;    pDevice->cbRD = RX_DESC_DEF0;    pDevice->uChannel = CHANNEL_DEF;    pDevice->wRTSThreshold = RTS_THRESH_DEF;    pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;    pDevice->byShortRetryLimit = SHORT_RETRY_DEF;    pDevice->byLongRetryLimit = LONG_RETRY_DEF;    pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;    pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;    pDevice->ePSMode = PS_MODE_DEF;    pDevice->b11hEnable = X80211h_MODE_DEF;        pDevice->eOPMode = OP_MODE_DEF;        pDevice->uConnectionRate = DATA_RATE_DEF;    if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;        pDevice->byBBType = BBP_TYPE_DEF;    pDevice->byPacketType = pDevice->byBBType;    pDevice->byAutoFBCtrl = AUTO_FB_0;    pDevice->bUpdateBBVGA = TRUE;    pDevice->byFOETuning = 0;    pDevice->byAutoPwrTunning = 0;    pDevice->wCTSDuration = 0;    pDevice->byPreambleType = 0;        pDevice->bExistSWNetAddr = FALSE;//    pDevice->bDiversityRegCtlON = TRUE;    pDevice->bDiversityRegCtlON = FALSE;    }        static VOID device_init_diversity_timer(PSDevice pDevice) {        init_timer(&pDevice->TimerSQ3Tmax1);    pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;    pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;    pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);            init_timer(&pDevice->TimerSQ3Tmax2);    pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;    pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;    pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);        init_timer(&pDevice->TimerSQ3Tmax3);

⌨️ 快捷键说明

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