1
0
forked from me/IronOS

Device validation

This commit is contained in:
Ben V. Brown
2022-06-21 20:52:05 +10:00
parent 51ad2f71c7
commit 85f30f2da6
5 changed files with 437 additions and 434 deletions

View File

@@ -1,7 +1,6 @@
var def =
{
"messages": [
var def = ///
{
"messages": [{
"id": "SettingsCalibrationWarning",
"description": "Confirmation message shown before performing an offset calibration. Should warn the user to make sure tip and handle are at the same temperature."
},
@@ -45,10 +44,14 @@ var def =
"id": "OffString",
"maxLen": 3,
"description": "Shown when a setting is turned off."
},
{
"id": "DeviceFailedValidationWarning",
"default": "Device may be\ncounterfeit",
"description": "Warning shown if the device may be a clone or counterfeit unit."
}
],
"messagesWarn": [
{
"messagesWarn": [{
"id": "SettingsResetMessage",
"description": "Shown when the settings are reset to factory defaults either by the user or by incompatible firmware changes."
},
@@ -77,8 +80,7 @@ var def =
"description": "Warning text shown when the software has disabled the heater as a safety precaution as the temperature reading didn't react as expected."
}
],
"characters": [
{
"characters": [{
"id": "SettingRightChar",
"len": 1,
"description": "Shown for fixed Right-handed display rotation."
@@ -176,8 +178,7 @@ var def =
"description": "Shown when the locking mode is set to lock all buttons."
}
],
"menuGroups": [
{
"menuGroups": [{
"id": "PowerMenu",
"maxLen": 5,
"maxLen2": 11,
@@ -209,8 +210,7 @@ var def =
"description": "Advanced settings. Misc catchall for settings that don't fit anywhere else or settings that require some thought before use."
}
],
"menuOptions": [
{
"menuOptions": [{
"id": "DCInCutoff",
"maxLen": 5,
"maxLen2": 11,

View File

@@ -79,6 +79,8 @@ uint64_t getDeviceID();
// If device has burned in validation code's, return the code
uint32_t getDeviceValidation();
// If device validation passes returns 0
uint8_t getDeviceValidationStatus();
// Status LED controls

View File

@@ -8,7 +8,7 @@
#include "TipThermoModel.h"
#include "USBPD.h"
#include "configuration.h"
#include "crc16.hpp"
#include "crc32.h"
#include "history.hpp"
#include "main.hpp"
@@ -328,32 +328,29 @@ uint64_t getDeviceID() {
return __builtin_bswap64(tmp);
}
uint16_t gethash() {
uint32_t userData = 0;
EF_Ctrl_Read_Sw_Usage(0, &userData);
userData &= 0xFFFF; // We only want the lower two bytes
// TODO FOR TESTING OVERRIDE
userData = 0xDEAD;
const uint16_t crcInitialVector = 0xCAFE;
uint8_t crcPayload[] = {userData & 0xFF, (userData >> 8) & 0xFF, 0, 0, 0, 0, 0, 0, 0, 0};
EF_Ctrl_Read_Chip_ID(crcPayload + 2);
auto crc32Table = CRC32Table<>();
uint32_t result = crcInitialVector;
for (int i = 0; i < 10; i++) {
result = crc16(result, crcPayload[i]);
uint32_t gethash() {
static uint32_t computedHash = 0;
if (computedHash != 0) {
return computedHash;
}
return result & 0xFFFF;
uint32_t deviceKey = EF_Ctrl_Get_Key_Slot_w0();
const uint32_t crcInitialVector = 0xCAFEF00D;
uint8_t crcPayload[] = {(uint8_t)(deviceKey), (uint8_t)(deviceKey >> 8), (uint8_t)(deviceKey >> 16), (uint8_t)(deviceKey >> 24), 0, 0, 0, 0, 0, 0, 0, 0};
EF_Ctrl_Read_Chip_ID(crcPayload + sizeof(deviceKey)); // Load device key into second half
computedHash = crc32Table.computeCRC32(crcInitialVector, crcPayload, sizeof(crcPayload));
return computedHash;
}
uint32_t getDeviceValidation() {
uint32_t userData = 0;
EF_Ctrl_Read_Sw_Usage(0, &userData);
// 4 byte user data burned in at factory
// TODO TESTING
// userData |= gethash() << 16;
return userData;
return EF_Ctrl_Get_Key_Slot_w1();
}
uint8_t getDeviceValidationStatus() {
return 1; // Device is OK
uint32_t programmedHash = EF_Ctrl_Get_Key_Slot_w1();
uint32_t computedHash = gethash();
return programmedHash == computedHash ? 0 : 1;
}

View File

@@ -83,6 +83,7 @@ struct TranslationIndexTable {
uint16_t SleepingAdvancedString;
uint16_t SleepingTipAdvancedString;
uint16_t OffString;
uint16_t DeviceFailedValidationWarning;
uint16_t SettingsResetMessage;
uint16_t NoAccelerometerMessage;

View File

@@ -897,9 +897,12 @@ static void showPDDebug(void) {
void showWarnings() {
// Display alert if settings were reset
if (settingsWereReset) {
warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND);
}
if (getDeviceValidationStatus()) {
// Warn user this device might be counterfeit
warnUser(translatedString(Tr->DeviceFailedValidationWarning), 10 * TICKS_SECOND);
}
#ifndef NO_WARN_MISSING
// We also want to alert if accel or pd is not detected / not responding
// In this case though, we dont want to nag the user _too_ much