diff --git a/AMBEFEC.cpp b/AMBEFEC.cpp index 4b280465..03f8ac23 100644 --- a/AMBEFEC.cpp +++ b/AMBEFEC.cpp @@ -793,22 +793,25 @@ unsigned int CAMBEFEC::regenerateIMBE(unsigned char* bytes) const unsigned int CAMBEFEC::regenerateDStar(unsigned int& a, unsigned int& b) const { - bool valid; - unsigned int orig_a = a; unsigned int orig_b = b; - unsigned int data = CGolay24128::decode24128(a, valid); - - a = CGolay24128::encode24128(data); + unsigned int data; + bool valid1 = CGolay24128::decode24128(a, data); + if (!valid1) + return 10U; // The PRNG unsigned int p = PRNG_TABLE[data]; b ^= p; - unsigned int datb = CGolay24128::decode24128(b, valid); + unsigned int datb; + bool valid2 = CGolay24128::decode24128(b, datb); + if (!valid2) + return 10U; + a = CGolay24128::encode24128(data); b = CGolay24128::encode24128(datb); b ^= p; @@ -824,12 +827,17 @@ unsigned int CAMBEFEC::regenerateDStar(unsigned int& a, unsigned int& b) const unsigned int CAMBEFEC::regenerateDMR(unsigned int& a, unsigned int& b, unsigned int& c) const { - bool valid; - unsigned int orig_a = a; unsigned int orig_b = b; - unsigned int data = CGolay24128::decode24128(a, valid); + unsigned int data; + bool valid = CGolay24128::decode24128(a, data); + if (!valid) { + a = 0xF00292U; + b = 0x0E0B20U; + c = 0x000000U; + return 10U; // An invalid A block gives an error count of 10 + } a = CGolay24128::encode24128(data); diff --git a/Golay24128.cpp b/Golay24128.cpp index 715c8dce..22cef65e 100644 --- a/Golay24128.cpp +++ b/Golay24128.cpp @@ -1090,23 +1090,25 @@ unsigned int CGolay24128::decode23127(unsigned int code) return code >> 11; } -unsigned int CGolay24128::decode24128(unsigned int input, bool& valid) +bool CGolay24128::decode24128(unsigned int in, unsigned int& out) { - unsigned int syndrome = ::get_syndrome_23127(input >> 1); + unsigned int syndrome = ::get_syndrome_23127(in >> 1); unsigned int error_pattern = DECODING_TABLE_23127[syndrome] << 1; - unsigned int output = input ^ error_pattern; + out = in ^ error_pattern; - valid = (CUtils::countBits(syndrome) < 3U) || !(CUtils::countBits(output) & 1); + bool valid = (CUtils::countBits(syndrome) < 3U) || !(CUtils::countBits(out) & 1); - return output >> 12; + out >>= 12; + + return valid; } -unsigned int CGolay24128::decode24128(unsigned char* bytes, bool& valid) +bool CGolay24128::decode24128(unsigned char* in, unsigned int& out) { - assert(bytes != NULL); + assert(in != NULL); - unsigned int code = (bytes[0U] << 16) | (bytes[1U] << 8) | (bytes[2U] << 0); + unsigned int code = (in[0U] << 16) | (in[1U] << 8) | (in[2U] << 0); - return decode24128(code, valid); + return decode24128(code, out); } diff --git a/Golay24128.h b/Golay24128.h index 721dcbc9..169b31ad 100644 --- a/Golay24128.h +++ b/Golay24128.h @@ -25,8 +25,9 @@ class CGolay24128 { static unsigned int encode24128(unsigned int data); static unsigned int decode23127(unsigned int code); - static unsigned int decode24128(unsigned int code, bool& valid); - static unsigned int decode24128(unsigned char* bytes, bool& valid); + + static bool decode24128(unsigned int in, unsigned int& out); + static bool decode24128(unsigned char* in, unsigned int& out); }; #endif diff --git a/M17Control.cpp b/M17Control.cpp index 653413df..f518037b 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -212,11 +212,11 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) } if (m_rfState == RS_RF_LATE_ENTRY && data[0U] == TAG_DATA1) { - bool valid1, valid2, valid3, valid4; - unsigned int lich1 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 0U, valid1); - unsigned int lich2 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 3U, valid2); - unsigned int lich3 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 6U, valid3); - unsigned int lich4 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 9U, valid4); + unsigned int lich1, lich2, lich3, lich4; + bool valid1 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 0U, lich1); + bool valid2 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 3U, lich2); + bool valid3 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 6U, lich3); + bool valid4 = CGolay24128::decode24128(data + 2U + M17_SYNC_LENGTH_BYTES + 9U, lich4); if (!valid1 || !valid2 || !valid3 || !valid4) return false; diff --git a/Version.h b/Version.h index 7dbf25da..9aea4861 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210329"; +const char* VERSION = "20210407"; #endif diff --git a/YSFFICH.cpp b/YSFFICH.cpp index ce37a7fd..cbe31751 100644 --- a/YSFFICH.cpp +++ b/YSFFICH.cpp @@ -99,13 +99,13 @@ bool CYSFFICH::decode(const unsigned char* bytes) unsigned char output[13U]; viterbi.chainback(output, 96U); - bool valid1, valid2, valid3, valid4; - unsigned int b0 = CGolay24128::decode24128(output + 0U, valid1); - unsigned int b1 = CGolay24128::decode24128(output + 3U, valid2); - unsigned int b2 = CGolay24128::decode24128(output + 6U, valid3); - unsigned int b3 = CGolay24128::decode24128(output + 9U, valid4); + unsigned int b0, b1, b2, b3; + bool valid0 = CGolay24128::decode24128(output + 0U, b0); + bool valid1 = CGolay24128::decode24128(output + 3U, b1); + bool valid2 = CGolay24128::decode24128(output + 6U, b2); + bool valid3 = CGolay24128::decode24128(output + 9U, b3); - if (!valid1 || !valid2 || !valid3 || !valid4) + if (!valid0 || !valid1 || !valid2 || !valid3) return false; m_fich[0U] = (b0 >> 4) & 0xFFU;