diff --git a/DMRAccessControl.cpp b/DMRAccessControl.cpp new file mode 100644 index 0000000..73499b0 --- /dev/null +++ b/DMRAccessControl.cpp @@ -0,0 +1,86 @@ +/* + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + */ + +#include "DMRAccessControl.h" + +#include +#include + +std::vector DMRAccessControl::m_dstBlackListSlot1; +std::vector DMRAccessControl::m_dstBlackListSlot2; +std::vector DMRAccessControl::m_dstWhiteListSlot1; +std::vector DMRAccessControl::m_dstWhiteListSlot2; + +void DMRAccessControl::init(const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2) +{ + + m_dstBlackListSlot1 = DstIdBlacklistSlot1; + m_dstWhiteListSlot1 = DstIdWhitelistSlot1; + m_dstBlackListSlot2 = DstIdBlacklistSlot2; + m_dstWhiteListSlot2 = DstIdWhitelistSlot2; +} + +bool DMRAccessControl::DstIdBlacklist(unsigned int did, unsigned int slot) +{ + if (slot == 1U) { + if (std::find(m_dstBlackListSlot1.begin(), m_dstBlackListSlot1.end(), did) != m_dstBlackListSlot1.end()) + return true; + } else { + if (std::find(m_dstBlackListSlot2.begin(), m_dstBlackListSlot2.end(), did) != m_dstBlackListSlot2.end()) + return true; + } + + return false; +} + +bool DMRAccessControl::DstIdWhitelist(unsigned int did, unsigned int slot, bool gt4k) +{ + if (slot == 1U) { + if (m_dstWhiteListSlot1.size() == 0U) + return true; + + // No reflectors on slot1, so we only allow all IDs over 99999 unless specifically whitelisted. + //Allow traffic to TG0 as I think this is a special case - need to confirm + if (gt4k) { + if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end() || did >= 99999U || did == 0) + return true; + } else { + if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end() || did == 0) + return true; + } + } else { + if (m_dstWhiteListSlot2.size() == 0U) + return true; + + //On slot2 we allow reflector control IDs, but not secondary TG IDs unless specifically listed. Also allow echo. + if (gt4k) { + if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end() || did == 0) + return true; + + //if dstId in secondary TG range or whitelist + else if (did >= 4000) { + if (did > 5000U && did < 10000U) + return false; + else + return true; + } + } else { + if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end()) + return true; + } + } + + return false; +} diff --git a/DMRAccessControl.h b/DMRAccessControl.h new file mode 100644 index 0000000..9a3cabe --- /dev/null +++ b/DMRAccessControl.h @@ -0,0 +1,39 @@ +/* + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + */ +#if !defined(DMRAccessControl_H) +#define DMRAccessControl_H + +#include + +class DMRAccessControl { +public: + static bool DstIdBlacklist(unsigned int did,unsigned int slot); + static bool DstIdWhitelist(unsigned int did,unsigned int slot,bool gt4k); + + static void init(const std::vector& DstIdBlacklistSlot1, const std::vector& DstIdWhitelistSlot1, const std::vector& DstIdBlacklistSlot2, const std::vector& DstIdWhitelistSlot2); + + + +private: + static std::vector m_dstBlackListSlot1; + static std::vector m_dstBlackListSlot2; + static std::vector m_dstWhiteListSlot1; + static std::vector m_dstWhiteListSlot2; + + + +}; + +#endif \ No newline at end of file diff --git a/DMRSlot.cpp b/DMRSlot.cpp index bcff87a..67fa024 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -22,6 +22,7 @@ #include "Sync.h" #include "CRC.h" #include "Log.h" +#include "DMRAccessControl.h" #include #include @@ -32,11 +33,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_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; @@ -148,14 +149,14 @@ void CDMRSlot::writeModem(unsigned char *data) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = lc->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG blacklisted)", m_slotNo, did); delete lc; return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG not in whitelist)", m_slotNo, did); delete lc; return; @@ -279,13 +280,13 @@ void CDMRSlot::writeModem(unsigned char *data) // add check for valid dst id (e.g. TG) // - G7RZU - if (DstIdBlacklist(dstId, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(dstId, m_slotNo)) { LogMessage("DMR Slot %u, invalid access attempt to TG %u (TG blacklisted)", m_slotNo, dstId); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(dstId, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(dstId, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid access attempt to TG %u (TG not in whitelist)", m_slotNo, dstId); return; } @@ -350,13 +351,13 @@ void CDMRSlot::writeModem(unsigned char *data) // add check for valid dst id (e.g. TG) // - G7RZU - if (DstIdBlacklist(dstId, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(dstId, m_slotNo)) { LogMessage("DMR Slot %u, invalid access attempt to TG %u (TG blacklisted)", m_slotNo, dstId); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(dstId, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(dstId, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid access attempt to TG %u (TG not in whitelist)", m_slotNo, dstId); return; } @@ -519,14 +520,14 @@ void CDMRSlot::writeModem(unsigned char *data) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = lc->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG blacklisted)", m_slotNo, did); delete lc; return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG not in whitelist)", m_slotNo, did); delete lc; return; @@ -807,13 +808,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = m_netLC->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -879,13 +880,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = m_netLC->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -920,14 +921,14 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = m_netLC->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); writeEndNet(); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); writeEndNet(); return; @@ -989,13 +990,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = dataHeader.getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -1043,13 +1044,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = dmrData.getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -1150,13 +1151,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = m_netLC->getDstId(); - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -1221,13 +1222,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // add check for valid dst id (e.g. TG) // - G7RZU unsigned int did = dstId; - if (DstIdBlacklist(did, m_slotNo)) { + if (DMRAccessControl::DstIdBlacklist(did, m_slotNo)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG blacklisted)", m_slotNo, did); return; } // true sets allow greater than 4k. Need to add boolean in conf for this later. - if (!DstIdWhitelist(did, m_slotNo, true)) { + if (!DMRAccessControl::DstIdWhitelist(did, m_slotNo, true)) { LogMessage("DMR Slot %u, invalid traffic to TG%u (TG not in whitelist)", m_slotNo, did); return; } @@ -1467,10 +1468,6 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa 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; @@ -1487,6 +1484,9 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa slotType.setColorCode(colorCode); slotType.setDataType(DT_IDLE); slotType.getData(m_idle + 2U); + + //Load black and white lists to DMRAccessControl + DMRAccessControl::init(DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2); } bool CDMRSlot::validateId(unsigned int id) @@ -1508,59 +1508,6 @@ bool CDMRSlot::validateId(unsigned int id) } } -//is dst id blacklisted? -bool CDMRSlot::DstIdBlacklist(unsigned int did, unsigned int slot) -{ - if (slot == 1U) { - if (std::find(m_dstBlackListSlot1.begin(), m_dstBlackListSlot1.end(), did) != m_dstBlackListSlot1.end()) - return true; - } else { - if (std::find(m_dstBlackListSlot2.begin(), m_dstBlackListSlot2.end(), did) != m_dstBlackListSlot2.end()) - return true; - } - - return false; -} - -bool CDMRSlot::DstIdWhitelist(unsigned int did, unsigned int slot, bool gt4k) -{ - if (slot == 1U) { - if (m_dstWhiteListSlot1.size() == 0U) - return true; - - // No reflectors on slot1, so we only allow all IDs over 99999 unless specifically whitelisted. - //Allow traffic to TG0 as I think this is a special case - need to confirm - if (gt4k) { - if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end() || did >= 99999U || did == 0) - return true; - } else { - if (std::find(m_dstWhiteListSlot1.begin(), m_dstWhiteListSlot1.end(), did) != m_dstWhiteListSlot1.end() || did == 0) - return true; - } - } else { - if (m_dstWhiteListSlot2.size() == 0U) - return true; - - //On slot2 we allow reflector control IDs, but not secondary TG IDs unless specifically listed. Also allow echo. - if (gt4k) { - if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end() || did == 0) - return true; - - //if dstId in secondary TG range or whitelist - else if (did >= 4000) { - if (did > 5000U && did < 10000U) - return false; - else - return true; - } - } else { - if (std::find(m_dstWhiteListSlot2.begin(), m_dstWhiteListSlot2.end(), did) != m_dstWhiteListSlot2.end()) - return true; - } - } - - return false; -} void CDMRSlot::setShortLC(unsigned int slotNo, unsigned int id, FLCO flco, bool voice) { diff --git a/DMRSlot.h b/DMRSlot.h index aa363b5..e6ab014 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -90,11 +90,12 @@ 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; @@ -133,6 +134,7 @@ private: 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); + static char DMRAC; }; #endif diff --git a/Makefile b/Makefile index 64fa332..ae39487 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LDFLAGS = -g OBJECTS = \ AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \ - DMRShortLC.o DMRSlot.o DMRSlotType.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o \ + DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o \ Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \ YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o @@ -22,4 +22,4 @@ MMDVMHost: $(OBJECTS) clean: $(RM) MMDVMHost *.o *.d *.bak *~ - \ No newline at end of file +