From e031b2bb8f6990f3eeddd000eb7f774c06cc5d0c Mon Sep 17 00:00:00 2001 From: firealarmss <99303085+firealarmss@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:21:34 -0500 Subject: [PATCH] Add support for GRP UNAFFIL opcode. (#65) * Add support for GRP UNAFFIL opcode * Fix line spacing --- src/common/network/BaseNetwork.cpp | 15 +++++++++++++++ src/common/network/BaseNetwork.h | 10 ++++++++++ src/common/network/RTPFNEHeader.h | 1 + src/fne/network/FNENetwork.cpp | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/common/network/BaseNetwork.cpp b/src/common/network/BaseNetwork.cpp index c3870ffd..4750062c 100644 --- a/src/common/network/BaseNetwork.cpp +++ b/src/common/network/BaseNetwork.cpp @@ -6,6 +6,7 @@ * * Copyright (C) 2015,2016,2017 Jonathan Naylor, G4KLX * Copyright (C) 2020-2024 Bryan Biedenkapp, N2PLL + * Copyright (C) 2024 Caleb, KO4UYJ * */ #include "Defines.h" @@ -187,6 +188,20 @@ bool BaseNetwork::announceGroupAffiliation(uint32_t srcId, uint32_t dstId) return writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_GRP_AFFIL }, buffer, MSG_ANNC_GRP_AFFIL, RTP_END_OF_CALL_SEQ, 0U); } +/* Writes a group affiliation removal to the network. */ + +bool BaseNetwork::announceGroupAffiliationRemoval(uint32_t srcId) +{ + if (m_status != NET_STAT_RUNNING && m_status != NET_STAT_MST_RUNNING) + return false; + + uint8_t buffer[DATA_PACKET_LENGTH]; + + __SET_UINT16(srcId, buffer, 0U); + + return writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_GRP_UNAFFIL }, buffer, MSG_ANNC_GRP_UNAFFIL, RTP_END_OF_CALL_SEQ, 0U); +} + /* Writes a unit registration to the network. */ bool BaseNetwork::announceUnitRegistration(uint32_t srcId) diff --git a/src/common/network/BaseNetwork.h b/src/common/network/BaseNetwork.h index cc41deb5..a8b9178c 100644 --- a/src/common/network/BaseNetwork.h +++ b/src/common/network/BaseNetwork.h @@ -77,6 +77,7 @@ namespace network const uint32_t MSG_HDR_SIZE = 24U; const uint32_t MSG_ANNC_GRP_AFFIL = 6U; + const uint32_t MSG_ANNC_GRP_UNAFFIL = 3U; const uint32_t MSG_ANNC_UNIT_REG = 3U; const uint32_t DMR_PACKET_LENGTH = 55U; // 20 byte header + DMR_FRAME_LENGTH_BYTES + 2 byte trailer const uint32_t P25_LDU1_PACKET_LENGTH = 193U; // 24 byte header + DFSI data + 1 byte frame type + 12 byte enc sync @@ -209,6 +210,13 @@ namespace network * @returns bool True, if group affiliation announcement was sent, otherwise false. */ virtual bool announceGroupAffiliation(uint32_t srcId, uint32_t dstId); + /** + * @brief Writes a group affiliation removal to the network. + * @param srcId Source Radio ID. + * @returns bool True, if group affiliation announcement was sent, otherwise false. + */ + virtual bool announceGroupAffiliationRemoval(uint32_t srcId); + /** * @brief Writes a unit registration to the network. * \code{.unparsed} @@ -231,12 +239,14 @@ namespace network * @returns bool True, if unit deregistration announcement was sent, otherwise false. */ virtual bool announceUnitDeregistration(uint32_t srcId); + /** * @brief Writes a complete update of the peer affiliation list to the network. * @param affs Complete map of peer unit affiliations. * @returns bool True, if affiliation update announcement was sent, otherwise false. */ virtual bool announceAffiliationUpdate(const std::unordered_map affs); + /** * @brief Writes a complete update of the peer's voice channel list to the network. * @param peers List of voice channel peers. diff --git a/src/common/network/RTPFNEHeader.h b/src/common/network/RTPFNEHeader.h index 019a3538..8e0d8066 100644 --- a/src/common/network/RTPFNEHeader.h +++ b/src/common/network/RTPFNEHeader.h @@ -95,6 +95,7 @@ namespace network ANNC_SUBFUNC_GRP_AFFIL = 0x00U, //! Announce Group Affiliation ANNC_SUBFUNC_UNIT_REG = 0x01U, //! Announce Unit Registration ANNC_SUBFUNC_UNIT_DEREG = 0x02U, //! Announce Unit Deregistration + ANNC_SUBFUNC_GRP_UNAFFIL = 0x03U, //! Announce Group Affiliation Removal ANNC_SUBFUNC_AFFILS = 0x90U, //! Update All Affiliations ANNC_SUBFUNC_SITE_VC = 0x9AU //! Announce Site VCs }; diff --git a/src/fne/network/FNENetwork.cpp b/src/fne/network/FNENetwork.cpp index 32b2eba5..65722780 100644 --- a/src/fne/network/FNENetwork.cpp +++ b/src/fne/network/FNENetwork.cpp @@ -1107,6 +1107,27 @@ void* FNENetwork::threadedNetworkRx(void* arg) } } } + else if (req->fneHeader.getSubFunction() == NET_SUBFUNC::ANNC_SUBFUNC_GRP_UNAFFIL) { // Announce Group Affiliation Removal + if (peerId > 0 && (network->m_peers.find(peerId) != network->m_peers.end())) { + FNEPeerConnection* connection = network->m_peers[peerId]; + if (connection != nullptr) { + std::string ip = udp::Socket::address(req->address); + lookups::AffiliationLookup* aff = network->m_peerAffiliations[peerId]; + if (aff == nullptr) { + LogError(LOG_NET, "PEER %u (%s) has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId, connection->identity().c_str()); + } + + // validate peer (simple validation really) + if (connection->connected() && connection->address() == ip && aff != nullptr) { + uint32_t srcId = __GET_UINT16(req->buffer, 0U); // Source Address + aff->groupUnaff(srcId); + } + else { + network->writePeerNAK(peerId, TAG_ANNOUNCE, NET_CONN_NAK_FNE_UNAUTHORIZED); + } + } + } + } else if (req->fneHeader.getSubFunction() == NET_SUBFUNC::ANNC_SUBFUNC_AFFILS) { // Announce Update All Affiliations if (peerId > 0 && (network->m_peers.find(peerId) != network->m_peers.end())) { FNEPeerConnection* connection = network->m_peers[peerId];