diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 064eb6043fe567f64d9d558d009f217f4faca0b1..b0e147780ecd51178458f3dbd4178c489b9c213c 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -1017,7 +1017,7 @@ uint16_t do_RRCReconfiguration( /******************** Secondary Cell Group ********************/ rrc_gNB_carrier_data_t *carrier = &(gnb_rrc_inst->carrier); - fill_default_secondaryCellGroup( carrier->ServingCellConfigCommon, + fill_default_secondaryCellGroup( carrier->servingcellconfigcommon, ue_context_pP->ue_context.secondaryCellGroup, 1, 1, @@ -1074,7 +1074,7 @@ uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) { memset((void *)&ul_ccch_msg,0,sizeof(NR_UL_CCCH_Message_t)); ul_ccch_msg.message.present = NR_UL_CCCH_MessageType_PR_c1; ul_ccch_msg.message.choice.c1->present = NR_UL_CCCH_MessageType__c1_PR_rrcSetupRequest; - rrcSetupRequest = &ul_ccch_msg.message.choice.c1->choice.rrcSetupRequest; + rrcSetupRequest = ul_ccch_msg.message.choice.c1->choice.rrcSetupRequest; if (1) { diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index 2222f8a3f988e7f4ff9a8fac1226c6058f15f2a9..fa424fb7a4dd0c7261d5a2b222500bb380b8aacf 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -99,6 +99,10 @@ uint8_t do_NR_SecurityModeCommand( const uint8_t cipheringAlgorithm, NR_IntegrityProtAlgorithm_t *integrityProtAlgorithm); +uint8_t do_NR_UECapabilityEnquiry_nr( const protocol_ctxt_t *const ctxt_pP, + uint8_t *const buffer, + const uint8_t Transaction_id); + uint8_t do_NR_RRCConnectionRelease(uint8_t *buffer, uint8_t Transaction_id); uint16_t do_RRCReconfiguration( diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h index cceb294dd638a8c3c3ca5cc7b8ee84bbd629fadd..a9a8c80ed121a3f63ffdddb1a5c7cb92644ab8dd 100644 --- a/openair2/RRC/NR/nr_rrc_defs.h +++ b/openair2/RRC/NR/nr_rrc_defs.h @@ -134,8 +134,6 @@ typedef enum UE_STATE_NR_e { /* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */ #define NR_RRC_TRANSACTION_IDENTIFIER_NUMBER 3 -#define ENABLE_SECURITY 1 - typedef struct { unsigned short transport_block_size; /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */ unsigned short max_transport_blocks; /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */ @@ -289,13 +287,12 @@ typedef struct gNB_RRC_UE_s { ImsiMobileIdentity_t imsi; -#if defined(ENABLE_SECURITY) /* KgNB as derived from KASME received from EPC */ uint8_t kgnb[32]; int8_t kgnb_ncc; uint8_t nh[32]; int8_t nh_ncc; -#endif + /* Used integrity/ciphering algorithms */ NR_CipheringAlgorithm_t ciphering_algorithm; e_NR_IntegrityProtAlgorithm integrity_algorithm; diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 771e797fa7d69483fa242460d05a6a73dd95a3c1..9612bf625d49fac7129db5f2fc90913a6496c76d 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -68,9 +68,7 @@ #include "OCG.h" #include "OCG_extern.h" -#if defined(ENABLE_SECURITY) - #include "UTIL/OSA/osa_defs.h" -#endif +#include "UTIL/OSA/osa_defs.h" #include "rrc_eNB_S1AP.h" #include "rrc_gNB_NGAP.h" @@ -92,6 +90,28 @@ extern RAN_CONTEXT_t RC; +extern boolean_t nr_rrc_pdcp_config_asn1_req( + const protocol_ctxt_t *const ctxt_pP, + NR_SRB_ToAddModList_t *const srb2add_list, + NR_DRB_ToAddModList_t *const drb2add_list, + NR_DRB_ToReleaseList_t *const drb2release_list, + const uint8_t security_modeP, + uint8_t *const kRRCenc, + uint8_t *const kRRCint, + uint8_t *const kUPenc + #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) + ,LTE_PMCH_InfoList_r9_t *pmch_InfoList_r9 + #endif + ,rb_id_t *const defaultDRB, + struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list); + +extern rlc_op_status_t nr_rrc_rlc_config_asn1_req (const protocol_ctxt_t * const ctxt_pP, + const NR_SRB_ToAddModList_t * const srb2add_listP, + const NR_DRB_ToAddModList_t * const drb2add_listP, + const NR_DRB_ToReleaseList_t * const drb2release_listP, + const LTE_PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP, + struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list); + mui_t rrc_gNB_mui = 0; ///---------------------------------------------------------------------------------------------------------------/// @@ -570,6 +590,7 @@ rrc_gNB_process_RRCReconfigurationComplete( kRRCint, kUPenc, NULL, + NULL, NULL); /* Refresh SRBs/DRBs */ nr_rrc_rlc_config_asn1_req(ctxt_pP, @@ -577,9 +598,7 @@ rrc_gNB_process_RRCReconfigurationComplete( DRB_configList, DRB_Release_configList2, NULL, - 0, - 0 - ); + NULL); /* Loop through DRBs and establish if necessary */ if (DRB_configList != NULL) { diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index 9d81462d40faf9b1c4515918ef1d9dc5adf42ee5..b615cb833e5bdc4d1be6be84859d2ab6a7781356 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -47,6 +47,7 @@ #include "S1AP_NAS-PDU.h" #include "executables/softmodem-common.h" +#include "UTIL/OSA/osa_defs.h" extern RAN_CONTEXT_t RC; @@ -115,6 +116,75 @@ rrc_gNB_get_ue_context_from_ngap_ids( return NULL; } +//------------------------------------------------------------------------------ +void +nr_rrc_pdcp_config_security( + const protocol_ctxt_t *const ctxt_pP, + rrc_gNB_ue_context_t *const ue_context_pP, + const uint8_t send_security_mode_command +) +//------------------------------------------------------------------------------ +{ + NR_SRB_ToAddModList_t *SRB_configList = ue_context_pP->ue_context.SRB_configList; + uint8_t *kRRCenc = NULL; + uint8_t *kRRCint = NULL; + uint8_t *kUPenc = NULL; + pdcp_t *pdcp_p = NULL; + static int print_keys= 1; + hashtable_rc_t h_rc; + hash_key_t key; + + /* Derive the keys from kgnb */ + if (SRB_configList != NULL) { + derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm, + ue_context_pP->ue_context.kgnb, + &kUPenc); + } + + derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm, + ue_context_pP->ue_context.kgnb, + &kRRCenc); + derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm, + ue_context_pP->ue_context.kgnb, + &kRRCint); + if (!IS_SOFTMODEM_IQPLAYER) { + SET_LOG_DUMP(DEBUG_SECURITY) ; + } + + + if ( LOG_DUMPFLAG( DEBUG_SECURITY ) ) { + if (print_keys == 1 ) { + print_keys =0; + LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, ue_context_pP->ue_context.kgnb, 32,"\nKgNB:" ); + LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCenc, 32,"\nKRRCenc:" ); + LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCint, 32,"\nKRRCint:" ); + } + } + + key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, DCCH, SRB_FLAG_YES); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); + + if (h_rc == HASH_TABLE_OK) { + pdcp_config_set_security( + ctxt_pP, + pdcp_p, + DCCH, + DCCH+2, + (send_security_mode_command == TRUE) ? + 0 | (ue_context_pP->ue_context.integrity_algorithm << 4) : + (ue_context_pP->ue_context.ciphering_algorithm ) | + (ue_context_pP->ue_context.integrity_algorithm << 4), + kRRCenc, + kRRCint, + kUPenc); + } else { + LOG_E(NR_RRC, + PROTOCOL_NR_RRC_CTXT_UE_FMT"Could not get PDCP instance for SRB DCCH %u\n", + PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP), + DCCH); + } +} + //------------------------------------------------------------------------------ /* * Initial UE NAS message on S1AP. @@ -280,7 +350,7 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ( uint8_t send_security_mode_command = TRUE; - rrc_pdcp_config_security( + nr_rrc_pdcp_config_security( &ctxt, ue_context_p, send_security_mode_command); @@ -289,7 +359,7 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ( rrc_gNB_generate_SecurityModeCommand (&ctxt, ue_context_p); send_security_mode_command = FALSE; - rrc_pdcp_config_security( + nr_rrc_pdcp_config_security( &ctxt, ue_context_p, send_security_mode_command);