mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-28 01:53:48 +08:00
[gec] fix compilation of secure telemetry module gec_dl (#2646)
* [gec] fix compilation of secure telemetry module gec_dl * [chibios] add RNG support to ChibiOS arch * Force clearning Cargo.lock files * change unlock order thread stack should have around 2 Kb free both AP and FBW in case of fixedwing Co-authored-by: Michal Podhradsky <mpodhradsky@galois.com>
This commit is contained in:
committed by
GitHub
parent
3ef68882ce
commit
b0d9eaf6ae
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file rng_arch.c
|
||||
* \brief arch specific Random Number Generator API
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mcu_periph/rng.h"
|
||||
#include <hal.h>
|
||||
|
||||
/***********
|
||||
* RNG API *
|
||||
***********/
|
||||
|
||||
// FIXME remove and use API from ChibiOS after updating to newer version
|
||||
|
||||
static void TRNGStart(void)
|
||||
{
|
||||
rccEnableAHB2(RCC_AHB2ENR_RNGEN, 0);
|
||||
RNG->CR |= RNG_CR_RNGEN;
|
||||
}
|
||||
|
||||
static void TRNGStop(void)
|
||||
{
|
||||
RNG->CR &= ~RNG_CR_RNGEN;
|
||||
rccDisableAHB2(RCC_AHB2ENR_RNGEN);
|
||||
}
|
||||
|
||||
static uint32_t TRNGGet(void)
|
||||
{
|
||||
// waiting for data ready
|
||||
while ((RNG->SR & RNG_SR_DRDY) == 0) {};
|
||||
return RNG->DR;
|
||||
}
|
||||
|
||||
static bool TRNGGetErrors(void)
|
||||
{
|
||||
return (RNG->SR & RNG_SR_CECS) || (RNG->SR & RNG_SR_SECS);
|
||||
}
|
||||
|
||||
static void TRNGClearErrors(void)
|
||||
{
|
||||
RNG->SR &= ~(RNG_SR_SEIS | RNG_SR_CEIS);
|
||||
}
|
||||
|
||||
static bool TRNGGenerate(size_t size, uint32_t *out)
|
||||
{
|
||||
while (size) {
|
||||
out[--size] = TRNGGet();
|
||||
}
|
||||
return TRNGGetErrors();
|
||||
}
|
||||
|
||||
|
||||
/************
|
||||
* PPRZ API *
|
||||
************/
|
||||
|
||||
void rng_init(void)
|
||||
{
|
||||
TRNGStart();
|
||||
}
|
||||
|
||||
void rng_deinit(void)
|
||||
{
|
||||
TRNGStop();
|
||||
}
|
||||
|
||||
// Return true only if we got a new number
|
||||
// that is different from the previous one
|
||||
bool rng_get(uint32_t *rand_nr)
|
||||
{
|
||||
bool err = TRNGGenerate(1, rand_nr);
|
||||
if (err) {
|
||||
TRNGClearErrors();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until we get a new number that is different
|
||||
// from the previous one. We can wait forever here if
|
||||
// the clocks are not setup properly.
|
||||
uint32_t rng_wait_and_get(void)
|
||||
{
|
||||
uint32_t tmp = 0;
|
||||
bool err = true;
|
||||
do {
|
||||
err = TRNGGenerate(1, &tmp);
|
||||
} while (err);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ static void start_message(struct pprzlink_msg *msg,
|
||||
uint8_t payload_len __attribute__((unused)))
|
||||
{
|
||||
PPRZ_MUTEX_LOCK(get_trans(msg)->mtx_tx); // lock mutex
|
||||
memset(get_trans(msg)->tx_msg, _FD, TRANSPORT_PAYLOAD_LEN);// erase message data
|
||||
memset(get_trans(msg)->tx_msg, 0, TRANSPORT_PAYLOAD_LEN);// erase message data
|
||||
get_trans(msg)->tx_msg_idx = 0;// reset index
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ static void end_message(struct pprzlink_msg *msg, long fd)
|
||||
case CRYPTO_OK:
|
||||
if (gec_encrypt_message(gec_tp.tx_msg, &gec_tp.tx_msg_idx)) {
|
||||
gec_encapsulate_and_send_msg(msg, fd);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -214,10 +215,11 @@ static void end_message(struct pprzlink_msg *msg, long fd)
|
||||
*/
|
||||
void gec_encapsulate_and_send_msg(struct pprzlink_msg *msg, long fd)
|
||||
{
|
||||
get_trans(msg)->pprz_tp.trans_tx.start_message(msg, fd,
|
||||
get_trans(msg)->tx_msg_idx);
|
||||
get_trans(msg)->pprz_tp.trans_tx.put_bytes(msg, _FD, DL_TYPE_UINT8,
|
||||
get_trans(msg)->pprz_tp.trans_tx.start_message(msg, fd, get_trans(msg)->tx_msg_idx);
|
||||
get_trans(msg)->pprz_tp.trans_tx.put_bytes(msg, fd, DL_TYPE_UINT8,
|
||||
DL_FORMAT_SCALAR, get_trans(msg)->tx_msg, get_trans(msg)->tx_msg_idx);
|
||||
// unlock mutex
|
||||
PPRZ_MUTEX_UNLOCK(get_trans(msg)->mtx_tx);
|
||||
get_trans(msg)->pprz_tp.trans_tx.end_message(msg, fd);
|
||||
}
|
||||
|
||||
@@ -262,7 +264,7 @@ static void start_message(struct gec_transport *trans,
|
||||
uint8_t payload_len __attribute__((unused)))
|
||||
{
|
||||
PPRZ_MUTEX_LOCK(trans->mtx_tx); // lock mutex
|
||||
memset(trans->tx_msg, _FD, TRANSPORT_PAYLOAD_LEN); // erase message data
|
||||
memset(trans->tx_msg, 0, TRANSPORT_PAYLOAD_LEN); // erase message data
|
||||
trans->tx_msg_idx = 0; // reset index
|
||||
}
|
||||
|
||||
@@ -273,6 +275,7 @@ static void end_message(struct gec_transport *trans, struct link_device *dev,
|
||||
case CRYPTO_OK:
|
||||
if (gec_encrypt_message(gec_tp.tx_msg, &gec_tp.tx_msg_idx)) {
|
||||
gec_encapsulate_and_send_msg(trans, dev, fd);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -287,8 +290,10 @@ void gec_encapsulate_and_send_msg(struct gec_transport *trans,
|
||||
struct link_device *dev, long fd)
|
||||
{
|
||||
trans->pprz_tp.trans_tx.start_message(trans, dev, fd, trans->tx_msg_idx);
|
||||
trans->pprz_tp.trans_tx.put_bytes(trans, dev, _FD, DL_TYPE_UINT8,
|
||||
trans->pprz_tp.trans_tx.put_bytes(trans, dev, fd, DL_TYPE_UINT8,
|
||||
DL_FORMAT_SCALAR, trans->tx_msg, trans->tx_msg_idx);
|
||||
// unlock mutex
|
||||
PPRZ_MUTEX_UNLOCK(trans->mtx_tx);
|
||||
trans->pprz_tp.trans_tx.end_message(trans, dev, fd);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user