From 9035656eeb3d3f74a17d7254c669388d7b57abae Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 12 Jul 2016 07:50:01 +0100 Subject: [PATCH] Add rejected state to incoming RF data. --- DStarControl.cpp | 17 ++++++++++++----- Defines.h | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/DStarControl.cpp b/DStarControl.cpp index 541a3d7..a7621b5 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -117,8 +117,7 @@ bool CDStarControl::writeModem(unsigned char *data) } if (type == TAG_LOST) { - if (m_rfState == RS_RF_LATE_ENTRY) - m_rfState = RS_RF_LISTENING; + m_rfState = RS_RF_LISTENING; return false; } @@ -131,6 +130,7 @@ bool CDStarControl::writeModem(unsigned char *data) // Is this a transmission destined for a repeater? if (!header.isRepeater()) { LogMessage("D-Star, non repeater RF header received from %8.8s", my1); + m_rfState = RS_RF_REJECTED; return false; } @@ -140,16 +140,19 @@ bool CDStarControl::writeModem(unsigned char *data) // Is it for us? if (::memcmp(callsign, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH) != 0) { LogMessage("D-Star, received RF header for wrong repeater (%8.8s) from %8.8s", callsign, my1); + m_rfState = RS_RF_REJECTED; return false; } if (m_selfOnly && ::memcmp(my1, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH - 1U) != 0) { LogMessage("D-Star, invalid access attempt from %8.8s", my1); + m_rfState = RS_RF_REJECTED; return false; } if (!m_selfOnly && std::find_if(m_blackList.begin(), m_blackList.end(), std::bind(CallsignCompare, std::placeholders::_1, my1)) != m_blackList.end()) { LogMessage("D-Star, invalid access attempt from %8.8s", my1); + m_rfState = RS_RF_REJECTED; return false; } @@ -205,7 +208,9 @@ bool CDStarControl::writeModem(unsigned char *data) LogMessage("D-Star, received RF header from %8.8s/%4.4s to %8.8s", my1, my2, your); } else if (type == TAG_EOT) { - if (m_rfState == RS_RF_AUDIO) { + if (m_rfState == RS_RF_REJECTED) { + m_rfState = RS_RF_LISTENING; + } else if (m_rfState == RS_RF_AUDIO) { if (m_net) writeNetworkDataRF(DSTAR_END_PATTERN_BYTES, 0U, true); @@ -220,7 +225,9 @@ bool CDStarControl::writeModem(unsigned char *data) return false; } else if (type == TAG_DATA) { - if (m_rfState == RS_RF_LISTENING) { + if (m_rfState == RS_RF_REJECTED) { + return false; + } else if (m_rfState == RS_RF_LISTENING) { // The sync is regenerated by the modem so can do exact match if (::memcmp(data + 1U + DSTAR_VOICE_FRAME_LENGTH_BYTES, DSTAR_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES) == 0) { m_slowData.start(); @@ -436,7 +443,7 @@ void CDStarControl::writeNetwork() if (length == 0U) return; - if (m_rfState != RS_RF_LISTENING && m_netState == RS_NET_IDLE) + if (m_rfState == RS_RF_AUDIO && m_netState == RS_NET_IDLE) return; m_networkWatchdog.start(); diff --git a/Defines.h b/Defines.h index 13ffcba..c3c8941 100644 --- a/Defines.h +++ b/Defines.h @@ -35,7 +35,8 @@ enum RPT_RF_STATE { RS_RF_LISTENING, RS_RF_LATE_ENTRY, RS_RF_AUDIO, - RS_RF_DATA + RS_RF_DATA, + RS_RF_REJECTED }; enum RPT_NET_STATE {