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
);
442 case TDI_ASSOCIATE_ADDRESS
:
443 Status
= DispTdiAssociateAddress(Irp
);
446 case TDI_DISASSOCIATE_ADDRESS
:
447 Status
= DispTdiDisassociateAddress(Irp
);
450 case TDI_QUERY_INFORMATION
:
451 Status
= DispTdiQueryInformation(DeviceObject
, Irp
);
454 case TDI_SET_INFORMATION
:
455 Status
= DispTdiSetInformation(Irp
);
458 case TDI_SET_EVENT_HANDLER
:
459 Status
= DispTdiSetEventHandler(Irp
);
463 Status
= STATUS_SUCCESS
;
466 /* An unsupported IOCTL code was submitted */
468 Status
= STATUS_INVALID_DEVICE_REQUEST
;
471 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
474 IRPFinish( Irp
, Status
);
476 Irp
->IoStatus
.Status
= Status
;
484 PDEVICE_OBJECT DeviceObject
,
487 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
489 * DeviceObject = Pointer to a device object for this driver
490 * Irp = Pointer to a I/O request packet
492 * Status of the operation
496 PIO_STACK_LOCATION IrpSp
;
500 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
502 TI_DbgPrint(DEBUG_IRP
, ("Called. IRP is at (0x%X).\n", Irp
));
504 Irp
->IoStatus
.Information
= 0;
507 Status
= TdiMapUserRequest(DeviceObject
, Irp
, IrpSp
);
508 if (NT_SUCCESS(Status
)) {
509 TiDispatchInternal(DeviceObject
, Irp
);
510 Status
= STATUS_PENDING
;
515 /* See if this request is TCP/IP specific */
516 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
517 case IOCTL_TCP_QUERY_INFORMATION_EX
:
518 TI_DbgPrint(MIN_TRACE
, ("TCP_QUERY_INFORMATION_EX\n"));
519 Status
= DispTdiQueryInformationEx(Irp
, IrpSp
);
522 case IOCTL_TCP_SET_INFORMATION_EX
:
523 TI_DbgPrint(MIN_TRACE
, ("TCP_SET_INFORMATION_EX\n"));
524 Status
= DispTdiSetInformationEx(Irp
, IrpSp
);
527 case IOCTL_SET_IP_ADDRESS
:
528 TI_DbgPrint(MIN_TRACE
, ("SET_IP_ADDRESS\n"));
529 Status
= DispTdiSetIPAddress(Irp
, IrpSp
);
532 case IOCTL_DELETE_IP_ADDRESS
:
533 TI_DbgPrint(MIN_TRACE
, ("DELETE_IP_ADDRESS\n"));
534 Status
= DispTdiDeleteIPAddress(Irp
, IrpSp
);
538 TI_DbgPrint(MIN_TRACE
, ("Unknown IOCTL 0x%X\n",
539 IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
));
540 Status
= STATUS_NOT_IMPLEMENTED
;
545 TI_DbgPrint(DEBUG_IRP
, ("Leaving. Status = (0x%X).\n", Status
));
547 return IRPFinish( Irp
, Status
);
551 VOID STDCALL
TiUnload(
552 PDRIVER_OBJECT DriverObject
)
554 * FUNCTION: Unloads the driver
556 * DriverObject = Pointer to driver object created by the system
562 TcpipAcquireSpinLock(&AddressFileListLock
, &OldIrql
);
563 if (!IsListEmpty(&AddressFileListHead
)) {
564 TI_DbgPrint(MIN_TRACE
, ("Open address file objects exists.\n"));
566 TcpipReleaseSpinLock(&AddressFileListLock
, OldIrql
);
571 KeCancelTimer(&IPTimer
);
573 /* Unregister loopback adapter */
574 LoopUnregisterAdapter(NULL
);
576 /* Unregister protocol with NDIS */
577 LANUnregisterProtocol();
579 /* Shutdown transport level protocol subsystems */
584 /* Shutdown network level protocol subsystem */
587 /* Shutdown the lan worker */
590 /* Free NDIS buffer descriptors */
591 if (GlobalBufferPool
)
592 NdisFreeBufferPool(GlobalBufferPool
);
594 /* Free NDIS packet descriptors */
595 if (GlobalPacketPool
)
596 NdisFreePacketPool(GlobalPacketPool
);
598 /* Release all device objects */
601 IoDeleteDevice(TCPDeviceObject
);
604 IoDeleteDevice(UDPDeviceObject
);
606 if (RawIPDeviceObject
)
607 IoDeleteDevice(RawIPDeviceObject
);
610 IoDeleteDevice(IPDeviceObject
);
613 PoolFreeBuffer(EntityList
);
615 TI_DbgPrint(MAX_TRACE
, ("Leaving.\n"));
618 VOID STDCALL
IPTimeoutDpcFn(
620 PVOID DeferredContext
,
621 PVOID SystemArgument1
,
622 PVOID SystemArgument2
)
624 * FUNCTION: Timeout DPC
626 * Dpc = Pointer to our DPC object
627 * DeferredContext = Pointer to context information (unused)
628 * SystemArgument1 = Unused
629 * SystemArgument2 = Unused
631 * This routine is dispatched once in a while to do maintainance jobs
634 if( !IpWorkItemQueued
) {
635 ExQueueWorkItem( &IpWorkItem
, CriticalWorkQueue
);
636 IpWorkItemQueued
= TRUE
;
642 PDRIVER_OBJECT DriverObject
,
643 PUNICODE_STRING RegistryPath
)
645 * FUNCTION: Main driver entry point
647 * DriverObject = Pointer to a driver object for this driver
648 * RegistryPath = Registry node for configuration parameters
650 * Status of driver initialization
654 UNICODE_STRING strIpDeviceName
= RTL_CONSTANT_STRING(DD_IP_DEVICE_NAME
);
655 UNICODE_STRING strRawDeviceName
= RTL_CONSTANT_STRING(DD_RAWIP_DEVICE_NAME
);
656 UNICODE_STRING strUdpDeviceName
= RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME
);
657 UNICODE_STRING strTcpDeviceName
= RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME
);
658 UNICODE_STRING strNdisDeviceName
= RTL_CONSTANT_STRING(TCPIP_PROTOCOL_NAME
);
659 NDIS_STATUS NdisStatus
;
660 LARGE_INTEGER DueTime
;
662 TI_DbgPrint(MAX_TRACE
, ("Called.\n"));
665 TrackTag(NDIS_BUFFER_TAG
);
666 TrackTag(NDIS_PACKET_TAG
);
667 TrackTag(FBSD_MALLOC
);
668 TrackTag(EXALLOC_TAG
);
670 /* TdiInitialize() ? */
672 /* FIXME: Create symbolic links in Win32 namespace */
674 /* Create IP device object */
675 Status
= IoCreateDevice(DriverObject
, 0, &strIpDeviceName
,
676 FILE_DEVICE_NETWORK
, 0, FALSE
, &IPDeviceObject
);
677 if (!NT_SUCCESS(Status
)) {
678 TI_DbgPrint(MIN_TRACE
, ("Failed to create IP device object. Status (0x%X).\n", Status
));
682 ChewInit( IPDeviceObject
);
684 /* Create RawIP device object */
685 Status
= IoCreateDevice(DriverObject
, 0, &strRawDeviceName
,
686 FILE_DEVICE_NETWORK
, 0, FALSE
, &RawIPDeviceObject
);
687 if (!NT_SUCCESS(Status
)) {
688 TI_DbgPrint(MIN_TRACE
, ("Failed to create RawIP device object. Status (0x%X).\n", Status
));
689 TiUnload(DriverObject
);
693 /* Create UDP device object */
694 Status
= IoCreateDevice(DriverObject
, 0, &strUdpDeviceName
,
695 FILE_DEVICE_NETWORK
, 0, FALSE
, &UDPDeviceObject
);
696 if (!NT_SUCCESS(Status
)) {
697 TI_DbgPrint(MIN_TRACE
, ("Failed to create UDP device object. Status (0x%X).\n", Status
));
698 TiUnload(DriverObject
);
702 /* Create TCP device object */
703 Status
= IoCreateDevice(DriverObject
, 0, &strTcpDeviceName
,
704 FILE_DEVICE_NETWORK
, 0, FALSE
, &TCPDeviceObject
);
705 if (!NT_SUCCESS(Status
)) {
706 TI_DbgPrint(MIN_TRACE
, ("Failed to create TCP device object. Status (0x%X).\n", Status
));
707 TiUnload(DriverObject
);
711 /* Setup network layer and transport layer entities */
712 KeInitializeSpinLock(&EntityListLock
);
713 EntityList
= ExAllocatePool(NonPagedPool
, sizeof(TDIEntityID
) * MAX_TDI_ENTITIES
);
714 if (!NT_SUCCESS(Status
)) {
715 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
716 TiUnload(DriverObject
);
717 return STATUS_INSUFFICIENT_RESOURCES
;
720 EntityList
[0].tei_entity
= CL_NL_ENTITY
;
721 EntityList
[0].tei_instance
= 0;
722 EntityList
[0].context
= 0;
723 EntityList
[0].info_req
= InfoNetworkLayerTdiQueryEx
;
724 EntityList
[0].info_set
= InfoNetworkLayerTdiSetEx
;
725 EntityList
[1].tei_entity
= CL_TL_ENTITY
;
726 EntityList
[1].tei_instance
= 0;
727 EntityList
[1].context
= 0;
728 EntityList
[1].info_req
= InfoTransportLayerTdiQueryEx
;
729 EntityList
[1].info_set
= InfoTransportLayerTdiSetEx
;
731 EntityMax
= MAX_TDI_ENTITIES
;
733 /* Allocate NDIS packet descriptors */
734 NdisAllocatePacketPool(&NdisStatus
, &GlobalPacketPool
, 100, sizeof(PACKET_CONTEXT
));
735 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
736 TiUnload(DriverObject
);
737 return STATUS_INSUFFICIENT_RESOURCES
;
740 /* Allocate NDIS buffer descriptors */
741 NdisAllocateBufferPool(&NdisStatus
, &GlobalBufferPool
, 100);
742 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
743 TiUnload(DriverObject
);
744 return STATUS_INSUFFICIENT_RESOURCES
;
747 /* Initialize address file list and protecting spin lock */
748 InitializeListHead(&AddressFileListHead
);
749 KeInitializeSpinLock(&AddressFileListLock
);
751 /* Initialize connection endpoint list and protecting spin lock */
752 InitializeListHead(&ConnectionEndpointListHead
);
753 KeInitializeSpinLock(&ConnectionEndpointListLock
);
755 /* Initialize interface list and protecting spin lock */
756 InitializeListHead(&InterfaceListHead
);
757 KeInitializeSpinLock(&InterfaceListLock
);
759 /* Initialize network level protocol subsystem */
760 IPStartup(RegistryPath
);
762 /* Initialize transport level protocol subsystems */
767 /* Initialize the lan worker */
770 /* Register protocol with NDIS */
771 /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
772 Status
= LANRegisterProtocol(&strNdisDeviceName
);
773 if (!NT_SUCCESS(Status
)) {
774 TI_DbgPrint(MIN_TRACE
,("Failed to register protocol with NDIS; status 0x%x\n", Status
));
777 EVENT_TRANSPORT_REGISTER_FAILED
,
778 TI_ERROR_DRIVERENTRY
,
783 TiUnload(DriverObject
);
787 /* Open loopback adapter */
788 if (!NT_SUCCESS(LoopRegisterAdapter(NULL
, NULL
))) {
789 TI_DbgPrint(MIN_TRACE
, ("Failed to create loopback adapter. Status (0x%X).\n", Status
));
790 TiUnload(DriverObject
);
791 return STATUS_INSUFFICIENT_RESOURCES
;
795 IPDeviceObject
->Flags
|= DO_DIRECT_IO
;
796 RawIPDeviceObject
->Flags
|= DO_DIRECT_IO
;
797 UDPDeviceObject
->Flags
|= DO_DIRECT_IO
;
798 TCPDeviceObject
->Flags
|= DO_DIRECT_IO
;
800 /* Initialize the driver object with this driver's entry points */
801 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = TiDispatchOpenClose
;
802 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = TiDispatchOpenClose
;
803 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = TiDispatchOpenClose
;
804 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = TiDispatchInternal
;
805 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = TiDispatch
;
807 DriverObject
->DriverUnload
= TiUnload
;
809 /* Initialize our periodic timer and its associated DPC object. When the
810 timer expires, the IPTimeout deferred procedure call (DPC) is queued */
811 ExInitializeWorkItem( &IpWorkItem
, IPTimeout
, NULL
);
812 KeInitializeDpc(&IPTimeoutDpc
, IPTimeoutDpcFn
, NULL
);
813 KeInitializeTimer(&IPTimer
);
815 /* Start the periodic timer with an initial and periodic
816 relative expiration time of IP_TIMEOUT milliseconds */
817 DueTime
.QuadPart
= -(LONGLONG
)IP_TIMEOUT
* 10000;
818 KeSetTimerEx(&IPTimer
, DueTime
, IP_TIMEOUT
, &IPTimeoutDpc
);
820 return STATUS_SUCCESS
;