mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-16 18:57:24 -05:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26641453ba | ||
|
|
b202353df2 | ||
|
|
fbe7fcab0e | ||
|
|
138a48ad31 | ||
|
|
cd6ce80124 | ||
|
|
edf97e26b8 |
185
src/bptc.c
185
src/bptc.c
@@ -213,8 +213,8 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== Pass 1: row Hamming(15,11) on rows 0..8 ========== */
|
||||
for (i = 0; i < 9; i++)
|
||||
/* ========== Pass 1: row Hamming(15,11) on rows 0..12 ========== */
|
||||
for (i = 0; i < 13; i++)
|
||||
{
|
||||
for (j = 0; j < 15; j++)
|
||||
{
|
||||
@@ -232,8 +232,8 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
fprintf(stderr, "%u", LineBefore[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
/* Keep original data bits on failure */
|
||||
for (j = 0; j < 11; j++)
|
||||
/* Keep original bits on failure */
|
||||
for (j = 0; j < 15; j++)
|
||||
DataMatrix[i][j] = LineBefore[j];
|
||||
}
|
||||
else
|
||||
@@ -253,8 +253,9 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
#endif
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineCorrected[j];
|
||||
/* Re-inject the full line (including corrected parity bits) in the matrix */
|
||||
for (j = 0; j < 15; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
}
|
||||
#if BPTC_196x96_DEBUG
|
||||
@@ -282,7 +283,7 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
fprintf(stderr, "%u", ColumnBefore[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
for (j = 0; j < 9; j++)
|
||||
for (j = 0; j < 13; j++)
|
||||
DataMatrix[j][i] = ColumnBefore[j];
|
||||
}
|
||||
else
|
||||
@@ -301,8 +302,9 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
#endif
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 9; j++)
|
||||
DataMatrix[j][i] = ColumnCorrected[j];
|
||||
/* Re-inject the full column (including corrected parity bits) in the matrix */
|
||||
for (j = 0; j < 13; j++)
|
||||
DataMatrix[j][i] = ColumnUncorrected[j];
|
||||
}
|
||||
}
|
||||
#if BPTC_196x96_DEBUG
|
||||
@@ -315,7 +317,7 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
HammingIrrecoverableErrorNb = 0;
|
||||
|
||||
/* ========== Pass 2: rows ========== */
|
||||
for (i = 0; i < 9; i++)
|
||||
for (i = 0; i < 13; i++)
|
||||
{
|
||||
for (j = 0; j < 15; j++)
|
||||
{
|
||||
@@ -333,7 +335,7 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
fprintf(stderr, "%u", LineBefore[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
for (j = 0; j < 11; j++)
|
||||
for (j = 0; j < 15; j++)
|
||||
DataMatrix[i][j] = LineBefore[j];
|
||||
}
|
||||
else
|
||||
@@ -352,8 +354,9 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
#endif
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineCorrected[j];
|
||||
/* Re-inject the full line (including corrected parity bits) in the matrix */
|
||||
for (j = 0; j < 15; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
}
|
||||
#if BPTC_196x96_DEBUG
|
||||
@@ -381,7 +384,7 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
fprintf(stderr, "%u", ColumnBefore[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
for (j = 0; j < 9; j++)
|
||||
for (j = 0; j < 13; j++)
|
||||
DataMatrix[j][i] = ColumnBefore[j];
|
||||
}
|
||||
else
|
||||
@@ -400,8 +403,58 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
#endif
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 9; j++)
|
||||
DataMatrix[j][i] = ColumnCorrected[j];
|
||||
/* Re-inject the full column (including corrected parity bits) in the matrix */
|
||||
for (j = 0; j < 13; j++)
|
||||
DataMatrix[j][i] = ColumnUncorrected[j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify that all rows (0..12) and columns (0..14) have converged to zero syndrome.
|
||||
* Hamming_15_11_decode never returns false because all 15 non-zero 4-bit syndromes
|
||||
* map to a bit flip, so without a post-pass consistency check a noisy burst can
|
||||
* mis-correct data bits in Pass 2 Columns while still reporting 0 errors. */
|
||||
for (i = 0; i < 13; i++)
|
||||
{
|
||||
for (j = 0; j < 15; j++)
|
||||
{
|
||||
LineUncorrected[j] = DataMatrix[i][j];
|
||||
}
|
||||
if (Hamming_15_11_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < 15; j++)
|
||||
{
|
||||
if (LineUncorrected[j] != DataMatrix[i][j])
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 15; i++)
|
||||
{
|
||||
for (j = 0; j < 13; j++)
|
||||
{
|
||||
ColumnUncorrected[j] = DataMatrix[j][i];
|
||||
}
|
||||
if (Hamming_13_9_decode(ColumnUncorrected, ColumnCorrected, 1) == false)
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < 13; j++)
|
||||
{
|
||||
if (ColumnUncorrected[j] != DataMatrix[j][i])
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if BPTC_196x96_DEBUG
|
||||
@@ -430,12 +483,33 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||
DMRDataExtracted[k++] = DataMatrix[i][j];
|
||||
}
|
||||
|
||||
uint32_t total_corr = row_corr_p1 + col_corr_p1 + row_corr_p2 + col_corr_p2;
|
||||
uint32_t p2_corr = row_corr_p2 + col_corr_p2;
|
||||
|
||||
/* In DMR BPTC(196,96), R(0) and R(1) must be 0. Also reject R(2)==1 when the
|
||||
* received R(2) bit was 0 or the matrix required heavy multi-pass corrections,
|
||||
* because is_ras==1 bypasses downstream CRC checks when no RAS key is loaded. */
|
||||
if (DataMatrix[0][2] != 0 || DataMatrix[0][1] != 0)
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
else if (DataMatrix[0][0] == 1 && ((InputDeInteleavedData[1] & 1) == 0 || total_corr > 8 || p2_corr > 2))
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
|
||||
if (HammingIrrecoverableErrorNb == 0)
|
||||
{
|
||||
R[0] = DataMatrix[0][2]; /* R(0) */
|
||||
R[1] = DataMatrix[0][1]; /* R(1) */
|
||||
R[2] = DataMatrix[0][0]; /* R(2) */
|
||||
}
|
||||
else
|
||||
{
|
||||
R[0] = 0;
|
||||
R[1] = 0;
|
||||
R[2] = 0;
|
||||
}
|
||||
|
||||
if (R[0] == 0 && R[1] == 0 && R[2] == 1)
|
||||
*is_ras = 1;
|
||||
@@ -466,7 +540,7 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
uint32_t ParityCheckErrorNb = 0;
|
||||
uint32_t NbOfOne;
|
||||
|
||||
uint8_t row_bad[7];
|
||||
uint8_t row_bad[8];
|
||||
uint8_t col_bad[16];
|
||||
|
||||
#if BPTC_128x77_DEBUG
|
||||
@@ -479,9 +553,9 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
DataMatrix[i][j] = (InputDataMatrix[i][j] & 1);
|
||||
}
|
||||
|
||||
/* ---------- Pass 1: Hamming (16,11,4) on rows 0..6 ---------- */
|
||||
/* ---------- Pass 1: Hamming (16,11,4) on rows 0..7 ---------- */
|
||||
memset(row_bad, 0, sizeof(row_bad));
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
for (j = 0; j < 16; j++)
|
||||
LineUncorrected[j] = DataMatrix[i][j];
|
||||
@@ -496,13 +570,11 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
fprintf(stderr, "%u", LineUncorrected[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineCorrected[j];
|
||||
for (j = 0; j < 16; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
}
|
||||
#if BPTC_128x77_DEBUG
|
||||
@@ -537,12 +609,14 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
(unsigned)ParityCheckErrorNb);
|
||||
#endif
|
||||
|
||||
/* ---------- Parity-guided single-bit repair ---------- */
|
||||
/* ---------- Parity-guided bit repair ---------- */
|
||||
{
|
||||
uint32_t n_bad_rows = 0, n_bad_cols = 0;
|
||||
uint32_t br = 0, bc = 0;
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
UNUSED(bc);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
if (row_bad[i]) { n_bad_rows++; br = i; }
|
||||
for (i = 0; i < 16; i++)
|
||||
if (col_bad[i]) { n_bad_cols++; bc = i; }
|
||||
@@ -558,29 +632,35 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
if (n_bad_rows == 1 && n_bad_cols == 1 && bc < 11)
|
||||
if (n_bad_rows == 1 && (n_bad_cols == 1 || n_bad_cols == 2))
|
||||
{
|
||||
DataMatrix[br][bc] ^= 1;
|
||||
row_bad[br] = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (col_bad[i])
|
||||
{
|
||||
DataMatrix[br][i] ^= 1;
|
||||
#if BPTC_128x77_DEBUG
|
||||
fprintf(stderr,
|
||||
" BPTC128 parity-guided FLIP at row=%u col=%u -> %u\n",
|
||||
(unsigned)br, (unsigned)bc, (unsigned)DataMatrix[br][bc]);
|
||||
(unsigned)br, (unsigned)i, (unsigned)DataMatrix[br][i]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
row_bad[br] = 0;
|
||||
}
|
||||
#if BPTC_128x77_DEBUG
|
||||
else if (n_bad_rows || n_bad_cols)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" BPTC128 no single-intersection flip "
|
||||
"(need exactly 1 bad row and 1 data col)\n");
|
||||
" BPTC128 no repair flip "
|
||||
"(need 1 bad row and 1 or 2 bad cols)\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ---------- Pass 2: Hamming (16,11,4) again ---------- */
|
||||
HammingIrrecoverableErrorNb = 0;
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
for (j = 0; j < 16; j++)
|
||||
LineUncorrected[j] = DataMatrix[i][j];
|
||||
@@ -594,13 +674,11 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
||||
fprintf(stderr, "%u", LineUncorrected[j] & 1);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < 11; j++)
|
||||
DataMatrix[i][j] = LineCorrected[j];
|
||||
for (j = 0; j < 16; j++)
|
||||
DataMatrix[i][j] = LineUncorrected[j];
|
||||
}
|
||||
}
|
||||
#if BPTC_128x77_DEBUG
|
||||
@@ -696,22 +774,45 @@ uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDat
|
||||
DMRDataExtracted[i] = DataMatrix[i] & 1;
|
||||
}
|
||||
|
||||
/* Prepare the line to be corrected */
|
||||
/* Prepare the first row (bits 0..15) to be corrected */
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LineUncorrected[i] = DataMatrix[i] & 1;
|
||||
}
|
||||
|
||||
/* Apply Hamming (16,11,4) code correction */
|
||||
/* Apply Hamming (16,11,4) code correction to row 0 */
|
||||
if(Hamming_16_11_4_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
|
||||
/* Copy the corrected content to the output buffer */
|
||||
for(i = 0; i < 11; i++)
|
||||
else
|
||||
{
|
||||
DMRDataExtracted[i] = LineCorrected[i] & 1;
|
||||
/* Copy all 16 corrected bits (including parity bits 11..15) */
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
DMRDataExtracted[i] = LineUncorrected[i] & 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the second row (bits 16..31) to be corrected;
|
||||
* 1^16 is a codeword of Hamming(16,11,4), so both even and odd parity rows are valid codewords */
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
LineUncorrected[i] = DataMatrix[i + 16] & 1;
|
||||
}
|
||||
|
||||
/* Apply Hamming (16,11,4) code correction to row 1 */
|
||||
if(Hamming_16_11_4_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||
{
|
||||
HammingIrrecoverableErrorNb++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy all 16 corrected bits (including parity bits 11..15) */
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
DMRDataExtracted[i + 16] = LineUncorrected[i] & 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check Parity bits */
|
||||
|
||||
101
src/dmr_dburst.c
101
src/dmr_dburst.c
@@ -14,6 +14,24 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
|
||||
@@ -60,6 +78,10 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
||||
uint8_t bptc_res_bits[3];
|
||||
memset (bptc_res_bits, 0, sizeof(bptc_res_bits));
|
||||
uint8_t crc_original_validity = 0;
|
||||
static uint8_t ras_confirm_count = 0;
|
||||
static uint8_t prev_dmr_is_ras = 0;
|
||||
if (prev_dmr_is_ras == 1 && state->dmr_is_ras == 0)
|
||||
ras_confirm_count = 0;
|
||||
|
||||
uint32_t crcmask = 0;
|
||||
uint8_t crclen = 0;
|
||||
@@ -300,10 +322,23 @@ 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) */
|
||||
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_ras)
|
||||
{
|
||||
uint32_t std_crc = dmr_flc_rs_calc(BPTCDmrDataByte);
|
||||
if (std_crc == CRCExtracted)
|
||||
{
|
||||
CRCComputed = std_crc;
|
||||
CRCCorrect = 1;
|
||||
is_ras = 0;
|
||||
|
||||
#ifdef DEBUG_RAS
|
||||
fprintf (stderr, " EXT: %06X; CRC: %06X;", CRCExtracted, CRCComputed);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
CRCComputed = ras_mac_calculator(state, BPTCDmrDataByte, 9, 1);
|
||||
if (CRCComputed == CRCExtracted)
|
||||
@@ -313,8 +348,21 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
||||
fprintf (stderr, " EXT: %06X; MAC: %06X;", CRCExtracted, CRCComputed);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
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
|
||||
if (state->hota_key_loaded && CRCCorrect && databurst == 0x01)
|
||||
hytera_create_lc_ctx(state, BPTCDmrDataBit);
|
||||
@@ -354,18 +402,28 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
||||
//run CCITT on other data forms
|
||||
else
|
||||
{
|
||||
if (is_ras == 1)
|
||||
uint32_t std_crc = ComputeCrcCCITT(BPTCDmrDataBit);
|
||||
if (std_crc == CRCExtracted)
|
||||
{
|
||||
is_ras = 0;
|
||||
CRCComputed = std_crc;
|
||||
CRCCorrect = 1;
|
||||
}
|
||||
else if (is_ras == 1)
|
||||
{
|
||||
CRCComputed = ras_mac_calculator(state, BPTCDmrDataByte, 10, 0);
|
||||
if (CRCComputed == CRCExtracted) CRCCorrect = 1;
|
||||
else CRCCorrect = 0;
|
||||
|
||||
#ifdef DEBUG_RAS
|
||||
fprintf (stderr, " EXT: %04X; MAC: %04X;", CRCExtracted, CRCComputed);
|
||||
#endif
|
||||
}
|
||||
else CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit);
|
||||
|
||||
if (CRCComputed == CRCExtracted) CRCCorrect = 1;
|
||||
else CRCCorrect = 0;
|
||||
else
|
||||
{
|
||||
CRCComputed = std_crc;
|
||||
CRCCorrect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//if this is a RAS system, set the CRC to okay if irrecoverable errors are okay
|
||||
@@ -473,9 +531,11 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
||||
/* Compute the 5 bit CRC */
|
||||
CRCComputed = ComputeCrc5Bit(LC_DataBit);
|
||||
|
||||
//read ahead first two bytes, look for 1X10 or 2X10 pattern
|
||||
//read ahead first two bytes, look for 1X10 or 2X10 pattern (with PF/R bits 0)
|
||||
uint16_t ras_test = (uint16_t)(ConvertBitIntoBytes(&LC_DataBit[0], 16) & 0x30FF);
|
||||
if ((IrrecoverableErrors == 0) && (ras_test == 0x2010 || ras_test == 0x1010))
|
||||
if ((IrrecoverableErrors == 0) &&
|
||||
(LC_DataBit[0] == 0) && (LC_DataBit[1] == 0) &&
|
||||
(ras_test == 0x2010 || ras_test == 0x1010))
|
||||
{
|
||||
is_ras = 1;
|
||||
if (state->ras_effective_key != 0)
|
||||
@@ -702,9 +762,28 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
|
||||
//might flicker the terminal on partially enabled systems, may need to find a better placement
|
||||
if (IrrecoverableErrors == 0 && (is_bptc || is_emb) && databurst != 0x05 && databurst != 0x07 && databurst != 0x09)
|
||||
state->dmr_is_ras = is_ras;
|
||||
//require a key-verified RAS burst or 2 RAS bursts to latch [RAS]; clear on valid non-PI non-RAS BPTC burst
|
||||
if (IrrecoverableErrors == 0 && is_ras == 1 && (is_bptc || is_emb) && databurst != 0x05 && databurst != 0x07 && databurst != 0x09)
|
||||
{
|
||||
if (state->ras_effective_key != 0 && CRCCorrect == 1)
|
||||
{
|
||||
ras_confirm_count = 2;
|
||||
state->dmr_is_ras = 1;
|
||||
}
|
||||
else if ((is_bptc || is_emb) && databurst != 0x00)
|
||||
{
|
||||
if (ras_confirm_count < 2)
|
||||
ras_confirm_count++;
|
||||
if (ras_confirm_count >= 2)
|
||||
state->dmr_is_ras = 1;
|
||||
}
|
||||
}
|
||||
else if (IrrecoverableErrors == 0 && is_ras == 0 && is_bptc && CRCCorrect == 1 && databurst != 0x00 && databurst != 0x05 && databurst != 0x07 && databurst != 0x09)
|
||||
{
|
||||
ras_confirm_count = 0;
|
||||
state->dmr_is_ras = 0;
|
||||
}
|
||||
prev_dmr_is_ras = state->dmr_is_ras;
|
||||
|
||||
if (IrrecoverableErrors == 0 && CRCCorrect == 0 && is_ras == 0 && databurst != 0x09 && databurst != 0x05)
|
||||
{
|
||||
|
||||
@@ -629,7 +629,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
|
||||
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 ");
|
||||
fprintf (stderr, "Private ");
|
||||
|
||||
@@ -236,10 +236,11 @@ uint32_t ComputeAndCorrectFullLinkControlCrc(uint8_t * FullLinkControlDataBytes,
|
||||
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);
|
||||
|
||||
/* Reconstitue the CRC */
|
||||
*CRCComputed = (uint32_t)((VoiceLCHeaderStr.data[9] << 16) & 0xFF0000);
|
||||
*CRCComputed |= (uint32_t)((VoiceLCHeaderStr.data[10] << 8) & 0x00FF00);
|
||||
*CRCComputed |= (uint32_t)((VoiceLCHeaderStr.data[11] << 0) & 0x0000FF);
|
||||
/* Compute the expected 24-bit RS(12,9) parity from the 9 LC data bytes */
|
||||
rs_12_9_checksum_t * cs = rs_12_9_calc_checksum(&VoiceLCHeaderStr);
|
||||
*CRCComputed = (uint32_t)((cs->bytes[0] << 16) & 0xFF0000);
|
||||
*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) ||
|
||||
(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;
|
||||
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);
|
||||
roots = rs_12_9_find_roots(&error_locator_poly);
|
||||
*errors_found = roots->errors_num;
|
||||
|
||||
if (roots->errors_num == 0)
|
||||
return RS_12_9_CORRECT_ERRORS_RESULT_NO_ERRORS_FOUND;
|
||||
|
||||
// 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.
|
||||
// With 3 parity bytes (d_min = 4), RS(12,9) can only uniquely correct t = 1 byte error.
|
||||
if (roots->errors_num == 1) {
|
||||
for (r = 0; r < roots->errors_num; r++) {
|
||||
if (roots->error_locations[r] >= RS_12_9_DATASIZE+RS_12_9_CHECKSUMSIZE)
|
||||
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)
|
||||
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));
|
||||
//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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user