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

Remove unneeded variables from TX_DATA.request pack/unpack functions

Allocate memory for TX_DATA.request TLV value pointer on tag == 1
In the past, this wasn't noticed because tag == 1 is not used

Add utility functions related to TX_DATA.request
Add extra function to calculate allocated memory
parent 00145559
......@@ -39,15 +39,19 @@ bool eq_dl_tti_request(const nfapi_nr_dl_tti_request_t *a, const nfapi_nr_dl_tti
bool eq_ul_tti_request(const nfapi_nr_ul_tti_request_t *a, const nfapi_nr_ul_tti_request_t *b);
bool eq_slot_indication(const nfapi_nr_slot_indication_scf_t *a, const nfapi_nr_slot_indication_scf_t *b);
bool eq_ul_dci_request(const nfapi_nr_ul_dci_request_t *a, const nfapi_nr_ul_dci_request_t *b);
bool eq_tx_data_request(const nfapi_nr_tx_data_request_t *a, const nfapi_nr_tx_data_request_t *b);
void free_dl_tti_request(nfapi_nr_dl_tti_request_t *msg);
void free_ul_tti_request(nfapi_nr_ul_tti_request_t *msg);
void free_slot_indication(nfapi_nr_slot_indication_scf_t *msg);
void free_ul_dci_request(nfapi_nr_ul_dci_request_t *msg);
void free_tx_data_request(nfapi_nr_tx_data_request_t *msg);
void copy_dl_tti_request(const nfapi_nr_dl_tti_request_t *src, nfapi_nr_dl_tti_request_t *dst);
void copy_ul_tti_request(const nfapi_nr_ul_tti_request_t *src, nfapi_nr_ul_tti_request_t *dst);
void copy_slot_indication(const nfapi_nr_slot_indication_scf_t *src, nfapi_nr_slot_indication_scf_t *dst);
void copy_ul_dci_request(const nfapi_nr_ul_dci_request_t *src, nfapi_nr_ul_dci_request_t *dst);
void copy_tx_data_request(const nfapi_nr_tx_data_request_t *src, nfapi_nr_tx_data_request_t *dst);
size_t get_tx_data_request_size(const nfapi_nr_tx_data_request_t *msg);
#endif // OPENAIRINTERFACE_NR_FAPI_P7_UTILS_H
......@@ -20,6 +20,8 @@
*/
#include "nr_fapi_p7_utils.h"
#include <malloc.h>
static bool eq_dl_tti_beamforming(const nfapi_nr_tx_precoding_and_beamforming_t *a,
const nfapi_nr_tx_precoding_and_beamforming_t *b)
{
......@@ -520,6 +522,50 @@ bool eq_ul_dci_request(const nfapi_nr_ul_dci_request_t *a, const nfapi_nr_ul_dci
return true;
}
bool eq_tx_data_request_PDU(const nfapi_nr_pdu_t *a, const nfapi_nr_pdu_t *b)
{
EQ(a->PDU_length, b->PDU_length);
EQ(a->PDU_index, b->PDU_index);
EQ(a->num_TLV, b->num_TLV);
for (int tlv_idx = 0; tlv_idx < a->num_TLV; ++tlv_idx) {
const nfapi_nr_tx_data_request_tlv_t *a_tlv = &a->TLVs[tlv_idx];
const nfapi_nr_tx_data_request_tlv_t *b_tlv = &b->TLVs[tlv_idx];
EQ(a_tlv->tag, b_tlv->tag);
EQ(a_tlv->length, b_tlv->length);
switch (a_tlv->tag) {
case 0:
for (int payload_idx = 0; payload_idx < (a_tlv->length + 3) / 4; ++payload_idx) {
// value.direct
EQ(a_tlv->value.direct[payload_idx], b_tlv->value.direct[payload_idx]);
}
break;
case 1:
for (int payload_idx = 0; payload_idx < (a_tlv->length + 3) / 4; ++payload_idx) {
// value.ptr
EQ(a_tlv->value.ptr[payload_idx], b_tlv->value.ptr[payload_idx]);
}
break;
default:
break;
}
}
return true;
}
bool eq_tx_data_request(const nfapi_nr_tx_data_request_t *a, const nfapi_nr_tx_data_request_t *b)
{
EQ(a->header.message_id, b->header.message_id);
EQ(a->header.message_length, b->header.message_length);
EQ(a->SFN, b->SFN);
EQ(a->Slot, b->Slot);
EQ(a->Number_of_PDUs, b->Number_of_PDUs);
for (int pdu_idx = 0; pdu_idx < a->Number_of_PDUs; ++pdu_idx) {
EQ(eq_tx_data_request_PDU(&a->pdu_list[pdu_idx], &b->pdu_list[pdu_idx]), true);
}
return true;
}
void free_dl_tti_request(nfapi_nr_dl_tti_request_t *msg)
{
if (msg->vendor_extension) {
......@@ -551,6 +597,20 @@ void free_ul_dci_request(nfapi_nr_ul_dci_request_t *msg)
// Nothing to free
}
void free_tx_data_request(nfapi_nr_tx_data_request_t *msg)
{
for (int pdu_idx = 0; pdu_idx < msg->Number_of_PDUs; ++pdu_idx) {
nfapi_nr_pdu_t *pdu = &msg->pdu_list[pdu_idx];
for (int tlv_idx = 0; tlv_idx < pdu->num_TLV; ++tlv_idx) {
nfapi_nr_tx_data_request_tlv_t *tlv = &pdu->TLVs[tlv_idx];
if (tlv->tag == 1) {
// value.ptr
free(tlv->value.ptr);
}
}
}
}
static void copy_dl_tti_beamforming(const nfapi_nr_tx_precoding_and_beamforming_t *src,
nfapi_nr_tx_precoding_and_beamforming_t *dst)
{
......@@ -1042,3 +1102,69 @@ void copy_ul_dci_request(const nfapi_nr_ul_dci_request_t *src, nfapi_nr_ul_dci_r
copy_ul_dci_request_pdu(&src->ul_dci_pdu_list[pdu_idx], &dst->ul_dci_pdu_list[pdu_idx]);
}
}
void copy_tx_data_request_PDU(const nfapi_nr_pdu_t *src, nfapi_nr_pdu_t *dst)
{
dst->PDU_length = src->PDU_length;
dst->PDU_index = src->PDU_index;
dst->num_TLV = src->num_TLV;
for (int tlv_idx = 0; tlv_idx < src->num_TLV; ++tlv_idx) {
const nfapi_nr_tx_data_request_tlv_t *src_tlv = &src->TLVs[tlv_idx];
nfapi_nr_tx_data_request_tlv_t *dst_tlv = &dst->TLVs[tlv_idx];
dst_tlv->tag = src_tlv->tag;
dst_tlv->length = src_tlv->length;
switch (src_tlv->tag) {
case 0:
// value.direct
memcpy(dst_tlv->value.direct, src_tlv->value.direct, sizeof(src_tlv->value.direct));
break;
case 1:
// value.ptr
dst_tlv->value.ptr = calloc((src_tlv->length + 3) / 4, sizeof(uint32_t));
memcpy(dst_tlv->value.ptr, src_tlv->value.ptr, src_tlv->length);
break;
default:
AssertFatal(1 == 0, "TX_DATA request TLV tag value unsupported");
break;
}
}
}
void copy_tx_data_request(const nfapi_nr_tx_data_request_t *src, nfapi_nr_tx_data_request_t *dst)
{
dst->header.message_id = src->header.message_id;
dst->header.message_length = src->header.message_length;
dst->SFN = src->SFN;
dst->Slot = src->Slot;
dst->Number_of_PDUs = src->Number_of_PDUs;
for (int pdu_idx = 0; pdu_idx < src->Number_of_PDUs; ++pdu_idx) {
copy_tx_data_request_PDU(&src->pdu_list[pdu_idx], &dst->pdu_list[pdu_idx]);
}
}
size_t get_tx_data_request_size(const nfapi_nr_tx_data_request_t *msg)
{
// Get size of the whole message ( allocated pointer included )
size_t total_size = sizeof(msg->header);
total_size += sizeof(msg->SFN);
total_size += sizeof(msg->Slot);
total_size += sizeof(msg->Number_of_PDUs);
for (int pdu_idx = 0; pdu_idx < msg->Number_of_PDUs; ++pdu_idx) {
const nfapi_nr_pdu_t *pdu = &msg->pdu_list[pdu_idx];
total_size += sizeof(pdu->PDU_length);
total_size += sizeof(pdu->PDU_index);
total_size += sizeof(pdu->num_TLV);
for (int tlv_idx = 0; tlv_idx < pdu->num_TLV; ++tlv_idx) {
const nfapi_nr_tx_data_request_tlv_t *tlv = &pdu->TLVs[tlv_idx];
total_size += sizeof(tlv->tag);
total_size += sizeof(tlv->length);
if (tlv->tag == 0) {
total_size += sizeof(tlv->value.direct);
} else {
total_size += (tlv->length + 3) / 4 * sizeof(uint32_t);
}
}
}
return total_size;
}
......@@ -1401,10 +1401,7 @@ static uint8_t pack_tx_data_pdu_list_value(void *tlv, uint8_t **ppWritePackedMsg
&& push32(value->num_TLV, ppWritePackedMsg, end)))
return 0;
uint16_t i = 0;
uint16_t total_number_of_tlvs = value->num_TLV;
for (; i < total_number_of_tlvs; ++i) {
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;
......@@ -4671,13 +4668,12 @@ static uint8_t unpack_tx_data_pdu_list_value(uint8_t **ppReadPackedMsg, uint8_t
&& pull32(ppReadPackedMsg, &pNfapiMsg->num_TLV, end)))
return 0;
uint16_t i = 0;
uint16_t total_number_of_tlvs = pNfapiMsg->num_TLV;
for(; i < total_number_of_tlvs; ++i) {
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,
......
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