Skip to content

Commit

Permalink
Added blacklist and whitelist for TGs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacknix committed Jun 7, 2016
1 parent daafbf6 commit ff4bd9f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DMRControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <cassert>
#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_colorCode(colorCode),
m_selfOnly(selfOnly),
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion DMRControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class CDMRControl {
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();

bool processWakeup(const unsigned char* data);
Expand Down
69 changes: 66 additions & 3 deletions DMRSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ unsigned int CDMRSlot::m_colorCode = 0U;
bool CDMRSlot::m_selfOnly = false;
std::vector<unsigned int> CDMRSlot::m_prefixes;
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;
CDMRIPSC* CDMRSlot::m_network = NULL;
CDisplay* CDMRSlot::m_display = NULL;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<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(modem != NULL);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion DMRSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CDMRSlot {

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:
unsigned int m_slotNo;
Expand Down Expand Up @@ -90,6 +90,11 @@ class CDMRSlot {
static bool m_selfOnly;
static std::vector<unsigned int> m_prefixes;
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 CDMRIPSC* m_network;
static CDisplay* m_display;
Expand Down Expand Up @@ -125,6 +130,8 @@ class CDMRSlot {

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
6 changes: 5 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ int CMMDVMHost::run()
bool selfOnly = m_conf.getDMRSelfOnly();
std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes();
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();
std::string lookupFile = m_conf.getDMRLookupFile();
unsigned int txHang = m_conf.getDMRTXHang();
Expand All @@ -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);
}
Expand Down

0 comments on commit ff4bd9f

Please sign in to comment.