@ -129,8 +129,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
// is this data from a peer connection?
// is this data from a peer connection?
if ( fromPeer ) {
if ( fromPeer ) {
// perform TGID mutation s if configured
// perform TGID route rewrite s if configured
mutateBuffer ( buffer , peerId , dmrData , dataType , dstId , slotNo , false ) ;
routeRewrite ( buffer , peerId , dmrData , dataType , dstId , slotNo , false ) ;
}
}
// is the stream valid?
// is the stream valid?
@ -254,8 +254,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
: : memset ( outboundPeerBuffer , 0x00U , len ) ;
: : memset ( outboundPeerBuffer , 0x00U , len ) ;
: : memcpy ( outboundPeerBuffer , buffer , len ) ;
: : memcpy ( outboundPeerBuffer , buffer , len ) ;
// perform TGID mutation s if configured
// perform TGID route rewrite s if configured
mutateBuffer ( outboundPeerBuffer , peerId , dmrData , dataType , dstId , slotNo ) ;
routeRewrite ( outboundPeerBuffer , peerId , dmrData , dataType , dstId , slotNo ) ;
peer . second - > writeMaster ( { NET_FUNC_PROTOCOL , NET_PROTOCOL_SUBFUNC_DMR } , outboundPeerBuffer , len , pktSeq , streamId ) ;
peer . second - > writeMaster ( { NET_FUNC_PROTOCOL , NET_PROTOCOL_SUBFUNC_DMR } , outboundPeerBuffer , len , pktSeq , streamId ) ;
}
}
@ -300,7 +300,7 @@ void TagDMRData::playbackParrot()
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/// <summary>
/// <summary>
/// Helper to muta te the network data buffer.
/// Helper to route rewri te the network data buffer.
/// </summary>
/// </summary>
/// <param name="buffer"></param>
/// <param name="buffer"></param>
/// <param name="peerId">Peer ID</param>
/// <param name="peerId">Peer ID</param>
@ -309,20 +309,20 @@ void TagDMRData::playbackParrot()
/// <param name="dstId"></param>
/// <param name="dstId"></param>
/// <param name="slotNo"></param>
/// <param name="slotNo"></param>
/// <param name="outbound"></param>
/// <param name="outbound"></param>
void TagDMRData : : mutateBuffer ( uint8_t * buffer , uint32_t peerId , dmr : : data : : Data dmrData , uint8_t dataType , uint32_t dstId , uint32_t slotNo , bool outbound )
void TagDMRData : : routeRewrite ( uint8_t * buffer , uint32_t peerId , dmr : : data : : Data dmrData , uint8_t dataType , uint32_t dstId , uint32_t slotNo , bool outbound )
{
{
uint32_t mutated DstId = dstId ;
uint32_t rewrite DstId = dstId ;
uint32_t mutated SlotNo = slotNo ;
uint32_t rewrite SlotNo = slotNo ;
// does the data require mutation ?
// does the data require route rewriting ?
if ( peer Mutate( peerId , mutatedDstId , mutated SlotNo, outbound ) ) {
if ( peer Rewrite( peerId , rewriteDstId , rewrite SlotNo, outbound ) ) {
// rewrite destination TGID in the frame
// rewrite destination TGID in the frame
__SET_UINT16 ( mutated DstId, buffer , 8U ) ;
__SET_UINT16 ( rewrite DstId, buffer , 8U ) ;
// set or clear the e.Slot flag (if 0x80 is set Slot 2 otherwise Slot 1)
// set or clear the e.Slot flag (if 0x80 is set Slot 2 otherwise Slot 1)
if ( mutated SlotNo = = 2 & & ( buffer [ 15U ] & 0x80U ) = = 0x00U )
if ( rewrite SlotNo = = 2 & & ( buffer [ 15U ] & 0x80U ) = = 0x00U )
buffer [ 15U ] | = 0x80 ;
buffer [ 15U ] | = 0x80 ;
if ( mutated SlotNo = = 1 & & ( buffer [ 15U ] & 0x80U ) = = 0x80U )
if ( rewrite SlotNo = = 1 & & ( buffer [ 15U ] & 0x80U ) = = 0x80U )
buffer [ 15U ] = buffer [ 15U ] & ~ 0x80U ;
buffer [ 15U ] = buffer [ 15U ] & ~ 0x80U ;
uint8_t data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
uint8_t data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
@ -335,10 +335,10 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
std : : unique_ptr < lc : : LC > lc = fullLC . decode ( data + 2U , dataType ) ;
std : : unique_ptr < lc : : LC > lc = fullLC . decode ( data + 2U , dataType ) ;
if ( lc = = nullptr ) {
if ( lc = = nullptr ) {
LogWarning ( LOG_NET , " DMR Slot %u, bad LC received from the network, replacing " , slotNo ) ;
LogWarning ( LOG_NET , " DMR Slot %u, bad LC received from the network, replacing " , slotNo ) ;
lc = new_unique ( lc : : LC , dmrData . getFLCO ( ) , dmrData . getSrcId ( ) , mutated DstId) ;
lc = new_unique ( lc : : LC , dmrData . getFLCO ( ) , dmrData . getSrcId ( ) , rewrite DstId) ;
}
}
lc - > setDstId ( mutated DstId) ;
lc - > setDstId ( rewrite DstId) ;
// Regenerate the LC data
// Regenerate the LC data
fullLC . encode ( * lc , data + 2U , dataType ) ;
fullLC . encode ( * lc , data + 2U , dataType ) ;
@ -353,7 +353,7 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
lc = new_unique ( lc : : PrivacyLC ) ;
lc = new_unique ( lc : : PrivacyLC ) ;
}
}
lc - > setDstId ( mutated DstId) ;
lc - > setDstId ( rewrite DstId) ;
// Regenerate the LC data
// Regenerate the LC data
fullLC . encodePI ( * lc , data + 2U ) ;
fullLC . encodePI ( * lc , data + 2U ) ;
@ -365,27 +365,27 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
}
}
/// <summary>
/// <summary>
/// Helper to muta te destination ID and slot.
/// Helper to route rewri te destination ID and slot.
/// </summary>
/// </summary>
/// <param name="peerId">Peer ID</param>
/// <param name="peerId">Peer ID</param>
/// <param name="dstId"></param>
/// <param name="dstId"></param>
/// <param name="slotNo"></param>
/// <param name="slotNo"></param>
/// <param name="outbound"></param>
/// <param name="outbound"></param>
bool TagDMRData : : peer Muta te( uint32_t peerId , uint32_t & dstId , uint32_t & slotNo , bool outbound )
bool TagDMRData : : peer Rewri te( uint32_t peerId , uint32_t & dstId , uint32_t & slotNo , bool outbound )
{
{
lookups : : TalkgroupRuleGroupVoice tg ;
lookups : : TalkgroupRuleGroupVoice tg ;
if ( outbound ) {
if ( outbound ) {
tg = m_network - > m_tidLookup - > find ( dstId , slotNo ) ;
tg = m_network - > m_tidLookup - > find ( dstId , slotNo ) ;
}
}
else {
else {
tg = m_network - > m_tidLookup - > findBy Mutation ( peerId , dstId , slotNo ) ;
tg = m_network - > m_tidLookup - > findBy Rewrite ( peerId , dstId , slotNo ) ;
}
}
std : : vector < lookups : : TalkgroupRule Mutation> mutations = tg . config ( ) . mutation ( ) ;
std : : vector < lookups : : TalkgroupRule Rewrite> rewrites = tg . config ( ) . rewrite ( ) ;
bool mutated = false ;
bool rewrote = false ;
if ( mutation s. size ( ) > 0 ) {
if ( rewrite s. size ( ) > 0 ) {
for ( auto entry : mutation s) {
for ( auto entry : rewrite s) {
if ( entry . peerId ( ) = = peerId ) {
if ( entry . peerId ( ) = = peerId ) {
if ( outbound ) {
if ( outbound ) {
dstId = tg . source ( ) . tgId ( ) ;
dstId = tg . source ( ) . tgId ( ) ;
@ -395,13 +395,13 @@ bool TagDMRData::peerMutate(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo,
dstId = entry . tgId ( ) ;
dstId = entry . tgId ( ) ;
slotNo = entry . tgSlot ( ) ;
slotNo = entry . tgSlot ( ) ;
}
}
mutated = true ;
rewrote = true ;
break ;
break ;
}
}
}
}
}
}
return mutated ;
return rewrote ;
}
}
/// <summary>
/// <summary>