2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
5 * PURPOSE: Driver entry point
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/08-2000 Created
12 PDEVICE_OBJECT TCPDeviceObject
= NULL
;
13 PDEVICE_OBJECT UDPDeviceObject
= NULL
;
14 PDEVICE_OBJECT IPDeviceObject
= NULL
;
15 PDEVICE_OBJECT RawIPDeviceObject
= NULL
;
16 NDIS_HANDLE GlobalPacketPool
= NULL
;
17 NDIS_HANDLE GlobalBufferPool
= NULL
;
18 KSPIN_LOCK EntityListLock
;
19 TDIEntityInfo
*EntityList
= NULL
;
20 ULONG EntityCount
= 0;
22 UDP_STATISTICS UDPStats
;
29 PDRIVER_OBJECT DriverContext
,
31 ULONG UniqueErrorValue
,
37 * FUNCTION: Writes an error log entry
39 * DriverContext = Pointer to the driver or device object
40 * ErrorCode = An error code to put in the log entry
41 * UniqueErrorValue = UniqueErrorValue in the error log packet
42 * FinalStatus = FinalStatus in the error log packet
43 * String = If not NULL, a pointer to a string to put in log
45 * DumpDataCount = Number of ULONGs of dump data
46 * DumpData = Pointer to dump data for the log entry
50 PIO_ERROR_LOG_PACKET LogEntry
;
54 static WCHAR DriverName
[] = L
"TCP/IP";
56 EntrySize
= sizeof(IO_ERROR_LOG_PACKET
) +
57 (DumpDataCount
* sizeof(ULONG
)) + sizeof(DriverName
);
60 StringSize
= (wcslen(String
) * sizeof(WCHAR
)) + sizeof(UNICODE_NULL
);
61 EntrySize
+= (UCHAR
)StringSize
;
64 LogEntry
= (PIO_ERROR_LOG_PACKET
)IoAllocateErrorLogEntry(
65 DriverContext
, EntrySize
);
68 LogEntry
->MajorFunctionCode
= -1;
69 LogEntry
->RetryCount
= -1;
70 LogEntry
->DumpDataSize
= (USHORT
)(DumpDataCount
* sizeof(ULONG
));
71 LogEntry
->NumberOfStrings
= (String
== NULL
) ? 1 : 2;
72 LogEntry
->StringOffset
= sizeof(IO_ERROR_LOG_PACKET
) + (DumpDataCount
-1) * sizeof(ULONG
);
73 LogEntry
->EventCategory
= 0;
74 LogEntry
->ErrorCode
= ErrorCode
;
75 LogEntry
->UniqueErrorValue
= UniqueErrorValue
;
76 LogEntry
->FinalStatus
= FinalStatus
;
77 LogEntry
->SequenceNumber
= -1;
78 LogEntry
->IoControlCode
= 0;
81 RtlCopyMemory(LogEntry
->DumpData
, DumpData
, DumpDataCount
* sizeof(ULONG
));
83 pString
= ((PUCHAR
)LogEntry
) + LogEntry
->StringOffset
;
84 RtlCopyMemory(pString
, DriverName
, sizeof(DriverName
));
85 pString
+= sizeof(DriverName
);
88 RtlCopyMemory(pString
, String
, StringSize
);
90 IoWriteErrorLogEntry(LogEntry
);
96 * FUNCTION: Creates a file object
98 * DeviceObject = Pointer to a device object for this driver
99 * Irp = Pointer to a I/O request packet
101 * Status of the operation
104 NTSTATUS
TiCreateFileObject(
105 PDEVICE_OBJECT DeviceObject
,
108 PFILE_FULL_EA_INFORMATION EaInfo
;
109 PTRANSPORT_CONTEXT Context
;
110 PIO_STACK_LOCATION IrpSp
;
111 PTA_IP_ADDRESS Address
;
117 TI_DbgPrint(DEBUG_IRP
, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject
, Irp
));
119 EaInfo
= Irp
->AssociatedIrp
.SystemBuffer
;
121 /* Parameter check */
122 /* No EA information means that we're opening for SET/QUERY_INFORMATION
125 /* Allocate resources here. We release them again if something failed */
126 Context
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(TRANSPORT_CONTEXT
),
129 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
130 return STATUS_INSUFFICIENT_RESOURCES
;
133 Context
->CancelIrps
= FALSE
;
135 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
136 IrpSp
->FileObject
->FsContext
= Context
;
137 Request
.RequestContext
= Irp
;
139 /* Branch to the right handler */
141 (EaInfo
->EaNameLength
== TDI_TRANSPORT_ADDRESS_LENGTH
) &&
143 (&EaInfo
->EaName
, TdiTransportAddress
,
144 TDI_TRANSPORT_ADDRESS_LENGTH
) == TDI_TRANSPORT_ADDRESS_LENGTH
)) {
145 /* This is a request to open an address */
148 /* XXX This should probably be done in IoCreateFile() */
149 /* Parameter checks */
151 Address
= (PTA_IP_ADDRESS
)(EaInfo
->EaName
+ EaInfo
->EaNameLength
+ 1); //0-term
153 if ((EaInfo
->EaValueLength
< sizeof(TA_IP_ADDRESS
)) ||
154 (Address
->TAAddressCount
!= 1) ||
155 (Address
->Address
[0].AddressLength
< TDI_ADDRESS_LENGTH_IP
) ||
156 (Address
->Address
[0].AddressType
!= TDI_ADDRESS_TYPE_IP
)) {
157 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid:\n"));
158 TI_DbgPrint(MIN_TRACE
, ("AddressCount: %d\n", Address
->TAAddressCount
));
159 if( Address
->TAAddressCount
== 1 ) {
160 TI_DbgPrint(MIN_TRACE
, ("AddressLength: %\n",
161 Address
->Address
[0].AddressLength
));
162 TI_DbgPrint(MIN_TRACE
, ("AddressType: %\n",
163 Address
->Address
[0].AddressType
));
165 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
166 return STATUS_INVALID_PARAMETER
;
169 /* Open address file object */
171 /* Protocol depends on device object so find the protocol */
172 if (DeviceObject
== TCPDeviceObject
)
173 Protocol
= IPPROTO_TCP
;
174 else if (DeviceObject
== UDPDeviceObject
)
175 Protocol
= IPPROTO_UDP
;
176 else if (DeviceObject
== IPDeviceObject
)
177 Protocol
= IPPROTO_RAW
;
178 else if (DeviceObject
== RawIPDeviceObject
) {
179 Status
= TiGetProtocolNumber(&IrpSp
->FileObject
->FileName
, &Protocol
);
180 if (!NT_SUCCESS(Status
)) {
181 TI_DbgPrint(MIN_TRACE
, ("Raw IP protocol number is invalid.\n"));
182 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
183 return STATUS_INVALID_PARAMETER
;
186 TI_DbgPrint(MIN_TRACE
, ("Invalid device object at (0x%X).\n", DeviceObject
));
187 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
188 return STATUS_INVALID_PARAMETER
;
191 Status
= FileOpenAddress(&Request
, Address
, Protocol
, NULL
);
192 if (NT_SUCCESS(Status
)) {
193 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
;
194 Context
->Handle
.AddressHandle
= Request
.Handle
.AddressHandle
;
198 (EaInfo
->EaNameLength
== TDI_CONNECTION_CONTEXT_LENGTH
) &&
200 (&EaInfo
->EaName
, TdiConnectionContext
,
201 TDI_CONNECTION_CONTEXT_LENGTH
) ==
202 TDI_CONNECTION_CONTEXT_LENGTH
)) {
203 /* This is a request to open a connection endpoint */
205 /* Parameter checks */
207 if (EaInfo
->EaValueLength
< sizeof(PVOID
)) {
208 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid.\n"));
209 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
210 return STATUS_INVALID_PARAMETER
;
213 /* Can only do connection oriented communication using TCP */
215 if (DeviceObject
!= TCPDeviceObject
) {
216 TI_DbgPrint(MIN_TRACE
, ("Bad device object.\n"));
217 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
218 return STATUS_INVALID_PARAMETER
;
221 ClientContext
= *((PVOID
*)(EaInfo
->EaName
+ EaInfo
->EaNameLength
));
223 /* Open connection endpoint file object */
225 Status
= FileOpenConnection(&Request
, ClientContext
);
226 if (NT_SUCCESS(Status
)) {
227 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_CONNECTION_FILE
;
228 Context
->Handle
.ConnectionContext
= Request
.Handle
.ConnectionContext
;
231 /* This is a request to open a control connection */
232 Status
= FileOpenControlChannel(&Request
);
233 if (NT_SUCCESS(Status
)) {
234 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_CONTROL_CHANNEL_FILE
;
235 Context
->Handle
.ControlChannel
= Request
.Handle
.ControlChannel
;
239 if (!NT_SUCCESS(Status
))
240 ExFreePoolWithTag(Context
, TRANS_CONTEXT_TAG
);
242 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
244 Irp
->IoStatus
.Status
= Status
;
250 * FUNCTION: Releases resources used by a file object
252 * DeviceObject = Pointer to a device object for this driver
253 * Irp = Pointer to a I/O request packet
255 * Status of the operation
257 * This function does not pend
259 NTSTATUS
TiCloseFileObject(
260 PDEVICE_OBJECT DeviceObject
,
263 PIO_STACK_LOCATION IrpSp
;
264 PTRANSPORT_CONTEXT Context
;
268 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
269 Context
= IrpSp
->FileObject
->FsContext
;
271 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid.\n"));
272 return STATUS_INVALID_PARAMETER
;
275 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
276 case TDI_TRANSPORT_ADDRESS_FILE
:
277 Request
.Handle
.AddressHandle
= Context
->Handle
.AddressHandle
;
278 Status
= FileCloseAddress(&Request
);
281 case TDI_CONNECTION_FILE
:
282 Request
.Handle
.ConnectionContext
= Context
->Handle
.ConnectionContext
;
283 Status
= FileCloseConnection(&Request
);
286 case TDI_CONTROL_CHANNEL_FILE
:
287 Request
.Handle
.ControlChannel
= Context
->Handle
.ControlChannel
;
288 Status
= FileCloseControlChannel(&Request
);
292 DbgPrint("Unknown type %d\n", (ULONG_PTR
)IrpSp
->FileObject
->FsContext2
);
293 Status
= STATUS_INVALID_PARAMETER
;
297 Irp
->IoStatus
.Status
= Status
;
299 return Irp
->IoStatus
.Status
;
305 IN PDEVICE_OBJECT DeviceObject
,
308 * FUNCTION: Main dispath routine
310 * DeviceObject = Pointer to a device object for this driver
311 * Irp = Pointer to a I/O request packet
313 * Status of the operation
316 PIO_STACK_LOCATION IrpSp
;
319 // DbgPrint("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp);
321 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
323 switch (IrpSp
->MajorFunction
) {
324 /* Open an address file, connection endpoint, or control connection */
326 Status
= TiCreateFileObject(DeviceObject
, Irp
);
329 /* Close an address file, connection endpoint, or control connection */
331 Status
= TiCloseFileObject(DeviceObject
, Irp
);
335 Status
= STATUS_INVALID_DEVICE_REQUEST
;
338 //DbgPrint("Leaving. Status is (0x%X)\n", Status);
340 return IRPFinish( Irp
, Status
);
346 PDEVICE_OBJECT DeviceObject
,
349 * FUNCTION: Internal IOCTL dispatch routine
351 * DeviceObject = Pointer to a device object for this driver
352 * Irp = Pointer to a I/O request packet
354 * Status of the operation
358 BOOLEAN Complete
= TRUE
;
359 PIO_STACK_LOCATION IrpSp
;
361 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
363 TI_DbgPrint(DEBUG_IRP
, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
364 DeviceObject
, Irp
, IrpSp
->MinorFunction
));
366 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
367 Irp
->IoStatus
.Information
= 0;
369 switch (IrpSp
->MinorFunction
) {
371 Status
= DispTdiReceive(Irp
);
375 case TDI_RECEIVE_DATAGRAM
:
376 Status
= DispTdiReceiveDatagram(Irp
);
381 Status
= DispTdiSend(Irp
);
382 Complete
= FALSE
; /* Completed in DispTdiSend */
385 case TDI_SEND_DATAGRAM
:
386 Status
= DispTdiSendDatagram(Irp
);
391 Status
= DispTdiAccept(Irp
);
395 Status
= DispTdiListen(Irp
);
400 Status
= DispTdiConnect(Irp
);
401 Complete
= FALSE
; /* Completed by the TCP event handler */
405 Status
= DispTdiDisconnect(Irp
);
409 case TDI_ASSOCIATE_ADDRESS
:
410 Status
= DispTdiAssociateAddress(Irp
);
413 case TDI_DISASSOCIATE_ADDRESS
:
414 Status
= DispTdiDisassociateAddress(Irp
);
417 case TDI_QUERY_INFORMATION
:
418 Status
= DispTdiQueryInformation(DeviceObject
, Irp
);
421 case TDI_SET_INFORMATION
:
422 Status
= DispTdiSetInformation(Irp
);
425 case TDI_SET_EVENT_HANDLER
:
426 Status
= DispTdiSetEventHandler(Irp
);
430 Status
= STATUS_SUCCESS
;
433 /* An unsupported IOCTL code was submitted */
435 Status
= STATUS_INVALID_DEVICE_REQUEST
;
438 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
441 IRPFinish( Irp
, Status
);
449 PDEVICE_OBJECT DeviceObject
,
452 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
454 * DeviceObject = Pointer to a device object for this driver
455 * Irp = Pointer to a I/O request packet
457 * Status of the operation
461 PIO_STACK_LOCATION IrpSp
;
463 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
465 TI_DbgPrint(DEBUG_IRP
, ("Called. IRP is at (0x%X).\n", Irp
));
467 Irp
->IoStatus
.Information
= 0;
470 Status
= TdiMapUserRequest(DeviceObject
, Irp
, IrpSp
);
471 if (NT_SUCCESS(Status
)) {
472 TiDispatchInternal(DeviceObject
, Irp
);
473 Status
= STATUS_PENDING
;
478 /* See if this request is TCP/IP specific */
479 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
480 case IOCTL_TCP_QUERY_INFORMATION_EX
:
481 TI_DbgPrint(MIN_TRACE
, ("TCP_QUERY_INFORMATION_EX\n"));
482 Status
= DispTdiQueryInformationEx(Irp
, IrpSp
);
485 case IOCTL_TCP_SET_INFORMATION_EX
:
486 TI_DbgPrint(MIN_TRACE
, ("TCP_SET_INFORMATION_EX\n"));
487 Status
= DispTdiSetInformationEx(Irp
, IrpSp
);
490 case IOCTL_SET_IP_ADDRESS
:
491 TI_DbgPrint(MIN_TRACE
, ("SET_IP_ADDRESS\n"));
492 Status
= DispTdiSetIPAddress(Irp
, IrpSp
);
495 case IOCTL_DELETE_IP_ADDRESS
:
496 TI_DbgPrint(MIN_TRACE
, ("DELETE_IP_ADDRESS\n"));
497 Status
= DispTdiDeleteIPAddress(Irp
, IrpSp
);
501 TI_DbgPrint(MIN_TRACE
, ("Unknown IOCTL 0x%X\n",
502 IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
));
503 Status
= STATUS_NOT_IMPLEMENTED
;
508 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
510 return IRPFinish( Irp
, Status
);
515 PDRIVER_OBJECT DriverObject
)
517 * FUNCTION: Unloads the driver
519 * DriverObject = Pointer to driver object created by the system
525 TcpipAcquireSpinLock(&AddressFileListLock
, &OldIrql
);
526 if (!IsListEmpty(&AddressFileListHead
)) {
527 TI_DbgPrint(MIN_TRACE
, ("Open address file objects exists.\n"));
529 TcpipReleaseSpinLock(&AddressFileListLock
, OldIrql
);
532 KeCancelTimer(&IPTimer
);
534 /* Unregister loopback adapter */
535 LoopUnregisterAdapter(NULL
);
537 /* Unregister protocol with NDIS */
538 LANUnregisterProtocol();
540 /* Shutdown transport level protocol subsystems */
546 /* Shutdown network level protocol subsystem */
549 /* Free NDIS buffer descriptors */
550 if (GlobalBufferPool
)
551 NdisFreeBufferPool(GlobalBufferPool
);
553 /* Free NDIS packet descriptors */
554 if (GlobalPacketPool
)
555 NdisFreePacketPool(GlobalPacketPool
);
557 /* Release all device objects */
560 IoDeleteDevice(TCPDeviceObject
);
563 IoDeleteDevice(UDPDeviceObject
);
565 if (RawIPDeviceObject
)
566 IoDeleteDevice(RawIPDeviceObject
);
568 if (IPDeviceObject
) {
570 IoDeleteDevice(IPDeviceObject
);
574 ExFreePoolWithTag(EntityList
, TDI_ENTITY_TAG
);
576 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
581 PDRIVER_OBJECT DriverObject
,
582 PUNICODE_STRING RegistryPath
)
584 * FUNCTION: Main driver entry point
586 * DriverObject = Pointer to a driver object for this driver
587 * RegistryPath = Registry node for configuration parameters
589 * Status of driver initialization
593 UNICODE_STRING strIpDeviceName
= RTL_CONSTANT_STRING(DD_IP_DEVICE_NAME
);
594 UNICODE_STRING strRawDeviceName
= RTL_CONSTANT_STRING(DD_RAWIP_DEVICE_NAME
);
595 UNICODE_STRING strUdpDeviceName
= RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME
);
596 UNICODE_STRING strTcpDeviceName
= RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME
);
597 UNICODE_STRING strNdisDeviceName
= RTL_CONSTANT_STRING(TCPIP_PROTOCOL_NAME
);
598 NDIS_STATUS NdisStatus
;
599 LARGE_INTEGER DueTime
;
601 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
603 /* TdiInitialize() ? */
605 /* FIXME: Create symbolic links in Win32 namespace */
607 /* Initialize our periodic timer and its associated DPC object. When the
608 timer expires, the IPTimeout deferred procedure call (DPC) is queued */
609 KeInitializeDpc(&IPTimeoutDpc
, IPTimeoutDpcFn
, NULL
);
610 KeInitializeTimer(&IPTimer
);
612 /* Create IP device object */
613 Status
= IoCreateDevice(DriverObject
, 0, &strIpDeviceName
,
614 FILE_DEVICE_NETWORK
, 0, FALSE
, &IPDeviceObject
);
615 if (!NT_SUCCESS(Status
)) {
616 TI_DbgPrint(MIN_TRACE
, ("Failed to create IP device object. Status (0x%X).\n", Status
));
617 TiUnload(DriverObject
);
621 ChewInit( IPDeviceObject
);
623 /* Create RawIP device object */
624 Status
= IoCreateDevice(DriverObject
, 0, &strRawDeviceName
,
625 FILE_DEVICE_NETWORK
, 0, FALSE
, &RawIPDeviceObject
);
626 if (!NT_SUCCESS(Status
)) {
627 TI_DbgPrint(MIN_TRACE
, ("Failed to create RawIP device object. Status (0x%X).\n", Status
));
628 TiUnload(DriverObject
);
632 /* Create UDP device object */
633 Status
= IoCreateDevice(DriverObject
, 0, &strUdpDeviceName
,
634 FILE_DEVICE_NETWORK
, 0, FALSE
, &UDPDeviceObject
);
635 if (!NT_SUCCESS(Status
)) {
636 TI_DbgPrint(MIN_TRACE
, ("Failed to create UDP device object. Status (0x%X).\n", Status
));
637 TiUnload(DriverObject
);
641 /* Create TCP device object */
642 Status
= IoCreateDevice(DriverObject
, 0, &strTcpDeviceName
,
643 FILE_DEVICE_NETWORK
, 0, FALSE
, &TCPDeviceObject
);
644 if (!NT_SUCCESS(Status
)) {
645 TI_DbgPrint(MIN_TRACE
, ("Failed to create TCP device object. Status (0x%X).\n", Status
));
646 TiUnload(DriverObject
);
650 /* Setup network layer and transport layer entities */
651 KeInitializeSpinLock(&EntityListLock
);
652 EntityList
= ExAllocatePoolWithTag(NonPagedPool
,
653 sizeof(TDIEntityID
) * MAX_TDI_ENTITIES
,
656 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
657 TiUnload(DriverObject
);
658 return STATUS_INSUFFICIENT_RESOURCES
;
662 EntityMax
= MAX_TDI_ENTITIES
;
664 /* Allocate NDIS packet descriptors */
665 NdisAllocatePacketPool(&NdisStatus
, &GlobalPacketPool
, 100, sizeof(PACKET_CONTEXT
));
666 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
667 TiUnload(DriverObject
);
668 return STATUS_INSUFFICIENT_RESOURCES
;
671 /* Allocate NDIS buffer descriptors */
672 NdisAllocateBufferPool(&NdisStatus
, &GlobalBufferPool
, 100);
673 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
674 TiUnload(DriverObject
);
675 return STATUS_INSUFFICIENT_RESOURCES
;
678 /* Initialize address file list and protecting spin lock */
679 InitializeListHead(&AddressFileListHead
);
680 KeInitializeSpinLock(&AddressFileListLock
);
682 /* Initialize connection endpoint list and protecting spin lock */
683 InitializeListHead(&ConnectionEndpointListHead
);
684 KeInitializeSpinLock(&ConnectionEndpointListLock
);
686 /* Initialize interface list and protecting spin lock */
687 InitializeListHead(&InterfaceListHead
);
688 KeInitializeSpinLock(&InterfaceListLock
);
690 /* Initialize network level protocol subsystem */
691 IPStartup(RegistryPath
);
693 /* Initialize transport level protocol subsystems */
694 Status
= RawIPStartup();
695 if( !NT_SUCCESS(Status
) ) {
696 TiUnload(DriverObject
);
700 Status
= UDPStartup();
701 if( !NT_SUCCESS(Status
) ) {
702 TiUnload(DriverObject
);
706 Status
= TCPStartup();
707 if( !NT_SUCCESS(Status
) ) {
708 TiUnload(DriverObject
);
712 Status
= ICMPStartup();
713 if( !NT_SUCCESS(Status
) ) {
714 TiUnload(DriverObject
);
719 IPDeviceObject
->Flags
|= DO_DIRECT_IO
;
720 RawIPDeviceObject
->Flags
|= DO_DIRECT_IO
;
721 UDPDeviceObject
->Flags
|= DO_DIRECT_IO
;
722 TCPDeviceObject
->Flags
|= DO_DIRECT_IO
;
724 /* Initialize the driver object with this driver's entry points */
725 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = TiDispatchOpenClose
;
726 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = TiDispatchOpenClose
;
727 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = TiDispatchInternal
;
728 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = TiDispatch
;
730 DriverObject
->DriverUnload
= TiUnload
;
732 /* Open loopback adapter */
733 Status
= LoopRegisterAdapter(NULL
, NULL
);
734 if (!NT_SUCCESS(Status
)) {
735 TI_DbgPrint(MIN_TRACE
, ("Failed to create loopback adapter. Status (0x%X).\n", Status
));
736 TiUnload(DriverObject
);
740 /* Register protocol with NDIS */
741 /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
742 Status
= LANRegisterProtocol(&strNdisDeviceName
);
743 if (!NT_SUCCESS(Status
)) {
744 TI_DbgPrint(MIN_TRACE
,("Failed to register protocol with NDIS; status 0x%x\n", Status
));
747 EVENT_TRANSPORT_REGISTER_FAILED
,
748 TI_ERROR_DRIVERENTRY
,
753 TiUnload(DriverObject
);
757 /* Start the periodic timer with an initial and periodic
758 relative expiration time of IP_TIMEOUT milliseconds */
759 DueTime
.QuadPart
= -(LONGLONG
)IP_TIMEOUT
* 10000;
760 KeSetTimerEx(&IPTimer
, DueTime
, IP_TIMEOUT
, &IPTimeoutDpc
);
762 return STATUS_SUCCESS
;