1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS Serial mouse driver
3c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4c2c66affSColin Finck * FILE: drivers/input/sermouse/fdo.c
5c2c66affSColin Finck * PURPOSE: Serial mouse driver entry point
6c2c66affSColin Finck * PROGRAMMERS: Copyright 2005-2006 Herv� Poussineau (hpoussin@reactos.org)
7c2c66affSColin Finck */
8c2c66affSColin Finck
9c2c66affSColin Finck #include "sermouse.h"
10c2c66affSColin Finck
11c2c66affSColin Finck #include <debug.h>
12c2c66affSColin Finck
13c2c66affSColin Finck static DRIVER_UNLOAD DriverUnload;
14c2c66affSColin Finck static DRIVER_DISPATCH IrpStub;
15c2c66affSColin Finck DRIVER_INITIALIZE DriverEntry;
16c2c66affSColin Finck
17c2c66affSColin Finck static VOID NTAPI
DriverUnload(IN PDRIVER_OBJECT DriverObject)18c2c66affSColin Finck DriverUnload(IN PDRIVER_OBJECT DriverObject)
19c2c66affSColin Finck {
20c2c66affSColin Finck // nothing to do here yet
21c2c66affSColin Finck }
22c2c66affSColin Finck
23c2c66affSColin Finck static NTSTATUS NTAPI
IrpStub(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)24c2c66affSColin Finck IrpStub(
25c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject,
26c2c66affSColin Finck IN PIRP Irp)
27c2c66affSColin Finck {
28c2c66affSColin Finck ERR_(SERMOUSE, "Irp stub for major function 0x%lx\n",
29c2c66affSColin Finck IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
30c2c66affSColin Finck IoCompleteRequest(Irp, IO_NO_INCREMENT);
31c2c66affSColin Finck return STATUS_NOT_SUPPORTED;
32c2c66affSColin Finck }
33c2c66affSColin Finck
34c2c66affSColin Finck static NTSTATUS
ReadRegistryEntries(IN PUNICODE_STRING RegistryPath,IN PSERMOUSE_DRIVER_EXTENSION DriverExtension)35c2c66affSColin Finck ReadRegistryEntries(
36c2c66affSColin Finck IN PUNICODE_STRING RegistryPath,
37c2c66affSColin Finck IN PSERMOUSE_DRIVER_EXTENSION DriverExtension)
38c2c66affSColin Finck {
39c2c66affSColin Finck UNICODE_STRING ParametersRegistryKey;
40c2c66affSColin Finck RTL_QUERY_REGISTRY_TABLE Parameters[2];
41c2c66affSColin Finck NTSTATUS Status;
42c2c66affSColin Finck
43c2c66affSColin Finck ULONG DefaultNumberOfButtons = 2;
44c2c66affSColin Finck
45c2c66affSColin Finck ParametersRegistryKey.Length = 0;
46c2c66affSColin Finck ParametersRegistryKey.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters") + sizeof(UNICODE_NULL);
47c2c66affSColin Finck ParametersRegistryKey.Buffer = ExAllocatePoolWithTag(PagedPool, ParametersRegistryKey.MaximumLength, SERMOUSE_TAG);
48c2c66affSColin Finck if (!ParametersRegistryKey.Buffer)
49c2c66affSColin Finck {
50c2c66affSColin Finck WARN_(SERMOUSE, "ExAllocatePoolWithTag() failed\n");
51c2c66affSColin Finck return STATUS_NO_MEMORY;
52c2c66affSColin Finck }
53c2c66affSColin Finck RtlCopyUnicodeString(&ParametersRegistryKey, RegistryPath);
54c2c66affSColin Finck RtlAppendUnicodeToString(&ParametersRegistryKey, L"\\Parameters");
55c2c66affSColin Finck ParametersRegistryKey.Buffer[ParametersRegistryKey.Length / sizeof(WCHAR)] = UNICODE_NULL;
56c2c66affSColin Finck
57c2c66affSColin Finck RtlZeroMemory(Parameters, sizeof(Parameters));
58c2c66affSColin Finck
59*4795177cSHermès Bélusca-Maïto Parameters[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
60c2c66affSColin Finck Parameters[0].Name = L"NumberOfButtons";
61c2c66affSColin Finck Parameters[0].EntryContext = &DriverExtension->NumberOfButtons;
62c2c66affSColin Finck Parameters[0].DefaultType = REG_DWORD;
63c2c66affSColin Finck Parameters[0].DefaultData = &DefaultNumberOfButtons;
64c2c66affSColin Finck Parameters[0].DefaultLength = sizeof(ULONG);
65c2c66affSColin Finck
66c2c66affSColin Finck Status = RtlQueryRegistryValues(
67*4795177cSHermès Bélusca-Maïto RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
68c2c66affSColin Finck ParametersRegistryKey.Buffer,
69c2c66affSColin Finck Parameters,
70c2c66affSColin Finck NULL,
71c2c66affSColin Finck NULL);
72c2c66affSColin Finck
73c2c66affSColin Finck if (NT_SUCCESS(Status))
74c2c66affSColin Finck {
75c2c66affSColin Finck /* Check values */
76c2c66affSColin Finck }
77c2c66affSColin Finck else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
78c2c66affSColin Finck {
79c2c66affSColin Finck /* Registry path doesn't exist. Set defaults */
80c2c66affSColin Finck DriverExtension->NumberOfButtons = (USHORT)DefaultNumberOfButtons;
81c2c66affSColin Finck Status = STATUS_SUCCESS;
82c2c66affSColin Finck }
83c2c66affSColin Finck
84c2c66affSColin Finck ExFreePoolWithTag(ParametersRegistryKey.Buffer, SERMOUSE_TAG);
85c2c66affSColin Finck return Status;
86c2c66affSColin Finck }
87c2c66affSColin Finck
88c2c66affSColin Finck /*
89c2c66affSColin Finck * Standard DriverEntry method.
90c2c66affSColin Finck */
91c2c66affSColin Finck NTSTATUS NTAPI
DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)92c2c66affSColin Finck DriverEntry(
93c2c66affSColin Finck IN PDRIVER_OBJECT DriverObject,
94c2c66affSColin Finck IN PUNICODE_STRING RegistryPath)
95c2c66affSColin Finck {
96c2c66affSColin Finck PSERMOUSE_DRIVER_EXTENSION DriverExtension;
97c2c66affSColin Finck ULONG i;
98c2c66affSColin Finck NTSTATUS Status;
99c2c66affSColin Finck
100c2c66affSColin Finck Status = IoAllocateDriverObjectExtension(
101c2c66affSColin Finck DriverObject,
102c2c66affSColin Finck DriverObject,
103c2c66affSColin Finck sizeof(SERMOUSE_DRIVER_EXTENSION),
104c2c66affSColin Finck (PVOID*)&DriverExtension);
105c2c66affSColin Finck if (!NT_SUCCESS(Status))
106c2c66affSColin Finck {
107c2c66affSColin Finck WARN_(SERMOUSE, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
108c2c66affSColin Finck return Status;
109c2c66affSColin Finck }
110c2c66affSColin Finck RtlZeroMemory(DriverExtension, sizeof(SERMOUSE_DRIVER_EXTENSION));
111c2c66affSColin Finck
112c2c66affSColin Finck Status = ReadRegistryEntries(RegistryPath, DriverExtension);
113c2c66affSColin Finck if (!NT_SUCCESS(Status))
114c2c66affSColin Finck {
115c2c66affSColin Finck WARN_(SERMOUSE, "ReadRegistryEntries() failed with status 0x%08lx\n", Status);
116c2c66affSColin Finck return Status;
117c2c66affSColin Finck }
118c2c66affSColin Finck
119c2c66affSColin Finck DriverObject->DriverUnload = DriverUnload;
120c2c66affSColin Finck DriverObject->DriverExtension->AddDevice = SermouseAddDevice;
121c2c66affSColin Finck
122c2c66affSColin Finck for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
123c2c66affSColin Finck DriverObject->MajorFunction[i] = IrpStub;
124c2c66affSColin Finck
125c2c66affSColin Finck DriverObject->MajorFunction[IRP_MJ_CREATE] = SermouseCreate;
126c2c66affSColin Finck DriverObject->MajorFunction[IRP_MJ_CLOSE] = SermouseClose;
127c2c66affSColin Finck DriverObject->MajorFunction[IRP_MJ_CLEANUP] = SermouseCleanup;
128c2c66affSColin Finck //DriverObject->MajorFunction[IRP_MJ_READ] = SermouseRead;
129c2c66affSColin Finck //DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SermouseDeviceControl;
130c2c66affSColin Finck DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = SermouseInternalDeviceControl;
131c2c66affSColin Finck //DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = SermouseQueryInformation;
132c2c66affSColin Finck DriverObject->MajorFunction[IRP_MJ_PNP] = SermousePnp;
133c2c66affSColin Finck //DriverObject->MajorFunction[IRP_MJ_POWER] = SermousePower;
134c2c66affSColin Finck
135c2c66affSColin Finck return STATUS_SUCCESS;
136c2c66affSColin Finck }
137