On Fri, 27 May 2005, Wakko Warner wrote:

> Any pointers on how to write this?  I will be writing this in perl.  The
> target system is mostly perl based (it's sorta like embedded but runs off a
> tmpfs filesystem)

Here is a program, dq.c, that demonstrates how to read the device
qualifier descriptor.  It uses a local copy of the usb_ch9.h include file,
which is present in the kernel source under include/linux but was not
stored in /usr/include/linux on my system.  Note that the program needs
root permission to run properly.  It takes a single argument, which is the
/proc/bus/usb/BBB/DDD pathname for the device.

Alan Stern


#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <asm/byteorder.h>
#include <linux/usbdevice_fs.h>

typedef __u16 __le16;           /* may not be needed */
#include "usb_ch9.h"            /* may exist in /usr/include/linux */


int get_version(int fd)
{
        struct usb_device_descriptor desc;
        int n;

        n = read(fd, &desc, sizeof(desc));
        if (n < 0) {
                perror("Error in read");
                return n;
        }

        return __le16_to_cpu(desc.bcdUSB);
}

int get_qualifier(int fd)
{
        struct usbdevfs_ctrltransfer ctrl;
        struct usb_qualifier_descriptor desc;
        int n;

        ctrl.requesttype = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
        ctrl.request = USB_REQ_GET_DESCRIPTOR;
        ctrl.value = USB_DT_DEVICE_QUALIFIER << 8;
        ctrl.index = 0;
        ctrl.length = sizeof(desc);
        ctrl.timeout = 5000;
        ctrl.data = &desc;

        n = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
        if (n < 0) {
                if (errno == EPIPE)     /* Request not supported */
                        return 0;
                perror("Error in USBDEVFS_CONTROL");
                return n;
        }

        return 1;
}


int main(int argc, char **argv)
{
        int fd;
        int version;
        int qualifier;

        if (argc != 2) {
                fprintf(stderr, "Usage: dq device_filename\n");
                return 1;
        }

        fd = open(argv[1], O_RDWR);
        if (fd < 0) {
                perror("Error in open");
                return 1;
        }

        version = get_version(fd);
        if (version < 0)
                return 1;
        printf("USB version is 0x%04x.\n", version);
        if (version < 0x0200)
                return 2;

        qualifier = get_qualifier(fd);
        if (qualifier < 0)
                return 1;
        printf("Device %s high speed.\n",
                        qualifier ? "supports" : "does not support");
        return 0;
}



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to