void ConnectNetwork(string ssid, WlanClient.WlanInterface nic, Wlan.WlanAvailableNetwork network) { var log = ServiceRegistration.Get<ILogger>(); if (!string.IsNullOrEmpty(network.profileName)) { try { log.Info("WifiConfiguration: Using existing Profile to connect to WLAN '{0}'", ssid); bool success = nic.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, network.profileName, CONNECTION_TIMEOUT_SECONDS); if (success) FindNetworks(); else log.Warn("Connection to WLAN '{0}' failed.", ssid); } catch (Exception ex) { log.Warn("Connection to WLAN '{0}' failed: {1}", ex, ssid, ex.Message); } } else { if (network.securityEnabled) { ServiceRegistration.Get<IScreenManager>().ShowDialog("dialogWifiPassword"); } else { log.Info("WifiConfiguration: Connecting to unsecured WLAN '{0}'", ssid); nic.Connect(Wlan.WlanConnectionMode.Auto, Wlan.Dot11BssType.Any, network.dot11Ssid, 0); } } }
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; }