Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

475 lines
9.0 KiB

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