Clean ups for IPv6.

This commit is contained in:
Jonathan Naylor 2020-09-06 12:54:08 +01:00
parent e45f0edec4
commit 7d3e899104
17 changed files with 323 additions and 259 deletions

View file

@ -34,8 +34,8 @@ const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U;
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_addrlen(),
m_addr(),
m_addrLen(0U),
m_port(port),
m_id(NULL),
m_duplex(duplex),
@ -62,7 +62,8 @@ m_pingTimer(1000U, 10U)
assert(port > 0U);
assert(id > 1000U);
CUDPSocket::lookup(m_addressStr, m_port, m_address, m_addrlen);
if (CUDPSocket::lookup(m_addressStr, m_port, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
m_buffer = new unsigned char[BUFFER_LENGTH];
m_id = new uint8_t[4U];
@ -100,12 +101,14 @@ void CDMRNetwork::setConfig(const std::string & callsign, unsigned int rxFrequen
bool CDMRNetwork::open()
{
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the DMR Gateway");
return false;
}
LogMessage("DMR, Opening DMR Network");
if (CUDPSocket::isNone(m_address))
CUDPSocket::lookup(m_addressStr, m_port, m_address, m_addrlen);
bool ret = m_socket.open();
bool ret = m_socket.open(m_addr);
if (ret)
m_pingTimer.start();
@ -297,26 +300,25 @@ void CDMRNetwork::clock(unsigned int ms)
}
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrlen);
unsigned int addrLen;
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_address, address)) {
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("DMR, packet received from an invalid source");
return;
}
if (!m_enabled)
return;
if (m_debug)
CUtils::dump(1U, "Network Received", 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);
if (m_enabled) {
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) {
@ -427,7 +429,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_addrlen);
bool ret = m_socket.write(data, length, m_addr, m_addrLen);
if (!ret) {
LogError("DMR, socket error when writing to the DMR Gateway");
return false;

View file

@ -56,30 +56,30 @@ public:
void close();
private:
std::string m_addressStr;
sockaddr_storage m_address;
unsigned int m_addrlen;
unsigned int m_port;
uint8_t* m_id;
bool m_duplex;
const char* m_version;
bool m_debug;
CUDPSocket m_socket;
bool m_enabled;
bool m_slot1;
bool m_slot2;
HW_TYPE m_hwType;
unsigned char* m_buffer;
uint32_t* m_streamId;
std::string m_addressStr;
sockaddr_storage m_addr;
unsigned int m_addrLen;
unsigned int m_port;
uint8_t* m_id;
bool m_duplex;
const char* m_version;
bool m_debug;
CUDPSocket m_socket;
bool m_enabled;
bool m_slot1;
bool m_slot2;
HW_TYPE m_hwType;
unsigned char* m_buffer;
uint32_t* m_streamId;
CRingBuffer<unsigned char> 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;
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;
bool writeConfig();

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016,2019 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,2019,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,8 +32,8 @@ 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_addrlen(),
m_addr(),
m_addrLen(0U),
m_duplex(duplex),
m_version(version),
m_debug(debug),
@ -47,7 +47,8 @@ m_linkStatus(LS_NONE),
m_linkReflector(NULL),
m_random()
{
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH];
@ -63,14 +64,16 @@ CDStarNetwork::~CDStarNetwork()
bool CDStarNetwork::open()
{
LogMessage("Opening D-Star network connection");
if (CUDPSocket::isNone(m_address))
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the ircDDB Gateway");
return false;
}
LogMessage("Opening D-Star network connection");
m_pollTimer.start();
return m_socket.open(m_address.ss_family);
return m_socket.open(m_addr);
}
bool CDStarNetwork::writeHeader(const unsigned char* header, unsigned int length, bool busy)
@ -103,7 +106,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_addrlen);
bool ret = m_socket.write(buffer, 49U, m_addr, m_addrLen);
if (!ret)
return false;
}
@ -146,7 +149,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_addrlen);
return m_socket.write(buffer, length + 9U, m_addr, m_addrLen);
}
bool CDStarNetwork::writePoll(const char* text)
@ -170,7 +173,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_addrlen);
return m_socket.write(buffer, 6U + length, m_addr, m_addrLen);
}
void CDStarNetwork::clock(unsigned int ms)
@ -196,11 +199,16 @@ void CDStarNetwork::clock(unsigned int ms)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
unsigned int addrLen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("D-Star, packet received from an invalid source");
return;
}
// Invalid packet type?
if (::memcmp(buffer, "DSRP", 4U) != 0)
return;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,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
@ -51,21 +51,21 @@ public:
void clock(unsigned int ms);
private:
CUDPSocket m_socket;
sockaddr_storage m_address;
unsigned int m_addrlen;
bool m_duplex;
const char* m_version;
bool m_debug;
bool m_enabled;
uint16_t m_outId;
uint8_t m_outSeq;
uint16_t m_inId;
CUDPSocket m_socket;
sockaddr_storage m_addr;
unsigned int m_addrLen;
bool m_duplex;
const char* m_version;
bool m_debug;
bool m_enabled;
uint16_t m_outId;
uint8_t m_outSeq;
uint16_t m_inId;
CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer;
LINK_STATUS m_linkStatus;
unsigned char* m_linkReflector;
std::mt19937 m_random;
CTimer m_pollTimer;
LINK_STATUS m_linkStatus;
unsigned char* m_linkReflector;
std::mt19937 m_random;
bool writePoll(const char* text);
};

View file

@ -338,10 +338,13 @@ int CMMDVMHost::run()
LogInfo(" Local Port: %u", localPort);
LogInfo(" Send Frame Type: %u", sendFrameType);
CUDPSocket::lookup(remoteAddress, remotePort, transparentAddress, transparentAddrLen);
if (CUDPSocket::lookup(remoteAddress, remotePort, transparentAddress, transparentAddrLen) != 0) {
LogError("Unable to resolve the address of the Transparent Data source");
return 1;
}
transparentSocket = new CUDPSocket(localPort);
ret = transparentSocket->open(transparentAddress.ss_family);
ret = transparentSocket->open(transparentAddress);
if (!ret) {
LogWarning("Could not open the Transparent data socket, disabling");
delete transparentSocket;

View file

@ -30,8 +30,8 @@ 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_addrlen(),
m_addr(),
m_addrLen(0U),
m_debug(debug),
m_enabled(false),
m_buffer(1000U, "NXDN Network")
@ -39,7 +39,8 @@ m_buffer(1000U, "NXDN Network")
assert(gatewayPort > 0U);
assert(!gatewayAddress.empty());
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
}
CNXDNIcomNetwork::~CNXDNIcomNetwork()
@ -48,12 +49,14 @@ CNXDNIcomNetwork::~CNXDNIcomNetwork()
bool CNXDNIcomNetwork::open()
{
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the NXDN Gateway");
return false;
}
LogMessage("Opening NXDN network connection");
if (CUDPSocket::isNone(m_address))
return false;
return m_socket.open();
return m_socket.open(m_addr);
}
bool CNXDNIcomNetwork::write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type)
@ -100,7 +103,7 @@ 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_addrlen);
return m_socket.write(buffer, 102U, m_addr, m_addrLen);
}
void CNXDNIcomNetwork::clock(unsigned int ms)
@ -108,11 +111,19 @@ void CNXDNIcomNetwork::clock(unsigned int ms)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
unsigned int addrLen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("NXDN, packet received from an invalid source");
return;
}
if (m_debug)
CUtils::dump(1U, "NXDN Network Data Received", buffer, length);
// Invalid packet type?
if (::memcmp(buffer, "ICOM", 4U) != 0)
return;
@ -123,9 +134,6 @@ void CNXDNIcomNetwork::clock(unsigned int ms)
if (!m_enabled)
return;
if (m_debug)
CUtils::dump(1U, "NXDN Network Data Received", buffer, length);
m_buffer.addData(buffer + 40U, 33U);
}

View file

@ -33,26 +33,26 @@ public:
CNXDNIcomNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug);
virtual ~CNXDNIcomNetwork();
virtual bool open();
virtual bool open();
virtual void enable(bool enabled);
virtual void enable(bool enabled);
virtual bool write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);
virtual bool write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);
virtual bool read(unsigned char* data);
virtual bool read(unsigned char* data);
virtual void reset();
virtual void reset();
virtual void close();
virtual void close();
virtual void clock(unsigned int ms);
virtual void clock(unsigned int ms);
private:
CUDPSocket m_socket;
sockaddr_storage m_address;
unsigned int m_addrlen;
bool m_debug;
bool m_enabled;
CUDPSocket m_socket;
sockaddr_storage m_addr;
unsigned int m_addrLen;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;
};

View file

@ -36,9 +36,10 @@ 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_rtcpaddress(),
m_rtpaddress(),
m_addrlen(),
m_rtcpAddr(),
m_rtpAddr(),
m_rtcpAddrLen(0U),
m_rtpAddrLen(0U),
m_enabled(false),
m_headerSeen(false),
m_seen1(false),
@ -65,8 +66,11 @@ m_random()
m_sacch = new unsigned char[10U];
CUDPSocket::lookup(gwyAddress, gwyPort + 1, m_rtcpaddress, m_addrlen);
CUDPSocket::lookup(gwyAddress, gwyPort, m_rtpaddress, m_addrlen);
if (CUDPSocket::lookup(gwyAddress, gwyPort + 1U, m_rtcpAddr, m_rtcpAddrLen) != 0)
m_rtcpAddrLen = 0U;
if (CUDPSocket::lookup(gwyAddress, gwyPort + 0U, m_rtpAddr, m_rtpAddrLen) != 0)
m_rtpAddrLen = 0U;
std::random_device rd;
std::mt19937 mt(rd());
@ -80,16 +84,17 @@ CNXDNKenwoodNetwork::~CNXDNKenwoodNetwork()
bool CNXDNKenwoodNetwork::open()
{
if (m_rtcpAddrLen == 0U || m_rtpAddrLen == 0U) {
LogError("Unable to resolve the address of the NXDN Gateway");
return false;
}
LogMessage("Opening Kenwood connection");
if (CUDPSocket::isNone(m_rtpaddress) ||
CUDPSocket::isNone(m_rtcpaddress))
if (!m_rtcpSocket.open(m_rtcpAddr))
return false;
if (!m_rtcpSocket.open())
return false;
if (!m_rtpSocket.open()) {
if (!m_rtpSocket.open(m_rtpAddr)) {
m_rtcpSocket.close();
return false;
}
@ -365,7 +370,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 47U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTPVoiceTrailer(const unsigned char* data)
@ -411,7 +416,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 47U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTPVoiceData(const unsigned char* data)
@ -457,7 +462,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 59U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTPDataHeader(const unsigned char* data)
@ -499,7 +504,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 42U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTPDataTrailer(const unsigned char* data)
@ -541,7 +546,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 42U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTPDataData(const unsigned char* data)
@ -583,7 +588,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_rtpaddress, m_addrlen);
return m_rtpSocket.write(buffer, 42U, m_rtpAddr, m_rtpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTCPStart()
@ -643,7 +648,7 @@ bool CNXDNKenwoodNetwork::writeRTCPStart()
if (m_debug)
CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 28U);
return m_rtcpSocket.write(buffer, 28U, m_rtcpaddress, m_addrlen);
return m_rtcpSocket.write(buffer, 28U, m_rtcpAddr, m_rtcpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTCPPing()
@ -685,7 +690,7 @@ bool CNXDNKenwoodNetwork::writeRTCPPing()
if (m_debug)
CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 28U);
return m_rtcpSocket.write(buffer, 28U, m_rtcpaddress, m_addrlen);
return m_rtcpSocket.write(buffer, 28U, m_rtcpAddr, m_rtcpAddrLen);
}
bool CNXDNKenwoodNetwork::writeRTCPHang(unsigned char type, unsigned short src, unsigned short dst)
@ -728,7 +733,7 @@ bool CNXDNKenwoodNetwork::writeRTCPHang()
if (m_debug)
CUtils::dump(1U, "Kenwood Network RTCP Data Sent", buffer, 20U);
return m_rtcpSocket.write(buffer, 20U, m_rtcpaddress, m_addrlen);
return m_rtcpSocket.write(buffer, 20U, m_rtcpAddr, m_rtcpAddrLen);
}
bool CNXDNKenwoodNetwork::read(unsigned char* data)
@ -764,11 +769,16 @@ unsigned int CNXDNKenwoodNetwork::readRTP(unsigned char* data)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_rtpSocket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_rtpaddress, address, IMT_ADDRESS_ONLY))
unsigned int addrLen;
int length = m_rtpSocket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return 0U;
if (!CUDPSocket::match(m_rtpAddr, address, IMT_ADDRESS_ONLY)) {
LogMessage("NXDN, RTP packet received from an invalid source");
return 0U;
}
if (!m_enabled)
return 0U;
@ -789,9 +799,14 @@ unsigned int CNXDNKenwoodNetwork::readRTCP(unsigned char* data)
sockaddr_storage address;
unsigned int addrlen;
int length = m_rtcpSocket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_rtcpaddress, address, IMT_ADDRESS_ONLY))
if (length <= 0)
return 0U;
if (!CUDPSocket::match(m_rtpAddr, address, IMT_ADDRESS_ONLY)) {
LogMessage("NXDN, RTCP packet received from an invalid source");
return 0U;
}
if (!m_enabled)
return 0U;

View file

@ -34,66 +34,67 @@ public:
virtual bool open();
virtual void enable(bool enabled);
virtual void enable(bool enabled);
virtual bool write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);
virtual bool write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);
virtual bool read(unsigned char* data);
virtual void reset();
virtual void reset();
virtual void close();
virtual void close();
virtual void clock(unsigned int ms);
virtual void clock(unsigned int ms);
private:
CUDPSocket m_rtpSocket;
CUDPSocket m_rtcpSocket;
sockaddr_storage m_rtcpaddress;
sockaddr_storage m_rtpaddress;
unsigned int m_addrlen;
bool m_enabled;
bool m_headerSeen;
bool m_seen1;
bool m_seen2;
bool m_seen3;
bool m_seen4;
unsigned char* m_sacch;
uint8_t m_sessionId;
uint16_t m_seqNo;
unsigned int m_ssrc;
bool m_debug;
uint32_t m_startSecs;
uint32_t m_startUSecs;
CTimer m_rtcpTimer;
CTimer m_hangTimer;
unsigned char m_hangType;
unsigned short m_hangSrc;
unsigned short m_hangDst;
std::mt19937 m_random;
CUDPSocket m_rtpSocket;
CUDPSocket m_rtcpSocket;
sockaddr_storage m_rtcpAddr;
sockaddr_storage m_rtpAddr;
unsigned int m_rtcpAddrLen;
unsigned int m_rtpAddrLen;
bool m_enabled;
bool m_headerSeen;
bool m_seen1;
bool m_seen2;
bool m_seen3;
bool m_seen4;
unsigned char* m_sacch;
uint8_t m_sessionId;
uint16_t m_seqNo;
unsigned int m_ssrc;
bool m_debug;
uint32_t m_startSecs;
uint32_t m_startUSecs;
CTimer m_rtcpTimer;
CTimer m_hangTimer;
unsigned char m_hangType;
unsigned short m_hangSrc;
unsigned short m_hangDst;
std::mt19937 m_random;
bool processIcomVoiceHeader(const unsigned char* data);
bool processIcomVoiceData(const unsigned char* data);
bool processIcomDataHeader(const unsigned char* data);
bool processIcomDataData(const unsigned char* data);
bool processIcomDataTrailer(const unsigned char* data);
bool processKenwoodVoiceHeader(unsigned char* data);
bool processKenwoodVoiceData(unsigned char* data);
bool processKenwoodVoiceLateEntry(unsigned char* data);
bool processKenwoodData(unsigned char* data);
bool writeRTPVoiceHeader(const unsigned char* data);
bool writeRTPVoiceData(const unsigned char* data);
bool writeRTPVoiceTrailer(const unsigned char* data);
bool writeRTPDataHeader(const unsigned char* data);
bool writeRTPDataData(const unsigned char* data);
bool writeRTPDataTrailer(const unsigned char* data);
bool writeRTCPStart();
bool writeRTCPPing();
bool writeRTCPHang(unsigned char type, unsigned short src, unsigned short dst);
bool writeRTCPHang();
unsigned int readRTP(unsigned char* data);
unsigned int readRTCP(unsigned char* data);
unsigned long getTimeStamp() const;
bool processIcomVoiceHeader(const unsigned char* data);
bool processIcomVoiceData(const unsigned char* data);
bool processIcomDataHeader(const unsigned char* data);
bool processIcomDataData(const unsigned char* data);
bool processIcomDataTrailer(const unsigned char* data);
bool processKenwoodVoiceHeader(unsigned char* data);
bool processKenwoodVoiceData(unsigned char* data);
bool processKenwoodVoiceLateEntry(unsigned char* data);
bool processKenwoodData(unsigned char* data);
bool writeRTPVoiceHeader(const unsigned char* data);
bool writeRTPVoiceData(const unsigned char* data);
bool writeRTPVoiceTrailer(const unsigned char* data);
bool writeRTPDataHeader(const unsigned char* data);
bool writeRTPDataData(const unsigned char* data);
bool writeRTPDataTrailer(const unsigned char* data);
bool writeRTCPStart();
bool writeRTCPPing();
bool writeRTCPHang(unsigned char type, unsigned short src, unsigned short dst);
bool writeRTCPHang();
unsigned int readRTP(unsigned char* data);
unsigned int readRTCP(unsigned char* data);
unsigned long getTimeStamp() const;
};
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016,2019 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,2019,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
@ -89,14 +89,15 @@ 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_addrlen(),
m_addr(),
m_addrLen(0U),
m_debug(debug),
m_enabled(false),
m_buffer(1000U, "P25 Network"),
m_audio()
{
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
}
CP25Network::~CP25Network()
@ -105,12 +106,14 @@ CP25Network::~CP25Network()
bool CP25Network::open()
{
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the P25 Gateway");
return false;
}
LogMessage("Opening P25 network connection");
if (CUDPSocket::isNone(m_address))
return false;
return m_socket.open(m_address.ss_family);
return m_socket.open(m_addr);
}
bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, const CP25LowSpeedData& lsd, bool end)
@ -126,7 +129,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_addrlen);
bool ret = m_socket.write(buffer, 22U, m_addr, m_addrLen);
if (!ret)
return false;
@ -137,7 +140,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_addrlen);
ret = m_socket.write(buffer, 14U, m_addr, m_addrLen);
if (!ret)
return false;
@ -150,7 +153,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -165,7 +168,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -180,7 +183,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -191,7 +194,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -202,7 +205,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -213,7 +216,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -226,7 +229,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_addrlen);
ret = m_socket.write(buffer, 16U, m_addr, m_addrLen);
if (!ret)
return false;
@ -234,7 +237,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_addrlen);
ret = m_socket.write(REC80, 17U, m_addr, m_addrLen);
if (!ret)
return false;
}
@ -255,7 +258,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_addrlen);
bool ret = m_socket.write(buffer, 22U, m_addr, m_addrLen);
if (!ret)
return false;
@ -266,7 +269,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_addrlen);
ret = m_socket.write(buffer, 14U, m_addr, m_addrLen);
if (!ret)
return false;
@ -283,7 +286,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -297,7 +300,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -311,7 +314,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -326,7 +329,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -337,7 +340,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -348,7 +351,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_addrlen);
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
if (!ret)
return false;
@ -361,7 +364,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_addrlen);
ret = m_socket.write(buffer, 16U, m_addr, m_addrLen);
if (!ret)
return false;
@ -369,7 +372,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_addrlen);
ret = m_socket.write(REC80, 17U, m_addr, m_addrLen);
if (!ret)
return false;
}
@ -382,11 +385,16 @@ void CP25Network::clock(unsigned int ms)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
unsigned int addrLen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("P25, packet received from an invalid source");
return;
}
if (!m_enabled)
return;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,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
@ -48,13 +48,13 @@ public:
void clock(unsigned int ms);
private:
CUDPSocket m_socket;
sockaddr_storage m_address;
unsigned int m_addrlen;
bool m_debug;
bool m_enabled;
CUDPSocket m_socket;
sockaddr_storage m_addr;
unsigned int m_addrLen;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;
CP25Audio m_audio;
CP25Audio m_audio;
};
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018,2019 by Jonathan Naylor G4KLX
* Copyright (C) 2018,2019,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
@ -30,13 +30,14 @@ 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_addrlen(),
m_addr(),
m_addrLen(0U),
m_debug(debug),
m_enabled(false),
m_buffer(1000U, "POCSAG Network")
{
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
}
CPOCSAGNetwork::~CPOCSAGNetwork()
@ -45,10 +46,12 @@ CPOCSAGNetwork::~CPOCSAGNetwork()
bool CPOCSAGNetwork::open()
{
LogMessage("Opening POCSAG network connection");
if (CUDPSocket::isNone(m_address))
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the DAPNET Gateway");
return false;
}
LogMessage("Opening POCSAG network connection");
return m_socket.open();
}
@ -58,11 +61,19 @@ void CPOCSAGNetwork::clock(unsigned int ms)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
unsigned int addrLen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("POCSAG, packet received from an invalid source");
return;
}
if (m_debug)
CUtils::dump(1U, "POCSAG Network Data Received", buffer, length);
// Invalid packet type?
if (::memcmp(buffer, "POCSAG", 6U) != 0)
return;
@ -70,9 +81,6 @@ void CPOCSAGNetwork::clock(unsigned int ms)
if (!m_enabled)
return;
if (m_debug)
CUtils::dump(1U, "POCSAG Network Data Received", buffer, length);
unsigned char len = length - 6U;
m_buffer.addData(&len, 1U);
m_buffer.addData(buffer + 6U, length - 6U);
@ -112,7 +120,7 @@ void CPOCSAGNetwork::enable(bool enabled)
unsigned char c = enabled ? 0x00U : 0xFFU;
m_socket.write(&c, 1U, m_address, m_addrlen);
m_socket.write(&c, 1U, m_addr, m_addrLen);
m_enabled = enabled;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 by Jonathan Naylor G4KLX
* 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
@ -45,11 +45,11 @@ public:
void clock(unsigned int ms);
private:
CUDPSocket m_socket;
sockaddr_storage m_address;
unsigned int m_addrlen;
bool m_debug;
bool m_enabled;
CUDPSocket m_socket;
sockaddr_storage m_addr;
unsigned int m_addrLen;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;
};

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 by Jonathan Naylor G4KLX
* Copyright (C) 2019,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
@ -61,17 +61,20 @@ CRemoteCommand::~CRemoteCommand()
int CRemoteCommand::send(const std::string& command)
{
sockaddr_storage address;
unsigned int addrlen;
CUDPSocket::lookup("127.0.0.1", m_port, address, addrlen);
sockaddr_storage addr;
unsigned int addrLen;
if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) {
LogError("Unable to resolve the address of the host");
return 1;
}
CUDPSocket socket(0U);
bool ret = socket.open(address.ss_family);
bool ret = socket.open(addr);
if (!ret)
return 1;
ret = socket.write((unsigned char*)command.c_str(), command.length(), address, addrlen);
ret = socket.write((unsigned char*)command.c_str(), command.length(), addr, addrLen);
if (!ret) {
socket.close();
return 1;

View file

@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H
const char* VERSION = "20200830";
const char* VERSION = "20200906";
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016,2019 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,2019,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
@ -30,8 +30,8 @@ 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_addrlen(),
m_addr(),
m_addrLen(0U),
m_callsign(),
m_debug(debug),
m_enabled(false),
@ -42,7 +42,8 @@ m_tag(NULL)
m_callsign = callsign;
m_callsign.resize(YSF_CALLSIGN_LENGTH, ' ');
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
m_addrLen = 0U;
m_tag = new unsigned char[YSF_CALLSIGN_LENGTH];
::memset(m_tag, ' ', YSF_CALLSIGN_LENGTH);
@ -55,14 +56,16 @@ CYSFNetwork::~CYSFNetwork()
bool CYSFNetwork::open()
{
LogMessage("Opening YSF network connection");
if (CUDPSocket::isNone(m_address))
if (m_addrLen == 0U) {
LogError("Unable to resolve the address of the YSF Gateway");
return false;
}
LogMessage("Opening YSF network connection");
m_pollTimer.start();
return m_socket.open();
return m_socket.open(m_addr);
}
bool CYSFNetwork::write(const unsigned char* src, const unsigned char* dest, const unsigned char* data, unsigned int count, bool end)
@ -97,7 +100,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_addrlen);
return m_socket.write(buffer, 155U, m_addr, m_addrLen);
}
bool CYSFNetwork::writePoll()
@ -115,7 +118,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_addrlen);
return m_socket.write(buffer, 14U, m_addr, m_addrLen);
}
void CYSFNetwork::clock(unsigned int ms)
@ -129,11 +132,16 @@ void CYSFNetwork::clock(unsigned int ms)
unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
unsigned int addrLen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
if (length <= 0)
return;
if (!CUDPSocket::match(m_addr, address)) {
LogMessage("YSF, packet received from an invalid source");
return;
}
// Ignore incoming polls
if (::memcmp(buffer, "YSFP", 4U) == 0)
return;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,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
@ -47,15 +47,15 @@ public:
void clock(unsigned int ms);
private:
CUDPSocket m_socket;
sockaddr_storage m_address;
unsigned int m_addrlen;
std::string m_callsign;
bool m_debug;
bool m_enabled;
CUDPSocket m_socket;
sockaddr_storage m_addr;
unsigned int m_addrLen;
std::string m_callsign;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer;
unsigned char* m_tag;
CTimer m_pollTimer;
unsigned char* m_tag;
bool writePoll();
};