From a6407bcf60fbca235e38e824aa994e6c8e494412 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Fri, 21 Aug 2009 12:58:20 +0000 Subject: [PATCH] - Partly implement KsCreateBusEnumObject svn path=/trunk/; revision=42823 --- reactos/drivers/ksfilter/ks/api.c | 116 +++++++++++++++++++++++++- reactos/drivers/ksfilter/ks/kstypes.h | 15 ++++ 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/reactos/drivers/ksfilter/ks/api.c b/reactos/drivers/ksfilter/ks/api.c index df0f709090b..bace9efaec7 100644 --- a/reactos/drivers/ksfilter/ks/api.c +++ b/reactos/drivers/ksfilter/ks/api.c @@ -1709,7 +1709,7 @@ KsCompletePendingRequest( } /* - @unimplemented + @implemented */ KSDDKAPI NTSTATUS @@ -1722,8 +1722,118 @@ KsCreateBusEnumObject( IN REFGUID InterfaceGuid OPTIONAL, IN PWCHAR ServiceRelativePath OPTIONAL) { - UNIMPLEMENTED - return STATUS_UNSUCCESSFUL; + ULONG Length; + NTSTATUS Status = STATUS_SUCCESS; + UNICODE_STRING ServiceKeyPath = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\"); + PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension; + PDEVICE_EXTENSION DeviceExtension; + + /* calculate sizeof bus enum device extension */ + Length = wcslen(BusIdentifier) * sizeof(WCHAR); + Length += sizeof(BUS_ENUM_DEVICE_EXTENSION); + + BusDeviceExtension = ExAllocatePool(NonPagedPool, Length); + if (!BusDeviceExtension) + { + /* not enough memory */ + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* zero device extension */ + RtlZeroMemory(BusDeviceExtension, sizeof(BUS_ENUM_DEVICE_EXTENSION)); + + /* initialize bus device extension */ + wcscpy(BusDeviceExtension->BusIdentifier, BusIdentifier); + + /* allocate service path string */ + Length = ServiceKeyPath.MaximumLength; + Length += BusDeviceObject->DriverObject->DriverExtension->ServiceKeyName.MaximumLength; + + if (ServiceRelativePath) + { + /* relative path for devices */ + Length += wcslen(ServiceRelativePath) + 2 * sizeof(WCHAR); + } + + BusDeviceExtension->ServicePath.Length = 0; + BusDeviceExtension->ServicePath.MaximumLength = Length; + BusDeviceExtension->ServicePath.Buffer = ExAllocatePool(NonPagedPool, Length); + + if (!BusDeviceExtension->ServicePath.Buffer) + { + /* not enough memory */ + ExFreePool(BusDeviceExtension); + return STATUS_INSUFFICIENT_RESOURCES; + } + + RtlAppendUnicodeStringToString(&BusDeviceExtension->ServicePath, &ServiceKeyPath); + RtlAppendUnicodeStringToString(&BusDeviceExtension->ServicePath, &BusDeviceObject->DriverObject->DriverExtension->ServiceKeyName); + + if (ServiceRelativePath) + { + RtlAppendUnicodeToString(&BusDeviceExtension->ServicePath, L"\\"); + RtlAppendUnicodeToString(&BusDeviceExtension->ServicePath, ServiceRelativePath); + } + + if (InterfaceGuid) + { + /* register an device interface */ + Status = IoRegisterDeviceInterface(PhysicalDeviceObject, InterfaceGuid, NULL, &BusDeviceExtension->SymbolicLinkName); + + /* check for success */ + if (!NT_SUCCESS(Status)) + { + ExFreePool(BusDeviceExtension->ServicePath.Buffer); + ExFreePool(BusDeviceExtension); + return Status; + } + + /* now enable device interface */ + Status = IoSetDeviceInterfaceState(&BusDeviceExtension->SymbolicLinkName, TRUE); + + if (!NT_SUCCESS(Status)) + { + ExFreePool(BusDeviceExtension->ServicePath.Buffer); + ExFreePool(BusDeviceExtension); + return Status; + } + + /* set state enabled */ + BusDeviceExtension->Enabled = TRUE; + } + + /* store device objects */ + BusDeviceExtension->BusDeviceObject = BusDeviceObject; + BusDeviceExtension->PnpDeviceObject = PnpDeviceObject; + BusDeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject; + + if (!PnpDeviceObject) + { + BusDeviceExtension->PnpDeviceObject = IoAttachDeviceToDeviceStack(BusDeviceObject, PhysicalDeviceObject); + + if (!BusDeviceExtension->PnpDeviceObject) + { + /* failed to attach device */ + if (BusDeviceExtension->Enabled) + { + IoSetDeviceInterfaceState(&BusDeviceExtension->SymbolicLinkName, FALSE); + RtlFreeUnicodeString(&BusDeviceExtension->SymbolicLinkName); + } + + /* free device extension */ + ExFreePool(BusDeviceExtension->ServicePath.Buffer); + ExFreePool(BusDeviceExtension); + + return STATUS_DEVICE_REMOVED; + } + } + + /* attach device extension */ + DeviceExtension = (PDEVICE_EXTENSION)BusDeviceObject->DeviceExtension; + DeviceExtension->DeviceHeader = (PKSIDEVICE_HEADER)BusDeviceExtension; + + /* FIXME scan bus and invalidate device relations */ + return Status; } NTSTATUS diff --git a/reactos/drivers/ksfilter/ks/kstypes.h b/reactos/drivers/ksfilter/ks/kstypes.h index 22c1a224b0d..503fc01079e 100644 --- a/reactos/drivers/ksfilter/ks/kstypes.h +++ b/reactos/drivers/ksfilter/ks/kstypes.h @@ -145,4 +145,19 @@ typedef struct typedef BOOLEAN (NTAPI *PKSEVENT_SYNCHRONIZED_ROUTINE)(PKSEVENT_CTX Context); +typedef struct +{ + BOOLEAN Enabled; + + PDEVICE_OBJECT PnpDeviceObject; + PDEVICE_OBJECT PhysicalDeviceObject; + PDEVICE_OBJECT BusDeviceObject; + + UNICODE_STRING ServicePath; + UNICODE_STRING SymbolicLinkName; + + WCHAR BusIdentifier[1]; +}BUS_ENUM_DEVICE_EXTENSION, *PBUS_ENUM_DEVICE_EXTENSION; + + #endif