Replace proprietary libAccess

This commit is contained in:
Raphael Coeffic
2021-07-20 13:52:29 +02:00
parent d3c16a89c4
commit 00e4194a70
8 changed files with 86 additions and 21 deletions
+3 -4
View File
@@ -2,7 +2,6 @@
path = radio/src/thirdparty/libopenui
url = https://github.com/EdgeTX/libopenui.git
branch = master
[submodule "libACCESS"]
path = radio/src/thirdparty/libACCESS
url = https://github.com/FrSkyRC/libACCESS.git
branch = master
[submodule "radio/src/thirdparty/AccessDenied"]
path = radio/src/thirdparty/AccessDenied
url = https://github.com/raphaelcoeffic/AccessDenied.git
+10 -6
View File
@@ -70,6 +70,7 @@ set(FIRMWARE_CXX_COMPILER "${GCC_ARM_PATH}arm-none-eabi-g++" CACHE STRING "Speci
set(FIRMWARE_ASM_COMPILER "${GCC_ARM_PATH}arm-none-eabi-as" CACHE STRING "Specific assembler for firmware target.")
set(FIRMWARE_OBJCOPY "${GCC_ARM_PATH}arm-none-eabi-objcopy" CACHE STRING "Specific objcopy for firmware target.")
set(FIRMWARE_SIZE "${GCC_ARM_PATH}arm-none-eabi-size" CACHE STRING "Specific size for firmware target.")
set(FIRMWARE_RANLIB "${GCC_ARM_PATH}arm-none-eabi-ranlib" CACHE STRING "Specific ranlib for firmware target.")
set(THIRDPARTY_DIR thirdparty)
set(LUA_DIR ${THIRDPARTY_DIR}/Lua/src)
@@ -499,8 +500,8 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "")
# customize linker command
set(CMAKE_EXE_LINKER_FLAGS "")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET>")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET>")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
@@ -514,6 +515,7 @@ if(NOT MSVC)
set(CMAKE_C_COMPILER ${FIRMWARE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${FIRMWARE_CXX_COMPILER})
set(CMAKE_ASM_COMPILER ${FIRMWARE_ASM_COMPILER})
set(CMAKE_RANLIB ${FIRMWARE_RANLIB})
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
@@ -528,10 +530,6 @@ if(NOT MSVC)
# these are in addition to CMAKE_CXX_FLAGS
set(CMAKE_EXE_LINKER_FLAGS "-lm -T${RADIO_SRC_DIR}/${LINKER_SCRIPT} -Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections")
if(ACCESS_LIB)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--whole-archive ${RADIO_SRC_DIR}/${THIRDPARTY_DIR}/libACCESS/libAccess.a -Wl,--no-whole-archive")
endif()
if(SEMIHOSTING)
add_definitions(-DSEMIHOSTING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=rdimon.specs")
@@ -577,6 +575,12 @@ if(NOT MSVC)
add_dependencies(firmware ${RADIO_DEPENDENCIES} ${FIRMWARE_DEPENDENCIES})
set_target_properties(firmware PROPERTIES EXCLUDE_FROM_ALL TRUE)
if(ACCESS_DENIED)
add_subdirectory(thirdparty/AccessDenied)
include_directories(thirdparty/AccessDenied)
target_link_libraries(firmware AccessDenied)
endif()
add_custom_command(
TARGET firmware POST_BUILD
COMMAND ${FIRMWARE_OBJCOPY} -O binary firmware.elf firmware.bin
+58
View File
@@ -1091,6 +1091,10 @@ int cliDebugVars(const char ** argv)
serialPrint("ioMutexReq=%d", ioMutexReq);
serialPrint("ioMutexRel=%d", ioMutexRel);
serialPrint("sdReadRetries=%d", sdReadRetries);
#if defined(ACCESS_DENIED)
extern volatile int32_t authenticateFrames;
serialPrint("authenticateFrames=%d", authenticateFrames);
#endif
#elif defined(PCBTARANIS)
serialPrint("telemetryErrors=%d", telemetryErrors);
#endif
@@ -1189,6 +1193,57 @@ int cliBlueTooth(const char ** argv)
}
#endif
#if defined(ACCESS_DENIED)
extern "C" {
#include "AccessDenied/access_denied.h"
}
static uint8_t cryptInput[16];
static uint8_t cryptOutput[16];
static void testAccessDenied(uint32_t runs)
{
while(runs--)
access_denied(0, cryptInput, cryptOutput);
}
int cliCrypt(const char ** argv)
{
if (argv[1][0] == '\0')
return -1;
strncpy((char*)cryptInput, argv[1], sizeof(cryptInput));
serialPrint("Input:");
dumpBody(cryptInput, sizeof(cryptInput));
dumpEnd();
watchdogSuspend(2000/* 20s */);
if (pulsesStarted()) {
pausePulses();
}
pauseMixerCalculations();
perMainEnabled = false;
uint32_t startMs = RTOS_GET_MS();
testAccessDenied(100000);
serialPrintf("access_denied: %f us/run\r\n", (RTOS_GET_MS() - startMs)*1000.0f / 100000.0f);
serialPrint("Decrypted (SW):");
dumpBody(cryptOutput, sizeof(cryptOutput));
dumpEnd();
perMainEnabled = true;
if (pulsesStarted()) {
resumePulses();
}
resumeMixerCalculations();
watchdogSuspend(0);
return 0;
}
#endif
const CliCommand cliCommands[] = {
{ "beep", cliBeep, "[<frequency>] [<duration>]" },
{ "ls", cliLs, "<directory>" },
@@ -1217,6 +1272,9 @@ const CliCommand cliCommands[] = {
#endif
#if defined(BLUETOOTH)
{ "bt", cliBlueTooth, "<baudrate>|<command>" },
#endif
#if defined(ACCESS_DENIED)
{ "crypt", cliCrypt, "<string to be encrypted>" },
#endif
{ nullptr, nullptr, nullptr } /* sentinel */
};
-6
View File
@@ -1328,9 +1328,3 @@ inline bool isAsteriskDisplayed()
}
#include "module.h"
#if defined(ACCESS_LIB)
// TODO should be inside module.h
#include "thirdparty/libACCESS/libAccess.h"
#endif
+2 -2
View File
@@ -202,8 +202,8 @@ if(INTERNAL_MODULE_PXX2)
add_definitions(-DHARDWARE_INTERNAL_MODULE)
add_definitions(-DINTERNAL_MODULE_PXX2)
if (NOT PCBREV STREQUAL EXPRESS)
set(ACCESS_LIB ON)
add_definitions(-DACCESS_LIB)
set(ACCESS_DENIED ON)
add_definitions(-DACCESS_DENIED)
endif()
endif()
+12 -2
View File
@@ -217,7 +217,14 @@ void processTelemetryFrame(uint8_t module, const uint8_t * frame)
}
}
#if defined(ACCESS_LIB) && !defined(SIMU)
#if defined(INTERNAL_MODULE_PXX2) && defined(ACCESS_DENIED) && !defined(SIMU)
extern "C" {
#include "AccessDenied/access_denied.h"
};
volatile int16_t authenticateFrames = 0;
void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
{
uint8_t cryptoType = frame[3];
@@ -231,12 +238,14 @@ void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
return;
}
if (INTERNAL_MODULE == module && accessCRL(cryptoType, frame+4, messageDigest)) {
if (INTERNAL_MODULE == module && access_denied(cryptoType, frame+4, messageDigest)) {
moduleState[module].mode = MODULE_MODE_AUTHENTICATION;
Pxx2Pulses & pxx2 = intmodulePulsesData.pxx2;
pxx2.setupAuthenticationFrame(module, cryptoType, (const uint8_t *)messageDigest);
intmoduleSendBuffer(pxx2.getData(), pxx2.getSize());
// we remain in AUTHENTICATION mode to avoid a CHANNELS frame is sent at the end of the mixing process
authenticateFrames++;
serialPrint("[authFrame %d]\r\n", authenticateFrames);
}
if (!globalData.upgradeModulePopup) {
@@ -249,6 +258,7 @@ void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
}
}
}
#else
#define processAuthenticationFrame(module, frame)
#endif