USBDevice *usb_host_device_open(const char *devname)

{

    struct usb_device_info bus_info, dev_info;

    USBDevice *d = NULL;

    USBHostDevice *dev;

    char ctlpath[PATH_MAX + 1];

    char buspath[PATH_MAX + 1];

    int bfd, dfd, bus, address, i;

    int ugendebug = UGEN_DEBUG_LEVEL;



    if (usb_host_find_device(&bus, &address, devname) < 0)

        return NULL;



    snprintf(buspath, PATH_MAX, "/dev/usb%d", bus);



    bfd = open(buspath, O_RDWR);

    if (bfd < 0) {

#ifdef DEBUG

        printf("usb_host_device_open: failed to open usb bus - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



    bus_info.udi_addr = address;

    if (ioctl(bfd, USB_DEVICEINFO, &bus_info) < 0) {

#ifdef DEBUG

        printf("usb_host_device_open: failed to grab bus information - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)

    snprintf(ctlpath, PATH_MAX, "/dev/%s", bus_info.udi_devnames[0]);

#else

    snprintf(ctlpath, PATH_MAX, "/dev/%s.00", bus_info.udi_devnames[0]);

#endif



    dfd  = open(ctlpath, O_RDWR);

    if (dfd < 0) {

        dfd = open(ctlpath, O_RDONLY);

        if (dfd < 0) {

#ifdef DEBUG

            printf("usb_host_device_open: failed to open usb device %s - %s\n",

                   ctlpath, strerror(errno));

#endif

        }

    }



    if (dfd >= 0) {

        if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {

#ifdef DEBUG

            printf("usb_host_device_open: failed to grab device info - %s\n",

                   strerror(errno));

#endif

            goto fail;

        }



        d = usb_create(NULL /* FIXME */, "usb-host");

        dev = DO_UPCAST(USBHostDevice, dev, d);



        if (dev_info.udi_speed == 1)

            dev->dev.speed = USB_SPEED_LOW - 1;

        else

            dev->dev.speed = USB_SPEED_FULL - 1;



        if (strncmp(dev_info.udi_product, "product", 7) != 0)

            pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                    dev_info.udi_product);

        else

            snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                     "host:%s", devname);



        pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");

        pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);



        /* Mark the endpoints as not yet open */

        for (i = 0; i < USB_MAX_ENDPOINTS; i++)

           dev->ep_fd[i] = -1;



        ioctl(dfd, USB_SETDEBUG, &ugendebug);



        return (USBDevice *)dev;

    }



fail:

    return NULL;

}

USBDevice *usb_host_device_open(const char *devname)

{

    struct usb_device_info bus_info, dev_info;

    USBDevice *d = NULL;

    USBHostDevice *dev;

    char ctlpath[PATH_MAX + 1];

    char buspath[PATH_MAX + 1];

    int bfd, dfd, bus, address, i;

    int ugendebug = UGEN_DEBUG_LEVEL;



    if (usb_host_find_device(&bus, &address, devname) < 0)

        return NULL;



    snprintf(buspath, PATH_MAX, "/dev/usb%d", bus);



    bfd = open(buspath, O_RDWR);

    if (bfd < 0) {

#ifdef DEBUG

        printf("usb_host_device_open: failed to open usb bus - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



    bus_info.udi_addr = address;

    if (ioctl(bfd, USB_DEVICEINFO, &bus_info) < 0) {

#ifdef DEBUG

        printf("usb_host_device_open: failed to grab bus information - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)

    snprintf(ctlpath, PATH_MAX, "/dev/%s", bus_info.udi_devnames[0]);

#else

    snprintf(ctlpath, PATH_MAX, "/dev/%s.00", bus_info.udi_devnames[0]);

#endif



    dfd  = open(ctlpath, O_RDWR);

    if (dfd < 0) {

        dfd = open(ctlpath, O_RDONLY);

        if (dfd < 0) {

#ifdef DEBUG

            printf("usb_host_device_open: failed to open usb device %s - %s\n",

                   ctlpath, strerror(errno));

#endif

        }

    }



    if (dfd >= 0) {

        if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {

#ifdef DEBUG

            printf("usb_host_device_open: failed to grab device info - %s\n",

                   strerror(errno));

#endif

            goto fail;

        }



        d = usb_create(NULL , "usb-host");

        dev = DO_UPCAST(USBHostDevice, dev, d);



        if (dev_info.udi_speed == 1)

            dev->dev.speed = USB_SPEED_LOW - 1;

        else

            dev->dev.speed = USB_SPEED_FULL - 1;



        if (strncmp(dev_info.udi_product, "product", 7) != 0)

            pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                    dev_info.udi_product);

        else

            snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                     "host:%s", devname);



        pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");

        pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);



        

        for (i = 0; i < USB_MAX_ENDPOINTS; i++)

           dev->ep_fd[i] = -1;



        ioctl(dfd, USB_SETDEBUG, &ugendebug);



        return (USBDevice *)dev;

    }



fail:

    return NULL;

}

    USBHostDevice *dev;     if (usb_host_find_device(&bus, &address, devname) < 0)         return NULL;         return NULL;         return NULL;     if (dfd >= 0) {         if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {             printf("usb_host_device_open: failed to grab device info - %s\n",                    strerror(errno));             goto fail;         dev = DO_UPCAST(USBHostDevice, dev, d);         if (dev_info.udi_speed == 1)             dev->dev.speed = USB_SPEED_LOW - 1;             dev->dev.speed = USB_SPEED_FULL - 1;         if (strncmp(dev_info.udi_product, "product", 7) != 0)             pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),                     dev_info.udi_product);             snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),                      "host:%s", devname);         pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");         pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);         for (i = 0; i < USB_MAX_ENDPOINTS; i++)            dev->ep_fd[i] = -1;         ioctl(dfd, USB_SETDEBUG, &ugendebug);         return (USBDevice *)dev;     return NULL;
USBDevice *FUNC_0(const char *devname)

{

    struct usb_device_info VAR_0, VAR_1;

    USBDevice *d = NULL;

    USBHostDevice *dev;

    char VAR_2[PATH_MAX + 1];

    char VAR_3[PATH_MAX + 1];

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    int VAR_9 = UGEN_DEBUG_LEVEL;



    if (usb_host_find_device(&VAR_6, &VAR_7, devname) < 0)

        return NULL;



    snprintf(VAR_3, PATH_MAX, "/dev/usb%d", VAR_6);



    VAR_4 = open(VAR_3, O_RDWR);

    if (VAR_4 < 0) {

#ifdef DEBUG

        printf("FUNC_0: failed to open usb VAR_6 - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



    VAR_0.udi_addr = VAR_7;

    if (ioctl(VAR_4, USB_DEVICEINFO, &VAR_0) < 0) {

#ifdef DEBUG

        printf("FUNC_0: failed to grab VAR_6 information - %s\n",

               strerror(errno));

#endif

        return NULL;

    }



#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)

    snprintf(VAR_2, PATH_MAX, "/dev/%s", VAR_0.udi_devnames[0]);

#else

    snprintf(VAR_2, PATH_MAX, "/dev/%s.00", VAR_0.udi_devnames[0]);

#endif



    VAR_5  = open(VAR_2, O_RDWR);

    if (VAR_5 < 0) {

        VAR_5 = open(VAR_2, O_RDONLY);

        if (VAR_5 < 0) {

#ifdef DEBUG

            printf("FUNC_0: failed to open usb device %s - %s\n",

                   VAR_2, strerror(errno));

#endif

        }

    }



    if (VAR_5 >= 0) {

        if (ioctl(VAR_5, USB_GET_DEVICEINFO, &VAR_1) < 0) {

#ifdef DEBUG

            printf("FUNC_0: failed to grab device info - %s\n",

                   strerror(errno));

#endif

            goto fail;

        }



        d = usb_create(NULL , "usb-host");

        dev = DO_UPCAST(USBHostDevice, dev, d);



        if (VAR_1.udi_speed == 1)

            dev->dev.speed = USB_SPEED_LOW - 1;

        else

            dev->dev.speed = USB_SPEED_FULL - 1;



        if (strncmp(VAR_1.udi_product, "product", 7) != 0)

            pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                    VAR_1.udi_product);

        else

            snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),

                     "host:%s", devname);



        pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");

        pstrcat(dev->devpath, sizeof(dev->devpath), VAR_1.udi_devnames[0]);



        

        for (VAR_8 = 0; VAR_8 < USB_MAX_ENDPOINTS; VAR_8++)

           dev->ep_fd[VAR_8] = -1;



        ioctl(VAR_5, USB_SETDEBUG, &VAR_9);



        return (USBDevice *)dev;

    }



fail:

    return NULL;

}

USBDevice *FUNC_0(const char *devname)
{ struct usb_device_info VAR_0, VAR_1; USBDevice *d = NULL; USBHostDevice *dev; char VAR_2[PATH_MAX + 1]; char VAR_3[PATH_MAX + 1]; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; int VAR_9 = UGEN_DEBUG_LEVEL; if (usb_host_find_device(&VAR_6, &VAR_7, devname) < 0)
return NULL; snprintf(VAR_3, PATH_MAX, "/dev/usb%d", VAR_6); VAR_4 = open(VAR_3, O_RDWR); if (VAR_4 < 0) { #ifdef DEBUG
printf("FUNC_0: failed to open usb VAR_6 - %s\n",
strerror(errno)); #endif
return NULL; } VAR_0.udi_addr = VAR_7; if (ioctl(VAR_4, USB_DEVICEINFO, &VAR_0) < 0) { #ifdef DEBUG
printf("FUNC_0: failed to grab VAR_6 information - %s\n",
strerror(errno)); #endif
return NULL; } #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
snprintf(VAR_2, PATH_MAX, "/dev/%s", VAR_0.udi_devnames[0]); #else
snprintf(VAR_2, PATH_MAX, "/dev/%s.00", VAR_0.udi_devnames[0]); #endif
VAR_5  = open(VAR_2, O_RDWR); if (VAR_5 < 0) { VAR_5 = open(VAR_2, O_RDONLY); if (VAR_5 < 0) { #ifdef DEBUG
printf("FUNC_0: failed to open usb device %s - %s\n",
VAR_2, strerror(errno)); #endif
} } if (VAR_5 >= 0) { if (ioctl(VAR_5, USB_GET_DEVICEINFO, &VAR_1) < 0) { #ifdef DEBUG
printf("FUNC_0: failed to grab device info - %s\n",
strerror(errno)); #endif
goto fail; } d = usb_create(NULL , "usb-host"); dev = DO_UPCAST(USBHostDevice, dev, d); if (VAR_1.udi_speed == 1)
dev->dev.speed = USB_SPEED_LOW - 1; else
dev->dev.speed = USB_SPEED_FULL - 1; if (strncmp(VAR_1.udi_product, "product", 7) != 0)
pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),
VAR_1.udi_product); else
snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),
"host:%s", devname); pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/"); pstrcat(dev->devpath, sizeof(dev->devpath), VAR_1.udi_devnames[0]); for (VAR_8 = 0; VAR_8 < USB_MAX_ENDPOINTS; VAR_8++) dev->ep_fd[VAR_8] = -1; ioctl(VAR_5, USB_SETDEBUG, &VAR_9); return (USBDevice *)dev; } fail:
return NULL; }