Merge pull request #1 from nostar/main

Extract valid callsign from YSF for DMR ID lookup and use compile-tim…
pull/8/head
Tom Early 4 years ago committed by GitHub
commit 4e2710c913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,10 +112,10 @@ bool CCallsign::IsValid(void) const
}
// prefix
// all chars are number, uppercase or space
// all chars are number, letter, special char, or space
for ( i = 0; i < CALLSUFFIX_LEN; i++ )
{
valid &= IsLetter(m_Suffix[i]) || IsNumber(m_Suffix[i]) || IsSpace(m_Suffix[i]);
valid &= IsLetter(m_Suffix[i]) || IsNumber(m_Suffix[i]) || IsSpace(m_Suffix[i]) || IsLetterLC(m_Suffix[i]) || IsSpecialChar(m_Suffix[i]);
}
// module
@ -371,6 +371,16 @@ bool CCallsign::IsSpace(char c) const
return (c == ' ');
}
bool CCallsign::IsLetterLC(char c) const
{
return ((c >= 'a') && (c <= 'z'));
}
bool CCallsign::IsSpecialChar(char c) const
{
return ((c >= '!') && (c <= '/'));
}
void CCallsign::CodeIn(const uint8_t *in)
{
char cs[10];

@ -84,6 +84,8 @@ protected:
bool IsNumber(char) const;
bool IsLetter(char) const;
bool IsSpace(char) const;
bool IsLetterLC(char) const;
bool IsSpecialChar(char) const;
protected:
// data

@ -859,12 +859,28 @@ void CDmrmmdvmProtocol::EncodeMMDVMPacket(const CDvHeaderPacket &Header, const C
{
uint8_t tag[] = { 'D','M','R','D' };
Buffer->Set(tag, sizeof(tag));
uint8_t cs[12];
// DMR header
// uiSeqId
Buffer->Append((uint8_t)seqid);
// uiSrcId
uint32_t uiSrcId = Header.GetMyCallsign().GetDmrid();
DvFrame0.GetMyCallsign().GetCallsign(cs);
if(uiSrcId == 0){
uiSrcId = DvFrame0.GetMyCallsign().GetDmrid();
}
if(uiSrcId == 0){
uiSrcId = DvFrame1.GetMyCallsign().GetDmrid();
}
if(uiSrcId == 0){
uiSrcId = DvFrame2.GetMyCallsign().GetDmrid();
}
if(uiSrcId == 0){
uiSrcId = DMRMMDVM_DEFAULTID;
}
AppendDmrIdToBuffer(Buffer, uiSrcId);
// uiDstId = TG9
uint32_t uiDstId = 9; // ModuleToDmrDestId(Header.GetRpt2Module());

@ -59,7 +59,7 @@ CDvFramePacket::CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_
}
// ysf constructor
CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, uint8_t spid, uint8_t fid, bool islast)
CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, uint8_t spid, uint8_t fid, CCallsign cs, bool islast)
: CPacket(sid, pid, spid, fid, islast)
{
memcpy(m_TCPack.dmr, ambe, 9);
@ -69,6 +69,9 @@ CDvFramePacket::CDvFramePacket(const uint8_t *ambe, uint16_t sid, uint8_t pid, u
memset(m_TCPack.m17, 0, 16);
memset(m_Nonce, 0, 14);
m_TCPack.codec_in = ECodecType::dmr;
uint8_t c[12];
cs.GetCallsign(c);
m_Callsign.SetCallsign((char *)c);
}
// bm constructor

@ -19,6 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Packet.h"
#include "Callsign.h"
////////////////////////////////////////////////////////////////////////////////////////
// defines
@ -45,7 +46,7 @@ public:
// DMR Frame
CDvFramePacket(const uint8_t *ambe, const uint8_t *sync, uint16_t streamid, uint8_t counter1, uint8_t counter2, bool islast);
// YSF Frame
CDvFramePacket(const uint8_t *ambe, uint16_t streamid, uint8_t counter1, uint8_t counter2, uint8_t counter3, bool islast);
CDvFramePacket(const uint8_t *ambe, uint16_t streamid, uint8_t counter1, uint8_t counter2, uint8_t counter3, CCallsign cs, 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);
// M17 Frame
@ -68,6 +69,7 @@ public:
const uint8_t *GetDvSync(void) const { return m_uiDvSync; }
const uint8_t *GetDvData(void) const { return m_uiDvData; }
const uint8_t *GetNonce(void) const { return m_Nonce; }
const CCallsign &GetMyCallsign(void) const { return m_Callsign; }
// set
void SetDvData(const uint8_t *);
@ -86,4 +88,5 @@ protected:
uint8_t m_Nonce[14];
// the transcoder packet
STCPacket m_TCPack;
CCallsign m_Callsign;
};

@ -22,6 +22,7 @@
#include "DMRIdDir.h"
#include "DVHeaderPacket.h"
////////////////////////////////////////////////////////////////////////////////////////
// constructor
@ -89,6 +90,17 @@ CDvHeaderPacket::CDvHeaderPacket(const struct dstar_header *buffer, uint16_t sid
m_uiFlag2 = buffer->Flag2;
m_uiFlag3 = buffer->Flag3;
m_csUR.SetCallsign(buffer->UR, CALLSIGN_LEN);
if((buffer->RPT1)[7] == 0x20){
char rptr1[8];
memcpy(rptr1, buffer->RPT1, 8);
rptr1[7] = DPLUS_DEFAULT_RPTR1_SUFFIX;
m_csRPT1.SetCallsign(rptr1, CALLSIGN_LEN);
}
else{
m_csRPT1.SetCallsign(buffer->RPT1, CALLSIGN_LEN);
}
m_csRPT1.SetCallsign(buffer->RPT1, CALLSIGN_LEN);
m_csRPT2.SetCallsign(buffer->RPT2, CALLSIGN_LEN);
m_csMY.SetCallsign(buffer->MY, CALLSIGN_LEN);

@ -92,6 +92,7 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm
#define DPLUS_PORT 20001 // UDP port
#define DPLUS_KEEPALIVE_PERIOD 1 // in seconds
#define DPLUS_KEEPALIVE_TIMEOUT (DPLUS_KEEPALIVE_PERIOD*10) // in seconds
#define DPLUS_DEFAULT_RPTR1_SUFFIX 'Y'
// DCS
#define DCS_PORT 30051 // UDP port
@ -123,6 +124,7 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm
#define DMRMMDVM_KEEPALIVE_TIMEOUT (DMRMMDVM_KEEPALIVE_PERIOD*10) // in seconds
#define DMRMMDVM_REFLECTOR_SLOT DMR_SLOT2
#define DMRMMDVM_REFLECTOR_COLOUR 1
#define DMRMMDVM_DEFAULTID 0
// YSF
#define YSF_PORT 42000 // UDP port

@ -407,6 +407,7 @@ bool CYsfProtocol::IsValidDvPacket(const CBuffer &Buffer, CYSFFICH *Fich)
bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, std::unique_ptr<CDvHeaderPacket> &header, std::array<std::unique_ptr<CDvFramePacket>, 5> &frames)
{
CCallsign csMY;
// DV header ?
if ( Fich.getFI() == YSF_FI_HEADER )
{
@ -421,7 +422,14 @@ bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, co
char sz[YSF_CALLSIGN_LENGTH+1];
memcpy(sz, &(Buffer.data()[14]), YSF_CALLSIGN_LENGTH);
sz[YSF_CALLSIGN_LENGTH] = 0;
CCallsign csMY = CCallsign((const char *)sz);
for(uint32_t i = 0; i < YSF_CALLSIGN_LENGTH; ++i){
if( (sz[i] == '/') || (sz[i] == '\\') || (sz[i] == '-') || (sz[i] == ' ') ){
sz[i] = 0;
}
}
csMY = CCallsign((const char *)sz);
memcpy(sz, &(Buffer.data()[4]), YSF_CALLSIGN_LENGTH);
sz[YSF_CALLSIGN_LENGTH] = 0;
CCallsign rpt1 = CCallsign((const char *)sz);
@ -439,12 +447,12 @@ bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, co
{
uint8_t uiAmbe[9];
memset(uiAmbe, 0x00, sizeof(uiAmbe));
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, false));
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0, csMY, false));
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0, csMY, false));
}
// check validity of packets
if ( header && frames[0] && frames[1] && header->IsValid() && frames[0]->IsValid() && frames[1]->IsValid() )
if ( header && frames[0] && frames[1] && frames[0]->IsValid() && frames[1]->IsValid() )
return true;
}
@ -467,14 +475,26 @@ bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, con
uint8_t ambe4[9];
uint8_t *ambes[5] = { ambe0, ambe1, ambe2, ambe3, ambe4 };
CYsfUtils::DecodeVD2Vchs((unsigned char *)&(Buffer.data()[35]), ambes);
char sz[YSF_CALLSIGN_LENGTH+1];
::memcpy(sz, &(Buffer.data()[14]), YSF_CALLSIGN_LENGTH);
sz[YSF_CALLSIGN_LENGTH] = 0;
for(uint32_t i = 0; i < YSF_CALLSIGN_LENGTH; ++i){
if( (sz[i] == '/') || (sz[i] == '\\') || (sz[i] == '-') || (sz[i] == ' ') ){
sz[i] = 0;
}
}
CCallsign csMY = CCallsign((const char *)sz);
// get DV frames
uint8_t fid = Buffer.data()[34];
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, false));
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, false));
frames[4] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid, false));
frames[0] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe0, uiStreamId, Fich.getFN(), 0, fid, csMY, false));
frames[1] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe1, uiStreamId, Fich.getFN(), 1, fid, csMY, false));
frames[2] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe2, uiStreamId, Fich.getFN(), 2, fid, csMY, false));
frames[3] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe3, uiStreamId, Fich.getFN(), 3, fid, csMY, false));
frames[4] = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid, csMY, false));
// 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() )
@ -495,8 +515,21 @@ bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich,
{
uint8_t uiAmbe[9];
memset(uiAmbe, 0x00, sizeof(uiAmbe));
oneframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0, false));
lastframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0, true));
char sz[YSF_CALLSIGN_LENGTH+1];
::memcpy(sz, &(Buffer.data()[14]), YSF_CALLSIGN_LENGTH);
sz[YSF_CALLSIGN_LENGTH] = 0;
for(uint32_t i = 0; i < YSF_CALLSIGN_LENGTH; ++i){
if( (sz[i] == '/') || (sz[i] == '\\') || (sz[i] == '-') || (sz[i] == ' ') ){
sz[i] = 0;
}
}
CCallsign csMY = CCallsign((const char *)sz);
oneframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 0, 0, csMY, false));
lastframe = std::unique_ptr<CDvFramePacket>(new CDvFramePacket(uiAmbe, uiStreamId, Fich.getFN(), 1, 0, csMY, true));
}
// check validity of packets

Loading…
Cancel
Save

Powered by TurnKey Linux.