2016-07-10 10:47:23 +00:00
|
|
|
/*
|
2016-12-22 09:42:09 +00:00
|
|
|
* Copyright (C) 2016 by Simon Rune G7RZU
|
2017-01-05 19:15:10 +00:00
|
|
|
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
|
2016-12-22 09:42:09 +00:00
|
|
|
*
|
2016-07-10 10:47:23 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DMRAccessControl.h"
|
2016-07-10 16:32:00 +00:00
|
|
|
#include "Log.h"
|
2016-07-10 10:47:23 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2016-10-13 16:46:02 +00:00
|
|
|
#include <cstring>
|
2016-07-10 10:47:23 +00:00
|
|
|
|
2016-12-21 19:06:29 +00:00
|
|
|
std::vector<unsigned int> CDMRAccessControl::m_blackList;
|
|
|
|
std::vector<unsigned int> CDMRAccessControl::m_whiteList;
|
2016-07-10 15:46:02 +00:00
|
|
|
|
2016-11-10 18:43:54 +00:00
|
|
|
std::vector<unsigned int> CDMRAccessControl::m_prefixes;
|
2016-07-11 16:41:53 +00:00
|
|
|
|
2017-01-05 19:15:10 +00:00
|
|
|
std::vector<unsigned int> CDMRAccessControl::m_slot1TGWhiteList;
|
|
|
|
std::vector<unsigned int> CDMRAccessControl::m_slot2TGWhiteList;
|
|
|
|
|
2016-11-10 18:43:54 +00:00
|
|
|
bool CDMRAccessControl::m_selfOnly = false;
|
2016-07-11 16:41:53 +00:00
|
|
|
|
2016-11-10 18:43:54 +00:00
|
|
|
unsigned int CDMRAccessControl::m_id = 0U;
|
2016-07-10 15:46:02 +00:00
|
|
|
|
2017-01-05 19:15:10 +00:00
|
|
|
void CDMRAccessControl::init(const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, bool selfOnly, const std::vector<unsigned int>& prefixes, unsigned int id)
|
2016-07-10 10:47:23 +00:00
|
|
|
{
|
2017-01-05 19:15:10 +00:00
|
|
|
m_slot1TGWhiteList = slot1TGWhitelist;
|
|
|
|
m_slot2TGWhiteList = slot2TGWhitelist;
|
|
|
|
m_blackList = blacklist;
|
|
|
|
m_whiteList = whitelist;
|
|
|
|
m_selfOnly = selfOnly;
|
|
|
|
m_prefixes = prefixes;
|
|
|
|
m_id = id;
|
2016-07-10 10:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 19:15:10 +00:00
|
|
|
bool CDMRAccessControl::validateSrcId(unsigned int id)
|
2016-07-10 15:46:02 +00:00
|
|
|
{
|
2017-07-09 13:37:27 +00:00
|
|
|
if (m_selfOnly) {
|
2017-07-16 18:31:27 +00:00
|
|
|
if (m_id > 99999999U) // Check that the Config DMR-ID is bigger than 8 digits
|
|
|
|
return id == m_id / 100U; // Does RF ID match Config ID / 100
|
|
|
|
else if (m_id > 9999999U) // Check that the Config DMR-ID is bigger than 7 digits
|
|
|
|
return id == m_id / 10U; // Does RF ID match Config ID / 10
|
2017-07-10 18:38:47 +00:00
|
|
|
else
|
|
|
|
return id == m_id;
|
2017-07-09 13:37:27 +00:00
|
|
|
}
|
2016-07-10 15:46:02 +00:00
|
|
|
|
2016-12-22 09:14:39 +00:00
|
|
|
if (std::find(m_blackList.begin(), m_blackList.end(), id) != m_blackList.end())
|
|
|
|
return false;
|
2016-07-10 15:46:02 +00:00
|
|
|
|
2016-12-22 09:14:39 +00:00
|
|
|
unsigned int prefix = id / 10000U;
|
|
|
|
if (prefix == 0U || prefix > 999U)
|
|
|
|
return false;
|
2016-07-10 16:32:00 +00:00
|
|
|
|
2016-12-22 09:14:39 +00:00
|
|
|
if (!m_prefixes.empty()) {
|
|
|
|
bool ret = std::find(m_prefixes.begin(), m_prefixes.end(), prefix) == m_prefixes.end();
|
|
|
|
if (ret)
|
|
|
|
return false;
|
2016-07-11 16:41:53 +00:00
|
|
|
}
|
2016-12-22 09:14:39 +00:00
|
|
|
|
|
|
|
if (!m_whiteList.empty())
|
|
|
|
return std::find(m_whiteList.begin(), m_whiteList.end(), id) != m_whiteList.end();
|
|
|
|
|
|
|
|
return true;
|
2016-07-10 16:32:00 +00:00
|
|
|
}
|
2017-01-05 19:15:10 +00:00
|
|
|
|
|
|
|
bool CDMRAccessControl::validateTGId(unsigned int slotNo, bool group, unsigned int id)
|
|
|
|
{
|
|
|
|
if (!group)
|
|
|
|
return true;
|
|
|
|
|
2017-01-23 09:57:45 +00:00
|
|
|
// TG0 is never valid
|
|
|
|
if (id == 0U)
|
|
|
|
return false;
|
|
|
|
|
2017-01-05 19:15:10 +00:00
|
|
|
if (slotNo == 1U) {
|
|
|
|
if (m_slot1TGWhiteList.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return std::find(m_slot1TGWhiteList.begin(), m_slot1TGWhiteList.end(), id) != m_slot1TGWhiteList.end();
|
|
|
|
} else {
|
|
|
|
if (m_slot2TGWhiteList.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return std::find(m_slot2TGWhiteList.begin(), m_slot2TGWhiteList.end(), id) != m_slot2TGWhiteList.end();
|
|
|
|
}
|
|
|
|
}
|