Skip to content

Latest commit

 

History

History
158 lines (112 loc) · 4.77 KB

nc-ufxclient-evt_ufx_device_usb_state_change.md

File metadata and controls

158 lines (112 loc) · 4.77 KB
UID title description old-location tech.root ms.date keywords ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames f1_keywords topic_type api_type api_location api_name
NC:ufxclient.EVT_UFX_DEVICE_USB_STATE_CHANGE
EVT_UFX_DEVICE_USB_STATE_CHANGE (ufxclient.h)
The client driver's implementation to update the state of the USB device.
buses\evt_ufx_device_usb_state_change.htm
usbref
05/07/2018
EVT_UFX_DEVICE_USB_STATE_CHANGE callback function
EVT_UFX_DEVICE_USB_STATE_CHANGE, EVT_UFX_DEVICE_USB_STATE_CHANGE callback, EvtUfxDeviceUsbStateChange, EvtUfxDeviceUsbStateChange callback function [Buses], PFN_UFX_DEVICE_USB_STATE_CHANGE, PFN_UFX_DEVICE_USB_STATE_CHANGE callback function pointer [Buses], buses.evt_ufx_device_usb_state_change, ufxclient/EvtUfxDeviceUsbStateChange
ufxclient.h
Windows
1.0
2.0
PASSIVE_LEVEL
Windows
EVT_UFX_DEVICE_USB_STATE_CHANGE
ufxclient/EVT_UFX_DEVICE_USB_STATE_CHANGE
APIRef
kbSyntax
UserDefined
Ufxclient.h
EVT_UFX_DEVICE_USB_STATE_CHANGE

EVT_UFX_DEVICE_USB_STATE_CHANGE callback function

-description

The client driver's implementation to update the state of the USB device.

-parameters

-param unnamedParam1 [in]

The handle to a USB device object that the client driver received in a previous call to the UfxDeviceCreate.

-param unnamedParam2 [in]

A USBFN_DEVICE_STATE-typed flag that indicates state of the USB device.

-remarks

The client driver for the function host controller registers its EVT_UFX_DEVICE_USB_STATE_CHANGE implementation with the USB function class extension (UFX) by calling the UfxDeviceCreate method.

UFX invokes this event callback to inform the client driver about the new state of the device.

The client driver indicates completion of this event by calling the UfxDeviceEventComplete method.

Examples


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();
}

-see-also

UfxDeviceCreate

UfxDeviceEventComplete