From: Abhi on
Hi,

I am trying to connect to WEP network using OpenNETCF SDF 2.2 API
AddPreferredNetwork() and ConnectToPreferredNetwork(). Per the WEP
conventions, I am converting the 5 or 10 character ASCII passphrase to
HEX. But I am facing a few problems:

On my router settings, I set the WEP to be 64-bit 10 HEX digits. Then
I get a 10-digit HEX network keys for a 5-digit ASCII passphrase. When
I use this 10-digit in the AddPreferredNetwork()API, it works
perfectly and connects to the network. But if I try to convert it to a
13 or 26 digit HEX, I get an exception saying the key is not of the
right length. Also if I try to enter the 5-digit ASCII passphrase and
convert it to HEX I still get the same exception. Could anyone please
let me know what could be wrong here?

My code is below.

void ConnectToWEP ()
{

string useKey = key;

//THIS IS WEP so need to pass in a 13 or
26 character hex..which means converting a 5 or 10 character string
if (key.Length == 5 || key.Length == 10)
{
//useKey = convertToHex(key);
}
mWzc.AddPreferredNetwork(ssid, true,
useKey, 1, OpenNETCF.Net.NetworkInformation.AuthenticationMode.Open,
OpenNETCF.Net.NetworkInformation.WEPStatus.WEPEnabled, null);
mWzc.ConnectToPreferredNetwork(ssid);

}


/// <summary>
/// Converts passphrase to hex
/// </summary>
/// <param name="asciiString">Passphrase</param>
/// <returns>Passphrase in hex</returns>
private string convertToHex(string asciiString)
{
if (string.IsNullOrEmpty(asciiString))
{
return string.Empty;
}
string hex = "";
try
{
foreach (char c in asciiString)
{
int tmp = c;
hex += String.Format("{0:x2}",
(uint)System.Convert.ToUInt32(tmp.ToString()));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1);
return string.Empty;
}
return hex;
}