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

📄 globals.h

📁 ndis windows网络驱动程序的范例
💻 H
字号:
/*++

Copyright (c) 1995  Microsoft Corporation

Module Name:

    globals.h

Abstract:

    global defines and definitions

Author:

    Jim Mateer

Revision History:

--*/

#ifndef _GLOBALS_
#define _GLOBALS_

//
// forward struct declarations
//




//
// shutdown mask values
//

#define SHUTDOWN_DEALLOC_PACKET_POOL    0x00000001
#define SHUTDOWN_DEALLOC_LOOKAHEAD_POOL 0x00000002
#define SHUTDOWN_DEALLOC_RESIDUAL_POOL  0x00000004
#define SHUTDOWN_DEINIT_DEV_INSTANCE    0x00000008
#define SHUTDOWN_DELETE_PIPE            0x00000010
#define SHUTDOWN_RELEASE_TIMERQ         0x00000020
#define SHUTDOWN_TERMINATE_WRAPPER      0x00000040
#define SHUTDOWN_DEREGISTER_PROTOCOL    0x00000080
#define	SHUTDOWN_DELETE_DEVICE			0x00000100
#define SHUTDOWN_DELETE_SYMLINK			0x00000200
#define ADAPTER_STATE_INITIALIZING 0x00000001
#define ADAPTER_STATE_CLOSING      0x00000002
#define ADAPTER_STATE_RUNNING      0x00000008



//
// stats available through dev io control IRP. Immediately following this
// structure are unicode string structures and their buffers for the adapter
// names. Following that is the pointer to the flow data.
//

typedef struct _IM_ADAPTER_STATS {

    //
    // OutOfPackets is incremented when no packets for sending/receive packet
    // indications are available.
    //

    ULONG OutOfPackets;
    ULONG OutOfLookaheadBuffers;
    ULONG OutOfResidualBuffers;


} IM_ADAPTER_STATS, *PIM_ADAPTER_STATS;

//




//
// per Adapter control block
//

typedef struct _ADAPTER {

    LIST_ENTRY Linkage;

    STRUCT_TAG;

    //
    // structure book keeping
    //
    // IMDeviceName, MPDeviceName - unicode device names for the IM and underlying
    // MP device. the buffers for the strings are allocated as part of the adapter
    // structure allocation and are located just after the structure. Buffer size
    // is fixed at IM_DEVNAME_SIZE
    //
    // Closing - set if we're called to unbind from an adapter
    //
    // ShutdownMask - mask of operations to perform during unbinding from lower MP
    //

    NDIS_SPIN_LOCK Lock;
    LONG RefCount;
    NDIS_STRING IMDeviceName;
    NDIS_STRING MPDeviceName;
    ULONG Closing;
    ULONG ShutdownMask;
    ULONG IMMPState;            
    //
    //  "miniport" vars
    //
    // DevInstance - contains the number at the end of the device instance string
    // as in "ImSampMP3". This is used by MPInitiailize to determine which IM
    // device is being initialized. Comparison via device names is not possible
    // since the RTL unicode routines run at lowered IRQL and MPInitialize cannot
    // guarantee that condition.
    //
    // CopyLookaheadData - TRUE if the IM can directly touch the lookahead data
    //
    // IMNdisHandle - the handle that identifies the IM device to NDIS
    //
    // BlockingEvent - used to syncrhonize execution of functions that are
    // awaiting completion
    //
    // FinalStatus - holds status returned in completion routine
    //
    // PacketPoolHandle - handle to pool of NDIS_PACKETs used during Send and Packet
    // recieve operations
    //
    // PacketSList - SList of pre-allocated packet structures
    //
    USHORT DevInstance;
    BOOLEAN CopyLookaheadData;
    NDIS_HANDLE IMNdisHandle;
    NDIS_EVENT BlockingEvent;
    NDIS_STATUS FinalStatus;
    NDIS_HANDLE PacketPoolHandle;
    SLIST_HEADER PacketSList;
    NDIS_SPIN_LOCK PacketSListLock;
    //
    // Lookahead and residual buffer Pool vars. residual buffer size
    // is same as TotalSize
    //

    ULONG LookaheadBufferSize;
    NDIS_HANDLE LookaheadPoolHandle;
    SLIST_HEADER LookaheadSList;
    NDIS_SPIN_LOCK LookaheadSListLock;

    NDIS_HANDLE ResidualPoolHandle;
    SLIST_HEADER ResidualSList;
    NDIS_SPIN_LOCK ResidualSListLock;

    //
    // Underlying adapter info - handle, type, etc.
    //
    // LowerMPHandle - the binding handle to the underlying MP
    //
    // BindContext - used in BindAdapterHandler and UnbindAdapterHandler
    //
    // CMBindContext - used for CM when unbinding from IM MP
    //
    // MediaType - self explanatory I would hope
    //
    //
    // TotalSize - max # of bytes including the header.
    //
    // Stats - per adapter stats counters
    //
     //

    NDIS_HANDLE LowerMPHandle;
    NDIS_HANDLE BindContext;
    NDIS_MEDIUM MediaType;
    ULONG LinkSpeed;
    ULONG TotalSize;
    IM_ADAPTER_STATS Stats;
    LIST_ENTRY ClientList;
} ADAPTER, *PADAPTER;


typedef struct _IM_NDIS_REQUEST {
    NDIS_REQUEST ReqBuffer;
    PULONG BytesReadOrWritten;
    PULONG BytesNeeded;
    BOOLEAN LocalRequest;
    VOID (*LocalCompletionFunc)();
    PNDIS_REQUEST OriginalNdisRequest;
} IM_NDIS_REQUEST, *PIM_NDIS_REQUEST;

typedef VOID (*LOCAL_NDISREQUEST_COMPLETION_FUNCTION)(PADAPTER,
                                                      PIM_NDIS_REQUEST,
                                                      NDIS_STATUS);

//
// context structures used by NdisIMQueueMiniportCallback callback routine in
// order to perform work at lowered IRQL. This structure is shared among all
// the routines so we don't maintain routine specific context structures.
// No STRUCT_TAG since these are allocated by ExAllocateFromNPagedLookasideList.
//

typedef struct _UPPER_LAYER_NR_COMPLETION {
    BOOLEAN CallQueryInfoCompletion;
    NDIS_STATUS Status;
} UPPER_LAYER_NR_COMPLETION, *PUPPER_LAYER_NR_COMPLETION;

typedef struct _COREQUEST_COMPLETION {
    PNDIS_REQUEST OriginalNdisRequest;
    NDIS_STATUS Status;
} COREQUEST_COMPLETION, *PCOREQUEST_COMPLETION;

typedef struct _SEND_COMPLETION {
    PNDIS_PACKET Packet;
    NDIS_STATUS Status;
} SEND_COMPLETION, *PSEND_COMPLETION;

typedef struct _STATUS_INDICATION {
    NDIS_STATUS GeneralStatus;
    PVOID StatusBuffer;
    UINT StatusBufferSize;
} STATUS_INDICATION, *PSTATUS_INDICATION;

typedef union _IM_CALLBACK_CONTEXT {

    UPPER_LAYER_NR_COMPLETION NRCompletion;
    COREQUEST_COMPLETION NCoRCompletion;
    SEND_COMPLETION SendCompletion;
    STATUS_INDICATION StatusIndication;
    PNDIS_PACKET PacketToIndicate;

} IM_CALLBACK_CONTEXT, *PIM_CALLBACK_CONTEXT;

//
// use Generic NdisRequest types to indicate NdisRequests that were originated by PS
//

#define NdisRequestLocalSetInfo     NdisRequestGeneric1
#define NdisRequestLocalQueryInfo   NdisRequestGeneric2

//
// Packet context structure. This area resides in the ProtocolReserved area of each packet
//     just after the area reserved for PSA use.
//
//
// STRUCT_TAG - order sensitive. The first dword of the proto reserved area is
//     used to link the packets on an S List. If no PSA reserved area is specified
//     then the first member of this struct gets clobbered. By offsetting the tag,
//     it remains useful for checked builds.
//
//
// The following vars are used only during the sending of a packet:
//
// OriginalPacket - a pointer to the original packet (duh) handed to us by
//     the upper layer.
//
// LookaheadBuffer - used to remember the associated Lookahead buffer after
//     NdisTransferData has completed. This buffer contains the data that is
//     prepended to the residual or transferred data
//
//
// MediaSpecificInfo - used to hold packet priority for MPs that allow packet
//     priority to be specified. Included in the proto reserved area only if
//     the lower MP supports priority queueing. Immediately follows the 
//     packet context struct if included
//

typedef struct  _IM_PACKET_CONTEXT {
    
    LIST_ENTRY TimerQLink;
	STRUCT_TAG;
    PNDIS_PACKET OriginalPacket;
    PNDIS_BUFFER LookaheadBuffer;
} IM_PACKET_CONTEXT, *PIM_PACKET_CONTEXT;


#define IM_MEDIA_INFO_SIZE      (sizeof( MEDIA_SPECIFIC_INFORMATION ) + sizeof( ULONG ))




#define IM_PACKET_CONTEXT_FROM_PACKET( _adapter,  _pkt )   \
    ((PIM_PACKET_CONTEXT)((_pkt)->ProtocolReserved  )) 
//
//
// now the opposite: given a List entry and its position in the Packet context
// struct, find the beginning of the packet. This done by finding the beginning
// of the IM_PACKET_CONTEXT (embedded CONTAINING_RECORD), subtracting the # of
// reserved bytes for the PSA (which gets us to the beginning of the ProtocolReserved
// field in the packet structure), and then backing up to the beginning of the
// packet
//

#define NDISPACKET_FROM_PACKET_CONTEXT( ListEntry, LinkageField )                   \
    CONTAINING_RECORD(                                                              \
        (PUCHAR)(CONTAINING_RECORD( ListEntry, IM_PACKET_CONTEXT, LinkageField )),   \                                                               \
        NDIS_PACKET,                                                                \
        ProtocolReserved)

//
// Buffer context structure. Used when NDIS Buffers are sitting on their
// respective S Lists
//
// SListEntry - used when the buffer is not in use and sitting on either
//     the lookahead or residual buffer S List
//
// NdisBuffer - pointer to NDIS_BUFFER associated with this VM buffer
//

typedef struct  _IM_BUFFER_CONTEXT {

    SINGLE_LIST_ENTRY SListEntry;
    PNDIS_BUFFER NdisBuffer;

} IM_BUFFER_CONTEXT, *PIM_BUFFER_CONTEXT;

//
// registry data configuration structure
//

typedef struct _CONFIG_DATA {

    ULONG PacketPoolSize;
    ULONG LookaheadPoolSize;
    ULONG ResidualPoolSize;
    ULONG MaxMemoryUsage;
    ULONG DebugLevel;
    ULONG DebugMask;
    ULONG NdisRequestBufferLimit;
    ULONG CallbackContextBufferLimit;

} CONFIG_DATA, *PCONFIG_DATA;

//
// define for determing if media is LAN oriented
//

#define NDIS_MEDIA_LAN( _adpt ) (( _adpt )->MediaType == NdisMedium802_3 || \
                                 ( _adpt )->MediaType == NdisMedium802_5 || \
                                 ( _adpt )->MediaType == NdisMediumFddi || \
                                 ( _adpt )->MediaType == NdisMediumDix)

//
//  VOID
//  InsertEntryList(
//      PLIST_ENTRY Entry,
//      PLIST_ENTRY EntryToInsert
//      );
//
//  insert EntryToInsert just after Entry
//

#define InsertEntryList( Entry, EntryToInsert ) {           \
    (EntryToInsert)->Flink = (Entry)->Flink;                \
    (Entry)->Flink = (EntryToInsert);                       \
    (EntryToInsert)->Blink = (EntryToInsert)->Flink->Blink; \
    (EntryToInsert)->Flink->Blink = (EntryToInsert);        \
    }

//
// values for error log entries
//

#define IM_ERROR_MISSING_OID                    0x00010000
#define IM_ERROR_BAD_REGISTRY_DATA              0x00020000
#define IM_ERROR_CANT_REGISTER_ADDRESS_FAMILY   0x00030000
#define IM_ERROR_CANT_INITIALIZE_IMSAMP_DEVICE  0x00040000
#define IM_ERROR_IM _REGISTER_FAILED            0x00050000
#define IM_ERROR_PACKET                         0x00060000
#define IM_ERROR_PACKET_POOL                    0x00070000
#define IM_ERROR_LOOKAHEAD_POOL                 0x00080000
#define IM_ERROR_VM_LOOKAHEAD_BUFFER            0x00090000
#define IM_ERROR_LOOKAHEAD_BUFFER               0x000A0000
#define IM_ERROR_RESIDUAL_POOL                  0x000B0000
#define IM_ERROR_VM_RESIDUAL_BUFFER             0x000C0000
#define IM_ERROR_RESIDUAL_BUFFER                0x000D0000
#define IM_ERROR_INIT_NDIS_WRAPPER              0X000E0000
#define IM_ERROR_PROTOCOL_INIT                  0X000F0000
#define IM_ERROR_CANT_FIND_IMP                  0X00100000
#define IM_ERROR_CANT_READ_KEY                  0X00110000

// bad registry data indicator

#define IM_ERROR_LOWER_MP_INSTANCE_KEY          0x00000001
#define IM_ERROR_MISSING_IMSAMP_MP_INSTANCE_KEY 0x00000003
#define IM_ERROR_INVALID_IMSAMP_MP_INSTANCE     0x00000004

//
// global vars (not based on a device instance)
//

extern LIST_ENTRY AdapterList;
extern NDIS_SPIN_LOCK AdapterListLock;
extern NDIS_HANDLE ClientProtocolHandle;
extern NDIS_HANDLE MPWrapperHandle;
extern NDIS_HANDLE LMDriverHandle;
extern PDRIVER_OBJECT IMDriverObject;
extern PDEVICE_OBJECT IMDeviceObject;
extern NPAGED_LOOKASIDE_LIST NdisRequestLL;
extern NPAGED_LOOKASIDE_LIST CallbackContextLL;

extern CONFIG_DATA ConfigData;         // pointer to Registry data

extern NDIS_STRING IMSymbolicName;
extern NDIS_STRING IMDriverName;
extern NDIS_STRING IMMPName;

//#ifdef PACKET_LOG
//extern ULONG PLogEntries;
//#endif // PACKET_LOG

#endif /* _GLOBALS_ */

/* end globals.h */

⌨️ 快捷键说明

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