Failing controls transfers in VMware

Markus Dolze bsdfan at nurfuerspam.de
Tue Jun 30 20:11:36 UTC 2009


Markus Dolze wrote:
> To repeat run the attached program:
>
>    1. Fill in some vendor / product ID of a device detected as ugen device
>    2. Compile and run the code (devel/libusb must be installed).
>
> The result will look like this:
>
>   
The mailing list didn't send the attachment. Here is the code, put
together from different example programs:

/*
 * A program to test USB control messages
 */

#include <stdio.h>
#include <string.h>
#include <usb.h>

#define USBASP_SHARED_VID   0x16C0
#define USBASP_SHARED_PID   0x05DC

#define TIMEOUT 5000
#define LANGID  0x0409  /* english */

char* usbStringToAscii(char *buffer, int len)
{
    char    buf[256];
    int     i;

    printf("%02x %02x\n", buffer[0], buffer[1]);

    if(buffer[1] != USB_DT_STRING){
        *buf = 0;
        return 0;
    }
    if((unsigned char)buffer[0] < len)
        len = (unsigned char)buffer[0];
    len /= 2;
    /* lossy conversion to ISO Latin1: */
    for(i=1;i<len;i++){
        if(i > sizeof(buf))              /* destination buffer overflow */
            break;
        buf[i-1] = buffer[2 * i];
        if(buffer[2 * i + 1] != 0)  /* outside of ISO Latin1 range */
            buf[i-1] = '?';
    }
    buf[i-1] = 0;
    return strdup(buf);
}


int main(int argc, char *argv[])
{
    struct usb_bus      *bus;
    struct usb_device   *dev;
    usb_dev_handle      *handle = NULL;
    char    string[255];
    int     len;

    usb_init();
    usb_find_busses();
    usb_find_devices();
    for(bus = usb_get_busses(); bus; bus = bus->next) {
        for(dev = bus->devices; dev; dev = dev->next) {
            if((dev->descriptor.idVendor == USBASP_SHARED_VID &&
               dev->descriptor.idProduct == USBASP_SHARED_PID) {
                printf("Found AVR-USB device\n");
               
                handle = usb_open(dev);
                if(!handle) {
                    printf("Warning: cannot open USB device: %s\n",
usb_strerror());
                    continue;
                }

                memset(string, 0, sizeof(string));
                len = usb_control_msg(handle, USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR,
                    (USB_DT_STRING << 8) +
dev->descriptor.iManufacturer, LANGID, string,
                    sizeof(string), TIMEOUT);
                printf("USB_control_msg result: %d\n", len);
                if(len < 0)
                    printf("Warning: cannot query manufacturer for
device: %s\n",
                        usb_strerror());
                else
                    printf("Found device from vendor: %s\n",
usbStringToAscii(string, len));
               
                memset(string, 0, sizeof(string));
                len = usb_control_msg(handle, USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR,
                    (USB_DT_STRING << 8) + dev->descriptor.iProduct,
LANGID, string,
                    sizeof(string), TIMEOUT);
                printf("USB_control_msg result: %d\n", len);
                if(len < 0)
                    printf("Warning: cannot query product: %s\n",
                        usb_strerror());
                else
                    printf("Found device: %s\n",
usbStringToAscii(string, len));
               
                usb_close(handle);
                handle = NULL;
            }
        }
    }

    return 0;
}



More information about the freebsd-usb mailing list