mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 06:55:52 +08:00
Move DMR Access Control to new class.
This commit is contained in:
@@ -23,7 +23,13 @@ std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot2;
|
|||||||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot1;
|
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot1;
|
||||||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot2;
|
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;
|
m_dstBlackListSlot1 = DstIdBlacklistSlot1;
|
||||||
@@ -84,3 +90,22 @@ bool DMRAccessControl::DstIdWhitelist(unsigned int did, unsigned int slot, bool
|
|||||||
|
|
||||||
return false;
|
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 DstIdBlacklist(unsigned int did,unsigned int slot);
|
||||||
static bool DstIdWhitelist(unsigned int did,unsigned int slot,bool gt4k);
|
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_dstBlackListSlot2;
|
||||||
static std::vector<unsigned int> m_dstWhiteListSlot1;
|
static std::vector<unsigned int> m_dstWhiteListSlot1;
|
||||||
static std::vector<unsigned int> m_dstWhiteListSlot2;
|
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;
|
return;
|
||||||
|
|
||||||
unsigned int id = lc->getSrcId();
|
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);
|
LogMessage("DMR Slot %u, invalid access attempt from %u (blacklisted)", m_slotNo, id);
|
||||||
delete lc;
|
delete lc;
|
||||||
return;
|
return;
|
||||||
@@ -273,7 +273,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||||||
unsigned int srcId = dataHeader.getSrcId();
|
unsigned int srcId = dataHeader.getSrcId();
|
||||||
unsigned int dstId = dataHeader.getDstId();
|
unsigned int dstId = dataHeader.getDstId();
|
||||||
|
|
||||||
if (!validateId(srcId)) {
|
if (!DMRAccessControl::validateSrcId(srcId)) {
|
||||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -344,7 +344,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||||||
unsigned int srcId = csbk.getSrcId();
|
unsigned int srcId = csbk.getSrcId();
|
||||||
unsigned int dstId = csbk.getDstId();
|
unsigned int dstId = csbk.getDstId();
|
||||||
|
|
||||||
if (!validateId(srcId)) {
|
if (!DMRAccessControl::validateSrcId(srcId)) {
|
||||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, srcId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -511,7 +511,7 @@ void CDMRSlot::writeModem(unsigned char *data)
|
|||||||
CDMRLC* lc = m_rfEmbeddedLC.addData(data + 2U, emb.getLCSS());
|
CDMRLC* lc = m_rfEmbeddedLC.addData(data + 2U, emb.getLCSS());
|
||||||
if (lc != NULL) {
|
if (lc != NULL) {
|
||||||
unsigned int id = lc->getSrcId();
|
unsigned int id = lc->getSrcId();
|
||||||
if (!validateId(id)) {
|
if (!DMRAccessControl::validateSrcId(id)) {
|
||||||
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, id);
|
LogMessage("DMR Slot %u, invalid access attempt from %u", m_slotNo, id);
|
||||||
delete lc;
|
delete lc;
|
||||||
return;
|
return;
|
||||||
@@ -1456,7 +1456,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, 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(id != 0U);
|
||||||
assert(modem != NULL);
|
assert(modem != NULL);
|
||||||
@@ -1467,7 +1467,7 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa
|
|||||||
m_colorCode = colorCode;
|
m_colorCode = colorCode;
|
||||||
m_selfOnly = selfOnly;
|
m_selfOnly = selfOnly;
|
||||||
m_prefixes = prefixes;
|
m_prefixes = prefixes;
|
||||||
m_blackList = blackList;
|
// m_blackList = blackList;
|
||||||
m_modem = modem;
|
m_modem = modem;
|
||||||
m_network = network;
|
m_network = network;
|
||||||
m_display = display;
|
m_display = display;
|
||||||
@@ -1486,26 +1486,7 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, unsigned int callHa
|
|||||||
slotType.getData(m_idle + 2U);
|
slotType.getData(m_idle + 2U);
|
||||||
|
|
||||||
//Load black and white lists to DMRAccessControl
|
//Load black and white lists to DMRAccessControl
|
||||||
DMRAccessControl::init(DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2);
|
DMRAccessControl::init(DstIdBlacklistSlot1, DstIdWhitelistSlot1, DstIdBlacklistSlot2, DstIdWhitelistSlot2, SrcIdBlacklist, m_selfOnly, m_prefixes, m_id);
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user