ReactOS 0.4.16-dev-311-g9382aa2
tditest.c File Reference
#include <tditest.h>
#include <pseh/pseh2.h>
Include dependency graph for tditest.c:

Go to the source code of this file.

Functions

NTSTATUS TdiCall (PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
 
NTSTATUS TdiOpenDevice (PWSTR Protocol, ULONG EaLength, PFILE_FULL_EA_INFORMATION EaInfo, PHANDLE Handle, PFILE_OBJECT *Object)
 
NTSTATUS TdiCloseDevice (HANDLE Handle, PFILE_OBJECT FileObject)
 
NTSTATUS TdiOpenTransport (PWSTR Protocol, USHORT Port, PHANDLE Transport, PFILE_OBJECT *TransportObject)
 
NTSTATUS TdiQueryDeviceControl (PFILE_OBJECT FileObject, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, PULONG Return)
 
NTSTATUS TdiQueryInformationEx (PFILE_OBJECT FileObject, ULONG Entity, ULONG Instance, ULONG Class, ULONG Type, ULONG Id, PVOID OutputBuffer, PULONG OutputLength)
 
NTSTATUS TdiQueryAddress (PFILE_OBJECT FileObject, PULONG Address)
 
NTSTATUS TdiSendDatagram (PFILE_OBJECT TransportObject, USHORT Port, ULONG Address, PVOID Buffer, ULONG BufferSize)
 
NTSTATUS TdiReceiveDatagram (PFILE_OBJECT TransportObject, USHORT Port, PULONG Address, PUCHAR Buffer, PULONG BufferSize)
 
VOID TdiSendThread (PVOID Context)
 
VOID TdiReceiveThread (PVOID Context)
 
VOID TdiOpenThread (PVOID Context)
 
VOID TdiUnload (PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 

Variables

HANDLE TdiTransport = 0
 
PFILE_OBJECT TdiTransportObject = NULL
 
ULONG LocalAddress
 
BOOLEAN OpenError
 
KEVENT StopEvent
 
HANDLE SendThread
 
HANDLE ReceiveThread
 

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 889 of file tditest.c.

900{
904
906
907 /* Call TdiOpenThread() */
912
913 /* Create a UDP send thread that sends a dgram every 2 seconds */
915 &SendThread, /* Thread handle */
916 0, /* Desired access */
917 NULL, /* Object attributes */
918 NULL, /* Process handle */
919 NULL, /* Client id */
920 (PKSTART_ROUTINE)TdiSendThread, /* Start routine */
921 NULL); /* Start context */
922
923 if (!NT_SUCCESS(Status))
924 {
925 TDI_DbgPrint(MIN_TRACE, ("PsCreateSystemThread() failed for send thread (Status = 0x%X).\n", Status));
927 }
928
929 /* Create a UDP receive thread */
931 &ReceiveThread, /* Thread handle */
932 0, /* Desired access */
933 NULL, /* Object attributes */
934 NULL, /* Process handle */
935 NULL, /* Client id */
936 (PKSTART_ROUTINE)TdiReceiveThread, /* Start routine */
937 NULL); /* Start context */
938
939 if (!NT_SUCCESS(Status))
940 {
941 TDI_DbgPrint(MIN_TRACE, ("PsCreateSystemThread() failed for receive thread (Status = 0x%X).\n", Status));
944 }
945
946 DriverObject->DriverUnload = (PDRIVER_UNLOAD)TdiUnload;
947
948 return STATUS_SUCCESS;
949}
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Status
Definition: gdiplustypes.h:25
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ NotificationEvent
@ SynchronizationEvent
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID TdiUnload(PDRIVER_OBJECT DriverObject)
Definition: tditest.c:857
VOID TdiOpenThread(PVOID Context)
Definition: tditest.c:816
VOID TdiSendThread(PVOID Context)
Definition: tditest.c:717
HANDLE SendThread
Definition: tditest.c:29
HANDLE ReceiveThread
Definition: tditest.c:30
VOID TdiReceiveThread(PVOID Context)
Definition: tditest.c:770
KEVENT StopEvent
Definition: tditest.c:28
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200
DRIVER_UNLOAD * PDRIVER_UNLOAD
Definition: iotypes.h:2253
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:499
@ Executive
Definition: ketypes.h:415

◆ TdiCall()

NTSTATUS TdiCall ( PIRP  Irp,
PDEVICE_OBJECT  DeviceObject,
PIO_STATUS_BLOCK  IoStatusBlock,
BOOLEAN  CanCancel 
)

Definition at line 32 of file tditest.c.

49{
51 PKEVENT Events[2];
53 Events[0] = &StopEvent;
54 Events[1] = &Event;
55
57 Irp->UserEvent = &Event;
58 Irp->UserIosb = IoStatusBlock;
59
61
63 {
64 if (CanCancel)
65 {
67
68 if (KeReadStateEvent(&StopEvent) != 0)
69 {
70 if (IoCancelIrp(Irp))
71 {
72 TDI_DbgPrint(MAX_TRACE, ("Cancelled IRP.\n"));
73 }
74 else
75 {
76 TDI_DbgPrint(MIN_TRACE, ("Could not cancel IRP.\n"));
77 }
78 return STATUS_CANCELLED;
79 }
80 }
81 else
83 }
84
86}
#define MAX_TRACE
Definition: debug.h:16
HANDLE Events[3]
Definition: schedsvc.c:40
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
@ WaitAny
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
#define IoCallDriver
Definition: irp.c:1225
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by TdiQueryDeviceControl(), TdiReceiveDatagram(), and TdiSendDatagram().

◆ TdiCloseDevice()

NTSTATUS TdiCloseDevice ( HANDLE  Handle,
PFILE_OBJECT  FileObject 
)

Definition at line 158 of file tditest.c.

161{
162 if (FileObject)
164
165 if (Handle)
167
168 return STATUS_SUCCESS;
169}
ULONG Handle
Definition: gdb_input.c:15
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by TdiUnload().

◆ TdiOpenDevice()

NTSTATUS TdiOpenDevice ( PWSTR  Protocol,
ULONG  EaLength,
PFILE_FULL_EA_INFORMATION  EaInfo,
PHANDLE  Handle,
PFILE_OBJECT Object 
)

Definition at line 89 of file tditest.c.

106{
111
114 &Attr, /* Attribute buffer */
115 &Name, /* Device name */
116 OBJ_CASE_INSENSITIVE, /* Attributes */
117 NULL, /* Root directory */
118 NULL); /* Security descriptor */
119
120 Status = ZwCreateFile(
121 Handle, /* Return file handle */
122 GENERIC_READ | GENERIC_WRITE, /* Desired access */
123 &Attr, /* Object attributes */
124 &Iosb, /* IO status */
125 0, /* Initial allocation size */
126 FILE_ATTRIBUTE_NORMAL, /* File attributes */
127 FILE_SHARE_READ | FILE_SHARE_WRITE, /* Share access */
128 FILE_OPEN_IF, /* Create disposition */
129 0, /* Create options */
130 EaInfo, /* EA buffer */
131 EaLength); /* EA length */
132
133 if (NT_SUCCESS(Status))
134 {
136 *Handle, /* Handle to open file */
137 GENERIC_READ | GENERIC_WRITE, /* Access mode */
138 NULL, /* Object type */
139 KernelMode, /* Access mode */
140 (PVOID*)Object, /* Pointer to object */
141 NULL); /* Handle information */
142
143 if (!NT_SUCCESS(Status))
144 {
145 TDI_DbgPrint(MIN_TRACE, ("ObReferenceObjectByHandle() failed with status (0x%X).\n", Status));
146 ZwClose(*Handle);
147 }
148 }
149 else
150 {
151 TDI_DbgPrint(MIN_TRACE, ("ZwCreateFile() failed with status (0x%X)\n", Status));
152 }
153
154 return Status;
155}
struct NameRec_ * Name
Definition: cdprocs.h:460
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
return Iosb
Definition: create.c:4402
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:879
#define FILE_OPEN_IF
Definition: from_kernel.h:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by TdiOpenTransport().

◆ TdiOpenThread()

VOID TdiOpenThread ( PVOID  Context)

Definition at line 816 of file tditest.c.

823{
825
826 TDI_DbgPrint(MAX_TRACE, ("Called.\n"));
827
828 OpenError = TRUE;
829
831
832 if (NT_SUCCESS(Status))
833 {
835
836 if (NT_SUCCESS(Status))
837 {
839 DbgPrint("Using local IP address 0x%X\n", LocalAddress);
840 }
841 else
842 {
843 TDI_DbgPrint(MIN_TRACE, ("Unable to determine local IP address.\n"));
844 }
845 }
846 else
847 TDI_DbgPrint(MIN_TRACE, ("Cannot open transport (Status = 0x%X).\n", Status));
848
849 TDI_DbgPrint(MAX_TRACE, ("Setting close event.\n"));
850
852
853 TDI_DbgPrint(MIN_TRACE, ("Leaving.\n"));
854}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DbgPrint
Definition: hal.h:12
NTSTATUS TdiOpenTransport(PWSTR Protocol, USHORT Port, PHANDLE Transport, PFILE_OBJECT *TransportObject)
Definition: tditest.c:172
BOOLEAN OpenError
Definition: tditest.c:27
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
HANDLE TdiTransport
Definition: tditest.c:24
NTSTATUS TdiQueryAddress(PFILE_OBJECT FileObject, PULONG Address)
Definition: tditest.c:319
#define UDP_DEVICE_NAME
Definition: tditest.h:17
#define TEST_PORT
Definition: tditest.h:116
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:171

Referenced by DriverEntry().

◆ TdiOpenTransport()

NTSTATUS TdiOpenTransport ( PWSTR  Protocol,
USHORT  Port,
PHANDLE  Transport,
PFILE_OBJECT TransportObject 
)

Definition at line 172 of file tditest.c.

187{
192
193 /* EaName must be 0-termed, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
196
197 if (!EaInfo)
198 {
199 TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
201 }
202
203 RtlZeroMemory(EaInfo, EaLength);
204
206
207 /* don't copy the 0; we have already zeroed it */
209
210 EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
211 Address = (PTA_IP_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); // 0-term
212 Address->TAAddressCount = 1;
213 Address->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
214 Address->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
215 Address->Address[0].Address[0].sin_port = WH2N(Port);
216 Address->Address[0].Address[0].in_addr = 0;
217
218 Status = TdiOpenDevice(Protocol, EaLength, EaInfo, Transport, TransportObject);
219
220 ExFreePool(EaInfo);
221
222 return Status;
223}
#define WH2N(w)
Definition: addrconv.c:40
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
struct _FILE_FULL_EA_INFORMATION FILE_FULL_EA_INFORMATION
CPPORT Port[4]
Definition: headless.c:35
static WCHAR Address[46]
Definition: ping.c:68
struct _TA_ADDRESS_IP TA_IP_ADDRESS
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
#define TdiTransportAddress
Definition: tdi.h:370
NTSTATUS TdiOpenDevice(PWSTR Protocol, ULONG EaLength, PFILE_FULL_EA_INFORMATION EaInfo, PHANDLE Handle, PFILE_OBJECT *Object)
Definition: tditest.c:89
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59

Referenced by TdiOpenThread().

◆ TdiQueryAddress()

NTSTATUS TdiQueryAddress ( PFILE_OBJECT  FileObject,
PULONG  Address 
)

Definition at line 319 of file tditest.c.

330{
331 ULONG i;
332 TDIEntityID *Entities;
334 ULONG EntityType;
335 IPSNMP_INFO SnmpInfo;
336 PIPADDR_ENTRY IpAddress;
339
340 TDI_DbgPrint(MAX_TRACE, ("Called\n"));
341
342 BufferSize = sizeof(TDIEntityID) * 20;
344
345 if (!Entities)
346 {
347 TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
349 }
350
351 /* Query device for supported entities */
353 FileObject, /* File object */
354 GENERIC_ENTITY, /* Entity */
355 TL_INSTANCE, /* Instance */
356 INFO_CLASS_GENERIC, /* Entity class */
357 INFO_TYPE_PROVIDER, /* Entity type */
358 ENTITY_LIST_ID, /* Entity id */
359 Entities, /* Output buffer */
360 &BufferSize); /* Output buffer size */
361
362 if (!NT_SUCCESS(Status))
363 {
364 TDI_DbgPrint(MIN_TRACE, ("Unable to get list of supported entities (Status = 0x%X).\n", Status));
365 ExFreePool(Entities);
366 return Status;
367 }
368
369 /* Locate an IP entity */
371
372 TDI_DbgPrint(MAX_TRACE, ("EntityCount = %d\n", EntityCount));
373
374 for (i = 0; i < EntityCount; i++)
375 {
376 if (Entities[i].tei_entity == CL_NL_ENTITY)
377 {
378 /* Query device for entity type */
379 BufferSize = sizeof(EntityType);
381 FileObject, /* File object */
382 CL_NL_ENTITY, /* Entity */
383 Entities[i].tei_instance, /* Instance */
384 INFO_CLASS_GENERIC, /* Entity class */
385 INFO_TYPE_PROVIDER, /* Entity type */
386 ENTITY_TYPE_ID, /* Entity id */
387 &EntityType, /* Output buffer */
388 &BufferSize); /* Output buffer size */
389
390 if (!NT_SUCCESS(Status) || (EntityType != CL_NL_IP))
391 {
392 TDI_DbgPrint(MIN_TRACE, ("Unable to get entity of type IP (Status = 0x%X).\n", Status));
393 break;
394 }
395
396 /* Query device for SNMP information */
397 BufferSize = sizeof(SnmpInfo);
399 FileObject, /* File object */
400 CL_NL_ENTITY, /* Entity */
401 Entities[i].tei_instance, /* Instance */
402 INFO_CLASS_PROTOCOL, /* Entity class */
403 INFO_TYPE_PROVIDER, /* Entity type */
404 IP_MIB_STATS_ID, /* Entity id */
405 &SnmpInfo, /* Output buffer */
406 &BufferSize); /* Output buffer size */
407
408 if (!NT_SUCCESS(Status) || (SnmpInfo.NumAddr == 0))
409 {
410 TDI_DbgPrint(MIN_TRACE, ("Unable to get SNMP information or no IP addresses available (Status = 0x%X).\n", Status));
411 break;
412 }
413
414 /* Query device for all IP addresses */
415 if (SnmpInfo.NumAddr != 0)
416 {
417 BufferSize = SnmpInfo.NumAddr * sizeof(IPADDR_ENTRY);
419 if (!IpAddress)
420 {
421 TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
422 break;
423 }
424
426 FileObject, /* File object */
427 CL_NL_ENTITY, /* Entity */
428 Entities[i].tei_instance, /* Instance */
429 INFO_CLASS_PROTOCOL, /* Entity class */
430 INFO_TYPE_PROVIDER, /* Entity type */
431 IP_MIB_ADDRTABLE_ENTRY_ID, /* Entity id */
432 IpAddress, /* Output buffer */
433 &BufferSize); /* Output buffer size */
434
435 if (!NT_SUCCESS(Status))
436 {
437 TDI_DbgPrint(MIN_TRACE, ("Unable to get IP address (Status = 0x%X).\n", Status));
438 ExFreePool(IpAddress);
439 break;
440 }
441
442 if (SnmpInfo.NumAddr != 1)
443 {
444 /* Skip loopback address */
445 *Address = DN2H(((PIPADDR_ENTRY)((PUCHAR)IpAddress + sizeof(IPADDR_ENTRY)))->Addr);
446 }
447 else
448 {
449 /* Select the first address returned */
450 *Address = DN2H(IpAddress->Addr);
451 }
452 ExFreePool(IpAddress);
453
454 }
455 else
456 {
458 break;
459 }
460 }
461 }
462
463 ExFreePool(Entities);
464
465 TDI_DbgPrint(MAX_TRACE, ("Leaving\n"));
466
467 return Status;
468}
#define DN2H(dw)
Definition: addrconv.c:21
struct IPADDR_ENTRY * PIPADDR_ENTRY
#define IP_MIB_STATS_ID
Definition: afd.h:35
#define IP_MIB_ADDRTABLE_ENTRY_ID
Definition: afd.h:36
#define TL_INSTANCE
Definition: afd.h:34
#define BufferSize
Definition: mmc.h:75
ULONG EntityCount
Definition: main.c:28
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: afd.h:56
ULONG Addr
Definition: afd.h:57
ULONG NumAddr
Definition: tditest.h:88
#define CL_NL_IP
Definition: tdiinfo.h:54
#define ENTITY_LIST_ID
Definition: tdiinfo.h:38
struct _TDIEntityID TDIEntityID
#define INFO_CLASS_PROTOCOL
Definition: tdiinfo.h:65
#define ENTITY_TYPE_ID
Definition: tdiinfo.h:39
#define INFO_CLASS_GENERIC
Definition: tdiinfo.h:64
#define INFO_TYPE_PROVIDER
Definition: tdiinfo.h:69
#define GENERIC_ENTITY
Definition: tdiinfo.h:37
#define CL_NL_ENTITY
Definition: tdiinfo.h:42
NTSTATUS TdiQueryInformationEx(PFILE_OBJECT FileObject, ULONG Entity, ULONG Instance, ULONG Class, ULONG Type, ULONG Id, PVOID OutputBuffer, PULONG OutputLength)
Definition: tditest.c:275
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by TdiOpenThread().

◆ TdiQueryDeviceControl()

NTSTATUS TdiQueryDeviceControl ( PFILE_OBJECT  FileObject,
ULONG  IoControlCode,
PVOID  InputBuffer,
ULONG  InputBufferLength,
PVOID  OutputBuffer,
ULONG  OutputBufferLength,
PULONG  Return 
)

Definition at line 226 of file tditest.c.

246{
248 PIO_STACK_LOCATION IoStack;
251 PIRP Irp;
252
256
257 if (!Irp)
258 {
259 TDI_DbgPrint(MIN_TRACE, ("IoBuildDeviceIoControlRequest() failed.\n"));
261 }
262
264 IoStack->DeviceObject = DeviceObject;
265 IoStack->FileObject = FileObject;
267
268 if (Return)
269 *Return = Iosb.Information;
270
271 return Status;
272}
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
Definition: tditest.c:32
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695

Referenced by TdiQueryInformationEx().

◆ TdiQueryInformationEx()

NTSTATUS TdiQueryInformationEx ( PFILE_OBJECT  FileObject,
ULONG  Entity,
ULONG  Instance,
ULONG  Class,
ULONG  Type,
ULONG  Id,
PVOID  OutputBuffer,
PULONG  OutputLength 
)

Definition at line 275 of file tditest.c.

298{
300
302 QueryInfo.ID.toi_entity.tei_entity = Entity;
304 QueryInfo.ID.toi_class = Class;
305 QueryInfo.ID.toi_type = Type;
306 QueryInfo.ID.toi_id = Id;
307
309 FileObject, /* Transport/connection object */
310 IOCTL_TCP_QUERY_INFORMATION_EX, /* Control code */
311 &QueryInfo, /* Input buffer */
312 sizeof(TCP_REQUEST_QUERY_INFORMATION_EX), /* Input buffer length */
313 OutputBuffer, /* Output buffer */
314 *OutputLength, /* Output buffer length */
315 OutputLength); /* Return information */
316}
DWORD Id
Type
Definition: Type.h:7
ULONG tei_entity
Definition: tdiinfo.h:31
ULONG tei_instance
Definition: tdiinfo.h:32
ULONG toi_id
Definition: tdiinfo.h:77
ULONG toi_type
Definition: tdiinfo.h:76
ULONG toi_class
Definition: tdiinfo.h:75
TDIEntityID toi_entity
Definition: tdiinfo.h:74
NTSTATUS TdiQueryDeviceControl(PFILE_OBJECT FileObject, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, PULONG Return)
Definition: tditest.c:226
#define IOCTL_TCP_QUERY_INFORMATION_EX
Definition: tditest.h:110
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481

Referenced by TdiQueryAddress().

◆ TdiReceiveDatagram()

NTSTATUS TdiReceiveDatagram ( PFILE_OBJECT  TransportObject,
USHORT  Port,
PULONG  Address,
PUCHAR  Buffer,
PULONG  BufferSize 
)

Definition at line 579 of file tditest.c.

596{
597 PTDI_CONNECTION_INFORMATION ReceiveInfo;
599 PTA_IP_ADDRESS ReturnAddress;
601 PTDI_ADDRESS_IP IpAddress;
603 PVOID MdlBuffer;
605 PIRP Irp;
606 PMDL Mdl;
607
608 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
609 if (!DeviceObject)
611
615 sizeof(TA_IP_ADDRESS));
616
617 if (!ReceiveInfo)
619
620 MdlBuffer = ExAllocatePool(PagedPool, *BufferSize);
621 if (!MdlBuffer)
623
625 sizeof(TA_IP_ADDRESS));
626
627 RtlCopyMemory(MdlBuffer, Buffer, *BufferSize);
628
629 /* Receive from any address */
630 ReceiveInfo->RemoteAddressLength = 0;
631 ReceiveInfo->RemoteAddress = NULL;
632
633 ReturnInfo = (PTDI_CONNECTION_INFORMATION) ((PUCHAR)ReceiveInfo + sizeof(TDI_CONNECTION_INFORMATION));
634 ReturnInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
635 ReturnInfo->RemoteAddress = ((PUCHAR)ReturnInfo + sizeof(TDI_CONNECTION_INFORMATION));
636
637 ReturnAddress = (PTA_IP_ADDRESS)(ReturnInfo->RemoteAddress);
638 ReturnAddress->TAAddressCount = 1;
639 ReturnAddress->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
640 ReturnAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
641
642 IpAddress = (PTDI_ADDRESS_IP)(ReturnAddress->Address[0].Address);
643 IpAddress->sin_port = WH2N(Port);
644 IpAddress->in_addr = DH2N(LocalAddress);
645
647 TDI_RECEIVE_DATAGRAM, /* Sub function */
648 DeviceObject, /* Device object */
649 TransportObject, /* File object */
650 NULL, /* Event */
651 NULL); /* Return buffer */
652
653 if (!Irp)
654 {
655 ExFreePool(MdlBuffer);
656 ExFreePool(ReceiveInfo);
658 }
659
661 MdlBuffer, /* Virtual address */
662 *BufferSize, /* Length of buffer */
663 FALSE, /* Not secondary */
664 FALSE, /* Don't charge quota */
665 NULL); /* Don't use IRP */
666
667 if (!Mdl)
668 {
669 IoFreeIrp(Irp);
670 ExFreePool(MdlBuffer);
671 ExFreePool(ReceiveInfo);
673 }
674
676 {
678 }
680 {
681 TDI_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
682 IoFreeMdl(Mdl);
683 IoFreeIrp(Irp);
684 ExFreePool(MdlBuffer);
685 ExFreePool(ReceiveInfo);
687 } _SEH2_END;
688
690 Irp, /* I/O Request Packet */
691 DeviceObject, /* Device object */
692 TransportObject, /* File object */
693 NULL, /* Completion routine */
694 NULL, /* Completion context */
695 Mdl, /* Data buffer */
696 *BufferSize, /* Size of data buffer */
697 ReceiveInfo, /* Connection information */
698 ReturnInfo, /* Connection information */
699 TDI_RECEIVE_NORMAL); /* Flags */
700
702
703 if (NT_SUCCESS(Status))
704 {
705 RtlCopyMemory(Buffer, MdlBuffer, Iosb.Information);
706 *BufferSize = Iosb.Information;
707 *Address = DN2H(IpAddress->in_addr);
708 }
709
710 ExFreePool(MdlBuffer);
711 ExFreePool(ReceiveInfo);
712
713 return Status;
714}
#define DH2N(dw)
Definition: addrconv.c:28
Definition: bufpool.h:45
#define PagedPool
Definition: env_spec_w32.h:308
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _TA_ADDRESS_IP::_AddrIp Address[1]
LONG TAAddressCount
Definition: tdi.h:523
ULONG in_addr
Definition: tdi.h:409
USHORT sin_port
Definition: tdi.h:408
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
#define TDI_RECEIVE_NORMAL
Definition: tdi.h:122
struct _TDI_ADDRESS_IP TDI_ADDRESS_IP
struct _TDI_CONNECTION_INFORMATION TDI_CONNECTION_INFORMATION
#define TDI_RECEIVE_DATAGRAM
Definition: tdikrnl.h:56
#define TdiBuildInternalDeviceControlIrp(IrpSubFunction, DeviceObject, FileObject, Event, IoStatusBlock)
Definition: tdikrnl.h:573
#define TdiBuildReceiveDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)
Definition: tdikrnl.h:699
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
@ IoModifyAccess
Definition: ketypes.h:865

Referenced by TdiReceiveThread().

◆ TdiReceiveThread()

VOID TdiReceiveThread ( PVOID  Context)

Definition at line 770 of file tditest.c.

779{
781 UCHAR Data[40];
782 ULONG Size;
784
785 if (!OpenError)
786 {
787 while (NT_SUCCESS(Status))
788 {
789 Size = sizeof(Data);
791
793
794 if (NT_SUCCESS(Status))
795 {
796 DbgPrint("Received data - '%s'\n", Data);
797 }
798 else
800 {
801 TDI_DbgPrint(MIN_TRACE, ("Receive error (Status = 0x%X).\n", Status));
802 }
803 else
804 {
805 TDI_DbgPrint(MAX_TRACE, ("IRP was cancelled.\n"));
806 }
807 }
808 }
809
810 TDI_DbgPrint(MAX_TRACE, ("Terminating receive thread...\n"));
811
813}
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1145
NTSTATUS TdiReceiveDatagram(PFILE_OBJECT TransportObject, USHORT Port, PULONG Address, PUCHAR Buffer, PULONG BufferSize)
Definition: tditest.c:579
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DriverEntry().

◆ TdiSendDatagram()

NTSTATUS TdiSendDatagram ( PFILE_OBJECT  TransportObject,
USHORT  Port,
ULONG  Address,
PVOID  Buffer,
ULONG  BufferSize 
)

Definition at line 471 of file tditest.c.

488{
489 PIRP Irp;
490 PMDL Mdl;
492 PTDI_CONNECTION_INFORMATION ConnectInfo;
494 PTDI_ADDRESS_IP IpAddress;
497
498 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
499 ConnectInfo = (PTDI_CONNECTION_INFORMATION)
502 sizeof(TA_IP_ADDRESS));
503
504 if (!ConnectInfo)
506
507 RtlZeroMemory(ConnectInfo, sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
508
509 ConnectInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
510 ConnectInfo->RemoteAddress = ((PUCHAR)ConnectInfo + sizeof(TDI_CONNECTION_INFORMATION));
511
512 TA = (PTA_IP_ADDRESS)(ConnectInfo->RemoteAddress);
513 TA->TAAddressCount = 1;
514 TA->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
515 TA->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
516 IpAddress = (PTDI_ADDRESS_IP)(TA->Address[0].Address);
517 IpAddress->sin_port = WH2N(Port);
518 IpAddress->in_addr = DH2N(Address);
520 TDI_SEND_DATAGRAM, /* Sub function */
521 DeviceObject, /* Device object */
522 TransportObject, /* File object */
523 NULL, /* Event */
524 NULL); /* Return buffer */
525
526 if (!Irp)
527 {
528 TDI_DbgPrint(MIN_TRACE, ("TdiBuildInternalDeviceControlIrp() failed.\n"));
529 ExFreePool(ConnectInfo);
531 }
532
534 Buffer, /* Virtual address of buffer */
535 BufferSize, /* Length of buffer */
536 FALSE, /* Not secondary */
537 FALSE, /* Don't charge quota */
538 NULL); /* Don't use IRP */
539
540 if (!Mdl)
541 {
542 TDI_DbgPrint(MIN_TRACE, ("IoAllocateMdl() failed.\n"));
543 IoFreeIrp(Irp);
544 ExFreePool(ConnectInfo);
546 }
547
549 {
551 }
553 {
554 TDI_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
555 IoFreeMdl(Mdl);
556 IoFreeIrp(Irp);
557 ExFreePool(ConnectInfo);
559 } _SEH2_END;
560
562 Irp, /* I/O Request Packet */
563 DeviceObject, /* Device object */
564 TransportObject, /* File object */
565 NULL, /* Completion routine */
566 NULL, /* Completion context */
567 Mdl, /* Descriptor for data buffer */
568 BufferSize, /* Size of data to send */
569 ConnectInfo); /* Connection information */
570
572
573 ExFreePool(ConnectInfo);
574
575 return Status;
576}
#define TDI_SEND_DATAGRAM
Definition: tdikrnl.h:55
#define TdiBuildSendDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)
Definition: tdikrnl.h:761

Referenced by TdiSendThread().

◆ TdiSendThread()

VOID TdiSendThread ( PVOID  Context)

Definition at line 717 of file tditest.c.

726{
728 PKEVENT Events[2];
731 UCHAR Data[40] = "Testing one, two, three, ...";
732
733 if (!OpenError)
734 {
735 Timeout.QuadPart = 10000000L; /* Second factor */
736 Timeout.QuadPart *= 2; /* Number of seconds */
737 Timeout.QuadPart = -(Timeout.QuadPart); /* Relative time */
738
740
741 Events[0] = &StopEvent;
742 Events[1] = &Event;
743
744 while (NT_SUCCESS(Status))
745 {
746 /* Wait until timeout or stop flag is set */
748
749 if (KeReadStateEvent(&StopEvent) != 0)
750 {
751 TDI_DbgPrint(MAX_TRACE, ("Received terminate signal...\n"));
752 break;
753 }
754
755 DbgPrint("Sending data - '%s'\n", Data);
756
758
759 if (!NT_SUCCESS(Status))
760 DbgPrint("Failed sending data (Status = 0x%X)\n", Status);
761 }
762 }
763
764 TDI_DbgPrint(MAX_TRACE, ("Terminating send thread...\n"));
765
767}
static ULONG Timeout
Definition: ping.c:61
NTSTATUS TdiSendDatagram(PFILE_OBJECT TransportObject, USHORT Port, ULONG Address, PVOID Buffer, ULONG BufferSize)
Definition: tditest.c:471

Referenced by DriverEntry().

◆ TdiUnload()

VOID TdiUnload ( PDRIVER_OBJECT  DriverObject)

Definition at line 857 of file tditest.c.

864{
865 PVOID ReceiveThreadObject = 0;
866 PVOID SendThreadObject = 0;
867
868 TDI_DbgPrint(MAX_TRACE, ("Setting stop flag\n"));
869
870 /* Get pointers to the thread objects */
873
875
876 /* Wait for send thread to stop */
878
879 /* Wait for receive thread to stop */
880 KeWaitForSingleObject(ReceiveThreadObject, Executive, KernelMode, FALSE, NULL);
881
882 /* Close device */
884}
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
NTSTATUS TdiCloseDevice(HANDLE Handle, PFILE_OBJECT FileObject)
Definition: tditest.c:158

Referenced by DriverEntry().

Variable Documentation

◆ LocalAddress

Definition at line 26 of file tditest.c.

◆ OpenError

BOOLEAN OpenError

Definition at line 27 of file tditest.c.

Referenced by TdiOpenThread(), TdiReceiveThread(), and TdiSendThread().

◆ ReceiveThread

HANDLE ReceiveThread

Definition at line 30 of file tditest.c.

Referenced by DriverEntry(), and TdiUnload().

◆ SendThread

HANDLE SendThread

Definition at line 29 of file tditest.c.

Referenced by DriverEntry(), and TdiUnload().

◆ StopEvent

KEVENT StopEvent

Definition at line 28 of file tditest.c.

Referenced by DriverEntry(), TdiCall(), TdiSendThread(), and TdiUnload().

◆ TdiTransport

HANDLE TdiTransport = 0

Definition at line 24 of file tditest.c.

Referenced by TdiOpenThread(), and TdiUnload().

◆ TdiTransportObject

PFILE_OBJECT TdiTransportObject = NULL

Definition at line 25 of file tditest.c.

Referenced by TdiOpenThread(), TdiReceiveThread(), TdiSendThread(), and TdiUnload().