ReactOS 0.4.16-dev-311-g9382aa2
fdo.c
Go to the documentation of this file.
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: IRP_MJ_PNP operations for FDOs
6 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9#include "sermouse.h"
10
11#include <debug.h>
12
17{
20 PSERMOUSE_DEVICE_EXTENSION DeviceExtension = NULL;
22
23 TRACE_(SERMOUSE, "SermouseAddDevice called. Pdo = 0x%p\n", Pdo);
24
25 if (Pdo == NULL)
26 return STATUS_SUCCESS;
27
28 /* Create new device object */
33 NULL,
36 TRUE,
37 &Fdo);
38 if (!NT_SUCCESS(Status))
39 {
40 WARN_(SERMOUSE, "IoCreateDevice() failed with status 0x%08lx\n", Status);
41 goto cleanup;
42 }
43
44 DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)Fdo->DeviceExtension;
45 RtlZeroMemory(DeviceExtension, sizeof(SERMOUSE_DEVICE_EXTENSION));
46 DeviceExtension->MouseType = mtNone;
47 DeviceExtension->PnpState = dsStopped;
48 DeviceExtension->DriverExtension = DriverExtension;
51 if (!NT_SUCCESS(Status))
52 {
53 WARN_(SERMOUSE, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
54 goto cleanup;
55 }
56 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
57 Fdo->Flags |= DO_POWER_PAGABLE;
58 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
59 Fdo->Flags |= DO_BUFFERED_IO;
60 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
61 Fdo->Flags |= DO_DIRECT_IO;
62 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
63
64 return STATUS_SUCCESS;
65
67 if (DeviceExtension)
68 {
69 if (DeviceExtension->LowerDevice)
70 IoDetachDevice(DeviceExtension->LowerDevice);
71 }
72 if (Fdo)
73 {
75 }
76 return Status;
77}
78
82 IN PIRP Irp)
83{
84 PSERMOUSE_DEVICE_EXTENSION DeviceExtension;
85 SERMOUSE_MOUSE_TYPE MouseType;
87
88 DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
89
90 ASSERT(DeviceExtension->PnpState == dsStopped);
91 ASSERT(DeviceExtension->LowerDevice);
92 MouseType = SermouseDetectLegacyDevice(DeviceExtension->LowerDevice);
93 if (MouseType == mtNone)
94 {
95 WARN_(SERMOUSE, "No mouse connected to Fdo %p\n",
96 DeviceExtension->LowerDevice);
98 }
99
100 switch (MouseType)
101 {
102 case mtMicrosoft:
104 DeviceExtension->AttributesInformation.NumberOfButtons = 2;
105 break;
106 case mtLogitech:
108 DeviceExtension->AttributesInformation.NumberOfButtons = 3;
109 break;
110 case mtWheelZ:
112 DeviceExtension->AttributesInformation.NumberOfButtons = 3;
113 break;
114 default:
115 WARN_(SERMOUSE, "Unknown mouse type 0x%lx\n", MouseType);
116 ASSERT(FALSE);
117 return STATUS_UNSUCCESSFUL;
118 }
119
120 if (DeviceExtension->DriverExtension->NumberOfButtons != 0)
121 /* Override the number of buttons */
122 DeviceExtension->AttributesInformation.NumberOfButtons = DeviceExtension->DriverExtension->NumberOfButtons;
123
124 DeviceExtension->AttributesInformation.SampleRate = 1200 / 8;
125 DeviceExtension->AttributesInformation.InputDataQueueLength = 1;
126 DeviceExtension->MouseType = MouseType;
127 DeviceExtension->PnpState = dsStarted;
128
129 /* Start read loop */
131 &DeviceExtension->WorkerThreadHandle,
132 (ACCESS_MASK)0L,
133 NULL,
134 NULL,
135 NULL,
138
139 return Status;
140}
141
145 IN PIRP Irp)
146{
151
153 MinorFunction = Stack->MinorFunction;
154 Information = Irp->IoStatus.Information;
155
156 switch (MinorFunction)
157 {
158 /* FIXME: do all these minor functions
159 IRP_MN_QUERY_REMOVE_DEVICE 0x1
160 IRP_MN_REMOVE_DEVICE 0x2
161 IRP_MN_CANCEL_REMOVE_DEVICE 0x3
162 IRP_MN_STOP_DEVICE 0x4
163 IRP_MN_QUERY_STOP_DEVICE 0x5
164 IRP_MN_CANCEL_STOP_DEVICE 0x6
165 IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
166 IRP_MN_QUERY_INTERFACE (optional) 0x8
167 IRP_MN_QUERY_CAPABILITIES (optional) 0x9
168 IRP_MN_FILTER_RESOURCE_REQUIREMENTS (optional or required) 0xd
169 IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
170 IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
171 IRP_MN_SURPRISE_REMOVAL 0x17
172 */
173 case IRP_MN_START_DEVICE: /* 0x0 */
174 {
175 PSERMOUSE_DEVICE_EXTENSION DeviceExtension;
176
177 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
179 DeviceExtension = DeviceObject->DeviceExtension;
180
181 /* Call lower driver */
182 if (IoForwardIrpSynchronously(DeviceExtension->LowerDevice, Irp))
183 {
184 Status = Irp->IoStatus.Status;
185 if (NT_SUCCESS(Status))
186 {
188 }
189 }
190 break;
191 }
192 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
193 {
194 switch (Stack->Parameters.QueryDeviceRelations.Type)
195 {
196 case BusRelations:
197 {
198 PDEVICE_RELATIONS DeviceRelations = NULL;
199 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n");
200
202 if (!DeviceRelations)
203 {
204 WARN_(SERMOUSE, "ExAllocatePoolWithTag() failed\n");
206 }
207 else
208 {
209 DeviceRelations->Count = 0;
211 Information = (ULONG_PTR)DeviceRelations;
212 }
213 break;
214 }
215 default:
216 {
217 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
218 Stack->Parameters.QueryDeviceRelations.Type);
220 }
221 }
222 break;
223 }
224 default:
225 {
226 TRACE_(SERMOUSE, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
228 }
229 }
230
231 Irp->IoStatus.Information = Information;
232 Irp->IoStatus.Status = Status;
234 return Status;
235}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define TRACE_(x)
Definition: compat.h:76
static void cleanup(void)
Definition: main.c:1335
SERMOUSE_MOUSE_TYPE SermouseDetectLegacyDevice(IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:117
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
NTSTATUS NTAPI SermouseStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:80
@ dsStopped
Definition: isapnp.h:30
@ dsStarted
Definition: isapnp.h:31
#define ASSERT(a)
Definition: mode.c:44
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define MOUSE_SERIAL_HARDWARE
Definition: ntddmou.h:99
#define WHEELMOUSE_SERIAL_HARDWARE
Definition: ntddmou.h:103
@ NotificationEvent
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
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define L(x)
Definition: ntvdm.h:50
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
#define FILE_DEVICE_SERIAL_MOUSE_PORT
Definition: winioctl.h:71
VOID NTAPI SermouseDeviceWorker(PVOID Context)
Definition: readmouse.c:64
#define WARN_(ch,...)
Definition: debug.h:157
SERMOUSE_MOUSE_TYPE
Definition: sermouse.h:20
@ mtMicrosoft
Definition: sermouse.h:22
@ mtNone
Definition: sermouse.h:21
@ mtLogitech
Definition: sermouse.h:23
@ mtWheelZ
Definition: sermouse.h:24
struct _SERMOUSE_DEVICE_EXTENSION * PSERMOUSE_DEVICE_EXTENSION
#define SERMOUSE_TAG
Definition: sermouse.h:8
DRIVER_DISPATCH SermousePnp
Definition: sermouse.h:93
DRIVER_ADD_DEVICE SermouseAddDevice
Definition: sermouse.h:91
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MouseIdentifier
Definition: ntddmou.h:109
ULONG InputDataQueueLength
Definition: ntddmou.h:112
USHORT SampleRate
Definition: ntddmou.h:111
USHORT NumberOfButtons
Definition: ntddmou.h:110
PSERMOUSE_DRIVER_EXTENSION DriverExtension
Definition: sermouse.h:60
SERMOUSE_MOUSE_TYPE MouseType
Definition: sermouse.h:59
PDEVICE_OBJECT LowerDevice
Definition: sermouse.h:57
MOUSE_ATTRIBUTES AttributesInformation
Definition: sermouse.h:72
SERMOUSE_DEVICE_STATE PnpState
Definition: sermouse.h:58
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
@ BusRelations
Definition: iotypes.h:2152
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DO_POWER_PAGABLE