Am 14.02.2012 18:35, schrieb Tim Roberts:
Do you want to post your code?
Here you are, configuration = 1,
/Uwe
NTSTATUS Usb_set_configuration(PDEVICE_EXTENSION dev, int configuration,
int timeout)
{
NTSTATUS status = STATUS_SUCCESS;
URB urb, *urb_ptr = NULL;
USB_CONFIGURATION_DESCRIPTOR *configuration_descriptor = NULL;
USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;
USBD_INTERFACE_LIST_ENTRY *interfaces = NULL;
int i, j, interface_number, desc_size;
memset(&urb, 0, sizeof(URB));
TRACE(TL_TRACE, (“Usb_set_configuration() Enter\n”));
TRACE(TL_TRACE, (“Usb_get_config_descriptor()\n”));
configuration_descriptor = Usb_get_config_descriptor(dev, configuration,
&desc_size);
if(!configuration_descriptor)
{
TRACE(TL_TRACE, (“Usb_set_configuration(): getting configuration
descriptor failed\n”));
return STATUS_INVALID_PARAMETER;
}
TRACE(TL_TRACE, (“Usb_get_config_descriptor() Exit 0”));
interfaces =
ExAllocatePoolWithTag(NonPagedPool,(configuration_descriptor->bNumInterfaces
* sizeof(USBD_INTERFACE_LIST_ENTRY), ‘SetC’);
if(!interfaces)
{
ExFreePool(configuration_descriptor);
return STATUS_NO_MEMORY;
}
memset(interfaces, 0, (configuration_descriptor->bNumInterfaces + 1)
* sizeof(USBD_INTERFACE_LIST_ENTRY));
interface_number = 0;
TRACE(TL_TRACE, (“Usb_find_interface_desc bNumInterfaces = %d\n”,
configuration_descriptor->bNumInterfaces));
for(i = 0; i < configuration_descriptor->bNumInterfaces; i++)
{
TRACE(TL_TRACE, (“interface_number = %d\n”, interface_number));
for(j = interface_number; j < MAX_NUMBER_OF_INTERFACES; j++)
{
interface_descriptor =
Usb_find_interface_desc(configuration_descriptor,
desc_size, j, 0);
if(interface_descriptor)
{
interface_number = ++j;
break;
}
}
if(!interface_descriptor)
{
TRACE(TL_TRACE, (“Usb_set_configuration(): unable to find
interface descriptor at index %d\n”, i));
ExFreePool(interfaces);
ExFreePool(configuration_descriptor);
return STATUS_INVALID_PARAMETER;
}
else
{
TRACE(TL_TRACE, (“Usb_set_configuration(): found interface
%d\n”, interface_descriptor->bInterfaceNumber));
interfaces[i].InterfaceDescriptor = interface_descriptor;
}
}
TRACE(TL_TRACE, (“USBD_CreateConfigurationRequestEx\n”));
urb_ptr = USBD_CreateConfigurationRequestEx(configuration_descriptor,
interfaces);
if(!urb_ptr)
{
TRACE(TL_TRACE, (“Usb_set_configuration(): memory allocation
failed\n”));
ExFreePool(interfaces);
ExFreePool(configuration_descriptor);
return STATUS_NO_MEMORY;
}
TRACE(TL_TRACE, (“Usb_call_usbd\n”));
status = Usb_call_usbd(dev, urb_ptr, IOCTL_INTERNAL_USB_SUBMIT_URB,
timeout);
if(!NT_SUCCESS(status) || !USBD_SUCCESS(urb_ptr->UrbHeader.Status))
{
TRACE(TL_TRACE, ("Usb_set_configuration(): setting configuration
%d failed: ", configuration));
TRACE(TL_TRACE, (“status: 0x%x”, status));
TRACE(TL_TRACE, (“urb-status: 0x%x\n”, urb_ptr->UrbHeader.Status));
ExFreePool(interfaces);
ExFreePool(urb_ptr);
ExFreePool(configuration_descriptor);
return status;
}
dev->usb.config.handle =
urb_ptr->UrbSelectConfiguration.ConfigurationHandle;
dev->usb.config.value = configuration;
TRACE(TL_TRACE, (“Usb_clear_pipe_info\n”));
Usb_clear_pipe_info(dev);
TRACE(TL_TRACE, (“Usb_update_pipe_info, bNumInterfaces = %d\n”,
configuration_descriptor->bNumInterfaces));
for(i = 0; i < configuration_descriptor->bNumInterfaces; i++)
{
Usb_update_pipe_info(dev, interfaces[i].Interface);
}
ExFreePool(interfaces);
ExFreePool(urb_ptr);
ExFreePool(configuration_descriptor);
TRACE(TL_TRACE, (“Exit Usb_set_configuration() %d\n”, status));
return status;
}
NTSTATUS Usb_call_usbd(PDEVICE_EXTENSION dev, void *urb, ULONG
control_code,
int timeout)
{
KEVENT event;
NTSTATUS status;
IRP *irp;
IO_STACK_LOCATION *next_irp_stack;
IO_STATUS_BLOCK io_status;
io_status.Status = 0;
io_status.Information = 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
TRACE(TL_TRACE, (“IoBuildDeviceIoControlRequest\n”));
irp = IoBuildDeviceIoControlRequest(control_code, dev->StackDeviceObject,
NULL, 0, NULL, 0, TRUE,
&event, &io_status);
if(!irp) {
return STATUS_NO_MEMORY;
}
next_irp_stack = IoGetNextIrpStackLocation(irp);
next_irp_stack->Parameters.Others.Argument1 = urb;
next_irp_stack->Parameters.Others.Argument2 = NULL;
TRACE(TL_TRACE, (“IoCallDriver\n”));
status = IoCallDriver(dev->StackDeviceObject, irp);
if(status == STATUS_PENDING) {
TRACE(TL_TRACE, (“status == STATUS_PENDING\n”));
KeWaitForSingleObject (&event, Executive, KernelMode, FALSE, NULL);
status = io_status.Status;
}
TRACE(TL_TRACE, (“Usb_call_usbd: Exit\n”));
return status;
}