ReactOS  0.4.13-dev-92-gf251225
tditest.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS TDI test driver
4  * FILE: tditest.c
5  * PURPOSE: Testing TDI drivers
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * Vizzini (vizzini@plasmic.com)
8  * REVISIONS:
9  * CSH 01/08-2000 Created
10  * 26-Nov-2003 Vizzini Updated to run properly on Win2ksp4
11  */
12 #include <tditest.h>
13 #include <pseh/pseh2.h>
14 
15 
16 #if DBG
17 
18 /* See debug.h for debug/trace constants */
20 
21 #endif /* DBG */
22 
23 
31 
33  PIRP Irp,
36  BOOLEAN CanCancel)
37 /*
38  * FUNCTION: Calls a transport driver device
39  * ARGUMENTS:
40  * Irp = Pointer to I/O Request Packet
41  * DeviceObject = Pointer to device object to call
42  * IoStatusBlock = Address of buffer with I/O status block
43  * CanCancel = TRUE if the IRP can be cancelled, FALSE if not
44  * RETURNS:
45  * Status of operation
46  * NOTES
47  * All requests are completed synchronously. A request may be cancelled
48  */
49 {
50  KEVENT Event;
51  PKEVENT Events[2];
53  Events[0] = &StopEvent;
54  Events[1] = &Event;
55 
57  Irp->UserEvent = &Event;
58  Irp->UserIosb = IoStatusBlock;
59 
61 
62  if (Status == STATUS_PENDING)
63  {
64  if (CanCancel)
65  {
67 
68  if (KeReadStateEvent(&StopEvent) != 0)
69  {
70  if (IoCancelIrp(Irp))
71  {
72  TDI_DbgPrint(MAX_TRACE, ("Cancelled IRP.\n"));
73  }
74  else
75  {
76  TDI_DbgPrint(MIN_TRACE, ("Could not cancel IRP.\n"));
77  }
78  return STATUS_CANCELLED;
79  }
80  }
81  else
83  }
84 
86 }
87 
88 
95 /*
96  * FUNCTION: Opens a device
97  * ARGUMENTS:
98  * Protocol = Pointer to buffer with name of device
99  * EaLength = Length of EA information
100  * EaInfo = Pointer to buffer with EA information
101  * Handle = Address of buffer to place device handle
102  * Object = Address of buffer to place device object
103  * RETURNS:
104  * Status of operation
105  */
106 {
107  OBJECT_ATTRIBUTES Attr;
111 
114  &Attr, /* Attribute buffer */
115  &Name, /* Device name */
116  OBJ_CASE_INSENSITIVE, /* Attributes */
117  NULL, /* Root directory */
118  NULL); /* Security descriptor */
119 
120  Status = ZwCreateFile(
121  Handle, /* Return file handle */
122  GENERIC_READ | GENERIC_WRITE, /* Desired access */
123  &Attr, /* Object attributes */
124  &Iosb, /* IO status */
125  0, /* Initial allocation size */
126  FILE_ATTRIBUTE_NORMAL, /* File attributes */
127  FILE_SHARE_READ | FILE_SHARE_WRITE, /* Share access */
128  FILE_OPEN_IF, /* Create disposition */
129  0, /* Create options */
130  EaInfo, /* EA buffer */
131  EaLength); /* EA length */
132 
133  if (NT_SUCCESS(Status))
134  {
136  *Handle, /* Handle to open file */
137  GENERIC_READ | GENERIC_WRITE, /* Access mode */
138  NULL, /* Object type */
139  KernelMode, /* Access mode */
140  (PVOID*)Object, /* Pointer to object */
141  NULL); /* Handle information */
142 
143  if (!NT_SUCCESS(Status))
144  {
145  TDI_DbgPrint(MIN_TRACE, ("ObReferenceObjectByHandle() failed with status (0x%X).\n", Status));
146  ZwClose(*Handle);
147  }
148  }
149  else
150  {
151  TDI_DbgPrint(MIN_TRACE, ("ZwCreateFile() failed with status (0x%X)\n", Status));
152  }
153 
154  return Status;
155 }
156 
157 
159  HANDLE Handle,
161 {
162  if (FileObject)
164 
165  if (Handle)
166  ZwClose(Handle);
167 
168  return STATUS_SUCCESS;
169 }
170 
171 
173  PWSTR Protocol,
174  USHORT Port,
175  PHANDLE Transport,
176  PFILE_OBJECT *TransportObject)
177 /*
178  * FUNCTION: Opens a transport driver
179  * ARGUMENTS:
180  * Protocol = Pointer to buffer with name of device
181  * Port = Port number to use
182  * Transport = Address of buffer to place transport device handle
183  * TransportObject = Address of buffer to place transport object
184  * RETURNS:
185  * Status of operation
186  */
187 {
191  ULONG EaLength;
192 
193  /* EaName must be 0-termed, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
196 
197  if (!EaInfo)
198  {
199  TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
201  }
202 
203  RtlZeroMemory(EaInfo, EaLength);
204 
206 
207  /* don't copy the 0; we have already zeroed it */
209 
210  EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
211  Address = (PTA_IP_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); // 0-term
212  Address->TAAddressCount = 1;
213  Address->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
214  Address->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
215  Address->Address[0].Address[0].sin_port = WH2N(Port);
216  Address->Address[0].Address[0].in_addr = 0;
217 
218  Status = TdiOpenDevice(Protocol, EaLength, EaInfo, Transport, TransportObject);
219 
220  ExFreePool(EaInfo);
221 
222  return Status;
223 }
224 
225 
233  PULONG Return)
234 /*
235  * FUNCTION: Queries a device for information
236  * ARGUMENTS:
237  * FileObject = Pointer to device object
238  * IoControlCode = I/O control code
239  * InputBuffer = Pointer to buffer with input data
240  * InputBufferLength = Length of InputBuffer
241  * OutputBuffer = Address of buffer to place output data
242  * OutputBufferLength = Length of OutputBuffer
243  * RETURNS:
244  * Status of operation
245  */
246 {
248  PIO_STACK_LOCATION IoStack;
251  PIRP Irp;
252 
256 
257  if (!Irp)
258  {
259  TDI_DbgPrint(MIN_TRACE, ("IoBuildDeviceIoControlRequest() failed.\n"));
261  }
262 
263  IoStack = IoGetNextIrpStackLocation(Irp);
264  IoStack->DeviceObject = DeviceObject;
265  IoStack->FileObject = FileObject;
267 
268  if (Return)
269  *Return = Iosb.Information;
270 
271  return Status;
272 }
273 
274 
277  ULONG Entity,
278  ULONG Instance,
279  ULONG Class,
280  ULONG Type,
281  ULONG Id,
283  PULONG OutputLength)
284 /*
285  * FUNCTION: Extended query for information
286  * ARGUMENTS:
287  * FileObject = Pointer to transport object
288  * Entity = Entity
289  * Instance = Instance
290  * Class = Entity class
291  * Type = Entity type
292  * Id = Entity id
293  * OutputBuffer = Address of buffer to place data
294  * OutputLength = Address of buffer with length of OutputBuffer (updated)
295  * RETURNS:
296  * Status of operation
297  */
298 {
300 
301  RtlZeroMemory(&QueryInfo, sizeof(TCP_REQUEST_QUERY_INFORMATION_EX));
302  QueryInfo.ID.toi_entity.tei_entity = Entity;
303  QueryInfo.ID.toi_entity.tei_instance = Instance;
304  QueryInfo.ID.toi_class = Class;
305  QueryInfo.ID.toi_type = Type;
306  QueryInfo.ID.toi_id = Id;
307 
308  return TdiQueryDeviceControl(
309  FileObject, /* Transport/connection object */
310  IOCTL_TCP_QUERY_INFORMATION_EX, /* Control code */
311  &QueryInfo, /* Input buffer */
312  sizeof(TCP_REQUEST_QUERY_INFORMATION_EX), /* Input buffer length */
313  OutputBuffer, /* Output buffer */
314  *OutputLength, /* Output buffer length */
315  OutputLength); /* Return information */
316 }
317 
318 
321  PULONG Address)
322 /*
323  * FUNCTION: Queries for a local IP address
324  * ARGUMENTS:
325  * FileObject = Pointer to file object
326  * Address = Address of buffer to place local address
327  * RETURNS:
328  * Status of operation
329  */
330 {
331  ULONG i;
332  TDIEntityID *Entities;
334  ULONG EntityType;
335  IPSNMP_INFO SnmpInfo;
336  PIPADDR_ENTRY IpAddress;
339 
340  TDI_DbgPrint(MAX_TRACE, ("Called\n"));
341 
342  BufferSize = sizeof(TDIEntityID) * 20;
344 
345  if (!Entities)
346  {
347  TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
349  }
350 
351  /* Query device for supported entities */
353  FileObject, /* File object */
354  GENERIC_ENTITY, /* Entity */
355  TL_INSTANCE, /* Instance */
356  INFO_CLASS_GENERIC, /* Entity class */
357  INFO_TYPE_PROVIDER, /* Entity type */
358  ENTITY_LIST_ID, /* Entity id */
359  Entities, /* Output buffer */
360  &BufferSize); /* Output buffer size */
361 
362  if (!NT_SUCCESS(Status))
363  {
364  TDI_DbgPrint(MIN_TRACE, ("Unable to get list of supported entities (Status = 0x%X).\n", Status));
365  ExFreePool(Entities);
366  return Status;
367  }
368 
369  /* Locate an IP entity */
370  EntityCount = BufferSize / sizeof(TDIEntityID);
371 
372  TDI_DbgPrint(MAX_TRACE, ("EntityCount = %d\n", EntityCount));
373 
374  for (i = 0; i < EntityCount; i++)
375  {
376  if (Entities[i].tei_entity == CL_NL_ENTITY)
377  {
378  /* Query device for entity type */
379  BufferSize = sizeof(EntityType);
381  FileObject, /* File object */
382  CL_NL_ENTITY, /* Entity */
383  Entities[i].tei_instance, /* Instance */
384  INFO_CLASS_GENERIC, /* Entity class */
385  INFO_TYPE_PROVIDER, /* Entity type */
386  ENTITY_TYPE_ID, /* Entity id */
387  &EntityType, /* Output buffer */
388  &BufferSize); /* Output buffer size */
389 
390  if (!NT_SUCCESS(Status) || (EntityType != CL_NL_IP))
391  {
392  TDI_DbgPrint(MIN_TRACE, ("Unable to get entity of type IP (Status = 0x%X).\n", Status));
393  break;
394  }
395 
396  /* Query device for SNMP information */
397  BufferSize = sizeof(SnmpInfo);
399  FileObject, /* File object */
400  CL_NL_ENTITY, /* Entity */
401  Entities[i].tei_instance, /* Instance */
402  INFO_CLASS_PROTOCOL, /* Entity class */
403  INFO_TYPE_PROVIDER, /* Entity type */
404  IP_MIB_STATS_ID, /* Entity id */
405  &SnmpInfo, /* Output buffer */
406  &BufferSize); /* Output buffer size */
407 
408  if (!NT_SUCCESS(Status) || (SnmpInfo.NumAddr == 0))
409  {
410  TDI_DbgPrint(MIN_TRACE, ("Unable to get SNMP information or no IP addresses available (Status = 0x%X).\n", Status));
411  break;
412  }
413 
414  /* Query device for all IP addresses */
415  if (SnmpInfo.NumAddr != 0)
416  {
417  BufferSize = SnmpInfo.NumAddr * sizeof(IPADDR_ENTRY);
419  if (!IpAddress)
420  {
421  TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
422  break;
423  }
424 
426  FileObject, /* File object */
427  CL_NL_ENTITY, /* Entity */
428  Entities[i].tei_instance, /* Instance */
429  INFO_CLASS_PROTOCOL, /* Entity class */
430  INFO_TYPE_PROVIDER, /* Entity type */
431  IP_MIB_ADDRTABLE_ENTRY_ID, /* Entity id */
432  IpAddress, /* Output buffer */
433  &BufferSize); /* Output buffer size */
434 
435  if (!NT_SUCCESS(Status))
436  {
437  TDI_DbgPrint(MIN_TRACE, ("Unable to get IP address (Status = 0x%X).\n", Status));
438  ExFreePool(IpAddress);
439  break;
440  }
441 
442  if (SnmpInfo.NumAddr != 1)
443  {
444  /* Skip loopback address */
445  *Address = DN2H(((PIPADDR_ENTRY)((PUCHAR)IpAddress + sizeof(IPADDR_ENTRY)))->Addr);
446  }
447  else
448  {
449  /* Select the first address returned */
450  *Address = DN2H(IpAddress->Addr);
451  }
452  ExFreePool(IpAddress);
453 
454  }
455  else
456  {
458  break;
459  }
460  }
461  }
462 
463  ExFreePool(Entities);
464 
465  TDI_DbgPrint(MAX_TRACE, ("Leaving\n"));
466 
467  return Status;
468 }
469 
470 
472  PFILE_OBJECT TransportObject,
473  USHORT Port,
474  ULONG Address,
475  PVOID Buffer,
477 /*
478  * FUNCTION: Sends a datagram
479  * ARGUMENTS:
480  * TransportObject = Pointer to transport object
481  * Port = Remote port
482  * Address = Remote address
483  * Buffer = Pointer to buffer with data to send
484  * BufferSize = Length of Buffer
485  * RETURNS:
486  * Status of operation
487  */
488 {
489  PIRP Irp;
490  PMDL Mdl;
492  PTDI_CONNECTION_INFORMATION ConnectInfo;
493  PTA_IP_ADDRESS TA;
494  PTDI_ADDRESS_IP IpAddress;
497 
498  DeviceObject = IoGetRelatedDeviceObject(TransportObject);
499  ConnectInfo = (PTDI_CONNECTION_INFORMATION)
502  sizeof(TA_IP_ADDRESS));
503 
504  if (!ConnectInfo)
506 
507  RtlZeroMemory(ConnectInfo, sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
508 
509  ConnectInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
510  ConnectInfo->RemoteAddress = ((PUCHAR)ConnectInfo + sizeof(TDI_CONNECTION_INFORMATION));
511 
512  TA = (PTA_IP_ADDRESS)(ConnectInfo->RemoteAddress);
513  TA->TAAddressCount = 1;
514  TA->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
515  TA->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
516  IpAddress = (PTDI_ADDRESS_IP)(TA->Address[0].Address);
517  IpAddress->sin_port = WH2N(Port);
518  IpAddress->in_addr = DH2N(Address);
520  TDI_SEND_DATAGRAM, /* Sub function */
521  DeviceObject, /* Device object */
522  TransportObject, /* File object */
523  NULL, /* Event */
524  NULL); /* Return buffer */
525 
526  if (!Irp)
527  {
528  TDI_DbgPrint(MIN_TRACE, ("TdiBuildInternalDeviceControlIrp() failed.\n"));
529  ExFreePool(ConnectInfo);
531  }
532 
533  Mdl = IoAllocateMdl(
534  Buffer, /* Virtual address of buffer */
535  BufferSize, /* Length of buffer */
536  FALSE, /* Not secondary */
537  FALSE, /* Don't charge quota */
538  NULL); /* Don't use IRP */
539 
540  if (!Mdl)
541  {
542  TDI_DbgPrint(MIN_TRACE, ("IoAllocateMdl() failed.\n"));
543  IoFreeIrp(Irp);
544  ExFreePool(ConnectInfo);
546  }
547 
548  _SEH2_TRY
549  {
551  }
553  {
554  TDI_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
555  IoFreeMdl(Mdl);
556  IoFreeIrp(Irp);
557  ExFreePool(ConnectInfo);
559  } _SEH2_END;
560 
562  Irp, /* I/O Request Packet */
563  DeviceObject, /* Device object */
564  TransportObject, /* File object */
565  NULL, /* Completion routine */
566  NULL, /* Completion context */
567  Mdl, /* Descriptor for data buffer */
568  BufferSize, /* Size of data to send */
569  ConnectInfo); /* Connection information */
570 
572 
573  ExFreePool(ConnectInfo);
574 
575  return Status;
576 }
577 
578 
580  PFILE_OBJECT TransportObject,
581  USHORT Port,
582  PULONG Address,
583  PUCHAR Buffer,
585 /*
586  * FUNCTION: Receives a datagram
587  * ARGUMENTS:
588  * TransportObject = Pointer to transport object
589  * Port = Port to receive on
590  * Address = Address of buffer to place remote address
591  * Buffer = Address of buffer to place received data
592  * BufferSize = Address of buffer with length of Buffer (updated)
593  * RETURNS:
594  * Status of operation
595  */
596 {
597  PTDI_CONNECTION_INFORMATION ReceiveInfo;
598  PTDI_CONNECTION_INFORMATION ReturnInfo;
599  PTA_IP_ADDRESS ReturnAddress;
601  PTDI_ADDRESS_IP IpAddress;
603  PVOID MdlBuffer;
605  PIRP Irp;
606  PMDL Mdl;
607 
608  DeviceObject = IoGetRelatedDeviceObject(TransportObject);
609  if (!DeviceObject)
611 
615  sizeof(TA_IP_ADDRESS));
616 
617  if (!ReceiveInfo)
619 
620  MdlBuffer = ExAllocatePool(PagedPool, *BufferSize);
621  if (!MdlBuffer)
623 
625  sizeof(TA_IP_ADDRESS));
626 
627  RtlCopyMemory(MdlBuffer, Buffer, *BufferSize);
628 
629  /* Receive from any address */
630  ReceiveInfo->RemoteAddressLength = 0;
631  ReceiveInfo->RemoteAddress = NULL;
632 
633  ReturnInfo = (PTDI_CONNECTION_INFORMATION) ((PUCHAR)ReceiveInfo + sizeof(TDI_CONNECTION_INFORMATION));
634  ReturnInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
635  ReturnInfo->RemoteAddress = ((PUCHAR)ReturnInfo + sizeof(TDI_CONNECTION_INFORMATION));
636 
637  ReturnAddress = (PTA_IP_ADDRESS)(ReturnInfo->RemoteAddress);
638  ReturnAddress->TAAddressCount = 1;
639  ReturnAddress->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
640  ReturnAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
641 
642  IpAddress = (PTDI_ADDRESS_IP)(ReturnAddress->Address[0].Address);
643  IpAddress->sin_port = WH2N(Port);
644  IpAddress->in_addr = DH2N(LocalAddress);
645 
647  TDI_RECEIVE_DATAGRAM, /* Sub function */
648  DeviceObject, /* Device object */
649  TransportObject, /* File object */
650  NULL, /* Event */
651  NULL); /* Return buffer */
652 
653  if (!Irp)
654  {
655  ExFreePool(MdlBuffer);
656  ExFreePool(ReceiveInfo);
658  }
659 
660  Mdl = IoAllocateMdl(
661  MdlBuffer, /* Virtual address */
662  *BufferSize, /* Length of buffer */
663  FALSE, /* Not secondary */
664  FALSE, /* Don't charge quota */
665  NULL); /* Don't use IRP */
666 
667  if (!Mdl)
668  {
669  IoFreeIrp(Irp);
670  ExFreePool(MdlBuffer);
671  ExFreePool(ReceiveInfo);
673  }
674 
675  _SEH2_TRY
676  {
678  }
680  {
681  TDI_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
682  IoFreeMdl(Mdl);
683  IoFreeIrp(Irp);
684  ExFreePool(MdlBuffer);
685  ExFreePool(ReceiveInfo);
687  } _SEH2_END;
688 
690  Irp, /* I/O Request Packet */
691  DeviceObject, /* Device object */
692  TransportObject, /* File object */
693  NULL, /* Completion routine */
694  NULL, /* Completion context */
695  Mdl, /* Data buffer */
696  *BufferSize, /* Size of data buffer */
697  ReceiveInfo, /* Connection information */
698  ReturnInfo, /* Connection information */
699  TDI_RECEIVE_NORMAL); /* Flags */
700 
702 
703  if (NT_SUCCESS(Status))
704  {
705  RtlCopyMemory(Buffer, MdlBuffer, Iosb.Information);
706  *BufferSize = Iosb.Information;
707  *Address = DN2H(IpAddress->in_addr);
708  }
709 
710  ExFreePool(MdlBuffer);
711  ExFreePool(ReceiveInfo);
712 
713  return Status;
714 }
715 
716 
718  PVOID Context)
719 /*
720  * FUNCTION: Send thread
721  * ARGUMENTS:
722  * Context = Pointer to context information
723  * NOTES:
724  * Transmits an UDP packet every two seconds to ourselves on the chosen port
725  */
726 {
727  KEVENT Event;
728  PKEVENT Events[2];
731  UCHAR Data[40] = "Testing one, two, three, ...";
732 
733  if (!OpenError)
734  {
735  Timeout.QuadPart = 10000000L; /* Second factor */
736  Timeout.QuadPart *= 2; /* Number of seconds */
737  Timeout.QuadPart = -(Timeout.QuadPart); /* Relative time */
738 
740 
741  Events[0] = &StopEvent;
742  Events[1] = &Event;
743 
744  while (NT_SUCCESS(Status))
745  {
746  /* Wait until timeout or stop flag is set */
748 
749  if (KeReadStateEvent(&StopEvent) != 0)
750  {
751  TDI_DbgPrint(MAX_TRACE, ("Received terminate signal...\n"));
752  break;
753  }
754 
755  DbgPrint("Sending data - '%s'\n", Data);
756 
758 
759  if (!NT_SUCCESS(Status))
760  DbgPrint("Failed sending data (Status = 0x%X)\n", Status);
761  }
762  }
763 
764  TDI_DbgPrint(MAX_TRACE, ("Terminating send thread...\n"));
765 
767 }
768 
769 
771  PVOID Context)
772 /*
773  * FUNCTION: Receive thread
774  * ARGUMENTS:
775  * Context = Pointer to context information
776  * NOTES:
777  * Waits until an UDP packet is received on the chosen endpoint and displays the data
778  */
779 {
780  ULONG Address;
781  UCHAR Data[40];
782  ULONG Size;
784 
785  if (!OpenError)
786  {
787  while (NT_SUCCESS(Status))
788  {
789  Size = sizeof(Data);
791 
793 
794  if (NT_SUCCESS(Status))
795  {
796  DbgPrint("Received data - '%s'\n", Data);
797  }
798  else
799  if (Status != STATUS_CANCELLED)
800  {
801  TDI_DbgPrint(MIN_TRACE, ("Receive error (Status = 0x%X).\n", Status));
802  }
803  else
804  {
805  TDI_DbgPrint(MAX_TRACE, ("IRP was cancelled.\n"));
806  }
807  }
808  }
809 
810  TDI_DbgPrint(MAX_TRACE, ("Terminating receive thread...\n"));
811 
813 }
814 
815 
817  PVOID Context)
818 /*
819  * FUNCTION: Open thread
820  * ARGUMENTS:
821  * Context = Pointer to context information (event)
822  */
823 {
825 
826  TDI_DbgPrint(MAX_TRACE, ("Called.\n"));
827 
828  OpenError = TRUE;
829 
831 
832  if (NT_SUCCESS(Status))
833  {
835 
836  if (NT_SUCCESS(Status))
837  {
838  OpenError = FALSE;
839  DbgPrint("Using local IP address 0x%X\n", LocalAddress);
840  }
841  else
842  {
843  TDI_DbgPrint(MIN_TRACE, ("Unable to determine local IP address.\n"));
844  }
845  }
846  else
847  TDI_DbgPrint(MIN_TRACE, ("Cannot open transport (Status = 0x%X).\n", Status));
848 
849  TDI_DbgPrint(MAX_TRACE, ("Setting close event.\n"));
850 
852 
853  TDI_DbgPrint(MIN_TRACE, ("Leaving.\n"));
854 }
855 
856 
859 /*
860  * FUNCTION: Unload routine
861  * ARGUMENTS:
862  * DriverObject = Pointer to a driver object for this driver
863  */
864 {
865  PVOID ReceiveThreadObject = 0;
866  PVOID SendThreadObject = 0;
867 
868  TDI_DbgPrint(MAX_TRACE, ("Setting stop flag\n"));
869 
870  /* Get pointers to the thread objects */
873 
874  KeSetEvent(&StopEvent, 0, FALSE);
875 
876  /* Wait for send thread to stop */
877  KeWaitForSingleObject(SendThreadObject, Executive, KernelMode, FALSE, NULL);
878 
879  /* Wait for receive thread to stop */
880  KeWaitForSingleObject(ReceiveThreadObject, Executive, KernelMode, FALSE, NULL);
881 
882  /* Close device */
884 }
885 
886 
887 NTSTATUS
888 NTAPI
892 /*
893  * FUNCTION: Main driver entry point
894  * ARGUMENTS:
895  * DriverObject = Pointer to a driver object for this driver
896  * RegistryPath = Registry node for configuration parameters
897  * RETURNS:
898  * Status of driver initialization
899  */
900 {
901  KEVENT Event;
903  WORK_QUEUE_ITEM WorkItem;
904 
906 
907  /* Call TdiOpenThread() */
910  ExQueueWorkItem(&WorkItem, DelayedWorkQueue);
912 
913  /* Create a UDP send thread that sends a dgram every 2 seconds */
915  &SendThread, /* Thread handle */
916  0, /* Desired access */
917  NULL, /* Object attributes */
918  NULL, /* Process handle */
919  NULL, /* Client id */
920  (PKSTART_ROUTINE)TdiSendThread, /* Start routine */
921  NULL); /* Start context */
922 
923  if (!NT_SUCCESS(Status))
924  {
925  TDI_DbgPrint(MIN_TRACE, ("PsCreateSystemThread() failed for send thread (Status = 0x%X).\n", Status));
927  }
928 
929  /* Create a UDP receive thread */
931  &ReceiveThread, /* Thread handle */
932  0, /* Desired access */
933  NULL, /* Object attributes */
934  NULL, /* Process handle */
935  NULL, /* Client id */
936  (PKSTART_ROUTINE)TdiReceiveThread, /* Start routine */
937  NULL); /* Start context */
938 
939  if (!NT_SUCCESS(Status))
940  {
941  TDI_DbgPrint(MIN_TRACE, ("PsCreateSystemThread() failed for receive thread (Status = 0x%X).\n", Status));
944  }
945 
947 
948  return STATUS_SUCCESS;
949 }
950 
951 /* EOF */
952 
TDIEntityID toi_entity
Definition: tdiinfo.h:74
static const WCHAR Class[]
Definition: cfgmgr.c:31
LONG TAAddressCount
Definition: tdi.h:523
CPPORT Port[4]
Definition: headless.c:34
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
ULONG EntityCount
Definition: main.c:24
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_OPEN_IF
Definition: from_kernel.h:56
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
Type
Definition: Type.h:6
ULONG toi_class
Definition: tdiinfo.h:75
#define DbgPrint
Definition: loader.c:25
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
_In_ PIRP Irp
Definition: csq.h:116
ULONG NumAddr
Definition: tditest.h:88
VOID TdiReceiveThread(PVOID Context)
Definition: tditest.c:770
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
struct _TDIEntityID TDIEntityID
Definition: afd.h:56
unsigned char * PUCHAR
Definition: retypes.h:3
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
NTSTATUS TdiQueryAddress(PFILE_OBJECT FileObject, PULONG Address)
Definition: tditest.c:319
LONG NTSTATUS
Definition: precomp.h:26
#define ENTITY_TYPE_ID
Definition: tdiinfo.h:39
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
NTSTATUS TdiReceiveDatagram(PFILE_OBJECT TransportObject, USHORT Port, PULONG Address, PUCHAR Buffer, PULONG BufferSize)
Definition: tditest.c:579
#define WH2N(w)
Definition: addrconv.c:40
#define TdiBuildSendDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)
Definition: tdikrnl.h:761
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define IOCTL_TCP_QUERY_INFORMATION_EX
Definition: ticonsts.h:42
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define CL_NL_IP
Definition: tdiinfo.h:54
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define FILE_SHARE_READ
Definition: compat.h:125
_SEH2_TRY
Definition: create.c:4250
DWORD Id
DRIVER_UNLOAD * PDRIVER_UNLOAD
Definition: iotypes.h:2144
ULONG LocalAddress
Definition: tditest.c:26
#define TDI_RECEIVE_NORMAL
Definition: tdi.h:122
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define TL_INSTANCE
Definition: afd.h:34
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:487
#define GENERIC_WRITE
Definition: nt_native.h:90
ULONG toi_id
Definition: tdiinfo.h:77
struct NameRec_ * Name
Definition: cdprocs.h:464
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS TdiCloseDevice(HANDLE Handle, PFILE_OBJECT FileObject)
Definition: tditest.c:158
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
Definition: bufpool.h:45
#define TDI_RECEIVE_DATAGRAM
Definition: tdikrnl.h:56
struct _TA_ADDRESS_IP::_AddrIp Address[1]
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
VOID TdiUnload(PDRIVER_OBJECT DriverObject)
Definition: tditest.c:857
NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, BOOLEAN CanCancel)
Definition: tditest.c:32
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
ULONG DebugTraceLevel
Definition: ndis.c:13
#define TdiBuildInternalDeviceControlIrp(IrpSubFunction, DeviceObject, FileObject, Event, IoStatusBlock)
Definition: tdikrnl.h:573
_In_ HANDLE Handle
Definition: extypes.h:390
struct IPADDR_ENTRY * PIPADDR_ENTRY
#define TEST_PORT
Definition: tditest.h:116
ULONG tei_entity
Definition: tdiinfo.h:31
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: tditest.c:889
#define IP_MIB_STATS_ID
Definition: afd.h:35
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:866
#define INFO_CLASS_GENERIC
Definition: tdiinfo.h:64
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
NTSTATUS TdiSendDatagram(PFILE_OBJECT TransportObject, USHORT Port, ULONG Address, PVOID Buffer, ULONG BufferSize)
Definition: tditest.c:471
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
ULONG tei_instance
Definition: tdiinfo.h:32
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define BufferSize
Definition: classpnp.h:419
BOOLEAN OpenError
Definition: tditest.c:27
ULONG in_addr
Definition: tdi.h:409
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2866
VOID TdiOpenThread(PVOID Context)
Definition: tditest.c:816
HANDLE TdiTransport
Definition: tditest.c:24
* PFILE_OBJECT
Definition: iotypes.h:1954
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
struct _TA_ADDRESS_IP TA_IP_ADDRESS
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
static IUnknown Object
Definition: main.c:512
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PFILE_OBJECT TdiTransportObject
Definition: tditest.c:25
unsigned char UCHAR
Definition: xmlstorage.h:181
#define CL_NL_ENTITY
Definition: tdiinfo.h:42
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define TdiBuildReceiveDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)
Definition: tdikrnl.h:699
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
struct _FILE_FULL_EA_INFORMATION FILE_FULL_EA_INFORMATION
#define GENERIC_READ
Definition: compat.h:124
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
struct _TDI_CONNECTION_INFORMATION TDI_CONNECTION_INFORMATION
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
USHORT sin_port
Definition: tdi.h:408
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
HANDLE ReceiveThread
Definition: tditest.c:30
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
NTSTATUS TdiOpenTransport(PWSTR Protocol, USHORT Port, PHANDLE Transport, PFILE_OBJECT *TransportObject)
Definition: tditest.c:172
_SEH2_END
Definition: create.c:4424
struct _TDI_ADDRESS_IP TDI_ADDRESS_IP
#define UDP_DEVICE_NAME
Definition: tditest.h:17
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
HANDLE Events[2]
Definition: schedsvc.c:40
unsigned short USHORT
Definition: pedump.c:61
#define ENTITY_LIST_ID
Definition: tdiinfo.h:38
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
HANDLE SendThread
Definition: tditest.c:29
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define DN2H(dw)
Definition: addrconv.c:21
#define DH2N(dw)
Definition: addrconv.c:28
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define TdiTransportAddress
Definition: tdi.h:370
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
IN PVOID Instance
Definition: pci.h:359
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
#define INFO_TYPE_PROVIDER
Definition: tdiinfo.h:69
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
#define TDI_SEND_DATAGRAM
Definition: tdikrnl.h:55
ULONG Addr
Definition: afd.h:57
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
NTSTATUS TdiOpenDevice(PWSTR Protocol, ULONG EaLength, PFILE_FULL_EA_INFORMATION EaInfo, PHANDLE Handle, PFILE_OBJECT *Object)
Definition: tditest.c:89
NTSTATUS TdiQueryInformationEx(PFILE_OBJECT FileObject, ULONG Entity, ULONG Instance, ULONG Class, ULONG Type, ULONG Id, PVOID OutputBuffer, PULONG OutputLength)
Definition: tditest.c:275
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
VOID TdiSendThread(PVOID Context)
Definition: tditest.c:717
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
NTSTATUS TdiQueryDeviceControl(PFILE_OBJECT FileObject, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, PULONG Return)
Definition: tditest.c:226
#define IP_MIB_ADDRTABLE_ENTRY_ID
Definition: afd.h:36
#define TDI_DbgPrint(_t_, _x_)
Definition: debug.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define GENERIC_ENTITY
Definition: tdiinfo.h:37
KEVENT StopEvent
Definition: tditest.c:28
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
ULONG toi_type
Definition: tdiinfo.h:76
struct IPADDR_ENTRY IPADDR_ENTRY
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200
#define INFO_CLASS_PROTOCOL
Definition: tdiinfo.h:65
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170