correct V.24 confirmed PDU receive block extraction to the 18 byte wire block the transmit path already uses; (#141)
Inbound confirmed PDUs of more than one block failed the packet CRC-32 on every attempt. The receive path stepped 19 bytes per block on the wire and stored 18 byte chunks, while storeConvertedRxPDU() reads 16 bytes of user data per block, so every block after the first was misaligned. A confirmed block on the wire is a sequence/flag byte, 16 bytes of user data and a reserved byte (DFSI_PDU_CONFIRMED_BLOCK_LENGTH_BYTES). The single, header and continuation frame cases now copy the user data through one bounded helper, and reject a frame that is too short for its block count. The single frame layout is checked against a frame captured from a Quantar, using the subscriber's own packet CRC-32 and the IPv4 header checksum. No capture of a header or continuation frame was available; those follow the layout the transmit path generates.r05a06_dev
parent
ffda6d50a1
commit
4e3a34182b
@ -0,0 +1,164 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Digital Voice Modem - Test Suite
|
||||
* GPLv2 Open Source. Use is subject to license terms.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* Copyright (C) 2026 David Andrzejewski
|
||||
*
|
||||
*/
|
||||
#include "host/Defines.h"
|
||||
#include "common/edac/CRC.h"
|
||||
#include "common/p25/P25Defines.h"
|
||||
#include "common/p25/dfsi/DFSIDefines.h"
|
||||
#include "host/modem/ModemV24.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace modem;
|
||||
using namespace p25::defines;
|
||||
using namespace p25::dfsi::defines;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** @brief Offset in bytes of the first block in a V.24 PDU frame carrying an embedded start of stream and header. */
|
||||
static const uint32_t HEADER_FRAME_BLOCK_OFFSET = DFSI_MOT_START_LEN + P25_PDU_HEADER_LENGTH_BYTES + DFSI_PDU_RESERVED_LENGTH_BYTES;
|
||||
|
||||
/** @brief Number of confirmed blocks in the captured frame. */
|
||||
static const uint32_t CAPTURED_BLOCK_CNT = 3U;
|
||||
|
||||
/** @brief Length in bytes of the user data carried by the captured frame, including the packet CRC-32. */
|
||||
static const uint32_t CAPTURED_USER_DATA_LENGTH = CAPTURED_BLOCK_CNT * P25_PDU_CONFIRMED_DATA_LENGTH_BYTES;
|
||||
|
||||
/**
|
||||
* @brief Single confirmed PDU frame (frame type $8F) captured inbound from a Quantar over V.24.
|
||||
* A 44 byte IPv4/UDP packet in three confirmed blocks, followed by the packet CRC-32. Each block on the wire is a
|
||||
* sequence/flag byte ($00, $02, $04), 16 bytes of user data and a trailing byte.
|
||||
*/
|
||||
static const uint8_t CAPTURED_SINGLE_CONF_FRAME[] = {
|
||||
0x8FU, 0x02U, 0x04U, 0x0CU, 0x06U, 0x00U, 0x00U, 0x00U, 0x00U, // embedded start of stream
|
||||
0x56U, 0xC4U, 0x00U, 0x00U, 0x13U, 0x57U, 0x03U, 0x00U, 0x58U, 0x00U, 0xACU, 0x00U, // PDU header
|
||||
0x02U, // reserved
|
||||
0x00U, 0x45U, 0x00U, 0x00U, 0x2CU, 0x40U, 0xC5U, 0x00U, 0x00U, 0x40U, 0x11U, 0x24U, 0xC3U, 0x0AU, 0x19U, 0x00U, 0x0AU, 0x03U,
|
||||
0x02U, 0x0AU, 0x19U, 0x00U, 0xFEU, 0x0FU, 0xA5U, 0x0FU, 0xA5U, 0x00U, 0x18U, 0xFDU, 0x0BU, 0x00U, 0x0EU, 0xF0U, 0x20U, 0x03U,
|
||||
0x04U, 0x04U, 0x34U, 0x39U, 0x35U, 0x31U, 0x04U, 0x39U, 0x30U, 0x35U, 0x31U, 0x01U, 0x31U, 0x5EU, 0x9EU, 0x53U, 0x53U, 0x02U,
|
||||
0xC0U, 0x01U, 0x67U, 0x02U // end metadata
|
||||
};
|
||||
|
||||
/** @brief User data carried by the captured frame; a 44 byte IPv4/UDP packet and its CRC-32. */
|
||||
static const uint8_t CAPTURED_USER_DATA[] = {
|
||||
0x45U, 0x00U, 0x00U, 0x2CU, 0x40U, 0xC5U, 0x00U, 0x00U, 0x40U, 0x11U, 0x24U, 0xC3U, 0x0AU, 0x19U, 0x00U, 0x0AU,
|
||||
0x0AU, 0x19U, 0x00U, 0xFEU, 0x0FU, 0xA5U, 0x0FU, 0xA5U, 0x00U, 0x18U, 0xFDU, 0x0BU, 0x00U, 0x0EU, 0xF0U, 0x20U,
|
||||
0x04U, 0x34U, 0x39U, 0x35U, 0x31U, 0x04U, 0x39U, 0x30U, 0x35U, 0x31U, 0x01U, 0x31U, 0x5EU, 0x9EU, 0x53U, 0x53U
|
||||
};
|
||||
|
||||
TEST_CASE("V.24 confirmed PDU blocks from a captured single frame carry a valid packet", "[p25][dfsi][pdu][v24]")
|
||||
{
|
||||
REQUIRE(sizeof(CAPTURED_SINGLE_CONF_FRAME) == 80U);
|
||||
REQUIRE(sizeof(CAPTURED_USER_DATA) == CAPTURED_USER_DATA_LENGTH);
|
||||
|
||||
uint8_t userData[CAPTURED_USER_DATA_LENGTH];
|
||||
::memset(userData, 0xFFU, CAPTURED_USER_DATA_LENGTH);
|
||||
|
||||
REQUIRE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, sizeof(CAPTURED_SINGLE_CONF_FRAME), HEADER_FRAME_BLOCK_OFFSET,
|
||||
CAPTURED_BLOCK_CNT, userData, CAPTURED_USER_DATA_LENGTH));
|
||||
|
||||
REQUIRE(::memcmp(userData, CAPTURED_USER_DATA, CAPTURED_USER_DATA_LENGTH) == 0);
|
||||
|
||||
// the packet CRC-32 was generated by the subscriber, so it verifies the block boundaries independently
|
||||
REQUIRE(edac::CRC::checkCRC32(userData, CAPTURED_USER_DATA_LENGTH));
|
||||
|
||||
// the IPv4 header checksum covers bytes on both sides of the first block boundary
|
||||
uint32_t sum = 0U;
|
||||
for (uint32_t i = 0U; i < 20U; i += 2U)
|
||||
sum += (uint32_t)((userData[i] << 8) | userData[i + 1U]);
|
||||
sum = (sum & 0xFFFFU) + (sum >> 16);
|
||||
REQUIRE(sum == 0xFFFFU);
|
||||
}
|
||||
|
||||
TEST_CASE("V.24 confirmed PDU block copy is bounded by the frame and the user data buffer", "[p25][dfsi][pdu][v24]")
|
||||
{
|
||||
// the reserved byte trailing the last block is not required
|
||||
const uint32_t minFrameLength = HEADER_FRAME_BLOCK_OFFSET + ((CAPTURED_BLOCK_CNT - 1U) * DFSI_PDU_CONFIRMED_BLOCK_LENGTH_BYTES) +
|
||||
1U + P25_PDU_CONFIRMED_DATA_LENGTH_BYTES;
|
||||
|
||||
uint8_t userData[CAPTURED_USER_DATA_LENGTH + 1U];
|
||||
|
||||
SECTION("minimum frame length is accepted") {
|
||||
::memset(userData, 0xFFU, sizeof(userData));
|
||||
|
||||
REQUIRE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, minFrameLength, HEADER_FRAME_BLOCK_OFFSET,
|
||||
CAPTURED_BLOCK_CNT, userData, CAPTURED_USER_DATA_LENGTH));
|
||||
REQUIRE(::memcmp(userData, CAPTURED_USER_DATA, CAPTURED_USER_DATA_LENGTH) == 0);
|
||||
|
||||
// nothing is written past the copied blocks
|
||||
REQUIRE(userData[CAPTURED_USER_DATA_LENGTH] == 0xFFU);
|
||||
}
|
||||
|
||||
SECTION("frame one byte short is rejected without writing") {
|
||||
::memset(userData, 0xFFU, sizeof(userData));
|
||||
|
||||
REQUIRE_FALSE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, minFrameLength - 1U, HEADER_FRAME_BLOCK_OFFSET,
|
||||
CAPTURED_BLOCK_CNT, userData, CAPTURED_USER_DATA_LENGTH));
|
||||
REQUIRE(userData[0U] == 0xFFU);
|
||||
}
|
||||
|
||||
SECTION("user data buffer one byte short is rejected without writing") {
|
||||
::memset(userData, 0xFFU, sizeof(userData));
|
||||
|
||||
REQUIRE_FALSE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, sizeof(CAPTURED_SINGLE_CONF_FRAME), HEADER_FRAME_BLOCK_OFFSET,
|
||||
CAPTURED_BLOCK_CNT, userData, CAPTURED_USER_DATA_LENGTH - 1U));
|
||||
REQUIRE(userData[0U] == 0xFFU);
|
||||
}
|
||||
|
||||
SECTION("zero blocks copies nothing") {
|
||||
::memset(userData, 0xFFU, sizeof(userData));
|
||||
|
||||
REQUIRE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, sizeof(CAPTURED_SINGLE_CONF_FRAME), HEADER_FRAME_BLOCK_OFFSET,
|
||||
0U, userData, CAPTURED_USER_DATA_LENGTH));
|
||||
REQUIRE(userData[0U] == 0xFFU);
|
||||
}
|
||||
|
||||
SECTION("block count that overflows 32-bit length arithmetic is rejected") {
|
||||
::memset(userData, 0xFFU, sizeof(userData));
|
||||
|
||||
REQUIRE_FALSE(ModemV24::copyConfirmedPDUBlocks(CAPTURED_SINGLE_CONF_FRAME, sizeof(CAPTURED_SINGLE_CONF_FRAME), HEADER_FRAME_BLOCK_OFFSET,
|
||||
0xFFFFFFFFU, userData, CAPTURED_USER_DATA_LENGTH));
|
||||
REQUIRE(userData[0U] == 0xFFU);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("V.24 confirmed PDU continuation frame blocks follow the frame type byte", "[p25][dfsi][pdu][v24]")
|
||||
{
|
||||
// no continuation frame capture is available; this frame is built to the layout the transmit path
|
||||
// generates: frame type, then for each block a sequence/flag byte, 16 bytes of user data and a reserved byte
|
||||
const uint32_t frameLength = 1U + (DFSI_PDU_BLOCK_CNT * DFSI_PDU_CONFIRMED_BLOCK_LENGTH_BYTES) + 1U;
|
||||
const uint32_t userDataLength = DFSI_PDU_BLOCK_CNT * P25_PDU_CONFIRMED_DATA_LENGTH_BYTES;
|
||||
|
||||
uint8_t frame[1U + (DFSI_PDU_BLOCK_CNT * DFSI_PDU_CONFIRMED_BLOCK_LENGTH_BYTES) + 1U];
|
||||
::memset(frame, 0x00U, frameLength);
|
||||
frame[0U] = DFSIFrameType::MOT_PDU_CONF_BLOCK_1;
|
||||
|
||||
uint8_t expected[DFSI_PDU_BLOCK_CNT * P25_PDU_CONFIRMED_DATA_LENGTH_BYTES];
|
||||
for (uint32_t i = 0U; i < DFSI_PDU_BLOCK_CNT; i++) {
|
||||
const uint32_t blockOffset = 1U + (i * DFSI_PDU_CONFIRMED_BLOCK_LENGTH_BYTES);
|
||||
|
||||
frame[blockOffset] = 0xEEU; // sequence/flag byte
|
||||
for (uint32_t j = 0U; j < P25_PDU_CONFIRMED_DATA_LENGTH_BYTES; j++) {
|
||||
const uint8_t value = (uint8_t)((i << 4) | j);
|
||||
frame[blockOffset + 1U + j] = value;
|
||||
expected[(i * P25_PDU_CONFIRMED_DATA_LENGTH_BYTES) + j] = value;
|
||||
}
|
||||
frame[blockOffset + 1U + P25_PDU_CONFIRMED_DATA_LENGTH_BYTES] = 0xDDU; // reserved byte
|
||||
}
|
||||
|
||||
uint8_t userData[DFSI_PDU_BLOCK_CNT * P25_PDU_CONFIRMED_DATA_LENGTH_BYTES];
|
||||
::memset(userData, 0xFFU, userDataLength);
|
||||
|
||||
REQUIRE(ModemV24::copyConfirmedPDUBlocks(frame, frameLength, 1U, DFSI_PDU_BLOCK_CNT, userData, userDataLength));
|
||||
REQUIRE(::memcmp(userData, expected, userDataLength) == 0);
|
||||
}
|
||||
Loading…
Reference in new issue