support standard unconfirmed P25 MBT packets; implement TELE_INT_DIAL_REQ encoding and decoding; add factory routing and unit tests;

pull/134/head
Bryan Biedenkapp 1 month ago
parent 55b7570701
commit 3b1d249dd9

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2022,2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2022,2024,2026 Bryan Biedenkapp, N2PLL
*
*/
#include "Defines.h"
@ -26,7 +26,8 @@ using namespace p25::lc;
/* Initializes a new instance of the AMBT class. */
AMBT::AMBT() : TSBK()
AMBT::AMBT() : TSBK(),
m_isAMBT(true)
{
/* stub */
}
@ -51,6 +52,14 @@ void AMBT::encode(uint8_t* data, bool rawTSBK, bool noTrellis)
LogError(LOG_P25, "AMBT::encode(), bad call, not implemented");
}
/* Determines whether a PDU header identifies an MBT packet. */
bool AMBT::isMBT(const data::DataHeader& dataHeader)
{
return dataHeader.getSAP() == PDUSAP::TRUNK_CTRL &&
(dataHeader.getFormat() == PDUFormatType::AMBT || dataHeader.getFormat() == PDUFormatType::UNCONFIRMED);
}
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
@ -62,14 +71,21 @@ ulong64_t AMBT::toValue(const data::DataHeader& dataHeader, const uint8_t* pduUs
ulong64_t tsbkValue = 0U;
// combine bytes into ulong64_t (8 byte) value
tsbkValue = dataHeader.getAMBTField8();
tsbkValue = (tsbkValue << 8) + dataHeader.getAMBTField9();
tsbkValue = (tsbkValue << 8) + pduUserData[0U];
tsbkValue = (tsbkValue << 8) + pduUserData[1U];
tsbkValue = (tsbkValue << 8) + pduUserData[2U];
tsbkValue = (tsbkValue << 8) + pduUserData[3U];
tsbkValue = (tsbkValue << 8) + pduUserData[4U];
tsbkValue = (tsbkValue << 8) + pduUserData[5U];
if (dataHeader.getFormat() == PDUFormatType::UNCONFIRMED) {
// Standard MBT: data block octet 0 is the opcode and octets 1.. are message data
for (uint32_t i = 1U; i <= 8U; i++)
tsbkValue = (tsbkValue << 8) + pduUserData[i];
} else {
// Alternate MBT: data block octets are combined with header fields to form the 64-bit value
tsbkValue = dataHeader.getAMBTField8();
tsbkValue = (tsbkValue << 8) + dataHeader.getAMBTField9();
tsbkValue = (tsbkValue << 8) + pduUserData[0U];
tsbkValue = (tsbkValue << 8) + pduUserData[1U];
tsbkValue = (tsbkValue << 8) + pduUserData[2U];
tsbkValue = (tsbkValue << 8) + pduUserData[3U];
tsbkValue = (tsbkValue << 8) + pduUserData[4U];
tsbkValue = (tsbkValue << 8) + pduUserData[5U];
}
return tsbkValue;
}
@ -81,8 +97,8 @@ bool AMBT::decode(const data::DataHeader& dataHeader, const data::DataBlock* blo
assert(blocks != nullptr);
assert(pduUserData != nullptr);
if (dataHeader.getFormat() != PDUFormatType::AMBT) {
LogError(LOG_P25, "AMBT::decode(), PDU is not a AMBT PDU");
if (!isMBT(dataHeader)) {
LogError(LOG_P25, "AMBT::decode(), PDU is not a standard or alternate MBT PDU");
return false;
}
@ -91,7 +107,21 @@ bool AMBT::decode(const data::DataHeader& dataHeader, const data::DataBlock* blo
return false;
}
m_lco = dataHeader.getAMBTOpcode(); // LCO
// determine if the MBT is standard or alternate based on the PDU format
if (dataHeader.getFormat() == PDUFormatType::UNCONFIRMED) {
uint8_t firstBlock[P25_PDU_UNCONFIRMED_LENGTH_BYTES];
if (blocks[0U].getData(firstBlock) != P25_PDU_UNCONFIRMED_LENGTH_BYTES) {
LogError(LOG_P25, "AMBT::decode(), failed to read first PDU data block");
return false;
}
m_isAMBT = false;
m_lco = firstBlock[0U] & 0x3FU; // LCO
} else {
m_isAMBT = true;
m_lco = dataHeader.getAMBTOpcode(); // LCO
}
m_lastBlock = true; // Last Block Marker
m_mfId = dataHeader.getMFId(); // Mfg Id.
@ -114,7 +144,11 @@ bool AMBT::decode(const data::DataHeader& dataHeader, const data::DataBlock* blo
}
if (s_verbose) {
LogDebugEx(LOG_P25, "AMBT::decode()", "mfId = $%02X, lco = $%02X, ambt8 = $%02X, ambt9 = $%02X", m_mfId, m_lco, dataHeader.getAMBTField8(), dataHeader.getAMBTField9());
if (m_isAMBT) {
LogDebugEx(LOG_P25, "AMBT::decode()", "mfId = $%02X, ambt = %u, lco = $%02X, ambt8 = $%02X, ambt9 = $%02X", m_mfId, m_isAMBT, m_lco, dataHeader.getAMBTField8(), dataHeader.getAMBTField9());
} else {
LogDebugEx(LOG_P25, "AMBT::decode()", "mfId = $%02X, ambt = %u, lco = $%02X", m_mfId, m_isAMBT, m_lco);
}
Utils::dump(2U, "P25, AMBT::decode(), pduUserData", pduUserData, P25_PDU_UNCONFIRMED_LENGTH_BYTES * dataHeader.getBlocksToFollow());
}
@ -127,7 +161,8 @@ void AMBT::encode(data::DataHeader& dataHeader, uint8_t* pduUserData)
{
assert(pduUserData != nullptr);
dataHeader.setFormat(PDUFormatType::AMBT);
const bool standardMBT = dataHeader.getFormat() == PDUFormatType::UNCONFIRMED;
dataHeader.setFormat(standardMBT ? PDUFormatType::UNCONFIRMED : PDUFormatType::AMBT);
dataHeader.setMFId(m_mfId); // Mfg Id.
dataHeader.setAckNeeded(false);
dataHeader.setOutbound(true);
@ -139,7 +174,40 @@ void AMBT::encode(data::DataHeader& dataHeader, uint8_t* pduUserData)
dataHeader.setBlocksToFollow(1U);
}
dataHeader.setAMBTOpcode(m_lco); // LCO
// determine if we are encoding a standard or alternate MBT based on the PDU format
if (standardMBT) {
uint32_t oldLength = P25_PDU_UNCONFIRMED_LENGTH_BYTES * dataHeader.getBlocksToFollow();
uint32_t bytesToMove = oldLength - 7U; // retain four octets for the packet CRC
// standard MBT moves the opcode and the two message octets from the header
// into the data stream. Grow by a block if those three octets would displace
// non-padding message data
if (pduUserData[oldLength - 7U] != 0U || pduUserData[oldLength - 6U] != 0U ||
pduUserData[oldLength - 5U] != 0U) {
// AABB limits an MBT packet to four blocks total: one header plus
// at most three data blocks
if (dataHeader.getBlocksToFollow() >= 3U) {
LogError(LOG_P25, "AMBT::encode(), standard MBT payload exceeds three data blocks");
return;
}
dataHeader.setBlocksToFollow(dataHeader.getBlocksToFollow() + 1U);
bytesToMove = oldLength - 4U;
}
const uint32_t newLength = P25_PDU_UNCONFIRMED_LENGTH_BYTES * dataHeader.getBlocksToFollow();
::memmove(pduUserData + 3U, pduUserData, bytesToMove);
::memset(pduUserData + 3U + bytesToMove, 0x00U, newLength - 3U - bytesToMove);
pduUserData[0U] = m_lco & 0x3FU; // LCO
pduUserData[1U] = dataHeader.getAMBTField8(); // Message octet 0
pduUserData[2U] = dataHeader.getAMBTField9(); // Message octet 1
dataHeader.setPadLength(0U);
dataHeader.setHeaderOffset(0U);
} else {
dataHeader.setAMBTOpcode(m_lco); // LCO
}
// generate packet CRC-32 and set data blocks
if (dataHeader.getBlocksToFollow() > 1U) {

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2022 Bryan Biedenkapp, N2PLL
* Copyright (C) 2022,2026 Bryan Biedenkapp, N2PLL
*
*/
/**
@ -48,9 +48,11 @@ namespace p25
*/
virtual bool decodeMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks) = 0;
/**
* @brief Encode a alternate trunking signalling block.
* @brief Encode a trunking signalling block.
* @param[out] dataHeader P25 PDU data header
* @param[out] pduUserData P25 PDU user data
* @note Set dataHeader format to UNCONFIRMED before calling to request
* the standard MBT header; all other formats produce alternate MBT.
*/
virtual void encodeMBT(data::DataHeader& dataHeader, uint8_t* pduUserData) = 0;
@ -69,6 +71,19 @@ namespace p25
*/
void encode(uint8_t* data, bool rawTSBK = false, bool noTrellis = false);
/**
* @brief Determines whether a PDU header identifies either standard or alternate MBT.
* @param[in] dataHeader P25 PDU data header
* @returns bool True, if the header identifies an MBT packet.
*/
static bool isMBT(const data::DataHeader& dataHeader);
public:
/**
* @brief Determines whether the AMBT instance represents a standard or alternate MBT.
*/
DECLARE_RO_PROPERTY(bool, isAMBT, isAMBT);
protected:
/**
* @brief Internal helper to convert AMBT bytes to a 64-bit long value.
@ -87,7 +102,7 @@ namespace p25
*/
bool decode(const data::DataHeader& dataHeader, const data::DataBlock* blocks, uint8_t* pduUserData);
/**
* @brief Internal helper to encode a trunking signalling block.
* @brief Internal helper to encode a standard or alternate trunking signalling block.
* @param[out] dataHeader P25 PDU data header
* @param[out] pduUserData P25 PDU user data
*/

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2022,2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2022,2024,2026 Bryan Biedenkapp, N2PLL
*
*/
#include "Defines.h"
@ -20,6 +20,15 @@ using namespace p25::lc::tsbk;
#include <cassert>
// ---------------------------------------------------------------------------
// Macros
// ---------------------------------------------------------------------------
// MBT is a Standard MBT (SMBT)
#define MBT_IS_SMBT if (smbt)
// MBT is a Alternate MBT (AMBT)
#define MBT_IS_AMBT if (!smbt)
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
@ -225,14 +234,14 @@ std::unique_ptr<TSBK> TSBKFactory::createTSBK(const uint8_t* data, bool rawTSBK)
return nullptr;
}
/* Create an instance of a AMBT. */
/* Create an instance of a SMBT/AMBT. */
std::unique_ptr<AMBT> TSBKFactory::createAMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks)
{
assert(blocks != nullptr);
if (dataHeader.getFormat() != PDUFormatType::AMBT) {
LogError(LOG_P25, "TSBKFactory::createAMBT(), PDU is not a AMBT PDU");
if (!AMBT::isMBT(dataHeader)) {
LogError(LOG_P25, "TSBKFactory::createAMBT(), PDU is not a standard or alternate MBT PDU");
return nullptr;
}
@ -241,7 +250,19 @@ std::unique_ptr<AMBT> TSBKFactory::createAMBT(const data::DataHeader& dataHeader
return nullptr;
}
bool smbt = false;
uint8_t lco = dataHeader.getAMBTOpcode(); // LCO
if (dataHeader.getFormat() == PDUFormatType::UNCONFIRMED) {
uint8_t firstBlock[P25_PDU_UNCONFIRMED_LENGTH_BYTES];
if (blocks[0U].getData(firstBlock) != P25_PDU_UNCONFIRMED_LENGTH_BYTES) {
LogError(LOG_P25, "TSBKFactory::createAMBT(), failed to read first PDU data block");
return nullptr;
}
smbt = true;
lco = firstBlock[0U] & 0x3FU;
}
uint8_t mfId = dataHeader.getMFId(); // Mfg Id.
// Motorola P25 vendor opcodes
@ -267,7 +288,7 @@ std::unique_ptr<AMBT> TSBKFactory::createAMBT(const data::DataHeader& dataHeader
mfId = MFG_STANDARD;
break;
case TSBKO::ISP_GRP_AFF_Q_RSP:
return decode(new MBT_ISP_GRP_AFF_Q_RSP(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_ISP_GRP_AFF_Q_RSP(), dataHeader, blocks);
default:
LogError(LOG_P25, "TSBKFactory::createAMBT(), unknown TSBK LCO value, mfId = $%02X, lco = $%02X", mfId, lco);
break;
@ -283,24 +304,26 @@ std::unique_ptr<AMBT> TSBKFactory::createAMBT(const data::DataHeader& dataHeader
// standard P25 reference opcodes
switch (lco) {
case TSBKO::IOSP_TELE_INT_DIAL:
MBT_IS_SMBT return decode(new MBT_ISP_TELE_INT_DIAL_REQ(), dataHeader, blocks);
case TSBKO::IOSP_STS_UPDT:
return decode(new MBT_IOSP_STS_UPDT(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_STS_UPDT(), dataHeader, blocks);
case TSBKO::IOSP_MSG_UPDT:
return decode(new MBT_IOSP_MSG_UPDT(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_MSG_UPDT(), dataHeader, blocks);
case TSBKO::IOSP_CALL_ALRT:
return decode(new MBT_IOSP_CALL_ALRT(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_CALL_ALRT(), dataHeader, blocks);
case TSBKO::IOSP_ACK_RSP:
return decode(new MBT_IOSP_ACK_RSP(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_ACK_RSP(), dataHeader, blocks);
case TSBKO::IOSP_GRP_AFF:
return decode(new MBT_IOSP_GRP_AFF(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_GRP_AFF(), dataHeader, blocks);
case TSBKO::ISP_CAN_SRV_REQ:
return decode(new MBT_ISP_CAN_SRV_REQ(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_ISP_CAN_SRV_REQ(), dataHeader, blocks);
case TSBKO::IOSP_EXT_FNCT:
return decode(new MBT_IOSP_EXT_FNCT(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_IOSP_EXT_FNCT(), dataHeader, blocks);
case TSBKO::ISP_AUTH_RESP_M:
return decode(new MBT_ISP_AUTH_RESP_M(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_ISP_AUTH_RESP_M(), dataHeader, blocks);
case TSBKO::ISP_AUTH_SU_DMD:
return decode(new MBT_ISP_AUTH_SU_DMD(), dataHeader, blocks);
MBT_IS_AMBT return decode(new MBT_ISP_AUTH_SU_DMD(), dataHeader, blocks);
default:
LogError(LOG_P25, "TSBKFactory::createAMBT(), unknown TSBK LCO value, mfId = $%02X, lco = $%02X", mfId, lco);
break;

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2022 Bryan Biedenkapp, N2PLL
* Copyright (C) 2022,2026 Bryan Biedenkapp, N2PLL
*
*/
/**
@ -93,6 +93,7 @@
#include "common/p25/lc/tsbk/mbt/MBT_ISP_AUTH_SU_DMD.h"
#include "common/p25/lc/tsbk/mbt/MBT_ISP_CAN_SRV_REQ.h"
#include "common/p25/lc/tsbk/mbt/MBT_ISP_GRP_AFF_Q_RSP.h"
#include "common/p25/lc/tsbk/mbt/MBT_ISP_TELE_INT_DIAL_REQ.h"
#include "common/p25/lc/tsbk/mbt/MBT_OSP_ADJ_STS_BCAST.h"
#include "common/p25/lc/tsbk/mbt/MBT_OSP_AUTH_DMD.h"
#include "common/p25/lc/tsbk/mbt/MBT_OSP_GRP_VCH_GRANT.h"
@ -133,10 +134,10 @@ namespace p25
*/
static std::unique_ptr<TSBK> createTSBK(const uint8_t* data, bool rawTSBK = false);
/**
* @brief Create an instance of a AMBT.
* @brief Create an instance of a SMBT/AMBT.
* @param[in] dataHeader P25 PDU data header
* @param[in] blocks P25 PDU data blocks
* @returns AMBT* Instance of a AMBT representing the decoded data.
* @returns AMBT* Instance of a SMBT/AMBT representing the decoded data.
*/
static std::unique_ptr<AMBT> createAMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks);

@ -0,0 +1,155 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Common Library
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2026 Bryan Biedenkapp, N2PLL
*
*/
#include "Defines.h"
#include "p25/P25Defines.h"
#include "p25/lc/tsbk/mbt/MBT_ISP_TELE_INT_DIAL_REQ.h"
#include "edac/CRC.h"
#include "Log.h"
using namespace p25;
using namespace p25::defines;
using namespace p25::lc;
using namespace p25::lc::tsbk;
#include <cassert>
#include <cstring>
MBT_ISP_TELE_INT_DIAL_REQ::MBT_ISP_TELE_INT_DIAL_REQ() : AMBT(),
m_digitCount(0U),
m_duplex(false),
m_packetMode(false)
{
m_lco = TSBKO::IOSP_TELE_INT_DIAL;
::memset(m_digits, 0x0FU, MAX_DIGITS);
}
bool MBT_ISP_TELE_INT_DIAL_REQ::decodeMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks)
{
assert(blocks != nullptr);
if (dataHeader.getFormat() != PDUFormatType::UNCONFIRMED ||
dataHeader.getSAP() != PDUSAP::TRUNK_CTRL || dataHeader.getOutbound()) {
LogError(LOG_P25, "MBT_ISP_TELE_INT_DIAL_REQ::decodeMBT(), invalid PDU header");
return false;
}
DECLARE_UINT8_ARRAY(pduUserData, P25_PDU_UNCONFIRMED_LENGTH_BYTES * dataHeader.getBlocksToFollow());
if (!AMBT::decode(dataHeader, blocks, pduUserData))
return false;
if (m_lco != TSBKO::IOSP_TELE_INT_DIAL) {
LogError(LOG_P25, "MBT_ISP_TELE_INT_DIAL_REQ::decodeMBT(), invalid opcode, lco = $%02X", m_lco);
return false;
}
m_digitCount = pduUserData[1U];
const uint8_t expectedBlocks = (m_digitCount <= 10U) ? 1U : 2U;
if (m_digitCount == 0U || m_digitCount > MAX_DIGITS ||
dataHeader.getBlocksToFollow() != expectedBlocks) {
LogError(LOG_P25, "MBT_ISP_TELE_INT_DIAL_REQ::decodeMBT(), invalid digit/block count, digits = %u, blocks = %u",
m_digitCount, dataHeader.getBlocksToFollow());
return false;
}
const uint8_t serviceOptions = pduUserData[2U];
m_emergency = (serviceOptions & 0x80U) == 0x80U;
m_encrypted = (serviceOptions & 0x40U) == 0x40U;
m_duplex = (serviceOptions & 0x20U) == 0x20U;
m_packetMode = (serviceOptions & 0x10U) == 0x10U;
m_priority = serviceOptions & 0x07U;
m_srcId = dataHeader.getLLId();
::memset(m_digits, 0x0FU, MAX_DIGITS);
for (uint8_t i = 0U; i < m_digitCount; i++) {
const uint32_t octet = 3U + (i / 2U);
m_digits[i] = ((i & 1U) == 0U) ?
((pduUserData[octet] >> 4) & 0x0FU) : (pduUserData[octet] & 0x0FU);
}
return true;
}
void MBT_ISP_TELE_INT_DIAL_REQ::encodeMBT(data::DataHeader& dataHeader, uint8_t* pduUserData)
{
assert(pduUserData != nullptr);
if (m_digitCount == 0U || m_digitCount > MAX_DIGITS) {
LogError(LOG_P25, "MBT_ISP_TELE_INT_DIAL_REQ::encodeMBT(), invalid digit count, digits = %u", m_digitCount);
return;
}
const uint8_t blocksToFollow = (m_digitCount <= 10U) ? 1U : 2U;
const uint32_t length = P25_PDU_UNCONFIRMED_LENGTH_BYTES * blocksToFollow;
::memset(pduUserData, 0x00U, length);
dataHeader.setFormat(PDUFormatType::UNCONFIRMED);
dataHeader.setMFId(m_mfId);
dataHeader.setAckNeeded(false);
dataHeader.setOutbound(false);
dataHeader.setSAP(PDUSAP::TRUNK_CTRL);
dataHeader.setLLId(m_srcId);
dataHeader.setFullMessage(true);
dataHeader.setBlocksToFollow(blocksToFollow);
dataHeader.setPadLength(0U);
dataHeader.setHeaderOffset(0U);
pduUserData[0U] = m_lco & 0x3FU;
pduUserData[1U] = m_digitCount;
pduUserData[2U] =
(m_emergency ? 0x80U : 0x00U) |
(m_encrypted ? 0x40U : 0x00U) |
(m_duplex ? 0x20U : 0x00U) |
(m_packetMode ? 0x10U : 0x00U) |
(m_priority & 0x07U);
// Unused digit positions use the DTMF null value.
const uint8_t capacity = (blocksToFollow == 1U) ? 10U : MAX_DIGITS;
for (uint8_t i = 0U; i < capacity; i++) {
const uint8_t digit = (i < m_digitCount) ? m_digits[i] : 0x0FU;
const uint32_t octet = 3U + (i / 2U);
if ((i & 1U) == 0U)
pduUserData[octet] = (digit & 0x0FU) << 4;
else
pduUserData[octet] |= digit & 0x0FU;
}
edac::CRC::addCRC32(pduUserData, length);
}
std::string MBT_ISP_TELE_INT_DIAL_REQ::toString(bool isp)
{
return std::string("TSBKO, ISP_TELE_INT_DIAL_REQ (Telephone Interconnect Request - Explicit Dialing)");
}
uint8_t MBT_ISP_TELE_INT_DIAL_REQ::getDialDigits(uint8_t* digits) const
{
assert(digits != nullptr);
::memcpy(digits, m_digits, m_digitCount);
return m_digitCount;
}
bool MBT_ISP_TELE_INT_DIAL_REQ::setDialDigits(const uint8_t* digits, uint8_t count)
{
assert(digits != nullptr);
if (count == 0U || count > MAX_DIGITS)
return false;
for (uint8_t i = 0U; i < count; i++) {
if (digits[i] > 0x0FU)
return false;
}
::memset(m_digits, 0x0FU, MAX_DIGITS);
::memcpy(m_digits, digits, count);
m_digitCount = count;
return true;
}

@ -0,0 +1,54 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Common Library
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2026 Bryan Biedenkapp, N2PLL
*
*/
#if !defined(__P25_LC_TSBK__MBT_ISP_TELE_INT_DIAL_REQ_H__)
#define __P25_LC_TSBK__MBT_ISP_TELE_INT_DIAL_REQ_H__
#include "common/Defines.h"
#include "common/p25/lc/AMBT.h"
namespace p25
{
namespace lc
{
namespace tsbk
{
/**
* @brief Implements TELE INT DIAL REQ - Telephone Interconnect Request,
* Explicit Dialing (standard unconfirmed MBT format).
* @ingroup p25_ambt
*/
class DVM_COMMON_API MBT_ISP_TELE_INT_DIAL_REQ : public AMBT {
public:
MBT_ISP_TELE_INT_DIAL_REQ();
bool decodeMBT(const data::DataHeader& dataHeader, const data::DataBlock* blocks) override;
void encodeMBT(data::DataHeader& dataHeader, uint8_t* pduUserData) override;
std::string toString(bool isp = false) override;
/** @brief Copies the encoded four-bit dial digit values to the supplied buffer. */
uint8_t getDialDigits(uint8_t* digits) const;
/** @brief Sets encoded four-bit dial digit values. */
bool setDialDigits(const uint8_t* digits, uint8_t count);
public:
DECLARE_PROTECTED_RO_PROPERTY(uint8_t, digitCount, DigitCount);
DECLARE_PROPERTY(bool, duplex, Duplex);
DECLARE_PROPERTY(bool, packetMode, PacketMode);
private:
static const uint8_t MAX_DIGITS = 34U;
uint8_t m_digits[MAX_DIGITS];
};
} // namespace tsbk
} // namespace lc
} // namespace p25
#endif // __P25_LC_TSBK__MBT_ISP_TELE_INT_DIAL_REQ_H__

@ -5,7 +5,7 @@
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2016,2017,2018 Jonathan Naylor, G4KLX
* Copyright (C) 2017-2025 Bryan Biedenkapp, N2PLL
* Copyright (C) 2017-2026 Bryan Biedenkapp, N2PLL
*
*/
#include "Defines.h"
@ -118,7 +118,7 @@ bool Data::process(uint8_t* data, uint32_t len)
}
// if we're a dedicated CC or in control only mode, we only want to handle AMBTs. Otherwise return
if ((m_p25->m_dedicatedControl || m_p25->m_controlOnly) && m_rfAssembler->dataHeader.getFormat() != PDUFormatType::AMBT) {
if ((m_p25->m_dedicatedControl || m_p25->m_controlOnly) && !lc::AMBT::isMBT(m_rfAssembler->dataHeader)) {
if (m_debug) {
LogDebug(LOG_RF, "CC only mode, ignoring non-AMBT PDU from RF");
}
@ -370,9 +370,14 @@ bool Data::process(uint8_t* data, uint32_t len)
if (m_rfAssembler->getUndecodableBlockCount() > 0U)
break;
if (m_verbose) {
LogInfoEx(LOG_RF, P25_PDU_STR ", TRUNK_CTRL (Alternate MBT Packet), lco = $%02X, blocksToFollow = %u",
m_rfAssembler->dataHeader.getAMBTOpcode(), m_rfAssembler->dataHeader.getBlocksToFollow());
if (m_rfAssembler->dataHeader.getFormat() == PDUFormatType::UNCONFIRMED && m_verbose) {
LogInfoEx(LOG_RF, P25_PDU_STR ", TRUNK_CTRL (Standard MBT Packet), blocksToFollow = %u",
m_rfAssembler->dataHeader.getBlocksToFollow());
} else {
if (m_rfAssembler->dataHeader.getFormat() == PDUFormatType::AMBT && m_verbose) {
LogInfoEx(LOG_RF, P25_PDU_STR ", TRUNK_CTRL (Alternate MBT Packet), lco = $%02X, blocksToFollow = %u",
m_rfAssembler->dataHeader.getAMBTOpcode(), m_rfAssembler->dataHeader.getBlocksToFollow());
}
}
m_p25->m_control->processMBT(m_rfAssembler->dataHeader, m_rfAssembler->dataBlocks);
@ -480,7 +485,7 @@ bool Data::processNetwork(uint8_t* data, uint32_t len, uint8_t currentBlock, uin
}
// if we're a dedicated CC or in control only mode, we only want to handle AMBTs. Otherwise return
if ((m_p25->m_dedicatedControl || m_p25->m_controlOnly) && m_netAssembler->dataHeader.getFormat() != PDUFormatType::AMBT) {
if ((m_p25->m_dedicatedControl || m_p25->m_controlOnly) && !lc::AMBT::isMBT(m_netAssembler->dataHeader)) {
if (m_debug) {
LogDebug(LOG_NET, "CC only mode, ignoring non-AMBT PDU from network");
}

@ -10,6 +10,9 @@
#include "host/Defines.h"
#include "common/p25/lc/tsbk/OSP_SCCB.h"
#include "common/p25/lc/tsbk/OSP_TSBK_RAW.h"
#include "common/p25/lc/tsbk/TSBKFactory.h"
#include "common/p25/data/DataBlock.h"
#include "common/p25/data/DataHeader.h"
#include "common/p25/P25Defines.h"
#include "common/edac/CRC.h"
#include "common/Log.h"
@ -30,6 +33,56 @@ TEST_CASE("TSBK", "[p25][tsbk]") {
REQUIRE(P25_TSBK_FEC_LENGTH_BITS == (P25_TSBK_FEC_LENGTH_BYTES * 8 - 4)); // 196 bits (Trellis)
}
SECTION("Standard_Unconfirmed_MBT_TELE_INT_DIAL_REQ") {
const uint8_t counts[] = { 1U, 10U, 11U, 34U };
for (uint8_t count : counts) {
MBT_ISP_TELE_INT_DIAL_REQ source;
source.setSrcId(0x654321U);
source.setEmergency(true);
source.setEncrypted(true);
source.setDuplex(true);
source.setPacketMode(false);
source.setPriority(5U);
uint8_t expectedDigits[34U];
for (uint8_t i = 0U; i < count; i++)
expectedDigits[i] = i % 12U;
REQUIRE(source.setDialDigits(expectedDigits, count));
data::DataHeader header;
uint8_t raw[2U * P25_PDU_UNCONFIRMED_LENGTH_BYTES] = { 0U };
source.encodeMBT(header, raw);
CHECK(header.getFormat() == PDUFormatType::UNCONFIRMED);
CHECK(header.getSAP() == PDUSAP::TRUNK_CTRL);
CHECK_FALSE(header.getOutbound());
CHECK(header.getBlocksToFollow() == ((count <= 10U) ? 1U : 2U));
data::DataBlock blocks[2U];
for (uint8_t i = 0U; i < header.getBlocksToFollow(); i++) {
blocks[i].setFormat(header);
blocks[i].setData(raw + (i * P25_PDU_UNCONFIRMED_LENGTH_BYTES));
}
std::unique_ptr<AMBT> decoded = TSBKFactory::createAMBT(header, blocks);
REQUIRE(decoded != nullptr);
MBT_ISP_TELE_INT_DIAL_REQ* dial = dynamic_cast<MBT_ISP_TELE_INT_DIAL_REQ*>(decoded.get());
REQUIRE(dial != nullptr);
CHECK(dial->getLCO() == TSBKO::IOSP_TELE_INT_DIAL);
CHECK(dial->getSrcId() == source.getSrcId());
CHECK(dial->getDigitCount() == count);
CHECK(dial->getEmergency());
CHECK(dial->getEncrypted());
CHECK(dial->getDuplex());
CHECK_FALSE(dial->getPacketMode());
CHECK(dial->getPriority() == 5U);
uint8_t actualDigits[34U] = { 0U };
CHECK(dial->getDialDigits(actualDigits) == count);
CHECK(::memcmp(actualDigits, expectedDigits, count) == 0);
}
}
SECTION("RawTSBK_Encode_Decode_NoTrellis") {
g_logDisplayLevel = 1U;

Loading…
Cancel
Save

Powered by TurnKey Linux.