From da382647f6e4f195cc04799d0caf63228fa4508b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 1 Feb 2024 14:31:03 +0000 Subject: [PATCH 1/3] Regularise the UDP socket handling for DMR, POCSAG and the Remote Control port. --- DMRDirectNetwork.cpp | 20 ++++++++++---------- DMRGatewayNetwork.cpp | 2 +- POCSAGNetwork.cpp | 2 +- RemoteControl.cpp | 14 ++++++++++++-- RemoteControl.h | 4 +++- Version.h | 2 +- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/DMRDirectNetwork.cpp b/DMRDirectNetwork.cpp index c5013dd..d8c34fe 100644 --- a/DMRDirectNetwork.cpp +++ b/DMRDirectNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020,2021,2024 by Jonathan Naylor G4KLX * * 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 @@ -72,6 +72,9 @@ m_beacon(false) assert(id > 1000U); assert(!password.empty()); + if (CUDPSocket::lookup(m_address, m_port, m_addr, m_addrLen) != 0) + m_addrLen = 0U; + m_buffer = new unsigned char[BUFFER_LENGTH]; m_salt = new unsigned char[sizeof(uint32_t)]; m_id = new uint8_t[4U]; @@ -121,18 +124,18 @@ void CDMRDirectNetwork::setConfig(const std::string& callsign, unsigned int rxFr bool CDMRDirectNetwork::open() { - if (CUDPSocket::lookup(m_address, m_port, m_addr, m_addrLen) != 0) { + if (m_addrLen == 0U) { LogError("DMR, Could not lookup the address of the DMR Network"); return false; } - LogMessage("Opening DMR Network"); + LogMessage("DMR, Opening DMR Network"); m_status = WAITING_CONNECT; m_timeoutTimer.stop(); m_retryTimer.start(); - return true; + return m_socket.open(m_addr); } void CDMRDirectNetwork::enable(bool enabled) @@ -323,7 +326,7 @@ bool CDMRDirectNetwork::isConnected() const void CDMRDirectNetwork::close(bool sayGoodbye) { - LogMessage("Closing DMR Network"); + LogMessage("DMR, Closing DMR Network"); if (sayGoodbye && (m_status == RUNNING)) { unsigned char buffer[9U]; @@ -344,11 +347,8 @@ void CDMRDirectNetwork::clock(unsigned int ms) if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) { switch (m_status) { case WAITING_CONNECT: - if (m_socket.open(m_addr)) { - if (writeLogin()) { - m_status = WAITING_LOGIN; - } - } + writeLogin(); + m_status = WAITING_LOGIN; break; case WAITING_LOGIN: writeLogin(); diff --git a/DMRGatewayNetwork.cpp b/DMRGatewayNetwork.cpp index 5dd55b5..1eb7e63 100644 --- a/DMRGatewayNetwork.cpp +++ b/DMRGatewayNetwork.cpp @@ -105,7 +105,7 @@ void CDMRGatewayNetwork::setOptions(const std::string& options) bool CDMRGatewayNetwork::open() { if (m_addrLen == 0U) { - LogError("Unable to resolve the address of the DMR Network"); + LogError("DMR, Unable to resolve the address of the DMR Network"); return false; } diff --git a/POCSAGNetwork.cpp b/POCSAGNetwork.cpp index 2a4e650..f8bd073 100644 --- a/POCSAGNetwork.cpp +++ b/POCSAGNetwork.cpp @@ -53,7 +53,7 @@ bool CPOCSAGNetwork::open() LogMessage("Opening POCSAG network connection"); - return m_socket.open(); + return m_socket.open(m_addr); } void CPOCSAGNetwork::clock(unsigned int ms) diff --git a/RemoteControl.cpp b/RemoteControl.cpp index e9f5429..f88f15d 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2019,2020,2021,2024 by Jonathan Naylor G4KLX * * 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 @@ -36,10 +36,15 @@ const unsigned int BUFFER_LENGTH = 100U; CRemoteControl::CRemoteControl(CMMDVMHost *host, const std::string address, unsigned int port) : m_host(host), m_socket(address, port), +m_addr(), +m_addrLen(0U), m_command(RCD_NONE), m_args() { assert(port > 0U); + + if (CUDPSocket::lookup(address, port, m_addr, m_addrLen) != 0) + m_addrLen = 0U; } CRemoteControl::~CRemoteControl() @@ -48,7 +53,12 @@ CRemoteControl::~CRemoteControl() bool CRemoteControl::open() { - return m_socket.open(); + if (m_addrLen == 0U) { + LogError("Unable to resolve the address of the remote control port"); + return false; + } + + return m_socket.open(m_addr); } REMOTE_COMMAND CRemoteControl::getCommand() diff --git a/RemoteControl.h b/RemoteControl.h index a4b2885..61d0516 100644 --- a/RemoteControl.h +++ b/RemoteControl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2019,2020,2021,2024 by Jonathan Naylor G4KLX * * 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 @@ -83,6 +83,8 @@ public: private: CMMDVMHost* m_host; CUDPSocket m_socket; + sockaddr_storage m_addr; + unsigned int m_addrLen; REMOTE_COMMAND m_command; std::vector m_args; }; diff --git a/Version.h b/Version.h index ba845b1..a4e820a 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240129"; +const char* VERSION = "20240201"; #endif From 06a3da0f2e8bcd6c2f0e1f9700fcd84fc65902d2 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 7 Feb 2024 19:38:54 +0000 Subject: [PATCH 2/3] Hopefully fix the unreceivable P25 transmissions. --- P25Control.cpp | 26 +++++++++++++------------- P25Data.cpp | 37 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/P25Control.cpp b/P25Control.cpp index 412ec7f..b7682cd 100644 --- a/P25Control.cpp +++ b/P25Control.cpp @@ -361,7 +361,7 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) // Regenerate NID m_nid.encode(data + 2U, P25_DUID_LDU2); - // Add the dummy LDU2 data + // Add the LDU2 data m_rfData.encodeLDU2(data + 2U); // Regenerate the Low Speed Data @@ -960,7 +960,7 @@ void CP25Control::createRFHeader() // Add the NID m_nid.encode(buffer + 2U, P25_DUID_HEADER); - // Add the dummy header + // Add the header m_rfData.encodeHeader(buffer + 2U); // Add busy bits, inbound busy @@ -995,18 +995,18 @@ void CP25Control::createNetHeader() unsigned int dstId = (m_netLDU1[76U] << 16) + (m_netLDU1[77U] << 8) + m_netLDU1[78U]; unsigned int srcId = (m_netLDU1[101U] << 16) + (m_netLDU1[102U] << 8) + m_netLDU1[103U]; - unsigned char algId = m_netLDU2[126U]; - unsigned int kId = (m_netLDU2[127U] << 8) + m_netLDU2[128U]; +// unsigned char algId = m_netLDU2[126U]; +// unsigned int kId = (m_netLDU2[127U] << 8) + m_netLDU2[128U]; - unsigned char mi[P25_MI_LENGTH_BYTES]; - ::memcpy(mi + 0U, m_netLDU2 + 51U, 3U); - ::memcpy(mi + 3U, m_netLDU2 + 76U, 3U); - ::memcpy(mi + 6U, m_netLDU2 + 101U, 3U); +// unsigned char mi[P25_MI_LENGTH_BYTES]; +// ::memcpy(mi + 0U, m_netLDU2 + 51U, 3U); +// ::memcpy(mi + 3U, m_netLDU2 + 76U, 3U); +// ::memcpy(mi + 6U, m_netLDU2 + 101U, 3U); m_netData.reset(); - m_netData.setMI(mi); - m_netData.setAlgId(algId); - m_netData.setKId(kId); +// m_netData.setMI(mi); +// m_netData.setAlgId(algId); +// m_netData.setKId(kId); m_netData.setLCF(lcf); m_netData.setMFId(mfId); m_netData.setSrcId(srcId); @@ -1035,7 +1035,7 @@ void CP25Control::createNetHeader() // Add the NID m_nid.encode(buffer + 2U, P25_DUID_HEADER); - // Add the dummy header + // Add the header m_netData.encodeHeader(buffer + 2U); // Add busy bits @@ -1121,7 +1121,7 @@ void CP25Control::createNetLDU2() // Add the NID m_nid.encode(buffer + 2U, P25_DUID_LDU2); - // Add the dummy LDU2 data + // Add the LDU2 data m_netData.encodeLDU2(buffer + 2U); // Add the Audio diff --git a/P25Data.cpp b/P25Data.cpp index f2ae4ae..4a8aa58 100644 --- a/P25Data.cpp +++ b/P25Data.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017,2023 by Jonathan Naylor G4KLX * Copyright (C) 2018 by Bryan Biedenkapp N2PLL * * This program is free software; you can redistribute it and/or modify @@ -38,7 +38,7 @@ const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04 CP25Data::CP25Data() : m_mi(NULL), m_mfId(0U), -m_algId(0x80U), +m_algId(P25_ALGO_UNENCRYPT), m_kId(0U), m_lcf(0x00U), m_emergency(false), @@ -48,6 +48,7 @@ m_rs241213(), m_trellis() { m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; + ::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES); } CP25Data::~CP25Data() @@ -66,7 +67,7 @@ CP25Data& CP25Data::operator=(const CP25Data& data) m_emergency = data.m_emergency; m_algId = data.m_algId; - m_kId = data.m_kId; + m_kId = data.m_kId; ::memcpy(m_mi, data.m_mi, P25_MI_LENGTH_BYTES); } @@ -97,20 +98,19 @@ bool CP25Data::decodeHeader(const unsigned char* data) } m_mfId = rs[9U]; // Mfg Id. +/* m_algId = rs[10U]; // Algorithm ID if (m_algId != P25_ALGO_UNENCRYPT) { - m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; ::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator - m_kId = (rs[11U] << 8) + rs[12U]; // Key ID + m_kId = (rs[11U] << 8) | (rs[12U] << 0); // Key ID } else { - m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; ::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES); m_kId = 0x0000U; } - +*/ return true; } @@ -291,21 +291,20 @@ bool CP25Data::decodeLDU2(const unsigned char* data) CUtils::dump(2U, "P25, RS crashed with input data", rs, 18U); return false; } +/* + m_algId = rs[9U]; // Algorithm ID - m_algId = rs[9U]; // Algorithm ID if (m_algId != P25_ALGO_UNENCRYPT) { - m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; - ::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator + ::memcpy(m_mi, rs, P25_MI_LENGTH_BYTES); // Message Indicator - m_kId = (rs[10U] << 8) + rs[11U]; // Key ID + m_kId = (rs[10U] << 8) + rs[11U]; // Key ID } else { - m_mi = new unsigned char[P25_MI_LENGTH_BYTES]; ::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES); m_kId = 0x0000U; } - +*/ return true; } @@ -318,11 +317,11 @@ void CP25Data::encodeLDU2(unsigned char* data) ::memset(rs, 0x00U, 18U); for (unsigned int i = 0; i < P25_MI_LENGTH_BYTES; i++) - rs[i] = m_mi[i]; // Message Indicator + rs[i] = m_mi[i]; // Message Indicator - rs[9U] = m_algId; // Algorithm ID - rs[10U] = (m_kId >> 8) & 0xFFU; // Key ID MSB - rs[11U] = (m_kId >> 0) & 0xFFU; // Key ID LSB + rs[9U] = m_algId; // Algorithm ID + rs[10U] = (m_kId >> 8) & 0xFFU; // Key ID MSB + rs[11U] = (m_kId >> 0) & 0xFFU; // Key ID LSB // encode RS (24,16,9) FEC m_rs241213.encode24169(rs); @@ -370,7 +369,7 @@ bool CP25Data::decodeTSDU(const unsigned char* data) return false; } - m_lcf = tsbk[0U] & 0x3F; + m_lcf = tsbk[0U] & 0x3F; m_mfId = tsbk[1U]; unsigned long long tsbkValue = 0U; @@ -556,7 +555,7 @@ void CP25Data::reset() { ::memset(m_mi, 0x00U, P25_MI_LENGTH_BYTES); - m_algId = 0x80U; + m_algId = P25_ALGO_UNENCRYPT; m_kId = 0x0000U; m_lcf = P25_LCF_GROUP; m_mfId = 0x00U; From 218a017956b174334a2fe0418e373ba139768f5f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 9 Feb 2024 15:56:49 +0000 Subject: [PATCH 3/3] Bump the version date. --- Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Version.h b/Version.h index a4e820a..85c1d9f 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240201"; +const char* VERSION = "20240207"; #endif