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.

597 lines
16 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ndisprot.h
  5. Abstract:
  6. Data structures, defines and function prototypes for NDISPROT.
  7. Environment:
  8. Kernel mode only.
  9. Revision History:
  10. arvindm 4/5/2000 Created
  11. --*/
  12. #ifndef __NDISPROT__H
  13. #define __NDISPROT__H
  14. #define NT_DEVICE_NAME L"\\Device\\NdisProt"
  15. #define DOS_DEVICE_NAME L"\\DosDevices\\NdisProt"
  16. //
  17. // Abstract types
  18. //
  19. typedef NDIS_EVENT NPROT_EVENT;
  20. #define NPROT_MAC_ADDR_LEN 6
  21. //
  22. // The Open Context represents an open of our device object.
  23. // We allocate this on processing a BindAdapter from NDIS,
  24. // and free it when all references (see below) to it are gone.
  25. //
  26. // Binding/unbinding to an NDIS device:
  27. //
  28. // On processing a BindAdapter call from NDIS, we set up a binding
  29. // to the specified NDIS device (miniport). This binding is
  30. // torn down when NDIS asks us to Unbind by calling
  31. // our UnbindAdapter handler.
  32. //
  33. // Receiving data:
  34. //
  35. // While an NDIS binding exists, read IRPs are queued on this
  36. // structure, to be processed when packets are received.
  37. // If data arrives in the absense of a pended read IRP, we
  38. // queue it, to the extent of one packet, i.e. we save the
  39. // contents of the latest packet received. We fail read IRPs
  40. // received when no NDIS binding exists (or is in the process
  41. // of being torn down).
  42. //
  43. // Sending data:
  44. //
  45. // Write IRPs are used to send data. Each write IRP maps to
  46. // a single NDIS packet. Packet send-completion is mapped to
  47. // write IRP completion. We use NDIS 5.1 CancelSend to support
  48. // write IRP cancellation. Write IRPs that arrive when we don't
  49. // have an active NDIS binding are failed.
  50. //
  51. // Reference count:
  52. //
  53. // The following are long-lived references:
  54. // OPEN_DEVICE ioctl (goes away on processing a Close IRP)
  55. // Pended read IRPs
  56. // Queued received packets
  57. // Uncompleted write IRPs (outstanding sends)
  58. // Existence of NDIS binding
  59. //
  60. typedef struct _NDISPROT_OPEN_CONTEXT
  61. {
  62. LIST_ENTRY Link; // Link into global list
  63. ULONG Flags; // State information
  64. ULONG RefCount;
  65. NPROT_LOCK Lock;
  66. PFILE_OBJECT pFileObject; // Set on OPEN_DEVICE
  67. NDIS_HANDLE BindingHandle;
  68. NDIS_HANDLE SendPacketPool;
  69. NDIS_HANDLE SendBufferPool;
  70. NDIS_HANDLE RecvPacketPool;
  71. NDIS_HANDLE RecvBufferPool;
  72. ULONG MacOptions;
  73. ULONG MaxFrameSize;
  74. LIST_ENTRY PendedWrites; // pended Write IRPs
  75. ULONG PendedSendCount;
  76. LIST_ENTRY PendedReads; // pended Read IRPs
  77. ULONG PendedReadCount;
  78. LIST_ENTRY RecvPktQueue; // queued rcv packets
  79. ULONG RecvPktCount;
  80. NET_DEVICE_POWER_STATE PowerState;
  81. NDIS_EVENT PoweredUpEvent; // signalled iff PowerState is D0
  82. NDIS_STRING DeviceName; // used in NdisOpenAdapter
  83. NDIS_STRING DeviceDescr; // friendly name
  84. NDIS_STATUS BindStatus; // for Open/CloseAdapter
  85. NPROT_EVENT BindEvent; // for Open/CloseAdapter
  86. BOOLEAN bRunningOnWin9x;// TRUE if Win98/SE/ME, FALSE if NT
  87. ULONG oc_sig; // Signature for sanity
  88. UCHAR CurrentAddress[NPROT_MAC_ADDR_LEN];
  89. } NDISPROT_OPEN_CONTEXT, *PNDISPROT_OPEN_CONTEXT;
  90. #define oc_signature 'OiuN'
  91. //
  92. // Definitions for Flags above.
  93. //
  94. #define NUIOO_BIND_IDLE 0x00000000
  95. #define NUIOO_BIND_OPENING 0x00000001
  96. #define NUIOO_BIND_FAILED 0x00000002
  97. #define NUIOO_BIND_ACTIVE 0x00000004
  98. #define NUIOO_BIND_CLOSING 0x00000008
  99. #define NUIOO_BIND_FLAGS 0x0000000F // State of the binding
  100. #define NUIOO_OPEN_IDLE 0x00000000
  101. #define NUIOO_OPEN_ACTIVE 0x00000010
  102. #define NUIOO_OPEN_FLAGS 0x000000F0 // State of the I/O open
  103. #define NUIOO_RESET_IN_PROGRESS 0x00000100
  104. #define NUIOO_NOT_RESETTING 0x00000000
  105. #define NUIOO_RESET_FLAGS 0x00000100
  106. #define NUIOO_MEDIA_CONNECTED 0x00000000
  107. #define NUIOO_MEDIA_DISCONNECTED 0x00000200
  108. #define NUIOO_MEDIA_FLAGS 0x00000200
  109. #define NUIOO_READ_SERVICING 0x00100000 // Is the read service
  110. // routine running?
  111. #define NUIOO_READ_FLAGS 0x00100000
  112. #define NUIOO_UNBIND_RECEIVED 0x10000000 // Seen NDIS Unbind?
  113. #define NUIOO_UNBIND_FLAGS 0x10000000
  114. //
  115. // Globals:
  116. //
  117. typedef struct _NDISPROT_GLOBALS
  118. {
  119. PDRIVER_OBJECT pDriverObject;
  120. PDEVICE_OBJECT ControlDeviceObject;
  121. NDIS_HANDLE NdisProtocolHandle;
  122. UCHAR PartialCancelId; // for cancelling sends
  123. ULONG LocalCancelId;
  124. LIST_ENTRY OpenList; // of OPEN_CONTEXT structures
  125. NPROT_LOCK GlobalLock; // to protect the above
  126. NPROT_EVENT BindsComplete; // have we seen NetEventBindsComplete?
  127. } NDISPROT_GLOBALS, *PNDISPROT_GLOBALS;
  128. //
  129. // NDIS Request context structure
  130. //
  131. typedef struct _NDISPROT_REQUEST
  132. {
  133. NDIS_REQUEST Request;
  134. NPROT_EVENT ReqEvent;
  135. ULONG Status;
  136. } NDISPROT_REQUEST, *PNDISPROT_REQUEST;
  137. #define NUIOO_PACKET_FILTER (NDIS_PACKET_TYPE_DIRECTED| \
  138. NDIS_PACKET_TYPE_MULTICAST| \
  139. NDIS_PACKET_TYPE_BROADCAST)
  140. //
  141. // Send packet pool bounds
  142. //
  143. #define MIN_SEND_PACKET_POOL_SIZE 20
  144. #define MAX_SEND_PACKET_POOL_SIZE 400
  145. //
  146. // ProtocolReserved in sent packets. We save a pointer to the IRP
  147. // that generated the send.
  148. //
  149. // The RefCount is used to determine when to free the packet back
  150. // to its pool. It is used to synchronize between a thread completing
  151. // a send and a thread attempting to cancel a send.
  152. //
  153. typedef struct _NPROT_SEND_PACKET_RSVD
  154. {
  155. PIRP pIrp;
  156. ULONG RefCount;
  157. } NPROT_SEND_PACKET_RSVD, *PNPROT_SEND_PACKET_RSVD;
  158. //
  159. // Receive packet pool bounds
  160. //
  161. #define MIN_RECV_PACKET_POOL_SIZE 4
  162. #define MAX_RECV_PACKET_POOL_SIZE 20
  163. //
  164. // Max receive packets we allow to be queued up
  165. //
  166. #define MAX_RECV_QUEUE_SIZE 4
  167. //
  168. // ProtocolReserved in received packets: we link these
  169. // packets up in a queue waiting for Read IRPs.
  170. //
  171. typedef struct _NPROT_RECV_PACKET_RSVD
  172. {
  173. LIST_ENTRY Link;
  174. PNDIS_BUFFER pOriginalBuffer; // used if we had to partial-map
  175. } NPROT_RECV_PACKET_RSVD, *PNPROT_RECV_PACKET_RSVD;
  176. #include <pshpack1.h>
  177. typedef struct _NDISPROT_ETH_HEADER
  178. {
  179. UCHAR DstAddr[NPROT_MAC_ADDR_LEN];
  180. UCHAR SrcAddr[NPROT_MAC_ADDR_LEN];
  181. USHORT EthType;
  182. } NDISPROT_ETH_HEADER;
  183. typedef struct _NDISPROT_ETH_HEADER UNALIGNED * PNDISPROT_ETH_HEADER;
  184. #include <poppack.h>
  185. extern NDISPROT_GLOBALS Globals;
  186. #define NPROT_ALLOC_TAG 'oiuN'
  187. #ifndef NDIS51
  188. #define NdisGetPoolFromPacket(_Pkt) (_Pkt->Private.Pool)
  189. #endif
  190. //
  191. // Prototypes.
  192. //
  193. NTSTATUS
  194. DriverEntry(
  195. IN PDRIVER_OBJECT pDriverObject,
  196. IN PUNICODE_STRING pRegistryPath
  197. );
  198. VOID
  199. NdisProtUnload(
  200. IN PDRIVER_OBJECT DriverObject
  201. );
  202. NTSTATUS
  203. NdisProtOpen(
  204. IN PDEVICE_OBJECT pDeviceObject,
  205. IN PIRP pIrp
  206. );
  207. NTSTATUS
  208. NdisProtClose(
  209. IN PDEVICE_OBJECT pDeviceObject,
  210. IN PIRP pIrp
  211. );
  212. NTSTATUS
  213. NdisProtCleanup(
  214. IN PDEVICE_OBJECT pDeviceObject,
  215. IN PIRP pIrp
  216. );
  217. NTSTATUS
  218. NdisProtIoControl(
  219. IN PDEVICE_OBJECT pDeviceObject,
  220. IN PIRP pIrp
  221. );
  222. NTSTATUS
  223. ndisprotOpenDevice(
  224. IN PUCHAR pDeviceName,
  225. IN ULONG DeviceNameLength,
  226. IN PFILE_OBJECT pFileObject,
  227. OUT PNDISPROT_OPEN_CONTEXT * ppOpenContext
  228. );
  229. VOID
  230. ndisprotRefOpen(
  231. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  232. );
  233. VOID
  234. ndisprotDerefOpen(
  235. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  236. );
  237. #if DBG
  238. VOID
  239. ndisprotDbgRefOpen(
  240. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  241. IN ULONG FileNumber,
  242. IN ULONG LineNumber
  243. );
  244. VOID
  245. ndisprotDbgDerefOpen(
  246. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  247. IN ULONG FileNumber,
  248. IN ULONG LineNumber
  249. );
  250. #endif // DBG
  251. VOID
  252. NdisProtBindAdapter(
  253. OUT PNDIS_STATUS pStatus,
  254. IN NDIS_HANDLE BindContext,
  255. IN PNDIS_STRING DeviceName,
  256. IN PVOID SystemSpecific1,
  257. IN PVOID SystemSpecific2
  258. );
  259. VOID
  260. NdisProtOpenAdapterComplete(
  261. IN NDIS_HANDLE ProtocolBindingContext,
  262. IN NDIS_STATUS Status,
  263. IN NDIS_STATUS OpenErrorCode
  264. );
  265. VOID
  266. NdisProtUnbindAdapter(
  267. OUT PNDIS_STATUS pStatus,
  268. IN NDIS_HANDLE ProtocolBindingContext,
  269. IN NDIS_HANDLE UnbindContext
  270. );
  271. VOID
  272. NdisProtCloseAdapterComplete(
  273. IN NDIS_HANDLE ProtocolBindingContext,
  274. IN NDIS_STATUS Status
  275. );
  276. NDIS_STATUS
  277. NdisProtPnPEventHandler(
  278. IN NDIS_HANDLE ProtocolBindingContext,
  279. IN PNET_PNP_EVENT pNetPnPEvent
  280. );
  281. VOID
  282. NdisProtProtocolUnloadHandler(
  283. VOID
  284. );
  285. NDIS_STATUS
  286. ndisprotCreateBinding(
  287. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  288. IN PUCHAR pBindingInfo,
  289. IN ULONG BindingInfoLength
  290. );
  291. VOID
  292. ndisprotShutdownBinding(
  293. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  294. );
  295. VOID
  296. ndisprotFreeBindResources(
  297. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  298. );
  299. VOID
  300. ndisprotWaitForPendingIO(
  301. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  302. IN BOOLEAN DoCancelReads
  303. );
  304. VOID
  305. ndisprotDoProtocolUnload(
  306. VOID
  307. );
  308. NDIS_STATUS
  309. ndisprotDoRequest(
  310. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  311. IN NDIS_REQUEST_TYPE RequestType,
  312. IN NDIS_OID Oid,
  313. IN PVOID InformationBuffer,
  314. IN ULONG InformationBufferLength,
  315. OUT PULONG pBytesProcessed
  316. );
  317. NDIS_STATUS
  318. ndisprotValidateOpenAndDoRequest(
  319. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  320. IN NDIS_REQUEST_TYPE RequestType,
  321. IN NDIS_OID Oid,
  322. IN PVOID InformationBuffer,
  323. IN ULONG InformationBufferLength,
  324. OUT PULONG pBytesProcessed,
  325. IN BOOLEAN bWaitForPowerOn
  326. );
  327. VOID
  328. NdisProtResetComplete(
  329. IN NDIS_HANDLE ProtocolBindingContext,
  330. IN NDIS_STATUS Status
  331. );
  332. VOID
  333. NdisProtRequestComplete(
  334. IN NDIS_HANDLE ProtocolBindingContext,
  335. IN PNDIS_REQUEST pNdisRequest,
  336. IN NDIS_STATUS Status
  337. );
  338. VOID
  339. NdisProtStatus(
  340. IN NDIS_HANDLE ProtocolBindingContext,
  341. IN NDIS_STATUS GeneralStatus,
  342. IN PVOID StatusBuffer,
  343. IN UINT StatusBufferSize
  344. );
  345. VOID
  346. NdisProtStatusComplete(
  347. IN NDIS_HANDLE ProtocolBindingContext
  348. );
  349. NDIS_STATUS
  350. ndisprotQueryBinding(
  351. IN PUCHAR pBuffer,
  352. IN ULONG InputLength,
  353. IN ULONG OutputLength,
  354. OUT PULONG pBytesReturned
  355. );
  356. PNDISPROT_OPEN_CONTEXT
  357. ndisprotLookupDevice(
  358. IN PUCHAR pBindingInfo,
  359. IN ULONG BindingInfoLength
  360. );
  361. NDIS_STATUS
  362. ndisprotQueryOidValue(
  363. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  364. OUT PVOID pDataBuffer,
  365. IN ULONG BufferLength,
  366. OUT PULONG pBytesWritten
  367. );
  368. NDIS_STATUS
  369. ndisprotSetOidValue(
  370. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  371. OUT PVOID pDataBuffer,
  372. IN ULONG BufferLength
  373. );
  374. NTSTATUS
  375. NdisProtRead(
  376. IN PDEVICE_OBJECT pDeviceObject,
  377. IN PIRP pIrp
  378. );
  379. VOID
  380. NdisProtCancelRead(
  381. IN PDEVICE_OBJECT pDeviceObject,
  382. IN PIRP pIrp
  383. );
  384. VOID
  385. ndisprotServiceReads(
  386. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  387. );
  388. NDIS_STATUS
  389. NdisProtReceive(
  390. IN NDIS_HANDLE ProtocolBindingContext,
  391. IN NDIS_HANDLE MacReceiveContext,
  392. IN PVOID pHeaderBuffer,
  393. IN UINT HeaderBufferSize,
  394. IN PVOID pLookaheadBuffer,
  395. IN UINT LookaheadBufferSize,
  396. IN UINT PacketSize
  397. );
  398. VOID
  399. NdisProtTransferDataComplete(
  400. IN NDIS_HANDLE ProtocolBindingContext,
  401. IN PNDIS_PACKET pNdisPacket,
  402. IN NDIS_STATUS TransferStatus,
  403. IN UINT BytesTransferred
  404. );
  405. VOID
  406. NdisProtReceiveComplete(
  407. IN NDIS_HANDLE ProtocolBindingContext
  408. );
  409. INT
  410. NdisProtReceivePacket(
  411. IN NDIS_HANDLE ProtocolBindingContext,
  412. IN PNDIS_PACKET pNdisPacket
  413. );
  414. VOID
  415. ndisprotShutdownBinding(
  416. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  417. );
  418. VOID
  419. ndisprotQueueReceivePacket(
  420. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  421. IN PNDIS_PACKET pRcvPacket
  422. );
  423. PNDIS_PACKET
  424. ndisprotAllocateReceivePacket(
  425. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  426. IN UINT DataLength,
  427. OUT PUCHAR * ppDataBuffer
  428. );
  429. VOID
  430. ndisprotFreeReceivePacket(
  431. IN PNDISPROT_OPEN_CONTEXT pOpenContext,
  432. IN PNDIS_PACKET pNdisPacket
  433. );
  434. VOID
  435. ndisprotCancelPendingReads(
  436. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  437. );
  438. VOID
  439. ndisprotFlushReceiveQueue(
  440. IN PNDISPROT_OPEN_CONTEXT pOpenContext
  441. );
  442. NTSTATUS
  443. NdisProtWrite(
  444. IN PDEVICE_OBJECT pDeviceObject,
  445. IN PIRP pIrp
  446. );
  447. VOID
  448. NdisProtCancelWrite(
  449. IN PDEVICE_OBJECT pDeviceObject,
  450. IN PIRP pIrp
  451. );
  452. VOID
  453. NdisProtSendComplete(
  454. IN NDIS_HANDLE ProtocolBindingContext,
  455. IN PNDIS_PACKET pNdisPacket,
  456. IN NDIS_STATUS Status
  457. );
  458. #ifdef EX_CALLBACK
  459. BOOLEAN
  460. ndisprotRegisterExCallBack();
  461. VOID
  462. ndisprotUnregisterExCallBack();
  463. VOID
  464. ndisprotCallback(
  465. PVOID CallBackContext,
  466. PVOID Source,
  467. PVOID NotifyPresenceCallback
  468. );
  469. #else
  470. #define ndisprotRegisterExCallBack() TRUE
  471. #define ndisprotUnregisterExCallBack()
  472. #endif
  473. #endif // __NDISPROT__H