Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with wireless config save/load #135

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions source/USB Test App WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,17 +739,30 @@ private async void SetDeviceConfigButton_Click(object sender, RoutedEventArgs e)
//deviceConfig.NetworkConfiguraton.MacAddress = new byte[] { 0, 0x80, 0xe1, 0x01, 0x35, 0x56 };
//deviceConfig.NetworkConfiguraton.StartupAddressMode = DeviceConfiguration.AddressMode.DHCP;

// set new network configuration on the specific class
DeviceConfiguration.NetworkConfigurationProperties newDeviceNetworkConfiguration = new DeviceConfiguration.NetworkConfigurationProperties();
newDeviceNetworkConfiguration.MacAddress = new byte[] { 0, 0x80, 0xe1, 0x01, 0x35, 0x56 };
newDeviceNetworkConfiguration.InterfaceType = nanoFramework.Tools.Debugger.NetworkInterfaceType.Ethernet;
newDeviceNetworkConfiguration.StartupAddressMode = AddressMode.DHCP;
// update new network configuration
DeviceConfiguration.NetworkConfigurationProperties newDeviceNetworkConfiguration = new DeviceConfiguration.NetworkConfigurationProperties
{
MacAddress = new byte[] { 0, 0x80, 0xe1, 0x01, 0x35, 0x56 },
InterfaceType = nanoFramework.Tools.Debugger.NetworkInterfaceType.Ethernet,
StartupAddressMode = AddressMode.DHCP,

newDeviceNetworkConfiguration.IPv4DNSAddress1 = IPAddress.Parse("192.168.1.254");
IPv4DNSAddress1 = IPAddress.Parse("192.168.1.254"),
};

// write device configuration to device
var returnValue = device.DebugEngine.UpdateDeviceConfiguration(newDeviceNetworkConfiguration, 0);

// add new wireless 802.11 configuration
DeviceConfiguration.Wireless80211ConfigurationProperties newWireless80211Configuration = new DeviceConfiguration.Wireless80211ConfigurationProperties()
{
Id = 44,
Ssid = "Nice_Ssid",
Password = "1234",
};

// write wireless configuration to device
returnValue = device.DebugEngine.UpdateDeviceConfiguration(newWireless80211Configuration, 0);

Debug.WriteLine("");
Debug.WriteLine("");
Debug.WriteLine($"device config update result: {returnValue}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public Wireless80211ConfigurationProperties(Wireless80211ConfigurationBase confi
Authentication = (AuthenticationType)config.Authentication;
Encryption = (EncryptionType)config.Encryption;
Radio = (RadioType)config.Radio;
Ssid = config.Ssid;
Password = config.Password;
Ssid = Encoding.UTF8.GetString(config.Ssid).Trim('\0');
Password = Encoding.UTF8.GetString(config.Password).Trim('\0');

// reset unknown flag
IsUnknown = false;
Expand All @@ -225,13 +225,15 @@ public static explicit operator Wireless80211ConfigurationBase(Wireless80211Conf
Marker = Encoding.UTF8.GetBytes(MarkerConfigurationWireless80211_v1),

Id = value.Id,

Authentication = (byte)value.Authentication,
Encryption = (byte)value.Encryption,
Radio = (byte)value.Radio,
Ssid = value.Ssid,
Password = value.Password,
};
};

// the following ones are strings so they need to be copied over to the array
// this is required to when serializing the class the struct size matches the one in the native end
Array.Copy(Encoding.UTF8.GetBytes(value.Ssid), 0, networkWirelessConfig.Ssid, 0, value.Ssid.Length);
Array.Copy(Encoding.UTF8.GetBytes(value.Password), 0, networkWirelessConfig.Password, 0, value.Password.Length);

return networkWirelessConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ public class NetworkConfigurationBase
/// Address mode (static, DHCP or auto IP)
/// </summary>
public byte StartupAddressMode;

public NetworkConfigurationBase()
{
// need to init this here to match the expected size on the struct to be sent to the device
Marker = new byte[4];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ public class Wireless80211ConfigurationBase

/// <summary>
/// Network SSID
/// 32 bytes length.
/// </summary>
public string Ssid;
public byte[] Ssid;

/// <summary>
/// Network password
/// 64 bytes length.
/// </summary>
public string Password;
public byte[] Password;

public Wireless80211ConfigurationBase()
{
// need to init these here to match the expected size on the struct to be sent to the device
Marker = new byte[4];
Ssid = new byte[32];
Password = new byte[64];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ public NetworkWirelessConfiguration()
Authentication = (byte)AuthenticationType.None ;
Encryption = (byte)EncryptionType.None;
Radio = (byte)RadioType.None;
}
Ssid = new byte[32];
Password = new byte[64];
}

public void PrepareForDeserialize(int size, byte[] data, Converter converter)
{
Expand All @@ -321,6 +323,8 @@ public void PrepareForDeserialize(int size, byte[] data, Converter converter)
Authentication = (byte)AuthenticationType.None;
Encryption = (byte)EncryptionType.None;
Radio = (byte)RadioType.None;
Ssid = new byte[32];
Password = new byte[64];
}
}
}
Expand Down