NDIS_PROTOCOL_BLOCK的定义

来源:互联网 发布:destoon网站系站源码 编辑:程序博客网 时间:2024/05/20 06:28

http://blog.csdn.net/rhettxie/archive/2006/03/07/618083.aspx

NDIS_PROTOCOL_BLOCK 结构的完整定义我翻遍了DDK都没找到,翻windows2000源代码也没找到。google到驱动开发网上一篇讲封包过滤技术的文章,里面给出了NDIS_PROTOCOL_BLOCK 的定义。我打印出来对照的一个NDIS protocol hook的代码看,总感觉这个结构的定义有问题。不爽了好几天。今天终于google到正确的定义,放这存着:

Q: Where can I get the definition of NDIS_PROTOCOL_BLOCK structure? Does it depend of Windows version or NDIS version?

A: _NDIS_PROTOCOL_BLOCK structure definition depends of Windows and NDIS versions and it's just partially documented by

Microsoft. Some it's definitions can be found in ndis.h. An example, for Windows XP NDIS_PROTOCOL_BLOCK defined as the

following:

struct _NDIS_PROTOCOL_BLOCK
{
  _NDIS_OPEN_BLOCK*    OpenQueue;
  _REFERENCE     Ref;
  _KEVENT*     DeregEvent;
  _NDIS_PROTOCOL_BLOCK*   NextProtocol;
  _NDIS50_PROTOCOL_CHARACTERISTICS  ProtocolCharacteristics;
  _WORK_QUEUE_ITEM    WorkItem;
  _KMUTANT     Mutex;
  DWORD     MutexOwner;
  _UNICODE_STRING*    BindDeviceName;
  _UNICODE_STRING*    RootDeviceName;
  _NDIS_M_DRIVER_BLOCK*   AssociatedMiniDriver;
  _NDIS_MINIPORT_BLOCK*   BindingAdapter;
};
But in ndis.h for Windows ME you can find the following definition:

//-----------------驱动开发网上给的是这个,这个已经过时了---------------------

struct _NDIS_PROTOCOL_BLOCK
{
  PNDIS_OPEN_BLOCK       OpenQueue;  // queue of opens for this protocol
  REFERENCE        Ref;  // contains spinlock for OpenQueue
  UINT         Length; // of this NDIS_PROTOCOL_BLOCK struct
  NDIS50_PROTOCOL_CHARACTERISTICS   ProtocolCharacteristics;// handler addresses struct
  _NDIS_PROTOCOL_BLOCK *      NextProtocol; // Link to next   
  ULONG        MaxPatternSize;
#if defined(NDIS_WRAPPER)
  //
  // Protocol filters
  //
  struct    _NDIS_PROTOCOL_FILTER * ProtocolFilter[NdisMediumMax+1];
  WORK_QUEUE_ITEM       WorkItem; // Used during NdisRegisterProtocol to
      // notify protocols of existing drivers.
  KMUTEX        Mutex;  // For serialization of Bind/Unbind requests
  PKEVENT        DeregEvent; // Used by NdisDeregisterProtocol
#endif
};
As you can see this structure definition depends of NDIS_PROTOCOL_CHARACTERISTICS definition, which is NDIS version

dependent. The Windows version dependence does not need any comments.

//------------------------------------------------------------------------------------------------------------

也给出NDIS_OPEN_BLOCK定义,这个是在xp ddk的ndis.h里翻出来的:

typedef struct _NDIS_COMMON_OPEN_BLOCK
{
    PVOID                       MacHandle;          // needed for backward compatibility
    NDIS_HANDLE                 BindingHandle;      // Miniport's open context
    PNDIS_MINIPORT_BLOCK        MiniportHandle;     // pointer to the miniport
    PNDIS_PROTOCOL_BLOCK        ProtocolHandle;     // pointer to our protocol
    NDIS_HANDLE                 ProtocolBindingContext;// context when calling ProtXX funcs
    PNDIS_OPEN_BLOCK            MiniportNextOpen;   // used by adapter's OpenQueue
    PNDIS_OPEN_BLOCK            ProtocolNextOpen;   // used by protocol's OpenQueue
    NDIS_HANDLE                 MiniportAdapterContext; // context for miniport
    BOOLEAN                     Reserved1;
    BOOLEAN                     Reserved2;
    BOOLEAN                     Reserved3;
    BOOLEAN                     Reserved4;
    PNDIS_STRING                BindDeviceName;
    KSPIN_LOCK                  Reserved5;
    PNDIS_STRING                RootDeviceName;

    //
    // These are referenced by the macros used by protocols to call.
    // All of the ones referenced by the macros are internal NDIS handlers for the miniports
    //
    union
    {
        SEND_HANDLER            SendHandler;
        WAN_SEND_HANDLER        WanSendHandler;
    };
    TRANSFER_DATA_HANDLER       TransferDataHandler;

    //
    // These are referenced internally by NDIS
    //
    SEND_COMPLETE_HANDLER       SendCompleteHandler;
    TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler;
    RECEIVE_HANDLER             ReceiveHandler;
    RECEIVE_COMPLETE_HANDLER    ReceiveCompleteHandler;
    WAN_RECEIVE_HANDLER         WanReceiveHandler;
    REQUEST_COMPLETE_HANDLER    RequestCompleteHandler;

    //
    // NDIS 4.0 extensions
    //
    RECEIVE_PACKET_HANDLER      ReceivePacketHandler;
    SEND_PACKETS_HANDLER        SendPacketsHandler;

    //
    // More Cached Handlers
    //
    RESET_HANDLER               ResetHandler;
    REQUEST_HANDLER             RequestHandler;
    RESET_COMPLETE_HANDLER      ResetCompleteHandler;
    STATUS_HANDLER              StatusHandler;
    STATUS_COMPLETE_HANDLER     StatusCompleteHandler;
   
#if defined(NDIS_WRAPPER)
    ULONG                       Flags;
    ULONG                       References;
    KSPIN_LOCK                  SpinLock;           // guards Closing
    NDIS_HANDLE                 FilterHandle;
    ULONG                       ProtocolOptions;
    USHORT                      CurrentLookahead;
    USHORT                      ConnectDampTicks;
    USHORT                      DisconnectDampTicks;

    //
    // These are optimizations for getting to driver routines. They are not
    // necessary, but are here to save a dereference through the Driver block.
    //
    W_SEND_HANDLER              WSendHandler;
    W_TRANSFER_DATA_HANDLER     WTransferDataHandler;

    //
    //  NDIS 4.0 miniport entry-points
    //
    W_SEND_PACKETS_HANDLER      WSendPacketsHandler;

    W_CANCEL_SEND_PACKETS_HANDLER   CancelSendPacketsHandler;

    //
    //  Contains the wake-up events that are enabled for the open.
    //
    ULONG                       WakeUpEnable;
    //
    // event to be signalled when close complets
    //
    PKEVENT                     CloseCompleteEvent;

    QUEUED_CLOSE                QC;

    ULONG                       AfReferences;

    PNDIS_OPEN_BLOCK            NextGlobalOpen;

#endif

} NDIS_COMMON_OPEN_BLOCK;

//
// one of these per open on an adapter/protocol
//
struct _NDIS_OPEN_BLOCK
{
#ifdef __cplusplus
    NDIS_COMMON_OPEN_BLOCK NdisCommonOpenBlock;
#else
    NDIS_COMMON_OPEN_BLOCK;
#endif

#if defined(NDIS_WRAPPER)
   
    //
    // The stuff below is for CO drivers/protocols. This part is not allocated for CL drivers.
    //
    struct _NDIS_OPEN_CO
    {
        //
        // this is the list of the call manager opens done on this adapter
        //
        struct _NDIS_CO_AF_BLOCK *  NextAf;
   
        //
        //  NDIS 5.0 miniport entry-points, filled in at open time.
        //
        W_CO_CREATE_VC_HANDLER      MiniportCoCreateVcHandler;
        W_CO_REQUEST_HANDLER        MiniportCoRequestHandler;
   
        //
        // NDIS 5.0 protocol completion routines, filled in at RegisterAf/OpenAf time
        //
        CO_CREATE_VC_HANDLER        CoCreateVcHandler;
        CO_DELETE_VC_HANDLER        CoDeleteVcHandler;
        PVOID                       CmActivateVcCompleteHandler;
        PVOID                       CmDeactivateVcCompleteHandler;
        PVOID                       CoRequestCompleteHandler;
   
        //
        // lists for queuing connections. There is both a queue for currently
        // active connections and a queue for connections that are not active.
        //
        LIST_ENTRY                  ActiveVcHead;
        LIST_ENTRY                  InactiveVcHead;
        LONG                        PendingAfNotifications;
        PKEVENT                     AfNotifyCompleteEvent;
    };
#endif
};