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-
>Adapter.FUsbDevice,
&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.