public async void SetupWirelessAP(object sender, EventArgs e) { this.SetViewState(true); App.wirelessconfig.Password = this.PasswordEntry.Text; var publicKey = await SoftAPConfig.GetPublicKeyAsync(); var configureresult = await SoftAPConfig.SetConfigureAPAsync(0, ssidlist.Where(l => l.SSID == App.wirelessconfig.SSID).First(), App.wirelessconfig.Password, publicKey); if (configureresult == 0) { await SoftAPConfig.SetConnectAPAsync(0); } this.SetViewState(false); }
public async Task RefreshWirelessAPList() { this.SetViewState(true); try { this.ssidlist = await SoftAPConfig.GetScanAPsAsync(); this.WirelessAPList.ItemsSource = this.ssidlist.Select(x => x.SSID); } catch { await DisplayAlert("Refresh error", "Could not get wireless networks - are you connected to the Ambient device?", "OK"); } this.SetViewState(false); }
private async void GetPhotonWiFiAsync() { PhotonWiFiListBox.DataContext = null; LoadWiFiProgress.IsActive = true; int maxRetries = 5; List <SoftAPScanAP> setupScanAPs = null; for (int tries = 0; tries < maxRetries; ++tries) { if (setupScanAPs == null) { setupScanAPs = await SoftAPConfig.GetScanAPsAsync(); } } LoadWiFiProgress.IsActive = false; PhotonWiFiListBox.DataContext = setupScanAPs; }
private async void ConfigureDeviceAsync() // STEP 1 { Step1ProgressRing.IsActive = true; Step1Grid.Visibility = Visibility.Visible; int result = await SoftAPConfig.SetConfigureAPAsync(configurIndex, SoftAPConfig.SoftAPData.ScanAP, SoftAPConfig.SoftAPData.Password, SoftAPConfig.SoftAPData.PublicKey); Step1ProgressRing.IsActive = false; Step1Checkmark.Visibility = Visibility.Visible; if (result == 0) { ConnectDeviceAsync(); } else { FailureToConfigure(); } }
private async void ConnectDeviceAsync() // STEP 2 { Step2ProgressRing.IsActive = true; Step2Grid.Visibility = Visibility.Visible; int result = await SoftAPConfig.SetConnectAPAsync(configurIndex); Step2ProgressRing.IsActive = false; Step2Checkmark.Visibility = Visibility.Visible; if (result == 0) { CloudConnectionAsync(); } else { FailureToConfigure(); } }
private async Task <bool> VerifyPhotonConnectionAsync(ConnectionProfile connectionProfile) { PhotonNetworkTextBlock.Text = connectionProfile.ProfileName; ProgressBar.IsIndeterminate = true; int setClaimCode = -1; int maxRetries = 5; for (int tries = 0; tries < maxRetries; ++tries) { if (SoftAPConfig.SoftAPData.Version == null) { SoftAPConfig.SoftAPData.Version = await SoftAPConfig.GetVersionAsync(); } if (SoftAPConfig.SoftAPData.DeviceId == null) { SoftAPConfig.SoftAPData.DeviceId = await SoftAPConfig.GetDeviceIdAsync(); } if (SoftAPConfig.SoftAPData.PublicKey == null) { SoftAPConfig.SoftAPData.PublicKey = await SoftAPConfig.GetPublicKeyAsync(); } if (setClaimCode == -1) { setClaimCode = await SoftAPConfig.SetClaimCodeAsync(SoftAPConfig.SoftAPData.ClaimCode); } } ProgressBar.IsIndeterminate = false; if (SoftAPConfig.SoftAPData.Version == null || SoftAPConfig.SoftAPData.DeviceId == null || SoftAPConfig.SoftAPData.PublicKey == null || setClaimCode == -1) { return(false); } return(true); }
public async void Start() { try { _iconFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///IoTOnboardingService/icon72x72.png")); var connectionProfiles = NetworkInformation.GetConnectionProfiles(); foreach (var profile in connectionProfiles) { if (profile.IsWlanConnectionProfile) { lock (_stateLock) { _state = OnboardingState.ConfiguredValidated; } break; } } // read configuration var configResult = await ReadConfig(); if (!configResult.Item1) { // for some reason config file doesn't seem to be OK // => reset config and try another time await ResetConfig(); configResult = await ReadConfig(); if (!configResult.Item1) { throw new System.IO.InvalidDataException("Invalid configuration"); } } _ajOnboardingConfig = configResult.Item2; _softAPConfig = configResult.Item3; bool monitorOk = await MonitorConfigFile(); if (!monitorOk) { throw new System.Exception("Unable to monitor configuration file for changes. Unexpected."); } // If everything is disabled, then there's nothing to do. if ((_softAPConfig.enabled == false) && (_ajOnboardingConfig.enabled == false)) { return; } // create softAP if (_softAccessPoint == null && (_softAPConfig.enabled || _ajOnboardingConfig.enabled)) { // The following builds up an Access Point SSID from information available to the IotOnboarding Task // If AllJoyn is enabled, then we must add AJ_ to the start of the SSID // If a Soft AP SSID value is specified in the configuration settings, then we will add that next // Finally we add the Soft AP's MAC Address to the end. Note that if a device does not have a WiFi adapter, // this _mac value will be a forced to the onboardingDevice ID GUID created the first time this app runs // // Examples: AllJoyn enabled, Wifi: AJ_SoftAPSsid_<MACADDRESS> // AllJoyn disabled, Wifi: SoftAPSsid_<MACADDRESS> // AllJoyn disabled, No Wifi: SoftAPSsid_<8Chars_of_Onboarding_GUID> // // string prefix = ""; string suffix = "_" + _mac; string ssid = ""; if (_ajOnboardingConfig.enabled) { prefix = SOFTAP_SSID_AJONBOARDING_PREFIX; } // SSID examples: AJ_SoftAPSsid_AABBCCDDEEFF ssid = prefix + _softAPConfig.ssid + suffix; _softAccessPoint = new OnboardingAccessPoint(ssid, _softAPConfig.password, _onboardingDeviceId); } // create AllJoyn related things if (_busAttachment == null && _ajOnboardingConfig.enabled) { _busAttachment = new AllJoynBusAttachment(); _busAttachment.AboutData.DefaultDescription = _ajOnboardingConfig.defaultDescription + " MAC: " + _mac; _busAttachment.AboutData.DefaultManufacturer = _ajOnboardingConfig.defaultManufacturer; _busAttachment.AboutData.ModelNumber = _ajOnboardingConfig.modelNumber; _onboardingProducer = new OnboardingProducer(_busAttachment); _onboardingProducer.Service = this; _busAttachment.AuthenticationMechanisms.Clear(); if (_ajOnboardingConfig.presharedKey.Length == 0) { _busAttachment.AuthenticationMechanisms.Add(AllJoynAuthenticationMechanism.EcdheNull); } else { _busAttachment.AuthenticationMechanisms.Add(AllJoynAuthenticationMechanism.EcdhePsk); } _busAttachment.CredentialsRequested += CredentialsRequested; _busAttachment.CredentialsVerificationRequested += CredentialsVerificationRequested; _busAttachment.AuthenticationComplete += AuthenticationComplete; _iconProducer = new IconProducer(_busAttachment); _iconProducer.Service = this; } if (_deviceWatcher == null) { var accessStatus = await WiFiAdapter.RequestAccessAsync(); if (accessStatus == WiFiAccessStatus.Allowed) { _deviceWatcher = DeviceInformation.CreateWatcher(WiFiAdapter.GetDeviceSelector()); _deviceWatcher.Added += this.HandleAdapterAdded; _deviceWatcher.Removed += this.HandleAdapterRemoved; _deviceWatcher.Start(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private async Task <Tuple <bool, AJOnboardingConfig, SoftAPConfig> > ReadConfig() { bool retVal = true; AJOnboardingConfig ajOnboardCfg = new AJOnboardingConfig(); SoftAPConfig softAPCfg = new SoftAPConfig(); try { // get config file from app folder var localFolder = ApplicationData.Current.LocalFolder; StorageFile configFile; if (await localFolder.TryGetItemAsync(CONFIG_FILE_NAME) == null) { // config file doesn't exist => copy it from the app package var installedLocation = Package.Current.InstalledLocation; var pkgFile = await installedLocation.GetFileAsync(CONFIG_FILE_NAME); configFile = await pkgFile.CopyAsync(localFolder); } else { configFile = await localFolder.GetFileAsync(CONFIG_FILE_NAME); } var xmlConfig = await XmlDocument.LoadFromFileAsync(configFile); // SoftAP config var xmlNode = xmlConfig.SelectSingleNode(NODE_SOFTAPENABLE); var tempString = GetXmlNodeValue(xmlNode); if (tempString == "true") { softAPCfg.enabled = true; } else { softAPCfg.enabled = false; } xmlNode = xmlConfig.SelectSingleNode(NODE_SOFTAPSSIDTEMPLATE); softAPCfg.ssid = GetXmlNodeValue(xmlNode); xmlNode = xmlConfig.SelectSingleNode(NODE_SOFTAPPASSWORD); softAPCfg.password = GetXmlNodeValue(xmlNode); // AllJoyn Onboarding config xmlNode = xmlConfig.SelectSingleNode(NODE_ALLJOYNONBOARDINGENABLE); tempString = GetXmlNodeValue(xmlNode); if (tempString == "true") { ajOnboardCfg.enabled = true; } else { ajOnboardCfg.enabled = false; } xmlNode = xmlConfig.SelectSingleNode(NODE_DEFAULTDESCRIPTIONTEMPLATE); ajOnboardCfg.defaultDescription = GetXmlNodeValue(xmlNode); xmlNode = xmlConfig.SelectSingleNode(NODE_DEFAULTMANUFACTURER); ajOnboardCfg.defaultManufacturer = GetXmlNodeValue(xmlNode); xmlNode = xmlConfig.SelectSingleNode(NODE_MODELNUMBER); ajOnboardCfg.modelNumber = GetXmlNodeValue(xmlNode); // For backwards compatbility with original config file. If the AllJoyn PSK is not found, // default to the ECDHE_NULL authentication method xmlNode = xmlConfig.SelectSingleNode(NODE_ALLJOYNPSK); if (xmlNode == null) { ajOnboardCfg.presharedKey = ""; } else { ajOnboardCfg.presharedKey = GetXmlNodeValue(xmlNode); } } catch (Exception) { retVal = false; } return(new Tuple <bool, AJOnboardingConfig, SoftAPConfig>(retVal, ajOnboardCfg, softAPCfg)); }