Replace ngap_pdu_t with byte_array_t
ngap_pdu_t has the same definition as byte_array_t, so it is replaced by the latter. This simplify the stack and reduces duplicated code. Also, add function create_byte_array to copy from an existing buffer to a new byte_array_t and replaced allocCopy with create_byte_array, and adopted OCTET_STRING_fromBuf whenever possible.
This commit is contained in:
@@ -52,15 +52,6 @@
|
||||
#include "oai_asn1.h"
|
||||
#include "queue.h"
|
||||
|
||||
static void allocCopy(ngap_pdu_t *out, OCTET_STRING_t in)
|
||||
{
|
||||
if (in.size) {
|
||||
out->buffer = malloc(in.size);
|
||||
memcpy(out->buffer, in.buf, in.size);
|
||||
}
|
||||
out->length = in.size;
|
||||
}
|
||||
|
||||
char *ngap_direction2String(int ngap_dir) {
|
||||
static char *ngap_direction_String[] = {
|
||||
"", /* Nothing */
|
||||
@@ -772,9 +763,10 @@ static int ngap_gNB_handle_initial_context_request(sctp_assoc_t assoc_id, uint32
|
||||
}
|
||||
|
||||
if (item_p->nAS_PDU) {
|
||||
allocCopy(&msg->pdusession_param[i].nas_pdu, *item_p->nAS_PDU);
|
||||
msg->pdusession_param[i].nas_pdu = create_byte_array(item_p->nAS_PDU->size, item_p->nAS_PDU->buf);
|
||||
}
|
||||
allocCopy(&msg->pdusession_param[i].pdusessionTransfer, item_p->pDUSessionResourceSetupRequestTransfer);
|
||||
OCTET_STRING_t *transfer = &item_p->pDUSessionResourceSetupRequestTransfer;
|
||||
msg->pdusession_param[i].pdusessionTransfer = create_byte_array(transfer->size, transfer->buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,7 +833,7 @@ static int ngap_gNB_handle_initial_context_request(sctp_assoc_t assoc_id, uint32
|
||||
NGAP_ProtocolIE_ID_id_NAS_PDU, false);
|
||||
|
||||
if (ie)
|
||||
allocCopy(&msg->nas_pdu, ie->value.choice.NAS_PDU);
|
||||
msg->nas_pdu = create_byte_array(ie->value.choice.NAS_PDU.size, ie->value.choice.NAS_PDU.buf);
|
||||
|
||||
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
|
||||
|
||||
@@ -985,9 +977,9 @@ static int ngap_gNB_handle_pdusession_setup_request(sctp_assoc_t assoc_id, uint3
|
||||
} else {
|
||||
msg->pdusession_setup_params[i].nssai.sd = 0xffffff;
|
||||
}
|
||||
|
||||
allocCopy(&msg->pdusession_setup_params[i].nas_pdu, *item_p->pDUSessionNAS_PDU);
|
||||
allocCopy(&msg->pdusession_setup_params[i].pdusessionTransfer, item_p->pDUSessionResourceSetupRequestTransfer);
|
||||
OCTET_STRING_t *transfer = &item_p->pDUSessionResourceSetupRequestTransfer;
|
||||
msg->pdusession_setup_params[i].nas_pdu = create_byte_array(item_p->pDUSessionNAS_PDU->size, item_p->pDUSessionNAS_PDU->buf);
|
||||
msg->pdusession_setup_params[i].pdusessionTransfer = create_byte_array(transfer->size, transfer->buf);
|
||||
}
|
||||
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
|
||||
|
||||
@@ -1164,8 +1156,9 @@ static int ngap_gNB_handle_pdusession_modify_request(sctp_assoc_t assoc_id, uint
|
||||
|
||||
// check for the NAS PDU
|
||||
if (item_p->nAS_PDU != NULL && item_p->nAS_PDU->size > 0) {
|
||||
allocCopy(&msg->pdusession_modify_params[i].nas_pdu, *item_p->nAS_PDU);
|
||||
allocCopy(&msg->pdusession_modify_params[i].pdusessionTransfer, item_p->pDUSessionResourceModifyRequestTransfer);
|
||||
msg->pdusession_modify_params[i].nas_pdu = create_byte_array(item_p->nAS_PDU->size, item_p->nAS_PDU->buf);
|
||||
OCTET_STRING_t *transfer = &item_p->pDUSessionResourceModifyRequestTransfer;
|
||||
msg->pdusession_modify_params[i].pdusessionTransfer = create_byte_array(transfer->size, transfer->buf);
|
||||
} else {
|
||||
LOG_W(NGAP, "received pdu session modify with void content for UE %u, pdu session %lu\n", msg->gNB_ue_ngap_id, item_p->pDUSessionID);
|
||||
continue;
|
||||
@@ -1241,7 +1234,7 @@ static int ngap_gNB_handle_pdusession_release_command(sctp_assoc_t assoc_id, uin
|
||||
NGAP_ProtocolIE_ID_id_NAS_PDU, false);
|
||||
|
||||
if (ie)
|
||||
allocCopy(&msg->nas_pdu, ie->value.choice.NAS_PDU);
|
||||
msg->nas_pdu = create_byte_array(ie->value.choice.NAS_PDU.size, ie->value.choice.NAS_PDU.buf);
|
||||
|
||||
/* id-PDUSessionResourceToReleaseListRelCmd */
|
||||
NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
|
||||
@@ -1252,8 +1245,9 @@ static int ngap_gNB_handle_pdusession_release_command(sctp_assoc_t assoc_id, uin
|
||||
for (i = 0; i < ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count; i++) {
|
||||
NGAP_PDUSessionResourceToReleaseItemRelCmd_t *item_p;
|
||||
item_p = ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.array[i];
|
||||
msg->pdusession_release_params[i].pdusession_id = item_p->pDUSessionID;
|
||||
allocCopy(&msg->pdusession_release_params[i].data, item_p->pDUSessionResourceReleaseCommandTransfer);
|
||||
pdusession_release_t *r = &msg->pdusession_release_params[i];
|
||||
r->pdusession_id = item_p->pDUSessionID;
|
||||
r->data = create_byte_array(item_p->pDUSessionResourceReleaseCommandTransfer.size, item_p->pDUSessionResourceReleaseCommandTransfer.buf);
|
||||
}
|
||||
|
||||
itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
|
||||
|
||||
@@ -64,9 +64,7 @@ void ngap_gNB_itti_send_nas_downlink_ind(instance_t instance, uint32_t gNB_ue_ng
|
||||
ngap_downlink_nas = &message_p->ittiMsg.ngap_downlink_nas;
|
||||
|
||||
ngap_downlink_nas->gNB_ue_ngap_id = gNB_ue_ngap_id;
|
||||
ngap_downlink_nas->nas_pdu.buffer = malloc(sizeof(uint8_t) * nas_pdu_length);
|
||||
memcpy(ngap_downlink_nas->nas_pdu.buffer, nas_pdu, nas_pdu_length);
|
||||
ngap_downlink_nas->nas_pdu.length = nas_pdu_length;
|
||||
ngap_downlink_nas->nas_pdu = create_byte_array(nas_pdu_length, nas_pdu);
|
||||
|
||||
itti_send_msg_to_task(TASK_RRC_GNB, instance, message_p);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "ngap_gNB_defs.h"
|
||||
#include "queue.h"
|
||||
#include "tree.h"
|
||||
#include "ds/byte_array.h"
|
||||
|
||||
static ngap_gNB_internal_data_t ngap_gNB_internal_data;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
* @ingroup _ngap
|
||||
*/
|
||||
|
||||
#include "ds/byte_array.h"
|
||||
|
||||
#ifndef NGAP_GNB_MANAGEMENT_PROCEDURES_H_
|
||||
#define NGAP_GNB_MANAGEMENT_PROCEDURES_H_
|
||||
|
||||
|
||||
@@ -58,15 +58,6 @@
|
||||
#include "s1ap_messages_types.h"
|
||||
#include "xer_encoder.h"
|
||||
|
||||
static void allocCopy(OCTET_STRING_t *out, ngap_pdu_t in)
|
||||
{
|
||||
if (in.length) {
|
||||
out->buf = malloc(in.length);
|
||||
memcpy(out->buf, in.buffer, in.length);
|
||||
}
|
||||
out->size = in.length;
|
||||
}
|
||||
|
||||
static void allocAddrCopy(BIT_STRING_t *out, transport_layer_addr_t in)
|
||||
{
|
||||
if (in.length) {
|
||||
@@ -203,7 +194,7 @@ int ngap_gNB_handle_nas_first_req(instance_t instance, ngap_nas_first_req_t *UEf
|
||||
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
|
||||
ie->criticality = NGAP_Criticality_reject;
|
||||
ie->value.present = NGAP_InitialUEMessage_IEs__value_PR_NAS_PDU;
|
||||
allocCopy(&ie->value.choice.NAS_PDU, UEfirstReq->nas_pdu);
|
||||
OCTET_STRING_fromBuf(&ie->value.choice.NAS_PDU, (const char *)UEfirstReq->nas_pdu.buf, UEfirstReq->nas_pdu.len);
|
||||
}
|
||||
|
||||
/* mandatory */
|
||||
@@ -436,8 +427,8 @@ int ngap_gNB_nas_uplink(instance_t instance, ngap_uplink_nas_t *ngap_uplink_nas_
|
||||
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
|
||||
ie->criticality = NGAP_Criticality_reject;
|
||||
ie->value.present = NGAP_UplinkNASTransport_IEs__value_PR_NAS_PDU;
|
||||
ie->value.choice.NAS_PDU.buf = ngap_uplink_nas_p->nas_pdu.buffer;
|
||||
ie->value.choice.NAS_PDU.size = ngap_uplink_nas_p->nas_pdu.length;
|
||||
ie->value.choice.NAS_PDU.buf = ngap_uplink_nas_p->nas_pdu.buf;
|
||||
ie->value.choice.NAS_PDU.size = ngap_uplink_nas_p->nas_pdu.len;
|
||||
}
|
||||
/* mandatory */
|
||||
{
|
||||
@@ -532,8 +523,8 @@ int ngap_gNB_nas_non_delivery_ind(instance_t instance,
|
||||
ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU;
|
||||
ie->criticality = NGAP_Criticality_ignore;
|
||||
ie->value.present = NGAP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU;
|
||||
ie->value.choice.NAS_PDU.buf = ngap_nas_non_delivery_ind->nas_pdu.buffer;
|
||||
ie->value.choice.NAS_PDU.size = ngap_nas_non_delivery_ind->nas_pdu.length;
|
||||
ie->value.choice.NAS_PDU.buf = ngap_nas_non_delivery_ind->nas_pdu.buf;
|
||||
ie->value.choice.NAS_PDU.size = ngap_nas_non_delivery_ind->nas_pdu.len;
|
||||
}
|
||||
/* mandatory */
|
||||
{
|
||||
@@ -861,8 +852,8 @@ int ngap_gNB_ue_capabilities(instance_t instance, ngap_ue_cap_info_ind_t *ue_cap
|
||||
ie->id = NGAP_ProtocolIE_ID_id_UERadioCapability;
|
||||
ie->criticality = NGAP_Criticality_ignore;
|
||||
ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_UERadioCapability;
|
||||
ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer;
|
||||
ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length;
|
||||
ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buf;
|
||||
ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.len;
|
||||
}
|
||||
/* optional */
|
||||
//NGAP_UERadioCapabilityForPaging TBD
|
||||
@@ -1224,8 +1215,9 @@ int ngap_gNB_pdusession_release_resp(instance_t instance, ngap_pdusession_releas
|
||||
|
||||
for (i = 0; i < pdusession_release_resp_p->nb_of_pdusessions_released; i++) {
|
||||
asn1cSequenceAdd(ie->value.choice.PDUSessionResourceReleasedListRelRes.list, NGAP_PDUSessionResourceReleasedItemRelRes_t, item);
|
||||
item->pDUSessionID = pdusession_release_resp_p->pdusession_release[i].pdusession_id;
|
||||
allocCopy(&item->pDUSessionResourceReleaseResponseTransfer, pdusession_release_resp_p->pdusession_release[i].data);
|
||||
pdusession_release_t *r = &pdusession_release_resp_p->pdusession_release[i];
|
||||
item->pDUSessionID = r->pdusession_id;
|
||||
OCTET_STRING_fromBuf(&item->pDUSessionResourceReleaseResponseTransfer, (const char *)r->data.buf, r->data.len);
|
||||
NGAP_DEBUG("pdusession_release_resp: pdusession ID %ld\n", item->pDUSessionID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user