From 4fbdcbb352adfc9a70ea53268ca6ec93c0bf702a Mon Sep 17 00:00:00 2001 From: Nunu Date: Wed, 24 Jan 2024 15:45:39 +0100 Subject: [PATCH] menu enc key added --- app/menu.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++------ settings.h | 3 +++ ui/menu.c | 23 ++++++++++++++++++++ ui/menu.h | 3 +++ 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/app/menu.c b/app/menu.c index b20f810..a80e069 100644 --- a/app/menu.c +++ b/app/menu.c @@ -1183,7 +1183,13 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) + if (edit_index >= 0 && ( + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME + #ifdef ENABLE_ENCRYPTION + || UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY + #endif + )) + { // currently editing the channel name if (edit_index < 10) @@ -1455,15 +1461,42 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) return; } + #ifdef ENABLE_ENCRYPTION + if (UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY) + { + if (edit_index < 0) + { // enter encryption key edit mode + // pad the encryption key out with '_' + // TODO: Extract to shared function - common with MENU_MEM_NAME below + edit_index = strlen(edit); + while (edit_index < 10) + edit[edit_index++] = '_'; + edit[edit_index] = 0; + edit_index = 0; // 'edit_index' is going to be used as the cursor position + + return; + } + else if (edit_index >= 0 && edit_index < 10) + { // editing the encryption key characters + + if (++edit_index < 10) + return; // next char + + // exit, save encryption key + memcpy(gEeprom.ENC_KEY, edit, sizeof(gEeprom.ENC_KEY)); + } + } + #endif + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) { if (edit_index < 0) { // enter channel name edit mode if (!RADIO_CheckValidChannel(gSubMenuSelection, false, 0)) - return; - + return; + SETTINGS_FetchChannelName(edit, gSubMenuSelection); - + // pad the channel name out with '_' edit_index = strlen(edit); while (edit_index < 10) @@ -1613,10 +1646,19 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) uint8_t Channel; bool bCheckScanList; - if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && gIsInSubMenu && edit_index >= 0) + if (gIsInSubMenu && + edit_index >= 0 && + ( + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME + #ifdef ENABLE_ENCRYPTION + || UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY + #endif + ) + ) { // change the character if (bKeyPressed && edit_index < 10 && Direction != 0) { + // TODO: Allow special chars when setting encryption key const char unwanted[] = "$%&!\"':;?^`|{}"; char c = edit[edit_index] + Direction; unsigned int i = 0; @@ -1747,8 +1789,16 @@ void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) MENU_Key_STAR(bKeyPressed, bKeyHeld); break; case KEY_F: - if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) - { // currently editing the channel name + if (edit_index >= 0 && + ( + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME + #ifdef ENABLE_ENCRYPTION + || UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY + #endif + ) + ) + { // adds space, + // currently editing the channel name or enc_key if (!bKeyHeld && bKeyPressed) { gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; diff --git a/settings.h b/settings.h index 5f3f83c..377c06d 100644 --- a/settings.h +++ b/settings.h @@ -245,6 +245,9 @@ typedef struct { #ifdef ENABLE_PWRON_PASSWORD uint32_t POWER_ON_PASSWORD; uint8_t PASSWORD_WRONG_ATTEMPTS; +#endif +#ifdef ENABLE_ENCRYPTION + char ENC_KEY[10]; #endif uint16_t VOX1_THRESHOLD; uint16_t VOX0_THRESHOLD; diff --git a/ui/menu.c b/ui/menu.c index e81cb13..79009d1 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -111,6 +111,9 @@ const t_menu_item MenuList[] = {"RxMode", VOICE_ID_DUAL_STANDBY, MENU_TDR }, #ifdef ENABLE_PWRON_PASSWORD {"Passwd", VOICE_ID_INVALID, MENU_PASSWORD }, // power on password +#endif +#ifdef ENABLE_ENCRYPTION + {"EncKey", VOICE_ID_INVALID, MENU_ENC_KEY }, // encryption key #endif {"Sql", VOICE_ID_SQUELCH, MENU_SQL }, // hidden menu items from here on @@ -721,6 +724,26 @@ void UI_DisplayMenu(void) already_printed = true; break; } + #ifdef ENABLE_ENCRYPTION + case MENU_ENC_KEY: + { + if (!gIsInSubMenu) + { // show the key + strcpy(String, "****"); + UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8); + } + else + { // show the key being edited + sprintf(String, "%s", gEeprom.ENC_KEY); + UI_PrintString(edit, (menu_item_x1 -2), 0, 2, 8); + if (edit_index != -1 && edit_index < 10) + UI_PrintString( "^", (menu_item_x1 -2) + (8 * edit_index), 0, 4, 8); // show the cursor + } + + already_printed = true; + break; + } + #endif case MENU_SAVE: strcpy(String, gSubMenu_SAVE[gSubMenuSelection]); diff --git a/ui/menu.h b/ui/menu.h index 74bf7a2..f40cace 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -61,6 +61,9 @@ enum MENU_TDR, #ifdef ENABLE_PWRON_PASSWORD MENU_PASSWORD, +#endif +#ifdef ENABLE_ENCRYPTION + MENU_ENC_KEY, #endif MENU_BEEP, #ifdef ENABLE_VOICE