Example #1
0
/*++

Routine Description:

    This routine is a callback into the driver to set for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.
            
    DataItemId has the id of the data item being set

    BufferSize has the size of the data item passed

    Buffer has the new values for the data item


Return Value:

    status

--*/
NTSTATUS
NdasPortSetWmiDataItem(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN ULONG GuidIndex,
    IN ULONG InstanceIndex,
    IN ULONG DataItemId,
    IN ULONG BufferSize,
    IN PUCHAR Buffer)
{
	PNDASPORT_FDO_EXTENSION FdoExtension;
    NTSTATUS status;
    ULONG requiredSize = 0;

    PAGED_CODE();

	FdoExtension = (PNDASPORT_FDO_EXTENSION) DeviceObject->DeviceExtension;

    switch (GuidIndex) 
	{
    case WMI_NDASPORT_STD_DATA:
 
		if (DataItemId == 2)
		{
           requiredSize = sizeof(ULONG);

           if (BufferSize < requiredSize) 
		   {
                status = STATUS_BUFFER_TOO_SMALL;
                break;
           }

			//BusEnumDebugLevel = FdoExtension->StdToasterBusData.DebugPrintLevel = 
			//	*((PULONG)Buffer);

			status = STATUS_SUCCESS;
        }
        else 
		{
            status = STATUS_WMI_READ_ONLY;
        }
        break;

	case WMI_NDASPORT_EVENT:
		status = STATUS_WMI_READ_ONLY;
		break;

	default:
        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(
		DeviceObject,
        Irp,
        status,
        requiredSize,
        IO_NO_INCREMENT);

    return status;
}
Example #2
0
/*++

Routine Description:

    This routine is a callback into the driver to query for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.
            
    InstanceCount is the number of instnaces expected to be returned for
        the data block.
            
    InstanceLengthArray is a pointer to an array of ULONG that returns the 
        lengths of each instance of the data block. If this is NULL then
        there was not enough space in the output buffer to fulfill the request
        so the irp should be completed with the buffer needed.        
            
    BufferAvail on has the maximum size available to write the data
        block.

    Buffer on return is filled with the returned data block


Return Value:

    status

--*/
NTSTATUS
NdasPortQueryWmiDataBlock(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN ULONG GuidIndex,
    IN ULONG InstanceIndex,
    IN ULONG InstanceCount,
    IN OUT PULONG InstanceLengthArray,
    IN ULONG OutBufferSize,
    OUT PUCHAR Buffer)
{
	NTSTATUS status;
	PNDASPORT_FDO_EXTENSION FdoExtension;
    ULONG size = 0;

    PAGED_CODE();

    //
    // Only ever registers 1 instance per guid
    //
    
    ASSERT((InstanceIndex == 0) && (InstanceCount == 1));
  
	FdoExtension = (PNDASPORT_FDO_EXTENSION) DeviceObject->DeviceExtension;

    switch (GuidIndex) 
	{
	case WMI_NDASPORT_STD_DATA:
        // size = sizeof (TOASTER_BUS_WMI_STD_DATA);
		size = 0;
        if ( OutBufferSize < size) 
		{
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        //* (PTOASTER_BUS_WMI_STD_DATA) Buffer = fdoData->StdToasterBusData;
		*InstanceLengthArray = size;
        status = STATUS_SUCCESS;
        break;
	case WMI_NDASPORT_EVENT:
		*InstanceLengthArray = 0;
		status = STATUS_SUCCESS;
		break;
    default:

        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(
		DeviceObject,
        Irp,
        status,
        size,
        IO_NO_INCREMENT);

    return status;
}
Example #3
0
/*++

Routine Description:

    This routine is a callback into the driver to set the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.
            
    BufferSize has the size of the data block passed

    Buffer has the new values for the data block


Return Value:

    status

--*/
NTSTATUS
NdasPortSetWmiDataBlock(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN ULONG GuidIndex,
    IN ULONG InstanceIndex,
    IN ULONG BufferSize,
    IN PUCHAR Buffer)
{
	PNDASPORT_FDO_EXTENSION FdoExtension;
    NTSTATUS status;
    ULONG requiredSize = 0;

    PAGED_CODE();

	FdoExtension = (PNDASPORT_FDO_EXTENSION) DeviceObject->DeviceExtension;

    switch (GuidIndex)
	{
    case WMI_NDASPORT_STD_DATA:

        requiredSize = 0;

        if(BufferSize < requiredSize) 
		{
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        //
        // We will update only writable elements.
        //
        //BusEnumDebugLevel = FdoExtension->StdToasterBusData.DebugPrintLevel = 
        //            ((PTOASTER_BUS_WMI_STD_DATA)Buffer)->DebugPrintLevel;
                    
        status = STATUS_SUCCESS;
        break;

	case WMI_NDASPORT_EVENT:
		status = STATUS_SUCCESS;
		break;

	default:
        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(
		DeviceObject,
        Irp,
        status,
        requiredSize,
        IO_NO_INCREMENT);

    return(status);
}
// query data block
NTSTATUS AppleKeyboardQueryWmiDataBlock(__in PDEVICE_OBJECT pDeviceObject,__in PIRP pIrp,__in ULONG ulGuidIndex,__in ULONG ulInstanceIndex,
										__in ULONG ulInstanceCount,__in __out PULONG pulInstanceLengthArray,__in ULONG ulBufferAvail,__out PUCHAR pBuffer)
{
	ASSERT(ulInstanceIndex == 0 && ulInstanceCount == 1);
	CDeviceExtension* pDevExt = static_cast<CDeviceExtension*>(pDeviceObject->DeviceExtension);
	NTSTATUS statusRet = STATUS_SUCCESS;
	ULONG ulBufferUsed = 0;

	switch(ulInstanceIndex)
	{
	case 0:
		ulBufferUsed = sizeof(KEYBOARD_PORT_WMI_STD_DATA);
		if(ulBufferAvail < ulBufferUsed)
		{
			statusRet = STATUS_BUFFER_TOO_SMALL;
		}
		else
		{
			PKEYBOARD_PORT_WMI_STD_DATA pData = static_cast<PKEYBOARD_PORT_WMI_STD_DATA>(static_cast<PVOID>(pBuffer));
			pData->ConnectorType = KEYBOARD_PORT_WMI_STD_USB;
			pData->DataQueueSize = pDevExt->m_attributeKeyboard.InputDataQueueLength;
			pData->ErrorCount = 0;
			pData->FunctionKeys = pDevExt->m_attributeKeyboard.NumberOfFunctionKeys;
			pData->Indicators = pDevExt->m_attributeKeyboard.NumberOfIndicators;

			*pulInstanceLengthArray = ulBufferUsed;
		}
		break;

	case 1:
		ulBufferUsed = sizeof(KEYBOARD_ID_EX);
		if(ulBufferAvail < ulBufferUsed)
		{
			statusRet = STATUS_BUFFER_TOO_SMALL;
		}
		else
		{
			RtlCopyMemory(pBuffer,&pDevExt->m_wmiKeyboardIdEx,ulBufferUsed);
			*pulInstanceLengthArray = ulBufferUsed;
		}
		break;

	default:
		statusRet = STATUS_WMI_GUID_NOT_FOUND;
	}

	return WmiCompleteRequest(pDeviceObject,pIrp,statusRet,ulBufferUsed,IO_NO_INCREMENT);
}
Example #5
0
NTSTATUS BulkUsb_QueryWmiDataBlock(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex,
								   IN ULONG InstanceIndex, IN ULONG InstanceCount, 
								   IN OUT PULONG InstanceLengthArray, IN ULONG OutBufferSize,
								   OUT PUCHAR Buffer)
{
    PTDeviceExtension deviceExtension;
    NTSTATUS          ntStatus;
    ULONG             size;
    WCHAR             modelName[] = L"Aishverya\0\0";
    USHORT            modelNameLen;

    PAGED_CODE();
    BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_QueryWmiDataBlock - begins\n"));
    size = 0;
    modelNameLen = (wcslen(modelName) + 1) * sizeof(WCHAR);

    ASSERT((InstanceIndex == 0) && (InstanceCount == 1));
    
    deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension;
    switch (GuidIndex) 
	{
    case WMI_BULKUSB_DRIVER_INFORMATION:
        size = sizeof(ULONG) + modelNameLen + sizeof(USHORT);
        if (OutBufferSize < size ) 
		{
            BulkUsb_DbgPrint(3, ("file bulkwmi: OutBuffer too small\n"));
            ntStatus = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        * (PULONG) Buffer = DebugLevel;
        Buffer += sizeof(ULONG);
        *((PUSHORT)Buffer) = modelNameLen;
        Buffer = (PUCHAR)Buffer + sizeof(USHORT);
        RtlCopyBytes((PVOID)Buffer, (PVOID)modelName, modelNameLen);
        *InstanceLengthArray = size ;
        ntStatus = STATUS_SUCCESS;
        break;

    default:
        ntStatus = STATUS_WMI_GUID_NOT_FOUND;
		break;
    }
    ntStatus = WmiCompleteRequest(DeviceObject, Irp, ntStatus, size, IO_NO_INCREMENT);
    BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_QueryWmiDataBlock - ends\n"));
    return ntStatus;
}
Example #6
0
NTSTATUS BulkUsb_SetWmiDataItem(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN ULONG GuidIndex,
								IN ULONG InstanceIndex, IN ULONG DataItemId, IN ULONG BufferSize,
								IN PUCHAR Buffer)
{
    PTDeviceExtension deviceExtension;
    NTSTATUS          ntStatus;
    ULONG             info;
    
    PAGED_CODE();
    BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_SetWmiDataItem - begins\n"));
    deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension;
    info = 0;
    switch(GuidIndex) 
	{
    case WMI_BULKUSB_DRIVER_INFORMATION:
        if(DataItemId == 1) 
		{
            if(BufferSize == sizeof(ULONG)) 
			{
                DebugLevel = *((PULONG)Buffer);
                ntStatus = STATUS_SUCCESS;
                info = sizeof(ULONG);
            }
            else 
                ntStatus = STATUS_INFO_LENGTH_MISMATCH;
        }
        else 
            ntStatus = STATUS_WMI_READ_ONLY;
        break;

    default:
        ntStatus = STATUS_WMI_GUID_NOT_FOUND;
		break;
    }

    ntStatus = WmiCompleteRequest(DeviceObject,
                                Irp,
                                ntStatus,
                                info,
                                IO_NO_INCREMENT);

    BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_SetWmiDataItem - ends\n"));
    return ntStatus;
}
Example #7
0
NTSTATUS
NdasPortWmiCompleteRequest(
	__in PNDAS_LOGICALUNIT_EXTENSION LogicalUnitExtension,
	__in PIRP Irp,
	__in NTSTATUS Status,
	__in ULONG BufferUsed,
	__in CCHAR PriorityBoost)
{
	NTSTATUS status;
	PNDASPORT_PDO_EXTENSION PdoExtension;
	PDEVICE_OBJECT Pdo;
	PdoExtension = NdasPortLogicalUnitGetPdoExtension(LogicalUnitExtension);
	Pdo = PdoExtension->DeviceObject;
	NpReleaseRemoveLock(PdoExtension->CommonExtension, Irp);
	status = WmiCompleteRequest(
		Pdo,
		Irp,
		Status,
		BufferUsed,
		PriorityBoost);
	return status;
}
Example #8
0
NTSTATUS NTAPI FreeBT_SetWmiDataBlock(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp,
    IN ULONG          GuidIndex,
    IN ULONG          InstanceIndex,
    IN ULONG          BufferSize,
    IN PUCHAR         Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to set the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    BufferSize has the size of the data block passed

    Buffer has the new values for the data block

--*/
{
    PDEVICE_EXTENSION deviceExtension;
    NTSTATUS          ntStatus;
    ULONG             info;

    PAGED_CODE();

    FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataBlock: Entered\n"));

    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    info = 0;

    switch(GuidIndex)
	{
    case WMI_FREEBT_DRIVER_INFORMATION:
        if(BufferSize == sizeof(ULONG))
		{
            DebugLevel = *(PULONG) Buffer;
            ntStatus = STATUS_SUCCESS;
            info = sizeof(ULONG);

        }

        else
		{
            ntStatus = STATUS_INFO_LENGTH_MISMATCH;

        }

        break;

    default:
        ntStatus = STATUS_WMI_GUID_NOT_FOUND;

    }

    ntStatus = WmiCompleteRequest(DeviceObject,
                                Irp,
                                ntStatus,
                                info,
                                IO_NO_INCREMENT);

    FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataBlock: Leaving\n"));

    return ntStatus;

}
Example #9
0
NTSTATUS NTAPI FreeBT_QueryWmiDataBlock(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp,
    IN ULONG          GuidIndex,
    IN ULONG          InstanceIndex,
    IN ULONG          InstanceCount,
    IN OUT PULONG     InstanceLengthArray,
    IN ULONG          OutBufferSize,
    OUT PUCHAR        Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to query for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    InstanceCount is the number of instances expected to be returned for
        the data block.

    InstanceLengthArray is a pointer to an array of ULONG that returns the
        lengths of each instance of the data block. If this is NULL then
        there was not enough space in the output buffer to fulfill the request
        so the irp should be completed with the buffer needed.

    OutBufferSize has the maximum size available to write the data
        block.

    Buffer on return is filled with the returned data block


Return Value:

    status

--*/
{
    PDEVICE_EXTENSION deviceExtension;
    NTSTATUS          ntStatus;
    ULONG             size;
    WCHAR             modelName[] = L"Aishverya\0\0";
    USHORT            modelNameLen;

    PAGED_CODE();

    FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiDataBlock: Entered\n"));

    size = 0;
    modelNameLen = (wcslen(modelName) + 1) * sizeof(WCHAR);

    // Only ever registers 1 instance per guid
    ASSERT((InstanceIndex == 0) && (InstanceCount == 1));

    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    switch (GuidIndex)
	{
    case WMI_FREEBT_DRIVER_INFORMATION:
        size = sizeof(ULONG) + modelNameLen + sizeof(USHORT);
        if (OutBufferSize < size )
		{
            FreeBT_DbgPrint(3, ("FBTUSB: OutBuffer too small\n"));
            ntStatus = STATUS_BUFFER_TOO_SMALL;
            break;

        }

        * (PULONG) Buffer = DebugLevel;
        Buffer += sizeof(ULONG);

        // put length of string ahead of string
        *((PUSHORT)Buffer) = modelNameLen;
        Buffer = (PUCHAR)Buffer + sizeof(USHORT);
        RtlCopyBytes((PVOID)Buffer, (PVOID)modelName, modelNameLen);
        *InstanceLengthArray = size ;

        ntStatus = STATUS_SUCCESS;
        break;

    default:
        ntStatus = STATUS_WMI_GUID_NOT_FOUND;

    }

    ntStatus = WmiCompleteRequest(DeviceObject,
                                Irp,
                                ntStatus,
                                size,
                                IO_NO_INCREMENT);

    FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiDataBlock: Leaving\n"));

    return ntStatus;

}
// set data item
NTSTATUS AppleKeyboardSetWmiDataItem(__in PDEVICE_OBJECT pDeviceObject,__in PIRP pIrp,__in ULONG ulGuidIndex,__in ULONG ulInstanceIndex,
									 __in ULONG ulDataItemId,__in ULONG ulBufferSize,__in PUCHAR pBuffer)
{
	return WmiCompleteRequest(pDeviceObject,pIrp,ulGuidIndex == 1 ? STATUS_WMI_READ_ONLY : STATUS_WMI_GUID_NOT_FOUND,0,IO_NO_INCREMENT);
}
Example #11
0
File: Wmi.c Project: kcrazy/winekit
NTSTATUS
Bus_QueryWmiDataBlock(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    ULONG GuidIndex,
    ULONG InstanceIndex,
    ULONG InstanceCount,
    PULONG InstanceLengthArray,
    ULONG OutBufferSize,
    PUCHAR Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to query for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    InstanceCount is the number of instnaces expected to be returned for
        the data block.

    InstanceLengthArray is a pointer to an array of ULONG that returns the
        lengths of each instance of the data block. If this is NULL then
        there was not enough space in the output buffer to fulfill the request
        so the irp should be completed with the buffer needed.

    BufferAvail on has the maximum size available to write the data
        block.

    Buffer on return is filled with the returned data block


Return Value:

    status

--*/
{
    PFDO_DEVICE_DATA               fdoData;
    NTSTATUS    status;
    ULONG       size = 0;

    UNREFERENCED_PARAMETER(InstanceCount);
    UNREFERENCED_PARAMETER(InstanceIndex);

    PAGED_CODE();

    //
    // Only ever registers 1 instance per guid
    //

    ASSERT((InstanceIndex == 0) &&
           (InstanceCount == 1));

    fdoData = (PFDO_DEVICE_DATA) DeviceObject->DeviceExtension;

    switch (GuidIndex) {
    case WMI_TOASTER_BUS_DRIVER_INFORMATION:

        size = sizeof (TOASTER_BUS_WMI_STD_DATA);

        if (OutBufferSize < size) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        * (PTOASTER_BUS_WMI_STD_DATA) Buffer = fdoData->StdToasterBusData;
        *InstanceLengthArray = size;
        status = STATUS_SUCCESS;

        break;

    default:

        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(  DeviceObject,
                                  Irp,
                                  status,
                                  size,
                                  IO_NO_INCREMENT);

    return status;
}
Example #12
0
File: Wmi.c Project: kcrazy/winekit
NTSTATUS
Bus_SetWmiDataBlock(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    ULONG GuidIndex,
    ULONG InstanceIndex,
    ULONG BufferSize,
    PUCHAR Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to set the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    BufferSize has the size of the data block passed

    Buffer has the new values for the data block


Return Value:

    status

--*/
{
    PFDO_DEVICE_DATA   fdoData;
    NTSTATUS status;
    ULONG requiredSize = 0;

    UNREFERENCED_PARAMETER(InstanceIndex);

    PAGED_CODE();

    fdoData = (PFDO_DEVICE_DATA) DeviceObject->DeviceExtension;


    switch(GuidIndex) {
    case WMI_TOASTER_BUS_DRIVER_INFORMATION:

        requiredSize = sizeof(TOASTER_BUS_WMI_STD_DATA);

        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        //
        // We will update only writable elements.
        //
        BusEnumDebugLevel = fdoData->StdToasterBusData.DebugPrintLevel =
                    ((PTOASTER_BUS_WMI_STD_DATA)Buffer)->DebugPrintLevel;

        status = STATUS_SUCCESS;

        break;

    default:

        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(  DeviceObject,
                                  Irp,
                                  status,
                                  requiredSize,
                                  IO_NO_INCREMENT);

    return(status);
}
Example #13
0
NTSTATUS
MobiUsb_SetWmiDataItem(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp,
    IN ULONG          GuidIndex,
    IN ULONG          InstanceIndex,
    IN ULONG          DataItemId,
    IN ULONG          BufferSize,
    IN PUCHAR         Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to set for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.
            
    DataItemId has the id of the data item being set

    BufferSize has the size of the data item passed

    Buffer has the new values for the data item


Return Value:

    status

--*/
{
    PDEVICE_EXTENSION deviceExtension;
    NTSTATUS          ntStatus;
    ULONG             info;
    
    PAGED_CODE();

    MobiUsb_DbgPrint(3, ("file mobiwmi: MobiUsb_SetWmiDataItem - begins\n"));

    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    info = 0;

    switch(GuidIndex) {
    
    case WMI_MOBIUSB_DRIVER_INFORMATION:

        if(DataItemId == 1) {

            if(BufferSize == sizeof(ULONG)) {

                DebugLevel = *((PULONG)Buffer);

                ntStatus = STATUS_SUCCESS;

                info = sizeof(ULONG);
            }
            else {

                ntStatus = STATUS_INFO_LENGTH_MISMATCH;
            }
        }
        else {

            ntStatus = STATUS_WMI_READ_ONLY;
        }

        break;

    default:

        ntStatus = STATUS_WMI_GUID_NOT_FOUND;
    }

    ntStatus = WmiCompleteRequest(DeviceObject,
                                Irp,
                                ntStatus,
                                info,
                                IO_NO_INCREMENT);

    MobiUsb_DbgPrint(3, ("file mobiwmi: MobiUsb_SetWmiDataItem - ends\n"));

    return ntStatus;
}
Example #14
0
File: wmi.c Project: kcrazy/winekit
NTSTATUS
PciDrvQueryWmiDataBlock(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    ULONG GuidIndex,
    ULONG InstanceIndex,
    ULONG InstanceCount,
    PULONG InstanceLengthArray,
    ULONG OutBufferSize,
    PUCHAR Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to query for the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    InstanceCount is the number of instances expected to be returned for
        the data block.

    InstanceLengthArray is a pointer to an array of ULONG that returns the
        lengths of each instance of the data block. If this is NULL then
        there was not enough space in the output buffer to fulfill the request
        so the irp should be completed with the buffer needed.

    BufferAvail on has the maximum size available to write the data
        block.

    Buffer on return is filled with the returned data block


Return Value:

    status

--*/
{
    PFDO_DATA               fdoData;
    NTSTATUS                status = STATUS_WMI_GUID_NOT_FOUND;
    ULONG                   size = 0;

    PAGED_CODE();

    DebugPrint(TRACE, DBG_WMI, "Entered PciDrvQueryWmiDataBlock\n");

    //
    // Only ever registers 1 instance per guid
    ASSERT((InstanceIndex == 0) &&
           (InstanceCount == 1));

    fdoData = (PFDO_DATA) DeviceObject->DeviceExtension;

    switch (GuidIndex) {
    case WMI_PCIDRV_DRIVER_INFORMATION:

        size = sizeof (PCIDRV_WMI_STD_DATA);
        if (OutBufferSize < size ) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        //
        // Copy the structure information
        //
        * (PPCIDRV_WMI_STD_DATA) Buffer = fdoData->StdDeviceData;

        *InstanceLengthArray = size ;
        status = STATUS_SUCCESS;
        break;


    case WMI_POWER_DEVICE_WAKE_ENABLE:

        //
        // Here we return the current preference of the user for wait-waking
        // the system. We read(IoOpenDeviceRegistryKey/ZwQueryValueKey)
        // the default value written by the INF file in the HW registery.
        // If the user changes his preference, then we must record
        // the changes in the registry to have that in affect across
        // boots.
        //

        size = sizeof(BOOLEAN);

        if (OutBufferSize < size) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        if(IsPoMgmtSupported(fdoData)){
            *(PBOOLEAN) Buffer = PciDrvGetWaitWakeEnableState(fdoData) ;
            *InstanceLengthArray = size;
            status = STATUS_SUCCESS;
        }
        break;

    case WMI_POWER_DEVICE_ENABLE:

        //
        // The same rule discussed above applies here
        // for responding to the query.
        //
        size = sizeof(BOOLEAN);

        if (OutBufferSize < size) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        if(IsPoMgmtSupported(fdoData)){

            *(PBOOLEAN) Buffer = PciDrvGetPowerSaveEnableState(fdoData);
            *InstanceLengthArray = size;
            status = STATUS_SUCCESS;
        }

        break;

    case WMI_POWER_CONSERVATION_IDLE_TIME:

        size = sizeof(ULONG);

        if (OutBufferSize < size) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        //
        // Convert the value back to secs.
        //
        *(PULONG) Buffer = (ULONG)(fdoData->ConservationIdleTime/-SECOND_TO_100NS);
        *InstanceLengthArray = size;
        status = STATUS_SUCCESS;
        break;

    case WMI_POWER_PERFORMANCE_IDLE_TIME:

        size = sizeof(ULONG);

        if (OutBufferSize < size) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        //
        // Convert the value back to secs.
        //
        *(PULONG) Buffer = (ULONG)(fdoData->PerformanceIdleTime/-SECOND_TO_100NS);
        *InstanceLengthArray = size;
        status = STATUS_SUCCESS;
        break;

    default:

        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(  DeviceObject,
                                  Irp,
                                  status,
                                  size,
                                  IO_NO_INCREMENT);

    return status;
}
Example #15
0
File: wmi.c Project: kcrazy/winekit
NTSTATUS
PciDrvSetWmiDataBlock(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    ULONG GuidIndex,
    ULONG InstanceIndex,
    ULONG BufferSize,
    PUCHAR Buffer
    )
/*++

Routine Description:

    This routine is a callback into the driver to set the contents of
    a data block. When the driver has finished filling the data block it
    must call WmiCompleteRequest to complete the irp. The driver can
    return STATUS_PENDING if the irp cannot be completed immediately.

Arguments:

    DeviceObject is the device whose data block is being queried

    Irp is the Irp that makes this request

    GuidIndex is the index into the list of guids provided when the
        device registered

    InstanceIndex is the index that denotes which instance of the data block
        is being queried.

    BufferSize has the size of the data block passed

    Buffer has the new values for the data block


Return Value:

    status

--*/
{
    PFDO_DATA   fdoData;
    NTSTATUS    status = STATUS_WMI_GUID_NOT_FOUND;
    BOOLEAN     waitWakeEnabled;
    BOOLEAN     powerSaveEnabled;
    LONGLONG    newIdleTime, prevIdleTime;
    ULONG       requiredSize = 0;

    PAGED_CODE();

    fdoData = (PFDO_DATA) DeviceObject->DeviceExtension;

    DebugPrint(TRACE, DBG_WMI, "Entered PciDrvSetWmiDataBlock\n");

    switch(GuidIndex) {
    case WMI_PCIDRV_DRIVER_INFORMATION:

        //
        // We will update only writable elements.
        //
        requiredSize = sizeof(PCIDRV_WMI_STD_DATA);
        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }
        DebugLevel = fdoData->StdDeviceData.DebugPrintLevel =
                    ((PPCIDRV_WMI_STD_DATA)Buffer)->DebugPrintLevel;

        status = STATUS_SUCCESS;

        break;


    case WMI_POWER_DEVICE_WAKE_ENABLE:

        //
        // If the wait-wake state is true (box is checked), we send a IRP_MN_WAIT_WAKE
        //  irp to the bus driver. If it's FALSE, we cancel it.
        // Every time the user changes his preference,
        // we write that to the registry to carry over his preference across boot.
        // If the user tries to enable wait-wake, and if the driver stack is not
        // able to do, it will reset the value in the registry to indicate that
        // the device is incapable of wait-waking the system.
        //
        requiredSize = sizeof(BOOLEAN);
        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        if(IsPoMgmtSupported(fdoData)){

            waitWakeEnabled = *(PBOOLEAN) Buffer;

            PciDrvSetWaitWakeEnableState(fdoData, waitWakeEnabled);

            if (waitWakeEnabled) {

                PciDrvArmForWake(fdoData, FALSE);

            } else {

                PciDrvDisarmWake(fdoData, FALSE);
            }

            status = STATUS_SUCCESS;
        }
        break;

    case WMI_POWER_DEVICE_ENABLE:

        requiredSize = sizeof(BOOLEAN);
        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        if(IsPoMgmtSupported(fdoData)){

            powerSaveEnabled = *(PBOOLEAN) Buffer;

            PciDrvSetPowerSaveEnableState(fdoData,  powerSaveEnabled);

            if(powerSaveEnabled) {

                PciDrvRegisterForIdleDetection(fdoData, FALSE);

            } else {

                PciDrvDeregisterIdleDetection(fdoData, FALSE);
            }

            status = STATUS_SUCCESS;
        }
        break;

    case WMI_POWER_CONSERVATION_IDLE_TIME:

        requiredSize =  sizeof(ULONG);
        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        newIdleTime = *(PULONG) Buffer;
        newIdleTime = max(newIdleTime, PCIDRV_MIN_IDLE_TIME);
        //
        // Convert that to ms time units
        //
        newIdleTime = (LONGLONG) -SECOND_TO_100NS * newIdleTime;
        prevIdleTime = fdoData->ConservationIdleTime;
        fdoData->ConservationIdleTime = newIdleTime;

        if(IsPoMgmtSupported(fdoData) &&
            newIdleTime != prevIdleTime){ // if not setting the same value

            //
            // Reset the timer by deregistering and registering the Idle
            // detection.
            //
            PciDrvDeregisterIdleDetection(fdoData, FALSE);
            PciDrvRegisterForIdleDetection(fdoData, FALSE);

        }
        status = STATUS_SUCCESS;
        break;

    case WMI_POWER_PERFORMANCE_IDLE_TIME:

        requiredSize = sizeof(ULONG);
        if (BufferSize < requiredSize) {
            status = STATUS_BUFFER_TOO_SMALL;
            break;
        }

        newIdleTime = *(PULONG) Buffer;
        newIdleTime = max(newIdleTime, PCIDRV_MIN_IDLE_TIME);
        //
        // Convert that to ms time units
        //
        newIdleTime = (LONGLONG) -SECOND_TO_100NS * newIdleTime;
        prevIdleTime = fdoData->PerformanceIdleTime;
        fdoData->PerformanceIdleTime = newIdleTime;

        if(IsPoMgmtSupported(fdoData) &&
            newIdleTime != prevIdleTime){ // if not setting the same value
                        //
            // Reset the timer by deregistering and registering the Idle
            // detection.
            //
            PciDrvDeregisterIdleDetection(fdoData, FALSE);
            PciDrvRegisterForIdleDetection(fdoData, FALSE);
        }
        status = STATUS_SUCCESS;
        break;

    default:

        status = STATUS_WMI_GUID_NOT_FOUND;
    }

    status = WmiCompleteRequest(  DeviceObject,
                                  Irp,
                                  status,
                                  requiredSize,
                                  IO_NO_INCREMENT);

    return(status);
}