ReactOS  0.4.14-dev-376-gaedba84
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 {
19  PDEVICE_OBJECT Fdo;
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;
50  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
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;
63 
64  return STATUS_SUCCESS;
65 
66 cleanup:
67  if (DeviceExtension)
68  {
69  if (DeviceExtension->LowerDevice)
70  IoDetachDevice(DeviceExtension->LowerDevice);
71  }
72  if (Fdo)
73  {
74  IoDeleteDevice(Fdo);
75  }
76  return Status;
77 }
78 
82  IN PIRP Irp)
83 {
84  PSERMOUSE_DEVICE_EXTENSION DeviceExtension;
85  SERMOUSE_MOUSE_TYPE MouseType;
87 
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,
137  DeviceObject);
138 
139  return Status;
140 }
141 
145  IN PIRP Irp)
146 {
148  PIO_STACK_LOCATION Stack;
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  TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
176  /* Call lower driver */
178  if (NT_SUCCESS(Status))
180  break;
181  }
182  case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
183  {
184  switch (Stack->Parameters.QueryDeviceRelations.Type)
185  {
186  case BusRelations:
187  {
188  PDEVICE_RELATIONS DeviceRelations = NULL;
189  TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n");
190 
192  if (!DeviceRelations)
193  {
194  WARN_(SERMOUSE, "ExAllocatePoolWithTag() failed\n");
196  }
197  else
198  {
199  DeviceRelations->Count = 0;
201  Information = (ULONG_PTR)DeviceRelations;
202  }
203  break;
204  }
205  default:
206  {
207  TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
208  Stack->Parameters.QueryDeviceRelations.Type);
210  }
211  }
212  break;
213  }
214  default:
215  {
216  TRACE_(SERMOUSE, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
218  }
219  }
220 
221  Irp->IoStatus.Information = Information;
222  Irp->IoStatus.Status = Status;
224  return Status;
225 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
NTSTATUS NTAPI ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:32
SERMOUSE_MOUSE_TYPE
Definition: sermouse.h:19
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT LowerDevice
Definition: sermouse.h:57
LONG NTSTATUS
Definition: precomp.h:26
SERMOUSE_MOUSE_TYPE SermouseDetectLegacyDevice(IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:117
SERMOUSE_DEVICE_STATE PnpState
Definition: sermouse.h:58
#define MOUSE_SERIAL_HARDWARE
Definition: ntddmou.h:99
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
struct _SERMOUSE_DEVICE_EXTENSION * PSERMOUSE_DEVICE_EXTENSION
USHORT MouseIdentifier
Definition: ntddmou.h:109
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SERMOUSE_TAG
Definition: sermouse.h:8
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS NTAPI SermouseStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:80
ULONG InputDataQueueLength
Definition: ntddmou.h:112
VOID NTAPI SermouseDeviceWorker(PVOID Context)
Definition: readmouse.c:64
USHORT SampleRate
Definition: ntddmou.h:111
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define TRACE_(x)
Definition: compat.h:66
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI SermousePnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:143
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define IRP_MN_START_DEVICE
MOUSE_ATTRIBUTES AttributesInformation
Definition: sermouse.h:72
NTSTATUS NTAPI SermouseAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
Definition: fdo.c:14
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:66
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
#define FILE_DEVICE_SERIAL_MOUSE_PORT
Definition: winioctl.h:131
#define WHEELMOUSE_SERIAL_HARDWARE
Definition: ntddmou.h:103
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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 FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define IRP_MN_QUERY_DEVICE_RELATIONS
SERMOUSE_MOUSE_TYPE MouseType
Definition: sermouse.h:59
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
char * cleanup(char *str)
Definition: wpickclick.c:99
PSERMOUSE_DRIVER_EXTENSION DriverExtension
Definition: sermouse.h:60
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
USHORT NumberOfButtons
Definition: ntddmou.h:110
#define WARN_(ch,...)
Definition: debug.h:157
ULONG ACCESS_MASK
Definition: nt_native.h:40
Iosb Information
Definition: create.c:4377