mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 06:55:52 +08:00
Further clean up of DMR Access Control.
This commit is contained in:
@@ -18,8 +18,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot1RF;
|
||||
@@ -32,7 +31,7 @@ std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot2NET;
|
||||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot1NET;
|
||||
std::vector<unsigned int> DMRAccessControl::m_dstWhiteListSlot2NET;
|
||||
|
||||
std::vector<unsigned int> DMRAccessControl::m_SrcIdBlacklist;
|
||||
std::vector<unsigned int> DMRAccessControl::m_srcIdBlacklist;
|
||||
|
||||
std::vector<unsigned int> DMRAccessControl::m_prefixes;
|
||||
|
||||
@@ -41,37 +40,37 @@ bool DMRAccessControl::m_selfOnly = false;
|
||||
unsigned int DMRAccessControl::m_id = 0U;
|
||||
|
||||
unsigned int DMRAccessControl::m_dstRewriteID = 0U;
|
||||
unsigned int DMRAccessControl::m_SrcID = 0U;
|
||||
unsigned int DMRAccessControl::m_srcID = 0U;
|
||||
|
||||
CDMRLC* DMRAccessControl::m_lastdmrLC;
|
||||
|
||||
std::time_t DMRAccessControl::m_time;
|
||||
time_t DMRAccessControl::m_time;
|
||||
|
||||
int DMRAccessControl::m_callHang;
|
||||
|
||||
bool DMRAccessControl::m_TGRewriteSlot1;
|
||||
bool DMRAccessControl::m_TGRewriteSlot2;
|
||||
bool DMRAccessControl::m_BMAutoRewrite;
|
||||
bool DMRAccessControl::m_BMRewriteReflectorVoicePrompts;
|
||||
bool DMRAccessControl::m_tgRewriteSlot1;
|
||||
bool DMRAccessControl::m_tgRewriteSlot2;
|
||||
bool DMRAccessControl::m_bmAutoRewrite;
|
||||
bool DMRAccessControl::m_bmRewriteReflectorVoicePrompts;
|
||||
|
||||
void DMRAccessControl::init(const std::vector<unsigned int>& DstIdBlacklistSlot1RF, const std::vector<unsigned int>& DstIdWhitelistSlot1RF, const std::vector<unsigned int>& DstIdBlacklistSlot2RF, const std::vector<unsigned int>& DstIdWhitelistSlot2RF, const std::vector<unsigned int>& DstIdBlacklistSlot1NET, const std::vector<unsigned int>& DstIdWhitelistSlot1NET, const std::vector<unsigned int>& DstIdBlacklistSlot2NET, const std::vector<unsigned int>& DstIdWhitelistSlot2NET, const std::vector<unsigned int>& SrcIdBlacklist, bool selfOnly, const std::vector<unsigned int>& prefixes,unsigned int id,unsigned int callHang,bool TGRewriteSlot1, bool TGRewriteSlot2, bool BMAutoRewrite, bool BMRewriteReflectorVoicePrompts)
|
||||
void DMRAccessControl::init(const std::vector<unsigned int>& dstIdBlacklistSlot1RF, const std::vector<unsigned int>& dstIdWhitelistSlot1RF, const std::vector<unsigned int>& dstIdBlacklistSlot2RF, const std::vector<unsigned int>& dstIdWhitelistSlot2RF, const std::vector<unsigned int>& dstIdBlacklistSlot1NET, const std::vector<unsigned int>& dstIdWhitelistSlot1NET, const std::vector<unsigned int>& dstIdBlacklistSlot2NET, const std::vector<unsigned int>& dstIdWhitelistSlot2NET, const std::vector<unsigned int>& srcIdBlacklist, bool selfOnly, const std::vector<unsigned int>& prefixes, unsigned int id, unsigned int callHang, bool tgRewriteSlot1, bool tgRewriteSlot2, bool bmAutoRewrite, bool bmRewriteReflectorVoicePrompts)
|
||||
{
|
||||
m_dstBlackListSlot1RF = DstIdBlacklistSlot1RF;
|
||||
m_dstWhiteListSlot1RF = DstIdWhitelistSlot1RF;
|
||||
m_dstBlackListSlot2RF = DstIdBlacklistSlot2RF;
|
||||
m_dstWhiteListSlot2RF = DstIdWhitelistSlot2RF;
|
||||
m_dstBlackListSlot1NET = DstIdBlacklistSlot1NET;
|
||||
m_dstWhiteListSlot1NET = DstIdWhitelistSlot1NET;
|
||||
m_dstBlackListSlot2NET = DstIdBlacklistSlot2NET;
|
||||
m_dstWhiteListSlot2NET = DstIdWhitelistSlot2NET;
|
||||
m_callHang = callHang;
|
||||
m_TGRewriteSlot1 = TGRewriteSlot1;
|
||||
m_TGRewriteSlot2 = TGRewriteSlot2;
|
||||
m_BMAutoRewrite = BMAutoRewrite;
|
||||
m_BMRewriteReflectorVoicePrompts = BMRewriteReflectorVoicePrompts;
|
||||
m_dstBlackListSlot1RF = dstIdBlacklistSlot1RF;
|
||||
m_dstWhiteListSlot1RF = dstIdWhitelistSlot1RF;
|
||||
m_dstBlackListSlot2RF = dstIdBlacklistSlot2RF;
|
||||
m_dstWhiteListSlot2RF = dstIdWhitelistSlot2RF;
|
||||
m_dstBlackListSlot1NET = dstIdBlacklistSlot1NET;
|
||||
m_dstWhiteListSlot1NET = dstIdWhitelistSlot1NET;
|
||||
m_dstBlackListSlot2NET = dstIdBlacklistSlot2NET;
|
||||
m_dstWhiteListSlot2NET = dstIdWhitelistSlot2NET;
|
||||
m_callHang = callHang;
|
||||
m_tgRewriteSlot1 = tgRewriteSlot1;
|
||||
m_tgRewriteSlot2 = tgRewriteSlot2;
|
||||
m_bmAutoRewrite = bmAutoRewrite;
|
||||
m_bmRewriteReflectorVoicePrompts = bmRewriteReflectorVoicePrompts;
|
||||
}
|
||||
|
||||
bool DMRAccessControl::DstIdBlacklist(unsigned int did, unsigned int slot, bool network)
|
||||
bool DMRAccessControl::dstIdBlacklist(unsigned int did, unsigned int slot, bool network)
|
||||
{
|
||||
static std::vector<unsigned int> blacklist;
|
||||
|
||||
@@ -90,7 +89,7 @@ bool DMRAccessControl::DstIdBlacklist(unsigned int did, unsigned int slot, bool
|
||||
return std::find(blacklist.begin(), blacklist.end(), did) != blacklist.end();
|
||||
}
|
||||
|
||||
bool DMRAccessControl::DstIdWhitelist(unsigned int did, unsigned int slot, bool gt4k, bool network)
|
||||
bool DMRAccessControl::dstIdWhitelist(unsigned int did, unsigned int slot, bool gt4k, bool network)
|
||||
{
|
||||
if (network) {
|
||||
if (slot == 1U) {
|
||||
@@ -151,7 +150,7 @@ bool DMRAccessControl::DstIdWhitelist(unsigned int did, unsigned int slot, bool
|
||||
if (std::find(m_dstWhiteListSlot2RF.begin(), m_dstWhiteListSlot2RF.end(), did) != m_dstWhiteListSlot2RF.end() || did == 0)
|
||||
return true;
|
||||
// If dstId in secondary TG range or whitelist
|
||||
else if (did >= 4000) {
|
||||
else if (did >= 4000U) {
|
||||
if (did > 5000U && did < 10000U)
|
||||
return false;
|
||||
else
|
||||
@@ -172,7 +171,7 @@ 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())
|
||||
if (std::find(m_srcIdBlacklist.begin(), m_srcIdBlacklist.end(), id) != m_srcIdBlacklist.end())
|
||||
return false;
|
||||
|
||||
unsigned int prefix = id / 10000U;
|
||||
@@ -186,16 +185,16 @@ bool DMRAccessControl::validateSrcId(unsigned int id)
|
||||
}
|
||||
}
|
||||
|
||||
bool DMRAccessControl::validateAccess (unsigned int src_id, unsigned int dst_id, unsigned int slot, bool network)
|
||||
bool DMRAccessControl::validateAccess(unsigned int src_id, unsigned int dst_id, unsigned int slot, bool network)
|
||||
{
|
||||
// source ID validation is only applied to RF traffic
|
||||
if (!network && !DMRAccessControl::validateSrcId(src_id)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt from %u (blacklisted)", slot, src_id);
|
||||
return false;
|
||||
} else if (DMRAccessControl::DstIdBlacklist(dst_id, slot, network)) {
|
||||
} else if (DMRAccessControl::dstIdBlacklist(dst_id, slot, network)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG blacklisted)", slot, dst_id);
|
||||
return false;
|
||||
} else if (!DMRAccessControl::DstIdWhitelist(dst_id, slot, true, network)) {
|
||||
} else if (!DMRAccessControl::dstIdWhitelist(dst_id, slot, true, network)) {
|
||||
LogMessage("DMR Slot %u, invalid access attempt to TG%u (TG not in whitelist)", slot, dst_id);
|
||||
return false;
|
||||
} else {
|
||||
@@ -203,51 +202,49 @@ bool DMRAccessControl::validateAccess (unsigned int src_id, unsigned int dst_id,
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int DMRAccessControl::DstIdRewrite (unsigned int did, unsigned int sid, unsigned int slot, bool network, CDMRLC* dmrLC)
|
||||
unsigned int DMRAccessControl::dstIdRewrite(unsigned int did, unsigned int sid, unsigned int slot, bool network, CDMRLC* dmrLC)
|
||||
{
|
||||
if (slot == 1U && !m_tgRewriteSlot1)
|
||||
return 0U;
|
||||
|
||||
if (slot == 1U && m_TGRewriteSlot1 == false)
|
||||
return 0U;
|
||||
if (slot == 2U && !m_tgRewriteSlot2)
|
||||
return 0U;
|
||||
|
||||
time_t currenttime = ::time(NULL);
|
||||
|
||||
if (slot == 2U && m_TGRewriteSlot2 == false)
|
||||
return 0U;
|
||||
|
||||
|
||||
std::time_t currenttime = std::time(nullptr);
|
||||
|
||||
if (network) {
|
||||
m_dstRewriteID = did;
|
||||
m_SrcID = sid;
|
||||
//not needed at present - for direct dial, which requires change at master end.
|
||||
//memcpy(&m_lastdmrLC, &dmrLC, sizeof(dmrLC));
|
||||
if (m_BMAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did != 9U && dmrLC->getFLCO() == FLCO_GROUP ) {
|
||||
LogMessage("DMR Slot %u, Rewrite DST ID (TG) of of inbound network traffic from %u to 9",slot,did);
|
||||
return 9U;
|
||||
// rewrite incoming BM voice prompts to TG 9
|
||||
} else if (m_BMRewriteReflectorVoicePrompts && (sid >= 4000U && sid <= 5000U) && dmrLC->getFLCO() == FLCO_USER_USER) {
|
||||
dmrLC->setFLCO(FLCO_GROUP);
|
||||
LogMessage("DMR Slot %u, Rewrite inbound private call to %u to Group Call on TG 9 (BM reflector voice prompt)",slot,did);
|
||||
return 9U;
|
||||
} else {
|
||||
return 0U;
|
||||
if (network) {
|
||||
m_dstRewriteID = did;
|
||||
m_srcID = sid;
|
||||
|
||||
//not needed at present - for direct dial, which requires change at master end.
|
||||
//memcpy(&m_lastdmrLC, &dmrLC, sizeof(dmrLC));
|
||||
if (m_bmAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did != 9U && dmrLC->getFLCO() == FLCO_GROUP ) {
|
||||
LogMessage("DMR Slot %u, Rewrite DST ID (TG) of of inbound network traffic from %u to 9",slot,did);
|
||||
return 9U;
|
||||
// rewrite incoming BM voice prompts to TG 9
|
||||
} else if (m_bmRewriteReflectorVoicePrompts && (sid >= 4000U && sid <= 5000U) && dmrLC->getFLCO() == FLCO_USER_USER) {
|
||||
dmrLC->setFLCO(FLCO_GROUP);
|
||||
LogMessage("DMR Slot %u, Rewrite inbound private call to %u to Group Call on TG 9 (BM reflector voice prompt)",slot,did);
|
||||
return 9U;
|
||||
} else {
|
||||
return 0U;
|
||||
}
|
||||
} else if (m_bmAutoRewrite && did == 9U && m_dstRewriteID != 9U && m_dstRewriteID != 0U && (m_time + m_callHang) > currenttime && dmrLC->getFLCO() == FLCO_GROUP ) {
|
||||
LogMessage("DMR Slot %u, Rewrite DST ID (TG) of outbound network traffic from %u to %u (return traffic during CallHang)",slot,did,m_dstRewriteID);
|
||||
return m_dstRewriteID;
|
||||
} else if (m_bmAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did !=9U && did < 99999U && dmrLC->getFLCO() == FLCO_USER_USER) {
|
||||
m_dstRewriteID = did;
|
||||
dmrLC->setFLCO(FLCO_GROUP);
|
||||
LogMessage("DMR Slot %u, Rewrite outbound private call to %u Group Call (Connect talkgroup by private call)",slot,did);
|
||||
return did;
|
||||
} else if (m_bmAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did !=9U && did > 99999U) {
|
||||
m_dstRewriteID = did;
|
||||
}
|
||||
} else if (m_BMAutoRewrite && did == 9U && m_dstRewriteID != 9U && m_dstRewriteID != 0U && (m_time + m_callHang) > currenttime && dmrLC->getFLCO() == FLCO_GROUP ) {
|
||||
LogMessage("DMR Slot %u, Rewrite DST ID (TG) of outbound network traffic from %u to %u (return traffic during CallHang)",slot,did,m_dstRewriteID);
|
||||
return(m_dstRewriteID);
|
||||
|
||||
} else if (m_BMAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did !=9U && did < 99999U && dmrLC->getFLCO() == FLCO_USER_USER) {
|
||||
m_dstRewriteID = did;
|
||||
dmrLC->setFLCO(FLCO_GROUP);
|
||||
LogMessage("DMR Slot %u, Rewrite outbound private call to %u Group Call (Connect talkgroup by private call)",slot,did);
|
||||
return did;
|
||||
} else if (m_BMAutoRewrite && (did < 4000U || did > 5000U) && did > 0U && did !=9U && did > 99999U) {
|
||||
m_dstRewriteID = did;
|
||||
}
|
||||
return 0U;
|
||||
return 0U;
|
||||
}
|
||||
|
||||
|
||||
void DMRAccessControl::setOverEndTime()
|
||||
{
|
||||
m_time = std::time(nullptr);
|
||||
}
|
||||
m_time = ::time(NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user