Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfdo.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Serial mouse driver 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: drivers/input/sermouse/fdo.c 00005 * PURPOSE: IRP_MJ_PNP operations for FDOs 00006 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org) 00007 */ 00008 00009 #include "sermouse.h" 00010 00011 NTSTATUS NTAPI 00012 SermouseAddDevice( 00013 IN PDRIVER_OBJECT DriverObject, 00014 IN PDEVICE_OBJECT Pdo) 00015 { 00016 PSERMOUSE_DRIVER_EXTENSION DriverExtension; 00017 PDEVICE_OBJECT Fdo; 00018 PSERMOUSE_DEVICE_EXTENSION DeviceExtension = NULL; 00019 NTSTATUS Status; 00020 00021 TRACE_(SERMOUSE, "SermouseAddDevice called. Pdo = 0x%p\n", Pdo); 00022 00023 if (Pdo == NULL) 00024 return STATUS_SUCCESS; 00025 00026 /* Create new device object */ 00027 DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject); 00028 Status = IoCreateDevice( 00029 DriverObject, 00030 sizeof(SERMOUSE_DEVICE_EXTENSION), 00031 NULL, 00032 FILE_DEVICE_SERIAL_MOUSE_PORT, 00033 FILE_DEVICE_SECURE_OPEN, 00034 TRUE, 00035 &Fdo); 00036 if (!NT_SUCCESS(Status)) 00037 { 00038 WARN_(SERMOUSE, "IoCreateDevice() failed with status 0x%08lx\n", Status); 00039 goto cleanup; 00040 } 00041 00042 DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)Fdo->DeviceExtension; 00043 RtlZeroMemory(DeviceExtension, sizeof(SERMOUSE_DEVICE_EXTENSION)); 00044 DeviceExtension->MouseType = mtNone; 00045 DeviceExtension->PnpState = dsStopped; 00046 DeviceExtension->DriverExtension = DriverExtension; 00047 KeInitializeEvent(&DeviceExtension->StopWorkerThreadEvent, NotificationEvent, FALSE); 00048 Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice); 00049 if (!NT_SUCCESS(Status)) 00050 { 00051 WARN_(SERMOUSE, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status); 00052 goto cleanup; 00053 } 00054 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE) 00055 Fdo->Flags |= DO_POWER_PAGABLE; 00056 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO) 00057 Fdo->Flags |= DO_BUFFERED_IO; 00058 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO) 00059 Fdo->Flags |= DO_DIRECT_IO; 00060 Fdo->Flags &= ~DO_DEVICE_INITIALIZING; 00061 00062 return STATUS_SUCCESS; 00063 00064 cleanup: 00065 if (DeviceExtension) 00066 { 00067 if (DeviceExtension->LowerDevice) 00068 IoDetachDevice(DeviceExtension->LowerDevice); 00069 } 00070 if (Fdo) 00071 { 00072 IoDeleteDevice(Fdo); 00073 } 00074 return Status; 00075 } 00076 00077 NTSTATUS NTAPI 00078 SermouseStartDevice( 00079 IN PDEVICE_OBJECT DeviceObject, 00080 IN PIRP Irp) 00081 { 00082 PSERMOUSE_DEVICE_EXTENSION DeviceExtension; 00083 SERMOUSE_MOUSE_TYPE MouseType; 00084 NTSTATUS Status; 00085 00086 DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)DeviceObject->DeviceExtension; 00087 00088 ASSERT(DeviceExtension->PnpState == dsStopped); 00089 ASSERT(DeviceExtension->LowerDevice); 00090 MouseType = SermouseDetectLegacyDevice(DeviceExtension->LowerDevice); 00091 if (MouseType == mtNone) 00092 { 00093 WARN_(SERMOUSE, "No mouse connected to Fdo %p\n", 00094 DeviceExtension->LowerDevice); 00095 return STATUS_DEVICE_NOT_CONNECTED; 00096 } 00097 00098 switch (MouseType) 00099 { 00100 case mtMicrosoft: 00101 DeviceExtension->AttributesInformation.MouseIdentifier = MOUSE_SERIAL_HARDWARE; 00102 DeviceExtension->AttributesInformation.NumberOfButtons = 2; 00103 break; 00104 case mtLogitech: 00105 DeviceExtension->AttributesInformation.MouseIdentifier = MOUSE_SERIAL_HARDWARE; 00106 DeviceExtension->AttributesInformation.NumberOfButtons = 3; 00107 break; 00108 case mtWheelZ: 00109 DeviceExtension->AttributesInformation.MouseIdentifier = WHEELMOUSE_SERIAL_HARDWARE; 00110 DeviceExtension->AttributesInformation.NumberOfButtons = 3; 00111 break; 00112 default: 00113 WARN_(SERMOUSE, "Unknown mouse type 0x%lx\n", MouseType); 00114 ASSERT(FALSE); 00115 return STATUS_UNSUCCESSFUL; 00116 } 00117 00118 if (DeviceExtension->DriverExtension->NumberOfButtons != 0) 00119 /* Override the number of buttons */ 00120 DeviceExtension->AttributesInformation.NumberOfButtons = DeviceExtension->DriverExtension->NumberOfButtons; 00121 00122 DeviceExtension->AttributesInformation.SampleRate = 1200 / 8; 00123 DeviceExtension->AttributesInformation.InputDataQueueLength = 1; 00124 DeviceExtension->MouseType = MouseType; 00125 DeviceExtension->PnpState = dsStarted; 00126 00127 /* Start read loop */ 00128 Status = PsCreateSystemThread( 00129 &DeviceExtension->WorkerThreadHandle, 00130 (ACCESS_MASK)0L, 00131 NULL, 00132 NULL, 00133 NULL, 00134 SermouseDeviceWorker, 00135 DeviceObject); 00136 00137 return Status; 00138 } 00139 00140 NTSTATUS NTAPI 00141 SermousePnp( 00142 IN PDEVICE_OBJECT DeviceObject, 00143 IN PIRP Irp) 00144 { 00145 ULONG MinorFunction; 00146 PIO_STACK_LOCATION Stack; 00147 ULONG_PTR Information = 0; 00148 NTSTATUS Status; 00149 00150 Stack = IoGetCurrentIrpStackLocation(Irp); 00151 MinorFunction = Stack->MinorFunction; 00152 Information = Irp->IoStatus.Information; 00153 00154 switch (MinorFunction) 00155 { 00156 /* FIXME: do all these minor functions 00157 IRP_MN_QUERY_REMOVE_DEVICE 0x1 00158 IRP_MN_REMOVE_DEVICE 0x2 00159 IRP_MN_CANCEL_REMOVE_DEVICE 0x3 00160 IRP_MN_STOP_DEVICE 0x4 00161 IRP_MN_QUERY_STOP_DEVICE 0x5 00162 IRP_MN_CANCEL_STOP_DEVICE 0x6 00163 IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7 00164 IRP_MN_QUERY_INTERFACE (optional) 0x8 00165 IRP_MN_QUERY_CAPABILITIES (optional) 0x9 00166 IRP_MN_FILTER_RESOURCE_REQUIREMENTS (optional or required) 0xd 00167 IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14 00168 IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16 00169 IRP_MN_SURPRISE_REMOVAL 0x17 00170 */ 00171 case IRP_MN_START_DEVICE: /* 0x0 */ 00172 { 00173 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n"); 00174 /* Call lower driver */ 00175 Status = ForwardIrpAndWait(DeviceObject, Irp); 00176 if (NT_SUCCESS(Status)) 00177 Status = SermouseStartDevice(DeviceObject, Irp); 00178 break; 00179 } 00180 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */ 00181 { 00182 switch (Stack->Parameters.QueryDeviceRelations.Type) 00183 { 00184 case BusRelations: 00185 { 00186 PDEVICE_RELATIONS DeviceRelations = NULL; 00187 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n"); 00188 00189 DeviceRelations = ExAllocatePoolWithTag(PagedPool, FIELD_OFFSET(DEVICE_RELATIONS, Objects), SERMOUSE_TAG); 00190 if (!DeviceRelations) 00191 { 00192 WARN_(SERMOUSE, "ExAllocatePoolWithTag() failed\n"); 00193 Status = STATUS_NO_MEMORY; 00194 } 00195 else 00196 { 00197 DeviceRelations->Count = 0; 00198 Status = STATUS_SUCCESS; 00199 Information = (ULONG_PTR)DeviceRelations; 00200 } 00201 break; 00202 } 00203 default: 00204 { 00205 TRACE_(SERMOUSE, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n", 00206 Stack->Parameters.QueryDeviceRelations.Type); 00207 return ForwardIrpAndForget(DeviceObject, Irp); 00208 } 00209 } 00210 break; 00211 } 00212 default: 00213 { 00214 TRACE_(SERMOUSE, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction); 00215 return ForwardIrpAndForget(DeviceObject, Irp); 00216 } 00217 } 00218 00219 Irp->IoStatus.Information = Information; 00220 Irp->IoStatus.Status = Status; 00221 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00222 return Status; 00223 } Generated on Sun May 27 2012 04:27:26 for ReactOS by
1.7.6.1
|