From ec16d8e664f7ddade70f756e838c5f9385ef2f44 Mon Sep 17 00:00:00 2001 From: pyopower Date: Mon, 16 Nov 2026 00:21:40 +0100 Subject: [PATCH] Send the last packet for NXDN and P25 streams NXDN: the end of transmission is only recognised when byte 10 is NXDN_LICH_USC_SACCH_NS, but NXDNGateway/MMDVMHost flag it with bit 0x08 of byte 9 on a regular voice packet. That packet is handled as voice and the stream is never closed with a last packet. Also, the existing last-frame branch only reset the stream id. Both paths now push a last frame packet. P25: on the 0x80 terminator the stream id was reset before building the last packet, so that packet carried id 0, was dropped as an orphaned frame and the stream ended by timeout. Without a last packet the other protocols never send their terminator: a DMR/XLX peer (e.g. hblink) sees the call end by timeout several seconds after the user releases PTT. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hi9GtwUEB6mDD5pfhaJoKB --- reflector/NXDNProtocol.cpp | 18 ++++++++++++++++++ reflector/P25Protocol.cpp | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/reflector/NXDNProtocol.cpp b/reflector/NXDNProtocol.cpp index e5d2b0e..5d97898 100644 --- a/reflector/NXDNProtocol.cpp +++ b/reflector/NXDNProtocol.cpp @@ -102,6 +102,17 @@ void CNXDNProtocol::Task(void) OnDvFramePacketIn(Frames[1], &Ip); OnDvFramePacketIn(Frames[2], &Ip); OnDvFramePacketIn(Frames[3], &Ip); + // end of transmission flagged in byte 9 (bit 0x08), as sent by + // NXDNGateway/MMDVMHost: close the stream with a last packet so the + // other protocols send their terminator instead of timing out + if ( (Buffer.data()[9U] & 0x08U) && (m_uiStreamId != 0) ) + { + uint8_t ambe[9]; + memset(ambe, 0x00, sizeof(ambe)); + auto last = std::unique_ptr(new CDvFramePacket(ambe, m_uiStreamId, 0, true)); + OnDvFramePacketIn(last, &Ip); + m_uiStreamId = 0; + } } else if ( IsValidDvHeaderPacket(Ip, Buffer, Header) ) { @@ -114,6 +125,13 @@ void CNXDNProtocol::Task(void) } else if ( IsValidDvLastFramePacket(Ip, Buffer) ) { + if ( m_uiStreamId != 0 ) + { + uint8_t ambe[9]; + memset(ambe, 0x00, sizeof(ambe)); + auto last = std::unique_ptr(new CDvFramePacket(ambe, m_uiStreamId, 0, true)); + OnDvFramePacketIn(last, &Ip); + } m_uiStreamId = 0; } else if ( IsValidConnectPacket(Buffer, &Callsign) ) diff --git a/reflector/P25Protocol.cpp b/reflector/P25Protocol.cpp index 0c52204..f8bcb83 100644 --- a/reflector/P25Protocol.cpp +++ b/reflector/P25Protocol.cpp @@ -352,14 +352,17 @@ bool CP25Protocol::IsValidDvPacket(const CIp &Ip, const CBuffer &Buffer, std::un offset = 4U; break; case 0x80U: + // terminator: reset the stream id AFTER building the last packet, + // otherwise it gets id 0, is dropped as orphaned and the stream times out last = true; - m_uiStreamId = 0; break; default: break; } frame = std::unique_ptr(new CDvFramePacket(&(Buffer.data()[offset]), m_uiStreamId, last)); + if ( last ) + m_uiStreamId = 0; return true; } return false;