共用方式為


EVT_UFX_DEVICE_USB_STATE_CHANGE回呼函式 (ufxclient.h)

用戶端驅動程序的實作,以更新 USB 裝置的狀態。

語法

EVT_UFX_DEVICE_USB_STATE_CHANGE EvtUfxDeviceUsbStateChange;

void EvtUfxDeviceUsbStateChange(
  [in] UFXDEVICE unnamedParam1,
  [in] USBFN_DEVICE_STATE unnamedParam2
)
{...}

參數

[in] unnamedParam1

用戶端驅動程式在先前呼叫 UfxDeviceCreate 中收到的USB裝置物件的句柄。

[in] unnamedParam2

指出USB裝置狀態的USBFN_DEVICE_STATE型別旗標。

傳回值

備註

函式主機控制器的用戶端驅動程式會藉由呼叫 UfxDeviceCreate 方法,向 USB 函式類別延伸模組 (UFX) 註冊其EVT_UFX_DEVICE_USB_STATE_CHANGE實作。

UFX 會叫用此事件回呼,以通知用戶端驅動程式有關裝置的新狀態。

用戶端驅動程式會呼叫 UfxDeviceEventComplete 方法來指出此事件的完成。

範例


EVT_UFX_DEVICE_USB_STATE_CHANGE UfxDevice_EvtDeviceUsbStateChange;

VOID
UfxDevice_EvtDeviceUsbStateChange (
    _In_ UFXDEVICE UfxDevice,
    _In_ USBFN_DEVICE_STATE NewState
)
/*++

Routine Description:

    EvtDeviceUsbStateChange handler for the UFXDEVICE object.

Arguments:

    UfxDevice - UFXDEVICE object representing the device.

    NewState - The new device state.

--*/
{
    NTSTATUS Status;
    PUFXDEVICE_CONTEXT Context;
    PCONTROLLER_CONTEXT ControllerContext;
    ULONG EpIndex;
    USBFN_DEVICE_STATE OldState;
 
    PAGED_CODE();

    TraceEntry();

    Context = UfxDeviceGetContext(UfxDevice);
    ControllerContext = DeviceGetControllerContext(Context->FdoWdfDevice);
    OldState = Context->UsbState;

    TraceInformation("New STATE: %d", NewState);

    Status = UfxDeviceStopOrResumeIdle(UfxDevice, NewState, Context->UsbPort);
    LOG_NT_MSG(Status, "Failed to stop or resume idle");

    WdfWaitLockAcquire(ControllerContext->InitializeDefaultEndpointLock, NULL);
    if (ControllerContext->InitializeDefaultEndpoint == TRUE) {
        //
        // Reset endpoint 0. This is the last part of soft reset, which was postponed
        // until now, since we need to make sure EP0 is created by UFX.
        //
        DeviceInitializeDefaultEndpoint(Context->FdoWdfDevice);
        ControllerContext->InitializeDefaultEndpoint = FALSE;
    }
    WdfWaitLockRelease(ControllerContext->InitializeDefaultEndpointLock);

    if (NewState == UsbfnDeviceStateConfigured && OldState != UsbfnDeviceStateSuspended) {

        for (EpIndex = 1; EpIndex < WdfCollectionGetCount(Context->Endpoints); EpIndex++) {
            UfxEndpointConfigure(WdfCollectionGetItem(Context->Endpoints, EpIndex));
        }

        // 
        // #### TODO: Insert code to allow the controller to accept U1/U2, if supported ####
        //
       
    }


    if (NewState == UsbfnDeviceStateDetached) {
        KeSetEvent(&ControllerContext->DetachEvent,
                   IO_NO_INCREMENT,
                   FALSE);
    }

    UfxDeviceEventComplete(UfxDevice, STATUS_SUCCESS);
    TraceExit();
}

規格需求

需求
目標平台 Windows
最低 KMDF 版本 1.0
最低UMDF版本 2.0
標頭 ufxclient.h
IRQL PASSIVE_LEVEL

另請參閱

UfxDeviceCreate

UfxDeviceEventComplete