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.

584 lines
15 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ndisuio.h
  5. Abstract:
  6. Data structures, defines and function prototypes for NDISUIO.
  7. Environment:
  8. Kernel mode only.
  9. Revision History:
  10. arvindm 4/5/2000 Created
  11. --*/
  12. #ifndef __NDISUIO__H
  13. #define __NDISUIO__H
  14. #define NT_DEVICE_NAME L"\\Device\\Ndisuio"
  15. #define DOS_DEVICE_NAME L"\\DosDevices\\Ndisuio"
  16. //
  17. // Abstract types
  18. //
  19. typedef NDIS_EVENT NUIO_EVENT;
  20. #define NUIO_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 _NDISUIO_OPEN_CONTEXT
  61. {
  62. LIST_ENTRY Link; // Link into global list
  63. ULONG Flags; // State information
  64. ULONG RefCount;
  65. NUIO_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. NUIO_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[NUIO_MAC_ADDR_LEN];
  89. } NDISUIO_OPEN_CONTEXT, *PNDISUIO_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 _NDISUIO_GLOBALS
  118. {
  119. PDRIVER_OBJECT pDriverObject;
  120. PDEVICE_OBJECT ControlDeviceObject;
  121. NDIS_HANDLE NdisProtocolHandle;
  122. USHORT EthType; // frame type we are interested in
  123. UCHAR PartialCancelId; // for cancelling sends
  124. ULONG LocalCancelId;
  125. LIST_ENTRY OpenList; // of OPEN_CONTEXT structures
  126. NUIO_LOCK GlobalLock; // to protect the above
  127. NUIO_EVENT BindsComplete; // have we seen NetEventBindsComplete?
  128. } NDISUIO_GLOBALS, *PNDISUIO_GLOBALS;
  129. //
  130. // The following are arranged in the way a little-endian processor
  131. // would read 2 bytes off the wire.
  132. //
  133. #define NUIO_ETH_TYPE 0x8e88
  134. #define NUIO_8021P_TAG_TYPE 0x0081
  135. //
  136. // NDIS Request context structure
  137. //
  138. typedef struct _NDISUIO_REQUEST
  139. {
  140. NDIS_REQUEST Request;
  141. NUIO_EVENT ReqEvent;
  142. ULONG Status;
  143. } NDISUIO_REQUEST, *PNDISUIO_REQUEST;
  144. #define NUIOO_PACKET_FILTER (NDIS_PACKET_TYPE_DIRECTED| \
  145. NDIS_PACKET_TYPE_MULTICAST| \
  146. NDIS_PACKET_TYPE_BROADCAST)
  147. //
  148. // Send packet pool bounds
  149. //
  150. #define MIN_SEND_PACKET_POOL_SIZE 20
  151. #define MAX_SEND_PACKET_POOL_SIZE 400
  152. //
  153. // ProtocolReserved in sent packets. We save a pointer to the IRP
  154. // that generated the send.
  155. //
  156. // The RefCount is used to determine when to free the packet back
  157. // to its pool. It is used to synchronize between a thread completing
  158. // a send and a thread attempting to cancel a send.
  159. //
  160. typedef struct _NUIO_SEND_PACKET_RSVD
  161. {
  162. PIRP pIrp;
  163. ULONG RefCount;
  164. } NUIO_SEND_PACKET_RSVD, *PNUIO_SEND_PACKET_RSVD;
  165. //
  166. // Receive packet pool bounds
  167. //
  168. #define MIN_RECV_PACKET_POOL_SIZE 4
  169. #define MAX_RECV_PACKET_POOL_SIZE 20
  170. //
  171. // Max receive packets we allow to be queued up
  172. //
  173. #define MAX_RECV_QUEUE_SIZE 4
  174. //
  175. // ProtocolReserved in received packets: we link these
  176. // packets up in a queue waiting for Read IRPs.
  177. //
  178. typedef struct _NUIO_RECV_PACKET_RSVD
  179. {
  180. LIST_ENTRY Link;
  181. PNDIS_BUFFER pOriginalBuffer; // used if we had to partial-map
  182. } NUIO_RECV_PACKET_RSVD, *PNUIO_RECV_PACKET_RSVD;
  183. #include <pshpack1.h>
  184. typedef struct _NDISUIO_ETH_HEADER
  185. {
  186. UCHAR DstAddr[NUIO_MAC_ADDR_LEN];
  187. UCHAR SrcAddr[NUIO_MAC_ADDR_LEN];
  188. USHORT EthType;
  189. } NDISUIO_ETH_HEADER;
  190. typedef struct _NDISUIO_ETH_HEADER UNALIGNED * PNDISUIO_ETH_HEADER;
  191. #include <poppack.h>
  192. extern NDISUIO_GLOBALS Globals;
  193. #define NUIO_ALLOC_TAG 'oiuN'
  194. #ifndef NDIS51
  195. #define NdisGetPoolFromPacket(_Pkt) (_Pkt->Private.Pool)
  196. #endif
  197. //
  198. // Prototypes.
  199. //
  200. NTSTATUS
  201. DriverEntry(
  202. IN PDRIVER_OBJECT pDriverObject,
  203. IN PUNICODE_STRING pRegistryPath
  204. );
  205. VOID
  206. NdisuioUnload(
  207. IN PDRIVER_OBJECT DriverObject
  208. );
  209. NTSTATUS
  210. NdisuioOpen(
  211. IN PDEVICE_OBJECT pDeviceObject,
  212. IN PIRP pIrp
  213. );
  214. NTSTATUS
  215. NdisuioClose(
  216. IN PDEVICE_OBJECT pDeviceObject,
  217. IN PIRP pIrp
  218. );
  219. NTSTATUS
  220. NdisuioCleanup(
  221. IN PDEVICE_OBJECT pDeviceObject,
  222. IN PIRP pIrp
  223. );
  224. NTSTATUS
  225. NdisuioIoControl(
  226. IN PDEVICE_OBJECT pDeviceObject,
  227. IN PIRP pIrp
  228. );
  229. NTSTATUS
  230. ndisuioOpenDevice(
  231. IN PUCHAR pDeviceName,
  232. IN ULONG DeviceNameLength,
  233. IN PFILE_OBJECT pFileObject,
  234. OUT PNDISUIO_OPEN_CONTEXT * ppOpenContext
  235. );
  236. VOID
  237. ndisuioRefOpen(
  238. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  239. );
  240. VOID
  241. ndisuioDerefOpen(
  242. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  243. );
  244. #if DBG
  245. VOID
  246. ndisuioDbgRefOpen(
  247. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  248. IN ULONG FileNumber,
  249. IN ULONG LineNumber
  250. );
  251. VOID
  252. ndisuioDbgDerefOpen(
  253. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  254. IN ULONG FileNumber,
  255. IN ULONG LineNumber
  256. );
  257. #endif // DBG
  258. VOID
  259. NdisuioBindAdapter(
  260. OUT PNDIS_STATUS pStatus,
  261. IN NDIS_HANDLE BindContext,
  262. IN PNDIS_STRING DeviceName,
  263. IN PVOID SystemSpecific1,
  264. IN PVOID SystemSpecific2
  265. );
  266. VOID
  267. NdisuioOpenAdapterComplete(
  268. IN NDIS_HANDLE ProtocolBindingContext,
  269. IN NDIS_STATUS Status,
  270. IN NDIS_STATUS OpenErrorCode
  271. );
  272. VOID
  273. NdisuioUnbindAdapter(
  274. OUT PNDIS_STATUS pStatus,
  275. IN NDIS_HANDLE ProtocolBindingContext,
  276. IN NDIS_HANDLE UnbindContext
  277. );
  278. VOID
  279. NdisuioCloseAdapterComplete(
  280. IN NDIS_HANDLE ProtocolBindingContext,
  281. IN NDIS_STATUS Status
  282. );
  283. NDIS_STATUS
  284. NdisuioPnPEventHandler(
  285. IN NDIS_HANDLE ProtocolBindingContext,
  286. IN PNET_PNP_EVENT pNetPnPEvent
  287. );
  288. VOID
  289. NdisuioProtocolUnloadHandler(
  290. VOID
  291. );
  292. NDIS_STATUS
  293. ndisuioCreateBinding(
  294. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  295. IN PUCHAR pBindingInfo,
  296. IN ULONG BindingInfoLength
  297. );
  298. VOID
  299. ndisuioShutdownBinding(
  300. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  301. );
  302. VOID
  303. ndisuioFreeBindResources(
  304. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  305. );
  306. VOID
  307. ndisuioWaitForPendingIO(
  308. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  309. IN BOOLEAN DoCancelReads
  310. );
  311. VOID
  312. ndisuioDoProtocolUnload(
  313. VOID
  314. );
  315. NDIS_STATUS
  316. ndisuioDoRequest(
  317. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  318. IN NDIS_REQUEST_TYPE RequestType,
  319. IN NDIS_OID Oid,
  320. IN PVOID InformationBuffer,
  321. IN UINT InformationBufferLength,
  322. OUT PUINT pBytesProcessed
  323. );
  324. NDIS_STATUS
  325. ndisuioValidateOpenAndDoRequest(
  326. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  327. IN NDIS_REQUEST_TYPE RequestType,
  328. IN NDIS_OID Oid,
  329. IN PVOID InformationBuffer,
  330. IN UINT InformationBufferLength,
  331. OUT PUINT pBytesProcessed,
  332. IN BOOLEAN bWaitForPowerOn
  333. );
  334. VOID
  335. NdisuioResetComplete(
  336. IN NDIS_HANDLE ProtocolBindingContext,
  337. IN NDIS_STATUS Status
  338. );
  339. VOID
  340. NdisuioRequestComplete(
  341. IN NDIS_HANDLE ProtocolBindingContext,
  342. IN PNDIS_REQUEST pNdisRequest,
  343. IN NDIS_STATUS Status
  344. );
  345. VOID
  346. NdisuioStatus(
  347. IN NDIS_HANDLE ProtocolBindingContext,
  348. IN NDIS_STATUS GeneralStatus,
  349. IN PVOID StatusBuffer,
  350. IN UINT StatusBufferSize
  351. );
  352. VOID
  353. NdisuioStatusComplete(
  354. IN NDIS_HANDLE ProtocolBindingContext
  355. );
  356. NDIS_STATUS
  357. ndisuioQueryBinding(
  358. IN PUCHAR pBuffer,
  359. IN ULONG InputLength,
  360. IN ULONG OutputLength,
  361. OUT PULONG pBytesReturned
  362. );
  363. PNDISUIO_OPEN_CONTEXT
  364. ndisuioLookupDevice(
  365. IN PUCHAR pBindingInfo,
  366. IN ULONG BindingInfoLength
  367. );
  368. NDIS_STATUS
  369. ndisuioQueryOidValue(
  370. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  371. OUT PVOID pDataBuffer,
  372. IN ULONG BufferLength,
  373. OUT PULONG pBytesWritten
  374. );
  375. NDIS_STATUS
  376. ndisuioSetOidValue(
  377. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  378. OUT PVOID pDataBuffer,
  379. IN ULONG BufferLength
  380. );
  381. BOOLEAN
  382. ndisuioValidOid(
  383. IN NDIS_OID Oid
  384. );
  385. NTSTATUS
  386. NdisuioRead(
  387. IN PDEVICE_OBJECT pDeviceObject,
  388. IN PIRP pIrp
  389. );
  390. VOID
  391. NdisuioCancelRead(
  392. IN PDEVICE_OBJECT pDeviceObject,
  393. IN PIRP pIrp
  394. );
  395. VOID
  396. ndisuioServiceReads(
  397. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  398. );
  399. NDIS_STATUS
  400. NdisuioReceive(
  401. IN NDIS_HANDLE ProtocolBindingContext,
  402. IN NDIS_HANDLE MacReceiveContext,
  403. IN PVOID pHeaderBuffer,
  404. IN UINT HeaderBufferSize,
  405. IN PVOID pLookaheadBuffer,
  406. IN UINT LookaheadBufferSize,
  407. IN UINT PacketSize
  408. );
  409. VOID
  410. NdisuioTransferDataComplete(
  411. IN NDIS_HANDLE ProtocolBindingContext,
  412. IN PNDIS_PACKET pNdisPacket,
  413. IN NDIS_STATUS TransferStatus,
  414. IN UINT BytesTransferred
  415. );
  416. VOID
  417. NdisuioReceiveComplete(
  418. IN NDIS_HANDLE ProtocolBindingContext
  419. );
  420. INT
  421. NdisuioReceivePacket(
  422. IN NDIS_HANDLE ProtocolBindingContext,
  423. IN PNDIS_PACKET pNdisPacket
  424. );
  425. VOID
  426. ndisuioShutdownBinding(
  427. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  428. );
  429. VOID
  430. ndisuioQueueReceivePacket(
  431. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  432. IN PNDIS_PACKET pRcvPacket
  433. );
  434. PNDIS_PACKET
  435. ndisuioAllocateReceivePacket(
  436. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  437. IN UINT DataLength,
  438. OUT PUCHAR * ppDataBuffer
  439. );
  440. VOID
  441. ndisuioFreeReceivePacket(
  442. IN PNDISUIO_OPEN_CONTEXT pOpenContext,
  443. IN PNDIS_PACKET pNdisPacket
  444. );
  445. VOID
  446. ndisuioCancelPendingReads(
  447. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  448. );
  449. VOID
  450. ndisuioFlushReceiveQueue(
  451. IN PNDISUIO_OPEN_CONTEXT pOpenContext
  452. );
  453. NTSTATUS
  454. NdisuioWrite(
  455. IN PDEVICE_OBJECT pDeviceObject,
  456. IN PIRP pIrp
  457. );
  458. VOID
  459. NdisuioCancelWrite(
  460. IN PDEVICE_OBJECT pDeviceObject,
  461. IN PIRP pIrp
  462. );
  463. VOID
  464. NdisuioSendComplete(
  465. IN NDIS_HANDLE ProtocolBindingContext,
  466. IN PNDIS_PACKET pNdisPacket,
  467. IN NDIS_STATUS Status
  468. );
  469. #endif // __NDISUIO__H