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.
This commit is contained in:
Guido Casati
2025-06-05 11:35:51 +02:00
parent 615f5ef663
commit 5e2d7638d1
3 changed files with 17 additions and 12 deletions
@@ -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;
}
}
@@ -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_ */
+2 -12
View File
@@ -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],