Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gec_dl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Michal Podhradsky <michal.podhradsky@aggiemail.usu.edu>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  */
21 
26 #ifndef GEC_DL_H
27 #define GEC_DL_H
28 
29 #include "pprzlink/pprzlink_transport.h"
30 #include "pprzlink/pprz_transport.h"
32 #include "pprz_mutex.h"
33 
34 #include "mcu_periph/uart.h"
35 #if USE_USB_SERIAL
36 #include "mcu_periph/usb_serial.h"
37 #endif
38 #if USE_UDP
39 #include "mcu_periph/udp.h"
40 #endif
41 
42 // MSG_ID for key exchange messages.
43 // Update if IDs change in messages.xml
44 #define KEY_EXCHANGE_MSG_ID_UAV 239
45 #define KEY_EXCHANGE_MSG_ID_GCS 159
46 #define WHITELIST_LEN 20
47 
53 struct gec_whitelist {
56  bool init;
57 };
58 
64  uint8_t msg[TRANSPORT_PAYLOAD_LEN];
67 };
68 
69 struct gec_transport {
70  // pprz encapsulation layer
71  struct pprz_transport pprz_tp;
72 
73  // generic reception interface
74  struct transport_rx trans_rx;
75 
76  // generic transmission interface
77  struct transport_tx trans_tx;
78  // buffered tx message
79  uint8_t tx_msg[TRANSPORT_PAYLOAD_LEN];
81 
82  // ecnryption primitives
83  struct gec_sts_ctx sts;
85 
86  // optional mutex
87  PPRZ_MUTEX(mtx_tx);
88 };
89 
91 extern struct gec_transport gec_tp;
92 
94 extern void gec_dl_init(void);
95 
97 extern void gec_dl_event(void);
98 
99 void gec_transport_init(struct gec_transport *t);
100 
102 void gec_check_and_parse(struct link_device *dev, struct gec_transport *trans,
103  uint8_t *buf, bool *msg_available);
104 
105 void gec_process_sts_msg(struct link_device *dev, struct gec_transport *trans, uint8_t *buf);
106 
107 void respond_sts(struct link_device *dev, struct gec_transport *trans, uint8_t *buf);
108 void finish_sts(struct link_device *dev, struct gec_transport *trans,
109  uint8_t *buf);
110 
113 bool gec_decrypt_message(uint8_t *buf, volatile uint8_t *payload_len);
114 bool gec_encrypt_message(uint8_t *buf, uint8_t *payload_len);
115 
116 void gec_process_msg1(uint8_t *buf);
117 bool gec_process_msg3(uint8_t *buf);
118 
119 #endif /* GEC_DL_H */
120 
bool gec_decrypt_message(uint8_t *buf, volatile uint8_t *payload_len)
Attemp message decryption If a message is unencrypted, pass it through only if the MSG_ID is in the w...
Definition: gec_dl.c:425
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
bool gec_encrypt_message(uint8_t *buf, uint8_t *payload_len)
Attempts message encryption Adds crypto_byte, counter and tag Returns encrypted pprzlink message (cry...
Definition: gec_dl.c:366
void gec_process_msg1(uint8_t *buf)
NOTE: for RESPONDER party only Process incoming message (expected MSG1) if the right (KEY_EXCHANGE) m...
Definition: gec_dl.c:592
bool init
Definition: gec_dl.h:56
void gec_check_and_parse(struct link_device *dev, struct gec_transport *trans, uint8_t *buf, bool *msg_available)
Parsing a frame data and copy the payload to the datalink buffer.
void gec_dl_event(void)
Datalink Event.
Definition: gec_dl.c:528
Galois embedded crypto implementation.
uint8_t msg[TRANSPORT_PAYLOAD_LEN]
Definition: gec_dl.h:64
uint8_t idx
Definition: gec_dl.h:55
struct gec_sts_ctx sts
Definition: gec_dl.h:83
uint8_t len
Definition: gec_dl.h:65
Auxilliary message buffer for storing precomputed key exchange messages.
Definition: gec_dl.h:63
void gec_dl_init(void)
Init function.
Definition: gec_dl.c:340
struct transport_tx trans_tx
Definition: gec_dl.h:77
bool message_ready
Definition: gec_dl.h:66
#define WHITELIST_LEN
Definition: gec_dl.h:46
void gec_add_to_whitelist(struct gec_whitelist *whitelist, uint8_t id)
Definition: gec_dl.c:795
void respond_sts(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
bool gec_process_msg3(uint8_t *buf)
Process incoming message (expected MSG3) if the right (KEY_EXCHANGE) message received with the right ...
Definition: gec_dl.c:739
void finish_sts(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
struct gec_whitelist whitelist
Definition: gec_dl.h:84
struct pprz_transport pprz_tp
Definition: gec_dl.h:71
uint8_t tx_msg[TRANSPORT_PAYLOAD_LEN]
Definition: gec_dl.h:79
Whitelist for sending and receiving unencrypted messages (mostly for KEY_EXCHANGE messages) ...
Definition: gec_dl.h:53
void gec_process_sts_msg(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
uint8_t whitelist[WHITELIST_LEN]
Definition: gec_dl.h:54
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
struct gec_transport gec_tp
PPRZ transport structure.
Definition: gec_dl.c:70
Utility functions and macros to abstract some RTOS functionalities such as mutexes.
unsigned char uint8_t
Definition: types.h:14
void gec_transport_init(struct gec_transport *t)
Definition: gec_dl.c:320
PPRZ_MUTEX(mtx_tx)
struct transport_rx trans_rx
Definition: gec_dl.h:74
uint8_t tx_msg_idx
Definition: gec_dl.h:80
bool gec_is_in_the_whitelist(struct gec_whitelist *whitelist, uint8_t id)
Definition: gec_dl.c:809
arch independent UDP API
arch independent USB API