Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Use UTF8 to encode strings read from the device ...
details: https://anonhg.NetBSD.org/src/rev/75d8174a27d5
branches: trunk
changeset: 580657:75d8174a27d5
user: augustss <augustss%NetBSD.org@localhost>
date: Mon May 02 15:32:18 2005 +0000
description:
Use UTF8 to encode strings read from the device (instead of using '?' for
characters >=0x100).
Also add serial number string to the device information struct.
diffstat:
sys/dev/usb/if_cdce.c | 6 +++---
sys/dev/usb/usb.h | 8 +++++---
sys/dev/usb/usb_subr.c | 38 +++++++++++++++++++++-----------------
sys/dev/usb/usbdi.c | 22 ++++++++++++++--------
4 files changed, 43 insertions(+), 31 deletions(-)
diffs (199 lines):
diff -r ead6553cba95 -r 75d8174a27d5 sys/dev/usb/if_cdce.c
--- a/sys/dev/usb/if_cdce.c Mon May 02 15:29:59 2005 +0000
+++ b/sys/dev/usb/if_cdce.c Mon May 02 15:32:18 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_cdce.c,v 1.4 2004/10/24 12:50:54 augustss Exp $ */
+/* $NetBSD: if_cdce.c,v 1.5 2005/05/02 15:32:18 augustss Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul%windriver.com@localhost>
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.4 2004/10/24 12:50:54 augustss Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.5 2005/05/02 15:32:18 augustss Exp $");
#include "bpfilter.h"
#include <sys/param.h>
@@ -167,7 +167,7 @@
int i;
u_char eaddr[ETHER_ADDR_LEN];
const usb_cdc_ethernet_descriptor_t *ue;
- char eaddr_str[USB_MAX_STRING_LEN];
+ char eaddr_str[USB_MAX_ENCODED_STRING_LEN];
usbd_devinfo(dev, 0, devinfo, sizeof devinfo);
USB_ATTACH_SETUP;
diff -r ead6553cba95 -r 75d8174a27d5 sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h Mon May 02 15:29:59 2005 +0000
+++ b/sys/dev/usb/usb.h Mon May 02 15:32:18 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usb.h,v 1.71 2004/06/23 06:27:54 mycroft Exp $ */
+/* $NetBSD: usb.h,v 1.72 2005/05/02 15:32:18 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $ */
/*
@@ -270,6 +270,7 @@
} UPACKED usb_string_descriptor_t;
#define USB_MAX_STRING_LEN 128
#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
+#define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
/* Hub specific request */
#define UR_GET_BUS_STATE 0x02
@@ -595,9 +596,10 @@
u_int8_t udi_bus;
u_int8_t udi_addr; /* device address */
usb_event_cookie_t udi_cookie;
- char udi_product[USB_MAX_STRING_LEN];
- char udi_vendor[USB_MAX_STRING_LEN];
+ char udi_product[USB_MAX_ENCODED_STRING_LEN];
+ char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
char udi_release[8];
+ char udi_serial[USB_MAX_ENCODED_STRING_LEN];
u_int16_t udi_productNo;
u_int16_t udi_vendorNo;
u_int16_t udi_releaseNo;
diff -r ead6553cba95 -r 75d8174a27d5 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c Mon May 02 15:29:59 2005 +0000
+++ b/sys/dev/usb/usb_subr.c Mon May 02 15:32:18 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_subr.c,v 1.122 2005/03/04 05:03:19 mycroft Exp $ */
+/* $NetBSD: usb_subr.c,v 1.123 2005/05/02 15:32:18 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.122 2005/03/04 05:03:19 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.123 2005/05/02 15:32:18 augustss Exp $");
#include "opt_usbverbose.h"
@@ -81,8 +81,9 @@
#endif
Static usbd_status usbd_set_config(usbd_device_handle, int);
-Static void usbd_devinfo_vp(usbd_device_handle, char *, size_t, char *,
- size_t, int);
+Static void usbd_devinfo_vp(usbd_device_handle dev,
+ char v[USB_MAX_ENCODED_STRING_LEN],
+ char p[USB_MAX_ENCODED_STRING_LEN], int usedev);
Static int usbd_getnewaddr(usbd_bus_handle bus);
#if defined(__NetBSD__)
Static int usbd_print(void *, const char *);
@@ -207,9 +208,9 @@
*e = 0; /* kill trailing spaces */
}
-void
-usbd_devinfo_vp(usbd_device_handle dev, char *v, size_t lv, char *p, size_t lp,
- int usedev)
+Static void
+usbd_devinfo_vp(usbd_device_handle dev, char v[USB_MAX_ENCODED_STRING_LEN],
+ char p[USB_MAX_ENCODED_STRING_LEN], int usedev)
{
usb_device_descriptor_t *udd = &dev->ddesc;
char *vendor = NULL, *product = NULL;
@@ -254,14 +255,15 @@
product = usb_products[n].productname;
}
#endif
+ /* There is no need for strlcpy & snprintf below. */
if (vendor != NULL && *vendor)
- strlcpy(v, vendor, lv);
+ strcpy(v, vendor);
else
- snprintf(v, lv, "vendor 0x%04x", UGETW(udd->idVendor));
+ sprintf(v, "vendor 0x%04x", UGETW(udd->idVendor));
if (product != NULL && *product)
- strlcpy(p, product, lp);
+ strcpy(p, product);
else
- snprintf(p, lp, "product 0x%04x", UGETW(udd->idProduct));
+ sprintf(p, "product 0x%04x", UGETW(udd->idProduct));
}
int
@@ -274,15 +276,14 @@
usbd_devinfo(usbd_device_handle dev, int showclass, char *cp, size_t l)
{
usb_device_descriptor_t *udd = &dev->ddesc;
- char vendor[USB_MAX_STRING_LEN];
- char product[USB_MAX_STRING_LEN];
+ char vendor[USB_MAX_ENCODED_STRING_LEN];
+ char product[USB_MAX_ENCODED_STRING_LEN];
int bcdDevice, bcdUSB;
char *ep;
ep = cp + l;
- usbd_devinfo_vp(dev, vendor, sizeof(vendor), product,
- sizeof(product), 1);
+ usbd_devinfo_vp(dev, vendor, product, 1);
cp += snprintf(cp, ep - cp, "%s %s", vendor, product);
if (showclass)
cp += snprintf(cp, ep - cp, ", class %d/%d",
@@ -1256,10 +1257,13 @@
di->udi_bus = USBDEVUNIT(dev->bus->bdev);
di->udi_addr = dev->address;
di->udi_cookie = dev->cookie;
- usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor),
- di->udi_product, sizeof(di->udi_product), usedev);
+ usbd_devinfo_vp(dev, di->udi_vendor, di->udi_product, usedev);
usbd_printBCD(di->udi_release, sizeof(di->udi_release),
UGETW(dev->ddesc.bcdDevice));
+ di->udi_serial[0] = 0;
+ if (usedev)
+ (void)usbd_get_string(dev, dev->ddesc.iSerialNumber,
+ di->udi_serial);
di->udi_vendorNo = UGETW(dev->ddesc.idVendor);
di->udi_productNo = UGETW(dev->ddesc.idProduct);
di->udi_releaseNo = UGETW(dev->ddesc.bcdDevice);
diff -r ead6553cba95 -r 75d8174a27d5 sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c Mon May 02 15:29:59 2005 +0000
+++ b/sys/dev/usb/usbdi.c Mon May 02 15:32:18 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi.c,v 1.106 2004/10/24 12:52:40 augustss Exp $ */
+/* $NetBSD: usbdi.c,v 1.107 2005/05/02 15:32:18 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
/*
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.106 2004/10/24 12:52:40 augustss Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.107 2005/05/02 15:32:18 augustss Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1210,13 +1210,19 @@
n = size / 2 - 1;
for (i = 0; i < n; i++) {
c = UGETW(us.bString[i]);
- /* Convert from Unicode, handle buggy strings. */
- if ((c & 0xff00) == 0)
+ if (swap)
+ c = (c >> 8) | (c << 8);
+ /* Encode (16-bit) Unicode as UTF8. */
+ if (c < 0x0080) {
*s++ = c;
- else if ((c & 0x00ff) == 0 && swap)
- *s++ = c >> 8;
- else
- *s++ = '?';
+ } else if (c < 0x0800) {
+ *s++ = 0xc0 | (c >> 6);
+ *s++ = 0x80 | (c & 0x3f);
+ } else {
+ *s++ = 0xe0 | (c >> 12);
+ *s++ = 0x80 | ((c >> 6) & 0x3f);
+ *s++ = 0x80 | (c & 0x3f);
+ }
}
*s++ = 0;
return (USBD_NORMAL_COMPLETION);
Home |
Main Index |
Thread Index |
Old Index