From patchwork Mon Jun 24 06:44:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 253652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 22C132C0091 for ; Mon, 24 Jun 2013 16:50:01 +1000 (EST) Received: from localhost ([::1]:49028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur0b9-000529-9X for incoming@patchwork.ozlabs.org; Mon, 24 Jun 2013 02:49:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur0W9-0004yc-Vi for qemu-devel@nongnu.org; Mon, 24 Jun 2013 02:44:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ur0W7-0000Ig-CJ for qemu-devel@nongnu.org; Mon, 24 Jun 2013 02:44:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur0W7-0000I2-56 for qemu-devel@nongnu.org; Mon, 24 Jun 2013 02:44:47 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5O6ikNl014048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Jun 2013 02:44:46 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5O6ij8N019110; Mon, 24 Jun 2013 02:44:45 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 3F72641782; Mon, 24 Jun 2013 08:44:44 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2013 08:44:42 +0200 Message-Id: <1372056283-4845-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1372056283-4845-1-git-send-email-kraxel@redhat.com> References: <1372056283-4845-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 8/9] usb: add serial bus property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds a serial property for all usb devices, which can be used to set the serial number of a usb device (as listed by lsusb -v) to a specific value. Applies to emulated devices only. Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 1 + hw/usb/desc.c | 6 ++++++ hw/usb/dev-hid.c | 3 +++ hw/usb/dev-storage.c | 13 +++---------- include/hw/usb.h | 1 + 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index d1827be..f83d1de 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -13,6 +13,7 @@ static int usb_qdev_exit(DeviceState *qdev); static Property usb_props[] = { DEFINE_PROP_STRING("port", USBDevice, port_path), + DEFINE_PROP_STRING("serial", USBDevice, serial), DEFINE_PROP_BIT("full-path", USBDevice, flags, USB_DEV_FLAG_FULL_PATH, true), DEFINE_PROP_END_OF_LIST() diff --git a/hw/usb/desc.c b/hw/usb/desc.c index fce303e..bf6c522 100644 --- a/hw/usb/desc.c +++ b/hw/usb/desc.c @@ -566,6 +566,12 @@ void usb_desc_create_serial(USBDevice *dev) char *path; int dst; + if (dev->serial) { + /* 'serial' usb bus property has priority if present */ + usb_desc_set_string(dev, index, dev->serial); + return; + } + assert(index != 0 && desc->str[index] != NULL); dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]); path = qdev_get_dev_path(hcd); diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index b48899d..31f3cde 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -560,6 +560,9 @@ static int usb_hid_initfn(USBDevice *dev, int kind) { USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev); + if (dev->serial) { + usb_desc_set_string(dev, STR_SERIALNUMBER, dev->serial); + } usb_desc_init(dev); us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); hid_init(&us->hid, kind, usb_hid_changed); diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 1073901..fe914ab 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -58,7 +58,6 @@ typedef struct { USBPacket *packet; /* usb-storage only */ BlockConf conf; - char *serial; uint32_t removable; } MSDState; @@ -602,7 +601,7 @@ static int usb_msd_initfn_storage(USBDevice *dev) return -1; } - blkconf_serial(&s->conf, &s->serial); + blkconf_serial(&s->conf, &dev->serial); /* * Hack alert: this pretends to be a block device, but it's really @@ -616,16 +615,11 @@ static int usb_msd_initfn_storage(USBDevice *dev) bdrv_detach_dev(bs, &s->dev.qdev); s->conf.bs = NULL; - if (s->serial) { - usb_desc_set_string(dev, STR_SERIALNUMBER, s->serial); - } else { - usb_desc_create_serial(dev); - } - + usb_desc_create_serial(dev); usb_desc_init(dev); scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL); scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable, - s->conf.bootindex, s->serial); + s->conf.bootindex, dev->serial); if (!scsi_dev) { return -1; } @@ -734,7 +728,6 @@ static const VMStateDescription vmstate_usb_msd = { static Property msd_properties[] = { DEFINE_BLOCK_PROPERTIES(MSDState, conf), - DEFINE_PROP_STRING("serial", MSDState, serial), DEFINE_PROP_BIT("removable", MSDState, removable, 0, false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/usb.h b/include/hw/usb.h index 4d9d05e..901b0da 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -205,6 +205,7 @@ struct USBDevice { DeviceState qdev; USBPort *port; char *port_path; + char *serial; void *opaque; uint32_t flags;