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