Skip to content

Commit

Permalink
Added RNG for NPS, cleaned up telemetry config files
Browse files Browse the repository at this point in the history
  • Loading branch information
podhrmic committed Dec 10, 2017
1 parent e6924b2 commit d263f85
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 56 deletions.
4 changes: 3 additions & 1 deletion conf/airframes/AGGIEAIR/aggieair_ark_hexa_1-8.xml
Expand Up @@ -26,6 +26,7 @@ Aggie Air ARK
<module name="radio_control" type="spektrum"/>
</target>

<!-- hitl currently not supported for secure link comms
<target name="hitl" board="pc">
<module name="fdm" type="jsbsim"/>
<module name="imu" type="nps"/>
Expand All @@ -35,6 +36,7 @@ Aggie Air ARK
<configure name="AP_DEV" value="/dev/ttyUSB2"/>
<configure name="AP_BAUD" value="B921600"/>
</target>
-->

<module name="motor_mixing"/>
<module name="actuators" type="pwm">
Expand All @@ -56,7 +58,7 @@ Aggie Air ARK

<modules>
<module name="sys_mon"/>
<module name="rng"/>
<!--module name="rng"/-->
<module name="copilot"/>
<module name="extra_dl">
<!-- in order to use uart1 without chibios we need to remap the peripheral-->
Expand Down
2 changes: 1 addition & 1 deletion conf/airframes/AGGIEAIR/aggieair_conf.xml
Expand Up @@ -7,7 +7,7 @@
telemetry="telemetry/AGGIEAIR/aggieair_rotorcraft.xml"
flight_plan="flight_plans/rotorcraft_basic_geofence.xml"
settings="settings/rotorcraft_basic.xml settings/nps.xml"
settings_modules="modules/battery_monitor.xml modules/gps.xml modules/stabilization_float_euler.xml modules/nav_basic_rotorcraft.xml modules/guidance_rotorcraft.xml modules/imu_common.xml"
settings_modules="modules/battery_monitor.xml modules/gps.xml modules/stabilization_float_euler.xml modules/nav_basic_rotorcraft.xml modules/guidance_rotorcraft.xml"
gui_color="#ffff954c0000"
/>
<aircraft
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/haclc.xml
Expand Up @@ -7,7 +7,7 @@
see https://github.com/mitls/hacl-star for details
</description>
</doc>
<makefile target="!fbw|sim|nps|hitl">
<makefile target="!fbw|sim">
<file name="Hacl_Chacha20Poly1305.c" dir="../ext/hacl-c"/>
<file name="kremlib.c" dir="../ext/hacl-c"/>
<file name="Hacl_Policies.c" dir="../ext/hacl-c"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/rng.xml
Expand Up @@ -9,7 +9,7 @@
<header>
<file name="rng.h" dir="mcu_periph"/>
</header>
<makefile target="ap|fbw">
<makefile target="!fbw|sim">
<define name="USE_RNG"/>
<file_arch name="rng_arch.c" dir="mcu_periph"/>
</makefile>
Expand Down
@@ -1,31 +1,19 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="telemetry_secure_nps" dir="datalink" task="datalink">
<module name="telemetry_nps_secure" dir="datalink" task="datalink">
<doc>
<description>
Example of using secure telemetr over PPRZ protocol over UDP
Telemetry module for NPS simalation

This file serves only as an example and should not be used in real applications,
because it only passes though all data (so it is equivalent to using plaintext data).

However, this example should make it easier for users to device their own encryption scheme.

Note that this file largely copies "telemetry_transparent_secure_example" module,
the major difference are the device definitions.
Currently a simple copy of telemetry UDP but only for target nps
</description>
<configure name="MODEM_DEV" value="UDPx" description="UDP port used for communication"/>
<configure name="MODEM_HOST" value="192.168.1.255" description="IP address of the ground station (can be a broadcast address)"/>
<configure name="MODEM_PORT_OUT" value="4242" description="output UDP port"/>
<configure name="MODEM_PORT_IN" value="4243" description="input UDP port"/>
<configure name="MODEM_BROADCAST" value="TRUE|FALSE" description="UDP socket in broadcast mode"/>
</doc>
<header>
<!-- required header file declaring spprz_transport -->
<file name="spprz_dl.h"/>
</header>
<!-- required init and event functions -->
<init fun="spprz_dl_init()"/>
<event fun="spprz_dl_event()"/>

<makefile target="nps|hitl">
<configure name="MODEM_DEV" default="UDP0" case="upper|lower"/>
<configure name="MODEM_PORT_OUT" default="4242"/>
Expand All @@ -36,23 +24,8 @@
<define name="$(MODEM_DEV_UPPER)_PORT_OUT" value="$(MODEM_PORT_OUT)"/>
<define name="$(MODEM_DEV_UPPER)_PORT_IN" value="$(MODEM_PORT_IN)"/>
<define name="$(MODEM_DEV_UPPER)_BROADCAST" value="$(MODEM_BROADCAST)"/>
<define name="DOWNLINK"/>
<define name="PERIODIC_TELEMETRY"/>
<define name="DOWNLINK_DEVICE" value="$(MODEM_DEV_LOWER)"/>
<define name="PPRZ_UART" value="$(MODEM_DEV_LOWER)"/>
<!-- we are using "spprz_tp" instead of "pprz_tp" -->
<define name="DOWNLINK_TRANSPORT" value="spprz_tp"/>
<define name="DATALINK" value="PPRZ"/>
<file name="downlink.c" dir="subsystems/datalink"/>
<file name="datalink.c" dir="subsystems/datalink"/>
<file name="telemetry.c" dir="subsystems/datalink"/>
<!-- provide your own source file, or expand the template one -->
<file name="spprz_dl.c"/>
<!-- required files, defining the secure transport -->
<file name="spprz_transport.c" dir="pprzlink/src"/>
<!-- and providing default pass-through implementation -->
<!-- this file shouldn't be used in your implementation -->
<file name="spprz_utils.c" dir="pprzlink/src"/>
<raw>
include $(CFG_SHARED)/udp.makefile
</raw>
Expand Down
@@ -1,29 +1,22 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="telemetry_transparent_secure" dir="datalink" task="datalink">
<module name="telemetry_secure_common" dir="datalink" task="datalink">
<doc>
<description>
Example of using secure telemetr over PPRZ protocol over UART

This file serves only as an example and should not be used in real applications,
because it only passes though all data (so it is equivalent to using plaintext data).

However, this example should make it easier for users to device their own encryption scheme.
Telemetry using PPRZ protocol - common parts
</description>
<configure name="MODEM_PORT" value="UARTx" description="UART where the modem is connected to (UART1, UART2, etc)"/>
<configure name="MODEM_BAUD" value="B57600" description="UART baud rate"/>
</doc>
<!-- autoload secure_nps_example module to allow encryption for simulation and testing -->
<!-- change accordingly when devising your own secure link -->
<autoload name="telemetry" type="secure_nps_example"/>
<autoload name="telemetry" type="sim"/>

<autoload name="telemetry" type="nps_secure"/>

<header>
<!-- required header file declaring spprz_transport -->
<file name="spprz_dl.h"/>
</header>
<!-- required init and event functions -->
<init fun="spprz_dl_init()"/>
<event fun="spprz_dl_event()"/>

<makefile target="!fbw|sim|nps|hitl">
<configure name="MODEM_PORT" case="upper|lower"/>
<define name="USE_$(MODEM_PORT_UPPER)"/>
Expand All @@ -32,19 +25,18 @@
<define name="PERIODIC_TELEMETRY"/>
<define name="DOWNLINK_DEVICE" value="$(MODEM_PORT_LOWER)"/>
<define name="PPRZ_UART" value="$(MODEM_PORT_LOWER)"/>
<!-- we are using "spprz_tp" instead of "pprz_tp" -->
</makefile>

<makefile target="!fbw|sim">
<define name="DOWNLINK"/>
<define name="PERIODIC_TELEMETRY"/>
<define name="DOWNLINK_TRANSPORT" value="spprz_tp"/>
<define name="DATALINK" value="PPRZ"/>
<file name="spprz_dl.c"/>
<file name="downlink.c" dir="subsystems/datalink"/>
<file name="datalink.c" dir="subsystems/datalink"/>
<file name="telemetry.c" dir="subsystems/datalink"/>
<!-- provide your own source file, or expand the template one -->
<file name="spprz_dl.c"/>
<!-- required files, defining the secure transport -->
<file name="telemetry.c" dir="subsystems/datalink"/>
<file name="spprz_transport.c" dir="pprzlink/src"/>
<!-- and providing default pass-through implementation -->
<!-- this file shouldn't be used in your implementation -->
<file name="spprz_utils.c" dir="pprzlink/src"/>
</makefile>
<makefile target="ap" firmware="fixedwing">
<file name="fixedwing_datalink.c" dir="$(SRC_FIRMWARE)"/>
Expand Down
25 changes: 25 additions & 0 deletions conf/modules/telemetry_transparent_gec.xml
@@ -0,0 +1,25 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="telemetry_transparent_secure_gec" dir="datalink" task="datalink">
<doc>
<description>
Example of using secure telemetry over PPRZ protocol over UART

This file serves only as an example and should not be used in real applications,
because it only passes through all data (so it is equivalent to using plaintext data).

However, this example should make it easier for users to devise their own encryption scheme.
</description>

</doc>

<autoload name="telemetry" type="secure_common"/>
<autoload name="rng"/>
<autoload name="haclc"/>

<makefile target="!fbw|sim">
<file name="gec_ke.c" dir="modules/datalink/gec"/>
</makefile>

</module>

66 changes: 66 additions & 0 deletions sw/airborne/arch/sim/mcu_periph/rng_arch.c
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2017 Michal Podhradsky <mpodhradsky@galois.com>
*
* 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, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

/** \file rng_arch.c
* \brief arch specific Random Number Generator API
*
*/
#include "mcu_periph/rng.h"

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

void rng_init(void) {}

void rng_deinit(void) {}

// Return true only if we got a new number
// that is different from the previous one
bool rng_get(uint32_t *rand_nr)
{
int fd = open("/dev/urandom", O_RDONLY);
if (fd == -1) {
printf("Cannot open /dev/urandom\n");
return false;
}

uint8_t len = sizeof(uint32_t);
uint8_t res = read(fd, rand_nr, len);
if (res != len) {
printf("Error on reading, expected %u bytes, got %u bytes\n",
len, res);
return false;
}
close(fd);
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;
while (!rng_get(&tmp)) {};
return tmp;
}
56 changes: 56 additions & 0 deletions sw/airborne/modules/datalink/gec/gec_ke.c
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2017 Michal Podhradsky <mpodhradsky@galois.com>
*
* 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 datalink/gec/gec.c
*
* Galois embedded crypto iplementation
*
*/
#include "pprzlink/spprz_utils.h" // for incoming/outgoing functions
#include "mcu_periph/rng.h"




/**
* Trivial implementation of the processing function
* Shall be replaced by user implementation!
*
* This function only copies trans->trans_rx.payload into provided buf
*/
bool spprz_process_incoming_packet(struct spprz_transport *trans, uint8_t *buf)
{
for (uint8_t i = 0; i < trans->trans_rx.payload_len; i++) {
buf[i] = trans->trans_rx.payload[i];
}
return true;
}

/**
* Trivial implementation of the processing function
* Shall be replaced by user implementation!
*
* This function is only a pass-through.
*/
bool spprz_process_outgoing_packet(struct spprz_transport *trans __attribute__((unused)))
{
return true;
}
32 changes: 32 additions & 0 deletions sw/airborne/modules/datalink/gec/gec_ke.h
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Michal Podhradsky <mpodhradsky@galois.com>
*
* 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 datalink/gec/gec.h
*
* Galois embedded crypto iplementation
*
*/
#ifndef SPPRZ_GEC_KE_H
#define SPPRZ_GEC_KE_H



#endif /* SPPRZ_GEC_KE_H */

0 comments on commit d263f85

Please sign in to comment.