From eae892322720e6f1e488f789db71e87fa0a5affa Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 20 Jul 2024 12:27:44 -0400 Subject: [PATCH] various cleanups; correct incorrect implementation for copy constructors on DFSI FSC messages; --- src/common/network/BaseNetwork.h | 2 +- src/common/p25/dfsi/DFSIDefines.h | 2 ++ src/common/p25/dfsi/frames/fsc/FSCACK.cpp | 2 +- src/common/p25/dfsi/frames/fsc/FSCACK.h | 2 +- src/common/p25/dfsi/frames/fsc/FSCConnect.cpp | 2 +- src/common/p25/dfsi/frames/fsc/FSCConnect.h | 2 +- .../dfsi/frames/fsc/FSCConnectResponse.cpp | 2 +- .../p25/dfsi/frames/fsc/FSCConnectResponse.h | 2 +- .../p25/dfsi/frames/fsc/FSCDisconnect.cpp | 2 +- .../p25/dfsi/frames/fsc/FSCDisconnect.h | 2 +- .../p25/dfsi/frames/fsc/FSCHeartbeat.cpp | 2 +- src/common/p25/dfsi/frames/fsc/FSCHeartbeat.h | 2 +- src/common/p25/dfsi/frames/fsc/FSCMessage.cpp | 32 ++++++++++++++++++- src/common/p25/dfsi/frames/fsc/FSCMessage.h | 13 ++++++-- .../p25/dfsi/frames/fsc/FSCResponse.cpp | 2 +- src/common/p25/dfsi/frames/fsc/FSCResponse.h | 2 +- src/common/p25/lc/tsbk/TSBKFactory.cpp | 6 ++++ src/host/modem/port/UDPPort.h | 4 --- 18 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/common/network/BaseNetwork.h b/src/common/network/BaseNetwork.h index 95a83283..cc41deb5 100644 --- a/src/common/network/BaseNetwork.h +++ b/src/common/network/BaseNetwork.h @@ -474,7 +474,7 @@ namespace network /** * @brief Generates a new stream ID. - * @returns uint32_T New stream ID. + * @returns uint32_t New stream ID. */ uint32_t createStreamId() { std::uniform_int_distribution dist(DVM_RAND_MIN, DVM_RAND_MAX); return dist(m_random); } diff --git a/src/common/p25/dfsi/DFSIDefines.h b/src/common/p25/dfsi/DFSIDefines.h index 5c83099c..4a2a51f0 100644 --- a/src/common/p25/dfsi/DFSIDefines.h +++ b/src/common/p25/dfsi/DFSIDefines.h @@ -68,6 +68,8 @@ namespace p25 * @{ */ + const uint8_t DFSI_RTP_PAYLOAD_TYPE = 0x64U; //! + const uint8_t DFSI_STATUS_NO_ERROR = 0x00U; //! const uint8_t DFSI_STATUS_ERASE = 0x02U; //! diff --git a/src/common/p25/dfsi/frames/fsc/FSCACK.cpp b/src/common/p25/dfsi/frames/fsc/FSCACK.cpp index f99d32f9..2fa01505 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCACK.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCACK.cpp @@ -37,7 +37,7 @@ FSCACK::FSCACK() : FSCMessage(), /* Initializes a instance of the FSCACK class. */ -FSCACK::FSCACK(uint8_t* data) : FSCMessage(data), +FSCACK::FSCACK(const uint8_t* data) : FSCMessage(data), m_ackMessageId(FSCMessageType::FSC_INVALID), m_ackVersion(1U), m_ackCorrelationTag(0U), diff --git a/src/common/p25/dfsi/frames/fsc/FSCACK.h b/src/common/p25/dfsi/frames/fsc/FSCACK.h index ef59d939..f2df8f51 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCACK.h +++ b/src/common/p25/dfsi/frames/fsc/FSCACK.h @@ -51,7 +51,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCACK class. * @param data Buffer to containing FSCACK to decode. */ - FSCACK(uint8_t* data); + FSCACK(const uint8_t* data); /** * @brief Decode a FSC ACK frame. diff --git a/src/common/p25/dfsi/frames/fsc/FSCConnect.cpp b/src/common/p25/dfsi/frames/fsc/FSCConnect.cpp index 14265b39..ce7d3666 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCConnect.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCConnect.cpp @@ -36,7 +36,7 @@ FSCConnect::FSCConnect() : FSCMessage(), /* Initializes a instance of the FSCConnect class. */ -FSCConnect::FSCConnect(uint8_t* data) : FSCMessage(data), +FSCConnect::FSCConnect(const uint8_t* data) : FSCMessage(data), m_vcBasePort(0U), m_vcSSRC(0U), m_fsHeartbeatPeriod(5U), diff --git a/src/common/p25/dfsi/frames/fsc/FSCConnect.h b/src/common/p25/dfsi/frames/fsc/FSCConnect.h index 0c0a0ab4..067a93bd 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCConnect.h +++ b/src/common/p25/dfsi/frames/fsc/FSCConnect.h @@ -51,7 +51,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCConnect class. * @param data Buffer to containing FSCConnect to decode. */ - FSCConnect(uint8_t* data); + FSCConnect(const uint8_t* data); /** * @brief Decode a FSC connect frame. diff --git a/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.cpp b/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.cpp index cc412df4..6af0a65e 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.cpp @@ -33,7 +33,7 @@ FSCConnectResponse::FSCConnectResponse() : FSCResponse(), /* Initializes a instance of the FSCConnectResponse class. */ -FSCConnectResponse::FSCConnectResponse(uint8_t* data) : FSCResponse(data), +FSCConnectResponse::FSCConnectResponse(const uint8_t* data) : FSCResponse(data), m_vcBasePort(0U) { decode(data); diff --git a/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.h b/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.h index 2243d004..18196c15 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.h +++ b/src/common/p25/dfsi/frames/fsc/FSCConnectResponse.h @@ -51,7 +51,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCConnectResponse class. * @param data Buffer to containing FSCConnectResponse to decode. */ - FSCConnectResponse(uint8_t* data); + FSCConnectResponse(const uint8_t* data); /** * @brief Decode a FSC connect response frame. diff --git a/src/common/p25/dfsi/frames/fsc/FSCDisconnect.cpp b/src/common/p25/dfsi/frames/fsc/FSCDisconnect.cpp index a59f28d0..f6f79c01 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCDisconnect.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCDisconnect.cpp @@ -32,7 +32,7 @@ FSCDisconnect::FSCDisconnect() : FSCMessage() /* Initializes a instance of the FSCDisconnect class. */ -FSCDisconnect::FSCDisconnect(uint8_t* data) : FSCMessage(data) +FSCDisconnect::FSCDisconnect(const uint8_t* data) : FSCMessage(data) { decode(data); } diff --git a/src/common/p25/dfsi/frames/fsc/FSCDisconnect.h b/src/common/p25/dfsi/frames/fsc/FSCDisconnect.h index a39739f4..0cea9537 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCDisconnect.h +++ b/src/common/p25/dfsi/frames/fsc/FSCDisconnect.h @@ -51,7 +51,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCDisconnect class. * @param data Buffer to containing FSCDisconnect to decode. */ - FSCDisconnect(uint8_t* data); + FSCDisconnect(const uint8_t* data); }; } // namespace fsc } // namespace frames diff --git a/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.cpp b/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.cpp index d8ae59b5..43aef62e 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.cpp @@ -32,7 +32,7 @@ FSCHeartbeat::FSCHeartbeat() : FSCMessage() /* Initializes a instance of the FSCHeartbeat class. */ -FSCHeartbeat::FSCHeartbeat(uint8_t* data) : FSCMessage(data) +FSCHeartbeat::FSCHeartbeat(const uint8_t* data) : FSCMessage(data) { decode(data); } diff --git a/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.h b/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.h index eca02888..15a33d1f 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.h +++ b/src/common/p25/dfsi/frames/fsc/FSCHeartbeat.h @@ -51,7 +51,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCHeartbeat class. * @param data Buffer to containing FSCHeartbeat to decode. */ - FSCHeartbeat(uint8_t* data); + FSCHeartbeat(const uint8_t* data); }; } // namespace fsc } // namespace frames diff --git a/src/common/p25/dfsi/frames/fsc/FSCMessage.cpp b/src/common/p25/dfsi/frames/fsc/FSCMessage.cpp index 7689b314..cd483f35 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCMessage.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCMessage.cpp @@ -8,6 +8,7 @@ * */ #include "common/p25/dfsi/frames/fsc/FSCMessage.h" +#include "common/p25/dfsi/frames/Frames.h" #include "common/p25/dfsi/DFSIDefines.h" #include "common/Utils.h" #include "common/Log.h" @@ -35,7 +36,7 @@ FSCMessage::FSCMessage() : /* Initializes a instance of the FSCMessage class. */ -FSCMessage::FSCMessage(uint8_t* data) : +FSCMessage::FSCMessage(const uint8_t* data) : m_messageId(FSCMessageType::FSC_INVALID), m_version(1U), m_correlationTag(0U) @@ -70,3 +71,32 @@ void FSCMessage::encode(uint8_t* data) if (m_messageId != FSCMessageType::FSC_HEARTBEAT && m_messageId != FSCMessageType::FSC_ACK) data[2U] = m_correlationTag; // Message Correlation Tag } + +/* Create an instance of a FSCMessage. */ + +std::unique_ptr FSCMessage::createMessage(const uint8_t* data) +{ + assert(data != nullptr); + + uint8_t msg[FSCMessage::LENGTH + 1U]; + ::memset(msg, 0x00U, FSCMessage::LENGTH); + + uint8_t messageId = (FSCMessageType::E)(msg[0U]); // Message ID + + // standard P25 reference opcodes + switch (messageId) { + case FSCMessageType::FSC_CONNECT: + return std::unique_ptr(new FSCConnect(data)); + case FSCMessageType::FSC_HEARTBEAT: + return std::unique_ptr(new FSCHeartbeat(data)); + case FSCMessageType::FSC_ACK: + return std::unique_ptr(new FSCACK(data)); + case FSCMessageType::FSC_DISCONNECT: + return std::unique_ptr(new FSCDisconnect(data)); + default: + LogError(LOG_P25, "FSCMessage::create(), unknown message value, messageId = $%02X", messageId); + break; + } + + return nullptr; +} diff --git a/src/common/p25/dfsi/frames/fsc/FSCMessage.h b/src/common/p25/dfsi/frames/fsc/FSCMessage.h index 55be0087..1772c86c 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCMessage.h +++ b/src/common/p25/dfsi/frames/fsc/FSCMessage.h @@ -50,7 +50,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCMessage class. * @param data Buffer to containing FSCMessage to decode. */ - FSCMessage(uint8_t* data); + FSCMessage(const uint8_t* data); /** * @brief Decode a FSC message frame. @@ -62,7 +62,14 @@ namespace p25 * @param[out] data Buffer to encode a FSCMessage. */ virtual void encode(uint8_t* data); - + + /** + * @brief Create an instance of a FSCMessage. + * @param[in] data Buffer containing FSCMessage packet data to decode. + * @returns FSCMessage* Instance of a FSCMessage representing the decoded data. + */ + static std::unique_ptr createMessage(const uint8_t* data); + public: /** * @brief Message ID. @@ -82,4 +89,4 @@ namespace p25 } // namespace dfsi } // namespace p25 -#endif // __FSC_MESSAGE_H__ \ No newline at end of file +#endif // __FSC_MESSAGE_H__ diff --git a/src/common/p25/dfsi/frames/fsc/FSCResponse.cpp b/src/common/p25/dfsi/frames/fsc/FSCResponse.cpp index 1a12ab12..4cf5b57d 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCResponse.cpp +++ b/src/common/p25/dfsi/frames/fsc/FSCResponse.cpp @@ -33,7 +33,7 @@ FSCResponse::FSCResponse() : /* Initializes a instance of the FSCResponse class. */ -FSCResponse::FSCResponse(uint8_t* data) : +FSCResponse::FSCResponse(const uint8_t* data) : m_version(1U) { decode(data); diff --git a/src/common/p25/dfsi/frames/fsc/FSCResponse.h b/src/common/p25/dfsi/frames/fsc/FSCResponse.h index 517b39ed..cb4cbf18 100644 --- a/src/common/p25/dfsi/frames/fsc/FSCResponse.h +++ b/src/common/p25/dfsi/frames/fsc/FSCResponse.h @@ -50,7 +50,7 @@ namespace p25 * @brief Initializes a copy instance of the FSCResponse class. * @param data Buffer to containing FSCResponse to decode. */ - FSCResponse(uint8_t* data); + FSCResponse(const uint8_t* data); /** * @brief Decode a FSC message frame. diff --git a/src/common/p25/lc/tsbk/TSBKFactory.cpp b/src/common/p25/lc/tsbk/TSBKFactory.cpp index 5d467fd8..3f6a596b 100644 --- a/src/common/p25/lc/tsbk/TSBKFactory.cpp +++ b/src/common/p25/lc/tsbk/TSBKFactory.cpp @@ -35,12 +35,15 @@ bool TSBKFactory::m_warnCRC = false; // --------------------------------------------------------------------------- /* Initializes a new instance of the TSBKFactory class. */ + TSBKFactory::TSBKFactory() = default; /* Finalizes a instance of TSBKFactory class. */ + TSBKFactory::~TSBKFactory() = default; /* Create an instance of a TSBK. */ + std::unique_ptr TSBKFactory::createTSBK(const uint8_t* data, bool rawTSBK) { assert(data != nullptr); @@ -223,6 +226,7 @@ std::unique_ptr TSBKFactory::createTSBK(const uint8_t* data, bool rawTSBK) } /* Create an instance of a AMBT. */ + std::unique_ptr TSBKFactory::createAMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks) { assert(blocks != nullptr); @@ -310,6 +314,7 @@ std::unique_ptr TSBKFactory::createAMBT(const data::DataHeader& dataHeader // --------------------------------------------------------------------------- /* Decode a TSBK. */ + std::unique_ptr TSBKFactory::decode(TSBK* tsbk, const uint8_t* data, bool rawTSBK) { assert(tsbk != nullptr); @@ -323,6 +328,7 @@ std::unique_ptr TSBKFactory::decode(TSBK* tsbk, const uint8_t* data, bool } /* Decode an AMBT. */ + std::unique_ptr TSBKFactory::decode(AMBT* ambt, const data::DataHeader& dataHeader, const data::DataBlock* blocks) { assert(ambt != nullptr); diff --git a/src/host/modem/port/UDPPort.h b/src/host/modem/port/UDPPort.h index c766ff1e..1098918b 100644 --- a/src/host/modem/port/UDPPort.h +++ b/src/host/modem/port/UDPPort.h @@ -4,10 +4,6 @@ * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * @package DVM / Modem Host Software - * @derivedfrom MMDVMHost (https://github.com/g4klx/MMDVMHost) - * @license GPLv2 License (https://opensource.org/licenses/GPL-2.0) - * * Copyright (C) 2021 Jonathan Naylor, G4KLX * Copyright (C) 2021 Bryan Biedenkapp, N2PLL *