From 5e2d7638d1e43cca1790c5e85bf87fe1863a506c Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 12 Mar 2025 18:11:22 +0100 Subject: [PATCH] Move allocAddrCopy to NGAP utilities This function is needed also in upcoming NGAP libraries (i.e. N2 Handover) and therefore is moved to the NGAP utilities file. The function converts transport_layer_addr_t data struct to BIT_STRING_t by copying the content of its members. The naming is also updated to tnl_to_bitstring. --- openair3/NGAP/ngap_gNB_management_procedures.c | 12 ++++++++++++ openair3/NGAP/ngap_gNB_management_procedures.h | 3 +++ openair3/NGAP/ngap_gNB_nas_procedures.c | 14 ++------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/openair3/NGAP/ngap_gNB_management_procedures.c b/openair3/NGAP/ngap_gNB_management_procedures.c index e82fd1401b..6ffce99d9c 100644 --- a/openair3/NGAP/ngap_gNB_management_procedures.c +++ b/openair3/NGAP/ngap_gNB_management_procedures.c @@ -39,6 +39,8 @@ #include "queue.h" #include "tree.h" #include "ds/byte_array.h" +#include "BIT_STRING.h" +#include "common/utils/utils.h" static ngap_gNB_internal_data_t ngap_gNB_internal_data; @@ -188,3 +190,13 @@ void ngap_gNB_remove_amf_desc(ngap_gNB_instance_t * instance) free(amf); } } + +void tnl_to_bitstring(BIT_STRING_t *out, const transport_layer_addr_t in) +{ + if (in.length) { + out->buf = malloc_or_fail(in.length); + memcpy(out->buf, in.buffer, in.length); + out->size = in.length; + out->bits_unused = 0; + } +} diff --git a/openair3/NGAP/ngap_gNB_management_procedures.h b/openair3/NGAP/ngap_gNB_management_procedures.h index d71480da30..365fd0dd9d 100644 --- a/openair3/NGAP/ngap_gNB_management_procedures.h +++ b/openair3/NGAP/ngap_gNB_management_procedures.h @@ -29,6 +29,7 @@ */ #include "ds/byte_array.h" +#include "BIT_STRING.h" #ifndef NGAP_GNB_MANAGEMENT_PROCEDURES_H_ #define NGAP_GNB_MANAGEMENT_PROCEDURES_H_ @@ -47,4 +48,6 @@ uint16_t ngap_gNB_fetch_add_global_cnx_id(void); void ngap_gNB_prepare_internal_data(void); +void tnl_to_bitstring(BIT_STRING_t *out, const transport_layer_addr_t in); + #endif /* NGAP_GNB_MANAGEMENT_PROCEDURES_H_ */ diff --git a/openair3/NGAP/ngap_gNB_nas_procedures.c b/openair3/NGAP/ngap_gNB_nas_procedures.c index 7729ffa4f2..10ef36ec2a 100644 --- a/openair3/NGAP/ngap_gNB_nas_procedures.c +++ b/openair3/NGAP/ngap_gNB_nas_procedures.c @@ -58,16 +58,6 @@ #include "s1ap_messages_types.h" #include "xer_encoder.h" -static void allocAddrCopy(BIT_STRING_t *out, transport_layer_addr_t in) -{ - if (in.length) { - out->buf = malloc(in.length); - memcpy(out->buf, in.buffer, in.length); - out->size = in.length; - out->bits_unused = 0; - } -} - /** @brief Selects the AMF instance for a given UE based on identity information. * It attempts to select an AMF using the following prioritized criteria: * 1. GUAMI, if provided and valid (via Region ID, Set ID, Pointer). @@ -621,7 +611,7 @@ int ngap_gNB_initial_ctxt_resp(instance_t instance, ngap_initial_context_setup_r asn1cCalloc(pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel, tmp); GTP_TEID_TO_ASN1(initial_ctxt_resp_p->pdusessions[i].gtp_teid, &tmp->gTP_TEID); - allocAddrCopy(&tmp->transportLayerAddress, initial_ctxt_resp_p->pdusessions[i].gNB_addr); + tnl_to_bitstring(&tmp->transportLayerAddress, initial_ctxt_resp_p->pdusessions[i].gNB_addr); NGAP_DEBUG("initial_ctxt_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld, TEID %u\n", item->pDUSessionID, @@ -936,7 +926,7 @@ int ngap_gNB_pdusession_setup_resp(instance_t instance, ngap_pdusession_setup_re pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.present = NGAP_UPTransportLayerInformation_PR_gTPTunnel; asn1cCalloc(pdusessionTransfer.dLQosFlowPerTNLInformation.uPTransportLayerInformation.choice.gTPTunnel, tmp); GTP_TEID_TO_ASN1(pdusession->gtp_teid, &tmp->gTP_TEID); - allocAddrCopy(&tmp->transportLayerAddress, pdusession->gNB_addr); + tnl_to_bitstring(&tmp->transportLayerAddress, pdusession->gNB_addr); NGAP_DEBUG("pdusession_setup_resp_p: pdusession ID %ld, gnb_addr %d.%d.%d.%d, SIZE %ld, TEID %u\n", item->pDUSessionID, tmp->transportLayerAddress.buf[0],