Problem in porting USBD_CreateConfigurationRequestEx to KMDF

Discussion in 'Windows Vista Drivers' started by Neeti, Mar 13, 2007.

  1. Neeti

    Neeti Guest

    Hi,

    I have ported the USB part of NDIS-WDM driver from to KMDF. I am
    facing issue while porting the configuration select function. My
    device has 1 configuration and 1 Interface with 6 alternate settings
    so I call UsbPhyConfigureDevice routine for each of the AltSetting:-

    The NDIS-WDM piece of code is as under:-

    for (AltSetting = 0; AltSetting <= MAX_DOWN_RATE_TABLE_SIZE; AltSetting
    ++)
    {
    DataInterfaceDescriptor =
    USBD_ParseConfigurationDescriptorEx(
    ConfigurationDescriptor,
    ConfigurationDescriptor,
    USB_PHY_DATA_INTERFACE_INDEX,
    AltSetting,
    -1,
    -1,
    -1);

    if ( NULL == DataInterfaceDescriptor)
    {
    DBGPRINT(
    DBG_PRINT_MODULE_USB_ALL,
    DBG_PRINT_LEVEL_ERR,
    ("Device has no data class interfaces alternate setting %u
    \n",AltSetting));
    return( STATUS_UNSUCCESSFUL);
    }

    InterfaceList[USB_PHY_DATA_INTERFACE_INDEX].InterfaceDescriptor =
    DataInterfaceDescriptor;
    UsbPhy->DataInterfaceOnAlternateSetting = AltSetting;

    // Configure the device
    NtStatus = UsbPhyConfigureDevice(
    UsbPhy,
    ConfigurationDescriptor,
    InterfaceList);

    }


    NTSTATUS
    UsbPhyConfigureDevice(
    PUSB_PHY UsbPhy,
    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
    PUSBD_INTERFACE_LIST_ENTRY InterfaceList
    )
    {
    NTSTATUS NtStatus;
    PURB Urb;
    PUSBD_INTERFACE_INFORMATION DataInterface;

    DBGPRINT(
    DBG_PRINT_MODULE_USB_ALL,
    DBG_PRINT_LEVEL_TRACE,
    ("UsbPhyConfigureDevice\n"));

    ASSERT( UsbPhy);
    ASSERT( ConfigurationDescriptor);
    ASSERT( InterfaceList);

    //
    // Create the URB for the configuration request. Prior to submitting
    the
    // URB to USBD for processing, we can alter the default settings for
    each
    // interface as desired.
    //
    Urb = USBD_CreateConfigurationRequestEx(
    ConfigurationDescriptor,
    InterfaceList);

    if ( NULL == Urb ) {
    return( STATUS_INSUFFICIENT_RESOURCES);
    }

    /* ISO pipe requires user to indicate the maximum Transfer size.
    ** We are allocating 64k (0xFFFF) transfer size.
    ** This variable probably allocates memory in the host controller
    */
    DataInterface =
    InterfaceList[USB_PHY_DATA_INTERFACE_INDEX].Interface;
    DataInterface->Pipes[0].MaximumTransferSize = 0xFFFF;

    //
    // Pass the configuration request to USBD with the default settings
    //
    NtStatus = UsbPhyCallUSBD( UsbPhy, Urb);

    if ( !NT_SUCCESS( NtStatus)) {
    DBGPRINT(
    DBG_PRINT_MODULE_USB_ALL,
    DBG_PRINT_LEVEL_ERR,
    ("Configure attempt failed\n"));
    FREE_MEMORY( Urb, sizeof(URB));
    return( NtStatus);
    }
    DataInterface =
    InterfaceList[USB_PHY_DATA_INTERFACE_INDEX].Interface;

    //
    // Save the handle for this configuration as well as the interface
    // information needed when changing the device settings (i.e changing
    // the alternate setting for an interface)
    //
    UsbPhy->ConfigurationHandle =
    Urb->UrbSelectConfiguration.ConfigurationHandle;

    UsbPhy->DataInterfaceNumber =
    DataInterface->InterfaceNumber;

    return( STATUS_SUCCESS);
    }



    This Above piece of code is working fine.

    The ported function is:-

    pDeviceContext = GetWdfDeviceInfo(gFMiniportDevice);

    if(pDeviceContext == NULL)
    return NULL;

    UsbInterface = WdfUsbTargetDeviceGetInterface(
    pDeviceContext->Adapter.FUsbDevice,
    USB_PHY_DATA_INTERFACE_INDEX);

    for (AltSetting = 0; AltSetting <= MAX_DOWN_RATE_TABLE_SIZE;
    AltSetting++)
    {
    WdfUsbInterfaceGetDescriptor(UsbInterface,
    AltSetting,
    DataInterfaceDescriptor);

    if ( NULL == DataInterfaceDescriptor)
    {
    DBGPRINT(
    DBG_PRINT_MODULE_USB_ALL,
    DBG_PRINT_LEVEL_ERR,
    ("Device has no data class interfaces alternate setting %u
    \n",AltSetting));
    return( STATUS_UNSUCCESSFUL);
    }

    // Configure the device

    NtStatus = UsbPhyConfigureDevice(UsbPhy,
    ConfigurationDescriptor,
    DataInterfaceDescriptor);
    }

    NTSTATUS
    UsbPhyConfigureDevice(
    PUSB_PHY UsbPhy,
    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
    PUSB_INTERFACE_DESCRIPTOR DataInterfaceDescriptor
    )
    {
    NTSTATUS NtStatus;
    int i;
    WDF_OBJECT_ATTRIBUTES PipeAttrib;
    PWDF_DEVICE_INFO pDeviceContext = NULL;
    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS configParams;
    PUSB_INTERFACE_DESCRIPTOR
    InterfaceDescriptors[MAX_NUM_OF_INTERFACES];


    DBGPRINT(
    DBG_PRINT_MODULE_USB_ALL,
    DBG_PRINT_LEVEL_TRACE,
    ("UsbPhyConfigureDevice\n"));

    ASSERT( UsbPhy);
    ASSERT( ConfigurationDescriptor);
    ASSERT( DataInterfaceDescriptor);

    InterfaceDescriptors[0] = DataInterfaceDescriptor;

    pDeviceContext = GetWdfDeviceInfo(gFMiniportDevice);

    if(pDeviceContext == NULL)
    return NULL;


    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_INTERFACES_DESCRIPTORS( &configParams,
    ConfigurationDescriptor,
    InterfaceDescriptors,
    MAX_NUM_OF_INTERFACES);

    WDF_OBJECT_ATTRIBUTES_INIT(&PipeAttrib);
    WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&PipeAttrib,
    USB_PIPE_STRUCTURE);

    NtStatus = WdfUsbTargetDeviceSelectConfig(pDeviceContext-
    &PipeAttrib,
    &configParams);

    if (NT_SUCCESS(NtStatus)) {

    UsbPhy->NumberConfiguredPipes =
    WdfUsbInterfaceGetNumConfiguredPipes(UsbPhy->UsbInterface);
    }
    return( STATUS_SUCCESS);
    }


    WdfUsbTargetDeviceSelectConfig return NtStatus NT_SUCCESS but My
    device is coming as "Disabled" under network Connections. I am not
    even able to enable the device. Am I missing out something? Not even
    able to shutdown the device. Please help.

    I dont know how to set the default configuration while selecting the
    configuration.
     
    Neeti, Mar 13, 2007
    #1
    1. Advertisements

  2. since this config is one interface with multiple settings, just use
    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE to initialize the
    select config struct and then if alt setting #0 is not the right default,
    select a different alt setting with WdfUsbInterfaceSelectSetting.
    Alternatively you can use
    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_MULTIPLE_INTERFACES and specify the
    alt setting you want in the WDF_USB_INTERFACE_SETTING_PAIR array

    d
    --
    Please do not send e-mail directly to this alias. this alias is for
    newsgroup purposes only.
    This posting is provided "AS IS" with no warranties, and confers no rights.


     
    Doron Holan [MS], Mar 13, 2007
    #2
    1. Advertisements

  3. Neeti

    Neeti Guest

    HI Doron,

    I tried all but doesnt seems to working :( I even observed that if I
    plug out the device the device removal even is not coming to Windows,
    it still shows device under netwok connection.

    Who enables a USB Device when configured? Is it the host controller
    that does that. What all parameters it expects for configuring and
    enabling the USB Device?

    Navneet
     
    Neeti, Mar 14, 2007
    #3
  4. the host just needs a well formed select config URB, KMDF does that for you.
    your device does participate in the select config process as well. If the
    OS does not detect your device disappearing or has problems with select
    config, you should recheck your device's firmware.

    has select config ever worked on your device (regardless of the technology
    used to write the driver)?

    d
     
    Doron Holan [MS], Mar 14, 2007
    #4
  5. Neeti

    Neeti Guest

    Hi Doron,

    Yes SelectConfg Has worked with my device when we used NDIS-WDM (here
    we are creating the URB and sending the IRP down) . I have written the
    code in this thread. But now I have ported this piece of code to WDM.
    Please see the code also in the thread. I think I have missed out
    something in configuration.

    I doubt it is due to pipe packetsize. How to set the default
    MaximunPacketSize while configuring in WDM.

    Request you to please compare the code in my earlier thread and give
    some pointers.
     
    Neeti, Mar 14, 2007
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.