// SPDX-License-Identifier: GPL-2.0-only /** * Digital Voice Modem - Converged FNE Software * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * @package DVM / Converged FNE Software * @license GPLv2 License (https://opensource.org/licenses/GPL-2.0) * * Copyright (C) 2024 Bryan Biedenkapp, N2PLL * */ #include "fne/Defines.h" #include "common/network/json/json.h" #include "common/Utils.h" #include "fne/network/PeerNetwork.h" using namespace network; #include #include #include // --------------------------------------------------------------------------- // Public Class Members // --------------------------------------------------------------------------- /// /// Initializes a new instance of the PeerNetwork class. /// /// Network Hostname/IP address to connect to. /// Network port number. /// /// Unique ID on the network. /// Network authentication password. /// Flag indicating full-duplex operation. /// Flag indicating whether network debug is enabled. /// Flag indicating whether DMR is enabled. /// Flag indicating whether P25 is enabled. /// Flag indicating whether NXDN is enabled. /// Flag indicating whether DMR slot 1 is enabled for network traffic. /// Flag indicating whether DMR slot 2 is enabled for network traffic. /// Flag indicating that the system activity logs will be sent to the network. /// Flag indicating that the system diagnostic logs will be sent to the network. /// Flag indicating that the system will accept radio ID and talkgroup ID lookups from the network. PeerNetwork::PeerNetwork(const std::string& address, uint16_t port, uint16_t localPort, uint32_t peerId, const std::string& password, bool duplex, bool debug, bool dmr, bool p25, bool nxdn, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer, bool updateLookup, bool saveLookup) : Network(address, port, localPort, peerId, password, duplex, debug, dmr, p25, nxdn, slot1, slot2, allowActivityTransfer, allowDiagnosticTransfer, updateLookup, saveLookup), m_blockTrafficToTable() { assert(!address.empty()); assert(port > 0U); assert(!password.empty()); } /// /// Checks if the passed peer ID is blocked from sending to this peer. /// /// bool PeerNetwork::checkBlockedPeer(uint32_t peerId) { if (m_blockTrafficToTable.empty()) return false; if (std::find(m_blockTrafficToTable.begin(), m_blockTrafficToTable.end(), peerId) != m_blockTrafficToTable.end()) { return true; } return false; } // --------------------------------------------------------------------------- // Protected Class Members // --------------------------------------------------------------------------- /// /// Writes configuration to the network. /// /// bool PeerNetwork::writeConfig() { if (m_loginStreamId == 0U) { LogWarning(LOG_NET, "BUGBUG: tried to write network authorisation with no stream ID?"); return false; } const char* software = __NETVER__; json::object config = json::object(); // identity and frequency config["identity"].set(m_identity); // Identity config["rxFrequency"].set(m_rxFrequency); // Rx Frequency config["txFrequency"].set(m_txFrequency); // Tx Frequency // system info json::object sysInfo = json::object(); sysInfo["latitude"].set(m_latitude); // Latitude sysInfo["longitude"].set(m_longitude); // Longitude sysInfo["height"].set(m_height); // Height sysInfo["location"].set(m_location); // Location config["info"].set(sysInfo); // channel data json::object channel = json::object(); channel["txPower"].set(m_power); // Tx Power channel["txOffsetMhz"].set(m_txOffsetMhz); // Tx Offset (Mhz) channel["chBandwidthKhz"].set(m_chBandwidthKhz); // Ch. Bandwidth (khz) channel["channelId"].set(m_channelId); // Channel ID channel["channelNo"].set(m_channelNo); // Channel No config["channel"].set(channel); // RCON json::object rcon = json::object(); rcon["password"].set(m_restApiPassword); // REST API Password rcon["port"].set(m_restApiPort); // REST API Port config["rcon"].set(rcon); bool external = true; config["externalPeer"].set(external); // External Peer Marker config["software"].set(std::string(software)); // Software ID json::value v = json::value(config); std::string json = v.serialize(); char buffer[json.length() + 8U]; ::memcpy(buffer + 0U, TAG_REPEATER_CONFIG, 4U); ::sprintf(buffer + 8U, "%s", json.c_str()); if (m_debug) { Utils::dump(1U, "Network Message, Configuration", (uint8_t*)buffer, json.length() + 8U); } return writeMaster({ NET_FUNC_RPTC, NET_SUBFUNC_NOP }, (uint8_t*)buffer, json.length() + 8U, pktSeq(), m_loginStreamId); }