From 24b6cca30128074ccac256c4c2c86b10dfa4303e Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 1 Oct 2022 21:30:50 -0400 Subject: [PATCH] make TSCC Aloha NRand_Wait and Backoff configurable; set TSCC Aloha NRand_Wait to a resaonable value so as to not DDoS the inbound TSCC slot; mark CSBKO_RAND as "handled"; --- dmr/Control.cpp | 12 ++++++++++++ dmr/DMRDefines.h | 1 + dmr/Slot.cpp | 15 +++++++++++++++ dmr/Slot.h | 5 +++++ dmr/lc/CSBK.cpp | 3 ++- dmr/lc/CSBK.h | 2 ++ dmr/packet/ControlSignaling.cpp | 5 +++++ 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/dmr/Control.cpp b/dmr/Control.cpp index 027a9757..fde2933e 100644 --- a/dmr/Control.cpp +++ b/dmr/Control.cpp @@ -117,7 +117,15 @@ void Control::setOptions(yaml::Node& conf, uint32_t netId, uint8_t siteId, uint8 yaml::Node systemConf = conf["system"]; yaml::Node dmrProtocol = conf["protocols"]["dmr"]; + uint8_t nRandWait = (uint8_t)dmrProtocol["nRandWait"].as(dmr::DEFAULT_NRAND_WAIT); + if (nRandWait > 15U) + nRandWait = 15U; + uint8_t backOff = (uint8_t)dmrProtocol["backOff"].as(1U); + if (backOff > 15U) + backOff = 15U; + Slot::setSiteData(netId, siteId, channelId, channelNo); + Slot::setAlohaConfig(nRandWait, backOff); yaml::Node control = dmrProtocol["control"]; bool enableTSCC = control["enable"].as(false); @@ -153,6 +161,10 @@ void Control::setOptions(yaml::Node& conf, uint32_t netId, uint8_t siteId, uint8 if (printOptions) { LogInfo(" TSCC Slot: %u", m_tsccSlotNo); + if (enableTSCC) { + LogInfo(" TSCC Aloha Random Access Wait: %u", nRandWait); + LogInfo(" TSCC Aloha Backoff: %u", backOff); + } LogInfo(" Silence Threshold: %u (%.1f%%)", silenceThreshold, float(silenceThreshold) / 1.41F); } } diff --git a/dmr/DMRDefines.h b/dmr/DMRDefines.h index ef94cd9d..d53c7c95 100644 --- a/dmr/DMRDefines.h +++ b/dmr/DMRDefines.h @@ -133,6 +133,7 @@ namespace dmr const uint16_t DMR_LOGICAL_CH_ABSOLUTE = 0xFFFU; + const uint8_t DEFAULT_NRAND_WAIT = 8U; const uint32_t DEFAULT_SILENCE_THRESHOLD = 21U; const uint32_t MAX_DMR_VOICE_ERRORS = 141U; diff --git a/dmr/Slot.cpp b/dmr/Slot.cpp index 50546780..07c0b786 100644 --- a/dmr/Slot.cpp +++ b/dmr/Slot.cpp @@ -91,6 +91,9 @@ bool Slot::m_voice2 = true; uint16_t Slot::m_tsccCnt = 0U; +uint8_t Slot::m_alohaNRandWait = DEFAULT_NRAND_WAIT; +uint8_t Slot::m_alohaBackOff = 1U; + // --------------------------------------------------------------------------- // Public Class Members // --------------------------------------------------------------------------- @@ -623,6 +626,7 @@ void Slot::init(uint32_t colorCode, SiteData siteData, bool embeddedLCOnly, bool /// DMR Site ID. /// Channel ID. /// Channel Number. +/// void Slot::setSiteData(uint32_t netId, uint8_t siteId, uint8_t channelId, uint32_t channelNo) { m_siteData = SiteData(SITE_MODEL_SMALL, netId, siteId, 3U, true); @@ -638,6 +642,17 @@ void Slot::setSiteData(uint32_t netId, uint8_t siteId, uint8_t channelId, uint32 } } +/// +/// Sets TSCC Aloha configuration. +/// +/// +/// +void Slot::setAlohaConfig(uint8_t nRandWait, uint8_t backOff) +{ + m_alohaNRandWait = nRandWait; + m_alohaBackOff = backOff; +} + // --------------------------------------------------------------------------- // Private Class Members // --------------------------------------------------------------------------- diff --git a/dmr/Slot.h b/dmr/Slot.h index 45481cd3..5b2f9176 100644 --- a/dmr/Slot.h +++ b/dmr/Slot.h @@ -109,6 +109,8 @@ namespace dmr lookups::IdenTableLookup* idenTable, lookups::RSSIInterpolator* rssiMapper, uint32_t jitter); /// Sets local configured site data. static void setSiteData(uint32_t netId, uint8_t siteId, uint8_t channelId, uint32_t channelNo); + /// Sets TSCC Aloha configuration. + static void setAlohaConfig(uint8_t nRandWait, uint8_t backOff); private: friend class Control; @@ -220,6 +222,9 @@ namespace dmr static uint16_t m_tsccCnt; + static uint8_t m_alohaNRandWait; + static uint8_t m_alohaBackOff; + /// Add data frame to the data ring buffer. void addFrame(const uint8_t* data, bool net = false); diff --git a/dmr/lc/CSBK.cpp b/dmr/lc/CSBK.cpp index 4074364a..d4aa6e9e 100644 --- a/dmr/lc/CSBK.cpp +++ b/dmr/lc/CSBK.cpp @@ -261,7 +261,7 @@ void CSBK::encode(uint8_t* data) csbkValue = (csbkValue << 1) + ((m_siteData.netActive()) ? 1U : 0U); // Site Networked csbkValue = (csbkValue << 5) + (m_alohaMask & 0x1FU); // MS Mask csbkValue = (csbkValue << 2) + 0U; // Service Function - csbkValue = (csbkValue << 4) + 0U; // + csbkValue = (csbkValue << 4) + (m_nRandWait & 0x0FU); // Random Access Wait csbkValue = (csbkValue << 1) + ((m_siteData.requireReg()) ? 1U : 0U); // Require Registration csbkValue = (csbkValue << 4) + (m_backoffNo & 0x0FU); // Backoff Number csbkValue = (csbkValue << 16) + m_siteData.systemIdentity(); // Site Identity @@ -463,6 +463,7 @@ CSBK::CSBK(SiteData siteData) : m_priority(0U), m_broadcast(false), m_backoffNo(1U), + m_nRandWait(DEFAULT_NRAND_WAIT), m_serviceData(0U), m_serviceType(0U), m_targetAddress(TGT_ADRS_TGID), diff --git a/dmr/lc/CSBK.h b/dmr/lc/CSBK.h index 069ad9e2..8a6ac1c2 100644 --- a/dmr/lc/CSBK.h +++ b/dmr/lc/CSBK.h @@ -108,6 +108,8 @@ namespace dmr /** Tier III */ /// Backoff Number. __PROPERTY(uint8_t, backoffNo, BackoffNo); + /// Random Access Wait Delay. + __PROPERTY(uint8_t, nRandWait, NRandWait); /// Service Data. __PROPERTY(uint8_t, serviceData, ServiceData); diff --git a/dmr/packet/ControlSignaling.cpp b/dmr/packet/ControlSignaling.cpp index b3e25139..3d3b8265 100644 --- a/dmr/packet/ControlSignaling.cpp +++ b/dmr/packet/ControlSignaling.cpp @@ -146,6 +146,8 @@ bool ControlSignaling::process(uint8_t* data, uint32_t len) ::ActivityLog("DMR", true, "Slot %u call alert request from %u to %u", m_slot->m_slotNo, srcId, dstId); } else { + handled = true; + if (m_verbose) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_RAND (Random Access), emerg = %u, prio = %u, serviceType = %02X, serviceData = %02X, srcId = %u, dstId = %u", m_slot->m_slotNo, csbk.getEmergency(), csbk.getPriority(), csbk.getServiceType(), csbk.getServiceData(), csbk.getSrcId(), csbk.getDstId()); @@ -557,6 +559,9 @@ void ControlSignaling::writeRF_TSCC_Aloha() csbk.setCSBKO(CSBKO_ALOHA); csbk.setFID(FID_ETSI); + csbk.setNRandWait(m_slot->m_alohaNRandWait); + csbk.setBackoffNo(m_slot->m_alohaBackOff); + // Regenerate the CSBK data csbk.encode(data + 2U);