@ -29,6 +29,12 @@ using namespace p25;
# include <cassert>
# include <chrono>
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const uint32_t GRANT_TIMER_TIMEOUT = 15U ;
// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------
@ -384,8 +390,40 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
/// <returns></returns>
bool TagP25Data : : processGrantReq ( uint32_t srcId , uint32_t dstId , bool unitToUnit , uint32_t peerId , uint16_t pktSeq , uint32_t streamId )
{
// bryanb: TODO TODO TODO
return false ;
// if we have an Rx status for the destination deny the grant
if ( std : : find_if ( m_status . begin ( ) , m_status . end ( ) , [ & ] ( StatusMapPair x ) { return x . second . dstId = = dstId ; } ) ! = m_status . end ( ) ) {
return false ;
}
// is the source ID a blacklisted ID?
lookups : : RadioId rid = m_network - > m_ridLookup - > find ( srcId ) ;
if ( ! rid . radioDefault ( ) ) {
if ( ! rid . radioEnabled ( ) ) {
return false ;
}
}
lookups : : TalkgroupRuleGroupVoice tg = m_network - > m_tidLookup - > find ( dstId ) ;
// check TGID validity
if ( tg . isInvalid ( ) ) {
return false ;
}
if ( ! tg . config ( ) . active ( ) ) {
return false ;
}
// repeat traffic to the connected peers
if ( m_network - > m_peers . size ( ) > 0U ) {
for ( auto peer : m_network - > m_peers ) {
if ( peerId ! = peer . first ) {
write_TSDU_Grant ( peer . first , srcId , dstId , 4U , ! unitToUnit ) ;
}
}
}
return true ;
}
/// <summary>
@ -1123,6 +1161,76 @@ bool TagP25Data::validate(uint32_t peerId, lc::LC& control, uint8_t duid, const
return true ;
}
/// <summary>
/// Helper to write a grant packet.
/// </summary>
/// <param name="peerId"></param>
/// <param name="srcId"></param>
/// <param name="dstId"></param>
/// <param name="grp"></param>
/// <returns></returns>
bool TagP25Data : : write_TSDU_Grant ( uint32_t peerId , uint32_t srcId , uint32_t dstId , uint8_t serviceOptions , bool grp )
{
bool emergency = ( ( serviceOptions & 0xFFU ) & 0x80U ) = = 0x80U ; // Emergency Flag
bool encryption = ( ( serviceOptions & 0xFFU ) & 0x40U ) = = 0x40U ; // Encryption Flag
uint8_t priority = ( ( serviceOptions & 0xFFU ) & 0x07U ) ; // Priority
if ( dstId = = P25_TGID_ALL ) {
return true ; // do not generate grant packets for $FFFF (All Call) TGID
}
// check the affiliations for this peer to see if we can grant traffic
lookups : : AffiliationLookup * aff = m_network - > m_peerAffiliations [ peerId ] ;
if ( aff = = nullptr ) {
std : : string peerIdentity = m_network - > resolvePeerIdentity ( peerId ) ;
LogError ( LOG_NET , " PEER %u (%s) has an invalid affiliations lookup? This shouldn't happen BUGBUG. " , peerId , peerIdentity . c_str ( ) ) ;
return false ; // this will cause no traffic to pass for this peer now...I'm not sure this is good behavior
}
else {
if ( ! aff - > hasGroupAff ( dstId ) ) {
return false ;
}
}
if ( grp ) {
std : : unique_ptr < lc : : tsbk : : IOSP_GRP_VCH > iosp = std : : make_unique < lc : : tsbk : : IOSP_GRP_VCH > ( ) ;
iosp - > setSrcId ( srcId ) ;
iosp - > setDstId ( dstId ) ;
iosp - > setGrpVchId ( 0U ) ;
iosp - > setGrpVchNo ( 0U ) ;
iosp - > setEmergency ( emergency ) ;
iosp - > setEncrypted ( encryption ) ;
iosp - > setPriority ( priority ) ;
if ( m_network - > m_verbose ) {
LogMessage ( LOG_NET , P25_TSDU_STR " , %s, emerg = %u, encrypt = %u, prio = %u, chNo = %u, srcId = %u, dstId = %u, peerId = %u " ,
iosp - > toString ( ) . c_str ( ) , iosp - > getEmergency ( ) , iosp - > getEncrypted ( ) , iosp - > getPriority ( ) , iosp - > getGrpVchNo ( ) , iosp - > getSrcId ( ) , iosp - > getDstId ( ) , peerId ) ;
}
write_TSDU ( peerId , iosp . get ( ) ) ;
}
else {
std : : unique_ptr < lc : : tsbk : : IOSP_UU_VCH > iosp = std : : make_unique < lc : : tsbk : : IOSP_UU_VCH > ( ) ;
iosp - > setSrcId ( srcId ) ;
iosp - > setDstId ( dstId ) ;
iosp - > setGrpVchId ( 0U ) ;
iosp - > setGrpVchNo ( 0U ) ;
iosp - > setEmergency ( emergency ) ;
iosp - > setEncrypted ( encryption ) ;
iosp - > setPriority ( priority ) ;
if ( m_network - > m_verbose ) {
LogMessage ( LOG_NET , P25_TSDU_STR " , %s, emerg = %u, encrypt = %u, prio = %u, chNo = %u, srcId = %u, dstId = %u, peerId = %u " ,
iosp - > toString ( ) . c_str ( ) , iosp - > getEmergency ( ) , iosp - > getEncrypted ( ) , iosp - > getPriority ( ) , iosp - > getGrpVchNo ( ) , iosp - > getSrcId ( ) , iosp - > getDstId ( ) , peerId ) ;
}
write_TSDU ( peerId , iosp . get ( ) ) ;
}
return true ;
}
/// <summary>
/// Helper to write a deny packet.
/// </summary>