how wpa_suppliant processes the chinese characters

Jouni Malinen j
Mon Dec 28 10:50:38 PST 2009


On Mon, Dec 28, 2009 at 04:23:26PM +0800, root wrote:

>   yes, i agree with you, but although there is no standard, i think the
> wpa_gui should support one encoding,and also as you said, it is UTF-8.  

Sounds reasonable, but will probably not match in behavior with many
deployed systems that are more likely to use ISO-8859-1 or some small
modification of Latin1. Anyway, the locale configuration could be used
to select something and hope for the best..

>  in china, lots of people work in Windows's XP,and the XP uses the
>  default encoding GB2312(which is included by GB18030) for chinese     
>  character, but in linux, we use the UTF-8. but it does't matter, in
>  the linux, there is command "iconv", it can convert the gb2312 to
>  UTF-8("iconv -f GB2312 -t utf-8 text.txt > text-utf-8.txt"),so if we
>  can get the code of how it do the convert then it can show two kinds
>  of encoding.
> 
>  for example: the words:"my company"in chinese is four characters:
>  and in gb2312 its ced2 b5c4 b9ab cbbe

Thanks. The patch below seems to work in my tests, i.e., this shows up
as ???? in the wpa_gui scan dialog and it can also handle ASCII
characters (but unlikely some Latin1 characters, I would assume).
Obviously, it is hardcoded for GB2312 for the test, so it is not
suitable as-is to be merged into the release, but if there is some
generic mechanism for figuring out that this codec should be used based
on the locale configuration, this could be a reasonable option and just
use codecForLocale() as the default if no better guess is available for
SSID encoding.

What would QTextCodec::codecForLocale() return in normal Linux setup in
China? UTF-8? I would assume that the codec would need to be hardcoded
to GB2312 to get more consistent behavior if that is the most likely
encoding used in SSIDs.



diff --git a/wpa_supplicant/wpa_gui-qt4/scanresults.cpp b/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
index 459aa8c..af4fbc5 100644
--- a/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
+++ b/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
@@ -13,6 +13,7 @@
  */
 
 #include <cstdio>
+#include <QTextCodec>
 
 #include "scanresults.h"
 #include "wpagui.h"
@@ -78,7 +79,7 @@ void ScanResults::updateResults()
 		if (bss.isEmpty() || bss.startsWith("FAIL"))
 			break;
 
-		QString ssid, bssid, freq, signal, flags;
+		QString ssid, bssid, freq, signal, flags, ie;
 
 		QStringList lines = bss.split(QRegExp("\\n"));
 		for (QStringList::Iterator it = lines.begin();
@@ -97,6 +98,31 @@ void ScanResults::updateResults()
 				flags = (*it).mid(pos);
 			else if ((*it).startsWith("ssid="))
 				ssid = (*it).mid(pos);
+			else if ((*it).startsWith("ie="))
+				ie = (*it).mid(pos);
+		}
+
+		if (ie.length() > 4 && ie.startsWith("00")) {
+			bool ok;
+			int ssid_len = ie.mid(2, 2).toInt(&ok, 16);
+			if (ok && ssid_len > 0 && ssid_len <= 32 &&
+			    ie.length() >= 4 + 2 * ssid_len) {
+				/*
+				 * Try to convert binary SSID into unicode
+				 * based on guessed encoding.
+				 */
+				QByteArray s;
+				s = QByteArray::fromHex(
+					ie.mid(4, 2 * ssid_len).
+					toAscii().constData());
+				QTextCodec *codec;
+				/* Assume GB2312 for a test.. */
+				codec = QTextCodec::codecForName("GB2312");
+				if (codec == NULL)
+					codec = QTextCodec::codecForLocale();
+				if (codec)
+					ssid = codec->toUnicode(s);
+			}
 		}
 
 		QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list