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
;
27 KSPIN_LOCK IpWorkLock
;
28 WORK_QUEUE_ITEM IpWorkItem
;
31 PDRIVER_OBJECT DriverContext
,
33 ULONG UniqueErrorValue
,
39 * FUNCTION: Writes an error log entry
41 * DriverContext = Pointer to the driver or device object
42 * ErrorCode = An error code to put in the log entry
43 * UniqueErrorValue = UniqueErrorValue in the error log packet
44 * FinalStatus = FinalStatus in the error log packet
45 * String = If not NULL, a pointer to a string to put in log
47 * DumpDataCount = Number of ULONGs of dump data
48 * DumpData = Pointer to dump data for the log entry
52 PIO_ERROR_LOG_PACKET LogEntry
;
56 static WCHAR DriverName
[] = L
"TCP/IP";
58 EntrySize
= sizeof(IO_ERROR_LOG_PACKET
) +
59 (DumpDataCount
* sizeof(ULONG
)) + sizeof(DriverName
);
62 StringSize
= (wcslen(String
) * sizeof(WCHAR
)) + sizeof(UNICODE_NULL
);
63 EntrySize
+= (UCHAR
)StringSize
;
66 LogEntry
= (PIO_ERROR_LOG_PACKET
)IoAllocateErrorLogEntry(
67 DriverContext
, EntrySize
);
70 LogEntry
->MajorFunctionCode
= -1;
71 LogEntry
->RetryCount
= -1;
72 LogEntry
->DumpDataSize
= (USHORT
)(DumpDataCount
* sizeof(ULONG
));
73 LogEntry
->NumberOfStrings
= (String
== NULL
) ? 1 : 2;
74 LogEntry
->StringOffset
= sizeof(IO_ERROR_LOG_PACKET
) + (DumpDataCount
-1) * sizeof(ULONG
);
75 LogEntry
->EventCategory
= 0;
76 LogEntry
->ErrorCode
= ErrorCode
;
77 LogEntry
->UniqueErrorValue
= UniqueErrorValue
;
78 LogEntry
->FinalStatus
= FinalStatus
;
79 LogEntry
->SequenceNumber
= -1;
80 LogEntry
->IoControlCode
= 0;
83 RtlCopyMemory(LogEntry
->DumpData
, DumpData
, DumpDataCount
* sizeof(ULONG
));
85 pString
= ((PUCHAR
)LogEntry
) + LogEntry
->StringOffset
;
86 RtlCopyMemory(pString
, DriverName
, sizeof(DriverName
));
87 pString
+= sizeof(DriverName
);
90 RtlCopyMemory(pString
, String
, StringSize
);
92 IoWriteErrorLogEntry(LogEntry
);
98 * FUNCTION: Creates a file object
100 * DeviceObject = Pointer to a device object for this driver
101 * Irp = Pointer to a I/O request packet
103 * Status of the operation
106 NTSTATUS
TiCreateFileObject(
107 PDEVICE_OBJECT DeviceObject
,
110 PFILE_FULL_EA_INFORMATION EaInfo
;
111 PTRANSPORT_CONTEXT Context
;
112 PIO_STACK_LOCATION IrpSp
;
113 PTA_IP_ADDRESS Address
;
119 TI_DbgPrint(DEBUG_IRP
, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject
, Irp
));
121 EaInfo
= Irp
->AssociatedIrp
.SystemBuffer
;
123 /* Parameter check */
124 /* No EA information means that we're opening for SET/QUERY_INFORMATION
128 TI_DbgPrint(MIN_TRACE
, ("No EA information in IRP.\n"));
129 return STATUS_INVALID_PARAMETER
;
133 /* Allocate resources here. We release them again if something failed */
134 Context
= ExAllocatePool(NonPagedPool
, sizeof(TRANSPORT_CONTEXT
));
136 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
137 return STATUS_INSUFFICIENT_RESOURCES
;
140 Context
->CancelIrps
= FALSE
;
142 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
143 IrpSp
->FileObject
->FsContext
= Context
;
144 Request
.RequestContext
= Irp
;
146 /* Branch to the right handler */
148 (EaInfo
->EaNameLength
== TDI_TRANSPORT_ADDRESS_LENGTH
) &&
150 (&EaInfo
->EaName
, TdiTransportAddress
,
151 TDI_TRANSPORT_ADDRESS_LENGTH
) == TDI_TRANSPORT_ADDRESS_LENGTH
)) {
152 /* This is a request to open an address */
155 /* XXX This should probably be done in IoCreateFile() */
156 /* Parameter checks */
158 Address
= (PTA_IP_ADDRESS
)(EaInfo
->EaName
+ EaInfo
->EaNameLength
+ 1); //0-term
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 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid:\n"));
165 TI_DbgPrint(MIN_TRACE
, ("AddressCount: %d\n", Address
->TAAddressCount
));
166 if( Address
->TAAddressCount
== 1 ) {
167 TI_DbgPrint(MIN_TRACE
, ("AddressLength: %\n",
168 Address
->Address
[0].AddressLength
));
169 TI_DbgPrint(MIN_TRACE
, ("AddressType: %\n",
170 Address
->Address
[0].AddressType
));
172 PoolFreeBuffer(Context
);
173 return STATUS_INVALID_PARAMETER
;
176 /* Open address file object */
178 /* Protocol depends on device object so find the protocol */
179 if (DeviceObject
== TCPDeviceObject
)
180 Protocol
= IPPROTO_TCP
;
181 else if (DeviceObject
== UDPDeviceObject
)
182 Protocol
= IPPROTO_UDP
;
183 else if (DeviceObject
== IPDeviceObject
)
184 Protocol
= IPPROTO_RAW
;
185 else if (DeviceObject
== RawIPDeviceObject
) {
186 Status
= TiGetProtocolNumber(&IrpSp
->FileObject
->FileName
, &Protocol
);
187 if (!NT_SUCCESS(Status
)) {
188 TI_DbgPrint(MIN_TRACE
, ("Raw IP protocol number is invalid.\n"));
189 PoolFreeBuffer(Context
);
190 return STATUS_INVALID_PARAMETER
;
193 TI_DbgPrint(MIN_TRACE
, ("Invalid device object at (0x%X).\n", DeviceObject
));
194 PoolFreeBuffer(Context
);
195 return STATUS_INVALID_PARAMETER
;
198 Status
= FileOpenAddress(&Request
, Address
, Protocol
, NULL
);
199 if (NT_SUCCESS(Status
)) {
200 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_TRANSPORT_ADDRESS_FILE
;
201 Context
->Handle
.AddressHandle
= Request
.Handle
.AddressHandle
;
205 (EaInfo
->EaNameLength
== TDI_CONNECTION_CONTEXT_LENGTH
) &&
207 (&EaInfo
->EaName
, TdiConnectionContext
,
208 TDI_CONNECTION_CONTEXT_LENGTH
) ==
209 TDI_CONNECTION_CONTEXT_LENGTH
)) {
210 /* This is a request to open a connection endpoint */
212 /* Parameter checks */
214 if (EaInfo
->EaValueLength
< sizeof(PVOID
)) {
215 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid.\n"));
216 PoolFreeBuffer(Context
);
217 return STATUS_INVALID_PARAMETER
;
220 /* Can only do connection oriented communication using TCP */
222 if (DeviceObject
!= TCPDeviceObject
) {
223 TI_DbgPrint(MIN_TRACE
, ("Bad device object.\n"));
224 PoolFreeBuffer(Context
);
225 return STATUS_INVALID_PARAMETER
;
228 ClientContext
= *((PVOID
*)(EaInfo
->EaName
+ EaInfo
->EaNameLength
));
230 /* Open connection endpoint file object */
232 Status
= FileOpenConnection(&Request
, ClientContext
);
233 if (NT_SUCCESS(Status
)) {
234 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_CONNECTION_FILE
;
235 Context
->Handle
.ConnectionContext
= Request
.Handle
.ConnectionContext
;
238 /* This is a request to open a control connection */
239 Status
= FileOpenControlChannel(&Request
);
240 if (NT_SUCCESS(Status
)) {
241 IrpSp
->FileObject
->FsContext2
= (PVOID
)TDI_CONTROL_CHANNEL_FILE
;
242 Context
->Handle
.ControlChannel
= Request
.Handle
.ControlChannel
;
246 if (!NT_SUCCESS(Status
))
247 PoolFreeBuffer(Context
);
249 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
251 Irp
->IoStatus
.Status
= Status
;
256 VOID
TiCleanupFileObjectComplete(
260 * FUNCTION: Completes an object cleanup IRP I/O request
262 * Context = Pointer to the IRP for this request
263 * Status = Final status of the operation
267 PIO_STACK_LOCATION IrpSp
;
270 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
272 Irp
->IoStatus
.Status
= Status
;
277 * FUNCTION: Releases resources used by a file object
279 * DeviceObject = Pointer to a device object for this driver
280 * Irp = Pointer to a I/O request packet
282 * Status of the operation
284 * This function does not pend
286 NTSTATUS
TiCleanupFileObject(
287 PDEVICE_OBJECT DeviceObject
,
290 PIO_STACK_LOCATION IrpSp
;
291 PTRANSPORT_CONTEXT Context
;
296 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
297 Context
= IrpSp
->FileObject
->FsContext
;
299 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid.\n"));
300 return STATUS_INVALID_PARAMETER
;
303 IoAcquireCancelSpinLock(&OldIrql
);
305 Context
->CancelIrps
= TRUE
;
307 IoReleaseCancelSpinLock(OldIrql
);
309 Request
.RequestNotifyObject
= TiCleanupFileObjectComplete
;
310 Request
.RequestContext
= Irp
;
312 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
313 case TDI_TRANSPORT_ADDRESS_FILE
:
314 Request
.Handle
.AddressHandle
= Context
->Handle
.AddressHandle
;
315 Status
= FileCloseAddress(&Request
);
318 case TDI_CONNECTION_FILE
:
319 Request
.Handle
.ConnectionContext
= Context
->Handle
.ConnectionContext
;
320 Status
= FileCloseConnection(&Request
);
323 case TDI_CONTROL_CHANNEL_FILE
:
324 Request
.Handle
.ControlChannel
= Context
->Handle
.ControlChannel
;
325 Status
= FileCloseControlChannel(&Request
);
329 /* This should never happen */
331 TI_DbgPrint(MIN_TRACE
, ("Unknown transport context.\n"));
333 IoAcquireCancelSpinLock(&OldIrql
);
334 Context
->CancelIrps
= FALSE
;
335 IoReleaseCancelSpinLock(OldIrql
);
337 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
339 return Irp
->IoStatus
.Status
;
342 Irp
->IoStatus
.Status
= Status
;
344 return Irp
->IoStatus
.Status
;
350 IN PDEVICE_OBJECT DeviceObject
,
353 * FUNCTION: Main dispath routine
355 * DeviceObject = Pointer to a device object for this driver
356 * Irp = Pointer to a I/O request packet
358 * Status of the operation
361 PIO_STACK_LOCATION IrpSp
;
363 PTRANSPORT_CONTEXT Context
;
367 // DbgPrint("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp);
369 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
371 switch (IrpSp
->MajorFunction
) {
372 /* Open an address file, connection endpoint, or control connection */
374 Status
= TiCreateFileObject(DeviceObject
, Irp
);
377 /* Close an address file, connection endpoint, or control connection */
379 Context
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
381 PoolFreeBuffer(Context
);
382 Status
= STATUS_SUCCESS
;
385 /* Release resources bound to an address file, connection endpoint,
386 or control connection */
388 Status
= TiCleanupFileObject(DeviceObject
, Irp
);
392 Status
= STATUS_INVALID_DEVICE_REQUEST
;
395 //DbgPrint("Leaving. Status is (0x%X)\n", Status);
397 return IRPFinish( Irp
, Status
);
403 PDEVICE_OBJECT DeviceObject
,
406 * FUNCTION: Internal IOCTL dispatch routine
408 * DeviceObject = Pointer to a device object for this driver
409 * Irp = Pointer to a I/O request packet
411 * Status of the operation
415 BOOL Complete
= TRUE
;
416 PIO_STACK_LOCATION IrpSp
;
420 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
422 TI_DbgPrint(DEBUG_IRP
, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
423 DeviceObject
, Irp
, IrpSp
->MinorFunction
));
425 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
426 Irp
->IoStatus
.Information
= 0;
428 switch (IrpSp
->MinorFunction
) {
430 Status
= DispTdiReceive(Irp
);
434 case TDI_RECEIVE_DATAGRAM
:
435 Status
= DispTdiReceiveDatagram(Irp
);
440 Status
= DispTdiSend(Irp
);
441 Complete
= FALSE
; /* Completed in DispTdiSend */
444 case TDI_SEND_DATAGRAM
:
445 Status
= DispTdiSendDatagram(Irp
);
450 Status
= DispTdiAccept(Irp
);
454 Status
= DispTdiListen(Irp
);
459 Status
= DispTdiConnect(Irp
);
460 Complete
= FALSE
; /* Completed by the TCP event handler */
464 Status
= DispTdiDisconnect(Irp
);
467 case TDI_ASSOCIATE_ADDRESS
:
468 Status
= DispTdiAssociateAddress(Irp
);
471 case TDI_DISASSOCIATE_ADDRESS
:
472 Status
= DispTdiDisassociateAddress(Irp
);
475 case TDI_QUERY_INFORMATION
:
476 Status
= DispTdiQueryInformation(DeviceObject
, Irp
);
479 case TDI_SET_INFORMATION
:
480 Status
= DispTdiSetInformation(Irp
);
483 case TDI_SET_EVENT_HANDLER
:
484 Status
= DispTdiSetEventHandler(Irp
);
488 Status
= STATUS_SUCCESS
;
491 /* An unsupported IOCTL code was submitted */
493 Status
= STATUS_INVALID_DEVICE_REQUEST
;
496 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
499 IRPFinish( Irp
, Status
);
501 Irp
->IoStatus
.Status
= Status
;
509 PDEVICE_OBJECT DeviceObject
,
512 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
514 * DeviceObject = Pointer to a device object for this driver
515 * Irp = Pointer to a I/O request packet
517 * Status of the operation
521 PIO_STACK_LOCATION IrpSp
;
525 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
527 TI_DbgPrint(DEBUG_IRP
, ("Called. IRP is at (0x%X).\n", Irp
));
529 Irp
->IoStatus
.Information
= 0;
532 Status
= TdiMapUserRequest(DeviceObject
, Irp
, IrpSp
);
533 if (NT_SUCCESS(Status
)) {
534 TiDispatchInternal(DeviceObject
, Irp
);
535 Status
= STATUS_PENDING
;
540 /* See if this request is TCP/IP specific */
541 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
542 case IOCTL_TCP_QUERY_INFORMATION_EX
:
543 TI_DbgPrint(MIN_TRACE
, ("TCP_QUERY_INFORMATION_EX\n"));
544 Status
= DispTdiQueryInformationEx(Irp
, IrpSp
);
547 case IOCTL_TCP_SET_INFORMATION_EX
:
548 TI_DbgPrint(MIN_TRACE
, ("TCP_SET_INFORMATION_EX\n"));
549 Status
= DispTdiSetInformationEx(Irp
, IrpSp
);
552 case IOCTL_SET_IP_ADDRESS
:
553 TI_DbgPrint(MIN_TRACE
, ("SET_IP_ADDRESS\n"));
554 Status
= DispTdiSetIPAddress(Irp
, IrpSp
);
557 case IOCTL_DELETE_IP_ADDRESS
:
558 TI_DbgPrint(MIN_TRACE
, ("DELETE_IP_ADDRESS\n"));
559 Status
= DispTdiDeleteIPAddress(Irp
, IrpSp
);
563 TI_DbgPrint(MIN_TRACE
, ("Unknown IOCTL 0x%X\n",
564 IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
));
565 Status
= STATUS_NOT_IMPLEMENTED
;
570 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
572 return IRPFinish( Irp
, Status
);
576 VOID STDCALL
TiUnload(
577 PDRIVER_OBJECT DriverObject
)
579 * FUNCTION: Unloads the driver
581 * DriverObject = Pointer to driver object created by the system
587 TcpipAcquireSpinLock(&AddressFileListLock
, &OldIrql
);
588 if (!IsListEmpty(&AddressFileListHead
)) {
589 TI_DbgPrint(MIN_TRACE
, ("Open address file objects exists.\n"));
591 TcpipReleaseSpinLock(&AddressFileListLock
, OldIrql
);
596 KeCancelTimer(&IPTimer
);
598 /* Unregister loopback adapter */
599 LoopUnregisterAdapter(NULL
);
601 /* Unregister protocol with NDIS */
602 LANUnregisterProtocol();
604 /* Shutdown transport level protocol subsystems */
609 /* Shutdown network level protocol subsystem */
612 /* Shutdown the lan worker */
615 /* Free NDIS buffer descriptors */
616 if (GlobalBufferPool
)
617 NdisFreeBufferPool(GlobalBufferPool
);
619 /* Free NDIS packet descriptors */
620 if (GlobalPacketPool
)
621 NdisFreePacketPool(GlobalPacketPool
);
623 /* Release all device objects */
626 IoDeleteDevice(TCPDeviceObject
);
629 IoDeleteDevice(UDPDeviceObject
);
631 if (RawIPDeviceObject
)
632 IoDeleteDevice(RawIPDeviceObject
);
635 IoDeleteDevice(IPDeviceObject
);
638 PoolFreeBuffer(EntityList
);
640 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
643 VOID STDCALL
IPTimeoutDpcFn(
645 PVOID DeferredContext
,
646 PVOID SystemArgument1
,
647 PVOID SystemArgument2
)
649 * FUNCTION: Timeout DPC
651 * Dpc = Pointer to our DPC object
652 * DeferredContext = Pointer to context information (unused)
653 * SystemArgument1 = Unused
654 * SystemArgument2 = Unused
656 * This routine is dispatched once in a while to do maintainance jobs
659 if( !IpWorkItemQueued
) {
660 ExQueueWorkItem( &IpWorkItem
, CriticalWorkQueue
);
661 IpWorkItemQueued
= TRUE
;
667 PDRIVER_OBJECT DriverObject
,
668 PUNICODE_STRING RegistryPath
)
670 * FUNCTION: Main driver entry point
672 * DriverObject = Pointer to a driver object for this driver
673 * RegistryPath = Registry node for configuration parameters
675 * Status of driver initialization
679 UNICODE_STRING strIpDeviceName
= RTL_CONSTANT_STRING(DD_IP_DEVICE_NAME
);
680 UNICODE_STRING strRawDeviceName
= RTL_CONSTANT_STRING(DD_RAWIP_DEVICE_NAME
);
681 UNICODE_STRING strUdpDeviceName
= RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME
);
682 UNICODE_STRING strTcpDeviceName
= RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME
);
683 UNICODE_STRING strNdisDeviceName
= RTL_CONSTANT_STRING(TCPIP_PROTOCOL_NAME
);
684 NDIS_STATUS NdisStatus
;
685 LARGE_INTEGER DueTime
;
687 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
690 TrackTag(NDIS_BUFFER_TAG
);
691 TrackTag(NDIS_PACKET_TAG
);
692 TrackTag(FBSD_MALLOC
);
693 TrackTag(EXALLOC_TAG
);
695 /* TdiInitialize() ? */
697 /* FIXME: Create symbolic links in Win32 namespace */
699 /* Create IP device object */
700 Status
= IoCreateDevice(DriverObject
, 0, &strIpDeviceName
,
701 FILE_DEVICE_NETWORK
, 0, FALSE
, &IPDeviceObject
);
702 if (!NT_SUCCESS(Status
)) {
703 TI_DbgPrint(MIN_TRACE
, ("Failed to create IP device object. Status (0x%X).\n", Status
));
707 ChewInit( IPDeviceObject
);
709 /* Create RawIP device object */
710 Status
= IoCreateDevice(DriverObject
, 0, &strRawDeviceName
,
711 FILE_DEVICE_NETWORK
, 0, FALSE
, &RawIPDeviceObject
);
712 if (!NT_SUCCESS(Status
)) {
713 TI_DbgPrint(MIN_TRACE
, ("Failed to create RawIP device object. Status (0x%X).\n", Status
));
714 TiUnload(DriverObject
);
718 /* Create UDP device object */
719 Status
= IoCreateDevice(DriverObject
, 0, &strUdpDeviceName
,
720 FILE_DEVICE_NETWORK
, 0, FALSE
, &UDPDeviceObject
);
721 if (!NT_SUCCESS(Status
)) {
722 TI_DbgPrint(MIN_TRACE
, ("Failed to create UDP device object. Status (0x%X).\n", Status
));
723 TiUnload(DriverObject
);
727 /* Create TCP device object */
728 Status
= IoCreateDevice(DriverObject
, 0, &strTcpDeviceName
,
729 FILE_DEVICE_NETWORK
, 0, FALSE
, &TCPDeviceObject
);
730 if (!NT_SUCCESS(Status
)) {
731 TI_DbgPrint(MIN_TRACE
, ("Failed to create TCP device object. Status (0x%X).\n", Status
));
732 TiUnload(DriverObject
);
736 /* Setup network layer and transport layer entities */
737 KeInitializeSpinLock(&EntityListLock
);
738 EntityList
= ExAllocatePool(NonPagedPool
, sizeof(TDIEntityID
) * MAX_TDI_ENTITIES
);
739 if (!NT_SUCCESS(Status
)) {
740 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
741 TiUnload(DriverObject
);
742 return STATUS_INSUFFICIENT_RESOURCES
;
745 EntityList
[0].tei_entity
= CL_NL_ENTITY
;
746 EntityList
[0].tei_instance
= 0;
747 EntityList
[0].context
= 0;
748 EntityList
[0].info_req
= InfoNetworkLayerTdiQueryEx
;
749 EntityList
[0].info_set
= InfoNetworkLayerTdiSetEx
;
750 EntityList
[1].tei_entity
= CL_TL_ENTITY
;
751 EntityList
[1].tei_instance
= 0;
752 EntityList
[1].context
= 0;
753 EntityList
[1].info_req
= InfoTransportLayerTdiQueryEx
;
754 EntityList
[1].info_set
= InfoTransportLayerTdiSetEx
;
756 EntityMax
= MAX_TDI_ENTITIES
;
758 /* Allocate NDIS packet descriptors */
759 NdisAllocatePacketPool(&NdisStatus
, &GlobalPacketPool
, 100, sizeof(PACKET_CONTEXT
));
760 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
761 TiUnload(DriverObject
);
762 return STATUS_INSUFFICIENT_RESOURCES
;
765 /* Allocate NDIS buffer descriptors */
766 NdisAllocateBufferPool(&NdisStatus
, &GlobalBufferPool
, 100);
767 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
768 TiUnload(DriverObject
);
769 return STATUS_INSUFFICIENT_RESOURCES
;
772 /* Initialize address file list and protecting spin lock */
773 InitializeListHead(&AddressFileListHead
);
774 KeInitializeSpinLock(&AddressFileListLock
);
776 /* Initialize connection endpoint list and protecting spin lock */
777 InitializeListHead(&ConnectionEndpointListHead
);
778 KeInitializeSpinLock(&ConnectionEndpointListLock
);
780 /* Initialize interface list and protecting spin lock */
781 InitializeListHead(&InterfaceListHead
);
782 KeInitializeSpinLock(&InterfaceListLock
);
784 /* Initialize network level protocol subsystem */
785 IPStartup(RegistryPath
);
787 /* Initialize transport level protocol subsystems */
792 /* Initialize the lan worker */
795 /* Register protocol with NDIS */
796 /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
797 Status
= LANRegisterProtocol(&strNdisDeviceName
);
798 if (!NT_SUCCESS(Status
)) {
799 TI_DbgPrint(MIN_TRACE
,("Failed to register protocol with NDIS; status 0x%x\n", Status
));
802 EVENT_TRANSPORT_REGISTER_FAILED
,
803 TI_ERROR_DRIVERENTRY
,
808 TiUnload(DriverObject
);
812 /* Open loopback adapter */
813 if (!NT_SUCCESS(LoopRegisterAdapter(NULL
, NULL
))) {
814 TI_DbgPrint(MIN_TRACE
, ("Failed to create loopback adapter. Status (0x%X).\n", Status
));
815 TiUnload(DriverObject
);
816 return STATUS_INSUFFICIENT_RESOURCES
;
820 IPDeviceObject
->Flags
|= DO_DIRECT_IO
;
821 RawIPDeviceObject
->Flags
|= DO_DIRECT_IO
;
822 UDPDeviceObject
->Flags
|= DO_DIRECT_IO
;
823 TCPDeviceObject
->Flags
|= DO_DIRECT_IO
;
825 /* Initialize the driver object with this driver's entry points */
826 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = TiDispatchOpenClose
;
827 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = TiDispatchOpenClose
;
828 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = TiDispatchOpenClose
;
829 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = TiDispatchInternal
;
830 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = TiDispatch
;
832 DriverObject
->DriverUnload
= TiUnload
;
834 /* Initialize our periodic timer and its associated DPC object. When the
835 timer expires, the IPTimeout deferred procedure call (DPC) is queued */
836 ExInitializeWorkItem( &IpWorkItem
, IPTimeout
, NULL
);
837 KeInitializeDpc(&IPTimeoutDpc
, IPTimeoutDpcFn
, NULL
);
838 KeInitializeTimer(&IPTimer
);
840 /* Start the periodic timer with an initial and periodic
841 relative expiration time of IP_TIMEOUT milliseconds */
842 DueTime
.QuadPart
= -(LONGLONG
)IP_TIMEOUT
* 10000;
843 KeSetTimerEx(&IPTimer
, DueTime
, IP_TIMEOUT
, &IPTimeoutDpc
);
845 return STATUS_SUCCESS
;