forked from BrandMeister/DMRHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMRAccessControl.cpp
99 lines (80 loc) · 3.12 KB
/
DMRAccessControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2016 by Simon Rune G7RZU
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
*
* 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"
#include "Log.h"
#include <algorithm>
#include <vector>
#include <cstring>
std::vector<unsigned int> CDMRAccessControl::m_blackList;
std::vector<unsigned int> CDMRAccessControl::m_whiteList;
std::vector<unsigned int> CDMRAccessControl::m_prefixes;
std::vector<unsigned int> CDMRAccessControl::m_slot1TGWhiteList;
std::vector<unsigned int> CDMRAccessControl::m_slot2TGWhiteList;
bool CDMRAccessControl::m_selfOnly = false;
unsigned int CDMRAccessControl::m_id = 0U;
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)
{
m_slot1TGWhiteList = slot1TGWhitelist;
m_slot2TGWhiteList = slot2TGWhitelist;
m_blackList = blacklist;
m_whiteList = whitelist;
m_selfOnly = selfOnly;
m_prefixes = prefixes;
m_id = id;
}
bool CDMRAccessControl::validateSrcId(unsigned int id)
{
if (m_selfOnly) {
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
else
return id == m_id;
}
if (std::find(m_blackList.begin(), m_blackList.end(), id) != m_blackList.end())
return false;
unsigned int prefix = id / 10000U;
if (prefix == 0U || prefix > 999U)
return false;
if (!m_prefixes.empty()) {
bool ret = std::find(m_prefixes.begin(), m_prefixes.end(), prefix) == m_prefixes.end();
if (ret)
return false;
}
if (!m_whiteList.empty())
return std::find(m_whiteList.begin(), m_whiteList.end(), id) != m_whiteList.end();
return true;
}
bool CDMRAccessControl::validateTGId(unsigned int slotNo, bool group, unsigned int id)
{
if (!group)
return true;
// TG0 is never valid
if (id == 0U)
return false;
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();
}
}