Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tstrcv.c
  5. Abstract:
  6. start receive side tests utility
  7. Author:
  8. Dave Beaver (dbeaver) 24-Mar-1991
  9. Revision History:
  10. --*/
  11. //
  12. // download a ub board
  13. //
  14. typedef unsigned char uchar_t;
  15. #include <assert.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <memory.h>
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <string.h>
  23. //#include <windows.h>
  24. #include <nbf.h>
  25. #define TDIDEV "\\Device\\Nbf"
  26. char Tdidevice[] = TDIDEV; /* default device */
  27. char *Tdidev = Tdidevice;
  28. HANDLE FileHandle;
  29. VOID
  30. usage(
  31. VOID
  32. );
  33. NTSTATUS
  34. main (
  35. IN SHORT argc,
  36. IN PSZ argv[]
  37. )
  38. {
  39. IO_STATUS_BLOCK IoStatusBlock;
  40. NTSTATUS Status;
  41. STRING NameString;
  42. UNICODE_STRING unicodeString;
  43. PUCHAR buffer;
  44. ULONG IoControlCode;
  45. int n;
  46. CHAR c;
  47. for( n = 1; n < argc && argv[n][0] == '-' ; ++n ) {
  48. c = argv[n][1];
  49. switch( c ) {
  50. case 's': // send test
  51. IoControlCode = IOCTL_TDI_SEND_TEST;
  52. break;
  53. case 'r': // receive test
  54. IoControlCode = IOCTL_TDI_RECEIVE_TEST;
  55. break;
  56. case 'b': /* both test */
  57. IoControlCode = IOCTL_TDI_SERVER_TEST;
  58. break;
  59. default:
  60. usage ();
  61. break;
  62. }
  63. }
  64. printf ("Opening TDI device: %s \n", Tdidev);
  65. RtlInitString (&NameString, Tdidev);
  66. Status = RtlAnsiStringToUnicodeString(
  67. &unicodeString,
  68. &NameString,
  69. TRUE);
  70. buffer = (PUCHAR)malloc (100);
  71. Status = TdiOpenNetbiosAddress (&FileHandle, buffer, (PVOID)&NameString, NULL);
  72. RtlFreeUnicodeString(&unicodeString);
  73. free (buffer);
  74. if (!NT_SUCCESS( Status )) {
  75. printf ("FAILURE, Unable to open TDI driver %s, status: %lx.\n",
  76. Tdidev,Status);
  77. return (Status);
  78. }
  79. if (!(NT_SUCCESS( IoStatusBlock.Status ))) {
  80. printf ("FAILURE, Unable to open TDI driver %s, IoStatusBlock.Status: %lx.\n",
  81. Tdidev, IoStatusBlock.Status);
  82. return (IoStatusBlock.Status);
  83. }
  84. //
  85. // start the test
  86. //
  87. printf("Starting test.... ");
  88. Status = NtDeviceIoControlFile(
  89. FileHandle,
  90. NULL,
  91. NULL,
  92. NULL,
  93. &IoStatusBlock,
  94. IoControlCode,
  95. NULL,
  96. 0,
  97. NULL,
  98. 0);
  99. if (!NT_SUCCESS( Status )) {
  100. printf ("FAILURE, Unable to start test: %lx.\n", Status);
  101. return (Status);
  102. }
  103. if (!(NT_SUCCESS( IoStatusBlock.Status ))) {
  104. printf ("FAILURE, Unable to start test: %lx.\n", IoStatusBlock.Status);
  105. return (IoStatusBlock.Status);
  106. }
  107. NtClose (FileHandle);
  108. return STATUS_SUCCESS;
  109. }
  110. NTSTATUS
  111. TdiOpenNetbiosAddress (
  112. IN OUT PHANDLE FileHandle,
  113. IN PUCHAR Buffer,
  114. IN PVOID DeviceName,
  115. IN PVOID Address)
  116. /*++
  117. Routine Description:
  118. Opens an address on the given file handle and device.
  119. Arguments:
  120. FileHandle - the returned handle to the file object that is opened.
  121. Buffer - pointer to a buffer that the ea is to be built in. This buffer
  122. must be at least 40 bytes long.
  123. DeviceName - the Unicode string that points to the device object.
  124. Name - the address to be registered. If this pointer is NULL, the routine
  125. will attempt to open a "control channel" to the device; that is, it
  126. will attempt to open the file object with a null ea pointer, and if the
  127. transport provider allows for that, will return that handle.
  128. Return Value:
  129. An informative error code if something goes wrong. STATUS_SUCCESS if the
  130. returned file handle is valid.
  131. --*/
  132. {
  133. IO_STATUS_BLOCK IoStatusBlock;
  134. NTSTATUS Status;
  135. OBJECT_ATTRIBUTES ObjectAttributes;
  136. PFILE_FULL_EA_INFORMATION EaBuffer;
  137. PTRANSPORT_ADDRESS TAAddress;
  138. PTA_ADDRESS AddressType;
  139. PTDI_ADDRESS_NETBIOS AddressName;
  140. PSZ Name;
  141. ULONG Length;
  142. int i;
  143. if (Address != NULL) {
  144. Name = (PSZ)Address;
  145. try {
  146. Length = sizeof (FILE_FULL_EA_INFORMATION) +
  147. sizeof (TRANSPORT_ADDRESS) +
  148. sizeof (TDI_ADDRESS_NETBIOS);
  149. EaBuffer = (PFILE_FULL_EA_INFORMATION)Buffer;
  150. if (EaBuffer == NULL) {
  151. return STATUS_UNSUCCESSFUL;
  152. }
  153. EaBuffer->NextEntryOffset =0;
  154. EaBuffer->Flags = 0;
  155. EaBuffer->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
  156. EaBuffer->EaValueLength = sizeof (TDI_ADDRESS_NETBIOS) +
  157. sizeof (TRANSPORT_ADDRESS);
  158. for (i=0;i<(int)EaBuffer->EaNameLength;i++) {
  159. EaBuffer->EaName[i] = TdiTransportAddress[i];
  160. }
  161. TAAddress = (PTRANSPORT_ADDRESS)&EaBuffer->EaName[EaBuffer->EaNameLength+1];
  162. TAAddress->TAAddressCount = 1;
  163. AddressType = (PTA_ADDRESS)((PUCHAR)TAAddress + sizeof (TAAddress->TAAddressCount));
  164. AddressType->AddressType = TDI_ADDRESS_TYPE_NETBIOS;
  165. AddressType->AddressLength = TDI_ADDRESS_LENGTH_NETBIOS;
  166. AddressName = (PTDI_ADDRESS_NETBIOS)((PUCHAR)AddressType +
  167. sizeof (AddressType->AddressType) + sizeof (AddressType->AddressLength));
  168. AddressName->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
  169. for (i=0;i<16;i++) {
  170. AddressName->NetbiosName[i] = Name[i];
  171. }
  172. } except(EXCEPTION_EXECUTE_HANDLER) {
  173. //
  174. // Couldn't touch the passed parameters; just return an error
  175. // status.
  176. //
  177. return GetExceptionCode();
  178. }
  179. } else {
  180. EaBuffer = NULL;
  181. Length = 0;
  182. }
  183. InitializeObjectAttributes (
  184. &ObjectAttributes,
  185. DeviceName,
  186. 0,
  187. NULL,
  188. NULL);
  189. Status = NtCreateFile (
  190. FileHandle,
  191. FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, // desired access.
  192. &ObjectAttributes, // object attributes.
  193. &IoStatusBlock, // returned status information.
  194. 0, // block size (unused).
  195. 0, // file attributes.
  196. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access.
  197. FILE_CREATE, // create disposition.
  198. 0, // create options.
  199. EaBuffer, // EA buffer.
  200. Length); // EA length.
  201. if (!NT_SUCCESS( Status )) {
  202. return Status;
  203. }
  204. Status = IoStatusBlock.Status;
  205. if (!(NT_SUCCESS( Status ))) {
  206. }
  207. return Status;
  208. } /* TdiOpenNetbiosAddress */
  209. VOID
  210. usage(
  211. VOID
  212. )
  213. {
  214. printf( "usage: tsttdi [-r] [-s] -[b]\n");
  215. printf( "usage: -r run receive test.\n" );
  216. printf( "usage: -b run server test.\n" );
  217. printf( "usage: -s run send test.\n" );
  218. printf( "\n" );
  219. exit( 1 );
  220. }
  221.