From a40072069f5613e94bdc4686224d9186970ad042 Mon Sep 17 00:00:00 2001 From: Nunu Date: Sat, 13 Jan 2024 18:39:07 +0100 Subject: [PATCH] Revert "UART disabled in locked state." This reverts commit 1227460f952de4a126705bddcc36eb51ddb91ea4. --- app/uart.c | 35 ++++++++++++++++++++++------------- board.c | 12 ++++++++++++ main.c | 1 - misc.c | 3 ++- misc.h | 3 ++- ui/lock.c | 8 +++++++- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/app/uart.c b/app/uart.c index c1aa6ea..60cf0b6 100644 --- a/app/uart.c +++ b/app/uart.c @@ -191,7 +191,7 @@ static void SendVersion(void) Reply.Header.ID = 0x0515; Reply.Header.Size = sizeof(Reply.Data); strcpy(Reply.Data.Version, Version); - Reply.Data.bHasCustomAesKey = false; + Reply.Data.bHasCustomAesKey = bHasCustomAesKey; Reply.Data.bIsInLockScreen = bIsInLockScreen; Reply.Data.Challenge[0] = gChallenge[0]; Reply.Data.Challenge[1] = gChallenge[1]; @@ -223,6 +223,7 @@ static void CMD_051B(const uint8_t *pBuffer) { const CMD_051B_t *pCmd = (const CMD_051B_t *)pBuffer; REPLY_051B_t Reply; + bool bLocked = false; if (pCmd->Timestamp != Timestamp) return; @@ -239,8 +240,11 @@ static void CMD_051B(const uint8_t *pBuffer) Reply.Data.Offset = pCmd->Offset; Reply.Data.Size = pCmd->Size; + if (bHasCustomAesKey) + bLocked = gIsLocked; - EEPROM_ReadBuffer(pCmd->Offset, Reply.Data.Data, pCmd->Size); + if (!bLocked) + EEPROM_ReadBuffer(pCmd->Offset, Reply.Data.Data, pCmd->Size); SendReply(&Reply, pCmd->Size + 8); } @@ -250,6 +254,7 @@ static void CMD_051D(const uint8_t *pBuffer) const CMD_051D_t *pCmd = (const CMD_051D_t *)pBuffer; REPLY_051D_t Reply; bool bReloadEeprom; + bool bIsLocked; if (pCmd->Timestamp != Timestamp) return; @@ -266,23 +271,27 @@ static void CMD_051D(const uint8_t *pBuffer) Reply.Header.Size = sizeof(Reply.Data); Reply.Data.Offset = pCmd->Offset; + bIsLocked = bHasCustomAesKey ? gIsLocked : bHasCustomAesKey; - unsigned int i; - for (i = 0; i < (pCmd->Size / 8); i++) + if (!bIsLocked) { - const uint16_t Offset = pCmd->Offset + (i * 8U); + unsigned int i; + for (i = 0; i < (pCmd->Size / 8); i++) + { + const uint16_t Offset = pCmd->Offset + (i * 8U); - if (Offset >= 0x0F30 && Offset < 0x0F40) - bReloadEeprom = true; + if (Offset >= 0x0F30 && Offset < 0x0F40) + if (!gIsLocked) + bReloadEeprom = true; - if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !bIsInLockScreen || pCmd->bAllowPassword) - EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U], true); + if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !bIsInLockScreen || pCmd->bAllowPassword) + EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U], true); + } + + if (bReloadEeprom) + BOARD_EEPROM_Init(); } - if (bReloadEeprom) - BOARD_EEPROM_Init(); - - SendReply(&Reply, sizeof(Reply)); } diff --git a/board.c b/board.c index 5b74575..29e26fd 100644 --- a/board.c +++ b/board.c @@ -727,6 +727,18 @@ void BOARD_EEPROM_Init(void) } } + // 0F30..0F3F + EEPROM_ReadBuffer(0x0F30, gCustomAesKey, sizeof(gCustomAesKey)); + bHasCustomAesKey = false; + for (i = 0; i < ARRAY_SIZE(gCustomAesKey); i++) + { + if (gCustomAesKey[i] != 0xFFFFFFFFu) + { + bHasCustomAesKey = true; + return; + } + } + #ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME BOARD_gMR_LoadChannels(); #endif diff --git a/main.c b/main.c index 97f7779..d4d4d26 100644 --- a/main.c +++ b/main.c @@ -177,7 +177,6 @@ void Main(void) if (gEeprom.POWER_ON_PASSWORD < PASSWORD_OFF) { bIsInLockScreen = true; - gIsLocked = true; UI_DisplayLock(); bIsInLockScreen = false; } diff --git a/misc.c b/misc.c index 5c94f6a..37c3d94 100644 --- a/misc.c +++ b/misc.c @@ -97,6 +97,7 @@ uint8_t gSetting_battery_text; bool gMonitor = false; // true opens the squelch uint32_t gCustomAesKey[4]; +bool bHasCustomAesKey; uint32_t gChallenge[4]; uint8_t gTryCount; @@ -248,7 +249,7 @@ volatile uint8_t boot_counter_10ms; int16_t gCurrentRSSI[2] = {0, 0}; // now one per VFO -bool gIsLocked = false; +uint8_t gIsLocked = 0xFF; diff --git a/misc.h b/misc.h index 3bf239e..30a89bd 100644 --- a/misc.h +++ b/misc.h @@ -173,6 +173,7 @@ extern bool gMonitor; extern const uint32_t gDefaultAesKey[4]; extern uint32_t gCustomAesKey[4]; +extern bool bHasCustomAesKey; extern uint32_t gChallenge[4]; extern uint8_t gTryCount; @@ -353,7 +354,7 @@ extern volatile uint8_t gVFOStateResumeCountdown_500ms; extern volatile bool gScheduleFM; #endif extern int16_t gCurrentRSSI[2]; // now one per VFO -extern bool gIsLocked; +extern uint8_t gIsLocked; extern volatile uint8_t boot_counter_10ms; int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit); diff --git a/ui/lock.c b/ui/lock.c index 2e03571..8af64d3 100644 --- a/ui/lock.c +++ b/ui/lock.c @@ -112,7 +112,6 @@ void UI_DisplayLock(void) if ((gEeprom.POWER_ON_PASSWORD) == Password) { AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); - gIsLocked = false; gEeprom.PASSWORD_WRONG_ATTEMPTS = 0; return; } @@ -156,6 +155,13 @@ void UI_DisplayLock(void) gKeyReading0 = Key; } + if (UART_IsCommandAvailable()) + { + __disable_irq(); + UART_HandleCommand(); + __enable_irq(); + } + if (gUpdateDisplay) { Render();