diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h index 97e27c9a3b..4ee6d0edc2 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h @@ -40,5 +40,7 @@ uint8_t unpack_nr_slot_indication(uint8_t **ppReadPackedMsg, uint8_t pack_nr_slot_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); uint8_t pack_ul_dci_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); uint8_t unpack_ul_dci_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config); +uint8_t pack_tx_data_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); +uint8_t unpack_tx_data_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config); #endif // OPENAIRINTERFACE_NR_FAPI_P7_H diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c b/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c index 891d769ad4..ed2af12964 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c @@ -43,6 +43,9 @@ uint8_t fapi_nr_p7_message_body_pack(nfapi_nr_p7_message_header_t *header, case NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST: result = pack_ul_dci_request(header, ppWritePackedMsg, end, config); break; + case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST: + result = pack_tx_data_request(header, ppWritePackedMsg, end, config); + break; default: { if (header->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && header->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) { if (config && config->pack_p7_vendor_extension) { @@ -161,6 +164,10 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf, if (check_nr_fapi_unpack_length(NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST, unpackedBufLen)) result = unpack_ul_dci_request(&pReadPackedMessage, end, pMessageHeader, config); break; + case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST: + if (check_nr_fapi_unpack_length(NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST, unpackedBufLen)) + result = unpack_tx_data_request(&pReadPackedMessage, end, pMessageHeader, config); + break; default: if (pMessageHeader->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && pMessageHeader->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) { @@ -1454,3 +1461,127 @@ uint8_t unpack_ul_dci_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg return 1; } + +static uint8_t pack_tx_data_pdu_list_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) +{ + nfapi_nr_pdu_t *value = (nfapi_nr_pdu_t *)tlv; + if (!(push32(value->PDU_length, ppWritePackedMsg, end) && push16(value->PDU_index, ppWritePackedMsg, end) + && push32(value->num_TLV, ppWritePackedMsg, end))) + return 0; + + for (int i = 0; i < value->num_TLV; ++i) { + if (!(push16(value->TLVs[i].tag, ppWritePackedMsg, end) && push32(value->TLVs[i].length, ppWritePackedMsg, end))) + return 0; + const uint32_t byte_len = (value->TLVs[i].length + 3) / 4; + switch (value->TLVs[i].tag) { + case 0: { + if (!pusharray32(value->TLVs[i].value.direct, byte_len, byte_len, ppWritePackedMsg, end)) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s():%d. value->TLVs[i].length %d \n", __FUNCTION__, __LINE__, value->TLVs[i].length); + return 0; + } + break; + } + + case 1: { + if (!pusharray32(value->TLVs[i].value.ptr, byte_len, byte_len, ppWritePackedMsg, end)) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s():%d. value->TLVs[i].length %d \n", __FUNCTION__, __LINE__, value->TLVs[i].length); + return 0; + } + + break; + } + + default: { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "FIXME : Invalid tag value %d \n", value->TLVs[i].tag); + break; + } + } + } + + return 1; +} + +uint8_t pack_tx_data_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) +{ + nfapi_nr_tx_data_request_t *pNfapiMsg = (nfapi_nr_tx_data_request_t *)msg; + + if (!(push16(pNfapiMsg->SFN, ppWritePackedMsg, end) && push16(pNfapiMsg->Slot, ppWritePackedMsg, end) + && push16(pNfapiMsg->Number_of_PDUs, ppWritePackedMsg, end))) + return 0; + + for (int i = 0; i < pNfapiMsg->Number_of_PDUs; i++) { + if (!pack_tx_data_pdu_list_value(&pNfapiMsg->pdu_list[i], ppWritePackedMsg, end)) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, + "%s():%d. Error packing TX_DATA.request PDU #%d, PDU length = %d PDU IDX = %d\n", + __FUNCTION__, + __LINE__, + i, + pNfapiMsg->pdu_list[i].PDU_length, + pNfapiMsg->pdu_list[i].PDU_index); + return 0; + } + } + + return 1; +} + +static uint8_t unpack_tx_data_pdu_list_value(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg) +{ + nfapi_nr_pdu_t *pNfapiMsg = (nfapi_nr_pdu_t *)msg; + + if (!(pull32(ppReadPackedMsg, &pNfapiMsg->PDU_length, end) && pull16(ppReadPackedMsg, &pNfapiMsg->PDU_index, end) + && pull32(ppReadPackedMsg, &pNfapiMsg->num_TLV, end))) + return 0; + + for (int i = 0; i < pNfapiMsg->num_TLV; ++i) { + if (!(pull16(ppReadPackedMsg, &pNfapiMsg->TLVs[i].tag, end) && pull32(ppReadPackedMsg, &pNfapiMsg->TLVs[i].length, end))) + return 0; + const uint32_t byte_len = (pNfapiMsg->TLVs[i].length + 3) / 4; + if (pNfapiMsg->TLVs[i].tag == 1) { + pNfapiMsg->TLVs[i].value.ptr = calloc(byte_len, sizeof(uint32_t)); + } + switch (pNfapiMsg->TLVs[i].tag) { + case 0: { + if (!pullarray32(ppReadPackedMsg, + pNfapiMsg->TLVs[i].value.direct, + sizeof(pNfapiMsg->TLVs[i].value.direct) / sizeof(uint32_t), + byte_len, + end)) + return 0; + + break; + } + + case 1: { + if (!pullarray32(ppReadPackedMsg, pNfapiMsg->TLVs[i].value.ptr, byte_len, byte_len, end)) + return 0; + + break; + } + + default: { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "FIXME : Invalid tag value %d \n", pNfapiMsg->TLVs[i].tag); + return 0; + } + } + } + + return 1; +} + +uint8_t unpack_tx_data_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) +{ + nfapi_nr_tx_data_request_t *pNfapiMsg = (nfapi_nr_tx_data_request_t *)msg; + + if (!(pull16(ppReadPackedMsg, &pNfapiMsg->SFN, end) && pull16(ppReadPackedMsg, &pNfapiMsg->Slot, end) + && pull16(ppReadPackedMsg, &pNfapiMsg->Number_of_PDUs, end))) + return 0; + + for (int i = 0; i < pNfapiMsg->Number_of_PDUs; i++) { + if (!unpack_tx_data_pdu_list_value(ppReadPackedMsg, end, &pNfapiMsg->pdu_list[i])) { + return 0; + } + } + + return 1; +} diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nr_nfapi_p7.h b/nfapi/open-nFAPI/nfapi/public_inc/nr_nfapi_p7.h index 79f59f3922..0c57ad675e 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nr_nfapi_p7.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nr_nfapi_p7.h @@ -51,8 +51,6 @@ uint8_t pack_nr_crc_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *e uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); -uint8_t pack_tx_data_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); - uint8_t pack_nr_srs_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); uint8_t pack_nr_rach_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config); @@ -75,8 +73,6 @@ uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg, nfapi_nr_rach_indication_t *msg, nfapi_p7_codec_config_t *config); -uint8_t unpack_tx_data_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config); - uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_nr_rx_data_indication_t *msg, diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index 437e67820b..d1182d01b4 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -1394,52 +1394,6 @@ static uint8_t pack_hi_dci0_request(void *msg, uint8_t **ppWritePackedMsg, uint8 } //pack_tx_data_pdu_list_value -static uint8_t pack_tx_data_pdu_list_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) -{ - nfapi_nr_pdu_t *value = (nfapi_nr_pdu_t *)tlv; - if (!(push32(value->PDU_length, ppWritePackedMsg, end) && push16(value->PDU_index, ppWritePackedMsg, end) - && push32(value->num_TLV, ppWritePackedMsg, end))) - return 0; - - for (int i = 0; i < value->num_TLV; ++i) { - if (!(push16(value->TLVs[i].tag, ppWritePackedMsg, end) && push32(value->TLVs[i].length, ppWritePackedMsg, end))) - return 0; - - switch (value->TLVs[i].tag) { - case 0: { - if (!pusharray32(value->TLVs[i].value.direct, - (value->TLVs[i].length + 3) / 4, - (value->TLVs[i].length + 3) / 4, - ppWritePackedMsg, - end)) { - NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s():%d. value->TLVs[i].length %d \n", __FUNCTION__, __LINE__, value->TLVs[i].length); - return 0; - } - break; - } - - case 1: { - if (!pusharray32(value->TLVs[i].value.ptr, - (value->TLVs[i].length + 3) / 4, - (value->TLVs[i].length + 3) / 4, - ppWritePackedMsg, - end)) { - NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s():%d. value->TLVs[i].length %d \n", __FUNCTION__, __LINE__, value->TLVs[i].length); - return 0; - } - - break; - } - - default: { - NFAPI_TRACE(NFAPI_TRACE_ERROR, "FIXME : Invalid tag value %d \n", value->TLVs[i].tag); - break; - } - } - } - - return 1; -} static uint8_t pack_tx_request_body_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) { nfapi_tx_request_body_t *value = (nfapi_tx_request_body_t *)tlv; @@ -1484,30 +1438,6 @@ static uint8_t pack_tx_request_body_value(void *tlv, uint8_t **ppWritePackedMsg, return 1; } -uint8_t pack_tx_data_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) -{ - nfapi_nr_tx_data_request_t *pNfapiMsg = (nfapi_nr_tx_data_request_t *)msg; - - if (!(push16(pNfapiMsg->SFN, ppWritePackedMsg, end) && push16(pNfapiMsg->Slot, ppWritePackedMsg, end) - && push16(pNfapiMsg->Number_of_PDUs, ppWritePackedMsg, end))) - return 0; - - for (int i = 0; i < pNfapiMsg->Number_of_PDUs; i++) { - if (!pack_tx_data_pdu_list_value(&pNfapiMsg->pdu_list[i], ppWritePackedMsg, end)) { - NFAPI_TRACE(NFAPI_TRACE_ERROR, - "%s():%d. Error packing TX_DATA.request PDU #%d, PDU length = %d PDU IDX = %d\n", - __FUNCTION__, - __LINE__, - i, - pNfapiMsg->pdu_list[i].PDU_length, - pNfapiMsg->pdu_list[i].PDU_index); - return 0; - } - } - - return 1; -} - static uint8_t pack_tx_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) { nfapi_tx_request_t *pNfapiMsg = (nfapi_tx_request_t *)msg; int x = push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end); @@ -4661,66 +4591,6 @@ static uint8_t unpack_hi_dci0_request(uint8_t **ppReadPackedMsg, uint8_t *end, v return (pull16(ppReadPackedMsg, &pNfapiMsg->sfn_sf, end) && unpack_p7_tlv_list(unpack_fns, sizeof(unpack_fns)/sizeof(unpack_tlv_t), ppReadPackedMsg, end, config, &pNfapiMsg->vendor_extension)); } -static uint8_t unpack_tx_data_pdu_list_value(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg) { - nfapi_nr_pdu_t *pNfapiMsg = (nfapi_nr_pdu_t *)msg; - - if (!(pull32(ppReadPackedMsg, &pNfapiMsg->PDU_length, end) && pull16(ppReadPackedMsg, &pNfapiMsg->PDU_index, end) - && pull32(ppReadPackedMsg, &pNfapiMsg->num_TLV, end))) - return 0; - - for (int i = 0; i < pNfapiMsg->num_TLV; ++i) { - if (!(pull16(ppReadPackedMsg, &pNfapiMsg->TLVs[i].tag, end) && pull32(ppReadPackedMsg, &pNfapiMsg->TLVs[i].length, end))) - return 0; - if (pNfapiMsg->TLVs[i].tag == 1) { - pNfapiMsg->TLVs[i].value.ptr = calloc((pNfapiMsg->TLVs[i].length + 3) / 4, sizeof(uint32_t)); - } - switch(pNfapiMsg->TLVs[i].tag) { - case 0: { - if (!pullarray32(ppReadPackedMsg, pNfapiMsg->TLVs[i].value.direct, - sizeof(pNfapiMsg->TLVs[i].value.direct) / sizeof(uint32_t), - (pNfapiMsg->TLVs[i].length+3)/4, end)) - return 0; - - break; - } - - case 1: { - if (!pullarray32(ppReadPackedMsg, - pNfapiMsg->TLVs[i].value.ptr, - (pNfapiMsg->TLVs[i].length + 3) / 4, - (pNfapiMsg->TLVs[i].length + 3) / 4, - end)) - return 0; - - break; - } - - default: { - NFAPI_TRACE(NFAPI_TRACE_ERROR, "FIXME : Invalid tag value %d \n", pNfapiMsg->TLVs[i].tag ); - break; - } - } - } - - return 1; -} - -uint8_t unpack_tx_data_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) -{ - nfapi_nr_tx_data_request_t *pNfapiMsg = (nfapi_nr_tx_data_request_t *)msg; - - if (!(pull16(ppReadPackedMsg, &pNfapiMsg->SFN, end) && pull16(ppReadPackedMsg, &pNfapiMsg->Slot, end) - && pull16(ppReadPackedMsg, &pNfapiMsg->Number_of_PDUs, end))) - return 0; - - for (int i = 0; i < pNfapiMsg->Number_of_PDUs; i++) { - if (!unpack_tx_data_pdu_list_value(ppReadPackedMsg, end, &pNfapiMsg->pdu_list[i])) { - return 0; - } - } - - return 1; -} static uint8_t unpack_tx_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) { uint8_t proceed = 1; diff --git a/nfapi/tests/p7/CMakeLists.txt b/nfapi/tests/p7/CMakeLists.txt index 32e33f7ae6..e79227c95a 100644 --- a/nfapi/tests/p7/CMakeLists.txt +++ b/nfapi/tests/p7/CMakeLists.txt @@ -1,5 +1,5 @@ set(Test_Labels fapi p7) -set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request") +set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request;tx_data_request") foreach (fapi_p7_message IN LISTS _fapi_p7_messages) add_executable(nr_fapi_${fapi_p7_message}_test nr_fapi_${fapi_p7_message}_test.c) target_link_libraries(nr_fapi_${fapi_p7_message}_test PUBLIC nr_fapi_p7) diff --git a/nfapi/tests/p7/nr_fapi_tx_data_request_test.c b/nfapi/tests/p7/nr_fapi_tx_data_request_test.c new file mode 100644 index 0000000000..e67b5bf3ca --- /dev/null +++ b/nfapi/tests/p7/nr_fapi_tx_data_request_test.c @@ -0,0 +1,176 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ +#include "dci_payload_utils.h" +#include "nr_fapi_p7.h" +#include "nr_fapi_p7_utils.h" + +static void fill_tx_data_request_PDU(nfapi_nr_pdu_t *pdu) +{ + // PDU_Length The total length (in bytes) of the PDU description and PDU data, without the padding bytes. + // Minimum length = 4 PDULength + 2 PDUIndex + 4 numTLV + 2 tag + 4 length + 4 value = 20 + // ( assuming 1 TLV and "empty payload" sends 4 bytes of zeroes - For testing purposes only ) + // Max Length => 10 bytes PDU Header + 2 * (2 bytes tag, 4 bytes length, 38016*4 bytes value (on value.direct)) + // = 304150 + pdu->PDU_index = rand16(); + pdu->num_TLV = rand8_range(1, NFAPI_NR_MAX_TX_REQUEST_TLV); + pdu->PDU_length = rand32_range(20, 10 + pdu->num_TLV * (4 + (38016 * 4))); + uint32_t remaining_size = pdu->PDU_length - 10 - (pdu->num_TLV * 4); + for (int tlv_idx = 0; tlv_idx < pdu->num_TLV; ++tlv_idx) { + nfapi_nr_tx_data_request_tlv_t *tlv = &pdu->TLVs[tlv_idx]; + tlv->tag = rand16_range(0, 1); + uint32_t maxSize = 0; + if (tlv->tag == 0) { + maxSize = sizeof(tlv->value.direct); + } else { + maxSize = (remaining_size / pdu->num_TLV); + } + if (pdu->num_TLV == 1) { + tlv->length = remaining_size; + } else { + if (tlv_idx == pdu->num_TLV - 1) { + tlv->length = min(maxSize, sizeof(tlv->value.direct)); + } else { + tlv->length = min(rand32_range(0, maxSize), sizeof(tlv->value.direct)); + remaining_size -= tlv->length - 4; + } + } + switch (tlv->tag) { + case 0: + // value.direct + if (tlv->length % 4 != 0) { + for (int idx = 0; idx < ((tlv->length + 3) / 4) - 1; ++idx) { + tlv->value.direct[idx] = rand32(); + } + uint32_t bytesToAdd = 4 - (4 - (tlv->length % 4)) % 4; + if (bytesToAdd != 4) { + for (int j = 0; j < bytesToAdd; j++) { + tlv->value.direct[((tlv->length + 3) / 4) - 1] |= rand8(); + tlv->value.direct[((tlv->length + 3) / 4) - 1] = tlv->value.direct[((tlv->length + 3) / 4) - 1] << (j * 8); + } + } + } else { + // no padding needed + for (int idx = 0; idx < (tlv->length + 3) / 4; ++idx) { + tlv->value.direct[idx] = rand32(); + } + } + break; + case 1: + // value.ptr + tlv->value.ptr = calloc((tlv->length + 3) / 4, sizeof(uint32_t)); + if (tlv->length % 4 != 0) { + for (int idx = 0; idx < ((tlv->length + 3) / 4) - 1; ++idx) { + tlv->value.ptr[idx] = rand32(); + } + uint32_t bytesToAdd = 4 - (4 - (tlv->length % 4)) % 4; + if (bytesToAdd != 4) { + uint32_t value = 0; + for (int j = 0; j < bytesToAdd; j++) { + value |= rand8() << (j * 8); + } + tlv->value.ptr[((tlv->length + 3) / 4) - 1] = value; + } + } else { + // no padding needed + for (int idx = 0; idx < (tlv->length + 3) / 4; ++idx) { + tlv->value.ptr[idx] = rand32(); + } + } + break; + default: + AssertFatal(1 == 0, "Unsupported tag value %d\n", tlv->tag); + } + } +} + +static void fill_tx_data_request(nfapi_nr_tx_data_request_t *msg) +{ + msg->SFN = rand16_range(0, 1023); + msg->Slot = rand16_range(0, 159); + msg->Number_of_PDUs = rand8_range(1, NFAPI_NR_MAX_TX_REQUEST_PDUS); // Minimum 1 PDUs in order to test at least one + for (int pdu_idx = 0; pdu_idx < msg->Number_of_PDUs; ++pdu_idx) { + fill_tx_data_request_PDU(&msg->pdu_list[pdu_idx]); + } +} + +static void test_pack_unpack(nfapi_nr_tx_data_request_t *req) +{ + size_t message_size = get_tx_data_request_size(req); + uint8_t *msg_buf = calloc_or_fail(message_size, sizeof(uint8_t)); + /*uint8_t msg_buf[1024*1024*3]; + size_t message_size = sizeof(msg_buf);*/ + // first test the packing procedure + int pack_result = fapi_nr_p7_message_pack(req, msg_buf, message_size, NULL); + + DevAssert(pack_result >= 0 + NFAPI_HEADER_LENGTH); + // update req message_length value with value calculated in message_pack procedure + req->header.message_length = pack_result; //- NFAPI_HEADER_LENGTH; + // test the unpacking of the header + // copy first NFAPI_HEADER_LENGTH bytes into a new buffer, to simulate SCTP PEEK + fapi_message_header_t header; + uint32_t header_buffer_size = NFAPI_HEADER_LENGTH; + uint8_t header_buffer[header_buffer_size]; + for (int idx = 0; idx < header_buffer_size; idx++) { + header_buffer[idx] = msg_buf[idx]; + } + uint8_t *pReadPackedMessage = header_buffer; + int unpack_header_result = fapi_nr_message_header_unpack(&pReadPackedMessage, NFAPI_HEADER_LENGTH, &header, sizeof(header), 0); + DevAssert(unpack_header_result >= 0); + DevAssert(header.message_id == req->header.message_id); + DevAssert(header.message_length == req->header.message_length); + // test the unpacking and compare with initial message + nfapi_nr_tx_data_request_t unpacked_req = {0}; + int unpack_result = + fapi_nr_p7_message_unpack(msg_buf, header.message_length + NFAPI_HEADER_LENGTH, &unpacked_req, sizeof(unpacked_req), 0); + DevAssert(unpack_result >= 0); + DevAssert(eq_tx_data_request(&unpacked_req, req)); + free_tx_data_request(&unpacked_req); + free(msg_buf); +} + +static void test_copy(const nfapi_nr_tx_data_request_t *msg) +{ + // Test copy function + nfapi_nr_tx_data_request_t copy = {0}; + copy_tx_data_request(msg, ©); + DevAssert(eq_tx_data_request(msg, ©)); + free_tx_data_request(©); +} + +int main(int n, char *v[]) +{ + fapi_test_init(); + + nfapi_nr_tx_data_request_t *req = calloc_or_fail(1, sizeof(nfapi_nr_tx_data_request_t)); + req->header.message_id = NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST; + // Get the actual allocated size + printf("Allocated size before filling: %zu bytes\n", get_tx_data_request_size(req)); + // Fill TX_DATA request + fill_tx_data_request(req); + printf("Allocated size after filling: %zu bytes\n", get_tx_data_request_size(req)); + // Perform tests + test_pack_unpack(req); + test_copy(req); + // All tests successful! + free_tx_data_request(req); + free(req); + return 0; +}