public async Task<bool> ConnectToNetworkWithPassword(WiFiAvailableNetwork network, bool autoConnect, PasswordCredential password)
        {
            if (network == null)
            {
                return false;
            }

            var result = await networkNameToInfo[network].ConnectAsync(
                network,
                autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual,
                password);

            return (result.ConnectionStatus == WiFiConnectionStatus.Success);
        }
 public static bool IsNetworkOpen(WiFiAvailableNetwork network)
 {
     return network.SecuritySettings.NetworkEncryptionType == NetworkEncryptionType.None;
 }
Exemple #3
1
        public async void GetNetworks()
        {
            var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());

            if (result.Count >= 1)
            {
                firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);

                await firstAdapter.ScanAsync();

                deviceNetwork = firstAdapter.NetworkReport.AvailableNetworks.FirstOrDefault(N => N.Ssid == selectedDevice.GivenName);

                var qualifyingWifi = firstAdapter.NetworkReport.AvailableNetworks.Where(N => !N.Ssid.ToLower().StartsWith("ioespt-thing"));

                foreach (var network in qualifyingWifi)
                {
                    networks.Add(network);
                }

                selectedNetwork = networks.FirstOrDefault();
            }
        }
        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null ?
                networkPresenter.ConnectToNetwork(network, Automatic) :
                networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            if (await didConnect)
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    NavigationUtils.NavigateToScreen(typeof(MainPage));
                });
            }
            else
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var item = SwitchToItemState(network, WifiInitialState, false);
                    item.IsSelected = false;
                });
            }
        }
Exemple #5
0
        private bool IsConnected(WiFiAvailableNetwork network)
        {
            if (network == null)
            {
                return(false);
            }

            string profileName = GetCurrentWifiNetwork();

            if (!String.IsNullOrEmpty(network.Ssid) &&
                !String.IsNullOrEmpty(profileName) &&
                (network.Ssid == profileName))
            {
                return(true);
            }

            return(false);
        }
Exemple #6
0
        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null?
                             networkPresenter.ConnectToNetwork(network, Automatic) :
                                 networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            DataTemplate nextState = (await didConnect) ? WifiConnectedState : WifiInitialState;

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var item        = SwitchToItemState(network, nextState, false);
                item.IsSelected = false;
            });
        }
        public async Task <bool> ConnectToNetworkWithPassword(WiFiAvailableNetwork network, bool autoConnect, PasswordCredential password)
        {
            if (network == null)
            {
                return(false);
            }

            if (_networkNameToInfo.TryGetValue(network, out var adapter))
            {
                var result = await adapter.ConnectAsync(
                    network,
                    autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual,
                    password);

                return(result.ConnectionStatus == WiFiConnectionStatus.Success);
            }

            return(false);
        }
        public async Task <bool> ConnectToNetwork(WiFiAvailableNetwork network, bool autoConnect)
        {
            try
            {
                await NetworkNameToInfoLock.WaitAsync();

                if (network == null)
                {
                    return(false);
                }

                // We need to use TryGetValue here.  If we are rescanning for Wifi networks
                // (ie. 'await'ing on ScanAsync() in UpdateInfo(), 'NetworkNameToInfo' may not
                // have an entry described by the key'network'.
                WiFiAdapter wifiAdapter;
                if (!NetworkNameToInfo.TryGetValue(network, out wifiAdapter))
                {
                    return(false);
                }

                try
                {
                    var result = await wifiAdapter.ConnectAsync(network, autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual);

                    //Call redirect only for Open Wifi
                    if (IsNetworkOpen(network))
                    {
                        //Navigate to http://www.msftconnecttest.com/redirect
                        NavigationUtils.NavigateToScreen(typeof(WebBrowserPage), Common.GetLocalizedText("MicrosoftWifiConnect"));
                    }

                    return(result.ConnectionStatus == WiFiConnectionStatus.Success);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            finally
            {
                NetworkNameToInfoLock.Release();
            }
        }
Exemple #9
0
        public async Task <bool> ConnectToNetwork(WiFiAvailableNetwork network, bool autoConnect)
        {
            if (network == null)
            {
                return(false);
            }

            // We need to use TryGetValue here.  If we are rescanning for Wifi networks
            // (ie. 'await'ing on ScanAsync() in UpdateInfo(), 'networkNameToInfo' may not
            // have an entry described by the key'network'.
            WiFiAdapter wifiAdapter;

            if (!networkNameToInfo.TryGetValue(network, out wifiAdapter))
            {
                return(false);
            }

            var result = await wifiAdapter.ConnectAsync(network, autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual);

            return(result.ConnectionStatus == WiFiConnectionStatus.Success);
        }
        public static async Task <string> TryConnectToWireless()
        {
            try
            {
                WiFiAdapter adapter = await WiFiSettings.Instance.Load();

                await WiFiConnector.Instance.Init(adapter);

                if (adapter != null)
                {
                    //We have an adapter saved, try to connect
                    WiFiAvailableNetwork availableNetwork = await WiFiConnector.Instance.GetSpecificNetwork(
                        adapter,
                        WiFiSettings.Instance.Bssid,
                        WiFiSettings.Instance.Ssid);

                    var network = new WiFiNetworkDisplay(availableNetwork, adapter);

                    WiFiConnectionResult result = await WiFiConnector.Instance.ConnectAsync(
                        network,
                        WiFiSettings.Instance.ReconnectionKind,
                        WiFiSettings.Instance.Password);

                    if (result.ConnectionStatus == WiFiConnectionStatus.Success)
                    {
                        Debug.WriteLine("Connect on startup to wireless network: " + network.Ssid);
                        return(GetAddresses());
                    }
                    else
                    {
                        Debug.WriteLine("Could not connect to wireless network on startup: " + network.Ssid);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Could not connect to wireless network on startup: " + e);
            }
            return("Unknown");
        }
Exemple #11
0
        /// <summary>
        /// Connect to Wireless Network
        /// </summary>
        /// <param name="_network">Wireless Network Name (SSID)</param>
        /// <param name="_password">Password Creditentials</param>
        /// <returns></returns>
        public async Task Connect(string _network, string _password, string id)
        {
            try
            {
                // Get WiFi Adapter from ID
                this._wifi = await WiFiAdapter.FromIdAsync(id);

                // Scan for Wireless Networks
                await this._wifi.ScanAsync();

                // Select Wireless Network
                List <WiFiAvailableNetwork> _list = new List <WiFiAvailableNetwork>();
                _list.AddRange(_wifi.NetworkReport.AvailableNetworks.ToList());
                _nets = _list.FirstOrDefault(x => x.Ssid.Equals(_network));

                // Enter Password Creditentials
                var credential = new PasswordCredential()
                {
                    Password = _password
                };

                // Wireless Connection Result
                _conn = await _wifi.ConnectAsync(_nets, WiFiReconnectionKind.Automatic, credential);

                // Connected Status
                if (_conn.ConnectionStatus != WiFiConnectionStatus.Success)
                {
                    _connected = false;
                }
                else
                {
                    _connected = true;
                }
            }
            catch
            {
                _connected = false;
            }
        }
        public async Task <bool> ConnectToNetworkWithPassword(WiFiAvailableNetwork network, bool autoConnect, PasswordCredential password)
        {
            try
            {
                await NetworkNameToInfoLock.WaitAsync();

                if (network == null)
                {
                    return(false);
                }

                // We need to use TryGetValue here.  If we are rescanning for Wifi networks
                // (ie. 'await'ing on ScanAsync() in UpdateInfo(), 'NetworkNameToInfo' may not
                // have an entry described by the key'network'.
                WiFiAdapter wifiAdapter;
                if (!NetworkNameToInfo.TryGetValue(network, out wifiAdapter))
                {
                    return(false);
                }

                try
                {
                    var result = await wifiAdapter.ConnectAsync(
                        network,
                        autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual,
                        password);

                    return(result.ConnectionStatus == WiFiConnectionStatus.Success);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            finally
            {
                NetworkNameToInfoLock.Release();
            }
        }
Exemple #13
0
        private void WiFiList_ItemClick(object sender, ItemClickEventArgs e)
        {
            var item = e.ClickedItem as string;

            foreach (var selecteditem in wifiAdapter.NetworkReport.AvailableNetworks)
            {
                if (selecteditem.Ssid == item)
                {
                    availableNetwork = selecteditem;
                }
            }

            connectpanel.Visibility = Visibility.Visible;
            if (availableNetwork.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211)
            {
                Credentials.Visibility = Visibility.Collapsed;
            }
            else
            {
                Credentials.Visibility = Visibility.Visible;
            }
        }
Exemple #14
0
        public async Task<bool> ConnectToNetworkWithPasswordAsync(WiFiAvailableNetwork network, bool autoConnect, PasswordCredential password)
        {
            if (network == null)
            {
                return false;
            }

            var result = await networkNameToInfo[network].ConnectAsync(network, autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual, password);
            
            if (result.ConnectionStatus == WiFiConnectionStatus.Success)
            {
                SettingManager.GetProvider().NetworkSsid = network.Ssid;
                SettingManager.GetProvider().NetworkPassword = password.Password;
            }

            return result.ConnectionStatus == WiFiConnectionStatus.Success;
        }
 public WiFiConnection(WiFiAvailableNetwork network)
 {
     _network = network;
 }
        private async void OnConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            // Don't need the listener anymore
            socketListener.Dispose();
            socketListener = null;

            try
            {
                socket = args.Socket;
            }
            catch (Exception e)
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Debug.WriteLine(e.Message);
                });

                Disconnect();
                return;
            }

            // Note - this is the supported way to get a Bluetooth device from a given socket
            var remoteDevice = await BluetoothDevice.FromHostNameAsync(socket.Information.RemoteHostName);

            writer = new DataWriter(socket.OutputStream);
            var  reader = new DataReader(socket.InputStream);
            bool remoteDisconnection = false;

            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                Debug.WriteLine("Connected to Client: " + remoteDevice.Name);
                SendMessage("IOTCore Master App:");
            });

            // Infinite read buffer loop
            while (true)
            {
                try
                {
                    // Based on the protocol we've defined, the first uint is the size of the message
                    uint readLength = await reader.LoadAsync(sizeof(uint));

                    // Check if the size of the data is expected (otherwise the remote has already terminated the connection)
                    if (readLength < sizeof(uint))
                    {
                        remoteDisconnection = true;
                        break;
                    }
                    uint currentLength = reader.ReadUInt32();

                    // Load the rest of the message since you already know the length of the data expected.
                    readLength = await reader.LoadAsync(currentLength);

                    // Check if the size of the data is expected (otherwise the remote has already terminated the connection)
                    if (readLength < currentLength)
                    {
                        remoteDisconnection = true;
                        break;
                    }
                    string message = reader.ReadString(currentLength);

                    await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        Debug.WriteLine("Received: " + message);
                        if (message.ToUpper() == "?")
                        {
                            SendMessage("GETWLAN");
                            SendMessage("GETCURRENTNET");
                            SendMessage("CONNECTWLANPW,[SSID],[PASSWORD]");
                        }
                        else if (message.ToUpper() == "GETWLAN")
                        {
                            NetworkPresenter np = new NetworkPresenter();
                            await Task.Delay(100);
                            var networklist = await np.GetAvailableNetworks();
                            foreach (WiFiAvailableNetwork network in networklist)
                            {
                                SendMessage("WLAN,NETINFO," + network.Ssid + "," + network.SecuritySettings.NetworkAuthenticationType.ToString());
                            }
                        }
                        else if (message.ToUpper() == "GETCURRENTNET")
                        {
                            NetworkPresenter np = new NetworkPresenter();
                            await Task.Delay(100);
                            var networklist = await np.GetAvailableNetworks();
                            WiFiAvailableNetwork network = np.GetCurrentWifiNetwork();
                            if (network != null)
                            {
                                SendMessage("WLAN,CURRENTNET,CONNECTED," + network.Ssid + "," + network.SecuritySettings.NetworkAuthenticationType.ToString() + ',' + NetworkPresenter.GetCurrentIpv4Address());
                            }
                            else
                            {
                                SendMessage("WLAN,CURRENTNET,DISCONNECTED");
                            }
                        }
                        else if (message.ToUpper().Contains("CONNECTWLANPW"))
                        {
                            string[] s = message.Split(',');
                            try
                            {
                                string net      = s[1];
                                string password = s[2];
                                WiFiAvailableNetwork connectnetwork = null;
                                NetworkPresenter np = new NetworkPresenter();
                                await Task.Delay(100);
                                var networklist = await np.GetAvailableNetworks();
                                foreach (WiFiAvailableNetwork network in networklist)
                                {
                                    if (network.Ssid == net)
                                    {
                                        connectnetwork = network;
                                        break;
                                    }
                                }
                                if (connectnetwork == null)
                                {
                                    SendMessage("CONNECTWLANPW,ERROR,UNKNOWNSSID");
                                }
                                else
                                {
                                    PasswordCredential credential = new PasswordCredential();
                                    credential.Password           = password;
                                    bool result = await np.ConnectToNetworkWithPassword(connectnetwork, true, credential);
                                }
                            }
                            catch
                            {
                                SendMessage("ERROR,COMMAND,SYNTAXERROR");
                            }
                        }
                        else
                        {
                            SendMessage("ERROR,COMMAND,UNKNOWN");
                        }
                    });
                }
                // Catch exception HRESULT_FROM_WIN32(ERROR_OPERATION_ABORTED).
                catch (Exception ex) when((uint)ex.HResult == 0x800703E3)
                {
                    await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        Debug.WriteLine("Client Disconnected Successfully");
                    });

                    break;
                }
            }

            reader.DetachStream();
            if (remoteDisconnection)
            {
                Disconnect();
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Debug.WriteLine("Client disconnected");
                });
            }
        }
        private async Task <WiFiConnectionStatus> ConnectToNetwork(WiFiAdapter adapter, WiFiAvailableNetwork network)
        {
            lock (_stateLock)
            {
                _state = OnboardingState.ConfiguredValidating;
            }

            string resultPassword = "";
            WiFiConnectionResult connectionResult;

            // For all open networks (when no PSK was provided) connect without a password
            // Note, that in test, we have seen some WEP networks identify themselves as Open even though
            // they required a PSK, so use the PSK as a determining factor
            if ((network.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211) &&
                string.IsNullOrEmpty(_personalApPassword))
            {
                connectionResult = await adapter.ConnectAsync(network, WiFiReconnectionKind.Automatic);
            }
            // Otherwise for all WEP/WPA/WPA2 networks convert the PSK back from a hex-ized format back to a passphrase, if necessary,
            // and onboard this device to the requested network.
            else
            {
                PasswordCredential pwd = new PasswordCredential();
                resultPassword   = ConvertHexToPassPhrase(network.SecuritySettings.NetworkAuthenticationType, _personalApPassword);
                pwd.Password     = resultPassword;
                connectionResult = await adapter.ConnectAsync(network, WiFiReconnectionKind.Automatic, pwd);
            }

            lock (_stateLock)
            {
                if (connectionResult.ConnectionStatus == WiFiConnectionStatus.Success)
                {
                    _error        = OnboardingError.Validated;
                    _errorMessage = null;
                    _state        = OnboardingState.ConfiguredValidated;
                }
                else
                {
                    _state        = OnboardingState.ConfiguredError;
                    _errorMessage = connectionResult.ConnectionStatus.ToString();

                    switch (connectionResult.ConnectionStatus)
                    {
                    case WiFiConnectionStatus.AccessRevoked:
                    case WiFiConnectionStatus.InvalidCredential:
                    {
                        _error = OnboardingError.Unauthorized;
                        break;
                    }

                    case WiFiConnectionStatus.UnsupportedAuthenticationProtocol:
                    {
                        _error = OnboardingError.UnsupportedProtocol;
                        break;
                    }

                    case WiFiConnectionStatus.NetworkNotAvailable:
                    case WiFiConnectionStatus.Timeout:
                    case WiFiConnectionStatus.UnspecifiedFailure:
                    default:
                    {
                        _error = OnboardingError.ErrorMessage;
                        break;
                    }
                    }
                }
            }
#if DEBUG
            var folder = Windows.Storage.ApplicationData.Current.LocalFolder;
            var file   = await folder.CreateFileAsync("ConnectionResult.Txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);

            string myout = "ConnectionResult= " + connectionResult.ConnectionStatus.ToString() + "\r\n";
            myout += "Type=" + network.SecuritySettings.NetworkAuthenticationType.ToString() + "\r\n";
            myout += "InputPassword= "******"\r\n";
            myout += "ResultPassword= "******"\r\n";
            await Windows.Storage.FileIO.WriteTextAsync(file, myout);
#endif
            return(connectionResult.ConnectionStatus);
        }
Exemple #18
0
 public WiFiNetworkViewModel(WiFiAvailableNetwork availableNetwork, WiFiAdapter wifiAdapter)
 {
     _wifiAdapter     = wifiAdapter;
     AvailableNetwork = availableNetwork;
 }
Exemple #19
0
 public void Disconnect(WiFiAvailableNetwork network)
 {
     _wifiNetworks[network].Disconnect();
 }
Exemple #20
0
        public async Task<bool> Connect(WiFiAvailableNetwork network,bool autoConnect, PasswordCredential password = null)
        {
            if (network == null)
            {
                return false;
            }

            WiFiConnectionResult result;

            if(password == null)
                result = await _wifiNetworks[network].ConnectAsync(network, autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual);
            else 
                result = await _wifiNetworks[network].ConnectAsync(network, autoConnect ? WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual, password);

            return (result.ConnectionStatus == WiFiConnectionStatus.Success);
        }
Exemple #21
0
        public WiFiNetworkDisplay(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter)
        {
            AvailableNetwork = availableNetwork;
            this.adapter = adapter;

        }
 public WifiAvailableAP(WiFiAvailableNetwork availableNetwork)
 {
     this.network = availableNetwork;
     this.InitNetworkImage();
 }
 public WiFiNetworkDisplay(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter)
 {
     AvailableNetwork = availableNetwork;
     this.adapter     = adapter;
 }
Exemple #24
0
        /// <summary>Run asynchronous connection where ConnectionCompleted is raised on completion</summary>
        /// <param name="deviceDataModel">The data model with information on the device</param>
        public void ConnectAsync(WifiNetworkInfo dataModel)
        {
            this.DisconnectSynchronous(true);
            Task.Run(async() => {
                try {
                    this.log.InfoEntry("ConnectAsync");
                    this.log.Info("ConnectAsync", () => string.Format(
                                      "Host:{0} Service:{1}", dataModel.RemoteHostName, dataModel.RemoteServiceName));

                    WiFiAvailableNetwork net = this.GetNetwork(dataModel.SSID);
                    if (net != null)
                    {
                        // Connect WIFI level
                        // TODO How to establish kind of authentication

                        switch (dataModel.AuthenticationType)
                        {
                        // Arduino authentication - requires password but no user name
                        case NetAuthenticationType.RSNA_PSK:
                            break;
                        }

                        WiFiConnectionResult result = null;
                        PasswordCredential cred     = this.GetCredentials(dataModel);
                        if (cred == null)
                        {
                            result = await wifiAdapter.ConnectAsync(net, WiFiReconnectionKind.Automatic);
                        }
                        else
                        {
                            result = await wifiAdapter.ConnectAsync(net, WiFiReconnectionKind.Automatic, cred);
                        }

                        // If the password is bad you get a timeout rather than failed credentials
                        switch (result.ConnectionStatus)
                        {
                        case WiFiConnectionStatus.Success:
                            //ConnectionProfile profile = await this.wifiAdapter.NetworkAdapter.GetConnectedProfileAsync();
                            //this.log.Info("ConnectAsync", () => string.Format("Connected to:{0}", profile.ProfileName));
                            //if (profile.IsWlanConnectionProfile) {

                            //await this.DumpWifiAdapterInfo(wifiAdapter);
                            this.log.Info("ConnectAsync", () => string.Format("Connecting to {0}:{1}", dataModel.RemoteHostName, dataModel.RemoteServiceName));
                            //this.log.Info("ConnectAsync", () => string.Format(
                            //    "Connecting to {0}:{1}:{2}", dataModel.RemoteHostName, dataModel.RemoteServiceName, dataModel.Password));
                            // Connect socket
                            await msgPump.ConnectAsync2(new SocketMsgPumpConnectData()
                            {
                                MaxReadBufferSize = 255,
                                RemoteHostName    = dataModel.RemoteHostName,
                                ServiceName       = dataModel.RemoteServiceName,
                                // TODO - determine protection level according to connection
                                ProtectionLevel = SocketProtectionLevel.PlainSocket,
                            });
                            break;

                        case WiFiConnectionStatus.UnspecifiedFailure:
                        case WiFiConnectionStatus.AccessRevoked:
                        case WiFiConnectionStatus.InvalidCredential:
                        case WiFiConnectionStatus.NetworkNotAvailable:
                        case WiFiConnectionStatus.Timeout:
                        case WiFiConnectionStatus.UnsupportedAuthenticationProtocol:
                            this.OnError?.Invoke(this, new WifiError(result.ConnectionStatus.Convert()));
                            break;

                        default:
                            this.OnError?.Invoke(this, new WifiError(WifiErrorCode.Unknown));
                            break;
                        }
                    }
                    else
                    {
                        this.OnError?.Invoke(this, new WifiError(WifiErrorCode.NetworkNotAvailable)
                        {
                            ExtraInfo = dataModel.SSID
                        });
                    }
                }
                catch (ErrReportException erE) {
                    this.OnError?.Invoke(this, new WifiError(WifiErrorCode.Unknown)
                    {
                        ExtraInfo = erE.Report.Msg
                    });
                }
                catch (Exception e) {
                    this.log.Exception(9999, "Connect Asyn Error", e);
                    this.OnError?.Invoke(this, new WifiError(WifiErrorCode.Unknown));
                }
            });
        }
Exemple #25
0
        private async void ConnectToNetwork(WiFiAvailableNetwork network)
        {
            lock (_stateLock)
            {
                _state = OnboardingState.ConfiguredValidating;
            }

            WiFiConnectionResult connectionResult;
            if (network.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211)
            {
                connectionResult = await _wlanAdapter.ConnectAsync(network, WiFiReconnectionKind.Automatic);
            }
            else
            {
                connectionResult = await _wlanAdapter.ConnectAsync(network, WiFiReconnectionKind.Automatic, new PasswordCredential { Password = _personalApPassword });
            }

            lock (_stateLock)
            {
                if (connectionResult.ConnectionStatus == WiFiConnectionStatus.Success)
                {
                    _error = OnboardingError.Validated;
                    _errorMessage = null;
                    _state = OnboardingState.ConfiguredValidated;
                }
                else
                {
                    _state = OnboardingState.ConfiguredError;
                    _errorMessage = connectionResult.ConnectionStatus.ToString();

                    switch (connectionResult.ConnectionStatus)
                    {
                        case WiFiConnectionStatus.AccessRevoked:
                        case WiFiConnectionStatus.InvalidCredential:
                            {
                                _error = OnboardingError.Unauthorized;
                                break;
                            }
                        case WiFiConnectionStatus.UnsupportedAuthenticationProtocol:
                            {
                                _error = OnboardingError.UnsupportedProtocol;
                                break;
                            }
                        case WiFiConnectionStatus.NetworkNotAvailable:
                        case WiFiConnectionStatus.Timeout:
                        case WiFiConnectionStatus.UnspecifiedFailure:
                        default:
                            {
                                _error = OnboardingError.ErrorMessage;
                                break;
                            }
                    }
                }
            }
        }
        private void WiFiList_ItemClick(object sender, ItemClickEventArgs e)
        {
            var item = e.ClickedItem as string;
            foreach (var selecteditem in wifiAdapter.NetworkReport.AvailableNetworks)
            {
                if (selecteditem.Ssid == item)
                {
                    availableNetwork = selecteditem;
                }
            }

            connectpanel.Visibility = Visibility.Visible;
            if (availableNetwork.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Open80211)
            {
                Credentials.Visibility = Visibility.Collapsed;
            }
            else
            {
                Credentials.Visibility = Visibility.Visible;
            }
        }
Exemple #27
0
 public WiFiNetworkDisplay(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter)
 {
     AvailableNetwork = availableNetwork;
     this.adapter     = adapter;
     UpdateWiFiImage();
 }
Exemple #28
0
 public WiFiNetwork(WiFiAvailableNetwork wifiAvailableNetwork)
 {
     _wifiAvailableNetwork = wifiAvailableNetwork;
 }
 public void DisconnectNetwork(WiFiAvailableNetwork network)
 {
     networkNameToInfo[network].Disconnect();
 }
 public WifiDataModel(WiFiAvailableNetwork avNetwork, WiFiAdapter adapter)
 {
     AvailableNetwork = avNetwork;
     this.adapter = adapter;
 }
Exemple #31
0
        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null ?
                networkPresenter.ConnectToNetwork(network, Automatic) :
                networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            DataTemplate nextState = (await didConnect) ? WifiConnectedState : WifiInitialState;

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var item = SwitchToItemState(network, nextState, false);
                item.IsSelected = false; 
            });
        }
        public async void GetNetworks()
        {
            var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());

            if (result.Count >= 1)
            {
                firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);

                await firstAdapter.ScanAsync();

                deviceNetwork = firstAdapter.NetworkReport.AvailableNetworks.FirstOrDefault(N => N.Ssid == selectedDevice.GivenName); 

                var qualifyingWifi = firstAdapter.NetworkReport.AvailableNetworks.Where(N => !N.Ssid.ToLower().StartsWith("ioespt-thing"));

                foreach(var network in qualifyingWifi)
                {
                    networks.Add(network);
                }

                selectedNetwork = networks.FirstOrDefault();
            }
        }
 public WiFiListViewItemPresenter(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter, DateTime reportTime)
 {
     AvailableNetwork = availableNetwork;
     Adapter          = adapter;
     LastSeen         = reportTime;
 }
 public void DisconnectNetwork(WiFiAvailableNetwork network)
 {
     networkNameToInfo[network].Disconnect();
 }
 public static bool IsNetworkOpen(WiFiAvailableNetwork network)
 {
     return(network.SecuritySettings.NetworkEncryptionType == NetworkEncryptionType.None);
 }
 public WiFiNetworkDisplay(WiFiAvailableNetwork availableNetwork, WiFiAdapter adapter)
 {
     AvailableNetwork = availableNetwork;
     this.adapter = adapter;
     UpdateWiFiImage();
     UpdateConnectivityLevel();
 }