ReactOS  0.4.13-dev-100-gc8611ae
tdi.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite for TCPIP.sys
5  * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 #include <tdikrnl.h>
10 
11 static
13 NTAPI
16  _In_ PIRP Irp,
18 {
21 
23 
25 }
26 
27 static
28 VOID
30 {
31  struct
32  {
34  NTSTATUS CreateStatus, IrpStatus;
35  TDI_PROVIDER_INFO ExpectedInfo;
36  } TestData[] =
37  {
38  {
39  RTL_CONSTANT_STRING(L"\\Device\\Tcp"),
41  {
42  0x0100, // Version
43  0xFFFFFFFF, // MaxSendSize
44  0, // MaxConnectionUserData
45  65507, // MaxDatagramSize
60  TDI_SERVICE_NO_PUSH, // ServiceFlags
61  1, // MinimumLookaheadData
62  65535, // MaximumLookaheadData
63  0, // NumberOfResources
64  {{0}} // StartTime
65  }
66  },
67  {
68  RTL_CONSTANT_STRING(L"\\Device\\Udp"),
70  {
71  0x0100, // Version
72  0xFFFFFFFF, // MaxSendSize
73  0, // MaxConnectionUserData
74  65507, // MaxDatagramSize
89  TDI_SERVICE_NO_PUSH, // ServiceFlags
90  1, // MinimumLookaheadData
91  65535, // MaximumLookaheadData
92  0, // NumberOfResources
93  {{0}} // StartTime
94  }
95  },
96  {
97  RTL_CONSTANT_STRING(L"\\Device\\Ip"),
99  },
100  {
101  RTL_CONSTANT_STRING(L"\\Device\\RawIp"),
103  {
104  0x0100, // Version
105  0xFFFFFFFF, // MaxSendSize
106  0, // MaxConnectionUserData
107  65507, // MaxDatagramSize
122  TDI_SERVICE_NO_PUSH, // ServiceFlags
123  1, // MinimumLookaheadData
124  65535, // MaximumLookaheadData
125  0, // NumberOfResources
126  {{0}} // StartTime
127  }
128  },
129  {
130  RTL_CONSTANT_STRING(L"\\Device\\IPMULTICAST"),
132  },
133  };
134  ULONG i;
135 
136  for (i = 0; i < (sizeof(TestData) / sizeof(TestData[0])); i++)
137  {
138  IO_STATUS_BLOCK StatusBlock;
142  PIRP Irp;
143  KEVENT Event;
144  PMDL Mdl;
145  TDI_PROVIDER_INFO* ProviderInfo;
148 
149  trace("Testing device %wZ\n", &TestData[i].DeviceName);
150 
155  NULL,
156  NULL);
157 
158  Status = ZwCreateFile(
159  &FileHandle,
162  &StatusBlock,
163  NULL,
166  FILE_OPEN,
167  0,
168  NULL,
169  0);
170  ok_eq_hex(Status, TestData[i].CreateStatus);
171  if (!NT_SUCCESS(Status))
172  continue;
173 
175  FileHandle,
176  GENERIC_READ,
178  KernelMode,
179  (PVOID*)&FileObject,
180  NULL);
182  if (!NT_SUCCESS(Status))
183  return;
184 
186  ok(DeviceObject != NULL, "Device object is NULL!\n");
187  if (!DeviceObject)
188  {
190  return;
191  }
192 
193  ProviderInfo = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ProviderInfo), 'tseT');
194  ok(ProviderInfo != NULL, "Ran out of memory.\n");
195  if (!ProviderInfo)
196  {
198  return;
199  }
200 
201  Mdl = IoAllocateMdl(ProviderInfo, sizeof(*ProviderInfo), FALSE, FALSE, NULL);
202  ok(Mdl != NULL, "Could not allocate the MDL!\n");
203  if (!Mdl)
204  {
205  ExFreePoolWithTag(ProviderInfo, 'tseT');
207  return;
208  }
209 
211 
212  /* Build the IRP */
215  ok(Irp != NULL, "TdiBuildInternalDeviceControlIrp returned NULL!\n");
216  if (!Irp)
217  {
218  IoFreeMdl(Mdl);
219  ExFreePoolWithTag(ProviderInfo, 'tseT');
221  return;
222  }
223 
225  Irp,
226  DeviceObject,
227  FileObject,
228  NULL,
229  NULL,
231  Mdl);
232 
234 
236  if (Status == STATUS_PENDING)
237  {
239  &Event,
240  Executive,
241  KernelMode,
242  FALSE,
243  NULL);
244  Status = StatusBlock.Status;
245  }
246  ok_eq_hex(Status, TestData[i].IrpStatus);
247 
248  IoFreeIrp(Irp);
249  IoFreeMdl(Mdl);
251 
252  if (!NT_SUCCESS(Status))
253  {
254  ExFreePoolWithTag(ProviderInfo, 'tseT');
255  continue;
256  }
257 
258  ok_eq_hex(ProviderInfo->Version, TestData[i].ExpectedInfo.Version);
259  ok_eq_ulong(ProviderInfo->MaxSendSize, TestData[i].ExpectedInfo.MaxSendSize);
260  ok_eq_ulong(ProviderInfo->MaxConnectionUserData, TestData[i].ExpectedInfo.MaxConnectionUserData);
261  ok_eq_ulong(ProviderInfo->MaxDatagramSize, TestData[i].ExpectedInfo.MaxDatagramSize);
262  ok_eq_hex(ProviderInfo->ServiceFlags, TestData[i].ExpectedInfo.ServiceFlags);
263  ok_eq_ulong(ProviderInfo->MinimumLookaheadData, TestData[i].ExpectedInfo.MinimumLookaheadData);
264  ok_eq_ulong(ProviderInfo->MaximumLookaheadData, TestData[i].ExpectedInfo.MaximumLookaheadData);
265  ok_eq_ulong(ProviderInfo->NumberOfResources, TestData[i].ExpectedInfo.NumberOfResources);
266 
267  ExFreePoolWithTag(ProviderInfo, 'tseT');
268  }
269 }
270 
271 static KSTART_ROUTINE RunTest;
272 static
273 VOID
274 NTAPI
277 {
279 
281 }
282 
283 KMT_MESSAGE_HANDLER TestTdi;
284 NTSTATUS
289  _In_ SIZE_T InLength,
290  _Inout_ PSIZE_T OutLength
291 )
292 {
294 
297 
298  return STATUS_SUCCESS;
299 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ok_eq_ulong(value, expected)
#define trace(...)
Definition: kmt_test.h:217
static KSTART_ROUTINE RunTest
Definition: tdi.c:271
#define TRUE
Definition: types.h:120
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
#define TDI_SERVICE_DGRAM_CONNECTION
Definition: tdi.h:260
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
KMT_MESSAGE_HANDLER TestTdi
Definition: tdi.c:283
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define TDI_SERVICE_ACCEPT_LOCAL_ADDR
Definition: tdi.h:264
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
#define FILE_SHARE_READ
Definition: compat.h:125
#define _In_opt_
Definition: no_sal2.h:213
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
HANDLE FileHandle
Definition: stats.c:38
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 TDI_SERVICE_CONNECTIONLESS_MODE
Definition: tdi.h:247
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
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FILE_READ_DATA
Definition: nt_native.h:628
ULONG ServiceFlags
Definition: tdi.h:238
#define TDI_SERVICE_FORCE_ACCESS_CHECK
Definition: tdi.h:261
#define ok(value,...)
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define TDI_SERVICE_CONNECTION_MODE
Definition: tdi.h:245
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define TDI_SERVICE_EXPEDITED_DATA
Definition: tdi.h:253
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define TDI_SERVICE_NO_PUSH
Definition: tdi.h:267
static NTSTATUS NTAPI IrpCompletionRoutine(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
Definition: tdi.c:14
struct _TestData TestData
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define _Inout_
Definition: no_sal2.h:244
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG MinimumLookaheadData
Definition: tdi.h:239
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define TDI_SERVICE_PREPOST_RECVS
Definition: tdi.h:266
static const WCHAR L[]
Definition: oid.c:1250
ULONG MaxDatagramSize
Definition: tdi.h:237
#define GENERIC_READ
Definition: compat.h:124
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
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
#define FILE_OPEN
Definition: from_kernel.h:54
#define _In_
Definition: no_sal2.h:204
#define TdiBuildQueryInformation( Irp, DevObj, FileObj, CompRoutine, Contxt, QType, MdlAddr)
Definition: tdikrnl.h:638
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define TDI_SERVICE_BROADCAST_SUPPORTED
Definition: tdi.h:250
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
ULONG MaximumLookaheadData
Definition: tdi.h:240
ULONG MaxSendSize
Definition: tdi.h:235
#define TDI_SERVICE_ADDRESS_SECURITY
Definition: tdi.h:265
#define TDI_SERVICE_ORDERLY_RELEASE
Definition: tdi.h:246
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define TDI_QUERY_PROVIDER_INFO
Definition: tdi.h:180
ULONG MaxConnectionUserData
Definition: tdi.h:236
ULONG NumberOfResources
Definition: tdi.h:241
ULONG Version
Definition: tdi.h:234
#define TDI_SERVICE_DELAYED_ACCEPTANCE
Definition: tdi.h:252
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define TDI_SERVICE_SEND_AND_DISCONNECT
Definition: tdi.h:262
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static VOID TestProviderInfo(void)
Definition: tdi.c:29
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define ok_eq_hex(value, expected)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TDI_SERVICE_NO_ZERO_LENGTH
Definition: tdi.h:256
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define TDI_SERVICE_ERROR_FREE_DELIVERY
Definition: tdi.h:248
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14