2005-07-07 23:10:35 +00:00
|
|
|
|
/*
|
2005-04-05 19:04:07 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS Serial enumerator driver
|
|
|
|
|
* FILE: drivers/bus/serenum/fdo.c
|
|
|
|
|
* PURPOSE: IRP_MJ_PNP operations for FDOs
|
2005-05-08 02:16:32 +00:00
|
|
|
|
*
|
2007-07-08 22:19:51 +00:00
|
|
|
|
* PROGRAMMERS: Herv<EFBFBD> Poussineau (hpoussin@reactos.org)
|
2005-04-05 19:04:07 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "serenum.h"
|
|
|
|
|
|
2014-02-03 00:13:57 +00:00
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2006-06-07 17:31:43 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2005-04-05 19:04:07 +00:00
|
|
|
|
SerenumAddDevice(
|
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
|
IN PDEVICE_OBJECT Pdo)
|
|
|
|
|
{
|
|
|
|
|
PDEVICE_OBJECT Fdo;
|
|
|
|
|
PFDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
NTSTATUS Status;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "SerenumAddDevice called. Pdo = %p\n", Pdo);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
/* Create new device object */
|
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
|
sizeof(FDO_DEVICE_EXTENSION),
|
|
|
|
|
NULL,
|
|
|
|
|
FILE_DEVICE_BUS_EXTENDER,
|
|
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
|
|
|
|
FALSE,
|
|
|
|
|
&Fdo);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
WARN_(SERENUM, "IoCreateDevice() failed with status 0x%08lx\n", Status);
|
2005-04-05 19:04:07 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
2005-04-30 15:04:10 +00:00
|
|
|
|
DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
|
|
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
/* Register device interface */
|
2005-04-30 15:04:10 +00:00
|
|
|
|
Status = IoRegisterDeviceInterface(
|
|
|
|
|
Pdo,
|
|
|
|
|
&GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
|
|
|
|
|
NULL,
|
|
|
|
|
&DeviceExtension->SerenumInterfaceName);
|
2005-04-05 19:04:07 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
WARN_(SERENUM, "IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
|
2005-04-30 15:04:10 +00:00
|
|
|
|
IoDeleteDevice(Fdo);
|
|
|
|
|
return Status;
|
2005-04-05 19:04:07 +00:00
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
DeviceExtension->Common.IsFDO = TRUE;
|
|
|
|
|
DeviceExtension->Common.PnpState = dsStopped;
|
|
|
|
|
DeviceExtension->Pdo = Pdo;
|
|
|
|
|
IoInitializeRemoveLock(&DeviceExtension->RemoveLock, SERENUM_TAG, 0, 0);
|
|
|
|
|
Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
WARN_(SERENUM, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
|
2005-04-05 19:04:07 +00:00
|
|
|
|
IoDeleteDevice(Fdo);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
2006-09-30 23:06:51 +00:00
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
|
|
|
|
|
Fdo->Flags |= DO_POWER_PAGABLE;
|
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
|
|
|
|
|
Fdo->Flags |= DO_BUFFERED_IO;
|
|
|
|
|
if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
|
|
|
|
|
Fdo->Flags |= DO_DIRECT_IO;
|
2005-04-05 19:04:07 +00:00
|
|
|
|
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-07 17:31:43 +00:00
|
|
|
|
static NTSTATUS NTAPI
|
2005-04-05 19:04:07 +00:00
|
|
|
|
SerenumFdoStartDevice(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
2005-04-30 15:04:10 +00:00
|
|
|
|
PFDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
NTSTATUS Status;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "SerenumFdoStartDevice() called\n");
|
2005-04-30 15:04:10 +00:00
|
|
|
|
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-30 15:04:10 +00:00
|
|
|
|
ASSERT(DeviceExtension->Common.PnpState == dsStopped);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-30 15:04:10 +00:00
|
|
|
|
Status = IoSetDeviceInterfaceState(&DeviceExtension->SerenumInterfaceName, TRUE);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
WARN_(SERENUM, "IoSetDeviceInterfaceState() failed with status 0x%08lx\n", Status);
|
2005-04-30 15:04:10 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-30 15:04:10 +00:00
|
|
|
|
DeviceExtension->Common.PnpState = dsStarted;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-06 21:39:18 +00:00
|
|
|
|
static NTSTATUS
|
2005-04-05 19:04:07 +00:00
|
|
|
|
SerenumFdoQueryBusRelations(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
OUT PDEVICE_RELATIONS* pDeviceRelations)
|
|
|
|
|
{
|
|
|
|
|
PFDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
PDEVICE_RELATIONS DeviceRelations;
|
|
|
|
|
ULONG NumPDO;
|
|
|
|
|
ULONG i;
|
2005-04-06 12:32:14 +00:00
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
ASSERT(DeviceExtension->Common.IsFDO);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
/* Do enumeration if needed */
|
|
|
|
|
if (!(DeviceExtension->Flags & FLAG_ENUMERATION_DONE))
|
|
|
|
|
{
|
|
|
|
|
ASSERT(DeviceExtension->AttachedPdo == NULL);
|
|
|
|
|
/* Detect plug-and-play devices */
|
|
|
|
|
Status = SerenumDetectPnpDevice(DeviceObject, DeviceExtension->LowerDevice);
|
|
|
|
|
if (Status == STATUS_DEVICE_NOT_CONNECTED)
|
|
|
|
|
{
|
|
|
|
|
/* Detect legacy devices */
|
|
|
|
|
Status = SerenumDetectLegacyDevice(DeviceObject, DeviceExtension->LowerDevice);
|
|
|
|
|
if (Status == STATUS_DEVICE_NOT_CONNECTED)
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
DeviceExtension->Flags |= FLAG_ENUMERATION_DONE;
|
|
|
|
|
}
|
|
|
|
|
NumPDO = (DeviceExtension->AttachedPdo != NULL ? 1 : 0);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-08-24 15:33:58 +00:00
|
|
|
|
DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePoolWithTag(
|
2005-04-05 19:04:07 +00:00
|
|
|
|
PagedPool,
|
2005-08-24 15:33:58 +00:00
|
|
|
|
sizeof(DEVICE_RELATIONS) + sizeof(PDEVICE_OBJECT) * (NumPDO - 1),
|
|
|
|
|
SERENUM_TAG);
|
2005-04-05 19:04:07 +00:00
|
|
|
|
if (!DeviceRelations)
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
/* Fill returned structure */
|
|
|
|
|
DeviceRelations->Count = NumPDO;
|
|
|
|
|
for (i = 0; i < NumPDO; i++)
|
|
|
|
|
{
|
|
|
|
|
ObReferenceObject(DeviceExtension->AttachedPdo);
|
|
|
|
|
DeviceRelations->Objects[i] = DeviceExtension->AttachedPdo;
|
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
*pDeviceRelations = DeviceRelations;
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
SerenumFdoPnp(
|
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN PIRP Irp)
|
|
|
|
|
{
|
2022-01-04 00:56:52 +00:00
|
|
|
|
PFDO_DEVICE_EXTENSION FdoExtension;
|
2005-04-05 19:04:07 +00:00
|
|
|
|
ULONG MinorFunction;
|
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
|
ULONG_PTR Information = 0;
|
|
|
|
|
NTSTATUS Status;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
MinorFunction = Stack->MinorFunction;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
switch (MinorFunction)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: do all these minor functions
|
|
|
|
|
IRP_MN_QUERY_REMOVE_DEVICE 0x1
|
|
|
|
|
IRP_MN_REMOVE_DEVICE 0x2
|
|
|
|
|
IRP_MN_CANCEL_REMOVE_DEVICE 0x3
|
|
|
|
|
IRP_MN_STOP_DEVICE 0x4
|
|
|
|
|
IRP_MN_QUERY_STOP_DEVICE 0x5
|
|
|
|
|
IRP_MN_CANCEL_STOP_DEVICE 0x6
|
|
|
|
|
IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
|
|
|
|
|
IRP_MN_QUERY_INTERFACE (optional) 0x8
|
|
|
|
|
IRP_MN_QUERY_CAPABILITIES (optional) 0x9
|
|
|
|
|
IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
|
|
|
|
|
IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
|
|
|
|
|
IRP_MN_SURPRISE_REMOVAL 0x17
|
|
|
|
|
*/
|
|
|
|
|
case IRP_MN_START_DEVICE: /* 0x0 */
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
|
2005-04-05 19:04:07 +00:00
|
|
|
|
/* Call lower driver */
|
2022-01-04 00:56:52 +00:00
|
|
|
|
FdoExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
if (IoForwardIrpSynchronously(FdoExtension->LowerDevice, Irp))
|
|
|
|
|
{
|
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
Status = SerenumFdoStartDevice(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
|
|
|
|
|
{
|
|
|
|
|
switch (Stack->Parameters.QueryDeviceRelations.Type)
|
|
|
|
|
{
|
|
|
|
|
case BusRelations:
|
|
|
|
|
{
|
2005-08-01 12:57:34 +00:00
|
|
|
|
PDEVICE_RELATIONS DeviceRelations = NULL;
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
|
2005-04-05 19:04:07 +00:00
|
|
|
|
Status = SerenumFdoQueryBusRelations(DeviceObject, &DeviceRelations);
|
|
|
|
|
Information = (ULONG_PTR)DeviceRelations;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
|
2005-04-05 19:04:07 +00:00
|
|
|
|
Stack->Parameters.QueryDeviceRelations.Type);
|
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-07-08 22:19:51 +00:00
|
|
|
|
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* 0xd */
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
|
2007-07-08 22:19:51 +00:00
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
}
|
2005-04-05 19:04:07 +00:00
|
|
|
|
default:
|
|
|
|
|
{
|
2007-12-28 21:10:07 +00:00
|
|
|
|
TRACE_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
|
2005-04-05 19:04:07 +00:00
|
|
|
|
return ForwardIrpAndForget(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
|
2005-04-05 19:04:07 +00:00
|
|
|
|
Irp->IoStatus.Information = Information;
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|