ReactOS 0.4.16-dev-306-g647d351
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
18
19/* FUNCTIONS ******************************************************************/
20
21CODE_SEG("PAGE")
27{
28 PAGED_CODE();
29
30 DPRINT("%s(%p, %p) %X\n", __FUNCTION__, DeviceObject,
32
33 Irp->IoStatus.Information = 0;
34 Irp->IoStatus.Status = STATUS_SUCCESS;
36
37 return STATUS_SUCCESS;
38}
39
40CODE_SEG("PAGE")
46{
50 WCHAR HardwareIdBuffer[32];
51 UNICODE_STRING HardwareId;
52 ULONG DummyResultLength;
53 UNICODE_STRING HardwareId1 = RTL_CONSTANT_STRING(L"*nEC1F00");
54 UNICODE_STRING HardwareId2 = RTL_CONSTANT_STRING(L"*PNP0F00");
55 UNICODE_STRING HardwareId3 = RTL_CONSTANT_STRING(L"*PNP0F02");
56 UNICODE_STRING HardwareId4 = RTL_CONSTANT_STRING(L"*PNP0F0D");
57 UNICODE_STRING HardwareId5 = RTL_CONSTANT_STRING(L"*PNP0F11");
58 UNICODE_STRING HardwareId6 = RTL_CONSTANT_STRING(L"*PNP0F15");
59
60 PAGED_CODE();
61
63
66 NULL,
69 FALSE,
70 &Fdo);
71 if (!NT_SUCCESS(Status))
72 {
73 DPRINT1("Failed to create FDO 0x%X\n", Status);
74 goto Failure;
75 }
76
77 FdoExtension = Fdo->DeviceExtension;
78
80 FdoExtension->State = dsStopped;
81 FdoExtension->Self = Fdo;
84 if (!FdoExtension->Ldo)
85 {
86 DPRINT1("Failed to attach FDO\n");
88 goto Failure;
89 }
90
93
96 sizeof(HardwareIdBuffer),
97 HardwareIdBuffer,
98 &DummyResultLength);
99 if (!NT_SUCCESS(Status))
100 {
101 DPRINT1("Failed to query the hardware ID string 0x%X\n", Status);
102 goto Failure;
103 }
104 RtlInitUnicodeString(&HardwareId, HardwareIdBuffer);
105
106 if (RtlEqualUnicodeString(&HardwareId, &HardwareId1, FALSE))
107 {
108 FdoExtension->MouseType = NecBusMouse;
109 FdoExtension->MouseAttributes.SampleRate = 60;
110 FdoExtension->MouseAttributes.NumberOfButtons = 2;
111 }
112 else if (RtlEqualUnicodeString(&HardwareId, &HardwareId3, FALSE) ||
113 RtlEqualUnicodeString(&HardwareId, &HardwareId4, FALSE))
114 {
115 FdoExtension->MouseType = MsInPortMouse;
116 FdoExtension->MouseAttributes.SampleRate = 100;
117 FdoExtension->MouseAttributes.NumberOfButtons = 3;
118 }
119 else if (RtlEqualUnicodeString(&HardwareId, &HardwareId2, FALSE) ||
120 RtlEqualUnicodeString(&HardwareId, &HardwareId5, FALSE) ||
121 RtlEqualUnicodeString(&HardwareId, &HardwareId6, FALSE))
122 {
123 FdoExtension->MouseType = LogitechBusMouse;
124 FdoExtension->MouseAttributes.SampleRate = 100;
125 FdoExtension->MouseAttributes.NumberOfButtons = 3;
126 }
127 else
128 {
129 DPRINT1("Unrecognized hardware '%wZ'\n", &HardwareId);
131 goto Failure;
132 }
133 FdoExtension->MouseAttributes.MouseIdentifier = MOUSE_INPORT_HARDWARE;
134 /* 1 packet */
135 FdoExtension->MouseAttributes.InputDataQueueLength = sizeof(MOUSE_INPUT_DATA);
136
137 Fdo->Flags |= DO_BUFFERED_IO;
138 if (FdoExtension->Ldo->Flags & DO_POWER_PAGABLE)
139 Fdo->Flags |= DO_POWER_PAGABLE;
140 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
141
142 return STATUS_SUCCESS;
143
144Failure:
145 if (FdoExtension)
146 {
147 if (FdoExtension->Ldo)
149 }
150
151 if (Fdo)
152 {
154 }
155
156 return Status;
157}
158
159CODE_SEG("PAGE")
160VOID
161NTAPI
164{
165 PAGED_CODE();
166
167 DPRINT("%s(%p)\n", __FUNCTION__, DriverObject);
168
170}
171
173NTAPI
177{
179 PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
180
181 DPRINT("%s(%p, %p) %X\n", __FUNCTION__, DeviceObject, Irp,
183
184 Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
185 if (!NT_SUCCESS(Status))
186 {
187 Irp->IoStatus.Status = Status;
190
191 return Status;
192 }
193
196 Status = PoCallDriver(DeviceExtension->Ldo, Irp);
197
198 IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
199
200 return Status;
201}
202
203CODE_SEG("INIT")
205NTAPI
209{
210 DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
211
213 RegistryPath->Length +
214 sizeof(UNICODE_NULL),
215 INPORT_TAG);
217 {
218 DPRINT1("Failed to allocate the registry string buffer\n");
220 }
224
225 DriverObject->MajorFunction[IRP_MJ_CREATE] =
228 DriverObject->MajorFunction[IRP_MJ_POWER] = InPortPower;
230 DriverObject->MajorFunction[IRP_MJ_PNP] = InPortPnp;
231 DriverObject->DriverExtension->AddDevice = InPortAddDevice;
232 DriverObject->DriverUnload = InPortUnload;
233
234 return STATUS_SUCCESS;
235}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
#define CODE_SEG(...)
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_DEVICE_REMOVED
Definition: d3dkmdt.h:39
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define __FUNCTION__
Definition: types.h:116
NTSTATUS NTAPI InPortInternalDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: ioctl.c:19
NTSTATUS NTAPI InPortPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pnp.c:221
NTSTATUS NTAPI InPortWmi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: wmi.c:152
@ FdoExtension
Definition: precomp.h:48
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
UNICODE_STRING DriverRegistryPath
Definition: inport.c:17
NTSTATUS NTAPI InPortCreateClose(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: inport.c:24
NTSTATUS NTAPI InPortPower(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: inport.c:174
#define INPORT_TAG
Definition: inport.h:18
DRIVER_ADD_DEVICE InPortAddDevice
Definition: inport.h:86
IO_DPC_ROUTINE InPortDpcForIsr
Definition: inport.h:109
@ NecBusMouse
Definition: inport.h:29
@ MsInPortMouse
Definition: inport.h:30
@ LogitechBusMouse
Definition: inport.h:31
DRIVER_UNLOAD InPortUnload
Definition: inport.h:83
@ dsStopped
Definition: isapnp.h:30
#define _Inout_
Definition: no_sal2.h:162
#define _In_
Definition: no_sal2.h:158
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
struct _MOUSE_INPUT_DATA MOUSE_INPUT_DATA
#define MOUSE_INPORT_HARDWARE
Definition: ntddmou.h:97
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
#define FILE_DEVICE_INPORT_PORT
Definition: winioctl.h:55
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
PDEVICE_OBJECT Ldo
Definition: inport.h:46
IO_REMOVE_LOCK RemoveLock
Definition: inport.h:48
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
#define IoAcquireRemoveLock(RemoveLock, Tag)
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2840
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833
#define IO_NO_INCREMENT
Definition: iotypes.h:598
@ DevicePropertyHardwareID
Definition: iotypes.h:1196
#define DO_POWER_PAGABLE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
__wchar_t WCHAR
Definition: xmlstorage.h:180