Added blacklist and whitelist for TGs

This commit is contained in:
Simon 2016-06-07 15:34:16 +01:00
parent daafbf6d8f
commit ff4bd9f82e
5 changed files with 82 additions and 8 deletions

View file

@ -20,7 +20,7 @@
#include <cassert> #include <cassert>
#include <algorithm> #include <algorithm>
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& 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<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile) :
m_id(id), m_id(id),
m_colorCode(colorCode), m_colorCode(colorCode),
m_selfOnly(selfOnly), m_selfOnly(selfOnly),
@ -38,7 +38,7 @@ m_lookup(NULL)
m_lookup = new CDMRLookup(lookupFile); m_lookup = new CDMRLookup(lookupFile);
m_lookup->read(); 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() CDMRControl::~CDMRControl()

View file

@ -30,7 +30,7 @@
class CDMRControl { class CDMRControl {
public: public:
CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& 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<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, unsigned int timeout, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, const std::string& lookupFile);
~CDMRControl(); ~CDMRControl();
bool processWakeup(const unsigned char* data); bool processWakeup(const unsigned char* data);

View file

@ -31,6 +31,11 @@ unsigned int CDMRSlot::m_colorCode = 0U;
bool CDMRSlot::m_selfOnly = false; bool CDMRSlot::m_selfOnly = false;
std::vector<unsigned int> CDMRSlot::m_prefixes; std::vector<unsigned int> CDMRSlot::m_prefixes;
std::vector<unsigned int> CDMRSlot::m_blackList; std::vector<unsigned int> CDMRSlot::m_blackList;
std::vector<unsigned int> CDMRSlot::m_dstBlackListSlot1;
std::vector<unsigned int> CDMRSlot::m_dstWhiteListSlot1;
std::vector<unsigned int> CDMRSlot::m_dstBlackListSlot2;
std::vector<unsigned int> CDMRSlot::m_dstWhiteListSlot2;
CModem* CDMRSlot::m_modem = NULL; CModem* CDMRSlot::m_modem = NULL;
CDMRIPSC* CDMRSlot::m_network = NULL; CDMRIPSC* CDMRSlot::m_network = NULL;
CDisplay* CDMRSlot::m_display = NULL; CDisplay* CDMRSlot::m_display = NULL;
@ -131,12 +136,31 @@ void CDMRSlot::writeModem(unsigned char *data)
if (lc == NULL) if (lc == NULL)
return; return;
unsigned int id = lc->getSrcId(); unsigned int id;
unsigned int did;
id = lc->getSrcId();
if (!validateId(id)) { 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; delete lc;
return; 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; m_rfLC = lc;
@ -1263,7 +1287,7 @@ void CDMRSlot::writeQueueNet(const unsigned char *data)
m_queue.addData(data, len); m_queue.addData(data, len);
} }
void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& 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<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup)
{ {
assert(id != 0U); assert(id != 0U);
assert(modem != NULL); assert(modem != NULL);
@ -1275,6 +1299,10 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, cons
m_selfOnly = selfOnly; m_selfOnly = selfOnly;
m_prefixes = prefixes; m_prefixes = prefixes;
m_blackList = blackList; m_blackList = blackList;
m_dstBlackListSlot1 = DstIdBlacklistSlot1;
m_dstWhiteListSlot1 = DstIdWhitelistSlot1;
m_dstBlackListSlot2 = DstIdBlacklistSlot2;
m_dstWhiteListSlot2 = DstIdWhitelistSlot2;
m_modem = modem; m_modem = modem;
m_network = network; m_network = network;
m_display = display; 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) void CDMRSlot::setShortLC(unsigned int slotNo, unsigned int id, FLCO flco, bool voice)
{ {
assert(m_modem != NULL); assert(m_modem != NULL);

View file

@ -50,7 +50,7 @@ public:
void clock(); void clock();
static void init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& 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<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, CModem* modem, CDMRIPSC* network, CDisplay* display, bool duplex, CDMRLookup* lookup);
private: private:
unsigned int m_slotNo; unsigned int m_slotNo;
@ -90,6 +90,11 @@ private:
static bool m_selfOnly; static bool m_selfOnly;
static std::vector<unsigned int> m_prefixes; static std::vector<unsigned int> m_prefixes;
static std::vector<unsigned int> m_blackList; static std::vector<unsigned int> m_blackList;
static std::vector<unsigned int> m_dstBlackListSlot1;
static std::vector<unsigned int> m_dstBlackListSlot2;
static std::vector<unsigned int> m_dstWhiteListSlot1;
static std::vector<unsigned int> m_dstWhiteListSlot2;
static CModem* m_modem; static CModem* m_modem;
static CDMRIPSC* m_network; static CDMRIPSC* m_network;
static CDisplay* m_display; 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 void setShortLC(unsigned int slotNo, unsigned int id, FLCO flco = FLCO_GROUP, bool voice = true);
static bool validateId(unsigned int id); 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 #endif

View file

@ -288,6 +288,10 @@ int CMMDVMHost::run()
bool selfOnly = m_conf.getDMRSelfOnly(); bool selfOnly = m_conf.getDMRSelfOnly();
std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes(); std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes();
std::vector<unsigned int> blackList = m_conf.getDMRBlackList(); std::vector<unsigned int> blackList = m_conf.getDMRBlackList();
std::vector<unsigned int> dstIDBlackListSlot1 = m_conf.getDMRDstIdBlacklistSlot1();
std::vector<unsigned int> dstIDBlackListSlot2 = m_conf.getDMRDstIdBlacklistSlot2();
std::vector<unsigned int> dstIDWhiteListSlot1 = m_conf.getDMRDstIdWhitelistSlot1();
std::vector<unsigned int> dstIDWhiteListSlot2 = m_conf.getDMRDstIdWhitelistSlot2();
unsigned int timeout = m_conf.getTimeout(); unsigned int timeout = m_conf.getTimeout();
std::string lookupFile = m_conf.getDMRLookupFile(); std::string lookupFile = m_conf.getDMRLookupFile();
unsigned int txHang = m_conf.getDMRTXHang(); 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(" Lookup File: %s", lookupFile.length() > 0U ? lookupFile.c_str() : "None");
LogInfo(" TX Hang: %us", txHang); 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); m_dmrTXTimer.setTimeout(txHang);
} }