Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 
usb_serial.h
arch independent USB API
gec_whitelist
Whitelist for sending and receiving unencrypted messages (mostly for KEY_EXCHANGE messages)
Definition: gec_dl.h:53
gec.h
gec_transport::tx_msg
uint8_t tx_msg[TRANSPORT_PAYLOAD_LEN]
Definition: gec_dl.h:79
gec_process_msg1
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:597
gec_transport::trans_rx
struct transport_rx trans_rx
Definition: gec_dl.h:74
gec_transport::whitelist
struct gec_whitelist whitelist
Definition: gec_dl.h:84
gec_encrypt_message
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:371
gec_dl_event
void gec_dl_event(void)
Datalink Event.
Definition: gec_dl.c:533
gec_add_to_whitelist
void gec_add_to_whitelist(struct gec_whitelist *whitelist, uint8_t id)
Definition: gec_dl.c:800
message_buffer::message_ready
bool message_ready
Definition: gec_dl.h:66
WHITELIST_LEN
#define WHITELIST_LEN
Definition: gec_dl.h:46
message_buffer
Auxilliary message buffer for storing precomputed key exchange messages.
Definition: gec_dl.h:63
gec_dl_init
void gec_dl_init(void)
Init function.
Definition: gec_dl.c:345
message_buffer::msg
uint8_t msg[TRANSPORT_PAYLOAD_LEN]
Definition: gec_dl.h:64
gec_whitelist::idx
uint8_t idx
Definition: gec_dl.h:55
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
message_buffer::len
uint8_t len
Definition: gec_dl.h:65
gec_transport::sts
struct gec_sts_ctx sts
Definition: gec_dl.h:83
gec_transport::tx_msg_idx
uint8_t tx_msg_idx
Definition: gec_dl.h:80
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
gec_whitelist::whitelist
uint8_t whitelist[WHITELIST_LEN]
Definition: gec_dl.h:54
gec_process_msg3
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:744
uint8_t
unsigned char uint8_t
Definition: types.h:14
gec_transport::PPRZ_MUTEX
PPRZ_MUTEX(mtx_tx)
gec_transport::pprz_tp
struct pprz_transport pprz_tp
Definition: gec_dl.h:71
gec_process_sts_msg
void gec_process_sts_msg(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
respond_sts
void respond_sts(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
gec_transport_init
void gec_transport_init(struct gec_transport *t)
Definition: gec_dl.c:325
finish_sts
void finish_sts(struct link_device *dev, struct gec_transport *trans, uint8_t *buf)
udp.h
arch independent UDP API
pprz_mutex.h
gec_transport
Definition: gec_dl.h:69
gec_is_in_the_whitelist
bool gec_is_in_the_whitelist(struct gec_whitelist *whitelist, uint8_t id)
Definition: gec_dl.c:814
gec_tp
struct gec_transport gec_tp
PPRZ transport structure.
Definition: gec_dl.c:70
gec_sts_ctx
Definition: gec.h:115
gec_decrypt_message
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:430
gec_transport::trans_tx
struct transport_tx trans_tx
Definition: gec_dl.h:77
gec_whitelist::init
bool init
Definition: gec_dl.h:56
gec_check_and_parse
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.