Fix PXX2 authentication support

This commit is contained in:
Raphael Coeffic
2022-08-11 12:15:46 +02:00
committed by Raphael Coeffic
parent 4cecdc0cae
commit df0d115a72
4 changed files with 21 additions and 13 deletions
+4 -1
View File
@@ -775,7 +775,10 @@ static void pxx2ProcessData(void* context, uint8_t data, uint8_t* buffer, uint8_
} }
auto state = (PXX2State*)context; auto state = (PXX2State*)context;
processPXX2Frame(state->module, frame); auto module = state->module;
auto drv = state->uart_drv;
auto ctx = state->uart_ctx;
processPXX2Frame(module, frame, drv, ctx);
*len = 0; *len = 0;
} }
+1 -1
View File
@@ -224,7 +224,7 @@ if(NOT INTERNAL_MODULE_PXX1)
option(ALLOW_TRAINER_MULTI "Allow multimodule to be use as trainer input" OFF) option(ALLOW_TRAINER_MULTI "Allow multimodule to be use as trainer input" OFF)
endif() endif()
if(PXX2 IN_LIST INTERNAL_MODULES) if("PXX2" IN_LIST INTERNAL_MODULES)
if (NOT PCBREV STREQUAL EXPRESS) if (NOT PCBREV STREQUAL EXPRESS)
set(ACCESS_DENIED ON) set(ACCESS_DENIED ON)
add_definitions(-DACCESS_DENIED) add_definitions(-DACCESS_DENIED)
+14 -10
View File
@@ -237,7 +237,8 @@ extern "C" {
volatile int16_t authenticateFrames = 0; volatile int16_t authenticateFrames = 0;
static void processAuthenticationFrame(uint8_t module, const uint8_t * frame) static void processAuthenticationFrame(uint8_t module, const uint8_t * frame,
const etx_serial_driver_t* drv, void* ctx)
{ {
uint8_t cryptoType = frame[3]; uint8_t cryptoType = frame[3];
uint8_t messageDigest[16] = {0}; uint8_t messageDigest[16] = {0};
@@ -253,12 +254,13 @@ static void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
if (INTERNAL_MODULE == module && if (INTERNAL_MODULE == module &&
access_denied(cryptoType, frame + 4, messageDigest)) { access_denied(cryptoType, frame + 4, messageDigest)) {
moduleState[module].mode = MODULE_MODE_AUTHENTICATION;
Pxx2Pulses &pxx2 = intmodulePulsesData.pxx2;
pxx2.setupAuthenticationFrame(module, cryptoType,
(const uint8_t *)messageDigest);
IntmoduleSerialDriver.sendBuffer(pxx2.getData(), pxx2.getSize()); moduleState[module].mode = MODULE_MODE_AUTHENTICATION;
Pxx2Pulses &pxx2 = intmodulePulsesData.pxx2;
pxx2.setupAuthenticationFrame(module, cryptoType, (const uint8_t *)messageDigest);
drv->sendBuffer(ctx, pxx2.getData(), pxx2.getSize());
// we remain in AUTHENTICATION mode to avoid a CHANNELS frame is sent at the // we remain in AUTHENTICATION mode to avoid a CHANNELS frame is sent at the
// end of the mixing process // end of the mixing process
authenticateFrames++; authenticateFrames++;
@@ -345,7 +347,8 @@ static void processOtaUpdateFrame(uint8_t module, const uint8_t * frame)
} }
} }
static void processModuleFrame(uint8_t module, const uint8_t *frame) static void processModuleFrame(uint8_t module, const uint8_t *frame,
const etx_serial_driver_t* drv, void* ctx)
{ {
switch (frame[2]) { switch (frame[2]) {
case PXX2_TYPE_ID_HW_INFO: case PXX2_TYPE_ID_HW_INFO:
@@ -373,7 +376,7 @@ static void processModuleFrame(uint8_t module, const uint8_t *frame)
break; break;
case PXX2_TYPE_ID_AUTHENTICATION: case PXX2_TYPE_ID_AUTHENTICATION:
processAuthenticationFrame(module, frame); processAuthenticationFrame(module, frame, drv, ctx);
break; break;
case PXX2_TYPE_ID_RESET: case PXX2_TYPE_ID_RESET:
@@ -395,7 +398,8 @@ static void processToolsFrame(uint8_t module, const uint8_t * frame)
} }
} }
void processPXX2Frame(uint8_t module, const uint8_t * frame) void processPXX2Frame(uint8_t module, const uint8_t * frame,
const etx_serial_driver_t* drv, void* ctx)
{ {
LOG_TELEMETRY_WRITE_START(); LOG_TELEMETRY_WRITE_START();
for (uint8_t i = 0; i < 1 + frame[0]; i++) { for (uint8_t i = 0; i < 1 + frame[0]; i++) {
@@ -404,7 +408,7 @@ void processPXX2Frame(uint8_t module, const uint8_t * frame)
switch (frame[1]) { switch (frame[1]) {
case PXX2_TYPE_C_MODULE: case PXX2_TYPE_C_MODULE:
processModuleFrame(module, frame); processModuleFrame(module, frame, drv, ctx);
break; break;
case PXX2_TYPE_C_POWER_METER: case PXX2_TYPE_C_POWER_METER:
+2 -1
View File
@@ -304,7 +304,8 @@ extern OutputTelemetryBuffer outputTelemetryBuffer __DMA;
extern Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo; extern Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo;
#endif #endif
void processPXX2Frame(uint8_t idx, const uint8_t* frame); void processPXX2Frame(uint8_t idx, const uint8_t* frame,
const etx_serial_driver_t* drv, void* ctx);
// Module pulse synchronization // Module pulse synchronization
struct ModuleSyncStatus struct ModuleSyncStatus