Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Nov 2008 08:42:58 +0100
From:      Nick Hibma <nick@van-laarhoven.org>
To:        FreeBSD Hackers Mailing List <hackers@FreeBSD.org>
Subject:   Unicode USB strings conversion
Message-ID:  <200811190842.59377.nick@van-laarhoven.org>

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



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