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 * FUNCTION: Releases resources used by a file object
258 * DeviceObject = Pointer to a device object for this driver
259 * Irp = Pointer to a I/O request packet
261 * Status of the operation
263 * This function does not pend
265 NTSTATUS
TiCleanupFileObject(
266 PDEVICE_OBJECT DeviceObject
,
269 PIO_STACK_LOCATION IrpSp
;
270 PTRANSPORT_CONTEXT Context
;
275 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
276 Context
= IrpSp
->FileObject
->FsContext
;
278 TI_DbgPrint(MIN_TRACE
, ("Parameters are invalid.\n"));
279 return STATUS_INVALID_PARAMETER
;
282 IoAcquireCancelSpinLock(&OldIrql
);
284 Context
->CancelIrps
= TRUE
;
286 IoReleaseCancelSpinLock(OldIrql
);
288 switch ((ULONG_PTR
)IrpSp
->FileObject
->FsContext2
) {
289 case TDI_TRANSPORT_ADDRESS_FILE
:
290 Request
.Handle
.AddressHandle
= Context
->Handle
.AddressHandle
;
291 Status
= FileCloseAddress(&Request
);
294 case TDI_CONNECTION_FILE
:
295 Request
.Handle
.ConnectionContext
= Context
->Handle
.ConnectionContext
;
296 Status
= FileCloseConnection(&Request
);
299 case TDI_CONTROL_CHANNEL_FILE
:
300 Request
.Handle
.ControlChannel
= Context
->Handle
.ControlChannel
;
301 Status
= FileCloseControlChannel(&Request
);
305 /* This should never happen */
307 TI_DbgPrint(MIN_TRACE
, ("Unknown transport context.\n"));
309 IoAcquireCancelSpinLock(&OldIrql
);
310 Context
->CancelIrps
= FALSE
;
311 IoReleaseCancelSpinLock(OldIrql
);
313 Status
= STATUS_INVALID_PARAMETER
;
317 Irp
->IoStatus
.Status
= Status
;
319 return Irp
->IoStatus
.Status
;
325 IN PDEVICE_OBJECT DeviceObject
,
328 * FUNCTION: Main dispath routine
330 * DeviceObject = Pointer to a device object for this driver
331 * Irp = Pointer to a I/O request packet
333 * Status of the operation
336 PIO_STACK_LOCATION IrpSp
;
338 PTRANSPORT_CONTEXT Context
;
342 // DbgPrint("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp);
344 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
346 switch (IrpSp
->MajorFunction
) {
347 /* Open an address file, connection endpoint, or control connection */
349 Status
= TiCreateFileObject(DeviceObject
, Irp
);
352 /* Close an address file, connection endpoint, or control connection */
354 Context
= (PTRANSPORT_CONTEXT
)IrpSp
->FileObject
->FsContext
;
356 PoolFreeBuffer(Context
);
357 Status
= STATUS_SUCCESS
;
360 /* Release resources bound to an address file, connection endpoint,
361 or control connection */
363 Status
= TiCleanupFileObject(DeviceObject
, Irp
);
367 Status
= STATUS_INVALID_DEVICE_REQUEST
;
370 //DbgPrint("Leaving. Status is (0x%X)\n", Status);
372 return IRPFinish( Irp
, Status
);
378 PDEVICE_OBJECT DeviceObject
,
381 * FUNCTION: Internal IOCTL dispatch routine
383 * DeviceObject = Pointer to a device object for this driver
384 * Irp = Pointer to a I/O request packet
386 * Status of the operation
390 BOOL Complete
= TRUE
;
391 PIO_STACK_LOCATION IrpSp
;
395 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
397 TI_DbgPrint(DEBUG_IRP
, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
398 DeviceObject
, Irp
, IrpSp
->MinorFunction
));
400 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
401 Irp
->IoStatus
.Information
= 0;
403 switch (IrpSp
->MinorFunction
) {
405 Status
= DispTdiReceive(Irp
);
409 case TDI_RECEIVE_DATAGRAM
:
410 Status
= DispTdiReceiveDatagram(Irp
);
415 Status
= DispTdiSend(Irp
);
416 Complete
= FALSE
; /* Completed in DispTdiSend */
419 case TDI_SEND_DATAGRAM
:
420 Status
= DispTdiSendDatagram(Irp
);
425 Status
= DispTdiAccept(Irp
);
429 Status
= DispTdiListen(Irp
);
434 Status
= DispTdiConnect(Irp
);
435 Complete
= FALSE
; /* Completed by the TCP event handler */
439 Status
= DispTdiDisconnect(Irp
);
443 case TDI_ASSOCIATE_ADDRESS
:
444 Status
= DispTdiAssociateAddress(Irp
);
447 case TDI_DISASSOCIATE_ADDRESS
:
448 Status
= DispTdiDisassociateAddress(Irp
);
451 case TDI_QUERY_INFORMATION
:
452 Status
= DispTdiQueryInformation(DeviceObject
, Irp
);
455 case TDI_SET_INFORMATION
:
456 Status
= DispTdiSetInformation(Irp
);
459 case TDI_SET_EVENT_HANDLER
:
460 Status
= DispTdiSetEventHandler(Irp
);
464 Status
= STATUS_SUCCESS
;
467 /* An unsupported IOCTL code was submitted */
469 Status
= STATUS_INVALID_DEVICE_REQUEST
;
472 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
475 IRPFinish( Irp
, Status
);
477 Irp
->IoStatus
.Status
= Status
;
485 PDEVICE_OBJECT DeviceObject
,
488 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
490 * DeviceObject = Pointer to a device object for this driver
491 * Irp = Pointer to a I/O request packet
493 * Status of the operation
497 PIO_STACK_LOCATION IrpSp
;
501 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
503 TI_DbgPrint(DEBUG_IRP
, ("Called. IRP is at (0x%X).\n", Irp
));
505 Irp
->IoStatus
.Information
= 0;
508 Status
= TdiMapUserRequest(DeviceObject
, Irp
, IrpSp
);
509 if (NT_SUCCESS(Status
)) {
510 TiDispatchInternal(DeviceObject
, Irp
);
511 Status
= STATUS_PENDING
;
516 /* See if this request is TCP/IP specific */
517 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
518 case IOCTL_TCP_QUERY_INFORMATION_EX
:
519 TI_DbgPrint(MIN_TRACE
, ("TCP_QUERY_INFORMATION_EX\n"));
520 Status
= DispTdiQueryInformationEx(Irp
, IrpSp
);
523 case IOCTL_TCP_SET_INFORMATION_EX
:
524 TI_DbgPrint(MIN_TRACE
, ("TCP_SET_INFORMATION_EX\n"));
525 Status
= DispTdiSetInformationEx(Irp
, IrpSp
);
528 case IOCTL_SET_IP_ADDRESS
:
529 TI_DbgPrint(MIN_TRACE
, ("SET_IP_ADDRESS\n"));
530 Status
= DispTdiSetIPAddress(Irp
, IrpSp
);
533 case IOCTL_DELETE_IP_ADDRESS
:
534 TI_DbgPrint(MIN_TRACE
, ("DELETE_IP_ADDRESS\n"));
535 Status
= DispTdiDeleteIPAddress(Irp
, IrpSp
);
539 TI_DbgPrint(MIN_TRACE
, ("Unknown IOCTL 0x%X\n",
540 IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
));
541 Status
= STATUS_NOT_IMPLEMENTED
;
546 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
548 return IRPFinish( Irp
, Status
);
552 VOID STDCALL
TiUnload(
553 PDRIVER_OBJECT DriverObject
)
555 * FUNCTION: Unloads the driver
557 * DriverObject = Pointer to driver object created by the system
563 TcpipAcquireSpinLock(&AddressFileListLock
, &OldIrql
);
564 if (!IsListEmpty(&AddressFileListHead
)) {
565 TI_DbgPrint(MIN_TRACE
, ("Open address file objects exists.\n"));
567 TcpipReleaseSpinLock(&AddressFileListLock
, OldIrql
);
572 KeCancelTimer(&IPTimer
);
574 /* Unregister loopback adapter */
575 LoopUnregisterAdapter(NULL
);
577 /* Unregister protocol with NDIS */
578 LANUnregisterProtocol();
580 /* Shutdown transport level protocol subsystems */
585 /* Shutdown network level protocol subsystem */
588 /* Shutdown the lan worker */
591 /* Free NDIS buffer descriptors */
592 if (GlobalBufferPool
)
593 NdisFreeBufferPool(GlobalBufferPool
);
595 /* Free NDIS packet descriptors */
596 if (GlobalPacketPool
)
597 NdisFreePacketPool(GlobalPacketPool
);
599 /* Release all device objects */
602 IoDeleteDevice(TCPDeviceObject
);
605 IoDeleteDevice(UDPDeviceObject
);
607 if (RawIPDeviceObject
)
608 IoDeleteDevice(RawIPDeviceObject
);
611 IoDeleteDevice(IPDeviceObject
);
614 PoolFreeBuffer(EntityList
);
616 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
619 VOID STDCALL
IPTimeoutDpcFn(
621 PVOID DeferredContext
,
622 PVOID SystemArgument1
,
623 PVOID SystemArgument2
)
625 * FUNCTION: Timeout DPC
627 * Dpc = Pointer to our DPC object
628 * DeferredContext = Pointer to context information (unused)
629 * SystemArgument1 = Unused
630 * SystemArgument2 = Unused
632 * This routine is dispatched once in a while to do maintainance jobs
635 if( !IpWorkItemQueued
) {
636 ExQueueWorkItem( &IpWorkItem
, CriticalWorkQueue
);
637 IpWorkItemQueued
= TRUE
;
643 PDRIVER_OBJECT DriverObject
,
644 PUNICODE_STRING RegistryPath
)
646 * FUNCTION: Main driver entry point
648 * DriverObject = Pointer to a driver object for this driver
649 * RegistryPath = Registry node for configuration parameters
651 * Status of driver initialization
655 UNICODE_STRING strIpDeviceName
= RTL_CONSTANT_STRING(DD_IP_DEVICE_NAME
);
656 UNICODE_STRING strRawDeviceName
= RTL_CONSTANT_STRING(DD_RAWIP_DEVICE_NAME
);
657 UNICODE_STRING strUdpDeviceName
= RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME
);
658 UNICODE_STRING strTcpDeviceName
= RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME
);
659 UNICODE_STRING strNdisDeviceName
= RTL_CONSTANT_STRING(TCPIP_PROTOCOL_NAME
);
660 NDIS_STATUS NdisStatus
;
661 LARGE_INTEGER DueTime
;
663 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
666 TrackTag(NDIS_BUFFER_TAG
);
667 TrackTag(NDIS_PACKET_TAG
);
668 TrackTag(FBSD_MALLOC
);
669 TrackTag(EXALLOC_TAG
);
671 /* TdiInitialize() ? */
673 /* FIXME: Create symbolic links in Win32 namespace */
675 /* Create IP device object */
676 Status
= IoCreateDevice(DriverObject
, 0, &strIpDeviceName
,
677 FILE_DEVICE_NETWORK
, 0, FALSE
, &IPDeviceObject
);
678 if (!NT_SUCCESS(Status
)) {
679 TI_DbgPrint(MIN_TRACE
, ("Failed to create IP device object. Status (0x%X).\n", Status
));
683 ChewInit( IPDeviceObject
);
685 /* Create RawIP device object */
686 Status
= IoCreateDevice(DriverObject
, 0, &strRawDeviceName
,
687 FILE_DEVICE_NETWORK
, 0, FALSE
, &RawIPDeviceObject
);
688 if (!NT_SUCCESS(Status
)) {
689 TI_DbgPrint(MIN_TRACE
, ("Failed to create RawIP device object. Status (0x%X).\n", Status
));
691 IoDeleteDevice(IPDeviceObject
);
695 /* Create UDP device object */
696 Status
= IoCreateDevice(DriverObject
, 0, &strUdpDeviceName
,
697 FILE_DEVICE_NETWORK
, 0, FALSE
, &UDPDeviceObject
);
698 if (!NT_SUCCESS(Status
)) {
699 TI_DbgPrint(MIN_TRACE
, ("Failed to create UDP device object. Status (0x%X).\n", Status
));
701 IoDeleteDevice(IPDeviceObject
);
702 IoDeleteDevice(RawIPDeviceObject
);
706 /* Create TCP device object */
707 Status
= IoCreateDevice(DriverObject
, 0, &strTcpDeviceName
,
708 FILE_DEVICE_NETWORK
, 0, FALSE
, &TCPDeviceObject
);
709 if (!NT_SUCCESS(Status
)) {
710 TI_DbgPrint(MIN_TRACE
, ("Failed to create TCP device object. Status (0x%X).\n", Status
));
712 IoDeleteDevice(IPDeviceObject
);
713 IoDeleteDevice(RawIPDeviceObject
);
714 IoDeleteDevice(UDPDeviceObject
);
718 /* Setup network layer and transport layer entities */
719 KeInitializeSpinLock(&EntityListLock
);
720 EntityList
= ExAllocatePool(NonPagedPool
, sizeof(TDIEntityID
) * MAX_TDI_ENTITIES
);
722 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
724 IoDeleteDevice(IPDeviceObject
);
725 IoDeleteDevice(RawIPDeviceObject
);
726 IoDeleteDevice(UDPDeviceObject
);
727 IoDeleteDevice(TCPDeviceObject
);
728 return STATUS_INSUFFICIENT_RESOURCES
;
731 EntityList
[0].tei_entity
= CL_NL_ENTITY
;
732 EntityList
[0].tei_instance
= 0;
733 EntityList
[0].context
= 0;
734 EntityList
[0].info_req
= InfoNetworkLayerTdiQueryEx
;
735 EntityList
[0].info_set
= InfoNetworkLayerTdiSetEx
;
736 EntityList
[1].tei_entity
= CL_TL_ENTITY
;
737 EntityList
[1].tei_instance
= 0;
738 EntityList
[1].context
= 0;
739 EntityList
[1].info_req
= InfoTransportLayerTdiQueryEx
;
740 EntityList
[1].info_set
= InfoTransportLayerTdiSetEx
;
742 EntityMax
= MAX_TDI_ENTITIES
;
744 /* Allocate NDIS packet descriptors */
745 NdisAllocatePacketPool(&NdisStatus
, &GlobalPacketPool
, 100, sizeof(PACKET_CONTEXT
));
746 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
748 IoDeleteDevice(IPDeviceObject
);
749 IoDeleteDevice(RawIPDeviceObject
);
750 IoDeleteDevice(UDPDeviceObject
);
751 IoDeleteDevice(TCPDeviceObject
);
752 ExFreePool(EntityList
);
753 return STATUS_INSUFFICIENT_RESOURCES
;
756 /* Allocate NDIS buffer descriptors */
757 NdisAllocateBufferPool(&NdisStatus
, &GlobalBufferPool
, 100);
758 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
760 IoDeleteDevice(IPDeviceObject
);
761 IoDeleteDevice(RawIPDeviceObject
);
762 IoDeleteDevice(UDPDeviceObject
);
763 IoDeleteDevice(TCPDeviceObject
);
764 ExFreePool(EntityList
);
765 NdisFreePacketPool(GlobalPacketPool
);
766 return STATUS_INSUFFICIENT_RESOURCES
;
769 /* Initialize address file list and protecting spin lock */
770 InitializeListHead(&AddressFileListHead
);
771 KeInitializeSpinLock(&AddressFileListLock
);
773 /* Initialize connection endpoint list and protecting spin lock */
774 InitializeListHead(&ConnectionEndpointListHead
);
775 KeInitializeSpinLock(&ConnectionEndpointListLock
);
777 /* Initialize interface list and protecting spin lock */
778 InitializeListHead(&InterfaceListHead
);
779 KeInitializeSpinLock(&InterfaceListLock
);
781 /* Initialize network level protocol subsystem */
782 IPStartup(RegistryPath
);
784 /* Initialize transport level protocol subsystems */
785 Status
= RawIPStartup();
786 if( !NT_SUCCESS(Status
) ) {
789 IoDeleteDevice(IPDeviceObject
);
790 IoDeleteDevice(RawIPDeviceObject
);
791 IoDeleteDevice(UDPDeviceObject
);
792 IoDeleteDevice(TCPDeviceObject
);
793 ExFreePool(EntityList
);
794 NdisFreePacketPool(GlobalPacketPool
);
795 NdisFreeBufferPool(GlobalBufferPool
);
799 Status
= UDPStartup();
800 if( !NT_SUCCESS(Status
) ) {
804 IoDeleteDevice(IPDeviceObject
);
805 IoDeleteDevice(RawIPDeviceObject
);
806 IoDeleteDevice(UDPDeviceObject
);
807 IoDeleteDevice(TCPDeviceObject
);
808 ExFreePool(EntityList
);
809 NdisFreePacketPool(GlobalPacketPool
);
810 NdisFreeBufferPool(GlobalBufferPool
);
814 Status
= TCPStartup();
815 if( !NT_SUCCESS(Status
) ) {
820 IoDeleteDevice(IPDeviceObject
);
821 IoDeleteDevice(RawIPDeviceObject
);
822 IoDeleteDevice(UDPDeviceObject
);
823 IoDeleteDevice(TCPDeviceObject
);
824 ExFreePool(EntityList
);
825 NdisFreePacketPool(GlobalPacketPool
);
826 NdisFreeBufferPool(GlobalBufferPool
);
830 /* Initialize the lan worker */
833 /* Register protocol with NDIS */
834 /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
835 Status
= LANRegisterProtocol(&strNdisDeviceName
);
836 if (!NT_SUCCESS(Status
)) {
837 TI_DbgPrint(MIN_TRACE
,("Failed to register protocol with NDIS; status 0x%x\n", Status
));
840 EVENT_TRANSPORT_REGISTER_FAILED
,
841 TI_ERROR_DRIVERENTRY
,
852 IoDeleteDevice(IPDeviceObject
);
853 IoDeleteDevice(RawIPDeviceObject
);
854 IoDeleteDevice(UDPDeviceObject
);
855 IoDeleteDevice(TCPDeviceObject
);
856 ExFreePool(EntityList
);
857 NdisFreePacketPool(GlobalPacketPool
);
858 NdisFreeBufferPool(GlobalBufferPool
);
862 /* Open loopback adapter */
863 Status
= LoopRegisterAdapter(NULL
, NULL
);
864 if (!NT_SUCCESS(Status
)) {
865 TI_DbgPrint(MIN_TRACE
, ("Failed to create loopback adapter. Status (0x%X).\n", Status
));
872 IoDeleteDevice(IPDeviceObject
);
873 IoDeleteDevice(RawIPDeviceObject
);
874 IoDeleteDevice(UDPDeviceObject
);
875 IoDeleteDevice(TCPDeviceObject
);
876 ExFreePool(EntityList
);
877 NdisFreePacketPool(GlobalPacketPool
);
878 NdisFreeBufferPool(GlobalBufferPool
);
879 LANUnregisterProtocol();
884 IPDeviceObject
->Flags
|= DO_DIRECT_IO
;
885 RawIPDeviceObject
->Flags
|= DO_DIRECT_IO
;
886 UDPDeviceObject
->Flags
|= DO_DIRECT_IO
;
887 TCPDeviceObject
->Flags
|= DO_DIRECT_IO
;
889 /* Initialize the driver object with this driver's entry points */
890 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = TiDispatchOpenClose
;
891 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = TiDispatchOpenClose
;
892 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = TiDispatchOpenClose
;
893 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = TiDispatchInternal
;
894 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = TiDispatch
;
896 DriverObject
->DriverUnload
= TiUnload
;
898 /* Initialize our periodic timer and its associated DPC object. When the
899 timer expires, the IPTimeout deferred procedure call (DPC) is queued */
900 ExInitializeWorkItem( &IpWorkItem
, IPTimeout
, NULL
);
901 KeInitializeDpc(&IPTimeoutDpc
, IPTimeoutDpcFn
, NULL
);
902 KeInitializeTimer(&IPTimer
);
904 /* Start the periodic timer with an initial and periodic
905 relative expiration time of IP_TIMEOUT milliseconds */
906 DueTime
.QuadPart
= -(LONGLONG
)IP_TIMEOUT
* 10000;
907 KeSetTimerEx(&IPTimer
, DueTime
, IP_TIMEOUT
, &IPTimeoutDpc
);
909 return STATUS_SUCCESS
;