Author: janderwald Date: Tue Jul 28 12:22:02 2009 New Revision: 42264
URL: http://svn.reactos.org/svn/reactos?rev=42264&view=rev Log: - Implement KoDriverInitialize, KoDeviceInitialize - Fix storing of device descriptor in KsInitializeDriver, KsAddDevice
Modified: trunk/reactos/drivers/ksfilter/ks/api.c trunk/reactos/drivers/ksfilter/ks/device.c trunk/reactos/drivers/ksfilter/ks/driver.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] Tue Jul 28 12:22:02 2009 @@ -8,7 +8,6 @@
#include "priv.h" -
/* @unimplemented @@ -1167,8 +1166,209 @@ }
-/* - @unimplemented +NTSTATUS +NTAPI +KopDispatchClose( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PKO_OBJECT_HEADER Header; + PIO_STACK_LOCATION IoStack; + PDEVICE_EXTENSION DeviceExtension; + + /* get current irp stack location */ + IoStack = IoGetCurrentIrpStackLocation(Irp); + + /* get ko object header */ + Header = (PKO_OBJECT_HEADER)IoStack->FileObject->FsContext2; + + /* free ks object header */ + KsFreeObjectHeader(Header->ObjectHeader); + + /* free ko object header */ + FreeItem(Header); + + /* get device extension */ + DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; + + /* release bus object */ + KsDereferenceBusObject((KSDEVICE_HEADER)DeviceExtension->DeviceHeader); + + /* complete request */ + Irp->IoStatus.Status = STATUS_SUCCESS; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return STATUS_SUCCESS; +} + + + +static KSDISPATCH_TABLE KoDispatchTable = +{ + KsDispatchInvalidDeviceRequest, + KsDispatchInvalidDeviceRequest, + KsDispatchInvalidDeviceRequest, + KsDispatchInvalidDeviceRequest, + KopDispatchClose, + KsDispatchQuerySecurity, + KsDispatchSetSecurity, + KsDispatchFastIoDeviceControlFailure, + KsDispatchFastReadFailure, + KsDispatchFastReadFailure, +}; + + +NTSTATUS +NTAPI +KopDispatchCreate( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PKO_OBJECT_HEADER Header = NULL; + PIO_STACK_LOCATION IoStack; + PKO_DRIVER_EXTENSION DriverObjectExtension; + NTSTATUS Status; + + /* get current irp stack location */ + IoStack = IoGetCurrentIrpStackLocation(Irp); + + if (!IoStack->FileObject) + { + DPRINT1("FileObject not attached!\n"); + Status = STATUS_UNSUCCESSFUL; + goto cleanup; + } + + /* get driver object extension */ + DriverObjectExtension = (PKO_DRIVER_EXTENSION)IoGetDriverObjectExtension(DeviceObject->DriverObject, (PVOID)KoDriverInitialize); + if (!DriverObjectExtension) + { + DPRINT1("FileObject not attached!\n"); + Status = STATUS_UNSUCCESSFUL; + goto cleanup; + } + + /* allocate ko object header */ + Header = (PKO_OBJECT_HEADER)AllocateItem(NonPagedPool, sizeof(KO_OBJECT_HEADER)); + if (!Header) + { + DPRINT1("failed to allocate KO_OBJECT_HEADER\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + + /* initialize create item */ + Header->CreateItem.Create = KopDispatchCreate; + RtlInitUnicodeString(&Header->CreateItem.ObjectClass, KOSTRING_CreateObject); + + + /* now allocate the object header */ + Status = KsAllocateObjectHeader(&Header->ObjectHeader, 1, &Header->CreateItem, Irp, &KoDispatchTable); + if (!NT_SUCCESS(Status)) + { + /* failed */ + goto cleanup; + } + + /* FIXME + * extract clsid and interface id from irp + * call the standard create handler + */ + + UNIMPLEMENTED + + IoStack->FileObject->FsContext2 = (PVOID)Header; + + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return Status; + +cleanup: + + if (Header && Header->ObjectHeader) + KsFreeObjectHeader(Header->ObjectHeader); + + if (Header) + FreeItem(Header); + + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; +} + + + +NTSTATUS +NTAPI +KopAddDevice( + IN PDRIVER_OBJECT DriverObject, + IN PDEVICE_OBJECT PhysicalDeviceObject) +{ + NTSTATUS Status = STATUS_DEVICE_REMOVED; + PDEVICE_OBJECT FunctionalDeviceObject= NULL; + PDEVICE_OBJECT NextDeviceObject; + PDEVICE_EXTENSION DeviceExtension; + PKSOBJECT_CREATE_ITEM CreateItem; + + /* create the device object */ + Status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_KS, FILE_DEVICE_SECURE_OPEN, FALSE, &FunctionalDeviceObject); + if (!NT_SUCCESS(Status)) + return Status; + + /* allocate the create item */ + CreateItem = AllocateItem(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM)); + + if (!CreateItem) + { + /* not enough memory */ + IoDeleteDevice(FunctionalDeviceObject); + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* initialize create item */ + CreateItem->Create = KopDispatchCreate; + RtlInitUnicodeString(&CreateItem->ObjectClass, KOSTRING_CreateObject); + + /* get device extension */ + DeviceExtension = (PDEVICE_EXTENSION)FunctionalDeviceObject->DeviceExtension; + + /* now allocate the device header */ + Status = KsAllocateDeviceHeader((KSDEVICE_HEADER*)&DeviceExtension->DeviceHeader, 1, CreateItem); + if (!NT_SUCCESS(Status)) + { + /* failed */ + IoDeleteDevice(FunctionalDeviceObject); + FreeItem(CreateItem); + return Status; + } + + /* now attach to device stack */ + NextDeviceObject = IoAttachDeviceToDeviceStack(FunctionalDeviceObject, PhysicalDeviceObject); + if (NextDeviceObject) + { + /* store pnp base object */ + KsSetDevicePnpAndBaseObject((KSDEVICE_HEADER)DeviceExtension->DeviceHeader, NextDeviceObject, FunctionalDeviceObject); + /* set device flags */ + FunctionalDeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE; + FunctionalDeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING; + } + else + { + /* failed */ + KsFreeDeviceHeader((KSDEVICE_HEADER)DeviceExtension->DeviceHeader); + FreeItem(CreateItem); + IoDeleteDevice(FunctionalDeviceObject); + Status = STATUS_DEVICE_REMOVED; + } + + /* return result */ + return Status; +} + + +/* + @implemented */ COMDDKAPI NTSTATUS @@ -1176,12 +1376,16 @@ KoDeviceInitialize( IN PDEVICE_OBJECT DeviceObject) { - UNIMPLEMENTED; - return STATUS_UNSUCCESSFUL; -} - -/* - @unimplemented + PDEVICE_EXTENSION DeviceExtension; + + /* get device extension */ + DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; + + return KsAddObjectCreateItemToDeviceHeader((KSDEVICE_HEADER)DeviceExtension->DeviceHeader, KopDispatchCreate, NULL, KOSTRING_CreateObject, NULL); +} + +/* + @implemented */ COMDDKAPI NTSTATUS @@ -1191,8 +1395,38 @@ IN PUNICODE_STRING RegistryPathName, IN KoCreateObjectHandler CreateObjectHandler) { - UNIMPLEMENTED; - return STATUS_UNSUCCESSFUL; + PKO_DRIVER_EXTENSION DriverObjectExtension; + NTSTATUS Status; + + /* allocate driver object extension */ + Status = IoAllocateDriverObjectExtension(DriverObject, (PVOID)KoDriverInitialize, sizeof(KO_DRIVER_EXTENSION), (PVOID*)&DriverObjectExtension); + + /* did it work */ + if (NT_SUCCESS(Status)) + { + /* store create handler */ + DriverObjectExtension->CreateObjectHandler = CreateObjectHandler; + + /* Setting our IRP handlers */ + DriverObject->MajorFunction[IRP_MJ_PNP] = KsDefaultDispatchPnp; + DriverObject->MajorFunction[IRP_MJ_POWER] = KsDefaultDispatchPower; + DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = KsDefaultForwardIrp; + + /* The driver unload routine */ + DriverObject->DriverUnload = KsNullDriverUnload; + + /* The driver-supplied AddDevice */ + DriverObject->DriverExtension->AddDevice = KopAddDevice; + + /* KS handles these */ + DPRINT1("Setting KS function handlers\n"); + KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CREATE); + KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CLOSE); + KsSetMajorFunctionHandler(DriverObject, IRP_MJ_DEVICE_CONTROL); + + } + + return Status; }
/*
Modified: trunk/reactos/drivers/ksfilter/ks/device.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/device.... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/device.c [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/device.c [iso-8859-1] Tue Jul 28 12:22:02 2009 @@ -688,7 +688,7 @@ }
/* - @unimplemented + @implemented */ KSDDKAPI NTSTATUS @@ -712,7 +712,7 @@ }
/* - @unimplemented + @implemented */ KSDDKAPI NTSTATUS @@ -737,7 +737,7 @@ }
/* - @unimplemented + @implemented */ KSDDKAPI VOID @@ -759,7 +759,7 @@ }
/* - @unimplemented + @implemented */ KSDDKAPI VOID
Modified: trunk/reactos/drivers/ksfilter/ks/driver.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/driver.... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/driver.c [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/driver.c [iso-8859-1] Tue Jul 28 12:22:02 2009 @@ -116,13 +116,16 @@ IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject) { - PKSDEVICE_DESCRIPTOR *DriverObjectExtension; - PKSDEVICE_DESCRIPTOR Descriptor = NULL; + PKS_DRIVER_EXTENSION DriverObjectExtension; + const KSDEVICE_DESCRIPTOR *Descriptor = NULL;
+ /* get stored driver object extension */ DriverObjectExtension = IoGetDriverObjectExtension(DriverObject, (PVOID)KsAddDevice); + if (DriverObjectExtension) { - Descriptor = *DriverObjectExtension; + /* get the stored descriptor see KsInitializeDriver */ + Descriptor = DriverObjectExtension->Descriptor; }
return KsCreateDevice(DriverObject, PhysicalDeviceObject, Descriptor, 0, NULL); @@ -140,17 +143,18 @@ IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL ) { - PKSDEVICE_DESCRIPTOR *DriverObjectExtension; + PKS_DRIVER_EXTENSION DriverObjectExtension; NTSTATUS Status;
if (Descriptor) { - Status = IoAllocateDriverObjectExtension(DriverObject, (PVOID)KsAddDevice, sizeof(PKSDEVICE_DESCRIPTOR), (PVOID*)&DriverObjectExtension); + Status = IoAllocateDriverObjectExtension(DriverObject, (PVOID)KsAddDevice, sizeof(KS_DRIVER_EXTENSION), (PVOID*)&DriverObjectExtension); if (NT_SUCCESS(Status)) { - *DriverObjectExtension = (KSDEVICE_DESCRIPTOR*)Descriptor; + DriverObjectExtension->Descriptor = Descriptor; } } + /* Setting our IRP handlers */ DriverObject->MajorFunction[IRP_MJ_CREATE] = IKsDevice_Create; DriverObject->MajorFunction[IRP_MJ_PNP] = IKsDevice_Pnp;
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] Tue Jul 28 12:22:02 2009 @@ -1,5 +1,22 @@ #ifndef KSTYPES_H__ #define KSTYPES_H__ + +typedef struct +{ + KoCreateObjectHandler CreateObjectHandler; +}KO_DRIVER_EXTENSION, *PKO_DRIVER_EXTENSION; + +typedef struct +{ + const KSDEVICE_DESCRIPTOR *Descriptor; +}KS_DRIVER_EXTENSION, *PKS_DRIVER_EXTENSION; + +typedef struct +{ + KSOBJECT_HEADER ObjectHeader; + KSOBJECT_CREATE_ITEM CreateItem; +}KO_OBJECT_HEADER, *PKO_OBJECT_HEADER; +
typedef struct {