Author: janderwald Date: Fri Aug 21 14:58:20 2009 New Revision: 42823
URL: http://svn.reactos.org/svn/reactos?rev=42823&view=rev Log: - Partly implement KsCreateBusEnumObject
Modified: trunk/reactos/drivers/ksfilter/ks/api.c trunk/reactos/drivers/ksfilter/ks/kstypes.h
Modified: trunk/reactos/drivers/ksfilter/ks/api.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/api.c?r... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/api.c [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/api.c [iso-8859-1] Fri Aug 21 14:58:20 2009 @@ -1709,7 +1709,7 @@ }
/* - @unimplemented + @implemented */ KSDDKAPI NTSTATUS @@ -1722,8 +1722,118 @@ 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
Modified: trunk/reactos/drivers/ksfilter/ks/kstypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/kstypes... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/kstypes.h [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/kstypes.h [iso-8859-1] Fri Aug 21 14:58:20 2009 @@ -145,4 +145,19 @@
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