From 022d1a768b1ebf3f37ea79c6ac678d3870edba5f Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Fri, 27 Mar 2020 06:25:54 +0900 Subject: [PATCH 01/16] add IPv6 support (code from DAPNETGateway-IPv6) --- UDPSocket.cpp | 115 ++++++++++++++++++-------------------------------- UDPSocket.h | 9 ++-- 2 files changed, 47 insertions(+), 77 deletions(-) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index ba0e35f..7899601 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -60,49 +60,46 @@ CUDPSocket::~CUDPSocket() #endif } -in_addr CUDPSocket::lookup(const std::string& hostname) +int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage &addr, unsigned int &address_length) { - in_addr addr; -#if defined(_WIN32) || defined(_WIN64) - unsigned long address = ::inet_addr(hostname.c_str()); - if (address != INADDR_NONE && address != INADDR_ANY) { - addr.s_addr = address; - return addr; + int err; + std::string portstr = std::to_string(port); + struct addrinfo hints, *res; + + ::memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_NUMERICSERV; + + err = getaddrinfo(hostname.c_str(), portstr.c_str(), &hints, &res); + if (err) { + sockaddr_in *paddr = (sockaddr_in *)&addr; + ::memset(paddr, 0, address_length = sizeof(sockaddr_in)); + paddr->sin_family = AF_INET; + paddr->sin_port = htons(port); + paddr->sin_addr.s_addr = htonl(INADDR_NONE); + LogError("Cannot find address for host %s", hostname.c_str()); + return err; } - struct hostent* hp = ::gethostbyname(hostname.c_str()); - if (hp != NULL) { - ::memcpy(&addr, hp->h_addr_list[0], sizeof(struct in_addr)); - return addr; - } + ::memcpy(&addr, res->ai_addr, address_length = res->ai_addrlen); - LogError("Cannot find address for host %s", hostname.c_str()); - - addr.s_addr = INADDR_NONE; - return addr; -#else - in_addr_t address = ::inet_addr(hostname.c_str()); - if (address != in_addr_t(-1)) { - addr.s_addr = address; - return addr; - } - - struct hostent* hp = ::gethostbyname(hostname.c_str()); - if (hp != NULL) { - ::memcpy(&addr, hp->h_addr_list[0], sizeof(struct in_addr)); - return addr; - } - - LogError("Cannot find address for host %s", hostname.c_str()); - - addr.s_addr = INADDR_NONE; - return addr; -#endif + freeaddrinfo(res); + return 0; } bool CUDPSocket::open() { - m_fd = ::socket(PF_INET, SOCK_DGRAM, 0); + int err; + sockaddr_storage addr; + unsigned int addrlen; + + /* to determine protocol family, call lookup() first. */ + err = lookup(m_address.empty() ? "0.0.0.0" : m_address.c_str(), m_port, addr, addrlen); + if (err) { + LogError("The local address is invalid - %s", m_address.c_str()); + return false; + } + + m_fd = ::socket(addr.ss_family, SOCK_DGRAM, 0); if (m_fd < 0) { #if defined(_WIN32) || defined(_WIN64) LogError("Cannot create the UDP socket, err: %lu", ::GetLastError()); @@ -113,24 +110,6 @@ bool CUDPSocket::open() } if (m_port > 0U) { - sockaddr_in addr; - ::memset(&addr, 0x00, sizeof(sockaddr_in)); - addr.sin_family = AF_INET; - addr.sin_port = htons(m_port); - addr.sin_addr.s_addr = htonl(INADDR_ANY); - - if (!m_address.empty()) { -#if defined(_WIN32) || defined(_WIN64) - addr.sin_addr.s_addr = ::inet_addr(m_address.c_str()); -#else - addr.sin_addr.s_addr = ::inet_addr(m_address.c_str()); -#endif - if (addr.sin_addr.s_addr == INADDR_NONE) { - LogError("The local address is invalid - %s", m_address.c_str()); - return false; - } - } - int reuse = 1; if (::setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) { #if defined(_WIN32) || defined(_WIN64) @@ -141,7 +120,7 @@ bool CUDPSocket::open() return false; } - if (::bind(m_fd, (sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { + if (::bind(m_fd, (sockaddr*)&addr, addrlen) == -1) { #if defined(_WIN32) || defined(_WIN64) LogError("Cannot bind the UDP address, err: %lu", ::GetLastError()); #else @@ -154,7 +133,7 @@ bool CUDPSocket::open() return true; } -int CUDPSocket::read(unsigned char* buffer, unsigned int length, in_addr& address, unsigned int& port) +int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length) { assert(buffer != NULL); assert(length > 0U); @@ -186,17 +165,16 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, in_addr& addres if (ret == 0) return 0; - sockaddr_in addr; #if defined(_WIN32) || defined(_WIN64) - int size = sizeof(sockaddr_in); + int size = sizeof(sockaddr_storage); #else - socklen_t size = sizeof(sockaddr_in); + socklen_t size = sizeof(sockaddr_storage); #endif #if defined(_WIN32) || defined(_WIN64) - int len = ::recvfrom(m_fd, (char*)buffer, length, 0, (sockaddr *)&addr, &size); + int len = ::recvfrom(m_fd, (char*)buffer, length, 0, (sockaddr *)&address, &size); #else - ssize_t len = ::recvfrom(m_fd, (char*)buffer, length, 0, (sockaddr *)&addr, &size); + ssize_t len = ::recvfrom(m_fd, (char*)buffer, length, 0, (sockaddr *)&address, &size); #endif if (len <= 0) { #if defined(_WIN32) || defined(_WIN64) @@ -207,28 +185,19 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, in_addr& addres return -1; } - address = addr.sin_addr; - port = ntohs(addr.sin_port); - + address_length = size; return len; } -bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const in_addr& address, unsigned int port) +bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length) { assert(buffer != NULL); assert(length > 0U); - sockaddr_in addr; - ::memset(&addr, 0x00, sizeof(sockaddr_in)); - - addr.sin_family = AF_INET; - addr.sin_addr = address; - addr.sin_port = htons(port); - #if defined(_WIN32) || defined(_WIN64) - int ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&addr, sizeof(sockaddr_in)); + int ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&address, address_length); #else - ssize_t ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&addr, sizeof(sockaddr_in)); + ssize_t ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&address, address_length); #endif if (ret < 0) { #if defined(_WIN32) || defined(_WIN64) diff --git a/UDPSocket.h b/UDPSocket.h index e0af272..ec5de9c 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -31,7 +31,8 @@ #include #include #else -#include +#include +#include #endif class CUDPSocket { @@ -42,12 +43,12 @@ public: bool open(); - int read(unsigned char* buffer, unsigned int length, in_addr& address, unsigned int& port); - bool write(const unsigned char* buffer, unsigned int length, const in_addr& address, unsigned int port); + int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length); + bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length); void close(); - static in_addr lookup(const std::string& hostName); + static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length); private: std::string m_address; From 5dccd5c5ce6ae5afd424327816366ae1e19cea87 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 28 Mar 2020 04:37:51 +0900 Subject: [PATCH 02/16] add match(), isnone() utility function match() checks address family, IP address and port between two sockaddr_storages. isnone() checks sockaddr_storage has INADDR_NONE IPv4 address. (sockaddr_storage has this address when lookup() failed) --- UDPSocket.cpp | 31 +++++++++++++++++++++++++++++++ UDPSocket.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 7899601..9e5e2cf 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -86,6 +86,37 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_ return 0; } +bool CUDPSocket::match(const sockaddr_storage &addr1, const sockaddr_storage &addr2) +{ + if (addr1.ss_family != addr2.ss_family) + return false; + + switch (addr1.ss_family) { + case AF_INET: + struct sockaddr_in *in_1, *in_2; + in_1 = (struct sockaddr_in *)&addr1; + in_2 = (struct sockaddr_in *)&addr2; + return ( (in_1->sin_addr.s_addr == in_2->sin_addr.s_addr) && + (in_1->sin_port == in_2->sin_port) ); + case AF_INET6: + struct sockaddr_in6 *in6_1, *in6_2; + in6_1 = (struct sockaddr_in6 *)&addr1; + in6_2 = (struct sockaddr_in6 *)&addr2; + return ( IN6_ARE_ADDR_EQUAL(&in6_1->sin6_addr, &in6_2->sin6_addr) && + (in6_1->sin6_port == in6_2->sin6_port) ); + default: + return false; + } +} + +bool CUDPSocket::isnone(const sockaddr_storage &addr) +{ + struct sockaddr_in *in = (struct sockaddr_in *)&addr; + + return ( (addr.ss_family == AF_INET) && + (in->sin_addr.s_addr == htonl(INADDR_NONE)) ); +} + bool CUDPSocket::open() { int err; diff --git a/UDPSocket.h b/UDPSocket.h index ec5de9c..288273f 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -49,6 +49,8 @@ public: void close(); static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length); + static bool match(const sockaddr_storage &addr1, const sockaddr_storage &addr2); + static bool isnone(const sockaddr_storage &addr); private: std::string m_address; From c92039d83bb9f193ff189f5634c365523c5e4b66 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 28 Mar 2020 05:40:35 +0900 Subject: [PATCH 03/16] modified for IPv6 supported CUDPSocket --- DMRNetwork.cpp | 17 +++++++------- DMRNetwork.h | 3 ++- DStarNetwork.cpp | 26 ++++++++------------ DStarNetwork.h | 4 ++-- MMDVMHost.cpp | 15 ++++++------ MobileGPS.cpp | 12 +++++----- MobileGPS.h | 4 ++-- NXDNNetwork.cpp | 22 +++++++---------- NXDNNetwork.h | 4 ++-- P25Network.cpp | 60 +++++++++++++++++++++-------------------------- P25Network.h | 4 ++-- POCSAGNetwork.cpp | 22 +++++++---------- POCSAGNetwork.h | 4 ++-- RemoteCommand.cpp | 6 +++-- RemoteControl.cpp | 6 ++--- YSFNetwork.cpp | 24 +++++++------------ YSFNetwork.h | 4 ++-- 17 files changed, 105 insertions(+), 132 deletions(-) diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index b2aedb5..ea52096 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -36,6 +36,7 @@ const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U; CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType) : m_addressStr(address), m_address(), +m_addrlen(), m_port(port), m_id(NULL), m_password(password), @@ -73,7 +74,7 @@ m_beacon(false) assert(id > 1000U); assert(!password.empty()); - m_address = CUDPSocket::lookup(address); + CUDPSocket::lookup(m_addressStr, m_port, m_address, m_addrlen); m_buffer = new unsigned char[BUFFER_LENGTH]; m_salt = new unsigned char[sizeof(uint32_t)]; @@ -124,8 +125,8 @@ bool CDMRNetwork::open() { LogMessage("DMR, Opening DMR Network"); - if (m_address.s_addr == INADDR_NONE) - m_address = CUDPSocket::lookup(m_addressStr); + if (CUDPSocket::isnone(m_address)) + CUDPSocket::lookup(m_addressStr, m_port, m_address, m_addrlen); m_status = WAITING_CONNECT; m_timeoutTimer.stop(); @@ -377,9 +378,9 @@ void CDMRNetwork::clock(unsigned int ms) return; } - in_addr address; - unsigned int port; - int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port); + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrlen); if (length < 0) { LogError("DMR, Socket has failed, retrying connection to the master"); close(); @@ -390,7 +391,7 @@ void CDMRNetwork::clock(unsigned int ms) // if (m_debug && length > 0) // CUtils::dump(1U, "Network Received", m_buffer, length); - if (length > 0 && m_address.s_addr == address.s_addr && m_port == port) { + if (length > 0 && CUDPSocket::match(m_address, address)) { if (::memcmp(m_buffer, "DMRD", 4U) == 0) { if (m_enabled) { if (m_debug) @@ -663,7 +664,7 @@ bool CDMRNetwork::write(const unsigned char* data, unsigned int length) // if (m_debug) // CUtils::dump(1U, "Network Transmitted", data, length); - bool ret = m_socket.write(data, length, m_address, m_port); + bool ret = m_socket.write(data, length, m_address, m_addrlen); if (!ret) { LogError("DMR, Socket has failed when writing data to the master, retrying connection"); m_socket.close(); diff --git a/DMRNetwork.h b/DMRNetwork.h index 9d1c52e..96f1074 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -60,7 +60,8 @@ public: private: std::string m_addressStr; - in_addr m_address; + sockaddr_storage m_address; + unsigned int m_addrlen; unsigned int m_port; uint8_t* m_id; std::string m_password; diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index de0af69..295c289 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -33,7 +33,7 @@ const unsigned int BUFFER_LENGTH = 100U; CDStarNetwork::CDStarNetwork(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, bool duplex, const char* version, bool debug) : m_socket(localPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_duplex(duplex), m_version(version), m_debug(debug), @@ -46,7 +46,7 @@ m_pollTimer(1000U, 60U), m_linkStatus(LS_NONE), m_linkReflector(NULL) { - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH]; @@ -63,7 +63,7 @@ bool CDStarNetwork::open() { LogMessage("Opening D-Star network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; m_pollTimer.start(); @@ -100,7 +100,7 @@ bool CDStarNetwork::writeHeader(const unsigned char* header, unsigned int length CUtils::dump(1U, "D-Star Network Header Sent", buffer, 49U); for (unsigned int i = 0U; i < 2U; i++) { - bool ret = m_socket.write(buffer, 49U, m_address, m_port); + bool ret = m_socket.write(buffer, 49U, m_address, m_addrlen); if (!ret) return false; } @@ -143,7 +143,7 @@ bool CDStarNetwork::writeData(const unsigned char* data, unsigned int length, un if (m_debug) CUtils::dump(1U, "D-Star Network Data Sent", buffer, length + 9U); - return m_socket.write(buffer, length + 9U, m_address, m_port); + return m_socket.write(buffer, length + 9U, m_address, m_addrlen); } bool CDStarNetwork::writePoll(const char* text) @@ -167,7 +167,7 @@ bool CDStarNetwork::writePoll(const char* text) // if (m_debug) // CUtils::dump(1U, "D-Star Network Poll Sent", buffer, 6U + length); - return m_socket.write(buffer, 6U + length, m_address, m_port); + return m_socket.write(buffer, 6U + length, m_address, m_addrlen); } void CDStarNetwork::clock(unsigned int ms) @@ -192,18 +192,12 @@ void CDStarNetwork::clock(unsigned int ms) unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || m_port != port) { - LogMessage("D-Star packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - // Invalid packet type? if (::memcmp(buffer, "DSRP", 4U) != 0) return; diff --git a/DStarNetwork.h b/DStarNetwork.h index aeebbbf..6f96880 100644 --- a/DStarNetwork.h +++ b/DStarNetwork.h @@ -51,8 +51,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; bool m_duplex; const char* m_version; bool m_debug; diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 53f6d1f..4769895 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -316,8 +316,8 @@ int CMMDVMHost::run() return 1; } - in_addr transparentAddress; - unsigned int transparentPort = 0U; + sockaddr_storage transparentAddress; + unsigned int transparentAddrLen; CUDPSocket* transparentSocket = NULL; unsigned int sendFrameType = 0U; @@ -333,8 +333,7 @@ int CMMDVMHost::run() LogInfo(" Local Port: %u", localPort); LogInfo(" Send Frame Type: %u", sendFrameType); - transparentAddress = CUDPSocket::lookup(remoteAddress); - transparentPort = remotePort; + CUDPSocket::lookup(remoteAddress, remotePort, transparentAddress, transparentAddrLen); transparentSocket = new CUDPSocket(localPort); ret = transparentSocket->open(); @@ -793,7 +792,7 @@ int CMMDVMHost::run() len = m_modem->readTransparentData(data); if (transparentSocket != NULL && len > 0U) - transparentSocket->write(data, len, transparentAddress, transparentPort); + transparentSocket->write(data, len, transparentAddress, transparentAddrLen); if (!m_fixedMode) { if (m_modeTimer.isRunning() && m_modeTimer.hasExpired()) @@ -942,9 +941,9 @@ int CMMDVMHost::run() } if (transparentSocket != NULL) { - in_addr address; - unsigned int port = 0U; - len = transparentSocket->read(data, 200U, address, port); + sockaddr_storage address; + unsigned int addrlen; + len = transparentSocket->read(data, 200U, address, addrlen); if (len > 0U) m_modem->writeTransparentData(data, len); } diff --git a/MobileGPS.cpp b/MobileGPS.cpp index 27721bd..7cd782e 100644 --- a/MobileGPS.cpp +++ b/MobileGPS.cpp @@ -26,7 +26,7 @@ CMobileGPS::CMobileGPS(const std::string& address, unsigned int port, CDMRNetwork* network) : m_idTimer(1000U, 60U), m_address(), -m_port(port), +m_addrlen(), m_socket(), m_network(network) { @@ -34,7 +34,7 @@ m_network(network) assert(port > 0U); assert(network != NULL); - m_address = CUDPSocket::lookup(address); + CUDPSocket::lookup(address, port, m_address, m_addrlen); } CMobileGPS::~CMobileGPS() @@ -71,16 +71,16 @@ void CMobileGPS::close() bool CMobileGPS::pollGPS() { - return m_socket.write((unsigned char*)"MMDVMHost", 9U, m_address, m_port); + return m_socket.write((unsigned char*)"MMDVMHost", 9U, m_address, m_addrlen); } void CMobileGPS::sendReport() { // Grab GPS data if it's available unsigned char buffer[200U]; - in_addr address; - unsigned int port; - int ret = m_socket.read(buffer, 200U, address, port); + sockaddr_storage address; + unsigned int addrlen; + int ret = m_socket.read(buffer, 200U, address, addrlen); if (ret <= 0) return; diff --git a/MobileGPS.h b/MobileGPS.h index 8d69572..8384c65 100644 --- a/MobileGPS.h +++ b/MobileGPS.h @@ -51,8 +51,8 @@ public: private: CTimer m_idTimer; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; CUDPSocket m_socket; CDMRNetwork* m_network; diff --git a/NXDNNetwork.cpp b/NXDNNetwork.cpp index 9e26900..dcf215e 100644 --- a/NXDNNetwork.cpp +++ b/NXDNNetwork.cpp @@ -31,7 +31,7 @@ const unsigned int BUFFER_LENGTH = 200U; CNXDNNetwork::CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) : m_socket(localAddress, localPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_debug(debug), m_enabled(false), m_buffer(1000U, "NXDN Network") @@ -39,7 +39,7 @@ m_buffer(1000U, "NXDN Network") assert(gatewayPort > 0U); assert(!gatewayAddress.empty()); - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); } CNXDNNetwork::~CNXDNNetwork() @@ -50,7 +50,7 @@ bool CNXDNNetwork::open() { LogMessage("Opening NXDN network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; return m_socket.open(); @@ -100,25 +100,19 @@ bool CNXDNNetwork::write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE ty if (m_debug) CUtils::dump(1U, "NXDN Network Data Sent", buffer, 102U); - return m_socket.write(buffer, 102U, m_address, m_port); + return m_socket.write(buffer, 102U, m_address, m_addrlen); } void CNXDNNetwork::clock(unsigned int ms) { unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || port != m_port) { - LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - // Invalid packet type? if (::memcmp(buffer, "ICOM", 4U) != 0) return; diff --git a/NXDNNetwork.h b/NXDNNetwork.h index 3a5b784..ec428d9 100644 --- a/NXDNNetwork.h +++ b/NXDNNetwork.h @@ -57,8 +57,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; bool m_debug; bool m_enabled; CRingBuffer m_buffer; diff --git a/P25Network.cpp b/P25Network.cpp index 14a0fd5..a326966 100644 --- a/P25Network.cpp +++ b/P25Network.cpp @@ -90,13 +90,13 @@ const unsigned int BUFFER_LENGTH = 100U; CP25Network::CP25Network(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, bool debug) : m_socket(localPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_debug(debug), m_enabled(false), m_buffer(1000U, "P25 Network"), m_audio() { - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); } CP25Network::~CP25Network() @@ -107,7 +107,7 @@ bool CP25Network::open() { LogMessage("Opening P25 network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; return m_socket.open(); @@ -126,7 +126,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 22U); - bool ret = m_socket.write(buffer, 22U, m_address, m_port); + bool ret = m_socket.write(buffer, 22U, m_address, m_addrlen); if (!ret) return false; @@ -137,7 +137,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 14U); - ret = m_socket.write(buffer, 14U, m_address, m_port); + ret = m_socket.write(buffer, 14U, m_address, m_addrlen); if (!ret) return false; @@ -150,7 +150,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -165,7 +165,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -180,7 +180,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -191,7 +191,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -202,7 +202,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -213,7 +213,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -226,7 +226,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 16U); - ret = m_socket.write(buffer, 16U, m_address, m_port); + ret = m_socket.write(buffer, 16U, m_address, m_addrlen); if (!ret) return false; @@ -234,7 +234,7 @@ bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network END Sent", REC80, 17U); - ret = m_socket.write(REC80, 17U, m_address, m_port); + ret = m_socket.write(REC80, 17U, m_address, m_addrlen); if (!ret) return false; } @@ -255,7 +255,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 22U); - bool ret = m_socket.write(buffer, 22U, m_address, m_port); + bool ret = m_socket.write(buffer, 22U, m_address, m_addrlen); if (!ret) return false; @@ -266,7 +266,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 14U); - ret = m_socket.write(buffer, 14U, m_address, m_port); + ret = m_socket.write(buffer, 14U, m_address, m_addrlen); if (!ret) return false; @@ -283,7 +283,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -297,7 +297,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -311,7 +311,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -326,7 +326,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -337,7 +337,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -348,7 +348,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U); - ret = m_socket.write(buffer, 17U, m_address, m_port); + ret = m_socket.write(buffer, 17U, m_address, m_addrlen); if (!ret) return false; @@ -361,7 +361,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 16U); - ret = m_socket.write(buffer, 16U, m_address, m_port); + ret = m_socket.write(buffer, 16U, m_address, m_addrlen); if (!ret) return false; @@ -369,7 +369,7 @@ bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, if (m_debug) CUtils::dump(1U, "P25 Network END Sent", REC80, 17U); - ret = m_socket.write(REC80, 17U, m_address, m_port); + ret = m_socket.write(REC80, 17U, m_address, m_addrlen); if (!ret) return false; } @@ -381,18 +381,12 @@ void CP25Network::clock(unsigned int ms) { unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || m_port != port) { - LogMessage("P25 packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - if (!m_enabled) return; diff --git a/P25Network.h b/P25Network.h index 054c772..009c994 100644 --- a/P25Network.h +++ b/P25Network.h @@ -49,8 +49,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; bool m_debug; bool m_enabled; CRingBuffer m_buffer; diff --git a/POCSAGNetwork.cpp b/POCSAGNetwork.cpp index 682fdd1..e6b755a 100644 --- a/POCSAGNetwork.cpp +++ b/POCSAGNetwork.cpp @@ -31,12 +31,12 @@ const unsigned int BUFFER_LENGTH = 200U; CPOCSAGNetwork::CPOCSAGNetwork(const std::string& myAddress, unsigned int myPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) : m_socket(myAddress, myPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_debug(debug), m_enabled(false), m_buffer(1000U, "POCSAG Network") { - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); } CPOCSAGNetwork::~CPOCSAGNetwork() @@ -47,7 +47,7 @@ bool CPOCSAGNetwork::open() { LogMessage("Opening POCSAG network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; return m_socket.open(); @@ -57,18 +57,12 @@ void CPOCSAGNetwork::clock(unsigned int ms) { unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || m_port != port) { - LogMessage("POCSAG packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - // Invalid packet type? if (::memcmp(buffer, "POCSAG", 6U) != 0) return; @@ -118,7 +112,7 @@ void CPOCSAGNetwork::enable(bool enabled) unsigned char c = enabled ? 0x00U : 0xFFU; - m_socket.write(&c, 1U, m_address, m_port); + m_socket.write(&c, 1U, m_address, m_addrlen); m_enabled = enabled; } diff --git a/POCSAGNetwork.h b/POCSAGNetwork.h index fe95203..dd3945b 100644 --- a/POCSAGNetwork.h +++ b/POCSAGNetwork.h @@ -46,8 +46,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; bool m_debug; bool m_enabled; CRingBuffer m_buffer; diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index bf3fb1e..42a09be 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -67,9 +67,11 @@ int CRemoteCommand::send(const std::string& command) if (!ret) return 1; - in_addr address = CUDPSocket::lookup("localhost"); + sockaddr_storage address; + unsigned int addrlen; + CUDPSocket::lookup("localhost", m_port, address, addrlen); - ret = socket.write((unsigned char*)command.c_str(), command.length(), address, m_port); + ret = socket.write((unsigned char*)command.c_str(), command.length(), address, addrlen); if (!ret) { socket.close(); return 1; diff --git a/RemoteControl.cpp b/RemoteControl.cpp index afa1473..0c72f6b 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -53,9 +53,9 @@ REMOTE_COMMAND CRemoteControl::getCommand() char command[BUFFER_LENGTH]; char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int ret = m_socket.read((unsigned char*)buffer, BUFFER_LENGTH, address, port); + sockaddr_storage address; + unsigned int addrlen; + int ret = m_socket.read((unsigned char*)buffer, BUFFER_LENGTH, address, addrlen); if (ret > 0) { buffer[ret] = '\0'; diff --git a/YSFNetwork.cpp b/YSFNetwork.cpp index a8effba..ff5cab8 100644 --- a/YSFNetwork.cpp +++ b/YSFNetwork.cpp @@ -31,7 +31,7 @@ const unsigned int BUFFER_LENGTH = 200U; CYSFNetwork::CYSFNetwork(const std::string& myAddress, unsigned int myPort, const std::string& gatewayAddress, unsigned int gatewayPort, const std::string& callsign, bool debug) : m_socket(myAddress, myPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_callsign(), m_debug(debug), m_enabled(false), @@ -42,7 +42,7 @@ m_tag(NULL) m_callsign = callsign; m_callsign.resize(YSF_CALLSIGN_LENGTH, ' '); - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); m_tag = new unsigned char[YSF_CALLSIGN_LENGTH]; ::memset(m_tag, ' ', YSF_CALLSIGN_LENGTH); @@ -57,7 +57,7 @@ bool CYSFNetwork::open() { LogMessage("Opening YSF network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; m_pollTimer.start(); @@ -97,7 +97,7 @@ bool CYSFNetwork::write(const unsigned char* src, const unsigned char* dest, con if (m_debug) CUtils::dump(1U, "YSF Network Data Sent", buffer, 155U); - return m_socket.write(buffer, 155U, m_address, m_port); + return m_socket.write(buffer, 155U, m_address, m_addrlen); } bool CYSFNetwork::writePoll() @@ -115,7 +115,7 @@ bool CYSFNetwork::writePoll() if (m_debug) CUtils::dump(1U, "YSF Network Poll Sent", buffer, 14U); - return m_socket.write(buffer, 14U, m_address, m_port); + return m_socket.write(buffer, 14U, m_address, m_addrlen); } void CYSFNetwork::clock(unsigned int ms) @@ -128,18 +128,12 @@ void CYSFNetwork::clock(unsigned int ms) unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || m_port != port) { - LogMessage("YSF packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - // Ignore incoming polls if (::memcmp(buffer, "YSFP", 4U) == 0) return; diff --git a/YSFNetwork.h b/YSFNetwork.h index e9a430f..292364d 100644 --- a/YSFNetwork.h +++ b/YSFNetwork.h @@ -48,8 +48,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; std::string m_callsign; bool m_debug; bool m_enabled; From dad47317e638d22c8d4008eb63032895ba1739ca Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sun, 29 Mar 2020 15:06:20 +0900 Subject: [PATCH 04/16] set INADDR_ANY/IN6ADDR_ANY_INIT address string to m_socket when CUDPSocket::open() is called with m_address (in CUDPSocket) is nothing, IPv4 socket is created by "0.0.0.0" (INADDR_ANY) address. This causes a problem that DMRGateway cannot connect to reflector on IPv6. To choose default INADDR_ANY/IN6ADDR_ANY_INIT address, added open(address_family) in UDPSocket.cpp. Following code sets address string at construction, not modified. NXDNNetwork.cpp POCSAGNetwork.cpp YSFNetwork.cpp Other codes does not set, modified open() -> open(address_family) DMRNetwork.cpp DStarNetwork.cpp MMDVMHost.cpp MobileGPS.cpp P25Network.cpp RemoteCommand.cpp RemoteControl.cpp I think there is more clever method, but I have no other idea. Maybe IPv6 support for digital radio works, but RemoteControl can work IPv4 only. --- DMRNetwork.cpp | 2 +- DStarNetwork.cpp | 2 +- MMDVMHost.cpp | 2 +- MobileGPS.cpp | 2 +- P25Network.cpp | 2 +- RemoteCommand.cpp | 14 +++++++------- RemoteControl.cpp | 2 +- UDPSocket.cpp | 25 ++++++++++++++++++++++++- UDPSocket.h | 1 + 9 files changed, 38 insertions(+), 14 deletions(-) diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index ea52096..91ae0a4 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -362,7 +362,7 @@ void CDMRNetwork::clock(unsigned int ms) if (m_status == WAITING_CONNECT) { m_retryTimer.clock(ms); if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) { - bool ret = m_socket.open(); + bool ret = m_socket.open(m_address.ss_family); if (ret) { ret = writeLogin(); if (!ret) diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index 295c289..072b7cf 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -68,7 +68,7 @@ bool CDStarNetwork::open() m_pollTimer.start(); - return m_socket.open(); + return m_socket.open(m_address.ss_family); } bool CDStarNetwork::writeHeader(const unsigned char* header, unsigned int length, bool busy) diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 4769895..9f792e5 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -336,7 +336,7 @@ int CMMDVMHost::run() CUDPSocket::lookup(remoteAddress, remotePort, transparentAddress, transparentAddrLen); transparentSocket = new CUDPSocket(localPort); - ret = transparentSocket->open(); + ret = transparentSocket->open(transparentAddress.ss_family); if (!ret) { LogWarning("Could not open the Transparent data socket, disabling"); delete transparentSocket; diff --git a/MobileGPS.cpp b/MobileGPS.cpp index 7cd782e..0cb2c3b 100644 --- a/MobileGPS.cpp +++ b/MobileGPS.cpp @@ -43,7 +43,7 @@ CMobileGPS::~CMobileGPS() bool CMobileGPS::open() { - bool ret = m_socket.open(); + bool ret = m_socket.open(m_address.ss_family); if (!ret) return false; diff --git a/P25Network.cpp b/P25Network.cpp index a326966..ed28fa6 100644 --- a/P25Network.cpp +++ b/P25Network.cpp @@ -110,7 +110,7 @@ bool CP25Network::open() if (CUDPSocket::isnone(m_address)) return false; - return m_socket.open(); + return m_socket.open(m_address.ss_family); } bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, const CP25LowSpeedData& lsd, bool end) diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index 42a09be..9d7b038 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -61,15 +61,15 @@ CRemoteCommand::~CRemoteCommand() int CRemoteCommand::send(const std::string& command) { - CUDPSocket socket(0U); - - bool ret = socket.open(); - if (!ret) - return 1; - sockaddr_storage address; unsigned int addrlen; - CUDPSocket::lookup("localhost", m_port, address, addrlen); + CUDPSocket::lookup("127.0.0.1", m_port, address, addrlen); + + CUDPSocket socket(0U); + + bool ret = socket.open(address.ss_family); + if (!ret) + return 1; ret = socket.write((unsigned char*)command.c_str(), command.length(), address, addrlen); if (!ret) { diff --git a/RemoteControl.cpp b/RemoteControl.cpp index 0c72f6b..0c29791 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -43,7 +43,7 @@ CRemoteControl::~CRemoteControl() bool CRemoteControl::open() { - return m_socket.open(); + return m_socket.open(AF_INET); /* XXX IPv4 only */ } REMOTE_COMMAND CRemoteControl::getCommand() diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 9e5e2cf..a2b5991 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -117,14 +117,37 @@ bool CUDPSocket::isnone(const sockaddr_storage &addr) (in->sin_addr.s_addr == htonl(INADDR_NONE)) ); } +bool CUDPSocket::open(const unsigned int af) +{ + switch (af) { + case AF_INET6: + m_address = "::"; + break; + case AF_INET: + m_address = "0.0.0.0"; + break; + default: + LogWarning("unknown address family - %d", af); + break; + } + + return open(); +} + bool CUDPSocket::open() { int err; sockaddr_storage addr; unsigned int addrlen; + /* m_address should be defined */ + if (m_address.empty()) { + LogError("The local address is undefined"); + return false; + } + /* to determine protocol family, call lookup() first. */ - err = lookup(m_address.empty() ? "0.0.0.0" : m_address.c_str(), m_port, addr, addrlen); + err = lookup(m_address.c_str(), m_port, addr, addrlen); if (err) { LogError("The local address is invalid - %s", m_address.c_str()); return false; diff --git a/UDPSocket.h b/UDPSocket.h index 288273f..b5add46 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -42,6 +42,7 @@ public: ~CUDPSocket(); bool open(); + bool open(const unsigned int af); int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length); bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length); From 15b5011ebf0212894ca5bf574c1fc1efddf81c72 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 4 Apr 2020 15:18:55 +0900 Subject: [PATCH 05/16] rewrite with getaddrinfo() API to support IPv6 Currently LCDproc seems to be IPv6 unsupported, but this code is modified for the future IPv6-supported LCDproc. --- LCDproc.cpp | 57 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/LCDproc.cpp b/LCDproc.cpp index 8ef2721..eddba78 100644 --- a/LCDproc.cpp +++ b/LCDproc.cpp @@ -121,44 +121,53 @@ CLCDproc::~CLCDproc() bool CLCDproc::open() { - const char *server; - unsigned int port, localPort; - struct sockaddr_in serverAddress, clientAddress; - struct hostent *h; + int err; + unsigned int addrlen; + std::string port, localPort; + struct sockaddr_storage serverAddress, clientAddress; + struct addrinfo hints, *res; - server = m_address.c_str(); - port = m_port; - localPort = m_localPort; + port = std::to_string(m_port); + localPort = std::to_string(m_localPort); + memset(&hints, 0, sizeof(hints)); + /* Lookup the hostname address */ + hints.ai_flags = AI_NUMERICSERV; + hints.ai_socktype = SOCK_STREAM; + err = getaddrinfo(m_address.c_str(), port.c_str(), &hints, &res); + if (err) { + LogError("LCDproc, cannot lookup server"); + return false; + } + memcpy(&serverAddress, res->ai_addr, addrlen = res->ai_addrlen); + freeaddrinfo(res); + + /* Lookup the client address (random port - need to specify manual port from ini file) */ + hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE; + hints.ai_family = serverAddress.ss_family; + err = getaddrinfo(NULL, localPort.c_str(), &hints, &res); + if (err) { + LogError("LCDproc, cannot lookup client"); + return false; + } + memcpy(&clientAddress, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); /* Create TCP socket */ - m_socketfd = socket(AF_INET, SOCK_STREAM, 0); + m_socketfd = socket(clientAddress.ss_family, SOCK_STREAM, 0); if (m_socketfd == -1) { LogError("LCDproc, failed to create socket"); return false; } - /* Sets client address (random port - need to specify manual port from ini file?) */ - clientAddress.sin_family = AF_INET; - clientAddress.sin_addr.s_addr = htonl(INADDR_ANY); - //clientAddress.sin_port = htons(0); - clientAddress.sin_port = htons(localPort); - /* Bind the address to the socket */ - if (bind(m_socketfd, (struct sockaddr *)&clientAddress, sizeof(clientAddress)) == -1) { + if (bind(m_socketfd, (struct sockaddr *)&clientAddress, addrlen) == -1) { LogError("LCDproc, error whilst binding address"); return false; } - /* Lookup the hostname address */ - h = gethostbyname(server); - - /* Sets server address */ - serverAddress.sin_family = h->h_addrtype; - memcpy((char*)&serverAddress.sin_addr.s_addr, h->h_addr_list[0], h->h_length); - serverAddress.sin_port = htons(port); - - if (connect(m_socketfd, (struct sockaddr * )&serverAddress, sizeof(serverAddress))==-1) { + /* Connect to server */ + if (connect(m_socketfd, (struct sockaddr *)&serverAddress, addrlen) == -1) { LogError("LCDproc, cannot connect to server"); return false; } From 88bbb0cd0f5a76269985e3504a550baadaf7512b Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sun, 5 Apr 2020 07:05:33 +0900 Subject: [PATCH 06/16] use getaddrinfo() AI_PASSIVE flag, to remove "::" and "0.0.0.0" --- UDPSocket.cpp | 46 +++++++++++++++++++++------------------------- UDPSocket.h | 1 + 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index a2b5991..beec3ce 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -61,15 +61,24 @@ CUDPSocket::~CUDPSocket() } int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage &addr, unsigned int &address_length) +{ + struct addrinfo hints; + + ::memset(&hints, 0, sizeof(hints)); + + return lookup(hostname, port, addr, address_length, hints); +} + +int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage &addr, unsigned int &address_length, struct addrinfo &hints) { int err; std::string portstr = std::to_string(port); - struct addrinfo hints, *res; + struct addrinfo *res; - ::memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_flags = AI_NUMERICSERV; + /* port is always digits, no needs to lookup service */ + hints.ai_flags |= AI_NUMERICSERV; - err = getaddrinfo(hostname.c_str(), portstr.c_str(), &hints, &res); + err = getaddrinfo(hostname.empty() ? NULL : hostname.c_str(), portstr.c_str(), &hints, &res); if (err) { sockaddr_in *paddr = (sockaddr_in *)&addr; ::memset(paddr, 0, address_length = sizeof(sockaddr_in)); @@ -117,37 +126,24 @@ bool CUDPSocket::isnone(const sockaddr_storage &addr) (in->sin_addr.s_addr == htonl(INADDR_NONE)) ); } -bool CUDPSocket::open(const unsigned int af) +bool CUDPSocket::open() { - switch (af) { - case AF_INET6: - m_address = "::"; - break; - case AF_INET: - m_address = "0.0.0.0"; - break; - default: - LogWarning("unknown address family - %d", af); - break; - } - - return open(); + return open(AF_UNSPEC); } -bool CUDPSocket::open() +bool CUDPSocket::open(const unsigned int af) { int err; sockaddr_storage addr; unsigned int addrlen; + struct addrinfo hints; - /* m_address should be defined */ - if (m_address.empty()) { - LogError("The local address is undefined"); - return false; - } + ::memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = af; /* to determine protocol family, call lookup() first. */ - err = lookup(m_address.c_str(), m_port, addr, addrlen); + err = lookup(m_address, m_port, addr, addrlen, hints); if (err) { LogError("The local address is invalid - %s", m_address.c_str()); return false; diff --git a/UDPSocket.h b/UDPSocket.h index b5add46..46b2370 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -50,6 +50,7 @@ public: void close(); static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length); + static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length, struct addrinfo &hints); static bool match(const sockaddr_storage &addr1, const sockaddr_storage &addr2); static bool isnone(const sockaddr_storage &addr); From 5df1fe551f232c25dff1302ff1f9350062b93995 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 11 Apr 2020 13:12:19 +0900 Subject: [PATCH 07/16] add IPv6 support for RemoteControl To specify IP(v4/v6) address for RemoteControl port, add Address parameter in [RemoteControl] section to MMDVM.ini. Different from other Address(es), the default IP address of RemoteControl is 127.0.0.1 for security. --- Conf.cpp | 8 ++++++++ Conf.h | 2 ++ MMDVM.ini | 1 + MMDVMHost.cpp | 4 +++- RemoteControl.cpp | 6 +++--- RemoteControl.h | 2 +- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 9325a1b..e365827 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -250,6 +250,7 @@ m_mobileGPSEnabled(false), m_mobileGPSAddress(), m_mobileGPSPort(0U), m_remoteControlEnabled(false), +m_remoteControlAddress("127.0.0.1"), m_remoteControlPort(0U) { } @@ -838,6 +839,8 @@ bool CConf::read() } else if (section == SECTION_REMOTE_CONTROL) { if (::strcmp(key, "Enable") == 0) m_remoteControlEnabled = ::atoi(value) == 1; + else if (::strcmp(key, "Address") == 0) + m_remoteControlAddress = value; else if (::strcmp(key, "Port") == 0) m_remoteControlPort = (unsigned int)::atoi(value); } @@ -1794,6 +1797,11 @@ bool CConf::getRemoteControlEnabled() const return m_remoteControlEnabled; } +std::string CConf::getRemoteControlAddress() const +{ + return m_remoteControlAddress; +} + unsigned int CConf::getRemoteControlPort() const { return m_remoteControlPort; diff --git a/Conf.h b/Conf.h index c76b202..42fa261 100644 --- a/Conf.h +++ b/Conf.h @@ -276,6 +276,7 @@ public: // The Remote Control section bool getRemoteControlEnabled() const; + std::string getRemoteControlAddress() const; unsigned int getRemoteControlPort() const; private: @@ -497,6 +498,7 @@ private: unsigned int m_mobileGPSPort; bool m_remoteControlEnabled; + std::string m_remoteControlAddress; unsigned int m_remoteControlPort; }; diff --git a/MMDVM.ini b/MMDVM.ini index d6a8d84..bf07c6a 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -257,4 +257,5 @@ Port=7834 [Remote Control] Enable=0 +Address=127.0.0.1 Port=7642 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 9f792e5..5ee837a 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -606,12 +606,14 @@ int CMMDVMHost::run() bool remoteControlEnabled = m_conf.getRemoteControlEnabled(); if (remoteControlEnabled) { + std::string address = m_conf.getRemoteControlAddress(); unsigned int port = m_conf.getRemoteControlPort(); LogInfo("Remote Control Parameters"); + LogInfo(" Address: %s", address.c_str()); LogInfo(" Port: %u", port); - m_remoteControl = new CRemoteControl(port); + m_remoteControl = new CRemoteControl(address, port); ret = m_remoteControl->open(); if (!ret) { diff --git a/RemoteControl.cpp b/RemoteControl.cpp index 0c29791..e982894 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -29,8 +29,8 @@ const unsigned int PAGE_ARGS = 3U; const unsigned int BUFFER_LENGTH = 100U; -CRemoteControl::CRemoteControl(unsigned int port) : -m_socket(port), +CRemoteControl::CRemoteControl(const std::string address, unsigned int port) : +m_socket(address, port), m_command(RCD_NONE), m_args() { @@ -43,7 +43,7 @@ CRemoteControl::~CRemoteControl() bool CRemoteControl::open() { - return m_socket.open(AF_INET); /* XXX IPv4 only */ + return m_socket.open(); } REMOTE_COMMAND CRemoteControl::getCommand() diff --git a/RemoteControl.h b/RemoteControl.h index 479987a..079d983 100644 --- a/RemoteControl.h +++ b/RemoteControl.h @@ -38,7 +38,7 @@ enum REMOTE_COMMAND { class CRemoteControl { public: - CRemoteControl(unsigned int port); + CRemoteControl(const std::string address, unsigned int port); ~CRemoteControl(); bool open(); From 6de0bdb5360b76d75bec692f7786357bd712c8ca Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Fri, 3 Jul 2020 04:35:22 +0900 Subject: [PATCH 08/16] add match_addr() match() compares IP address and port match_addr() compares IP address only --- UDPSocket.cpp | 21 +++++++++++++++++++++ UDPSocket.h | 1 + 2 files changed, 22 insertions(+) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index beec3ce..0bbe27b 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -118,6 +118,27 @@ bool CUDPSocket::match(const sockaddr_storage &addr1, const sockaddr_storage &ad } } +bool CUDPSocket::match_addr(const sockaddr_storage &addr1, const sockaddr_storage &addr2) +{ + if (addr1.ss_family != addr2.ss_family) + return false; + + switch (addr1.ss_family) { + case AF_INET: + struct sockaddr_in *in_1, *in_2; + in_1 = (struct sockaddr_in *)&addr1; + in_2 = (struct sockaddr_in *)&addr2; + return (in_1->sin_addr.s_addr == in_2->sin_addr.s_addr); + case AF_INET6: + struct sockaddr_in6 *in6_1, *in6_2; + in6_1 = (struct sockaddr_in6 *)&addr1; + in6_2 = (struct sockaddr_in6 *)&addr2; + return IN6_ARE_ADDR_EQUAL(&in6_1->sin6_addr, &in6_2->sin6_addr); + default: + return false; + } +} + bool CUDPSocket::isnone(const sockaddr_storage &addr) { struct sockaddr_in *in = (struct sockaddr_in *)&addr; diff --git a/UDPSocket.h b/UDPSocket.h index 46b2370..ad5b2a1 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -52,6 +52,7 @@ public: static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length); static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage &address, unsigned int &address_length, struct addrinfo &hints); static bool match(const sockaddr_storage &addr1, const sockaddr_storage &addr2); + static bool match_addr(const sockaddr_storage &addr1, const sockaddr_storage &addr2); static bool isnone(const sockaddr_storage &addr); private: From 8a0db8cb8b685c5af1cfaa9d537578d753370e7f Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Fri, 3 Jul 2020 04:40:41 +0900 Subject: [PATCH 09/16] NXDNIcomNetwork: IPv6 support --- NXDNIcomNetwork.cpp | 22 ++++++++-------------- NXDNIcomNetwork.h | 4 ++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/NXDNIcomNetwork.cpp b/NXDNIcomNetwork.cpp index 2f3767b..3b340cc 100644 --- a/NXDNIcomNetwork.cpp +++ b/NXDNIcomNetwork.cpp @@ -31,7 +31,7 @@ const unsigned int BUFFER_LENGTH = 200U; CNXDNIcomNetwork::CNXDNIcomNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) : m_socket(localAddress, localPort), m_address(), -m_port(gatewayPort), +m_addrlen(), m_debug(debug), m_enabled(false), m_buffer(1000U, "NXDN Network") @@ -39,7 +39,7 @@ m_buffer(1000U, "NXDN Network") assert(gatewayPort > 0U); assert(!gatewayAddress.empty()); - m_address = CUDPSocket::lookup(gatewayAddress); + CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen); } CNXDNIcomNetwork::~CNXDNIcomNetwork() @@ -50,7 +50,7 @@ bool CNXDNIcomNetwork::open() { LogMessage("Opening NXDN network connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_address)) return false; return m_socket.open(); @@ -100,25 +100,19 @@ bool CNXDNIcomNetwork::write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYP if (m_debug) CUtils::dump(1U, "NXDN Network Data Sent", buffer, 102U); - return m_socket.write(buffer, 102U, m_address, m_port); + return m_socket.write(buffer, 102U, m_address, m_addrlen); } void CNXDNIcomNetwork::clock(unsigned int ms) { unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_socket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match(m_address, address)) return; - // Check if the data is for us - if (m_address.s_addr != address.s_addr || port != m_port) { - LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); - return; - } - // Invalid packet type? if (::memcmp(buffer, "ICOM", 4U) != 0) return; diff --git a/NXDNIcomNetwork.h b/NXDNIcomNetwork.h index 05fb023..18bdd97 100644 --- a/NXDNIcomNetwork.h +++ b/NXDNIcomNetwork.h @@ -49,8 +49,8 @@ public: private: CUDPSocket m_socket; - in_addr m_address; - unsigned int m_port; + sockaddr_storage m_address; + unsigned int m_addrlen; bool m_debug; bool m_enabled; CRingBuffer m_buffer; From 9137399ea92a87c90e81985f2defebf52d71c55c Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Fri, 3 Jul 2020 06:56:36 +0900 Subject: [PATCH 10/16] NXDNKenwoodNetwork: IPv6 support --- NXDNKenwoodNetwork.cpp | 58 +++++++++++++++++------------------------- NXDNKenwoodNetwork.h | 6 ++--- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/NXDNKenwoodNetwork.cpp b/NXDNKenwoodNetwork.cpp index e873bd3..f84af6e 100644 --- a/NXDNKenwoodNetwork.cpp +++ b/NXDNKenwoodNetwork.cpp @@ -36,9 +36,9 @@ const unsigned int BUFFER_LENGTH = 200U; CNXDNKenwoodNetwork::CNXDNKenwoodNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gwyAddress, unsigned int gwyPort, bool debug) : m_rtpSocket(localAddress, localPort + 0U), m_rtcpSocket(localAddress, localPort + 1U), -m_address(), -m_rtcpPort(gwyPort + 1U), -m_rtpPort(gwyPort + 0U), +m_rtcpaddress(), +m_rtpaddress(), +m_addrlen(), m_enabled(false), m_headerSeen(false), m_seen1(false), @@ -65,7 +65,8 @@ m_random() m_sacch = new unsigned char[10U]; - m_address = CUDPSocket::lookup(gwyAddress); + CUDPSocket::lookup(gwyAddress, gwyPort + 1, m_rtcpaddress, m_addrlen); + CUDPSocket::lookup(gwyAddress, gwyPort, m_rtpaddress, m_addrlen); std::random_device rd; std::mt19937 mt(rd()); @@ -81,7 +82,8 @@ bool CNXDNKenwoodNetwork::open() { LogMessage("Opening Kenwood connection"); - if (m_address.s_addr == INADDR_NONE) + if (CUDPSocket::isnone(m_rtpaddress) || + CUDPSocket::isnone(m_rtcpaddress)) return false; if (!m_rtcpSocket.open()) @@ -363,7 +365,7 @@ bool CNXDNKenwoodNetwork::writeRTPVoiceHeader(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 47U); - return m_rtpSocket.write(buffer, 47U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 47U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTPVoiceTrailer(const unsigned char* data) @@ -409,7 +411,7 @@ bool CNXDNKenwoodNetwork::writeRTPVoiceTrailer(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 47U); - return m_rtpSocket.write(buffer, 47U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 47U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTPVoiceData(const unsigned char* data) @@ -455,7 +457,7 @@ bool CNXDNKenwoodNetwork::writeRTPVoiceData(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 59U); - return m_rtpSocket.write(buffer, 59U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 59U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTPDataHeader(const unsigned char* data) @@ -497,7 +499,7 @@ bool CNXDNKenwoodNetwork::writeRTPDataHeader(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 42U); - return m_rtpSocket.write(buffer, 42U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 42U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTPDataTrailer(const unsigned char* data) @@ -539,7 +541,7 @@ bool CNXDNKenwoodNetwork::writeRTPDataTrailer(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 42U); - return m_rtpSocket.write(buffer, 42U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 42U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTPDataData(const unsigned char* data) @@ -581,7 +583,7 @@ bool CNXDNKenwoodNetwork::writeRTPDataData(const unsigned char* data) if (m_debug) CUtils::dump(1U, "Kenwood Network RTP Data Sent", buffer, 42U); - return m_rtpSocket.write(buffer, 42U, m_address, m_rtpPort); + return m_rtpSocket.write(buffer, 42U, m_rtpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTCPStart() @@ -641,7 +643,7 @@ bool CNXDNKenwoodNetwork::writeRTCPStart() if (m_debug) CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 28U); - return m_rtcpSocket.write(buffer, 28U, m_address, m_rtcpPort); + return m_rtcpSocket.write(buffer, 28U, m_rtcpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTCPPing() @@ -683,7 +685,7 @@ bool CNXDNKenwoodNetwork::writeRTCPPing() if (m_debug) CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 28U); - return m_rtcpSocket.write(buffer, 28U, m_address, m_rtcpPort); + return m_rtcpSocket.write(buffer, 28U, m_rtcpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::writeRTCPHang(unsigned char type, unsigned short src, unsigned short dst) @@ -726,7 +728,7 @@ bool CNXDNKenwoodNetwork::writeRTCPHang() if (m_debug) CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 20U); - return m_rtcpSocket.write(buffer, 20U, m_address, m_rtcpPort); + return m_rtcpSocket.write(buffer, 20U, m_rtcpaddress, m_addrlen); } bool CNXDNKenwoodNetwork::read(unsigned char* data) @@ -761,18 +763,12 @@ unsigned int CNXDNKenwoodNetwork::readRTP(unsigned char* data) unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_rtpSocket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_rtpSocket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match_addr(m_rtpaddress, address)) return 0U; - // Check if the data is for us - if (m_address.s_addr != address.s_addr) { - LogMessage("Kenwood RTP packet received from an invalid source, %08X != %08X", m_address.s_addr, address.s_addr); - return 0U; - } - if (!m_enabled) return 0U; @@ -790,18 +786,12 @@ unsigned int CNXDNKenwoodNetwork::readRTCP(unsigned char* data) unsigned char buffer[BUFFER_LENGTH]; - in_addr address; - unsigned int port; - int length = m_rtcpSocket.read(buffer, BUFFER_LENGTH, address, port); - if (length <= 0) + sockaddr_storage address; + unsigned int addrlen; + int length = m_rtcpSocket.read(buffer, BUFFER_LENGTH, address, addrlen); + if (length <= 0 || !CUDPSocket::match_addr(m_rtcpaddress, address)) return 0U; - // Check if the data is for us - if (m_address.s_addr != address.s_addr) { - LogMessage("Kenwood RTCP packet received from an invalid source, %08X != %08X", m_address.s_addr, address.s_addr); - return 0U; - } - if (!m_enabled) return 0U; diff --git a/NXDNKenwoodNetwork.h b/NXDNKenwoodNetwork.h index 6645c23..3466569 100644 --- a/NXDNKenwoodNetwork.h +++ b/NXDNKenwoodNetwork.h @@ -49,9 +49,9 @@ public: private: CUDPSocket m_rtpSocket; CUDPSocket m_rtcpSocket; - in_addr m_address; - unsigned int m_rtcpPort; - unsigned int m_rtpPort; + sockaddr_storage m_rtcpaddress; + sockaddr_storage m_rtpaddress; + unsigned int m_addrlen; bool m_enabled; bool m_headerSeen; bool m_seen1; From 66a17f4849ac92f6e1e82c51bc5851162db4b291 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 26 Aug 2020 09:29:11 +0100 Subject: [PATCH 11/16] Simplify the Host to DMR Gateway protocol. --- Conf.cpp | 76 --------- Conf.h | 21 --- DMRNetwork.cpp | 344 ++++++-------------------------------- DMRNetwork.h | 59 ++----- Display.cpp | 6 +- GPSD.cpp | 103 ------------ GPSD.h | 54 ------ MMDVM.ini | 11 -- MMDVMHost.cpp | 67 +------- MMDVMHost.h | 5 - MMDVMHost.vcxproj | 2 - MMDVMHost.vcxproj.filters | 6 - Makefile | 9 +- Makefile.Pi | 8 +- Makefile.Pi.Adafruit | 8 +- Makefile.Pi.HD44780 | 9 +- Makefile.Pi.OLED | 9 +- Makefile.Pi.PCF8574 | 9 +- Nextion.cpp | 10 +- Nextion.h | 3 +- Version.h | 2 +- 21 files changed, 81 insertions(+), 740 deletions(-) delete mode 100644 GPSD.cpp delete mode 100644 GPSD.h diff --git a/Conf.cpp b/Conf.cpp index 7491717..8b2578b 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -57,7 +57,6 @@ enum SECTION { SECTION_OLED, SECTION_LCDPROC, SECTION_LOCK_FILE, - SECTION_GPSD, SECTION_REMOTE_CONTROL }; @@ -72,12 +71,6 @@ m_daemon(false), m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), -m_latitude(0.0F), -m_longitude(0.0F), -m_height(0), -m_location(), -m_description(), -m_url(), m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), @@ -282,9 +275,6 @@ m_lcdprocUTC(false), m_lcdprocDimOnIdle(false), m_lockFileEnabled(false), m_lockFileName(), -m_gpsdEnabled(false), -m_gpsdAddress(), -m_gpsdPort(), m_remoteControlEnabled(false), m_remoteControlPort(0U) { @@ -366,8 +356,6 @@ bool CConf::read() section = SECTION_LCDPROC; else if (::strncmp(buffer, "[Lock File]", 11U) == 0) section = SECTION_LOCK_FILE; - else if (::strncmp(buffer, "[GPSD]", 6U) == 0) - section = SECTION_GPSD; else if (::strncmp(buffer, "[Remote Control]", 16U) == 0) section = SECTION_REMOTE_CONTROL; else @@ -432,18 +420,6 @@ bool CConf::read() m_rxFrequency = (unsigned int)::atoi(value); else if (::strcmp(key, "Power") == 0) m_power = (unsigned int)::atoi(value); - else if (::strcmp(key, "Latitude") == 0) - m_latitude = float(::atof(value)); - else if (::strcmp(key, "Longitude") == 0) - m_longitude = float(::atof(value)); - else if (::strcmp(key, "Height") == 0) - m_height = ::atoi(value); - else if (::strcmp(key, "Location") == 0) - m_location = value; - else if (::strcmp(key, "Description") == 0) - m_description = value; - else if (::strcmp(key, "URL") == 0) - m_url = value; } else if (section == SECTION_LOG) { if (::strcmp(key, "FilePath") == 0) m_logFilePath = value; @@ -959,13 +935,6 @@ bool CConf::read() m_lockFileEnabled = ::atoi(value) == 1; else if (::strcmp(key, "File") == 0) m_lockFileName = value; - } else if (section == SECTION_GPSD) { - if (::strcmp(key, "Enable") == 0) - m_gpsdEnabled = ::atoi(value) == 1; - else if (::strcmp(key, "Address") == 0) - m_gpsdAddress = value; - else if (::strcmp(key, "Port") == 0) - m_gpsdPort = value; } else if (section == SECTION_REMOTE_CONTROL) { if (::strcmp(key, "Enable") == 0) m_remoteControlEnabled = ::atoi(value) == 1; @@ -1024,36 +993,6 @@ unsigned int CConf::getPower() const return m_power; } -float CConf::getLatitude() const -{ - return m_latitude; -} - -float CConf::getLongitude() const -{ - return m_longitude; -} - -int CConf::getHeight() const -{ - return m_height; -} - -std::string CConf::getLocation() const -{ - return m_location; -} - -std::string CConf::getDescription() const -{ - return m_description; -} - -std::string CConf::getURL() const -{ - return m_url; -} - unsigned int CConf::getLogDisplayLevel() const { return m_logDisplayLevel; @@ -2075,21 +2014,6 @@ std::string CConf::getLockFileName() const return m_lockFileName; } -bool CConf::getGPSDEnabled() const -{ - return m_gpsdEnabled; -} - -std::string CConf::getGPSDAddress() const -{ - return m_gpsdAddress; -} - -std::string CConf::getGPSDPort() const -{ - return m_gpsdPort; -} - bool CConf::getRemoteControlEnabled() const { return m_remoteControlEnabled; diff --git a/Conf.h b/Conf.h index 335d461..f75fdb4 100644 --- a/Conf.h +++ b/Conf.h @@ -42,12 +42,6 @@ public: unsigned int getRXFrequency() const; unsigned int getTXFrequency() const; unsigned int getPower() const; - float getLatitude() const; - float getLongitude() const; - int getHeight() const; - std::string getLocation() const; - std::string getDescription() const; - std::string getURL() const; // The Log section unsigned int getLogDisplayLevel() const; @@ -305,11 +299,6 @@ public: bool getLockFileEnabled() const; std::string getLockFileName() const; - // The GPSD section - bool getGPSDEnabled() const; - std::string getGPSDAddress() const; - std::string getGPSDPort() const; - // The Remote Control section bool getRemoteControlEnabled() const; unsigned int getRemoteControlPort() const; @@ -326,12 +315,6 @@ private: unsigned int m_rxFrequency; unsigned int m_txFrequency; unsigned int m_power; - float m_latitude; - float m_longitude; - int m_height; - std::string m_location; - std::string m_description; - std::string m_url; unsigned int m_logDisplayLevel; unsigned int m_logFileLevel; @@ -563,10 +546,6 @@ private: bool m_lockFileEnabled; std::string m_lockFileName; - bool m_gpsdEnabled; - std::string m_gpsdAddress; - std::string m_gpsdPort; - bool m_remoteControlEnabled; unsigned int m_remoteControlPort; }; diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index fece49c..ffe3aea 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 by Jonathan Naylor G4KLX + * Copyright (C) 2015-2020 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 @@ -19,7 +19,6 @@ #include "DMRNetwork.h" #include "StopWatch.h" -#include "SHA256.h" #include "Utils.h" #include "Log.h" @@ -33,12 +32,11 @@ const unsigned int BUFFER_LENGTH = 500U; const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U; -CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType) : +CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType) : m_addressStr(address), m_address(), m_port(port), m_id(NULL), -m_password(password), m_duplex(duplex), m_version(version), m_debug(debug), @@ -47,37 +45,25 @@ m_enabled(false), m_slot1(slot1), m_slot2(slot2), m_hwType(hwType), -m_status(WAITING_CONNECT), -m_retryTimer(1000U, 10U), -m_timeoutTimer(1000U, 60U), m_buffer(NULL), -m_salt(NULL), m_streamId(NULL), m_rxData(1000U, "DMR Network"), -m_options(), +m_beacon(false), +m_random(), m_callsign(), m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), m_colorCode(0U), -m_latitude(0.0F), -m_longitude(0.0F), -m_height(0), -m_location(), -m_description(), -m_url(), -m_beacon(false), -m_random() +m_pingTimer(1000U, 10U) { assert(!address.empty()); assert(port > 0U); assert(id > 1000U); - assert(!password.empty()); m_address = CUDPSocket::lookup(address); m_buffer = new unsigned char[BUFFER_LENGTH]; - m_salt = new unsigned char[sizeof(uint32_t)]; m_id = new uint8_t[4U]; m_streamId = new uint32_t[2U]; @@ -98,43 +84,29 @@ m_random() CDMRNetwork::~CDMRNetwork() { delete[] m_buffer; - delete[] m_salt; delete[] m_streamId; delete[] m_id; } -void CDMRNetwork::setOptions(const std::string& options) -{ - m_options = options; -} - -void CDMRNetwork::setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url) +void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode) { m_callsign = callsign; m_rxFrequency = rxFrequency; m_txFrequency = txFrequency; m_power = power; m_colorCode = colorCode; - m_latitude = latitude; - m_longitude = longitude; - m_height = height; - m_location = location; - m_description = description; - m_url = url; } bool CDMRNetwork::open() { LogMessage("DMR, Opening DMR Network"); - if (m_address.s_addr == INADDR_NONE) - m_address = CUDPSocket::lookup(m_addressStr); + bool ret = m_socket.open(); - m_status = WAITING_CONNECT; - m_timeoutTimer.stop(); - m_retryTimer.start(); + if (ret) + m_pingTimer.start(); - return true; + return ret; } void CDMRNetwork::enable(bool enabled) @@ -147,9 +119,6 @@ void CDMRNetwork::enable(bool enabled) bool CDMRNetwork::read(CDMRData& data) { - if (m_status != RUNNING) - return false; - if (m_rxData.isEmpty()) return false; @@ -211,9 +180,6 @@ bool CDMRNetwork::read(CDMRData& data) bool CDMRNetwork::write(const CDMRData& data) { - if (m_status != RUNNING) - return false; - unsigned char buffer[HOMEBREW_DATA_PACKET_LENGTH]; ::memset(buffer, 0x00U, HOMEBREW_DATA_PACKET_LENGTH); @@ -285,264 +251,79 @@ bool CDMRNetwork::write(const CDMRData& data) bool CDMRNetwork::writeRadioPosition(unsigned int id, const unsigned char* data) { - if (m_status != RUNNING) - return false; - unsigned char buffer[20U]; ::memcpy(buffer + 0U, "DMRG", 4U); - ::memcpy(buffer + 4U, m_id, 4U); + buffer[4U] = id >> 16; + buffer[5U] = id >> 8; + buffer[6U] = id >> 0; - buffer[8U] = id >> 16; - buffer[9U] = id >> 8; - buffer[10U] = id >> 0; + ::memcpy(buffer + 7U, data + 2U, 7U); - ::memcpy(buffer + 11U, data + 2U, 7U); - - return write(buffer, 18U); + return write(buffer, 14U); } bool CDMRNetwork::writeTalkerAlias(unsigned int id, unsigned char type, const unsigned char* data) { - if (m_status != RUNNING) - return false; - unsigned char buffer[20U]; ::memcpy(buffer + 0U, "DMRA", 4U); - ::memcpy(buffer + 4U, m_id, 4U); + buffer[4U] = id >> 16; + buffer[5U] = id >> 8; + buffer[6U] = id >> 0; - buffer[8U] = id >> 16; - buffer[9U] = id >> 8; - buffer[10U] = id >> 0; + buffer[7U] = type; - buffer[11U] = type; + ::memcpy(buffer + 8U, data + 2U, 7U); - ::memcpy(buffer + 12U, data + 2U, 7U); - - return write(buffer, 19U); -} - -bool CDMRNetwork::writeHomePosition(float latitude, float longitude) -{ - m_latitude = latitude; - m_longitude = longitude; - - if (m_status != RUNNING) - return false; - - char buffer[50U]; - - ::memcpy(buffer + 0U, "RPTG", 4U); - ::memcpy(buffer + 4U, m_id, 4U); - - ::sprintf(buffer + 8U, "%08f%09f", latitude, longitude); - - return write((unsigned char*)buffer, 25U); + return write(buffer, 15U); } void CDMRNetwork::close() { LogMessage("DMR, Closing DMR Network"); - if (m_status == RUNNING) { - unsigned char buffer[9U]; - ::memcpy(buffer + 0U, "RPTCL", 5U); - ::memcpy(buffer + 5U, m_id, 4U); - write(buffer, 9U); - } - m_socket.close(); - - m_retryTimer.stop(); - m_timeoutTimer.stop(); } void CDMRNetwork::clock(unsigned int ms) { - if (m_status == WAITING_CONNECT) { - m_retryTimer.clock(ms); - if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) { - bool ret = m_socket.open(); - if (ret) { - ret = writeLogin(); - if (!ret) - return; - - m_status = WAITING_LOGIN; - m_timeoutTimer.start(); - } - - m_retryTimer.start(); - } - - return; + m_pingTimer.clock(ms); + if (m_pingTimer.isRunning() && m_pingTimer.hasExpired()) { + writeConfig(); + m_pingTimer.start(); } in_addr address; unsigned int port; int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port); - if (length < 0) { - LogError("DMR, Socket has failed, retrying connection to the master"); - close(); - open(); + if (length <= 0) + return; + + if (m_address.s_addr != address.s_addr || m_port != port) { + LogMessage("DMR, packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); return; } - // if (m_debug && length > 0) - // CUtils::dump(1U, "Network Received", m_buffer, length); + if (!m_enabled) + return; - if (length > 0 && m_address.s_addr == address.s_addr && m_port == port) { - if (::memcmp(m_buffer, "DMRD", 4U) == 0) { - if (m_enabled) { - if (m_debug) - CUtils::dump(1U, "Network Received", m_buffer, length); + if (m_debug) + CUtils::dump(1U, "Network Received", m_buffer, length); - unsigned char len = length; - m_rxData.addData(&len, 1U); - m_rxData.addData(m_buffer, len); - } - } else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) { - if (m_status == RUNNING) { - LogWarning("DMR, Login to the master has failed, retrying login ..."); - m_status = WAITING_LOGIN; - m_timeoutTimer.start(); - m_retryTimer.start(); - } else { - /* Once the modem death spiral has been prevented in Modem.cpp - the Network sometimes times out and reaches here. - We want it to reconnect so... */ - LogError("DMR, Login to the master has failed, retrying network ..."); - close(); - open(); - return; - } - } else if (::memcmp(m_buffer, "RPTACK", 6U) == 0) { - switch (m_status) { - case WAITING_LOGIN: - LogDebug("DMR, Sending authorisation"); - ::memcpy(m_salt, m_buffer + 6U, sizeof(uint32_t)); - writeAuthorisation(); - m_status = WAITING_AUTHORISATION; - m_timeoutTimer.start(); - m_retryTimer.start(); - break; - case WAITING_AUTHORISATION: - LogDebug("DMR, Sending configuration"); - writeConfig(); - m_status = WAITING_CONFIG; - m_timeoutTimer.start(); - m_retryTimer.start(); - break; - case WAITING_CONFIG: - if (m_options.empty()) { - LogMessage("DMR, Logged into the master successfully"); - m_status = RUNNING; - } else { - LogDebug("DMR, Sending options"); - writeOptions(); - m_status = WAITING_OPTIONS; - } - m_timeoutTimer.start(); - m_retryTimer.start(); - break; - case WAITING_OPTIONS: - LogMessage("DMR, Logged into the master successfully"); - m_status = RUNNING; - m_timeoutTimer.start(); - m_retryTimer.start(); - break; - default: - break; - } - } else if (::memcmp(m_buffer, "MSTCL", 5U) == 0) { - LogError("DMR, Master is closing down"); - close(); - open(); - } else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) { - m_timeoutTimer.start(); - } else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) { - m_beacon = true; - } else { - CUtils::dump("Unknown packet from the master", m_buffer, length); - } + if (::memcmp(m_buffer, "DMRD", 4U) == 0) { + unsigned char len = length; + m_rxData.addData(&len, 1U); + m_rxData.addData(m_buffer, len); + } else if (::memcmp(m_buffer, "DMRP", 4U) == 0) { + ; + } else if (::memcmp(m_buffer, "DMRB", 4U) == 0) { + m_beacon = true; + } else { + CUtils::dump("DMR, unknown packet from the DMR Gateway", m_buffer, length); } - - m_retryTimer.clock(ms); - if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) { - switch (m_status) { - case WAITING_LOGIN: - writeLogin(); - break; - case WAITING_AUTHORISATION: - writeAuthorisation(); - break; - case WAITING_OPTIONS: - writeOptions(); - break; - case WAITING_CONFIG: - writeConfig(); - break; - case RUNNING: - writePing(); - break; - default: - break; - } - - m_retryTimer.start(); - } - - m_timeoutTimer.clock(ms); - if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { - LogError("DMR, Connection to the master has timed out, retrying connection"); - close(); - open(); - } -} - -bool CDMRNetwork::writeLogin() -{ - unsigned char buffer[8U]; - - ::memcpy(buffer + 0U, "RPTL", 4U); - ::memcpy(buffer + 4U, m_id, 4U); - - return write(buffer, 8U); -} - -bool CDMRNetwork::writeAuthorisation() -{ - size_t size = m_password.size(); - - unsigned char* in = new unsigned char[size + sizeof(uint32_t)]; - ::memcpy(in, m_salt, sizeof(uint32_t)); - for (size_t i = 0U; i < size; i++) - in[i + sizeof(uint32_t)] = m_password.at(i); - - unsigned char out[40U]; - ::memcpy(out + 0U, "RPTK", 4U); - ::memcpy(out + 4U, m_id, 4U); - - CSHA256 sha256; - sha256.buffer(in, (unsigned int)(size + sizeof(uint32_t)), out + 8U); - - delete[] in; - - return write(out, 40U); -} - -bool CDMRNetwork::writeOptions() -{ - char buffer[300U]; - - ::memcpy(buffer + 0U, "RPTO", 4U); - ::memcpy(buffer + 4U, m_id, 4U); - ::strcpy(buffer + 8U, m_options.c_str()); - - return write((unsigned char*)buffer, (unsigned int)m_options.length() + 8U); } bool CDMRNetwork::writeConfig() @@ -614,40 +395,13 @@ bool CDMRNetwork::writeConfig() } } - char buffer[400U]; + char buffer[100U]; - ::memcpy(buffer + 0U, "RPTC", 4U); + ::memcpy(buffer + 0U, "DMRC", 4U); ::memcpy(buffer + 4U, m_id, 4U); + ::sprintf(buffer + 8U, "%02u%c%-40.40s%-40.40s", m_colorCode, slots, m_version, software); - char latitude[20U]; - ::sprintf(latitude, "%08f", m_latitude); - - char longitude[20U]; - ::sprintf(longitude, "%09f", m_longitude); - - unsigned int power = m_power; - if (power > 99U) - power = 99U; - - int height = m_height; - if (height > 999) - height = 999; - - ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%8.8s%9.9s%03d%-20.20s%-19.19s%c%-124.124s%-40.40s%-40.40s", m_callsign.c_str(), - m_rxFrequency, m_txFrequency, power, m_colorCode, latitude, longitude, height, m_location.c_str(), - m_description.c_str(), slots, m_url.c_str(), m_version, software); - - return write((unsigned char*)buffer, 302U); -} - -bool CDMRNetwork::writePing() -{ - unsigned char buffer[11U]; - - ::memcpy(buffer + 0U, "RPTPING", 7U); - ::memcpy(buffer + 7U, m_id, 4U); - - return write(buffer, 11U); + return write((unsigned char*)buffer, 91U); } bool CDMRNetwork::wantsBeacon() @@ -670,8 +424,6 @@ bool CDMRNetwork::write(const unsigned char* data, unsigned int length) bool ret = m_socket.write(data, length, m_address, m_port); if (!ret) { LogError("DMR, Socket has failed when writing data to the master, retrying connection"); - m_socket.close(); - open(); return false; } diff --git a/DMRNetwork.h b/DMRNetwork.h index 754c970..9f01925 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020 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 @@ -32,12 +32,10 @@ class CDMRNetwork { public: - CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType); + CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType); ~CDMRNetwork(); - void setOptions(const std::string& options); - - void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url); + void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode); bool open(); @@ -51,8 +49,6 @@ public: bool writeTalkerAlias(unsigned int id, unsigned char type, const unsigned char* data); - bool writeHomePosition(float latitude, float longitude); - bool wantsBeacon(); void clock(unsigned int ms); @@ -64,7 +60,6 @@ private: in_addr m_address; unsigned int m_port; uint8_t* m_id; - std::string m_password; bool m_duplex; const char* m_version; bool m_debug; @@ -73,47 +68,19 @@ private: bool m_slot1; bool m_slot2; HW_TYPE m_hwType; - - enum STATUS { - WAITING_CONNECT, - WAITING_LOGIN, - WAITING_AUTHORISATION, - WAITING_CONFIG, - WAITING_OPTIONS, - RUNNING - }; - - STATUS m_status; - CTimer m_retryTimer; - CTimer m_timeoutTimer; - unsigned char* m_buffer; - unsigned char* m_salt; - uint32_t* m_streamId; - + unsigned char* m_buffer; + uint32_t* m_streamId; CRingBuffer m_rxData; + bool m_beacon; + std::mt19937 m_random; + std::string m_callsign; + unsigned int m_rxFrequency; + unsigned int m_txFrequency; + unsigned int m_power; + unsigned int m_colorCode; + CTimer m_pingTimer; - std::string m_options; - - std::string m_callsign; - unsigned int m_rxFrequency; - unsigned int m_txFrequency; - unsigned int m_power; - unsigned int m_colorCode; - float m_latitude; - float m_longitude; - int m_height; - std::string m_location; - std::string m_description; - std::string m_url; - - bool m_beacon; - std::mt19937 m_random; - - bool writeLogin(); - bool writeAuthorisation(); - bool writeOptions(); bool writeConfig(); - bool writePing(); bool write(const unsigned char* data, unsigned int length); }; diff --git a/Display.cpp b/Display.cpp index 03f0a4f..29f00d0 100644 --- a/Display.cpp +++ b/Display.cpp @@ -556,10 +556,10 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) if (port == "modem") { ISerialPort* serial = new CModemSerialPort(modem); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } else if (port == "ump") { if (ump != NULL) { - display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } else { LogInfo(" NullDisplay loaded"); display = new CNullDisplay; @@ -571,7 +571,7 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) LogInfo(" Display baudrate: %u ",baudrate); ISerialPort* serial = new CSerialController(port, baudrate); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } } else if (type == "LCDproc") { std::string address = conf.getLCDprocAddress(); diff --git a/GPSD.cpp b/GPSD.cpp deleted file mode 100644 index c06321a..0000000 --- a/GPSD.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2018,2020 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 - * 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. - */ - -#include "GPSD.h" - -#if defined(USE_GPSD) - -#include -#include -#include -#include - -CGPSD::CGPSD(const std::string& address, const std::string& port, CDMRNetwork* network) : -m_gpsdAddress(address), -m_gpsdPort(port), -m_network(network), -m_gpsdData(), -m_idTimer(1000U, 60U) -{ - assert(!address.empty()); - assert(!port.empty()); - assert(network != NULL); -} - -CGPSD::~CGPSD() -{ -} - -bool CGPSD::open() -{ - int ret = ::gps_open(m_gpsdAddress.c_str(), m_gpsdPort.c_str(), &m_gpsdData); - if (ret != 0) { - LogError("Error when opening access to gpsd - %d - %s", errno, ::gps_errstr(errno)); - return false; - } - - ::gps_stream(&m_gpsdData, WATCH_ENABLE | WATCH_JSON, NULL); - - LogMessage("Connected to GPSD"); - - m_idTimer.start(); - - return true; -} - -void CGPSD::clock(unsigned int ms) -{ - m_idTimer.clock(ms); - - if (m_idTimer.hasExpired()) { - sendReport(); - m_idTimer.start(); - } -} - -void CGPSD::close() -{ - ::gps_stream(&m_gpsdData, WATCH_DISABLE, NULL); - ::gps_close(&m_gpsdData); -} - -void CGPSD::sendReport() -{ - if (!::gps_waiting(&m_gpsdData, 0)) - return; - -#if GPSD_API_MAJOR_VERSION >= 7 - if (::gps_read(&m_gpsdData, NULL, 0) <= 0) - return; -#else - if (::gps_read(&m_gpsdData) <= 0) - return; -#endif - - if (m_gpsdData.status != STATUS_FIX) - return; - - bool latlonSet = (m_gpsdData.set & LATLON_SET) == LATLON_SET; - if (!latlonSet) - return; - - float latitude = float(m_gpsdData.fix.latitude); - float longitude = float(m_gpsdData.fix.longitude); - - m_network->writeHomePosition(latitude, longitude); -} - -#endif diff --git a/GPSD.h b/GPSD.h deleted file mode 100644 index cef93b5..0000000 --- a/GPSD.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2018,2020 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 - * 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. - */ - -#ifndef GPSD_H -#define GPSD_H - -#if defined(USE_GPSD) - -#include "DMRNetwork.h" -#include "Timer.h" - -#include - -#include - -class CGPSD { -public: - CGPSD(const std::string& address, const std::string& port, CDMRNetwork* network); - ~CGPSD(); - - bool open(); - - void clock(unsigned int ms); - - void close(); - -private: - std::string m_gpsdAddress; - std::string m_gpsdPort; - CDMRNetwork* m_network; - struct gps_data_t m_gpsdData; - CTimer m_idTimer; - - void sendReport(); -}; - -#endif - -#endif diff --git a/MMDVM.ini b/MMDVM.ini index ccc561b..7a4f333 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -13,12 +13,6 @@ Daemon=0 RXFrequency=435000000 TXFrequency=435000000 Power=1 -Latitude=0.0 -Longitude=0.0 -Height=0 -Location=Nowhere -Description=Multi-Mode Repeater -URL=www.google.co.uk [Log] # Logging levels, 0=No logging @@ -288,11 +282,6 @@ UTC=0 Enable=0 File=/tmp/MMDVM_Active.lck -[GPSD] -Enable=0 -Address=127.0.0.1 -Port=2947 - [Remote Control] Enable=0 Port=7642 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index f174b83..8faff95 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -161,9 +161,6 @@ m_id(0U), m_cwCallsign(), m_lockFileEnabled(false), m_lockFileName(), -#if defined(USE_GPSD) -m_gpsd(NULL), -#endif m_remoteControl(NULL), m_fixedMode(false) { @@ -1000,11 +997,6 @@ int CMMDVMHost::run() if (m_pocsagNetwork != NULL) m_pocsagNetwork->clock(ms); -#if defined(USE_GPSD) - if (m_gpsd != NULL) - m_gpsd->clock(ms); -#endif - m_cwIdTimer.clock(ms); if (m_cwIdTimer.isRunning() && m_cwIdTimer.hasExpired()) { if (!m_modem->hasTX()){ @@ -1080,13 +1072,6 @@ int CMMDVMHost::run() m_display->close(); delete m_display; -#if defined(USE_GPSD) - if (m_gpsd != NULL) { - m_gpsd->close(); - delete m_gpsd; - } -#endif - if (m_ump != NULL) { m_ump->close(); delete m_ump; @@ -1354,38 +1339,20 @@ bool CMMDVMHost::createDMRNetwork() LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled"); LogInfo(" Mode Hang: %us", m_dmrNetModeHang); - m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, hwType); - - std::string options = m_conf.getDMRNetworkOptions(); - if (!options.empty()) { - LogInfo(" Options: %s", options.c_str()); - m_dmrNetwork->setOptions(options); - } + m_dmrNetwork = new CDMRNetwork(address, port, local, id, m_duplex, VERSION, debug, slot1, slot2, hwType); unsigned int rxFrequency = m_conf.getRXFrequency(); unsigned int txFrequency = m_conf.getTXFrequency(); unsigned int power = m_conf.getPower(); unsigned int colorCode = m_conf.getDMRColorCode(); - float latitude = m_conf.getLatitude(); - float longitude = m_conf.getLongitude(); - int height = m_conf.getHeight(); - std::string location = m_conf.getLocation(); - std::string description = m_conf.getDescription(); - std::string url = m_conf.getURL(); - LogInfo("Info Parameters"); + LogInfo("RF Parameters"); LogInfo(" Callsign: %s", m_callsign.c_str()); LogInfo(" RX Frequency: %uHz", rxFrequency); LogInfo(" TX Frequency: %uHz", txFrequency); LogInfo(" Power: %uW", power); - LogInfo(" Latitude: %fdeg N", latitude); - LogInfo(" Longitude: %fdeg E", longitude); - LogInfo(" Height: %um", height); - LogInfo(" Location: \"%s\"", location.c_str()); - LogInfo(" Description: \"%s\"", description.c_str()); - LogInfo(" URL: \"%s\"", url.c_str()); - m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode, latitude, longitude, height, location, description, url); + m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode); bool ret = m_dmrNetwork->open(); if (!ret) { @@ -1394,26 +1361,6 @@ bool CMMDVMHost::createDMRNetwork() return false; } -#if defined(USE_GPSD) - bool gpsdEnabled = m_conf.getGPSDEnabled(); - if (gpsdEnabled) { - std::string gpsdAddress = m_conf.getGPSDAddress(); - std::string gpsdPort = m_conf.getGPSDPort(); - - LogInfo("GPSD Parameters"); - LogInfo(" Address: %s", gpsdAddress.c_str()); - LogInfo(" Port: %s", gpsdPort.c_str()); - - m_gpsd = new CGPSD(gpsdAddress, gpsdPort, m_dmrNetwork); - - ret = m_gpsd->open(); - if (!ret) { - delete m_gpsd; - m_gpsd = NULL; - } - } -#endif - m_dmrNetwork->enable(true); return true; @@ -1421,12 +1368,12 @@ bool CMMDVMHost::createDMRNetwork() bool CMMDVMHost::createYSFNetwork() { - std::string myAddress = m_conf.getFusionNetworkMyAddress(); - unsigned int myPort = m_conf.getFusionNetworkMyPort(); + std::string myAddress = m_conf.getFusionNetworkMyAddress(); + unsigned int myPort = m_conf.getFusionNetworkMyPort(); std::string gatewayAddress = m_conf.getFusionNetworkGatewayAddress(); unsigned int gatewayPort = m_conf.getFusionNetworkGatewayPort(); - m_ysfNetModeHang = m_conf.getFusionNetworkModeHang(); - bool debug = m_conf.getFusionNetworkDebug(); + m_ysfNetModeHang = m_conf.getFusionNetworkModeHang(); + bool debug = m_conf.getFusionNetworkDebug(); LogInfo("System Fusion Network Parameters"); LogInfo(" Local Address: %s", myAddress.c_str()); diff --git a/MMDVMHost.h b/MMDVMHost.h index 3d77653..4c58f98 100644 --- a/MMDVMHost.h +++ b/MMDVMHost.h @@ -38,13 +38,11 @@ #include "Timer.h" #include "Modem.h" #include "Conf.h" -#include "GPSD.h" #include "UMP.h" #include - class CMMDVMHost { public: @@ -102,9 +100,6 @@ private: std::string m_cwCallsign; bool m_lockFileEnabled; std::string m_lockFileName; -#if defined(USE_GPSD) - CGPSD* m_gpsd; -#endif CRemoteControl* m_remoteControl; bool m_fixedMode; diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index b17f851..7981c50 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -183,7 +183,6 @@ - @@ -281,7 +280,6 @@ - diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index 7168194..534b3cd 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -302,9 +302,6 @@ Header Files - - Header Files - @@ -571,8 +568,5 @@ Source Files - - Source Files - \ No newline at end of file diff --git a/Makefile b/Makefile index 1ad3c8a..4dae872 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,14 @@ CC = cc CXX = c++ - -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread LIBS = -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -#LIBS = -lpthread -lgps - LDFLAGS = -g OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o \ NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o \ P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o \ diff --git a/Makefile.Pi b/Makefile.Pi index 53e457e..c124bc9 100644 --- a/Makefile.Pi +++ b/Makefile.Pi @@ -2,20 +2,14 @@ CC = gcc CXX = g++ -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DRASPBERRY_PI -I/usr/local/include LIBS = -lwiringPi -lwiringPiDev -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DRASPBERRY_PI -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps - LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index 0a8fa85..b4cc4d7 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -3,20 +3,14 @@ CC = gcc CXX = g++ -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include LIBS = -lwiringPi -lwiringPiDev -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps - LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index 5417946..ba0fc74 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -2,21 +2,14 @@ CC = gcc CXX = g++ - -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -I/usr/local/include LIBS = -lwiringPi -lwiringPiDev -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps - LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index 9949cf2..67babd1 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -2,21 +2,14 @@ CC = gcc CXX = g++ - -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DOLED -I/usr/local/include LIBS = -lArduiPi_OLED -lwiringPi -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DOLED -I/usr/local/include -#LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lgps - LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o I2CController.o OLED.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o OLED.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index aa84cc8..e3a9b53 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -3,21 +3,14 @@ CC = gcc CXX = g++ - -# Use the following CFLAGS and LIBS if you don't want to use gpsd. CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include LIBS = -lwiringPi -lwiringPiDev -lpthread - -# Use the following CFLAGS and LIBS if you do want to use gpsd. -#CFLAGS = -g -O3 -Wall -DUSE_GPSD -std=c++0x -pthread -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include -#LIBS = -lwiringPi -lwiringPiDev -lpthread -lgps - LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedData.o DMRFullLC.o \ DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o \ - DStarSlowData.o Golay2087.o Golay24128.o GPSD.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ + DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Mutex.o \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ diff --git a/Nextion.cpp b/Nextion.cpp index ac6e8d7..fa6851e 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -25,7 +25,6 @@ #include #include #include -//#include const unsigned int DSTAR_RSSI_COUNT = 3U; // 3 * 420ms = 1260ms const unsigned int DSTAR_BER_COUNT = 63U; // 63 * 20ms = 1260ms @@ -48,7 +47,7 @@ const unsigned int NXDN_BER_COUNT = 28U; // 28 * 40ms = 1120ms // 00:low, others:high-speed. bit[2] is overlapped with LAYOUT_COMPAT_MASK. #define LAYOUT_HIGHSPEED (3 << 2) -CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location) : +CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF) : CDisplay(), m_callsign(callsign), m_ipaddress("(ip unknown)"), @@ -73,8 +72,7 @@ m_txFrequency(txFrequency), m_rxFrequency(rxFrequency), m_fl_txFrequency(0.0F), m_fl_rxFrequency(0.0F), -m_displayTempInF(displayTempInF), -m_location(location) +m_displayTempInF(displayTempInF) { assert(serial != NULL); assert(brightness >= 0U && brightness <= 100U); @@ -179,10 +177,6 @@ void CNextion::setIdleInt() sendCommandAction(22U); } } - - ::sprintf(command, "t31.txt=\"%s\"", m_location.c_str()); // location - sendCommand(command); - sendCommandAction(23U); } else { sendCommandAction(17U); } diff --git a/Nextion.h b/Nextion.h index 7217d2a..488372f 100644 --- a/Nextion.h +++ b/Nextion.h @@ -29,7 +29,7 @@ class CNextion : public CDisplay { public: - CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location); + CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); virtual ~CNextion(); virtual bool open(); @@ -103,7 +103,6 @@ private: double m_fl_txFrequency; double m_fl_rxFrequency; bool m_displayTempInF; - std::string m_location; void sendCommand(const char* command); void sendCommandAction(unsigned int status); diff --git a/Version.h b/Version.h index 4d2faa4..426bd2a 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200809"; +const char* VERSION = "20200826"; #endif From a9c9ff601102c967af18c442b7e303c201f0af40 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 26 Aug 2020 10:18:57 +0100 Subject: [PATCH 12/16] Changes for the simplified protocol. --- DMRNetwork.cpp | 12 ++++++++---- MMDVM.ini | 4 +--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index ffe3aea..061cac3 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -395,13 +395,17 @@ bool CDMRNetwork::writeConfig() } } - char buffer[100U]; + unsigned int power = m_power; + if (power > 99U) + power = 99U; + + char buffer[200U]; ::memcpy(buffer + 0U, "DMRC", 4U); ::memcpy(buffer + 4U, m_id, 4U); - ::sprintf(buffer + 8U, "%02u%c%-40.40s%-40.40s", m_colorCode, slots, m_version, software); + ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%c%-40.40s%-40.40s", m_callsign.c_str(), m_rxFrequency, m_txFrequency, power, m_colorCode, slots, m_version, software); - return write((unsigned char*)buffer, 91U); + return write((unsigned char*)buffer, 119U); } bool CDMRNetwork::wantsBeacon() @@ -423,7 +427,7 @@ bool CDMRNetwork::write(const unsigned char* data, unsigned int length) bool ret = m_socket.write(data, length, m_address, m_port); if (!ret) { - LogError("DMR, Socket has failed when writing data to the master, retrying connection"); + LogError("DMR, socket error when writing to the DMR Gateway"); return false; } diff --git a/MMDVM.ini b/MMDVM.ini index 7a4f333..9600db8 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -181,10 +181,8 @@ Debug=0 Enable=1 Address=44.131.4.1 Port=62031 +Local=62032 Jitter=360 -# Local=62032 -Password=PASSWORD -# Options= Slot1=1 Slot2=1 # ModeHang=3 From 98879b5c14ec6691a686374dacf794a6ca8e22c6 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 26 Aug 2020 12:13:34 +0100 Subject: [PATCH 13/16] Reinstated the location field. --- Conf.cpp | 8 ++++++++ Conf.h | 2 ++ DMRNetwork.cpp | 10 +++++++--- DMRNetwork.h | 3 ++- Display.cpp | 14 +++++++------- MMDVM.ini | 1 + MMDVMHost.cpp | 6 ++++-- Nextion.cpp | 9 +++++++-- Nextion.h | 3 ++- 9 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 8b2578b..4410443 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -71,6 +71,7 @@ m_daemon(false), m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), +m_location(), m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), @@ -420,6 +421,8 @@ bool CConf::read() m_rxFrequency = (unsigned int)::atoi(value); else if (::strcmp(key, "Power") == 0) m_power = (unsigned int)::atoi(value); + else if (::strcmp(key, "Location") == 0) + m_location = value; } else if (section == SECTION_LOG) { if (::strcmp(key, "FilePath") == 0) m_logFilePath = value; @@ -993,6 +996,11 @@ unsigned int CConf::getPower() const return m_power; } +std::string CConf::getLocation() const +{ + return m_location; +} + unsigned int CConf::getLogDisplayLevel() const { return m_logDisplayLevel; diff --git a/Conf.h b/Conf.h index f75fdb4..3e868ef 100644 --- a/Conf.h +++ b/Conf.h @@ -42,6 +42,7 @@ public: unsigned int getRXFrequency() const; unsigned int getTXFrequency() const; unsigned int getPower() const; + std::string getLocation() const; // The Log section unsigned int getLogDisplayLevel() const; @@ -315,6 +316,7 @@ private: unsigned int m_rxFrequency; unsigned int m_txFrequency; unsigned int m_power; + std::string m_location; unsigned int m_logDisplayLevel; unsigned int m_logFileLevel; diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index 061cac3..d784e21 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -55,6 +55,7 @@ m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), m_colorCode(0U), +m_location(), m_pingTimer(1000U, 10U) { assert(!address.empty()); @@ -88,13 +89,14 @@ CDMRNetwork::~CDMRNetwork() delete[] m_id; } -void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode) +void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, const std::string& location) { m_callsign = callsign; m_rxFrequency = rxFrequency; m_txFrequency = txFrequency; m_power = power; m_colorCode = colorCode; + m_location = location; } bool CDMRNetwork::open() @@ -403,9 +405,11 @@ bool CDMRNetwork::writeConfig() ::memcpy(buffer + 0U, "DMRC", 4U); ::memcpy(buffer + 4U, m_id, 4U); - ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%c%-40.40s%-40.40s", m_callsign.c_str(), m_rxFrequency, m_txFrequency, power, m_colorCode, slots, m_version, software); + ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%-20.20s%c%-40.40s%-40.40s", + m_callsign.c_str(), m_rxFrequency, m_txFrequency, power, m_colorCode, m_location.c_str(), slots, m_version, + software); - return write((unsigned char*)buffer, 119U); + return write((unsigned char*)buffer, 139U); } bool CDMRNetwork::wantsBeacon() diff --git a/DMRNetwork.h b/DMRNetwork.h index 9f01925..7539ec3 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -35,7 +35,7 @@ public: CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType); ~CDMRNetwork(); - void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode); + void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, const std::string& location); bool open(); @@ -78,6 +78,7 @@ private: unsigned int m_txFrequency; unsigned int m_power; unsigned int m_colorCode; + std::string m_location; CTimer m_pingTimer; bool writeConfig(); diff --git a/Display.cpp b/Display.cpp index 29f00d0..6238d57 100644 --- a/Display.cpp +++ b/Display.cpp @@ -556,14 +556,14 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) if (port == "modem") { ISerialPort* serial = new CModemSerialPort(modem); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); } else if (port == "ump") { if (ump != NULL) { - display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); - } else { - LogInfo(" NullDisplay loaded"); - display = new CNullDisplay; - } + display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + } else { + LogInfo(" NullDisplay loaded"); + display = new CNullDisplay; + } } else { SERIAL_SPEED baudrate = SERIAL_9600; if (screenLayout&0x0cU) @@ -571,7 +571,7 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) LogInfo(" Display baudrate: %u ",baudrate); ISerialPort* serial = new CSerialController(port, baudrate); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); } } else if (type == "LCDproc") { std::string address = conf.getLCDprocAddress(); diff --git a/MMDVM.ini b/MMDVM.ini index 9600db8..c4f11e0 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -13,6 +13,7 @@ Daemon=0 RXFrequency=435000000 TXFrequency=435000000 Power=1 +Location=Nowhere [Log] # Logging levels, 0=No logging diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 8faff95..8a6c5d0 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -1345,14 +1345,16 @@ bool CMMDVMHost::createDMRNetwork() unsigned int txFrequency = m_conf.getTXFrequency(); unsigned int power = m_conf.getPower(); unsigned int colorCode = m_conf.getDMRColorCode(); + std::string location = m_conf.getLocation(); - LogInfo("RF Parameters"); + LogInfo("Info Parameters"); LogInfo(" Callsign: %s", m_callsign.c_str()); LogInfo(" RX Frequency: %uHz", rxFrequency); LogInfo(" TX Frequency: %uHz", txFrequency); LogInfo(" Power: %uW", power); + LogInfo(" Location: \"%s\"", location.c_str()); - m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode); + m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode, location); bool ret = m_dmrNetwork->open(); if (!ret) { diff --git a/Nextion.cpp b/Nextion.cpp index fa6851e..b5253c1 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -47,7 +47,7 @@ const unsigned int NXDN_BER_COUNT = 28U; // 28 * 40ms = 1120ms // 00:low, others:high-speed. bit[2] is overlapped with LAYOUT_COMPAT_MASK. #define LAYOUT_HIGHSPEED (3 << 2) -CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF) : +CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location) : CDisplay(), m_callsign(callsign), m_ipaddress("(ip unknown)"), @@ -72,7 +72,8 @@ m_txFrequency(txFrequency), m_rxFrequency(rxFrequency), m_fl_txFrequency(0.0F), m_fl_rxFrequency(0.0F), -m_displayTempInF(displayTempInF) +m_displayTempInF(displayTempInF), +m_location(location) { assert(serial != NULL); assert(brightness >= 0U && brightness <= 100U); @@ -177,6 +178,10 @@ void CNextion::setIdleInt() sendCommandAction(22U); } } + + ::sprintf(command, "t31.txt=\"%s\"", m_location.c_str()); // location + sendCommand(command); + sendCommandAction(23U); } else { sendCommandAction(17U); } diff --git a/Nextion.h b/Nextion.h index 488372f..7217d2a 100644 --- a/Nextion.h +++ b/Nextion.h @@ -29,7 +29,7 @@ class CNextion : public CDisplay { public: - CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); + CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location); virtual ~CNextion(); virtual bool open(); @@ -103,6 +103,7 @@ private: double m_fl_txFrequency; double m_fl_rxFrequency; bool m_displayTempInF; + std::string m_location; void sendCommand(const char* command); void sendCommandAction(unsigned int status); From 01da0ded7fae871eae1a6ffc2ef44ed960bc4b3b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 27 Aug 2020 09:00:49 +0100 Subject: [PATCH 14/16] Remove the unused SHA256 functions. --- MMDVMHost.vcxproj | 2 - MMDVMHost.vcxproj.filters | 6 - Makefile | 2 +- Makefile.Pi | 2 +- Makefile.Pi.Adafruit | 2 +- Makefile.Pi.HD44780 | 2 +- Makefile.Pi.OLED | 2 +- Makefile.Pi.PCF8574 | 2 +- SHA256.cpp | 373 -------------------------------------- SHA256.h | 73 -------- 10 files changed, 6 insertions(+), 460 deletions(-) delete mode 100644 SHA256.cpp delete mode 100644 SHA256.h diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 7981c50..06a0cc9 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -230,7 +230,6 @@ - @@ -322,7 +321,6 @@ - diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index 534b3cd..ee1ff1b 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -77,9 +77,6 @@ Header Files - - Header Files - Header Files @@ -358,9 +355,6 @@ Source Files - - Source Files - Source Files diff --git a/Makefile b/Makefile index 4dae872..6c25552 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o \ NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o \ P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o \ - SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o \ + SerialController.o SerialPort.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o \ YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/Makefile.Pi b/Makefile.Pi index c124bc9..cc25fc0 100644 --- a/Makefile.Pi +++ b/Makefile.Pi @@ -13,7 +13,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ - SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ + StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index b4cc4d7..e043286 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -14,7 +14,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ - SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ + StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index ba0fc74..07a5507 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -13,7 +13,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ - SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ + StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index 67babd1..5f01923 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -13,7 +13,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ - SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ + StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index e3a9b53..bf65dc7 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -14,7 +14,7 @@ OBJECTS = \ NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o \ NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \ P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o \ - SHA256.o StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ + StopWatch.o Sync.o TFTSerial.o TFTSurenoo.o Thread.o Timer.o UDPSocket.o UMP.o UserDB.o UserDBentry.o Utils.o YSFControl.o YSFConvolution.o \ YSFFICH.o YSFNetwork.o YSFPayload.o all: MMDVMHost RemoteCommand diff --git a/SHA256.cpp b/SHA256.cpp deleted file mode 100644 index b3366e0..0000000 --- a/SHA256.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc. - * Copyright (C) 2011,2015 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 - * 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. - */ - -#include "SHA256.h" - -#include -#include -#include - -#ifdef WORDS_BIGENDIAN -# define SWAP(n) (n) -#else -# define SWAP(n) \ - (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) -#endif - -#define BLOCKSIZE 4096 -#if BLOCKSIZE % 64 != 0 -# error "invalid BLOCKSIZE" -#endif - -/* This array contains the bytes used to pad the buffer to the next - 64-byte boundary. */ -static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; - - -/* - Takes a pointer to a 256 bit block of data (eight 32 bit ints) and - intializes it to the start constants of the SHA256 algorithm. This - must be called before using hash in the call to sha256_hash -*/ -CSHA256::CSHA256() : -m_state(NULL), -m_total(NULL), -m_buflen(0U), -m_buffer(NULL) -{ - m_state = new uint32_t[8U]; - m_total = new uint32_t[2U]; - m_buffer = new uint32_t[32U]; - - init(); -} - -CSHA256::~CSHA256() -{ - delete[] m_state; - delete[] m_total; - delete[] m_buffer; -} - -void CSHA256::init() -{ - m_state[0] = 0x6a09e667UL; - m_state[1] = 0xbb67ae85UL; - m_state[2] = 0x3c6ef372UL; - m_state[3] = 0xa54ff53aUL; - m_state[4] = 0x510e527fUL; - m_state[5] = 0x9b05688cUL; - m_state[6] = 0x1f83d9abUL; - m_state[7] = 0x5be0cd19UL; - - m_total[0] = m_total[1] = 0; - m_buflen = 0; -} - -/* Copy the value from v into the memory location pointed to by *cp, - If your architecture allows unaligned access this is equivalent to - * (uint32_t *) cp = v */ -static inline void set_uint32(unsigned char* cp, uint32_t v) -{ - assert(cp != NULL); - - ::memcpy(cp, &v, sizeof v); -} - -/* Put result from CTX in first 32 bytes following RESBUF. The result - must be in little endian byte order. */ -unsigned char* CSHA256::read(unsigned char* resbuf) -{ - assert(resbuf != NULL); - - for (unsigned int i = 0U; i < 8U; i++) - set_uint32(resbuf + i * sizeof(m_state[0]), SWAP(m_state[i])); - - return resbuf; -} - -/* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. */ -void CSHA256::conclude() -{ - /* Take yet unprocessed bytes into account. */ - unsigned int bytes = m_buflen; - unsigned int size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; - - /* Now count remaining bytes. */ - m_total[0] += bytes; - if (m_total[0] < bytes) - ++m_total[1]; - - /* Put the 64-bit file length in *bits* at the end of the buffer. - Use set_uint32 rather than a simple assignment, to avoid risk of - unaligned access. */ - set_uint32((unsigned char*)&m_buffer[size - 2], SWAP((m_total[1] << 3) | (m_total[0] >> 29))); - set_uint32((unsigned char*)&m_buffer[size - 1], SWAP(m_total[0] << 3)); - - ::memcpy(&((char*)m_buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); - - /* Process last bytes. */ - processBlock((unsigned char*)m_buffer, size * 4); -} - -unsigned char* CSHA256::finish(unsigned char* resbuf) -{ - assert(resbuf != NULL); - - conclude(); - - return read(resbuf); -} - -/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The - result is always in little endian byte order, so that a byte-wise - output yields to the wanted ASCII representation of the message - digest. */ -unsigned char* CSHA256::buffer(const unsigned char* buffer, unsigned int len, unsigned char* resblock) -{ - assert(buffer != NULL); - assert(resblock != NULL); - - /* Initialize the computation context. */ - init(); - - /* Process whole buffer but last len % 64 bytes. */ - processBytes(buffer, len); - - /* Put result in desired memory area. */ - return finish(resblock); -} - -void CSHA256::processBytes(const unsigned char* buffer, unsigned int len) -{ - assert(buffer != NULL); - - /* When we already have some bits in our internal buffer concatenate - both inputs first. */ - if (m_buflen != 0U) { - unsigned int left_over = m_buflen; - unsigned int add = 128U - left_over > len ? len : 128U - left_over; - - ::memcpy(&((char*)m_buffer)[left_over], buffer, add); - m_buflen += add; - - if (m_buflen > 64U) { - processBlock((unsigned char*)m_buffer, m_buflen & ~63U); - - m_buflen &= 63U; - - /* The regions in the following copy operation cannot overlap. */ - ::memcpy(m_buffer, &((char*)m_buffer)[(left_over + add) & ~63U], m_buflen); - } - - buffer += add; - len -= add; - } - - /* Process available complete blocks. */ - if (len >= 64U) { -//#if !_STRING_ARCH_unaligned -//# define alignof(type) offsetof (struct { char c; type x; }, x) -//# define UNALIGNED_P(p) (((unsigned int) p) % alignof (uint32_t) != 0) -// if (UNALIGNED_P (buffer)) { -// while (len > 64U) { -// ::memcpy(m_buffer, buffer, 64U); -// processBlock((unsigned char*)m_buffer, 64U); -// buffer += 64U; -// len -= 64U; -// } -// } else -//#endif - { - processBlock(buffer, len & ~63U); - buffer += (len & ~63U); - len &= 63U; - } - } - - /* Move remaining bytes in internal buffer. */ - if (len > 0U) { - unsigned int left_over = m_buflen; - - ::memcpy(&((char*)m_buffer)[left_over], buffer, len); - left_over += len; - - if (left_over >= 64U) { - processBlock((unsigned char*)m_buffer, 64U); - left_over -= 64U; - ::memcpy(m_buffer, &m_buffer[16], left_over); - } - - m_buflen = left_over; - } -} - -/* --- Code below is the primary difference between sha1.c and sha256.c --- */ - -/* SHA256 round constants */ -#define K(I) roundConstants[I] -static const uint32_t roundConstants[64] = { - 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, - 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, - 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, - 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, - 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, - 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, - 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, - 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, - 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, - 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, - 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, - 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, - 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, - 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, - 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, - 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL, -}; - -/* Round functions. */ -#define F2(A,B,C) ( ( A & B ) | ( C & ( A | B ) ) ) -#define F1(E,F,G) ( G ^ ( E & ( F ^ G ) ) ) - -/* Process LEN bytes of BUFFER, accumulating context into CTX. - It is assumed that LEN % 64 == 0. - Most of this code comes from GnuPG's cipher/sha1.c. */ - -void CSHA256::processBlock(const unsigned char* buffer, unsigned int len) -{ - assert(buffer != NULL); - - const uint32_t* words = (uint32_t*)buffer; - unsigned int nwords = len / sizeof(uint32_t); - const uint32_t* endp = words + nwords; - uint32_t x[16]; - uint32_t a = m_state[0]; - uint32_t b = m_state[1]; - uint32_t c = m_state[2]; - uint32_t d = m_state[3]; - uint32_t e = m_state[4]; - uint32_t f = m_state[5]; - uint32_t g = m_state[6]; - uint32_t h = m_state[7]; - - /* First increment the byte count. FIPS PUB 180-2 specifies the possible - length of the file up to 2^64 bits. Here we only compute the - number of bytes. Do a double word increment. */ - m_total[0] += len; - if (m_total[0] < len) - ++m_total[1]; - - #define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - #define S0(x) (rol(x,25)^rol(x,14)^(x>>3)) - #define S1(x) (rol(x,15)^rol(x,13)^(x>>10)) - #define SS0(x) (rol(x,30)^rol(x,19)^rol(x,10)) - #define SS1(x) (rol(x,26)^rol(x,21)^rol(x,7)) - - #define M(I) (tm = S1(x[(I-2)&0x0f]) + x[(I-7)&0x0f] + S0(x[(I-15)&0x0f]) + x[I&0x0f], x[I&0x0f] = tm) - - #define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \ - t1 = H + SS1(E) + F1(E,F,G) + K + M; \ - D += t1; H = t0 + t1; \ - } while(0) - - while (words < endp) { - uint32_t tm; - uint32_t t0, t1; - /* FIXME: see sha1.c for a better implementation. */ - for (unsigned int t = 0U; t < 16U; t++) { - x[t] = SWAP(*words); - words++; - } - - R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); - R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); - R( g, h, a, b, c, d, e, f, K( 2), x[ 2] ); - R( f, g, h, a, b, c, d, e, K( 3), x[ 3] ); - R( e, f, g, h, a, b, c, d, K( 4), x[ 4] ); - R( d, e, f, g, h, a, b, c, K( 5), x[ 5] ); - R( c, d, e, f, g, h, a, b, K( 6), x[ 6] ); - R( b, c, d, e, f, g, h, a, K( 7), x[ 7] ); - R( a, b, c, d, e, f, g, h, K( 8), x[ 8] ); - R( h, a, b, c, d, e, f, g, K( 9), x[ 9] ); - R( g, h, a, b, c, d, e, f, K(10), x[10] ); - R( f, g, h, a, b, c, d, e, K(11), x[11] ); - R( e, f, g, h, a, b, c, d, K(12), x[12] ); - R( d, e, f, g, h, a, b, c, K(13), x[13] ); - R( c, d, e, f, g, h, a, b, K(14), x[14] ); - R( b, c, d, e, f, g, h, a, K(15), x[15] ); - R( a, b, c, d, e, f, g, h, K(16), M(16) ); - R( h, a, b, c, d, e, f, g, K(17), M(17) ); - R( g, h, a, b, c, d, e, f, K(18), M(18) ); - R( f, g, h, a, b, c, d, e, K(19), M(19) ); - R( e, f, g, h, a, b, c, d, K(20), M(20) ); - R( d, e, f, g, h, a, b, c, K(21), M(21) ); - R( c, d, e, f, g, h, a, b, K(22), M(22) ); - R( b, c, d, e, f, g, h, a, K(23), M(23) ); - R( a, b, c, d, e, f, g, h, K(24), M(24) ); - R( h, a, b, c, d, e, f, g, K(25), M(25) ); - R( g, h, a, b, c, d, e, f, K(26), M(26) ); - R( f, g, h, a, b, c, d, e, K(27), M(27) ); - R( e, f, g, h, a, b, c, d, K(28), M(28) ); - R( d, e, f, g, h, a, b, c, K(29), M(29) ); - R( c, d, e, f, g, h, a, b, K(30), M(30) ); - R( b, c, d, e, f, g, h, a, K(31), M(31) ); - R( a, b, c, d, e, f, g, h, K(32), M(32) ); - R( h, a, b, c, d, e, f, g, K(33), M(33) ); - R( g, h, a, b, c, d, e, f, K(34), M(34) ); - R( f, g, h, a, b, c, d, e, K(35), M(35) ); - R( e, f, g, h, a, b, c, d, K(36), M(36) ); - R( d, e, f, g, h, a, b, c, K(37), M(37) ); - R( c, d, e, f, g, h, a, b, K(38), M(38) ); - R( b, c, d, e, f, g, h, a, K(39), M(39) ); - R( a, b, c, d, e, f, g, h, K(40), M(40) ); - R( h, a, b, c, d, e, f, g, K(41), M(41) ); - R( g, h, a, b, c, d, e, f, K(42), M(42) ); - R( f, g, h, a, b, c, d, e, K(43), M(43) ); - R( e, f, g, h, a, b, c, d, K(44), M(44) ); - R( d, e, f, g, h, a, b, c, K(45), M(45) ); - R( c, d, e, f, g, h, a, b, K(46), M(46) ); - R( b, c, d, e, f, g, h, a, K(47), M(47) ); - R( a, b, c, d, e, f, g, h, K(48), M(48) ); - R( h, a, b, c, d, e, f, g, K(49), M(49) ); - R( g, h, a, b, c, d, e, f, K(50), M(50) ); - R( f, g, h, a, b, c, d, e, K(51), M(51) ); - R( e, f, g, h, a, b, c, d, K(52), M(52) ); - R( d, e, f, g, h, a, b, c, K(53), M(53) ); - R( c, d, e, f, g, h, a, b, K(54), M(54) ); - R( b, c, d, e, f, g, h, a, K(55), M(55) ); - R( a, b, c, d, e, f, g, h, K(56), M(56) ); - R( h, a, b, c, d, e, f, g, K(57), M(57) ); - R( g, h, a, b, c, d, e, f, K(58), M(58) ); - R( f, g, h, a, b, c, d, e, K(59), M(59) ); - R( e, f, g, h, a, b, c, d, K(60), M(60) ); - R( d, e, f, g, h, a, b, c, K(61), M(61) ); - R( c, d, e, f, g, h, a, b, K(62), M(62) ); - R( b, c, d, e, f, g, h, a, K(63), M(63) ); - - a = m_state[0] += a; - b = m_state[1] += b; - c = m_state[2] += c; - d = m_state[3] += d; - e = m_state[4] += e; - f = m_state[5] += f; - g = m_state[6] += g; - h = m_state[7] += h; - } -} diff --git a/SHA256.h b/SHA256.h deleted file mode 100644 index 7c48f19..0000000 --- a/SHA256.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc. - * Copyright (C) 2011,2015,2016 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 - * 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. - */ - -#ifndef SHA256_H -#define SHA256_H - -#include - -enum { - SHA256_DIGEST_SIZE = 256 / 8 -}; - -class CSHA256 { -public: - CSHA256(); - ~CSHA256(); - - /* Starting with the result of former calls of this function (or the - initialization function update the context for the next LEN bytes - starting at BUFFER. - It is necessary that LEN is a multiple of 64!!! */ - void processBlock(const unsigned char* buffer, unsigned int len); - - /* Starting with the result of former calls of this function (or the - initialization function update the context for the next LEN bytes - starting at BUFFER. - It is NOT required that LEN is a multiple of 64. */ - void processBytes(const unsigned char* buffer, unsigned int len); - - /* Process the remaining bytes in the buffer and put result from CTX - in first 32 bytes following RESBUF. The result is always in little - endian byte order, so that a byte-wise output yields to the wanted - ASCII representation of the message digest. */ - unsigned char* finish(unsigned char* resbuf); - - /* Put result from CTX in first 32 bytes following RESBUF. The result is - always in little endian byte order, so that a byte-wise output yields - to the wanted ASCII representation of the message digest. */ - unsigned char* read(unsigned char* resbuf); - - /* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The - result is always in little endian byte order, so that a byte-wise - output yields to the wanted ASCII representation of the message - digest. */ - unsigned char* buffer(const unsigned char* buffer, unsigned int len, unsigned char* resblock); - -private: - uint32_t* m_state; - uint32_t* m_total; - unsigned int m_buflen; - uint32_t* m_buffer; - - void init(); - void conclude(); -}; - -#endif From 23495209649c2c18a635ab1dc6115655862f43b6 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 27 Aug 2020 10:13:02 +0100 Subject: [PATCH 15/16] Remove the location information from the new config message. --- Conf.cpp | 8 -------- Conf.h | 2 -- DMRNetwork.cpp | 16 +++++++--------- DMRNetwork.h | 3 +-- Display.cpp | 6 +++--- MMDVM.ini | 1 - MMDVMHost.cpp | 4 +--- Nextion.cpp | 9 ++------- Nextion.h | 3 +-- Version.h | 2 +- 10 files changed, 16 insertions(+), 38 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 4410443..8b2578b 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -71,7 +71,6 @@ m_daemon(false), m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), -m_location(), m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), @@ -421,8 +420,6 @@ bool CConf::read() m_rxFrequency = (unsigned int)::atoi(value); else if (::strcmp(key, "Power") == 0) m_power = (unsigned int)::atoi(value); - else if (::strcmp(key, "Location") == 0) - m_location = value; } else if (section == SECTION_LOG) { if (::strcmp(key, "FilePath") == 0) m_logFilePath = value; @@ -996,11 +993,6 @@ unsigned int CConf::getPower() const return m_power; } -std::string CConf::getLocation() const -{ - return m_location; -} - unsigned int CConf::getLogDisplayLevel() const { return m_logDisplayLevel; diff --git a/Conf.h b/Conf.h index 3e868ef..f75fdb4 100644 --- a/Conf.h +++ b/Conf.h @@ -42,7 +42,6 @@ public: unsigned int getRXFrequency() const; unsigned int getTXFrequency() const; unsigned int getPower() const; - std::string getLocation() const; // The Log section unsigned int getLogDisplayLevel() const; @@ -316,7 +315,6 @@ private: unsigned int m_rxFrequency; unsigned int m_txFrequency; unsigned int m_power; - std::string m_location; unsigned int m_logDisplayLevel; unsigned int m_logFileLevel; diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index d784e21..3d29fb1 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -55,7 +55,6 @@ m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), m_colorCode(0U), -m_location(), m_pingTimer(1000U, 10U) { assert(!address.empty()); @@ -89,14 +88,13 @@ CDMRNetwork::~CDMRNetwork() delete[] m_id; } -void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, const std::string& location) +void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode) { m_callsign = callsign; m_rxFrequency = rxFrequency; m_txFrequency = txFrequency; m_power = power; m_colorCode = colorCode; - m_location = location; } bool CDMRNetwork::open() @@ -401,15 +399,15 @@ bool CDMRNetwork::writeConfig() if (power > 99U) power = 99U; - char buffer[200U]; + char buffer[150U]; ::memcpy(buffer + 0U, "DMRC", 4U); ::memcpy(buffer + 4U, m_id, 4U); - ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%-20.20s%c%-40.40s%-40.40s", - m_callsign.c_str(), m_rxFrequency, m_txFrequency, power, m_colorCode, m_location.c_str(), slots, m_version, + ::sprintf(buffer + 8U, "%-8.8s%09u%09u%02u%02u%c%-40.40s%-40.40s", + m_callsign.c_str(), m_rxFrequency, m_txFrequency, power, m_colorCode, slots, m_version, software); - return write((unsigned char*)buffer, 139U); + return write((unsigned char*)buffer, 119U); } bool CDMRNetwork::wantsBeacon() @@ -426,8 +424,8 @@ bool CDMRNetwork::write(const unsigned char* data, unsigned int length) assert(data != NULL); assert(length > 0U); - // if (m_debug) - // CUtils::dump(1U, "Network Transmitted", data, length); + if (m_debug) + CUtils::dump(1U, "Network Transmitted", data, length); bool ret = m_socket.write(data, length, m_address, m_port); if (!ret) { diff --git a/DMRNetwork.h b/DMRNetwork.h index 7539ec3..9f01925 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -35,7 +35,7 @@ public: CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType); ~CDMRNetwork(); - void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, const std::string& location); + void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode); bool open(); @@ -78,7 +78,6 @@ private: unsigned int m_txFrequency; unsigned int m_power; unsigned int m_colorCode; - std::string m_location; CTimer m_pingTimer; bool writeConfig(); diff --git a/Display.cpp b/Display.cpp index 6238d57..39b0a09 100644 --- a/Display.cpp +++ b/Display.cpp @@ -556,10 +556,10 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) if (port == "modem") { ISerialPort* serial = new CModemSerialPort(modem); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } else if (port == "ump") { if (ump != NULL) { - display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, ump, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } else { LogInfo(" NullDisplay loaded"); display = new CNullDisplay; @@ -571,7 +571,7 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CUMP* ump, CModem* modem) LogInfo(" Display baudrate: %u ",baudrate); ISerialPort* serial = new CSerialController(port, baudrate); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, conf.getLocation()); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); } } else if (type == "LCDproc") { std::string address = conf.getLCDprocAddress(); diff --git a/MMDVM.ini b/MMDVM.ini index c4f11e0..9600db8 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -13,7 +13,6 @@ Daemon=0 RXFrequency=435000000 TXFrequency=435000000 Power=1 -Location=Nowhere [Log] # Logging levels, 0=No logging diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 8a6c5d0..1231e99 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -1345,16 +1345,14 @@ bool CMMDVMHost::createDMRNetwork() unsigned int txFrequency = m_conf.getTXFrequency(); unsigned int power = m_conf.getPower(); unsigned int colorCode = m_conf.getDMRColorCode(); - std::string location = m_conf.getLocation(); LogInfo("Info Parameters"); LogInfo(" Callsign: %s", m_callsign.c_str()); LogInfo(" RX Frequency: %uHz", rxFrequency); LogInfo(" TX Frequency: %uHz", txFrequency); LogInfo(" Power: %uW", power); - LogInfo(" Location: \"%s\"", location.c_str()); - m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode, location); + m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode); bool ret = m_dmrNetwork->open(); if (!ret) { diff --git a/Nextion.cpp b/Nextion.cpp index b5253c1..fa6851e 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -47,7 +47,7 @@ const unsigned int NXDN_BER_COUNT = 28U; // 28 * 40ms = 1120ms // 00:low, others:high-speed. bit[2] is overlapped with LAYOUT_COMPAT_MASK. #define LAYOUT_HIGHSPEED (3 << 2) -CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location) : +CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF) : CDisplay(), m_callsign(callsign), m_ipaddress("(ip unknown)"), @@ -72,8 +72,7 @@ m_txFrequency(txFrequency), m_rxFrequency(rxFrequency), m_fl_txFrequency(0.0F), m_fl_rxFrequency(0.0F), -m_displayTempInF(displayTempInF), -m_location(location) +m_displayTempInF(displayTempInF) { assert(serial != NULL); assert(brightness >= 0U && brightness <= 100U); @@ -178,10 +177,6 @@ void CNextion::setIdleInt() sendCommandAction(22U); } } - - ::sprintf(command, "t31.txt=\"%s\"", m_location.c_str()); // location - sendCommand(command); - sendCommandAction(23U); } else { sendCommandAction(17U); } diff --git a/Nextion.h b/Nextion.h index 7217d2a..488372f 100644 --- a/Nextion.h +++ b/Nextion.h @@ -29,7 +29,7 @@ class CNextion : public CDisplay { public: - CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, const std::string& location); + CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); virtual ~CNextion(); virtual bool open(); @@ -103,7 +103,6 @@ private: double m_fl_txFrequency; double m_fl_rxFrequency; bool m_displayTempInF; - std::string m_location; void sendCommand(const char* command); void sendCommandAction(unsigned int status); diff --git a/Version.h b/Version.h index 426bd2a..a4a9c51 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200826"; +const char* VERSION = "20200827"; #endif From 132fb62d56d5e3fbda4d64c4c8d570e30e9d9564 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 30 Aug 2020 14:54:51 +0100 Subject: [PATCH 16/16] Small cleanups. --- DMRNetwork.cpp | 3 --- Version.h | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index 3d29fb1..3a7b344 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -241,9 +241,6 @@ bool CDMRNetwork::write(const CDMRData& data) buffer[54U] = data.getRSSI(); - if (m_debug) - CUtils::dump(1U, "Network Transmitted", buffer, HOMEBREW_DATA_PACKET_LENGTH); - write(buffer, HOMEBREW_DATA_PACKET_LENGTH); return true; diff --git a/Version.h b/Version.h index a4a9c51..23ae81e 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200827"; +const char* VERSION = "20200830"; #endif