Commit aeac2b0d authored by Rúben Soares Silva's avatar Rúben Soares Silva Committed by Robert Schmidt

Move functions for packing/unpacking RX_DATA.indication

Changed parameter of unpack_nr_rx_data_indication to void* to be inline with other unpack procedures.
Changed nfapi_p7_allocate calls to calloc to avoid dependency from FAPI lib to nFAPI lib.
Add unitary test for RX_DATA.indication( test pack/unpack, free, copy and compare )
parent 3ec9006f
......@@ -42,5 +42,6 @@ uint8_t pack_ul_dci_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end,
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);
uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
#endif // OPENAIRINTERFACE_NR_FAPI_P7_H
......@@ -46,6 +46,9 @@ uint8_t fapi_nr_p7_message_body_pack(nfapi_nr_p7_message_header_t *header,
case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST:
result = pack_tx_data_request(header, ppWritePackedMsg, end, config);
break;
case NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION:
result = pack_nr_rx_data_indication(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) {
......@@ -168,6 +171,11 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf,
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;
case NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION:
if (check_nr_fapi_unpack_length(NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION, unpackedBufLen)) {
result = unpack_nr_rx_data_indication(&pReadPackedMessage, end, pMessageHeader, config);
}
break;
default:
if (pMessageHeader->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && pMessageHeader->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
......@@ -1585,3 +1593,73 @@ uint8_t unpack_tx_data_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *ms
return 1;
}
static uint8_t pack_nr_rx_data_indication_body(const nfapi_nr_rx_data_pdu_t *value, uint8_t **ppWritePackedMsg, uint8_t *end)
{
if (!(push32(value->handle, ppWritePackedMsg, end) && push16(value->rnti, ppWritePackedMsg, end)
&& push8(value->harq_id, ppWritePackedMsg, end) && push32(value->pdu_length, ppWritePackedMsg, end)
&& push8(value->ul_cqi, ppWritePackedMsg, end) && push16(value->timing_advance, ppWritePackedMsg, end)
&& push16(value->rssi, ppWritePackedMsg, end)))
return 0;
if (pusharray8(value->pdu, value->pdu_length, value->pdu_length, ppWritePackedMsg, end) == 0)
return 0;
return 1;
}
uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
{
nfapi_nr_rx_data_indication_t *pNfapiMsg = (nfapi_nr_rx_data_indication_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_nr_rx_data_indication_body(&(pNfapiMsg->pdu_list[i]), ppWritePackedMsg, end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_rx_data_indication_body(nfapi_nr_rx_data_pdu_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!(pull32(ppReadPackedMsg, &value->handle, end) && pull16(ppReadPackedMsg, &value->rnti, end)
&& pull8(ppReadPackedMsg, &value->harq_id, end) && pull32(ppReadPackedMsg, &value->pdu_length, end)
&& pull8(ppReadPackedMsg, &value->ul_cqi, end) && pull16(ppReadPackedMsg, &value->timing_advance, end)
&& pull16(ppReadPackedMsg, &value->rssi, end)))
return 0;
const uint32_t length = value->pdu_length;
value->pdu = calloc(length, sizeof(*value->pdu));
if (pullarray8(ppReadPackedMsg, value->pdu, length, length, end) == 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pullarray8 failure\n", __FUNCTION__);
return 0;
}
return 1;
}
uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config)
{
nfapi_nr_rx_data_indication_t *pNfapiMsg = (nfapi_nr_rx_data_indication_t *)msg;
if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end) && pull16(ppReadPackedMsg, &pNfapiMsg->slot, end)
&& pull16(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end)))
return 0;
if (pNfapiMsg->number_of_pdus > 0) {
pNfapiMsg->pdu_list = calloc(pNfapiMsg->number_of_pdus, sizeof(*pNfapiMsg->pdu_list));
}
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++) {
if (!unpack_nr_rx_data_indication_body(&pNfapiMsg->pdu_list[i], ppReadPackedMsg, end, config))
return 0;
}
return 1;
}
......@@ -45,8 +45,6 @@ uint8_t pack_ue_release_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *
uint8_t pack_ue_release_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_crc_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
......@@ -73,9 +71,4 @@ uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg,
nfapi_nr_rach_indication_t *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,
nfapi_p7_codec_config_t *config);
#endif // OPENAIRINTERFACE_NR_NFAPI_P7_H
......@@ -2471,42 +2471,6 @@ uint8_t pack_nr_timing_info(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end,
//NR UPLINK indication function packing
//RX DATA INDICATION
static uint8_t pack_nr_rx_data_indication_body(nfapi_nr_rx_data_pdu_t *value, uint8_t **ppWritePackedMsg, uint8_t *end)
{
if(!(push32(value->handle, ppWritePackedMsg, end)
&& push16(value->rnti, ppWritePackedMsg, end)
&& push8(value->harq_id, ppWritePackedMsg, end)
&& push32(value->pdu_length, ppWritePackedMsg, end)
&& push8(value->ul_cqi, ppWritePackedMsg, end)
&& push16(value->timing_advance, ppWritePackedMsg, end)
&& push16(value->rssi, ppWritePackedMsg, end)
))
return 0;
if (pusharray8(value->pdu, value->pdu_length, value->pdu_length, ppWritePackedMsg, end) == 0)
return 0;
return 1;
}
uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
{
nfapi_nr_rx_data_indication_t *pNfapiMsg = (nfapi_nr_rx_data_indication_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_nr_rx_data_indication_body(&(pNfapiMsg->pdu_list[i]), ppWritePackedMsg, end))
return 0;
}
return 1;
}
//NR CRC INDICATION
static uint8_t pack_nr_crc_indication_body(nfapi_nr_crc_t *value, uint8_t **ppWritePackedMsg, uint8_t *end)
......@@ -4683,57 +4647,6 @@ static uint8_t unpack_tx_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *
//UNPACK NR UPLINK INDICATION FUNCTIONS
//RX DATA INDICATION
static uint8_t unpack_nr_rx_data_indication_body(nfapi_nr_rx_data_pdu_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!(pull32(ppReadPackedMsg, &value->handle, end)
&& pull16(ppReadPackedMsg, &value->rnti, end)
&& pull8(ppReadPackedMsg, &value->harq_id, end)
&& pull32(ppReadPackedMsg, &value->pdu_length, end)
&& pull8(ppReadPackedMsg, &value->ul_cqi, end)
&& pull16(ppReadPackedMsg, &value->timing_advance, end)
&& pull16(ppReadPackedMsg, &value->rssi, end)))
return 0;
value->pdu = nfapi_p7_allocate(sizeof(*value->pdu) * value->pdu_length, config);
if (pullarray8(ppReadPackedMsg, value->pdu, value->pdu_length, value->pdu_length, end) == 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pullarray8 failure\n", __FUNCTION__);
return 0;
}
return 1;
}
uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_nr_rx_data_indication_t *msg,
nfapi_p7_codec_config_t *config)
{
nfapi_nr_rx_data_indication_t *pNfapiMsg = (nfapi_nr_rx_data_indication_t*)msg;
if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn , end) &&
pull16(ppReadPackedMsg, &pNfapiMsg->slot , end) &&
pull16(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end)
))
return 0;
if (pNfapiMsg->number_of_pdus > 0)
{
pNfapiMsg->pdu_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->pdu_list) * pNfapiMsg->number_of_pdus, config);
}
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++)
{
if(!unpack_nr_rx_data_indication_body(&pNfapiMsg->pdu_list[i], ppReadPackedMsg, end, config))
return 0;
}
return 1;
}
//NR CRC INDICATION
uint8_t unpack_nr_crc_indication_body(nfapi_nr_crc_t *value, uint8_t **ppReadPackedMsg, uint8_t *end)
......
set(Test_Labels fapi p7)
set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request;tx_data_request")
set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request;tx_data_request;rx_data_indication")
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)
......
/*
* 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_rx_data_indication_PDU(nfapi_nr_rx_data_pdu_t *pdu)
{
pdu->handle = rand32();
pdu->rnti = rand16_range(1, 65535);
pdu->harq_id = rand8_range(0, 15);
pdu->pdu_length = rand32_range(0, 65535 * 100); // Testing to a maximum of 100 times 2^16, to test 32 bit would take too long
pdu->ul_cqi = rand8();
pdu->timing_advance = rand16_range(0, 63);
pdu->rssi = rand16_range(0, 1280);
pdu->pdu = calloc_or_fail(pdu->pdu_length, sizeof(uint8_t));
for (int i = 0; i < pdu->pdu_length; ++i) {
pdu->pdu[i] = rand8();
}
}
static void fill_rx_data_indication(nfapi_nr_rx_data_indication_t *msg)
{
msg->sfn = rand16_range(0, 1023);
msg->slot = rand16_range(0, 159);
msg->number_of_pdus = rand8_range(1, NFAPI_NR_RX_DATA_IND_MAX_PDU); // Minimum 1 PDUs in order to test at least one
msg->pdu_list = calloc_or_fail(msg->number_of_pdus, sizeof(*msg->pdu_list));
for (int pdu_idx = 0; pdu_idx < msg->number_of_pdus; ++pdu_idx) {
fill_rx_data_indication_PDU(&msg->pdu_list[pdu_idx]);
}
}
static void test_pack_unpack(nfapi_nr_rx_data_indication_t *req)
{
const size_t message_size = get_rx_data_indication_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_rx_data_indication_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_rx_data_indication(&unpacked_req, req));
free_rx_data_indication(&unpacked_req);
free(msg_buf);
}
static void test_copy(const nfapi_nr_rx_data_indication_t *msg)
{
// Test copy function
nfapi_nr_rx_data_indication_t copy = {0};
copy_rx_data_indication(msg, &copy);
DevAssert(eq_rx_data_indication(msg, &copy));
free_rx_data_indication(&copy);
}
int main(int n, char *v[])
{
fapi_test_init();
nfapi_nr_rx_data_indication_t *req = calloc_or_fail(1, sizeof(nfapi_nr_rx_data_indication_t));
req->header.message_id = NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION;
// Get the actual allocated size
printf("Allocated size before filling: %zu bytes\n", get_rx_data_indication_size(req));
// Fill TX_DATA request
fill_rx_data_indication(req);
printf("Allocated size after filling: %zu bytes\n", get_rx_data_indication_size(req));
// Perform tests
test_pack_unpack(req);
test_copy(req);
// All tests successful!
free_rx_data_indication(req);
free(req);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment