add more KMM frames; implement support in the network core for key request and response (this allows peers to request a encryption key from a EKC file loaded on the FNE to use for encryption/decryption, i.e. peer keyloading);
parent
0fd6758161
commit
df648a2c50
@ -0,0 +1,73 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Defines.h"
|
||||||
|
#include "p25/P25Defines.h"
|
||||||
|
#include "p25/kmm/KMMFactory.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace p25;
|
||||||
|
using namespace p25::defines;
|
||||||
|
using namespace p25::kmm;
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Initializes a new instance of the KMMFactory class. */
|
||||||
|
|
||||||
|
KMMFactory::KMMFactory() = default;
|
||||||
|
|
||||||
|
/* Finalizes a instance of KMMFactory class. */
|
||||||
|
|
||||||
|
KMMFactory::~KMMFactory() = default;
|
||||||
|
|
||||||
|
/* Create an instance of a KMMFrame. */
|
||||||
|
|
||||||
|
std::unique_ptr<KMMFrame> KMMFactory::create(const uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(data != nullptr);
|
||||||
|
|
||||||
|
uint8_t messageId = data[0U]; // Message ID
|
||||||
|
|
||||||
|
switch (messageId) {
|
||||||
|
case KMM_MessageType::HELLO:
|
||||||
|
return decode(new KMMHello(), data);
|
||||||
|
case KMM_MessageType::INVENTORY_CMD:
|
||||||
|
return decode(new KMMInventoryCommand(), data);
|
||||||
|
case KMM_MessageType::MODIFY_KEY_CMD:
|
||||||
|
return decode(new KMMModifyKey(), data);
|
||||||
|
default:
|
||||||
|
LogError(LOG_P25, "KMMFactory::create(), unknown KMM message ID value, messageId = $%02X", messageId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Private Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Decode a SNDCP packet. */
|
||||||
|
|
||||||
|
std::unique_ptr<KMMFrame> KMMFactory::decode(KMMFrame* packet, const uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(packet != nullptr);
|
||||||
|
assert(data != nullptr);
|
||||||
|
|
||||||
|
if (!packet->decode(data)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::unique_ptr<KMMFrame>(packet);
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file KMMFactory.h
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
* @file KMMFactory.cpp
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
*/
|
||||||
|
#if !defined(__P25_KMM__KMM_FACTORY_H__)
|
||||||
|
#define __P25_KMM__KMM_FACTORY_H__
|
||||||
|
|
||||||
|
#include "common/Defines.h"
|
||||||
|
|
||||||
|
#include "common/p25/kmm/KeysetItem.h"
|
||||||
|
|
||||||
|
#include "common/p25/kmm/KMMFrame.h"
|
||||||
|
#include "common/p25/kmm/KMMHello.h"
|
||||||
|
#include "common/p25/kmm/KMMInventoryCommand.h"
|
||||||
|
#include "common/p25/kmm/KMMModifyKey.h"
|
||||||
|
|
||||||
|
namespace p25
|
||||||
|
{
|
||||||
|
namespace kmm
|
||||||
|
{
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Class Declaration
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper class to instantiate an instance of a KMM frame packet.
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
*/
|
||||||
|
class HOST_SW_API KMMFactory {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Initializes a new instance of the KMMFactory class.
|
||||||
|
*/
|
||||||
|
KMMFactory();
|
||||||
|
/**
|
||||||
|
* @brief Finalizes a instance of the KMMFactory class.
|
||||||
|
*/
|
||||||
|
~KMMFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create an instance of a KMMFrame.
|
||||||
|
* @param[in] data Buffer containing KMM frame packet data to decode.
|
||||||
|
* @returns KMMFrame* Instance of a KMMFrame representing the decoded data.
|
||||||
|
*/
|
||||||
|
static std::unique_ptr<KMMFrame> create(const uint8_t* data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Decode a KMM frame.
|
||||||
|
* @param packet Instance of KMMFrame.
|
||||||
|
* @param[in] data Buffer containing KMM frame packet data to decode.
|
||||||
|
* @returns KMMFrame* Instance of a KMMFrame representing the decoded data.
|
||||||
|
*/
|
||||||
|
static std::unique_ptr<KMMFrame> decode(KMMFrame* packet, const uint8_t* data);
|
||||||
|
};
|
||||||
|
} // namespace kmm
|
||||||
|
} // namespace p25
|
||||||
|
|
||||||
|
#endif // __P25_KMM__KMM_FACTORY_H__
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Defines.h"
|
||||||
|
#include "p25/P25Defines.h"
|
||||||
|
#include "p25/kmm/KMMHello.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
using namespace p25;
|
||||||
|
using namespace p25::defines;
|
||||||
|
using namespace p25::kmm;
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Initializes a new instance of the KMMHello class. */
|
||||||
|
|
||||||
|
KMMHello::KMMHello() : KMMFrame(),
|
||||||
|
m_flag(KMM_HelloFlag::IDENT_ONLY)
|
||||||
|
{
|
||||||
|
m_messageId = KMM_MessageType::HELLO;
|
||||||
|
m_respKind = KMM_ResponseKind::DELAYED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalizes a instance of the KMMHello class. */
|
||||||
|
|
||||||
|
KMMHello::~KMMHello() = default;
|
||||||
|
|
||||||
|
/* Decode a KMM modify key. */
|
||||||
|
|
||||||
|
bool KMMHello::decode(const uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(data != nullptr);
|
||||||
|
|
||||||
|
KMMFrame::decodeHeader(data);
|
||||||
|
|
||||||
|
m_flag = data[10U]; // Hello Flag
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode a KMM modify key. */
|
||||||
|
|
||||||
|
void KMMHello::encode(uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(data != nullptr);
|
||||||
|
m_messageLength = KMM_HELLO_LENGTH;
|
||||||
|
|
||||||
|
KMMFrame::encodeHeader(data);
|
||||||
|
|
||||||
|
data[10U] = m_flag; // Hello Flag
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Protected Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Internal helper to copy the the class. */
|
||||||
|
|
||||||
|
void KMMHello::copy(const KMMHello& data)
|
||||||
|
{
|
||||||
|
m_flag = data.m_flag;
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file KMMHello.h
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
* @file KMMHello.cpp
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
*/
|
||||||
|
#if !defined(__P25_KMM__KMM_HELLO_H__)
|
||||||
|
#define __P25_KMM__KMM_HELLO_H__
|
||||||
|
|
||||||
|
#include "common/Defines.h"
|
||||||
|
#include "common/p25/kmm/KMMFrame.h"
|
||||||
|
#include "common/p25/kmm/KeysetItem.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace p25
|
||||||
|
{
|
||||||
|
namespace kmm
|
||||||
|
{
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Constants
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup p25_kmm
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
const uint32_t KMM_HELLO_LENGTH = KMM_FRAME_LENGTH + 1U;
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Class Declaration
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class HOST_SW_API KMMHello : public KMMFrame {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Initializes a new instance of the KMMHello class.
|
||||||
|
*/
|
||||||
|
KMMHello();
|
||||||
|
/**
|
||||||
|
* @brief Finalizes a instance of the KMMHello class.
|
||||||
|
*/
|
||||||
|
~KMMHello();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decode a KMM hello.
|
||||||
|
* @param[in] data Buffer containing KMM frame data to decode.
|
||||||
|
* @returns bool True, if decoded, otherwise false.
|
||||||
|
*/
|
||||||
|
bool decode(const uint8_t* data) override;
|
||||||
|
/**
|
||||||
|
* @brief Encode a KMM hello.
|
||||||
|
* @param[out] data Buffer to encode KMM frame data to.
|
||||||
|
*/
|
||||||
|
void encode(uint8_t* data) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
__PROPERTY(uint8_t, flag, Flag);
|
||||||
|
|
||||||
|
__COPY(KMMHello);
|
||||||
|
};
|
||||||
|
} // namespace kmm
|
||||||
|
} // namespace p25
|
||||||
|
|
||||||
|
#endif // __P25_KMM__KMM_HELLO_H__
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Defines.h"
|
||||||
|
#include "p25/P25Defines.h"
|
||||||
|
#include "p25/kmm/KMMInventoryCommand.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
using namespace p25;
|
||||||
|
using namespace p25::defines;
|
||||||
|
using namespace p25::kmm;
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Initializes a new instance of the KMMInventoryCommand class. */
|
||||||
|
|
||||||
|
KMMInventoryCommand::KMMInventoryCommand() : KMMFrame(),
|
||||||
|
m_inventoryType(KMM_InventoryType::NULL_INVENTORY)
|
||||||
|
{
|
||||||
|
m_messageId = KMM_MessageType::INVENTORY_CMD;
|
||||||
|
m_respKind = KMM_ResponseKind::IMMEDIATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalizes a instance of the KMMInventoryCommand class. */
|
||||||
|
|
||||||
|
KMMInventoryCommand::~KMMInventoryCommand() = default;
|
||||||
|
|
||||||
|
/* Decode a KMM modify key. */
|
||||||
|
|
||||||
|
bool KMMInventoryCommand::decode(const uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(data != nullptr);
|
||||||
|
|
||||||
|
KMMFrame::decodeHeader(data);
|
||||||
|
|
||||||
|
m_inventoryType = data[10U]; // Inventory Type
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode a KMM modify key. */
|
||||||
|
|
||||||
|
void KMMInventoryCommand::encode(uint8_t* data)
|
||||||
|
{
|
||||||
|
assert(data != nullptr);
|
||||||
|
m_messageLength = KMM_INVENTORY_CMD_LENGTH;
|
||||||
|
|
||||||
|
KMMFrame::encodeHeader(data);
|
||||||
|
|
||||||
|
data[10U] = m_inventoryType; // Inventory Type
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Protected Class Members
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* Internal helper to copy the the class. */
|
||||||
|
|
||||||
|
void KMMInventoryCommand::copy(const KMMInventoryCommand& data)
|
||||||
|
{
|
||||||
|
m_inventoryType = data.m_inventoryType;
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
// 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) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file KMMInventoryCommand.h
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
* @file KMMInventoryCommand.cpp
|
||||||
|
* @ingroup p25_kmm
|
||||||
|
*/
|
||||||
|
#if !defined(__P25_KMM__KMM_INVENTORY_COMMAND_H__)
|
||||||
|
#define __P25_KMM__KMM_INVENTORY_COMMAND_H__
|
||||||
|
|
||||||
|
#include "common/Defines.h"
|
||||||
|
#include "common/p25/kmm/KMMFrame.h"
|
||||||
|
#include "common/p25/kmm/KeysetItem.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace p25
|
||||||
|
{
|
||||||
|
namespace kmm
|
||||||
|
{
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Constants
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup p25_kmm
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
const uint32_t KMM_INVENTORY_CMD_LENGTH = KMM_FRAME_LENGTH + 1U;
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Class Declaration
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class HOST_SW_API KMMInventoryCommand : public KMMFrame {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Initializes a new instance of the KMMInventoryCommand class.
|
||||||
|
*/
|
||||||
|
KMMInventoryCommand();
|
||||||
|
/**
|
||||||
|
* @brief Finalizes a instance of the KMMInventoryCommand class.
|
||||||
|
*/
|
||||||
|
~KMMInventoryCommand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decode a KMM inventory command.
|
||||||
|
* @param[in] data Buffer containing KMM frame data to decode.
|
||||||
|
* @returns bool True, if decoded, otherwise false.
|
||||||
|
*/
|
||||||
|
bool decode(const uint8_t* data) override;
|
||||||
|
/**
|
||||||
|
* @brief Encode a KMM inventory command.
|
||||||
|
* @param[out] data Buffer to encode KMM frame data to.
|
||||||
|
*/
|
||||||
|
void encode(uint8_t* data) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
__PROPERTY(uint8_t, inventoryType, InventoryType);
|
||||||
|
|
||||||
|
__COPY(KMMInventoryCommand);
|
||||||
|
};
|
||||||
|
} // namespace kmm
|
||||||
|
} // namespace p25
|
||||||
|
|
||||||
|
#endif // __P25_KMM__KMM_INVENTORY_COMMAND_H__
|
||||||
Loading…
Reference in new issue