I am now working for adding libusb-win32 isochronous transfer into Qemu(a open source simulator acts like vmare).
In Qemu,simulated os writes its usb TD into fake UCHI which is a component of Qemu.Fake UCHI will transfer TD into USB packet ,and finally passes these packets to function usb_host_handle_data().
Setting the usb devices into a proper state is the job of simulated os,Qemu just initializes the usb interfaces of usb device by standard libusb-win32 steps:
usb_init();
usb_set_debug(255);
usb_find_busses();
usb_find_devices();
usb_get_descriptor();
usb_set_configuration(udev, 1);
for (interface = 0; interface < nb_interfaces; interface++) {
ret = usb_claim_interface(udev, interface);
}
Once the usb interfaces is initialized,Qemu's responsibility is transferring USB request to libusb-win32.
Here is the key functions which plays roles of transferring USB request:
static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
{
USBHostDevice *s = (USBHostDevice *)dev;
int ret = 0;
uint8_t devep = p->devep;
int pid = p->pid;
uint8_t *data = p->data;
int len = p->len;
int transmitted = 0;
void *context1 = NULL;
/* XXX: optimize and handle all data types by looking at the
config descriptor */
if (pid == USB_TOKEN_IN)
devep |= 0x80;
/*************************************************
isochronous transfer
**********************************************/
#define TD_CTRL_IOS (1 << 25)
/*check if this td is isochronous td*/
if(p->ctrl & TD_CTRL_IOS){
if(devep| 0x80){
printf("opt is read\n");
}
else{
printf("opt is write\n");
}
do{
/*the simulated os has devided usb request into packets whose size is
no larger than wMaxPacketSize,
so we used len of this packet as parameter packetsize*/
usb_isochronous_setup_async(s->udev,&context1,devep,len);
ret = usb_submit_async(context1, data, len);
if(ret < 0)
{
transmitted = ret;
break;
}
ret = usb_reap_async_nocancel(context1, 50);
if(ret < 0)
{
if(ret==-5){
transmitted = len;
printf("error in iso ignore it \n");
}
else
{
transmitted = ret;
}
}
}while(0)
usb_free_async(&context1);
return transmitted;
}
}
It seems that the isochronous packets can't be sent by libusb-win32.
The libusb-win32 report errors(capture form debugview):
/*In the beginning, libusb-win32 succeeds in transferring
one isochronous packet.
However it fails subsequently*/
00003503 11295.52636719
LIBUSB-DRIVER - transfer(): isochronous transfer
00003504 11295.52636719
LIBUSB-DRIVER - transfer(): direction out
00003505 11295.52636719
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003506 11295.52636719
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003507 11295.52636719
LIBUSB-DRIVER - transfer(): size 192
00003508 11295.52636719
LIBUSB-DRIVER - transfer(): sequence 2530
00003509 11295.52636719
00003510 11295.53222656
LIBUSB-DRIVER - transfer_complete(): sequence 2530: 192 bytes transmitted
00003511 11295.53906250
00003512 11295.53906250
00003513 11295.53906250
LIBUSB-DRIVER - transfer(): isochronous transfer
00003514 11295.53906250
LIBUSB-DRIVER - transfer(): direction out
00003515 11295.53906250
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003516 11295.53906250
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003517 11295.53906250
LIBUSB-DRIVER - transfer(): size 192
00003518 11295.53906250
LIBUSB-DRIVER - transfer(): sequence 2531
00003519 11295.53906250
00003520 11295.53906250
LIBUSB-DRIVER - transfer_complete(): sequence 2531: transfer failed: status: 0xc0000001, urb-status: 0xc0000b00
00003521 11295.54589844
[6052] LIBUSB_DLL: error: usb_reap: reaping request failed, win error: A device attached to the system is not functioning.
00003522 11295.54589844 [6052]
00003523 11295.54785156
00003524 11295.54785156
00003525 11295.54785156
LIBUSB-DRIVER - transfer(): isochronous transfer
00003526 11295.54785156
LIBUSB-DRIVER - transfer(): direction out
00003527 11295.54785156
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003528 11295.54785156
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003529 11295.54785156
LIBUSB-DRIVER - transfer(): size 192
00003530 11295.54785156
LIBUSB-DRIVER - transfer(): sequence 2532
00003531 11295.54785156
00003532 11295.54785156
LIBUSB-DRIVER - transfer_complete(): sequence 2532: transfer failed: status: 0xc0000001, urb-status: 0xc0000b00
00003533 11295.55859375
00003534 11295.55859375
00003535 11295.55859375
LIBUSB-DRIVER - transfer(): isochronous transfer
00003536 11295.55859375
LIBUSB-DRIVER - transfer(): direction out
00003537 11295.55859375
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003538 11295.55859375
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003539 11295.55859375
LIBUSB-DRIVER - transfer(): size 192
00003540 11295.55859375
LIBUSB-DRIVER - transfer(): sequence 2533
00003541 11295.55859375
00003542 11295.55859375
LIBUSB-DRIVER - transfer_complete(): sequence 2533: transfer failed: status: 0xc0000001, urb-status: 0xc0000b00
00003543 11295.56152344
[6052] LIBUSB_DLL: error: usb_reap: reaping request failed, win error: A device attached to the system is not functioning.
00003544 11295.56152344 [6052]
00003545 11295.56738281
00003546 11295.56738281
00003547 11295.56738281
LIBUSB-DRIVER - transfer(): isochronous transfer
00003548 11295.56738281
LIBUSB-DRIVER - transfer(): direction out
00003549 11295.56738281
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003550 11295.56738281
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003551 11295.56738281
LIBUSB-DRIVER - transfer(): size 192
00003552 11295.56738281
LIBUSB-DRIVER - transfer(): sequence 2534
00003553 11295.56738281
00003554 11295.56738281
LIBUSB-DRIVER - transfer_complete(): sequence 2534: transfer failed: status: 0xc0000001, urb-status: 0xc0000b00
00003555 11295.59765625
[6052] LIBUSB_DLL: error: usb_reap: reaping request failed, win error: A device attached to the system is not functioning.
00003556 11295.59765625 [6052]
00003557 11295.60156250
00003558 11295.60156250
00003559 11295.60156250
LIBUSB-DRIVER - transfer(): isochronous transfer
00003560 11295.60156250
LIBUSB-DRIVER - transfer(): direction out
00003561 11295.60156250
LIBUSB-DRIVER - transfer(): endpoint 0x06
00003562 11295.60156250
LIBUSB-DRIVER - transfer(): packet_size 0xc0
00003563 11295.60156250
LIBUSB-DRIVER - transfer(): size 192
00003564 11295.60156250
LIBUSB-DRIVER - transfer(): sequence 2535
00003565 11295.60156250
00003566 11295.60156250
LIBUSB-DRIVER - transfer_complete(): sequence 2535: transfer failed: status: 0xc0000001, urb-status: 0xc0000b00
00003567 11295.61718750
[6052] LIBUSB_DLL: error: usb_reap: reaping request failed, win error: A device attached to the system is not functioning.
00003568 11295.61718750 [6052]
Here is my usb device information:
bus/device idVendor/idProduct
bus-0/\\.\libusb0-0001--0x0d8c-0x0103 0D8C/0103
- Manufacturer : C-Media INC.
- Product : USB Sound Device
wTotalLength: 116
bNumInterfaces: 2
bConfigurationValue: 1
iConfiguration: 0
bmAttributes: 80h
MaxPower: 250
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 1
bInterfaceSubClass: 1
bInterfaceProtocol: 0
iInterface: 0
bInterfaceNumber: 1
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 1
bInterfaceSubClass: 2
bInterfaceProtocol: 0
iInterface: 0
bInterfaceNumber: 1
bAlternateSetting: 1
bNumEndpoints: 1
bInterfaceClass: 1
bInterfaceSubClass: 2
bInterfaceProtocol: 0
iInterface: 0
bEndpointAddress: 06h
bmAttributes: 09h
wMaxPacketSize: 192
bInterval: 1
bRefresh: 0
bSynchAddress: 0
Any suggestions will be appreciated.
Best regards,
Marshal_CD