passthru.h
上传用户:zhuzhu0204
上传日期:2020-07-13
资源大小:13165k
文件大小:13k
开发平台:

Visual C++

  1. /*++
  2. Copyright (c) 1992-2000  Microsoft Corporation
  3. Module Name:
  4.     passthru.h
  5. Abstract:
  6.     Ndis Intermediate Miniport driver sample. This is a passthru driver.
  7. Author:
  8. Environment:
  9. Revision History:
  10.  
  11. --*/
  12. #ifdef NDIS51_MINIPORT
  13. #define PASSTHRU_MAJOR_NDIS_VERSION            5
  14. #define PASSTHRU_MINOR_NDIS_VERSION            1
  15. #else
  16. #define PASSTHRU_MAJOR_NDIS_VERSION            4
  17. #define PASSTHRU_MINOR_NDIS_VERSION            0
  18. #endif
  19. #ifdef NDIS51
  20. #define PASSTHRU_PROT_MAJOR_NDIS_VERSION    5
  21. #define PASSTHRU_PROT_MINOR_NDIS_VERSION    0
  22. #else
  23. #define PASSTHRU_PROT_MAJOR_NDIS_VERSION    4
  24. #define PASSTHRU_PROT_MINOR_NDIS_VERSION    0
  25. #endif
  26. #define MAX_BUNDLEID_LENGTH 50
  27. #define TAG 'ImPa'
  28. #define WAIT_INFINITE 0
  29. //advance declaration
  30. typedef struct _ADAPT ADAPT, *PADAPT;
  31. // BEGIN_PTUSERIO
  32. typedef struct _OPEN_CONTEXT OPEN_CONTEXT, *POPEN_CONTEXT;
  33. // END_PTUSERIO
  34. extern
  35. NTSTATUS
  36. DriverEntry(
  37.     IN PDRIVER_OBJECT            DriverObject,
  38.     IN PUNICODE_STRING           RegistryPath
  39.     );
  40. NTSTATUS
  41. PtDispatch(
  42.     IN PDEVICE_OBJECT            DeviceObject,
  43.     IN PIRP                      Irp
  44.     );
  45. NDIS_STATUS
  46. PtRegisterDevice(
  47.     VOID
  48.     );
  49. NDIS_STATUS
  50. PtDeregisterDevice(
  51.     VOID
  52.    );
  53. VOID
  54. PtUnloadProtocol(
  55.     VOID
  56.     );
  57. //
  58. // Protocol proto-types
  59. //
  60. extern
  61. VOID
  62. PtOpenAdapterComplete(
  63.     IN NDIS_HANDLE                ProtocolBindingContext,
  64.     IN NDIS_STATUS                Status,
  65.     IN NDIS_STATUS                OpenErrorStatus
  66.     );
  67. extern
  68. VOID
  69. PtCloseAdapterComplete(
  70.     IN NDIS_HANDLE                ProtocolBindingContext,
  71.     IN NDIS_STATUS                Status
  72.     );
  73. extern
  74. VOID
  75. PtResetComplete(
  76.     IN NDIS_HANDLE                ProtocolBindingContext,
  77.     IN NDIS_STATUS                Status
  78.     );
  79. extern
  80. VOID
  81. PtRequestComplete(
  82.     IN NDIS_HANDLE                ProtocolBindingContext,
  83.     IN PNDIS_REQUEST              NdisRequest,
  84.     IN NDIS_STATUS                Status
  85.     );
  86. extern
  87. VOID
  88. PtStatus(
  89.     IN NDIS_HANDLE                ProtocolBindingContext,
  90.     IN NDIS_STATUS                GeneralStatus,
  91.     IN PVOID                      StatusBuffer,
  92.     IN UINT                       StatusBufferSize
  93.     );
  94. extern
  95. VOID
  96. PtStatusComplete(
  97.     IN NDIS_HANDLE                ProtocolBindingContext
  98.     );
  99. extern
  100. VOID
  101. PtSendComplete(
  102.     IN NDIS_HANDLE                ProtocolBindingContext,
  103.     IN PNDIS_PACKET               Packet,
  104.     IN NDIS_STATUS                Status
  105.     );
  106. extern
  107. VOID
  108. PtTransferDataComplete(
  109.     IN NDIS_HANDLE                ProtocolBindingContext,
  110.     IN PNDIS_PACKET               Packet,
  111.     IN NDIS_STATUS                Status,
  112.     IN UINT                       BytesTransferred
  113.     );
  114. extern
  115. NDIS_STATUS
  116. PtReceive(
  117.     IN NDIS_HANDLE                ProtocolBindingContext,
  118.     IN NDIS_HANDLE                MacReceiveContext,
  119.     IN PVOID                      HeaderBuffer,
  120.     IN UINT                       HeaderBufferSize,
  121.     IN PVOID                      LookAheadBuffer,
  122.     IN UINT                       LookaheadBufferSize,
  123.     IN UINT                       PacketSize
  124.     );
  125. extern
  126. VOID
  127. PtReceiveComplete(
  128.     IN NDIS_HANDLE                ProtocolBindingContext
  129.     );
  130. extern
  131. INT
  132. PtReceivePacket(
  133.     IN NDIS_HANDLE                ProtocolBindingContext,
  134.     IN PNDIS_PACKET               Packet
  135.     );
  136. extern
  137. VOID
  138. PtBindAdapter(
  139.     OUT PNDIS_STATUS              Status,
  140.     IN  NDIS_HANDLE               BindContext,
  141.     IN  PNDIS_STRING              DeviceName,
  142.     IN  PVOID                     SystemSpecific1,
  143.     IN  PVOID                     SystemSpecific2
  144.     );
  145. extern
  146. VOID
  147. PtUnbindAdapter(
  148.     OUT PNDIS_STATUS              Status,
  149.     IN  NDIS_HANDLE               ProtocolBindingContext,
  150.     IN  NDIS_HANDLE               UnbindContext
  151.     );
  152.     
  153. VOID
  154. PtUnload(
  155.     IN PDRIVER_OBJECT             DriverObject
  156.     );
  157. extern 
  158. NDIS_STATUS
  159. PtPNPHandler(
  160.     IN NDIS_HANDLE                ProtocolBindingContext,
  161.     IN PNET_PNP_EVENT             pNetPnPEvent
  162.     );
  163. NDIS_STATUS
  164. PtPnPNetEventReconfigure(
  165.     IN PADAPT            pAdapt,
  166.     IN PNET_PNP_EVENT    pNetPnPEvent
  167.     );    
  168. NDIS_STATUS 
  169. PtPnPNetEventSetPower (
  170.     IN PADAPT                    pAdapt,
  171.     IN PNET_PNP_EVENT            pNetPnPEvent
  172.     );
  173.     
  174. //
  175. // Miniport proto-types
  176. //
  177. NDIS_STATUS
  178. MPInitialize(
  179.     OUT PNDIS_STATUS             OpenErrorStatus,
  180.     OUT PUINT                    SelectedMediumIndex,
  181.     IN PNDIS_MEDIUM              MediumArray,
  182.     IN UINT                      MediumArraySize,
  183.     IN NDIS_HANDLE               MiniportAdapterHandle,
  184.     IN NDIS_HANDLE               WrapperConfigurationContext
  185.     );
  186. VOID
  187. MPSendPackets(
  188.     IN NDIS_HANDLE                MiniportAdapterContext,
  189.     IN PPNDIS_PACKET              PacketArray,
  190.     IN UINT                       NumberOfPackets
  191.     );
  192. NDIS_STATUS
  193. MPSend(
  194.     IN NDIS_HANDLE                MiniportAdapterContext,
  195.     IN PNDIS_PACKET               Packet,
  196.     IN UINT                       Flags
  197.     );
  198. NDIS_STATUS
  199. MPQueryInformation(
  200.     IN NDIS_HANDLE                MiniportAdapterContext,
  201.     IN NDIS_OID                   Oid,
  202.     IN PVOID                      InformationBuffer,
  203.     IN ULONG                      InformationBufferLength,
  204.     OUT PULONG                    BytesWritten,
  205.     OUT PULONG                    BytesNeeded
  206.     );
  207. NDIS_STATUS
  208. MPSetInformation(
  209.     IN NDIS_HANDLE                MiniportAdapterContext,
  210.     IN NDIS_OID                   Oid,
  211.     IN PVOID                      InformationBuffer,
  212.     IN ULONG                      InformationBufferLength,
  213.     OUT PULONG                    BytesRead,
  214.     OUT PULONG                    BytesNeeded
  215.     );
  216. VOID
  217. MPReturnPacket(
  218.     IN NDIS_HANDLE                MiniportAdapterContext,
  219.     IN PNDIS_PACKET               Packet
  220.     );
  221. NDIS_STATUS
  222. MPTransferData(
  223.     OUT PNDIS_PACKET              Packet,
  224.     OUT PUINT                     BytesTransferred,
  225.     IN NDIS_HANDLE                MiniportAdapterContext,
  226.     IN NDIS_HANDLE                MiniportReceiveContext,
  227.     IN UINT                       ByteOffset,
  228.     IN UINT                       BytesToTransfer
  229.     );
  230. VOID
  231. MPHalt(
  232.     IN NDIS_HANDLE                MiniportAdapterContext
  233.     );
  234. VOID
  235. MPQueryPNPCapabilities(  
  236.     OUT PADAPT                    MiniportProtocolContext, 
  237.     OUT PNDIS_STATUS              Status
  238.     );
  239. NDIS_STATUS
  240. MPSetMiniportSecondary ( 
  241.     IN PADAPT                    Secondary, 
  242.     IN PADAPT                    Primary
  243.     );
  244. #ifdef NDIS51_MINIPORT
  245. VOID
  246. MPCancelSendPackets(
  247.     IN NDIS_HANDLE            MiniportAdapterContext,
  248.     IN PVOID                  CancelId
  249.     );
  250. VOID
  251. MPAdapterShutdown(
  252.     IN NDIS_HANDLE                MiniportAdapterContext
  253.     );
  254. VOID
  255. MPDevicePnPEvent(
  256.     IN NDIS_HANDLE                MiniportAdapterContext,
  257.     IN NDIS_DEVICE_PNP_EVENT      DevicePnPEvent,
  258.     IN PVOID                      InformationBuffer,
  259.     IN ULONG                      InformationBufferLength
  260.     );
  261. #endif // NDIS51_MINIPORT
  262. VOID
  263. MPFreeAllPacketPools(
  264.     IN PADAPT                    pAdapt
  265.     );
  266. NDIS_STATUS 
  267. MPPromoteSecondary ( 
  268.     IN PADAPT                    pAdapt 
  269.     );
  270. NDIS_STATUS 
  271. MPBundleSearchAndSetSecondary (
  272.     IN PADAPT                    pAdapt 
  273.     );
  274. VOID
  275. MPProcessSetPowerOid(
  276.     IN OUT PNDIS_STATUS          pNdisStatus,
  277.     IN PADAPT                    pAdapt,
  278.     IN PVOID                     InformationBuffer,
  279.     IN ULONG                     InformationBufferLength,
  280.     OUT PULONG                   BytesRead,
  281.     OUT PULONG                   BytesNeeded
  282.     );
  283. //
  284. // There should be no DbgPrint's in the Free version of the driver
  285. //
  286. #if DBG
  287. #define DBGPRINT(Fmt)                                        
  288.     {                                                        
  289.         DbgPrint("Passthru: ");                                
  290.         DbgPrint Fmt;                                        
  291.     }
  292. #else // if DBG
  293. #define DBGPRINT(Fmt)                                            
  294. #endif // if DBG 
  295. #define    NUM_PKTS_IN_POOL    256
  296. //
  297. // Protocol reserved part of a sent packet that is allocated by us.
  298. //
  299. typedef struct _SEND_RSVD
  300. {
  301.     PNDIS_PACKET    OriginalPkt;
  302. } SEND_RSVD, *PSEND_RSVD;
  303. //
  304. // Miniport reserved part of a received packet that is allocated by
  305. // us. Note that this should fit into the MiniportReserved space
  306. // in an NDIS_PACKET.
  307. //
  308. typedef struct _RECV_RSVD
  309. {
  310.     PNDIS_PACKET    OriginalPkt;
  311. } RECV_RSVD, *PRECV_RSVD;
  312. C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved));
  313. //
  314. // Event Codes related to the PassthruEvent Structure
  315. //
  316. typedef enum 
  317. {
  318.     Passthru_Invalid,
  319.     Passthru_SetPower,
  320.     Passthru_Unbind
  321. } PASSSTHRU_EVENT_CODE, *PPASTHRU_EVENT_CODE; 
  322. //
  323. // Passthru Event with  a code to state why they have been state
  324. //
  325. typedef struct _PASSTHRU_EVENT
  326. {
  327.     NDIS_EVENT Event;
  328.     PASSSTHRU_EVENT_CODE Code;
  329. } PASSTHRU_EVENT, *PPASSTHRU_EVENT;
  330. /*
  331. //
  332. // Structure used by both the miniport as well as the protocol part of the intermediate driver
  333. // to represent an adapter and its corres. lower bindings
  334. //
  335. typedef struct _ADAPT
  336. {
  337.     struct _ADAPT *                Next;
  338.     
  339.     NDIS_HANDLE                    BindingHandle;    // To the lower miniport
  340.     NDIS_HANDLE                    MiniportHandle;    // NDIS Handle to for miniport up-calls
  341.     NDIS_HANDLE                    SendPacketPoolHandle;
  342.     NDIS_HANDLE                    RecvPacketPoolHandle;
  343.     NDIS_STATUS                    Status;            // Open Status
  344.     NDIS_EVENT                     Event;            // Used by bind/halt for Open/Close Adapter synch.
  345.     NDIS_MEDIUM                    Medium;
  346.     NDIS_REQUEST                   Request;        // This is used to wrap a request coming down
  347.                                                 // to us. This exploits the fact that requests
  348.                                                 // are serialized down to us.
  349.     PULONG                         BytesNeeded;
  350.     PULONG                         BytesReadOrWritten;
  351.     BOOLEAN                        IndicateRcvComplete;
  352.     
  353.     BOOLEAN                        OutstandingRequests;      // TRUE iff a request is pending
  354.                                                         // at the miniport below
  355.     BOOLEAN                        QueuedRequest;            // TRUE iff a request is queued at
  356.                                                         // this IM miniport
  357.     BOOLEAN                        StandingBy;                // True - When the miniport or protocol is transitioning from a D0 to Standby (>D0) State
  358.     BOOLEAN                        UnbindingInProcess;
  359.     NDIS_SPIN_LOCK                 Lock;
  360.                                                         // False - At all other times, - Flag is cleared after a transition to D0
  361.     NDIS_DEVICE_POWER_STATE        MPDeviceState;            // Miniport's Device State 
  362.     NDIS_DEVICE_POWER_STATE        PTDeviceState;            // Protocol's Device State 
  363.     NDIS_STRING                    DeviceName;                // For initializing the miniport edge
  364. // BEGIN_PTUSERIO
  365.     NDIS_STRING                    LowerDeviceName;     // 设备对象的名称,这是传递给NdisOpenAdapter的参数
  366.     
  367.     ULONG                          RefCount; // 此结构的引用计数
  368.     POPEN_CONTEXT                  pOpenContext;
  369. // END_PTUSERIO
  370.     NDIS_EVENT                     MiniportInitEvent;        // For blocking UnbindAdapter while
  371.                                                         // an IM Init is in progress.
  372.     BOOLEAN                        MiniportInitPending;    // TRUE iff IMInit in progress
  373.     NDIS_STATUS                    LastIndicatedStatus;    // The last indicated media status
  374.     NDIS_STATUS                    LatestUnIndicateStatus; // The latest suppressed media status
  375.     ULONG                          OutstandingSends;
  376. // BEGIN_PTEX_FILTER
  377.     //
  378.     // Per-Adapter Filter-Specific Area
  379.     //
  380.     ULONG                          FilterReserved[16];
  381. // END_PTEX_FILTER
  382. } ADAPT, *PADAPT;
  383. */
  384. extern    NDIS_HANDLE                        ProtHandle, DriverHandle;
  385. extern    NDIS_MEDIUM                        MediumArray[4];
  386. extern    PADAPT                             pAdaptList;
  387. extern    NDIS_SPIN_LOCK                     GlobalLock;
  388. #define ADAPT_MINIPORT_HANDLE(_pAdapt)    ((_pAdapt)->MiniportHandle)
  389. #define ADAPT_DECR_PENDING_SENDS(_pAdapt)     
  390.     {                                         
  391.         NdisAcquireSpinLock(&(_pAdapt)->Lock);   
  392.         (_pAdapt)->OutstandingSends--;           
  393.         NdisReleaseSpinLock(&(_pAdapt)->Lock);   
  394.     }
  395. //
  396. // Custom Macros to be used by the passthru driver 
  397. //
  398. /*
  399. BOOLEAN
  400. IsIMDeviceStateOn(
  401.    PADAPT 
  402.    )
  403. */
  404. #define IsIMDeviceStateOn(_pP)        ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 )