The network connection profile is corrupted

Nov 26, 2012 at 9:51 PM

Whenever I am trying to connect to a network with WPA2PSK security with TKIP/AES Encryption I am getting "The network connection profile is corrupted". Below is the profilexml I am using.

profileXml = string.Format("<?xml version=\"1.0\" ?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>TKIP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>true</protected><keyMaterial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profileName, key);

Can any one please suggest what am I doing wrong. Below is the complete function.

public void Wifi_SetProfile(string profileargs, string keyargs)
        {
            // Connects to a known network with WEP security
            string profileName = profileargs; // this is also the SSID
            string key = keyargs;

            WlanClient client = new WlanClient();
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                // Connects to a known network with WEP security
				string profileXml = string.Empty;
				Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
				foreach (Wlan.WlanAvailableNetwork network in networks)
				{
					if (profileargs == GetStringForSSID(network.dot11Ssid))
					{
						string name = GetStringForSSID(network.dot11Ssid); // this is typically the network's SSID

						if (network.dot11DefaultAuthAlgorithm == Wlan.Dot11AuthAlgorithm.IEEE80211_Open)
						{
							profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>None</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", profileName, key);
							break;
						}
						if (network.dot11DefaultAuthAlgorithm == Wlan.Dot11AuthAlgorithm.RSNA_PSK)
						{
							//doesnot used shared key on this profile xml which will prompt user to add the key to connect
							profileXml = string.Format("<?xml version=\"1.0\" ?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>TKIP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>true</protected><keyMaterial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profileName, key);
							break;
						}
						if (network.dot11DefaultAuthAlgorithm == Wlan.Dot11AuthAlgorithm.WPA)
						{
							profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>WPAPSK</authentication><encryption>TKIP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>true</protected><keyMaterial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profileName, key);
							break;
						}
						if (network.dot11DefaultAuthAlgorithm == Wlan.Dot11AuthAlgorithm.WPA_PSK)
						{
							profileXml = string.Format("<?xml version=\"1.0\" ?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>WPAPSK</authentication><encryption>TKIP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>true</protected><keyMaterial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profileName, key);
							break;
						}

					}
				}

				//makes sure you do not replace the saved profile
				foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
				{
					string profilename = profileInfo.profileName;
					if (profileargs == profilename)
					{
						try
						{
							profileXml = wlanIface.GetProfileXml(profileInfo.profileName);
							wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, false);
							wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);

							//Send Message to Update View
							NetworkParameters param = new NetworkParameters();
							param.isConnected = true;
							param.connectionString = profileInfo.profileName;
							var genericmessage = new GenericMessage<NetworkParameters>(this, param);
							Messenger.Default.Send(genericmessage);
							btnCancel.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
							return;
						}
						catch (Exception ex)
						{
							MessageBox.Show(ex.Message);
						}
					}
				}

				try
				{
					wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
					wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
					//Send Message to Update View
					NetworkParameters param = new NetworkParameters();
					param.isConnected = true;
					param.connectionString = profileargs;
					var genericmessage = new GenericMessage<NetworkParameters>(this, param);
					Messenger.Default.Send(genericmessage);
					btnCancel.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
               
            }
        }
        
	}

Nov 29, 2012 at 3:45 PM

I have been running into this same issue.  No matter what I do, I always get the corrupted profile error.  I have been swallowing this exception and using the event handler (wlanIface_WlanConnectionNotification) to report success and failure based on the Wlan.WlanNotificationCodeAcm objects that come back.

 

Even if the Corrupt profile exception occurs I am still seeing a successful connection.

 

However when i give the Connect method a bad passPhrase my application seems to crash unexpectedly even if I swallow all System.Exceptions.  Not quite sure why.

Feb 6, 2013 at 10:59 AM
Edited Feb 6, 2013 at 11:00 AM
You forget the <hex></hex> of the SSID in the SSID-Tag.

<SSIDConfig>
<SSID>
<name>{0}</name>
<hex>{x}</hex>
</SSID>
</SSIDConfig>

You must convert the SSID-name to HEX.

Then it should be working.

greetz
Apr 9, 2013 at 12:19 PM
What's interesting to me is that Microsoft does not include the hex element in their profiles that they create for connections, nor do they have it in any of their samples. So if I just use the profile that's already on the system, it may throw the error. Easy to put in a try/catch, but still...

I actually posted because I noticed that you have <authenticate> set to WPAPSK for both WPA and WPAPSK profiles. Looking at Microsoft's samples, it's hard to tell what they are using as WPA and what is WPAPSK. it looks like their WPA-Personal is shared key, and Enterprise is not? (cf http://msdn.microsoft.com/en-us/library/windows/desktop/aa369853(v=vs.85).aspx)

Anyone know how to map the dot11DefaultAuthAlgorithm enum to those samples?