/** * 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/AMBT.h" #include "p25/lc/TDULC.h" #include "p25/Control.h" #include "network/BaseNetwork.h" #include "Timer.h" #include #include #include #include namespace p25 { // --------------------------------------------------------------------------- // Class Prototypes // --------------------------------------------------------------------------- namespace packet { class HOST_SW_API Voice; } namespace dfsi { namespace packet { class HOST_SW_API DFSIVoice; } } namespace packet { class HOST_SW_API Data; } namespace lookups { class HOST_SW_API P25AffiliationLookup; } class HOST_SW_API Control; namespace packet { // --------------------------------------------------------------------------- // Class Declaration // This class implements handling logic for P25 trunking packets. // --------------------------------------------------------------------------- class HOST_SW_API Trunk { public: /// Process a data frame from the RF interface. virtual bool process(uint8_t* data, uint32_t len, std::unique_ptr preDecodedTSBK = nullptr); /// 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(); /// Updates the processor by the passed number of milliseconds. void clock(uint32_t ms); /// Helper to write a call alert packet. void writeRF_TSDU_Call_Alrt(uint32_t srcId, uint32_t dstId); /// Helper to write a radio monitor packet. void writeRF_TSDU_Radio_Mon(uint32_t srcId, uint32_t dstId, uint8_t txMult); /// 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 emergency alarm packet. void writeRF_TSDU_Emerg_Alrm(uint32_t srcId, uint32_t dstId); /// Helper to write a emergency alarm packet. void writeRF_TSDU_Raw(const uint8_t* tsbk); /// Helper to change the conventional fallback state. void setConvFallback(bool fallback); /// Helper to change the last MFId value. void setLastMFId(uint8_t mfId) { m_lastMFID = mfId; } /// Flag indicating whether P25 TSBK verbosity is enabled or not. bool getTSBKVerbose() const { return m_dumpTSBK; }; /// 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; friend class lookups::P25AffiliationLookup; network::BaseNetwork* m_network; uint32_t m_patchSuperGroup; bool m_verifyAff; bool m_verifyReg; 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::unordered_map m_adjSiteTable; std::unordered_map m_adjSiteUpdateCnt; std::unordered_map m_sccbTable; std::unordered_map m_sccbUpdateCnt; uint8_t m_lastMFID; bool m_noStatusAck; bool m_noMessageAck; bool m_unitToUnitAvailCheck; uint8_t m_convFallbackPacketDelay; bool m_convFallback; Timer m_adjSiteUpdateTimer; uint32_t m_adjSiteUpdateInterval; uint16_t m_microslotCount; bool m_ctrlTimeDateAnn; bool m_ctrlTSDUMBF; bool m_sndcpChGrant; bool m_disableGrantSrcIdCheck; 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(lc::TSBK* tsbk, const uint8_t* data, bool autoReset); /// Write data processed from RF to the network. void writeNetworkRF(lc::TDULC* tduLc, 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 network P25 TDU w/ link control packet. virtual void writeNet_TDULC(lc::TDULC* lc); /// 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(lc::TSBK* tsbk, bool noNetwork, bool clearBeforeWrite = false, bool force = false); /// Helper to write a network single-block P25 TSDU packet. virtual void writeNet_TSDU(lc::TSBK* tsbk); /// Helper to write a multi-block (3-block) P25 TSDU packet. void writeRF_TSDU_MBF(lc::TSBK* tsbk, bool clearBeforeWrite = false); /// Helper to write a alternate multi-block trunking PDU packet. virtual void writeRF_TSDU_AMBT(lc::AMBT* ambt, 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(uint32_t srcId, uint32_t dstId, uint8_t serviceOptions, bool grp, bool net = false, bool skip = false, uint32_t chNo = 0U); /// Helper to write a SNDCP grant packet. bool writeRF_TSDU_SNDCP_Grant(uint32_t srcId, uint32_t dstId, 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(uint32_t srcId, uint32_t dstId, uint8_t reason, uint8_t service, bool aiv = false); /// 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, uint32_t sysId); /// 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(uint32_t srcId, uint32_t dstId, uint8_t reason, uint8_t service, bool aiv = false); /// Helper to write a location registration response packet. bool writeRF_TSDU_Loc_Reg_Rsp(uint32_t srcId, uint32_t dstId, bool grp); /// 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(lc::TSBK* tsbk, uint8_t * data); /// 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__