Skip to content

Commit

Permalink
Merge pull request #66 from kamilsss655/rc19.1
Browse files Browse the repository at this point in the history
Rc19.1
  • Loading branch information
kamilsss655 committed Jan 13, 2024
2 parents 60d0427 + 8719df9 commit d0f97a8
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 203 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ENABLE_VOICE := 0
ENABLE_VOX := 1
ENABLE_ALARM := 0
ENABLE_TX1750 := 0
ENABLE_PWRON_PASSWORD := 0
ENABLE_PWRON_PASSWORD := 1
ENABLE_DTMF_CALLING := 0

#---- DEBUG ----
Expand Down Expand Up @@ -83,9 +83,6 @@ OBJS += external/printf/printf.o

# Drivers
OBJS += driver/adc.o
ifeq ($(ENABLE_UART),1)
OBJS += driver/aes.o
endif
OBJS += driver/backlight.o
ifeq ($(ENABLE_FMRADIO),1)
OBJS += driver/bk1080.o
Expand Down
34 changes: 33 additions & 1 deletion app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,13 @@ void MENU_AcceptSetting(void)
gUpdateStatus = true;
break;

#ifdef ENABLE_PWRON_PASSWORD
case MENU_PASSWORD:
gEeprom.POWER_ON_PASSWORD = MIN(gSubMenuSelection, PASSWORD_OFF);
gUpdateStatus = true;
break;
#endif

case MENU_W_N:
gTxVfo->CHANNEL_BANDWIDTH = gSubMenuSelection;
gRequestSaveChannel = 1;
Expand Down Expand Up @@ -903,6 +910,12 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gEeprom.RX_OFFSET;
break;

#ifdef ENABLE_PWRON_PASSWORD
case MENU_PASSWORD:
gSubMenuSelection = gEeprom.POWER_ON_PASSWORD;
break;
#endif

case MENU_W_N:
gSubMenuSelection = gTxVfo->CHANNEL_BANDWIDTH;
break;
Expand All @@ -916,7 +929,8 @@ void MENU_ShowCurrentSetting(void)
break;

case MENU_MEM_CH:
gSubMenuSelection = RADIO_ValidMemoryChannelsCount(false, 0);
//todo: in vfo mode select last empty channel slot
gSubMenuSelection = gEeprom.MrChannel[gEeprom.TX_VFO];
break;

case MENU_MEM_NAME:
Expand Down Expand Up @@ -1258,6 +1272,17 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gInputBoxIndex = 0;
return;
}
#ifdef ENABLE_PWRON_PASSWORD
if (UI_MENU_GetCurrentMenuId() == MENU_PASSWORD)
{
// get 4 digits
if (gInputBoxIndex < 4) { return; }

uint32_t Password;
Password = StrToUL(INPUTBOX_GetAscii());
gSubMenuSelection = Password;
}
#endif

if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH ||
UI_MENU_GetCurrentMenuId() == MENU_DEL_CH ||
Expand Down Expand Up @@ -1650,6 +1675,13 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
gRequestDisplayScreen = DISPLAY_MENU;
return;
}
#ifdef ENABLE_PWRON_PASSWORD
if (UI_MENU_GetCurrentMenuId() == MENU_PASSWORD)
{
gSubMenuSelection = PASSWORD_OFF;
gRequestDisplayScreen = DISPLAY_MENU;
}
#endif

VFO = 0;

Expand Down
70 changes: 0 additions & 70 deletions app/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "board.h"
#include "bsp/dp32g030/dma.h"
#include "bsp/dp32g030/gpio.h"
#include "driver/aes.h"
#include "driver/backlight.h"
#include "driver/bk4819.h"
#include "driver/crc.h"
Expand Down Expand Up @@ -120,11 +119,6 @@ typedef struct {
} Data;
} REPLY_0529_t;

typedef struct {
Header_t Header;
uint32_t Response[4];
} CMD_052D_t;

typedef struct {
Header_t Header;
struct {
Expand Down Expand Up @@ -207,25 +201,6 @@ static void SendVersion(void)
SendReply(&Reply, sizeof(Reply));
}

static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint32_t *pResponse)
{
unsigned int i;
uint32_t IV[4];

IV[0] = 0;
IV[1] = 0;
IV[2] = 0;
IV[3] = 0;

AES_Encrypt(pKey, IV, pIn, IV, true);

for (i = 0; i < 4; i++)
if (IV[i] != pResponse[i])
return true;

return false;
}

static void CMD_0514(const uint8_t *pBuffer)
{
const CMD_0514_t *pCmd = (const CMD_0514_t *)pBuffer;
Expand Down Expand Up @@ -346,47 +321,6 @@ static void CMD_0529(void)
SendReply(&Reply, sizeof(Reply));
}

static void CMD_052D(const uint8_t *pBuffer)
{
const CMD_052D_t *pCmd = (const CMD_052D_t *)pBuffer;
REPLY_052D_t Reply;
bool bIsLocked;

#ifdef ENABLE_FMRADIO
gFmRadioCountdown_500ms = fm_radio_countdown_500ms;
#endif
Reply.Header.ID = 0x052E;
Reply.Header.Size = sizeof(Reply.Data);

bIsLocked = bHasCustomAesKey;

if (!bIsLocked)
bIsLocked = IsBadChallenge(gCustomAesKey, gChallenge, pCmd->Response);

if (!bIsLocked)
{
bIsLocked = IsBadChallenge(gDefaultAesKey, gChallenge, pCmd->Response);
if (bIsLocked)
gTryCount++;
}

if (gTryCount < 3)
{
if (!bIsLocked)
gTryCount = 0;
}
else
{
gTryCount = 3;
bIsLocked = true;
}

gIsLocked = bIsLocked;
Reply.Data.bIsLocked = bIsLocked;

SendReply(&Reply, sizeof(Reply));
}

static void CMD_052F(const uint8_t *pBuffer)
{
const CMD_052F_t *pCmd = (const CMD_052F_t *)pBuffer;
Expand Down Expand Up @@ -544,10 +478,6 @@ void UART_HandleCommand(void)
CMD_0529();
break;

case 0x052D:
CMD_052D(UART_Command.Buffer);
break;

case 0x052F:
CMD_052F(UART_Command.Buffer);
break;
Expand Down
15 changes: 13 additions & 2 deletions board.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "sram-overlay.h"
#endif
#include "ui/menu.h"
#include "ARMCM0.h"

static const uint32_t gDefaultFrequencyTable[] =
{
Expand Down Expand Up @@ -579,15 +580,20 @@ void BOARD_EEPROM_Init(void)
gEeprom.POWER_ON_DISPLAY_MODE = (Data[7] < 4) ? Data[7] : POWER_ON_DISPLAY_MODE_VOLTAGE;

// 0E98..0E9F
EEPROM_ReadBuffer(0x0E98, Data, 8);
memmove(&gEeprom.POWER_ON_PASSWORD, Data, 4);
#ifdef ENABLE_PWRON_PASSWORD
EEPROM_ReadBuffer(0x0E98, Data, 8);
memmove(&gEeprom.POWER_ON_PASSWORD, Data, 4);
#endif

// 0EA0..0EA7
EEPROM_ReadBuffer(0x0EA0, Data, 8);
#ifdef ENABLE_VOX
gEeprom.VOX_DELAY = (Data[0] < 11) ? Data[0] : 4;
#endif
gEeprom.RX_AGC = (Data[1] < RX_AGC_LEN) ? Data[1] : RX_AGC_SLOW;
#ifdef ENABLE_PWRON_PASSWORD
gEeprom.PASSWORD_WRONG_ATTEMPTS = (Data[2] > PASSWORD_MAX_RETRIES) ? PASSWORD_MAX_RETRIES : Data[2];
#endif

// 0EA8..0EAF
EEPROM_ReadBuffer(0x0EA8, Data, 8);
Expand Down Expand Up @@ -868,6 +874,9 @@ void BOARD_FactoryReset(bool bIsAll)
{
RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000);
gEeprom.RX_OFFSET = 0;
gEeprom.POWER_ON_PASSWORD = PASSWORD_OFF;
gEeprom.PASSWORD_WRONG_ATTEMPTS = 0;
SETTINGS_SaveSettings();
// set the first few memory channels
for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++)
{
Expand All @@ -877,5 +886,7 @@ void BOARD_FactoryReset(bool bIsAll)
gRxVfo->Band = FREQUENCY_GetBand(Frequency);
SETTINGS_SaveChannel(MR_CHANNEL_FIRST + i, 0, gRxVfo, 2);
}
// reboot device
NVIC_SystemReset();
}
}
Binary file modified docs/UV K5 EEPROM.xlsx
Binary file not shown.
74 changes: 0 additions & 74 deletions driver/aes.c

This file was deleted.

25 changes: 0 additions & 25 deletions driver/aes.h

This file was deleted.

6 changes: 3 additions & 3 deletions driver/bk1080.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201);
}

BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F);
// Europe/USA configuration
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (0u << 8) | (0b00 << 6) | (0b01 << 4) | (0b1111 << 0));
BK1080_SetFrequency(Frequency);
}
else
Expand All @@ -78,8 +79,7 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
}

// Europe/USA configuration
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (0u << 8) | (0b00 << 6) | (0b01 << 4) | (0b1111 << 0));

}

uint16_t BK1080_ReadRegister(BK1080_Register_t Register)
Expand Down
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ void Main(void)
}

#ifdef ENABLE_PWRON_PASSWORD
if (gEeprom.POWER_ON_PASSWORD < 1000000)
if (gEeprom.POWER_ON_PASSWORD < PASSWORD_OFF)
{
bIsInLockScreen = true;
UI_DisplayLock();
bIsInLockScreen = false;
}
gEeprom.PASSWORD_WRONG_ATTEMPTS = 0;
gFlagSaveSettings = true;
#endif

BOOT_ProcessMode(BootMode);
Expand Down
7 changes: 7 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ enum {
LAST_CHANNEL
};

#ifdef ENABLE_PWRON_PASSWORD
enum {
PASSWORD_OFF = 10000u
};
#define PASSWORD_MAX_RETRIES 3
#endif

enum {
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
Expand Down
Loading

0 comments on commit d0f97a8

Please sign in to comment.