From 317bda01770ef28f3ed6117af898b7628bffa545 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 29 Jan 2019 22:32:24 +0000 Subject: [PATCH] Check the guard byte on fast data as well as the mini header. --- DStarControl.cpp | 10 ++++++---- DStarDefines.h | 6 ++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DStarControl.cpp b/DStarControl.cpp index e514635..c37e730 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -343,8 +343,9 @@ bool CDStarControl::writeModem(unsigned char *data, unsigned int len) // Check for the fast data signature if (m_rfState == RS_RF_AUDIO && (m_rfN % 2U) == 1U) { - unsigned char slowDataType = (data[DSTAR_VOICE_FRAME_LENGTH_BYTES + 1U] ^ DSTAR_SCRAMBLER_BYTE1) & DSTAR_SLOW_DATA_TYPE_MASK; - if (slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA1 || slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA2) { + unsigned char slowDataType = (data[DSTAR_VOICE_FRAME_LENGTH_BYTES + 1U] ^ DSTAR_SCRAMBLER_BYTES[0U]) & DSTAR_SLOW_DATA_TYPE_MASK; + unsigned char guard = data[4U + 1U] ^ DSTAR_SCRAMBLER_BYTES[4U]; + if ((slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA1 || slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA2) && guard == DSTAR_FAST_DATA_GUARD_BYTE) { LogMessage("D-Star, switching to fast data mode"); m_rfState = RS_RF_DATA; } @@ -712,8 +713,9 @@ void CDStarControl::writeNetwork() // Check for the fast data signature if (m_netState == RS_NET_AUDIO && (n % 2U) == 1U) { - unsigned char slowDataType = data[DSTAR_VOICE_FRAME_LENGTH_BYTES + 2U] & DSTAR_SLOW_DATA_TYPE_MASK; - if (slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA1 || slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA2) { + unsigned char slowDataType = (data[DSTAR_VOICE_FRAME_LENGTH_BYTES + 2U] ^ DSTAR_SCRAMBLER_BYTES[0U]) & DSTAR_SLOW_DATA_TYPE_MASK; + unsigned char guard = data[4U + 2U] ^ DSTAR_SCRAMBLER_BYTES[4U]; + if ((slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA1 || slowDataType == DSTAR_SLOW_DATA_TYPE_FAST_DATA2) && guard == DSTAR_FAST_DATA_GUARD_BYTE) { LogMessage("D-Star, switching to fast data mode"); m_netState = RS_NET_DATA; } diff --git a/DStarDefines.h b/DStarDefines.h index 3f826ac..9db014c 100644 --- a/DStarDefines.h +++ b/DStarDefines.h @@ -53,7 +53,7 @@ const unsigned char DSTAR_SLOW_DATA_TYPE_FAST_DATA2 = 0x90U; const unsigned char DSTAR_SLOW_DATA_TYPE_SQUELCH = 0xC0U; const unsigned char DSTAR_SLOW_DATA_LENGTH_MASK = 0x0FU; -const unsigned char DSTAR_SCRAMBLER_BYTES[] = {0x70U, 0x4FU, 0x93U}; +const unsigned char DSTAR_SCRAMBLER_BYTES[] = { 0x70U, 0x4FU, 0x93U, 0x40U, 0x64U, 0x74U, 0x6DU, 0x30U, 0x2BU }; const unsigned char DSTAR_DATA_MASK = 0x80U; const unsigned char DSTAR_REPEATER_MASK = 0x40U; @@ -67,9 +67,7 @@ const unsigned char DSTAR_ACK_FLAG = 0x03U; const unsigned char DSTAR_NO_RESPONSE = 0x02U; const unsigned char DSTAR_RELAY_UNAVAILABLE = 0x01U; -const unsigned char DSTAR_SCRAMBLER_BYTE1 = 0x70U; -const unsigned char DSTAR_SCRAMBLER_BYTE2 = 0x4FU; -const unsigned char DSTAR_SCRAMBLER_BYTE3 = 0x93U; +const unsigned char DSTAR_FAST_DATA_GUARD_BYTE = 0x02U; const unsigned char DSTAR_SYNC_BYTES[] = {0x55U, 0x2DU, 0x16U};