Unicode USB strings conversion
Nick Hibma
nick at van-laarhoven.org
Tue Nov 18 23:55:15 PST 2008
In the USB code (and I bet it is the same in the USB4BSD code) unicode
characters in strings are converted in a very crude way to ASCII. As I have
a user on the line who sees rubbish in his logs and when using
usbctl/usbdevs/etc., I bet this is the problem.
I'd like to try and fix this problem by using libkern/libiconv.
1) Is this the right approach to convert UTF8 to printable string in the
kernel?
2) Is this needed at all in the short term future? I remember seeing
attempts at making the kernel use UTF8.
3) Does anyone know of a good example in the code without me having to hunt
through the kernel to find it?
For reference: The code that needs replacing is:
usbd_get_string():
s = buf;
n = size / 2 - 1;
for (i = 0; i < n && i < len - 1; i++) {
c = UGETW(us.bString[i]);
/* Convert from Unicode, handle buggy strings. */
if ((c & 0xff00) == 0)
*s++ = c;
else if ((c & 0x00ff) == 0 && swap)
*s++ = c >> 8;
else
*s++ = '?';
}
*s++ = 0;
I haven't got the USB specs handy, but I believe that this is a simple way
of converting LE and BE UTF8 to ASCII.
Nick
More information about the freebsd-hackers
mailing list