You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dvmhost/src/common/nxdn/acl/AccessControl.cpp

105 lines
2.5 KiB

// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Common Library
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2016 Simon Rune, G7RZU
* Copyright (C) 2016,2017 Jonathan Naylor, G4KLX
* Copyright (C) 2017,2019,2024 Bryan Biedenkapp, N2PLL
*
*/
#include "Defines.h"
#include "nxdn/acl/AccessControl.h"
using namespace nxdn::acl;
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
RadioIdLookup* AccessControl::m_ridLookup;
TalkgroupRulesLookup* AccessControl::m_tidLookup;
/* Initializes the NXDN access control. */
void AccessControl::init(RadioIdLookup* ridLookup, TalkgroupRulesLookup* tidLookup)
{
m_ridLookup = ridLookup;
m_tidLookup = tidLookup;
}
/* Helper to validate a source radio ID. */
bool AccessControl::validateSrcId(uint32_t id)
{
// check if RID ACLs are enabled
if (!m_ridLookup->getACL()) {
RadioId rid = m_ridLookup->find(id);
if (!rid.radioDefault() && !rid.radioEnabled()) {
return false;
}
return true;
}
// lookup RID and perform test for validity
RadioId rid = m_ridLookup->find(id);
if (!rid.radioEnabled())
return false;
return true;
}
/* Helper to validate a talkgroup ID. */
bool AccessControl::validateTGId(uint32_t id)
{
// TG0 is never valid
if (id == 0U)
return false;
// check if TID ACLs are enabled
if (!m_tidLookup->getACL()) {
return true;
}
// lookup TID and perform test for validity
TalkgroupRuleGroupVoice tid = m_tidLookup->find(id);
if (tid.isInvalid())
return false;
if (!tid.config().active())
return false;
return true;
}
/* Validates whether a radio ID is admitted to a talkgroup. */
bool AccessControl::validateTGAccess(uint32_t srcId, uint32_t dstId)
{
return m_tidLookup->isRIDPermitted(dstId, 0U, srcId);
}
/* Helper to determine if a talkgroup ID is non-preferred. */
bool AccessControl::tgidNonPreferred(uint32_t id)
{
// TG0 is never valid
if (id == 0U)
return false;
// check if TID ACLs are enabled
if (!m_tidLookup->getACL()) {
return false;
}
// lookup TID and perform test for validity
TalkgroupRuleGroupVoice tid = m_tidLookup->find(id);
if (tid.config().nonPreferred())
return true;
return false;
}

Powered by TurnKey Linux.