diff --git a/DMRLookup.cpp b/DMRLookup.cpp index 418c3e6..29aa66f 100644 --- a/DMRLookup.cpp +++ b/DMRLookup.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -103,6 +103,17 @@ std::string CDMRLookup::find(unsigned int id) return callsign; } +bool CDMRLookup::exists(unsigned int id) +{ + m_mutex.lock(); + + bool found = m_table.count(id) == 1U; + + m_mutex.unlock(); + + return found; +} + bool CDMRLookup::load() { FILE* fp = ::fopen(m_filename.c_str(), "rt"); diff --git a/DMRLookup.h b/DMRLookup.h index 6cb3cda..ed09ac2 100644 --- a/DMRLookup.h +++ b/DMRLookup.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,8 @@ public: std::string find(unsigned int id); + bool exists(unsigned int id); + void stop(); private: diff --git a/P25Control.cpp b/P25Control.cpp index 1fd6016..70707bc 100644 --- a/P25Control.cpp +++ b/P25Control.cpp @@ -179,7 +179,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) if (duid == P25_DUID_LDU1) { if (m_rfState == RS_RF_LISTENING) { m_rfData.reset(); - bool ret = m_rfData.decodeLDU1(data + 2U, m_network != NULL, m_uidOverride); + bool ret = m_rfData.decodeLDU1(data + 2U); if (!ret) { m_lastDUID = duid; return false; @@ -189,28 +189,26 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) if (m_selfOnly) { if (m_id > 99999999U) { // Check that the Config DMR-ID is bigger than 8 digits - if (srcId != m_id / 100U) { - LogMessage("P25, invalid access attempt from %u", srcId); - m_rfState = RS_RF_REJECTED; + if (srcId != m_id / 100U) return false; - } } else if (m_id > 9999999U) { // Check that the Config DMR-ID is bigger than 7 digits - if (srcId != m_id / 10U) { - LogMessage("P25, invalid access attempt from %u", srcId); - m_rfState = RS_RF_REJECTED; + if (srcId != m_id / 10U) return false; - } } else if (srcId != m_id) { // All other cases - LogMessage("P25, invalid access attempt from %u", srcId); - m_rfState = RS_RF_REJECTED; return false; } } + if (!m_uidOverride) { + bool found = m_lookup->exists(srcId); + if (!found) + return false; + } + bool grp = m_rfData.getLCF() == P25_LCF_GROUP; unsigned int dstId = m_rfData.getDstId(); std::string source = m_lookup->find(srcId); @@ -321,9 +319,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) return true; } } else if (duid == P25_DUID_TERM || duid == P25_DUID_TERM_LC) { - if (m_rfState == RS_RF_REJECTED) { - m_rfState = RS_RF_LISTENING; - } else if (m_rfState == RS_RF_AUDIO) { + if (m_rfState == RS_RF_AUDIO) { writeNetwork(m_rfLDU, m_lastDUID, true); ::memset(data + 2U, 0x00U, P25_TERM_FRAME_LENGTH_BYTES); diff --git a/P25Data.cpp b/P25Data.cpp index 11ec57c..3c9eb66 100644 --- a/P25Data.cpp +++ b/P25Data.cpp @@ -71,7 +71,7 @@ void CP25Data::encodeHeader(unsigned char* data) CP25Utils::encode(DUMMY_HEADER, data, 114U, 780U); } -bool CP25Data::decodeLDU1(const unsigned char* data, bool m_network, bool m_uidOverride) +bool CP25Data::decodeLDU1(const unsigned char* data) { assert(data != NULL); @@ -105,12 +105,7 @@ bool CP25Data::decodeLDU1(const unsigned char* data, bool m_network, bool m_uidO return false; } - // Simple validation of the source id - does not check if no network unsigned int srcId = (rs[6U] << 16) + (rs[7U] << 8) + rs[8U]; - if (m_network || (!m_network && !m_uidOverride)) { - if (srcId < 1000000U) - return false; - } switch (rs[0U]) { case P25_LCF_GROUP: diff --git a/P25Data.h b/P25Data.h index dff5be0..6618da2 100644 --- a/P25Data.h +++ b/P25Data.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ public: void encodeHeader(unsigned char* data); - bool decodeLDU1(const unsigned char* data, bool m_network, bool m_uidOverride); + bool decodeLDU1(const unsigned char* data); void encodeLDU1(unsigned char* data); void encodeLDU2(unsigned char* data);