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.

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