mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Device validation
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
var def =
|
var def = ///
|
||||||
{
|
|
||||||
"messages": [
|
|
||||||
{
|
{
|
||||||
|
"messages": [{
|
||||||
"id": "SettingsCalibrationWarning",
|
"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."
|
"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",
|
"id": "OffString",
|
||||||
"maxLen": 3,
|
"maxLen": 3,
|
||||||
"description": "Shown when a setting is turned off."
|
"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",
|
"id": "SettingsResetMessage",
|
||||||
"description": "Shown when the settings are reset to factory defaults either by the user or by incompatible firmware changes."
|
"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."
|
"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",
|
"id": "SettingRightChar",
|
||||||
"len": 1,
|
"len": 1,
|
||||||
"description": "Shown for fixed Right-handed display rotation."
|
"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."
|
"description": "Shown when the locking mode is set to lock all buttons."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"menuGroups": [
|
"menuGroups": [{
|
||||||
{
|
|
||||||
"id": "PowerMenu",
|
"id": "PowerMenu",
|
||||||
"maxLen": 5,
|
"maxLen": 5,
|
||||||
"maxLen2": 11,
|
"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."
|
"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",
|
"id": "DCInCutoff",
|
||||||
"maxLen": 5,
|
"maxLen": 5,
|
||||||
"maxLen2": 11,
|
"maxLen2": 11,
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ uint64_t getDeviceID();
|
|||||||
|
|
||||||
// If device has burned in validation code's, return the code
|
// If device has burned in validation code's, return the code
|
||||||
uint32_t getDeviceValidation();
|
uint32_t getDeviceValidation();
|
||||||
|
// If device validation passes returns 0
|
||||||
|
uint8_t getDeviceValidationStatus();
|
||||||
|
|
||||||
// Status LED controls
|
// Status LED controls
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "TipThermoModel.h"
|
#include "TipThermoModel.h"
|
||||||
#include "USBPD.h"
|
#include "USBPD.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "crc16.hpp"
|
#include "crc32.h"
|
||||||
#include "history.hpp"
|
#include "history.hpp"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
|
||||||
@@ -328,32 +328,29 @@ uint64_t getDeviceID() {
|
|||||||
|
|
||||||
return __builtin_bswap64(tmp);
|
return __builtin_bswap64(tmp);
|
||||||
}
|
}
|
||||||
uint16_t gethash() {
|
auto crc32Table = CRC32Table<>();
|
||||||
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);
|
|
||||||
|
|
||||||
uint32_t result = crcInitialVector;
|
uint32_t gethash() {
|
||||||
for (int i = 0; i < 10; i++) {
|
static uint32_t computedHash = 0;
|
||||||
result = crc16(result, crcPayload[i]);
|
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 getDeviceValidation() {
|
||||||
uint32_t userData = 0;
|
|
||||||
EF_Ctrl_Read_Sw_Usage(0, &userData);
|
|
||||||
// 4 byte user data burned in at factory
|
// 4 byte user data burned in at factory
|
||||||
// TODO TESTING
|
return EF_Ctrl_Get_Key_Slot_w1();
|
||||||
// userData |= gethash() << 16;
|
|
||||||
return userData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getDeviceValidationStatus() {
|
uint8_t getDeviceValidationStatus() {
|
||||||
|
uint32_t programmedHash = EF_Ctrl_Get_Key_Slot_w1();
|
||||||
return 1; // Device is OK
|
uint32_t computedHash = gethash();
|
||||||
|
return programmedHash == computedHash ? 0 : 1;
|
||||||
}
|
}
|
||||||
@@ -83,6 +83,7 @@ struct TranslationIndexTable {
|
|||||||
uint16_t SleepingAdvancedString;
|
uint16_t SleepingAdvancedString;
|
||||||
uint16_t SleepingTipAdvancedString;
|
uint16_t SleepingTipAdvancedString;
|
||||||
uint16_t OffString;
|
uint16_t OffString;
|
||||||
|
uint16_t DeviceFailedValidationWarning;
|
||||||
|
|
||||||
uint16_t SettingsResetMessage;
|
uint16_t SettingsResetMessage;
|
||||||
uint16_t NoAccelerometerMessage;
|
uint16_t NoAccelerometerMessage;
|
||||||
|
|||||||
@@ -897,9 +897,12 @@ static void showPDDebug(void) {
|
|||||||
void showWarnings() {
|
void showWarnings() {
|
||||||
// Display alert if settings were reset
|
// Display alert if settings were reset
|
||||||
if (settingsWereReset) {
|
if (settingsWereReset) {
|
||||||
|
|
||||||
warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND);
|
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
|
#ifndef NO_WARN_MISSING
|
||||||
// We also want to alert if accel or pd is not detected / not responding
|
// 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
|
// In this case though, we dont want to nag the user _too_ much
|
||||||
|
|||||||
Reference in New Issue
Block a user