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.

375 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. USBD.C
  5. Abstract:
  6. Environment:
  7. kernel mode only
  8. Notes:
  9. Revision History:
  10. 09-29-95 : created
  11. 07-19-96 : removed device object
  12. --*/
  13. #include <wdm.h>
  14. #include "stdarg.h"
  15. #include "stdio.h"
  16. #include "usbdi.h" //public data structures
  17. #include "hcdi.h"
  18. #include "usbd.h" //private data strutures
  19. NTSTATUS
  20. DriverEntry(
  21. IN PDRIVER_OBJECT DriverObject,
  22. IN PUNICODE_STRING RegistryPath
  23. )
  24. /*++
  25. Routine Description:
  26. Installable driver initialization entry point.
  27. This entry point is called directly by the I/O system.
  28. Arguments:
  29. DriverObject - pointer to the driver object
  30. RegistryPath - pointer to a unicode string representing the path
  31. to driver-specific key in the registry
  32. Return Value:
  33. NT status code
  34. --*/
  35. {
  36. // This function is never called
  37. return STATUS_SUCCESS;
  38. }
  39. #ifdef PAGE_CODE
  40. #ifdef ALLOC_PRAGMA
  41. #pragma alloc_text(PAGE, USBD_GetRegistryKeyValue)
  42. #endif
  43. #endif
  44. NTSTATUS
  45. USBD_GetRegistryKeyValue (
  46. IN HANDLE Handle,
  47. IN PWCHAR KeyNameString,
  48. IN ULONG KeyNameStringLength,
  49. IN PVOID Data,
  50. IN ULONG DataLength
  51. )
  52. /*++
  53. Routine Description:
  54. Arguments:
  55. Return Value:
  56. --*/
  57. {
  58. NTSTATUS ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  59. UNICODE_STRING keyName;
  60. ULONG length;
  61. PKEY_VALUE_FULL_INFORMATION fullInfo;
  62. PAGED_CODE();
  63. RtlInitUnicodeString(&keyName, KeyNameString);
  64. length = sizeof(KEY_VALUE_FULL_INFORMATION) +
  65. KeyNameStringLength + DataLength;
  66. fullInfo = ExAllocatePoolWithTag(PagedPool, length, USBD_TAG);
  67. USBD_KdPrint(3, ("' USBD_GetRegistryKeyValue buffer = 0x%x\n", fullInfo));
  68. if (fullInfo) {
  69. ntStatus = ZwQueryValueKey(Handle,
  70. &keyName,
  71. KeyValueFullInformation,
  72. fullInfo,
  73. length,
  74. &length);
  75. if (NT_SUCCESS(ntStatus)){
  76. USBD_ASSERT(DataLength == fullInfo->DataLength);
  77. RtlCopyMemory(Data, ((PUCHAR) fullInfo) + fullInfo->DataOffset, DataLength);
  78. }
  79. ExFreePool(fullInfo);
  80. }
  81. return ntStatus;
  82. }
  83. #ifdef USBD_DRIVER // USBPORT supercedes most of USBD, so we will remove
  84. // the obsolete code by compiling it only if
  85. // USBD_DRIVER is set.
  86. #ifdef PAGE_CODE
  87. #ifdef ALLOC_PRAGMA
  88. #pragma alloc_text(PAGE, USBD_GetPdoRegistryParameters)
  89. #pragma alloc_text(PAGE, USBD_GetGlobalRegistryParameters)
  90. #endif
  91. #endif
  92. // global flag to force double buffering
  93. // bulk - ins
  94. UCHAR ForceDoubleBuffer = 0;
  95. // global flag to force fast iso
  96. // iso - outs
  97. UCHAR ForceFastIso = 0;
  98. NTSTATUS
  99. USBD_GetConfigValue(
  100. IN PWSTR ValueName,
  101. IN ULONG ValueType,
  102. IN PVOID ValueData,
  103. IN ULONG ValueLength,
  104. IN PVOID Context,
  105. IN PVOID EntryContext
  106. )
  107. /*++
  108. Routine Description:
  109. This routine is a callback routine for RtlQueryRegistryValues
  110. It is called for each entry in the Parameters
  111. node to set the config values. The table is set up
  112. so that this function will be called with correct default
  113. values for keys that are not present.
  114. Arguments:
  115. ValueName - The name of the value (ignored).
  116. ValueType - The type of the value
  117. ValueData - The data for the value.
  118. ValueLength - The length of ValueData.
  119. Context - A pointer to the CONFIG structure.
  120. EntryContext - The index in Config->Parameters to save the value.
  121. Return Value:
  122. --*/
  123. {
  124. NTSTATUS ntStatus = STATUS_SUCCESS;
  125. USBD_KdPrint(2, ("'Type 0x%x, Length 0x%x\n", ValueType, ValueLength));
  126. switch (ValueType) {
  127. case REG_DWORD:
  128. *(PVOID*)EntryContext = *(PVOID*)ValueData;
  129. break;
  130. case REG_BINARY:
  131. // we are only set up to read a byte
  132. RtlCopyMemory(EntryContext, ValueData, 1);
  133. break;
  134. default:
  135. ntStatus = STATUS_INVALID_PARAMETER;
  136. }
  137. return ntStatus;
  138. }
  139. NTSTATUS
  140. USBD_GetGlobalRegistryParameters(
  141. IN PDEVICE_OBJECT PhysicalDeviceObject,
  142. IN OUT PULONG ComplienceFlags,
  143. IN OUT PULONG DiagnosticFlags,
  144. IN OUT PULONG DeviceHackFlags
  145. )
  146. /*++
  147. Routine Description:
  148. Arguments:
  149. Return Value:
  150. --*/
  151. {
  152. NTSTATUS ntStatus;
  153. UCHAR toshibaLegacyFlags = 0;
  154. RTL_QUERY_REGISTRY_TABLE QueryTable[4];
  155. PWCHAR usb = L"usb";
  156. PAGED_CODE();
  157. //
  158. // Set up QueryTable to do the following:
  159. //
  160. // legacy flag
  161. QueryTable[0].QueryRoutine = USBD_GetConfigValue;
  162. QueryTable[0].Flags = 0;
  163. QueryTable[0].Name = LEGACY_TOSHIBA_USB_KEY;
  164. QueryTable[0].EntryContext = &toshibaLegacyFlags;
  165. QueryTable[0].DefaultType = REG_BINARY;
  166. QueryTable[0].DefaultData = &toshibaLegacyFlags;
  167. QueryTable[0].DefaultLength = sizeof(toshibaLegacyFlags);
  168. // double buffer flag
  169. // this turns on the double buffer flag for all
  170. // bulk - INs for testing purposes
  171. QueryTable[1].QueryRoutine = USBD_GetConfigValue;
  172. QueryTable[1].Flags = 0;
  173. QueryTable[1].Name = L"ForceDoubleBuffer";
  174. QueryTable[1].EntryContext = &ForceDoubleBuffer;
  175. QueryTable[1].DefaultType = REG_BINARY;
  176. QueryTable[1].DefaultData = &ForceDoubleBuffer;
  177. QueryTable[1].DefaultLength = sizeof(ForceDoubleBuffer);
  178. // fast iso flag
  179. // this turns on the double buffer flag for all
  180. // iso - OUTs for testing purposes
  181. QueryTable[2].QueryRoutine = USBD_GetConfigValue;
  182. QueryTable[2].Flags = 0;
  183. QueryTable[2].Name = L"ForceFastIso";
  184. QueryTable[2].EntryContext = &ForceFastIso;
  185. QueryTable[2].DefaultType = REG_BINARY;
  186. QueryTable[2].DefaultData = &ForceFastIso;
  187. QueryTable[2].DefaultLength = sizeof(ForceFastIso);
  188. //
  189. // Stop
  190. //
  191. QueryTable[3].QueryRoutine = NULL;
  192. QueryTable[3].Flags = 0;
  193. QueryTable[3].Name = NULL;
  194. ntStatus = RtlQueryRegistryValues(
  195. // RTL_REGISTRY_ABSOLUTE, // RelativeTo
  196. RTL_REGISTRY_SERVICES,
  197. // UnicodeRegistryPath->Buffer, // Path
  198. usb,
  199. QueryTable, // QurryTable
  200. NULL, // Context
  201. NULL); // Environment
  202. USBD_KdPrint(1, ("<Global Parameters>\n"));
  203. if (NT_SUCCESS(ntStatus)) {
  204. USBD_KdPrint(1, ("LegacyToshibaUSB = 0x%x\n",
  205. toshibaLegacyFlags));
  206. if (toshibaLegacyFlags) {
  207. *ComplienceFlags |= 1;
  208. }
  209. USBD_KdPrint(1, ("ForceDoubleBuffer = 0x%x\n",
  210. ForceDoubleBuffer));
  211. USBD_KdPrint(1, ("ForceFastIso = 0x%x\n",
  212. ForceFastIso));
  213. }
  214. if ( STATUS_OBJECT_NAME_NOT_FOUND == ntStatus ) {
  215. ntStatus = STATUS_SUCCESS;
  216. }
  217. return ntStatus;
  218. }
  219. NTSTATUS
  220. USBD_GetPdoRegistryParameters (
  221. IN PDEVICE_OBJECT PhysicalDeviceObject,
  222. IN OUT PULONG ComplienceFlags,
  223. IN OUT PULONG DiagnosticFlags,
  224. IN OUT PULONG DeviceHackFlags
  225. )
  226. /*++
  227. Routine Description:
  228. Arguments:
  229. Return Value:
  230. --*/
  231. {
  232. NTSTATUS ntStatus;
  233. HANDLE handle;
  234. WCHAR supportNonCompKey[] = SUPPORT_NON_COMP_KEY;
  235. WCHAR diagnosticModeKey[] = DAIGNOSTIC_MODE_KEY;
  236. WCHAR deviceHackKey[] = DEVICE_HACK_KEY;
  237. PAGED_CODE();
  238. ntStatus=IoOpenDeviceRegistryKey(PhysicalDeviceObject,
  239. PLUGPLAY_REGKEY_DRIVER,
  240. STANDARD_RIGHTS_ALL,
  241. &handle);
  242. if (NT_SUCCESS(ntStatus)) {
  243. /*
  244. RtlInitUnicodeString(&keyName, L"DeviceFoo");
  245. ZwSetValueKey(handle,
  246. &keyName,
  247. 0,
  248. REG_DWORD,
  249. ComplienceFlags,
  250. sizeof(*ComplienceFlags));
  251. */
  252. USBD_GetRegistryKeyValue(handle,
  253. supportNonCompKey,
  254. sizeof(supportNonCompKey),
  255. ComplienceFlags,
  256. sizeof(*ComplienceFlags));
  257. USBD_GetRegistryKeyValue(handle,
  258. diagnosticModeKey,
  259. sizeof(diagnosticModeKey),
  260. DiagnosticFlags,
  261. sizeof(*DiagnosticFlags));
  262. USBD_GetRegistryKeyValue(handle,
  263. deviceHackKey,
  264. sizeof(deviceHackKey),
  265. DeviceHackFlags,
  266. sizeof(*DeviceHackFlags));
  267. ZwClose(handle);
  268. }
  269. USBD_KdPrint(3, ("' RtlQueryRegistryValues status 0x%x, comp %x diag %x\n",
  270. ntStatus, *ComplienceFlags, *DiagnosticFlags));
  271. return ntStatus;
  272. }
  273. #endif // USBD_DRIVER