GNU Radio's M17 Package
m17_decoder_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2023 jmfriedt.
4 *
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#ifndef INCLUDED_M17_M17_DECODER_IMPL_H
9#define INCLUDED_M17_M17_DECODER_IMPL_H
10
12
13#include "m17.h"
14#include "aes.h"
15#include "uECC.h"
16
17namespace gr
18{
19 namespace m17
20 {
21
23 {
24 private:
25 // M17
26 static constexpr int PAYLOAD_BYTES = 16;
27
28 bool _debug_data = false;
29 bool _debug_ctrl = false;
30 float _sw_threshold = 2.0;
31 float _vt_threshold = 30.0;
32 bool _callsign = false;
33 bool _signed_str = false;
34 uint8_t _key[32] = {0}; // AES key
35 uint8_t _pub_key[64] = {0}; // ECDSA public key (signature verification)
36 uint8_t _iv[16];
37 encr_t _encr_type = ENCR_NONE;
38 // used for signatures
39 uint8_t _digest[16] = {0}; // 16-byte field for the stream digest
40 uint8_t _sig[64] = {0}; // ECDSA signature
41 uint32_t _scrambler_key = 0; // keep set to initial value for seed calculation function
42
43 typedef enum
44 {
45 AES128,
46 AES192,
47 AES256
48 } aes_t;
49 int8_t _aes_subtype = -1;
50
51 float last[8] = {0}; // look-back buffer for finding syncwords
52 float _pld[SYM_PER_PLD]; // raw frame symbols
53 uint16_t soft_bit[2 * SYM_PER_PLD]; // raw frame soft bits
54 uint16_t d_soft_bit[2 * SYM_PER_PLD]; // deinterleaved soft bits
55 uint16_t _expected_next_fn;
56 uint16_t _fn;
57
58 lsf_t _lsf; // complete LSF (one byte extra needed for the Viterbi decoder)
59 uint16_t lich_chunk[96]; // raw, soft LSF chunk extracted from the LICH
60 uint8_t _lich_b[6]; // 48-bit decoded LICH
61 uint8_t _lich_cnt; // LICH_CNT
62 uint8_t lich_chunks_rcvd = 0; // flags set for each LSF chunk received
63
64 uint16_t enc_data[272]; // raw frame data soft bits
65 uint8_t _stream_frame_data[16]; // decoded stream frame data, 128 bits
66 char rcvd_msg[33 * 25 + 1]; // reassembled Packet Data (up to 33 frames) + guard null byte
67 uint16_t _pkt_wr_offs = 0; // reassembly write position
68 uint8_t digest[16] = {0};
69
70 uint8_t syncd = 0; // syncword found?
71 uint8_t flp = 0; // stream rame=0, LSF=1, packet frame=2
72 uint8_t pushed; // counter for pushed symbols
73
74 char d_dst[12], d_src[12]; // decoded strings
75
76 // Scrambler
77 uint8_t _seed[3]; // 24-bit is the largest seed value
78 uint8_t _scr_bytes[16];
79 uint8_t _scrambler_pn[128];
80 uint32_t _scrambler_seed = 0;
81 int8_t _scrambler_subtype = -1;
82
83 const struct uECC_Curve_t *_curve = uECC_secp256r1();
84
85 public:
86 m17_decoder_impl(bool debug_data, bool debug_ctrl, float sw_threshold,
87 float vt_threshold, bool callsign, bool signed_str, int encr_type,
88 std::string key, std::string seed, std::string pub_key, int undecodable_out);
90 void set_debug_data(bool debug);
91 void set_key(std::string arg);
92 bool start() override;
93 std::string tag() const;
94 void rx_reset(void);
95 void publish_fields(const std::string &text = "");
96 void text_block(const lsf_t &l);
97 uint8_t _txt_block[4][13]; // multi-block Text Data being collected
98 uint8_t _txt_used = 0; // block bit map of the message
99 uint8_t _txt_have = 0; // blocks received so far (OR-ed Control Bytes)
100 bool _txt_done = false; // complete text reported for this transmission
101 void check_keys(uint16_t type);
102 int _key_len = 0; // AES key length in bytes (0 = none)
103 int _seed_len = 0; // scrambler seed length in bytes (0 = none)
104 bool _started = false; // flowgraph started: setters report runtime changes
105 int _rx_frames = 0; // data frames of the current transmission
106 float _rx_max_e = 0.0f; // highest Viterbi metric seen in it
107 std::string _rx_sig; // signature verification result
108 lsf_t _rx_lsf; // last reported LSF
109 bool _rx_lsf_seen = false; // LSF of the current transmission reported?
110 void set_pub_key(std::string arg);
111 void set_undecodable_out(int mode);
112 int _undecodable_out = 0; // undecryptable/signature frames: 0 = Codec2 silence, 1 = zeros, 2 = nothing
113 void set_seed(std::string seed);
114 void set_debug_ctrl(bool debug);
115 void set_callsign(bool callsign);
116 void set_sw_threshold(float sw_threshold);
117 void set_vt_threshold(float vt_threshold);
118 void set_signed(bool signed_str);
119 void set_encr_type(int encr_type);
120 void parse_raw_key_string(uint8_t *dest, const char *inp);
122 uint32_t scrambler_seed_calculation(int8_t subtype, uint32_t key,
123 int fn);
124
125 // Where all the action really happens
126 void forecast(int noutput_items,
127 gr_vector_int &ninput_items_required);
128
129 int general_work(int noutput_items,
130 gr_vector_int &ninput_items,
131 gr_vector_const_void_star &input_items,
132 gr_vector_void_star &output_items);
133 };
134
135 } // namespace m17
136} // namespace gr
137
138#endif /* INCLUDED_M17_M17_DECODER_IMPL_H */
void set_undecodable_out(int mode)
void set_vt_threshold(float vt_threshold)
int _key_len
Definition m17_decoder_impl.h:102
lsf_t _rx_lsf
Definition m17_decoder_impl.h:108
void set_signed(bool signed_str)
m17_decoder_impl(bool debug_data, bool debug_ctrl, float sw_threshold, float vt_threshold, bool callsign, bool signed_str, int encr_type, std::string key, std::string seed, std::string pub_key, int undecodable_out)
uint8_t _txt_used
Definition m17_decoder_impl.h:98
void text_block(const lsf_t &l)
float _rx_max_e
Definition m17_decoder_impl.h:106
int _seed_len
Definition m17_decoder_impl.h:103
bool _started
Definition m17_decoder_impl.h:104
bool _txt_done
Definition m17_decoder_impl.h:100
void set_encr_type(int encr_type)
uint8_t _txt_block[4][13]
Definition m17_decoder_impl.h:97
void set_sw_threshold(float sw_threshold)
uint32_t scrambler_seed_calculation(int8_t subtype, uint32_t key, int fn)
int _undecodable_out
Definition m17_decoder_impl.h:112
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
void set_seed(std::string seed)
void set_pub_key(std::string arg)
void check_keys(uint16_t type)
bool _rx_lsf_seen
Definition m17_decoder_impl.h:109
void set_callsign(bool callsign)
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
int _rx_frames
Definition m17_decoder_impl.h:105
void publish_fields(const std::string &text="")
std::string _rx_sig
Definition m17_decoder_impl.h:107
uint8_t _txt_have
Definition m17_decoder_impl.h:99
std::string tag() const
void set_key(std::string arg)
<+description of block+>
Definition m17_decoder.h:25
encr_t
Definition m17_decoder.h:29
@ ENCR_NONE
Definition m17_decoder.h:30
Definition codec2_decoder.h:17
Definition codec2_decoder.h:15