mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-16 18:57:24 -05:00
DMR: Fix RS(12,9) FLC CRC/FEC and add CapMax RAS private call FLCO
This commit is contained in:
@@ -14,6 +14,24 @@
|
|||||||
|
|
||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
|
|
||||||
|
uint32_t dmr_flc_rs_calc(uint8_t * input)
|
||||||
|
{
|
||||||
|
uint8_t tmp_bytes[12];
|
||||||
|
memset(tmp_bytes, 0, sizeof(tmp_bytes));
|
||||||
|
memcpy (tmp_bytes, input, 9);
|
||||||
|
|
||||||
|
uint32_t rs_clc = 0;
|
||||||
|
rs_12_9_encode(tmp_bytes);
|
||||||
|
|
||||||
|
rs_clc |= tmp_bytes[9];
|
||||||
|
rs_clc <<= 8;
|
||||||
|
rs_clc |= tmp_bytes[10];
|
||||||
|
rs_clc <<= 8;
|
||||||
|
rs_clc |= tmp_bytes[11];
|
||||||
|
|
||||||
|
return rs_clc;
|
||||||
|
}
|
||||||
|
|
||||||
void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst)
|
void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -304,20 +322,21 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
/* Apply the CRC mask (see DMR standard B.3.12 Data Type CRC Mask) */
|
/* Apply the CRC mask (see DMR standard B.3.12 Data Type CRC Mask) */
|
||||||
CRCExtracted = CRCExtracted ^ crcmask;
|
CRCExtracted = CRCExtracted ^ crcmask;
|
||||||
|
|
||||||
/* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */
|
/* Check the 9 byte Full Link Control for Correct RS (or RAS MAC) Encoding*/
|
||||||
if (is_lc)
|
if (is_lc)
|
||||||
{
|
{
|
||||||
if (is_ras)
|
if (is_ras)
|
||||||
{
|
{
|
||||||
uint8_t tmp_bytes[12];
|
uint32_t std_crc = dmr_flc_rs_calc(BPTCDmrDataByte);
|
||||||
uint32_t std_crc = 0;
|
if (std_crc == CRCExtracted)
|
||||||
memcpy (tmp_bytes, BPTCDmrDataByte, sizeof(tmp_bytes));
|
|
||||||
if (ComputeAndCorrectFullLinkControlCrc(tmp_bytes, &std_crc, crcmask) && std_crc == CRCExtracted)
|
|
||||||
{
|
{
|
||||||
memcpy (BPTCDmrDataByte, tmp_bytes, sizeof(tmp_bytes));
|
|
||||||
is_ras = 0;
|
|
||||||
CRCComputed = std_crc;
|
CRCComputed = std_crc;
|
||||||
CRCCorrect = 1;
|
CRCCorrect = 1;
|
||||||
|
is_ras = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
fprintf (stderr, " EXT: %06X; CRC: %06X;", CRCExtracted, CRCComputed);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -330,7 +349,19 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask);
|
else
|
||||||
|
{
|
||||||
|
CRCComputed = dmr_flc_rs_calc(BPTCDmrDataByte);
|
||||||
|
if (CRCComputed == CRCExtracted)
|
||||||
|
CRCCorrect = 1;
|
||||||
|
|
||||||
|
/* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */
|
||||||
|
else CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask);
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
fprintf (stderr, " EXT: %06X; CRC: %06X;", CRCExtracted, CRCComputed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//Hytera OTA Encryption LC Context Creation for VLC Header
|
//Hytera OTA Encryption LC Context Creation for VLC Header
|
||||||
if (state->hota_key_loaded && CRCCorrect && databurst == 0x01)
|
if (state->hota_key_loaded && CRCCorrect && databurst == 0x01)
|
||||||
|
|||||||
@@ -629,7 +629,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
|
|||||||
state->gi[slot] = 1;
|
state->gi[slot] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (flco == 0x3 || flco == 0x23) //UU_V_Ch_Usr
|
else if (flco == 0x3 || flco == 0x13 || flco == 0x23) //UU_V_Ch_Usr
|
||||||
{
|
{
|
||||||
sprintf (state->call_string[slot], " Private ");
|
sprintf (state->call_string[slot], " Private ");
|
||||||
fprintf (stderr, "Private ");
|
fprintf (stderr, "Private ");
|
||||||
|
|||||||
@@ -236,10 +236,11 @@ uint32_t ComputeAndCorrectFullLinkControlCrc(uint8_t * FullLinkControlDataBytes,
|
|||||||
rs_12_9_calc_syndrome(&VoiceLCHeaderStr, &syndrome);
|
rs_12_9_calc_syndrome(&VoiceLCHeaderStr, &syndrome);
|
||||||
if(rs_12_9_check_syndrome(&syndrome) != 0) result = rs_12_9_correct_errors(&VoiceLCHeaderStr, &syndrome, &errors_found);
|
if(rs_12_9_check_syndrome(&syndrome) != 0) result = rs_12_9_correct_errors(&VoiceLCHeaderStr, &syndrome, &errors_found);
|
||||||
|
|
||||||
/* Reconstitue the CRC */
|
/* Compute the expected 24-bit RS(12,9) parity from the 9 LC data bytes */
|
||||||
*CRCComputed = (uint32_t)((VoiceLCHeaderStr.data[9] << 16) & 0xFF0000);
|
rs_12_9_checksum_t * cs = rs_12_9_calc_checksum(&VoiceLCHeaderStr);
|
||||||
*CRCComputed |= (uint32_t)((VoiceLCHeaderStr.data[10] << 8) & 0x00FF00);
|
*CRCComputed = (uint32_t)((cs->bytes[0] << 16) & 0xFF0000);
|
||||||
*CRCComputed |= (uint32_t)((VoiceLCHeaderStr.data[11] << 0) & 0x0000FF);
|
*CRCComputed |= (uint32_t)((cs->bytes[1] << 8) & 0x00FF00);
|
||||||
|
*CRCComputed |= (uint32_t)((cs->bytes[2] << 0) & 0x0000FF);
|
||||||
|
|
||||||
if((result == RS_12_9_CORRECT_ERRORS_RESULT_NO_ERRORS_FOUND) ||
|
if((result == RS_12_9_CORRECT_ERRORS_RESULT_NO_ERRORS_FOUND) ||
|
||||||
(result == RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CORRECTED))
|
(result == RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CORRECTED))
|
||||||
|
|||||||
@@ -254,16 +254,17 @@ rs_12_9_correct_errors_result_t rs_12_9_correct_errors(rs_12_9_codeword_t *codew
|
|||||||
rs_12_9_roots_t *roots;
|
rs_12_9_roots_t *roots;
|
||||||
uint8_t num, denom;
|
uint8_t num, denom;
|
||||||
|
|
||||||
|
if (rs_12_9_check_syndrome(syndrome) == 0) {
|
||||||
|
*errors_found = 0;
|
||||||
|
return RS_12_9_CORRECT_ERRORS_RESULT_NO_ERRORS_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
rs_12_9_calculate(syndrome, &error_locator_poly, &error_evaluator_poly);
|
rs_12_9_calculate(syndrome, &error_locator_poly, &error_evaluator_poly);
|
||||||
roots = rs_12_9_find_roots(&error_locator_poly);
|
roots = rs_12_9_find_roots(&error_locator_poly);
|
||||||
*errors_found = roots->errors_num;
|
*errors_found = roots->errors_num;
|
||||||
|
|
||||||
if (roots->errors_num == 0)
|
// With 3 parity bytes (d_min = 4), RS(12,9) can only uniquely correct t = 1 byte error.
|
||||||
return RS_12_9_CORRECT_ERRORS_RESULT_NO_ERRORS_FOUND;
|
if (roots->errors_num == 1) {
|
||||||
|
|
||||||
// Error correction is done using the error-evaluator equation on pp 207.
|
|
||||||
if (roots->errors_num > 0 && roots->errors_num <= RS_12_9_CHECKSUMSIZE) {
|
|
||||||
// First check for illegal error locations.
|
|
||||||
for (r = 0; r < roots->errors_num; r++) {
|
for (r = 0; r < roots->errors_num; r++) {
|
||||||
if (roots->error_locations[r] >= RS_12_9_DATASIZE+RS_12_9_CHECKSUMSIZE)
|
if (roots->error_locations[r] >= RS_12_9_DATASIZE+RS_12_9_CHECKSUMSIZE)
|
||||||
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CANT_BE_CORRECTED;
|
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CANT_BE_CORRECTED;
|
||||||
@@ -284,10 +285,20 @@ rs_12_9_correct_errors_result_t rs_12_9_correct_errors(rs_12_9_codeword_t *codew
|
|||||||
for (j = 1; j < RS_12_9_POLY_MAXDEG; j += 2)
|
for (j = 1; j < RS_12_9_POLY_MAXDEG; j += 2)
|
||||||
denom ^= rs_12_9_galois_multiplication(error_locator_poly.data[j], rs_12_9_galois_exp_table_get(((255-i)*(j-1)) % 255));
|
denom ^= rs_12_9_galois_multiplication(error_locator_poly.data[j], rs_12_9_galois_exp_table_get(((255-i)*(j-1)) % 255));
|
||||||
|
|
||||||
|
if (denom == 0)
|
||||||
|
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CANT_BE_CORRECTED;
|
||||||
|
|
||||||
err = rs_12_9_galois_multiplication(num, rs_12_9_galois_inv(denom));
|
err = rs_12_9_galois_multiplication(num, rs_12_9_galois_inv(denom));
|
||||||
//console_log(LOGLEVEL_CODING LOGLEVEL_DEBUG " rs (12,9): error magnitude %#x at byte loc. %u\n", err, sizeof(rs_12_9_codeword_t)-i);
|
//console_log(LOGLEVEL_CODING LOGLEVEL_DEBUG " rs (12,9): error magnitude %#x at byte loc. %u\n", err, sizeof(rs_12_9_codeword_t)-i);
|
||||||
|
|
||||||
codeword->data[sizeof(rs_12_9_codeword_t)-i-1] ^= err;
|
codeword->data[sizeof(rs_12_9_codeword_t)-i-1] ^= err;
|
||||||
|
|
||||||
|
rs_12_9_poly_t post_syndrome;
|
||||||
|
rs_12_9_calc_syndrome(codeword, &post_syndrome);
|
||||||
|
if (rs_12_9_check_syndrome(&post_syndrome) != 0) {
|
||||||
|
codeword->data[sizeof(rs_12_9_codeword_t)-i-1] ^= err;
|
||||||
|
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CANT_BE_CORRECTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CORRECTED;
|
return RS_12_9_CORRECT_ERRORS_RESULT_ERRORS_CORRECTED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user