diff options
Diffstat (limited to 'hw/usb-net.c')
-rw-r--r-- | hw/usb-net.c | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/hw/usb-net.c b/hw/usb-net.c index 141d749..f123045 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -627,7 +627,6 @@ struct rndis_response { typedef struct USBNetState { USBDevice dev; - unsigned int rndis; enum rndis_state rndis_state; uint32_t medium; uint32_t speed; @@ -648,6 +647,11 @@ typedef struct USBNetState { QTAILQ_HEAD(rndis_resp_head, rndis_response) rndis_resp; } USBNetState; +static int is_rndis(USBNetState *s) +{ + return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE; +} + static int ndis_query(USBNetState *s, uint32_t oid, uint8_t *inbuf, unsigned int inlen, uint8_t *outbuf, size_t outlen) @@ -1077,8 +1081,9 @@ static int usb_net_handle_control(USBDevice *dev, int request, int value, break; case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND: - if (!s->rndis || value || index != 0) + if (!is_rndis(s) || value || index != 0) { goto fail; + } #ifdef TRAFFIC_DEBUG { unsigned int i; @@ -1095,8 +1100,9 @@ static int usb_net_handle_control(USBDevice *dev, int request, int value, break; case ClassInterfaceRequest | USB_CDC_GET_ENCAPSULATED_RESPONSE: - if (!s->rndis || value || index != 0) + if (!is_rndis(s) || value || index != 0) { goto fail; + } ret = rndis_get_response(s, data); if (!ret) { data[0] = 0; @@ -1116,27 +1122,6 @@ static int usb_net_handle_control(USBDevice *dev, int request, int value, #endif break; - case DeviceRequest | USB_REQ_GET_CONFIGURATION: - data[0] = s->rndis ? DEV_RNDIS_CONFIG_VALUE : DEV_CONFIG_VALUE; - ret = 1; - break; - - case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: - switch (value & 0xff) { - case DEV_CONFIG_VALUE: - s->rndis = 0; - break; - - case DEV_RNDIS_CONFIG_VALUE: - s->rndis = 1; - break; - - default: - goto fail; - } - ret = 0; - break; - case DeviceRequest | USB_REQ_GET_INTERFACE: case InterfaceRequest | USB_REQ_GET_INTERFACE: data[0] = 0; @@ -1207,7 +1192,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p) memcpy(p->data, &s->in_buf[s->in_ptr], ret); s->in_ptr += ret; if (s->in_ptr >= s->in_len && - (s->rndis || (s->in_len & (64 - 1)) || !ret)) { + (is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) { /* no short packet necessary */ s->in_ptr = s->in_len = 0; } @@ -1256,7 +1241,7 @@ static int usb_net_handle_dataout(USBNetState *s, USBPacket *p) memcpy(&s->out_buf[s->out_ptr], p->data, sz); s->out_ptr += sz; - if (!s->rndis) { + if (!is_rndis(s)) { if (ret < 64) { qemu_send_packet(&s->nic->nc, s->out_buf, s->out_ptr); s->out_ptr = 0; @@ -1327,7 +1312,7 @@ static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t si USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; struct rndis_packet_msg_type *msg; - if (s->rndis) { + if (is_rndis(s)) { msg = (struct rndis_packet_msg_type *) s->in_buf; if (!s->rndis_state == RNDIS_DATA_INITIALIZED) return -1; @@ -1363,8 +1348,9 @@ static int usbnet_can_receive(VLANClientState *nc) { USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; - if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED) + if (is_rndis(s) && !s->rndis_state == RNDIS_DATA_INITIALIZED) { return 1; + } return !s->in_len; } @@ -1397,9 +1383,8 @@ static int usb_net_initfn(USBDevice *dev) { USBNetState *s = DO_UPCAST(USBNetState, dev, dev); - s->dev.speed = USB_SPEED_FULL; + usb_desc_init(dev); - s->rndis = 1; s->rndis_state = RNDIS_UNINITIALIZED; QTAILQ_INIT(&s->rndis_resp); |