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