2016-01-14 18:45:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015,2016 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DMRControl.h"
|
2016-11-10 18:43:54 +00:00
|
|
|
#include "DMRAccessControl.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "Defines.h"
|
2016-02-15 18:45:57 +00:00
|
|
|
#include "DMRCSBK.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "Log.h"
|
|
|
|
|
2016-03-07 20:21:55 +00:00
|
|
|
#include <cstdio>
|
2016-01-14 18:45:04 +00:00
|
|
|
#include <cassert>
|
2016-04-06 16:24:14 +00:00
|
|
|
#include <algorithm>
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-12-21 18:06:43 +00:00
|
|
|
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, 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, unsigned int timeout, CModem* modem, CDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, int rssiMultiplier, int rssiOffset, unsigned int jitter) :
|
2016-01-14 18:45:04 +00:00
|
|
|
m_id(id),
|
|
|
|
m_colorCode(colorCode),
|
|
|
|
m_modem(modem),
|
|
|
|
m_network(network),
|
|
|
|
m_slot1(1U, timeout),
|
2016-04-12 17:26:13 +00:00
|
|
|
m_slot2(2U, timeout),
|
2016-09-12 22:26:05 +00:00
|
|
|
m_lookup(lookup)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
2016-11-10 18:43:54 +00:00
|
|
|
assert(id != 0U);
|
2016-01-14 18:45:04 +00:00
|
|
|
assert(modem != NULL);
|
|
|
|
assert(display != NULL);
|
2016-09-12 22:26:05 +00:00
|
|
|
assert(lookup != NULL);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-11-10 18:43:54 +00:00
|
|
|
// Load black and white lists to DMRAccessControl
|
2016-12-21 18:06:43 +00:00
|
|
|
CDMRAccessControl::init(dstIdBlacklistSlot1RF, dstIdWhitelistSlot1RF, dstIdBlacklistSlot2RF, dstIdWhitelistSlot2RF, dstIdBlacklistSlot1NET, dstIdWhitelistSlot1NET, dstIdBlacklistSlot2NET, dstIdWhitelistSlot2NET, blacklist, selfOnly, prefixes, id);
|
2016-11-10 18:43:54 +00:00
|
|
|
|
|
|
|
CDMRSlot::init(colorCode, callHang, modem, network, display, duplex, m_lookup, rssiMultiplier, rssiOffset, jitter);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CDMRControl::~CDMRControl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDMRControl::processWakeup(const unsigned char* data)
|
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
// Wakeups always come in on slot 1
|
|
|
|
if (data[0U] != TAG_DATA || data[1U] != (DMR_IDLE_RX | DMR_SYNC_DATA | DT_CSBK))
|
|
|
|
return false;
|
|
|
|
|
2016-02-22 18:12:24 +00:00
|
|
|
CDMRCSBK csbk;
|
|
|
|
bool valid = csbk.put(data + 2U);
|
|
|
|
if (!valid)
|
2016-02-18 21:56:26 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
CSBKO csbko = csbk.getCSBKO();
|
|
|
|
if (csbko != CSBKO_BSDWNACT)
|
|
|
|
return false;
|
|
|
|
|
2016-04-04 16:40:05 +00:00
|
|
|
unsigned int srcId = csbk.getSrcId();
|
|
|
|
unsigned int bsId = csbk.getBSId();
|
|
|
|
|
2016-04-12 17:26:13 +00:00
|
|
|
std::string src = m_lookup->find(srcId);
|
|
|
|
|
2016-11-10 18:43:54 +00:00
|
|
|
bool ret = CDMRAccessControl::validateSrcId(srcId);
|
|
|
|
if (!ret) {
|
|
|
|
LogMessage("Invalid CSBK BS_Dwn_Act received from %s", src.c_str());
|
|
|
|
return false;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 18:03:38 +00:00
|
|
|
if (bsId == 0xFFFFFFU) {
|
2016-04-12 17:26:13 +00:00
|
|
|
LogMessage("CSBK BS_Dwn_Act for ANY received from %s", src.c_str());
|
2016-04-04 18:03:38 +00:00
|
|
|
return true;
|
|
|
|
} else if (bsId == m_id) {
|
2016-04-12 17:26:13 +00:00
|
|
|
LogMessage("CSBK BS_Dwn_Act for %u received from %s", bsId, src.c_str());
|
2016-04-04 18:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:26:18 +00:00
|
|
|
void CDMRControl::writeModemSlot1(unsigned char *data, unsigned int len)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-08-08 20:26:18 +00:00
|
|
|
m_slot1.writeModem(data, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 20:26:18 +00:00
|
|
|
void CDMRControl::writeModemSlot2(unsigned char *data, unsigned int len)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-08-08 20:26:18 +00:00
|
|
|
m_slot2.writeModem(data, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CDMRControl::readModemSlot1(unsigned char *data)
|
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return m_slot1.readModem(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CDMRControl::readModemSlot2(unsigned char *data)
|
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return m_slot2.readModem(data);
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:55:15 +00:00
|
|
|
void CDMRControl::clock()
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
|
|
|
if (m_network != NULL) {
|
|
|
|
CDMRData data;
|
|
|
|
bool ret = m_network->read(data);
|
|
|
|
if (ret) {
|
|
|
|
unsigned int slotNo = data.getSlotNo();
|
|
|
|
switch (slotNo) {
|
|
|
|
case 1U: m_slot1.writeNetwork(data); break;
|
|
|
|
case 2U: m_slot2.writeNetwork(data); break;
|
|
|
|
default: LogError("Invalid slot no %u", slotNo); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:55:15 +00:00
|
|
|
m_slot1.clock();
|
|
|
|
m_slot2.clock();
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|