⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbfx2lk_sysctrl.cpp

📁 基于vc++6.0环境的cypress USB 驱动源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        {
            //
            // We really should never get here, but if we do just forward....
            //
            IoSkipCurrentIrpStackLocation (Irp);
            status = IoCallDriver (devExt->DeviceToSendIrpsTo, Irp);
            break;
        }        
    }

    OsrDecrementOutstandingIoCount(devExt,__FILE__,__LINE__);

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkSystemControl: Exit\n"));

    return(status);

}

//
// WMI System Call back functions
//


///////////////////////////////////////////////////////////////////////////////
//
//  UsbFx2LkWmiSetDataBlock
//
//      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.
//
//  Inputs:
//
//      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
//
//  Outputs:
//
//      None.
//
//  Returns:
//
//      STATUS_SUCCESS if successful, error otherwise.
//
//  IRQL:
//
//      IRQL == PASSIVE_LEVEL.
//
//  Notes:
//
///////////////////////////////////////////////////////////////////////////////
NTSTATUS UsbFx2LkWmiSetDataBlock(IN PDEVICE_OBJECT DeviceObject,
                              IN PIRP Irp,
                              IN ULONG GuidIndex,
                              IN ULONG InstanceIndex,
                              IN ULONG BufferSize,
                              IN PUCHAR Buffer)
{
    PUSBFX2LK_EXT   devExt;
    NTSTATUS        status;
    ULONG           info;
    KIRQL           oldIrql;

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiSetDataBlock: Entered\n"));

    devExt = (PUSBFX2LK_EXT) DeviceObject->DeviceExtension;

    ASSERT(InstanceIndex == 0);

    switch(GuidIndex) {

        case UsbFx2LkDeviceWakeEnableGuidIndex: {
            BOOLEAN* pBoolean = (BOOLEAN*) Buffer;

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                ("UsbFx2LkWmiSetDataBlock: UsbFx2LkDeviceWakeEnable\n"));

            info = sizeof(BOOLEAN);

            if (BufferSize < info) {
                status = STATUS_BUFFER_TOO_SMALL;
                break;

            }

            //
            // Can't do anything with WW IRPs if the device
            //  isn't powered up.
            //
            SSPowerDeviceIfSuspended(devExt);

            //
            // See if the setting of WaitWakeEnable is changing.
            //
            if(devExt->WaitWakeEnable != *pBoolean) {
                if(*pBoolean) {
                    //
                    // Wait Wake is being enabled.  First determine
                    // if this is possible, and if it is, then enable it.
                    // Otherwise we have to return an error.
                    //
                    if(devExt->UsbConfigurationDescriptor->bmAttributes & USB_CONFIG_REMOTE_WAKEUP) {
                        //
                        // The device is capable of Remote Wake up, so we will enable it.
                        //
                        devExt->WaitWakeEnable = *pBoolean;
                        IssueWaitWake(devExt);
                    } else {
                        //
                        // The device is not capable of Remote Wake up, so we have to
                        // inform the user of the error.
                        //
                        status = STATUS_INVALID_DEVICE_REQUEST;
                        break;
                    }
                } else {
                    //
                    // Wait Wake is being disabled. 
                    //
                    devExt->WaitWakeEnable = *pBoolean;
                    CancelWaitWake(devExt);
                }
            }
            status = STATUS_SUCCESS;
            break;
        }

        case UsbFx2LkSelectiveSuspendEnabledGuidIndex: {
            BOOLEAN* pBoolean = (BOOLEAN*) Buffer;

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                ("UsbFx2LkWmiSetDataBlock: UsbFx2LkSelectiveSuspendEnabledGuidIndex\n"));

            info = sizeof(BOOLEAN);

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

            //
            // Get the SS code into a known state by
            //  powering up the device if we're suspended
            //
            SSPowerDeviceIfSuspended(devExt);

            //
            // We'll need the SS lock for this 
            //
            KeAcquireSpinLock(&devExt->SSLock,&oldIrql);

            //
            // Update the field that indicates whether or not
            //  SS is enabled by ths ueer
            //
            devExt->SSEnabledByUser = *pBoolean;

            KeReleaseSpinLock(&devExt->SSLock, oldIrql);

            //
            // And let the SS code deal with whether else 
            //  needs to be done
            //
            if (*pBoolean) {

                OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                    ("UsbFx2LkWmiSetDataBlock: User wants to enable selective suspend\n"));

                EnableSelectiveSuspend(devExt);

            } else {

                OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                    ("UsbFx2LkWmiSetDataBlock: User wants to disable selective suspend\n"));

                DisableSelectiveSuspend(devExt);

            }

            status = STATUS_SUCCESS;
            break;

        }

        default: {
            status = STATUS_WMI_GUID_NOT_FOUND;
            break;

        }

    }


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

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiSetDataBlock: Exit\n"));

    return(status);
}


///////////////////////////////////////////////////////////////////////////////
//
//  UsbFx2LkWmiQueryDataBlock
//
//      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.
//
//  Inputs:
//
//      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
//
//  Outputs:
//
//      None.
//
//  Returns:
//
//      STATUS_SUCCESS if successful, error otherwise.
//
//  IRQL:
//
//      IRQL == PASSIVE_LEVEL.
//
//  Notes:
//
///////////////////////////////////////////////////////////////////////////////
NTSTATUS UsbFx2LkWmiQueryDataBlock(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)
{
    PUSBFX2LK_EXT   devExt;
    NTSTATUS        status;
    ULONG           size;
    ULONG           sizeNeeded = 0;

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiQueryDataBlock: Entered\n"));

    //
    // we only ever register 1 instance per guid
    //
    
    ASSERT((InstanceIndex == 0) && (InstanceCount == 1));
    
    devExt = (PUSBFX2LK_EXT) DeviceObject->DeviceExtension;

    switch (GuidIndex) {

        case UsbFx2LkPerformanceCountGuidIndex: {
                OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                    ("UsbFx2LkWmiQueryDataBlock: UsbFx2LkPerformanceCountGuidIndex\n"));

                sizeNeeded = sizeof(USBFX2LK_STATISTICS);

                if (OutBufferSize >= sizeNeeded) {
                    PUSBFX2LK_STATISTICS pStatistics = (PUSBFX2LK_STATISTICS)Buffer;

                    RtlCopyMemory(pStatistics,&devExt->WmiStatistics,sizeNeeded);

                    *InstanceLengthArray = sizeNeeded;

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

#ifdef USE_BINARY_MOF_QUERY
        case UsbFx2LkBinaryMofGuidGuidIndex: {
                OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                    ("UsbFx2LkWmiQueryDataBlock: UsbFx2LkBinaryMofGuidGuidIndex\n"));
                sizeNeeded = sizeof(UsbFx2LkBinaryMofData);

                if (OutBufferSize < sizeNeeded)
                {
                    status = STATUS_BUFFER_TOO_SMALL;
                } else {
                    RtlCopyMemory(Buffer, UsbFx2LkBinaryMofData, sizeNeeded);
                    *InstanceLengthArray = sizeNeeded;
                    status = STATUS_SUCCESS;
                }
                break;
            }
#endif

        case UsbFx2LkDeviceWakeEnableGuidIndex: {

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                ("UsbFx2LkWmiQueryDataBlock: UsbFx2LkDeviceWakeEnableGuidIndex\n"));

            sizeNeeded = sizeof(BOOLEAN);

            //
            // Only registers 1 instance for this guid
            //
            if ((0 != InstanceIndex) || (1 != InstanceCount)) {
                status = STATUS_INVALID_DEVICE_REQUEST;
                break;
            }
            size = sizeof(BOOLEAN);

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

            *((PBOOLEAN) Buffer) = (BOOLEAN) devExt->WaitWakeEnable; 
            *InstanceLengthArray = size;
            status = STATUS_SUCCESS;
            break;
        }

        case UsbFx2LkSelectiveSuspendEnabledGuidIndex: {

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WMI_INFO,
                ("UsbFx2LkWmiQueryDataBlock: UsbFx2LkSelectiveSuspendEnabledGuidIndex\n"));

            sizeNeeded = sizeof(BOOLEAN);

            //
            // Only registers 1 instance for this guid
            //
            if ((0 != InstanceIndex) || (1 != InstanceCount)) {
                status = STATUS_INVALID_DEVICE_REQUEST;
                break;
            }

            size = sizeof(BOOLEAN);

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

            *((PBOOLEAN) Buffer) = devExt->SSEnabledByUser;
            *InstanceLengthArray = size;
            status = STATUS_SUCCESS;
            break;
        }

        default:

            OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_WMI_INFO,
                ("UsbFx2LkWmiQueryDataBlock: unknown %d\n",GuidIndex));

            status = STATUS_WMI_GUID_NOT_FOUND;
            break;

    }

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

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiQueryDataBlock: Exit\n"));

    return status;
}

///////////////////////////////////////////////////////////////////////////////
//
//  UsbFx2LkWmiQueryRegInfo
//
//      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.
//
//  Inputs:
//
//      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 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.
//
//
//  Outputs:
//
//      None.
//
//  Returns:
//
//      STATUS_SUCCESS if successful, error otherwise.
//
//  IRQL:
//
//      IRQL == PASSIVE_LEVEL.
//
//  Notes:
//
///////////////////////////////////////////////////////////////////////////////
NTSTATUS UsbFx2LkWmiQueryRegInfo(IN PDEVICE_OBJECT DeviceObject,
                                OUT ULONG *RegFlags,
                                OUT PUNICODE_STRING InstanceName,
                                OUT PUNICODE_STRING *RegistryPath,
                                OUT PUNICODE_STRING MofResourceName,
                                OUT PDEVICE_OBJECT *Pdo)
{
    PUSBFX2LK_EXT pDevExt;
        
    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiQueryRegInfo: Entered\n"));

    pDevExt = (PUSBFX2LK_EXT) DeviceObject->DeviceExtension;

    *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
    *RegistryPath = &GlobalRegistryPath;
    *Pdo = pDevExt->PhysicalDeviceObject;

#ifndef USE_BINARY_MOF_QUERY
    RtlInitUnicodeString(MofResourceName, MOFRESOURCENAME);
#endif 

    pDevExt->WmiRegistered = TRUE;
    
    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WMI_INFO,("UsbFx2LkWmiQueryRegInfo: Exit\n"));

    return STATUS_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -