Sync trunk.
[reactos.git] / drivers / usb / usbehci / misc.c
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbehci/misc.c
5 * PURPOSE: Misceallenous operations.
6 * PROGRAMMERS:
7 * Michael Martin
8 */
9
10 #include "usbehci.h"
11
12 /*
13 Get SymblicName from Parameters in Registry Key
14 Caller is responsible for freeing pool of returned pointer
15 */
16 PWSTR
17 GetSymbolicName(PDEVICE_OBJECT DeviceObject)
18 {
19 NTSTATUS Status;
20 HANDLE DevInstRegKey;
21 UNICODE_STRING SymbolicName;
22 PKEY_VALUE_PARTIAL_INFORMATION KeyPartInfo;
23 ULONG SizeNeeded;
24 PWCHAR SymbolicNameString = NULL;
25
26 Status = IoOpenDeviceRegistryKey(DeviceObject,
27 PLUGPLAY_REGKEY_DEVICE,
28 STANDARD_RIGHTS_ALL,
29 &DevInstRegKey);
30
31 DPRINT("IoOpenDeviceRegistryKey PLUGPLAY_REGKEY_DEVICE Status %x\n", Status);
32
33 if (NT_SUCCESS(Status))
34 {
35 RtlInitUnicodeString(&SymbolicName, L"SymbolicName");
36 Status = ZwQueryValueKey(DevInstRegKey,
37 &SymbolicName,
38 KeyValuePartialInformation,
39 NULL,
40 0,
41 &SizeNeeded);
42
43 DPRINT("ZwQueryValueKey status %x, %d\n", Status, SizeNeeded);
44
45 if (Status == STATUS_BUFFER_TOO_SMALL)
46 {
47 KeyPartInfo = (PKEY_VALUE_PARTIAL_INFORMATION ) ExAllocatePool(PagedPool, SizeNeeded);
48 if (!KeyPartInfo)
49 {
50 DPRINT1("OUT OF MEMORY\n");
51 return NULL;
52 }
53 else
54 {
55 Status = ZwQueryValueKey(DevInstRegKey,
56 &SymbolicName,
57 KeyValuePartialInformation,
58 KeyPartInfo,
59 SizeNeeded,
60 &SizeNeeded);
61
62 SymbolicNameString = ExAllocatePool(PagedPool, (KeyPartInfo->DataLength + sizeof(WCHAR)));
63 if (!SymbolicNameString)
64 {
65 return NULL;
66 }
67 RtlZeroMemory(SymbolicNameString, KeyPartInfo->DataLength + 2);
68 RtlCopyMemory(SymbolicNameString, KeyPartInfo->Data, KeyPartInfo->DataLength);
69 }
70
71 ExFreePool(KeyPartInfo);
72 }
73
74 ZwClose(DevInstRegKey);
75 }
76
77 return SymbolicNameString;
78 }
79
80 /*
81 Get Physical Device Object Name from registry
82 Caller is responsible for freeing pool
83 */
84 PWSTR
85 GetPhysicalDeviceObjectName(PDEVICE_OBJECT DeviceObject)
86 {
87 NTSTATUS Status;
88 PWSTR ObjectName = NULL;
89 ULONG SizeNeeded;
90
91 Status = IoGetDeviceProperty(DeviceObject,
92 DevicePropertyPhysicalDeviceObjectName,
93 0,
94 NULL,
95 &SizeNeeded);
96
97 if (Status != STATUS_BUFFER_TOO_SMALL)
98 {
99 DPRINT1("Expected STATUS_BUFFER_TOO_SMALL, got %x!\n", Status);
100 return NULL;
101 }
102
103 ObjectName = (PWSTR) ExAllocatePool(PagedPool, SizeNeeded + sizeof(WCHAR));
104 if (!ObjectName)
105 {
106 DPRINT1("Out of memory\n");
107 return NULL;
108 }
109
110 Status = IoGetDeviceProperty(DeviceObject,
111 DevicePropertyPhysicalDeviceObjectName,
112 SizeNeeded,
113 ObjectName,
114 &SizeNeeded);
115 if (!NT_SUCCESS(Status))
116 {
117 DPRINT1("Failed to Get Property\n");
118 return NULL;
119 }
120
121 return ObjectName;
122 }
123