From 1711b1b4b8f2fbc19c6c5811032c60115df921a3 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 24 Sep 2025 14:55:52 +0200 Subject: [PATCH] Refactor ASN.1 PDCP configuration building - Limit scope of get_default_rbconfig function: from asn1_msg.c/.h to rrc_gNB_nsa.c where it's used - Create new rrc_gNB_asn1.c/h files for ASN.1 utility functions: they can be used in other RRC files - Add nr_rrc_build_pdcp_config_ie function for building PDCP configuration IEs - Update get_default_rbconfig to use the new PDCP config builder - Add rrc_gNB_asn1.c to CMakeLists.txt build configuration --- CMakeLists.txt | 1 + openair2/RRC/NR/MESSAGES/asn1_msg.c | 45 --------------------------- openair2/RRC/NR/MESSAGES/asn1_msg.h | 6 ---- openair2/RRC/NR/rrc_gNB_asn1.c | 48 +++++++++++++++++++++++++++++ openair2/RRC/NR/rrc_gNB_asn1.h | 33 ++++++++++++++++++++ openair2/RRC/NR/rrc_gNB_nsa.c | 27 ++++++++++++++++ 6 files changed, 109 insertions(+), 51 deletions(-) create mode 100644 openair2/RRC/NR/rrc_gNB_asn1.c create mode 100644 openair2/RRC/NR/rrc_gNB_asn1.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 528b3e6482..314ee0ee0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1167,6 +1167,7 @@ set(L2_NR_SRC ${NR_RRC_DIR}/rrc_gNB.c ${NR_RRC_DIR}/mac_rrc_dl_direct.c ${NR_RRC_DIR}/mac_rrc_dl_f1ap.c + ${NR_RRC_DIR}/rrc_gNB_asn1.c ${NR_RRC_DIR}/rrc_gNB_nsa.c ${NR_RRC_DIR}/rrc_gNB_UE_context.c ${NR_RRC_DIR}/rrc_gNB_NGAP.c diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 51618d1f3e..0ed1750d6b 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -319,51 +319,6 @@ int do_RRCReject(uint8_t *const buffer) return (enc_rval.encoded + 7) / 8; } -/* returns a default radio bearer config suitable for NSA etc */ -NR_RadioBearerConfig_t *get_default_rbconfig(int eps_bearer_id, - int rb_id, - e_NR_CipheringAlgorithm ciphering_algorithm, - e_NR_SecurityConfig__keyToUse key_to_use, - const nr_pdcp_configuration_t *pdcp_config) -{ - NR_RadioBearerConfig_t *rbconfig = calloc(1, sizeof(*rbconfig)); - rbconfig->srb_ToAddModList = NULL; - rbconfig->srb3_ToRelease = NULL; - rbconfig->drb_ToAddModList = calloc(1,sizeof(*rbconfig->drb_ToAddModList)); - NR_DRB_ToAddMod_t *drb_ToAddMod = calloc(1,sizeof(*drb_ToAddMod)); - drb_ToAddMod->cnAssociation = calloc(1,sizeof(*drb_ToAddMod->cnAssociation)); - drb_ToAddMod->cnAssociation->present = NR_DRB_ToAddMod__cnAssociation_PR_eps_BearerIdentity; - drb_ToAddMod->cnAssociation->choice.eps_BearerIdentity= eps_bearer_id; - drb_ToAddMod->drb_Identity = rb_id; - drb_ToAddMod->reestablishPDCP = NULL; - drb_ToAddMod->recoverPDCP = NULL; - drb_ToAddMod->pdcp_Config = calloc(1,sizeof(*drb_ToAddMod->pdcp_Config)); - asn1cCalloc(drb_ToAddMod->pdcp_Config->drb, drb); - asn1cCallocOne(drb->discardTimer, encode_discard_timer(pdcp_config->drb.discard_timer)); - asn1cCallocOne(drb->pdcp_SN_SizeUL, encode_sn_size_ul(pdcp_config->drb.sn_size)); - asn1cCallocOne(drb->pdcp_SN_SizeDL, encode_sn_size_dl(pdcp_config->drb.sn_size)); - drb->headerCompression.present = NR_PDCP_Config__drb__headerCompression_PR_notUsed; - drb->headerCompression.choice.notUsed = 0; - drb->integrityProtection = NULL; - drb->statusReportRequired = NULL; - drb->outOfOrderDelivery = NULL; - - drb_ToAddMod->pdcp_Config->moreThanOneRLC = NULL; - asn1cCallocOne(drb_ToAddMod->pdcp_Config->t_Reordering, encode_t_reordering(pdcp_config->drb.t_reordering)); - drb_ToAddMod->pdcp_Config->ext1 = NULL; - - asn1cSeqAdd(&rbconfig->drb_ToAddModList->list,drb_ToAddMod); - - rbconfig->drb_ToReleaseList = NULL; - - asn1cCalloc(rbconfig->securityConfig, secConf); - asn1cCalloc(secConf->securityAlgorithmConfig, secConfAlgo); - secConfAlgo->cipheringAlgorithm = ciphering_algorithm; - secConfAlgo->integrityProtAlgorithm = NULL; - asn1cCallocOne(secConf->keyToUse, key_to_use); - return rbconfig; -} - //------------------------------------------------------------------------------ int do_RRCSetup(uint8_t *const buffer, size_t buffer_size, diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index 607fa95994..f347f3428c 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -89,12 +89,6 @@ int do_SIB2_NR(uint8_t **msg_SIB2, NR_SSB_MTC_t *ssbmtc); int do_RRCReject(uint8_t *const buffer); -NR_RadioBearerConfig_t *get_default_rbconfig(int eps_bearer_id, - int rb_id, - e_NR_CipheringAlgorithm ciphering_algorithm, - e_NR_SecurityConfig__keyToUse key_to_use, - const nr_pdcp_configuration_t *pdcp_config); - int do_RRCSetup(uint8_t *const buffer, size_t buffer_size, const uint8_t transaction_id, diff --git a/openair2/RRC/NR/rrc_gNB_asn1.c b/openair2/RRC/NR/rrc_gNB_asn1.c new file mode 100644 index 0000000000..17f4bb8af5 --- /dev/null +++ b/openair2/RRC/NR/rrc_gNB_asn1.c @@ -0,0 +1,48 @@ +/* + * 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 +#include "NR_DRB-ToAddMod.h" +#include "NR_RadioBearerConfig.h" +#include "common/utils/oai_asn1.h" +#include "common/utils/LOG/log.h" +#include "openair2/LAYER2/nr_pdcp/nr_pdcp_configuration.h" +#include "openair2/LAYER2/nr_pdcp/nr_pdcp_asn1_utils.h" + +NR_PDCP_Config_t *nr_rrc_build_pdcp_config_ie(const bool integrity, const bool ciphering, const nr_pdcp_configuration_t *pdcp) +{ + NR_PDCP_Config_t *out = calloc_or_fail(1, sizeof(*out)); + asn1cCallocOne(out->t_Reordering, encode_t_reordering(pdcp->drb.t_reordering)); + if (!ciphering) { + asn1cCalloc(out->ext1, ext1); + asn1cCallocOne(ext1->cipheringDisabled, NR_PDCP_Config__ext1__cipheringDisabled_true); + } + asn1cCalloc(out->drb, drb); + asn1cCallocOne(drb->discardTimer, encode_discard_timer(pdcp->drb.discard_timer)); + asn1cCallocOne(drb->pdcp_SN_SizeUL, encode_sn_size_ul(pdcp->drb.sn_size)); + asn1cCallocOne(drb->pdcp_SN_SizeDL, encode_sn_size_dl(pdcp->drb.sn_size)); + drb->headerCompression.present = NR_PDCP_Config__drb__headerCompression_PR_notUsed; + drb->headerCompression.choice.notUsed = 0; + if (integrity) { + asn1cCallocOne(drb->integrityProtection, NR_PDCP_Config__drb__integrityProtection_enabled); + } + return out; +} diff --git a/openair2/RRC/NR/rrc_gNB_asn1.h b/openair2/RRC/NR/rrc_gNB_asn1.h new file mode 100644 index 0000000000..b706a68a15 --- /dev/null +++ b/openair2/RRC/NR/rrc_gNB_asn1.h @@ -0,0 +1,33 @@ +/* + * 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 + */ + +#ifndef _RRC_GNB_ASN1_H_ +#define _RRC_GNB_ASN1_H_ + +#include +#include "seq_arr.h" +#include "NR_DRB-ToAddMod.h" +#include "NR_RadioBearerConfig.h" +#include "openair2/LAYER2/nr_pdcp/nr_pdcp_configuration.h" + +NR_PDCP_Config_t *nr_rrc_build_pdcp_config_ie(const bool integrity, const bool ciphering, const nr_pdcp_configuration_t *pdcp); + +#endif diff --git a/openair2/RRC/NR/rrc_gNB_nsa.c b/openair2/RRC/NR/rrc_gNB_nsa.c index aa97a026e0..f0f7201517 100644 --- a/openair2/RRC/NR/rrc_gNB_nsa.c +++ b/openair2/RRC/NR/rrc_gNB_nsa.c @@ -72,6 +72,7 @@ #include "xer_encoder.h" #include "f1ap_common.h" #include "lib/f1ap_ue_context.h" +#include "rrc_gNB_asn1.h" // In case of phy-test and do-ra mode, read UE capabilities directly from file // and put it into a CG-ConfigInfo field @@ -134,6 +135,32 @@ static instance_t get_f1_gtp_instance(void) return inst->gtpInst; } +/* returns a default radio bearer config suitable for NSA etc */ +static NR_RadioBearerConfig_t *get_default_rbconfig(int eps_bearer_id, + int rb_id, + e_NR_CipheringAlgorithm ciphering_algorithm, + e_NR_SecurityConfig__keyToUse key_to_use, + const nr_pdcp_configuration_t *pdcp_config) +{ + NR_RadioBearerConfig_t *rbconfig = calloc_or_fail(1, sizeof(*rbconfig)); + rbconfig->drb_ToAddModList = calloc_or_fail(1, sizeof(*rbconfig->drb_ToAddModList)); + NR_DRB_ToAddMod_t *drb_ToAddMod = calloc_or_fail(1, sizeof(*drb_ToAddMod)); + drb_ToAddMod->drb_Identity = rb_id; + drb_ToAddMod->pdcp_Config = nr_rrc_build_pdcp_config_ie(false, false, pdcp_config); + asn1cCalloc(drb_ToAddMod->cnAssociation, cn_association); + cn_association->present = NR_DRB_ToAddMod__cnAssociation_PR_eps_BearerIdentity; + cn_association->choice.eps_BearerIdentity = eps_bearer_id; + asn1cSeqAdd(&rbconfig->drb_ToAddModList->list, drb_ToAddMod); + asn1cCalloc(rbconfig->securityConfig, secConf); + asn1cCalloc(secConf->securityAlgorithmConfig, secConfAlgo); + secConfAlgo->cipheringAlgorithm = ciphering_algorithm; + secConfAlgo->integrityProtAlgorithm = NULL; + asn1cCallocOne(secConf->keyToUse, key_to_use); + if (LOG_DEBUGFLAG(DEBUG_ASN1)) + xer_fprint(stdout, &asn_DEF_NR_DRB_ToAddMod, drb_ToAddMod); + return rbconfig; +} + /* generate prototypes for the tree management functions (RB_INSERT used in rrc_add_nsa_user) */ RB_PROTOTYPE(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s, entries, rrc_gNB_compare_ue_rnti_id);