Skip to content

Commit

Permalink
Merge pull request #96 from kamilsss655/encryption
Browse files Browse the repository at this point in the history
[WIP] Encryption
  • Loading branch information
kamilsss655 authored Jan 26, 2024
2 parents 2178942 + bf94da3 commit d7c27d0
Show file tree
Hide file tree
Showing 33 changed files with 791 additions and 330 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ENABLE_MESSENGER := 1
ENABLE_MESSENGER_DELIVERY_NOTIFICATION := 1
ENABLE_MESSENGER_NOTIFICATION := 1
ENABLE_MESSENGER_UART := 0
ENABLE_ENCRYPTION := 1

#############################################################

Expand Down Expand Up @@ -163,6 +164,10 @@ ifeq ($(ENABLE_MESSENGER),1)
OBJS += app/messenger.o
OBJS += ui/messenger.o
endif
ifeq ($(ENABLE_ENCRYPTION),1)
OBJS += external/chacha/chacha.o
OBJS += helper/crypto.o
endif

ifeq ($(OS), Windows_NT)
TOP := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
Expand Down Expand Up @@ -222,7 +227,10 @@ endif

CFLAGS =
ifeq ($(ENABLE_CLANG),0)
CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
# Highest optimization settings (possible breaking changes):
CFLAGS += -Oz -mcpu=cortex-m0 -fno-delete-null-pointer-checks -std=c11 -MMD
# Standard settings:
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c99 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu99 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu11 -MMD
Expand Down Expand Up @@ -374,6 +382,9 @@ endif
ifeq ($(ENABLE_MESSENGER_UART),1)
CFLAGS += -DENABLE_MESSENGER_UART
endif
ifeq ($(ENABLE_ENCRYPTION),1)
CFLAGS += -DENABLE_ENCRYPTION
endif

LDFLAGS =
ifeq ($(ENABLE_CLANG),0)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This repository is a fork of [Egzumer firmare](https://github.com/egzumer/uv-k5-firmware-custom) plus my changes:

* `ENABLE_SPECTRUM_CHANNEL_SCAN` this enables spectrum channel scan mode (enter by going into memory mode and press F+5, this allows SUPER fast channel scanning (**4.5x faster than regular scanning**), regular scan of 200 memory channels takes roughly 18 seconds, **spectrum memory scan takes roughly 4 seconds**, if you have less channels stored i.e 50 - the spectrum memory scan will take only **1 second**
* `ENABLE_ENCRYPTION` - ChaCha20 256 bit encryption for the messenger, more info at [Encryption](https://github.com/kamilsss655/uv-k5-firmware-custom/wiki/44-%E2%80%90-Encryption#details)
* Fixed AM AGC so **AM demodulation is crystal clear**, no audible clicks, no need for `AM_FIX`.
* `RxOff` menu setting offsets the receive frequency by any specified amount in the range of `0-150Mhz` for use with upconverters. Allows to fine tune frequency (in `1kHz` steps) as opposed to other implementations that use hardcoded offsets. (**IMPORTANT: Make sure you set this value to 0 if not using an upconverter, when used for the first time. Otherwise it might load some random offset from EEPROM.**)
* `ENABLE_SPECTRUM_COPY_VFO` allowing to exit the spectrum and fine tuning screen with PTT button and copy current peak frequency, modulation, step, bandwidth to VFO. Also entering spectrum will carry these settings from VFO (full integration). Now to enter fine tuning screen in spectrum press MENU button. This allows you to save and respond to the frequencies found much faster.
Expand Down Expand Up @@ -159,6 +160,7 @@ ENABLE_SPECTRUM_SHOW_CHANNEL_NAME := 1 shows channel number and channel n
ENABLE_ULTRA_LOW_POWER_TX := 0 transmits with ultra low power. useful for dev/testing
ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS := 1 keeps the rx gain settings set in spectrum mode after exit (otherwise these are always overwritten to default value), this makes much more sense considering that we have a radio with user adjustable gain so why not use it to adjust to current radio conditions, maximum gain allows to greatly increase reception in scan memory channels mode (in this configuration default gain settings are only set at boot and when exiting AM modulation mode to set it to sane value after am fix)
ENABLE_SPECTRUM_CHANNEL_SCAN := 1 this enables spectrum channel scan mode (enter by going into memory mode and press F+5, this allows SUPER fast channel scanning (4.5x faster than regular scanning), regular scan of 200 memory channels takes roughly 18 seconds, spectrum memory scan takes roughly 4 seconds, if you have less channels stored i.e 50 - the spectrum memory scan will take only **1 second**
ENABLE_ENCRYPTION := 1 enable ChaCha20 256 bit encryption for messenger
```


Expand Down
30 changes: 0 additions & 30 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,12 @@ void ACTION_Monitor(void)

RADIO_SetupRegisters(true);

#ifdef ENABLE_FMRADIO
if (gFmRadioMode) {
FM_Start();
gRequestDisplayScreen = DISPLAY_FM;
}
else
#endif
gRequestDisplayScreen = gScreenToDisplay;
}

void ACTION_Scan(bool bRestart)
{
(void)bRestart;
#ifdef ENABLE_FMRADIO
if (gFmRadioMode)
{
if (gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_TRANSMIT)
{
GUI_SelectNextDisplay(DISPLAY_FM);

gMonitor = false;

if (gFM_ScanState != FM_SCAN_OFF)
{
FM_Start();

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
#endif
}
}
return;
}
#endif

if (!SCANNER_IsScanning())
{ // not scanning
Expand Down
92 changes: 36 additions & 56 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,17 +915,6 @@ void APP_Update(void)
}
}

#ifdef ENABLE_FMRADIO
if (gScheduleFM &&
gFM_ScanState != FM_SCAN_OFF &&
gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_TRANSMIT)
{ // switch to FM radio mode
FM_Start();
gScheduleFM = false;
}
#endif

#ifdef ENABLE_VOX
if (gEeprom.VOX_SWITCH)
Expand Down Expand Up @@ -1419,9 +1408,9 @@ void APP_TimeSlice500ms(void)

if (gReducedService)
{
BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent);
BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage);

if (gBatteryCurrent > 500 || gBatteryCalibration[3] < gBatteryCurrentVoltage)
if (gBatteryCalibration[3] < gBatteryCurrentVoltage)
{
#ifdef ENABLE_OVERLAY
overlay_FLASH_RebootToBootloader();
Expand All @@ -1442,7 +1431,7 @@ void APP_TimeSlice500ms(void)

if ((gBatteryCheckCounter & 1) == 0)
{
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[gBatteryVoltageIndex++], &gBatteryCurrent);
BOARD_ADC_GetBatteryInfo(&gBatteryVoltages[gBatteryVoltageIndex++]);
if (gBatteryVoltageIndex > 3)
gBatteryVoltageIndex = 0;
BATTERY_GetReadings(true);
Expand All @@ -1452,16 +1441,12 @@ void APP_TimeSlice500ms(void)
// regular display updates (once every 2 sec) - if need be
if ((gBatteryCheckCounter & 3) == 0)
{
if (gChargingWithTypeC || gSetting_battery_text > 0)
if (gSetting_battery_text > 0)
gUpdateStatus = true;
#ifdef ENABLE_SHOW_CHARGE_LEVEL
if (gChargingWithTypeC)
gUpdateDisplay = true;
#endif
}

#ifdef ENABLE_FMRADIO
if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && !gCssBackgroundScan)
if (gAskToSave && !gCssBackgroundScan)
#else
if (!gCssBackgroundScan)
#endif
Expand Down Expand Up @@ -1893,51 +1878,45 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
#endif
}
else if (Key != KEY_SIDE1 && Key != KEY_SIDE2) {
switch (gScreenToDisplay) {
case DISPLAY_MAIN:
switch (gScreenToDisplay) {
case DISPLAY_MAIN:
if ((Key == KEY_SIDE1 || Key == KEY_SIDE2) && !SCANNER_IsScanning())
{
ACTION_Handle(Key, bKeyPressed, bKeyHeld);
}
else
MAIN_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;

break;
#ifdef ENABLE_FMRADIO
case DISPLAY_FM:
FM_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
case DISPLAY_FM:
FM_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
case DISPLAY_MENU:
MENU_ProcessKeys(Key, bKeyPressed, bKeyHeld);
case DISPLAY_MENU:
MENU_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;

#ifdef ENABLE_MESSENGER
case DISPLAY_MSG:
MSG_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;

#ifdef ENABLE_MESSENGER
case DISPLAY_MSG:
MSG_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
#endif

case DISPLAY_SCANNER:
SCANNER_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
case DISPLAY_SCANNER:
SCANNER_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;

#ifdef ENABLE_AIRCOPY
case DISPLAY_AIRCOPY:
AIRCOPY_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
case DISPLAY_INVALID:
default:
break;
}
}
else
#ifdef ENABLE_AIRCOPY
if (!SCANNER_IsScanning() && gScreenToDisplay != DISPLAY_AIRCOPY)
#else
if (!SCANNER_IsScanning())
case DISPLAY_AIRCOPY:
AIRCOPY_ProcessKeys(Key, bKeyPressed, bKeyHeld);
break;
#endif
{
ACTION_Handle(Key, bKeyPressed, bKeyHeld);
case DISPLAY_INVALID:
default:
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
else if (!bKeyHeld && bKeyPressed)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
}

Skip:
Expand All @@ -1963,6 +1942,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
SETTINGS_SaveSettings();
else
gFlagSaveSettings = 1;

gRequestSaveSettings = false;
gUpdateStatus = true;
}
Expand Down
9 changes: 1 addition & 8 deletions app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,8 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
case KEY_EXIT:
Key_EXIT();
break;
case KEY_F:
GENERIC_Key_F(bKeyPressed, bKeyHeld);
break;
case KEY_PTT:
GENERIC_Key_PTT(bKeyPressed);
break;
default:
if (!bKeyHeld && bKeyPressed)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
}
Expand Down
18 changes: 3 additions & 15 deletions app/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld)
}
else // released
{
#ifdef ENABLE_FMRADIO
if ((gFmRadioMode || gScreenToDisplay != DISPLAY_MAIN) && gScreenToDisplay != DISPLAY_FM)
return;
#else
if (gScreenToDisplay != DISPLAY_MAIN)
return;
#endif

if (gScreenToDisplay != DISPLAY_MAIN)
return;

gWasFKeyPressed = !gWasFKeyPressed; // toggle F function

Expand All @@ -90,14 +86,6 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld)
return;
}

#ifdef ENABLE_FMRADIO
if (gFM_ScanState == FM_SCAN_OFF) // not scanning
{
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
return;
}
#endif

gBeepToPlay = BEEP_440HZ_500MS;

gPttWasReleased = true;
Expand Down
Loading

0 comments on commit d7c27d0

Please sign in to comment.