Added TG rewrite code
This commit is contained in:
parent
bce0056101
commit
c53a96baab
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot1RF;
|
std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot1RF;
|
||||||
std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot2RF;
|
std::vector<unsigned int> DMRAccessControl::m_dstBlackListSlot2RF;
|
||||||
|
@ -37,6 +38,10 @@ bool DMRAccessControl::m_selfOnly = false;
|
||||||
|
|
||||||
unsigned int DMRAccessControl::m_id = 0U;
|
unsigned int DMRAccessControl::m_id = 0U;
|
||||||
|
|
||||||
|
unsigned int DMRAccessControl::m_dstRewriteID = 0U;
|
||||||
|
|
||||||
|
std::time_t DMRAccessControl::m_time;
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
m_dstBlackListSlot1RF = DstIdBlacklistSlot1RF;
|
m_dstBlackListSlot1RF = DstIdBlacklistSlot1RF;
|
||||||
|
@ -180,3 +185,33 @@ bool DMRAccessControl::validateAccess (unsigned int src_id, unsigned int dst_id,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int DMRAccessControl::DstIdRewrite (unsigned int id, bool network)
|
||||||
|
{
|
||||||
|
// record current time
|
||||||
|
std::time_t currenttime = std::time(nullptr);
|
||||||
|
|
||||||
|
// if the traffic is from the network
|
||||||
|
if (network) {
|
||||||
|
m_dstRewriteID = id;
|
||||||
|
// record current time
|
||||||
|
m_time = std::time(nullptr);
|
||||||
|
// if the ID is a talkgroup, log and rewrite to TG9
|
||||||
|
if (id < 4000 && id != 0) {
|
||||||
|
LogMessage("Rewrite DST ID (TG) of of inbound network traffic from %u to 9", id);
|
||||||
|
return 9;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if less than 30 seconds has passed since we last saw traffic
|
||||||
|
if (m_dstRewriteID == id && (m_time + 30) > currenttime && m_time) {
|
||||||
|
LogMessage("Inbound DST ID (TG) rewrite seen in last 30 seconds");
|
||||||
|
LogMessage("Rewrite DST ID (TG) of outbound network traffic from 9 to %u", id);
|
||||||
|
return(id);
|
||||||
|
} else {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -16,12 +16,15 @@
|
||||||
#define DMRAccessControl_H
|
#define DMRAccessControl_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
class DMRAccessControl {
|
class DMRAccessControl {
|
||||||
public:
|
public:
|
||||||
static bool validateAccess (unsigned int src_id, unsigned int dst_id, unsigned int slot, bool network);
|
static bool validateAccess (unsigned int src_id, unsigned int dst_id, unsigned int slot, bool network);
|
||||||
|
|
||||||
static void 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);
|
static void 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);
|
||||||
|
|
||||||
|
static unsigned int DstIdRewrite(unsigned int id, bool network);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<unsigned int> m_dstBlackListSlot1RF;
|
static std::vector<unsigned int> m_dstBlackListSlot1RF;
|
||||||
|
@ -45,6 +48,12 @@ private:
|
||||||
static bool DstIdWhitelist(unsigned int did,unsigned int slot,bool gt4k, bool network);
|
static bool DstIdWhitelist(unsigned int did,unsigned int slot,bool gt4k, bool network);
|
||||||
|
|
||||||
static bool validateSrcId(unsigned int id);
|
static bool validateSrcId(unsigned int id);
|
||||||
|
|
||||||
|
static std::time_t m_time;
|
||||||
|
|
||||||
|
static unsigned int m_dstRewriteID;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
16
DMRSlot.cpp
16
DMRSlot.cpp
|
@ -157,7 +157,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
|
||||||
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, false)) {
|
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, false)) {
|
||||||
delete lc;
|
delete lc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rfLC = lc;
|
m_rfLC = lc;
|
||||||
|
|
||||||
|
@ -762,6 +762,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
|
||||||
unsigned int id = m_netLC->getSrcId();
|
unsigned int id = m_netLC->getSrcId();
|
||||||
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, true))
|
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, true))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Test dst rewrite
|
||||||
|
unsigned int rw_id = DMRAccessControl::DstIdRewrite(id, true);
|
||||||
|
if (rw_id) {
|
||||||
|
LogMessage("Rewrite ID: %u", rw_id);
|
||||||
|
m_netLC->setDstId(rw_id);
|
||||||
|
}
|
||||||
|
|
||||||
// Store the LC for the embedded LC
|
// Store the LC for the embedded LC
|
||||||
m_netEmbeddedLC.setData(*m_netLC);
|
m_netEmbeddedLC.setData(*m_netLC);
|
||||||
|
@ -825,6 +832,13 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
|
||||||
unsigned int id = m_netLC->getSrcId();
|
unsigned int id = m_netLC->getSrcId();
|
||||||
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, true))
|
if (!DMRAccessControl::validateAccess(id, did, m_slotNo, true))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Test dst rewrite
|
||||||
|
unsigned int rw_id = DMRAccessControl::DstIdRewrite(id,true);
|
||||||
|
if (rw_id) {
|
||||||
|
LogMessage("Rewrite ID: %u", rw_id);
|
||||||
|
m_netLC->setDstId(rw_id);
|
||||||
|
}
|
||||||
|
|
||||||
// Regenerate the Slot Type
|
// Regenerate the Slot Type
|
||||||
CDMRSlotType slotType;
|
CDMRSlotType slotType;
|
||||||
|
|
Loading…
Reference in a new issue