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

📄 ne2000adapter.h

📁 VC++ 6.0NDIS, NDIS Miniport NIC Drivers
💻 H
📖 第 1 页 / 共 2 页
字号:
//  Acknowledges a counter interrupt by setting the bit in
//  the interrupt status (ISR) register.
#define CardAcknowledgeCounterInterrupt(pAdapter) \
    NdisRawWritePortUchar((pAdapter->Info.IoPAddr+NIC_INTR_STATUS), ISR_COUNTER)



// This structure contains specific information about a single for a single ne2000 adapter
typedef struct _NE2000_ADAPTER {
    // This is a count of the number of receives that have been
    // indicated in a row.  This is used to limit the number
    // of sequential receives so that one can periodically check
    // for transmit complete interrupts.
    ULONG ReceivePacketCount;

    // Configuration information.

    // Number of buffer in this adapter.
    UINT NumBuffers;
    // Physical address of the IoBaseAddress
    PVOID IoBaseAddr;
    // Interrupt number this adapter is using.
    CHAR InterruptNumber;
    // Number of multicast addresses that this adapter is to support.
    UINT MulticastListMax;
    // The type of bus that this adapter is running on.
    NDIS_INTERFACE_TYPE BusType;
    // InterruptType is the next interrupt that should be serviced.
    UCHAR InterruptType;
    //  Type of ne2000 card.
    USHORT    CardType;
    //  Address of the memory window.
    ULONG   AttributeMemoryAddress;
    ULONG   AttributeMemorySize;

    // Transmit information.
    // 
    // The next available empty transmit buffer.
    XMIT_BUF NextBufToFill;
    // The next full transmit buffer waiting to transmitted.  This
    // is valid only if CurBufXmitting is -1
    XMIT_BUF NextBufToXmit;
    // This transmit buffer that is currently transmitting.  If none,
    // then the value is -1.
    XMIT_BUF CurBufXmitting;
    // TRUE if a transmit has been started, and have not received the
    // corresponding transmit complete interrupt.
    BOOLEAN TransmitInterruptPending;
    // TRUE if a receive buffer overflow occurs while a
    // transmit complete interrupt was pending.
    BOOLEAN OverflowRestartXmitDpc;
    // The current status of each transmit buffer.
    BUFFER_STATUS BufferStatus[MAX_XMIT_BUFS];
    // Used to map packets to transmit buffers and visa-versa.
    PNDIS_PACKET Packets[MAX_XMIT_BUFS];
    // The length of each packet in the Packets list.
    UINT PacketLens[MAX_XMIT_BUFS];
    // The first packet we have pending.
    PNDIS_PACKET FirstPacket;
    // The tail of the pending queue.
    PNDIS_PACKET LastPacket;
    // The address of the start of the transmit buffer space.
    PUCHAR XmitStart;
    // The address of the start of the receive buffer space.
    PUCHAR PageStart;
    // The address of the end of the receive buffer space.
    PUCHAR PageStop;
    // Status of the last transmit.
    UCHAR XmitStatus;
    // The value to write to the adapter for the start of
    // the transmit buffer space.
    UCHAR NicXmitStart;
    // The value to write to the adapter for the start of
    // the receive buffer space.
    UCHAR NicPageStart;
    // The value to write to the adapter for the end of
    // the receive buffer space.
    UCHAR NicPageStop;

    // Receive information
    // 
    // The value to write to the adapter for the next receive
    // buffer that is free.
    UCHAR NicNextPacket;
    // The next receive buffer that will be filled.
    UCHAR Current;
    // Total length of a received packet.
    UINT PacketLen;

    // 
    // Operational information.
    // 
    // Mapped address of the base io port.
    ULONG IoPAddr;
    // 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 ne2000.h)
    UCHAR InterruptStatus;
    // The ethernet address currently in use.
    UCHAR StationAddress[NE2000_LENGTH_OF_ADDRESS];
    // The ethernet address that is burned into the adapter.
    UCHAR PermanentAddress[NE2000_LENGTH_OF_ADDRESS];
    // The adapter space address of the start of on board memory.
    PUCHAR RamBase;
    // The number of K on the adapter.
    ULONG RamSize;
    // The current packet filter in use.
    ULONG PacketFilter;
    // TRUE if a receive buffer overflow occured.
    BOOLEAN BufferOverflow;
    // TRUE if the driver needs to call NdisMEthIndicateReceiveComplete
    BOOLEAN IndicateReceiveDone;
    // TRUE if this is an NE2000 in an eight bit slot.
    BOOLEAN EightBitSlot;

    // 
    // 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

    // 
    // Reset information.
    // 
    UCHAR NicMulticastRegs[8];          // contents of card multicast registers
    UCHAR NicReceiveConfig;             // contents of NIC RCR
    UCHAR NicInterruptMask;             // contents of NIC IMR

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

    // These are for the current packet being indicated.
    // 
    // The NIC appended header.  Used to find corrupted receive packets.
    UCHAR PacketHeader[4];
    // Ne2000 address of the beginning of the packet.
    PUCHAR PacketHeaderLoc;
    // Lookahead buffer
    UCHAR Lookahead[NE2000_MAX_LOOKAHEAD + NE2000_HEADER_SIZE];
    // List of multicast addresses in use.
    CHAR Addresses[DEFAULT_MULTICASTLISTMAX][NE2000_LENGTH_OF_ADDRESS];

} NE2000_ADAPTER, * PNE2000_ADAPTER;




class KdNdisMiniport;


class KdNe2000Adapter : public KdNdisAdapter{

public :

    KdNe2000Adapter();
    virtual ~KdNe2000Adapter();

    // this is used by the base class KNdisMiniport during initialization, 
    // (in KNdisMiniport::InitializeHandler) to tell NDIS the medium type supported by this adapter
    virtual NDIS_MEDIUM GetMediumType() {return NdisMedium802_3;}
    // the ne2000 data structure
    NE2000_ADAPTER Info;

protected: //for internal use only (private)

    static UINT Ne2000SupportedOids[];
    // used for padding short packets with blanks
    static UCHAR BlankBuffer[60];

    // The overriden Init().Called by the base class
    // This is where we read the configuration info for setting the adapter. 
    virtual NDIS_STATUS Init(PNDIS_STATUS OpenErrorStatus,
                             KdNdisConfiguration  *pConf,
                             NDIS_HANDLE WrapperConfigurationContext); 

    // Handlers called by the Miniports wrapper handlers registered during initialization.
    // These are the actual callbacks that NDIS  expects ,to do the work.The Miniport handlers
    // are the ones registered with NDIS but they only call these functions.
    virtual VOID DisableInterruptHandler();
    virtual VOID EnableInterruptHandler();
    virtual VOID HaltHandler();
    virtual VOID HandleInterruptHandler();
    virtual VOID ISRHandler(OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueDpc);
    virtual NDIS_STATUS QueryInformationHandler(IN NDIS_OID Oid, 
                                                IN  PVOID InformationBuffer,
                                                IN  ULONG InformationBufferLength,
                                                OUT PULONG BytesWritten,
                                                OUT PULONG BytesNeeded);
    virtual NDIS_STATUS ResetHandler(OUT PBOOLEAN AddressingReset);
    virtual NDIS_STATUS SendHandler(IN PNDIS_PACKET Packet, IN UINT Flags);
    virtual NDIS_STATUS SetInformationHandler(IN NDIS_OID Oid, 
                                              IN PVOID InformationBuffer,
                                              IN ULONG InformationBufferLength,
                                              OUT PULONG BytesRead,
                                              OUT PULONG BytesNeeded);
    virtual NDIS_STATUS TransferDataHandler(OUT PNDIS_PACKET Packet,    
                                            OUT PUINT BytesTransferred,
                                            IN NDIS_HANDLE MiniportReceiveContext,
                                            IN UINT ByteOffset,
                                            IN UINT BytesToTransfer);



    // functions for the interrupt handling
    // 
    // called by the SendHandler - Send handler just adds the new  packet to a list
    // DoNextSend iterates the packet list and tries to send each one.
    VOID DoNextSend();
    // called by the RcvDpc to indicate arival of new packet
    INDICATE_STATUS IndicatePacket();
    // The receive DPC handler (called by HandleInterruptHandler)
    BOOLEAN RcvDpc();
    // reads a packet off the card and checks that the CRC is OK
    BOOLEAN PacketOK();
    // the transmit DPC Handler (called by HandleInterruptHandler)
    VOID XmitDpc();
    // recovers the card from a transmit error
    VOID OctogmetusceratorRevisited();

    // hardware functions 
    // 
    // init the adapter block ,initialize physical adapter
    BOOLEAN CardInitialize();
    // Checks that the I/0 base address is correct
    BOOLEAN CardCheckParameters();
    // Checks if the card is in an 8 or 16 bit slot and sets a flag in the Info structure
    BOOLEAN CardSlotTest();
    // Finds out how much RAM the adapter has.
    BOOLEAN CardRamTest();
    BOOLEAN CardReadEthernetAddress();
    BOOLEAN CardSetup();
    VOID CardStop();
    BOOLEAN CardReset();
    BOOLEAN CardCopyDownPacket(PNDIS_PACKET Packet, PUINT Length);
    VOID CardSetBoundary();
    VOID CardStartXmit();
    VOID CardFillMulticastRegs();
    // Copies data from the card to memory.
    BOOLEAN CardCopyUp(PUCHAR TargetBuffer, PUCHAR SourceBuffer, UINT BufferLength);
    BOOLEAN CardCopyDown(PUCHAR TargetBuffer, PUCHAR SourceBuffer, UINT Length);

    NDIS_STATUS DispatchSetMulticastAddressList();
    NDIS_STATUS DispatchSetPacketFilter();

    BOOLEAN SyncCardHandleOverflow();
    BOOLEAN SyncCardUpdateCounters();
    // Acknowledges an overflow interrupt by setting the bit in
    // the interrupt status (ISR) register. Calls SyncCardAcknowledgeOverflow.
    BOOLEAN SyncCardAcknowledgeOverflow();
    BOOLEAN SyncCardGetXmitStatus();
    BOOLEAN SyncCardGetCurrent();
    BOOLEAN SyncCardStop();

    // these functions are registered via KdNdisAdapter::SynchronizeWithInterrupt
    BOOLEAN SyncCardCopyMulticastRegs(PVOID pExtraContext);
    BOOLEAN SyncCardSetReceiveConfig(PVOID pExtraContext);
    BOOLEAN SyncCardSetAllMulticast(PVOID pExtraContext);

    NDIS_STATUS Register(NDIS_HANDLE ConfigurationHandle,
                         BOOLEAN ConfigError,
                         ULONG ConfigErrorValue);

};

#endif // _NE2000ADAPTER_H_

⌨️ 快捷键说明

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