Unicode USB strings conversion

Hans Petter Selasky hselasky at c2i.net
Wed Nov 19 01:19:11 PST 2008


On Wednesday 19 November 2008, Nick Hibma wrote:
> 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.

Or you could try to search for a better language ID. Currently the USB stack 
(old and new) selects the first language ID in the language string. Probably 
there is an english language ID, but not as the first selection.

--HPS


More information about the freebsd-hackers mailing list