From 2ebc202e346cc2b2634fe2ed845a53e84159c9bb Mon Sep 17 00:00:00 2001 From: weiwentan23 Date: Wed, 26 Jan 2022 10:43:47 +0800 Subject: [PATCH 1/4] add device firmware UI check --- .../PasskeyConfigurationApp/MainPage.xaml.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs index 9ba9fdf1..55b77ca4 100644 --- a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs +++ b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs @@ -146,6 +146,14 @@ private void ShimmerDevice_BLEEvent(object sender, ShimmerBLEEventData e) { deviceState.Text = device.GetVerisenseBLEState().ToString(); }); + if(device.GetVerisenseBLEState() == ShimmerDeviceBluetoothState.Connected) + { + if (device.GetProductionConfig().REV_FW_INTERNAL < 99) + { + DisconnectDevices(); + DisplayAlert("Error!", "Firmware below 1.02.99 is not supported\nYour device will now be disconnect", "OK"); + } + } } } From 04927e487421615fe955b32b28b1dbdf180453d2 Mon Sep 17 00:00:00 2001 From: weiwentan23 Date: Fri, 28 Jan 2022 16:00:34 +0800 Subject: [PATCH 2/4] disable write passkey when custom setting is selected --- .../PasskeyConfigurationApp/MainPage.xaml.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs index 9ba9fdf1..d2f7f333 100644 --- a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs +++ b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs @@ -54,6 +54,7 @@ public async void ScanDevices() public void PasskeySettings_SelectedIndexChanged(object sender, EventArgs e) { + writePasskeyConfigurationButton.IsEnabled = true; switch (passkeySettings.SelectedIndex) { // no passkey @@ -76,6 +77,7 @@ public void PasskeySettings_SelectedIndexChanged(object sender, EventArgs e) break; // custom case 3: + writePasskeyConfigurationButton.IsEnabled = false; deviceAdvertisingNamePrefix.Text = ""; passkeyId.Text = ""; passkey.Text = ""; @@ -222,7 +224,7 @@ public async void WritePasskeyConfigurationButton() break; // custom case 3: - break; + return; default: break; } } From 2451a860486a94fd911e431f2da75e93dac316ff Mon Sep 17 00:00:00 2001 From: weiwentan23 Date: Mon, 31 Jan 2022 09:31:00 +0800 Subject: [PATCH 3/4] Add passkey check when writing production config --- .../ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs | 13 +++++++++++++ .../ShimmerBLEAPI/Models/ProdConfigPayload.cs | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs index 3cd5bf14..3176204a 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs @@ -607,6 +607,19 @@ public async Task ExecuteRequest(params Object[] reqObjects) case RequestType.WriteProductionConfig: if (additionalBytesToWrite != null) { + if (additionalBytesToWrite.Length >= 55) + { + byte[] passkeyBytes = new byte[ProdConfig.PasskeyLength]; + Array.Copy(additionalBytesToWrite, (int)ProdConfigPayload.ConfigurationBytesIndexName.PASSKEY, passkeyBytes, 0, passkeyBytes.Length); + for (int i = 0; i < passkeyBytes.Length; i++) + { + if (passkeyBytes[i] != 0xFF && !int.TryParse(Encoding.UTF8.GetString(passkeyBytes, i, 1), out _)) + { + throw new Exception("Passkey Must Be Numeric Values"); + } + } + } + //needs a header request = new byte[additionalBytesToWrite.Length + 3]; Array.Copy(additionalBytesToWrite, 0, request, 3, additionalBytesToWrite.Length); diff --git a/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs b/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs index 723f9a74..9d52ac28 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs @@ -31,9 +31,9 @@ public enum ConfigurationBytesIndexName ADVERTISING_NAME_PREFIX = 23 } - readonly int PasskeyIDLength = 2; - readonly int PasskeyLength = 6; - readonly int AdvertisingNameLength = 32; + public readonly int PasskeyIDLength = 2; + public readonly int PasskeyLength = 6; + public readonly int AdvertisingNameLength = 32; public ProdConfigPayload(string payload) { @@ -137,9 +137,12 @@ protected void SetPasskey(string passkey) } else if (passkey.Length == PasskeyLength) { - if (!int.TryParse(passkey, out _)) + for (int i = 0; i < PasskeyLength; i++) { - throw new Exception("Passkey Must Be Numeric Values"); + if (!int.TryParse(passkey[i].ToString(), out _)) + { + throw new Exception("Passkey Must Be Numeric Values"); + } } byte[] passkeyArray = Encoding.UTF8.GetBytes(passkey); From c64fa028dc5d7f5596f0b649f483d690e380d1a9 Mon Sep 17 00:00:00 2001 From: Jong Chern Date: Thu, 3 Feb 2022 15:12:57 +0800 Subject: [PATCH 4/4] minor update --- .../PasskeyConfigurationApp/MainPage.xaml.cs | 2 +- .../ShimmerBLEAPI/Devices/VerisenseDevice.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs index 06bbb4ff..3f6ef993 100644 --- a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs +++ b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs @@ -150,7 +150,7 @@ private void ShimmerDevice_BLEEvent(object sender, ShimmerBLEEventData e) }); if(device.GetVerisenseBLEState() == ShimmerDeviceBluetoothState.Connected) { - if (device.GetProductionConfig().REV_FW_INTERNAL < 99) + if (!device.MeetsMinimumFWRequirement(1,2,99)) // check if meets minimum requirement of 1.2.99 { DisconnectDevices(); DisplayAlert("Error!", "Firmware below 1.02.99 is not supported\nYour device will now be disconnect", "OK"); diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs index 2e2d8e49..0d6ca83f 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs @@ -600,6 +600,30 @@ public DeviceByteArraySettings(string displayName, byte[] operationalConfigurati public string GetDescription() { return Description; } } + /// + /// Returns true if the input version is smaller or equal + /// + /// + /// + /// + /// + public bool MeetsMinimumFWRequirement(int compMajor, int compMinor, int compInternal) + { + if (ProdConfig != null) + { + if ((compMajor < ProdConfig.REV_FW_MAJOR) + || (ProdConfig.REV_FW_MAJOR == compMajor && compMinor < ProdConfig.REV_FW_MINOR) + || (ProdConfig.REV_FW_MAJOR == compMajor && ProdConfig.REV_FW_MINOR == compMinor && compInternal <= ProdConfig.REV_FW_INTERNAL)) + { + return true; // if the version is smaller or equal + } + } else + { + throw new Exception("Production Config Unknown"); + } + return false; // if less + } + public static DeviceByteSetting GetDeviceSettingFromConfigurationValue(DeviceByteSetting[] settings, int value) { foreach (DeviceByteSetting setting in settings)