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

📄 rtsnt_sw.h

📁 虚拟网络驱动程序ndis for 数字电视 ip 数据接收
💻 H
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1995  Realtek Semiconductor Co.

Module Name:

    8139sw.h
    RTFNT_SW.H

Abstract:

    The main header for an RTL8139 Miniport driver.

    The overall structure and much of the code is taken from
    the NE2000 driver included in Microsoft NT3.5 DDK.


Environment:

    Architecturally, there is an assumption in this driver that we are
    on a little endian machine.

Notes:

    optional-notes

Revision History:

    1/25/95 ---- SID

--*/

//#include "DebugPrint.h"

#ifdef __cplusplus
extern "C"
{
#endif

#include "wdm.h"
#ifdef __cplusplus
}
#endif


#include "GUIDs.h"


#ifndef _RTFAST_SFT_
#define _RTFAST_SFT_

#define TS_SYNC_BYTE                    0x47

#ifdef NDIS50_MINIPORT
    #define _PNP_POWER                  1    //SID--------
    #define RTFAST_NDIS_MAJOR_VERSION   5
    #define RTFAST_NDIS_MINOR_VERSION   0
#endif

#ifdef NDIS40_MINIPORT
    #define _PNP_POWER                  1    //SID--------
    #define RTFAST_NDIS_MAJOR_VERSION   4
    #define RTFAST_NDIS_MINOR_VERSION   0
#endif

#ifdef NDIS30_MINIPORT
    #define RTFAST_NDIS_MAJOR_VERSION   3
    #define RTFAST_NDIS_MINOR_VERSION   0
#endif


#define I2C_TIMEOUT                     5

//
// This macro is used along with the flags to selectively
// turn on debugging.
//

#if DBG

#define IF_RTFAST_DEBUG(f) if (RTFast_DebugFlag & (f))
extern ULONG RTFast_DebugFlag;


#define RTFast_DEBUG_LOUD               0x00000001  // debugging info
#define RTFast_DEBUG_VERY_LOUD          0x00000002  // excessive debugging info
#define RTFast_DEBUG_LOG                0x00000004  // enable Rtl8139Log
#define RTFast_DEBUG_CHECK_DUP_SENDS    0x00000008  // check for duplicate sends
#define RTFast_DEBUG_TRACK_PACKET_LENS  0x00000010  // track directed packet lens
#define RTFast_DEBUG_WORKAROUND1        0x00000020  // drop DFR/DIS packets
#define RTFast_DEBUG_CARD_BAD           0x00000040  // dump data if CARD_BAD
#define RTFast_DEBUG_CARD_TESTS         0x00000080  // print reason for failing

//
// Macro for deciding whether to print a lot of debugging information.
//

#define IF_LOUD(A) IF_RTFAST_DEBUG( RTFast_DEBUG_LOUD ) { A }
#define IF_VERY_LOUD(A) IF_RTFAST_DEBUG( RTFast_DEBUG_VERY_LOUD ) { A }

//
// Whether to use the Rtl8139Log buffer to record a trace of the driver.
//

#define IF_LOG(A) IF_RTFAST_DEBUG( RTFast_DEBUG_LOG ) { A }
extern VOID RTFast_Log(UCHAR);

//
// Whether to do loud init failure
//
#define IF_INIT(A) A

//
// Whether to do loud card test failures
//
#define IF_TEST(A) IF_RTFAST_DEBUG( RTFast_DEBUG_CARD_TESTS ) { A }

#else

//
// This is not a debug build, so make everything quiet.
//
#define IF_LOUD(A)
#define IF_VERY_LOUD(A)
#define IF_LOG(A)
#define IF_INIT(A)
#define IF_TEST(A)

#endif


#ifdef DBG
#define RTFAST_DbgMessage(Msg) { DbgPrint(Msg); }
#else
#define RTFAST_DbgMessage(Msg) { }
#endif

//
// Adapter->NumBuffers
//
// controls the number of transmit buffers on the packet.
// Choices are 1 through 12.
//

// #define DEFAULT_NUMBUFFERS 12
#define DEFAULT_NUMBUFFERS              4

#define IMR_MASK                        0x0001        //ignore LengthChange and LinkChange

//
// Create a macro for moving memory from place to place.  Makes
// the code more readable and portable in case we ever support
// a shared memory Rtl8139 adapter.
//

#define RTFAST_MOVE_MEM(dest,src,size) NdisMoveMemory(dest,src,size)

//
// The status of transmit buffers.
//
typedef enum {
    LINK_CONNECT,
    LINK_DISCONNECT
} CONNECT_TYPE;

typedef enum {
    RTL8139,
    RTL8139REVK,
    RTL8139A,
    RTL8139B,
    RTL8130,
    RTL8139C
} RTL_CHIP_TYPE;


typedef enum {
    LINK_AUTO,
    LINK_10,
    LINK_100,
    LINK_UNKNOWN,
} LINK_SPEED;

typedef enum {
    DUPLEX_UNKNOWN,
    DUPLEX_AUTO,
    DUPLEX_FULL,
    DUPLEX_HALF,
} LINK_DUPLEX;

enum {
    MediumHWDefault,
    MediumAutoNegotiation,
    Medium10HALF,
    Medium10FULL,
    Medium100HALF,
    Medium100FULL,
    MediumNotSupported,
    MediumNwayDisabled,
} NwayedForceMediumType;

enum {
    StatisticsUnicast = 0,
    StatisticsMulticast,
    StatisticsAllPID,
    StatisticsEachPID,
    StatisticsSync,
    StatisticsReset,
    StatisticsPacket,
    StatisticsMaxCmd,
} StatisticsCommand;

//luke add for DMI counter
//
// Used to record the 8-byte counters.
//

// *** tiger add for IR
typedef struct _IR
{
	UCHAR	IRType;
	UCHAR	CodeType;
	ULONG	Code;
} IR, *PIR;
// ***

typedef struct _RTL_LARGE_INTEGER {
    ULONG LowPart;
    ULONG HighPart;
} RTL_LARGE_INTEGER, *PRTL_LARGE_INTEGER;

// Added by hanney on Aug 28th 2005
enum _ADAPTERTYPE
{
    DVB_S = 0,
    DVB_C,
    DVB_T,
};

typedef struct _DVB_AdapterType
{
	UCHAR Type;
	UCHAR Version;
    USHORT VendorID;
    USHORT DeviceID;
} DVB_AdapterType, *pDVB_AdapterType;

//
// This initializes an 8-byte counter.
//

#define RtlZeroLargeInteger(LargeInteger) \
{ \
    LargeInteger.LowPart = 0L;\
    LargeInteger.HighPart = 0L; \
}

//
// This adds a longword to an 8-byte counter.
//

#define RtlAddUlongToLargeInteger(LargeInteger,Ulong )  { \
   (LargeInteger).LowPart += (Ulong);                      \
   if ((LargeInteger).LowPart < (Ulong))                   \
     (LargeInteger).HighPart++;                       \
}

// Size of the ethernet header
//
#define RTFAST_HEADER_SIZE  14

//
// Size of the ethernet address
//

#define RTFAST_LENGTH_OF_ADDRESS        6

//
// Number of bytes allowed in a lookahead (max)
//

// Win95B OSR2
#define RTFAST_MAX_LOOKAHEAD (1518 - RTFAST_HEADER_SIZE)

//
// Maximum number of transmit buffers on the card.
//
//#define MAX_XMIT_BUFS     12
#define MAX_XMIT_BUFS       4
//#define MAX_WRITE_BUFS    8
#define MAX_WRITE_BUFS      16

//
// Definition of a transmit buffer.
//
typedef UINT XMIT_BUF;

//tiger add for IR 
#define IMR_IRM				0x08
#define IRCTR_IREN			0x01
#define IRCTR_IRSYSCHK		0x02
#define	IRCTR_REGFLG		0x10
#define	IRMODE_MASK			0x07
#define IRMODE_NEC			0x00
#define IRMODE_RC5			0x01

// x x x x  0 0 0 1  - for TS pack
// x x x x  1 0 0 0  - for TS pack and IR on 07.06
#define IMR_UNMASKALL       0x09 // X X X X  IRM MIRQM DETM TSIRQM   0 0 0 0  1 1 1 1
#define IMR_MASKALL         0x00
#define ISR_STATUS          0x0f
#define TS_INTUNMASK        0x01
#define DET_INTUNMASK       0x01
#define MIRQ_INTUNMASK      0x01
#define IR_INTUNMASK        0x01

#define TSCTR_DEFAULTVAL    0xC12A  // x x trans_mode SI  ALPAS CPRPID TSPES FEPAK
#define INT_DATALEN         188
#define INT_INTCNT          47    // 47 * 128 * 4 = 128 * 188

#define TSCTR_FEPAK         0x01
#define TSCTR_TSPES         0x02
#define TSCTR_CPRPID        0x04
#define TSCTR_ALPAS         0x08
#define TSCTR_SI            0x10
#define TSCTR_TSMODE        0x20
#define TSCTR_WIDTH_EXT     0x80

#define CAM_CAMCTR_DEFAULT  0x00  // RST TSOEN TSIEN ACS1 ACS0 AUTO DET


//
// Size of a single transmit buffer.
//
// #define TX_BUF_SIZE (BUFS_PER_TX*256)
#define TX_BUF_SIZE         2048

// Rx Buffer Start address+2k buffer+redundant
//#define RX_BUF_RING (1024*128)
//#define RX_BUF_SIZE (1024*128+1600+16)
#define RX_BUF_MASK         0x1FFFC
#define RX_BUF_RING         0x1FF20
#define RX_BUF_SIZE         (1024*(128+16) )

#define RTL_PASSIVE      TRUE
#define RTL_DISPATCH FALSE

#define MAX_IP_FILTERPID_NUM   64
#define MaxFilterPID           32
#define MaxIRPQueue            8    //  <32
#define MAXDESRAMBLETSNUM      MaxFilterPID
#define MAX_HARDWARE_FILTERPID 32


#define StatisticTest       0

//
// This structure contains information about the driver
// itself.  There is only have one of these structures.
//
typedef struct _DRIVER_BLOCK {

    //
    // NDIS wrapper information.
    //
    NDIS_HANDLE NdisMacHandle;          // returned from NdisRegisterMac
    NDIS_HANDLE NdisWrapperHandle;      // returned from NdisInitializeWrapper
 
#if CREATE_MY_NEWDEVICE

    NDIS_HANDLE NdisDeviceHandle;
    //
    // Adapters registered for this Miniport driver.
    //
    PDEVICE_OBJECT  pTsDevice;

#endif

    struct _RTFAST_ADAPTER * AdapterQueue;
        //current control adapter
    struct _RTFAST_ADAPTER * CurAdapter;

} DRIVER_BLOCK, * PDRIVER_BLOCK;


typedef struct _PACKET_RESERVED {
    LIST_ENTRY     ListElement;
}  PACKET_RESERVED, *PPACKET_RESERVED;

#define Packet_Protocol_Reserved_len    sizeof(PACKET_RESERVED)>16?sizeof(PACKET_RESERVED):16
#define Rx_PACKETS                      512
#define Rx_BufLen                       1600
#define PROTOCOL_RESERVED(_p)           ((PPACKET_RESERVED)((_p)->ProtocolReserved))


typedef struct _TSHEAD
{           
    UCHAR sync:8;
        
    UCHAR PID1:5;
    UCHAR transport_priority:1;
    UCHAR start_indicator:1;
    UCHAR error_indicator:1;
    UCHAR PID2;

    UCHAR continuity_counter:4;
    UCHAR adaptation_field:2;
    UCHAR scrambling_control:2;
}TSHEAD, *PTSHEAD;

typedef struct _MPE_SECTION_HEAD
{
    UCHAR table_id;

    UCHAR section_length1:4;
    UCHAR not_use1:2;
    UCHAR private_indicator:1;
    UCHAR syntax_indicator:1;
    UCHAR section_length2;
    
    UCHAR MAC_address6;
    UCHAR MAC_address5;
    
    UCHAR next_indicator:1;
    UCHAR LLC_SNAP_flag:1;
    UCHAR address_scramble_control:2;
    UCHAR payload_scramble_control:2;
    UCHAR not_use2:2;
    
    UCHAR section_number;
    UCHAR last_section_number;
    
    UCHAR MAC_address4;
    UCHAR MAC_address3;
    UCHAR MAC_address2;
    UCHAR MAC_address1;
}MPE_SECTION_HEAD, *PMPE_SECTION_HEAD;

typedef struct _MPE_DataStatistic
{
    USHORT wPID;
    LONGLONG lRxStatistic;
    LONG lLostStatistic;
    LONG lRxFrameStatistic;
} MPE_DataStatistic, *PMPE_DataStatistic;

//this structure contains all information about a single
// decode MPE varible  
#define MPE_MAXSECTIONLEN               2048  //2K Bytes

typedef struct _MPE_DECODER
{
  LIST_ENTRY     ListEntry;

  USHORT  wPID;
  ULONG   dw_ip ;// 相应的ip地址
  UCHAR   MACheader[RTFAST_HEADER_SIZE];
  UCHAR   SectionBuf[MPE_MAXSECTIONLEN]; 
  USHORT  TotalSectionLen;
  USHORT  CurSectionLen;
  BOOLEAN SectionSync;
  BOOLEAN SectionDone;

  PUCHAR  IPbuf;
  USHORT  IPPacketLen;// IP len

  ULONG   TotalTsNum;// statistic ts lost
  ULONG   LostTsNum;
  UCHAR   LastTsCounter;
  UCHAR   CurTsCounter;
  BOOLEAN bTsContinuous;

  LONGLONG RxStatistic;  // statistic IP packet length  ---- disabled by hanney on May 27th 
  UCHAR IndexPID;

  USHORT continueCount;
} MPE_DECODER, *PMPE_DECODER;

// Added by Hanney on Feb 16th 2005
/*typedef struct _FILTERPID_LIST
{
	WORD wPID;
	UCHAR cFlag;
} FILTERPID_LIST, *PFILTERPID_LIST;*/

// Encrypt key
// bit convertment table
#define WORD_BIT_NUM        16
#undef _DM2016_


#define HIGH_LSHIFT_BITS    5
#define LOW_LSHIFT_BITS     1

static struct _con
{
	UINT u_des_bit; 
	UINT u_src_bit; 
} 
g_con_table [WORD_BIT_NUM] = 
{
	{15, 9},
	{14, 0},
	{13, 11},
	{12, 8},
	{11, 5},
	{10, 3},
	{9,	1},
	{8,	10},
	{7,	6},
	{6,	4},
	{5,	2},
	{4,	7},
	{3, 13},
	{2, 12},
	{1, 15},
	{0, 14},
};

/*
typedef struct _DESCRAMBLE_INFO
{
    USHORT wPID;
    UCHAR  EvenCW[8];
    UCHAR  OddCW[8];
}DESCRAMBLE_INFO,*pDESCRAMBLE_INFO;
*/
//
// This structure contains all the information about a single
// adapter that this driver is controlling.
//
typedef struct _RTFAST_ADAPTER {

    //
    // This is the handle given by the wrapper for calling ndis
    // functions.
    //
    NDIS_HANDLE MiniportAdapterHandle;
    struct _RTFAST_ADAPTER * NextAdapter;

    RTL_CHIP_TYPE  ChipType;

    //PCI Configuration
    UCHAR       BusType;
    ULONG       IoAddr;                 //IO Base Address
    ULONG       IoSpace;                //IO space range
    UCHAR       InterruptNumber;        //Interrupt Number
    UCHAR       InterruptLevel;         //INterrupt Level

    //Registry variable
    UINT        SpeedDuplexMode;        //read from retistry
    ULONG       ChipOnCardbus;
    UINT        EarlyTxThreshold;
    ULONG       SlotNumber;
    UCHAR       BusMasterEnabledOnDriverLoad;
    BOOLEAN     PlatformIsNT;
    ULONG       RxMaxDMABurst;
    ULONG       TxMaxDMABurst;
    ULONG       EarlyRxThreshold;
    ULONG       TxInterFrameGap;

//  Tx/Rx configuration
    ULONG       NicConfig;               // contents of NIC RCR

    //MAC address
    UCHAR       StationAddress[RTFAST_LENGTH_OF_ADDRESS];       // The ethernet address currently in use.
    UCHAR       PermanentAddress[RTFAST_LENGTH_OF_ADDRESS];   // The ethernet address that is burned into the adapter.


    //
    // Interrupt object.
    //
    NDIS_MINIPORT_INTERRUPT Interrupt;
    USHORT      NicInterruptMask;                // contents of NIC IMR
    USHORT      InterruptEnabled;
    UCHAR       InterruptType;                 // InterruptType is the next interrupt that should be serviced.
    //
    // InterruptStatus tracks interrupt sources that still need to be serviced,
    // it is the logical OR of all card interrupts that have been received and not
    // processed and cleared. (see also INTERRUPT_TYPE definition in rtl8139.h)
    //
    USHORT      InterruptStatus;

    BOOLEAN InLinkCheckTimer;
	BOOLEAN TimerCanceled;
    NDIS_MINIPORT_TIMER ResetCheckingTimer;

    //Query and Set Information
     NDIS_OID   Oid;
     PVOID      InformationBuffer;
     ULONG      InformationBufferLength;
     PULONG     BytesWritten;
     PULONG     BytesNeeded;

    //
    // Statistics used by Set/QueryInformation.
    //
    ULONG       FramesXmitGood;         // Good Frames Transmitted
    ULONG       FramesRcvGood;          // Good Frames Received
    ULONG       FramesXmitBad;          // Bad Frames Transmitted
    ULONG       FramesXmitOneCollision; // Frames Transmitted with one collision
    ULONG       FramesXmitManyCollisions;       // Frames Transmitted with > 1 collision
    ULONG       FrameAlignmentErrors;   // FAE errors counted
    ULONG       CrcErrors;                      // CRC errors counted
    ULONG       MissedPackets;          // missed packet counted
    RTL_LARGE_INTEGER TotalReceiveBytes ;
    RTL_LARGE_INTEGER TotalTransmitBytes ;
    ULONG       ReceivePacketCount;

    //Multicast information
    CHAR        Addresses[MAX_IP_FILTERPID_NUM][RTFAST_LENGTH_OF_ADDRESS];
    UCHAR       NicMulticastRegs[8];          // contents of card multicast registers
    ULONG       PacketFilter;                 // The current packet filter in use.
    UINT        MulticastListMax;             // Number of multicast addresses that this adapter is to support.


    ULONG       MaxLookAhead;                 // The lookahead buffer size in use.


    //Receive variables
    ULONG       NicCurCAPR;            // read pointer
    ULONG       NicPageStart;          // The value to write to the adapter for the start of
                                        // the receive buffer space.
    ULONG       RxBufBoundary;
    ULONG       NicCurCBR;//Write pointer
    ULONG       RxFilledLen;
    UINT        PacketLen;      // Total length of a received packet.
    USHORT      PacketStatus;   // Status of Current received packet
    BOOLEAN     IndicateReceiveDone;// TRUE if the driver needs to call NdisMEthIndicateReceiveComplete
    BOOLEAN     TsPacket;

    PVOID RxVirtualSADTop;
    PVOID RxVirtualSAD;
    NDIS_PHYSICAL_ADDRESS pRxPhysicalSAD;
    ULONG RxPhysicalSAD;
    NDIS_SPIN_LOCK RTFAST_SpinLock;
    // NDIS_SPIN_LOCK IO_SpinLock;
    //cardbus
    UCHAR        BusNum;                         // The Bus number of this adapter;
    UCHAR        DevNum;                         // The Device number of this adapter;
    UCHAR        FunNum;                         // The Function Number of this adapter;
    ULONG        RegistryAdapterCFID;            // AdapterCFID from registry
    NDIS_ENVIRONMENT_TYPE    Environment;        //  Current platform.
    ULONG        MemBaseAddress;                 // base address for cardbus memory space
    UCHAR        DirectEnable;
//19970721

#ifdef  NDIS50_MINIPORT
    NDIS_DEVICE_POWER_STATE NextPowerState;
    NDIS_DEVICE_POWER_STATE CurrentPowerState;
#endif
    UCHAR       FrameCount;
    UCHAR       UnicastWakeup;
    UCHAR       WOL;
    UCHAR       LinkUp;
    UCHAR       AddWakeUpFrame;
    // WMI support
    ULONG       CustomDriverSet;

#if 0

⌨️ 快捷键说明

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