Convert UTF8 string to a hex encoded string sutiable for use as a SSID hex encoded string
Normal characters are converted into 2x hex digits
Unicode encoded characters using \x are retained as hex characters
//SSID
//output_file << " ssid=\"" << ssid << "\"\n";
//Using the above will output any unicode characters as UTF8, but wpa_supplicant.conf will not interpret them correctly, it uses UTF16.
//This is a problem as SSID can contain unicode chaaracters, for instance the iPhone will have a SSID of "Adam\xE2\x80\x99s iPhone" for "Adam’s iPhone".
//When performing "sudo iwlist wlan0 scan" you will get \x values returned, so we have to convert them somehow.
//To support GCC 4.9 without built in UTF8 to UTF16 conversion functions we instead handle this by storing the SSID as hex characters.
//In wpa_supplicant.conf if the SSID is surrounded by quotes "" then its dealt with as a string, but otherwise it is dealt with as
//2 digit hex characters.
output_file << " ssid=";
for (Index = 0; Index < ssid.length(); Index++)
{
if ((ssid[Index] == '\\') && (ssid[(Index+1)] == 'x'))
{
Index++;
Index++;
output_file << (char)ssid[Index++];
output_file << (char)ssid[Index];
}
else
{
output_file << hex << uppercase << setfill('0') << setw(2) << (int)ssid[Index];
}
}
output_file << "\n";
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.