1 | #include <ntddk.h>
|
---|
2 |
|
---|
3 | #include "devdesc.h"
|
---|
4 |
|
---|
5 | #ifdef PNP_IDENTIFY
|
---|
6 |
|
---|
7 | #ifdef ALLOC_PRAGMA
|
---|
8 | #pragma alloc_text(INIT,LinkDeviceToDescription)
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | NTSTATUS
|
---|
12 | LinkDeviceToDescription(
|
---|
13 | IN PUNICODE_STRING RegistryPath,
|
---|
14 | IN PUNICODE_STRING DeviceName,
|
---|
15 | IN INTERFACE_TYPE BusType,
|
---|
16 | IN ULONG BusNumber,
|
---|
17 | IN CONFIGURATION_TYPE ControllerType,
|
---|
18 | IN ULONG ControllerNumber,
|
---|
19 | IN CONFIGURATION_TYPE PeripheralType,
|
---|
20 | IN ULONG PeripheralNumber
|
---|
21 | )
|
---|
22 | {
|
---|
23 | //
|
---|
24 | // This routine will create a volatile "Description" key under the
|
---|
25 | // drivers service key. It will store values of the following form
|
---|
26 | // in that key:
|
---|
27 | //
|
---|
28 | // \\Device\\PointerPortX:REG_BINARY:...
|
---|
29 | // \\Device\\KeyboardPortX:REG_BINARY:...
|
---|
30 | //
|
---|
31 | // Where the binary data is six ULONG values (passed as parameters
|
---|
32 | // to this routine) that describe the physical location of the device.
|
---|
33 | //
|
---|
34 |
|
---|
35 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
36 | HANDLE ServiceKey = NULL, DescriptionKey = NULL;
|
---|
37 | UNICODE_STRING RegString;
|
---|
38 | OBJECT_ATTRIBUTES ObjectAttributes;
|
---|
39 | ULONG disposition;
|
---|
40 | HWDESC_INFO HwDescInfo;
|
---|
41 |
|
---|
42 | HwDescInfo.InterfaceType = BusType;
|
---|
43 | HwDescInfo.InterfaceNumber = BusNumber;
|
---|
44 | HwDescInfo.ControllerType = ControllerType;
|
---|
45 | HwDescInfo.ControllerNumber = ControllerNumber;
|
---|
46 | HwDescInfo.PeripheralType = PeripheralType;
|
---|
47 | HwDescInfo.PeripheralNumber = PeripheralNumber;
|
---|
48 |
|
---|
49 |
|
---|
50 | //
|
---|
51 | // Open the service subkey
|
---|
52 | //
|
---|
53 | InitializeObjectAttributes(&ObjectAttributes,
|
---|
54 | RegistryPath,
|
---|
55 | OBJ_CASE_INSENSITIVE,
|
---|
56 | NULL,
|
---|
57 | NULL);
|
---|
58 |
|
---|
59 | Status = ZwOpenKey(&ServiceKey,
|
---|
60 | KEY_WRITE,
|
---|
61 | &ObjectAttributes);
|
---|
62 |
|
---|
63 | if (!NT_SUCCESS(Status)) {
|
---|
64 | goto Clean0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | //
|
---|
68 | // Create a volatile Description subkey under the service subkey
|
---|
69 | //
|
---|
70 | RtlInitUnicodeString(&RegString, L"Description");
|
---|
71 |
|
---|
72 | InitializeObjectAttributes(&ObjectAttributes,
|
---|
73 | &RegString,
|
---|
74 | OBJ_CASE_INSENSITIVE,
|
---|
75 | ServiceKey,
|
---|
76 | NULL);
|
---|
77 |
|
---|
78 | Status = ZwCreateKey(&DescriptionKey,
|
---|
79 | KEY_ALL_ACCESS,
|
---|
80 | &ObjectAttributes,
|
---|
81 | 0,
|
---|
82 | (PUNICODE_STRING)NULL,
|
---|
83 | REG_OPTION_VOLATILE,
|
---|
84 | &disposition);
|
---|
85 |
|
---|
86 | if (!NT_SUCCESS(Status)) {
|
---|
87 | goto Clean0;
|
---|
88 | }
|
---|
89 |
|
---|
90 | //
|
---|
91 | // The description data is stored under a REG_BINARY value (name
|
---|
92 | // is the DeviceName passed in as a parameter)
|
---|
93 | //
|
---|
94 | Status = ZwSetValueKey(DescriptionKey,
|
---|
95 | DeviceName,
|
---|
96 | 0,
|
---|
97 | REG_BINARY,
|
---|
98 | &HwDescInfo,
|
---|
99 | sizeof(HwDescInfo));
|
---|
100 |
|
---|
101 |
|
---|
102 | Clean0:
|
---|
103 |
|
---|
104 | if (DescriptionKey) {
|
---|
105 | ZwClose(DescriptionKey);
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (ServiceKey) {
|
---|
109 | ZwClose(ServiceKey);
|
---|
110 | }
|
---|
111 |
|
---|
112 | return Status;
|
---|
113 | }
|
---|
114 | #endif
|
---|