[MSI]
[reactos.git] / rosapps / drivers / green / misc.c
1 /*
2 * PROJECT: ReactOS VT100 emulator
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/base/green/misc.c
5 * PURPOSE: Misceallenous operations
6 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9 #include "green.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 NTSTATUS
15 GreenDeviceIoControl(
16 IN PDEVICE_OBJECT DeviceObject,
17 IN ULONG CtlCode,
18 IN PVOID InputBuffer OPTIONAL,
19 IN ULONG InputBufferSize,
20 IN OUT PVOID OutputBuffer OPTIONAL,
21 IN OUT PULONG OutputBufferSize)
22 {
23 KEVENT Event;
24 PIRP Irp;
25 IO_STATUS_BLOCK IoStatus;
26 NTSTATUS Status;
27
28 KeInitializeEvent (&Event, NotificationEvent, FALSE);
29
30 Irp = IoBuildDeviceIoControlRequest(CtlCode,
31 DeviceObject,
32 InputBuffer,
33 InputBufferSize,
34 OutputBuffer,
35 (OutputBufferSize) ? *OutputBufferSize : 0,
36 FALSE,
37 &Event,
38 &IoStatus);
39 if (Irp == NULL)
40 {
41 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
42 return STATUS_INSUFFICIENT_RESOURCES;
43 }
44
45 Status = IoCallDriver(DeviceObject, Irp);
46
47 if (Status == STATUS_PENDING)
48 {
49 DPRINT("Operation pending\n");
50 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
51 Status = IoStatus.Status;
52 }
53
54 if (OutputBufferSize)
55 {
56 *OutputBufferSize = IoStatus.Information;
57 }
58
59 return Status;
60 }
61
62 NTSTATUS
63 ReadRegistryEntries(
64 IN PUNICODE_STRING RegistryPath,
65 IN PGREEN_DRIVER_EXTENSION DriverExtension)
66 {
67 UNICODE_STRING ParametersRegistryKey;
68 RTL_QUERY_REGISTRY_TABLE Parameters[4];
69 NTSTATUS Status;
70
71 ULONG DefaultDeviceReported = 0;
72 ULONG DefaultSampleRate = 1200;
73
74 ParametersRegistryKey.Length = 0;
75 ParametersRegistryKey.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters") + sizeof(UNICODE_NULL);
76 ParametersRegistryKey.Buffer = ExAllocatePool(PagedPool, ParametersRegistryKey.MaximumLength);
77 if (!ParametersRegistryKey.Buffer)
78 {
79 DPRINT("ExAllocatePool() failed\n");
80 return STATUS_INSUFFICIENT_RESOURCES;
81 }
82 RtlCopyUnicodeString(&ParametersRegistryKey, RegistryPath);
83 RtlAppendUnicodeToString(&ParametersRegistryKey, L"\\Parameters");
84 ParametersRegistryKey.Buffer[ParametersRegistryKey.Length / sizeof(WCHAR)] = UNICODE_NULL;
85
86 RtlZeroMemory(Parameters, sizeof(Parameters));
87
88 Parameters[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
89 Parameters[0].Name = L"AttachedDevice";
90 Parameters[0].EntryContext = &DriverExtension->AttachedDeviceName;
91
92 Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
93 Parameters[1].Name = L"DeviceReported";
94 Parameters[1].EntryContext = &DriverExtension->DeviceReported;
95 Parameters[1].DefaultType = REG_DWORD;
96 Parameters[1].DefaultData = &DefaultDeviceReported;
97 Parameters[1].DefaultLength = sizeof(ULONG);
98
99 Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
100 Parameters[2].Name = L"SampleRate";
101 Parameters[2].EntryContext = &DriverExtension->SampleRate;
102 Parameters[2].DefaultType = REG_DWORD;
103 Parameters[2].DefaultData = &DefaultSampleRate;
104 Parameters[2].DefaultLength = sizeof(ULONG);
105
106 Status = RtlQueryRegistryValues(
107 RTL_REGISTRY_ABSOLUTE,
108 ParametersRegistryKey.Buffer,
109 Parameters,
110 NULL,
111 NULL);
112
113 return Status;
114 }