diff --git a/DMRControl.cpp b/DMRControl.cpp index f35f7c9..d576bc8 100644 --- a/DMRControl.cpp +++ b/DMRControl.cpp @@ -20,7 +20,7 @@ #include #include -CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile) : +CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile) : m_id(id), m_colorCode(colorCode), m_selfOnly(selfOnly), @@ -38,7 +38,7 @@ m_lookup(NULL) m_lookup = new CDMRLookup(lookupFile); m_lookup->read(); - CDMRSlot::init(id, colorCode, selfOnly, prefixes, blackList, modem, network, display, duplex, m_lookup); + CDMRSlot::init(id, colorCode, selfOnly, prefixes, blackList, DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2, modem, network, display, duplex, m_lookup); } CDMRControl::~CDMRControl() diff --git a/DMRControl.h b/DMRControl.h index 5598564..c011048 100644 --- a/DMRControl.h +++ b/DMRControl.h @@ -30,7 +30,7 @@ class CDMRControl { public: - CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile); + CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile); ~CDMRControl(); bool processWakeup(const unsigned char* data); diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 28e6d76..5295c9e 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -31,6 +31,11 @@ unsigned int CDMRSlot::m_colorCode = 0U; bool CDMRSlot::m_selfOnly = false; std::vector CDMRSlot::m_prefixes; std::vector CDMRSlot::m_blackList; +std::vector CDMRSlot::m_dstBlackListSlot1; +std::vector CDMRSlot::m_dstWhiteListSlot1; +std::vector CDMRSlot::m_dstBlackListSlot2; +std::vector CDMRSlot::m_dstWhiteListSlot2; + CModem* CDMRSlot::m_modem = NULL; CDMRIPSC* CDMRSlot::m_network = NULL; CDisplay* CDMRSlot::m_display = NULL; @@ -131,12 +136,31 @@ void CDMRSlot::writeModem(unsigned char *data) if (lc == NULL) return; - unsigned int id = lc->getSrcId(); + unsigned int id; + unsigned int did; + id = lc->getSrcId(); if (!validateId(id)) { - LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, id); + LogMessage("DMR Slot %u, invalid access attempt from %u (blacklisted)", m_slotNo, id); delete lc; return; } + // add check for valid dst id (e.g. TG) + //AKA - the BlockTheNet modification ;-) + // - G7RZU + did = lc->getDstId(); + if (!DstIdBlacklist(did,m_slotNo)) { + LogMessage("DMR Slot %u, invalid access attempt to %u (blacklisted)", m_slotNo, did); + delete lc; + return; + } + did = lc->getDstId(); + // true sets allow greater than 4k. Need to add boolean in conf for this later. + if (!DstIdWhitelist(did,m_slotNo,true)) { + LogMessage("DMR Slot %u, invalid access attempt to %u (not in whitelist)", m_slotNo, did); + delete lc; + return; + } + m_rfLC = lc; @@ -1263,7 +1287,7 @@ void CDMRSlot::writeQueueNet(const unsigned char *data) m_queue.addData(data, len); } -void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup) +void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup) { assert(id != 0U); assert(modem != NULL); @@ -1275,6 +1299,10 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, cons m_selfOnly = selfOnly; m_prefixes = prefixes; m_blackList = blackList; + m_dstBlackListSlot1 = DstIdBlacklistSlot1; + m_dstWhiteListSlot1 = DstIdWhitelistSlot1; + m_dstBlackListSlot2 = DstIdBlacklistSlot2; + m_dstWhiteListSlot2 = DstIdWhitelistSlot2; m_modem = modem; m_network = network; m_display = display; @@ -1311,6 +1339,41 @@ bool CDMRSlot::validateId(unsigned int id) } } +//is dst id blacklisted? +bool CDMRSlot::DstIdBlacklist(unsigned int did, unsigned int slot) +{ + if (slot == 1) { + if (std::find(m_dstBlackListSlot1.begin(), m_dstBlackListSlot1.end(), did) != m_dstBlackListSlot1.end()) + return false; + } else { + if (std::find(m_dstBlackListSlot2.begin(), m_dstBlackListSlot2.end(), did) != m_dstBlackListSlot2.end()) + return false; + } +} + +//is dst id whitelisted or, if ID is greater than or equal to 4000 +bool CDMRSlot::DstIdWhitelist(unsigned int did, unsigned int slot, bool gt4k) +{ + if (slot == 1) { + if(gt4k) { + if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end() || did >= 4000) + return true; + } else { + if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end()) + return true; + } + } else { + if(gt4k) { + if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end() || did >= 4000) + return true; + } else { + if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end()) + return true; + } + } +} + + void CDMRSlot::setShortLC(unsigned int slotNo, unsigned int id, FLCO flco, bool voice) { assert(m_modem != NULL); diff --git a/DMRSlot.h b/DMRSlot.h index ae368b5..96fb3bf 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -50,7 +50,7 @@ public: void clock(); - static void init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup); + static void init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, const std::vector& blackList, const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup); private: unsigned int m_slotNo; @@ -90,6 +90,11 @@ private: static bool m_selfOnly; static std::vector m_prefixes; static std::vector m_blackList; + static std::vector m_dstBlackListSlot1; + static std::vector m_dstBlackListSlot2; + static std::vector m_dstWhiteListSlot1; + static std::vector m_dstWhiteListSlot2; + static CModem* m_modem; static CDMRIPSC* m_network; static CDisplay* m_display; @@ -125,6 +130,8 @@ private: static void setShortLC(unsigned int slotNo, unsigned int id, FLCO flco = FLCO_GROUP, bool voice = true); static bool validateId(unsigned int id); + static bool DstIdBlacklist(unsigned int did,unsigned int slot); + static bool DstIdWhitelist(unsigned int did,unsigned int slot,bool gt4k); }; #endif diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 514605b..328079a 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -288,6 +288,10 @@ int CMMDVMHost::run() bool selfOnly = m_conf.getDMRSelfOnly(); std::vector prefixes = m_conf.getDMRPrefixes(); std::vector blackList = m_conf.getDMRBlackList(); + std::vector dstIDBlackListSlot1 = m_conf.getDMRDstIdBlacklistSlot1(); + std::vector dstIDBlackListSlot2 = m_conf.getDMRDstIdBlacklistSlot2(); + std::vector dstIDWhiteListSlot1 = m_conf.getDMRDstIdWhitelistSlot1(); + std::vector dstIDWhiteListSlot2 = m_conf.getDMRDstIdWhitelistSlot2(); unsigned int timeout = m_conf.getTimeout(); std::string lookupFile = m_conf.getDMRLookupFile(); unsigned int txHang = m_conf.getDMRTXHang(); @@ -303,7 +307,7 @@ int CMMDVMHost::run() LogInfo(" Lookup File: %s", lookupFile.length() > 0U ? lookupFile.c_str() : "None"); LogInfo(" TX Hang: %us", txHang); - dmr = new CDMRControl(id, colorCode, selfOnly, prefixes, blackList, timeout, m_modem, m_dmrNetwork, m_display, m_duplex, lookupFile); + dmr = new CDMRControl(id, colorCode, selfOnly, prefixes, blackList,dstIDBlackListSlot1,dstIDWhiteListSlot1, dstIDBlackListSlot2, dstIDWhiteListSlot2, timeout, m_modem, m_dmrNetwork, m_display, m_duplex, lookupFile); m_dmrTXTimer.setTimeout(txHang); }