11// SPDX-License-Identifier: GPL-2.0-only
22/*
3- * Digital Voice Modem - Modem Host Software
3+ * Digital Voice Modem - Common Library
44 * GPLv2 Open Source. Use is subject to license terms.
55 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66 *
7- * Copyright (C) 2015,2016,2017 Jonathan Naylor, G4KLX
87 * Copyright (C) 2017-2025 Bryan Biedenkapp, N2PLL
98 *
109 */
@@ -56,23 +55,10 @@ Network::Network(const std::string& address, uint16_t port, uint16_t localPort,
5655 m_timeoutTimer(1000U , 60U ),
5756 m_pktSeq(0U ),
5857 m_loginStreamId(0U ),
59- m_identity(),
60- m_rxFrequency(0U ),
61- m_txFrequency(0U ),
62- m_txOffsetMhz(0 .0F ),
63- m_chBandwidthKhz(0 .0F ),
64- m_channelId(0U ),
65- m_channelNo(0U ),
66- m_power(0U ),
67- m_latitude(0 .0F ),
68- m_longitude(0 .0F ),
69- m_height(0 ),
70- m_location(),
71- m_restApiPassword(),
72- m_restApiPort(0 ),
73- m_conventional(false ),
58+ m_metadata(nullptr ),
7459 m_remotePeerId(0U ),
7560 m_promiscuousPeer(false ),
61+ m_userHandleProtocol(false ),
7662 m_dmrInCallCallback(nullptr ),
7763 m_p25InCallCallback(nullptr ),
7864 m_nxdnInCallCallback(nullptr ),
@@ -89,6 +75,8 @@ Network::Network(const std::string& address, uint16_t port, uint16_t localPort,
8975 m_rxDMRStreamId[1U ] = 0U ;
9076 m_rxP25StreamId = 0U ;
9177 m_rxNXDNStreamId = 0U ;
78+
79+ m_metadata = new PeerMetadata ();
9280}
9381
9482/* Finalizes a instance of the Network class. */
@@ -97,6 +85,7 @@ Network::~Network()
9785{
9886 delete[] m_salt;
9987 delete[] m_rxDMRStreamId;
88+ delete m_metadata;
10089}
10190
10291/* Resets the DMR ring buffer for the given slot. */
@@ -143,28 +132,29 @@ void Network::setLookups(lookups::RadioIdLookup* ridLookup, lookups::TalkgroupRu
143132void Network::setMetadata (const std::string& identity, uint32_t rxFrequency, uint32_t txFrequency, float txOffsetMhz, float chBandwidthKhz,
144133 uint8_t channelId, uint32_t channelNo, uint32_t power, float latitude, float longitude, int height, const std::string& location)
145134{
146- m_identity = identity;
147- m_rxFrequency = rxFrequency;
148- m_txFrequency = txFrequency;
149-
150- m_txOffsetMhz = txOffsetMhz;
151- m_chBandwidthKhz = chBandwidthKhz;
152- m_channelId = channelId;
153- m_channelNo = channelNo;
154-
155- m_power = power;
156- m_latitude = latitude;
157- m_longitude = longitude;
158- m_height = height;
159- m_location = location;
135+ m_metadata->identity = identity;
136+
137+ m_metadata->rxFrequency = rxFrequency;
138+ m_metadata->txFrequency = txFrequency;
139+
140+ m_metadata->txOffsetMhz = txOffsetMhz;
141+ m_metadata->chBandwidthKhz = chBandwidthKhz;
142+ m_metadata->channelId = channelId;
143+ m_metadata->channelNo = channelNo;
144+
145+ m_metadata->power = power;
146+ m_metadata->latitude = latitude;
147+ m_metadata->longitude = longitude;
148+ m_metadata->height = height;
149+ m_metadata->location = location;
160150}
161151
162152/* Sets REST API configuration settings from the modem. */
163153
164154void Network::setRESTAPIData (const std::string& password, uint16_t port)
165155{
166- m_restApiPassword = password;
167- m_restApiPort = port;
156+ m_metadata-> restApiPassword = password;
157+ m_metadata-> restApiPort = port;
168158}
169159
170160/* Sets endpoint preshared encryption key. */
@@ -265,6 +255,13 @@ void Network::clock(uint32_t ms)
265255 switch (fneHeader.getFunction ()) {
266256 case NET_FUNC::PROTOCOL:
267257 {
258+ // are protocol messages being user handled?
259+ if (m_userHandleProtocol) {
260+ userPacketHandler (fneHeader.getPeerId (), { fneHeader.getFunction (), fneHeader.getSubFunction () },
261+ buffer.get (), length, fneHeader.getStreamId ());
262+ break ;
263+ }
264+
268265 if (fneHeader.getSubFunction () == NET_SUBFUNC::PROTOCOL_SUBFUNC_DMR) { // Encapsulated DMR data frame
269266 if (m_enabled && m_dmrEnabled) {
270267 uint32_t slotNo = (buffer[15U ] & 0x80U ) == 0x80U ? 1U : 0U ; // this is the raw index for the stream ID array
@@ -931,36 +928,38 @@ bool Network::writeConfig()
931928 json::object config = json::object ();
932929
933930 // identity and frequency
934- config[" identity" ].set <std::string>(m_identity); // Identity
935- config[" rxFrequency" ].set <uint32_t >(m_rxFrequency); // Rx Frequency
936- config[" txFrequency" ].set <uint32_t >(m_txFrequency); // Tx Frequency
931+ config[" identity" ].set <std::string>(m_metadata-> identity ); // Identity
932+ config[" rxFrequency" ].set <uint32_t >(m_metadata-> rxFrequency ); // Rx Frequency
933+ config[" txFrequency" ].set <uint32_t >(m_metadata-> txFrequency ); // Tx Frequency
937934
938935 // system info
939936 json::object sysInfo = json::object ();
940- sysInfo[" latitude" ].set <float >(m_latitude); // Latitude
941- sysInfo[" longitude" ].set <float >(m_longitude); // Longitude
937+ sysInfo[" latitude" ].set <float >(m_metadata-> latitude ); // Latitude
938+ sysInfo[" longitude" ].set <float >(m_metadata-> longitude ); // Longitude
942939
943- sysInfo[" height" ].set <int >(m_height); // Height
944- sysInfo[" location" ].set <std::string>(m_location); // Location
940+ sysInfo[" height" ].set <int >(m_metadata-> height ); // Height
941+ sysInfo[" location" ].set <std::string>(m_metadata-> location ); // Location
945942 config[" info" ].set <json::object>(sysInfo);
946943
947944 // channel data
948945 json::object channel = json::object ();
949- channel[" txPower" ].set <uint32_t >(m_power); // Tx Power
950- channel[" txOffsetMhz" ].set <float >(m_txOffsetMhz); // Tx Offset (Mhz)
951- channel[" chBandwidthKhz" ].set <float >(m_chBandwidthKhz); // Ch. Bandwidth (khz)
952- channel[" channelId" ].set <uint8_t >(m_channelId); // Channel ID
953- channel[" channelNo" ].set <uint32_t >(m_channelNo); // Channel No
946+ channel[" txPower" ].set <uint32_t >(m_metadata-> power ); // Tx Power
947+ channel[" txOffsetMhz" ].set <float >(m_metadata-> txOffsetMhz ); // Tx Offset (Mhz)
948+ channel[" chBandwidthKhz" ].set <float >(m_metadata-> chBandwidthKhz ); // Ch. Bandwidth (khz)
949+ channel[" channelId" ].set <uint8_t >(m_metadata-> channelId ); // Channel ID
950+ channel[" channelNo" ].set <uint32_t >(m_metadata-> channelNo ); // Channel No
954951 config[" channel" ].set <json::object>(channel);
955952
956953 // RCON
957954 json::object rcon = json::object ();
958- rcon[" password" ].set <std::string>(m_restApiPassword); // REST API Password
959- rcon[" port" ].set <uint16_t >(m_restApiPort); // REST API Port
955+ rcon[" password" ].set <std::string>(m_metadata-> restApiPassword ); // REST API Password
956+ rcon[" port" ].set <uint16_t >(m_metadata-> restApiPort ); // REST API Port
960957 config[" rcon" ].set <json::object>(rcon);
961958
962- config[" conventionalPeer" ].set <bool >(m_conventional); // Conventional Peer Marker
963- config[" software" ].set <std::string>(std::string (software)); // Software ID
959+ // Flags
960+ config[" conventionalPeer" ].set <bool >(m_metadata->isConventional ); // Conventional Peer Marker
961+
962+ config[" software" ].set <std::string>(std::string (software));
964963
965964 json::value v = json::value (config);
966965 std::string json = v.serialize ();
0 commit comments