aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-net.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/usb-net.c')
-rw-r--r--hw/usb-net.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 8214a68be2..f19309ee13 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1432,32 +1432,34 @@ static void usb_net_handle_destroy(USBDevice *dev)
qemu_del_vlan_client(s->vc);
}
-USBDevice *usb_net_init(NICInfo *nd)
+static int usb_net_initfn(USBDevice *dev)
{
- USBNetState *s;
-
- s = qemu_mallocz(sizeof(USBNetState));
- s->dev.speed = USB_SPEED_FULL;
- s->dev.handle_packet = usb_generic_handle_packet;
+ USBNetState *s = DO_UPCAST(USBNetState, dev, dev);
- s->dev.handle_reset = usb_net_handle_reset;
- s->dev.handle_control = usb_net_handle_control;
- s->dev.handle_data = usb_net_handle_data;
- s->dev.handle_destroy = usb_net_handle_destroy;
+ s->dev.speed = USB_SPEED_FULL;
s->rndis = 1;
s->rndis_state = RNDIS_UNINITIALIZED;
+ TAILQ_INIT(&s->rndis_resp);
+
s->medium = 0; /* NDIS_MEDIUM_802_3 */
s->speed = 1000000; /* 100MBps, in 100Bps units */
s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */;
s->filter = 0;
s->vendorid = 0x1234;
+ return 0;
+}
+
+USBDevice *usb_net_init(NICInfo *nd)
+{
+ USBDevice *dev;
+ USBNetState *s;
+
+ dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Network Interface");
+ s = DO_UPCAST(USBNetState, dev, dev);
memcpy(s->mac, nd->macaddr, 6);
- TAILQ_INIT(&s->rndis_resp);
- pstrcpy(s->dev.devname, sizeof(s->dev.devname),
- "QEMU USB Network Interface");
s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
usbnet_can_receive,
usbnet_receive,
@@ -1476,3 +1478,20 @@ USBDevice *usb_net_init(NICInfo *nd)
return (USBDevice *) s;
}
+
+static struct USBDeviceInfo net_info = {
+ .qdev.name = "QEMU USB Network Interface",
+ .qdev.size = sizeof(USBNetState),
+ .init = usb_net_initfn,
+ .handle_packet = usb_generic_handle_packet,
+ .handle_reset = usb_net_handle_reset,
+ .handle_control = usb_net_handle_control,
+ .handle_data = usb_net_handle_data,
+ .handle_destroy = usb_net_handle_destroy,
+};
+
+static void usb_net_register_devices(void)
+{
+ usb_qdev_register(&net_info);
+}
+device_init(usb_net_register_devices)