ReactOS  0.4.15-dev-2153-g62b4c61
inport.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS InPort (Bus) Mouse Driver
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Driver entrypoint
5  * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "inport.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS ********************************************************************/
16 
17 #ifdef ALLOC_PRAGMA
18 #pragma alloc_text(INIT, DriverEntry)
19 #pragma alloc_text(PAGE, InPortCreateClose)
20 #pragma alloc_text(PAGE, InPortAddDevice)
21 #pragma alloc_text(PAGE, InPortUnload)
22 #endif
23 
25 
26 /* FUNCTIONS ******************************************************************/
27 
29 NTAPI
33 {
34  PAGED_CODE();
35 
36  DPRINT("%s(%p, %p) %X\n", __FUNCTION__, DeviceObject,
38 
39  Irp->IoStatus.Information = 0;
40  Irp->IoStatus.Status = STATUS_SUCCESS;
42 
43  return STATUS_SUCCESS;
44 }
45 
47 NTAPI
51 {
55  WCHAR HardwareIdBuffer[32];
56  UNICODE_STRING HardwareId;
57  ULONG DummyResultLength;
58  UNICODE_STRING HardwareId1 = RTL_CONSTANT_STRING(L"*nEC1F00");
59  UNICODE_STRING HardwareId2 = RTL_CONSTANT_STRING(L"*PNP0F00");
60  UNICODE_STRING HardwareId3 = RTL_CONSTANT_STRING(L"*PNP0F02");
61  UNICODE_STRING HardwareId4 = RTL_CONSTANT_STRING(L"*PNP0F0D");
62  UNICODE_STRING HardwareId5 = RTL_CONSTANT_STRING(L"*PNP0F11");
63  UNICODE_STRING HardwareId6 = RTL_CONSTANT_STRING(L"*PNP0F15");
64 
65  PAGED_CODE();
66 
68 
71  NULL,
74  FALSE,
75  &Fdo);
76  if (!NT_SUCCESS(Status))
77  {
78  DPRINT1("Failed to create FDO 0x%X\n", Status);
79  goto Failure;
80  }
81 
82  FdoExtension = Fdo->DeviceExtension;
83 
85  FdoExtension->State = dsStopped;
86  FdoExtension->Self = Fdo;
89  if (!FdoExtension->Ldo)
90  {
91  DPRINT1("Failed to attach FDO\n");
93  goto Failure;
94  }
95 
96  IoInitializeRemoveLock(&FdoExtension->RemoveLock, INPORT_TAG, 0, 0);
98 
101  sizeof(HardwareIdBuffer),
102  HardwareIdBuffer,
103  &DummyResultLength);
104  if (!NT_SUCCESS(Status))
105  {
106  DPRINT1("Failed to query the hardware ID string 0x%X\n", Status);
107  goto Failure;
108  }
109  RtlInitUnicodeString(&HardwareId, HardwareIdBuffer);
110 
111  if (RtlEqualUnicodeString(&HardwareId, &HardwareId1, FALSE))
112  {
113  FdoExtension->MouseType = NecBusMouse;
114  FdoExtension->MouseAttributes.SampleRate = 60;
115  FdoExtension->MouseAttributes.NumberOfButtons = 2;
116  }
117  else if (RtlEqualUnicodeString(&HardwareId, &HardwareId3, FALSE) ||
118  RtlEqualUnicodeString(&HardwareId, &HardwareId4, FALSE))
119  {
120  FdoExtension->MouseType = MsInPortMouse;
121  FdoExtension->MouseAttributes.SampleRate = 100;
122  FdoExtension->MouseAttributes.NumberOfButtons = 3;
123  }
124  else if (RtlEqualUnicodeString(&HardwareId, &HardwareId2, FALSE) ||
125  RtlEqualUnicodeString(&HardwareId, &HardwareId5, FALSE) ||
126  RtlEqualUnicodeString(&HardwareId, &HardwareId6, FALSE))
127  {
128  FdoExtension->MouseType = LogitechBusMouse;
129  FdoExtension->MouseAttributes.SampleRate = 100;
130  FdoExtension->MouseAttributes.NumberOfButtons = 3;
131  }
132  else
133  {
134  DPRINT1("Unrecognized hardware '%wZ'\n", &HardwareId);
136  goto Failure;
137  }
138  FdoExtension->MouseAttributes.MouseIdentifier = MOUSE_INPORT_HARDWARE;
139  /* 1 packet */
140  FdoExtension->MouseAttributes.InputDataQueueLength = sizeof(MOUSE_INPUT_DATA);
141 
142  Fdo->Flags |= DO_BUFFERED_IO;
143  if (FdoExtension->Ldo->Flags & DO_POWER_PAGABLE)
144  Fdo->Flags |= DO_POWER_PAGABLE;
145  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
146 
147  return STATUS_SUCCESS;
148 
149 Failure:
150  if (FdoExtension)
151  {
152  if (FdoExtension->Ldo)
154  }
155 
156  if (Fdo)
157  {
159  }
160 
161  return Status;
162 }
163 
164 VOID
165 NTAPI
168 {
169  PAGED_CODE();
170 
171  DPRINT("%s(%p)\n", __FUNCTION__, DriverObject);
172 
174 }
175 
176 NTSTATUS
177 NTAPI
180  _Inout_ PIRP Irp)
181 {
183  PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
184 
185  DPRINT("%s(%p, %p) %X\n", __FUNCTION__, DeviceObject, Irp,
187 
188  Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
189  if (!NT_SUCCESS(Status))
190  {
191  Irp->IoStatus.Status = Status;
194 
195  return Status;
196  }
197 
200  Status = PoCallDriver(DeviceExtension->Ldo, Irp);
201 
202  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
203 
204  return Status;
205 }
206 
207 NTSTATUS
208 NTAPI
212 {
213  DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
214 
216  RegistryPath->Length +
217  sizeof(UNICODE_NULL),
218  INPORT_TAG);
220  {
221  DPRINT1("Failed to allocate the registry string buffer\n");
223  }
227 
228  DriverObject->MajorFunction[IRP_MJ_CREATE] =
229  DriverObject->MajorFunction[IRP_MJ_CLOSE] = InPortCreateClose;
231  DriverObject->MajorFunction[IRP_MJ_POWER] = InPortPower;
232  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = InPortWmi;
233  DriverObject->MajorFunction[IRP_MJ_PNP] = InPortPnp;
234  DriverObject->DriverExtension->AddDevice = InPortAddDevice;
235  DriverObject->DriverUnload = InPortUnload;
236 
237  return STATUS_SUCCESS;
238 }
PDEVICE_OBJECT Ldo
Definition: inport.h:44
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2836
#define DO_POWER_PAGABLE
#define FILE_DEVICE_INPORT_PORT
Definition: winioctl.h:116
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2829
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2760
NTSTATUS NTAPI InPortCreateClose(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: inport.c:30
NTSTATUS NTAPI InPortInternalDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: ioctl.c:19
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
struct _MOUSE_INPUT_DATA MOUSE_INPUT_DATA
#define MOUSE_INPORT_HARDWARE
Definition: ntddmou.h:97
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
_In_ PIRP Irp
Definition: csq.h:116
IO_DPC_ROUTINE InPortDpcForIsr
Definition: inport.h:101
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1697
#define INPORT_TAG
Definition: inport.h:16
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1953
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
Definition: inport.c:209
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define _Inout_
Definition: no_sal2.h:162
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
IO_REMOVE_LOCK RemoveLock
Definition: inport.h:46
NTSTATUS NTAPI InPortPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pnp.c:226
VOID NTAPI InPortUnload(_In_ PDRIVER_OBJECT DriverObject)
Definition: inport.c:166
#define IRP_MJ_SYSTEM_CONTROL
#define _In_
Definition: no_sal2.h:158
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
UNICODE_STRING DriverRegistryPath
Definition: inport.c:24
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
NTSTATUS NTAPI InPortAddDevice(_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT PhysicalDeviceObject)
Definition: inport.c:48
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
NTSTATUS NTAPI InPortWmi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: wmi.c:156
#define NULL
Definition: types.h:112
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS NTAPI InPortPower(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: inport.c:178
#define __FUNCTION__
Definition: types.h:112
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define PAGED_CODE()
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14