[TCPIP] Fix debug traces
[reactos.git] / reactos / drivers / network / tcpip / tcpip / main.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: tcpip/main.c
5 * PURPOSE: Driver entry point
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/08-2000 Created
9 */
10
11 #include "precomp.h"
12
13 #include <dispatch.h>
14 #include <fileobjs.h>
15
16 PDEVICE_OBJECT TCPDeviceObject = NULL;
17 PDEVICE_OBJECT UDPDeviceObject = NULL;
18 PDEVICE_OBJECT IPDeviceObject = NULL;
19 PDEVICE_OBJECT RawIPDeviceObject = NULL;
20 NDIS_HANDLE GlobalPacketPool = NULL;
21 NDIS_HANDLE GlobalBufferPool = NULL;
22 KSPIN_LOCK EntityListLock;
23 TDIEntityInfo *EntityList = NULL;
24 ULONG EntityCount = 0;
25 ULONG EntityMax = 0;
26 UDP_STATISTICS UDPStats;
27
28 /* Network timers */
29 KTIMER IPTimer;
30 KDPC IPTimeoutDpc;
31
32 VOID TiWriteErrorLog(
33 PDRIVER_OBJECT DriverContext,
34 NTSTATUS ErrorCode,
35 ULONG UniqueErrorValue,
36 NTSTATUS FinalStatus,
37 PWSTR String,
38 ULONG DumpDataCount,
39 PULONG DumpData)
40 /*
41 * FUNCTION: Writes an error log entry
42 * ARGUMENTS:
43 * DriverContext = Pointer to the driver or device object
44 * ErrorCode = An error code to put in the log entry
45 * UniqueErrorValue = UniqueErrorValue in the error log packet
46 * FinalStatus = FinalStatus in the error log packet
47 * String = If not NULL, a pointer to a string to put in log
48 * entry
49 * DumpDataCount = Number of ULONGs of dump data
50 * DumpData = Pointer to dump data for the log entry
51 */
52 {
53 #if 0
54 PIO_ERROR_LOG_PACKET LogEntry;
55 UCHAR EntrySize;
56 ULONG StringSize;
57 PUCHAR pString;
58 static WCHAR DriverName[] = L"TCP/IP";
59
60 EntrySize = sizeof(IO_ERROR_LOG_PACKET) +
61 (DumpDataCount * sizeof(ULONG)) + sizeof(DriverName);
62
63 if (String) {
64 StringSize = (wcslen(String) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
65 EntrySize += (UCHAR)StringSize;
66 }
67
68 LogEntry = (PIO_ERROR_LOG_PACKET)IoAllocateErrorLogEntry(
69 DriverContext, EntrySize);
70
71 if (LogEntry) {
72 LogEntry->MajorFunctionCode = -1;
73 LogEntry->RetryCount = -1;
74 LogEntry->DumpDataSize = (USHORT)(DumpDataCount * sizeof(ULONG));
75 LogEntry->NumberOfStrings = (String == NULL) ? 1 : 2;
76 LogEntry->StringOffset = sizeof(IO_ERROR_LOG_PACKET) + (DumpDataCount-1) * sizeof(ULONG);
77 LogEntry->EventCategory = 0;
78 LogEntry->ErrorCode = ErrorCode;
79 LogEntry->UniqueErrorValue = UniqueErrorValue;
80 LogEntry->FinalStatus = FinalStatus;
81 LogEntry->SequenceNumber = -1;
82 LogEntry->IoControlCode = 0;
83
84 if (DumpDataCount)
85 RtlCopyMemory(LogEntry->DumpData, DumpData, DumpDataCount * sizeof(ULONG));
86
87 pString = ((PUCHAR)LogEntry) + LogEntry->StringOffset;
88 RtlCopyMemory(pString, DriverName, sizeof(DriverName));
89 pString += sizeof(DriverName);
90
91 if (String)
92 RtlCopyMemory(pString, String, StringSize);
93
94 IoWriteErrorLogEntry(LogEntry);
95 }
96 #endif
97 }
98
99 /*
100 * FUNCTION: Creates a file object
101 * ARGUMENTS:
102 * DeviceObject = Pointer to a device object for this driver
103 * Irp = Pointer to a I/O request packet
104 * RETURNS:
105 * Status of the operation
106 */
107
108 NTSTATUS TiCreateFileObject(
109 PDEVICE_OBJECT DeviceObject,
110 PIRP Irp)
111 {
112 PFILE_FULL_EA_INFORMATION EaInfo;
113 PTRANSPORT_CONTEXT Context;
114 PIO_STACK_LOCATION IrpSp;
115 PTA_IP_ADDRESS Address;
116 TDI_REQUEST Request;
117 PVOID ClientContext;
118 NTSTATUS Status;
119 ULONG Protocol;
120 BOOLEAN Shared;
121
122 TI_DbgPrint(DEBUG_IRP, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp));
123
124 EaInfo = Irp->AssociatedIrp.SystemBuffer;
125
126 /* Parameter check */
127 /* No EA information means that we're opening for SET/QUERY_INFORMATION
128 * style calls. */
129
130 /* Allocate resources here. We release them again if something failed */
131 Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(TRANSPORT_CONTEXT),
132 TRANS_CONTEXT_TAG);
133 if (!Context)
134 {
135 TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
136 return STATUS_INSUFFICIENT_RESOURCES;
137 }
138
139 Context->CancelIrps = FALSE;
140
141 IrpSp = IoGetCurrentIrpStackLocation(Irp);
142 IrpSp->FileObject->FsContext = Context;
143 Request.RequestContext = Irp;
144
145 /* Branch to the right handler */
146 if (EaInfo &&
147 (EaInfo->EaNameLength == TDI_TRANSPORT_ADDRESS_LENGTH) &&
148 (RtlCompareMemory(&EaInfo->EaName, TdiTransportAddress,
149 TDI_TRANSPORT_ADDRESS_LENGTH) == TDI_TRANSPORT_ADDRESS_LENGTH))
150 {
151 /* This is a request to open an address */
152
153
154 /* XXX This should probably be done in IoCreateFile() */
155 /* Parameter checks */
156
157 Address = (PTA_IP_ADDRESS)(EaInfo->EaName + EaInfo->EaNameLength + 1); //0-term
158
159 if ((EaInfo->EaValueLength < sizeof(TA_IP_ADDRESS)) ||
160 (Address->TAAddressCount != 1) ||
161 (Address->Address[0].AddressLength < TDI_ADDRESS_LENGTH_IP) ||
162 (Address->Address[0].AddressType != TDI_ADDRESS_TYPE_IP))
163 {
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 {
168 TI_DbgPrint(MIN_TRACE, ("AddressLength: %u\n",
169 Address->Address[0].AddressLength));
170 TI_DbgPrint(MIN_TRACE, ("AddressType: %u\n",
171 Address->Address[0].AddressType));
172 }
173
174 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
175 return STATUS_INVALID_PARAMETER;
176 }
177
178 /* Open address file object */
179
180 /* Protocol depends on device object so find the protocol */
181 if (DeviceObject == TCPDeviceObject)
182 Protocol = IPPROTO_TCP;
183 else if (DeviceObject == UDPDeviceObject)
184 Protocol = IPPROTO_UDP;
185 else if (DeviceObject == IPDeviceObject)
186 Protocol = IPPROTO_RAW;
187 else if (DeviceObject == RawIPDeviceObject)
188 {
189 Status = TiGetProtocolNumber(&IrpSp->FileObject->FileName, &Protocol);
190 if (!NT_SUCCESS(Status))
191 {
192 TI_DbgPrint(MIN_TRACE, ("Raw IP protocol number is invalid.\n"));
193 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
194 return STATUS_INVALID_PARAMETER;
195 }
196 }
197 else
198 {
199 TI_DbgPrint(MIN_TRACE, ("Invalid device object at (0x%X).\n", DeviceObject));
200 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
201 return STATUS_INVALID_PARAMETER;
202 }
203
204 Shared = (IrpSp->Parameters.Create.ShareAccess != 0);
205
206 Status = FileOpenAddress(&Request, Address, Protocol, Shared, NULL);
207 if (NT_SUCCESS(Status))
208 {
209 IrpSp->FileObject->FsContext2 = (PVOID)TDI_TRANSPORT_ADDRESS_FILE;
210 Context->Handle.AddressHandle = Request.Handle.AddressHandle;
211 }
212
213 }
214 else if (EaInfo &&
215 (EaInfo->EaNameLength == TDI_CONNECTION_CONTEXT_LENGTH) &&
216 (RtlCompareMemory
217 (&EaInfo->EaName, TdiConnectionContext,
218 TDI_CONNECTION_CONTEXT_LENGTH) ==
219 TDI_CONNECTION_CONTEXT_LENGTH))
220 {
221 /* This is a request to open a connection endpoint */
222
223 /* Parameter checks */
224
225 if (EaInfo->EaValueLength < sizeof(PVOID))
226 {
227 TI_DbgPrint(MIN_TRACE, ("Parameters are invalid.\n"));
228 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
229 return STATUS_INVALID_PARAMETER;
230 }
231
232 /* Can only do connection oriented communication using TCP */
233
234 if (DeviceObject != TCPDeviceObject)
235 {
236 TI_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
237 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
238 return STATUS_INVALID_PARAMETER;
239 }
240
241 ClientContext = *((PVOID*)(EaInfo->EaName + EaInfo->EaNameLength));
242
243 /* Open connection endpoint file object */
244
245 Status = FileOpenConnection(&Request, ClientContext);
246 if (NT_SUCCESS(Status))
247 {
248 IrpSp->FileObject->FsContext2 = (PVOID)TDI_CONNECTION_FILE;
249 Context->Handle.ConnectionContext = Request.Handle.ConnectionContext;
250 }
251 }
252 else
253 {
254 /* This is a request to open a control connection */
255 Status = FileOpenControlChannel(&Request);
256 if (NT_SUCCESS(Status))
257 {
258 IrpSp->FileObject->FsContext2 = (PVOID)TDI_CONTROL_CHANNEL_FILE;
259 Context->Handle.ControlChannel = Request.Handle.ControlChannel;
260 }
261 }
262
263 if (!NT_SUCCESS(Status))
264 ExFreePoolWithTag(Context, TRANS_CONTEXT_TAG);
265
266 TI_DbgPrint(DEBUG_IRP, ("Leaving. Status = (0x%X).\n", Status));
267
268 Irp->IoStatus.Status = Status;
269 return Status;
270 }
271
272
273 /*
274 * FUNCTION: Releases resources used by a file object
275 * ARGUMENTS:
276 * DeviceObject = Pointer to a device object for this driver
277 * Irp = Pointer to a I/O request packet
278 * RETURNS:
279 * Status of the operation
280 * NOTES:
281 * This function does not pend
282 */
283 NTSTATUS TiCloseFileObject(
284 PDEVICE_OBJECT DeviceObject,
285 PIRP Irp)
286 {
287 PIO_STACK_LOCATION IrpSp;
288 PTRANSPORT_CONTEXT Context;
289 TDI_REQUEST Request;
290 NTSTATUS Status;
291
292 IrpSp = IoGetCurrentIrpStackLocation(Irp);
293 Context = IrpSp->FileObject->FsContext;
294 if (!Context)
295 {
296 TI_DbgPrint(MIN_TRACE, ("Parameters are invalid.\n"));
297 return STATUS_INVALID_PARAMETER;
298 }
299
300 switch ((ULONG_PTR)IrpSp->FileObject->FsContext2)
301 {
302 case TDI_TRANSPORT_ADDRESS_FILE:
303 Request.Handle.AddressHandle = Context->Handle.AddressHandle;
304 Status = FileCloseAddress(&Request);
305 break;
306
307 case TDI_CONNECTION_FILE:
308 Request.Handle.ConnectionContext = Context->Handle.ConnectionContext;
309 Status = FileCloseConnection(&Request);
310 break;
311
312 case TDI_CONTROL_CHANNEL_FILE:
313 Request.Handle.ControlChannel = Context->Handle.ControlChannel;
314 Status = FileCloseControlChannel(&Request);
315 break;
316
317 default:
318 Status = STATUS_INVALID_PARAMETER;
319 break;
320 }
321
322 Irp->IoStatus.Status = Status;
323
324 return Irp->IoStatus.Status;
325 }
326
327
328 NTSTATUS NTAPI
329 TiDispatchOpenClose(
330 IN PDEVICE_OBJECT DeviceObject,
331 IN PIRP Irp)
332 /*
333 * FUNCTION: Main dispath routine
334 * ARGUMENTS:
335 * DeviceObject = Pointer to a device object for this driver
336 * Irp = Pointer to a I/O request packet
337 * RETURNS:
338 * Status of the operation
339 */
340 {
341 PIO_STACK_LOCATION IrpSp;
342 NTSTATUS Status;
343
344 // DbgPrint("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp);
345
346 IrpSp = IoGetCurrentIrpStackLocation(Irp);
347
348 switch (IrpSp->MajorFunction) {
349 /* Open an address file, connection endpoint, or control connection */
350 case IRP_MJ_CREATE:
351 Status = TiCreateFileObject(DeviceObject, Irp);
352 break;
353
354 /* Close an address file, connection endpoint, or control connection */
355 case IRP_MJ_CLOSE:
356 Status = TiCloseFileObject(DeviceObject, Irp);
357 break;
358
359 default:
360 Status = STATUS_INVALID_DEVICE_REQUEST;
361 }
362
363 //DbgPrint("Leaving. Status is (0x%X)\n", Status);
364
365 return IRPFinish( Irp, Status );
366 }
367
368
369 NTSTATUS NTAPI
370 TiDispatchInternal(
371 PDEVICE_OBJECT DeviceObject,
372 PIRP Irp)
373 /*
374 * FUNCTION: Internal IOCTL dispatch routine
375 * ARGUMENTS:
376 * DeviceObject = Pointer to a device object for this driver
377 * Irp = Pointer to a I/O request packet
378 * RETURNS:
379 * Status of the operation
380 */
381 {
382 NTSTATUS Status;
383 BOOLEAN Complete = TRUE;
384 PIO_STACK_LOCATION IrpSp;
385
386 IrpSp = IoGetCurrentIrpStackLocation(Irp);
387
388 TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatchInternal] Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
389 DeviceObject, Irp, IrpSp->MinorFunction));
390
391 Irp->IoStatus.Status = STATUS_SUCCESS;
392 Irp->IoStatus.Information = 0;
393
394 switch (IrpSp->MinorFunction) {
395 case TDI_RECEIVE:
396 Status = DispTdiReceive(Irp);
397 Complete = FALSE;
398 break;
399
400 case TDI_RECEIVE_DATAGRAM:
401 Status = DispTdiReceiveDatagram(Irp);
402 Complete = FALSE;
403 break;
404
405 case TDI_SEND:
406 Status = DispTdiSend(Irp);
407 Complete = FALSE; /* Completed in DispTdiSend */
408 break;
409
410 case TDI_SEND_DATAGRAM:
411 Status = DispTdiSendDatagram(Irp);
412 Complete = FALSE;
413 break;
414
415 case TDI_ACCEPT:
416 Status = DispTdiAccept(Irp);
417 break;
418
419 case TDI_LISTEN:
420 Status = DispTdiListen(Irp);
421 Complete = FALSE;
422 break;
423
424 case TDI_CONNECT:
425 Status = DispTdiConnect(Irp);
426 Complete = FALSE; /* Completed by the TCP event handler */
427 break;
428
429 case TDI_DISCONNECT:
430 Status = DispTdiDisconnect(Irp);
431 Complete = FALSE;
432 break;
433
434 case TDI_ASSOCIATE_ADDRESS:
435 Status = DispTdiAssociateAddress(Irp);
436 break;
437
438 case TDI_DISASSOCIATE_ADDRESS:
439 Status = DispTdiDisassociateAddress(Irp);
440 break;
441
442 case TDI_QUERY_INFORMATION:
443 Status = DispTdiQueryInformation(DeviceObject, Irp);
444 break;
445
446 case TDI_SET_INFORMATION:
447 Status = DispTdiSetInformation(Irp);
448 break;
449
450 case TDI_SET_EVENT_HANDLER:
451 Status = DispTdiSetEventHandler(Irp);
452 break;
453
454 case TDI_ACTION:
455 Status = STATUS_SUCCESS;
456 break;
457
458 /* An unsupported IOCTL code was submitted */
459 default:
460 Status = STATUS_INVALID_DEVICE_REQUEST;
461 }
462
463 TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatchInternal] Leaving. Status = (0x%X).\n", Status));
464
465 if( Complete )
466 IRPFinish( Irp, Status );
467
468 return Status;
469 }
470
471
472 NTSTATUS NTAPI
473 TiDispatch(
474 PDEVICE_OBJECT DeviceObject,
475 PIRP Irp)
476 /*
477 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
478 * ARGUMENTS:
479 * DeviceObject = Pointer to a device object for this driver
480 * Irp = Pointer to a I/O request packet
481 * RETURNS:
482 * Status of the operation
483 */
484 {
485 NTSTATUS Status;
486 PIO_STACK_LOCATION IrpSp;
487
488 IrpSp = IoGetCurrentIrpStackLocation(Irp);
489
490 TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Called. IRP is at (0x%X).\n", Irp));
491
492 Irp->IoStatus.Information = 0;
493
494 #if 0
495 Status = TdiMapUserRequest(DeviceObject, Irp, IrpSp);
496 if (NT_SUCCESS(Status)) {
497 TiDispatchInternal(DeviceObject, Irp);
498 Status = STATUS_PENDING;
499 } else {
500 #else
501 if (TRUE) {
502 #endif
503 /* See if this request is TCP/IP specific */
504 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
505 case IOCTL_TCP_QUERY_INFORMATION_EX:
506 TI_DbgPrint(MIN_TRACE, ("TCP_QUERY_INFORMATION_EX\n"));
507 Status = DispTdiQueryInformationEx(Irp, IrpSp);
508 break;
509
510 case IOCTL_TCP_SET_INFORMATION_EX:
511 TI_DbgPrint(MIN_TRACE, ("TCP_SET_INFORMATION_EX\n"));
512 Status = DispTdiSetInformationEx(Irp, IrpSp);
513 break;
514
515 case IOCTL_SET_IP_ADDRESS:
516 TI_DbgPrint(MIN_TRACE, ("SET_IP_ADDRESS\n"));
517 Status = DispTdiSetIPAddress(Irp, IrpSp);
518 break;
519
520 case IOCTL_DELETE_IP_ADDRESS:
521 TI_DbgPrint(MIN_TRACE, ("DELETE_IP_ADDRESS\n"));
522 Status = DispTdiDeleteIPAddress(Irp, IrpSp);
523 break;
524
525 default:
526 TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n",
527 IrpSp->Parameters.DeviceIoControl.IoControlCode));
528 Status = STATUS_NOT_IMPLEMENTED;
529 break;
530 }
531 }
532
533 TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Leaving. Status = (0x%X).\n", Status));
534
535 return IRPFinish( Irp, Status );
536 }
537
538
539 VOID NTAPI TiUnload(
540 PDRIVER_OBJECT DriverObject)
541 /*
542 * FUNCTION: Unloads the driver
543 * ARGUMENTS:
544 * DriverObject = Pointer to driver object created by the system
545 */
546 {
547 #if DBG
548 KIRQL OldIrql;
549
550 TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
551 if (!IsListEmpty(&AddressFileListHead)) {
552 TI_DbgPrint(MIN_TRACE, ("[TCPIP, TiUnload] Called. Open address file objects exists.\n"));
553 }
554 TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
555 #endif
556 /* Cancel timer */
557 KeCancelTimer(&IPTimer);
558
559 /* Unregister loopback adapter */
560 LoopUnregisterAdapter(NULL);
561
562 /* Unregister protocol with NDIS */
563 LANUnregisterProtocol();
564
565 /* Shutdown transport level protocol subsystems */
566 TCPShutdown();
567 UDPShutdown();
568 RawIPShutdown();
569 ICMPShutdown();
570
571 /* Shutdown network level protocol subsystem */
572 IPShutdown();
573
574 /* Free NDIS buffer descriptors */
575 if (GlobalBufferPool)
576 NdisFreeBufferPool(GlobalBufferPool);
577
578 /* Free NDIS packet descriptors */
579 if (GlobalPacketPool)
580 NdisFreePacketPool(GlobalPacketPool);
581
582 /* Release all device objects */
583
584 if (TCPDeviceObject)
585 IoDeleteDevice(TCPDeviceObject);
586
587 if (UDPDeviceObject)
588 IoDeleteDevice(UDPDeviceObject);
589
590 if (RawIPDeviceObject)
591 IoDeleteDevice(RawIPDeviceObject);
592
593 if (IPDeviceObject) {
594 ChewShutdown();
595 IoDeleteDevice(IPDeviceObject);
596 }
597
598 if (EntityList)
599 ExFreePoolWithTag(EntityList, TDI_ENTITY_TAG);
600
601 TI_DbgPrint(MAX_TRACE, ("[TCPIP, TiUnload] Leaving.\n"));
602 }
603
604 NTSTATUS NTAPI
605 DriverEntry(
606 PDRIVER_OBJECT DriverObject,
607 PUNICODE_STRING RegistryPath)
608 /*
609 * FUNCTION: Main driver entry point
610 * ARGUMENTS:
611 * DriverObject = Pointer to a driver object for this driver
612 * RegistryPath = Registry node for configuration parameters
613 * RETURNS:
614 * Status of driver initialization
615 */
616 {
617 NTSTATUS Status;
618 UNICODE_STRING strIpDeviceName = RTL_CONSTANT_STRING(DD_IP_DEVICE_NAME);
619 UNICODE_STRING strRawDeviceName = RTL_CONSTANT_STRING(DD_RAWIP_DEVICE_NAME);
620 UNICODE_STRING strUdpDeviceName = RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME);
621 UNICODE_STRING strTcpDeviceName = RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME);
622 UNICODE_STRING strNdisDeviceName = RTL_CONSTANT_STRING(TCPIP_PROTOCOL_NAME);
623 NDIS_STATUS NdisStatus;
624 LARGE_INTEGER DueTime;
625
626 TI_DbgPrint(MAX_TRACE, ("[TCPIP, DriverEntry] Called\n"));
627
628 /* TdiInitialize() ? */
629
630 /* FIXME: Create symbolic links in Win32 namespace */
631
632 /* Initialize our periodic timer and its associated DPC object. When the
633 timer expires, the IPTimeout deferred procedure call (DPC) is queued */
634 KeInitializeDpc(&IPTimeoutDpc, IPTimeoutDpcFn, NULL);
635 KeInitializeTimer(&IPTimer);
636
637 /* Create IP device object */
638 Status = IoCreateDevice(DriverObject, 0, &strIpDeviceName,
639 FILE_DEVICE_NETWORK, 0, FALSE, &IPDeviceObject);
640 if (!NT_SUCCESS(Status)) {
641 TI_DbgPrint(MIN_TRACE, ("Failed to create IP device object. Status (0x%X).\n", Status));
642 TiUnload(DriverObject);
643 return Status;
644 }
645
646 ChewInit( IPDeviceObject );
647
648 /* Create RawIP device object */
649 Status = IoCreateDevice(DriverObject, 0, &strRawDeviceName,
650 FILE_DEVICE_NETWORK, 0, FALSE, &RawIPDeviceObject);
651 if (!NT_SUCCESS(Status)) {
652 TI_DbgPrint(MIN_TRACE, ("Failed to create RawIP device object. Status (0x%X).\n", Status));
653 TiUnload(DriverObject);
654 return Status;
655 }
656
657 /* Create UDP device object */
658 Status = IoCreateDevice(DriverObject, 0, &strUdpDeviceName,
659 FILE_DEVICE_NETWORK, 0, FALSE, &UDPDeviceObject);
660 if (!NT_SUCCESS(Status)) {
661 TI_DbgPrint(MIN_TRACE, ("Failed to create UDP device object. Status (0x%X).\n", Status));
662 TiUnload(DriverObject);
663 return Status;
664 }
665
666 /* Create TCP device object */
667 Status = IoCreateDevice(DriverObject, 0, &strTcpDeviceName,
668 FILE_DEVICE_NETWORK, 0, FALSE, &TCPDeviceObject);
669 if (!NT_SUCCESS(Status)) {
670 TI_DbgPrint(MIN_TRACE, ("Failed to create TCP device object. Status (0x%X).\n", Status));
671 TiUnload(DriverObject);
672 return Status;
673 }
674
675 /* Setup network layer and transport layer entities */
676 KeInitializeSpinLock(&EntityListLock);
677 EntityList = ExAllocatePoolWithTag(NonPagedPool,
678 sizeof(TDIEntityID) * MAX_TDI_ENTITIES,
679 TDI_ENTITY_TAG );
680 if (!EntityList) {
681 TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
682 TiUnload(DriverObject);
683 return STATUS_INSUFFICIENT_RESOURCES;
684 }
685
686 EntityCount = 0;
687 EntityMax = MAX_TDI_ENTITIES;
688
689 /* Allocate NDIS packet descriptors */
690 NdisAllocatePacketPoolEx(&NdisStatus, &GlobalPacketPool, 500, 1500, sizeof(PACKET_CONTEXT));
691 if (NdisStatus != NDIS_STATUS_SUCCESS) {
692 TiUnload(DriverObject);
693 return STATUS_INSUFFICIENT_RESOURCES;
694 }
695
696 /* Allocate NDIS buffer descriptors */
697 NdisAllocateBufferPool(&NdisStatus, &GlobalBufferPool, 2000);
698 if (NdisStatus != NDIS_STATUS_SUCCESS) {
699 TiUnload(DriverObject);
700 return STATUS_INSUFFICIENT_RESOURCES;
701 }
702
703 /* Initialize address file list and protecting spin lock */
704 InitializeListHead(&AddressFileListHead);
705 KeInitializeSpinLock(&AddressFileListLock);
706
707 /* Initialize connection endpoint list and protecting spin lock */
708 InitializeListHead(&ConnectionEndpointListHead);
709 KeInitializeSpinLock(&ConnectionEndpointListLock);
710
711 /* Initialize interface list and protecting spin lock */
712 InitializeListHead(&InterfaceListHead);
713 KeInitializeSpinLock(&InterfaceListLock);
714
715 /* Initialize network level protocol subsystem */
716 IPStartup(RegistryPath);
717
718 /* Initialize transport level protocol subsystems */
719 Status = RawIPStartup();
720 if( !NT_SUCCESS(Status) ) {
721 TiUnload(DriverObject);
722 return Status;
723 }
724
725 Status = UDPStartup();
726 if( !NT_SUCCESS(Status) ) {
727 TiUnload(DriverObject);
728 return Status;
729 }
730
731 Status = TCPStartup();
732 if( !NT_SUCCESS(Status) ) {
733 TiUnload(DriverObject);
734 return Status;
735 }
736
737 Status = ICMPStartup();
738 if( !NT_SUCCESS(Status) ) {
739 TiUnload(DriverObject);
740 return Status;
741 }
742
743 /* Use direct I/O */
744 IPDeviceObject->Flags |= DO_DIRECT_IO;
745 RawIPDeviceObject->Flags |= DO_DIRECT_IO;
746 UDPDeviceObject->Flags |= DO_DIRECT_IO;
747 TCPDeviceObject->Flags |= DO_DIRECT_IO;
748
749 /* Initialize the driver object with this driver's entry points */
750 DriverObject->MajorFunction[IRP_MJ_CREATE] = TiDispatchOpenClose;
751 DriverObject->MajorFunction[IRP_MJ_CLOSE] = TiDispatchOpenClose;
752 DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = TiDispatchInternal;
753 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TiDispatch;
754
755 DriverObject->DriverUnload = TiUnload;
756
757 /* Open loopback adapter */
758 Status = LoopRegisterAdapter(NULL, NULL);
759 if (!NT_SUCCESS(Status)) {
760 TI_DbgPrint(MIN_TRACE, ("Failed to create loopback adapter. Status (0x%X).\n", Status));
761 TiUnload(DriverObject);
762 return Status;
763 }
764
765 /* Register protocol with NDIS */
766 /* This used to be IP_DEVICE_NAME but the DDK says it has to match your entry in the SCM */
767 Status = LANRegisterProtocol(&strNdisDeviceName);
768 if (!NT_SUCCESS(Status)) {
769 TI_DbgPrint(MIN_TRACE,("Failed to register protocol with NDIS; status 0x%x\n", Status));
770 TiWriteErrorLog(
771 DriverObject,
772 EVENT_TRANSPORT_REGISTER_FAILED,
773 TI_ERROR_DRIVERENTRY,
774 Status,
775 NULL,
776 0,
777 NULL);
778 TiUnload(DriverObject);
779 return Status;
780 }
781
782 /* Start the periodic timer with an initial and periodic
783 relative expiration time of IP_TIMEOUT milliseconds */
784 DueTime.QuadPart = -(LONGLONG)IP_TIMEOUT * 10000;
785 KeSetTimerEx(&IPTimer, DueTime, IP_TIMEOUT, &IPTimeoutDpc);
786
787 TI_DbgPrint(MAX_TRACE, ("[TCPIP, DriverEntry] Finished\n"));
788
789
790 return STATUS_SUCCESS;
791 }
792
793 VOID NTAPI
794 IPAddInterface(
795 ULONG Unknown0,
796 ULONG Unknown1,
797 ULONG Unknown2,
798 ULONG Unknown3,
799 ULONG Unknown4)
800 {
801 UNIMPLEMENTED
802 }
803
804
805 VOID NTAPI
806 IPDelInterface(
807 ULONG Unknown0)
808 {
809 UNIMPLEMENTED
810 }
811
812
813 VOID NTAPI
814 LookupRoute(
815 ULONG Unknown0,
816 ULONG Unknown1)
817 {
818 UNIMPLEMENTED
819 }
820
821 /* EOF */