Leaked source code of windows server 2003
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.

479 lines
13 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. VOID
  229. MPQueryPNPCapabilities(
  230. OUT PADAPT MiniportProtocolContext,
  231. OUT PNDIS_STATUS Status
  232. );
  233. NDIS_STATUS
  234. MPSetMiniportSecondary (
  235. IN PADAPT Secondary,
  236. IN PADAPT Primary
  237. );
  238. #ifdef NDIS51_MINIPORT
  239. VOID
  240. MPCancelSendPackets(
  241. IN NDIS_HANDLE MiniportAdapterContext,
  242. IN PVOID CancelId
  243. );
  244. VOID
  245. MPAdapterShutdown(
  246. IN NDIS_HANDLE MiniportAdapterContext
  247. );
  248. VOID
  249. MPDevicePnPEvent(
  250. IN NDIS_HANDLE MiniportAdapterContext,
  251. IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent,
  252. IN PVOID InformationBuffer,
  253. IN ULONG InformationBufferLength
  254. );
  255. #endif // NDIS51_MINIPORT
  256. VOID
  257. MPFreeAllPacketPools(
  258. IN PADAPT pAdapt
  259. );
  260. NDIS_STATUS
  261. MPPromoteSecondary (
  262. IN PADAPT pAdapt
  263. );
  264. NDIS_STATUS
  265. MPBundleSearchAndSetSecondary (
  266. IN PADAPT pAdapt
  267. );
  268. VOID
  269. MPProcessSetPowerOid(
  270. IN OUT PNDIS_STATUS pNdisStatus,
  271. IN PADAPT pAdapt,
  272. IN PVOID InformationBuffer,
  273. IN ULONG InformationBufferLength,
  274. OUT PULONG BytesRead,
  275. OUT PULONG BytesNeeded
  276. );
  277. //
  278. // There should be no DbgPrint's in the Free version of the driver
  279. //
  280. #if DBG
  281. #define DBGPRINT(Fmt) \
  282. { \
  283. DbgPrint("Passthru: "); \
  284. DbgPrint Fmt; \
  285. }
  286. #else // if DBG
  287. #define DBGPRINT(Fmt)
  288. #endif // if DBG
  289. #define NUM_PKTS_IN_POOL 256
  290. //
  291. // Protocol reserved part of a sent packet that is allocated by us.
  292. //
  293. typedef struct _SEND_RSVD
  294. {
  295. PNDIS_PACKET OriginalPkt;
  296. } SEND_RSVD, *PSEND_RSVD;
  297. //
  298. // Miniport reserved part of a received packet that is allocated by
  299. // us. Note that this should fit into the MiniportReserved space
  300. // in an NDIS_PACKET.
  301. //
  302. typedef struct _RECV_RSVD
  303. {
  304. PNDIS_PACKET OriginalPkt;
  305. } RECV_RSVD, *PRECV_RSVD;
  306. C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved));
  307. //
  308. // Event Codes related to the PassthruEvent Structure
  309. //
  310. typedef enum
  311. {
  312. Passthru_Invalid,
  313. Passthru_SetPower,
  314. Passthru_Unbind
  315. } PASSSTHRU_EVENT_CODE, *PPASTHRU_EVENT_CODE;
  316. //
  317. // Passthru Event with a code to state why they have been state
  318. //
  319. typedef struct _PASSTHRU_EVENT
  320. {
  321. NDIS_EVENT Event;
  322. PASSSTHRU_EVENT_CODE Code;
  323. } PASSTHRU_EVENT, *PPASSTHRU_EVENT;
  324. //
  325. // Structure used by both the miniport as well as the protocol part of the intermediate driver
  326. // to represent an adapter and its corres. lower bindings
  327. //
  328. typedef struct _ADAPT
  329. {
  330. struct _ADAPT * Next;
  331. NDIS_HANDLE BindingHandle; // To the lower miniport
  332. NDIS_HANDLE MiniportHandle; // NDIS Handle to for miniport up-calls
  333. NDIS_HANDLE SendPacketPoolHandle;
  334. NDIS_HANDLE RecvPacketPoolHandle;
  335. NDIS_STATUS Status; // Open Status
  336. NDIS_EVENT Event; // Used by bind/halt for Open/Close Adapter synch.
  337. NDIS_MEDIUM Medium;
  338. NDIS_REQUEST Request; // This is used to wrap a request coming down
  339. // to us. This exploits the fact that requests
  340. // are serialized down to us.
  341. PULONG BytesNeeded;
  342. PULONG BytesReadOrWritten;
  343. BOOLEAN IndicateRcvComplete;
  344. BOOLEAN OutstandingRequests; // TRUE iff a request is pending
  345. // at the miniport below
  346. BOOLEAN QueuedRequest; // TRUE iff a request is queued at
  347. // this IM miniport
  348. BOOLEAN StandingBy; // True - When the miniport or protocol is transitioning from a D0 to Standby (>D0) State
  349. BOOLEAN UnbindingInProcess;
  350. NDIS_SPIN_LOCK Lock;
  351. // False - At all other times, - Flag is cleared after a transition to D0
  352. NDIS_DEVICE_POWER_STATE MPDeviceState; // Miniport's Device State
  353. NDIS_DEVICE_POWER_STATE PTDeviceState; // Protocol's Device State
  354. NDIS_STRING DeviceName; // For initializing the miniport edge
  355. NDIS_EVENT MiniportInitEvent; // For blocking UnbindAdapter while
  356. // an IM Init is in progress.
  357. BOOLEAN MiniportInitPending; // TRUE iff IMInit in progress
  358. NDIS_STATUS LastIndicatedStatus; // The last indicated media status
  359. NDIS_STATUS LatestUnIndicateStatus; // The latest suppressed media status
  360. ULONG OutstandingSends;
  361. } ADAPT, *PADAPT;
  362. extern NDIS_HANDLE ProtHandle, DriverHandle;
  363. extern NDIS_MEDIUM MediumArray[4];
  364. extern PADAPT pAdaptList;
  365. extern NDIS_SPIN_LOCK GlobalLock;
  366. #define ADAPT_MINIPORT_HANDLE(_pAdapt) ((_pAdapt)->MiniportHandle)
  367. #define ADAPT_DECR_PENDING_SENDS(_pAdapt) \
  368. { \
  369. NdisAcquireSpinLock(&(_pAdapt)->Lock); \
  370. (_pAdapt)->OutstandingSends--; \
  371. NdisReleaseSpinLock(&(_pAdapt)->Lock); \
  372. }
  373. //
  374. // Custom Macros to be used by the passthru driver
  375. //
  376. /*
  377. BOOLEAN
  378. IsIMDeviceStateOn(
  379. PADAPT
  380. )
  381. */
  382. #define IsIMDeviceStateOn(_pP) ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 )