ReactOS 0.4.16-dev-340-g0540c21
connect.c File Reference
#include <kmt_test.h>
#include <tdikrnl.h>
#include <ndk/rtlfuncs.h>
#include <sys/param.h>
#include "tcpip.h"
Include dependency graph for connect.c:

Go to the source code of this file.

Macros

#define TAG_TEST   'tseT'
 

Functions

USHORT htons (USHORT x)
 
static NTSTATUS NTAPI IrpCompletionRoutine (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
 
static VOID TestTcpConnect (void)
 
static VOID NTAPI RunTest (_In_ PVOID Context)
 
NTSTATUS TestConnect (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_opt_ PVOID Buffer, _In_ SIZE_T InLength, _Inout_ PSIZE_T OutLength)
 

Variables

static KSTART_ROUTINE RunTest
 
KMT_MESSAGE_HANDLER TestConnect
 

Macro Definition Documentation

◆ TAG_TEST

#define TAG_TEST   'tseT'

Definition at line 16 of file connect.c.

Function Documentation

◆ htons()

USHORT htons ( USHORT  x)

Definition at line 20 of file connect.c.

21{
22 return ((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8);
23}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

◆ IrpCompletionRoutine()

static NTSTATUS NTAPI IrpCompletionRoutine ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PVOID  Context 
)
static

Definition at line 31 of file connect.c.

35{
38
40
42}
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by TestTcpConnect().

◆ RunTest()

static VOID NTAPI RunTest ( _In_ PVOID  Context)
static

Definition at line 249 of file connect.c.

251{
253
255}
static VOID TestTcpConnect(void)
Definition: connect.c:46

◆ TestConnect()

NTSTATUS TestConnect ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ ULONG  ControlCode,
_In_opt_ PVOID  Buffer,
_In_ SIZE_T  InLength,
_Inout_ PSIZE_T  OutLength 
)

Definition at line 259 of file connect.c.

266{
268
271
272 return STATUS_SUCCESS;
273}
#define NULL
Definition: types.h:112
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
static KSTART_ROUTINE RunTest
Definition: connect.c:245
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ TestTcpConnect()

static VOID TestTcpConnect ( void  )
static

Definition at line 46 of file connect.c.

47{
48 PIRP Irp;
49 HANDLE AddressHandle, ConnectionHandle;
50 FILE_OBJECT* ConnectionFileObject;
52 UNICODE_STRING TcpDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Tcp");
55 TA_IP_ADDRESS* IpAddress;
56 TA_IP_ADDRESS ConnectAddress, ReturnAddress;
58 IO_STATUS_BLOCK StatusBlock;
59 ULONG FileInfoSize;
60 IN_ADDR InAddr;
61 LPCWSTR AddressTerminator;
62 CONNECTION_CONTEXT ConnectionContext = (CONNECTION_CONTEXT)(ULONG_PTR)0xC0CAC01AC0CAC01AULL;
64 TDI_CONNECTION_INFORMATION RequestInfo, ReturnInfo;
65
66 /* Create a TCP address file */
69 FileInfoSize,
70 TAG_TEST);
71 ok(FileInfo != NULL, "FileInfo is NULL!\n");
72 RtlZeroMemory(FileInfo, FileInfoSize);
73
75 FileInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
77
78 IpAddress = (PTA_IP_ADDRESS)(&FileInfo->EaName[TDI_TRANSPORT_ADDRESS_LENGTH + 1]);
79 IpAddress->TAAddressCount = 1;
80 IpAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
81 IpAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
82 IpAddress->Address[0].Address[0].sin_port = htons(TEST_CONNECT_CLIENT_PORT);
83 Status = RtlIpv4StringToAddressW(L"127.0.0.1", TRUE, &AddressTerminator, &InAddr);
85 IpAddress->Address[0].Address[0].in_addr = InAddr.S_un.S_addr;
86
88 &TcpDeviceName,
90 NULL,
91 NULL);
92
93 Status = ZwCreateFile(
94 &AddressHandle,
97 &StatusBlock,
98 0,
102 0L,
103 FileInfo,
104 FileInfoSize);
106
108
109 /* Create a TCP connection file */
112 FileInfoSize,
113 TAG_TEST);
114 ok(FileInfo != NULL, "FileInfo is NULL!\n");
115 RtlZeroMemory(FileInfo, FileInfoSize);
116
118 FileInfo->EaValueLength = sizeof(CONNECTION_CONTEXT);
120 *((CONNECTION_CONTEXT*)&FileInfo->EaName[TDI_CONNECTION_CONTEXT_LENGTH + 1]) = ConnectionContext;
121
122 Status = ZwCreateFile(
126 &StatusBlock,
127 0,
131 0L,
132 FileInfo,
133 FileInfoSize);
135
137
138 /* Get the file and device object for the upcoming IRPs */
144 (PVOID*)&ConnectionFileObject,
145 NULL);
147 DeviceObject = IoGetRelatedDeviceObject(ConnectionFileObject);
148 ok(DeviceObject != NULL, "Device object is NULL!\n");
149
150 /* Associate the connection file and the address */
152 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
153 ok(Irp != NULL, "IoAllocateIrp failed.\n");
154
155 TdiBuildAssociateAddress(Irp, DeviceObject, ConnectionFileObject, NULL, NULL, AddressHandle);
157
159 if (Status == STATUS_PENDING)
160 {
161 trace("Associate address IRP is pending.\n");
163 &Event,
164 Executive,
166 FALSE,
167 NULL);
168 Status = Irp->IoStatus.Status;
169 trace("Associate address IRP completed.\n");
170 }
172 IoFreeIrp(Irp);
173
174
176
177 /* Build the connect IRP. */
178 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
179 ok(Irp != NULL, "IoAllocateIrp failed.\n");
180
181 /* Prepare the request */
182 RtlZeroMemory(&RequestInfo, sizeof(RequestInfo));
183 RtlZeroMemory(&ConnectAddress, sizeof(ConnectAddress));
184 RequestInfo.RemoteAddressLength = sizeof(TA_IP_ADDRESS);
185 RequestInfo.RemoteAddress = &ConnectAddress;
186 ConnectAddress.TAAddressCount = 1;
187 ConnectAddress.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
188 ConnectAddress.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
189 ConnectAddress.Address[0].Address[0].sin_port = htons(TEST_CONNECT_SERVER_PORT);
190 Status = RtlIpv4StringToAddressW(L"127.0.0.1", TRUE, &AddressTerminator, &InAddr);
191 ConnectAddress.Address[0].Address[0].in_addr = InAddr.S_un.S_addr;
192
193 /* See what we will get in exchange */
194 RtlZeroMemory(&ReturnInfo, sizeof(ReturnInfo));
195 RtlZeroMemory(&ReturnAddress, sizeof(ReturnAddress));
196 ReturnInfo.RemoteAddressLength = sizeof(TA_IP_ADDRESS);
197 ReturnInfo.RemoteAddress = &ReturnAddress;
198
201 ConnectionFileObject,
202 NULL,
203 NULL,
204 NULL,
205 &RequestInfo,
206 &ReturnInfo);
208
210 if (Status == STATUS_PENDING)
211 {
212 trace("Connect IRP is pending.\n");
214 &Event,
215 Executive,
217 FALSE,
218 NULL);
219 Status = Irp->IoStatus.Status;
220 trace("Connect IRP completed.\n");
221 }
223 IoFreeIrp(Irp);
224
225 /* The IRP doesn't touch the return info */
226 ok_eq_long(ReturnInfo.RemoteAddressLength, sizeof(TA_IP_ADDRESS));
227 ok_eq_pointer(ReturnInfo.RemoteAddress, &ReturnAddress);
228 ok_eq_long(ReturnInfo.OptionsLength, 0);
229 ok_eq_pointer(ReturnInfo.Options, NULL);
230 ok_eq_long(ReturnInfo.UserDataLength, 0);
231 ok_eq_pointer(ReturnInfo.UserData, NULL);
232
233 ok_eq_long(ReturnAddress.TAAddressCount, 1);
234 ok_eq_hex(ReturnAddress.Address[0].AddressType, TDI_ADDRESS_TYPE_IP);
235 ok_eq_hex(ReturnAddress.Address[0].AddressLength, TDI_ADDRESS_LENGTH_IP);
236 ok_eq_hex(ReturnAddress.Address[0].Address[0].sin_port, htons(TEST_CONNECT_SERVER_PORT));
237 ok_eq_hex(ReturnAddress.Address[0].Address[0].in_addr, InAddr.S_un.S_addr);
238
239 ObDereferenceObject(ConnectionFileObject);
240
242 ZwClose(AddressHandle);
243}
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_long(value, expected)
Definition: apitest.h:62
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define TRUE
Definition: types.h:120
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define FILE_OPEN_IF
Definition: from_kernel.h:56
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
_In_ PKSPIN_CONNECT _In_ ACCESS_MASK _Out_ PHANDLE ConnectionHandle
Definition: ks.h:4538
#define htons(x)
Definition: module.h:215
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define TAG_TEST
Definition: connect.c:16
static NTSTATUS NTAPI IrpCompletionRoutine(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
Definition: connect.c:31
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI RtlIpv4StringToAddressW(_In_ PCWSTR String, _In_ BOOLEAN Strict, _Out_ PCWSTR *Terminator, _Out_ struct in_addr *Addr)
Definition: network.c:385
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
@ NotificationEvent
@ FILE_OBJECT
Definition: ntobjenum.h:17
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define L(x)
Definition: ntvdm.h:50
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
struct _TA_ADDRESS_IP::_AddrIp Address[1]
LONG TAAddressCount
Definition: tdi.h:523
Definition: tcpip.h:126
u_long S_addr
Definition: tcpip.h:131
union in_addr::@1031 S_un
PVOID CONNECTION_CONTEXT
Definition: tdi.h:37
struct _TA_ADDRESS_IP TA_IP_ADDRESS
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
#define TDI_CONNECTION_CONTEXT_LENGTH
Definition: tdi.h:373
#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 TdiConnectionContext
Definition: tdi.h:371
#define TdiTransportAddress
Definition: tdi.h:370
#define TdiBuildAssociateAddress( Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle)
Definition: tdikrnl.h:467
#define TdiBuildConnect( Irp, DevObj, FileObj, CompRoutine, Contxt, Time, RequestConnectionInfo, ReturnConnectionInfo)
Definition: tdikrnl.h:494
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by RunTest().

Variable Documentation

◆ RunTest

KSTART_ROUTINE RunTest
static

Definition at line 245 of file connect.c.

Referenced by TestConnect().

◆ TestConnect

KMT_MESSAGE_HANDLER TestConnect

Definition at line 257 of file connect.c.

Referenced by RunTest().