ReactOS  0.4.14-dev-98-gb0d4763
main.c File Reference
#include "precomp.h"
#include <dispatch.h>
#include <fileobjs.h>
Include dependency graph for main.c:

Go to the source code of this file.

Functions

VOID TiWriteErrorLog (PDRIVER_OBJECT DriverContext, NTSTATUS ErrorCode, ULONG UniqueErrorValue, NTSTATUS FinalStatus, PWSTR String, ULONG DumpDataCount, PULONG DumpData)
 
NTSTATUS TiCreateFileObject (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS TiCloseFileObject (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI TiDispatchOpenClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI TiDispatchInternal (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI TiDispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI TiUnload (PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
VOID NTAPI IPAddInterface (ULONG Unknown0, ULONG Unknown1, ULONG Unknown2, ULONG Unknown3, ULONG Unknown4)
 
VOID NTAPI IPDelInterface (ULONG Unknown0)
 
VOID NTAPI LookupRoute (ULONG Unknown0, ULONG Unknown1)
 

Variables

PDEVICE_OBJECT TCPDeviceObject = NULL
 
PDEVICE_OBJECT UDPDeviceObject = NULL
 
PDEVICE_OBJECT IPDeviceObject = NULL
 
PDEVICE_OBJECT RawIPDeviceObject = NULL
 
NDIS_HANDLE GlobalPacketPool = NULL
 
NDIS_HANDLE GlobalBufferPool = NULL
 
KSPIN_LOCK EntityListLock
 
TDIEntityInfoEntityList = NULL
 
ULONG EntityCount = 0
 
ULONG EntityMax = 0
 
UDP_STATISTICS UDPStats
 
KTIMER IPTimer
 
KDPC IPTimeoutDpc
 

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 614 of file main.c.

625 {
632  NDIS_STATUS NdisStatus;
634 
635  TI_DbgPrint(MAX_TRACE, ("[TCPIP, DriverEntry] Called\n"));
636 
637  /* TdiInitialize() ? */
638 
639  /* FIXME: Create symbolic links in Win32 namespace */
640 
641  /* Initialize our periodic timer and its associated DPC object. When the
642  timer expires, the IPTimeout deferred procedure call (DPC) is queued */
645 
646  /* Create IP device object */
647  Status = IoCreateDevice(DriverObject, 0, &strIpDeviceName,
649  if (!NT_SUCCESS(Status)) {
650  TI_DbgPrint(MIN_TRACE, ("Failed to create IP device object. Status (0x%X).\n", Status));
652  return Status;
653  }
654 
656 
657  /* Create RawIP device object */
658  Status = IoCreateDevice(DriverObject, 0, &strRawDeviceName,
660  if (!NT_SUCCESS(Status)) {
661  TI_DbgPrint(MIN_TRACE, ("Failed to create RawIP device object. Status (0x%X).\n", Status));
663  return Status;
664  }
665 
666  /* Create UDP device object */
667  Status = IoCreateDevice(DriverObject, 0, &strUdpDeviceName,
669  if (!NT_SUCCESS(Status)) {
670  TI_DbgPrint(MIN_TRACE, ("Failed to create UDP device object. Status (0x%X).\n", Status));
672  return Status;
673  }
674 
675  /* Create TCP device object */
676  Status = IoCreateDevice(DriverObject, 0, &strTcpDeviceName,
678  if (!NT_SUCCESS(Status)) {
679  TI_DbgPrint(MIN_TRACE, ("Failed to create TCP device object. Status (0x%X).\n", Status));
681  return Status;
682  }
683 
684  /* Setup network layer and transport layer entities */
687  sizeof(TDIEntityID) * MAX_TDI_ENTITIES,
688  TDI_ENTITY_TAG );
689  if (!EntityList) {
690  TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
693  }
694 
695  EntityCount = 0;
697 
698  /* Allocate NDIS packet descriptors */
699  NdisAllocatePacketPoolEx(&NdisStatus, &GlobalPacketPool, 500, 1500, sizeof(PACKET_CONTEXT));
700  if (NdisStatus != NDIS_STATUS_SUCCESS) {
703  }
704 
705  /* Allocate NDIS buffer descriptors */
706  NdisAllocateBufferPool(&NdisStatus, &GlobalBufferPool, 2000);
707  if (NdisStatus != NDIS_STATUS_SUCCESS) {
710  }
711 
712  /* Initialize address file list and protecting spin lock */
715 
716  /* Initialize connection endpoint list and protecting spin lock */
719 
720  /* Initialize interface list and protecting spin lock */
723 
724  /* Initialize network level protocol subsystem */
726 
727  /* Initialize transport level protocol subsystems */
728  Status = RawIPStartup();
729  if( !NT_SUCCESS(Status) ) {
731  return Status;
732  }
733 
734  Status = UDPStartup();
735  if( !NT_SUCCESS(Status) ) {
737  return Status;
738  }
739 
740  Status = TCPStartup();
741  if( !NT_SUCCESS(Status) ) {
743  return Status;
744  }
745 
746  Status = ICMPStartup();
747  if( !NT_SUCCESS(Status) ) {
749  return Status;
750  }
751 
752  /* Use direct I/O */
757 
758  /* Initialize the driver object with this driver's entry points */
763 
765 
766  /* Open loopback adapter */
768  if (!NT_SUCCESS(Status)) {
769  TI_DbgPrint(MIN_TRACE, ("Failed to create loopback adapter. Status (0x%X).\n", Status));
771  return Status;
772  }
773 
774  /* Register protocol with NDIS */
775  /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
776  Status = LANRegisterProtocol(&strNdisDeviceName);
777  if (!NT_SUCCESS(Status)) {
778  TI_DbgPrint(MIN_TRACE,("Failed to register protocol with NDIS; status 0x%x\n", Status));
780  DriverObject,
783  Status,
784  NULL,
785  0,
786  NULL);
788  return Status;
789  }
790 
791  /* Start the periodic timer with an initial and periodic
792  relative expiration time of IP_TIMEOUT milliseconds */
793  DueTime.QuadPart = -(LONGLONG)IP_TIMEOUT * 10000;
795 
796  TI_DbgPrint(MAX_TRACE, ("[TCPIP, DriverEntry] Finished\n"));
797 
798 
799  return STATUS_SUCCESS;
800 }
KDPC IPTimeoutDpc
Definition: main.c:30
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID NTAPI IPTimeoutDpcFn(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: ip.c:112
#define MAX_TDI_ENTITIES
Definition: tdiinfo.h:35
NDIS_HANDLE GlobalPacketPool
Definition: main.c:20
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_DEVICE_NETWORK
Definition: winioctl.h:123
#define EVENT_TRANSPORT_REGISTER_FAILED
Definition: netevent.h:531
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
LIST_ENTRY ConnectionEndpointListHead
Definition: fileobjs.c:25
KSPIN_LOCK InterfaceListLock
Definition: ip.c:18
VOID TiWriteErrorLog(PDRIVER_OBJECT DriverContext, NTSTATUS ErrorCode, ULONG UniqueErrorValue, NTSTATUS FinalStatus, PWSTR String, ULONG DumpDataCount, PULONG DumpData)
Definition: main.c:32
LONG NTSTATUS
Definition: precomp.h:26
#define DD_TCP_DEVICE_NAME
Definition: wshtcpip.h:27
NTSTATUS RawIPStartup(VOID)
Definition: rawip.c:338
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
NTSTATUS NTAPI TiDispatchInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:374
ULONG EntityCount
Definition: main.c:24
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
VOID NTAPI TiUnload(PDRIVER_OBJECT DriverObject)
Definition: main.c:548
int NDIS_STATUS
Definition: ntddndis.h:471
NTSTATUS UDPStartup(VOID)
Definition: udp.c:337
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
#define TCPIP_PROTOCOL_NAME
Definition: ticonsts.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TI_ERROR_DRIVERENTRY
Definition: ticonsts.h:55
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define DD_IP_DEVICE_NAME
Definition: ticonsts.h:26
PDEVICE_OBJECT UDPDeviceObject
Definition: main.c:17
int64_t LONGLONG
Definition: typedefs.h:66
#define TDI_ENTITY_TAG
Definition: tags.h:14
NDIS_HANDLE GlobalBufferPool
Definition: main.c:21
PDEVICE_OBJECT TCPDeviceObject
Definition: main.c:16
ULONG EntityMax
Definition: main.c:25
PDEVICE_OBJECT IPDeviceObject
Definition: main.c:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI TiDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:477
KTIMER IPTimer
Definition: main.c:29
#define DD_UDP_DEVICE_NAME
Definition: wshtcpip.h:28
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
PDEVICE_OBJECT RawIPDeviceObject
Definition: main.c:19
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPStartup(VOID)
Definition: tcp.c:183
LIST_ENTRY AddressFileListHead
Definition: fileobjs.c:21
LIST_ENTRY InterfaceListHead
Definition: ip.c:17
NTSTATUS NTAPI TiDispatchOpenClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:333
#define MAX_TRACE
Definition: debug.h:16
NTSTATUS IPStartup(PUNICODE_STRING RegistryPath)
Definition: ip.c:411
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS LANRegisterProtocol(PNDIS_STRING Name)
Registers this protocol driver with NDIS.
Definition: lan.c:893
VOID EXPORT NdisAllocatePacketPoolEx(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT NumberOfOverflowDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:447
KSPIN_LOCK AddressFileListLock
Definition: fileobjs.c:22
NTSTATUS ICMPStartup(VOID)
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define MIN_TRACE
Definition: debug.h:14
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
KSPIN_LOCK EntityListLock
Definition: main.c:22
#define DD_RAWIP_DEVICE_NAME
Definition: ticonsts.h:27
TDIEntityInfo * EntityList
Definition: main.c:23
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
KSPIN_LOCK ConnectionEndpointListLock
Definition: fileobjs.c:26
return STATUS_SUCCESS
Definition: btrfs.c:2966
VOID ChewInit(PDEVICE_OBJECT DeviceObject)
Definition: workqueue.c:32
NDIS_STATUS LoopRegisterAdapter(PNDIS_STRING AdapterName, PLAN_ADAPTER *Adapter)
Definition: loopback.c:89
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:370
#define IP_TIMEOUT
Definition: ip.h:200
LONGLONG QuadPart
Definition: typedefs.h:112
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ IPAddInterface()

VOID NTAPI IPAddInterface ( ULONG  Unknown0,
ULONG  Unknown1,
ULONG  Unknown2,
ULONG  Unknown3,
ULONG  Unknown4 
)

Definition at line 803 of file main.c.

809 {
811 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ IPDelInterface()

VOID NTAPI IPDelInterface ( ULONG  Unknown0)

Definition at line 815 of file main.c.

817 {
819 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ LookupRoute()

VOID NTAPI LookupRoute ( ULONG  Unknown0,
ULONG  Unknown1 
)

Definition at line 823 of file main.c.

826 {
828 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ TiCloseFileObject()

NTSTATUS TiCloseFileObject ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 284 of file main.c.

287 {
292 
294  Context = IrpSp->FileObject->FsContext;
295  if (!Context)
296  {
297  TI_DbgPrint(MIN_TRACE, ("Parameters are invalid.\n"));
299  }
300 
301  switch ((ULONG_PTR)IrpSp->FileObject->FsContext2)
302  {
304  Request.Handle.AddressHandle = Context->Handle.AddressHandle;
306  break;
307 
308  case TDI_CONNECTION_FILE:
309  Request.Handle.ConnectionContext = Context->Handle.ConnectionContext;
311  break;
312 
314  Request.Handle.ControlChannel = Context->Handle.ControlChannel;
316  break;
317 
318  default:
320  break;
321  }
322 
323  if (NT_SUCCESS(Status))
325 
326  Irp->IoStatus.Status = Status;
327 
328  return Irp->IoStatus.Status;
329 }
NTSTATUS FileCloseConnection(PTDI_REQUEST Request)
Definition: fileobjs.c:656
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NTSTATUS FileCloseAddress(PTDI_REQUEST Request)
Definition: fileobjs.c:580
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS FileCloseControlChannel(PTDI_REQUEST Request)
Definition: fileobjs.c:727
LONG NTSTATUS
Definition: precomp.h:26
#define TDI_CONNECTION_FILE
Definition: tdikrnl.h:66
#define TRANS_CONTEXT_TAG
Definition: tags.h:13
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TDI_TRANSPORT_ADDRESS_FILE
Definition: tdikrnl.h:65
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct tagContext Context
Definition: acpixf.h:1024
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TDI_CONTROL_CHANNEL_FILE
Definition: tdikrnl.h:67

Referenced by TiDispatchOpenClose().

◆ TiCreateFileObject()

NTSTATUS TiCreateFileObject ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 109 of file main.c.

112 {
120  ULONG Protocol;
121  BOOLEAN Shared;
122 
123  TI_DbgPrint(DEBUG_IRP, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp));
124 
125  EaInfo = Irp->AssociatedIrp.SystemBuffer;
126 
127  /* Parameter check */
128  /* No EA information means that we're opening for SET/QUERY_INFORMATION
129  * style calls. */
130 
131  /* Allocate resources here. We release them again if something failed */
134  if (!Context)
135  {
136  TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
138  }
139 
140  Context->CancelIrps = FALSE;
141 
143  IrpSp->FileObject->FsContext = Context;
144  Request.RequestContext = Irp;
145 
146  /* Branch to the right handler */
147  if (EaInfo &&
151  {
152  /* This is a request to open an address */
153 
154 
155  /* XXX This should probably be done in IoCreateFile() */
156  /* Parameter checks */
157 
158  Address = (PTA_IP_ADDRESS)(EaInfo->EaName + EaInfo->EaNameLength + 1); //0-term
159 
160  if ((EaInfo->EaValueLength < sizeof(TA_IP_ADDRESS)) ||
161  (Address->TAAddressCount != 1) ||
162  (Address->Address[0].AddressLength < TDI_ADDRESS_LENGTH_IP) ||
163  (Address->Address[0].AddressType != TDI_ADDRESS_TYPE_IP))
164  {
165  TI_DbgPrint(MIN_TRACE, ("Parameters are invalid:\n"));
166  TI_DbgPrint(MIN_TRACE, ("AddressCount: %d\n", Address->TAAddressCount));
167  if( Address->TAAddressCount == 1 )
168  {
169  TI_DbgPrint(MIN_TRACE, ("AddressLength: %u\n",
170  Address->Address[0].AddressLength));
171  TI_DbgPrint(MIN_TRACE, ("AddressType: %u\n",
172  Address->Address[0].AddressType));
173  }
174 
177  }
178 
179  /* Open address file object */
180 
181  /* Protocol depends on device object so find the protocol */
184  else if (DeviceObject == UDPDeviceObject)
186  else if (DeviceObject == IPDeviceObject)
188  else if (DeviceObject == RawIPDeviceObject)
189  {
191  if (!NT_SUCCESS(Status))
192  {
193  TI_DbgPrint(MIN_TRACE, ("Raw IP protocol number is invalid.\n"));
196  }
197  }
198  else
199  {
200  TI_DbgPrint(MIN_TRACE, ("Invalid device object at (0x%X).\n", DeviceObject));
203  }
204 
205  Shared = (IrpSp->Parameters.Create.ShareAccess != 0);
206 
208  if (NT_SUCCESS(Status))
209  {
211  Context->Handle.AddressHandle = Request.Handle.AddressHandle;
212  }
213 
214  }
215  else if (EaInfo &&
218  (&EaInfo->EaName, TdiConnectionContext,
221  {
222  /* This is a request to open a connection endpoint */
223 
224  /* Parameter checks */
225 
226  if (EaInfo->EaValueLength < sizeof(PVOID))
227  {
228  TI_DbgPrint(MIN_TRACE, ("Parameters are invalid.\n"));
231  }
232 
233  /* Can only do connection oriented communication using TCP */
234 
236  {
237  TI_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
240  }
241 
242  ClientContext = *((PVOID*)(EaInfo->EaName + EaInfo->EaNameLength));
243 
244  /* Open connection endpoint file object */
245 
247  if (NT_SUCCESS(Status))
248  {
249  IrpSp->FileObject->FsContext2 = (PVOID)TDI_CONNECTION_FILE;
250  Context->Handle.ConnectionContext = Request.Handle.ConnectionContext;
251  }
252  }
253  else
254  {
255  /* This is a request to open a control connection */
257  if (NT_SUCCESS(Status))
258  {
260  Context->Handle.ControlChannel = Request.Handle.ControlChannel;
261  }
262  }
263 
264  if (!NT_SUCCESS(Status))
266 
267  TI_DbgPrint(DEBUG_IRP, ("Leaving. Status = (0x%X).\n", Status));
268 
269  Irp->IoStatus.Status = Status;
270  return Status;
271 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#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
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
LONG NTSTATUS
Definition: precomp.h:26
_In_ USHORT _In_ ULONG Protocol
Definition: wsk.h:182
#define TDI_CONNECTION_FILE
Definition: tdikrnl.h:66
#define TDI_CONNECTION_CONTEXT_LENGTH
Definition: tdi.h:373
#define TRANS_CONTEXT_TAG
Definition: tags.h:13
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
#define DEBUG_IRP
Definition: debug.h:19
PDEVICE_OBJECT UDPDeviceObject
Definition: main.c:17
NTSTATUS TiGetProtocolNumber(PUNICODE_STRING FileName, PULONG Protocol)
Definition: proto.c:3
PDEVICE_OBJECT TCPDeviceObject
Definition: main.c:16
PDEVICE_OBJECT IPDeviceObject
Definition: main.c:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PVOID ClientContext
Definition: netioddk.h:55
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDEVICE_OBJECT RawIPDeviceObject
Definition: main.c:19
#define TDI_TRANSPORT_ADDRESS_FILE
Definition: tdikrnl.h:65
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define TdiTransportAddress
Definition: tdi.h:370
#define TdiConnectionContext
Definition: tdi.h:371
NTSTATUS FileOpenAddress(PTDI_REQUEST Request, PTA_IP_ADDRESS AddrList, USHORT Protocol, BOOLEAN Shared, PVOID Options)
Definition: fileobjs.c:391
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
struct tagContext Context
Definition: acpixf.h:1024
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
NTSTATUS FileOpenControlChannel(PTDI_REQUEST Request)
Definition: fileobjs.c:683
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS FileOpenConnection(PTDI_REQUEST Request, PVOID ClientContext)
Definition: fileobjs.c:621
static PSecPkgInfoA *static SEC_CHAR PVOID
Definition: main.c:37
HRESULT Create([out]ITransactionReceiver **ppReceiver)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define TDI_CONTROL_CHANNEL_FILE
Definition: tdikrnl.h:67

Referenced by TiDispatchOpenClose().

◆ TiDispatch()

NTSTATUS NTAPI TiDispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 477 of file main.c.

488 {
491 
493 
494  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Called. IRP is at (0x%X).\n", Irp));
495 
496  Irp->IoStatus.Information = 0;
497 
498 #if 0
500  if (NT_SUCCESS(Status)) {
503  } else {
504 #else
505  if (TRUE) {
506 #endif
507  /* See if this request is TCP/IP specific */
508  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
510  TI_DbgPrint(MIN_TRACE, ("TCP_QUERY_INFORMATION_EX\n"));
512  break;
513 
515  TI_DbgPrint(MIN_TRACE, ("TCP_SET_INFORMATION_EX\n"));
517  break;
518 
520  TI_DbgPrint(MIN_TRACE, ("SET_IP_ADDRESS\n"));
522  break;
523 
525  TI_DbgPrint(MIN_TRACE, ("DELETE_IP_ADDRESS\n"));
527  break;
528 
530  TI_DbgPrint(MIN_TRACE, ("QUERY_IP_HW_ADDRESS\n"));
532  break;
533 
534  default:
535  TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n",
536  IrpSp->Parameters.DeviceIoControl.IoControlCode));
538  break;
539  }
540  }
541 
542  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Leaving. Status = (0x%X).\n", Status));
543 
544  return IRPFinish( Irp, Status );
545 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NTSTATUS DispTdiSetIPAddress(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: dispatch.c:1552
#define TRUE
Definition: types.h:120
NTSTATUS DispTdiQueryIpHwAddress(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: dispatch.c:1672
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI TiDispatchInternal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:374
#define IOCTL_TCP_QUERY_INFORMATION_EX
Definition: ticonsts.h:42
NTSTATUS DispTdiSetInformationEx(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: dispatch.c:1493
#define IOCTL_TCP_SET_INFORMATION_EX
Definition: ticonsts.h:45
NTSTATUS DispTdiQueryInformationEx(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: dispatch.c:1310
NTSTATUS DispTdiDeleteIPAddress(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: dispatch.c:1600
#define IOCTL_DELETE_IP_ADDRESS
Definition: ticonsts.h:51
#define DEBUG_IRP
Definition: debug.h:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI TdiMapUserRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: stubs.c:83
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IOCTL_SET_IP_ADDRESS
Definition: ticonsts.h:48
NTSTATUS IRPFinish(PIRP Irp, NTSTATUS Status)
Definition: dispatch.c:26
#define MIN_TRACE
Definition: debug.h:14
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define IOCTL_QUERY_IP_HW_ADDRESS
Definition: tcpioctl.h:40

Referenced by DriverEntry().

◆ TiDispatchInternal()

NTSTATUS NTAPI TiDispatchInternal ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 374 of file main.c.

385 {
387  BOOLEAN Complete = TRUE;
389 
391 
392  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatchInternal] Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
394 
395  Irp->IoStatus.Status = STATUS_SUCCESS;
396  Irp->IoStatus.Information = 0;
397 
398  switch (IrpSp->MinorFunction) {
399  case TDI_RECEIVE:
401  Complete = FALSE;
402  break;
403 
406  Complete = FALSE;
407  break;
408 
409  case TDI_SEND:
411  Complete = FALSE; /* Completed in DispTdiSend */
412  break;
413 
414  case TDI_SEND_DATAGRAM:
416  Complete = FALSE;
417  break;
418 
419  case TDI_ACCEPT:
421  break;
422 
423  case TDI_LISTEN:
425  Complete = FALSE;
426  break;
427 
428  case TDI_CONNECT:
430  Complete = FALSE; /* Completed by the TCP event handler */
431  break;
432 
433  case TDI_DISCONNECT:
435  Complete = FALSE;
436  break;
437 
440  break;
441 
444  break;
445 
448  break;
449 
450  case TDI_SET_INFORMATION:
452  break;
453 
456  break;
457 
458  case TDI_ACTION:
460  break;
461 
462  /* An unsupported IOCTL code was submitted */
463  default:
465  }
466 
467  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatchInternal] Leaving. Status = (0x%X).\n", Status));
468 
469  if( Complete )
470  IRPFinish( Irp, Status );
471 
472  return Status;
473 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NTSTATUS DispTdiSetInformation(PIRP Irp)
Definition: dispatch.c:1257
NTSTATUS DispTdiDisconnect(PIRP Irp)
Definition: dispatch.c:485
NTSTATUS DispTdiSend(PIRP Irp)
Definition: dispatch.c:935
#define TRUE
Definition: types.h:120
NTSTATUS DispTdiQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatch.c:664
#define TDI_LISTEN
Definition: tdikrnl.h:50
#define TDI_ASSOCIATE_ADDRESS
Definition: tdikrnl.h:47
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS DispTdiConnect(PIRP Irp)
Definition: dispatch.c:383
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define TDI_ACCEPT
Definition: tdikrnl.h:51
#define TDI_SET_INFORMATION
Definition: tdikrnl.h:59
#define TDI_DISCONNECT
Definition: tdikrnl.h:52
#define TDI_ACTION
Definition: tdikrnl.h:60
#define TDI_CONNECT
Definition: tdikrnl.h:49
unsigned char BOOLEAN
#define TDI_SET_EVENT_HANDLER
Definition: tdikrnl.h:57
#define TDI_RECEIVE_DATAGRAM
Definition: tdikrnl.h:56
#define DEBUG_IRP
Definition: debug.h:19
NTSTATUS DispTdiSendDatagram(PIRP Irp)
Definition: dispatch.c:1008
#define TDI_RECEIVE
Definition: tdikrnl.h:54
NTSTATUS DispTdiListen(PIRP Irp)
Definition: dispatch.c:551
NTSTATUS DispTdiReceiveDatagram(PIRP Irp)
Definition: dispatch.c:860
NTSTATUS DispTdiSetEventHandler(PIRP Irp)
Definition: dispatch.c:1093
#define TDI_QUERY_INFORMATION
Definition: tdikrnl.h:58
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define TDI_SEND
Definition: tdikrnl.h:53
NTSTATUS DispTdiAssociateAddress(PIRP Irp)
Definition: dispatch.c:270
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define TDI_SEND_DATAGRAM
Definition: tdikrnl.h:55
NTSTATUS IRPFinish(PIRP Irp, NTSTATUS Status)
Definition: dispatch.c:26
NTSTATUS DispTdiDisassociateAddress(PIRP Irp)
Definition: dispatch.c:447
#define TDI_DISASSOCIATE_ADDRESS
Definition: tdikrnl.h:48
NTSTATUS DispTdiReceive(PIRP Irp)
Definition: dispatch.c:792
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS DispTdiAccept(PIRP Irp)
Definition: dispatch.c:254

Referenced by DriverEntry(), and TiDispatch().

◆ TiDispatchOpenClose()

NTSTATUS NTAPI TiDispatchOpenClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 333 of file main.c.

344 {
347 
348 // DbgPrint("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp);
349 
351 
352  switch (IrpSp->MajorFunction) {
353  /* Open an address file, connection endpoint, or control connection */
354  case IRP_MJ_CREATE:
356  break;
357 
358  /* Close an address file, connection endpoint, or control connection */
359  case IRP_MJ_CLOSE:
361  break;
362 
363  default:
365  }
366 
367  //DbgPrint("Leaving. Status is (0x%X)\n", Status);
368 
369  return IRPFinish( Irp, Status );
370 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS TiCreateFileObject(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:109
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS TiCloseFileObject(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:284
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS IRPFinish(PIRP Irp, NTSTATUS Status)
Definition: dispatch.c:26

Referenced by DriverEntry().

◆ TiUnload()

VOID NTAPI TiUnload ( PDRIVER_OBJECT  DriverObject)

Definition at line 548 of file main.c.

555 {
556 #if DBG
557  KIRQL OldIrql;
558 
561  TI_DbgPrint(MIN_TRACE, ("[TCPIP, TiUnload] Called. Open address file objects exists.\n"));
562  }
564 #endif
565  /* Cancel timer */
567 
568  /* Unregister loopback adapter */
570 
571  /* Unregister protocol with NDIS */
573 
574  /* Shutdown transport level protocol subsystems */
575  TCPShutdown();
576  UDPShutdown();
577  RawIPShutdown();
578  ICMPShutdown();
579 
580  /* Shutdown network level protocol subsystem */
581  IPShutdown();
582 
583  /* Free NDIS buffer descriptors */
584  if (GlobalBufferPool)
586 
587  /* Free NDIS packet descriptors */
588  if (GlobalPacketPool)
590 
591  /* Release all device objects */
592 
593  if (TCPDeviceObject)
595 
596  if (UDPDeviceObject)
598 
599  if (RawIPDeviceObject)
601 
602  if (IPDeviceObject) {
603  ChewShutdown();
605  }
606 
607  if (EntityList)
609 
610  TI_DbgPrint(MAX_TRACE, ("[TCPIP, TiUnload] Leaving.\n"));
611 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
NDIS_HANDLE GlobalPacketPool
Definition: main.c:20
NTSTATUS IPShutdown(VOID)
Definition: ip.c:477
NTSTATUS RawIPShutdown(VOID)
Definition: rawip.c:356
NTSTATUS UDPShutdown(VOID)
Definition: udp.c:364
NDIS_STATUS LoopUnregisterAdapter(PLAN_ADAPTER Adapter)
Definition: loopback.c:136
VOID TcpipReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL Irql)
Definition: lock.c:26
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID TcpipAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL Irql)
Definition: lock.c:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
VOID ChewShutdown(VOID)
Definition: workqueue.c:40
NTSTATUS ICMPShutdown(VOID)
PDEVICE_OBJECT UDPDeviceObject
Definition: main.c:17
#define TDI_ENTITY_TAG
Definition: tags.h:14
NDIS_HANDLE GlobalBufferPool
Definition: main.c:21
PDEVICE_OBJECT TCPDeviceObject
Definition: main.c:16
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
PDEVICE_OBJECT IPDeviceObject
Definition: main.c:18
KTIMER IPTimer
Definition: main.c:29
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
PDEVICE_OBJECT RawIPDeviceObject
Definition: main.c:19
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
LIST_ENTRY AddressFileListHead
Definition: fileobjs.c:21
#define MAX_TRACE
Definition: debug.h:16
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:775
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:791
KSPIN_LOCK AddressFileListLock
Definition: fileobjs.c:22
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSTATUS TCPShutdown(VOID)
Definition: tcp.c:218
TDIEntityInfo * EntityList
Definition: main.c:23
VOID LANUnregisterProtocol(VOID)
Unregisters this protocol driver with NDIS.
Definition: lan.c:943

Referenced by DriverEntry().

◆ TiWriteErrorLog()

VOID TiWriteErrorLog ( PDRIVER_OBJECT  DriverContext,
NTSTATUS  ErrorCode,
ULONG  UniqueErrorValue,
NTSTATUS  FinalStatus,
PWSTR  String,
ULONG  DumpDataCount,
PULONG  DumpData 
)

Definition at line 32 of file main.c.

52 {
53  PIO_ERROR_LOG_PACKET LogEntry;
55  ULONG StringSize;
56  PUCHAR pString;
57  static WCHAR DriverName[] = L"TCP/IP";
58 
59  EntrySize = sizeof(IO_ERROR_LOG_PACKET) +
60  (DumpDataCount * sizeof(ULONG)) + sizeof(DriverName);
61 
62  if (String) {
63  StringSize = (wcslen(String) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
64  EntrySize += (UCHAR)StringSize;
65  }
66 
67  /* Fail if the required error log entry is too large */
69  return;
70 
72  if (!LogEntry)
73  return;
74 
75  LogEntry->MajorFunctionCode = -1;
76  LogEntry->RetryCount = -1;
77  LogEntry->DumpDataSize = (USHORT)(DumpDataCount * sizeof(ULONG));
78  LogEntry->NumberOfStrings = (String == NULL) ? 1 : 2;
79  LogEntry->StringOffset = sizeof(IO_ERROR_LOG_PACKET) + (DumpDataCount * sizeof(ULONG));
80  LogEntry->EventCategory = 0;
81  LogEntry->ErrorCode = ErrorCode;
83  LogEntry->FinalStatus = FinalStatus;
84  LogEntry->SequenceNumber = -1;
85  LogEntry->IoControlCode = 0;
86 
87  if (DumpDataCount)
88  RtlCopyMemory(LogEntry->DumpData, DumpData, DumpDataCount * sizeof(ULONG));
89 
90  pString = ((PUCHAR)LogEntry) + LogEntry->StringOffset;
91  RtlCopyMemory(pString, DriverName, sizeof(DriverName));
92  pString += sizeof(DriverName);
93 
94  if (String)
95  RtlCopyMemory(pString, String, StringSize);
96 
97  IoWriteErrorLogEntry(LogEntry);
98 }
_In_ ULONG _In_ BOOLEAN _In_ ULONG UniqueErrorValue
Definition: classpnp.h:1117
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
NTSTATUS FinalStatus
Definition: iotypes.h:1966
unsigned char * PUCHAR
Definition: retypes.h:3
Irp Tail Overlay DriverContext[3]
static WCHAR String[]
Definition: stringtable.c:55
_In_ UCHAR EntrySize
Definition: iofuncs.h:640
VOID NTAPI IoWriteErrorLogEntry(IN PVOID ElEntry)
Definition: error.c:620
NTSTATUS ErrorCode
Definition: iotypes.h:1964
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
struct _IO_ERROR_LOG_PACKET IO_ERROR_LOG_PACKET
#define ERROR_LOG_MAXIMUM_SIZE
Definition: iotypes.h:1999
PVOID NTAPI IoAllocateErrorLogEntry(IN PVOID IoObject, IN UCHAR EntrySize)
Definition: error.c:520
USHORT NumberOfStrings
Definition: iotypes.h:1961
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
unsigned short USHORT
Definition: pedump.c:61
struct _IO_ERROR_LOG_PACKET * PIO_ERROR_LOG_PACKET
unsigned int ULONG
Definition: retypes.h:1
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by DriverEntry().

Variable Documentation

◆ EntityCount

◆ EntityList

◆ EntityListLock

◆ EntityMax

ULONG EntityMax = 0

Definition at line 25 of file main.c.

Referenced by DriverEntry().

◆ GlobalBufferPool

NDIS_HANDLE GlobalBufferPool = NULL

Definition at line 21 of file main.c.

Referenced by DriverEntry(), and TiUnload().

◆ GlobalPacketPool

NDIS_HANDLE GlobalPacketPool = NULL

Definition at line 20 of file main.c.

Referenced by DriverEntry(), and TiUnload().

◆ IPDeviceObject

PDEVICE_OBJECT IPDeviceObject = NULL

Definition at line 18 of file main.c.

Referenced by DriverEntry(), TiCreateFileObject(), and TiUnload().

◆ IPTimeoutDpc

KDPC IPTimeoutDpc

Definition at line 30 of file main.c.

Referenced by DriverEntry().

◆ IPTimer

KTIMER IPTimer

Definition at line 29 of file main.c.

Referenced by DriverEntry(), and TiUnload().

◆ RawIPDeviceObject

PDEVICE_OBJECT RawIPDeviceObject = NULL

Definition at line 19 of file main.c.

Referenced by DriverEntry(), TiCreateFileObject(), and TiUnload().

◆ TCPDeviceObject

PDEVICE_OBJECT TCPDeviceObject = NULL

Definition at line 16 of file main.c.

Referenced by DriverEntry(), TiCreateFileObject(), and TiUnload().

◆ UDPDeviceObject

PDEVICE_OBJECT UDPDeviceObject = NULL

Definition at line 17 of file main.c.

Referenced by DriverEntry(), TiCreateFileObject(), and TiUnload().

◆ UDPStats

UDP_STATISTICS UDPStats

Definition at line 26 of file main.c.

Referenced by RawIPStartup(), and UDPStartup().