Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Nov 2008 09:21:12 +0100
From:      Hans Petter Selasky <hselasky@c2i.net>
To:        freebsd-hackers@freebsd.org
Cc:        FreeBSD Hackers Mailing List <hackers@freebsd.org>, Nick Hibma <nick@van-laarhoven.org>
Subject:   Re: Unicode USB strings conversion
Message-ID:  <200811190921.13859.hselasky@c2i.net>
In-Reply-To: <200811190842.59377.nick@van-laarhoven.org>
References:  <200811190842.59377.nick@van-laarhoven.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811190921.13859.hselasky>