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.

1391 lines
51 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. tdikrnl.h
  5. Abstract:
  6. This header file contains interface definitions for NT transport
  7. providers running in kernel mode. This interface is documented in the
  8. NT Transport Driver Interface (TDI) Specification, Version 2.
  9. Revision History:
  10. --*/
  11. #ifndef _TDI_KRNL_
  12. #define _TDI_KRNL_
  13. #include <tdi.h> // get the user mode includes
  14. #include <netpnp.h>
  15. #pragma warning(push)
  16. #pragma warning(disable:4201) // nameless struct/union
  17. //
  18. // In this TDI, a kernel mode client calls TDI using IoCallDriver with the
  19. // current Irp stack pointer set to 16 bytes of pointers to other structures.
  20. // each of the supported NtDeviceIoControlFile analogs has a somehat different
  21. // structure, laid out below.
  22. //
  23. // The IrpSP information passed by kernel mode clients looks like:
  24. //
  25. typedef struct _TDI_REQUEST_KERNEL {
  26. ULONG_PTR RequestFlags;
  27. PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
  28. PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
  29. PVOID RequestSpecific;
  30. } TDI_REQUEST_KERNEL, *PTDI_REQUEST_KERNEL;
  31. //
  32. // defined request codes for the kernel clients. We make these the same
  33. // as the IOCTL codes mostly for convenience; either can be used with
  34. // the same results.
  35. //
  36. #define TDI_ASSOCIATE_ADDRESS (0x01)
  37. #define TDI_DISASSOCIATE_ADDRESS (0x02)
  38. #define TDI_CONNECT (0x03)
  39. #define TDI_LISTEN (0x04)
  40. #define TDI_ACCEPT (0x05)
  41. #define TDI_DISCONNECT (0x06)
  42. #define TDI_SEND (0x07)
  43. #define TDI_RECEIVE (0x08)
  44. #define TDI_SEND_DATAGRAM (0x09)
  45. #define TDI_RECEIVE_DATAGRAM (0x0A)
  46. #define TDI_SET_EVENT_HANDLER (0x0B)
  47. #define TDI_QUERY_INFORMATION (0x0C)
  48. #define TDI_SET_INFORMATION (0x0D)
  49. #define TDI_ACTION (0x0E)
  50. #define TDI_DIRECT_SEND (0x27)
  51. #define TDI_DIRECT_SEND_DATAGRAM (0x29)
  52. //
  53. // TdiOpenAddress (Not Used)
  54. // TdiCloseAddress (Not Used)
  55. // TdiOpenConnection (Not Used)
  56. // TdiCloseConnection (Not Used)
  57. //
  58. //
  59. // some useful constants for comparison when determining the file type;
  60. // not required.
  61. //
  62. #define TDI_TRANSPORT_ADDRESS_FILE 1
  63. #define TDI_CONNECTION_FILE 2
  64. #define TDI_CONTROL_CHANNEL_FILE 3
  65. //
  66. // Internal TDI IOCTLS
  67. //
  68. #define IOCTL_TDI_QUERY_DIRECT_SEND_HANDLER _TDI_CONTROL_CODE( 0x80, METHOD_NEITHER )
  69. #define IOCTL_TDI_QUERY_DIRECT_SENDDG_HANDLER _TDI_CONTROL_CODE( 0x81, METHOD_NEITHER )
  70. //
  71. // TdiAssociateAddress
  72. //
  73. typedef struct _TDI_REQUEST_KERNEL_ASSOCIATE {
  74. HANDLE AddressHandle;
  75. } TDI_REQUEST_KERNEL_ASSOCIATE, *PTDI_REQUEST_KERNEL_ASSOCIATE;
  76. //
  77. // TdiDisassociateAddress -- None supplied
  78. //
  79. typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISASSOCIATE,
  80. *PTDI_REQUEST_KERNEL_DISASSOCIATE;
  81. //
  82. // TdiConnect uses the structure given above (TDI_REQUEST_KERNEL); it's
  83. // defined again below for convenience
  84. //
  85. typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_CONNECT,
  86. *PTDI_REQUEST_KERNEL_CONNECT;
  87. //
  88. // TdiDisconnect uses the structure given above (TDI_REQUEST_KERNEL); it's
  89. // defined again below for convenience
  90. //
  91. typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_DISCONNECT,
  92. *PTDI_REQUEST_KERNEL_DISCONNECT;
  93. //
  94. // TdiListen uses the structure given above (TDI_REQUEST_KERNEL); it's
  95. // defined again below for convenience
  96. //
  97. typedef TDI_REQUEST_KERNEL TDI_REQUEST_KERNEL_LISTEN,
  98. *PTDI_REQUEST_KERNEL_LISTEN;
  99. //
  100. // TdiAccept
  101. //
  102. typedef struct _TDI_REQUEST_KERNEL_ACCEPT {
  103. PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
  104. PTDI_CONNECTION_INFORMATION ReturnConnectionInformation;
  105. } TDI_REQUEST_KERNEL_ACCEPT, *PTDI_REQUEST_KERNEL_ACCEPT;
  106. //
  107. // TdiSend
  108. //
  109. typedef struct _TDI_REQUEST_KERNEL_SEND {
  110. ULONG SendLength;
  111. ULONG SendFlags;
  112. } TDI_REQUEST_KERNEL_SEND, *PTDI_REQUEST_KERNEL_SEND;
  113. //
  114. // TdiReceive
  115. //
  116. typedef struct _TDI_REQUEST_KERNEL_RECEIVE {
  117. ULONG ReceiveLength;
  118. ULONG ReceiveFlags;
  119. } TDI_REQUEST_KERNEL_RECEIVE, *PTDI_REQUEST_KERNEL_RECEIVE;
  120. //
  121. // TdiSendDatagram
  122. //
  123. typedef struct _TDI_REQUEST_KERNEL_SENDDG {
  124. ULONG SendLength;
  125. PTDI_CONNECTION_INFORMATION SendDatagramInformation;
  126. } TDI_REQUEST_KERNEL_SENDDG, *PTDI_REQUEST_KERNEL_SENDDG;
  127. //
  128. // TdiReceiveDatagram
  129. //
  130. typedef struct _TDI_REQUEST_KERNEL_RECEIVEDG {
  131. ULONG ReceiveLength;
  132. PTDI_CONNECTION_INFORMATION ReceiveDatagramInformation;
  133. PTDI_CONNECTION_INFORMATION ReturnDatagramInformation;
  134. ULONG ReceiveFlags;
  135. } TDI_REQUEST_KERNEL_RECEIVEDG, *PTDI_REQUEST_KERNEL_RECEIVEDG;
  136. //
  137. // TdiSetEventHandler
  138. //
  139. typedef struct _TDI_REQUEST_KERNEL_SET_EVENT {
  140. LONG EventType;
  141. PVOID EventHandler;
  142. PVOID EventContext;
  143. } TDI_REQUEST_KERNEL_SET_EVENT, *PTDI_REQUEST_KERNEL_SET_EVENT;
  144. //
  145. // TdiQueryInformation
  146. //
  147. typedef struct _TDI_REQUEST_KERNEL_QUERY_INFO {
  148. LONG QueryType;
  149. PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
  150. } TDI_REQUEST_KERNEL_QUERY_INFORMATION, *PTDI_REQUEST_KERNEL_QUERY_INFORMATION;
  151. //
  152. // TdiSetInformation
  153. //
  154. typedef struct _TDI_REQUEST_KERNEL_SET_INFO {
  155. LONG SetType;
  156. PTDI_CONNECTION_INFORMATION RequestConnectionInformation;
  157. } TDI_REQUEST_KERNEL_SET_INFORMATION, *PTDI_REQUEST_KERNEL_SET_INFORMATION;
  158. //
  159. // Event types that are known
  160. //
  161. #define TDI_EVENT_CONNECT ((USHORT)0) // TDI_IND_CONNECT event handler.
  162. #define TDI_EVENT_DISCONNECT ((USHORT)1) // TDI_IND_DISCONNECT event handler.
  163. #define TDI_EVENT_ERROR ((USHORT)2) // TDI_IND_ERROR event handler.
  164. #define TDI_EVENT_RECEIVE ((USHORT)3) // TDI_IND_RECEIVE event handler.
  165. #define TDI_EVENT_RECEIVE_DATAGRAM ((USHORT)4) // TDI_IND_RECEIVE_DATAGRAM event handler.
  166. #define TDI_EVENT_RECEIVE_EXPEDITED ((USHORT)5) // TDI_IND_RECEIVE_EXPEDITED event handler.
  167. #define TDI_EVENT_SEND_POSSIBLE ((USHORT)6) // TDI_IND_SEND_POSSIBLE event handler
  168. #define TDI_EVENT_CHAINED_RECEIVE ((USHORT)7) // TDI_IND_CHAINED_RECEIVE event handler.
  169. #define TDI_EVENT_CHAINED_RECEIVE_DATAGRAM ((USHORT)8) // TDI_IND_CHAINED_RECEIVE_DATAGRAM event handler.
  170. #define TDI_EVENT_CHAINED_RECEIVE_EXPEDITED ((USHORT)9) // TDI_IND_CHAINED_RECEIVE_EXPEDITED event handler.
  171. #define TDI_EVENT_ERROR_EX ((USHORT)10) // TDI_IND_UNREACH_ERROR event handler.
  172. //
  173. // indicate connection event prototype. This is invoked when a request for
  174. // connection has been received by the provider and the user wishes to either
  175. // accept or reject that request.
  176. //
  177. typedef
  178. NTSTATUS
  179. (*PTDI_IND_CONNECT)(
  180. IN PVOID TdiEventContext,
  181. IN LONG RemoteAddressLength,
  182. IN PVOID RemoteAddress,
  183. IN LONG UserDataLength,
  184. IN PVOID UserData,
  185. IN LONG OptionsLength,
  186. IN PVOID Options,
  187. OUT CONNECTION_CONTEXT *ConnectionContext,
  188. OUT PIRP *AcceptIrp
  189. );
  190. NTSTATUS
  191. TdiDefaultConnectHandler (
  192. IN PVOID TdiEventContext,
  193. IN LONG RemoteAddressLength,
  194. IN PVOID RemoteAddress,
  195. IN LONG UserDataLength,
  196. IN PVOID UserData,
  197. IN LONG OptionsLength,
  198. IN PVOID Options,
  199. OUT CONNECTION_CONTEXT *ConnectionContext,
  200. OUT PIRP *AcceptIrp
  201. );
  202. //
  203. // Disconnection indication prototype. This is invoked when a connection is
  204. // being disconnected for a reason other than the user requesting it. Note that
  205. // this is a change from TDI V1, which indicated only when the remote caused
  206. // a disconnection. Any non-directed disconnection will cause this indication.
  207. //
  208. typedef
  209. NTSTATUS
  210. (*PTDI_IND_DISCONNECT)(
  211. IN PVOID TdiEventContext,
  212. IN CONNECTION_CONTEXT ConnectionContext,
  213. IN LONG DisconnectDataLength,
  214. IN PVOID DisconnectData,
  215. IN LONG DisconnectInformationLength,
  216. IN PVOID DisconnectInformation,
  217. IN ULONG DisconnectFlags
  218. );
  219. NTSTATUS
  220. TdiDefaultDisconnectHandler (
  221. IN PVOID TdiEventContext,
  222. IN CONNECTION_CONTEXT ConnectionContext,
  223. IN LONG DisconnectDataLength,
  224. IN PVOID DisconnectData,
  225. IN LONG DisconnectInformationLength,
  226. IN PVOID DisconnectInformation,
  227. IN ULONG DisconnectFlags
  228. );
  229. //
  230. // A protocol error has occurred when this indication happens. This indication
  231. // occurs only for errors of the worst type; the address this indication is
  232. // delivered to is no longer usable for protocol-related operations, and
  233. // should not be used for operations henceforth. All connections associated
  234. // it are invalid.
  235. // For NetBIOS-type providers, this indication is also delivered when a name
  236. // in conflict or duplicate name occurs.
  237. //
  238. typedef
  239. NTSTATUS
  240. (*PTDI_IND_ERROR)(
  241. IN PVOID TdiEventContext, // the endpoint's file object.
  242. IN NTSTATUS Status // status code indicating error type.
  243. );
  244. typedef
  245. NTSTATUS
  246. (*PTDI_IND_ERROR_EX)(
  247. IN PVOID TdiEventContext, // the endpoint's file object.
  248. IN NTSTATUS Status, // status code indicating error type.
  249. IN PVOID Buffer
  250. );
  251. NTSTATUS
  252. TdiDefaultErrorHandler (
  253. IN PVOID TdiEventContext, // the endpoint's file object.
  254. IN NTSTATUS Status // status code indicating error type.
  255. );
  256. //
  257. // TDI_IND_RECEIVE indication handler definition. This client routine is
  258. // called by the transport provider when a connection-oriented TSDU is received
  259. // that should be presented to the client.
  260. //
  261. typedef
  262. NTSTATUS
  263. (*PTDI_IND_RECEIVE)(
  264. IN PVOID TdiEventContext,
  265. IN CONNECTION_CONTEXT ConnectionContext,
  266. IN ULONG ReceiveFlags,
  267. IN ULONG BytesIndicated,
  268. IN ULONG BytesAvailable,
  269. OUT ULONG *BytesTaken,
  270. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  271. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  272. );
  273. NTSTATUS
  274. TdiDefaultReceiveHandler (
  275. IN PVOID TdiEventContext,
  276. IN CONNECTION_CONTEXT ConnectionContext,
  277. IN ULONG ReceiveFlags,
  278. IN ULONG BytesIndicated,
  279. IN ULONG BytesAvailable,
  280. OUT ULONG *BytesTaken,
  281. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  282. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  283. );
  284. //
  285. // TDI_IND_RECEIVE_DATAGRAM indication handler definition. This client routine
  286. // is called by the transport provider when a connectionless TSDU is received
  287. // that should be presented to the client.
  288. //
  289. typedef
  290. NTSTATUS
  291. (*PTDI_IND_RECEIVE_DATAGRAM)(
  292. IN PVOID TdiEventContext, // the event context
  293. IN LONG SourceAddressLength, // length of the originator of the datagram
  294. IN PVOID SourceAddress, // string describing the originator of the datagram
  295. IN LONG OptionsLength, // options for the receive
  296. IN PVOID Options, //
  297. IN ULONG ReceiveDatagramFlags, //
  298. IN ULONG BytesIndicated, // number of bytes this indication
  299. IN ULONG BytesAvailable, // number of bytes in complete Tsdu
  300. OUT ULONG *BytesTaken, // number of bytes used
  301. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  302. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  303. );
  304. NTSTATUS
  305. TdiDefaultRcvDatagramHandler (
  306. IN PVOID TdiEventContext, // the event context
  307. IN LONG SourceAddressLength, // length of the originator of the datagram
  308. IN PVOID SourceAddress, // string describing the originator of the datagram
  309. IN LONG OptionsLength, // options for the receive
  310. IN PVOID Options, //
  311. IN ULONG ReceiveDatagramFlags, //
  312. IN ULONG BytesIndicated, // number of bytes this indication
  313. IN ULONG BytesAvailable, // number of bytes in complete Tsdu
  314. OUT ULONG *BytesTaken, // number of bytes used
  315. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  316. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  317. );
  318. //
  319. // This indication is delivered if expedited data is received on the connection.
  320. // This will only occur in providers that support expedited data.
  321. //
  322. typedef
  323. NTSTATUS
  324. (*PTDI_IND_RECEIVE_EXPEDITED)(
  325. IN PVOID TdiEventContext,
  326. IN CONNECTION_CONTEXT ConnectionContext,
  327. IN ULONG ReceiveFlags, //
  328. IN ULONG BytesIndicated, // number of bytes in this indication
  329. IN ULONG BytesAvailable, // number of bytes in complete Tsdu
  330. OUT ULONG *BytesTaken, // number of bytes used by indication routine
  331. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  332. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  333. );
  334. NTSTATUS
  335. TdiDefaultRcvExpeditedHandler (
  336. IN PVOID TdiEventContext,
  337. IN CONNECTION_CONTEXT ConnectionContext,
  338. IN ULONG ReceiveFlags, //
  339. IN ULONG BytesIndicated, // number of bytes in this indication
  340. IN ULONG BytesAvailable, // number of bytes in complete Tsdu
  341. OUT ULONG *BytesTaken, // number of bytes used by indication routine
  342. IN PVOID Tsdu, // pointer describing this TSDU, typically a lump of bytes
  343. OUT PIRP *IoRequestPacket // TdiReceive IRP if MORE_PROCESSING_REQUIRED.
  344. );
  345. //
  346. // TDI_IND_CHAINED_RECEIVE indication handler definition. This client routine
  347. // is called by the transport provider when a connection-oriented TSDU is
  348. // received that should be presented to the client. The TSDU is stored in an
  349. // MDL chain. The client may take ownership of the TSDU and return it at a
  350. // later time.
  351. //
  352. typedef
  353. NTSTATUS
  354. (*PTDI_IND_CHAINED_RECEIVE)(
  355. IN PVOID TdiEventContext,
  356. IN CONNECTION_CONTEXT ConnectionContext,
  357. IN ULONG ReceiveFlags,
  358. IN ULONG ReceiveLength, // length of client data in TSDU
  359. IN ULONG StartingOffset, // offset of start of client data in TSDU
  360. IN PMDL Tsdu, // TSDU data chain
  361. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  362. );
  363. NTSTATUS
  364. TdiDefaultChainedReceiveHandler (
  365. IN PVOID TdiEventContext,
  366. IN CONNECTION_CONTEXT ConnectionContext,
  367. IN ULONG ReceiveFlags,
  368. IN ULONG ReceiveLength, // length of client data in TSDU
  369. IN ULONG StartingOffset, // offset of start of client data in TSDU
  370. IN PMDL Tsdu, // TSDU data chain
  371. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  372. );
  373. //
  374. // TDI_IND_CHAINED_RECEIVE_DATAGRAM indication handler definition. This client
  375. // routine is called by the transport provider when a connectionless TSDU is
  376. // received that should be presented to the client. The TSDU is stored in an
  377. // MDL chain. The client may take ownership of the TSDU and return it at a
  378. // later time.
  379. //
  380. typedef
  381. NTSTATUS
  382. (*PTDI_IND_CHAINED_RECEIVE_DATAGRAM)(
  383. IN PVOID TdiEventContext, // the event context
  384. IN LONG SourceAddressLength, // length of the originator of the datagram
  385. IN PVOID SourceAddress, // string describing the originator of the datagram
  386. IN LONG OptionsLength, // options for the receive
  387. IN PVOID Options, //
  388. IN ULONG ReceiveDatagramFlags, //
  389. IN ULONG ReceiveDatagramLength, // length of client data in TSDU
  390. IN ULONG StartingOffset, // offset of start of client data in TSDU
  391. IN PMDL Tsdu, // TSDU data chain
  392. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  393. );
  394. NTSTATUS
  395. TdiDefaultChainedRcvDatagramHandler (
  396. IN PVOID TdiEventContext, // the event context
  397. IN LONG SourceAddressLength, // length of the originator of the datagram
  398. IN PVOID SourceAddress, // string describing the originator of the datagram
  399. IN LONG OptionsLength, // options for the receive
  400. IN PVOID Options, //
  401. IN ULONG ReceiveDatagramFlags, //
  402. IN ULONG ReceiveDatagramLength, // length of client data in TSDU
  403. IN ULONG StartingOffset, // offset of start of client data in TSDU
  404. IN PMDL Tsdu, // TSDU data chain
  405. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  406. );
  407. //
  408. // This indication is delivered if expedited data is received on the connection.
  409. // This will only occur in providers that support expedited data. The TSDU is
  410. // stored in an MDL chain. The client may take ownership of the TSDU and
  411. // return it at a later time.
  412. //
  413. typedef
  414. NTSTATUS
  415. (*PTDI_IND_CHAINED_RECEIVE_EXPEDITED)(
  416. IN PVOID TdiEventContext,
  417. IN CONNECTION_CONTEXT ConnectionContext,
  418. IN ULONG ReceiveFlags,
  419. IN ULONG ReceiveLength, // length of client data in TSDU
  420. IN ULONG StartingOffset, // offset of start of client data in TSDU
  421. IN PMDL Tsdu, // TSDU data chain
  422. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  423. );
  424. NTSTATUS
  425. TdiDefaultChainedRcvExpeditedHandler (
  426. IN PVOID TdiEventContext,
  427. IN CONNECTION_CONTEXT ConnectionContext,
  428. IN ULONG ReceiveFlags,
  429. IN ULONG ReceiveLength, // length of client data in TSDU
  430. IN ULONG StartingOffset, // offset of start of client data in TSDU
  431. IN PMDL Tsdu, // TSDU data chain
  432. IN PVOID TsduDescriptor // for call to TdiReturnChainedReceives
  433. );
  434. //
  435. // This indication is delivered if there is room for a send in the buffer of
  436. // a buffering protocol.
  437. //
  438. typedef
  439. NTSTATUS
  440. (*PTDI_IND_SEND_POSSIBLE)(
  441. IN PVOID TdiEventContext,
  442. IN PVOID ConnectionContext,
  443. IN ULONG BytesAvailable);
  444. NTSTATUS
  445. TdiDefaultSendPossibleHandler (
  446. IN PVOID TdiEventContext,
  447. IN PVOID ConnectionContext,
  448. IN ULONG BytesAvailable);
  449. //
  450. // defined MACROS to allow the kernel mode client to easily build an IRP for
  451. // any function.
  452. //
  453. #define TdiBuildAssociateAddress(Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle) \
  454. { \
  455. PTDI_REQUEST_KERNEL_ASSOCIATE p; \
  456. PIO_STACK_LOCATION _IRPSP; \
  457. if ( CompRoutine != NULL) { \
  458. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  459. } else { \
  460. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  461. } \
  462. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  463. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  464. _IRPSP->MinorFunction = TDI_ASSOCIATE_ADDRESS; \
  465. _IRPSP->DeviceObject = DevObj; \
  466. _IRPSP->FileObject = FileObj; \
  467. p = (PTDI_REQUEST_KERNEL_ASSOCIATE)&_IRPSP->Parameters; \
  468. p->AddressHandle = (HANDLE)(AddrHandle); \
  469. }
  470. #define TdiBuildDisassociateAddress(Irp, DevObj, FileObj, CompRoutine, Contxt) \
  471. { \
  472. PTDI_REQUEST_KERNEL_DISASSOCIATE p; \
  473. PIO_STACK_LOCATION _IRPSP; \
  474. if ( CompRoutine != NULL) { \
  475. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  476. } else { \
  477. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  478. } \
  479. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  480. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  481. _IRPSP->MinorFunction = TDI_DISASSOCIATE_ADDRESS; \
  482. _IRPSP->DeviceObject = DevObj; \
  483. _IRPSP->FileObject = FileObj; \
  484. p = (PTDI_REQUEST_KERNEL_DISASSOCIATE)&_IRPSP->Parameters; \
  485. }
  486. #define TdiBuildConnect(Irp, DevObj, FileObj, CompRoutine, Contxt, Time, RequestConnectionInfo, ReturnConnectionInfo)\
  487. { \
  488. PTDI_REQUEST_KERNEL p; \
  489. PIO_STACK_LOCATION _IRPSP; \
  490. if ( CompRoutine != NULL) { \
  491. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  492. } else { \
  493. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  494. } \
  495. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  496. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  497. _IRPSP->MinorFunction = TDI_CONNECT; \
  498. _IRPSP->DeviceObject = DevObj; \
  499. _IRPSP->FileObject = FileObj; \
  500. p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
  501. p->RequestConnectionInformation = RequestConnectionInfo; \
  502. p->ReturnConnectionInformation = ReturnConnectionInfo; \
  503. p->RequestSpecific = (PVOID)Time; \
  504. }
  505. #define TdiBuildListen(Irp, DevObj, FileObj, CompRoutine, Contxt, Flags, RequestConnectionInfo, ReturnConnectionInfo)\
  506. { \
  507. PTDI_REQUEST_KERNEL p; \
  508. PIO_STACK_LOCATION _IRPSP; \
  509. if ( CompRoutine != NULL) { \
  510. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  511. } else { \
  512. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  513. } \
  514. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  515. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  516. _IRPSP->MinorFunction = TDI_LISTEN; \
  517. _IRPSP->DeviceObject = DevObj; \
  518. _IRPSP->FileObject = FileObj; \
  519. p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
  520. p->RequestFlags = Flags; \
  521. p->RequestConnectionInformation = RequestConnectionInfo; \
  522. p->ReturnConnectionInformation = ReturnConnectionInfo; \
  523. }
  524. #define TdiBuildAccept(Irp, DevObj, FileObj, CompRoutine, Contxt, RequestConnectionInfo, ReturnConnectionInfo)\
  525. { \
  526. PTDI_REQUEST_KERNEL_ACCEPT p; \
  527. PIO_STACK_LOCATION _IRPSP; \
  528. if ( CompRoutine != NULL) { \
  529. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  530. } else { \
  531. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  532. } \
  533. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  534. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  535. _IRPSP->MinorFunction = TDI_ACCEPT; \
  536. _IRPSP->DeviceObject = DevObj; \
  537. _IRPSP->FileObject = FileObj; \
  538. p = (PTDI_REQUEST_KERNEL_ACCEPT)&_IRPSP->Parameters; \
  539. p->RequestConnectionInformation = RequestConnectionInfo; \
  540. p->ReturnConnectionInformation = ReturnConnectionInfo; \
  541. }
  542. #define TdiBuildDisconnect(Irp, DevObj, FileObj, CompRoutine, Contxt, Time, Flags, RequestConnectionInfo, ReturnConnectionInfo)\
  543. { \
  544. PTDI_REQUEST_KERNEL p; \
  545. PIO_STACK_LOCATION _IRPSP; \
  546. if ( CompRoutine != NULL) { \
  547. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  548. } else { \
  549. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  550. } \
  551. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  552. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  553. _IRPSP->MinorFunction = TDI_DISCONNECT; \
  554. _IRPSP->DeviceObject = DevObj; \
  555. _IRPSP->FileObject = FileObj; \
  556. p = (PTDI_REQUEST_KERNEL)&_IRPSP->Parameters; \
  557. p->RequestFlags = Flags; \
  558. p->RequestConnectionInformation = RequestConnectionInfo; \
  559. p->ReturnConnectionInformation = ReturnConnectionInfo; \
  560. p->RequestSpecific = (PVOID)Time; \
  561. }
  562. #define TdiBuildReceive(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, ReceiveLen)\
  563. { \
  564. PTDI_REQUEST_KERNEL_RECEIVE p; \
  565. PIO_STACK_LOCATION _IRPSP; \
  566. if ( CompRoutine != NULL) { \
  567. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  568. } else { \
  569. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  570. } \
  571. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  572. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  573. _IRPSP->MinorFunction = TDI_RECEIVE; \
  574. _IRPSP->DeviceObject = DevObj; \
  575. _IRPSP->FileObject = FileObj; \
  576. p = (PTDI_REQUEST_KERNEL_RECEIVE)&_IRPSP->Parameters; \
  577. p->ReceiveFlags = InFlags; \
  578. p->ReceiveLength = ReceiveLen; \
  579. Irp->MdlAddress = MdlAddr; \
  580. }
  581. #define TdiBuildSend(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, SendLen)\
  582. { \
  583. PTDI_REQUEST_KERNEL_SEND p; \
  584. PIO_STACK_LOCATION _IRPSP; \
  585. if ( CompRoutine != NULL) { \
  586. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  587. } else { \
  588. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  589. } \
  590. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  591. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  592. _IRPSP->MinorFunction = TDI_SEND; \
  593. _IRPSP->DeviceObject = DevObj; \
  594. _IRPSP->FileObject = FileObj; \
  595. p = (PTDI_REQUEST_KERNEL_SEND)&_IRPSP->Parameters; \
  596. p->SendFlags = InFlags; \
  597. p->SendLength = SendLen; \
  598. Irp->MdlAddress = MdlAddr; \
  599. }
  600. #define TdiBuildSendDatagram(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)\
  601. { \
  602. PTDI_REQUEST_KERNEL_SENDDG p; \
  603. PIO_STACK_LOCATION _IRPSP; \
  604. if ( CompRoutine != NULL) { \
  605. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  606. } else { \
  607. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  608. } \
  609. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  610. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  611. _IRPSP->MinorFunction = TDI_SEND_DATAGRAM; \
  612. _IRPSP->DeviceObject = DevObj; \
  613. _IRPSP->FileObject = FileObj; \
  614. p = (PTDI_REQUEST_KERNEL_SENDDG)&_IRPSP->Parameters; \
  615. p->SendLength = SendLen; \
  616. p->SendDatagramInformation = SendDatagramInfo; \
  617. Irp->MdlAddress = MdlAddr; \
  618. }
  619. #define TdiBuildReceiveDatagram(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)\
  620. { \
  621. PTDI_REQUEST_KERNEL_RECEIVEDG p; \
  622. PIO_STACK_LOCATION _IRPSP; \
  623. if ( CompRoutine != NULL) { \
  624. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  625. } else { \
  626. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  627. } \
  628. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  629. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  630. _IRPSP->MinorFunction = TDI_RECEIVE_DATAGRAM; \
  631. _IRPSP->DeviceObject = DevObj; \
  632. _IRPSP->FileObject = FileObj; \
  633. p = (PTDI_REQUEST_KERNEL_RECEIVEDG)&_IRPSP->Parameters; \
  634. p->ReceiveLength = ReceiveLen; \
  635. p->ReceiveDatagramInformation = ReceiveDatagramInfo; \
  636. p->ReturnDatagramInformation = ReturnInfo; \
  637. p->ReceiveFlags = InFlags; \
  638. Irp->MdlAddress = MdlAddr; \
  639. }
  640. #define TdiBuildSetEventHandler(Irp, DevObj, FileObj, CompRoutine, Contxt, InEventType, InEventHandler, InEventContext) \
  641. { \
  642. PTDI_REQUEST_KERNEL_SET_EVENT p; \
  643. PIO_STACK_LOCATION _IRPSP; \
  644. if ( CompRoutine != NULL) { \
  645. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  646. } else { \
  647. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  648. } \
  649. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  650. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  651. _IRPSP->MinorFunction = TDI_SET_EVENT_HANDLER; \
  652. _IRPSP->DeviceObject = DevObj; \
  653. _IRPSP->FileObject = FileObj; \
  654. p = (PTDI_REQUEST_KERNEL_SET_EVENT)&_IRPSP->Parameters; \
  655. p->EventType = InEventType; \
  656. p->EventHandler = (PVOID)InEventHandler; \
  657. p->EventContext = (PVOID)InEventContext; \
  658. }
  659. #define TdiBuildQueryInformationEx(Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr, ConnInfo)\
  660. { \
  661. PTDI_REQUEST_KERNEL_QUERY_INFORMATION p; \
  662. PIO_STACK_LOCATION _IRPSP; \
  663. Irp->MdlAddress = MdlAddr; \
  664. if ( CompRoutine != NULL) { \
  665. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  666. } else { \
  667. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  668. } \
  669. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  670. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  671. _IRPSP->MinorFunction = TDI_QUERY_INFORMATION; \
  672. _IRPSP->DeviceObject = DevObj; \
  673. _IRPSP->FileObject = FileObj; \
  674. p = (PTDI_REQUEST_KERNEL_QUERY_INFORMATION)&_IRPSP->Parameters; \
  675. p->QueryType = (ULONG)QType; \
  676. p->RequestConnectionInformation = ConnInfo; \
  677. }
  678. #define TdiBuildQueryInformation(Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr)\
  679. TdiBuildQueryInformationEx(Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr, NULL);
  680. #define TdiBuildSetInformation(Irp, DevObj, FileObj, CompRoutine, Contxt, SType, MdlAddr)\
  681. { \
  682. PTDI_REQUEST_KERNEL_SET_INFORMATION p; \
  683. PIO_STACK_LOCATION _IRPSP; \
  684. Irp->MdlAddress = MdlAddr; \
  685. if ( CompRoutine != NULL) { \
  686. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  687. } else { \
  688. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  689. } \
  690. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  691. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  692. _IRPSP->MinorFunction = TDI_SET_INFORMATION; \
  693. _IRPSP->DeviceObject = DevObj; \
  694. _IRPSP->FileObject = FileObj; \
  695. p = (PTDI_REQUEST_KERNEL_SET_INFORMATION)&_IRPSP->Parameters; \
  696. p->SetType = (ULONG)SType; \
  697. p->RequestConnectionInformation = NULL; \
  698. }
  699. #define TdiBuildAction(Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr)\
  700. { \
  701. PIO_STACK_LOCATION _IRPSP; \
  702. if ( CompRoutine != NULL) { \
  703. IoSetCompletionRoutine( Irp, CompRoutine, Contxt, TRUE, TRUE, TRUE);\
  704. } else { \
  705. IoSetCompletionRoutine( Irp, NULL, NULL, FALSE, FALSE, FALSE); \
  706. } \
  707. _IRPSP = IoGetNextIrpStackLocation (Irp); \
  708. _IRPSP->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; \
  709. _IRPSP->MinorFunction = TDI_ACTION; \
  710. _IRPSP->DeviceObject = DevObj; \
  711. _IRPSP->FileObject = FileObj; \
  712. Irp->MdlAddress = MdlAddr; \
  713. }
  714. //
  715. // definitions for the helper routines for TDI compliant transports and clients
  716. //
  717. // Note that the IOCTL used here for the Irp Function is not real; it is used
  718. // to avoid this IO routine having to map buffers (which we don't want).
  719. //
  720. //PIRP
  721. //TdiBuildInternalDeviceControlIrp (
  722. // IN CCHAR IrpSubFunction,
  723. // IN PDEVICE_OBJECT DeviceObject,
  724. // IN PFILE_OBJECT FileObject,
  725. // IN PKEVENT Event,
  726. // IN PIO_STATUS_BLOCK IoStatusBlock
  727. // );
  728. #define TdiBuildInternalDeviceControlIrp(IrpSubFunction,DeviceObject,FileObject,Event,IoStatusBlock) \
  729. IoBuildDeviceIoControlRequest (\
  730. 0x00000003,\
  731. DeviceObject, \
  732. NULL, \
  733. 0, \
  734. NULL, \
  735. 0, \
  736. TRUE, \
  737. Event, \
  738. IoStatusBlock)
  739. //
  740. // VOID
  741. // TdiCopyLookaheadData(
  742. // IN PVOID Destination,
  743. // IN PVOID Source,
  744. // IN ULONG Length,
  745. // IN ULONG ReceiveFlags
  746. // );
  747. //
  748. #ifdef _M_IX86
  749. #define TdiCopyLookaheadData(_Destination,_Source,_Length,_ReceiveFlags) \
  750. RtlCopyMemory(_Destination,_Source,_Length)
  751. #else
  752. #define TdiCopyLookaheadData(_Destination,_Source,_Length,_ReceiveFlags) { \
  753. if ((_ReceiveFlags) & TDI_RECEIVE_COPY_LOOKAHEAD) { \
  754. RtlCopyMemory(_Destination,_Source,_Length); \
  755. } else { \
  756. PUCHAR _Src = (PUCHAR)(_Source); \
  757. PUCHAR _Dest = (PUCHAR)(_Destination); \
  758. PUCHAR _End = _Dest + (_Length); \
  759. while (_Dest < _End) { \
  760. *_Dest++ = *_Src++; \
  761. } \
  762. } \
  763. }
  764. #endif
  765. NTSTATUS
  766. TdiMapUserRequest(
  767. IN PDEVICE_OBJECT DeviceObject,
  768. IN PIRP Irp,
  769. IN PIO_STACK_LOCATION IrpSp
  770. );
  771. NTSTATUS
  772. TdiCopyBufferToMdl (
  773. IN PVOID SourceBuffer,
  774. IN ULONG SourceOffset,
  775. IN ULONG SourceBytesToCopy,
  776. IN PMDL DestinationMdlChain,
  777. IN ULONG DestinationOffset,
  778. IN PULONG BytesCopied
  779. );
  780. NTSTATUS
  781. TdiCopyMdlToBuffer(
  782. IN PMDL SourceMdlChain,
  783. IN ULONG SourceOffset,
  784. IN PVOID DestinationBuffer,
  785. IN ULONG DestinationOffset,
  786. IN ULONG DestinationBufferSize,
  787. OUT PULONG BytesCopied
  788. );
  789. NTSTATUS
  790. TdiCopyMdlChainToMdlChain(
  791. IN PMDL SourceMdlChain,
  792. IN ULONG SourceOffset,
  793. IN PMDL DestinationMdlChain,
  794. IN ULONG DestinationOffset,
  795. OUT PULONG BytesCopied
  796. );
  797. VOID
  798. TdiCopyBufferToMdlWithReservedMappingAtDpcLevel(
  799. IN PVOID SourceBuffer,
  800. IN PMDL DestinationMdl,
  801. IN ULONG DestinationOffset,
  802. IN ULONG BytesToCopy
  803. );
  804. __inline
  805. VOID
  806. TdiCopyBufferToMdlWithReservedMapping(
  807. IN PVOID SourceBuffer,
  808. IN PMDL DestinationMdl,
  809. IN ULONG DestinationOffset,
  810. IN ULONG BytesToCopy
  811. )
  812. {
  813. KIRQL OldIrql;
  814. KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
  815. TdiCopyBufferToMdlWithReservedMappingAtDpcLevel(SourceBuffer,
  816. DestinationMdl,
  817. DestinationOffset,
  818. BytesToCopy);
  819. KeLowerIrql(OldIrql);
  820. }
  821. VOID
  822. TdiBuildNetbiosAddress (
  823. IN PUCHAR NetbiosName,
  824. IN BOOLEAN IsGroupName,
  825. IN OUT PTA_NETBIOS_ADDRESS NetworkName
  826. );
  827. NTSTATUS
  828. TdiBuildNetbiosAddressEa (
  829. IN PUCHAR Buffer,
  830. IN BOOLEAN IsGroupName,
  831. IN PUCHAR NetbiosName
  832. );
  833. //++
  834. //
  835. // VOID
  836. // TdiCompleteRequest (
  837. // IN PIRP Irp,
  838. // IN NTSTATUS Status
  839. // );
  840. //
  841. // Routine Description:
  842. //
  843. // This routine is used to complete an IRP with the indicated
  844. // status.
  845. //
  846. // Arguments:
  847. //
  848. // Irp - Supplies a pointer to the Irp to complete
  849. //
  850. // Status - Supplies the completion status for the Irp
  851. //
  852. // Return Value:
  853. //
  854. // None.
  855. //
  856. //--
  857. #define TdiCompleteRequest(IRP,STATUS) { \
  858. (IRP)->IoStatus.Status = (STATUS); \
  859. IoCompleteRequest( (IRP), IO_NETWORK_INCREMENT ); \
  860. }
  861. VOID
  862. TdiReturnChainedReceives(
  863. IN PVOID *TsduDescriptors,
  864. IN ULONG NumberOfTsdus
  865. );
  866. // The type definition for a TDI Bind handler callout. This callout is
  867. // called when a new transport device arrives.
  868. typedef VOID
  869. (*TDI_BIND_HANDLER)(
  870. IN PUNICODE_STRING DeviceName
  871. );
  872. typedef VOID
  873. (*TDI_UNBIND_HANDLER)(
  874. IN PUNICODE_STRING DeviceName
  875. );
  876. // The type definition for a TDI address handler callout.
  877. // This is typedefed defined at the end (with the others)
  878. typedef VOID
  879. (*TDI_ADD_ADDRESS_HANDLER)(
  880. IN PTA_ADDRESS Address
  881. );
  882. typedef VOID
  883. (*TDI_DEL_ADDRESS_HANDLER)(
  884. IN PTA_ADDRESS Address
  885. );
  886. typedef VOID
  887. (* TDI_NET_READY_HANDLER)(
  888. IN NTSTATUS ProviderStatus
  889. );
  890. typedef VOID
  891. (* ProviderPnPPowerComplete)(
  892. IN PNET_PNP_EVENT NetEvent,
  893. IN NTSTATUS ProviderStatus
  894. );
  895. NTSTATUS
  896. TdiRegisterAddressChangeHandler(
  897. IN TDI_ADD_ADDRESS_HANDLER AddHandler,
  898. IN TDI_DEL_ADDRESS_HANDLER DeleteHandler,
  899. OUT HANDLE *BindingHandle
  900. );
  901. NTSTATUS
  902. TdiDeregisterAddressChangeHandler(
  903. IN HANDLE BindingHandle
  904. );
  905. NTSTATUS
  906. TdiRegisterNotificationHandler(
  907. IN TDI_BIND_HANDLER BindHandler,
  908. IN TDI_UNBIND_HANDLER UnbindHandler,
  909. OUT HANDLE *BindingHandle
  910. );
  911. NTSTATUS
  912. TdiDeregisterNotificationHandler(
  913. IN HANDLE BindingHandle
  914. );
  915. NTSTATUS
  916. TdiRegisterDeviceObject(
  917. IN PUNICODE_STRING DeviceName,
  918. OUT HANDLE *RegistrationHandle
  919. );
  920. NTSTATUS
  921. TdiDeregisterDeviceObject(
  922. IN HANDLE RegistrationHandle
  923. );
  924. NTSTATUS
  925. TdiDeregisterNetAddress(
  926. IN HANDLE RegistrationHandle
  927. );
  928. VOID
  929. TdiInitialize(
  930. VOID
  931. );
  932. // PnP extensions to TDI. Spec : TdiPnp.doc : MunilS
  933. typedef enum _TDI_PNP_OPCODE {
  934. TDI_PNP_OP_MIN,
  935. TDI_PNP_OP_ADD,
  936. TDI_PNP_OP_DEL,
  937. TDI_PNP_OP_UPDATE,
  938. TDI_PNP_OP_PROVIDERREADY,
  939. TDI_PNP_OP_NETREADY,
  940. TDI_PNP_OP_ADD_IGNORE_BINDING,
  941. TDI_PNP_OP_DELETE_IGNORE_BINDING,
  942. TDI_PNP_OP_MAX,
  943. } TDI_PNP_OPCODE;
  944. typedef struct _TDI_PNP_CONTEXT {
  945. USHORT ContextSize;
  946. USHORT ContextType;
  947. UCHAR POINTER_ALIGNMENT ContextData[1];
  948. } TDI_PNP_CONTEXT, *PTDI_PNP_CONTEXT;
  949. typedef VOID
  950. (*TDI_BINDING_HANDLER)(
  951. IN TDI_PNP_OPCODE PnPOpcode,
  952. IN PUNICODE_STRING DeviceName,
  953. IN PWSTR MultiSZBindList
  954. );
  955. typedef VOID
  956. (*TDI_ADD_ADDRESS_HANDLER_V2)(
  957. IN PTA_ADDRESS Address,
  958. IN PUNICODE_STRING DeviceName,
  959. IN PTDI_PNP_CONTEXT Context
  960. );
  961. typedef VOID
  962. (*TDI_DEL_ADDRESS_HANDLER_V2)(
  963. IN PTA_ADDRESS Address,
  964. IN PUNICODE_STRING DeviceName,
  965. IN PTDI_PNP_CONTEXT Context
  966. );
  967. typedef NTSTATUS
  968. (*TDI_PNP_POWER_HANDLER)(
  969. IN PUNICODE_STRING DeviceName,
  970. IN PNET_PNP_EVENT PowerEvent,
  971. IN PTDI_PNP_CONTEXT Context1,
  972. IN PTDI_PNP_CONTEXT Context2
  973. );
  974. // When the user makes changes using the NCPA, a TdiMakeNCPAChanges request
  975. // is generated through NDIS. The following structure is used to communicate
  976. // these changes.
  977. typedef struct _TDI_NCPA_BINDING_INFO {
  978. PUNICODE_STRING TdiClientName;
  979. PUNICODE_STRING TdiProviderName;
  980. PUNICODE_STRING BindList;
  981. PVOID ReconfigBuffer;
  982. unsigned int ReconfigBufferSize;
  983. TDI_PNP_OPCODE PnpOpcode;
  984. } TDI_NCPA_BINDING_INFO, *PTDI_NCPA_BINDING_INFO;
  985. //
  986. // The following structure makes it easy for consistency/integrity checking
  987. //
  988. typedef struct _TDI_VERSION_ {
  989. union {
  990. struct {
  991. UCHAR MajorTdiVersion;
  992. UCHAR MinorTdiVersion;
  993. };
  994. USHORT TdiVersion;
  995. };
  996. } TDI_VERSION, *PTDI_VERSION;
  997. #define TDI20
  998. typedef struct _TDI20_CLIENT_INTERFACE_INFO {
  999. union {
  1000. struct {
  1001. UCHAR MajorTdiVersion;
  1002. UCHAR MinorTdiVersion;
  1003. };
  1004. USHORT TdiVersion;
  1005. };
  1006. //TDI_VERSION TdiVersion;
  1007. USHORT Unused;
  1008. PUNICODE_STRING ClientName;
  1009. TDI_PNP_POWER_HANDLER PnPPowerHandler;
  1010. union {
  1011. TDI_BINDING_HANDLER BindingHandler;
  1012. struct {
  1013. //
  1014. // Putting these back in for backward compatibility.
  1015. //
  1016. TDI_BIND_HANDLER BindHandler;
  1017. TDI_UNBIND_HANDLER UnBindHandler;
  1018. };
  1019. };
  1020. union {
  1021. struct {
  1022. TDI_ADD_ADDRESS_HANDLER_V2 AddAddressHandlerV2;
  1023. TDI_DEL_ADDRESS_HANDLER_V2 DelAddressHandlerV2;
  1024. };
  1025. struct {
  1026. //
  1027. // Putting these back in for backward compatibility.
  1028. //
  1029. TDI_ADD_ADDRESS_HANDLER AddAddressHandler;
  1030. TDI_DEL_ADDRESS_HANDLER DelAddressHandler;
  1031. };
  1032. };
  1033. // TDI_NET_READY_HANDLER NetReadyHandler;
  1034. } TDI20_CLIENT_INTERFACE_INFO, *PTDI20_CLIENT_INTERFACE_INFO;
  1035. #ifdef TDI20
  1036. #define TDI_CURRENT_MAJOR_VERSION (2)
  1037. #define TDI_CURRENT_MINOR_VERSION (0)
  1038. typedef TDI20_CLIENT_INTERFACE_INFO TDI_CLIENT_INTERFACE_INFO;
  1039. #define TDI_CURRENT_VERSION ((TDI_CURRENT_MINOR_VERSION) << 8 | \
  1040. (TDI_CURRENT_MAJOR_VERSION))
  1041. #endif // TDI20
  1042. #define TDI_VERSION_ONE 0x0001
  1043. typedef TDI_CLIENT_INTERFACE_INFO *PTDI_CLIENT_INTERFACE_INFO;
  1044. NTSTATUS
  1045. TdiRegisterPnPHandlers(
  1046. IN PTDI_CLIENT_INTERFACE_INFO ClientInterfaceInfo,
  1047. IN ULONG InterfaceInfoSize,
  1048. OUT HANDLE *BindingHandle
  1049. );
  1050. NTSTATUS
  1051. TdiDeregisterPnPHandlers(
  1052. IN HANDLE BindingHandle
  1053. );
  1054. NTSTATUS
  1055. TdiPnPPowerRequest(
  1056. IN PUNICODE_STRING DeviceName,
  1057. IN PNET_PNP_EVENT PowerEvent,
  1058. IN PTDI_PNP_CONTEXT Context1,
  1059. IN PTDI_PNP_CONTEXT Context2,
  1060. IN ProviderPnPPowerComplete ProtocolCompletionHandler
  1061. );
  1062. VOID
  1063. TdiPnPPowerComplete(
  1064. IN HANDLE BindingHandle,
  1065. //IN PUNICODE_STRING DeviceName,
  1066. IN PNET_PNP_EVENT PowerEvent,
  1067. IN NTSTATUS Status
  1068. );
  1069. NTSTATUS
  1070. TdiRegisterNetAddress(
  1071. IN PTA_ADDRESS Address,
  1072. IN PUNICODE_STRING DeviceName,
  1073. IN PTDI_PNP_CONTEXT Context,
  1074. OUT HANDLE *RegistrationHandle
  1075. );
  1076. NTSTATUS
  1077. TdiMakeNCPAChanges(
  1078. IN TDI_NCPA_BINDING_INFO NcpaBindingInfo
  1079. );
  1080. //
  1081. // Enumerate all TDI addresses for a client
  1082. //
  1083. NTSTATUS
  1084. TdiEnumerateAddresses(
  1085. IN HANDLE BindingHandle
  1086. );
  1087. //
  1088. // Introducing the concept of Transport provider.
  1089. //
  1090. NTSTATUS
  1091. TdiRegisterProvider(
  1092. PUNICODE_STRING ProviderName,
  1093. HANDLE *ProviderHandle
  1094. );
  1095. NTSTATUS
  1096. TdiProviderReady(
  1097. HANDLE ProviderHandle
  1098. );
  1099. NTSTATUS
  1100. TdiDeregisterProvider(
  1101. HANDLE ProviderHandle
  1102. );
  1103. BOOLEAN
  1104. TdiMatchPdoWithChainedReceiveContext(
  1105. IN PVOID TsduDescriptor,
  1106. IN PVOID PDO
  1107. );
  1108. #define TDI_STATUS_BAD_VERSION 0xC0010004L // same as NDIS, is that OK?
  1109. #define TDI_STATUS_BAD_CHARACTERISTICS 0xC0010005L // ,,
  1110. //
  1111. // PNP context types
  1112. //
  1113. #define TDI_PNP_CONTEXT_TYPE_IF_NAME 0x1
  1114. #define TDI_PNP_CONTEXT_TYPE_IF_ADDR 0x2
  1115. #define TDI_PNP_CONTEXT_TYPE_PDO 0x3
  1116. #define TDI_PNP_CONTEXT_TYPE_FIRST_OR_LAST_IF 0x4
  1117. // The following structures and macros are for handlers that support returning
  1118. // ancillary data via a control structure
  1119. //
  1120. //
  1121. // Layout of ancillary data objects in the control buffer
  1122. //
  1123. typedef struct _TDI_CMSGHDR {
  1124. SIZE_T cmsg_len;
  1125. LONG cmsg_level;
  1126. LONG cmsg_type;
  1127. /* followed by UCHAR cmsg_data[] */
  1128. } TDI_CMSGHDR, *PTDI_CMSGHDR;
  1129. //
  1130. // Alignment macros for header and data members of
  1131. // the control buffer.
  1132. //
  1133. #define TDI_CMSGHDR_ALIGN(length) \
  1134. ( ((length) + TYPE_ALIGNMENT(TDI_CMSGHDR)-1) & \
  1135. (~(TYPE_ALIGNMENT(TDI_CMSGHDR)-1)) ) \
  1136. #define TDI_CMSGDATA_ALIGN(length) \
  1137. ( ((length) + MAX_NATURAL_ALIGNMENT-1) & \
  1138. (~(MAX_NATURAL_ALIGNMENT-1)) )
  1139. // Returns a pointer to the first byte of data (what is referred
  1140. // to as the cmsg_data member though it is not defined in
  1141. // the structure).
  1142. //
  1143. // UCHAR *
  1144. // TDI_CMSG_DATA (
  1145. // PTDI_CMSGHDR pcmsg
  1146. // );
  1147. //
  1148. #define TDI_CMSG_DATA(cmsg) \
  1149. ( (UCHAR *)(cmsg) + TDI_CMSGDATA_ALIGN(sizeof(TDI_CMSGHDR)) )
  1150. //
  1151. // Returns total size of an ancillary data object given
  1152. // the amount of data. Used to allocate the correct amount
  1153. // of space.
  1154. //
  1155. // SIZE_T
  1156. // TDI_CMSG_SPACE (
  1157. // SIZE_T length
  1158. // );
  1159. //
  1160. #define TDI_CMSG_SPACE(length) \
  1161. (TDI_CMSGDATA_ALIGN(sizeof(TDI_CMSGHDR) + TDI_CMSGHDR_ALIGN(length)))
  1162. // Returns the value to store in cmsg_len given the amount of data.
  1163. //
  1164. // SIZE_T
  1165. // TDI_CMSG_LEN (
  1166. // SIZE_T length
  1167. // );
  1168. //
  1169. #define TDI_CMSG_LEN(length) \
  1170. (TDI_CMSGDATA_ALIGN(sizeof(TDI_CMSGHDR)) + length)
  1171. // Initializes the members of a TDI_CMSGHDR structure
  1172. //
  1173. // VOID
  1174. // TDI_INIT_CMSGHDR (
  1175. // PTDI_CMSGHDR cmsg,
  1176. // INT level,
  1177. // INT type,
  1178. // SIZE_T length,
  1179. // );
  1180. //
  1181. #define TDI_INIT_CMSGHDR(cmsg, level, type, length) { \
  1182. ((TDI_CMSGHDR *) cmsg)->cmsg_level = level; \
  1183. ((TDI_CMSGHDR *) cmsg)->cmsg_type = type; \
  1184. ((TDI_CMSGHDR *) cmsg)->cmsg_len = TDI_CMSG_LEN(length); \
  1185. }
  1186. #pragma warning(pop)
  1187. #endif // _TDI_KRNL_