moved XLX to URF to make room for XLX needed for BM

unstable
Tom Early 4 years ago
parent d38bf58891
commit 245fb5d321

@ -19,7 +19,7 @@
#pragma once #pragma once
#include "Client.h" #include "Client.h"
#include "URFClient.h" #include "XLXClient.h"
class CBmClient : public CClient class CBmClient : public CClient
{ {
@ -33,8 +33,8 @@ public:
virtual ~CBmClient() {}; virtual ~CBmClient() {};
// identity // identity
EProtocol GetProtocol(void) const { return EProtocol::ulx; } EProtocol GetProtocol(void) const { return EProtocol::xlx; }
int GetProtocolRevision(void) const { return XLX_PROTOCOL_REVISION_2; } EProtoRev GetProtocolRevision(void) const { return EProtoRev::m17; }
const char *GetProtocolName(void) const { return "XLX"; } const char *GetProtocolName(void) const { return "XLX"; }
ECodecType GetCodec(void) const { return ECodecType::dmr; } ECodecType GetCodec(void) const { return ECodecType::dmr; }
bool IsPeer(void) const { return true; } bool IsPeer(void) const { return true; }

@ -56,7 +56,7 @@ bool CBmPeer::IsAlive(void) const
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// revision helper // revision helper
int CBmPeer::GetProtocolRevision(const CVersion &version) EProtoRev CBmPeer::GetProtocolRevision(const CVersion &version)
{ {
return XLX_PROTOCOL_REVISION_2; return EProtoRev::ambe;
} }

@ -40,9 +40,9 @@ public:
bool IsAlive(void) const; bool IsAlive(void) const;
// identity // identity
EProtocol GetProtocol(void) const { return EProtocol::ulx; } EProtocol GetProtocol(void) const { return EProtocol::xlx; }
const char *GetProtocolName(void) const { return "XLX"; } const char *GetProtocolName(void) const { return "XLX"; }
// revision helper // revision helper
static int GetProtocolRevision(const CVersion &); static EProtoRev GetProtocolRevision(const CVersion &);
}; };

@ -24,7 +24,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "Packet.h" #include "Packet.h"
enum class EXLXProtocol { original, revised, ambe, m17 }; enum class EProtoRev { original, revised, ambe, urf };
class CClient class CClient
{ {
@ -54,7 +54,7 @@ public:
// identity // identity
virtual EProtocol GetProtocol(void) const { return EProtocol::none; } virtual EProtocol GetProtocol(void) const { return EProtocol::none; }
virtual EXLXProtocol GetProtocolRevision(void) const { return EXLXProtocol::m17; } virtual EProtoRev GetProtocolRevision(void) const { return EProtoRev::ambe; }
virtual ECodecType GetCodec(void) const { return ECodecType::none; } virtual ECodecType GetCodec(void) const { return ECodecType::none; }
virtual const char *GetProtocolName(void) const { return "none"; } virtual const char *GetProtocolName(void) const { return "none"; }
virtual bool IsNode(void) const { return false; } virtual bool IsNode(void) const { return false; }

@ -72,17 +72,8 @@ void CDcsProtocol::Task(void)
{ {
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
if ( !Frame->IsLastPacket() )
{
//std::cout << "DCS DV frame" << std::endl;
OnDvFramePacketIn(Frame, &Ip); OnDvFramePacketIn(Frame, &Ip);
} }
else
{
//std::cout << "DCS DV last frame" << std::endl;
OnDvLastFramePacketIn((std::unique_ptr<CDvLastFramePacket> &)Frame, &Ip);
}
}
} }
else if ( IsValidConnectPacket(Buffer, &Callsign, &ToLinkModule) ) else if ( IsValidConnectPacket(Buffer, &Callsign, &ToLinkModule) )
{ {
@ -393,16 +384,7 @@ bool CDcsProtocol::IsValidDvPacket(const CBuffer &Buffer, std::unique_ptr<CDvHea
header = std::unique_ptr<CDvHeaderPacket>(new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), *((uint16_t *)&(Buffer.data()[43])), 0x80)); header = std::unique_ptr<CDvHeaderPacket>(new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), *((uint16_t *)&(Buffer.data()[43])), 0x80));
// get the frame // get the frame
if ( Buffer.data()[45] & 0x40U ) frame = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDStarFrame *)&(Buffer.data()[46]), *((uint16_t *)&(Buffer.data()[43])), Buffer.data()[45]));
{
// it's the last frame
frame = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket((SDstarFrame *)&(Buffer.data()[46]), *((uint16_t *)&(Buffer.data()[43])), Buffer.data()[45]));
}
else
{
// it's a regular DV frame
frame = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDstarFrame *)&(Buffer.data()[46]), *((uint16_t *)&(Buffer.data()[43])), Buffer.data()[45]));
}
// check validity of packets // check validity of packets
if ( header && header->IsValid() && frame && frame->IsValid() ) if ( header && header->IsValid() && frame && frame->IsValid() )

@ -22,7 +22,6 @@
#include "Protocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// define // define

@ -54,7 +54,6 @@ void CDextraProtocol::Task(void)
int ProtRev; int ProtRev;
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvFramePacket> Frame; std::unique_ptr<CDvFramePacket> Frame;
std::unique_ptr<CDvLastFramePacket> LastFrame;
// any incoming packet ? // any incoming packet ?
#if DSTAR_IPV6==true #if DSTAR_IPV6==true
@ -80,10 +79,6 @@ void CDextraProtocol::Task(void)
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
} }
} }
else if ( IsValidDvLastFramePacket(Buffer, LastFrame) )
{
OnDvLastFramePacketIn(LastFrame, &Ip);
}
else if ( IsValidConnectPacket(Buffer, &Callsign, &ToLinkModule, &ProtRev) ) else if ( IsValidConnectPacket(Buffer, &Callsign, &ToLinkModule, &ProtRev) )
{ {
std::cout << "DExtra connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << " rev " << ProtRev << std::endl; std::cout << "DExtra connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << " rev " << ProtRev << std::endl;
@ -151,12 +146,12 @@ void CDextraProtocol::Task(void)
if ( client != nullptr ) if ( client != nullptr )
{ {
// ack disconnect packet // ack disconnect packet
if ( client->GetProtocolRevision() == 1 ) if ( client->GetProtocolRevision() == EProtoRev::revised )
{ {
EncodeDisconnectedPacket(&Buffer); EncodeDisconnectedPacket(&Buffer);
Send(Buffer, Ip); Send(Buffer, Ip);
} }
else if ( client->GetProtocolRevision() == 2 ) else if ( client->GetProtocolRevision() == EProtoRev::ambe )
{ {
Send(Buffer, Ip); Send(Buffer, Ip);
} }
@ -412,7 +407,7 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Heade
// get client callsign // get client callsign
rpt1 = client->GetCallsign(); rpt1 = client->GetCallsign();
// apply protocol revision details // apply protocol revision details
if ( client->GetProtocolRevision() == 2 ) if ( client->GetProtocolRevision() == EProtoRev::ambe )
{ {
// update Header RPT2 module letter with // update Header RPT2 module letter with
// the module the client is linked to // the module the client is linked to
@ -507,7 +502,7 @@ bool CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_pt
if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && 0U==(Buffer.data()[14] & 0x40U) ) if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && 0U==(Buffer.data()[14] & 0x40U) )
{ {
// create packet // create packet
dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDstarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14])); dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDStarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14]));
// check validity of packet // check validity of packet
if ( dvframe && dvframe->IsValid() ) if ( dvframe && dvframe->IsValid() )
return true; return true;
@ -515,18 +510,6 @@ bool CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_pt
return false; return false;
} }
bool CDextraProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvLastFramePacket> &dvframe)
{
if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && (Buffer.data()[14] & 0x40) )
{
// create packet
dvframe = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket((SDstarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14]));
// check validity of packet
if ( dvframe && dvframe->IsValid() )
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// packet encoding helpers // packet encoding helpers
@ -618,16 +601,3 @@ bool CDextraProtocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer
return true; return true;
} }
bool CDextraProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBuffer *Buffer) const
{
uint8_t tag1[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 };
uint8_t tag2[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x1A,0xC6 };
Buffer->Set(tag1, sizeof(tag1));
Buffer->Append(Packet.GetStreamId());
Buffer->Append((uint8_t)((Packet.GetPacketId() % 21) | 0x40));
Buffer->Append(tag2, sizeof(tag2));
return true;
}

@ -19,10 +19,9 @@
#pragma once #pragma once
#include "Timer.h" #include "Timer.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -74,7 +73,6 @@ protected:
bool IsValidKeepAlivePacket( const CBuffer &, CCallsign *); bool IsValidKeepAlivePacket( const CBuffer &, CCallsign *);
bool IsValidDvHeaderPacket( const CBuffer &, std::unique_ptr<CDvHeaderPacket> &); bool IsValidDvHeaderPacket( const CBuffer &, std::unique_ptr<CDvHeaderPacket> &);
bool IsValidDvFramePacket( const CBuffer &, std::unique_ptr<CDvFramePacket> &); bool IsValidDvFramePacket( const CBuffer &, std::unique_ptr<CDvFramePacket> &);
bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvLastFramePacket> &);
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *); void EncodeKeepAlivePacket(CBuffer *);
@ -85,7 +83,6 @@ protected:
void EncodeDisconnectedPacket(CBuffer *); void EncodeDisconnectedPacket(CBuffer *);
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const;
bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const; bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const;
bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const;
protected: protected:
// time // time

@ -79,7 +79,7 @@ void CDmrmmdvmProtocol::Task(void)
uint8_t Cmd; uint8_t Cmd;
uint8_t CallType; uint8_t CallType;
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvLastFramePacket> LastFrame; std::unique_ptr<CDvFramePacket> LastFrame;
std::array<std::unique_ptr<CDvFramePacket>, 3> Frames; std::array<std::unique_ptr<CDvFramePacket>, 3> Frames;
// handle incoming packets // handle incoming packets
@ -113,7 +113,7 @@ void CDmrmmdvmProtocol::Task(void)
} }
else if ( IsValidDvLastFramePacket(Buffer, LastFrame) ) else if ( IsValidDvLastFramePacket(Buffer, LastFrame) )
{ {
OnDvLastFramePacketIn(LastFrame, &Ip); OnDvFramePacketIn(LastFrame, &Ip);
} }
else if ( IsValidConnectPacket(Buffer, &Callsign, Ip) ) else if ( IsValidConnectPacket(Buffer, &Callsign, Ip) )
{ {
@ -707,15 +707,15 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::array<s
// and create 3 dv frames // and create 3 dv frames
// frame1 // frame1
memcpy(dmrambe, &dmr3ambe[0], 9); memcpy(dmrambe, &dmr3ambe[0], 9);
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 1)); frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 1, false));
// frame2 // frame2
memcpy(dmrambe, &dmr3ambe[9], 9); memcpy(dmrambe, &dmr3ambe[9], 9);
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 2)); frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 2, false));
// frame3 // frame3
memcpy(dmrambe, &dmr3ambe[18], 9); memcpy(dmrambe, &dmr3ambe[18], 9);
frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3)); frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3, false));
// check // check
if (frames[0] && frames[1] && frames[2]) if (frames[0] && frames[1] && frames[2])
@ -725,7 +725,7 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::array<s
return false; return false;
} }
bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvLastFramePacket> &frame) bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &frame)
{ {
uint8_t tag[] = { 'D','M','R','D' }; uint8_t tag[] = { 'D','M','R','D' };
@ -769,7 +769,7 @@ bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::uni
// and packet // and packet
frame = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket(ambe, dmrsync, uiStreamId, 0, 0)); frame = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe, dmrsync, uiStreamId, 0, 0, true));
if (frame) if (frame)
return true; return true;
} }

@ -19,10 +19,9 @@
#pragma once #pragma once
#include "Timer.h" #include "Timer.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// define // define
@ -82,7 +81,7 @@ protected:
bool IsValidRssiPacket(const CBuffer &, CCallsign *, int *); bool IsValidRssiPacket(const CBuffer &, CCallsign *, int *);
bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &, uint8_t *, uint8_t *); bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &, uint8_t *, uint8_t *);
bool IsValidDvFramePacket(const CBuffer &, std::array<std::unique_ptr<CDvFramePacket>, 3> &); bool IsValidDvFramePacket(const CBuffer &, std::array<std::unique_ptr<CDvFramePacket>, 3> &);
bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvLastFramePacket> &); bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr<CClient>); void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr<CClient>);

@ -475,21 +475,21 @@ bool CDmrplusProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer
uint32_t uiStreamId = IpToStreamId(Ip); uint32_t uiStreamId = IpToStreamId(Ip);
// frame1 // frame1
memcpy(dmrambe, &dmr3ambe[0], 9); memcpy(dmrambe, &dmr3ambe[0], 9);
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 1)); frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 1, false));
// frame2 // frame2
memcpy(dmrambe, &dmr3ambe[9], 9); memcpy(dmrambe, &dmr3ambe[9], 9);
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 2)); frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 2, false));
// frame3 // frame3
memcpy(dmrambe, &dmr3ambe[18], 9); memcpy(dmrambe, &dmr3ambe[18], 9);
if ( uiPacketType == 3 ) if ( uiPacketType == 3 )
{ {
frames[2] = std::unique_ptr<CDvFramePacket>(new CDvLastFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3)); frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3, true));
} }
else else
{ {
frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3)); frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 3, false));
} }
// check // check

@ -19,10 +19,9 @@
#pragma once #pragma once
#include "Timer.h" #include "Timer.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// define // define

@ -52,7 +52,6 @@ void CDplusProtocol::Task(void)
CCallsign Callsign; CCallsign Callsign;
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvFramePacket> Frame; std::unique_ptr<CDvFramePacket> Frame;
std::unique_ptr<CDvLastFramePacket> LastFrame;
// handle incoming packets // handle incoming packets
#if DSTAR_IPV6==true #if DSTAR_IPV6==true
@ -79,10 +78,6 @@ void CDplusProtocol::Task(void)
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
} }
} }
else if ( IsValidDvLastFramePacket(Buffer, LastFrame) )
{
OnDvLastFramePacketIn(LastFrame, &Ip);
}
else if ( IsValidConnectPacket(Buffer) ) else if ( IsValidConnectPacket(Buffer) )
{ {
std::cout << "DPlus connect request packet from " << Ip << std::endl; std::cout << "DPlus connect request packet from " << Ip << std::endl;
@ -428,23 +423,13 @@ bool CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, std::unique_pt
bool CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe) bool CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe)
{ {
if ( 29==Buffer.size() && 0x1DU==Buffer.data()[0] && 0x80U==Buffer.data()[1] && 0==Buffer.Compare((uint8_t *)"DSVT", 2, 4) && 0x20U==Buffer.data()[6] && 0x20U==Buffer.data()[10] ) auto size = Buffer.size();
{ if ( (29==size || 32==size) && 0x1DU==Buffer.data()[0] && 0x80U==Buffer.data()[1] && 0==Buffer.Compare((uint8_t *)"DSVT", 2, 4) && 0x20U==Buffer.data()[6] && 0x20U==Buffer.data()[10] )
// create packet
dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDstarFrame *)&(Buffer.data()[17]), *((uint16_t *)&(Buffer.data()[14])), Buffer.data()[16]));
// check validity of packet
if ( dvframe && dvframe->IsValid() )
return true;
}
return false;
}
bool CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvLastFramePacket> &dvframe)
{
if ( 32==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 2, 4) && 0x20U==Buffer.data()[0] && 0x80U==Buffer.data()[1] && 0x20U==Buffer.data()[6] && 0x20U==Buffer.data()[10] )
{ {
// create packet if (32==size)
dvframe = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket((SDstarFrame *)&(Buffer.data()[17]), *((uint16_t *)&(Buffer.data()[14])), Buffer.data()[16])); dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDStarFrame *)&(Buffer.data()[17]), *((uint16_t *)&(Buffer.data()[14])), 0x40U | Buffer.data()[16]));
else
dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDStarFrame *)&(Buffer.data()[17]), *((uint16_t *)&(Buffer.data()[14])), Buffer.data()[16]));
// check validity of packet // check validity of packet
if ( dvframe && dvframe->IsValid() ) if ( dvframe && dvframe->IsValid() )
return true; return true;
@ -510,7 +495,7 @@ bool CDplusProtocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer *
} }
bool CDplusProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBuffer *Buffer) const bool CDplusProtocol::EncodeDvLastFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const
{ {
uint8_t tag1[] = { 0x20,0x80,0x44,0x53,0x56,0x54,0x20,0x00,0x81,0x00,0x20,0x00,0x01,0x02 }; uint8_t tag1[] = { 0x20,0x80,0x44,0x53,0x56,0x54,0x20,0x00,0x81,0x00,0x20,0x00,0x01,0x02 };
uint8_t tag2[] = { 0x55,0xC8,0x7A,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x25,0x1A,0xC6 }; uint8_t tag2[] = { 0x55,0xC8,0x7A,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x25,0x1A,0xC6 };

@ -22,7 +22,6 @@
#include "Protocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
class CDplusClient; class CDplusClient;
@ -62,7 +61,6 @@ protected:
bool IsValidKeepAlivePacket(const CBuffer &); bool IsValidKeepAlivePacket(const CBuffer &);
bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &); bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &);
bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &); bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvLastFramePacket> &);
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *); void EncodeKeepAlivePacket(CBuffer *);
@ -71,7 +69,7 @@ protected:
void EncodeDisconnectPacket(CBuffer *); void EncodeDisconnectPacket(CBuffer *);
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const;
bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const; bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const;
bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const; bool EncodeDvLastFramePacket(const CDvFramePacket &, CBuffer *) const;
protected: protected:

@ -50,8 +50,8 @@ CDvFramePacket::CDvFramePacket(const SDStarFrame *dvframe, uint16_t sid, uint8_t
// dmr constructor // dmr constructor
CDvFramePacket::CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t sid, uint8_t pid, uint8_t spid) CDvFramePacket::CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t sid, uint8_t pid, uint8_t spid, bool islast)
: CPacket(sid, pid, spid) : CPacket(sid, pid, spid, islast)
{ {
memcpy(m_TCPack.dmr, ambe, 9); memcpy(m_TCPack.dmr, ambe, 9);
memcpy(m_uiDvSync, sync, 7); memcpy(m_uiDvSync, sync, 7);
@ -64,8 +64,8 @@ CDvFramePacket::CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_
// ysf constructor // ysf constructor
CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, uint8_t spid, uint8_t fid) CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, uint8_t spid, uint8_t fid, bool islast)
: CPacket(sid, pid, spid, fid) : CPacket(sid, pid, spid, fid, islast)
{ {
memcpy(m_TCPack.dmr, ambe, 9); memcpy(m_TCPack.dmr, ambe, 9);
memset(m_uiDvSync, 0, 7); memset(m_uiDvSync, 0, 7);
@ -81,8 +81,23 @@ CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, u
CDvFramePacket::CDvFramePacket CDvFramePacket::CDvFramePacket
(uint16_t sid, (uint16_t sid,
uint8_t dstarpid, const uint8_t *dstarambe, const uint8_t *dstardvdata, uint8_t dstarpid, const uint8_t *dstarambe, const uint8_t *dstardvdata,
uint8_t dmrpid, uint8_t dprspid, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType codecInType, const uint8_t *codec2, const uint8_t * nonce) uint8_t dmrpid, uint8_t dprspid, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType codecInType, bool islast)
: CPacket(sid, dstarpid, dmrpid, dprspid, 0xFF, 0xFF, 0xFF, codecInType) : CPacket(sid, dstarpid, dmrpid, dprspid, 0xFF, 0xFF, 0xFF, codecInType, islast)
{
::memcpy(m_TCPack.dstar, dstarambe, 9);
::memcpy(m_uiDvData, dstardvdata, 3);
::memcpy(m_TCPack.dmr, dmrambe, 9);
::memcpy(m_uiDvSync, dmrsync, 7);
m_TCPack.codec_in = codecInType;
}
// urf constructor
CDvFramePacket::CDvFramePacket
(uint16_t sid,
uint8_t dstarpid, const uint8_t *dstarambe, const uint8_t *dstardvdata,
uint8_t dmrpid, uint8_t dprspid, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType codecInType, const uint8_t *codec2, const uint8_t * nonce, bool islast)
: CPacket(sid, dstarpid, dmrpid, dprspid, 0xFF, 0xFF, 0xFF, codecInType, islast)
{ {
memcpy(m_TCPack.dstar, dstarambe, 9); memcpy(m_TCPack.dstar, dstarambe, 9);
memcpy(m_uiDvData, dstardvdata, 3); memcpy(m_uiDvData, dstardvdata, 3);

@ -43,11 +43,13 @@ public:
// DStar frame // DStar frame
CDvFramePacket(const SDStarFrame *dstarframe, uint16_t streamid, uint8_t counter); CDvFramePacket(const SDStarFrame *dstarframe, uint16_t streamid, uint8_t counter);
// DMR Frame // DMR Frame
CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t streamid, uint8_t counter1, uint8_t counter2); CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t streamid, uint8_t counter1, uint8_t counter2, bool islast);
// YSF Frame // YSF Frame
CDvFramePacket(const uint8_t *ambe, uint16_t streamid, uint8_t counter1, uint8_t counter2, uint8_t counter3); CDvFramePacket(const uint8_t *ambe, uint16_t streamid, uint8_t counter1, uint8_t counter2, uint8_t counter3, bool islast);
// XLX Frame
CDvFramePacket(uint16_t streamid, uint8_t counter, const uint8_t *ambe, const uint8_t *dvdata, uint8_t counter1, uint8_t counter2, const uint8_t *ambe2, const uint8_t *dmrsync, ECodecType type, bool islast);
// URF Frame // URF Frame
CDvFramePacket(uint16_t streamid, uint8_t dstarcounter, const uint8_t *dstarambe, const uint8_t *dvdata, uint8_t dmrcounter1, uint8_t dmrcounter2, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType type, const uint8_t *m17codec, const uint8_t *nonce); CDvFramePacket(uint16_t streamid, uint8_t dstarcounter, const uint8_t *dstarambe, const uint8_t *dvdata, uint8_t dmrcounter1, uint8_t dmrcounter2, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType type, const uint8_t *m17codec, const uint8_t *nonce, bool islast);
CDvFramePacket(const CM17Packet &m17); CDvFramePacket(const CM17Packet &m17);
// virtual duplication // virtual duplication

@ -52,7 +52,7 @@ CDvHeaderPacket::CDvHeaderPacket(const struct dstar_header *buffer, uint16_t sid
// dmr constructor // dmr constructor
CDvHeaderPacket::CDvHeaderPacket(uint32_t my, const CCallsign &ur, const CCallsign &rpt1, const CCallsign &rpt2, uint16_t sid, uint8_t pid, uint8_t spid) CDvHeaderPacket::CDvHeaderPacket(uint32_t my, const CCallsign &ur, const CCallsign &rpt1, const CCallsign &rpt2, uint16_t sid, uint8_t pid, uint8_t spid)
: CPacket(sid, pid, spid) : CPacket(sid, pid, spid, false)
{ {
m_uiFlag1 = 0; m_uiFlag1 = 0;
m_uiFlag2 = 0; m_uiFlag2 = 0;

@ -1,67 +0,0 @@
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "Main.h"
#include "DVLastFramePacket.h"
// constructor
CDvLastFramePacket::CDvLastFramePacket()
{
}
// dstar constructor
CDvLastFramePacket::CDvLastFramePacket(const SDStarFrame *DvFrame, uint16_t sid, uint8_t pid)
: CDvFramePacket(DvFrame, sid, pid)
{
}
// dmr constructor
CDvLastFramePacket::CDvLastFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t sid, uint8_t pid, uint8_t spid)
: CDvFramePacket(ambe, sync, sid, pid, spid)
{
}
// ysf constructor
CDvLastFramePacket::CDvLastFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, uint8_t spid, uint8_t fid)
: CDvFramePacket(ambe, sid, pid, spid, fid)
{
}
// urf constructor
CDvLastFramePacket::CDvLastFramePacket
(uint16_t sid, uint8_t dstarpid, const uint8_t *dstarambe, const uint8_t *dstardvdata, uint8_t dmrpid, uint8_t dprspid, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType type, const uint8_t *codec2, const uint8_t *nonce)
: CDvFramePacket(sid, dstarpid, dstarambe, dstardvdata, dmrpid, dprspid, dmrambe, dmrsync, type, codec2, nonce)
{
}
// m17 constructor
CDvLastFramePacket::CDvLastFramePacket(const CM17Packet &m17) : CDvFramePacket(m17)
{
}
// copy constructor
CDvLastFramePacket::CDvLastFramePacket(const CDvLastFramePacket &DvFrame)
: CDvFramePacket(DvFrame)
{
}
// virtual duplication
std::unique_ptr<CPacket> CDvLastFramePacket::Duplicate(void) const
{
return std::unique_ptr<CPacket>(new CDvLastFramePacket(*this));
}

@ -1,54 +0,0 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "DVFramePacket.h"
////////////////////////////////////////////////////////////////////////////////////////
// defines
////////////////////////////////////////////////////////////////////////////////////////
// class
class CDvLastFramePacket : public CDvFramePacket
{
public:
// empty constructor
CDvLastFramePacket();
// DStar constructor
CDvLastFramePacket(const SDStarFrame *dvframe, uint16_t streamid, uint8_t counter);
// DRM constructor
CDvLastFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t streamid, uint8_t counter1, uint8_t counter2);
// YSF constructor
CDvLastFramePacket(const uint8_t *ambe, uint16_t streamid, uint8_t counter1, uint8_t counter2, uint8_t counter3);
// URF constructor
CDvLastFramePacket(uint16_t streamid, uint8_t dstarcounter, const uint8_t *dstarambe, const uint8_t *dvdata, uint8_t dmrcounter1, uint8_t dmrcounter2, const uint8_t *dmrambe, const uint8_t *dmrsync, ECodecType type, const uint8_t *codec2, const uint8_t *nonce);
// M17 constructor
CDvLastFramePacket(const CM17Packet &);
// copy constructor
CDvLastFramePacket(const CDvLastFramePacket &);
// virtual duplication
std::unique_ptr<CPacket> Duplicate(void) const;
// identity
bool IsLastPacket(void) const { return true; }
bool HasTranscodableData(void) const { return false; }
};

@ -372,7 +372,6 @@ void CG3Protocol::Task(void)
int ProtRev; int ProtRev;
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvFramePacket> Frame; std::unique_ptr<CDvFramePacket> Frame;
std::unique_ptr<CDvLastFramePacket> LastFrame;
// any incoming packet ? // any incoming packet ?
if ( m_Socket4.Receive(Buffer, Ip, 20) ) if ( m_Socket4.Receive(Buffer, Ip, 20) )
@ -413,10 +412,6 @@ void CG3Protocol::Task(void)
OnDvHeaderPacketIn(Header, *BaseIp); OnDvHeaderPacketIn(Header, *BaseIp);
} }
} }
else if ( IsValidDvLastFramePacket(Buffer, LastFrame) )
{
OnDvLastFramePacketIn(LastFrame, BaseIp);
}
} }
} }
@ -603,23 +598,10 @@ bool CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer, std::unique_ptr<C
bool CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe) bool CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe)
{ {
if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && 0U==(Buffer.data()[14] & 0x40U) ) if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] )
{
// create packet
dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDstarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14]));
// check validity of packet
if ( dvframe && dvframe->IsValid() )
return true;
}
return false;
}
bool CG3Protocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvLastFramePacket> &dvframe)
{
if ( 27==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && (Buffer.data()[14] & 0x40U) )
{ {
// create packet // create packet
dvframe = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket((SDstarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14])); dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket((SDStarFrame *)&(Buffer.data()[15]), *((uint16_t *)&(Buffer.data()[12])), Buffer.data()[14]));
// check validity of packet // check validity of packet
if ( dvframe && dvframe->IsValid() ) if ( dvframe && dvframe->IsValid() )
return true; return true;
@ -659,7 +641,7 @@ bool CG3Protocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer *Buf
} }
bool CG3Protocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBuffer *Buffer) const bool CG3Protocol::EncodeDvLastFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const
{ {
uint8_t tag1[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; uint8_t tag1[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 };
uint8_t tag2[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x1A,0xC6 }; uint8_t tag2[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x1A,0xC6 };

@ -20,10 +20,9 @@
#include <string> #include <string>
#include "Timer.h" #include "Timer.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
#include "RawSocket.h" #include "RawSocket.h"
#include "UDPMsgSocket.h" #include "UDPMsgSocket.h"
@ -98,12 +97,11 @@ protected:
// packet decoding helpers // packet decoding helpers
bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &); bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &);
bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &); bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvLastFramePacket> &);
// packet encoding helpers // packet encoding helpers
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const;
bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const; bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const;
bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const; bool EncodeDvLastFramePacket(const CDvFramePacket &, CBuffer *) const;
protected: protected:
std::future<void> m_PresenceFuture, m_ConfigFuture, m_IcmpFuture; std::future<void> m_PresenceFuture, m_ConfigFuture, m_IcmpFuture;

@ -73,16 +73,7 @@ void CM17Protocol::Task(void)
{ {
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
if ( !Frame->IsLastPacket() ) OnDvFramePacketIn((std::unique_ptr<CDvFramePacket> &)Frame, &Ip);
{
//std::cout << "M17 DV frame" << std::endl;
OnDvFramePacketIn(Frame, &Ip);
}
else
{
//std::cout << "M17 DV last frame" << std::endl;
OnDvLastFramePacketIn((std::unique_ptr<CDvLastFramePacket> &)Frame, &Ip);
}
} }
} }
else if ( IsValidConnectPacket(Buffer, Callsign, ToLinkModule) ) else if ( IsValidConnectPacket(Buffer, Callsign, ToLinkModule) )
@ -373,16 +364,7 @@ bool CM17Protocol::IsValidDvPacket(const CBuffer &Buffer, std::unique_ptr<CDvHea
header = std::unique_ptr<CDvHeaderPacket>(new CDvHeaderPacket(m17)); header = std::unique_ptr<CDvHeaderPacket>(new CDvHeaderPacket(m17));
// get the frame // get the frame
if (m17.IsLastPacket())
{
// it's the last frame
frame = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket(m17));
}
else
{
// it's a regular DV frame
frame = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(m17)); frame = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(m17));
}
// check validity of packets // check validity of packets
if ( header && header->IsValid() && frame && frame->IsValid() ) if ( header && header->IsValid() && frame && frame->IsValid() )

@ -22,7 +22,6 @@
#include "Protocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
#include "M17CRC.h" #include "M17CRC.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -49,15 +49,19 @@
#define DMR_IPV4 true #define DMR_IPV4 true
#define YSF_IPV4 true #define YSF_IPV4 true
#define XLX_IPV4 true #define XLX_IPV4 true
#define M17_IPV4 true
#define URF_IPV4 true
#define DSTAR_IPV6 true #define DSTAR_IPV6 true
#define DMR_IPV6 false #define DMR_IPV6 false
#define YSF_IPV6 false #define YSF_IPV6 false
#define XLX_IPV6 false #define XLX_IPV6 false
#define M17_IPV6 true
#define URF_IPV6 true
// version ----------------------------------------------------- // version -----------------------------------------------------
#define VERSION_MAJOR 17 #define VERSION_MAJOR 1
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 0 #define VERSION_REVISION 0
@ -73,9 +77,9 @@
// protocols --------------------------------------------------- // protocols ---------------------------------------------------
#ifndef NO_G3 #ifndef NO_G3
enum class EProtocol { any, none, dextra, dplus, dcs, ulx, dmrplus, dmrmmdvm, ysf, m17, g3 }; enum class EProtocol { any, none, dextra, dplus, dcs, xlx, urf, dmrplus, dmrmmdvm, ysf, m17, g3 };
#else #else
enum class EProtocol { any, none, dextra, dplus, dcs, xlx, dmrplus, dmrmmdvm, ysf, m17 }; enum class EProtocol { any, none, dextra, dplus, dcs, xlx, urf, dmrplus, dmrmmdvm, ysf, m17 };
#endif #endif
// DExtra // DExtra
@ -100,6 +104,12 @@ enum class EProtocol { any, none, dextra, dplus, dcs, xlx, dmrplus, dmrmmdvm, ys
#define XLX_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds #define XLX_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds
#define XLX_RECONNECT_PERIOD 5 // in seconds #define XLX_RECONNECT_PERIOD 5 // in seconds
// URF
#define URF_PORT 10017 // UDP port
#define URF_KEEPALIVE_PERIOD 1 // in seconds
#define URF_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds
#define URF_RECONNECT_PERIOD 5 // in seconds
// DMRPlus (dongle) // DMRPlus (dongle)
#define DMRPLUS_PORT 8880 // UDP port #define DMRPLUS_PORT 8880 // UDP port
#define DMRPLUS_KEEPALIVE_PERIOD 1 // in seconds #define DMRPLUS_KEEPALIVE_PERIOD 1 // in seconds

@ -37,6 +37,7 @@ CPacket::CPacket()
m_cModule = ' '; m_cModule = ' ';
m_uiOriginId = ORIGIN_LOCAL; m_uiOriginId = ORIGIN_LOCAL;
m_eCodecIn = ECodecType::none; m_eCodecIn = ECodecType::none;
m_bLastPacket = false;
}; };
// dstar contrsuctor // dstar contrsuctor
@ -54,11 +55,12 @@ CPacket::CPacket(uint16_t sid, uint8_t dstarpid)
m_cModule = ' '; m_cModule = ' ';
m_uiOriginId = ORIGIN_LOCAL; m_uiOriginId = ORIGIN_LOCAL;
m_eCodecIn = ECodecType::dstar; m_eCodecIn = ECodecType::dstar;
m_bLastPacket = (0x40U == (dstarpid & 0x40U));
}; };
// dmr constructor // dmr constructor
CPacket::CPacket(uint16_t sid, uint8_t dmrpid, uint8_t dmrspid) CPacket::CPacket(uint16_t sid, uint8_t dmrpid, uint8_t dmrspid, bool lastpacket)
{ {
m_uiStreamId = sid; m_uiStreamId = sid;
m_uiDmrPacketId = dmrpid; m_uiDmrPacketId = dmrpid;
@ -71,11 +73,12 @@ CPacket::CPacket(uint16_t sid, uint8_t dmrpid, uint8_t dmrspid)
m_cModule = ' '; m_cModule = ' ';
m_uiOriginId = ORIGIN_LOCAL; m_uiOriginId = ORIGIN_LOCAL;
m_eCodecIn = ECodecType::dmr; m_eCodecIn = ECodecType::dmr;
m_bLastPacket = lastpacket;
}; };
// ysf constructor // ysf constructor
CPacket::CPacket(uint16_t sid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysffrid) CPacket::CPacket(uint16_t sid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysffrid, bool lastpacket)
{ {
m_uiStreamId = sid; m_uiStreamId = sid;
m_uiYsfPacketId = ysfpid; m_uiYsfPacketId = ysfpid;
@ -88,11 +91,12 @@ CPacket::CPacket(uint16_t sid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysffri
m_cModule = ' '; m_cModule = ' ';
m_uiOriginId = ORIGIN_LOCAL; m_uiOriginId = ORIGIN_LOCAL;
m_eCodecIn = ECodecType::dmr; m_eCodecIn = ECodecType::dmr;
m_bLastPacket = lastpacket;
} }
// xlx constructor // xlx constructor
CPacket::CPacket(uint16_t sid, uint8_t dstarpid, uint8_t dmrpid, uint8_t dmrsubpid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysffrid, ECodecType codecIn) CPacket::CPacket(uint16_t sid, uint8_t dstarpid, uint8_t dmrpid, uint8_t dmrsubpid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysffrid, ECodecType codecIn, bool lastpacket)
{ {
m_uiStreamId = sid; m_uiStreamId = sid;
m_uiDstarPacketId = dstarpid; m_uiDstarPacketId = dstarpid;
@ -105,6 +109,7 @@ CPacket::CPacket(uint16_t sid, uint8_t dstarpid, uint8_t dmrpid, uint8_t dmrsubp
m_cModule = ' '; m_cModule = ' ';
m_uiOriginId = ORIGIN_LOCAL; m_uiOriginId = ORIGIN_LOCAL;
m_eCodecIn = codecIn; m_eCodecIn = codecIn;
m_bLastPacket = lastpacket;
} }
// m17 constructor // m17 constructor
@ -120,6 +125,7 @@ CPacket::CPacket(const CM17Packet &m17) : CPacket()
m_uiYsfPacketFrameId = 0xFF; m_uiYsfPacketFrameId = 0xFF;
m_eCodecIn = (0x6U == (0x6U & m17.GetFrameType())) ? ECodecType::c2_1600 : ECodecType::c2_3200; m_eCodecIn = (0x6U == (0x6U & m17.GetFrameType())) ? ECodecType::c2_1600 : ECodecType::c2_3200;
m_uiM17FrameNumber = 0x7FFFU & m17.GetFrameNumber(); m_uiM17FrameNumber = 0x7FFFU & m17.GetFrameNumber();
m_bLastPacket = m17.IsLastPacket();
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -32,9 +32,9 @@ public:
// constructor // constructor
CPacket(); CPacket();
CPacket(uint16_t sid, uint8_t dstarpid); CPacket(uint16_t sid, uint8_t dstarpid);
CPacket(uint16_t sid, uint8_t dmrpid, uint8_t dmrsubpid); CPacket(uint16_t sid, uint8_t dmrpid, uint8_t dmrsubpid, bool lastpacket);
CPacket(uint16_t sid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysfsubpidmax); CPacket(uint16_t sid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysfsubpidmax, bool lastpacket);
CPacket(uint16_t sid, uint8_t dstarpid, uint8_t dmrpid, uint8_t dmrsubpid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysfsubpidmax, ECodecType); CPacket(uint16_t sid, uint8_t dstarpid, uint8_t dmrpid, uint8_t dmrsubpid, uint8_t ysfpid, uint8_t ysfsubpid, uint8_t ysfsubpidmax, ECodecType, bool lastpacket);
CPacket(const CM17Packet &); CPacket(const CM17Packet &);
// destructor // destructor
@ -46,8 +46,8 @@ public:
// identity // identity
virtual bool IsDvHeader(void) const { return false; } virtual bool IsDvHeader(void) const { return false; }
virtual bool IsDvFrame(void) const { return false; } virtual bool IsDvFrame(void) const { return false; }
virtual bool IsLastPacket(void) const { return false; }
virtual bool HasTranscodableData(void) const { return false; } virtual bool HasTranscodableData(void) const { return false; }
bool IsLastPacket(void) const { return m_bLastPacket; }
// get // get
virtual bool IsValid(void) const { return true; } virtual bool IsValid(void) const { return true; }
@ -72,6 +72,9 @@ public:
protected: protected:
// data // data
ECodecType m_eCodecIn;
bool m_bLastPacket;
char m_cModule;
uint16_t m_uiStreamId; uint16_t m_uiStreamId;
uint16_t m_uiM17FrameNumber; uint16_t m_uiM17FrameNumber;
uint8_t m_uiDstarPacketId; uint8_t m_uiDstarPacketId;
@ -80,7 +83,5 @@ protected:
uint8_t m_uiYsfPacketId; uint8_t m_uiYsfPacketId;
uint8_t m_uiYsfPacketSubId; uint8_t m_uiYsfPacketSubId;
uint8_t m_uiYsfPacketFrameId; uint8_t m_uiYsfPacketFrameId;
char m_cModule;
uint8_t m_uiOriginId; uint8_t m_uiOriginId;
ECodecType m_eCodecIn;
}; };

@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Main.h" #include "Main.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "Clients.h" #include "Clients.h"
#include "Reflector.h" #include "Reflector.h"
@ -130,12 +130,8 @@ void CProtocol::Close(void)
bool CProtocol::EncodeDvPacket(const CPacket &packet, CBuffer *buffer) const bool CProtocol::EncodeDvPacket(const CPacket &packet, CBuffer *buffer) const
{ {
if ( packet.IsDvFrame() ) if ( packet.IsDvFrame() )
{
if ( packet.IsLastPacket() )
return EncodeDvLastFramePacket((CDvLastFramePacket &)packet, buffer);
else
return EncodeDvFramePacket((CDvFramePacket &)packet, buffer); return EncodeDvFramePacket((CDvFramePacket &)packet, buffer);
}
if ( packet.IsDvHeader() ) if ( packet.IsDvHeader() )
return EncodeDvHeaderPacket((CDvHeaderPacket &)packet, buffer); return EncodeDvHeaderPacket((CDvHeaderPacket &)packet, buffer);
@ -158,34 +154,11 @@ void CProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &Frame, const
stream->Push(std::move(Frame)); stream->Push(std::move(Frame));
stream->Unlock(); stream->Unlock();
} }
// else else
// {
// std::cout << "Orphaned Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl;
// }
}
void CProtocol::OnDvLastFramePacketIn(std::unique_ptr<CDvLastFramePacket> &Frame, const CIp *Ip)
{
// find the stream
auto stream = GetStream(Frame->GetStreamId(), Ip);
if ( stream )
{ {
// push std::cout << "Orphaned Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl;
stream->Lock(); Frame.reset();
stream->Push(std::move(Frame));
stream->Unlock();
// Don't close yet, this stops the last packet relfection bug that was fixed in upstream by the same change.
// Don't close the stream yet but rely on CheckStreamsTimeout
// mechanism, so the stream will be closed after the queues have
// been sinked out. This avoid last packets to be send back
// to transmitting client (master)
} }
// else
// {
// std::cout << "Orphaned Last Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl;
// }
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -22,7 +22,6 @@
#include "PacketStream.h" #include "PacketStream.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -88,12 +87,10 @@ protected:
virtual bool EncodeDvPacket(const CPacket &, CBuffer *) const; virtual bool EncodeDvPacket(const CPacket &, CBuffer *) const;
virtual bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const { return false; } virtual bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const { return false; }
virtual bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const { return false; } virtual bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const { return false; }
virtual bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const { return false; }
// stream helpers // stream helpers
virtual void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &) {} virtual void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &) {}
virtual void OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr); virtual void OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr);
virtual void OnDvLastFramePacketIn(std::unique_ptr<CDvLastFramePacket> &, const CIp * = nullptr);
// stream handle helpers // stream handle helpers
std::shared_ptr<CPacketStream> GetStream(uint16_t, const CIp * = nullptr); std::shared_ptr<CPacketStream> GetStream(uint16_t, const CIp * = nullptr);

@ -24,6 +24,7 @@
#include "DMRPlusProtocol.h" #include "DMRPlusProtocol.h"
#include "DMRMMDVMProtocol.h" #include "DMRMMDVMProtocol.h"
#include "YSFProtocol.h" #include "YSFProtocol.h"
#include "M17Protocol.h"
#ifndef NO_G3 #ifndef NO_G3
#include "G3Protocol.h" #include "G3Protocol.h"
#endif #endif
@ -69,7 +70,11 @@ bool CProtocols::Init(void)
return false; return false;
m_Protocols.emplace_back(std::unique_ptr<CURFProtocol>(new CURFProtocol)); m_Protocols.emplace_back(std::unique_ptr<CURFProtocol>(new CURFProtocol));
if (! m_Protocols.back()->Initialize("XLX", EProtocol::ulx, XLX_PORT, DMR_IPV4, DMR_IPV6)) if (! m_Protocols.back()->Initialize("URF", EProtocol::urf, URF_PORT, URF_IPV4, URF_IPV6))
return false;
m_Protocols.emplace_back(std::unique_ptr<CM17Protocol>(new CM17Protocol));
if (! m_Protocols.back()->Initialize("URF", EProtocol::m17, M17_PORT, M17_IPV4, M17_IPV6))
return false; return false;
#ifndef NO_G3 #ifndef NO_G3

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "DCSProtocol.h" #include "Protocol.h"
class CProtocols class CProtocols
{ {

@ -0,0 +1,50 @@
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include <string.h>
#include "Main.h"
#include "URFClient.h"
////////////////////////////////////////////////////////////////////////////////////////
// constructors
CURFClient::CURFClient()
{
m_ProtRev = EProtoRev::original;
}
CURFClient::CURFClient(const CCallsign &callsign, const CIp &ip, char reflectorModule, EProtoRev protRev)
: CClient(callsign, ip, reflectorModule)
{
m_ProtRev = protRev;
}
CURFClient::CURFClient(const CURFClient &client)
: CClient(client)
{
m_ProtRev = client.m_ProtRev;
}
////////////////////////////////////////////////////////////////////////////////////////
// status
bool CURFClient::IsAlive(void) const
{
return (m_LastKeepaliveTime.time() < URF_KEEPALIVE_TIMEOUT);
}

@ -0,0 +1,53 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "Client.h"
enum class EURFProtocol { original };
class CURFClient : public CClient
{
public:
// constructors
CURFClient();
CURFClient(const CCallsign &, const CIp &, char = ' ', EProtoRev = EProtoRev::original);
CURFClient(const CURFClient &);
// destructor
virtual ~CURFClient() {};
// identity
EProtocol GetProtocol(void) const { return EProtocol::urf; }
EProtoRev GetProtocolRevision(void) const { return m_ProtRev; }
const char *GetProtocolName(void) const { return "URF"; }
ECodecType GetCodec(void) const { return ECodecType::none; };
bool IsPeer(void) const { return true; }
// status
bool IsAlive(void) const;
// reporting
void WriteXml(std::ofstream &) {}
protected:
// data
EProtoRev m_ProtRev;
};

@ -0,0 +1,63 @@
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "Main.h"
#include <string.h>
#include "Reflector.h"
#include "URFPeer.h"
#include "URFClient.h"
////////////////////////////////////////////////////////////////////////////////////////
// constructor
CURFPeer::CURFPeer()
{
}
CURFPeer::CURFPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version)
: CPeer(callsign, ip, modules, version)
{
// get protocol revision
EProtoRev protrev = GetProtocolRevision(version);
//std::cout << "Adding XLX peer with protocol revision " << protrev << std::endl;
// and construct all xlx clients
for ( unsigned i = 0; i < ::strlen(modules); i++ )
{
// create and append to vector
m_Clients.push_back(std::make_shared<CURFClient>(callsign, ip, modules[i], protrev));
}
}
////////////////////////////////////////////////////////////////////////////////////////
// status
bool CURFPeer::IsAlive(void) const
{
return (m_LastKeepaliveTime.time() < URF_KEEPALIVE_TIMEOUT);
}
////////////////////////////////////////////////////////////////////////////////////////
// revision helper
EProtoRev CURFPeer::GetProtocolRevision(const CVersion &/*version*/)
{
return EProtoRev::urf;
}

@ -0,0 +1,48 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "Peer.h"
#include "URFClient.h"
////////////////////////////////////////////////////////////////////////////////////////
// define
////////////////////////////////////////////////////////////////////////////////////////
// class
class CURFPeer : public CPeer
{
public:
// constructors
CURFPeer();
CURFPeer(const CCallsign &, const CIp &, const char *, const CVersion &);
CURFPeer(const CURFPeer &) = delete;
// status
bool IsAlive(void) const;
// identity
EProtocol GetProtocol(void) const { return EProtocol::urf; }
const char *GetProtocolName(void) const { return "URF"; }
// revision helper
static EProtoRev GetProtocolRevision(const CVersion &);
};

@ -0,0 +1,577 @@
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include <cstring>
#include "Main.h"
#include "URFPeer.h"
#include "URFProtocol.h"
#include "Reflector.h"
#include "GateKeeper.h"
////////////////////////////////////////////////////////////////////////////////////////
// operation
bool CURFProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6)
{
if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6))
return false;
// update time
m_LastKeepaliveTime.start();
m_LastPeersLinkTime.start();
// done
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
// task
void CURFProtocol::Task(void)
{
CBuffer Buffer;
CIp Ip;
CCallsign Callsign;
char Modules[27];
CVersion Version;
std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvFramePacket> Frame;
std::unique_ptr<CDvFramePacket> LastFrame;
// any incoming packet ?
#if XLX_IPV6==true
#if XLX_IPV4==true
if ( ReceiveDS(Buffer, Ip, 20) )
#else
if ( Receive6(Buffer, Ip, 20) )
#endif
#else
if ( Receive4(Buffer, Ip, 20) )
#endif
{
// crack the packet
if ( IsValidDvFramePacket(Buffer, Frame) )
{
OnDvFramePacketIn(Frame, &Ip);
}
else if ( IsValidDvHeaderPacket(Buffer, Header) )
{
// callsign allowed?
if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip) )
{
OnDvHeaderPacketIn(Header, Ip);
}
}
else if ( IsValidConnectPacket(Buffer, &Callsign, Modules, &Version) )
{
std::cout << "XLX (" << Version.GetMajor() << "." << Version.GetMinor() << "." << Version.GetRevision() << ") connect packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
// callsign authorized?
if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::urf, Modules) )
{
// acknowledge connecting request
// following is version dependent
if (EProtoRev::urf == CURFPeer::GetProtocolRevision(Version))
{
// already connected ?
CPeers *peers = g_Reflector.GetPeers();
if ( peers->FindPeer(Callsign, Ip, EProtocol::xlx) == nullptr )
{
// acknowledge the request
EncodeConnectAckPacket(&Buffer, Modules);
Send(Buffer, Ip);
}
g_Reflector.ReleasePeers();
}
else
{
EncodeConnectNackPacket(&Buffer);
Send(Buffer, Ip);
}
}
else
{
// deny the request
EncodeConnectNackPacket(&Buffer);
Send(Buffer, Ip);
}
}
else if ( IsValidAckPacket(Buffer, &Callsign, Modules, &Version) )
{
std::cout << "XLX ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
// callsign authorized?
if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::xlx, Modules) )
{
// already connected ?
CPeers *peers = g_Reflector.GetPeers();
if ( peers->FindPeer(Callsign, Ip, EProtocol::xlx) == nullptr )
{
// create the new peer
// this also create one client per module
std::shared_ptr<CPeer>peer = std::make_shared<CURFPeer>(Callsign, Ip, Modules, Version);
// append the peer to reflector peer list
// this also add all new clients to reflector client list
peers->AddPeer(peer);
}
g_Reflector.ReleasePeers();
}
}
else if ( IsValidDisconnectPacket(Buffer, &Callsign) )
{
std::cout << "XLX disconnect packet from " << Callsign << " at " << Ip << std::endl;
// find peer
CPeers *peers = g_Reflector.GetPeers();
std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::xlx);
if ( peer != nullptr )
{
// remove it from reflector peer list
// this also remove all concerned clients from reflector client list
// and delete them
peers->RemovePeer(peer);
}
g_Reflector.ReleasePeers();
}
else if ( IsValidNackPacket(Buffer, &Callsign) )
{
std::cout << "XLX nack packet from " << Callsign << " at " << Ip << std::endl;
}
else if ( IsValidKeepAlivePacket(Buffer, &Callsign) )
{
//std::cout << "XLX keepalive packet from " << Callsign << " at " << Ip << std::endl;
// find peer
CPeers *peers = g_Reflector.GetPeers();
std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::xlx);
if ( peer != nullptr )
{
// keep it alive
peer->Alive();
}
g_Reflector.ReleasePeers();
}
else
{
std::string title("Unknown XLX packet from ");
title += Ip.GetAddress();
Buffer.Dump(title);
}
}
// handle end of streaming timeout
CheckStreamsTimeout();
// handle queue from reflector
HandleQueue();
// keep alive
if ( m_LastKeepaliveTime.time() > URF_KEEPALIVE_PERIOD )
{
// handle keep alives
HandleKeepalives();
// update time
m_LastKeepaliveTime.start();
}
// peer connections
if ( m_LastPeersLinkTime.time() > URF_RECONNECT_PERIOD )
{
// handle remote peers connections
HandlePeerLinks();
// update time
m_LastPeersLinkTime.start();
}
}
////////////////////////////////////////////////////////////////////////////////////////
// queue helper
void CURFProtocol::HandleQueue(void)
{
m_Queue.Lock();
while ( !m_Queue.empty() )
{
// get the packet
auto packet = m_Queue.pop();
// check if origin of packet is local
// if not, do not stream it out as it will cause
// network loop between linked XLX peers
if ( packet->IsLocalOrigin() )
{
// encode it
CBuffer buffer;
if ( EncodeDvPacket(*packet, &buffer) )
{
// and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients();
auto it = clients->begin();
std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(EProtocol::xlx, it)) != nullptr )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModule()) )
{
// no, send the packet
// this is protocol revision dependent
if (EProtoRev::urf == client->GetProtocolRevision())
{
Send(buffer, client->GetIp());
}
}
}
g_Reflector.ReleaseClients();
}
}
}
m_Queue.Unlock();
}
////////////////////////////////////////////////////////////////////////////////////////
// keepalive helpers
void CURFProtocol::HandleKeepalives(void)
{
// DExtra protocol sends and monitors keepalives packets
// event if the client is currently streaming
// so, send keepalives to all
CBuffer keepalive;
EncodeKeepAlivePacket(&keepalive);
// iterate on peers
CPeers *peers = g_Reflector.GetPeers();
auto pit = peers->begin();
std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(EProtocol::xlx, pit)) != nullptr )
{
// send keepalive
Send(keepalive, peer->GetIp());
// client busy ?
if ( peer->IsAMaster() )
{
// yes, just tickle it
peer->Alive();
}
// otherwise check if still with us
else if ( !peer->IsAlive() )
{
// no, disconnect
CBuffer disconnect;
EncodeDisconnectPacket(&disconnect);
Send(disconnect, peer->GetIp());
// remove it
std::cout << "XLX peer " << peer->GetCallsign() << " keepalive timeout" << std::endl;
peers->RemovePeer(peer);
}
}
g_Reflector.ReleasePeers();
}
////////////////////////////////////////////////////////////////////////////////////////
// Peers helpers
void CURFProtocol::HandlePeerLinks(void)
{
CBuffer buffer;
// get the list of peers
CPeerCallsignList *list = g_GateKeeper.GetPeerList();
CPeers *peers = g_Reflector.GetPeers();
// check if all our connected peers are still listed by gatekeeper
// if not, disconnect
auto pit = peers->begin();
std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(EProtocol::xlx, pit)) != nullptr )
{
if ( list->FindListItem(peer->GetCallsign()) == nullptr )
{
// send disconnect packet
EncodeDisconnectPacket(&buffer);
Send(buffer, peer->GetIp());
std::cout << "Sending disconnect packet to XLX peer " << peer->GetCallsign() << std::endl;
// remove client
peers->RemovePeer(peer);
}
}
// check if all ours peers listed by gatekeeper are connected
// if not, connect or reconnect
for ( auto it=list->begin(); it!=list->end(); it++ )
{
if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue;
if ( peers->FindPeer((*it).GetCallsign(), EProtocol::xlx) == nullptr )
{
// resolve again peer's IP in case it's a dynamic IP
(*it).ResolveIp();
// send connect packet to re-initiate peer link
EncodeConnectPacket(&buffer, (*it).GetModules());
Send(buffer, (*it).GetIp(), URF_PORT);
std::cout << "Sending connect packet to XLX peer " << (*it).GetCallsign() << " @ " << (*it).GetIp() << " for modules " << (*it).GetModules() << std::endl;
}
}
// done
g_Reflector.ReleasePeers();
g_GateKeeper.ReleasePeerList();
}
////////////////////////////////////////////////////////////////////////////////////////
// streams helpers
void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, const CIp &Ip)
{
CCallsign peer;
// todo: verify Packet.GetModuleId() is in authorized list of XLX of origin
// todo: do the same for DVFrame and DVLAstFrame packets
// tag packet as remote peer origin
Header->SetRemotePeerOrigin();
// find the stream
auto stream = GetStream(Header->GetStreamId());
if ( stream )
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
else
{
CCallsign my(Header->GetMyCallsign());
CCallsign rpt1(Header->GetRpt1Callsign());
CCallsign rpt2(Header->GetRpt2Callsign());
// no stream open yet, open a new one
// find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, EProtocol::xlx, Header->GetRpt2Module());
if ( client )
{
// and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
{
// keep the handle
m_Streams.push_back(stream);
}
// get origin
peer = client->GetCallsign();
}
// release
g_Reflector.ReleaseClients();
// update last heard
g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2, peer);
g_Reflector.ReleaseUsers();
}
}
void CURFProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, const CIp *Ip)
{
// tag packet as remote peer origin
DvFrame->SetRemotePeerOrigin();
// and call base class
OnDvFramePacketIn(DvFrame, Ip);
}
////////////////////////////////////////////////////////////////////////////////////////
// packet decoding helpers
bool CURFProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *callsign)
{
bool valid = false;
if (Buffer.size() == 9)
{
callsign->SetCallsign(Buffer.data(), 8);
valid = callsign->IsValid();
}
return valid;
}
bool CURFProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version)
{
bool valid = false;
uint8_t magic[] = { 'C','O','N','N' };
if ((Buffer.size() == 40) && (0 == Buffer.Compare(magic, 4)) && (Buffer.data()[36] == 0))
{
callsign->CodeIn(Buffer.data()+4);
valid = callsign->IsValid();
*version = CVersion(Buffer.at(37), Buffer.at(38), Buffer.at(39));
memcpy(modules, Buffer.data()+10, 27);
for ( unsigned i = 0; i < ::strlen(modules), valid; i++ )
{
valid &= (nullptr != strchr(ACTIVE_MODULES, modules[i]));
}
}
return valid;
}
bool CURFProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign *callsign)
{
bool valid = false;
uint8_t magic[] = { 'D','I','S','C' };
if ((Buffer.size() == 10) && (0 == Buffer.Compare(magic, 4)))
{
callsign->CodeIn(Buffer.data()+4);
valid = callsign->IsValid();
}
return valid;
}
bool CURFProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version)
{
bool valid = false;
uint8_t magic[] = { 'A','C','K','N' };
if ((Buffer.size() == 40) && (0 == Buffer.Compare(magic, 4)) && (Buffer.data()[36] == 0))
{
callsign->CodeIn(Buffer.data()+4);
valid = callsign->IsValid();
*version = CVersion(Buffer.at(37), Buffer.at(38), Buffer.at(39));
memcpy(modules, Buffer.data()+10, 27);
for ( unsigned i = 0; i < ::strlen(modules), valid; i++ )
{
valid &= (nullptr != strchr(ACTIVE_MODULES, modules[i]));
}
}
return valid;
}
bool CURFProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign)
{
bool valid = false;
uint8_t magic[] = { 'N','A','C','K' };
if ((Buffer.size() == 10) && (0 == Buffer.Compare(magic, 4)))
{
callsign->CodeIn(Buffer.data()+4);
valid = callsign->IsValid();
}
return valid;
}
bool CURFProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, std::unique_ptr<CDvHeaderPacket> &header)
{
if (sizeof(CDvHeaderPacket) == Buffer.size()) {
header = std::unique_ptr<CDvHeaderPacket>(new CDvHeaderPacket());
memcpy(header.get(), Buffer.data(), sizeof(CDvHeaderPacket));
if (header) {
if (header->IsValid())
return true;
else
header.reset();
}
}
return false;
}
bool CURFProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe)
{
// otherwise try protocol revision 2
if (sizeof(CDvFramePacket)==Buffer.size())
{
// create packet
dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket());
memcpy(dvframe.get(), Buffer.data(), sizeof(CDvFramePacket));
// check validity of packet
if (dvframe) {
if (dvframe->IsValid())
return true;
else
dvframe.reset();
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////////////
// packet encoding helpers
bool CURFProtocol::EncodeDvHeaderPacket(const CDvHeaderPacket &packet, CBuffer *buffer) const
{
auto len = sizeof(CDvHeaderPacket);
buffer->resize(len);
memcpy(buffer->data(), &packet, len);
return true;
}
bool CURFProtocol::EncodeDvFramePacket(const CDvFramePacket &packet, CBuffer *buffer) const
{
auto len = sizeof(CDvFramePacket);
buffer->resize(len);
memcpy(buffer->data(), &packet, len);
return true;
}
void CURFProtocol::EncodeKeepAlivePacket(CBuffer *Buffer)
{
Buffer->Set("PING");
Buffer->resize(10);
g_Reflector.GetCallsign().CodeOut(Buffer->data()+4);
}
void CURFProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules)
{
// tag
Buffer->Set("CONN");
// our callsign
Buffer->resize(37);
g_Reflector.GetCallsign().CodeOut(Buffer->data()+4);
// our version
Buffer->ReplaceAt(10, (uint8_t *)Modules, strlen(Modules));
Buffer->Append((uint8_t)VERSION_MAJOR);
Buffer->Append((uint8_t)VERSION_MINOR);
Buffer->Append((uint8_t)VERSION_REVISION);
}
void CURFProtocol::EncodeDisconnectPacket(CBuffer *Buffer)
{
Buffer->Set("DISC");
// our callsign
Buffer->resize(10);
g_Reflector.GetCallsign().CodeOut(Buffer->data()+4);
}
void CURFProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules)
{
Buffer->Set("ACKN");
// our callsign
Buffer->resize(37);
g_Reflector.GetCallsign().CodeOut(Buffer->data()+4);
// the shared modules
Buffer->ReplaceAt(10, (uint8_t *)Modules, strlen(Modules));
// our version
Buffer->Append((uint8_t)VERSION_MAJOR);
Buffer->Append((uint8_t)VERSION_MINOR);
Buffer->Append((uint8_t)VERSION_REVISION);
}
void CURFProtocol::EncodeConnectNackPacket(CBuffer *Buffer)
{
Buffer->Set("NACK");
Buffer->resize(10);
g_Reflector.GetCallsign().CodeOut(Buffer->data()+4);
}

@ -0,0 +1,71 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
//
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#include "Version.h"
#include "Timer.h"
#include "Protocol.h"
#include "Clients.h"
class CPeer;
class CURFProtocol : public CProtocol
{
public:
// initialization
bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6);
// task
void Task(void);
protected:
// queue helper
void HandleQueue(void);
// keepalive helpers
void HandlePeerLinks(void);
void HandleKeepalives(void);
// stream helpers
void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &);
void OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr);
// packet decoding helpers
bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *);
bool IsValidConnectPacket(const CBuffer &, CCallsign *, char *, CVersion *);
bool IsValidDisconnectPacket(const CBuffer &, CCallsign *);
bool IsValidAckPacket(const CBuffer &, CCallsign *, char *, CVersion *);
bool IsValidNackPacket(const CBuffer &, CCallsign *);
bool IsValidDvHeaderPacket(const CBuffer &, std::unique_ptr<CDvHeaderPacket> &);
bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
// packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *);
void EncodeConnectPacket(CBuffer *, const char *);
void EncodeDisconnectPacket(CBuffer *);
void EncodeConnectAckPacket(CBuffer *, const char *);
void EncodeConnectNackPacket(CBuffer *Buffer);
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const;
bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const;
protected:
// time
CTimer m_LastKeepaliveTime;
CTimer m_LastPeersLinkTime;
};

@ -1,50 +1,77 @@
//
// cxlxclient.cpp
// xlxd
//
// Created by Jean-Luc Deltombe (LX3JL) on 28/01/2016.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
// //
// This program is free software: you can redistribute it and/or modify // ----------------------------------------------------------------------------
// This file is part of xlxd.
//
// xlxd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // xlxd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include <string.h> #include <string.h>
#include "Main.h" #include "Main.h"
#include "URFClient.h" #include "XLXClient.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// constructors // constructors
CURFClient::CURFClient() CXlxClient::CXlxClient()
{ {
m_ProtRev = EXLXProtocol::m17; m_ProtRev = EProtoRev::original;
} }
CURFClient::CURFClient(const CCallsign &callsign, const CIp &ip, char reflectorModule, EXLXProtocol protRev) CXlxClient::CXlxClient(const CCallsign &callsign, const CIp &ip, char reflectorModule, EProtoRev protRev)
: CClient(callsign, ip, reflectorModule) : CClient(callsign, ip, reflectorModule)
{ {
m_ProtRev = protRev; m_ProtRev = protRev;
} }
CURFClient::CURFClient(const CURFClient &client) CXlxClient::CXlxClient(const CXlxClient &client)
: CClient(client) : CClient(client)
{ {
m_ProtRev = client.m_ProtRev; m_ProtRev = client.m_ProtRev;
} }
////////////////////////////////////////////////////////////////////////////////////////
// identity
ECodecType CXlxClient::GetCodec(void) const
{
ECodecType codec;
switch ( GetProtocolRevision() )
{
case EProtoRev::original:
case EProtoRev::revised:
default:
codec = ECodecType::dstar;
break;
case EProtoRev::ambe:
codec = ECodecType::none;
break;
}
return codec;
}
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// status // status
bool CURFClient::IsAlive(void) const bool CXlxClient::IsAlive(void) const
{ {
return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT); return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT);
} }

@ -1,3 +1,5 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector // urfd -- The universal reflector
@ -16,26 +18,36 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Client.h" #include "Client.h"
class CURFClient : public CClient ////////////////////////////////////////////////////////////////////////////////////////
// define
#define XLX_PROTOCOL_REVISION_0 0 // AMBE only, original connect mechanism
#define XLX_PROTOCOL_REVISION_1 1 // AMBE only, revised connect mechanism
#define XLX_PROTOCOL_REVISION_2 2 // Transcoded AMBE+AMBE2 interlink
////////////////////////////////////////////////////////////////////////////////////////
// class
class CXlxClient : public CClient
{ {
public: public:
// constructors // constructors
CURFClient(); CXlxClient();
CURFClient(const CCallsign &, const CIp &, char = ' ', EXLXProtocol = EXLXProtocol::m17); CXlxClient(const CCallsign &, const CIp &, char = ' ', EProtoRev = EProtoRev::original);
CURFClient(const CURFClient &); CXlxClient(const CXlxClient &);
// destructor // destructor
virtual ~CURFClient() {}; virtual ~CXlxClient() {};
// identity // identity
EProtocol GetProtocol(void) const { return EProtocol::ulx; } EProtocol GetProtocol(void) const { return EProtocol::xlx; }
EXLXProtocol GetProtocolRevision(void) const { return m_ProtRev; } EProtoRev GetProtocolRevision(void) const { return m_ProtRev; }
const char *GetProtocolName(void) const { return "XLX"; } const char *GetProtocolName(void) const { return "XLX"; }
ECodecType GetCodec(void) const { return ECodecType::none; } ECodecType GetCodec(void) const;
bool IsPeer(void) const { return true; } bool IsPeer(void) const { return true; }
// status // status
@ -46,5 +58,5 @@ public:
protected: protected:
// data // data
EXLXProtocol m_ProtRev; EProtoRev m_ProtRev;
}; };

@ -1,4 +1,4 @@
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector // urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE // Copyright © 2021 Thomas A. Early N7TAE
@ -16,40 +16,41 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Main.h"
#include <string.h> #include <string.h>
#include "Main.h"
#include "Reflector.h" #include "Reflector.h"
#include "URFPeer.h" #include "XLXPeer.h"
#include "URFClient.h" #include "XLXClient.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// constructor // constructor
CURFPeer::CURFPeer() CXlxPeer::CXlxPeer()
{ {
} }
CURFPeer::CURFPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version) CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version)
: CPeer(callsign, ip, modules, version) : CPeer(callsign, ip, modules, version)
{ {
// get protocol revision // get protocol revision
int protrev = GetProtocolRevision(version); EProtoRev protrev = GetProtocolRevision(version);
//std::cout << "Adding XLX peer with protocol revision " << protrev << std::endl; //std::cout << "Adding XLX peer with protocol revision " << protrev << std::endl;
// and construct all xlx clients // and construct all xlx clients
for ( unsigned i = 0; i < ::strlen(modules); i++ ) for ( unsigned i = 0; i < ::strlen(modules); i++ )
{ {
// create and append to vector // create and append to vector
m_Clients.push_back(std::make_shared<CURFClient>(callsign, ip, modules[i], protrev)); m_Clients.push_back(std::make_shared<CXlxClient>(callsign, ip, modules[i], protrev));
} }
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// status // status
bool CURFPeer::IsAlive(void) const bool CXlxPeer::IsAlive(void) const
{ {
return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT); return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT);
} }
@ -57,17 +58,17 @@ bool CURFPeer::IsAlive(void) const
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// revision helper // revision helper
int CURFPeer::GetProtocolRevision(const CVersion &version) EProtoRev CXlxPeer::GetProtocolRevision(const CVersion &version)
{ {
int protrev = XLX_PROTOCOL_REVISION_0; EProtoRev protrev = EProtoRev::original;
if ( version.IsEqualOrHigherTo(CVersion(2,2,0)) ) if ( version.IsEqualOrHigherTo(CVersion(2,2,0)) )
{ {
protrev = XLX_PROTOCOL_REVISION_2; protrev = EProtoRev::ambe;
} }
else if ( version.IsEqualOrHigherTo(CVersion(1,4,0)) ) else if ( version.IsEqualOrHigherTo(CVersion(1,4,0)) )
{ {
protrev = XLX_PROTOCOL_REVISION_1; protrev = EProtoRev::revised;
} }
return protrev; return protrev;
} }

@ -1,4 +1,6 @@
/// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved. #pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector // urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE // Copyright © 2021 Thomas A. Early N7TAE
@ -16,26 +18,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Peer.h" #include "Peer.h"
#include "URFClient.h" #include "XLXClient.h"
class CURFPeer : public CPeer class CXlxPeer : public CPeer
{ {
public: public:
// constructors // constructors
CURFPeer(); CXlxPeer();
CURFPeer(const CCallsign &, const CIp &, const char *, const CVersion &); CXlxPeer(const CCallsign &, const CIp &, const char *, const CVersion &);
CURFPeer(const CURFPeer &) = delete; CXlxPeer(const CXlxPeer &) = delete;
// status // status
bool IsAlive(void) const; bool IsAlive(void) const;
// identity // identity
EProtocol GetProtocol(void) const { return EProtocol::ulx; } EProtocol GetProtocol(void) const { return EProtocol::xlx; }
const char *GetProtocolName(void) const { return "XLX"; } const char *GetProtocolName(void) const { return "XLX"; }
// revision helper // revision helper
static int GetProtocolRevision(const CVersion &); static EProtoRev GetProtocolRevision(const CVersion &);
}; };

@ -16,11 +16,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Main.h"
#include <string.h> #include <string.h>
#include "URFPeer.h"
#include "Main.h"
#include "XLXPeer.h"
#include "BMPeer.h" #include "BMPeer.h"
#include "URFProtocol.h" #include "XLXProtocol.h"
#include "Reflector.h" #include "Reflector.h"
#include "GateKeeper.h" #include "GateKeeper.h"
@ -28,7 +29,7 @@
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// operation // operation
bool CURFProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) bool CXlxProtocol::Initialize(const char *type, EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6)
{ {
if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6))
return false; return false;
@ -44,7 +45,7 @@ bool CURFProtocol::Initialize(const char *type, const EProtocol ptype, const uin
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// task // task
void CURFProtocol::Task(void) void CXlxProtocol::Task(void)
{ {
CBuffer Buffer; CBuffer Buffer;
CIp Ip; CIp Ip;
@ -53,7 +54,6 @@ void CURFProtocol::Task(void)
CVersion Version; CVersion Version;
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::unique_ptr<CDvFramePacket> Frame; std::unique_ptr<CDvFramePacket> Frame;
std::unique_ptr<CDvLastFramePacket> LastFrame;
// any incoming packet ? // any incoming packet ?
#if XLX_IPV6==true #if XLX_IPV6==true
@ -79,26 +79,26 @@ void CURFProtocol::Task(void)
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
} }
} }
else if ( IsValidDvLastFramePacket(Buffer, LastFrame) ) else if ( IsValidDvLastFramePacket(Buffer, Frame) )
{ {
OnDvLastFramePacketIn(LastFrame, &Ip); OnDvLastFramePacketIn(Frame, &Ip);
} }
else if ( IsValidConnectPacket(Buffer, &Callsign, Modules, &Version) ) else if ( IsValidConnectPacket(Buffer, &Callsign, Modules, &Version) )
{ {
std::cout << "XLX (" << Version.GetMajor() << "." << Version.GetMinor() << "." << Version.GetRevision() << ") connect packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl; std::cout << "XLX (" << Version.GetMajor() << "." << Version.GetMinor() << "." << Version.GetRevision() << ") connect packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
// callsign authorized? // callsign authorized?
if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::ulx, Modules) ) if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::xlx, Modules) )
{ {
// acknowledge connecting request // acknowledge connecting request
// following is version dependent // following is version dependent
switch ( GetConnectingPeerProtocolRevision(Callsign, Version) ) switch ( GetConnectingPeerProtocolRevision(Callsign, Version) )
{ {
case XLX_PROTOCOL_REVISION_0: case EProtoRev::original:
{ {
// already connected ? // already connected ?
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
if ( peers->FindPeer(Callsign, Ip, EProtocol::ulx) == nullptr ) if ( peers->FindPeer(Callsign, Ip, EProtocol::xlx) == nullptr )
{ {
// acknowledge the request // acknowledge the request
EncodeConnectAckPacket(&Buffer, Modules); EncodeConnectAckPacket(&Buffer, Modules);
@ -108,8 +108,8 @@ void CURFProtocol::Task(void)
} }
break; break;
case XLX_PROTOCOL_REVISION_1: case EProtoRev::revised:
case XLX_PROTOCOL_REVISION_2: case EProtoRev::ambe:
default: default:
// acknowledge the request // acknowledge the request
EncodeConnectAckPacket(&Buffer, Modules); EncodeConnectAckPacket(&Buffer, Modules);
@ -129,11 +129,11 @@ void CURFProtocol::Task(void)
std::cout << "XLX ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl; std::cout << "XLX ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
// callsign authorized? // callsign authorized?
if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::ulx, Modules) ) if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::xlx, Modules) )
{ {
// already connected ? // already connected ?
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
if ( peers->FindPeer(Callsign, Ip, EProtocol::ulx) == nullptr ) if ( peers->FindPeer(Callsign, Ip, EProtocol::xlx) == nullptr )
{ {
// create the new peer // create the new peer
// this also create one client per module // this also create one client per module
@ -152,7 +152,7 @@ void CURFProtocol::Task(void)
// find peer // find peer
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::ulx); std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::xlx);
if ( peer != nullptr ) if ( peer != nullptr )
{ {
// remove it from reflector peer list // remove it from reflector peer list
@ -172,7 +172,7 @@ void CURFProtocol::Task(void)
// find peer // find peer
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::ulx); std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, EProtocol::xlx);
if ( peer != nullptr ) if ( peer != nullptr )
{ {
// keep it alive // keep it alive
@ -218,7 +218,7 @@ void CURFProtocol::Task(void)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// queue helper // queue helper
void CURFProtocol::HandleQueue(void) void CXlxProtocol::HandleQueue(void)
{ {
m_Queue.Lock(); m_Queue.Lock();
while ( !m_Queue.empty() ) while ( !m_Queue.empty() )
@ -246,7 +246,7 @@ void CURFProtocol::HandleQueue(void)
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
std::shared_ptr<CClient>client = nullptr; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(EProtocol::ulx, it)) != nullptr ) while ( (client = clients->FindNextClient(EProtocol::xlx, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModule()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModule()) )
@ -255,13 +255,13 @@ void CURFProtocol::HandleQueue(void)
// this is protocol revision dependent // this is protocol revision dependent
switch ( client->GetProtocolRevision() ) switch ( client->GetProtocolRevision() )
{ {
case XLX_PROTOCOL_REVISION_0: case EProtoRev::original:
case XLX_PROTOCOL_REVISION_1: case EProtoRev::revised:
Send(bufferLegacy, client->GetIp()); Send(bufferLegacy, client->GetIp());
break; break;
case XLX_PROTOCOL_REVISION_2: case EProtoRev::ambe:
default: default:
#ifdef TRANSCODER_IP #ifdef TRANSCODED_MODULES
if ( g_Transcoder.IsConnected() ) if ( g_Transcoder.IsConnected() )
{ {
Send(buffer, client->GetIp()); Send(buffer, client->GetIp());
@ -285,7 +285,7 @@ void CURFProtocol::HandleQueue(void)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// keepalive helpers // keepalive helpers
void CURFProtocol::HandleKeepalives(void) void CXlxProtocol::HandleKeepalives(void)
{ {
// DExtra protocol sends and monitors keepalives packets // DExtra protocol sends and monitors keepalives packets
// event if the client is currently streaming // event if the client is currently streaming
@ -297,7 +297,7 @@ void CURFProtocol::HandleKeepalives(void)
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
auto pit = peers->begin(); auto pit = peers->begin();
std::shared_ptr<CPeer>peer = nullptr; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(EProtocol::ulx, pit)) != nullptr ) while ( (peer = peers->FindNextPeer(EProtocol::xlx, pit)) != nullptr )
{ {
// send keepalive // send keepalive
Send(keepalive, peer->GetIp()); Send(keepalive, peer->GetIp());
@ -327,7 +327,7 @@ void CURFProtocol::HandleKeepalives(void)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// Peers helpers // Peers helpers
void CURFProtocol::HandlePeerLinks(void) void CXlxProtocol::HandlePeerLinks(void)
{ {
CBuffer buffer; CBuffer buffer;
@ -339,7 +339,7 @@ void CURFProtocol::HandlePeerLinks(void)
// if not, disconnect // if not, disconnect
auto pit = peers->begin(); auto pit = peers->begin();
std::shared_ptr<CPeer>peer = nullptr; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(EProtocol::ulx, pit)) != nullptr ) while ( (peer = peers->FindNextPeer(EProtocol::xlx, pit)) != nullptr )
{ {
if ( list->FindListItem(peer->GetCallsign()) == nullptr ) if ( list->FindListItem(peer->GetCallsign()) == nullptr )
{ {
@ -358,7 +358,7 @@ void CURFProtocol::HandlePeerLinks(void)
{ {
if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue; continue;
if ( peers->FindPeer((*it).GetCallsign(), EProtocol::ulx) == nullptr ) if ( peers->FindPeer((*it).GetCallsign(), EProtocol::xlx) == nullptr )
{ {
// resolve again peer's IP in case it's a dynamic IP // resolve again peer's IP in case it's a dynamic IP
(*it).ResolveIp(); (*it).ResolveIp();
@ -378,7 +378,7 @@ void CURFProtocol::HandlePeerLinks(void)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// streams helpers // streams helpers
void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, const CIp &Ip) void CXlxProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, const CIp &Ip)
{ {
CCallsign peer; CCallsign peer;
@ -403,7 +403,7 @@ void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
CCallsign rpt2(Header->GetRpt2Callsign()); CCallsign rpt2(Header->GetRpt2Callsign());
// no stream open yet, open a new one // no stream open yet, open a new one
// find this client // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, EProtocol::ulx, Header->GetRpt2Module()); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, EProtocol::xlx, Header->GetRpt2Module());
if ( client ) if ( client )
{ {
// and try to open the stream // and try to open the stream
@ -423,7 +423,7 @@ void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
} }
} }
void CURFProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, const CIp *Ip) void CXlxProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, const CIp *Ip)
{ {
// tag packet as remote peer origin // tag packet as remote peer origin
DvFrame->SetRemotePeerOrigin(); DvFrame->SetRemotePeerOrigin();
@ -432,20 +432,20 @@ void CURFProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, c
CDextraProtocol::OnDvFramePacketIn(DvFrame, Ip); CDextraProtocol::OnDvFramePacketIn(DvFrame, Ip);
} }
void CURFProtocol::OnDvLastFramePacketIn(std::unique_ptr<CDvLastFramePacket> &DvFrame, const CIp *Ip) void CXlxProtocol::OnDvLastFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, const CIp *Ip)
{ {
// tag packet as remote peer origin // tag packet as remote peer origin
DvFrame->SetRemotePeerOrigin(); DvFrame->SetRemotePeerOrigin();
// anc call base class // anc call base class
CDextraProtocol::OnDvLastFramePacketIn(DvFrame, Ip); CDextraProtocol::OnDvFramePacketIn(DvFrame, Ip);
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// packet decoding helpers // packet decoding helpers
bool CURFProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *callsign) bool CXlxProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *callsign)
{ {
bool valid = false; bool valid = false;
if (Buffer.size() == 9) if (Buffer.size() == 9)
@ -457,7 +457,7 @@ bool CURFProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *call
} }
bool CURFProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version) bool CXlxProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version)
{ {
bool valid = false; bool valid = false;
if ((Buffer.size() == 39) && (Buffer.data()[0] == 'L') && (Buffer.data()[38] == 0)) if ((Buffer.size() == 39) && (Buffer.data()[0] == 'L') && (Buffer.data()[38] == 0))
@ -474,7 +474,7 @@ bool CURFProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsi
return valid; return valid;
} }
bool CURFProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign *callsign) bool CXlxProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign *callsign)
{ {
bool valid = false; bool valid = false;
if ((Buffer.size() == 10) && (Buffer.data()[0] == 'U') && (Buffer.data()[9] == 0)) if ((Buffer.size() == 10) && (Buffer.data()[0] == 'U') && (Buffer.data()[9] == 0))
@ -485,7 +485,7 @@ bool CURFProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign *cal
return valid; return valid;
} }
bool CURFProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version) bool CXlxProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, CVersion *version)
{ {
bool valid = false; bool valid = false;
if ((Buffer.size() == 39) && (Buffer.data()[0] == 'A') && (Buffer.data()[38] == 0)) if ((Buffer.size() == 39) && (Buffer.data()[0] == 'A') && (Buffer.data()[38] == 0))
@ -502,7 +502,7 @@ bool CURFProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign,
return valid; return valid;
} }
bool CURFProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign) bool CXlxProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign)
{ {
bool valid = false; bool valid = false;
if ((Buffer.size() == 10) && (Buffer.data()[0] == 'N') && (Buffer.data()[9] == 0)) if ((Buffer.size() == 10) && (Buffer.data()[0] == 'N') && (Buffer.data()[9] == 0))
@ -513,7 +513,7 @@ bool CURFProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign)
return valid; return valid;
} }
bool CURFProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe) bool CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe)
{ {
// base class first (protocol revision 1 and lower) // base class first (protocol revision 1 and lower)
if (CDextraProtocol::IsValidDvFramePacket(Buffer, dvframe)) if (CDextraProtocol::IsValidDvFramePacket(Buffer, dvframe))
@ -529,7 +529,8 @@ bool CURFProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<C
// dstar // dstar
Buffer.data()[14], &(Buffer.data()[15]), &(Buffer.data()[24]), Buffer.data()[14], &(Buffer.data()[15]), &(Buffer.data()[24]),
// dmr // dmr
Buffer.data()[27], Buffer.data()[28], &(Buffer.data()[29]), &(Buffer.data()[38]))); Buffer.data()[27], Buffer.data()[28], &(Buffer.data()[29]), &(Buffer.data()[38]),
ECodecType::dmr, false));
// check validity of packet // check validity of packet
if ( dvframe && dvframe->IsValid() ) if ( dvframe && dvframe->IsValid() )
@ -538,23 +539,24 @@ bool CURFProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::unique_ptr<C
return false; return false;
} }
bool CURFProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvLastFramePacket> &dvframe) bool CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &dvframe)
{ {
// base class first (protocol revision 1 and lower) // base class first (protocol revision 1 and lower)
if (CDextraProtocol::IsValidDvLastFramePacket(Buffer, dvframe)) if (CDextraProtocol::IsValidDvFramePacket(Buffer, dvframe))
return true; return true;
// otherwise try protocol revision 2 // otherwise try protocol revision 2
if ( 45==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && (Buffer.data()[14] & 0x40U) ) if ( 45==Buffer.size() && 0==Buffer.Compare((uint8_t *)"DSVT", 4) && 0x20U==Buffer.data()[4] && 0x20U==Buffer.data()[8] && (Buffer.data()[14] & 0x40U) )
{ {
// create packet // create packet
dvframe = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket( dvframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(
// sid // sid
*((uint16_t *)&(Buffer.data()[12])), *((uint16_t *)&(Buffer.data()[12])),
// dstar // dstar
Buffer.data()[14], &(Buffer.data()[15]), &(Buffer.data()[24]), Buffer.data()[14], &(Buffer.data()[15]), &(Buffer.data()[24]),
// dmr // dmr
Buffer.data()[27], Buffer.data()[28], &(Buffer.data()[29]), &(Buffer.data()[38]))); Buffer.data()[27], Buffer.data()[28], &(Buffer.data()[29]), &(Buffer.data()[38]),
ECodecType::dmr, true));
// check validity of packet // check validity of packet
if ( dvframe && dvframe->IsValid() ) if ( dvframe && dvframe->IsValid() )
@ -566,12 +568,12 @@ bool CURFProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, std::unique_p
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// packet encoding helpers // packet encoding helpers
void CURFProtocol::EncodeKeepAlivePacket(CBuffer *Buffer) void CXlxProtocol::EncodeKeepAlivePacket(CBuffer *Buffer)
{ {
Buffer->Set(GetReflectorCallsign()); Buffer->Set(GetReflectorCallsign());
} }
void CURFProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules) void CXlxProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules)
{ {
uint8_t tag[] = { 'L' }; uint8_t tag[] = { 'L' };
@ -589,7 +591,7 @@ void CURFProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules)
Buffer->resize(39); Buffer->resize(39);
} }
void CURFProtocol::EncodeDisconnectPacket(CBuffer *Buffer) void CXlxProtocol::EncodeDisconnectPacket(CBuffer *Buffer)
{ {
uint8_t tag[] = { 'U' }; uint8_t tag[] = { 'U' };
@ -601,7 +603,7 @@ void CURFProtocol::EncodeDisconnectPacket(CBuffer *Buffer)
Buffer->Append((uint8_t)0); Buffer->Append((uint8_t)0);
} }
void CURFProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules) void CXlxProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules)
{ {
uint8_t tag[] = { 'A' }; uint8_t tag[] = { 'A' };
@ -619,7 +621,7 @@ void CURFProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules)
Buffer->resize(39); Buffer->resize(39);
} }
void CURFProtocol::EncodeConnectNackPacket(CBuffer *Buffer) void CXlxProtocol::EncodeConnectNackPacket(CBuffer *Buffer)
{ {
uint8_t tag[] = { 'N' }; uint8_t tag[] = { 'N' };
@ -631,26 +633,26 @@ void CURFProtocol::EncodeConnectNackPacket(CBuffer *Buffer)
Buffer->Append((uint8_t)0); Buffer->Append((uint8_t)0);
} }
bool CURFProtocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const bool CXlxProtocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const
{ {
uint8_t tag[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; uint8_t tag[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 };
Buffer->Set(tag, sizeof(tag)); Buffer->Set(tag, sizeof(tag));
Buffer->Append(Packet.GetStreamId()); Buffer->Append(Packet.GetStreamId());
Buffer->Append((uint8_t)(Packet.GetDstarPacketId() % 21)); Buffer->Append((uint8_t)(Packet.GetDstarPacketId() % 21));
Buffer->Append((uint8_t *)Packet.GetAmbe(), 9); Buffer->Append((uint8_t *)Packet.GetCodecData(ECodecType::dstar), 9);
Buffer->Append((uint8_t *)Packet.GetDvData(), 3); Buffer->Append((uint8_t *)Packet.GetDvData(), 3);
Buffer->Append((uint8_t)Packet.GetDmrPacketId()); Buffer->Append((uint8_t)Packet.GetDmrPacketId());
Buffer->Append((uint8_t)Packet.GetDmrPacketSubid()); Buffer->Append((uint8_t)Packet.GetDmrPacketSubid());
Buffer->Append((uint8_t *)Packet.GetAmbePlus(), 9); Buffer->Append((uint8_t *)Packet.GetCodecData(ECodecType::dmr), 9);
Buffer->Append((uint8_t *)Packet.GetDvSync(), 7); Buffer->Append((uint8_t *)Packet.GetDvSync(), 7);
return true; return true;
} }
bool CURFProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBuffer *Buffer) const bool CXlxProtocol::EncodeDvLastFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const
{ {
uint8_t tag[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; uint8_t tag[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 };
uint8_t dstarambe[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00 }; uint8_t dstarambe[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00 };
@ -665,7 +667,7 @@ bool CURFProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBu
Buffer->Append((uint8_t)Packet.GetDmrPacketId()); Buffer->Append((uint8_t)Packet.GetDmrPacketId());
Buffer->Append((uint8_t)Packet.GetDmrPacketSubid()); Buffer->Append((uint8_t)Packet.GetDmrPacketSubid());
Buffer->Append((uint8_t *)Packet.GetAmbePlus(), 9); Buffer->Append((uint8_t *)Packet.GetCodecData(ECodecType::dmr), 9);
Buffer->Append((uint8_t *)Packet.GetDvSync(), 7); Buffer->Append((uint8_t *)Packet.GetDvSync(), 7);
return true; return true;
@ -674,9 +676,9 @@ bool CURFProtocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBu
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// protocol revision helper // protocol revision helper
int CURFProtocol::GetConnectingPeerProtocolRevision(const CCallsign &Callsign, const CVersion &Version) EProtoRev CXlxProtocol::GetConnectingPeerProtocolRevision(const CCallsign &Callsign, const CVersion &Version)
{ {
int protrev; EProtoRev protrev;
// BM ? // BM ?
if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) ) if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) )
@ -686,14 +688,14 @@ int CURFProtocol::GetConnectingPeerProtocolRevision(const CCallsign &Callsign, c
// otherwise, assume native xlx // otherwise, assume native xlx
else else
{ {
protrev = CURFPeer::GetProtocolRevision(Version); protrev = CXlxPeer::GetProtocolRevision(Version);
} }
// done // done
return protrev; return protrev;
} }
std::shared_ptr<CPeer> CURFProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version) std::shared_ptr<CPeer> CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version)
{ {
// BM ? // BM ?
if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) ) if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) )
@ -702,6 +704,6 @@ std::shared_ptr<CPeer> CURFProtocol::CreateNewPeer(const CCallsign &Callsign, co
} }
else else
{ {
return std::make_shared<CURFPeer>(Callsign, Ip, Modules, Version); return std::make_shared<CXlxPeer>(Callsign, Ip, Modules, Version);
} }
} }

@ -1,3 +1,5 @@
#pragma once
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. // Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector // urfd -- The universal reflector
@ -16,8 +18,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Version.h" #include "Version.h"
#include "Timer.h" #include "Timer.h"
#include "DExtraProtocol.h" #include "DExtraProtocol.h"
@ -30,11 +30,11 @@ class CPeer;
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// class // class
class CURFProtocol : public CDextraProtocol class CXlxProtocol : public CDextraProtocol
{ {
public: public:
// initialization // initialization
bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); bool Initialize(const char *type, EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6);
// task // task
void Task(void); void Task(void);
@ -50,7 +50,7 @@ protected:
// stream helpers // stream helpers
void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &); void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &);
void OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr); void OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr);
void OnDvLastFramePacketIn(std::unique_ptr<CDvLastFramePacket> &, const CIp * = nullptr); void OnDvLastFramePacketIn(std::unique_ptr<CDvFramePacket> &, const CIp * = nullptr);
// packet decoding helpers // packet decoding helpers
bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *); bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *);
@ -59,7 +59,7 @@ protected:
bool IsValidAckPacket(const CBuffer &, CCallsign *, char *, CVersion *); bool IsValidAckPacket(const CBuffer &, CCallsign *, char *, CVersion *);
bool IsValidNackPacket(const CBuffer &, CCallsign *); bool IsValidNackPacket(const CBuffer &, CCallsign *);
bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &); bool IsValidDvFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvLastFramePacket> &); bool IsValidDvLastFramePacket(const CBuffer &, std::unique_ptr<CDvFramePacket> &);
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *); void EncodeKeepAlivePacket(CBuffer *);
@ -68,10 +68,10 @@ protected:
void EncodeConnectAckPacket(CBuffer *, const char *); void EncodeConnectAckPacket(CBuffer *, const char *);
void EncodeConnectNackPacket(CBuffer *); void EncodeConnectNackPacket(CBuffer *);
bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const; bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const;
bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const; bool EncodeDvLastFramePacket(const CDvFramePacket &, CBuffer *) const;
// protocol revision helper // protocol revision helper
int GetConnectingPeerProtocolRevision(const CCallsign &, const CVersion &); EProtoRev GetConnectingPeerProtocolRevision(const CCallsign &, const CVersion &);
std::shared_ptr<CPeer>CreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &); std::shared_ptr<CPeer>CreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &);
protected: protected:

@ -79,7 +79,7 @@ void CYsfProtocol::Task(void)
std::unique_ptr<CDvHeaderPacket> Header; std::unique_ptr<CDvHeaderPacket> Header;
std::array<std::unique_ptr<CDvFramePacket>, 5> Frames; std::array<std::unique_ptr<CDvFramePacket>, 5> Frames;
std::unique_ptr<CDvFramePacket> OneFrame; std::unique_ptr<CDvFramePacket> OneFrame;
std::unique_ptr<CDvLastFramePacket> LastFrame; std::unique_ptr<CDvFramePacket> LastFrame;
// handle outgoing packets // handle outgoing packets
{ {
@ -130,7 +130,7 @@ void CYsfProtocol::Task(void)
else if ( IsValidDvLastFramePacket(Ip, Fich, Buffer, OneFrame, LastFrame) ) else if ( IsValidDvLastFramePacket(Ip, Fich, Buffer, OneFrame, LastFrame) )
{ {
OnDvFramePacketIn(OneFrame, &Ip); OnDvFramePacketIn(OneFrame, &Ip);
OnDvLastFramePacketIn(LastFrame, &Ip); OnDvFramePacketIn(LastFrame, &Ip);
} }
} }
else if ( IsValidConnectPacket(Buffer, &Callsign) ) else if ( IsValidConnectPacket(Buffer, &Callsign) )
@ -445,8 +445,8 @@ bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, co
{ {
uint8_t uiAmbe[9]; uint8_t uiAmbe[9];
memset(uiAmbe, 0x00, sizeof(uiAmbe)); memset(uiAmbe, 0x00, sizeof(uiAmbe));
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0)); frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0, false));
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0)); frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0, false));
} }
// check validity of packets // check validity of packets
@ -476,11 +476,11 @@ bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, con
// get DV frames // get DV frames
uint8_t fid = Buffer.data()[34]; uint8_t fid = Buffer.data()[34];
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe0, uiStreamId, Fich.getFN(), 0, fid)); frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe0, uiStreamId, Fich.getFN(), 0, fid, false));
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe1, uiStreamId, Fich.getFN(), 1, fid)); frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe1, uiStreamId, Fich.getFN(), 1, fid, false));
frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe2, uiStreamId, Fich.getFN(), 2, fid)); frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe2, uiStreamId, Fich.getFN(), 2, fid, false));
frames[3] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe3, uiStreamId, Fich.getFN(), 3, fid)); frames[3] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe3, uiStreamId, Fich.getFN(), 3, fid, false));
frames[4] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid)); frames[4] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid, false));
// check validity of packets // check validity of packets
if ( frames[0] && frames[0]->IsValid() && frames[1] && frames[1]->IsValid() && frames[2] && frames[2]->IsValid() && frames[3] && frames[3]->IsValid() && frames[4] && frames[4]->IsValid() ) if ( frames[0] && frames[0]->IsValid() && frames[1] && frames[1]->IsValid() && frames[2] && frames[2]->IsValid() && frames[3] && frames[3]->IsValid() && frames[4] && frames[4]->IsValid() )
@ -489,7 +489,7 @@ bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, con
return false; return false;
} }
bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &oneframe, std::unique_ptr<CDvLastFramePacket> &lastframe) bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, std::unique_ptr<CDvFramePacket> &oneframe, std::unique_ptr<CDvFramePacket> &lastframe)
{ {
// DV header ? // DV header ?
if ( Fich.getFI() == YSF_FI_TERMINATOR ) if ( Fich.getFI() == YSF_FI_TERMINATOR )
@ -501,8 +501,8 @@ bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich,
{ {
uint8_t uiAmbe[9]; uint8_t uiAmbe[9];
memset(uiAmbe, 0x00, sizeof(uiAmbe)); memset(uiAmbe, 0x00, sizeof(uiAmbe));
oneframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0)); oneframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0, false));
lastframe = std::unique_ptr<CDvLastFramePacket>(new CDvLastFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0)); lastframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0, true));
} }
// check validity of packets // check validity of packets

@ -19,10 +19,9 @@
#pragma once #pragma once
#include "Timer.h" #include "Timer.h"
#include "DCSProtocol.h" #include "Protocol.h"
#include "DVHeaderPacket.h" #include "DVHeaderPacket.h"
#include "DVFramePacket.h" #include "DVFramePacket.h"
#include "DVLastFramePacket.h"
#include "YSFDefines.h" #include "YSFDefines.h"
#include "YSFFich.h" #include "YSFFich.h"
#include "WiresXInfo.h" #include "WiresXInfo.h"
@ -87,7 +86,7 @@ protected:
bool IsValidDvPacket(const CBuffer &, CYSFFICH *); bool IsValidDvPacket(const CBuffer &, CYSFFICH *);
bool IsValidDvHeaderPacket(const CIp &, const CYSFFICH &, const CBuffer &, std::unique_ptr<CDvHeaderPacket> &, std::array<std::unique_ptr<CDvFramePacket>, 5> &); bool IsValidDvHeaderPacket(const CIp &, const CYSFFICH &, const CBuffer &, std::unique_ptr<CDvHeaderPacket> &, std::array<std::unique_ptr<CDvFramePacket>, 5> &);
bool IsValidDvFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, std::array<std::unique_ptr<CDvFramePacket>, 5> &); bool IsValidDvFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, std::array<std::unique_ptr<CDvFramePacket>, 5> &);
bool IsValidDvLastFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, std::unique_ptr<CDvFramePacket> &, std::unique_ptr<CDvLastFramePacket> &); bool IsValidDvLastFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, std::unique_ptr<CDvFramePacket> &, std::unique_ptr<CDvFramePacket> &);
// DV packet encoding helpers // DV packet encoding helpers
void EncodeConnectAckPacket(CBuffer *) const; void EncodeConnectAckPacket(CBuffer *) const;

Loading…
Cancel
Save

Powered by TurnKey Linux.