* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include "trace.h"
#include "hw/usb.h"
#include "hw/usb/desc.h"
-//#define DEBUG
-
#define NUM_PORTS 8
typedef struct USBHubPort {
};
static const USBDescStrings desc_strings = {
- [STR_MANUFACTURER] = "QEMU " QEMU_VERSION,
+ [STR_MANUFACTURER] = "QEMU",
[STR_PRODUCT] = "QEMU USB Hub",
[STR_SERIALNUMBER] = "314159",
};
USBHubState *s = port1->opaque;
USBHubPort *port = &s->ports[port1->index];
+ trace_usb_hub_attach(s->dev.addr, port1->index + 1);
port->wPortStatus |= PORT_STAT_CONNECTION;
port->wPortChange |= PORT_STAT_C_CONNECTION;
if (port->port.dev->speed == USB_SPEED_LOW) {
USBHubState *s = port1->opaque;
USBHubPort *port = &s->ports[port1->index];
+ trace_usb_hub_detach(s->dev.addr, port1->index + 1);
usb_wakeup(s->intr);
/* Let upstream know the device on this port is gone */
port->wPortStatus &= ~PORT_STAT_ENABLE;
port->wPortChange |= PORT_STAT_C_ENABLE;
}
+ usb_wakeup(s->intr);
}
static void usb_hub_child_detach(USBPort *port1, USBDevice *child)
USBHubPort *port;
int i;
+ trace_usb_hub_reset(s->dev.addr);
for (i = 0; i < NUM_PORTS; i++) {
port = s->ports + i;
port->wPortStatus = PORT_STAT_POWER;
}
}
-static int usb_hub_handle_control(USBDevice *dev, USBPacket *p,
+static const char *feature_name(int feature)
+{
+ static const char *name[] = {
+ [PORT_CONNECTION] = "connection",
+ [PORT_ENABLE] = "enable",
+ [PORT_SUSPEND] = "suspend",
+ [PORT_OVERCURRENT] = "overcurrent",
+ [PORT_RESET] = "reset",
+ [PORT_POWER] = "power",
+ [PORT_LOWSPEED] = "lowspeed",
+ [PORT_HIGHSPEED] = "highspeed",
+ [PORT_C_CONNECTION] = "change connection",
+ [PORT_C_ENABLE] = "change enable",
+ [PORT_C_SUSPEND] = "change suspend",
+ [PORT_C_OVERCURRENT] = "change overcurrent",
+ [PORT_C_RESET] = "change reset",
+ [PORT_TEST] = "test",
+ [PORT_INDICATOR] = "indicator",
+ };
+ if (feature < 0 || feature >= ARRAY_SIZE(name)) {
+ return "?";
+ }
+ return name[feature] ?: "?";
+}
+
+static void usb_hub_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
USBHubState *s = (USBHubState *)dev;
int ret;
+ trace_usb_hub_control(s->dev.addr, request, value, index, length);
+
ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
if (ret >= 0) {
- return ret;
+ return;
}
switch(request) {
if (value == 0 && index != 0x81) { /* clear ep halt */
goto fail;
}
- ret = 0;
break;
/* usb specific requests */
case GetHubStatus:
data[1] = 0;
data[2] = 0;
data[3] = 0;
- ret = 4;
+ p->actual_length = 4;
break;
case GetPortStatus:
{
goto fail;
}
port = &s->ports[n];
+ trace_usb_hub_get_port_status(s->dev.addr, index,
+ port->wPortStatus,
+ port->wPortChange);
data[0] = port->wPortStatus;
data[1] = port->wPortStatus >> 8;
data[2] = port->wPortChange;
data[3] = port->wPortChange >> 8;
- ret = 4;
+ p->actual_length = 4;
}
break;
case SetHubFeature:
case ClearHubFeature:
- if (value == 0 || value == 1) {
- } else {
+ if (value != 0 && value != 1) {
goto fail;
}
- ret = 0;
break;
case SetPortFeature:
{
unsigned int n = index - 1;
USBHubPort *port;
USBDevice *dev;
+
+ trace_usb_hub_set_port_feature(s->dev.addr, index,
+ feature_name(value));
+
if (n >= NUM_PORTS) {
goto fail;
}
port->wPortChange |= PORT_STAT_C_RESET;
/* set enable bit */
port->wPortStatus |= PORT_STAT_ENABLE;
+ usb_wakeup(s->intr);
}
break;
case PORT_POWER:
default:
goto fail;
}
- ret = 0;
}
break;
case ClearPortFeature:
unsigned int n = index - 1;
USBHubPort *port;
+ trace_usb_hub_clear_port_feature(s->dev.addr, index,
+ feature_name(value));
+
if (n >= NUM_PORTS) {
goto fail;
}
default:
goto fail;
}
- ret = 0;
}
break;
case GetHubDescriptor:
var_hub_size++;
}
- ret = sizeof(qemu_hub_hub_descriptor) + var_hub_size;
- data[0] = ret;
+ p->actual_length = sizeof(qemu_hub_hub_descriptor) + var_hub_size;
+ data[0] = p->actual_length;
break;
}
default:
fail:
- ret = USB_RET_STALL;
+ p->status = USB_RET_STALL;
break;
}
- return ret;
}
-static int usb_hub_handle_data(USBDevice *dev, USBPacket *p)
+static void usb_hub_handle_data(USBDevice *dev, USBPacket *p)
{
USBHubState *s = (USBHubState *)dev;
- int ret;
switch(p->pid) {
case USB_TOKEN_IN:
if (p->iov.size == 1) { /* FreeBSD workaround */
n = 1;
} else if (n > p->iov.size) {
- return USB_RET_BABBLE;
+ p->status = USB_RET_BABBLE;
+ return;
}
status = 0;
for(i = 0; i < NUM_PORTS; i++) {
buf[i] = status >> (8 * i);
}
usb_packet_copy(p, buf, n);
- ret = n;
} else {
- ret = USB_RET_NAK; /* usb11 11.13.1 */
+ p->status = USB_RET_NAK; /* usb11 11.13.1 */
}
} else {
goto fail;
case USB_TOKEN_OUT:
default:
fail:
- ret = USB_RET_STALL;
+ p->status = USB_RET_STALL;
break;
}
- return ret;
}
static void usb_hub_handle_destroy(USBDevice *dev)
USBHubPort *port;
int i;
+ usb_desc_create_serial(dev);
usb_desc_init(dev);
s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
for (i = 0; i < NUM_PORTS; i++) {