All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v4 09/32] usb descriptors: add settable strings.
Date: Wed, 12 Jan 2011 12:19:51 +0100	[thread overview]
Message-ID: <1294831214-4499-10-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1294831214-4499-1-git-send-email-kraxel@redhat.com>

This patch allows to set usb descriptor strings per device instance.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-bus.c  |    1 +
 hw/usb-desc.c |   52 ++++++++++++++++++++++++++++++++++++++++++++--------
 hw/usb-desc.h |    4 +++-
 hw/usb.h      |    9 +++++++++
 4 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 8b4583c..af537c2 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -48,6 +48,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
     pstrcpy(dev->product_desc, sizeof(dev->product_desc), info->product_desc);
     dev->info = info;
     dev->auto_attach = 1;
+    QLIST_INIT(&dev->strings);
     rc = dev->info->init(dev);
     if (rc == 0 && dev->auto_attach)
         usb_device_attach(dev);
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 559ced7..69ab207 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -151,9 +151,42 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len)
     return bLength;
 }
 
-int usb_desc_string(const char* const *str, int index, uint8_t *dest, size_t len)
+/* ------------------------------------------------------------------ */
+
+void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
+{
+    USBDescString *s;
+
+    QLIST_FOREACH(s, &dev->strings, next) {
+        if (s->index == index) {
+            break;
+        }
+    }
+    if (s == NULL) {
+        s = qemu_mallocz(sizeof(*s));
+        s->index = index;
+        QLIST_INSERT_HEAD(&dev->strings, s, next);
+    }
+    qemu_free(s->str);
+    s->str = qemu_strdup(str);
+}
+
+const char *usb_desc_get_string(USBDevice *dev, uint8_t index)
+{
+    USBDescString *s;
+
+    QLIST_FOREACH(s, &dev->strings, next) {
+        if (s->index == index) {
+            return s->str;
+        }
+    }
+    return NULL;
+}
+
+int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
 {
     uint8_t bLength, pos, i;
+    const char *str;
 
     if (len < 4) {
         return -1;
@@ -168,22 +201,25 @@ int usb_desc_string(const char* const *str, int index, uint8_t *dest, size_t len
         return 4;
     }
 
-    if (str[index] == NULL) {
-        return 0;
+    str = usb_desc_get_string(dev, index);
+    if (str == NULL) {
+        str = dev->info->usb_desc->str[index];
+        if (str == NULL) {
+            return 0;
+        }
     }
-    bLength = strlen(str[index]) * 2 + 2;
+
+    bLength = strlen(str) * 2 + 2;
     dest[0] = bLength;
     dest[1] = USB_DT_STRING;
     i = 0; pos = 2;
     while (pos+1 < bLength && pos+1 < len) {
-        dest[pos++] = str[index][i++];
+        dest[pos++] = str[i++];
         dest[pos++] = 0;
     }
     return pos;
 }
 
-/* ------------------------------------------------------------------ */
-
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len)
 {
     const USBDesc *desc = dev->info->usb_desc;
@@ -204,7 +240,7 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len
         trace_usb_desc_config(dev->addr, index, len, ret);
         break;
     case USB_DT_STRING:
-        ret = usb_desc_string(desc->str, index, buf, sizeof(buf));
+        ret = usb_desc_string(dev, index, buf, sizeof(buf));
         trace_usb_desc_string(dev->addr, index, len, ret);
         break;
     default:
diff --git a/hw/usb-desc.h b/hw/usb-desc.h
index d80efdb..20fc400 100644
--- a/hw/usb-desc.h
+++ b/hw/usb-desc.h
@@ -76,9 +76,11 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len);
 int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len);
 int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len);
 int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
-int usb_desc_string(const char* const *str, int index, uint8_t *dest, size_t len);
 
 /* control message emulation helpers */
+void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str);
+const char *usb_desc_get_string(USBDevice *dev, uint8_t index);
+int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len);
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len);
 int usb_desc_handle_control(USBDevice *dev, int request, int value,
                             int index, int length, uint8_t *data);
diff --git a/hw/usb.h b/hw/usb.h
index a29b6d6..7b5c8df 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -135,6 +135,13 @@ typedef struct USBDescConfig USBDescConfig;
 typedef struct USBDescIface USBDescIface;
 typedef struct USBDescEndpoint USBDescEndpoint;
 typedef struct USBDescOther USBDescOther;
+typedef struct USBDescString USBDescString;
+
+struct USBDescString {
+    uint8_t index;
+    char *str;
+    QLIST_ENTRY(USBDescString) next;
+};
 
 /* definition of a USB device */
 struct USBDevice {
@@ -155,6 +162,8 @@ struct USBDevice {
     int setup_state;
     int setup_len;
     int setup_index;
+
+    QLIST_HEAD(, USBDescString) strings;
 };
 
 struct USBDeviceInfo {
-- 
1.7.1

  parent reply	other threads:[~2011-01-12 11:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-12 11:19 [Qemu-devel] [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 01/32] usb: update MAINTAINERS Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 02/32] usb: data structs and helpers for usb descriptors Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 03/32] usb hid: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 04/32] usb serial: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 05/32] usb storage: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 06/32] usb wacom: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 07/32] usb bluetooth: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 08/32] usb hub: " Gerd Hoffmann
2011-01-12 11:19 ` Gerd Hoffmann [this message]
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 10/32] usb storage: serial number support Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 11/32] usb network: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 12/32] usb: move USB_REQ_SET_ADDRESS handling to common code Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 13/32] usb: move USB_REQ_{GET, SET}_CONFIGURATION " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 14/32] usb: move remote wakeup " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 15/32] usb: create USBPortOps, move attach there Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 16/32] usb: rework attach/detach workflow Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 17/32] usb: add usb_wakeup() + wakeup callback to port ops Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 18/32] usb: uhci: remote wakeup support Gerd Hoffmann
2011-01-12 12:25   ` Stefan Hajnoczi
2011-01-14 11:56     ` Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 19/32] usb: hub: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 20/32] usb: hid: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 21/32] usb: hid: change serial number to "42" Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 22/32] usb: add speed mask to ports Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 23/32] usb: add attach callback Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 24/32] usb: add usb_desc_attach Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 25/32] usb: add device qualifier support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 26/32] usb storage: high speed support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 27/32] usb storage: fix status reporting Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 28/32] usb storage: handle long responses Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 29/32] usb: keep track of physical port address Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 30/32] usb: add port property Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 31/32] usb: rewrite fw path, fix numbering Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 32/32] usb: zap pdev from usbport Gerd Hoffmann
2011-01-21 15:00 ` [Qemu-devel] Re: [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-21 17:04   ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1294831214-4499-10-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.