Add CRC8 to the header

This should prevent wrong decodings of modcod and packet length, which may disrupt decoding of directly following packets.
This commit is contained in:
Thomas Kolb 2024-01-07 00:02:26 +01:00
parent 16aa2ce92c
commit 07555edfdf
2 changed files with 13 additions and 2 deletions

View file

@ -173,7 +173,7 @@ result_t packet_mod_add_header(packet_mod_ctx_t *ctx)
} }
// build the header. All field are transferred in network byte order (big endian). // build the header. All field are transferred in network byte order (big endian).
uint8_t header[4]; uint8_t header[5];
// set length // set length
header[0] = (ctx->raw_data_len >> 8) & 0x07; header[0] = (ctx->raw_data_len >> 8) & 0x07;
@ -183,6 +183,9 @@ result_t packet_mod_add_header(packet_mod_ctx_t *ctx)
header[2] = (ctx->raw_data_crc >> 8) & 0xFF; header[2] = (ctx->raw_data_crc >> 8) & 0xFF;
header[3] = (ctx->raw_data_crc >> 0) & 0xFF; header[3] = (ctx->raw_data_crc >> 0) & 0xFF;
// append an 8-bit CRC to the header
crc_append_key(LIQUID_CRC_8, header, 4);
// note: the header is coded and modulated differently than the data. // note: the header is coded and modulated differently than the data.
// encode the header // encode the header

View file

@ -15,7 +15,7 @@
#define SYMBOL_BUFFER_SIZE 16384 #define SYMBOL_BUFFER_SIZE 16384
#define HEADER_SIZE_BYTES 4 #define HEADER_SIZE_BYTES 5 // including CRC
#define FREQ_EST_L 24 #define FREQ_EST_L 24
#define AGC_BW_ACQUISITION 5e-2f #define AGC_BW_ACQUISITION 5e-2f
@ -239,6 +239,14 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t
break; break;
} }
// CRC check
if(crc_check_key(LIQUID_CRC_8, header, HEADER_SIZE_BYTES-1) != LIQUID_OK) {
DEBUG_LOG("Header CRC check failed!\n");
rx->state = RX_STATE_ACQUISITION;
rx->callback(RX_EVT_HEADER_ERROR, NULL, 0);
break;
}
rx->payload_len_bytes = (((uint16_t)header[0] << 8) | header[1]) & 0x07FF; rx->payload_len_bytes = (((uint16_t)header[0] << 8) | header[1]) & 0x07FF;
rx->payload_crc = ((uint16_t)header[2] << 8) | header[3]; rx->payload_crc = ((uint16_t)header[2] << 8) | header[3];
rx->modcod = header[0] >> 3; rx->modcod = header[0] >> 3;