diff --git a/Utils.cpp b/Utils.cpp
index 2e5c2827..be3831f1 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -177,7 +177,7 @@ void Utils::symbols(const std::string& title, const uint8_t* data, uint32_t leng
microslotHeader += temp;
}
- ::Log(2U, "SYMBOLS", "MCR: % s\r\n", microslotHeader.c_str());
+ ::Log(2U, "SYMBOLS", "MCR: % s", microslotHeader.c_str());
uint32_t bufLen = length;
while (bufLen > 0U) {
@@ -207,7 +207,7 @@ void Utils::symbols(const std::string& title, const uint8_t* data, uint32_t leng
symOffset += 9;
}
- ::Log(2U, "SYMBOLS", "%03u: %s\r\n", count, output.c_str());
+ ::Log(2U, "SYMBOLS", "%03u: %s", count, output.c_str());
offset += 18U;
count += 2U;
diff --git a/dmr/VoicePacket.cpp b/dmr/VoicePacket.cpp
index 22db188e..733bf82e 100644
--- a/dmr/VoicePacket.cpp
+++ b/dmr/VoicePacket.cpp
@@ -206,24 +206,23 @@ bool VoicePacket::process(uint8_t* data, uint32_t len)
lc::FullLC fullLC;
lc::PrivacyLC* lc = fullLC.decodePI(data + 2U);
-/*
- if (lc == NULL)
- return false;
-*/
+ if (lc == NULL) {
+ LogWarning(LOG_RF, "DMR Slot %u, DT_VOICE_PI_HEADER, bad LC received, replacing", m_slot->m_slotNo);
+ lc = new lc::PrivacyLC();
+ lc->setDstId(m_slot->m_rfLC->getDstId());
+ }
+
m_slot->m_rfPrivacyLC = lc;
+ // Regenerate the LC data
+ fullLC.encodePI(*m_slot->m_rfPrivacyLC, data + 2U);
+
// Regenerate the Slot Type
slotType.encode(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed
Sync::addDMRDataSync(data + 2U, m_slot->m_duplex);
- // Regenerate the payload and the BPTC (196,96) FEC
- edac::BPTC19696 bptc;
- uint8_t payload[12U];
- bptc.decode(data + 2U, payload);
- bptc.encode(payload, data + 2U);
-
data[0U] = TAG_DATA;
data[1U] = 0x00U;
@@ -739,15 +738,17 @@ void VoicePacket::processNetwork(const data::Data& dmrData)
lc::FullLC fullLC;
lc::PrivacyLC* lc = fullLC.decodePI(data + 2U);
-/*
if (lc == NULL) {
- LogWarning(LOG_NET, "DMR Slot %u, DT_VOICE_PI_HEADER, bad LC received from the network, replacing", m_slot->m_slotNo);
+ LogWarning(LOG_NET, "DMR Slot %u, DT_VOICE_PI_HEADER, bad LC received, replacing", m_slot->m_slotNo);
lc = new lc::PrivacyLC();
lc->setDstId(dmrData.getDstId());
}
-*/
+
m_slot->m_netPrivacyLC = lc;
+ // Regenerate the LC data
+ fullLC.encodePI(*m_slot->m_netPrivacyLC, data + 2U);
+
// Regenerate the Slot Type
SlotType slotType;
slotType.setColorCode(m_slot->m_colorCode);
@@ -757,12 +758,6 @@ void VoicePacket::processNetwork(const data::Data& dmrData)
// Convert the Data Sync to be from the BS or MS as needed
Sync::addDMRDataSync(data + 2U, m_slot->m_duplex);
- // Regenerate the payload and the BPTC (196,96) FEC
- edac::BPTC19696 bptc;
- uint8_t payload[12U];
- bptc.decode(data + 2U, payload);
- bptc.encode(payload, data + 2U);
-
data[0U] = TAG_DATA;
data[1U] = 0x00U;
diff --git a/dmr/lc/FullLC.cpp b/dmr/lc/FullLC.cpp
index d2f45d4a..0d91ee8f 100644
--- a/dmr/lc/FullLC.cpp
+++ b/dmr/lc/FullLC.cpp
@@ -155,9 +155,19 @@ PrivacyLC* FullLC::decodePI(const uint8_t* data)
uint8_t lcData[DMR_LC_HEADER_LENGTH_BYTES];
m_bptc.decode(data, lcData);
- // check CRC-CCITT 16,2
-// if (!edac::CRC::checkCCITT162(lcData, DMR_LC_HEADER_LENGTH_BYTES))
-// return NULL;
+ // make sure the CRC-CCITT 16 was actually included (the network tends to zero the CRC)
+ if (lcData[10U] != 0x00U && lcData[11U] != 0x00U) {
+ // validate the CRC-CCITT 16
+ lcData[10U] ^= PI_HEADER_CRC_MASK[0U];
+ lcData[11U] ^= PI_HEADER_CRC_MASK[1U];
+
+ if (!edac::CRC::checkCCITT162(lcData, DMR_LC_HEADER_LENGTH_BYTES))
+ return NULL;
+
+ // restore the checksum
+ lcData[10U] ^= PI_HEADER_CRC_MASK[0U];
+ lcData[11U] ^= PI_HEADER_CRC_MASK[1U];
+ }
return new PrivacyLC(lcData);
}
@@ -175,9 +185,15 @@ void FullLC::encodePI(const PrivacyLC& lc, uint8_t* data)
uint8_t lcData[DMR_LC_HEADER_LENGTH_BYTES];
lc.getData(lcData);
- // encode CRC-CCITT 16,2
-// uint8_t parity[2U];
-// edac::CRC::addCCITT162(lcData, 9U);
+ // compute CRC-CCITT 16
+ lcData[10U] ^= PI_HEADER_CRC_MASK[0U];
+ lcData[11U] ^= PI_HEADER_CRC_MASK[1U];
+
+ edac::CRC::addCCITT162(lcData, DMR_LC_HEADER_LENGTH_BYTES);
+
+ // restore the checksum
+ lcData[10U] ^= PI_HEADER_CRC_MASK[0U];
+ lcData[11U] ^= PI_HEADER_CRC_MASK[1U];
// encode BPTC (196,96) FEC
m_bptc.encode(lcData, data);
diff --git a/dmr/lc/PrivacyLC.cpp b/dmr/lc/PrivacyLC.cpp
index d328d159..4e4d8bb9 100644
--- a/dmr/lc/PrivacyLC.cpp
+++ b/dmr/lc/PrivacyLC.cpp
@@ -127,7 +127,7 @@ PrivacyLC::PrivacyLC() :
m_kId(0U),
m_mi(NULL)
{
- /* stub */
+ m_mi = new uint8_t[DMR_MI_LENGTH_BYTES];
}
///
@@ -135,7 +135,7 @@ PrivacyLC::PrivacyLC() :
///
PrivacyLC::~PrivacyLC()
{
- /* stub */
+ delete m_mi;
}
///