2020-10-18 19:44:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 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
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "M17LICH.h"
|
|
|
|
#include "M17Utils.h"
|
2020-10-19 10:00:45 +00:00
|
|
|
#include "M17Defines.h"
|
2020-10-18 19:44:03 +00:00
|
|
|
#include "M17CRC.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
2020-10-18 22:28:29 +00:00
|
|
|
#include <cstring>
|
2020-10-18 19:44:03 +00:00
|
|
|
|
|
|
|
CM17LICH::CM17LICH() :
|
|
|
|
m_lich(NULL),
|
|
|
|
m_valid(false)
|
|
|
|
{
|
2020-10-19 10:00:45 +00:00
|
|
|
m_lich = new unsigned char[M17_LICH_LENGTH_BYTES];
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CM17LICH::~CM17LICH()
|
|
|
|
{
|
|
|
|
delete[] m_lich;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::getNetwork(unsigned char* data) const
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(data, m_lich, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::setNetwork(const unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(m_lich, data, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
|
|
|
|
m_valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CM17LICH::getSource() const
|
|
|
|
{
|
|
|
|
std::string callsign;
|
|
|
|
CM17Utils::decodeCallsign(m_lich + 6U, callsign);
|
|
|
|
|
|
|
|
return callsign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::setSource(const std::string& callsign)
|
|
|
|
{
|
|
|
|
CM17Utils::encodeCallsign(callsign, m_lich + 6U);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CM17LICH::getDest() const
|
|
|
|
{
|
|
|
|
std::string callsign;
|
|
|
|
CM17Utils::decodeCallsign(m_lich + 0U, callsign);
|
|
|
|
|
|
|
|
return callsign;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::setDest(const std::string& callsign)
|
|
|
|
{
|
|
|
|
CM17Utils::encodeCallsign(callsign, m_lich + 0U);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char CM17LICH::getDataType() const
|
|
|
|
{
|
2020-10-20 13:26:47 +00:00
|
|
|
return (m_lich[13U] >> 1) & 0x03U;
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::setDataType(unsigned char type)
|
|
|
|
{
|
2020-10-20 13:26:47 +00:00
|
|
|
m_lich[13U] &= 0xF9U;
|
|
|
|
m_lich[13U] |= (type << 1) & 0x06U;
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 10:10:31 +00:00
|
|
|
bool CM17LICH::isNONCENull() const
|
|
|
|
{
|
|
|
|
return ::memcmp(m_lich + 14U, M17_NULL_NONCE, M17_NONCE_LENGTH_BYTES) == 0;
|
|
|
|
}
|
|
|
|
|
2020-10-18 19:44:03 +00:00
|
|
|
void CM17LICH::reset()
|
|
|
|
{
|
|
|
|
::memset(m_lich, 0x00U, 30U);
|
|
|
|
|
|
|
|
m_valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CM17LICH::isValid() const
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::getLinkSetup(unsigned char* data) const
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(data, m_lich, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
CM17CRC::encodeCRC(data, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CM17LICH::setLinkSetup(const unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(m_lich, data, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
m_valid = CM17CRC::checkCRC(m_lich, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 13:47:47 +00:00
|
|
|
void CM17LICH::getFragment(unsigned char* data, unsigned int n) const
|
2020-10-18 19:44:03 +00:00
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
CM17CRC::encodeCRC(m_lich, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(data, m_lich + (n * M17_LICH_FRAGMENT_LENGTH_BYTES), M17_LICH_FRAGMENT_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 13:47:47 +00:00
|
|
|
void CM17LICH::setFragment(const unsigned char* data, unsigned int n)
|
2020-10-18 19:44:03 +00:00
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
::memcpy(m_lich + (n * M17_LICH_FRAGMENT_LENGTH_BYTES), data, M17_LICH_FRAGMENT_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
|
2020-10-19 10:00:45 +00:00
|
|
|
m_valid = CM17CRC::checkCRC(m_lich, M17_LICH_LENGTH_BYTES);
|
2020-10-18 19:44:03 +00:00
|
|
|
}
|