Пример #1
0
/*++

Routine Description:

    This routine is a callback into the driver to retrieve the list of
    guids or data blocks that the driver wants to register with WMI. This
    routine may not pend or block. Driver should NOT call
    WmiCompleteRequest.

Arguments:

    DeviceObject is the device whose data block is being queried

    *RegFlags returns with a set of flags that describe the guids being
        registered for this device. If the device wants to enable and disable
        collection callbacks before receiving queries for the registered
        guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
        returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
        the instance name is determined from the PDO associated with the
        device object. Note that the PDO must have an associated devnode. If
        WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
        name for the device.

    InstanceName returns with the instance name for the guids if
        WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
        caller will call ExFreePool with the buffer returned.

    *RegistryPath returns with the registry path of the driver

    *MofResourceName returns with the name of the MOF resource attached to
        the binary file. If the driver does not have a mof resource attached
        then this can be returned as NULL.

    *Pdo returns with the device object for the PDO associated with this
        device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in 
        *RegFlags.

Return Value:

    status

--*/
NTSTATUS
NdasPortQueryWmiRegInfo(
    IN PDEVICE_OBJECT DeviceObject,
    OUT ULONG *RegFlags,
    OUT PUNICODE_STRING InstanceName,
    OUT PUNICODE_STRING *RegistryPath,
    OUT PUNICODE_STRING MofResourceName,
    OUT PDEVICE_OBJECT *Pdo)
{
	PNDASPORT_FDO_EXTENSION FdoExtension;
	PNDASPORT_DRIVER_EXTENSION driverExtension;

    PAGED_CODE();

	driverExtension = IoGetDriverObjectExtension(
		DeviceObject->DriverObject, 
		&NdasPortDriverExtensionTag);

	ASSERT(NULL != driverExtension);

    FdoExtension = (PNDASPORT_FDO_EXTENSION) DeviceObject->DeviceExtension;

    *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
    *RegistryPath = &driverExtension->RegistryPath;
    *Pdo = FdoExtension->LowerPdo;
    RtlInitUnicodeString(MofResourceName, MOFRESOURCENAME);

    return STATUS_SUCCESS;
}
Пример #2
0
NTSTATUS SarKsDevicePostStart(IN PKSDEVICE device)
{
    SarDriverExtension *extension =
        (SarDriverExtension *)IoGetDriverObjectExtension(
            device->FunctionalDeviceObject->DriverObject, DriverEntry);

    return IoSetDeviceInterfaceState(&extension->sarInterfaceName, TRUE);
}
Пример #3
0
VOID
NdasPortAddNetAddressHandler(
	__in PTA_ADDRESS Address,
	__in PUNICODE_STRING DeviceName,
	__in PTDI_PNP_CONTEXT Context)
{
	PNDASPORT_DRIVER_EXTENSION driverExtension;
	PTDI_ADDRESS_LPX localAddress;

	DebugPrint((1, "NdasPortAddNetAddressHandler: %wZ Type=%04X Length=%04X %02X:%02X:%02X:%02X:%02X:%02X\n",
		DeviceName,
		Address->AddressType,
		Address->AddressLength,
		Address->AddressLength > 0 ? Address->Address[0] : 0x00,
		Address->AddressLength > 1 ? Address->Address[1] : 0x00,
		Address->AddressLength > 2 ? Address->Address[2] : 0x00,
		Address->AddressLength > 3 ? Address->Address[3] : 0x00,
		Address->AddressLength > 4 ? Address->Address[4] : 0x00,
		Address->AddressLength > 5 ? Address->Address[5] : 0x00));

	NdasPortTrace(NDASPORT_GENERAL, TRACE_LEVEL_INFORMATION,
		"NdasPortAddNetAddressHandler: %wZ Type=%04X Length=%04X %02X:%02X:%02X:%02X:%02X:%02X\n",
		DeviceName,
		Address->AddressType,
		Address->AddressLength,
		Address->AddressLength > 0 ? Address->Address[0] : 0x00,
		Address->AddressLength > 1 ? Address->Address[1] : 0x00,
		Address->AddressLength > 2 ? Address->Address[2] : 0x00,
		Address->AddressLength > 3 ? Address->Address[3] : 0x00,
		Address->AddressLength > 4 ? Address->Address[4] : 0x00,
		Address->AddressLength > 5 ? Address->Address[5] : 0x00);


	if (!NdasPortIsLpxAddress(Address, DeviceName))
	{
		return;
	}

	driverExtension = (PNDASPORT_DRIVER_EXTENSION) IoGetDriverObjectExtension(
		NdasPortDriverObject,
		&NdasPortDriverExtensionTag);

	ASSERT(NULL != driverExtension);

	localAddress = (PTDI_ADDRESS_LPX) &Address->Address[0];
	NdasPortAddToLpxLocalAddressList(driverExtension, localAddress);

	InterlockedIncrement(&driverExtension->LpxLocalAddressListUpdateCounter);

	//
	// LPX Address is found!
	//
}
Пример #4
0
static NTSTATUS
PciIdeXFdoStartDevice(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp)
{
	PPCIIDEX_DRIVER_EXTENSION DriverExtension;
	PFDO_DEVICE_EXTENSION DeviceExtension;
	PCM_RESOURCE_LIST ResourceList;
	NTSTATUS Status;

	DPRINT("PciIdeXStartDevice(%p %p)\n", DeviceObject, Irp);

	DriverExtension = IoGetDriverObjectExtension(DeviceObject->DriverObject, DeviceObject->DriverObject);
	ASSERT(DriverExtension);
	DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
	ASSERT(DeviceExtension);
	ASSERT(DeviceExtension->Common.IsFDO);

	DeviceExtension->Properties.Size = sizeof(IDE_CONTROLLER_PROPERTIES);
	DeviceExtension->Properties.ExtensionSize = DriverExtension->MiniControllerExtensionSize;
	Status = DriverExtension->HwGetControllerProperties(
		DeviceExtension->MiniControllerExtension,
		&DeviceExtension->Properties);
	if (!NT_SUCCESS(Status))
		return Status;

	DriverExtension->HwUdmaModesSupported = DeviceExtension->Properties.PciIdeUdmaModesSupported;
	if (!DriverExtension->HwUdmaModesSupported)
		/* This method is optional, so provide our own one */
		DriverExtension->HwUdmaModesSupported = PciIdeXUdmaModesSupported;

	/* Get bus master port base, if any */
	ResourceList = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResources;
	if (ResourceList
		&& ResourceList->Count == 1
		&& ResourceList->List[0].PartialResourceList.Count == 1
		&& ResourceList->List[0].PartialResourceList.Version == 1
		&& ResourceList->List[0].PartialResourceList.Revision == 1
		&& ResourceList->List[0].PartialResourceList.PartialDescriptors[0].Type == CmResourceTypePort
		&& ResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Length == 16)
	{
		DeviceExtension->BusMasterPortBase = ResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start;
	}
	return STATUS_SUCCESS;
}
Пример #5
0
static
VOID
NTAPI
PortUnload(
    _In_ PDRIVER_OBJECT DriverObject)
{
    PDRIVER_OBJECT_EXTENSION DriverExtension;

    DPRINT1("PortUnload(%p)\n",
            DriverObject);

    DriverExtension = IoGetDriverObjectExtension(DriverObject,
                                                 (PVOID)DriverEntry);
    if (DriverExtension != NULL)
    {
        PortDeleteDriverInitData(DriverExtension);
    }
}
Пример #6
0
static VOID
i8042RemoveDevice(
    IN PDEVICE_OBJECT DeviceObject)
{
    PI8042_DRIVER_EXTENSION DriverExtension;
    KIRQL OldIrql;
    PFDO_DEVICE_EXTENSION DeviceExtension;

    DriverExtension = (PI8042_DRIVER_EXTENSION)IoGetDriverObjectExtension(DeviceObject->DriverObject, DeviceObject->DriverObject);
    DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    KeAcquireSpinLock(&DriverExtension->DeviceListLock, &OldIrql);
    RemoveEntryList(&DeviceExtension->ListEntry);
    KeReleaseSpinLock(&DriverExtension->DeviceListLock, OldIrql);

    IoDetachDevice(DeviceExtension->LowerDevice);

    IoDeleteDevice(DeviceObject);
}
Пример #7
0
NTSTATUS SarKsDeviceAdd(IN PKSDEVICE device)
{
    NTSTATUS status;
    UNICODE_STRING referenceString;
    SarDriverExtension *extension =
        (SarDriverExtension *)IoGetDriverObjectExtension(
            device->FunctionalDeviceObject->DriverObject, DriverEntry);

    RtlUnicodeStringInit(&referenceString, SAR_CONTROL_REFERENCE_STRING + 1);
    status = IoRegisterDeviceInterface(device->PhysicalDeviceObject,
        &GUID_DEVINTERFACE_SYNCHRONOUSAUDIOROUTER, &referenceString,
        &extension->sarInterfaceName);

    if (!NT_SUCCESS(status)) {
        return status;
    }

    SAR_LOG("KSDevice was created for %p, dev interface: %wZ",
        device, &extension->sarInterfaceName);
    return status;
}
Пример #8
0
NTSTATUS
NTAPI
IntVideoPortAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject)
{
    PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
    PDEVICE_OBJECT DeviceObject;
    NTSTATUS Status;

    /* Get the initialization data we saved in VideoPortInitialize. */
    DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);

    /* Create adapter device object. */
    Status = IntVideoPortCreateAdapterDeviceObject(DriverObject,
                                                   DriverExtension,
                                                   PhysicalDeviceObject,
                                                   &DeviceObject);
    if (NT_SUCCESS(Status))
        VideoPortDeviceNumber++;

    return Status;
}
Пример #9
0
NTSTATUS NTAPI
PciIdeXAddDevice(
	IN PDRIVER_OBJECT DriverObject,
	IN PDEVICE_OBJECT Pdo)
{
	PPCIIDEX_DRIVER_EXTENSION DriverExtension;
	PFDO_DEVICE_EXTENSION DeviceExtension;
	PDEVICE_OBJECT Fdo;
	ULONG BytesRead;
	PCI_COMMON_CONFIG PciConfig;
	NTSTATUS Status;

	DPRINT("PciIdeXAddDevice(%p %p)\n", DriverObject, Pdo);

	DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
	ASSERT(DriverExtension);

	Status = IoCreateDevice(
		DriverObject,
		sizeof(FDO_DEVICE_EXTENSION) + DriverExtension->MiniControllerExtensionSize,
		NULL,
		FILE_DEVICE_BUS_EXTENDER,
		FILE_DEVICE_SECURE_OPEN,
		TRUE,
		&Fdo);
	if (!NT_SUCCESS(Status))
	{
		DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
		return Status;
	}

	DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
	RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));

	DeviceExtension->Common.IsFDO = TRUE;

	Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
	if (!NT_SUCCESS(Status))
	{
		DPRINT("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
		return Status;
	}

	Status = GetBusInterface(DeviceExtension);
	if (!NT_SUCCESS(Status))
	{
		DPRINT("GetBusInterface() failed with status 0x%08lx\n", Status);
		IoDetachDevice(DeviceExtension->LowerDevice);
		return Status;
	}

	BytesRead = (*DeviceExtension->BusInterface->GetBusData)(
		DeviceExtension->BusInterface->Context,
		PCI_WHICHSPACE_CONFIG,
		&PciConfig,
		0,
		PCI_COMMON_HDR_LENGTH);
	if (BytesRead != PCI_COMMON_HDR_LENGTH)
	{
		DPRINT("BusInterface->GetBusData() failed()\n");
		ReleaseBusInterface(DeviceExtension);
		IoDetachDevice(DeviceExtension->LowerDevice);
		return STATUS_IO_DEVICE_ERROR;
	}

	DeviceExtension->VendorId = PciConfig.VendorID;
	DeviceExtension->DeviceId = PciConfig.DeviceID;

	Fdo->Flags &= ~DO_DEVICE_INITIALIZING;

	return STATUS_SUCCESS;
}
Пример #10
0
static
NTSTATUS
NTAPI
PortAddDevice(
    _In_ PDRIVER_OBJECT DriverObject,
    _In_ PDEVICE_OBJECT PhysicalDeviceObject)
{
    PDRIVER_OBJECT_EXTENSION DriverObjectExtension;
    PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
    WCHAR NameBuffer[80];
    UNICODE_STRING DeviceName;
    PDEVICE_OBJECT Fdo = NULL;
    KLOCK_QUEUE_HANDLE LockHandle;
    NTSTATUS Status;

    DPRINT1("PortAddDevice(%p %p)\n",
            DriverObject, PhysicalDeviceObject);

    ASSERT(DriverObject);
    ASSERT(PhysicalDeviceObject);

    swprintf(NameBuffer,
             L"\\Device\\RaidPort%lu",
             PortNumber);
    RtlInitUnicodeString(&DeviceName, NameBuffer);
    PortNumber++;

    DPRINT1("Creating device: %wZ\n", &DeviceName);

    /* Create the port device */
    Status = IoCreateDevice(DriverObject,
                            sizeof(FDO_DEVICE_EXTENSION),
                            &DeviceName,
                            FILE_DEVICE_CONTROLLER,
                            FILE_DEVICE_SECURE_OPEN,
                            FALSE,
                            &Fdo);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
        return Status;
    }

    DPRINT1("Created device: %wZ (%p)\n", &DeviceName, Fdo);

    /* Initialize the device */
    Fdo->Flags |= DO_DIRECT_IO;
    Fdo->Flags |= DO_POWER_PAGABLE;

    /* Initialize the device extension */
    DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
    RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));

    DeviceExtension->ExtensionType = FdoExtension;

    DeviceExtension->Device = Fdo;
    DeviceExtension->PhysicalDevice = PhysicalDeviceObject;

    DeviceExtension->PnpState = dsStopped;

    /* Attach the FDO to the device stack */
    Status = IoAttachDeviceToDeviceStackSafe(Fdo,
                                             PhysicalDeviceObject,
                                             &DeviceExtension->LowerDevice);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("IoAttachDeviceToDeviceStackSafe() failed (Status 0x%08lx)\n", Status);
        IoDeleteDevice(Fdo);
        return Status;
    }

    /* Insert the FDO to the drivers FDO list */
    DriverObjectExtension = IoGetDriverObjectExtension(DriverObject,
                                                       (PVOID)DriverEntry);
    ASSERT(DriverObjectExtension->ExtensionType == DriverExtension);

    DeviceExtension->DriverExtension = DriverObjectExtension;

    KeAcquireInStackQueuedSpinLock(&DriverObjectExtension->AdapterListLock,
                                   &LockHandle);

    InsertHeadList(&DriverObjectExtension->AdapterListHead,
                   &DeviceExtension->AdapterListEntry);
    DriverObjectExtension->AdapterCount++;

    KeReleaseInStackQueuedSpinLock(&LockHandle);

    /* The device has been initialized */
    Fdo->Flags &= ~DO_DEVICE_INITIALIZING;

    DPRINT1("PortAddDevice() done (Status 0x%08lx)\n", Status);

    return Status;
}
Пример #11
0
NTSTATUS NTAPI
SermouseAddDevice(
	IN PDRIVER_OBJECT DriverObject,
	IN PDEVICE_OBJECT Pdo)
{
	PSERMOUSE_DRIVER_EXTENSION DriverExtension;
	PDEVICE_OBJECT Fdo;
	PSERMOUSE_DEVICE_EXTENSION DeviceExtension = NULL;
	NTSTATUS Status;

	TRACE_(SERMOUSE, "SermouseAddDevice called. Pdo = 0x%p\n", Pdo);

	if (Pdo == NULL)
		return STATUS_SUCCESS;

	/* Create new device object */
	DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
	Status = IoCreateDevice(
		DriverObject,
		sizeof(SERMOUSE_DEVICE_EXTENSION),
		NULL,
		FILE_DEVICE_SERIAL_MOUSE_PORT,
		FILE_DEVICE_SECURE_OPEN,
		TRUE,
		&Fdo);
	if (!NT_SUCCESS(Status))
	{
		WARN_(SERMOUSE, "IoCreateDevice() failed with status 0x%08lx\n", Status);
		goto cleanup;
	}

	DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)Fdo->DeviceExtension;
	RtlZeroMemory(DeviceExtension, sizeof(SERMOUSE_DEVICE_EXTENSION));
	DeviceExtension->MouseType = mtNone;
	DeviceExtension->PnpState = dsStopped;
	DeviceExtension->DriverExtension = DriverExtension;
	KeInitializeEvent(&DeviceExtension->StopWorkerThreadEvent, NotificationEvent, FALSE);
	Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
	if (!NT_SUCCESS(Status))
	{
		WARN_(SERMOUSE, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
		goto cleanup;
	}
	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;
	Fdo->Flags &= ~DO_DEVICE_INITIALIZING;

	return STATUS_SUCCESS;

cleanup:
	if (DeviceExtension)
	{
		if (DeviceExtension->LowerDevice)
			IoDetachDevice(DeviceExtension->LowerDevice);
	}
	if (Fdo)
	{
		IoDeleteDevice(Fdo);
	}
	return Status;
}
Пример #12
0
NTSTATUS NTAPI
i8042AddDevice(
	IN PDRIVER_OBJECT DriverObject,
	IN PDEVICE_OBJECT Pdo)
{
	PI8042_DRIVER_EXTENSION DriverExtension;
	PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
	PDEVICE_OBJECT Fdo = NULL;
	ULONG DeviceExtensionSize;
	NTSTATUS Status;

	TRACE_(I8042PRT, "i8042AddDevice(%p %p)\n", DriverObject, Pdo);

	DriverExtension = (PI8042_DRIVER_EXTENSION)IoGetDriverObjectExtension(DriverObject, DriverObject);

	if (Pdo == NULL)
	{
		/* We're getting a NULL Pdo at the first call as
		 * we are a legacy driver. Ignore it */
		return STATUS_SUCCESS;
	}

	/* Create new device object. As we don't know if the device would be a keyboard
	 * or a mouse, we have to allocate the biggest device extension. */
	DeviceExtensionSize = MAX(sizeof(I8042_KEYBOARD_EXTENSION), sizeof(I8042_MOUSE_EXTENSION));
	Status = IoCreateDevice(
		DriverObject,
		DeviceExtensionSize,
		NULL,
		Pdo->DeviceType,
		FILE_DEVICE_SECURE_OPEN,
		TRUE,
		&Fdo);
	if (!NT_SUCCESS(Status))
	{
		WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status);
		goto cleanup;
	}

	DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
	RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
	DeviceExtension->Type = Unknown;
	DeviceExtension->Fdo = Fdo;
	DeviceExtension->Pdo = Pdo;
	DeviceExtension->PortDeviceExtension = &DriverExtension->Port;
	Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
	if (!NT_SUCCESS(Status))
	{
		WARN_(I8042PRT, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
		goto cleanup;
	}

	ExInterlockedInsertTailList(
		&DriverExtension->DeviceListHead,
		&DeviceExtension->ListEntry,
		&DriverExtension->DeviceListLock);

	Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
	return STATUS_SUCCESS;

cleanup:
	if (DeviceExtension && DeviceExtension->LowerDevice)
		IoDetachDevice(DeviceExtension->LowerDevice);
	if (Fdo)
		IoDeleteDevice(Fdo);
	return Status;
}
Пример #13
0
NTSTATUS NTAPI
GreenDispatch(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp)
{
	ULONG MajorFunction;
	GREEN_DEVICE_TYPE DeviceType;
	ULONG_PTR Information;
	NTSTATUS Status;

	MajorFunction = IoGetCurrentIrpStackLocation(Irp)->MajorFunction;
	DeviceType = ((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Type;

	Information = Irp->IoStatus.Information;
	Status = Irp->IoStatus.Status;

	DPRINT("Dispatching major function 0x%lx, DeviceType %u\n",
		MajorFunction, DeviceType);

	if (DeviceType == PassThroughFDO)
	{
		IoSkipCurrentIrpStackLocation(Irp);
		return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
	}
	else if (MajorFunction == IRP_MJ_CREATE && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
		return GreenCreate(DeviceObject, Irp);
	else if (MajorFunction == IRP_MJ_CLOSE && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
		return GreenClose(DeviceObject, Irp);
	else if ((MajorFunction == IRP_MJ_CREATE || MajorFunction == IRP_MJ_CLOSE || MajorFunction == IRP_MJ_CLEANUP)
		&& (DeviceType == KeyboardFDO || DeviceType == ScreenFDO))
	{
		IoSkipCurrentIrpStackLocation(Irp);
		return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
	}
	else if (MajorFunction == IRP_MJ_INTERNAL_DEVICE_CONTROL && DeviceType == GreenFDO)
	{
		return KeyboardInternalDeviceControl(
			((PGREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->KeyboardFdo,
			Irp);
	}
	else if (MajorFunction == IRP_MJ_INTERNAL_DEVICE_CONTROL && DeviceType == KeyboardFDO)
		return KeyboardInternalDeviceControl(DeviceObject, Irp);
	else if (MajorFunction == IRP_MJ_DEVICE_CONTROL && DeviceType == GreenFDO)
	{
		return ScreenDeviceControl(
			((PGREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ScreenFdo,
			Irp);
	}
	else if (MajorFunction == IRP_MJ_DEVICE_CONTROL && DeviceType == ScreenFDO)
		return ScreenDeviceControl(DeviceObject, Irp);
	else if (MajorFunction == IRP_MJ_WRITE && DeviceType == ScreenFDO)
		return ScreenWrite(DeviceObject, Irp);
	else if (MajorFunction == IRP_MJ_PNP && (DeviceType == KeyboardFDO || DeviceType == ScreenFDO))
	{
		IoSkipCurrentIrpStackLocation(Irp);
		return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
	}
	else if (MajorFunction == IRP_MJ_PNP && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
		return GreenPnp(DeviceObject, Irp);
	else if (MajorFunction == IRP_MJ_POWER && DeviceType == GreenFDO)
		return GreenPower(DeviceObject, Irp);
	else
	{
		DPRINT1("Unknown combination: MajorFunction 0x%lx, DeviceType %d\n",
			MajorFunction, DeviceType);
		switch (DeviceType)
		{
			case KeyboardFDO:
			case ScreenFDO:
			{
				IoSkipCurrentIrpStackLocation(Irp);
				return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
			}
			case GreenFDO:
			{
				PDRIVER_OBJECT DriverObject;
				PGREEN_DRIVER_EXTENSION DriverExtension;
				DriverObject = DeviceObject->DriverObject;
				DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
				IoSkipCurrentIrpStackLocation(Irp);
				return IoCallDriver(DriverExtension->LowerDevice, Irp);
			}
			default:
				ASSERT(FALSE);
		}
	}

	Irp->IoStatus.Information = Information;
	Irp->IoStatus.Status = Status;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	return Status;
}
Пример #14
0
NTSTATUS
NTAPI
StreamClassAddDevice(
    IN PDRIVER_OBJECT  DriverObject,
    IN PDEVICE_OBJECT  PhysicalDeviceObject)
{
    PSTREAM_CLASS_DRIVER_EXTENSION DriverObjectExtension;
    PDEVICE_OBJECT DeviceObject, LowerDeviceObject;
    PSTREAM_DEVICE_EXTENSION DeviceExtension;
    PKSOBJECT_CREATE_ITEM ItemList;
    NTSTATUS Status;

    /* Fetch driver object extension */
    DriverObjectExtension = IoGetDriverObjectExtension(DriverObject, (PVOID)StreamClassAddDevice);
    if (!DriverObjectExtension)
    {
        /* Failed to get driver extension */
        return STATUS_DEVICE_DOES_NOT_EXIST;
    }
    /* Allocate Create Item */
    ItemList = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
    if (!ItemList)
    {
        /* Failed to allocated Create Item */
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* Create the FDO */
    Status = IoCreateDevice(DriverObject, DriverObjectExtension->Data.DeviceExtensionSize + sizeof(STREAM_DEVICE_EXTENSION), NULL, FILE_DEVICE_KS, FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN, 0, &DeviceObject);
    if (!NT_SUCCESS(Status))
    {
        /* Failed to create the FDO */
        ExFreePool(ItemList);
        return Status;
    }

    /* Attach to device stack */
    LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
    if (!LowerDeviceObject)
    {
        /* Failed to attach */
        IoDeleteDevice(DeviceObject);
        return STATUS_UNSUCCESSFUL;
    }

    /* Zero Create item */
    RtlZeroMemory(ItemList, sizeof(KSOBJECT_CREATE_ITEM));
    /* Setup object class */
    RtlInitUnicodeString(&ItemList->ObjectClass, L"GLOBAL");
    /* Setup CreateDispatch routine */
    ItemList->Create = StreamClassCreateFilter;

    /* Get device extension */
    DeviceExtension = (PSTREAM_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
    /* Zero device extension */
    RtlZeroMemory(DeviceExtension, sizeof(STREAM_DEVICE_EXTENSION));
    /* Initialize Ks streaming */
    Status = KsAllocateDeviceHeader(&DeviceExtension->Header, 1, ItemList);
    if (!NT_SUCCESS(Status))
    {
        /* Cleanup resources */
        IoDetachDevice(LowerDeviceObject);
        IoDeleteDevice(DeviceObject);
        ExFreePool(ItemList);
        return Status;
    }

    /* Store lower device object */
    DeviceExtension->LowerDeviceObject = LowerDeviceObject;

    /* Store physical device object */
    DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
    /* Store driver object extension */
    DeviceExtension->DriverExtension = DriverObjectExtension;
    /* Initialize memory list */
    InitializeListHead(&DeviceExtension->MemoryResourceList);
    /* Setup device extension */
    DeviceExtension->DeviceExtension = (PVOID) (DeviceExtension + 1);
    /* Init interrupt dpc */
    KeInitializeDpc(&DeviceExtension->InterruptDpc, StreamClassInterruptDpc, (PVOID)DeviceExtension);

    /* Set device transfer method */
    DeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
    /* Clear init flag */
    DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;

    return Status;
}
Пример #15
0
NTSTATUS NTAPI
IntVideoPortFilterResourceRequirements(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp)
{
    PDRIVER_OBJECT DriverObject;
    PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
    PVIDEO_ACCESS_RANGE AccessRanges;
    ULONG AccessRangeCount, ListSize, i;
    PIO_RESOURCE_REQUIREMENTS_LIST ResList, OldResList = (PVOID)Irp->IoStatus.Information;
    PIO_RESOURCE_DESCRIPTOR CurrentDescriptor;
    NTSTATUS Status;

    DriverObject = DeviceObject->DriverObject;
    DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
    DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    Status = IntVideoPortGetLegacyResources(DriverExtension, DeviceExtension, &AccessRanges, &AccessRangeCount);
    if (!NT_SUCCESS(Status))
        return Status;
    if (!AccessRangeCount)
    {
        /* No legacy resources to report */
        return Irp->IoStatus.Information;
    }

    /* OK, we've got the access ranges now. Let's set up the resource requirements list */

    if (OldResList)
    {
        /* Already one there so let's add to it */
        ListSize = OldResList->ListSize + sizeof(IO_RESOURCE_DESCRIPTOR) * AccessRangeCount;
        ResList = ExAllocatePool(NonPagedPool,
                                 ListSize);
        if (!ResList) return STATUS_NO_MEMORY;
        
        RtlCopyMemory(ResList, OldResList, OldResList->ListSize);
        
        ASSERT(ResList->AlternativeLists == 1);
        
        ResList->ListSize = ListSize;
        ResList->List[0].Count += AccessRangeCount;
        
        CurrentDescriptor = (PIO_RESOURCE_DESCRIPTOR)((PUCHAR)ResList + OldResList->ListSize);
        
        ExFreePool(OldResList);
        Irp->IoStatus.Information = 0;
    }
    else
    {
        /* We need to make a new one */
        ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (AccessRangeCount - 1);
        ResList = ExAllocatePool(NonPagedPool,
                                 ListSize);
        if (!ResList) return STATUS_NO_MEMORY;
        
        RtlZeroMemory(ResList, ListSize);
        
        /* We need to initialize some fields */
        ResList->ListSize = ListSize;
        ResList->InterfaceType = DeviceExtension->AdapterInterfaceType;
        ResList->BusNumber = DeviceExtension->SystemIoBusNumber;
        ResList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
        ResList->AlternativeLists = 1;
        ResList->List[0].Version = 1;
        ResList->List[0].Revision = 1;
        ResList->List[0].Count = AccessRangeCount;
        
        CurrentDescriptor = ResList->List[0].Descriptors;
    }

    for (i = 0; i < AccessRangeCount; i++)
    {
        /* This is a required resource */
        CurrentDescriptor->Option = 0;
        
        if (AccessRanges[i].RangeInIoSpace)
            CurrentDescriptor->Type = CmResourceTypePort;
        else
            CurrentDescriptor->Type = CmResourceTypeMemory;
        
        CurrentDescriptor->ShareDisposition =
        (AccessRanges[i].RangeShareable ? CmResourceShareShared : CmResourceShareDeviceExclusive);
        
        CurrentDescriptor->Flags = 0;
        
        if (CurrentDescriptor->Type == CmResourceTypePort)
        {
            CurrentDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
            CurrentDescriptor->u.Port.MinimumAddress =
            CurrentDescriptor->u.Port.MaximumAddress = AccessRanges[i].RangeStart;
            CurrentDescriptor->u.Port.Alignment = 1;
            if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
                CurrentDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
            if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
                CurrentDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
        }
        else
        {
            CurrentDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
            CurrentDescriptor->u.Memory.MinimumAddress =
            CurrentDescriptor->u.Memory.MaximumAddress = AccessRanges[i].RangeStart;
            CurrentDescriptor->u.Memory.Alignment = 1;
            CurrentDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
        }
        
        CurrentDescriptor++;
    }

    Irp->IoStatus.Information = (ULONG_PTR)ResList;

    return STATUS_SUCCESS;
}
Пример #16
0
VOID
NdasPortBindingChangeHandler(
	__in TDI_PNP_OPCODE PnPOpcode,
	__in PUNICODE_STRING TransportName,
	__in PWSTR BindingList)
{
	PNDASPORT_DRIVER_EXTENSION driverExtension;

	PAGED_CODE();

	driverExtension = (PNDASPORT_DRIVER_EXTENSION) IoGetDriverObjectExtension(
		NdasPortDriverObject,
		&NdasPortDriverExtensionTag);

	ASSERT(NULL != driverExtension);

	DebugPrint((1, 
		"NdasPortBindingChangeHandler: PnPOpcode=%s(%x), TransportName=%wZ,\n", 
		DbgTdiPnpOpCodeString(PnPOpcode),
		PnPOpcode, 
		TransportName));

	NdasPortTrace(NDASPORT_GENERAL, TRACE_LEVEL_INFORMATION,
		"NdasPortBindingChangeHandler: PnpOpCode=%s(%x), TransportName=%wZ,\n",
		DbgTdiPnpOpCodeString(PnPOpcode),
		PnPOpcode,
		TransportName);

	switch (PnPOpcode) 
	{
	case TDI_PNP_OP_ADD:
	case TDI_PNP_OP_DEL:
	case TDI_PNP_OP_PROVIDERREADY:
		break;

	case TDI_PNP_OP_NETREADY:
		{
			BOOLEAN previouslyReady;

			previouslyReady = driverExtension->IsNetworkReady;
			driverExtension->IsNetworkReady = TRUE;

			//
			// State change from network "not ready" to
			// network "ready" state. Will initialize
			// device detection
			//
			if (previouslyReady == FALSE) 
			{
				KIRQL oldIrql;
				PLIST_ENTRY entry;
				DebugPrint((3, "Network is now ready!\n"));

				//
				// Request device enumeration request from PnP.
				//

				KeAcquireSpinLock(&driverExtension->FdoListSpinLock, &oldIrql);
				for (entry = driverExtension->FdoList.Flink;
					entry != &driverExtension->FdoList;
					entry = entry->Flink) 
				{
					PNDASPORT_FDO_EXTENSION fdoExtension;
					fdoExtension = CONTAINING_RECORD(entry, NDASPORT_FDO_EXTENSION, Link);
					IoInvalidateDeviceRelations(
						fdoExtension->LowerPdo,
						BusRelations);
				}
				KeReleaseSpinLock(&driverExtension->FdoListSpinLock, oldIrql);
			}

			break;
		}
	default: 
		{
			break;
		}
	}

	return;
}
Пример #17
0
NTSTATUS
SpWmiIrpRegisterRequest(
    IN     PDEVICE_OBJECT  DeviceObject,
    IN OUT PWMI_PARAMETERS WmiParameters
    )

/*++

Routine Description:

   Process an IRP_MJ_SYSTEM_CONTROL registration request.

Arguments:

   DeviceObject  - Pointer to the functional or physical device object.

   WmiParameters - Pointer to the WMI request parameters.

Return Value:

   NTSTATUS result code to complete the WMI IRP with.

Notes:

   If this WMI request is completed with STATUS_SUCCESS, the WmiParameters
   BufferSize field will reflect the actual size of the WMI return buffer.

--*/

{
    PCOMMON_EXTENSION   commonExtension = DeviceObject->DeviceExtension;
    PSCSIPORT_DRIVER_EXTENSION driverExtension = NULL;

    ULONG                      countedRegistryPathSize = 0;
    ULONG                      retSz;
    PWMIREGINFO                spWmiRegInfoBuf;
    ULONG                      spWmiRegInfoBufSize;
    NTSTATUS                   status = STATUS_SUCCESS;
    BOOLEAN                    wmiUpdateRequest;
    ULONG                      i;
    PDEVICE_OBJECT             pDO;

    WMI_PARAMETERS  paranoidBackup = *WmiParameters;

    PAGED_CODE();

    //
    // Validate our assumptions for this function's code.
    //
    ASSERT(WmiParameters->BufferSize >= sizeof(ULONG));

    //
    // Validate the registration mode.
    //
    switch ( (ULONG)(ULONG_PTR)WmiParameters->DataPath ) {
        case WMIUPDATE:
            //
            // No SCSIPORT registration information will be piggybacked
            // on behalf of the miniport for a WMIUPDATE request.
            //
            wmiUpdateRequest = TRUE;
            break;

        case WMIREGISTER:
            wmiUpdateRequest = FALSE;
            break;

        default:
            //
            // Unsupported registration mode.
            //
            ASSERT(FALSE);
            return STATUS_INVALID_PARAMETER;
    }

    //
    // Obtain the driver extension for this miniport (FDO/PDO).
    //
    driverExtension = IoGetDriverObjectExtension(DeviceObject->DriverObject,
                                                 ScsiPortInitialize);

    ASSERT(driverExtension != NULL);

    //
    // Obtain a pointer to the SCSIPORT WMI registration information
    // buffer, which is registered on behalf of the miniport driver.
    //
    SpWmiGetSpRegInfo(DeviceObject, &spWmiRegInfoBuf,
                      &spWmiRegInfoBufSize);

    //
    // Pass the WMI registration request to the miniport.  This is not
    // necessary if we know the miniport driver does not support WMI.
    //
    if (commonExtension->WmiMiniPortSupport) {
        //
        // Note that we shrink the buffer size by the size necessary
        // to hold SCSIPORT's own registration information, which we
        // register on behalf of the miniport.   This information is
        // piggybacked into the WMI return buffer after the call  to
        // the miniport.  We ensure that the BufferSize passed to the
        // miniport is no smaller than "sizeof(ULONG)" so that it can
        // tell us the required buffer size should the buffer be too
        // small [by filling in this ULONG].
        //
        // Note that we must also make enough room for a copy of the
        // miniport registry path in the buffer, since the WMIREGINFO
        // structures from the miniport DO NOT set their registry
        // path fields.
        //
        ASSERT(WmiParameters->BufferSize >= sizeof(ULONG));

        //
        // Calculate size of required miniport registry path.
        //
        countedRegistryPathSize = driverExtension->RegistryPath.Length
                                  + sizeof(USHORT);

        //
        // Shrink buffer by the appropriate size. Note that the extra
        // 7 bytes (possibly extraneous) is subtracted to ensure that
        // the piggybacked data added later on is 8-byte aligned (if
        // any).
        //
        if (spWmiRegInfoBufSize && !wmiUpdateRequest) {
            WmiParameters->BufferSize =
                (WmiParameters->BufferSize > spWmiRegInfoBufSize + countedRegistryPathSize + 7 + sizeof(ULONG)) ?
                WmiParameters->BufferSize - spWmiRegInfoBufSize - countedRegistryPathSize - 7 :
            sizeof(ULONG);
        } else { // no data to piggyback
            WmiParameters->BufferSize =
                (WmiParameters->BufferSize > countedRegistryPathSize + sizeof(ULONG)) ?
                WmiParameters->BufferSize - countedRegistryPathSize :
            sizeof(ULONG);
        }

        //
        // Call the minidriver.
        //
        status = SpWmiPassToMiniPort(DeviceObject,
                                     IRP_MN_REGINFO,
                                     WmiParameters);

        ASSERT(WmiParameters->ProviderId == paranoidBackup.ProviderId);
        ASSERT(WmiParameters->DataPath == paranoidBackup.DataPath);
        ASSERT(WmiParameters->Buffer == paranoidBackup.Buffer);
        ASSERT(WmiParameters->BufferSize <= paranoidBackup.BufferSize);

        //
        // Assign WmiParameters->BufferSize to retSz temporarily.
        //
        // Note that on return from the above call, the wmiParameters'
        // BufferSize field has been _modified_ to reflect the current
        // size of the return buffer.
        //
        retSz = WmiParameters->BufferSize;

    } else if (WmiParameters->BufferSize < spWmiRegInfoBufSize &&
               !wmiUpdateRequest) {

        //
        // Insufficient space to hold SCSIPORT WMI registration information
        // alone.  Inform WMI appropriately of the required buffer size.
        //
        *((ULONG*)WmiParameters->Buffer) = spWmiRegInfoBufSize;
        WmiParameters->BufferSize = sizeof(ULONG);
        return STATUS_SUCCESS;

    } else { // no miniport support for WMI, sufficient space for scsiport info

        //
        // Fake having the miniport return zero WMIREGINFO structures.
        //
        retSz = 0;
    }

    //
    // Piggyback SCSIPORT's registration information into the WMI
    // registration buffer.
    //
    if (status == STATUS_BUFFER_TOO_SMALL || retSz == sizeof(ULONG)) {
        //
        // Miniport could not fit registration information into the
        // pre-shrunk buffer.
        //
        // Buffer currently contains a ULONG specifying required buffer
        // size of miniport registration info, but does not include the
        // SCSIPORT registration info's size.  Add it in.
        //
        if (spWmiRegInfoBufSize && !wmiUpdateRequest) {

            *((ULONG*)WmiParameters->Buffer) += spWmiRegInfoBufSize;

            //
            // Add an extra 7 bytes (possibly extraneous) which is used to
            // ensure that the piggybacked data structure 8-byte aligned.
            //
            *((ULONG*)WmiParameters->Buffer) += 7;
        }

        //
        // Add in size of the miniport registry path.
        //
        *((ULONG*)WmiParameters->Buffer) += countedRegistryPathSize;

        //
        // Return STATUS_SUCCESS, even though this is a BUFFER TOO
        // SMALL failure, while ensuring retSz = sizeof(ULONG), as
        // the WMI protocol calls us to do.
        //
        retSz  = sizeof(ULONG);
        status = STATUS_SUCCESS;

    } else if ( NT_SUCCESS(status) ) {
        //
        // Zero or more WMIREGINFOs exist in buffer from miniport.
        //

        //
        // Piggyback the miniport registry path transparently, if at least one
        // WMIREGINFO was returned by the minport.
        //
        if (retSz) {

            ULONG offsetToRegPath  = retSz;
            PWMIREGINFO wmiRegInfo = WmiParameters->Buffer;

            //
            // Build a counted wide-character string, containing the
            // registry path, into the WMI buffer.
            //
            *( (PUSHORT)( (PUCHAR)WmiParameters->Buffer + retSz ) ) =
                driverExtension->RegistryPath.Length,
            RtlCopyMemory( (PUCHAR)WmiParameters->Buffer + retSz + sizeof(USHORT),
                           driverExtension->RegistryPath.Buffer,
                           driverExtension->RegistryPath.Length);

            //
            // Traverse the WMIREGINFO structures returned by the mini-
            // driver and set the missing RegistryPath fields to point
            // to our registry path location. We also jam in the PDO for
            // the device stack so that the device instance name is used for
            // the wmi instance names.
            //
            pDO = commonExtension->IsPdo ? DeviceObject :
                            ((PADAPTER_EXTENSION)commonExtension)->LowerPdo;

            while (1) {
                wmiRegInfo->RegistryPath = offsetToRegPath;

                for (i = 0; i < wmiRegInfo->GuidCount; i++)
                {
                    wmiRegInfo->WmiRegGuid[i].InstanceInfo = (ULONG_PTR)pDO;
                    wmiRegInfo->WmiRegGuid[i].Flags &= ~(WMIREG_FLAG_INSTANCE_BASENAME |
                                                      WMIREG_FLAG_INSTANCE_LIST);
                    wmiRegInfo->WmiRegGuid[i].Flags |= WMIREG_FLAG_INSTANCE_PDO;
                }

                if (wmiRegInfo->NextWmiRegInfo == 0) {
                    break;
                }

                offsetToRegPath -= wmiRegInfo->NextWmiRegInfo;
                wmiRegInfo = (PWMIREGINFO)( (PUCHAR)wmiRegInfo +
                                            wmiRegInfo->NextWmiRegInfo );
            }

            //
            // Adjust retSz to reflect new size of the WMI buffer.
            //
            retSz += countedRegistryPathSize;
            wmiRegInfo->BufferSize = retSz;
        } // else, no WMIREGINFOs registered whatsoever, nothing to piggyback

        //
        // Do we have any SCSIPORT WMIREGINFOs to piggyback?
        //
        if (spWmiRegInfoBufSize && !wmiUpdateRequest) {

            //
            // Adjust retSz so that the data we piggyback is 8-byte aligned
            // (safe if retSz = 0).
            //
            retSz = (retSz + 7) & ~7;

            //
            // Piggyback SCSIPORT's registration info into the buffer.
            //
            RtlCopyMemory( (PUCHAR)WmiParameters->Buffer + retSz,
                           spWmiRegInfoBuf,
                           spWmiRegInfoBufSize);

            //
            // Was at least one WMIREGINFO returned by the minidriver?
            // Otherwise, we have nothing else to add to the WMI buffer.
            //
            if (retSz) { // at least one WMIREGINFO returned by minidriver
                PWMIREGINFO wmiRegInfo = WmiParameters->Buffer;

                //
                // Traverse to the end of the WMIREGINFO structures returned
                // by the miniport.
                //
                while (wmiRegInfo->NextWmiRegInfo) {
                    wmiRegInfo = (PWMIREGINFO)( (PUCHAR)wmiRegInfo +
                                                wmiRegInfo->NextWmiRegInfo );
                }

                //
                // Chain minidriver's WMIREGINFO structures to SCSIPORT's
                // WMIREGINFO structures.
                //
                wmiRegInfo->NextWmiRegInfo = retSz -
                                             (ULONG)((PUCHAR)wmiRegInfo - (PUCHAR)WmiParameters->Buffer);
            }

            //
            // Adjust retSz to reflect new size of the WMI buffer.
            //
            retSz += spWmiRegInfoBufSize;

        } // we had SCSIPORT REGINFO data to piggyback
    } // else, unknown error, complete IRP with this error status

    //
    // Save new buffer size to WmiParameters->BufferSize.
    //
    WmiParameters->BufferSize = retSz;

    return status;
}
Пример #18
0
NTSTATUS
NdasPortGetLpxLocalAddressList(
	__inout PTDI_ADDRESS_LPX TdiLpxAddressBuffer,
	__inout PULONG TdiLpxAddressCount,
	__out PULONG TotalAddressCount,
	__out PULONG UpdateCounter)
{
	PNDASPORT_DRIVER_EXTENSION driverExtension;
	PLIST_ENTRY entry;
	KIRQL oldIrql;
	ULONG bufferCount, i;

	driverExtension = (PNDASPORT_DRIVER_EXTENSION) IoGetDriverObjectExtension(
		NdasPortDriverObject,
		&NdasPortDriverExtensionTag);

	ASSERT(NULL != driverExtension);

	//
	// TODO: Clarify UpdateCounter coherency and usage
	//
	*UpdateCounter = driverExtension->LpxLocalAddressListUpdateCounter;

	if (NULL == TdiLpxAddressBuffer || 
		NULL == TdiLpxAddressCount ||
		0 == *TdiLpxAddressCount)
	{
		return STATUS_SUCCESS;
	}

	bufferCount = *TdiLpxAddressCount;
	*TdiLpxAddressCount = 0;

	KeAcquireSpinLock(&driverExtension->LpxLocalAddressListSpinLock, &oldIrql);

	for (entry = driverExtension->LpxLocalAddressList.Flink, i = 0;
		entry != &driverExtension->LpxLocalAddressList;
		entry = entry->Flink, ++i)
	{
		if (i < bufferCount)
		{
			PTDI_ADDRESS_LPX_LIST_ENTRY lpxAddressEntry;

			lpxAddressEntry = CONTAINING_RECORD(
				entry, 
				TDI_ADDRESS_LPX_LIST_ENTRY, 
				ListEntry);

			RtlCopyMemory(
				&TdiLpxAddressBuffer[i],
				&lpxAddressEntry->TdiAddress,
				sizeof(TDI_ADDRESS_LPX));

			++(*TdiLpxAddressCount);
		}
	}

	*TotalAddressCount = i;

	KeReleaseSpinLock(&driverExtension->LpxLocalAddressListSpinLock, oldIrql);

	return (bufferCount < i) ? STATUS_MORE_ENTRIES : STATUS_SUCCESS;
}
Пример #19
0
NTSTATUS
NTAPI
IntVideoPortPnPStartDevice(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp)
{
    PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
    PDRIVER_OBJECT DriverObject;
    PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
    PCM_RESOURCE_LIST AllocatedResources;

    /* Get the initialization data we saved in VideoPortInitialize.*/
    DriverObject = DeviceObject->DriverObject;
    DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
    DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    /* Store some resources in the DeviceExtension. */
    AllocatedResources = Stack->Parameters.StartDevice.AllocatedResources;
    if (AllocatedResources != NULL)
    {
        CM_FULL_RESOURCE_DESCRIPTOR *FullList;
        CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
        ULONG ResourceCount;
        ULONG ResourceListSize;

        /* Save the resource list */
        ResourceCount = AllocatedResources->List[0].PartialResourceList.Count;
        ResourceListSize =
            FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.
                         PartialDescriptors[ResourceCount]);
        DeviceExtension->AllocatedResources = ExAllocatePool(PagedPool, ResourceListSize);
        if (DeviceExtension->AllocatedResources == NULL)
        {
            return STATUS_INSUFFICIENT_RESOURCES;
        }

        RtlCopyMemory(DeviceExtension->AllocatedResources,
                      AllocatedResources,
                      ResourceListSize);

        /* Get the interrupt level/vector - needed by HwFindAdapter sometimes */
        for (FullList = AllocatedResources->List;
             FullList < AllocatedResources->List + AllocatedResources->Count;
             FullList++)
        {
            INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
                  FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber, FullList->PartialResourceList.Version, FullList->PartialResourceList.Revision);

            /* FIXME: Is this ASSERT ok for resources from the PNP manager? */
            ASSERT(FullList->InterfaceType == PCIBus);
            ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
            ASSERT(1 == FullList->PartialResourceList.Version);
            ASSERT(1 == FullList->PartialResourceList.Revision);
            for (Descriptor = FullList->PartialResourceList.PartialDescriptors;
                 Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
                 Descriptor++)
            {
                if (Descriptor->Type == CmResourceTypeInterrupt)
                {
                    DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
                    DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
                    if (Descriptor->ShareDisposition == CmResourceShareShared)
                        DeviceExtension->InterruptShared = TRUE;
                    else
                        DeviceExtension->InterruptShared = FALSE;
                }
            }
        }
    }

    INFO_(VIDEOPRT, "Interrupt level: 0x%x Interrupt Vector: 0x%x\n",
          DeviceExtension->InterruptLevel,
          DeviceExtension->InterruptVector);

    /* Create adapter device object. */
    return IntVideoPortFindAdapter(DriverObject,
                                   DriverExtension,
                                   DeviceObject);
}
Пример #20
0
	IN PDRIVER_OBJECT DriverObject,
	OUT PDEVICE_OBJECT *ClassDO OPTIONAL)
{
	PCLASS_DRIVER_EXTENSION DriverExtension;
	ULONG DeviceId = 0;
	ULONG PrefixLength;
	UNICODE_STRING DeviceNameU;
	PWSTR DeviceIdW = NULL; /* Pointer into DeviceNameU.Buffer */
	PDEVICE_OBJECT Fdo;
	PCLASS_DEVICE_EXTENSION DeviceExtension;
	NTSTATUS Status;

	TRACE_(CLASS_NAME, "CreateClassDeviceObject(0x%p)\n", DriverObject);

	/* Create new device object */
	DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
	DeviceNameU.Length = 0;
	DeviceNameU.MaximumLength =
		wcslen(L"\\Device\\") * sizeof(WCHAR)    /* "\Device\" */
		+ DriverExtension->DeviceBaseName.Length /* "PointerClass" */
		+ 4 * sizeof(WCHAR)                      /* Id between 0 and 9999 */
		+ sizeof(UNICODE_NULL);                  /* Final NULL char */
	DeviceNameU.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceNameU.MaximumLength, CLASS_TAG);
	if (!DeviceNameU.Buffer)
	{
		WARN_(CLASS_NAME, "ExAllocatePoolWithTag() failed\n");
		return STATUS_NO_MEMORY;
	}
	Status = RtlAppendUnicodeToString(&DeviceNameU, L"\\Device\\");
	if (!NT_SUCCESS(Status))
	{