GNU Radio's M17 Package
m17.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include <math.h>

Go to the source code of this file.

Classes

struct  lsf_t
 Structure holding Link Setup Frame data. More...

Macros

#define LIBM17_VERSION   "1.0.9"
#define SYM_PER_SWD   8
#define SYM_PER_PLD   184
#define SYM_PER_FRA   192
#define M17_TYPE_PACKET   0
#define M17_TYPE_STREAM   1
#define M17_TYPE_DATA   (1<<1)
#define M17_TYPE_VOICE   (2<<1)
#define M17_TYPE_ENCR_NONE   (0<<3)
#define M17_TYPE_ENCR_SCRAM   (1<<3)
#define M17_TYPE_ENCR_AES   (2<<3)
#define M17_TYPE_ENCR_SCRAM_8   (0<<5)
#define M17_TYPE_ENCR_SCRAM_16   (1<<5)
#define M17_TYPE_ENCR_SCRAM_24   (2<<5)
#define M17_TYPE_ENCR_AES128   (0<<5)
#define M17_TYPE_ENCR_AES192   (1<<5)
#define M17_TYPE_ENCR_AES256   (2<<5)
#define M17_TYPE_CAN(x)
#define M17_TYPE_UNSIGNED   (0<<11)
#define M17_TYPE_SIGNED   (1<<11)
#define M17_TYPE_META_TEXT   (0<<5)
#define M17_TYPE_META_POSITION   (1<<5)
#define M17_TYPE_META_EXT_CALL   (2<<5)
#define M17_META_SOURCE_M17C   0
#define M17_META_SOURCE_OPENRTX   1
#define M17_META_SOURCE_OTHER   255
#define M17_META_SOURCE_M17C   0
#define M17_META_STATION_FIXED   0
#define M17_META_STATION_MOBILE   1
#define M17_META_STATION_HANDHELD   2
#define M17_META_LAT_NORTH   (0<<0)
#define M17_META_LAT_SOUTH   (1<<0)
#define M17_META_LON_EAST   (0<<1)
#define M17_META_LON_WEST   (1<<1)
#define M17_META_ALT_DATA_INVALID   (0<<2)
#define M17_META_ALT_DATA_VALID   (1<<2)
#define M17_META_SPD_BEARING_INVALID   (0<<3)
#define M17_META_SPD_BEARING_VALID   (1<<3)
#define CHAR_MAP   " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."
#define U40_9   (262144000000000ULL)
#define U40_9_8   (268697600000000ULL)
#define M17_CONVOL_K   5
#define M17_CONVOL_STATES   (1 << (M17_CONVOL_K - 1))

Enumerations

enum  pream_t { PREAM_LSF , PREAM_BERT }
 Preamble type (0 for LSF, 1 for BERT). More...
enum  frame_t { FRAME_LSF , FRAME_STR , FRAME_PKT , FRAME_BERT }
 Frame type (0 - LSF, 1 - stream, 2 - packet, 3 - BERT). More...

Functions

void gen_preamble (float out[SYM_PER_FRA], uint32_t *cnt, pream_t type)
void gen_preamble_i8 (int8_t out[SYM_PER_FRA], uint32_t *cnt, pream_t type)
void gen_syncword (float out[SYM_PER_SWD], uint32_t *cnt, uint16_t syncword)
void gen_syncword_i8 (int8_t out[SYM_PER_SWD], uint32_t *cnt, uint16_t syncword)
void gen_data (float out[SYM_PER_PLD], uint32_t *cnt, const uint8_t *in)
void gen_data_i8 (int8_t out[SYM_PER_PLD], uint32_t *cnt, const uint8_t *in)
void gen_eot (float out[SYM_PER_FRA], uint32_t *cnt)
void gen_eot_i8 (int8_t out[SYM_PER_FRA], uint32_t *cnt)
void gen_frame (float out[SYM_PER_FRA], const uint8_t *data, frame_t type, const lsf_t *lsf, uint8_t lich_cnt, uint16_t fn)
void gen_frame_i8 (int8_t out[SYM_PER_FRA], const uint8_t *data, frame_t type, const lsf_t *lsf, uint8_t lich_cnt, uint16_t fn)
uint32_t decode_LSF (lsf_t *lsf, const float pld_symbs[SYM_PER_PLD])
uint32_t decode_str_frame (uint8_t frame_data[16], uint8_t lich[5], uint16_t *fn, uint8_t *lich_cnt, const float pld_symbs[SYM_PER_PLD])
uint32_t decode_pkt_frame (uint8_t frame_data[25], uint8_t *eof, uint8_t *fn, const float pld_symbs[SYM_PER_PLD])
void conv_encode_stream_frame (uint8_t *out, const uint8_t *in, uint16_t fn)
void conv_encode_packet_frame (uint8_t out[SYM_PER_PLD *2], const uint8_t in[26])
void conv_encode_LSF (uint8_t out[SYM_PER_PLD *2], const lsf_t *in)
void conv_encode_bert_frame (uint8_t out[SYM_PER_PLD *2], const uint8_t in[25])
void decode_callsign_bytes (uint8_t *outp, const uint8_t inp[6])
void decode_callsign_value (uint8_t *outp, uint64_t inp)
int8_t encode_callsign_bytes (uint8_t out[6], const uint8_t *inp)
int8_t encode_callsign_value (uint64_t *out, const uint8_t *inp)
uint16_t CRC_M17 (const uint8_t *in, uint16_t len)
uint16_t LSF_CRC (const lsf_t *in)
void extract_LICH (uint8_t outp[6], uint8_t cnt, const lsf_t *inp)
void unpack_LICH (uint8_t *out, const uint8_t in[12])
void update_LSF_CRC (lsf_t *lsf)
void set_LSF (lsf_t *lsf, char *src, char *dst, uint16_t type, uint8_t meta[14])
void set_LSF_meta (lsf_t *lsf, const uint8_t meta[14])
void set_LSF_meta_position (lsf_t *lsf, uint8_t data_source, uint8_t station_type, float lat, float lon, uint8_t flags, int32_t altitude, uint16_t bearing, uint8_t speed)
void set_LSF_meta_ecd (lsf_t *lsf, const char *cf1, const char *cf2)
void set_LSF_meta_nonce (lsf_t *lsf, time_t ts, const uint8_t rand[10])
int8_t get_LSF_meta_position (uint8_t *data_source, uint8_t *station_type, float *lat, float *lon, uint8_t *flags, int32_t *altitude, uint16_t *bearing, uint8_t *speed, const lsf_t *lsf)
uint32_t golay24_encode (uint16_t data)
uint16_t golay24_sdecode (const uint16_t codeword[24])
void decode_LICH (uint8_t outp[6], const uint16_t inp[96])
void encode_LICH (uint8_t outp[12], const uint8_t inp[6])
void reorder_bits (uint8_t outp[SYM_PER_PLD *2], const uint8_t inp[SYM_PER_PLD *2])
void reorder_soft_bits (uint16_t outp[SYM_PER_PLD *2], const uint16_t inp[SYM_PER_PLD *2])
uint16_t q_abs_diff (uint16_t v1, uint16_t v2)
float eucl_norm (const float *in1, const int8_t *in2, uint8_t n)
void int_to_soft (uint16_t *out, uint16_t in, uint8_t len)
uint16_t soft_to_int (const uint16_t *in, uint8_t len)
uint16_t div16 (uint16_t a, uint16_t b)
uint16_t mul16 (uint16_t a, uint16_t b)
uint16_t soft_bit_XOR (uint16_t a, uint16_t b)
uint16_t soft_bit_NOT (uint16_t a)
void soft_XOR (uint16_t *out, const uint16_t *a, const uint16_t *b, uint8_t len)
void randomize_bits (uint8_t inp[SYM_PER_PLD *2])
void randomize_soft_bits (uint16_t inp[SYM_PER_PLD *2])
void slice_symbols (uint16_t out[2 *SYM_PER_PLD], const float inp[SYM_PER_PLD])
uint32_t viterbi_decode (uint8_t *out, const uint16_t *in, uint16_t len)
uint32_t viterbi_decode_punctured (uint8_t *out, const uint16_t *in, const uint8_t *punct, uint16_t in_len, uint16_t p_len)
void viterbi_decode_bit (uint16_t s0, uint16_t s1, size_t pos)
uint32_t viterbi_chainback (uint8_t *out, size_t pos, uint16_t len)
void viterbi_reset (void)

Variables

const uint8_t puncture_pattern_1 [61]
const uint8_t puncture_pattern_2 [12]
const uint8_t puncture_pattern_3 [8]
const uint16_t M17_CRC_POLY
const uint16_t encode_matrix [12]
const uint16_t decode_matrix [12]
const uint16_t intrl_seq [SYM_PER_PLD *2]
const uint8_t rand_seq [46]
const float rrc_taps_10 [8 *10+1]
const float rrc_taps_5 [8 *5+1]
const int8_t symbol_map [4]
const int8_t symbol_list [4]
const uint16_t SYNC_LSF
const uint16_t SYNC_STR
const uint16_t SYNC_PKT
const uint16_t SYNC_BER
const uint16_t EOT_MRKR
const int8_t eot_symbols [8]
const int8_t lsf_sync_symbols [8]
const int8_t str_sync_symbols [8]
const int8_t pkt_sync_symbols [8]

Macro Definition Documentation

◆ CHAR_MAP

#define CHAR_MAP   " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."

◆ LIBM17_VERSION

#define LIBM17_VERSION   "1.0.9"

◆ M17_CONVOL_K

#define M17_CONVOL_K   5

◆ M17_CONVOL_STATES

#define M17_CONVOL_STATES   (1 << (M17_CONVOL_K - 1))

◆ M17_META_ALT_DATA_INVALID

#define M17_META_ALT_DATA_INVALID   (0<<2)

◆ M17_META_ALT_DATA_VALID

#define M17_META_ALT_DATA_VALID   (1<<2)

◆ M17_META_LAT_NORTH

#define M17_META_LAT_NORTH   (0<<0)

◆ M17_META_LAT_SOUTH

#define M17_META_LAT_SOUTH   (1<<0)

◆ M17_META_LON_EAST

#define M17_META_LON_EAST   (0<<1)

◆ M17_META_LON_WEST

#define M17_META_LON_WEST   (1<<1)

◆ M17_META_SOURCE_M17C [1/2]

#define M17_META_SOURCE_M17C   0

◆ M17_META_SOURCE_M17C [2/2]

#define M17_META_SOURCE_M17C   0

◆ M17_META_SOURCE_OPENRTX

#define M17_META_SOURCE_OPENRTX   1

◆ M17_META_SOURCE_OTHER

#define M17_META_SOURCE_OTHER   255

◆ M17_META_SPD_BEARING_INVALID

#define M17_META_SPD_BEARING_INVALID   (0<<3)

◆ M17_META_SPD_BEARING_VALID

#define M17_META_SPD_BEARING_VALID   (1<<3)

◆ M17_META_STATION_FIXED

#define M17_META_STATION_FIXED   0

◆ M17_META_STATION_HANDHELD

#define M17_META_STATION_HANDHELD   2

◆ M17_META_STATION_MOBILE

#define M17_META_STATION_MOBILE   1

◆ M17_TYPE_CAN

#define M17_TYPE_CAN ( x)
Value:
(x<<7)

◆ M17_TYPE_DATA

#define M17_TYPE_DATA   (1<<1)

◆ M17_TYPE_ENCR_AES

#define M17_TYPE_ENCR_AES   (2<<3)

◆ M17_TYPE_ENCR_AES128

#define M17_TYPE_ENCR_AES128   (0<<5)

◆ M17_TYPE_ENCR_AES192

#define M17_TYPE_ENCR_AES192   (1<<5)

◆ M17_TYPE_ENCR_AES256

#define M17_TYPE_ENCR_AES256   (2<<5)

◆ M17_TYPE_ENCR_NONE

#define M17_TYPE_ENCR_NONE   (0<<3)

◆ M17_TYPE_ENCR_SCRAM

#define M17_TYPE_ENCR_SCRAM   (1<<3)

◆ M17_TYPE_ENCR_SCRAM_16

#define M17_TYPE_ENCR_SCRAM_16   (1<<5)

◆ M17_TYPE_ENCR_SCRAM_24

#define M17_TYPE_ENCR_SCRAM_24   (2<<5)

◆ M17_TYPE_ENCR_SCRAM_8

#define M17_TYPE_ENCR_SCRAM_8   (0<<5)

◆ M17_TYPE_META_EXT_CALL

#define M17_TYPE_META_EXT_CALL   (2<<5)

◆ M17_TYPE_META_POSITION

#define M17_TYPE_META_POSITION   (1<<5)

◆ M17_TYPE_META_TEXT

#define M17_TYPE_META_TEXT   (0<<5)

◆ M17_TYPE_PACKET

#define M17_TYPE_PACKET   0

◆ M17_TYPE_SIGNED

#define M17_TYPE_SIGNED   (1<<11)

◆ M17_TYPE_STREAM

#define M17_TYPE_STREAM   1

◆ M17_TYPE_UNSIGNED

#define M17_TYPE_UNSIGNED   (0<<11)

◆ M17_TYPE_VOICE

#define M17_TYPE_VOICE   (2<<1)

◆ SYM_PER_FRA

#define SYM_PER_FRA   192

◆ SYM_PER_PLD

◆ SYM_PER_SWD

#define SYM_PER_SWD   8

Referenced by gen_syncword(), and gen_syncword_i8().

◆ U40_9

#define U40_9   (262144000000000ULL)

◆ U40_9_8

#define U40_9_8   (268697600000000ULL)

Enumeration Type Documentation

◆ frame_t

enum frame_t

Frame type (0 - LSF, 1 - stream, 2 - packet, 3 - BERT).

Enumerator
FRAME_LSF 
FRAME_STR 
FRAME_PKT 
FRAME_BERT 

◆ pream_t

enum pream_t

Preamble type (0 for LSF, 1 for BERT).

Enumerator
PREAM_LSF 
PREAM_BERT 

Function Documentation

◆ conv_encode_bert_frame()

void conv_encode_bert_frame ( uint8_t out[SYM_PER_PLD *2],
const uint8_t in[25] )

References SYM_PER_PLD.

◆ conv_encode_LSF()

void conv_encode_LSF ( uint8_t out[SYM_PER_PLD *2],
const lsf_t * in )

References SYM_PER_PLD.

◆ conv_encode_packet_frame()

void conv_encode_packet_frame ( uint8_t out[SYM_PER_PLD *2],
const uint8_t in[26] )

References SYM_PER_PLD.

◆ conv_encode_stream_frame()

void conv_encode_stream_frame ( uint8_t * out,
const uint8_t * in,
uint16_t fn )

◆ CRC_M17()

uint16_t CRC_M17 ( const uint8_t * in,
uint16_t len )

◆ decode_callsign_bytes()

void decode_callsign_bytes ( uint8_t * outp,
const uint8_t inp[6] )

◆ decode_callsign_value()

void decode_callsign_value ( uint8_t * outp,
uint64_t inp )

◆ decode_LICH()

void decode_LICH ( uint8_t outp[6],
const uint16_t inp[96] )

◆ decode_LSF()

uint32_t decode_LSF ( lsf_t * lsf,
const float pld_symbs[SYM_PER_PLD] )

References SYM_PER_PLD.

◆ decode_pkt_frame()

uint32_t decode_pkt_frame ( uint8_t frame_data[25],
uint8_t * eof,
uint8_t * fn,
const float pld_symbs[SYM_PER_PLD] )

◆ decode_str_frame()

uint32_t decode_str_frame ( uint8_t frame_data[16],
uint8_t lich[5],
uint16_t * fn,
uint8_t * lich_cnt,
const float pld_symbs[SYM_PER_PLD] )

References SYM_PER_PLD.

◆ div16()

uint16_t div16 ( uint16_t a,
uint16_t b )

◆ encode_callsign_bytes()

int8_t encode_callsign_bytes ( uint8_t out[6],
const uint8_t * inp )

◆ encode_callsign_value()

int8_t encode_callsign_value ( uint64_t * out,
const uint8_t * inp )

References M17_CRC_POLY.

◆ encode_LICH()

void encode_LICH ( uint8_t outp[12],
const uint8_t inp[6] )

References intrl_seq, and SYM_PER_PLD.

◆ eucl_norm()

float eucl_norm ( const float * in1,
const int8_t * in2,
uint8_t n )

◆ extract_LICH()

void extract_LICH ( uint8_t outp[6],
uint8_t cnt,
const lsf_t * inp )

◆ gen_data()

void gen_data ( float out[SYM_PER_PLD],
uint32_t * cnt,
const uint8_t * in )

References SYM_PER_PLD.

◆ gen_data_i8()

void gen_data_i8 ( int8_t out[SYM_PER_PLD],
uint32_t * cnt,
const uint8_t * in )

References SYM_PER_PLD.

◆ gen_eot()

void gen_eot ( float out[SYM_PER_FRA],
uint32_t * cnt )

References SYM_PER_FRA.

◆ gen_eot_i8()

void gen_eot_i8 ( int8_t out[SYM_PER_FRA],
uint32_t * cnt )

References SYM_PER_FRA.

◆ gen_frame()

void gen_frame ( float out[SYM_PER_FRA],
const uint8_t * data,
frame_t type,
const lsf_t * lsf,
uint8_t lich_cnt,
uint16_t fn )

References SYM_PER_FRA.

◆ gen_frame_i8()

void gen_frame_i8 ( int8_t out[SYM_PER_FRA],
const uint8_t * data,
frame_t type,
const lsf_t * lsf,
uint8_t lich_cnt,
uint16_t fn )

References SYM_PER_FRA.

◆ gen_preamble()

void gen_preamble ( float out[SYM_PER_FRA],
uint32_t * cnt,
pream_t type )

References SYM_PER_FRA.

◆ gen_preamble_i8()

void gen_preamble_i8 ( int8_t out[SYM_PER_FRA],
uint32_t * cnt,
pream_t type )

References SYM_PER_FRA.

◆ gen_syncword()

void gen_syncword ( float out[SYM_PER_SWD],
uint32_t * cnt,
uint16_t syncword )

References SYM_PER_SWD.

◆ gen_syncword_i8()

void gen_syncword_i8 ( int8_t out[SYM_PER_SWD],
uint32_t * cnt,
uint16_t syncword )

References SYM_PER_SWD.

◆ get_LSF_meta_position()

int8_t get_LSF_meta_position ( uint8_t * data_source,
uint8_t * station_type,
float * lat,
float * lon,
uint8_t * flags,
int32_t * altitude,
uint16_t * bearing,
uint8_t * speed,
const lsf_t * lsf )

References decode_matrix, and encode_matrix.

◆ golay24_encode()

uint32_t golay24_encode ( uint16_t data)

◆ golay24_sdecode()

uint16_t golay24_sdecode ( const uint16_t codeword[24])

◆ int_to_soft()

void int_to_soft ( uint16_t * out,
uint16_t in,
uint8_t len )

◆ LSF_CRC()

uint16_t LSF_CRC ( const lsf_t * in)

◆ mul16()

uint16_t mul16 ( uint16_t a,
uint16_t b )

◆ q_abs_diff()

uint16_t q_abs_diff ( uint16_t v1,
uint16_t v2 )

◆ randomize_bits()

void randomize_bits ( uint8_t inp[SYM_PER_PLD *2])

References SYM_PER_PLD.

◆ randomize_soft_bits()

void randomize_soft_bits ( uint16_t inp[SYM_PER_PLD *2])

References SYM_PER_PLD.

◆ reorder_bits()

void reorder_bits ( uint8_t outp[SYM_PER_PLD *2],
const uint8_t inp[SYM_PER_PLD *2] )

References SYM_PER_PLD.

◆ reorder_soft_bits()

void reorder_soft_bits ( uint16_t outp[SYM_PER_PLD *2],
const uint16_t inp[SYM_PER_PLD *2] )

References SYM_PER_PLD.

◆ set_LSF()

void set_LSF ( lsf_t * lsf,
char * src,
char * dst,
uint16_t type,
uint8_t meta[14] )

◆ set_LSF_meta()

void set_LSF_meta ( lsf_t * lsf,
const uint8_t meta[14] )

◆ set_LSF_meta_ecd()

void set_LSF_meta_ecd ( lsf_t * lsf,
const char * cf1,
const char * cf2 )

◆ set_LSF_meta_nonce()

void set_LSF_meta_nonce ( lsf_t * lsf,
time_t ts,
const uint8_t rand[10] )

◆ set_LSF_meta_position()

void set_LSF_meta_position ( lsf_t * lsf,
uint8_t data_source,
uint8_t station_type,
float lat,
float lon,
uint8_t flags,
int32_t altitude,
uint16_t bearing,
uint8_t speed )

◆ slice_symbols()

void slice_symbols ( uint16_t out[2 *SYM_PER_PLD],
const float inp[SYM_PER_PLD] )

◆ soft_bit_NOT()

uint16_t soft_bit_NOT ( uint16_t a)

◆ soft_bit_XOR()

uint16_t soft_bit_XOR ( uint16_t a,
uint16_t b )

◆ soft_to_int()

uint16_t soft_to_int ( const uint16_t * in,
uint8_t len )

◆ soft_XOR()

void soft_XOR ( uint16_t * out,
const uint16_t * a,
const uint16_t * b,
uint8_t len )

References rand_seq.

◆ unpack_LICH()

void unpack_LICH ( uint8_t * out,
const uint8_t in[12] )

◆ update_LSF_CRC()

void update_LSF_CRC ( lsf_t * lsf)

◆ viterbi_chainback()

uint32_t viterbi_chainback ( uint8_t * out,
size_t pos,
uint16_t len )

◆ viterbi_decode()

uint32_t viterbi_decode ( uint8_t * out,
const uint16_t * in,
uint16_t len )

◆ viterbi_decode_bit()

void viterbi_decode_bit ( uint16_t s0,
uint16_t s1,
size_t pos )

◆ viterbi_decode_punctured()

uint32_t viterbi_decode_punctured ( uint8_t * out,
const uint16_t * in,
const uint8_t * punct,
uint16_t in_len,
uint16_t p_len )

◆ viterbi_reset()

void viterbi_reset ( void )

Variable Documentation

◆ decode_matrix

const uint16_t decode_matrix[12]
extern

Referenced by get_LSF_meta_position().

◆ encode_matrix

const uint16_t encode_matrix[12]
extern

Referenced by get_LSF_meta_position().

◆ EOT_MRKR

const uint16_t EOT_MRKR
extern

Referenced by slice_symbols().

◆ eot_symbols

const int8_t eot_symbols[8]
extern

Referenced by viterbi_reset().

◆ intrl_seq

const uint16_t intrl_seq[SYM_PER_PLD *2]
extern

Referenced by encode_LICH().

◆ lsf_sync_symbols

const int8_t lsf_sync_symbols[8]
extern

Referenced by viterbi_reset().

◆ M17_CRC_POLY

const uint16_t M17_CRC_POLY
extern

Referenced by encode_callsign_value().

◆ pkt_sync_symbols

const int8_t pkt_sync_symbols[8]
extern

Referenced by viterbi_reset().

◆ puncture_pattern_1

const uint8_t puncture_pattern_1[61]
extern

Referenced by decode_pkt_frame().

◆ puncture_pattern_2

const uint8_t puncture_pattern_2[12]
extern

Referenced by decode_pkt_frame().

◆ puncture_pattern_3

const uint8_t puncture_pattern_3[8]
extern

Referenced by decode_pkt_frame().

◆ rand_seq

const uint8_t rand_seq[46]
extern

Referenced by soft_XOR().

◆ rrc_taps_10

const float rrc_taps_10[8 *10+1]
extern

Referenced by slice_symbols().

◆ rrc_taps_5

const float rrc_taps_5[8 *5+1]
extern

Referenced by slice_symbols().

◆ str_sync_symbols

const int8_t str_sync_symbols[8]
extern

Referenced by viterbi_reset().

◆ symbol_list

const int8_t symbol_list[4]
extern

Referenced by slice_symbols().

◆ symbol_map

const int8_t symbol_map[4]
extern

Referenced by slice_symbols().

◆ SYNC_BER

const uint16_t SYNC_BER
extern

Referenced by slice_symbols().

◆ SYNC_LSF

const uint16_t SYNC_LSF
extern

Referenced by slice_symbols().

◆ SYNC_PKT

const uint16_t SYNC_PKT
extern

Referenced by slice_symbols().

◆ SYNC_STR

const uint16_t SYNC_STR
extern

Referenced by slice_symbols().