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

{

    USBHubState *s = (USBHubState *)dev;

    int ret;



    switch(p->pid) {

    case USB_TOKEN_IN:

        if (p->devep == 1) {

            USBHubPort *port;

            unsigned int status;

            uint8_t buf[4];

            int i, n;

            n = (NUM_PORTS + 1 + 7) / 8;

            if (p->iov.size == 1) { /* FreeBSD workaround */

                n = 1;

            } else if (n > p->iov.size) {

                return USB_RET_BABBLE;

            }

            status = 0;

            for(i = 0; i < NUM_PORTS; i++) {

                port = &s->ports[i];

                if (port->wPortChange)

                    status |= (1 << (i + 1));

            }

            if (status != 0) {

                for(i = 0; i < n; i++) {

                    buf[i] = status >> (8 * i);

                }

                usb_packet_copy(p, buf, n);

                ret = n;

            } else {

                ret = USB_RET_NAK; /* usb11 11.13.1 */

            }

        } else {

            goto fail;

        }

        break;

    case USB_TOKEN_OUT:

    default:

    fail:

        ret = USB_RET_STALL;

        break;

    }

    return ret;

}

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

{

    USBHubState *s = (USBHubState *)dev;

    int ret;



    switch(p->pid) {

    case USB_TOKEN_IN:

        if (p->devep == 1) {

            USBHubPort *port;

            unsigned int status;

            uint8_t buf[4];

            int i, n;

            n = (NUM_PORTS + 1 + 7) / 8;

            if (p->iov.size == 1) { 

                n = 1;

            } else if (n > p->iov.size) {

                return USB_RET_BABBLE;

            }

            status = 0;

            for(i = 0; i < NUM_PORTS; i++) {

                port = &s->ports[i];

                if (port->wPortChange)

                    status |= (1 << (i + 1));

            }

            if (status != 0) {

                for(i = 0; i < n; i++) {

                    buf[i] = status >> (8 * i);

                }

                usb_packet_copy(p, buf, n);

                ret = n;

            } else {

                ret = USB_RET_NAK; 

            }

        } else {

            goto fail;

        }

        break;

    case USB_TOKEN_OUT:

    default:

    fail:

        ret = USB_RET_STALL;

        break;

    }

    return ret;

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)

{

    USBHubState *s = (USBHubState *)VAR_0;

    int VAR_2;



    switch(VAR_1->pid) {

    case USB_TOKEN_IN:

        if (VAR_1->devep == 1) {

            USBHubPort *port;

            unsigned int VAR_3;

            uint8_t buf[4];

            int VAR_4, VAR_5;

            VAR_5 = (NUM_PORTS + 1 + 7) / 8;

            if (VAR_1->iov.size == 1) { 

                VAR_5 = 1;

            } else if (VAR_5 > VAR_1->iov.size) {

                return USB_RET_BABBLE;

            }

            VAR_3 = 0;

            for(VAR_4 = 0; VAR_4 < NUM_PORTS; VAR_4++) {

                port = &s->ports[VAR_4];

                if (port->wPortChange)

                    VAR_3 |= (1 << (VAR_4 + 1));

            }

            if (VAR_3 != 0) {

                for(VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) {

                    buf[VAR_4] = VAR_3 >> (8 * VAR_4);

                }

                usb_packet_copy(VAR_1, buf, VAR_5);

                VAR_2 = VAR_5;

            } else {

                VAR_2 = USB_RET_NAK; 

            }

        } else {

            goto fail;

        }

        break;

    case USB_TOKEN_OUT:

    default:

    fail:

        VAR_2 = USB_RET_STALL;

        break;

    }

    return VAR_2;

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)
{ USBHubState *s = (USBHubState *)VAR_0; int VAR_2; switch(VAR_1->pid) { case USB_TOKEN_IN:
if (VAR_1->devep == 1) { USBHubPort *port; unsigned int VAR_3; uint8_t buf[4]; int VAR_4, VAR_5; VAR_5 = (NUM_PORTS + 1 + 7) / 8; if (VAR_1->iov.size == 1) { VAR_5 = 1; } else if (VAR_5 > VAR_1->iov.size) { return USB_RET_BABBLE; } VAR_3 = 0; for(VAR_4 = 0; VAR_4 < NUM_PORTS; VAR_4++) { port = &s->ports[VAR_4]; if (port->wPortChange)
VAR_3 |= (1 << (VAR_4 + 1)); } if (VAR_3 != 0) { for(VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) { buf[VAR_4] = VAR_3 >> (8 * VAR_4); } usb_packet_copy(VAR_1, buf, VAR_5); VAR_2 = VAR_5; } else { VAR_2 = USB_RET_NAK; } } else { goto fail; } break; case USB_TOKEN_OUT:
default:
fail:
VAR_2 = USB_RET_STALL; break; } return VAR_2; }