passthru.h
上传用户:sabrinaco
上传日期:2016-01-19
资源大小:3177k
文件大小:10k
开发平台:

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