From 65b9af543a7bccf5a79d3e7a9ea8846de41e148c Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 14 Oct 2024 17:19:00 +0200 Subject: [PATCH] Cleanup rrc_gNB_generate_SecurityModeCommand() Cleanup this function: pass UE context directly, remove protocol_ctxt_t. --- openair2/RRC/NR/MESSAGES/asn1_msg.c | 11 ++++------- openair2/RRC/NR/MESSAGES/asn1_msg.h | 10 ++++------ openair2/RRC/NR/nr_rrc_proto.h | 2 +- openair2/RRC/NR/rrc_gNB.c | 15 ++++----------- openair2/RRC/NR/rrc_gNB_NGAP.c | 2 +- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 25baed610a..2a0ebd736c 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -519,12 +519,10 @@ int do_RRCSetup(rrc_gNB_ue_context_t *const ue_context_pP, return ((enc_rval.encoded + 7) / 8); } -int do_NR_SecurityModeCommand( - const protocol_ctxt_t *const ctxt_pP, - uint8_t *const buffer, - const uint8_t Transaction_id, - const uint8_t cipheringAlgorithm, - NR_IntegrityProtAlgorithm_t integrityProtAlgorithm) +int do_NR_SecurityModeCommand(uint8_t *const buffer, + const uint8_t Transaction_id, + const uint8_t cipheringAlgorithm, + NR_IntegrityProtAlgorithm_t integrityProtAlgorithm) //------------------------------------------------------------------------------ { NR_DL_DCCH_Message_t dl_dcch_msg={0}; @@ -555,7 +553,6 @@ int do_NR_SecurityModeCommand( AssertFatal(enc_rval.encoded >0 , "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NR_DL_DCCH_Message,&dl_dcch_msg); - LOG_D(NR_RRC, "[gNB %d] securityModeCommand for UE %lx Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, ctxt_pP->rntiMaybeUEid, enc_rval.encoded, (enc_rval.encoded + 7) / 8); // rrc_ue_process_ueCapabilityEnquiry(0,1000,&dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry,0); // exit(-1); diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index 623573d24f..871fe08d49 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -81,12 +81,10 @@ int do_RRCSetup(rrc_gNB_ue_context_t *const ue_context_pP, const gNB_RrcConfigurationReq *configuration, NR_SRB_ToAddModList_t *SRBs); -int do_NR_SecurityModeCommand( - const protocol_ctxt_t *const ctxt_pP, - uint8_t *const buffer, - const uint8_t Transaction_id, - const uint8_t cipheringAlgorithm, - NR_IntegrityProtAlgorithm_t integrityProtAlgorithm); +int do_NR_SecurityModeCommand(uint8_t *const buffer, + const uint8_t Transaction_id, + const uint8_t cipheringAlgorithm, + NR_IntegrityProtAlgorithm_t integrityProtAlgorithm); int do_NR_SA_UECapabilityEnquiry(const protocol_ctxt_t *const ctxt_pP, uint8_t *const buffer, diff --git a/openair2/RRC/NR/nr_rrc_proto.h b/openair2/RRC/NR/nr_rrc_proto.h index 235b774bde..77202018e9 100644 --- a/openair2/RRC/NR/nr_rrc_proto.h +++ b/openair2/RRC/NR/nr_rrc_proto.h @@ -72,7 +72,7 @@ NR_CG_Config_t *generate_CG_Config(const NR_RRCReconfiguration_t *reconfig, cons int parse_CG_ConfigInfo(gNB_RRC_INST *rrc, NR_CG_ConfigInfo_t *CG_ConfigInfo, x2ap_ENDC_sgnb_addition_req_t *m); -void rrc_gNB_generate_SecurityModeCommand(const protocol_ctxt_t *const ctxt_pP, rrc_gNB_ue_context_t *const ue_context_pP); +void rrc_gNB_generate_SecurityModeCommand(gNB_RRC_INST *rrc, gNB_RRC_UE_t *ue_p); unsigned int rrc_gNB_get_next_transaction_identifier(module_id_t gnb_mod_idP); diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index d6844ee54e..19b36929f8 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -2585,28 +2585,21 @@ void *rrc_gnb_task(void *args_p) { } //----------------------------------------------------------------------------- -void rrc_gNB_generate_SecurityModeCommand(const protocol_ctxt_t *const ctxt_pP, rrc_gNB_ue_context_t *const ue_context_pP) +void rrc_gNB_generate_SecurityModeCommand(gNB_RRC_INST *rrc, gNB_RRC_UE_t *ue_p) //----------------------------------------------------------------------------- { uint8_t buffer[100]; - gNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; AssertFatal(!ue_p->as_security_active, "logic error: security already active\n"); - T(T_ENB_RRC_SECURITY_MODE_COMMAND, - T_INT(ctxt_pP->module_id), - T_INT(ctxt_pP->frame), - T_INT(ctxt_pP->subframe), - T_INT(ctxt_pP->rntiMaybeUEid)); + T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(0), T_INT(0), T_INT(0), T_INT(ue_p->rrc_ue_id)); NR_IntegrityProtAlgorithm_t integrity_algorithm = (NR_IntegrityProtAlgorithm_t)ue_p->integrity_algorithm; - int size = do_NR_SecurityModeCommand(ctxt_pP, - buffer, - rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id), + int size = do_NR_SecurityModeCommand(buffer, + rrc_gNB_get_next_transaction_identifier(0), ue_p->ciphering_algorithm, integrity_algorithm); LOG_DUMPMSG(NR_RRC, DEBUG_RRC, (char *)buffer, size, "[MSG] RRC Security Mode Command\n"); LOG_I(NR_RRC, "UE %u Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n", ue_p->rrc_ue_id, size); - gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; nr_rrc_transfer_protected_rrc_message(rrc, ue_p, DCCH, buffer, size); } diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index c8e1f5918d..261a16cec3 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -463,8 +463,8 @@ int rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, instance_t /* configure only integrity, ciphering comes after receiving SecurityModeComplete */ nr_rrc_pdcp_config_security(UE, false); + rrc_gNB_generate_SecurityModeCommand(rrc, UE); - rrc_gNB_generate_SecurityModeCommand(&ctxt, ue_context_p); if (req->nb_of_pdusessions > 0) { /* if there are PDU sessions to setup, store them to be created once * security (and UE capabilities) are received */