ReactOS  0.4.14-dev-323-g6fe6a88
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 {
901  KEVENT Event;
903  WORK_QUEUE_ITEM WorkItem;
904 
906 
907  /* Call TdiOpenThread() */
910  ExQueueWorkItem(&WorkItem, DelayedWorkQueue);
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 
947 
948  return STATUS_SUCCESS;
949 }
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID TdiReceiveThread(PVOID Context)
Definition: tditest.c:770
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
DRIVER_UNLOAD * PDRIVER_UNLOAD
Definition: iotypes.h:2145
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:487
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID TdiUnload(PDRIVER_OBJECT DriverObject)
Definition: tditest.c:857
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID TdiOpenThread(PVOID Context)
Definition: tditest.c:816
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
Status
Definition: gdiplustypes.h:24
HANDLE ReceiveThread
Definition: tditest.c:30
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
HANDLE SendThread
Definition: tditest.c:29
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 MIN_TRACE
Definition: debug.h:14
VOID TdiSendThread(PVOID Context)
Definition: tditest.c:717
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2938
KEVENT StopEvent
Definition: tditest.c:28
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200

◆ TdiCall()

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

Definition at line 32 of file tditest.c.

49 {
50  KEVENT Event;
51  PKEVENT Events[2];
53  Events[0] = &StopEvent;
54  Events[1] = &Event;
55 
57  Irp->UserEvent = &Event;
58  Irp->UserIosb = IoStatusBlock;
59 
61 
62  if (Status == STATUS_PENDING)
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 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
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
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
HANDLE Events[2]
Definition: schedsvc.c:40
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
#define MIN_TRACE
Definition: debug.h:14
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2938
KEVENT StopEvent
Definition: tditest.c:28

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)
166  ZwClose(Handle);
167 
168  return STATUS_SUCCESS;
169 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ HANDLE Handle
Definition: extypes.h:390
return STATUS_SUCCESS
Definition: btrfs.c:2938

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 {
107  OBJECT_ATTRIBUTES Attr;
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 }
#define FILE_OPEN_IF
Definition: from_kernel.h:56
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
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:496
#define GENERIC_WRITE
Definition: nt_native.h:90
struct NameRec_ * Name
Definition: cdprocs.h:464
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static IUnknown Object
Definition: main.c:512
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define MIN_TRACE
Definition: debug.h:14
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59

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  {
838  OpenError = FALSE;
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 TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
NTSTATUS TdiQueryAddress(PFILE_OBJECT FileObject, PULONG Address)
Definition: tditest.c:319
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define TEST_PORT
Definition: tditest.h:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN OpenError
Definition: tditest.c:27
HANDLE TdiTransport
Definition: tditest.c:24
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
Status
Definition: gdiplustypes.h:24
NTSTATUS TdiOpenTransport(PWSTR Protocol, USHORT Port, PHANDLE Transport, PFILE_OBJECT *TransportObject)
Definition: tditest.c:172
#define UDP_DEVICE_NAME
Definition: tditest.h:17
#define MAX_TRACE
Definition: debug.h:16
#define MIN_TRACE
Definition: debug.h:14
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

Referenced by DriverEntry().

◆ TdiOpenTransport()

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

Definition at line 172 of file tditest.c.

187 {
191  ULONG EaLength;
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 }
CPPORT Port[4]
Definition: headless.c:34
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
#define WH2N(w)
Definition: addrconv.c:40
static WCHAR Address[46]
Definition: ping.c:68
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
struct _TA_ADDRESS_IP TA_IP_ADDRESS
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
struct _FILE_FULL_EA_INFORMATION FILE_FULL_EA_INFORMATION
Status
Definition: gdiplustypes.h:24
#define TdiTransportAddress
Definition: tdi.h:370
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
NTSTATUS TdiOpenDevice(PWSTR Protocol, ULONG EaLength, PFILE_FULL_EA_INFORMATION EaInfo, PHANDLE Handle, PFILE_OBJECT *Object)
Definition: tditest.c:89
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

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 */
370  EntityCount = BufferSize / sizeof(TDIEntityID);
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 }
ULONG EntityCount
Definition: main.c:24
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG NumAddr
Definition: tditest.h:88
struct _TDIEntityID TDIEntityID
Definition: afd.h:56
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define ENTITY_TYPE_ID
Definition: tdiinfo.h:39
#define CL_NL_IP
Definition: tdiinfo.h:54
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
#define TL_INSTANCE
Definition: afd.h:34
static WCHAR Address[46]
Definition: ping.c:68
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct IPADDR_ENTRY * PIPADDR_ENTRY
#define IP_MIB_STATS_ID
Definition: afd.h:35
#define INFO_CLASS_GENERIC
Definition: tdiinfo.h:64
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CL_NL_ENTITY
Definition: tdiinfo.h:42
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
#define ENTITY_LIST_ID
Definition: tdiinfo.h:38
#define DN2H(dw)
Definition: addrconv.c:21
#define INFO_TYPE_PROVIDER
Definition: tdiinfo.h:69
ULONG Addr
Definition: afd.h:57
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
NTSTATUS TdiQueryInformationEx(PFILE_OBJECT FileObject, ULONG Entity, ULONG Instance, ULONG Class, ULONG Type, ULONG Id, PVOID OutputBuffer, PULONG OutputLength)
Definition: tditest.c:275
#define IP_MIB_ADDRTABLE_ENTRY_ID
Definition: afd.h:36
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define GENERIC_ENTITY
Definition: tdiinfo.h:37
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
struct IPADDR_ENTRY IPADDR_ENTRY
#define INFO_CLASS_PROTOCOL
Definition: tdiinfo.h:65

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 
263  IoStack = IoGetNextIrpStackLocation(Irp);
264  IoStack->DeviceObject = DeviceObject;
265  IoStack->FileObject = FileObject;
267 
268  if (Return)
269  *Return = Iosb.Information;
270 
271  return Status;
272 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
Definition: tditest.c:32
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
return Iosb
Definition: create.c:4426
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
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
#define MIN_TRACE
Definition: debug.h:14
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59

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 
301  RtlZeroMemory(&QueryInfo, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX));
302  QueryInfo.ID.toi_entity.tei_entity = Entity;
303  QueryInfo.ID.toi_entity.tei_instance = Instance;
304  QueryInfo.ID.toi_class = Class;
305  QueryInfo.ID.toi_type = Type;
306  QueryInfo.ID.toi_id = Id;
307 
308  return TdiQueryDeviceControl(
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 }
TDIEntityID toi_entity
Definition: tdiinfo.h:74
static const WCHAR Class[]
Definition: cfgmgr.c:39
Type
Definition: Type.h:6
ULONG toi_class
Definition: tdiinfo.h:75
#define IOCTL_TCP_QUERY_INFORMATION_EX
Definition: ticonsts.h:42
DWORD Id
ULONG toi_id
Definition: tdiinfo.h:77
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
ULONG tei_entity
Definition: tdiinfo.h:31
ULONG tei_instance
Definition: tdiinfo.h:32
IN PVOID Instance
Definition: pci.h:359
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
NTSTATUS TdiQueryDeviceControl(PFILE_OBJECT FileObject, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, PULONG Return)
Definition: tditest.c:226
ULONG toi_type
Definition: tdiinfo.h:76

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;
598  PTDI_CONNECTION_INFORMATION ReturnInfo;
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 
660  Mdl = IoAllocateMdl(
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 
675  _SEH2_TRY
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 }
LONG TAAddressCount
Definition: tdi.h:523
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
#define WH2N(w)
Definition: addrconv.c:40
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_SEH2_TRY
Definition: create.c:4250
#define TDI_RECEIVE_NORMAL
Definition: tdi.h:122
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
#define TDI_RECEIVE_DATAGRAM
Definition: tdikrnl.h:56
struct _TA_ADDRESS_IP::_AddrIp Address[1]
NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
Definition: tditest.c:32
#define TdiBuildInternalDeviceControlIrp(IrpSubFunction, DeviceObject, FileObject, Event, IoStatusBlock)
Definition: tdikrnl.h:573
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
#define BufferSize
Definition: classpnp.h:419
ULONG in_addr
Definition: tdi.h:409
struct _TA_ADDRESS_IP TA_IP_ADDRESS
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define TdiBuildReceiveDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)
Definition: tdikrnl.h:699
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
struct _TDI_CONNECTION_INFORMATION TDI_CONNECTION_INFORMATION
USHORT sin_port
Definition: tdi.h:408
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_SEH2_END
Definition: create.c:4424
struct _TDI_ADDRESS_IP TDI_ADDRESS_IP
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define DN2H(dw)
Definition: addrconv.c:21
#define DH2N(dw)
Definition: addrconv.c:28
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

Referenced by TdiReceiveThread().

◆ TdiReceiveThread()

VOID TdiReceiveThread ( PVOID  Context)

Definition at line 770 of file tditest.c.

779 {
780  ULONG Address;
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
799  if (Status != STATUS_CANCELLED)
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 }
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TdiReceiveDatagram(PFILE_OBJECT TransportObject, USHORT Port, PULONG Address, PUCHAR Buffer, PULONG BufferSize)
Definition: tditest.c:579
static WCHAR Address[46]
Definition: ping.c:68
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define TEST_PORT
Definition: tditest.h:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
BOOLEAN OpenError
Definition: tditest.c:27
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2938

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;
493  PTA_IP_ADDRESS TA;
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 
533  Mdl = IoAllocateMdl(
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 
548  _SEH2_TRY
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 }
LONG TAAddressCount
Definition: tdi.h:523
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
#define WH2N(w)
Definition: addrconv.c:40
#define TdiBuildSendDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)
Definition: tdikrnl.h:761
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
struct _TA_ADDRESS_IP::_AddrIp Address[1]
NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
Definition: tditest.c:32
#define TdiBuildInternalDeviceControlIrp(IrpSubFunction, DeviceObject, FileObject, Event, IoStatusBlock)
Definition: tdikrnl.h:573
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
return Iosb
Definition: create.c:4426
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
#define BufferSize
Definition: classpnp.h:419
ULONG in_addr
Definition: tdi.h:409
struct _TA_ADDRESS_IP TA_IP_ADDRESS
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
USHORT sin_port
Definition: tdi.h:408
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_SEH2_END
Definition: create.c:4424
struct _TDI_ADDRESS_IP TDI_ADDRESS_IP
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define DH2N(dw)
Definition: addrconv.c:28
#define TDI_SEND_DATAGRAM
Definition: tdikrnl.h:55
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by TdiSendThread().

◆ TdiSendThread()

VOID TdiSendThread ( PVOID  Context)

Definition at line 717 of file tditest.c.

726 {
727  KEVENT Event;
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 }
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define TEST_PORT
Definition: tditest.h:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS TdiSendDatagram(PFILE_OBJECT TransportObject, USHORT Port, ULONG Address, PVOID Buffer, ULONG BufferSize)
Definition: tditest.c:471
BOOLEAN OpenError
Definition: tditest.c:27
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
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
HANDLE Events[2]
Definition: schedsvc.c:40
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2938
KEVENT StopEvent
Definition: tditest.c:28
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

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 
874  KeSetEvent(&StopEvent, 0, FALSE);
875 
876  /* Wait for send thread to stop */
877  KeWaitForSingleObject(SendThreadObject, Executive, KernelMode, FALSE, NULL);
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
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
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:496
NTSTATUS TdiCloseDevice(HANDLE Handle, PFILE_OBJECT FileObject)
Definition: tditest.c:158
smooth NULL
Definition: ftsmooth.c:416
HANDLE TdiTransport
Definition: tditest.c:24
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
HANDLE ReceiveThread
Definition: tditest.c:30
#define MAX_TRACE
Definition: debug.h:16
HANDLE SendThread
Definition: tditest.c:29
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
KEVENT StopEvent
Definition: tditest.c:28

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().