Merge pull request #477 from EdgeTX/403-access-denied

Enable ISRM internal module for non-FrSky hardware (T16 / TX16S / etc...)
This commit is contained in:
Raphael Coeffic
2021-07-27 06:02:45 +02:00
committed by GitHub
14 changed files with 112 additions and 90 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 */
};
+7 -6
View File
@@ -912,14 +912,15 @@ class ModuleWindow : public FormGroup {
if (moduleState[moduleIdx].mode == MODULE_MODE_BIND) {
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
return 0;
}
} else {
#if defined(MULTIMODULE)
else {
setMultiBindStatus(moduleIdx, MULTI_BIND_INITIATED);
if (isModuleMultimodule(moduleIdx)) {
setMultiBindStatus(moduleIdx, MULTI_BIND_INITIATED);
}
#endif
moduleState[moduleIdx].mode = MODULE_MODE_BIND;
return 1;
}
#endif
return 0;
});
bindButton->setCheckHandler([=]() {
@@ -927,7 +928,7 @@ class ModuleWindow : public FormGroup {
bindButton->check(false);
}
#if defined(MULTIMODULE)
if (getMultiBindStatus(moduleIdx) == MULTI_BIND_FINISHED) {
if (isModuleMultimodule(moduleIdx) && getMultiBindStatus(moduleIdx) == MULTI_BIND_FINISHED) {
setMultiBindStatus(moduleIdx, MULTI_BIND_NONE);
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
bindButton->check(false);
@@ -1029,7 +1030,7 @@ class ModuleWindow : public FormGroup {
}
// Receivers
if (isModulePXX2(moduleIdx)) {
if (isModuleRFAccess(moduleIdx)) {
for (uint8_t receiverIdx = 0; receiverIdx < PXX2_MAX_RECEIVERS_PER_MODULE; receiverIdx++) {
char label[] = TR_RECEIVER " X";
label[sizeof(label) - 2] = '1' + receiverIdx;
-8
View File
@@ -522,13 +522,11 @@ extern uint8_t flightModeTransitionLast;
#define availableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap))
#endif
extern uint32_t nextMixerTime[NUM_MODULES];
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);
void evalMixes(uint8_t tick10ms);
void doMixerCalculations();
void doMixerPeriodicUpdates();
void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms);
void checkTrims();
extern uint8_t currentBacklightBright;
@@ -1328,9 +1326,3 @@ inline bool isAsteriskDisplayed()
}
#include "module.h"
#if defined(ACCESS_LIB)
// TODO should be inside module.h
#include "thirdparty/libACCESS/libAccess.h"
#endif
-31
View File
@@ -329,18 +329,12 @@ bool setupPulsesExternalModule(uint8_t protocol)
#if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1_PULSES:
extmodulePulsesData.pxx.setupFrame(EXTERNAL_MODULE);
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX_PULSES_PERIOD);
#endif
return true;
#endif
#if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
extmodulePulsesData.pxx_uart.setupFrame(EXTERNAL_MODULE);
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, EXTMODULE_PXX1_SERIAL_PERIOD);
#endif
return true;
#endif
@@ -348,32 +342,22 @@ bool setupPulsesExternalModule(uint8_t protocol)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
case PROTOCOL_CHANNELS_PXX2_LOWSPEED:
extmodulePulsesData.pxx2.setupFrame(EXTERNAL_MODULE);
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX2_NO_HEARTBEAT_PERIOD);
#endif
return true;
#endif
#if defined(SBUS)
case PROTOCOL_CHANNELS_SBUS:
setupPulsesSbus();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, SBUS_PERIOD);
#else
// SBUS_PERIOD is not a constant! It can be set from UI
mixerSchedulerSetPeriod(EXTERNAL_MODULE, SBUS_PERIOD);
return true;
#endif
#endif
#if defined(DSM2)
case PROTOCOL_CHANNELS_DSM2_LP45:
case PROTOCOL_CHANNELS_DSM2_DSM2:
case PROTOCOL_CHANNELS_DSM2_DSMX:
setupPulsesDSM2();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, DSM2_PERIOD);
#endif
return true;
#endif
@@ -386,9 +370,6 @@ bool setupPulsesExternalModule(uint8_t protocol)
else
mixerSchedulerSetPeriod(EXTERNAL_MODULE, CROSSFIRE_PERIOD);
setupPulsesCrossfire();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, CROSSFIRE_PERIOD);
#endif
return true;
}
#endif
@@ -402,9 +383,6 @@ bool setupPulsesExternalModule(uint8_t protocol)
else
mixerSchedulerSetPeriod(EXTERNAL_MODULE, GHOST_PERIOD);
setupPulsesGhost();
#if defined(PCBSKPCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, GHOST_PERIOD);
#endif
return true;
}
#endif
@@ -418,9 +396,6 @@ bool setupPulsesExternalModule(uint8_t protocol)
else
mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD);
setupPulsesMultiExternalModule();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, MULTIMODULE_PERIOD);
#endif
return true;
}
#endif
@@ -428,18 +403,12 @@ bool setupPulsesExternalModule(uint8_t protocol)
#if defined(PPM)
case PROTOCOL_CHANNELS_PPM:
setupPulsesPPMExternalModule();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, PPM_PERIOD(EXTERNAL_MODULE));
#endif
return true;
#endif
#if defined(AFHDS3)
case PROTOCOL_CHANNELS_AFHDS3:
extmodulePulsesData.afhds3.setupFrame();
#if defined(PCBSKY9X)
scheduleNextMixerCalculation(EXTERNAL_MODULE, AFHDS3_COMMAND_TIMEOUT);
#endif
return true;
#endif
+2
View File
@@ -24,6 +24,7 @@
#include "pxx.h"
#include "crc.h"
#if defined(INTMODULE_HEARTBEAT_GPIO)
struct HeartbeatCapture {
#if !defined(INTMODULE_USART)
uint32_t timestamp;
@@ -35,6 +36,7 @@ struct HeartbeatCapture {
};
extern volatile HeartbeatCapture heartbeatCapture;
#endif
class Pxx1CrcMixin {
protected:
@@ -26,6 +26,7 @@ volatile HeartbeatCapture heartbeatCapture;
void init_intmodule_heartbeat()
{
TRACE("init_intmodule_heartbeat");
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
@@ -34,7 +35,8 @@ void init_intmodule_heartbeat()
GPIO_InitStructure.GPIO_Pin = INTMODULE_HEARTBEAT_GPIO_PIN;
GPIO_Init(INTMODULE_HEARTBEAT_GPIO, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(INTMODULE_HEARTBEAT_EXTI_PortSource, INTMODULE_HEARTBEAT_EXTI_PinSource);
SYSCFG_EXTILineConfig(INTMODULE_HEARTBEAT_EXTI_PortSource,
INTMODULE_HEARTBEAT_EXTI_PinSource);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_StructInit(&EXTI_InitStructure);
@@ -51,6 +53,7 @@ void init_intmodule_heartbeat()
void stop_intmodule_heartbeat()
{
TRACE("stop_intmodule_heartbeat");
heartbeatCapture.valid = false;
#if !defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
@@ -69,9 +72,7 @@ void stop_intmodule_heartbeat()
void check_intmodule_heartbeat()
{
if (EXTI_GetITStatus(INTMODULE_HEARTBEAT_EXTI_LINE) != RESET) {
#if defined(INTMODULE_USART)
nextMixerTime[INTERNAL_MODULE] = RTOS_GET_MS();
#else
#if !defined(INTMODULE_USART)
heartbeatCapture.timestamp = getTmr2MHz();
#endif
#if defined(DEBUG_LATENCY)
+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()
+1
View File
@@ -909,6 +909,7 @@
#define INTMODULE_HEARTBEAT_EXTI_PinSource GPIO_PinSource12
#define INTMODULE_HEARTBEAT_EXTI_LINE EXTI_Line12
#define INTMODULE_HEARTBEAT_EXTI_IRQn EXTI15_10_IRQn
#define INTMODULE_HEARTBEAT_EXTI_IRQHandler EXTI15_10_IRQHandler
#define INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER
#if defined(INTERNAL_MODULE_PXX2)
#define INTMODULE_HEARTBEAT_TRIGGER EXTI_Trigger_Falling
+4 -23
View File
@@ -127,9 +127,12 @@ void execMixerFrequentActions()
#if defined(BLUETOOTH)
bluetooth.wakeup();
#endif
DEBUG_TIMER_START(debugTimerTelemetryWakeup);
telemetryWakeup();
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
}
uint32_t nextMixerTime[NUM_MODULES];
TASK_FUNCTION(mixerTask)
{
@@ -212,10 +215,6 @@ TASK_FUNCTION(mixerTask)
usbJoystickUpdate();
#endif
DEBUG_TIMER_START(debugTimerTelemetryWakeup);
telemetryWakeup();
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
if (heartbeat == HEART_WDT_CHECK) {
WDG_RESET();
heartbeat = 0;
@@ -232,24 +231,6 @@ TASK_FUNCTION(mixerTask)
}
}
void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms)
{
// Schedule next mixer calculation time,
if (isModuleSynchronous(module)) {
nextMixerTime[module] += period_ms / RTOS_MS_PER_TICK;
if (nextMixerTime[module] < RTOS_GET_TIME()) {
// we are late ... let's add some small delay
nextMixerTime[module] = (uint32_t) RTOS_GET_TIME() + (period_ms / RTOS_MS_PER_TICK);
}
}
else {
// for now assume mixer calculation takes 2 ms.
nextMixerTime[module] = (uint32_t) RTOS_GET_TIME() + (period_ms / RTOS_MS_PER_TICK);
}
DEBUG_TIMER_STOP(debugTimerMixerCalcToUsage);
}
#define MENU_TASK_PERIOD_TICKS (50 / RTOS_MS_PER_TICK) // 50ms
+19 -5
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];
@@ -228,15 +235,21 @@ void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
globalData.upgradeModulePopup = 1;
POPUP_INFORMATION(STR_AUTH_FAILURE);
}
TRACE("[authFailed]\r\n", authenticateFrames);
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);
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
// we remain in AUTHENTICATION mode to avoid a CHANNELS frame is sent at the
// end of the mixing process
authenticateFrames++;
TRACE("[authFrame %d]\r\n", authenticateFrames);
}
if (!globalData.upgradeModulePopup) {
@@ -249,6 +262,7 @@ void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
}
}
}
#else
#define processAuthenticationFrame(module, frame)
#endif