static int usb_host_handle_data(USBDevice *dev, USBPacket *p)

{

    USBHostDevice *s = (USBHostDevice *)dev;

    int ret, fd, mode;

    int one = 1, shortpacket = 0, timeout = 50;

    sigset_t new_mask, old_mask;

    uint8_t devep = p->devep;



    /* protect data transfers from SIGALRM signal */

    sigemptyset(&new_mask);

    sigaddset(&new_mask, SIGALRM);

    sigprocmask(SIG_BLOCK, &new_mask, &old_mask);



    if (p->pid == USB_TOKEN_IN) {

        devep |= 0x80;

        mode = O_RDONLY;

        shortpacket = 1;

    } else {

        mode = O_WRONLY;

    }



    fd = ensure_ep_open(s, devep, mode);

    if (fd < 0) {

        sigprocmask(SIG_SETMASK, &old_mask, NULL);

        return USB_RET_NODEV;

    }



    if (ioctl(fd, USB_SET_TIMEOUT, &timeout) < 0) {

#ifdef DEBUG

        printf("handle_data: failed to set timeout - %s\n",

               strerror(errno));

#endif

    }



    if (shortpacket) {

        if (ioctl(fd, USB_SET_SHORT_XFER, &one) < 0) {

#ifdef DEBUG

            printf("handle_data: failed to set short xfer mode - %s\n",

                   strerror(errno));

#endif

            sigprocmask(SIG_SETMASK, &old_mask, NULL);

        }

    }



    if (p->pid == USB_TOKEN_IN)

        ret = read(fd, p->data, p->len);

    else

        ret = write(fd, p->data, p->len);



    sigprocmask(SIG_SETMASK, &old_mask, NULL);



    if (ret < 0) {

#ifdef DEBUG

        printf("handle_data: error after %s data - %s\n",

               pid == USB_TOKEN_IN ? "reading" : "writing", strerror(errno));

#endif

        switch(errno) {

        case ETIMEDOUT:

        case EINTR:

            return USB_RET_NAK;

        default:

            return USB_RET_STALL;

        }

    } else {

        return ret;

    }

}

static int usb_host_handle_data(USBDevice *dev, USBPacket *p)

{

    USBHostDevice *s = (USBHostDevice *)dev;

    int ret, fd, mode;

    int one = 1, shortpacket = 0, timeout = 50;

    sigset_t new_mask, old_mask;

    uint8_t devep = p->devep;



    

    sigemptyset(&new_mask);

    sigaddset(&new_mask, SIGALRM);

    sigprocmask(SIG_BLOCK, &new_mask, &old_mask);



    if (p->pid == USB_TOKEN_IN) {

        devep |= 0x80;

        mode = O_RDONLY;

        shortpacket = 1;

    } else {

        mode = O_WRONLY;

    }



    fd = ensure_ep_open(s, devep, mode);

    if (fd < 0) {

        sigprocmask(SIG_SETMASK, &old_mask, NULL);

        return USB_RET_NODEV;

    }



    if (ioctl(fd, USB_SET_TIMEOUT, &timeout) < 0) {

#ifdef DEBUG

        printf("handle_data: failed to set timeout - %s\n",

               strerror(errno));

#endif

    }



    if (shortpacket) {

        if (ioctl(fd, USB_SET_SHORT_XFER, &one) < 0) {

#ifdef DEBUG

            printf("handle_data: failed to set short xfer mode - %s\n",

                   strerror(errno));

#endif

            sigprocmask(SIG_SETMASK, &old_mask, NULL);

        }

    }



    if (p->pid == USB_TOKEN_IN)

        ret = read(fd, p->data, p->len);

    else

        ret = write(fd, p->data, p->len);



    sigprocmask(SIG_SETMASK, &old_mask, NULL);



    if (ret < 0) {

#ifdef DEBUG

        printf("handle_data: error after %s data - %s\n",

               pid == USB_TOKEN_IN ? "reading" : "writing", strerror(errno));

#endif

        switch(errno) {

        case ETIMEDOUT:

        case EINTR:

            return USB_RET_NAK;

        default:

            return USB_RET_STALL;

        }

    } else {

        return ret;

    }

}

        ret = read(fd, p->data, p->len);         ret = write(fd, p->data, p->len);
static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)

{

    USBHostDevice *s = (USBHostDevice *)VAR_0;

    int VAR_2, VAR_3, VAR_4;

    int VAR_5 = 1, VAR_6 = 0, VAR_7 = 50;

    sigset_t new_mask, old_mask;

    uint8_t devep = VAR_1->devep;



    

    sigemptyset(&new_mask);

    sigaddset(&new_mask, SIGALRM);

    sigprocmask(SIG_BLOCK, &new_mask, &old_mask);



    if (VAR_1->pid == USB_TOKEN_IN) {

        devep |= 0x80;

        VAR_4 = O_RDONLY;

        VAR_6 = 1;

    } else {

        VAR_4 = O_WRONLY;

    }



    VAR_3 = ensure_ep_open(s, devep, VAR_4);

    if (VAR_3 < 0) {

        sigprocmask(SIG_SETMASK, &old_mask, NULL);

        return USB_RET_NODEV;

    }



    if (ioctl(VAR_3, USB_SET_TIMEOUT, &VAR_7) < 0) {

#ifdef DEBUG

        printf("handle_data: failed to set VAR_7 - %s\n",

               strerror(errno));

#endif

    }



    if (VAR_6) {

        if (ioctl(VAR_3, USB_SET_SHORT_XFER, &VAR_5) < 0) {

#ifdef DEBUG

            printf("handle_data: failed to set short xfer VAR_4 - %s\n",

                   strerror(errno));

#endif

            sigprocmask(SIG_SETMASK, &old_mask, NULL);

        }

    }



    if (VAR_1->pid == USB_TOKEN_IN)

        VAR_2 = read(VAR_3, VAR_1->data, VAR_1->len);

    else

        VAR_2 = write(VAR_3, VAR_1->data, VAR_1->len);



    sigprocmask(SIG_SETMASK, &old_mask, NULL);



    if (VAR_2 < 0) {

#ifdef DEBUG

        printf("handle_data: error after %s data - %s\n",

               pid == USB_TOKEN_IN ? "reading" : "writing", strerror(errno));

#endif

        switch(errno) {

        case ETIMEDOUT:

        case EINTR:

            return USB_RET_NAK;

        default:

            return USB_RET_STALL;

        }

    } else {

        return VAR_2;

    }

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)
{ USBHostDevice *s = (USBHostDevice *)VAR_0; int VAR_2, VAR_3, VAR_4; int VAR_5 = 1, VAR_6 = 0, VAR_7 = 50; sigset_t new_mask, old_mask; uint8_t devep = VAR_1->devep; sigemptyset(&new_mask); sigaddset(&new_mask, SIGALRM); sigprocmask(SIG_BLOCK, &new_mask, &old_mask); if (VAR_1->pid == USB_TOKEN_IN) { devep |= 0x80; VAR_4 = O_RDONLY; VAR_6 = 1; } else { VAR_4 = O_WRONLY; } VAR_3 = ensure_ep_open(s, devep, VAR_4); if (VAR_3 < 0) { sigprocmask(SIG_SETMASK, &old_mask, NULL); return USB_RET_NODEV; } if (ioctl(VAR_3, USB_SET_TIMEOUT, &VAR_7) < 0) { #ifdef DEBUG
printf("handle_data: failed to set VAR_7 - %s\n",
strerror(errno)); #endif
} if (VAR_6) { if (ioctl(VAR_3, USB_SET_SHORT_XFER, &VAR_5) < 0) { #ifdef DEBUG
printf("handle_data: failed to set short xfer VAR_4 - %s\n",
strerror(errno)); #endif
sigprocmask(SIG_SETMASK, &old_mask, NULL); } } if (VAR_1->pid == USB_TOKEN_IN)
VAR_2 = read(VAR_3, VAR_1->data, VAR_1->len); else
VAR_2 = write(VAR_3, VAR_1->data, VAR_1->len); sigprocmask(SIG_SETMASK, &old_mask, NULL); if (VAR_2 < 0) { #ifdef DEBUG
printf("handle_data: error after %s data - %s\n",
pid == USB_TOKEN_IN ? "reading" : "writing", strerror(errno)); #endif
switch(errno) { case ETIMEDOUT:
case EINTR:
return USB_RET_NAK; default:
return USB_RET_STALL; } } else { return VAR_2; } }