public async Task DisconnectFromWifiNetwork(WifiNetwork wifiNetwork) { if (wifiNetwork != null && wifiNetwork.SSID != null) { await Task.Run(() => NEHotspotConfigurationManager.SharedManager.RemoveConfiguration(wifiNetwork.SSID)); } }
public static void Change_XML_WifiNetwork_File(WifiNetwork WifiNetwork) { try { // Console.WriteLine(xml_name); if (File.Exists(xml_name)) { XmlDocument xdoc = new XmlDocument(); xdoc.Load(xml_name); XmlElement node = xdoc.CreateElement("WifiNetwork"); XmlElement SSID = xdoc.CreateElement("SSID"); SSID.InnerText = WifiNetwork.SSID; XmlElement Key = xdoc.CreateElement("Key"); Key.InnerText = WifiNetwork.Key; XmlElement DHCPorSTATIC = xdoc.CreateElement("DHCPorSTATIC"); DHCPorSTATIC.InnerText = WifiNetwork.DHCPorSTATIC; XmlElement StaticIP = xdoc.CreateElement("StaticIP"); StaticIP.InnerText = WifiNetwork.StaticIP; node.AppendChild(SSID); node.AppendChild(Key); node.AppendChild(DHCPorSTATIC); node.AppendChild(StaticIP); xdoc.DocumentElement.AppendChild(node); xdoc.Save(xml_name); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
private async Task <bool> GenerateDeviceInfo(WifiNetwork wifiNetwork) { // get stuff from device SetPairingStatusText("Grabbing some information from the device..."); onboardingRestService.SetBasicAuthentication(deviceSetupService.DefaultPortalPassword); var deviceIdResponse = await onboardingRestService.GetDeviceId(); if (deviceIdResponse == null) { return(await ProvisionDeviceFail()); } deviceSetupService.CurrentDeviceModel.DeviceId = deviceIdResponse.DeviceId; //return deviceIdResponse?.DeviceId; // shortcut for testing csrResult = await onboardingRestService.GetGeneratedCSR(); State = RegistrationState.DeviceInfoGenerated; var success = await wifiService.ConnectToWifiNetwork(deviceSetupService.OriginalSSID); return(true); }
public async Task <bool> ProvisionDevice(WifiNetwork wifiNetwork) { State = RegistrationState.Starting; OnBeginDevicePairing?.Invoke(); this.deviceSetupService.CurrentDeviceModel.SSID = wifiNetwork.SSID; this.deviceSetupService.CurrentDeviceHotspotNetwork = new WifiNetwork() { SSID = wifiNetwork.SSID }; // connect to device SetPairingStatusText("Connecting to device..."); var defaultWifiNetwork = await wifiService.GetCurrentlyConnectedWifiNetwork(); deviceSetupService.OriginalSSID = defaultWifiNetwork.SSID; State = RegistrationState.ConnectingConnectingToDeviceFirstTime; var success = await wifiService.ConnectToWifiNetwork(wifiNetwork.SSID, deviceSetupService.DefaultPassword); if (!success) { return(await ProvisionDeviceFail()); } return(true); }
public void Refresh(WifiNetwork wifiNetwork) { if (label == null) { label = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, TextColor = Constants.Color.DarkGray, Font = Constants.Fonts.RubikOfSize(Constants.Fonts.Size.Fourteen), }; ContentView.AddSubview(label); label.CenterYAnchor.ConstraintEqualTo(ContentView.CenterYAnchor).Active = true; label.LeftAnchor.ConstraintEqualTo(ContentView.LeftAnchor, constant: Constants.Padding).Active = true; arrowImageView = new UIImageView { TranslatesAutoresizingMaskIntoConstraints = false, Image = Constants.Assets.ArrowRight, ContentMode = UIViewContentMode.ScaleAspectFit, }; ContentView.AddSubview(arrowImageView); arrowImageView.RightAnchor.ConstraintEqualTo(ContentView.RightAnchor, constant: -Constants.Padding * 2).Active = true; arrowImageView.CenterYAnchor.ConstraintEqualTo(ContentView.CenterYAnchor).Active = true; arrowImageView.WidthAnchor.ConstraintEqualTo(12).Active = true; arrowImageView.HeightAnchor.ConstraintEqualTo(arrowImageView.WidthAnchor).Active = true; label.RightAnchor.ConstraintEqualTo(arrowImageView.LeftAnchor, constant: Constants.Padding).Active = true; } label.Text = wifiNetwork.SSID; }
public Task <WifiNetwork> GetCurrentlyConnectedWifiNetwork() { var network = new WifiNetwork() { SSID = wifiManager.ConnectionInfo.SSID }; return(Task.FromResult(network)); }
public async Task <bool> ConnectToDeviceHotspot(WifiNetwork wifiNetwork) { var success = await wifiService.ConnectToSecuredWifiNetwork(wifiNetwork.SSID, "Edison1234"); deviceSetupService.CurrentDeviceHotspotNetwork = success ? wifiNetwork : null; await onboardingRestService.GetDeviceId(); return(success); }
public NewItemPage() { InitializeComponent(); WifiNetwork = new WifiNetwork { SSID = "Item name", DeviceName = "This is an item description." }; BindingContext = this; }
public ItemDetailPage() { InitializeComponent(); var wifiNetwork = new WifiNetwork { SSID = "Item 1", DeviceName = "This is an item description." }; viewModel = new ItemDetailViewModel(wifiNetwork); BindingContext = viewModel; }
async void HandleOnWifiNetworkSelected(object sender, WifiNetwork wifiNetwork) { var success = await ViewModel.ConnectToDeviceHotspot(wifiNetwork); if (success) { DismissViewController(true, null); } else { var alertController = UIAlertController.Create(null, $"Could not join {wifiNetwork.SSID}", UIAlertControllerStyle.Alert); var action = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null); alertController.AddAction(action); PresentViewController(alertController, true, null); } }
public RegisterCar(User user, WifiNetwork network) { InitializeComponent(); this.user = user; this.network = network; labelSSID.Text = network.SSID; requirePassword = true; if (network.Protocol == null || network.Protocol == "") { requirePassword = false; entryWifiPass.IsEnabled = false; entryWifiPass.BackgroundColor = Color.LightGray; labelWifiPass.Text = "Wi-Fi Password (N/A):"; } }
Task <WifiNetwork> IWifiService.GetCurrentlyConnectedWifiNetwork() { WifiNetwork wifiNetwork = null; CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out var info); foreach (var pair in info) { if (pair.Key.ToString() == "SSID") { wifiNetwork = new WifiNetwork { SSID = pair.Value.ToString(), }; } } return(Task.FromResult(wifiNetwork)); }
private static void FoundNetworkNotify(Context context, WifiNetwork wifi) { var startWorkReceiverIntent = new Intent(context, typeof(EnteredWorkReceiver)); var pendingIntent = PendingIntent.GetBroadcast(context, 0, startWorkReceiverIntent, PendingIntentFlags.CancelCurrent); var builder = new NotificationCompat.Builder(context, AppConstants.ChannelId) .SetContentTitle("Wykryto sieć " + wifi.Ssid) .SetContentText("Kliknij, jeżeli jesteś w pracy.") .SetSmallIcon(Resource.Drawable.raports) .SetContentIntent(pendingIntent) .SetOnlyAlertOnce(true) .SetAutoCancel(true) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetDefaults((int)NotificationDefaults.Vibrate) .SetPriority(NotificationCompat.PriorityHigh); var notificationManager = NotificationManagerCompat.From(context); notificationManager.Notify(AppConstants.NotificationIdStartedWork, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { IList <ScanResult> scanwifinetworks = _wifiManager.ScanResults; foreach (ScanResult n in scanwifinetworks) { // System.Diagnostics.Debug.WriteLine($"Detected network: {n.Ssid} - {n.Bssid}"); var network = new WifiNetwork() { Ssid = n.Ssid, Bssid = n.Bssid, Level = n.Level }; var args = new OnNetworkDetectedEventArgs() { WifiNetwork = network }; OnNetworkDetected.Invoke(this, args); } }
public async Task <WifiNetwork> GetCurrentlyConnectedWifiNetwork() { WifiNetwork wifiNetwork = null; CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out var info); if (info != null) { foreach (var pair in info) { if (pair.Key.ToString() == "SSID") { wifiNetwork = new WifiNetwork { SSID = pair.Value.ToString(), }; } } } return(await Task.FromResult(wifiNetwork)); }
public static WifiNetwork fromString(string wifidata, Action <string> logger, out bool error) { error = true; WifiNetwork result = new WifiNetwork(); try { List <string> data = wifidata.Split(seperator).Select((a) => a.Trim()).ToList(); if (data.Count == 3) { result.TrustLevel = TrustMap[data[0]]; result.BSSID = data[1]; result.DisplaName = data[2]; error = false; } } catch (Exception ex) { logger(ex.ToString()); } return(result); }
public Task DisconnectFromWifiNetwork(WifiNetwork wifiNetwork) { throw new NotImplementedException(); }
async private void networkClicked(object sender, EventArgs args) { Button btn = (Button)sender; WifiNetwork network = (WifiNetwork)btn.CommandParameter; await Navigation.PushAsync(new RegisterCar(user, network)); }
public async Task <bool> ProvisionDevice(WifiNetwork wifiNetwork) { OnBeginDevicePairing?.Invoke(); // connect to device SetPairingStatusText("Connecting to device..."); var defaultWifiNetwork = await wifiService.GetCurrentlyConnectedWifiNetwork(); var success = await wifiService.ConnectToWifiNetwork(wifiNetwork.SSID, deviceSetupService.DefaultPassword); await Task.Delay(2000); if (!success) { ProvisionDeviceFail(); } // get stuff from device SetPairingStatusText("Grabbing some information from the device..."); deviceSetupService.CurrentDeviceHotspotNetwork = success ? wifiNetwork : null; var deviceId = await onboardingRestService.GetDeviceId(); var csrResult = await onboardingRestService.GetGeneratedCSR(); // disconnect from device and connect to the internet to provision device with services await wifiService.DisconnectFromWifiNetwork(deviceSetupService.CurrentDeviceHotspotNetwork); await Task.Delay(2000); if (csrResult == null) { ProvisionDeviceFail(); } // provision device with azure SetPairingStatusText("Provisioning device..."); var certificateResponse = await deviceProvisioningRestService.GenerateDeviceCertificate(new DeviceCertificateRequestModel { Csr = csrResult?.Csr ?? "MIIBbjCB2AIBADAvMS0wKwYDVQQDEyQ4OTJlYWM5YS1iOWFkLTQ0NDgtYWEwYS0wOTI0MDE1YWMwMWEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALeqOH+XoeXXERg8neKzr3IumxTDMKsPzKjZ/kfE1gu/FHmr1ugPuRTtQzP5WFVD5lWqtEKJyX+YDCjNevKeHBSpHTAAdVR8GbpDdvRvij0k6yrmrjTRVohO5bTaE611KNzXOW5K4Y8PhoTHasNnMEydfAh4ysut92lWObmg2CG1AgMBAAGgADANBgkqhkiG9w0BAQsFAAOBgQCg8dbM4gMxChp4MF67B/0ARv5Ezq3423v/Tkj5KOMxFql+NeYtM9JpIWABMw2xlARl+agp9e8eaj503grhHjYeGV0afC2/8AA2o/PyZOrS80QViDK6Z4cY+zUO5hp3darGCEH14fuAHKwrokSQxYReqdBELyT3r4ZnCdbi+NUx7A==", DeviceType = deviceSetupService.DeviceTypeAsString, }); if (certificateResponse == null) { ProvisionDeviceFail(); } await Task.Delay(1000); SetPairingStatusText("Reconnecting to device to finish up..."); // reconnect to device to set device type var reconnectSuccess = await wifiService.ConnectToWifiNetwork(deviceSetupService.CurrentDeviceHotspotNetwork.SSID, deviceSetupService.DefaultPassword); await Task.Delay(2000); if (!reconnectSuccess) { ProvisionDeviceFail(); } var provisionSuccess = await onboardingRestService.ProvisionDevice(new RequestCommandProvisionDevice { DeviceCertificateInformation = new DeviceCertificateModel { DeviceType = certificateResponse.DeviceType, Certificate = certificateResponse.Certificate, DpsIdScope = certificateResponse.DpsIdScope, DpsInstance = certificateResponse.DpsInstance, }, }); if (provisionSuccess == null || !provisionSuccess.IsSuccess) { ProvisionDeviceFail(); } var setDeviceTypeResult = await onboardingRestService.SetDeviceType(new RequestCommandSetDeviceType { DeviceType = certificateResponse.DeviceType, }); OnFinishDevicePairing?.Invoke(this, new OnFinishDevicePairingEventArgs { IsSuccess = setDeviceTypeResult.IsSuccess, }); if (setDeviceTypeResult.IsSuccess) { SetPairingStatusText("Pairing Successful!"); } else { ProvisionDeviceFail(); } // disconnect from device and connect to the internet to provision device with services await wifiService.DisconnectFromWifiNetwork(deviceSetupService.CurrentDeviceHotspotNetwork); await Task.Delay(2000); return(setDeviceTypeResult.IsSuccess); }
public Task DisconnectFromWifiNetwork(WifiNetwork wifiNetwork) { return(Task.FromResult(true)); }
public async Task DisconnectFromWifiNetwork(WifiNetwork wifiNetwork) { wifiManager.Disconnect(); await Task.FromResult(true); }
public void ClearDevice() { CurrentDeviceModel = new DeviceModel(); CurrentDeviceHotspotNetwork = new WifiNetwork(); }
public DeviceSetupService() { CurrentDeviceHotspotNetwork = new WifiNetwork(); }
public void SetDeviceHotspotNetwork(WifiNetwork wifiNetwork) { deviceSetupService.CurrentDeviceHotspotNetwork = wifiNetwork; OnPairedSuccessfully?.Invoke(); }
public ItemDetailViewModel(WifiNetwork wifiNetwork = null) { Title = wifiNetwork?.SSID; WifiNetwork = wifiNetwork; }
public EnterWifiPasswordViewController(WifiNetwork selectedWifiNetwork) { this.selectedWifiNetwork = selectedWifiNetwork; }
/// <summary> /// Quick call of the inBlockZone functions /// </summary> /// <param name="textcurrent">List of current Wifi BSSID</param> /// <param name="textrules">prefix: '-' block, '+' trusted, '?' ignore</param> /// <param name="new_textrules">A output of the new rules. Even if not in blocking zone</param> /// <param name="log">A logging function</param> /// <returns>in black zone?</returns> public static bool fastBlockZoneCheck( IEnumerable <string> textcurrent, IEnumerable <string> textrules, out List <string> new_textrules, Action <string> log, out string reason) { bool inBlockZone = true; new_textrules = new List <string>(); reason = "init"; try { List <WifiNetwork> networkRules = new List <WifiNetwork>(); foreach (string rule in textrules) { bool error = false; WifiNetwork wifi = WifiNetwork.fromString(rule, log, out error); if (!error) { networkRules.Add(wifi); } } List <WifiNetwork> currentWifis = textcurrent .Select((t) => { var data = t .Split(WifiNetwork.seperator) .Select((a) => a.Trim()) .ToList(); return(WifiNetwork.newNetwork(data[0], data[1])); }) .ToList(); List <WifiNetwork> trusted = networkRules .Where((s) => s.TrustLevel == WifiNetwork.TrustMode.TRUSTED).ToList(); List <WifiNetwork> ignored = networkRules .Where((s) => s.TrustLevel == WifiNetwork.TrustMode.IGNORED).ToList(); List <WifiNetwork> blocked = networkRules .Where((s) => s.TrustLevel == WifiNetwork.TrustMode.BLOCKED).ToList(); List <WifiNetwork> newBadWifis = new List <WifiNetwork>(); inBlockZone = WifiHelper.inBlockZone( currentWifis, blocked, ignored, trusted, out newBadWifis, log, out reason); new_textrules = new List <string>(textrules); if (inBlockZone) { foreach (var newbad in newBadWifis) { newbad.TrustLevel = WifiNetwork.TrustMode.BLOCKED; // From unkown to bad. new_textrules.Add(newbad.ToString()); } } } catch (Exception ex) { log(ex.ToString()); } return(inBlockZone); }