Move DMR Access Control to new class.
This commit is contained in:
parent
66415e004e
commit
f313615708
|
@ -23,7 +23,13 @@ std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot2;
|
|||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot1;
|
||||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot2;
|
||||
|
||||
void DMRAccessControl::init(const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2)
|
||||
std::vector<unsigned int> DMRAccessControl::m_SrcIdBlacklist;
|
||||
|
||||
std::vector<unsigned int> DMRAccessControl::m_prefixes;
|
||||
bool DMRAccessControl::m_selfOnly;
|
||||
unsigned int DMRAccessControl::m_id;
|
||||
|
||||
void DMRAccessControl::init(const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, const std::vector<unsigned int>& SrcIdBlacklist, bool selfOnly, const std::vector<unsigned int>& prefixes,unsigned int id)
|
||||
{
|
||||
|
||||
m_dstBlackListSlot1 = DstIdBlacklistSlot1;
|
||||
|
@ -84,3 +90,22 @@ bool DMRAccessControl::DstIdWhitelist(unsigned int did, unsigned int slot, bool
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DMRAccessControl::validateSrcId(unsigned int id)
|
||||
{
|
||||
if (m_selfOnly) {
|
||||
return id == m_id;
|
||||
} else {
|
||||
if (std::find(m_SrcIdBlacklist.begin(), m_SrcIdBlacklist.end(), id) != m_SrcIdBlacklist.end())
|
||||
return false;
|
||||
|
||||
unsigned int prefix = id / 10000U;
|
||||
if (prefix == 0U || prefix > 999U)
|
||||
return false;
|
||||
|
||||
if (m_prefixes.size() == 0U)
|
||||
return true;
|
||||
|
||||
return std::find(m_prefixes.begin(), m_prefixes.end(), prefix) != m_prefixes.end();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ 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<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2);
|
||||
static bool validateSrcId(unsigned int id);
|
||||
|
||||
static void init(const std::vector<unsigned int>& DstIdBlacklistSlot1, const std::vector<unsigned int>& DstIdWhitelistSlot1, const std::vector<unsigned int>& DstIdBlacklistSlot2, const std::vector<unsigned int>& DstIdWhitelistSlot2, const std::vector<unsigned int>& SrcIdBlacklist, bool selfOnly, const std::vector<unsigned int>& prefixes,unsigned int id);
|
||||
|
||||
|
||||
|
||||
|
@ -31,6 +33,13 @@ private:
|
|||
static std::vector<unsigned int> m_dstBlackListSlot2;
|
||||
static std::vector<unsigned int> m_dstWhiteListSlot1;
|
||||
static std::vector<unsigned int> m_dstWhiteListSlot2;
|
||||
|
||||
static std::vector<unsigned int> m_SrcIdBlacklist;
|
||||
|
||||
static std::vector<unsigned int> m_prefixes;
|
||||
|
||||
static bool m_selfOnly;
|
||||
static unsigned int m_id;
|
||||
|
||||
|
||||
|
||||
|
|
33
DMRSlot.cpp
33
DMRSlot.cpp
|
@ -140,7 +140,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||
return;
|
||||
|
||||
unsigned int id = lc->getSrcId();
|
||||
if (!validateId(id)) {
|
||||
if (!DMRAccessControl::validateSrcId(id)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt from %u (blacklisted)", m_slotNo, id);
|
||||
delete lc;
|
||||
return;
|
||||
|
@ -273,7 +273,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||
unsigned int srcId = dataHeader.getSrcId();
|
||||
unsigned int dstId = dataHeader.getDstId();
|
||||
|
||||
if (!validateId(srcId)) {
|
||||
if (!DMRAccessControl::validateSrcId(srcId)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
||||
return;
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||
unsigned int srcId = csbk.getSrcId();
|
||||
unsigned int dstId = csbk.getDstId();
|
||||
|
||||
if (!validateId(srcId)) {
|
||||
if (!DMRAccessControl::validateSrcId(srcId)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
||||
return;
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||
CDMRLC* lc = m_rfEmbeddedLC.addData(data + 2U, emb.getLCSS());
|
||||
if (lc != NULL) {
|
||||
unsigned int id = lc->getSrcId();
|
||||
if (!validateId(id)) {
|
||||
if (!DMRAccessControl::validateSrcId(id)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, id);
|
||||
delete lc;
|
||||
return;
|
||||
|
@ -1456,7 +1456,7 @@ void CDMRSlot::writeQueueNet(const unsigned char *data)
|
|||
m_queue.addData(data, len);
|
||||
}
|
||||
|
||||
void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHang, 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)
|
||||
void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& SrcIdBlacklist, 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);
|
||||
|
@ -1467,7 +1467,7 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa
|
|||
m_colorCode = colorCode;
|
||||
m_selfOnly = selfOnly;
|
||||
m_prefixes = prefixes;
|
||||
m_blackList = blackList;
|
||||
// m_blackList = blackList;
|
||||
m_modem = modem;
|
||||
m_network = network;
|
||||
m_display = display;
|
||||
|
@ -1486,26 +1486,7 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa
|
|||
slotType.getData(m_idle + 2U);
|
||||
|
||||
//Load black and white lists to DMRAccessControl
|
||||
DMRAccessControl::init(DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2);
|
||||
}
|
||||
|
||||
bool CDMRSlot::validateId(unsigned int id)
|
||||
{
|
||||
if (m_selfOnly) {
|
||||
return id == m_id;
|
||||
} else {
|
||||
if (std::find(m_blackList.begin(), m_blackList.end(), id) != m_blackList.end())
|
||||
return false;
|
||||
|
||||
unsigned int prefix = id / 10000U;
|
||||
if (prefix == 0U || prefix > 999U)
|
||||
return false;
|
||||
|
||||
if (m_prefixes.size() == 0U)
|
||||
return true;
|
||||
|
||||
return std::find(m_prefixes.begin(), m_prefixes.end(), prefix) != m_prefixes.end();
|
||||
}
|
||||
DMRAccessControl::init(DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2, SrcIdBlacklist, m_selfOnly, m_prefixes, m_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue