void ConnectNewSecureNetwork(string ssid, string key, WlanClient.WlanInterface nic, Wlan.WlanAvailableNetwork network) { var log = ServiceRegistration.Get<ILogger>(); log.Info("WifiConfiguration: Building new Profile to connect to WLAN '{0}'", ssid); string profileXml = Helper.GetProfileXml(ssid, key, network.dot11DefaultAuthAlgorithm, network.dot11DefaultCipherAlgorithm); if (profileXml != null) { string error = null; try { Wlan.WlanReasonCode reasonCode = nic.SetProfile(Wlan.WlanProfileFlags.User, profileXml, true); if (reasonCode != Wlan.WlanReasonCode.Success) error = reasonCode.ToString(); } catch (Exception ex) { error = ex.Message; } if (error == null) { nic.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, ssid, CONNECTION_TIMEOUT_SECONDS); } else { log.Warn("WifiConfiguration: Setting Profile for WLAN '{0}' failed: '{1}'", ssid, error); ServiceRegistration.Get<IDialogManager>().ShowDialog("[Dialogs.ErrorHeaderText]", error, DialogType.OkDialog, false, DialogButtonType.Ok); } } else { // don't know how to build profile log.Warn("WifiConfiguration: No known Mapping to create Profile '{0}' for AuthAlg: '{1}' and CipherAlg: '{2}'", ssid, network.dot11DefaultAuthAlgorithm, network.dot11DefaultCipherAlgorithm); ServiceRegistration.Get<IDialogManager>().ShowDialog("[Dialogs.ErrorHeaderText]", "Unable to build profile. Connect in Windows.", DialogType.OkDialog, false, DialogButtonType.Ok); } }
private bool MyConnect(string strTemplate, string authentication, WlanClient.WlanInterface wlanIface, Wlan.WlanAvailableNetwork network, string profileName, ref string key) { strTemplate = Properties.Resources.WPAPSK; authentication = "WPAPSK"; String encryption = network.dot11DefaultCipherAlgorithm.ToString().Trim((char)0); // key = "Navicon12351"; String profileXml = String.Format(strTemplate, profileName, authentication, encryption, key); var z = wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true); wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName); return wlanIface.CurrentConnection.isState == Wlan.WlanInterfaceState.Connected; }