Merge branch 'master' of /home/nchip/public_html/qemu into garage-push
[qemu] / hw / usb-net.c
index a4714c5..9e64425 100644 (file)
@@ -628,14 +628,13 @@ static int ndis_query(USBNetState *s, uint32_t oid,
                       uint8_t *inbuf, unsigned int inlen, uint8_t *outbuf,
                       size_t outlen)
 {
-    unsigned int i, count;
+    unsigned int i;
 
     switch (oid) {
     /* general oids (table 4-1) */
     /* mandatory */
     case OID_GEN_SUPPORTED_LIST:
-        count = sizeof(oid_supported_list) / sizeof(uint32_t);
-        for (i = 0; i < count; i++)
+        for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++)
             ((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]);
         return sizeof(oid_supported_list);
 
@@ -681,8 +680,8 @@ static int ndis_query(USBNetState *s, uint32_t oid,
 
     /* mandatory */
     case OID_GEN_VENDOR_DESCRIPTION:
-        pstrcpy(outbuf, outlen, "QEMU USB RNDIS Net");
-        return strlen(outbuf) + 1;
+        pstrcpy((char *)outbuf, outlen, "QEMU USB RNDIS Net");
+        return strlen((char *)outbuf) + 1;
 
     case OID_GEN_VENDOR_DRIVER_VERSION:
         *((le32 *) outbuf) = cpu_to_le32(1);
@@ -1416,14 +1415,20 @@ static int usbnet_can_receive(void *opaque)
     return !s->in_len;
 }
 
+static void usbnet_cleanup(VLANClientState *vc)
+{
+    USBNetState *s = vc->opaque;
+
+    rndis_clear_responsequeue(s);
+    qemu_free(s);
+}
+
 static void usb_net_handle_destroy(USBDevice *dev)
 {
     USBNetState *s = (USBNetState *) dev;
 
     /* TODO: remove the nd_table[] entry */
     qemu_del_vlan_client(s->vc);
-    rndis_clear_responsequeue(s);
-    qemu_free(s);
 }
 
 USBDevice *usb_net_init(NICInfo *nd)
@@ -1431,8 +1436,6 @@ USBDevice *usb_net_init(NICInfo *nd)
     USBNetState *s;
 
     s = qemu_mallocz(sizeof(USBNetState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
@@ -1454,17 +1457,17 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname),
                     "QEMU USB Network Interface");
-    s->vc = qemu_new_vlan_client(nd->vlan,
-                    usbnet_receive, usbnet_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
+                                 usbnet_receive,
+                                 usbnet_can_receive,
+                                 usbnet_cleanup, s);
+
+    qemu_format_nic_info_str(s->vc, s->mac);
 
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
                     "%02x%02x%02x%02x%02x%02x",
                     0x40, s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                    "usbnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                    s->mac[0], s->mac[1], s->mac[2],
-                    s->mac[3], s->mac[4], s->mac[5]);
     fprintf(stderr, "usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n",
                     s->mac[0], s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);