Unicode USB strings conversion



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
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Math
    ... converting them to strings, then back, the precision will be lost. ... string is performed by the C compiler, whence Perl is at the mercy of ...
    (comp.lang.perl.misc)
  • Re: Speed comparison of regex versus index, lc, and / /i
    ... "index" is better for matching fixed strings than using regular ... As a test of the proposition that index is better than regexes, ... doing the matching, rather than converting the strings using lc, saved ... spent converting to lower case. ...
    (comp.lang.perl.misc)
  • Re: ptrdiff_t maximum
    ... precision loss when converting back to integer. ... That's OK, strings of ... those sizes would be ridiculous anyway. ...
    (comp.lang.c)
  • Re: Math
    ... converting them to strings, then back, the precision will be lost. ... on the Perl numeric types. ... blb8 at po dot cwru dot edu ...
    (comp.lang.perl.misc)