diff --git a/Makefile b/Makefile index 14d2b282..bc2a6731 100644 --- a/Makefile +++ b/Makefile @@ -43,13 +43,13 @@ HOST_OBJECTS = \ dmr/lc/LC.o \ dmr/lc/PrivacyLC.o \ dmr/lc/ShortLC.o \ + dmr/packet/ControlSignaling.o \ + dmr/packet/Data.o \ + dmr/packet/Voice.o \ dmr/Control.o \ - dmr/ControlPacket.o \ - dmr/DataPacket.o \ dmr/Slot.o \ dmr/SlotType.o \ dmr/Sync.o \ - dmr/VoicePacket.o \ lookups/IdenTableLookup.o \ lookups/RadioIdLookup.o \ lookups/RSSIInterpolator.o \ @@ -59,20 +59,20 @@ HOST_OBJECTS = \ p25/data/DataHeader.o \ p25/data/LowSpeedData.o \ p25/dfsi/LC.o \ - p25/dfsi/DFSITrunkPacket.o \ - p25/dfsi/DFSIVoicePacket.o \ + p25/dfsi/packet/DFSITrunk.o \ + p25/dfsi/packet/DFSIVoice.o \ p25/edac/Trellis.o \ p25/lc/LC.o \ p25/lc/TDULC.o \ p25/lc/TSBK.o \ + p25/packet/Data.o \ + p25/packet/Trunk.o \ + p25/packet/Voice.o \ p25/Audio.o \ p25/Control.o \ - p25/DataPacket.o \ p25/NID.o \ p25/Sync.o \ - p25/TrunkPacket.o \ p25/P25Utils.o \ - p25/VoicePacket.o \ modem/port/IModemPort.o \ modem/port/ISerialPort.o \ modem/port/ModemNullPort.o \ diff --git a/dmr/ControlPacket.h b/dmr/ControlPacket.h deleted file mode 100644 index 088d96a9..00000000 --- a/dmr/ControlPacket.h +++ /dev/null @@ -1,96 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2020 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__DMR_CONTROL_PACKET_H__) -#define __DMR_CONTROL_PACKET_H__ - -#include "Defines.h" -#include "dmr/data/Data.h" -#include "dmr/data/EmbeddedData.h" -#include "dmr/lc/LC.h" -#include "dmr/Slot.h" -#include "modem/Modem.h" -#include "network/BaseNetwork.h" -#include "RingBuffer.h" -#include "lookups/RadioIdLookup.h" -#include "lookups/TalkgroupIdLookup.h" -#include "StopWatch.h" -#include "Timer.h" - -#include - -namespace dmr -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API Slot; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements core logic for handling DMR control (CSBK) packets. - // --------------------------------------------------------------------------- - - class HOST_SW_API ControlPacket { - public: - /// Process a data frame from the RF interface. - bool process(uint8_t* data, uint32_t len); - /// Process a data frame from the network. - void processNetwork(const data::Data& dmrData); - - /// Helper to write a extended function packet on the RF interface. - void writeRF_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId); - /// Helper to write a call alert packet on the RF interface. - void writeRF_Call_Alrt(uint32_t srcId, uint32_t dstId); - - private: - friend class Slot; - Slot* m_slot; - - bool m_dumpCSBKData; - bool m_verbose; - bool m_debug; - - /// Initializes a new instance of the ControlPacket class. - ControlPacket(Slot* slot, network::BaseNetwork* network, bool dumpCSBKData, bool debug, bool verbose); - /// Finalizes a instance of the DataPacket class. - ~ControlPacket(); - - /// Helper to write a TSCC Aloha broadcast packet on the RF interface. - void writeRF_TSCC_Aloha(); - /// Helper to write a TSCC Ann-Wd broadcast packet on the RF interface. - void writeRF_TSCC_Bcast_Ann_Wd(uint32_t channelNo, bool annWd); - /// Helper to write a TSCC Sys_Parm broadcast packet on the RF interface. - void writeRF_TSCC_Bcast_Sys_Parm(); - }; -} // namespace dmr - -#endif // __DMR_CONTROL_PACKET_H__ diff --git a/dmr/Slot.cpp b/dmr/Slot.cpp index aa0ec85e..608e5211 100644 --- a/dmr/Slot.cpp +++ b/dmr/Slot.cpp @@ -37,6 +37,7 @@ #include "Utils.h" using namespace dmr; +using namespace dmr::packet; #include #include @@ -153,9 +154,9 @@ Slot::Slot(uint32_t slotNo, uint32_t timeout, uint32_t tgHang, uint32_t queueSiz { m_interval.start(); - m_voice = new VoicePacket(this, m_network, m_embeddedLCOnly, m_dumpTAData, debug, verbose); - m_data = new DataPacket(this, m_network, dumpDataPacket, repeatDataPacket, debug, verbose); - m_control = new ControlPacket(this, m_network, dumpCSBKData, debug, verbose); + m_voice = new Voice(this, m_network, m_embeddedLCOnly, m_dumpTAData, debug, verbose); + m_data = new Data(this, m_network, dumpDataPacket, repeatDataPacket, debug, verbose); + m_control = new ControlSignaling(this, m_network, dumpCSBKData, debug, verbose); } /// diff --git a/dmr/Slot.h b/dmr/Slot.h index f47f127b..c5009ff4 100644 --- a/dmr/Slot.h +++ b/dmr/Slot.h @@ -34,9 +34,9 @@ #include "Defines.h" #include "dmr/Control.h" #include "dmr/SiteData.h" -#include "dmr/ControlPacket.h" -#include "dmr/DataPacket.h" -#include "dmr/VoicePacket.h" +#include "dmr/packet/ControlSignaling.h" +#include "dmr/packet/Data.h" +#include "dmr/packet/Voice.h" #include "modem/Modem.h" #include "network/BaseNetwork.h" #include "lookups/RSSIInterpolator.h" @@ -55,9 +55,9 @@ namespace dmr // Class Prototypes // --------------------------------------------------------------------------- - class HOST_SW_API VoicePacket; - class HOST_SW_API DataPacket; - class HOST_SW_API ControlPacket; + namespace packet { class HOST_SW_API Voice; } + namespace packet { class HOST_SW_API Data; } + namespace packet { class HOST_SW_API ControlSignaling; } // --------------------------------------------------------------------------- // Class Declaration @@ -86,8 +86,8 @@ namespace dmr /// Updates the slot processor. void clock(); - /// Gets instance of the ControlPacket class. - ControlPacket* control() { return m_control; } + /// Gets instance of the ControlSignaling class. + packet::ControlSignaling* control() { return m_control; } /// Helper to change the debug and verbose state. void setDebugVerbose(bool debug, bool verbose); @@ -105,12 +105,12 @@ namespace dmr static void setSiteData(uint32_t netId, uint8_t siteId, uint8_t channelId, uint32_t channelNo); private: - friend class VoicePacket; - VoicePacket* m_voice; - friend class DataPacket; - DataPacket* m_data; - friend class ControlPacket; - ControlPacket* m_control; + friend class packet::Voice; + packet::Voice* m_voice; + friend class packet::Data; + packet::Data* m_data; + friend class packet::ControlSignaling; + packet::ControlSignaling* m_control; uint32_t m_slotNo; diff --git a/dmr/VoicePacket.h b/dmr/VoicePacket.h deleted file mode 100644 index 1e94350a..00000000 --- a/dmr/VoicePacket.h +++ /dev/null @@ -1,118 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2021 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__DMR_VOICE_PACKET_H__) -#define __DMR_VOICE_PACKET_H__ - -#include "Defines.h" -#include "dmr/data/Data.h" -#include "dmr/data/EmbeddedData.h" -#include "dmr/lc/LC.h" -#include "dmr/lc/PrivacyLC.h" -#include "dmr/Slot.h" -#include "edac/AMBEFEC.h" -#include "network/BaseNetwork.h" -#include "lookups/RadioIdLookup.h" -#include "lookups/TalkgroupIdLookup.h" - -#include - -namespace dmr -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API DataPacket; - class HOST_SW_API Slot; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements core logic for handling DMR voice packets. - // --------------------------------------------------------------------------- - - class HOST_SW_API VoicePacket { - public: - /// Process a voice frame from the RF interface. - bool process(uint8_t* data, uint32_t len); - /// Process a voice frame from the network. - void processNetwork(const data::Data& dmrData); - - private: - friend class DataPacket; - friend class Slot; - Slot* m_slot; - - uint8_t* m_lastFrame; - bool m_lastFrameValid; - - uint8_t m_rfN; - uint8_t m_lastRfN; - uint8_t m_netN; - - data::EmbeddedData m_rfEmbeddedLC; - data::EmbeddedData* m_rfEmbeddedData; - uint32_t m_rfEmbeddedReadN; - uint32_t m_rfEmbeddedWriteN; - - data::EmbeddedData m_netEmbeddedLC; - data::EmbeddedData* m_netEmbeddedData; - uint32_t m_netEmbeddedReadN; - uint32_t m_netEmbeddedWriteN; - - uint8_t m_rfTalkerId; - uint8_t m_netTalkerId; - - edac::AMBEFEC m_fec; - - bool m_embeddedLCOnly; - bool m_dumpTAData; - - bool m_verbose; - bool m_debug; - - /// Initializes a new instance of the VoicePacket class. - VoicePacket(Slot* slot, network::BaseNetwork* network, bool embeddedLCOnly, bool dumpTAData, bool debug, bool verbose); - /// Finalizes a instance of the VoicePacket class. - ~VoicePacket(); - - /// - void logGPSPosition(const uint32_t srcId, const uint8_t* data); - - /// Helper to insert AMBE null frames for missing audio. - void insertNullAudio(uint8_t* data); - /// Helper to insert DMR AMBE silence frames. - bool insertSilence(const uint8_t* data, uint8_t seqNo); - /// Helper to insert DMR AMBE silence frames. - void insertSilence(uint32_t count); - }; -} // namespace dmr - -#endif // __DMR_VOICE_PACKET_H__ diff --git a/dmr/ControlPacket.cpp b/dmr/packet/ControlSignaling.cpp similarity index 96% rename from dmr/ControlPacket.cpp rename to dmr/packet/ControlSignaling.cpp index 7a8a6797..ec76bda4 100644 --- a/dmr/ControlPacket.cpp +++ b/dmr/packet/ControlSignaling.cpp @@ -24,7 +24,7 @@ * GNU General Public License for more details. */ #include "Defines.h" -#include "dmr/ControlPacket.h" +#include "dmr/packet/ControlSignaling.h" #include "dmr/acl/AccessControl.h" #include "dmr/data/DataHeader.h" #include "dmr/data/EMB.h" @@ -40,6 +40,7 @@ #include "Utils.h" using namespace dmr; +using namespace dmr::packet; #include #include @@ -74,7 +75,7 @@ using namespace dmr; /// Buffer containing data frame. /// Length of data frame. /// -bool ControlPacket::process(uint8_t* data, uint32_t len) +bool ControlSignaling::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -224,7 +225,7 @@ bool ControlPacket::process(uint8_t* data, uint32_t len) /// Process a data frame from the network. /// /// -void ControlPacket::processNetwork(const data::Data & dmrData) +void ControlSignaling::processNetwork(const data::Data & dmrData) { uint8_t dataType = dmrData.getDataType(); @@ -376,7 +377,7 @@ void ControlPacket::processNetwork(const data::Data & dmrData) /// Extended function opcode. /// Extended function argument. /// Destination radio ID. -void ControlPacket::writeRF_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId) +void ControlSignaling::writeRF_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId) { if (m_verbose) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_EXT_FNCT (Extended Function), op = $%02X, arg = %u, tgt = %u", @@ -434,7 +435,7 @@ void ControlPacket::writeRF_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId /// /// Source radio ID. /// Destination radio ID. -void ControlPacket::writeRF_Call_Alrt(uint32_t srcId, uint32_t dstId) +void ControlSignaling::writeRF_Call_Alrt(uint32_t srcId, uint32_t dstId) { if (m_verbose) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_CALL_ALRT (Call Alert), src = %u, dst = %u", @@ -482,14 +483,14 @@ void ControlPacket::writeRF_Call_Alrt(uint32_t srcId, uint32_t dstId) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the ControlPacket class. +/// Initializes a new instance of the ControlSignaling class. /// /// DMR slot. /// Instance of the BaseNetwork class. /// /// Flag indicating whether DMR debug is enabled. /// Flag indicating whether DMR verbose logging is enabled. -ControlPacket::ControlPacket(Slot * slot, network::BaseNetwork * network, bool dumpCSBKData, bool debug, bool verbose) : +ControlSignaling::ControlSignaling(Slot * slot, network::BaseNetwork * network, bool dumpCSBKData, bool debug, bool verbose) : m_slot(slot), m_dumpCSBKData(dumpCSBKData), m_verbose(verbose), @@ -499,9 +500,9 @@ ControlPacket::ControlPacket(Slot * slot, network::BaseNetwork * network, bool d } /// -/// Finalizes a instance of the ControlPacket class. +/// Finalizes a instance of the ControlSignaling class. /// -ControlPacket::~ControlPacket() +ControlSignaling::~ControlSignaling() { /* stub */ } @@ -509,7 +510,7 @@ ControlPacket::~ControlPacket() /// /// Helper to write a TSCC Aloha broadcast packet on the RF interface. /// -void ControlPacket::writeRF_TSCC_Aloha() +void ControlSignaling::writeRF_TSCC_Aloha() { if (m_debug) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_ALOHA (Aloha)", m_slot->m_slotNo); @@ -550,7 +551,7 @@ void ControlPacket::writeRF_TSCC_Aloha() /// /// /// -void ControlPacket::writeRF_TSCC_Bcast_Ann_Wd(uint32_t channelNo, bool annWd) +void ControlSignaling::writeRF_TSCC_Bcast_Ann_Wd(uint32_t channelNo, bool annWd) { if (m_debug) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_BROADCAST (Broadcast), BCAST_ANNC_ANN_WD_TSCC (Announce-WD TSCC Channel), channelNo = %u, annWd = %u", @@ -595,7 +596,7 @@ void ControlPacket::writeRF_TSCC_Bcast_Ann_Wd(uint32_t channelNo, bool annWd) /// /// Helper to write a TSCC Sys_Parm broadcast packet on the RF interface. /// -void ControlPacket::writeRF_TSCC_Bcast_Sys_Parm() +void ControlSignaling::writeRF_TSCC_Bcast_Sys_Parm() { if (m_debug) { LogMessage(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_BROADCAST (Broadcast), BCAST_ANNC_SITE_PARMS (Announce Site Parms)", m_slot->m_slotNo); diff --git a/dmr/packet/ControlSignaling.h b/dmr/packet/ControlSignaling.h new file mode 100644 index 00000000..effeb8cf --- /dev/null +++ b/dmr/packet/ControlSignaling.h @@ -0,0 +1,100 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +// +// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) +// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) +// +/* +* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2017-2020 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__DMR_PACKET_CONTROL_SIGNALING_H__) +#define __DMR_PACKET_CONTROL_SIGNALING_H__ + +#include "Defines.h" +#include "dmr/data/Data.h" +#include "dmr/data/EmbeddedData.h" +#include "dmr/lc/LC.h" +#include "dmr/Slot.h" +#include "modem/Modem.h" +#include "network/BaseNetwork.h" +#include "RingBuffer.h" +#include "lookups/RadioIdLookup.h" +#include "lookups/TalkgroupIdLookup.h" +#include "StopWatch.h" +#include "Timer.h" + +#include + +namespace dmr +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + class HOST_SW_API Slot; + + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements core logic for handling DMR control signaling (CSBK) + // packets. + // --------------------------------------------------------------------------- + + class HOST_SW_API ControlSignaling { + public: + /// Process a data frame from the RF interface. + bool process(uint8_t* data, uint32_t len); + /// Process a data frame from the network. + void processNetwork(const data::Data& dmrData); + + /// Helper to write a extended function packet on the RF interface. + void writeRF_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId); + /// Helper to write a call alert packet on the RF interface. + void writeRF_Call_Alrt(uint32_t srcId, uint32_t dstId); + + private: + friend class dmr::Slot; + Slot* m_slot; + + bool m_dumpCSBKData; + bool m_verbose; + bool m_debug; + + /// Initializes a new instance of the ControlSignaling class. + ControlSignaling(Slot* slot, network::BaseNetwork* network, bool dumpCSBKData, bool debug, bool verbose); + /// Finalizes a instance of the ControlSignaling class. + ~ControlSignaling(); + + /// Helper to write a TSCC Aloha broadcast packet on the RF interface. + void writeRF_TSCC_Aloha(); + /// Helper to write a TSCC Ann-Wd broadcast packet on the RF interface. + void writeRF_TSCC_Bcast_Ann_Wd(uint32_t channelNo, bool annWd); + /// Helper to write a TSCC Sys_Parm broadcast packet on the RF interface. + void writeRF_TSCC_Bcast_Sys_Parm(); + }; + } // namespace packet +} // namespace dmr + +#endif // __DMR_PACKET_CONTROL_SIGNALING_H__ diff --git a/dmr/DataPacket.cpp b/dmr/packet/Data.cpp similarity index 97% rename from dmr/DataPacket.cpp rename to dmr/packet/Data.cpp index 3f11a8ce..7598657a 100644 --- a/dmr/DataPacket.cpp +++ b/dmr/packet/Data.cpp @@ -24,7 +24,7 @@ * GNU General Public License for more details. */ #include "Defines.h" -#include "dmr/DataPacket.h" +#include "dmr/packet/Data.h" #include "dmr/acl/AccessControl.h" #include "dmr/data/EMB.h" #include "dmr/edac/Trellis.h" @@ -39,6 +39,7 @@ #include "Utils.h" using namespace dmr; +using namespace dmr::packet; #include #include @@ -73,7 +74,7 @@ using namespace dmr; /// Buffer containing data frame. /// Length of data frame. /// -bool DataPacket::process(uint8_t* data, uint32_t len) +bool Data::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -302,7 +303,7 @@ bool DataPacket::process(uint8_t* data, uint32_t len) /// Process a data frame from the network. /// /// -void DataPacket::processNetwork(const data::Data& dmrData) +void Data::processNetwork(const data::Data& dmrData) { uint8_t dataType = dmrData.getDataType(); @@ -506,7 +507,7 @@ void DataPacket::processNetwork(const data::Data& dmrData) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the DataPacket class. +/// Initializes a new instance of the Data class. /// /// DMR slot. /// Instance of the BaseNetwork class. @@ -514,7 +515,7 @@ void DataPacket::processNetwork(const data::Data& dmrData) /// /// Flag indicating whether DMR debug is enabled. /// Flag indicating whether DMR verbose logging is enabled. -DataPacket::DataPacket(Slot* slot, network::BaseNetwork* network, bool dumpDataPacket, bool repeatDataPacket, bool debug, bool verbose) : +Data::Data(Slot* slot, network::BaseNetwork* network, bool dumpDataPacket, bool repeatDataPacket, bool debug, bool verbose) : m_slot(slot), m_pduUserData(NULL), m_pduDataOffset(0U), @@ -529,9 +530,9 @@ DataPacket::DataPacket(Slot* slot, network::BaseNetwork* network, bool dumpDataP } /// -/// Finalizes a instance of the DataPacket class. +/// Finalizes a instance of the Data class. /// -DataPacket::~DataPacket() +Data::~Data() { delete[] m_pduUserData; } diff --git a/dmr/DataPacket.h b/dmr/packet/Data.h similarity index 54% rename from dmr/DataPacket.h rename to dmr/packet/Data.h index 352a66c3..6f7df374 100644 --- a/dmr/DataPacket.h +++ b/dmr/packet/Data.h @@ -28,8 +28,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if !defined(__DMR_DATA_PACKET_H__) -#define __DMR_DATA_PACKET_H__ +#if !defined(__DMR_PACKET_DATA_H__) +#define __DMR_PACKET_DATA_H__ #include "Defines.h" #include "dmr/data/Data.h" @@ -54,43 +54,46 @@ namespace dmr // Class Prototypes // --------------------------------------------------------------------------- - class HOST_SW_API VoicePacket; - class HOST_SW_API ControlPacket; + namespace packet { class HOST_SW_API Voice; } + namespace packet { class HOST_SW_API ControlSignaling; } class HOST_SW_API Slot; - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements core logic for handling DMR data packets. - // --------------------------------------------------------------------------- + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements core logic for handling DMR data packets. + // --------------------------------------------------------------------------- - class HOST_SW_API DataPacket { - public: - /// Process a data frame from the RF interface. - bool process(uint8_t* data, uint32_t len); - /// Process a data frame from the network. - void processNetwork(const data::Data& dmrData); + class HOST_SW_API Data { + public: + /// Process a data frame from the RF interface. + bool process(uint8_t* data, uint32_t len); + /// Process a data frame from the network. + void processNetwork(const data::Data& dmrData); - private: - friend class VoicePacket; - friend class ControlPacket; - friend class Slot; - Slot* m_slot; + private: + friend class packet::Voice; + friend class packet::ControlSignaling; + friend class dmr::Slot; + Slot* m_slot; - uint8_t* m_pduUserData; - uint32_t m_pduDataOffset; - uint32_t m_lastRejectId; + uint8_t* m_pduUserData; + uint32_t m_pduDataOffset; + uint32_t m_lastRejectId; - bool m_dumpDataPacket; - bool m_repeatDataPacket; + bool m_dumpDataPacket; + bool m_repeatDataPacket; - bool m_verbose; - bool m_debug; + bool m_verbose; + bool m_debug; - /// Initializes a new instance of the DataPacket class. - DataPacket(Slot* slot, network::BaseNetwork* network, bool dumpDataPacket, bool repeatDataPacket, bool debug, bool verbose); - /// Finalizes a instance of the DataPacket class. - ~DataPacket(); - }; + /// Initializes a new instance of the Data class. + Data(Slot* slot, network::BaseNetwork* network, bool dumpDataPacket, bool repeatDataPacket, bool debug, bool verbose); + /// Finalizes a instance of the Data class. + ~Data(); + }; + } // namespace packet } // namespace dmr -#endif // __DMR_DATA_PACKET_H__ +#endif // __DMR_PACKET_DATA_H__ diff --git a/dmr/VoicePacket.cpp b/dmr/packet/Voice.cpp similarity index 98% rename from dmr/VoicePacket.cpp rename to dmr/packet/Voice.cpp index c0912293..6ed21b5a 100644 --- a/dmr/VoicePacket.cpp +++ b/dmr/packet/Voice.cpp @@ -24,7 +24,7 @@ * GNU General Public License for more details. */ #include "Defines.h" -#include "dmr/VoicePacket.h" +#include "dmr/packet/Voice.h" #include "dmr/acl/AccessControl.h" #include "dmr/data/DataHeader.h" #include "dmr/data/EMB.h" @@ -40,6 +40,7 @@ #include "Utils.h" using namespace dmr; +using namespace dmr::packet; #include #include @@ -75,7 +76,7 @@ using namespace dmr; /// Buffer containing data frame. /// Length of data frame. /// -bool VoicePacket::process(uint8_t* data, uint32_t len) +bool Voice::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -617,7 +618,7 @@ bool VoicePacket::process(uint8_t* data, uint32_t len) /// Process a voice frame from the network. /// /// -void VoicePacket::processNetwork(const data::Data& dmrData) +void Voice::processNetwork(const data::Data& dmrData) { uint8_t dataType = dmrData.getDataType(); @@ -1059,7 +1060,7 @@ void VoicePacket::processNetwork(const data::Data& dmrData) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the VoicePacket class. +/// Initializes a new instance of the Voice class. /// /// DMR slot. /// Instance of the BaseNetwork class. @@ -1067,7 +1068,7 @@ void VoicePacket::processNetwork(const data::Data& dmrData) /// /// Flag indicating whether DMR debug is enabled. /// Flag indicating whether DMR verbose logging is enabled. -VoicePacket::VoicePacket(Slot* slot, network::BaseNetwork* network, bool embeddedLCOnly, bool dumpTAData, bool debug, bool verbose) : +Voice::Voice(Slot* slot, network::BaseNetwork* network, bool embeddedLCOnly, bool dumpTAData, bool debug, bool verbose) : m_slot(slot), m_lastFrame(NULL), m_lastFrameValid(false), @@ -1097,9 +1098,9 @@ VoicePacket::VoicePacket(Slot* slot, network::BaseNetwork* network, bool embedde } /// -/// Finalizes a instance of the VoicePacket class. +/// Finalizes a instance of the Voice class. /// -VoicePacket::~VoicePacket() +Voice::~Voice() { delete[] m_lastFrame; @@ -1112,7 +1113,7 @@ VoicePacket::~VoicePacket() /// /// Source radio ID. /// -void VoicePacket::logGPSPosition(const uint32_t srcId, const uint8_t* data) +void Voice::logGPSPosition(const uint32_t srcId, const uint8_t* data) { uint32_t errorVal = (data[2U] & 0x0E) >> 1U; @@ -1163,7 +1164,7 @@ void VoicePacket::logGPSPosition(const uint32_t srcId, const uint8_t* data) /// Helper to insert AMBE null frames for missing audio. /// /// -void VoicePacket::insertNullAudio(uint8_t* data) +void Voice::insertNullAudio(uint8_t* data) { uint8_t* ambeBuffer = new uint8_t[dmr::DMR_AMBE_LENGTH_BYTES]; ::memset(ambeBuffer, 0x00U, dmr::DMR_AMBE_LENGTH_BYTES); @@ -1186,7 +1187,7 @@ void VoicePacket::insertNullAudio(uint8_t* data) /// /// /// -bool VoicePacket::insertSilence(const uint8_t* data, uint8_t seqNo) +bool Voice::insertSilence(const uint8_t* data, uint8_t seqNo) { assert(data != NULL); @@ -1217,7 +1218,7 @@ bool VoicePacket::insertSilence(const uint8_t* data, uint8_t seqNo) /// Helper to insert DMR AMBE silence frames. /// /// -void VoicePacket::insertSilence(uint32_t count) +void Voice::insertSilence(uint32_t count) { uint8_t data[DMR_FRAME_LENGTH_BYTES + 2U]; diff --git a/dmr/packet/Voice.h b/dmr/packet/Voice.h new file mode 100644 index 00000000..94671106 --- /dev/null +++ b/dmr/packet/Voice.h @@ -0,0 +1,121 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +// +// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) +// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) +// +/* +* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2017-2021 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__DMR_PACKET_VOICE_H__) +#define __DMR_PACKET_VOICE_H__ + +#include "Defines.h" +#include "dmr/data/Data.h" +#include "dmr/data/EmbeddedData.h" +#include "dmr/lc/LC.h" +#include "dmr/lc/PrivacyLC.h" +#include "dmr/Slot.h" +#include "edac/AMBEFEC.h" +#include "network/BaseNetwork.h" +#include "lookups/RadioIdLookup.h" +#include "lookups/TalkgroupIdLookup.h" + +#include + +namespace dmr +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + namespace packet { class HOST_SW_API Data; } + class HOST_SW_API Slot; + + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements core logic for handling DMR voice packets. + // --------------------------------------------------------------------------- + + class HOST_SW_API Voice { + public: + /// Process a voice frame from the RF interface. + bool process(uint8_t* data, uint32_t len); + /// Process a voice frame from the network. + void processNetwork(const data::Data& dmrData); + + private: + friend class packet::Data; + friend class dmr::Slot; + Slot* m_slot; + + uint8_t* m_lastFrame; + bool m_lastFrameValid; + + uint8_t m_rfN; + uint8_t m_lastRfN; + uint8_t m_netN; + + data::EmbeddedData m_rfEmbeddedLC; + data::EmbeddedData* m_rfEmbeddedData; + uint32_t m_rfEmbeddedReadN; + uint32_t m_rfEmbeddedWriteN; + + data::EmbeddedData m_netEmbeddedLC; + data::EmbeddedData* m_netEmbeddedData; + uint32_t m_netEmbeddedReadN; + uint32_t m_netEmbeddedWriteN; + + uint8_t m_rfTalkerId; + uint8_t m_netTalkerId; + + edac::AMBEFEC m_fec; + + bool m_embeddedLCOnly; + bool m_dumpTAData; + + bool m_verbose; + bool m_debug; + + /// Initializes a new instance of the Voice class. + Voice(Slot* slot, network::BaseNetwork* network, bool embeddedLCOnly, bool dumpTAData, bool debug, bool verbose); + /// Finalizes a instance of the Voice class. + ~Voice(); + + /// + void logGPSPosition(const uint32_t srcId, const uint8_t* data); + + /// Helper to insert AMBE null frames for missing audio. + void insertNullAudio(uint8_t* data); + /// Helper to insert DMR AMBE silence frames. + bool insertSilence(const uint8_t* data, uint8_t seqNo); + /// Helper to insert DMR AMBE silence frames. + void insertSilence(uint32_t count); + }; + } // namespace packet +} // namespace dmr + +#endif // __DMR_PACKET_VOICE_H__ diff --git a/p25/Control.cpp b/p25/Control.cpp index 1d6356f0..fb8547a1 100644 --- a/p25/Control.cpp +++ b/p25/Control.cpp @@ -32,8 +32,8 @@ #include "p25/P25Defines.h" #include "p25/Control.h" #include "p25/acl/AccessControl.h" -#include "p25/dfsi/DFSITrunkPacket.h" -#include "p25/dfsi/DFSIVoicePacket.h" +#include "p25/dfsi/packet/DFSITrunk.h" +#include "p25/dfsi/packet/DFSIVoice.h" #include "p25/P25Utils.h" #include "p25/Sync.h" #include "edac/CRC.h" @@ -42,6 +42,7 @@ #include "Utils.h" using namespace p25; +using namespace p25::packet; #include #include @@ -147,18 +148,18 @@ Control::Control(uint32_t nac, uint32_t callHang, uint32_t queueSize, modem::Mod #if ENABLE_DFSI_SUPPORT if (m_modem->isP25DFSI()) { LogMessage(LOG_P25, "DFSI protocol mode is enabled."); - m_voice = new dfsi::DFSIVoicePacket(this, network, debug, verbose); - m_trunk = new dfsi::DFSITrunkPacket(this, network, dumpTSBKData, debug, verbose); + m_voice = new dfsi::packet::DFSIVoice(this, network, debug, verbose); + m_trunk = new dfsi::packet::DFSITrunk(this, network, dumpTSBKData, debug, verbose); } else { - m_voice = new VoicePacket(this, network, debug, verbose); - m_trunk = new TrunkPacket(this, network, dumpTSBKData, debug, verbose); - m_data = new DataPacket(this, network, dumpPDUData, repeatPDU, debug, verbose); + m_voice = new Voice(this, network, debug, verbose); + m_trunk = new Trunk(this, network, dumpTSBKData, debug, verbose); + m_data = new Data(this, network, dumpPDUData, repeatPDU, debug, verbose); } #else - m_voice = new VoicePacket(this, network, debug, verbose); - m_trunk = new TrunkPacket(this, network, dumpTSBKData, debug, verbose); - m_data = new DataPacket(this, network, dumpPDUData, repeatPDU, debug, verbose); + m_voice = new Voice(this, network, debug, verbose); + m_trunk = new Trunk(this, network, dumpTSBKData, debug, verbose); + m_data = new Data(this, network, dumpPDUData, repeatPDU, debug, verbose); #endif } diff --git a/p25/Control.h b/p25/Control.h index 07496fe8..e695da2b 100644 --- a/p25/Control.h +++ b/p25/Control.h @@ -32,9 +32,9 @@ #define __P25_CONTROL_H__ #include "Defines.h" -#include "p25/TrunkPacket.h" -#include "p25/DataPacket.h" -#include "p25/VoicePacket.h" +#include "p25/packet/Trunk.h" +#include "p25/packet/Data.h" +#include "p25/packet/Voice.h" #include "p25/NID.h" #include "p25/SiteData.h" #include "network/BaseNetwork.h" @@ -56,11 +56,11 @@ namespace p25 // Class Prototypes // --------------------------------------------------------------------------- - class HOST_SW_API VoicePacket; - namespace dfsi { class HOST_SW_API DFSIVoicePacket; } - class HOST_SW_API DataPacket; - class HOST_SW_API TrunkPacket; - namespace dfsi { class HOST_SW_API DFSITrunkPacket; } + namespace packet { class HOST_SW_API Voice; } + namespace dfsi::packet { class HOST_SW_API DFSIVoice; } + namespace packet { class HOST_SW_API Data; } + namespace packet { class HOST_SW_API Trunk; } + namespace dfsi::packet { class HOST_SW_API DFSITrunk; } // --------------------------------------------------------------------------- // Class Declaration @@ -110,21 +110,21 @@ namespace p25 /// Gets instance of the NID class. NID nid() { return m_nid; } - /// Gets instance of the TrunkPacket class. - TrunkPacket* trunk() { return m_trunk; } + /// Gets instance of the Trunk class. + packet::Trunk* trunk() { return m_trunk; } /// Helper to change the debug and verbose state. void setDebugVerbose(bool debug, bool verbose); private: - friend class VoicePacket; - friend class dfsi::DFSIVoicePacket; - VoicePacket* m_voice; - friend class DataPacket; - DataPacket* m_data; - friend class TrunkPacket; - friend class dfsi::DFSITrunkPacket; - TrunkPacket* m_trunk; + friend class packet::Voice; + friend class dfsi::packet::DFSIVoice; + packet::Voice* m_voice; + friend class packet::Data; + packet::Data* m_data; + friend class packet::Trunk; + friend class dfsi::packet::DFSITrunk; + packet::Trunk* m_trunk; uint32_t m_nac; uint32_t m_txNAC; diff --git a/p25/DataPacket.h b/p25/DataPacket.h deleted file mode 100644 index b321f8a8..00000000 --- a/p25/DataPacket.h +++ /dev/null @@ -1,137 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__P25_DATA_PACKET_H__) -#define __P25_DATA_PACKET_H__ - -#include "Defines.h" -#include "p25/data/DataBlock.h" -#include "p25/data/DataHeader.h" -#include "p25/data/LowSpeedData.h" -#include "p25/lc/LC.h" -#include "p25/Control.h" -#include "network/BaseNetwork.h" -#include "Timer.h" - -#include -#include -#include - -namespace p25 -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API Control; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements handling logic for P25 data packets. - // --------------------------------------------------------------------------- - - class HOST_SW_API DataPacket { - public: - /// Resets the data states for the RF interface. - void resetRF(); - - /// Process a data frame from the RF interface. - bool process(uint8_t* data, uint32_t len); - /// Process a data frame from the network. - bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); - - /// Helper to check if a logical link ID has registered with data services. - bool hasLLIdFNEReg(uint32_t llId) const; - - /// Updates the processor by the passed number of milliseconds. - void clock(uint32_t ms); - - private: - friend class Control; - Control* m_p25; - - network::BaseNetwork* m_network; - - RPT_RF_STATE m_prevRfState; - - data::DataBlock* m_rfData; - data::DataHeader m_rfDataHeader; - data::DataHeader m_rfSecondHeader; - bool m_rfUseSecondHeader; - uint8_t m_rfDataBlockCnt; - uint8_t* m_rfPDU; - uint32_t m_rfPDUCount; - uint32_t m_rfPDUBits; - - data::DataBlock* m_netData; - data::DataHeader m_netDataHeader; - data::DataHeader m_netSecondHeader; - bool m_netUseSecondHeader; - uint32_t m_netDataOffset; - uint8_t m_netDataBlockCnt; - uint8_t* m_netPDU; - uint32_t m_netPDUCount; - - uint8_t* m_pduUserData; - uint32_t m_pduUserDataLength; - - std::unordered_map m_fneRegTable; - - std::unordered_map m_connQueueTable; - std::unordered_map m_connTimerTable; - - bool m_dumpPDUData; - bool m_repeatPDU; - - bool m_verbose; - bool m_debug; - - /// Initializes a new instance of the DataPacket class. - DataPacket(Control* p25, network::BaseNetwork* network, bool dumpPDUData, bool repeatPDU, bool debug, bool verbose); - /// Finalizes a instance of the DataPacket class. - ~DataPacket(); - - /// Write data processed from RF to the network. - void writeNetwork(const uint8_t currentBlock, const uint8_t* data, uint32_t len); - - /// Helper to write a P25 PDU packet. - void writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNulls = false); - /// Helper to write a network P25 PDU packet. - void writeNet_PDU_Buffered(); - /// Helper to re-write a received P25 PDU packet. - void writeRF_PDU_Buffered(); - /// Helper to write a PDU registration response. - void writeRF_PDU_Reg_Response(uint8_t regType, uint32_t llId, ulong64_t ipAddr); - /// Helper to write a PDU acknowledge response. - void writeRF_PDU_Ack_Response(uint8_t ackClass, uint8_t ackType, uint32_t llId, bool noNulls = false); - }; -} // namespace p25 - -#endif // __P25_DATA_PACKET_H__ diff --git a/p25/TrunkPacket.h b/p25/TrunkPacket.h deleted file mode 100644 index bd509d69..00000000 --- a/p25/TrunkPacket.h +++ /dev/null @@ -1,241 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -/* -* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__P25_TRUNK_PACKET_H__) -#define __P25_TRUNK_PACKET_H__ - -#include "Defines.h" -#include "p25/data/DataHeader.h" -#include "p25/data/DataBlock.h" -#include "p25/lc/TSBK.h" -#include "p25/lc/TDULC.h" -#include "p25/Control.h" -#include "network/BaseNetwork.h" -#include "network/RemoteControl.h" -#include "Timer.h" - -#include -#include -#include -#include - -namespace p25 -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API VoicePacket; - namespace dfsi { class HOST_SW_API DFSIVoicePacket; } - class HOST_SW_API DataPacket; - class HOST_SW_API Control; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements handling logic for P25 trunking packets. - // --------------------------------------------------------------------------- - - class HOST_SW_API TrunkPacket { - public: - /// Resets the data states for the RF interface. - virtual void resetRF(); - /// Resets the data states for the network. - virtual void resetNet(); - - /// Process a data frame from the RF interface. - virtual bool process(uint8_t* data, uint32_t len, bool preDecoded = false); - /// Process a data frame from the network. - virtual bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); - - /// Helper used to process AMBTs from PDU data. - bool processMBT(data::DataHeader dataHeader, data::DataBlock* blocks); - - /// Helper to write P25 adjacent site information to the network. - void writeAdjSSNetwork(); - - /// Helper to determine if the source ID has affiliated to the group destination ID. - bool hasSrcIdGrpAff(uint32_t srcId, uint32_t dstId) const; - /// Helper to determine if the source ID has unit registered. - bool hasSrcIdUnitReg(uint32_t srcId) const; - - /// Helper to determine if the channel number is busy. - bool isChBusy(uint32_t chNo) const; - /// Helper to determine if the destination ID is already granted. - bool hasDstIdGranted(uint32_t dstId) const; - /// Helper to start the destination ID grant timer. - void touchDstIdGrant(uint32_t dstId); - /// Helper to release the channel grant for the destination ID. - void releaseDstIdGrant(uint32_t dstId, bool releaseAll); - /// Helper to release group affiliations. - void clearGrpAff(uint32_t dstId, bool releaseAll); - - /// Updates the processor by the passed number of milliseconds. - void clock(uint32_t ms); - - /// Helper to set the TSBK manufacturer ID. - void setMFId(uint8_t val) { m_rfTSBK.setMFId(val); } - /// Helper to write a call alert packet. - void writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId); - /// Helper to write a extended function packet. - void writeRF_TSDU_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId); - /// Helper to write a group affiliation query packet. - void writeRF_TSDU_Grp_Aff_Q(uint32_t dstId); - /// Helper to write a unit registration command packet. - void writeRF_TSDU_U_Reg_Cmd(uint32_t dstId); - - /// Helper to write a Motorola patch packet. - void writeRF_TSDU_Mot_Patch(uint32_t group1, uint32_t group2, uint32_t group3); - - /// Helper to change the conventional fallback state. - void setConvFallback(bool fallback); - - /// Helper to change the TSBK verbose state. - void setTSBKVerbose(bool verbose); - - protected: - friend class VoicePacket; - friend class dfsi::DFSIVoicePacket; - friend class DataPacket; - friend class Control; - Control* m_p25; - - network::BaseNetwork* m_network; - - uint32_t m_patchSuperGroup; - - bool m_verifyAff; - bool m_verifyReg; - - lc::TSBK m_rfTSBK; - lc::TSBK m_netTSBK; - uint8_t* m_rfMBF; - uint8_t m_mbfCnt; - - uint8_t m_mbfIdenCnt; - uint8_t m_mbfAdjSSCnt; - uint8_t m_mbfSCCBCnt; - uint8_t m_mbfGrpGrntCnt; - - std::vector m_voiceChTable; - - std::unordered_map m_adjSiteTable; - std::unordered_map m_adjSiteUpdateCnt; - - std::unordered_map m_sccbTable; - std::unordered_map m_sccbUpdateCnt; - - std::vector m_unitRegTable; - std::unordered_map m_grpAffTable; - - std::unordered_map m_grantChTable; - std::unordered_map m_grantTimers; - - uint8_t m_voiceChCnt; - uint8_t m_voiceGrantChCnt; - - bool m_noStatusAck; - bool m_noMessageAck; - bool m_unitToUnitAvailCheck; - - uint8_t m_convFallbackPacketDelay; - bool m_convFallback; - - Timer m_adjSiteUpdateTimer; - uint32_t m_adjSiteUpdateInterval; - - bool m_ctrlTSDUMBF; - - bool m_sndcpChGrant; - - bool m_dumpTSBK; - - bool m_verbose; - bool m_debug; - - /// Initializes a new instance of the TrunkPacket class. - TrunkPacket(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose); - /// Finalizes a instance of the TrunkPacket class. - virtual ~TrunkPacket(); - - /// Write data processed from RF to the network. - void writeNetworkRF(const uint8_t* data, bool autoReset); - - /// Helper to write control channel packet data. - void writeRF_ControlData(uint8_t frameCnt, uint8_t n, bool adjSS); - - /// Helper to write a P25 TDU w/ link control packet. - void writeRF_TDULC(lc::TDULC lc, bool noNetwork); - /// Helper to write a P25 TDU w/ link control channel release packet. - void writeRF_TDULC_ChanRelease(bool grp, uint32_t srcId, uint32_t dstId); - - /// Helper to write a single-block P25 TSDU packet. - virtual void writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite = false, bool force = false); - /// Helper to write a multi-block (3-block) P25 TSDU packet. - void writeRF_TSDU_MBF(bool clearBeforeWrite = false); - - /// Helper to generate the given control TSBK into the TSDU frame queue. - void queueRF_TSBK_Ctrl(uint8_t lco); - - /// Helper to write a grant packet. - bool writeRF_TSDU_Grant(bool grp, bool skip = false, bool net = false, bool skipNetCheck = false); - /// Helper to write a SNDCP grant packet. - bool writeRF_TSDU_SNDCP_Grant(bool skip = false, bool net = false); - /// Helper to write a unit to unit answer request packet. - void writeRF_TSDU_UU_Ans_Req(uint32_t srcId, uint32_t dstId); - /// Helper to write a acknowledge packet. - void writeRF_TSDU_ACK_FNE(uint32_t srcId, uint32_t service, bool extended, bool noActivityLog); - /// Helper to write a deny packet. - void writeRF_TSDU_Deny(uint8_t reason, uint8_t service); - /// Helper to write a group affiliation response packet. - bool writeRF_TSDU_Grp_Aff_Rsp(uint32_t srcId, uint32_t dstId); - /// Helper to write a unit registration response packet. - void writeRF_TSDU_U_Reg_Rsp(uint32_t srcId); - /// Helper to write a unit de-registration acknowledge packet. - void writeRF_TSDU_U_Dereg_Ack(uint32_t srcId); - /// Helper to write a queue packet. - void writeRF_TSDU_Queue(uint8_t reason, uint8_t service); - /// Helper to write a location registration response packet. - bool writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId); - - /// Helper to write a call termination packet. - bool writeNet_TSDU_Call_Term(uint32_t srcId, uint32_t dstId); - - /// Helper to write a network TSDU from the RF data queue. - void writeNet_TSDU_From_RF(uint8_t* data); - - /// Helper to write a network P25 TDU w/ link control packet. - virtual void writeNet_TDULC(lc::TDULC lc); - /// Helper to write a network single-block P25 TSDU packet. - virtual void writeNet_TSDU(); - - /// Helper to automatically inhibit a source ID on a denial. - void denialInhibit(uint32_t srcId); - - /// Helper to add the idle status bits on P25 frame data. - void addIdleBits(uint8_t* data, uint32_t length, bool b1, bool b2); - }; -} // namespace p25 - -#endif // __P25_TRUNK_PACKET_H__ diff --git a/p25/VoicePacket.h b/p25/VoicePacket.h deleted file mode 100644 index f2974768..00000000 --- a/p25/VoicePacket.h +++ /dev/null @@ -1,144 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__P25_VOICE_PACKET_H__) -#define __P25_VOICE_PACKET_H__ - -#include "Defines.h" -#include "p25/data/LowSpeedData.h" -#include "p25/dfsi/LC.h" -#include "p25/lc/LC.h" -#include "p25/Control.h" -#include "p25/Audio.h" -#include "network/BaseNetwork.h" - -#include -#include - -namespace p25 -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API TrunkPacket; - class HOST_SW_API Control; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements handling logic for P25 voice packets. - // --------------------------------------------------------------------------- - - class HOST_SW_API VoicePacket { - public: - /// Resets the data states for the RF interface. - virtual void resetRF(); - /// Resets the data states for the network. - virtual void resetNet(); - - /// Process a data frame from the RF interface. - virtual bool process(uint8_t* data, uint32_t len); - /// Process a data frame from the network. - virtual bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); - - protected: - friend class TrunkPacket; - friend class Control; - Control* m_p25; - - network::BaseNetwork* m_network; - - uint32_t m_rfFrames; - uint32_t m_rfBits; - uint32_t m_rfErrs; - uint32_t m_rfUndecodableLC; - uint32_t m_netFrames; - uint32_t m_netLost; - - Audio m_audio; - - lc::LC m_rfLC; - lc::LC m_rfLastHDU; - lc::LC m_rfLastLDU1; - lc::LC m_rfLastLDU2; - - lc::LC m_netLC; - lc::LC m_netLastLDU1; - - data::LowSpeedData m_rfLSD; - data::LowSpeedData m_netLSD; - - dfsi::LC m_dfsiLC; - uint8_t* m_netLDU1; - uint8_t* m_netLDU2; - - uint8_t m_lastDUID; - uint8_t* m_lastIMBE; - - bool m_hadVoice; - uint32_t m_lastRejectId; - - uint32_t m_silenceThreshold; - - uint8_t m_vocLDU1Count; - - bool m_verbose; - bool m_debug; - - /// Initializes a new instance of the VoicePacket class. - VoicePacket(Control* p25, network::BaseNetwork* network, bool debug, bool verbose); - /// Finalizes a instance of the VoicePacket class. - virtual ~VoicePacket(); - - /// Write data processed from RF to the network. - void writeNetwork(const uint8_t* data, uint8_t duid); - - /// Helper to write end of voice frame data. - void writeRF_EndOfVoice(); - - /// Helper to write a network P25 TDU packet. - virtual void writeNet_TDU(); - /// Helper to check for an unflushed LDU1 packet. - void checkNet_LDU1(); - /// Helper to write a network P25 LDU1 packet. - virtual void writeNet_LDU1(); - /// Helper to check for an unflushed LDU2 packet. - void checkNet_LDU2(); - /// Helper to write a network P25 LDU1 packet. - virtual void writeNet_LDU2(); - - /// Helper to insert IMBE silence frames for missing audio. - void insertMissingAudio(uint8_t* data); - /// Helper to insert IMBE null frames for missing audio. - void insertNullAudio(uint8_t* data); - }; -} // namespace p25 - -#endif // __P25_VOICE_PACKET_H__ diff --git a/p25/dfsi/DFSITrunkPacket.h b/p25/dfsi/DFSITrunkPacket.h deleted file mode 100644 index 436276fc..00000000 --- a/p25/dfsi/DFSITrunkPacket.h +++ /dev/null @@ -1,94 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -/* -* Copyright (C) 2022 by Bryan Biedenkapp N2PLL -* -* 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. -*/ -#if !defined(__P25_DFSI_TRUNK_PACKET_H__) -#define __P25_DFSI_TRUNK_PACKET_H__ - -#include "Defines.h" -#include "p25/dfsi/LC.h" -#include "p25/TrunkPacket.h" -#include "p25/Control.h" -#include "network/BaseNetwork.h" - -namespace p25 -{ - // --------------------------------------------------------------------------- - // Class Prototypes - // --------------------------------------------------------------------------- - - class HOST_SW_API TrunkPacket; - class HOST_SW_API Control; - - namespace dfsi - { - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements handling logic for P25 trunking packets using - // the DFSI protocol instead of the P25 OTA protocol. - // --------------------------------------------------------------------------- - - class HOST_SW_API DFSITrunkPacket : public TrunkPacket { - public: - /// Resets the data states for the RF interface. - virtual void resetRF(); - /// Resets the data states for the network. - virtual void resetNet(); - - /// Process a data frame from the RF interface. - virtual bool process(uint8_t* data, uint32_t len, bool preDecoded = false); - - protected: - LC m_rfDFSILC; - LC m_netDFSILC; - - /// Initializes a new instance of the DFSITrunkPacket class. - DFSITrunkPacket(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose); - /// Finalizes a instance of the DFSITrunkPacket class. - virtual ~DFSITrunkPacket(); - - /// Helper to write a P25 TDU w/ link control packet. - virtual void writeRF_TDULC(lc::TDULC lc, bool noNetwork); - - /// Helper to write a single-block P25 TSDU packet. - virtual void writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite = false, bool force = false); - - /// Helper to write a network P25 TDU w/ link control packet. - //virtual void writeNet_TDULC(lc::TDULC lc); - /// Helper to write a network single-block P25 TSDU packet. - virtual void writeNet_TSDU(); - - /// Helper to write start DFSI data. - void writeRF_DFSI_Start(uint8_t type); - /// Helper to write stop DFSI data. - void writeRF_DSFI_Stop(uint8_t type); - - private: - friend class DFSIVoicePacket; - friend class p25::Control; - }; - } // namespace dfsi -} // namespace p25 - -#endif // __P25_DFSI_TRUNK_PACKET_H__ diff --git a/p25/dfsi/DFSITrunkPacket.cpp b/p25/dfsi/packet/DFSITrunk.cpp similarity index 87% rename from p25/dfsi/DFSITrunkPacket.cpp rename to p25/dfsi/packet/DFSITrunk.cpp index 301ad89d..868f06aa 100644 --- a/p25/dfsi/DFSITrunkPacket.cpp +++ b/p25/dfsi/packet/DFSITrunk.cpp @@ -26,7 +26,7 @@ #include "Defines.h" #include "p25/P25Defines.h" #include "p25/dfsi/DFSIDefines.h" -#include "p25/dfsi/DFSITrunkPacket.h" +#include "p25/dfsi/packet/DFSITrunk.h" #include "p25/P25Utils.h" #include "p25/Sync.h" #include "Log.h" @@ -34,6 +34,7 @@ using namespace p25; using namespace p25::dfsi; +using namespace p25::dfsi::packet; // --------------------------------------------------------------------------- // Public Class Members @@ -42,9 +43,9 @@ using namespace p25::dfsi; /// /// Resets the data states for the RF interface. /// -void DFSITrunkPacket::resetRF() +void DFSITrunk::resetRF() { - TrunkPacket::resetRF(); + Trunk::resetRF(); LC lc = LC(); m_rfDFSILC = lc; } @@ -52,9 +53,9 @@ void DFSITrunkPacket::resetRF() /// /// Resets the data states for the network. /// -void DFSITrunkPacket::resetNet() +void DFSITrunk::resetNet() { - TrunkPacket::resetNet(); + Trunk::resetNet(); LC lc = LC(); m_netDFSILC = lc; } @@ -66,7 +67,7 @@ void DFSITrunkPacket::resetNet() /// Length of data frame. /// Flag indicating the TSBK data is pre-decoded TSBK data. /// -bool DFSITrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) +bool DFSITrunk::process(uint8_t* data, uint32_t len, bool preDecoded) { assert(data != NULL); @@ -77,7 +78,7 @@ bool DFSITrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) return false; if (preDecoded) { - return TrunkPacket::process(data + 2U, len, preDecoded); + return Trunk::process(data + 2U, len, preDecoded); } else { resetRF(); @@ -85,7 +86,7 @@ bool DFSITrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) if (m_rfDFSILC.decodeTSBK(data + 2U)) { m_rfTSBK = m_rfDFSILC.tsbk(); - return TrunkPacket::process(tsbk, P25_TSBK_LENGTH_BYTES, true); + return Trunk::process(tsbk, P25_TSBK_LENGTH_BYTES, true); } } @@ -97,23 +98,23 @@ bool DFSITrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the DFSITrunkPacket class. +/// Initializes a new instance of the DFSITrunk class. /// /// Instance of the Control class. /// Instance of the BaseNetwork class. /// Flag indicating whether TSBK data is dumped to the log. /// Flag indicating whether P25 debug is enabled. /// Flag indicating whether P25 verbose logging is enabled. -DFSITrunkPacket::DFSITrunkPacket(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose) : - TrunkPacket(p25, network, dumpTSBKData, debug, verbose) +DFSITrunk::DFSITrunk(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose) : + Trunk(p25, network, dumpTSBKData, debug, verbose) { /* stub */ } /// -/// Finalizes a instance of the DFSITrunkPacket class. +/// Finalizes a instance of the DFSITrunk class. /// -DFSITrunkPacket::~DFSITrunkPacket() +DFSITrunk::~DFSITrunk() { /* stub */ } @@ -123,7 +124,7 @@ DFSITrunkPacket::~DFSITrunkPacket() /// /// /// -void DFSITrunkPacket::writeRF_TDULC(lc::TDULC lc, bool noNetwork) +void DFSITrunk::writeRF_TDULC(lc::TDULC lc, bool noNetwork) { // for now this is ignored... } @@ -134,7 +135,7 @@ void DFSITrunkPacket::writeRF_TDULC(lc::TDULC lc, bool noNetwork) /// /// /// -void DFSITrunkPacket::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool force) +void DFSITrunk::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool force) { if (!m_p25->m_control) return; @@ -199,7 +200,7 @@ void DFSITrunkPacket::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bo /// /// Helper to write a network single-block P25 TSDU packet. /// -void DFSITrunkPacket::writeNet_TSDU() +void DFSITrunk::writeNet_TSDU() { uint8_t buffer[P25_DFSI_TSBK_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_DFSI_TSBK_FRAME_LENGTH_BYTES + 2U); @@ -221,7 +222,7 @@ void DFSITrunkPacket::writeNet_TSDU() /// Helper to write start DFSI data. /// /// -void DFSITrunkPacket::writeRF_DFSI_Start(uint8_t type) +void DFSITrunk::writeRF_DFSI_Start(uint8_t type) { uint8_t buffer[P25_DFSI_SS_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_DFSI_SS_FRAME_LENGTH_BYTES + 2U); @@ -244,7 +245,7 @@ void DFSITrunkPacket::writeRF_DFSI_Start(uint8_t type) /// Helper to write stop DFSI data. /// /// -void DFSITrunkPacket::writeRF_DSFI_Stop(uint8_t type) +void DFSITrunk::writeRF_DSFI_Stop(uint8_t type) { uint8_t buffer[P25_DFSI_SS_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_DFSI_SS_FRAME_LENGTH_BYTES + 2U); diff --git a/p25/dfsi/packet/DFSITrunk.h b/p25/dfsi/packet/DFSITrunk.h new file mode 100644 index 00000000..ec249f10 --- /dev/null +++ b/p25/dfsi/packet/DFSITrunk.h @@ -0,0 +1,97 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +/* +* Copyright (C) 2022 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__P25_DFSI_PACKET_TRUNK_H__) +#define __P25_DFSI_PACKET_TRUNK_H__ + +#include "Defines.h" +#include "p25/dfsi/LC.h" +#include "p25/packet/Trunk.h" +#include "p25/Control.h" +#include "network/BaseNetwork.h" + +namespace p25 +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + namespace packet { class HOST_SW_API Trunk; } + class HOST_SW_API Control; + + namespace dfsi + { + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements handling logic for P25 trunking packets using + // the DFSI protocol instead of the P25 OTA protocol. + // --------------------------------------------------------------------------- + + class HOST_SW_API DFSITrunk : public p25::packet::Trunk { + public: + /// Resets the data states for the RF interface. + virtual void resetRF(); + /// Resets the data states for the network. + virtual void resetNet(); + + /// Process a data frame from the RF interface. + virtual bool process(uint8_t* data, uint32_t len, bool preDecoded = false); + + protected: + LC m_rfDFSILC; + LC m_netDFSILC; + + /// Initializes a new instance of the DFSITrunk class. + DFSITrunk(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose); + /// Finalizes a instance of the DFSITrunk class. + virtual ~DFSITrunk(); + + /// Helper to write a P25 TDU w/ link control packet. + virtual void writeRF_TDULC(lc::TDULC lc, bool noNetwork); + + /// Helper to write a single-block P25 TSDU packet. + virtual void writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite = false, bool force = false); + + /// Helper to write a network P25 TDU w/ link control packet. + //virtual void writeNet_TDULC(lc::TDULC lc); + /// Helper to write a network single-block P25 TSDU packet. + virtual void writeNet_TSDU(); + + /// Helper to write start DFSI data. + void writeRF_DFSI_Start(uint8_t type); + /// Helper to write stop DFSI data. + void writeRF_DSFI_Stop(uint8_t type); + + private: + friend class packet::DFSIVoice; + friend class p25::Control; + }; + } // namespace packet + } // namespace dfsi +} // namespace p25 + +#endif // __P25_DFSI_PACKET_TRUNK_H__ diff --git a/p25/dfsi/DFSIVoicePacket.cpp b/p25/dfsi/packet/DFSIVoice.cpp similarity index 98% rename from p25/dfsi/DFSIVoicePacket.cpp rename to p25/dfsi/packet/DFSIVoice.cpp index fbde1a78..e9b8e7a0 100644 --- a/p25/dfsi/DFSIVoicePacket.cpp +++ b/p25/dfsi/packet/DFSIVoice.cpp @@ -31,7 +31,7 @@ #include "p25/P25Defines.h" #include "p25/acl/AccessControl.h" #include "p25/dfsi/DFSIDefines.h" -#include "p25/dfsi/DFSIVoicePacket.h" +#include "p25/dfsi/packet/DFSIVoice.h" #include "p25/P25Utils.h" #include "p25/Sync.h" #include "HostMain.h" @@ -40,6 +40,7 @@ using namespace p25; using namespace p25::dfsi; +using namespace p25::dfsi::packet; // --------------------------------------------------------------------------- // Constants @@ -54,9 +55,9 @@ const uint32_t VOC_LDU1_COUNT = 3U; /// /// Resets the data states for the RF interface. /// -void DFSIVoicePacket::resetRF() +void DFSIVoice::resetRF() { - VoicePacket::resetRF(); + Voice::resetRF(); LC lc = LC(); m_rfDFSILC = lc; @@ -65,9 +66,9 @@ void DFSIVoicePacket::resetRF() /// /// Resets the data states for the network. /// -void DFSIVoicePacket::resetNet() +void DFSIVoice::resetNet() { - VoicePacket::resetNet(); + Voice::resetNet(); LC lc = LC(); m_netDFSILC = lc; @@ -79,7 +80,7 @@ void DFSIVoicePacket::resetNet() /// Buffer containing data frame. /// Length of data frame. /// -bool DFSIVoicePacket::process(uint8_t* data, uint32_t len) +bool DFSIVoice::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -632,7 +633,7 @@ bool DFSIVoicePacket::process(uint8_t* data, uint32_t len) /// /// /// -bool DFSIVoicePacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) +bool DFSIVoice::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) { uint32_t count = 0U; @@ -791,14 +792,14 @@ bool DFSIVoicePacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& contro // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the DFSIVoicePacket class. +/// Initializes a new instance of the DFSIVoice class. /// /// Instance of the Control class. /// Instance of the BaseNetwork class. /// Flag indicating whether P25 debug is enabled. /// Flag indicating whether P25 verbose logging is enabled. -DFSIVoicePacket::DFSIVoicePacket(Control* p25, network::BaseNetwork* network, bool debug, bool verbose) : - VoicePacket(p25, network, debug, verbose), +DFSIVoice::DFSIVoice(Control* p25, network::BaseNetwork* network, bool debug, bool verbose) : + Voice(p25, network, debug, verbose), m_trunk(NULL), m_rfDFSILC(), m_netDFSILC(), @@ -812,13 +813,13 @@ DFSIVoicePacket::DFSIVoicePacket(Control* p25, network::BaseNetwork* network, bo ::memset(m_dfsiLDU2, 0x00U, 9U * 25U); // hmmm...this should hopefully be a safe cast...right? - m_trunk = (DFSITrunkPacket *)p25->m_trunk; + m_trunk = (DFSITrunk *)p25->m_trunk; } /// -/// Finalizes a instance of the DFSIVoicePacket class. +/// Finalizes a instance of the DFSIVoice class. /// -DFSIVoicePacket::~DFSIVoicePacket() +DFSIVoice::~DFSIVoice() { delete[] m_dfsiLDU1; delete[] m_dfsiLDU2; @@ -827,7 +828,7 @@ DFSIVoicePacket::~DFSIVoicePacket() /// /// Helper to write a network P25 TDU packet. /// -void DFSIVoicePacket::writeNet_TDU() +void DFSIVoice::writeNet_TDU() { if (m_p25->m_control) { m_p25->m_trunk->releaseDstIdGrant(m_netLC.getDstId(), false); @@ -866,7 +867,7 @@ void DFSIVoicePacket::writeNet_TDU() /// /// /// -void DFSIVoicePacket::writeNet_LDU1() +void DFSIVoice::writeNet_LDU1() { lc::LC control = lc::LC(m_dfsiLC.control()); data::LowSpeedData lsd = data::LowSpeedData(m_dfsiLC.lsd()); @@ -1161,7 +1162,7 @@ void DFSIVoicePacket::writeNet_LDU1() /// /// /// -void DFSIVoicePacket::writeNet_LDU2() +void DFSIVoice::writeNet_LDU2() { lc::LC control = lc::LC(m_dfsiLC.control()); data::LowSpeedData lsd = data::LowSpeedData(m_dfsiLC.lsd()); diff --git a/p25/dfsi/packet/DFSIVoice.h b/p25/dfsi/packet/DFSIVoice.h new file mode 100644 index 00000000..3223b97e --- /dev/null +++ b/p25/dfsi/packet/DFSIVoice.h @@ -0,0 +1,100 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +// +// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) +// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) +// +/* +* Copyright (C) 2022 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__P25_DFSI_PACKET_VOICE_H__) +#define __P25_DFSI_PACKET_VOICE_H__ + +#include "Defines.h" +#include "p25/dfsi/LC.h" +#include "p25/dfsi/packet/DFSITrunk.h" +#include "p25/packet/Trunk.h" +#include "p25/Control.h" +#include "network/BaseNetwork.h" + +namespace p25 +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + namespace packet { class HOST_SW_API Voice; } + class HOST_SW_API Control; + + namespace dfsi + { + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements handling logic for P25 voice packets using + // the DFSI protocol instead of the P25 OTA protocol. + // --------------------------------------------------------------------------- + + class HOST_SW_API DFSIVoice : public p25::packet::Voice { + public: + /// Resets the data states for the RF interface. + virtual void resetRF(); + /// Resets the data states for the network. + virtual void resetNet(); + + /// Process a data frame from the RF interface. + virtual bool process(uint8_t* data, uint32_t len); + /// Process a data frame from the network. + virtual bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); + + protected: + DFSITrunk* m_trunk; + + LC m_rfDFSILC; + LC m_netDFSILC; + + uint8_t* m_dfsiLDU1; + uint8_t* m_dfsiLDU2; + + /// Initializes a new instance of the DFSIVoice class. + DFSIVoice(Control* p25, network::BaseNetwork* network, bool debug, bool verbose); + /// Finalizes a instance of the DFSIVoice class. + virtual ~DFSIVoice(); + + /// Helper to write a network P25 TDU packet. + virtual void writeNet_TDU(); + /// Helper to write a network P25 LDU1 packet. + virtual void writeNet_LDU1(); + /// Helper to write a network P25 LDU1 packet. + virtual void writeNet_LDU2(); + + private: + friend class packet::DFSITrunk; + friend class p25::Control; + }; + } // namespace packet + } // namespace dfsi +} // namespace p25 + +#endif // __P25_DFSI_PACKET_VOICE_H__ diff --git a/p25/DataPacket.cpp b/p25/packet/Data.cpp similarity index 97% rename from p25/DataPacket.cpp rename to p25/packet/Data.cpp index 0f3ca9eb..c2ba23b7 100644 --- a/p25/DataPacket.cpp +++ b/p25/packet/Data.cpp @@ -30,7 +30,7 @@ */ #include "Defines.h" #include "p25/P25Defines.h" -#include "p25/DataPacket.h" +#include "p25/packet/Data.h" #include "p25/acl/AccessControl.h" #include "p25/P25Utils.h" #include "p25/Sync.h" @@ -41,6 +41,7 @@ using namespace p25; using namespace p25::data; +using namespace p25::packet; #include #include @@ -60,7 +61,7 @@ const uint32_t CONN_WAIT_TIMEOUT = 1U; /// /// Resets the data states for the RF interface. /// -void DataPacket::resetRF() +void Data::resetRF() { m_rfDataBlockCnt = 0U; m_rfPDUCount = 0U; @@ -75,7 +76,7 @@ void DataPacket::resetRF() /// Buffer containing data frame. /// Length of data frame. /// -bool DataPacket::process(uint8_t* data, uint32_t len) +bool Data::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -383,7 +384,7 @@ bool DataPacket::process(uint8_t* data, uint32_t len) /// /// /// -bool DataPacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) +bool Data::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) { if (m_p25->m_rfState != RS_RF_LISTENING && m_p25->m_netState == RS_NET_IDLE) return false; @@ -489,7 +490,7 @@ bool DataPacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, da /// /// Logical Link ID. /// True, if ID has registered, otherwise false. -bool DataPacket::hasLLIdFNEReg(uint32_t llId) const +bool Data::hasLLIdFNEReg(uint32_t llId) const { // lookup dynamic FNE registration table entry try { @@ -509,7 +510,7 @@ bool DataPacket::hasLLIdFNEReg(uint32_t llId) const /// Updates the processor by the passed number of milliseconds. /// /// -void DataPacket::clock(uint32_t ms) +void Data::clock(uint32_t ms) { // clock all the connect timers std::vector connToClear = std::vector(); @@ -554,7 +555,7 @@ void DataPacket::clock(uint32_t ms) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the DataPacket class. +/// Initializes a new instance of the Data class. /// /// Instance of the Control class. /// Instance of the BaseNetwork class. @@ -562,7 +563,7 @@ void DataPacket::clock(uint32_t ms) /// /// Flag indicating whether P25 debug is enabled. /// Flag indicating whether P25 verbose logging is enabled. -DataPacket::DataPacket(Control* p25, network::BaseNetwork* network, bool dumpPDUData, bool repeatPDU, bool debug, bool verbose) : +Data::Data(Control* p25, network::BaseNetwork* network, bool dumpPDUData, bool repeatPDU, bool debug, bool verbose) : m_p25(p25), m_network(network), m_prevRfState(RS_RF_LISTENING), @@ -611,9 +612,9 @@ DataPacket::DataPacket(Control* p25, network::BaseNetwork* network, bool dumpPDU } /// -/// Finalizes a instance of the DataPacket class. +/// Finalizes a instance of the Data class. /// -DataPacket::~DataPacket() +Data::~Data() { delete[] m_rfPDU; delete[] m_netPDU; @@ -626,7 +627,7 @@ DataPacket::~DataPacket() /// /// /// -void DataPacket::writeNetwork(const uint8_t currentBlock, const uint8_t *data, uint32_t len) +void Data::writeNetwork(const uint8_t currentBlock, const uint8_t *data, uint32_t len) { assert(data != NULL); @@ -646,7 +647,7 @@ void DataPacket::writeNetwork(const uint8_t currentBlock, const uint8_t *data, u /// /// /// This simply takes data packed into m_rfPDU and transmits it. -void DataPacket::writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNulls) +void Data::writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNulls) { assert(pdu != NULL); assert(bitLength > 0U); @@ -690,7 +691,7 @@ void DataPacket::writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNull /// Helper to write a network P25 PDU packet. /// /// This will take buffered network PDU data and repeat it over the air. -void DataPacket::writeNet_PDU_Buffered() +void Data::writeNet_PDU_Buffered() { uint32_t bitLength = ((m_netDataHeader.getBlocksToFollow() + 1U) * P25_PDU_FEC_LENGTH_BITS) + P25_PREAMBLE_LENGTH_BITS; uint32_t offset = P25_PREAMBLE_LENGTH_BITS; @@ -741,7 +742,7 @@ void DataPacket::writeNet_PDU_Buffered() /// Helper to re-write a received P25 PDU packet. /// /// This will take buffered received PDU data and repeat it over the air. -void DataPacket::writeRF_PDU_Buffered() +void Data::writeRF_PDU_Buffered() { uint32_t bitLength = ((m_rfDataHeader.getBlocksToFollow() + 1U) * P25_PDU_FEC_LENGTH_BITS) + P25_PREAMBLE_LENGTH_BITS; uint32_t offset = P25_PREAMBLE_LENGTH_BITS; @@ -794,7 +795,7 @@ void DataPacket::writeRF_PDU_Buffered() /// /// /// -void DataPacket::writeRF_PDU_Reg_Response(uint8_t regType, uint32_t llId, ulong64_t ipAddr) +void Data::writeRF_PDU_Reg_Response(uint8_t regType, uint32_t llId, ulong64_t ipAddr) { if ((regType != PDU_REG_TYPE_RSP_ACCPT) && (regType != PDU_REG_TYPE_RSP_DENY)) return; @@ -859,7 +860,7 @@ void DataPacket::writeRF_PDU_Reg_Response(uint8_t regType, uint32_t llId, ulong6 /// /// /// -void DataPacket::writeRF_PDU_Ack_Response(uint8_t ackClass, uint8_t ackType, uint32_t llId, bool noNulls) +void Data::writeRF_PDU_Ack_Response(uint8_t ackClass, uint8_t ackType, uint32_t llId, bool noNulls) { if (ackClass == PDU_ACK_CLASS_ACK && ackType != PDU_ACK_TYPE_ACK) return; diff --git a/p25/packet/Data.h b/p25/packet/Data.h new file mode 100644 index 00000000..193fdfe0 --- /dev/null +++ b/p25/packet/Data.h @@ -0,0 +1,140 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +// +// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) +// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) +// +/* +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__P25_PACKET_DATA_H__) +#define __P25_PACKET_DATA_H__ + +#include "Defines.h" +#include "p25/data/DataBlock.h" +#include "p25/data/DataHeader.h" +#include "p25/data/LowSpeedData.h" +#include "p25/lc/LC.h" +#include "p25/Control.h" +#include "network/BaseNetwork.h" +#include "Timer.h" + +#include +#include +#include + +namespace p25 +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + class HOST_SW_API Control; + + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements handling logic for P25 data packets. + // --------------------------------------------------------------------------- + + class HOST_SW_API Data { + public: + /// Resets the data states for the RF interface. + void resetRF(); + + /// Process a data frame from the RF interface. + bool process(uint8_t* data, uint32_t len); + /// Process a data frame from the network. + bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); + + /// Helper to check if a logical link ID has registered with data services. + bool hasLLIdFNEReg(uint32_t llId) const; + + /// Updates the processor by the passed number of milliseconds. + void clock(uint32_t ms); + + private: + friend class p25::Control; + Control* m_p25; + + network::BaseNetwork* m_network; + + RPT_RF_STATE m_prevRfState; + + data::DataBlock* m_rfData; + data::DataHeader m_rfDataHeader; + data::DataHeader m_rfSecondHeader; + bool m_rfUseSecondHeader; + uint8_t m_rfDataBlockCnt; + uint8_t* m_rfPDU; + uint32_t m_rfPDUCount; + uint32_t m_rfPDUBits; + + data::DataBlock* m_netData; + data::DataHeader m_netDataHeader; + data::DataHeader m_netSecondHeader; + bool m_netUseSecondHeader; + uint32_t m_netDataOffset; + uint8_t m_netDataBlockCnt; + uint8_t* m_netPDU; + uint32_t m_netPDUCount; + + uint8_t* m_pduUserData; + uint32_t m_pduUserDataLength; + + std::unordered_map m_fneRegTable; + + std::unordered_map m_connQueueTable; + std::unordered_map m_connTimerTable; + + bool m_dumpPDUData; + bool m_repeatPDU; + + bool m_verbose; + bool m_debug; + + /// Initializes a new instance of the Data class. + Data(Control* p25, network::BaseNetwork* network, bool dumpPDUData, bool repeatPDU, bool debug, bool verbose); + /// Finalizes a instance of the Data class. + ~Data(); + + /// Write data processed from RF to the network. + void writeNetwork(const uint8_t currentBlock, const uint8_t* data, uint32_t len); + + /// Helper to write a P25 PDU packet. + void writeRF_PDU(const uint8_t* pdu, uint32_t bitLength, bool noNulls = false); + /// Helper to write a network P25 PDU packet. + void writeNet_PDU_Buffered(); + /// Helper to re-write a received P25 PDU packet. + void writeRF_PDU_Buffered(); + /// Helper to write a PDU registration response. + void writeRF_PDU_Reg_Response(uint8_t regType, uint32_t llId, ulong64_t ipAddr); + /// Helper to write a PDU acknowledge response. + void writeRF_PDU_Ack_Response(uint8_t ackClass, uint8_t ackType, uint32_t llId, bool noNulls = false); + }; + } // namespace packet +} // namespace p25 + +#endif // __P25_PACKET_DATA_H__ diff --git a/p25/TrunkPacket.cpp b/p25/packet/Trunk.cpp similarity index 96% rename from p25/TrunkPacket.cpp rename to p25/packet/Trunk.cpp index 5e686426..f38732e3 100644 --- a/p25/TrunkPacket.cpp +++ b/p25/packet/Trunk.cpp @@ -25,7 +25,7 @@ */ #include "Defines.h" #include "p25/P25Defines.h" -#include "p25/TrunkPacket.h" +#include "p25/packet/Trunk.h" #include "p25/acl/AccessControl.h" #include "p25/P25Utils.h" #include "p25/Sync.h" @@ -35,6 +35,7 @@ using namespace p25; using namespace p25::data; +using namespace p25::packet; #include #include @@ -141,7 +142,7 @@ const uint8_t CONV_FALLBACK_PACKET_DELAY = 8U; /// /// Resets the data states for the RF interface. /// -void TrunkPacket::resetRF() +void Trunk::resetRF() { lc::TSBK tsbk = lc::TSBK(m_p25->m_siteData, m_p25->m_idenEntry, m_dumpTSBK); m_rfTSBK = tsbk; @@ -150,7 +151,7 @@ void TrunkPacket::resetRF() /// /// Resets the data states for the network. /// -void TrunkPacket::resetNet() +void Trunk::resetNet() { lc::TSBK tsbk = lc::TSBK(m_p25->m_siteData, m_p25->m_idenEntry, m_dumpTSBK); m_netTSBK = tsbk; @@ -163,7 +164,7 @@ void TrunkPacket::resetNet() /// Length of data frame. /// Flag indicating the TSBK data is pre-decoded TSBK data. /// -bool TrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) +bool Trunk::process(uint8_t* data, uint32_t len, bool preDecoded) { assert(data != NULL); @@ -527,7 +528,7 @@ bool TrunkPacket::process(uint8_t* data, uint32_t len, bool preDecoded) /// /// /// -bool TrunkPacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) +bool Trunk::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) { if (!m_p25->m_control) return false; @@ -794,7 +795,7 @@ bool TrunkPacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, d /// /// /// -bool TrunkPacket::processMBT(DataHeader dataHeader, DataBlock* blocks) +bool Trunk::processMBT(DataHeader dataHeader, DataBlock* blocks) { uint8_t data[1U]; ::memset(data, 0x00U, 1U); @@ -807,7 +808,7 @@ bool TrunkPacket::processMBT(DataHeader dataHeader, DataBlock* blocks) uint8_t raw[P25_PDU_UNCONFIRMED_LENGTH_BYTES]; uint32_t len = blocks[i].getData(raw); if (len != P25_PDU_UNCONFIRMED_LENGTH_BYTES) { - LogError(LOG_P25, "TrunkPacket::processMBT(), failed to read PDU data block"); + LogError(LOG_P25, "Trunk::processMBT(), failed to read PDU data block"); blockRead = false; } @@ -827,7 +828,7 @@ bool TrunkPacket::processMBT(DataHeader dataHeader, DataBlock* blocks) /// /// Helper to write P25 adjacent site information to the network. /// -void TrunkPacket::writeAdjSSNetwork() +void Trunk::writeAdjSSNetwork() { if (!m_p25->m_control) { return; @@ -867,7 +868,7 @@ void TrunkPacket::writeAdjSSNetwork() /// /// /// -bool TrunkPacket::hasSrcIdGrpAff(uint32_t srcId, uint32_t dstId) const +bool Trunk::hasSrcIdGrpAff(uint32_t srcId, uint32_t dstId) const { // lookup dynamic affiliation table entry try { @@ -888,7 +889,7 @@ bool TrunkPacket::hasSrcIdGrpAff(uint32_t srcId, uint32_t dstId) const /// /// /// -bool TrunkPacket::hasSrcIdUnitReg(uint32_t srcId) const +bool Trunk::hasSrcIdUnitReg(uint32_t srcId) const { // lookup dynamic unit registration table entry if (std::find(m_unitRegTable.begin(), m_unitRegTable.end(), srcId) != m_unitRegTable.end()) { @@ -904,7 +905,7 @@ bool TrunkPacket::hasSrcIdUnitReg(uint32_t srcId) const /// /// /// -bool TrunkPacket::isChBusy(uint32_t chNo) const +bool Trunk::isChBusy(uint32_t chNo) const { if (chNo == 0U) { return false; @@ -925,7 +926,7 @@ bool TrunkPacket::isChBusy(uint32_t chNo) const /// /// /// -bool TrunkPacket::hasDstIdGranted(uint32_t dstId) const +bool Trunk::hasDstIdGranted(uint32_t dstId) const { if (dstId == 0U) { return false; @@ -950,7 +951,7 @@ bool TrunkPacket::hasDstIdGranted(uint32_t dstId) const /// /// /// -void TrunkPacket::touchDstIdGrant(uint32_t dstId) +void Trunk::touchDstIdGrant(uint32_t dstId) { if (dstId == 0U) { return; @@ -966,7 +967,7 @@ void TrunkPacket::touchDstIdGrant(uint32_t dstId) /// /// /// -void TrunkPacket::releaseDstIdGrant(uint32_t dstId, bool releaseAll) +void Trunk::releaseDstIdGrant(uint32_t dstId, bool releaseAll) { if (dstId == 0U && !releaseAll) { return; @@ -1018,7 +1019,7 @@ void TrunkPacket::releaseDstIdGrant(uint32_t dstId, bool releaseAll) /// /// /// -void TrunkPacket::clearGrpAff(uint32_t dstId, bool releaseAll) +void Trunk::clearGrpAff(uint32_t dstId, bool releaseAll) { if (dstId == 0U && !releaseAll) { return; @@ -1053,7 +1054,7 @@ void TrunkPacket::clearGrpAff(uint32_t dstId, bool releaseAll) /// Updates the processor by the passed number of milliseconds. /// /// -void TrunkPacket::clock(uint32_t ms) +void Trunk::clock(uint32_t ms) { if (m_p25->m_control) { if (m_p25->m_network != NULL) { @@ -1140,7 +1141,7 @@ void TrunkPacket::clock(uint32_t ms) /// /// /// -void TrunkPacket::writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId) +void Trunk::writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId) { if (m_verbose) { LogMessage(LOG_RF, P25_TSDU_STR ", TSBK_IOSP_CALL_ALRT (Call Alert), srcId = %u, dstId = %u", srcId, dstId); @@ -1160,7 +1161,7 @@ void TrunkPacket::writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId) /// /// /// -void TrunkPacket::writeRF_TSDU_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId) +void Trunk::writeRF_TSDU_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId) { uint8_t lco = m_rfTSBK.getLCO(); uint8_t mfId = m_rfTSBK.getMFId(); @@ -1198,7 +1199,7 @@ void TrunkPacket::writeRF_TSDU_Ext_Func(uint32_t func, uint32_t arg, uint32_t ds /// Helper to write a group affiliation query packet. /// /// -void TrunkPacket::writeRF_TSDU_Grp_Aff_Q(uint32_t dstId) +void Trunk::writeRF_TSDU_Grp_Aff_Q(uint32_t dstId) { if (m_verbose) { LogMessage(LOG_RF, P25_TSDU_STR ", TSBK_OSP_GRP_AFF_Q (Group Affiliation Query), dstId = %u", dstId); @@ -1216,7 +1217,7 @@ void TrunkPacket::writeRF_TSDU_Grp_Aff_Q(uint32_t dstId) /// Helper to write a unit registration command packet. /// /// -void TrunkPacket::writeRF_TSDU_U_Reg_Cmd(uint32_t dstId) +void Trunk::writeRF_TSDU_U_Reg_Cmd(uint32_t dstId) { if (m_verbose) { LogMessage(LOG_RF, P25_TSDU_STR ", TSBK_OSP_U_REG_CMD (Unit Registration Command), dstId = %u", dstId); @@ -1236,7 +1237,7 @@ void TrunkPacket::writeRF_TSDU_U_Reg_Cmd(uint32_t dstId) /// /// /// -void TrunkPacket::writeRF_TSDU_Mot_Patch(uint32_t group1, uint32_t group2, uint32_t group3) +void Trunk::writeRF_TSDU_Mot_Patch(uint32_t group1, uint32_t group2, uint32_t group3) { uint8_t lco = m_rfTSBK.getLCO(); @@ -1261,7 +1262,7 @@ void TrunkPacket::writeRF_TSDU_Mot_Patch(uint32_t group1, uint32_t group2, uint3 /// Helper to change the conventional fallback state. /// /// Flag indicating whether conventional fallback is enabled. -void TrunkPacket::setConvFallback(bool fallback) +void Trunk::setConvFallback(bool fallback) { m_convFallback = fallback; if (m_convFallback && m_p25->m_control) { @@ -1284,7 +1285,7 @@ void TrunkPacket::setConvFallback(bool fallback) /// Helper to change the TSBK verbose state. /// /// Flag indicating whether TSBK dumping is enabled. -void TrunkPacket::setTSBKVerbose(bool verbose) +void Trunk::setTSBKVerbose(bool verbose) { m_dumpTSBK = verbose; } @@ -1294,14 +1295,14 @@ void TrunkPacket::setTSBKVerbose(bool verbose) // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the TrunkPacket class. +/// Initializes a new instance of the Trunk class. /// /// Instance of the Control class. /// Instance of the BaseNetwork class. /// Flag indicating whether TSBK data is dumped to the log. /// Flag indicating whether P25 debug is enabled. /// Flag indicating whether P25 verbose logging is enabled. -TrunkPacket::TrunkPacket(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose) : +Trunk::Trunk(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose) : m_p25(p25), m_network(network), m_patchSuperGroup(0xFFFFU), @@ -1362,9 +1363,9 @@ TrunkPacket::TrunkPacket(Control* p25, network::BaseNetwork* network, bool dumpT } /// -/// Finalizes a instance of the TrunkPacket class. +/// Finalizes a instance of the Trunk class. /// -TrunkPacket::~TrunkPacket() +Trunk::~Trunk() { delete[] m_rfMBF; } @@ -1374,7 +1375,7 @@ TrunkPacket::~TrunkPacket() /// /// /// -void TrunkPacket::writeNetworkRF(const uint8_t* data, bool autoReset) +void Trunk::writeNetworkRF(const uint8_t* data, bool autoReset) { assert(data != NULL); @@ -1395,7 +1396,7 @@ void TrunkPacket::writeNetworkRF(const uint8_t* data, bool autoReset) /// /// /// -void TrunkPacket::writeRF_ControlData(uint8_t frameCnt, uint8_t n, bool adjSS) +void Trunk::writeRF_ControlData(uint8_t frameCnt, uint8_t n, bool adjSS) { if (!m_p25->m_control) return; @@ -1525,7 +1526,7 @@ void TrunkPacket::writeRF_ControlData(uint8_t frameCnt, uint8_t n, bool adjSS) /// /// /// -void TrunkPacket::writeRF_TDULC(lc::TDULC lc, bool noNetwork) +void Trunk::writeRF_TDULC(lc::TDULC lc, bool noNetwork) { uint8_t data[P25_TDULC_FRAME_LENGTH_BYTES + 2U]; ::memset(data + 2U, 0x00U, P25_TDULC_FRAME_LENGTH_BYTES); @@ -1565,7 +1566,7 @@ void TrunkPacket::writeRF_TDULC(lc::TDULC lc, bool noNetwork) /// /// /// -void TrunkPacket::writeRF_TDULC_ChanRelease(bool grp, uint32_t srcId, uint32_t dstId) +void Trunk::writeRF_TDULC_ChanRelease(bool grp, uint32_t srcId, uint32_t dstId) { if (!m_p25->m_duplex) { return; @@ -1616,7 +1617,7 @@ void TrunkPacket::writeRF_TDULC_ChanRelease(bool grp, uint32_t srcId, uint32_t d /// /// /// -void TrunkPacket::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool force) +void Trunk::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool force) { if (!m_p25->m_control) return; @@ -1680,7 +1681,7 @@ void TrunkPacket::writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite, bool f /// Helper to write a multi-block (3-block) P25 TSDU packet. /// /// -void TrunkPacket::writeRF_TSDU_MBF(bool clearBeforeWrite) +void Trunk::writeRF_TSDU_MBF(bool clearBeforeWrite) { if (!m_p25->m_control) { ::memset(m_rfMBF, 0x00U, P25_MAX_PDU_COUNT * P25_LDU_FRAME_LENGTH_BYTES + 2U); @@ -1798,7 +1799,7 @@ void TrunkPacket::writeRF_TSDU_MBF(bool clearBeforeWrite) /// Helper to generate the given control TSBK into the TSDU frame queue. /// /// -void TrunkPacket::queueRF_TSBK_Ctrl(uint8_t lco) +void Trunk::queueRF_TSBK_Ctrl(uint8_t lco) { if (!m_p25->m_control) return; @@ -2044,7 +2045,7 @@ void TrunkPacket::queueRF_TSBK_Ctrl(uint8_t lco) /// /// /// -bool TrunkPacket::writeRF_TSDU_Grant(bool grp, bool skip, bool net, bool skipNetCheck) +bool Trunk::writeRF_TSDU_Grant(bool grp, bool skip, bool net, bool skipNetCheck) { uint8_t lco = m_rfTSBK.getLCO(); @@ -2193,7 +2194,7 @@ bool TrunkPacket::writeRF_TSDU_Grant(bool grp, bool skip, bool net, bool skipNet /// /// /// -bool TrunkPacket::writeRF_TSDU_SNDCP_Grant(bool skip, bool net) +bool Trunk::writeRF_TSDU_SNDCP_Grant(bool skip, bool net) { uint8_t lco = m_rfTSBK.getLCO(); @@ -2276,7 +2277,7 @@ bool TrunkPacket::writeRF_TSDU_SNDCP_Grant(bool skip, bool net) /// /// /// -void TrunkPacket::writeRF_TSDU_UU_Ans_Req(uint32_t srcId, uint32_t dstId) +void Trunk::writeRF_TSDU_UU_Ans_Req(uint32_t srcId, uint32_t dstId) { uint8_t lco = m_rfTSBK.getLCO(); @@ -2300,7 +2301,7 @@ void TrunkPacket::writeRF_TSDU_UU_Ans_Req(uint32_t srcId, uint32_t dstId) /// /// /// -void TrunkPacket::writeRF_TSDU_ACK_FNE(uint32_t srcId, uint32_t service, bool extended, bool noNetwork) +void Trunk::writeRF_TSDU_ACK_FNE(uint32_t srcId, uint32_t service, bool extended, bool noNetwork) { uint8_t lco = m_rfTSBK.getLCO(); uint8_t mfId = m_rfTSBK.getMFId(); @@ -2333,7 +2334,7 @@ void TrunkPacket::writeRF_TSDU_ACK_FNE(uint32_t srcId, uint32_t service, bool ex /// /// /// -void TrunkPacket::writeRF_TSDU_Deny(uint8_t reason, uint8_t service) +void Trunk::writeRF_TSDU_Deny(uint8_t reason, uint8_t service) { uint8_t lco = m_rfTSBK.getLCO(); uint32_t srcId = m_rfTSBK.getSrcId(); @@ -2359,7 +2360,7 @@ void TrunkPacket::writeRF_TSDU_Deny(uint8_t reason, uint8_t service) /// /// /// -bool TrunkPacket::writeRF_TSDU_Grp_Aff_Rsp(uint32_t srcId, uint32_t dstId) +bool Trunk::writeRF_TSDU_Grp_Aff_Rsp(uint32_t srcId, uint32_t dstId) { bool ret = false; @@ -2416,7 +2417,7 @@ bool TrunkPacket::writeRF_TSDU_Grp_Aff_Rsp(uint32_t srcId, uint32_t dstId) /// Helper to write a unit registration response packet. /// /// -void TrunkPacket::writeRF_TSDU_U_Reg_Rsp(uint32_t srcId) +void Trunk::writeRF_TSDU_U_Reg_Rsp(uint32_t srcId) { m_rfTSBK.setLCO(TSBK_IOSP_U_REG); m_rfTSBK.setResponse(P25_RSP_ACCEPT); @@ -2464,7 +2465,7 @@ void TrunkPacket::writeRF_TSDU_U_Reg_Rsp(uint32_t srcId) /// Helper to write a unit de-registration acknowledge packet. /// /// -void TrunkPacket::writeRF_TSDU_U_Dereg_Ack(uint32_t srcId) +void Trunk::writeRF_TSDU_U_Dereg_Ack(uint32_t srcId) { bool dereged = false; @@ -2510,7 +2511,7 @@ void TrunkPacket::writeRF_TSDU_U_Dereg_Ack(uint32_t srcId) /// /// /// -void TrunkPacket::writeRF_TSDU_Queue(uint8_t reason, uint8_t service) +void Trunk::writeRF_TSDU_Queue(uint8_t reason, uint8_t service) { uint8_t lco = m_rfTSBK.getLCO(); uint32_t srcId = m_rfTSBK.getSrcId(); @@ -2536,7 +2537,7 @@ void TrunkPacket::writeRF_TSDU_Queue(uint8_t reason, uint8_t service) /// /// /// -bool TrunkPacket::writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId) +bool Trunk::writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId) { bool ret = false; @@ -2593,7 +2594,7 @@ bool TrunkPacket::writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId) /// /// /// -bool TrunkPacket::writeNet_TSDU_Call_Term(uint32_t srcId, uint32_t dstId) +bool Trunk::writeNet_TSDU_Call_Term(uint32_t srcId, uint32_t dstId) { bool ret = false; @@ -2612,7 +2613,7 @@ bool TrunkPacket::writeNet_TSDU_Call_Term(uint32_t srcId, uint32_t dstId) /// Helper to write a network TSDU from the RF data queue. /// /// -void TrunkPacket::writeNet_TSDU_From_RF(uint8_t* data) +void Trunk::writeNet_TSDU_From_RF(uint8_t* data) { ::memset(data, 0x00U, P25_TSDU_FRAME_LENGTH_BYTES); @@ -2637,7 +2638,7 @@ void TrunkPacket::writeNet_TSDU_From_RF(uint8_t* data) /// Helper to write a network P25 TDU w/ link control packet. /// /// -void TrunkPacket::writeNet_TDULC(lc::TDULC lc) +void Trunk::writeNet_TDULC(lc::TDULC lc) { uint8_t buffer[P25_TDULC_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_TDULC_FRAME_LENGTH_BYTES + 2U); @@ -2683,7 +2684,7 @@ void TrunkPacket::writeNet_TDULC(lc::TDULC lc) /// /// Helper to write a network single-block P25 TSDU packet. /// -void TrunkPacket::writeNet_TSDU() +void Trunk::writeNet_TSDU() { uint8_t buffer[P25_TSDU_FRAME_LENGTH_BYTES + 2U]; ::memset(buffer, 0x00U, P25_TSDU_FRAME_LENGTH_BYTES + 2U); @@ -2717,7 +2718,7 @@ void TrunkPacket::writeNet_TSDU() /// Helper to automatically inhibit a source ID on a denial. /// /// -void TrunkPacket::denialInhibit(uint32_t srcId) +void Trunk::denialInhibit(uint32_t srcId) { if (!m_p25->m_inhibitIllegal) { return; @@ -2737,7 +2738,7 @@ void TrunkPacket::denialInhibit(uint32_t srcId) /// /// /// -void TrunkPacket::addIdleBits(uint8_t* data, uint32_t length, bool b1, bool b2) +void Trunk::addIdleBits(uint8_t* data, uint32_t length, bool b1, bool b2) { assert(data != NULL); diff --git a/p25/packet/Trunk.h b/p25/packet/Trunk.h new file mode 100644 index 00000000..467df014 --- /dev/null +++ b/p25/packet/Trunk.h @@ -0,0 +1,244 @@ +/** +* Digital Voice Modem - Host Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software +* +*/ +/* +* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL +* +* 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. +*/ +#if !defined(__P25_PACKET_TRUNK_H__) +#define __P25_PACKET_TRUNK_H__ + +#include "Defines.h" +#include "p25/data/DataHeader.h" +#include "p25/data/DataBlock.h" +#include "p25/lc/TSBK.h" +#include "p25/lc/TDULC.h" +#include "p25/Control.h" +#include "network/BaseNetwork.h" +#include "network/RemoteControl.h" +#include "Timer.h" + +#include +#include +#include +#include + +namespace p25 +{ + // --------------------------------------------------------------------------- + // Class Prototypes + // --------------------------------------------------------------------------- + + namespace packet { class HOST_SW_API Voice; } + namespace dfsi::packet { class HOST_SW_API DFSIVoice; } + namespace packet { class HOST_SW_API Data; } + class HOST_SW_API Control; + + namespace packet + { + // --------------------------------------------------------------------------- + // Class Declaration + // This class implements handling logic for P25 trunking packets. + // --------------------------------------------------------------------------- + + class HOST_SW_API Trunk { + public: + /// Resets the data states for the RF interface. + virtual void resetRF(); + /// Resets the data states for the network. + virtual void resetNet(); + + /// Process a data frame from the RF interface. + virtual bool process(uint8_t* data, uint32_t len, bool preDecoded = false); + /// Process a data frame from the network. + virtual bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); + + /// Helper used to process AMBTs from PDU data. + bool processMBT(data::DataHeader dataHeader, data::DataBlock* blocks); + + /// Helper to write P25 adjacent site information to the network. + void writeAdjSSNetwork(); + + /// Helper to determine if the source ID has affiliated to the group destination ID. + bool hasSrcIdGrpAff(uint32_t srcId, uint32_t dstId) const; + /// Helper to determine if the source ID has unit registered. + bool hasSrcIdUnitReg(uint32_t srcId) const; + + /// Helper to determine if the channel number is busy. + bool isChBusy(uint32_t chNo) const; + /// Helper to determine if the destination ID is already granted. + bool hasDstIdGranted(uint32_t dstId) const; + /// Helper to start the destination ID grant timer. + void touchDstIdGrant(uint32_t dstId); + /// Helper to release the channel grant for the destination ID. + void releaseDstIdGrant(uint32_t dstId, bool releaseAll); + /// Helper to release group affiliations. + void clearGrpAff(uint32_t dstId, bool releaseAll); + + /// Updates the processor by the passed number of milliseconds. + void clock(uint32_t ms); + + /// Helper to set the TSBK manufacturer ID. + void setMFId(uint8_t val) { m_rfTSBK.setMFId(val); } + /// Helper to write a call alert packet. + void writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId); + /// Helper to write a extended function packet. + void writeRF_TSDU_Ext_Func(uint32_t func, uint32_t arg, uint32_t dstId); + /// Helper to write a group affiliation query packet. + void writeRF_TSDU_Grp_Aff_Q(uint32_t dstId); + /// Helper to write a unit registration command packet. + void writeRF_TSDU_U_Reg_Cmd(uint32_t dstId); + + /// Helper to write a Motorola patch packet. + void writeRF_TSDU_Mot_Patch(uint32_t group1, uint32_t group2, uint32_t group3); + + /// Helper to change the conventional fallback state. + void setConvFallback(bool fallback); + + /// Helper to change the TSBK verbose state. + void setTSBKVerbose(bool verbose); + + protected: + friend class packet::Voice; + friend class dfsi::packet::DFSIVoice; + friend class packet::Data; + friend class p25::Control; + Control* m_p25; + + network::BaseNetwork* m_network; + + uint32_t m_patchSuperGroup; + + bool m_verifyAff; + bool m_verifyReg; + + lc::TSBK m_rfTSBK; + lc::TSBK m_netTSBK; + uint8_t* m_rfMBF; + uint8_t m_mbfCnt; + + uint8_t m_mbfIdenCnt; + uint8_t m_mbfAdjSSCnt; + uint8_t m_mbfSCCBCnt; + uint8_t m_mbfGrpGrntCnt; + + std::vector m_voiceChTable; + + std::unordered_map m_adjSiteTable; + std::unordered_map m_adjSiteUpdateCnt; + + std::unordered_map m_sccbTable; + std::unordered_map m_sccbUpdateCnt; + + std::vector m_unitRegTable; + std::unordered_map m_grpAffTable; + + std::unordered_map m_grantChTable; + std::unordered_map m_grantTimers; + + uint8_t m_voiceChCnt; + uint8_t m_voiceGrantChCnt; + + bool m_noStatusAck; + bool m_noMessageAck; + bool m_unitToUnitAvailCheck; + + uint8_t m_convFallbackPacketDelay; + bool m_convFallback; + + Timer m_adjSiteUpdateTimer; + uint32_t m_adjSiteUpdateInterval; + + bool m_ctrlTSDUMBF; + + bool m_sndcpChGrant; + + bool m_dumpTSBK; + + bool m_verbose; + bool m_debug; + + /// Initializes a new instance of the Trunk class. + Trunk(Control* p25, network::BaseNetwork* network, bool dumpTSBKData, bool debug, bool verbose); + /// Finalizes a instance of the Trunk class. + virtual ~Trunk(); + + /// Write data processed from RF to the network. + void writeNetworkRF(const uint8_t* data, bool autoReset); + + /// Helper to write control channel packet data. + void writeRF_ControlData(uint8_t frameCnt, uint8_t n, bool adjSS); + + /// Helper to write a P25 TDU w/ link control packet. + void writeRF_TDULC(lc::TDULC lc, bool noNetwork); + /// Helper to write a P25 TDU w/ link control channel release packet. + void writeRF_TDULC_ChanRelease(bool grp, uint32_t srcId, uint32_t dstId); + + /// Helper to write a single-block P25 TSDU packet. + virtual void writeRF_TSDU_SBF(bool noNetwork, bool clearBeforeWrite = false, bool force = false); + /// Helper to write a multi-block (3-block) P25 TSDU packet. + void writeRF_TSDU_MBF(bool clearBeforeWrite = false); + + /// Helper to generate the given control TSBK into the TSDU frame queue. + void queueRF_TSBK_Ctrl(uint8_t lco); + + /// Helper to write a grant packet. + bool writeRF_TSDU_Grant(bool grp, bool skip = false, bool net = false, bool skipNetCheck = false); + /// Helper to write a SNDCP grant packet. + bool writeRF_TSDU_SNDCP_Grant(bool skip = false, bool net = false); + /// Helper to write a unit to unit answer request packet. + void writeRF_TSDU_UU_Ans_Req(uint32_t srcId, uint32_t dstId); + /// Helper to write a acknowledge packet. + void writeRF_TSDU_ACK_FNE(uint32_t srcId, uint32_t service, bool extended, bool noActivityLog); + /// Helper to write a deny packet. + void writeRF_TSDU_Deny(uint8_t reason, uint8_t service); + /// Helper to write a group affiliation response packet. + bool writeRF_TSDU_Grp_Aff_Rsp(uint32_t srcId, uint32_t dstId); + /// Helper to write a unit registration response packet. + void writeRF_TSDU_U_Reg_Rsp(uint32_t srcId); + /// Helper to write a unit de-registration acknowledge packet. + void writeRF_TSDU_U_Dereg_Ack(uint32_t srcId); + /// Helper to write a queue packet. + void writeRF_TSDU_Queue(uint8_t reason, uint8_t service); + /// Helper to write a location registration response packet. + bool writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId); + + /// Helper to write a call termination packet. + bool writeNet_TSDU_Call_Term(uint32_t srcId, uint32_t dstId); + + /// Helper to write a network TSDU from the RF data queue. + void writeNet_TSDU_From_RF(uint8_t* data); + + /// Helper to write a network P25 TDU w/ link control packet. + virtual void writeNet_TDULC(lc::TDULC lc); + /// Helper to write a network single-block P25 TSDU packet. + virtual void writeNet_TSDU(); + + /// Helper to automatically inhibit a source ID on a denial. + void denialInhibit(uint32_t srcId); + + /// Helper to add the idle status bits on P25 frame data. + void addIdleBits(uint8_t* data, uint32_t length, bool b1, bool b2); + }; + } // namespace packet +} // namespace p25 + +#endif // __P25_PACKET_TRUNK_H__ diff --git a/p25/VoicePacket.cpp b/p25/packet/Voice.cpp similarity index 98% rename from p25/VoicePacket.cpp rename to p25/packet/Voice.cpp index 74162536..b6b835f7 100644 --- a/p25/VoicePacket.cpp +++ b/p25/packet/Voice.cpp @@ -30,7 +30,7 @@ */ #include "Defines.h" #include "p25/P25Defines.h" -#include "p25/VoicePacket.h" +#include "p25/packet/Voice.h" #include "p25/acl/AccessControl.h" #include "p25/dfsi/DFSIDefines.h" #include "p25/P25Utils.h" @@ -41,6 +41,7 @@ #include "Utils.h" using namespace p25; +using namespace p25::packet; #include #include @@ -60,7 +61,7 @@ const uint32_t VOC_LDU1_COUNT = 3U; /// /// Resets the data states for the RF interface. /// -void VoicePacket::resetRF() +void Voice::resetRF() { lc::LC lc = lc::LC(m_p25->m_siteData); @@ -79,7 +80,7 @@ void VoicePacket::resetRF() /// /// Resets the data states for the network. /// -void VoicePacket::resetNet() +void Voice::resetNet() { lc::LC lc = lc::LC(m_p25->m_siteData); @@ -97,7 +98,7 @@ void VoicePacket::resetNet() /// Buffer containing data frame. /// Length of data frame. /// -bool VoicePacket::process(uint8_t* data, uint32_t len) +bool Voice::process(uint8_t* data, uint32_t len) { assert(data != NULL); @@ -689,7 +690,7 @@ bool VoicePacket::process(uint8_t* data, uint32_t len) /// /// /// -bool VoicePacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) +bool Voice::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid) { uint32_t count = 0U; @@ -848,13 +849,13 @@ bool VoicePacket::processNetwork(uint8_t* data, uint32_t len, lc::LC& control, d // --------------------------------------------------------------------------- /// -/// Initializes a new instance of the VoicePacket class. +/// Initializes a new instance of the Voice class. /// /// Instance of the Control class. /// Instance of the BaseNetwork class. /// Flag indicating whether P25 debug is enabled. /// Flag indicating whether P25 verbose logging is enabled. -VoicePacket::VoicePacket(Control* p25, network::BaseNetwork* network, bool debug, bool verbose) : +Voice::Voice(Control* p25, network::BaseNetwork* network, bool debug, bool verbose) : m_p25(p25), m_network(network), m_rfFrames(0U), @@ -895,9 +896,9 @@ VoicePacket::VoicePacket(Control* p25, network::BaseNetwork* network, bool debug } /// -/// Finalizes a instance of the VoicePacket class. +/// Finalizes a instance of the Voice class. /// -VoicePacket::~VoicePacket() +Voice::~Voice() { delete[] m_netLDU1; delete[] m_netLDU2; @@ -909,7 +910,7 @@ VoicePacket::~VoicePacket() /// /// /// -void VoicePacket::writeNetwork(const uint8_t *data, uint8_t duid) +void Voice::writeNetwork(const uint8_t *data, uint8_t duid) { assert(data != NULL); @@ -943,7 +944,7 @@ void VoicePacket::writeNetwork(const uint8_t *data, uint8_t duid) /// Helper to write end of frame data. /// /// -void VoicePacket::writeRF_EndOfVoice() +void Voice::writeRF_EndOfVoice() { if (!m_hadVoice) { return; @@ -963,7 +964,7 @@ void VoicePacket::writeRF_EndOfVoice() /// /// Helper to write a network P25 TDU packet. /// -void VoicePacket::writeNet_TDU() +void Voice::writeNet_TDU() { if (m_p25->m_control) { m_p25->m_trunk->releaseDstIdGrant(m_netLC.getDstId(), false); @@ -1017,7 +1018,7 @@ void VoicePacket::writeNet_TDU() /// /// /// -void VoicePacket::checkNet_LDU1() +void Voice::checkNet_LDU1() { if (m_p25->m_netState == RS_NET_IDLE) return; @@ -1034,7 +1035,7 @@ void VoicePacket::checkNet_LDU1() /// /// /// -void VoicePacket::writeNet_LDU1() +void Voice::writeNet_LDU1() { lc::LC control = lc::LC(m_dfsiLC.control()); data::LowSpeedData lsd = data::LowSpeedData(m_dfsiLC.lsd()); @@ -1308,7 +1309,7 @@ void VoicePacket::writeNet_LDU1() /// /// /// -void VoicePacket::checkNet_LDU2() +void Voice::checkNet_LDU2() { if (m_p25->m_netState == RS_NET_IDLE) return; @@ -1325,7 +1326,7 @@ void VoicePacket::checkNet_LDU2() /// /// /// -void VoicePacket::writeNet_LDU2() +void Voice::writeNet_LDU2() { lc::LC control = lc::LC(m_dfsiLC.control()); data::LowSpeedData lsd = data::LowSpeedData(m_dfsiLC.lsd()); @@ -1411,7 +1412,7 @@ void VoicePacket::writeNet_LDU2() /// Helper to insert IMBE silence frames for missing audio. /// /// -void VoicePacket::insertMissingAudio(uint8_t* data) +void Voice::insertMissingAudio(uint8_t* data) { if (data[10U] == 0x00U) { ::memcpy(data + 10U, m_lastIMBE, 11U); @@ -1490,7 +1491,7 @@ void VoicePacket::insertMissingAudio(uint8_t* data) /// Helper to insert IMBE null frames for missing audio. /// /// -void VoicePacket::insertNullAudio(uint8_t* data) +void Voice::insertNullAudio(uint8_t* data) { if (data[0U] == 0x00U) { ::memcpy(data + 10U, P25_NULL_IMBE, 11U); diff --git a/p25/dfsi/DFSIVoicePacket.h b/p25/packet/Voice.h similarity index 53% rename from p25/dfsi/DFSIVoicePacket.h rename to p25/packet/Voice.h index 0d3c29a8..ef2c8031 100644 --- a/p25/dfsi/DFSIVoicePacket.h +++ b/p25/packet/Voice.h @@ -11,7 +11,8 @@ // Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) // /* -* Copyright (C) 2022 by Bryan Biedenkapp N2PLL +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2017-2022 by Bryan Biedenkapp N2PLL * * 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 @@ -27,34 +28,37 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if !defined(__P25_DFSI_VOICE_PACKET_H__) -#define __P25_DFSI_VOICE_PACKET_H__ +#if !defined(__P25_PACKET_VOICE_H__) +#define __P25_PACKET_VOICE_H__ #include "Defines.h" +#include "p25/data/LowSpeedData.h" #include "p25/dfsi/LC.h" -#include "p25/dfsi/DFSITrunkPacket.h" -#include "p25/TrunkPacket.h" +#include "p25/lc/LC.h" #include "p25/Control.h" +#include "p25/Audio.h" #include "network/BaseNetwork.h" +#include +#include + namespace p25 { // --------------------------------------------------------------------------- // Class Prototypes // --------------------------------------------------------------------------- - class HOST_SW_API VoicePacket; + namespace packet { class HOST_SW_API Trunk; } class HOST_SW_API Control; - namespace dfsi + namespace packet { // --------------------------------------------------------------------------- // Class Declaration - // This class implements handling logic for P25 voice packets using - // the DFSI protocol instead of the P25 OTA protocol. + // This class implements handling logic for P25 voice packets. // --------------------------------------------------------------------------- - class HOST_SW_API DFSIVoicePacket : public VoicePacket { + class HOST_SW_API Voice { public: /// Resets the data states for the RF interface. virtual void resetRF(); @@ -67,31 +71,77 @@ namespace p25 virtual bool processNetwork(uint8_t* data, uint32_t len, lc::LC& control, data::LowSpeedData& lsd, uint8_t& duid); protected: - DFSITrunkPacket* m_trunk; + friend class packet::Trunk; + friend class p25::Control; + Control* m_p25; + + network::BaseNetwork* m_network; + + uint32_t m_rfFrames; + uint32_t m_rfBits; + uint32_t m_rfErrs; + uint32_t m_rfUndecodableLC; + uint32_t m_netFrames; + uint32_t m_netLost; + + Audio m_audio; + + lc::LC m_rfLC; + lc::LC m_rfLastHDU; + lc::LC m_rfLastLDU1; + lc::LC m_rfLastLDU2; + + lc::LC m_netLC; + lc::LC m_netLastLDU1; + + data::LowSpeedData m_rfLSD; + data::LowSpeedData m_netLSD; - LC m_rfDFSILC; - LC m_netDFSILC; + dfsi::LC m_dfsiLC; + uint8_t* m_netLDU1; + uint8_t* m_netLDU2; - uint8_t* m_dfsiLDU1; - uint8_t* m_dfsiLDU2; + uint8_t m_lastDUID; + uint8_t* m_lastIMBE; - /// Initializes a new instance of the VoicePacket class. - DFSIVoicePacket(Control* p25, network::BaseNetwork* network, bool debug, bool verbose); - /// Finalizes a instance of the VoicePacket class. - virtual ~DFSIVoicePacket(); + bool m_hadVoice; + uint32_t m_lastRejectId; + + uint32_t m_silenceThreshold; + + uint8_t m_vocLDU1Count; + + bool m_verbose; + bool m_debug; + + /// Initializes a new instance of the Voice class. + Voice(Control* p25, network::BaseNetwork* network, bool debug, bool verbose); + /// Finalizes a instance of the Voice class. + virtual ~Voice(); + + /// Write data processed from RF to the network. + void writeNetwork(const uint8_t* data, uint8_t duid); + + /// Helper to write end of voice frame data. + void writeRF_EndOfVoice(); /// Helper to write a network P25 TDU packet. virtual void writeNet_TDU(); + /// Helper to check for an unflushed LDU1 packet. + void checkNet_LDU1(); /// Helper to write a network P25 LDU1 packet. virtual void writeNet_LDU1(); + /// Helper to check for an unflushed LDU2 packet. + void checkNet_LDU2(); /// Helper to write a network P25 LDU1 packet. virtual void writeNet_LDU2(); - private: - friend class DFSITrunkPacket; - friend class p25::Control; + /// Helper to insert IMBE silence frames for missing audio. + void insertMissingAudio(uint8_t* data); + /// Helper to insert IMBE null frames for missing audio. + void insertNullAudio(uint8_t* data); }; - } // namespace dfsi + } // namespace packet } // namespace p25 -#endif // __P25_DFSI_VOICE_PACKET_H__ +#endif // __P25_PACKET_VOICE_H__