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.

244 lines
8.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1993 - 1999
  3. Module Name:
  4. parharns.c
  5. Abstract:
  6. This module contains code for test harness useage.
  7. Author:
  8. Robbie Harris (Hewlett-Packard) 15-October-1998
  9. Environment:
  10. Kernel mode
  11. Revision History :
  12. --*/
  13. #include "pch.h"
  14. // NOTE: PAR_TEST_HARNESS must be below pch.h
  15. ULONG devHarness1; // dummy - so this file is not an empty translation unit if !PAR_TEST_HARNESS
  16. #if PAR_TEST_HARNESS
  17. #include "parharns.h"
  18. #include "bucket.h"
  19. NTSTATUS
  20. ParHarnessLoad(
  21. IN PDEVICE_EXTENSION Extension
  22. )
  23. {
  24. NTSTATUS status;
  25. RtlInitUnicodeString (&(Extension->ParTestHarness.deviceName),
  26. BUCKET_DEVICE_NAME);
  27. status = IoGetDeviceObjectPointer (
  28. &(Extension->ParTestHarness.deviceName),
  29. FILE_ALL_ACCESS,
  30. &(Extension->ParTestHarness.file),
  31. &(Extension->ParTestHarness.device));
  32. if (NT_SUCCESS(status))
  33. {
  34. Extension->ParTestHarness.fnRead = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnRead;
  35. Extension->ParTestHarness.fnRevSetInterfaceAddress = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnSetInterfaceAddress;
  36. Extension->ParTestHarness.fnEnterReverse = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnEnterReverse;
  37. Extension->ParTestHarness.fnExitReverse = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnExitReverse;
  38. Extension->ParTestHarness.fnReadShadow = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnReadShadow;
  39. Extension->ParTestHarness.fnHaveReadData = (PVOID) arpReverse[Extension->IdxReverseProtocol].fnHaveReadData;
  40. Extension->ParTestHarness.fnWrite = (PVOID) afpForward[Extension->IdxForwardProtocol].fnWrite;
  41. Extension->ParTestHarness.fnFwdSetInterfaceAddress = (PVOID) afpForward[Extension->IdxForwardProtocol].fnSetInterfaceAddress;
  42. Extension->ParTestHarness.fnEnterForward = (PVOID) afpForward[Extension->IdxForwardProtocol].fnEnterForward;
  43. Extension->ParTestHarness.fnExitForward = (PVOID) afpForward[Extension->IdxForwardProtocol].fnExitForward;
  44. arpReverse[Extension->IdxReverseProtocol].fnRead = ParHarnessRead;
  45. arpReverse[Extension->IdxReverseProtocol].fnSetInterfaceAddress = ParHarnessSetAddress;
  46. arpReverse[Extension->IdxReverseProtocol].fnEnterReverse = ParHarnessEnterReversePhase;
  47. arpReverse[Extension->IdxReverseProtocol].fnExitReverse = ParHarnessExitReversePhase;
  48. arpReverse[Extension->IdxReverseProtocol].fnReadShadow = NULL;
  49. arpReverse[Extension->IdxReverseProtocol].fnHaveReadData = ParHarnessHaveReadData;
  50. afpForward[Extension->IdxForwardProtocol].fnWrite = ParHarnessWrite;
  51. afpForward[Extension->IdxForwardProtocol].fnSetInterfaceAddress = ParHarnessSetAddress;
  52. afpForward[Extension->IdxForwardProtocol].fnEnterForward = ParHarnessEnterForwardPhase;
  53. afpForward[Extension->IdxForwardProtocol].fnExitForward = ParHarnessExitForwardPhase;
  54. }
  55. return status;
  56. }
  57. NTSTATUS
  58. ParHarnessEnterForwardPhase(
  59. IN PDEVICE_EXTENSION Extension
  60. )
  61. {
  62. Extension->CurrentPhase = PHASE_FORWARD_IDLE;
  63. return STATUS_SUCCESS;
  64. }
  65. NTSTATUS
  66. ParHarnessExitForwardPhase(
  67. IN PDEVICE_EXTENSION Extension
  68. )
  69. {
  70. Extension->CurrentPhase = PHASE_FORWARD_IDLE;
  71. return STATUS_SUCCESS;
  72. }
  73. NTSTATUS
  74. ParHarnessEnterReversePhase(
  75. IN PDEVICE_EXTENSION Extension
  76. )
  77. {
  78. Extension->CurrentPhase = PHASE_REVERSE_IDLE;
  79. return STATUS_SUCCESS;
  80. }
  81. NTSTATUS
  82. ParHarnessExitReversePhase(
  83. IN PDEVICE_EXTENSION Extension
  84. )
  85. {
  86. Extension->CurrentPhase = PHASE_FORWARD_IDLE;
  87. return STATUS_SUCCESS;
  88. }
  89. BOOLEAN
  90. ParHarnessHaveReadData (
  91. IN PDEVICE_EXTENSION Extension
  92. )
  93. {
  94. IO_STATUS_BLOCK iosbStatus;
  95. PIRP pIrp;
  96. KEVENT Event;
  97. char Buffer;
  98. NTSTATUS status;
  99. pIrp = IoBuildDeviceIoControlRequest(IOCTL_BUCKET_CLIENT_READ_PEEK,
  100. Extension->ParTestHarness.device,
  101. &Buffer,
  102. 1,
  103. NULL,
  104. 0,
  105. FALSE,
  106. &Event,
  107. &iosbStatus);
  108. status = IoCallDriver(Extension->ParTestHarness.device, pIrp);
  109. // Do we want to wait for the Irp to complete?
  110. return (BOOLEAN) (iosbStatus.Information > 0);
  111. }
  112. NTSTATUS
  113. ParHarnessRead(
  114. IN PDEVICE_EXTENSION Extension,
  115. IN PVOID Buffer,
  116. IN ULONG BufferSize,
  117. OUT PULONG BytesTransferred
  118. )
  119. {
  120. NTSTATUS status;
  121. IO_STATUS_BLOCK iosbStatus;
  122. PIRP pIrp;
  123. KEVENT Event;
  124. *BytesTransferred = 0;
  125. pIrp = IoBuildDeviceIoControlRequest(IOCTL_BUCKET_CLIENT_READ,
  126. Extension->ParTestHarness.device,
  127. NULL,
  128. 0,
  129. Buffer,
  130. BufferSize,
  131. FALSE,
  132. &Event,
  133. &iosbStatus);
  134. status = IoCallDriver(Extension->ParTestHarness.device, pIrp);
  135. // Do we want to wait for the Irp to complete?
  136. if (NT_SUCCESS(status))
  137. {
  138. *BytesTransferred = iosbStatus.Information;
  139. status = iosbStatus.Status;
  140. }
  141. return status;
  142. }
  143. NTSTATUS
  144. ParHarnessSetAddress(
  145. IN PDEVICE_EXTENSION Extension,
  146. IN UCHAR Address
  147. )
  148. {
  149. NTSTATUS Status = STATUS_SUCCESS;
  150. // Dunno what to do?
  151. return Status;
  152. }
  153. NTSTATUS
  154. ParHarnessWrite(
  155. IN PDEVICE_EXTENSION Extension,
  156. IN PVOID Buffer,
  157. IN ULONG BufferSize,
  158. OUT PULONG BytesTransferred
  159. )
  160. {
  161. NTSTATUS status;
  162. IO_STATUS_BLOCK iosbStatus;
  163. PIRP pIrp;
  164. KEVENT Event;
  165. *BytesTransferred = 0;
  166. pIrp = IoBuildDeviceIoControlRequest(IOCTL_BUCKET_CLIENT_WRITE,
  167. Extension->ParTestHarness.device,
  168. Buffer,
  169. BufferSize,
  170. NULL,
  171. 0,
  172. FALSE,
  173. &Event,
  174. &iosbStatus);
  175. status = IoCallDriver(Extension->ParTestHarness.device, pIrp);
  176. // Do we want to wait for the Irp to complete?
  177. if (NT_SUCCESS(status))
  178. {
  179. *BytesTransferred = iosbStatus.Information;
  180. status = iosbStatus.Status;
  181. }
  182. return status;
  183. }
  184. NTSTATUS
  185. ParHarnessUnload(
  186. IN PDEVICE_EXTENSION Extension
  187. )
  188. {
  189. NTSTATUS status = STATUS_SUCCESS;
  190. ObDereferenceObject(Extension->ParTestHarness.file);
  191. if (NT_SUCCESS(status))
  192. {
  193. arpReverse[Extension->IdxReverseProtocol].fnRead = Extension->ParTestHarness.fnRead;
  194. arpReverse[Extension->IdxReverseProtocol].fnSetInterfaceAddress = Extension->ParTestHarness.fnRevSetInterfaceAddress;
  195. arpReverse[Extension->IdxReverseProtocol].fnEnterReverse = Extension->ParTestHarness.fnEnterReverse;
  196. arpReverse[Extension->IdxReverseProtocol].fnExitReverse = Extension->ParTestHarness.fnExitReverse;
  197. arpReverse[Extension->IdxReverseProtocol].fnReadShadow = Extension->ParTestHarness.fnReadShadow;
  198. arpReverse[Extension->IdxReverseProtocol].fnHaveReadData = Extension->ParTestHarness.fnHaveReadData;
  199. afpForward[Extension->IdxForwardProtocol].fnWrite = Extension->ParTestHarness.fnWrite;
  200. afpForward[Extension->IdxForwardProtocol].fnSetInterfaceAddress = Extension->ParTestHarness.fnFwdSetInterfaceAddress;
  201. afpForward[Extension->IdxForwardProtocol].fnEnterForward = Extension->ParTestHarness.fnEnterForward;
  202. afpForward[Extension->IdxForwardProtocol].fnExitForward = Extension->ParTestHarness.fnExitForward;
  203. }
  204. return status;
  205. }
  206. #endif