Skip to content

Commit

Permalink
Add preliminary version of Wi-Fi configuration in device explorer (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Aug 7, 2018
1 parent 4d94684 commit e673603
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,19 @@ await ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
ViewModelLocator.DeviceExplorer.DeviceNetworkConfiguration = new Debugger.DeviceConfiguration.NetworkConfigurationProperties();
}

// for now, just get the 1st Wi-Fi configuration, if exists
var wirellesConfigurations = NanoDeviceCommService.Device.DebugEngine.GetAllWireless80211Configurations();

if (wirellesConfigurations.Count > 0)
{
ViewModelLocator.DeviceExplorer.DeviceWireless80211Configuration = wirellesConfigurations[0];
}
else
{
ViewModelLocator.DeviceExplorer.DeviceWireless80211Configuration = new Debugger.DeviceConfiguration.Wireless80211ConfigurationProperties();
}

// yield to give the UI thread a chance to respond to user input
await Task.Yield();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@

<!--MAC address-->
<Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Content="MAC address:" Margin="-6,0,0,0" />
<xctk:MaskedTextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Height="23" Mask="AA\:AA\:AA\:AA\:AA\:AA" VerticalAlignment="Top" Width="120" Margin="0,3,0,0" x:Name="MACAddress"/>
<xctk:MaskedTextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Height="23" Mask="AA\:AA\:AA\:AA\:AA\:AA" VerticalAlignment="Center" VerticalContentAlignment="Center" Width="120" Margin="0,3,0,0" x:Name="MACAddress"/>

<!--Interface type-->
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Interface type:" Margin="-6,0,0,0" />
<ComboBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" IsEnabled="False">
<ListBoxItem Content="Ethernet" Tag="6"/>
<ListBoxItem Content="Wireless 802.11" Tag="71"/>
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Interface type:" Margin="-6,6,0,0" />
<ComboBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" VerticalAlignment="Center" Margin="0,6,0,0" x:Name="InterfaceType">
<ListBoxItem Content="Ethernet" Tag="ETH"/>
<ListBoxItem Content="Wireless 802.11" Tag="WIFI"/>
</ComboBox>
<!--<xctk:MaskedTextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Mask="AA\:AA\:AA\:AA\:AA\:AA" VerticalAlignment="Top" Width="120" Margin="0,3,0,0" x:Name="InterfaceType"/>-->

Expand All @@ -126,6 +126,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
Expand All @@ -134,27 +135,42 @@

<!--SSID-->
<Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Content="SSID:" Margin="-6,0,0,0" />
<xctk:MaskedTextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" MaxLength="32" Height="23" VerticalAlignment="Top" Width="120" Margin="0,3,0,0" x:Name="SSID"/>
<xctk:MaskedTextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" MaxLength="32" Height="23" VerticalContentAlignment="Center" VerticalAlignment="Center" Width="120" Margin="0,3,0,0" Text="{Binding DeviceWireless80211Configuration.Ssid, Mode=TwoWay}" x:Name="SSID"/>

<!--Pass-->
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Password:" Margin="-6,0,0,0" />
<xctk:WatermarkPasswordBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" MaxLength="64" Height="23" VerticalAlignment="Top" Width="120" Margin="0,3,0,0" x:Name="WiFiPassword"/>
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Password:" Margin="-6,6,0,0" />
<xctk:WatermarkPasswordBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" MaxLength="64" Height="23" VerticalContentAlignment="Center" VerticalAlignment="Center" Width="120" Margin="0,6,0,0" Text="{Binding DeviceWireless80211Configuration.Password, Mode=TwoWay}" x:Name="WiFiPassword"/>

<!--Security type-->
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Content="Security type:" Margin="-6,0,0,0" />
<ComboBox Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" x:Name="SecurityType">
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Content="Security type:" Margin="-6,6,0,0" />
<ComboBox Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" VerticalAlignment="Center" Margin="0,6,0,0" x:Name="SecurityType">
<ListBoxItem Content="WPA2-Personal" Tag="WPA2"/>
<ListBoxItem Content="WPA2-Enterprise" Tag="WPA2"/>
<ListBoxItem Content="WPA" Tag="WPA"/>
<ListBoxItem Content="EAP" Tag="EAP"/>
<ListBoxItem Content="Open" Tag="Open"/>
<ListBoxItem Content="Shared" Tag="SHARED"/>
</ComboBox>

<!--Encryption type-->
<Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Content="Encryption type:" Margin="-6,0,0,0" />
<ComboBox Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" x:Name="EncryptionType">
<ListBoxItem Content="AES" Tag="AES"/>
<Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Content="Encryption type:" Margin="-6,6,0,0" />
<ComboBox Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" VerticalAlignment="Center" Margin="0,6,0,0" x:Name="EncryptionType">
<ListBoxItem Content="None" Tag="NONE"/>
<ListBoxItem Content="WEP" Tag="WEP"/>
<ListBoxItem Content="WPA" Tag="WPA"/>
<ListBoxItem Content="WPA2" Tag="WPA2"/>
<ListBoxItem Content="WPA Pre-shared key" Tag="WPAPSK"/>
<ListBoxItem Content="WPA2 Pre-shared key" Tag="WPA2PSK"/>
</ComboBox>

<!--Radio type-->
<Label Grid.Row="4" Grid.Column="0" HorizontalAlignment="Left" Content="Radio type:" Margin="-6,6,0,0" />
<ComboBox Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left" Height="23" Width="120" SelectedIndex="0" VerticalAlignment="Center" Margin="0,6,0,0" x:Name="RadioType">
<ListBoxItem Content="802.11a" Tag="802_11a"/>
<ListBoxItem Content="802.11b" Tag="802_11b"/>
<ListBoxItem Content="802.11g" Tag="802_11g"/>
<ListBoxItem Content="802.11n" Tag="802_11n"/>
</ComboBox>

</Grid>
</TabItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace nanoFramework.Tools.VisualStudio.Extension
using System;
using System.Linq;
using System.Net;
using System.Windows.Controls;

/// <summary>
/// Interaction logic for DeviceExplorerControl.
Expand Down Expand Up @@ -42,6 +43,7 @@ private void InitControls()
{
var networkConfiguration = (DataContext as DeviceExplorerViewModel).DeviceNetworkConfiguration;

// network config
// set IPv4 addresses
// DHCP ?
if ((networkConfiguration.StartupAddressMode == AddressMode.DHCP) ||
Expand All @@ -63,7 +65,7 @@ private void InitControls()
}

// DNS is automatic?
if (networkConfiguration.AutomaticDNS)
if (networkConfiguration.AutomaticDNS || networkConfiguration.IsUnknown)
{
IPv4DnsAutomatic.IsChecked = true;

Expand All @@ -84,6 +86,9 @@ private void InitControls()
MACAddress.Text = String.Join("", networkConfiguration.MacAddress.Select(a => a.ToString("X2")));
}

// wireless config


// set focus on cancel button
CancelButton.Focus();
}
Expand Down Expand Up @@ -173,15 +178,29 @@ private void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e)
(DataContext as DeviceExplorerViewModel).SelectedDevice.CreateDebugEngine();
}


// save network configuration to target...
if ((DataContext as DeviceExplorerViewModel).SelectedDevice.DebugEngine.UpdateDeviceConfiguration(networkConfigurationToSave, 0))
{
MessageCentre.OutputMessage($"{(DataContext as DeviceExplorerViewModel).SelectedDevice.Description} network configuration updated.");
MessageCentre.StopProgressMessage();

// close on success
Close();
if ((InterfaceType.SelectedItem as ListBoxItem).Tag as string == "WIFI")
{
// need to save Wireless

// TODO need to parse the various security options

if ((DataContext as DeviceExplorerViewModel).SelectedDevice.DebugEngine.UpdateDeviceConfiguration((DataContext as DeviceExplorerViewModel).DeviceWireless80211Configuration, 0))
{
MessageCentre.OutputMessage($"{(DataContext as DeviceExplorerViewModel).SelectedDevice.Description} network configuration updated.");
MessageCentre.StopProgressMessage();

// close on success
Close();
}
}
else
{
// close on success
Close();
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ public void OnSelectedTransportTypeChanged()

public DeviceConfiguration.NetworkConfigurationProperties DeviceNetworkConfiguration { get; set; }

public DeviceConfiguration.Wireless80211ConfigurationProperties DeviceWireless80211Configuration { get; set; }

#endregion

#region messaging tokens
Expand Down

0 comments on commit e673603

Please sign in to comment.