Commit f9b083eb authored by Anatolii Pankevych's avatar Anatolii Pankevych

bugz #124092: add control plane security

parent a7c0f0d1
This diff is collapsed.
...@@ -35,6 +35,20 @@ typedef enum { ...@@ -35,6 +35,20 @@ typedef enum {
NR_PDCP_SRB NR_PDCP_SRB
} nr_pdcp_entity_type_t; } nr_pdcp_entity_type_t;
/**
* 3GPP TS 33.501
* RRC downlink ciphering (encryption) at the gNB shall start after sending the AS security mode command message.
* RRC uplink deciphering (decryption) at the gNB shall start after receiving and successful verification of the AS security mode complete message.
*
* RRC uplink ciphering (encryption) at the UE shall start after sending the AS security mode complete message.
* RRC downlink deciphering (decryption) at the UE shall start after receiving and successful verification of the AS security mode command message.
*/
typedef enum {
NR_PDCP_ENTITY_CIPHERING_OFF = 0,
NR_PDCP_ENTITY_CIPHERING_ON = 1,
NR_PDCP_ENTITY_CIPHERING_SMC = 2, /* A Transient state to skip decryption @ gNB and encryption @ nrUE during SMC procedure */
} nr_pdcp_entity_ciphering_state_t;
typedef struct { typedef struct {
//nr_pdcp_entity_type_t mode; //nr_pdcp_entity_type_t mode;
/* PDU stats */ /* PDU stats */
...@@ -125,7 +139,7 @@ typedef struct nr_pdcp_entity_t { ...@@ -125,7 +139,7 @@ typedef struct nr_pdcp_entity_t {
int t_reordering_start; int t_reordering_start;
/* security */ /* security */
int has_ciphering; nr_pdcp_entity_ciphering_state_t has_ciphering;
int has_integrity; int has_integrity;
int ciphering_algorithm; int ciphering_algorithm;
int integrity_algorithm; int integrity_algorithm;
...@@ -152,19 +166,6 @@ typedef struct nr_pdcp_entity_t { ...@@ -152,19 +166,6 @@ typedef struct nr_pdcp_entity_t {
int rx_size; int rx_size;
int rx_maxsize; int rx_maxsize;
nr_pdcp_statistics_t stats; nr_pdcp_statistics_t stats;
// WARNING: This is a hack!
// 3GPP TS 38.331 (RRC) version 15.3
// Section 5.3.4.3 Reception of the SecurityModeCommand by the UE
// The UE needs to send the Security Mode Complete message. However, the message
// needs to be sent without being ciphered.
// However:
// 1- The Security Mode Command arrives to the UE with the cipher algo (e.g., nea2).
// 2- The UE is configured with the cipher algo.
// 3- The Security Mode Complete message is sent to the itti task queue.
// 4- The ITTI task, forwards the message ciphering (e.g., nea2) it.
// 5- The gNB cannot understand the ciphered Security Mode Complete message.
bool security_mode_completed;
} nr_pdcp_entity_t; } nr_pdcp_entity_t;
nr_pdcp_entity_t *new_nr_pdcp_entity( nr_pdcp_entity_t *new_nr_pdcp_entity(
......
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
#include "openair2/SDAP/nr_sdap/nr_sdap.h" #include "openair2/SDAP/nr_sdap/nr_sdap.h"
#include "executables/softmodem-common.h" #include "executables/softmodem-common.h"
// 2DO: REMOVE, FOR DEBUG PURPOSES ONLY
#include "nr_pdcp_security.h"
#define TODO do { \ #define TODO do { \
printf("%s:%d:%s: todo\n", __FILE__, __LINE__, __FUNCTION__); \ printf("%s:%d:%s: todo\n", __FILE__, __LINE__, __FUNCTION__); \
exit(1); \ exit(1); \
...@@ -786,6 +789,7 @@ rb_found: ...@@ -786,6 +789,7 @@ rb_found:
memblock = get_free_mem_block(size, __FUNCTION__); memblock = get_free_mem_block(size, __FUNCTION__);
memcpy(memblock->data, buf, size); memcpy(memblock->data, buf, size);
LOG_D(PDCP, "%s(): (drb %d) calling rlc_data_req size %d\n", __func__, rb_id, size); LOG_D(PDCP, "%s(): (drb %d) calling rlc_data_req size %d\n", __func__, rb_id, size);
LOG_MSG(memblock->data, size, "%s: from RLC to PDCP: ", __FUNCTION__);
//for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]); //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
//printf("\n"); //printf("\n");
enqueue_rlc_data_req(&ctxt, 0, MBMS_FLAG_NO, rb_id, sdu_id, 0, size, memblock); enqueue_rlc_data_req(&ctxt, 0, MBMS_FLAG_NO, rb_id, sdu_id, 0, size, memblock);
...@@ -874,9 +878,8 @@ static void deliver_pdu_srb(void *_ue, nr_pdcp_entity_t *entity, ...@@ -874,9 +878,8 @@ static void deliver_pdu_srb(void *_ue, nr_pdcp_entity_t *entity,
exit(1); exit(1);
srb_found: srb_found:
LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, srb_id, size); LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, srb_id, size);
LOG_MSG(buf, size, "%s: PDCP => RLC: ", __FUNCTION__);
//for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]); //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
//printf("\n"); //printf("\n");
if ((RC.nrrrc == NULL) || (!NODE_IS_CU(RC.nrrrc[0]->node_type))) { if ((RC.nrrrc == NULL) || (!NODE_IS_CU(RC.nrrrc[0]->node_type))) {
...@@ -1153,12 +1156,15 @@ void nr_pdcp_add_srbs(eNB_flag_t enb_flag, ue_id_t rntiMaybeUEid, NR_SRB_ToAddMo ...@@ -1153,12 +1156,15 @@ void nr_pdcp_add_srbs(eNB_flag_t enb_flag, ue_id_t rntiMaybeUEid, NR_SRB_ToAddMo
for (int i = 0; i < srb2add_list->list.count; i++) { for (int i = 0; i < srb2add_list->list.count; i++) {
add_srb(enb_flag, rntiMaybeUEid, srb2add_list->list.array[i], security_modeP & 0x0f, (security_modeP >> 4) & 0x0f, kRRCenc, kRRCint); add_srb(enb_flag, rntiMaybeUEid, srb2add_list->list.array[i], security_modeP & 0x0f, (security_modeP >> 4) & 0x0f, kRRCenc, kRRCint);
} }
} else } else {
LOG_W(PDCP, "nr_pdcp_add_srbs() with void list\n"); LOG_W(PDCP, "nr_pdcp_add_srbs() with void list\n");
if (kRRCenc) }
if (kRRCenc) {
free(kRRCenc); free(kRRCenc);
if (kRRCint) }
if (kRRCint) {
free(kRRCint); free(kRRCint);
}
} }
void nr_pdcp_add_drbs(eNB_flag_t enb_flag, void nr_pdcp_add_drbs(eNB_flag_t enb_flag,
...@@ -1314,6 +1320,7 @@ void pdcp_config_set_security( ...@@ -1314,6 +1320,7 @@ void pdcp_config_set_security(
uint8_t *const kRRCint_pP, uint8_t *const kRRCint_pP,
uint8_t *const kUPenc_pP) uint8_t *const kUPenc_pP)
{ {
FNIN;
nr_pdcp_ue_t *ue; nr_pdcp_ue_t *ue;
nr_pdcp_entity_t *rb; nr_pdcp_entity_t *rb;
ue_id_t ue_id = ctxt_pP->rntiMaybeUEid; ue_id_t ue_id = ctxt_pP->rntiMaybeUEid;
...@@ -1337,15 +1344,16 @@ void pdcp_config_set_security( ...@@ -1337,15 +1344,16 @@ void pdcp_config_set_security(
integrity_algorithm = (security_modeP>>4) & 0xf; integrity_algorithm = (security_modeP>>4) & 0xf;
ciphering_algorithm = security_modeP & 0x0f; ciphering_algorithm = security_modeP & 0x0f;
rb->set_security(rb, integrity_algorithm, (char *)kRRCint_pP, LOG_MSG(kRRCint_pP, 16, "%s: (%d) kRRCint_pP: ", __FUNCTION__, integrity_algorithm);
ciphering_algorithm, (char *)kRRCenc_pP); LOG_MSG(kRRCenc_pP, 16, "%s: (%d) kRRCenc_pP: ", __FUNCTION__, ciphering_algorithm);
rb->security_mode_completed = false; rb->set_security(rb, integrity_algorithm, kRRCint_pP, ciphering_algorithm, kRRCenc_pP);
} else { } else {
LOG_E(PDCP, "%s:%d:%s: TODO\n", __FILE__, __LINE__, __FUNCTION__); LOG_E(PDCP, "%s:%d:%s: TODO\n", __FILE__, __LINE__, __FUNCTION__);
exit(1); exit(1);
} }
nr_pdcp_manager_unlock(nr_pdcp_ue_manager); nr_pdcp_manager_unlock(nr_pdcp_ue_manager);
FNOUT;
} }
static bool pdcp_data_req_srb(protocol_ctxt_t *ctxt_pP, static bool pdcp_data_req_srb(protocol_ctxt_t *ctxt_pP,
...@@ -1592,3 +1600,21 @@ const bool nr_pdcp_get_statistics(ue_id_t ue_id, int srb_flag, int rb_id, nr_pdc ...@@ -1592,3 +1600,21 @@ const bool nr_pdcp_get_statistics(ue_id_t ue_id, int srb_flag, int rb_id, nr_pdc
return ret; return ret;
} }
void nr_pdcp_config_set_smc(ue_id_t crntiMaybeUEid, bool complete)
{
FNIN;
nr_pdcp_ue_t *ue;
nr_pdcp_entity_t *rb;
nr_pdcp_manager_lock(nr_pdcp_ue_manager);
ue = nr_pdcp_manager_get_ue(nr_pdcp_ue_manager, crntiMaybeUEid);
if (ue && ue->srb[0]) {
rb = ue->srb[0];
if (rb->ciphering_algorithm > 0) {
rb->has_ciphering = complete ? NR_PDCP_ENTITY_CIPHERING_ON : NR_PDCP_ENTITY_CIPHERING_SMC;
}
}
nr_pdcp_manager_unlock(nr_pdcp_ue_manager);
FNOUT;
}
/*
* 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 _NR_PDCP_SECURITY_H_
#define _NR_PDCP_SECURITY_H_
#define NR_PDCP_DBG
#ifdef NR_PDCP_DBG
#include "LOG/log.h"
#define FNIN LOG_D(PDCP, ">>> %s:%d\n",__FUNCTION__, __LINE__);
#define FNOUT LOG_D(PDCP, "<<< %s:%d\n",__FUNCTION__, __LINE__);
#define LOG_MSG(B, S, ...) LOG_UDUMPMSG(PDCP, B, S, LOG_DUMP_CHAR, __VA_ARGS__);
#else // NR_PDCP_DBG
#define FNIN printf(">>> %s:%d\n", __FUNCTION__, __LINE__);
#define FNOUT printf("<<< %s:%d\n", __FUNCTION__, __LINE__);
#define LOG_MSG(B, S, ...) do {printf(__VA_ARGS__); for (int i = 0; i < S; ++i) printf("%02X", (uint8_t)B[i]); printf("\n"); } while(0);
#endif // NR_PDCP_DBG
#endif /* _NR_PDCP_SECURITY_H_ */
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "nr_rrc_config.h" #include "nr_rrc_config.h"
#include "nr_rrc_defs.h" #include "nr_rrc_defs.h"
#include "nr_rrc_extern.h" #include "nr_rrc_extern.h"
#include "assertions.h"
#include "common/ran_context.h" #include "common/ran_context.h"
#include "oai_asn1.h" #include "oai_asn1.h"
#include "rrc_gNB_radio_bearers.h" #include "rrc_gNB_radio_bearers.h"
...@@ -88,6 +87,8 @@ ...@@ -88,6 +87,8 @@
#include "rrc_gNB_GTPV1U.h" #include "rrc_gNB_GTPV1U.h"
#include "nr_pdcp/nr_pdcp_entity.h" #include "nr_pdcp/nr_pdcp_entity.h"
#include "nr_pdcp/nr_pdcp.h"
#include "pdcp_primitives.h"
#include "pdcp.h" #include "pdcp.h"
#include "intertask_interface.h" #include "intertask_interface.h"
...@@ -112,6 +113,13 @@ static inline uint64_t bitStr_to_uint64(BIT_STRING_t *asn); ...@@ -112,6 +113,13 @@ static inline uint64_t bitStr_to_uint64(BIT_STRING_t *asn);
mui_t rrc_gNB_mui = 0; mui_t rrc_gNB_mui = 0;
uint8_t first_rrcreconfiguration = 0; uint8_t first_rrcreconfiguration = 0;
// temp static storage for AS Security settings to be applied for SRB1 and SRB2
static e_NR_IntegrityProtAlgorithm _int_algo = 0;
static NR_CipheringAlgorithm_t _cip_algo = 0;
static uint8_t _nr_cp_int_key[16] = {0};
static uint8_t _nr_cp_cip_key[16] = {0};
///---------------------------------------------------------------------------------------------------------------/// ///---------------------------------------------------------------------------------------------------------------///
///---------------------------------------------------------------------------------------------------------------/// ///---------------------------------------------------------------------------------------------------------------///
...@@ -1660,6 +1668,8 @@ rrc_gNB_process_RRCReconfigurationComplete( ...@@ -1660,6 +1668,8 @@ rrc_gNB_process_RRCReconfigurationComplete(
ue_context_pP->ue_context.ue_reestablishment_timer = 0; ue_context_pP->ue_context.ue_reestablishment_timer = 0;
#if 0
// TTCN does all the calculations of kgNB and derived RRC keys
/* Derive the keys from kgnb */ /* Derive the keys from kgnb */
if (DRB_configList != NULL) { if (DRB_configList != NULL) {
nr_derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm, nr_derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
...@@ -1677,10 +1687,17 @@ rrc_gNB_process_RRCReconfigurationComplete( ...@@ -1677,10 +1687,17 @@ rrc_gNB_process_RRCReconfigurationComplete(
ue_context_pP->ue_context.kgnb, ue_context_pP->ue_context.kgnb,
&kRRCint); &kRRCint);
/* Refresh SRBs/DRBs */ /* Refresh SRBs/DRBs */
#endif
kRRCenc = (uint8_t*)malloc(16);
kRRCint = (uint8_t*)malloc(16);
AssertFatal(kRRCint && kRRCenc, "malloc failed");
memcpy(kRRCenc, _nr_cp_cip_key, 16);
memcpy(kRRCint, _nr_cp_int_key, 16);
LOG_D(NR_RRC,"Configuring PDCP DRBs/SRBs for UE %x\n",ue_context_pP->ue_context.rnti); LOG_I(NR_RRC,"Configuring PDCP DRBs/SRBs for UE %x\n",ue_context_pP->ue_context.rnti);
nr_pdcp_add_srbs(ctxt_pP->enb_flag, ctxt_pP->rntiMaybeUEid, SRB_configList, (ue_context_pP->ue_context.integrity_algorithm << 4) | ue_context_pP->ue_context.ciphering_algorithm, kRRCenc, kRRCint); nr_pdcp_add_srbs(ctxt_pP->enb_flag, ctxt_pP->rntiMaybeUEid, SRB_configList, (_int_algo << 4) | _cip_algo, kRRCenc, kRRCint);
nr_pdcp_add_drbs(ctxt_pP->enb_flag, nr_pdcp_add_drbs(ctxt_pP->enb_flag,
ctxt_pP->rntiMaybeUEid, ctxt_pP->rntiMaybeUEid,
...@@ -2672,7 +2689,7 @@ rrc_gNB_decode_dcch( ...@@ -2672,7 +2689,7 @@ rrc_gNB_decode_dcch(
LOG_DUMPMSG(NR_RRC, DEBUG_RRC, (char *)(Rx_sdu), sdu_sizeP, LOG_DUMPMSG(NR_RRC, DEBUG_RRC, (char *)(Rx_sdu), sdu_sizeP,
"[MSG] RRC Connection Reconfiguration Complete\n"); "[MSG] RRC Connection Reconfiguration Complete\n");
LOG_D(NR_RRC, LOG_I(NR_RRC,
PROTOCOL_NR_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes " PROTOCOL_NR_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
"(RRCReconfigurationComplete) ---> RRC_gNB]\n", "(RRCReconfigurationComplete) ---> RRC_gNB]\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP), PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
...@@ -2742,7 +2759,7 @@ rrc_gNB_decode_dcch( ...@@ -2742,7 +2759,7 @@ rrc_gNB_decode_dcch(
LOG_DUMPMSG(NR_RRC, DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP, LOG_DUMPMSG(NR_RRC, DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
"[MSG] RRC SetupComplete\n"); "[MSG] RRC SetupComplete\n");
LOG_D(NR_RRC, LOG_I(NR_RRC,
PROTOCOL_NR_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes " PROTOCOL_NR_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
"(RRCSetupComplete) ---> RRC_gNB\n", "(RRCSetupComplete) ---> RRC_gNB\n",
PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP), PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
...@@ -2859,7 +2876,9 @@ rrc_gNB_decode_dcch( ...@@ -2859,7 +2876,9 @@ rrc_gNB_decode_dcch(
} }
/* configure ciphering */ /* configure ciphering */
nr_rrc_pdcp_config_security(ctxt_pP, ue_context_p, 1); // FIXME: Commented for Bug 124092, no need to NGAP key recalculation
// nr_rrc_pdcp_config_security(ctxt_pP, ue_context_p, 1);
nr_pdcp_config_set_smc(ctxt_pP->rntiMaybeUEid, true);
if (RC.ss.mode == SS_GNB) if (RC.ss.mode == SS_GNB)
{ {
...@@ -2877,9 +2896,9 @@ rrc_gNB_decode_dcch( ...@@ -2877,9 +2896,9 @@ rrc_gNB_decode_dcch(
DCCH, DCCH,
sdu_sizeP); sdu_sizeP);
if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { // if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
xer_fprint(stdout, &asn_DEF_NR_UL_DCCH_Message, (void *)ul_dcch_msg); xer_fprint(stdout, &asn_DEF_NR_UL_DCCH_Message, (void *)ul_dcch_msg);
} // }
rrc_gNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p); rrc_gNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
break; break;
...@@ -4578,6 +4597,37 @@ void *rrc_gnb_task(void *args_p) { ...@@ -4578,6 +4597,37 @@ void *rrc_gnb_task(void *args_p) {
} }
break; break;
case RRC_AS_SECURITY_CONFIG_REQ:
{
_int_algo = (e_NR_IntegrityProtAlgorithm)RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.integrity_algorithm;
_cip_algo = (NR_CipheringAlgorithm_t)RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ciphering_algorithm;
LOG_I(NR_RRC,"[gNB %ld] Received %s: Int algo: %d, Cip algo: %d \n", instance, msg_name_p, _int_algo, _cip_algo);
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, RRC_AS_SECURITY_CONFIG_REQ(msg_p).rnti,
msg_p->ittiMsgHeader.lte_time.frame, msg_p->ittiMsgHeader.lte_time.slot);
if (_int_algo > 0) {
memcpy(&(_nr_cp_int_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[0]), 16);
} else {
memset(&(_nr_cp_int_key[0]), 0, 16);
}
if (_cip_algo > 0) {
memcpy(&(_nr_cp_cip_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc[0]), 16);
} else {
memset(&(_nr_cp_cip_key[0]), 0, 16);
}
int unused = 0;
int rb = 1;
pdcp_config_set_security(&ctxt, NULL, rb, unused, _cip_algo | _int_algo << 4,
&(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc[0]),
&(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[0]),
&RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc);
}
break;
default: default:
LOG_E(NR_RRC, "[gNB %ld] Received unexpected message %s\n", instance, msg_name_p); LOG_E(NR_RRC, "[gNB %ld] Received unexpected message %s\n", instance, msg_name_p);
break; break;
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "executables/softmodem-common.h" #include "executables/softmodem-common.h"
#include "plmn_data.h" #include "plmn_data.h"
#include "pdcp.h" #include "pdcp.h"
#include "nr_pdcp/nr_pdcp.h"
#include "UTIL/OSA/osa_defs.h" #include "UTIL/OSA/osa_defs.h"
#include "common/utils/LOG/log.h" #include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h" #include "common/utils/LOG/vcd_signal_dumper.h"
...@@ -1781,10 +1782,9 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB ...@@ -1781,10 +1782,9 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
LOG_D(NR_RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8); LOG_D(NR_RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) { for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
LOG_T(NR_RRC, "%02x.", buffer[i]); LOG_I(NR_RRC, "%02x.", buffer[i]);
} }
LOG_I(NR_RRC, "\n");
LOG_T(NR_RRC, "\n");
rrc_data_req_nr_ue (ctxt_pP, rrc_data_req_nr_ue (ctxt_pP,
DCCH, DCCH,
nr_rrc_mui++, nr_rrc_mui++,
...@@ -1792,9 +1792,14 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB ...@@ -1792,9 +1792,14 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
(enc_rval.encoded + 7) / 8, (enc_rval.encoded + 7) / 8,
buffer, buffer,
PDCP_TRANSMISSION_MODE_CONTROL); PDCP_TRANSMISSION_MODE_CONTROL);
} else if (NR_UE_rrc_inst[ctxt_pP->module_id].cipheringAlgorithm != NR_CipheringAlgorithm_nea0) {
LOG_W(NR_RRC,"securityModeCommand->criticalExtensions.present (%d) != NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand\n", LOG_I(NR_RRC, "Calling nr_pdcp_config_set_smc");
securityModeCommand->criticalExtensions.present); nr_pdcp_config_set_smc(ctxt_pP->rntiMaybeUEid, false);
}
} else {
LOG_W(NR_RRC,"securityModeCommand->criticalExtensions.present (%d) != NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand\n",
securityModeCommand->criticalExtensions.present);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -2245,6 +2250,7 @@ nr_rrc_ue_establish_srb2( ...@@ -2245,6 +2250,7 @@ nr_rrc_ue_establish_srb2(
ie->nonCriticalExtension->masterCellGroup); ie->nonCriticalExtension->masterCellGroup);
} }
updateKgNB(0, &(NR_UE_rrc_inst[ctxt_pP->module_id].kgnb[0]));
if (ie->radioBearerConfig != NULL) { if (ie->radioBearerConfig != NULL) {
LOG_I(NR_RRC, "radio Bearer Configuration is present\n"); LOG_I(NR_RRC, "radio Bearer Configuration is present\n");
nr_rrc_ue_process_RadioBearerConfig(ctxt_pP, gNB_index, ie->radioBearerConfig); nr_rrc_ue_process_RadioBearerConfig(ctxt_pP, gNB_index, ie->radioBearerConfig);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c" #include "openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c"
#include "common/utils/LOG/ss-log.h" #include "common/utils/LOG/ss-log.h"
#include "ss_utils.h"
#define MSC_INTERFACE #define MSC_INTERFACE
#include "msc.h" #include "msc.h"
#include "softmodem-common.h" #include "softmodem-common.h"
...@@ -249,6 +250,138 @@ static void sys_handle_nr_cell_attn_req(struct NR_CellAttenuationConfig_Type_NR_ ...@@ -249,6 +250,138 @@ static void sys_handle_nr_cell_attn_req(struct NR_CellAttenuationConfig_Type_NR_
} }
} }
/*
* Function : sys_handle_nr_as_security_req
* Description: Funtion handler of SYS_PORT. Handles the AS
* Security command received from TTCN via the PORTMAN.
* In :
* req - AS Security Request received from the TTCN via PORTMAN
* Out:
* newState: No impact on state machine.
*
*/
static void sys_handle_nr_as_security_req(struct NR_AS_Security_Type *ASSecurity)
{
MessageDef *msg_p = itti_alloc_new_message(TASK_SYS_GNB, INSTANCE_DEFAULT, RRC_AS_SECURITY_CONFIG_REQ);
if(msg_p)
{
LOG_E(GNB_APP,"[SYS-GNB] AS Security Request Received\n");
RRC_AS_SECURITY_CONFIG_REQ(msg_p).rnti = SS_context.ss_rnti_g;
switch(ASSecurity->d) {
case NR_AS_Security_Type_StartRestart:
{
if(ASSecurity->v.StartRestart.Integrity.d == true)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).isIntegrityInfoPresent = true;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.integrity_algorithm = ASSecurity->v.StartRestart.Integrity.v.Algorithm;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint = CALLOC(1,16);
memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint,0,16);
bits_copy_from_array(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint, 0, ASSecurity->v.StartRestart.Integrity.v.KRRCint, 128);
LOG_E(GNB_APP, "[SYS-GNB] kRRCint:\n");
for(int i = 0; i < 16; i++) {
LOG_E(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[i]);
}
if(ASSecurity->v.StartRestart.Integrity.v.ActTimeList.d == true)
{
for(int i=0;i < ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.d; i++)
{
switch(ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].RadioBearerId.d)
{
case RadioBearerId_Type_Srb:
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].rb_id = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].RadioBearerId.v.Srb;
break;
case RadioBearerId_Type_Drb:
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].rb_id = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].RadioBearerId.v.Drb;
break;
case RadioBearerId_Type_UNBOUND_VALUE:
break;
default:
LOG_E(GNB_APP, "[SYS-GNB] AS Security Act time list is Invalid \n");
}
if (ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].UL.d == NR_PDCP_ActTime_Type_SQN)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].UL.format = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].UL.v.SQN.Format;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].UL.sqn = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].UL.v.SQN.Value;
}
if (ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].DL.d == NR_PDCP_ActTime_Type_SQN)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].DL.format = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].DL.v.SQN.Format;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.ActTimeList.SecurityActTime[i].DL.sqn = ASSecurity->v.StartRestart.Integrity.v.ActTimeList.v.v[i].DL.v.SQN.Value;
}
}
}
}
if(ASSecurity->v.StartRestart.Ciphering.d == true)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).isCipheringInfoPresent = true;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ciphering_algorithm = ASSecurity->v.StartRestart.Ciphering.v.Algorithm;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc = CALLOC(1,16);
memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc,0,16);
bits_copy_from_array(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc, 0, ASSecurity->v.StartRestart.Ciphering.v.KRRCenc, 128);
LOG_E(GNB_APP, "[SYS-GNB] kRRCenc:\n");
for(int i = 0; i < 16; i++) {
LOG_E(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc[i]);
}
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc = CALLOC(1,16);
memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc,0,16);
bits_copy_from_array(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc, 0, ASSecurity->v.StartRestart.Ciphering.v.KUPenc, 128);
LOG_E(GNB_APP, "[SYS-GNB] kUPenc:\n");
for(int i = 0; i < 16; i++) {
LOG_E(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc[i]);
}
for(int i=0;i < ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.d; i++)
{
switch(ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].RadioBearerId.d)
{
case RadioBearerId_Type_Srb:
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].rb_id = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].RadioBearerId.v.Srb;
break;
case RadioBearerId_Type_Drb:
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].rb_id = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].RadioBearerId.v.Drb;
break;
case RadioBearerId_Type_UNBOUND_VALUE:
break;
default:
LOG_E(GNB_APP, "[SYS-GNB] AS Security Act time list is Invalid \n");
}
if (ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].UL.d == NR_PDCP_ActTime_Type_SQN)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].UL.format = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].UL.v.SQN.Format;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].UL.sqn = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].UL.v.SQN.Value;
}
if (ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].DL.d == NR_PDCP_ActTime_Type_SQN)
{
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].DL.format = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].DL.v.SQN.Format;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.ActTimeList.SecurityActTime[i].DL.sqn = ASSecurity->v.StartRestart.Ciphering.v.ActTimeList.v[i].DL.v.SQN.Value;
}
}
}
}
break;
case NR_AS_Security_Type_Release:
{
// TODO
}
break;
default:
LOG_E(GNB_APP, "[TASK_SYS_GNB] unhandled message type %d\n", ASSecurity->d);
return;
}
int send_res = itti_send_msg_to_task(TASK_RRC_GNB, INSTANCE_DEFAULT, msg_p);
if (send_res < 0) {
LOG_E(GNB_APP, "[SYS-GNB] Error sending RRC_AS_SECURITY_CONFIG_REQ to RRC_gNB task");
}
}
}
/* /*
* Function : sys_handle_nr_paging_req * Function : sys_handle_nr_paging_req
* Description: Handles the attenuation updates received from TTCN * Description: Handles the attenuation updates received from TTCN
...@@ -504,8 +637,9 @@ static void ss_task_sys_nr_handle_req(struct NR_SYSTEM_CTRL_REQ *req, ss_nrset_t ...@@ -504,8 +637,9 @@ static void ss_task_sys_nr_handle_req(struct NR_SYSTEM_CTRL_REQ *req, ss_nrset_t
break; break;
case NR_SystemRequest_Type_AS_Security: case NR_SystemRequest_Type_AS_Security:
{ {
LOG_A(GNB_APP, "[SYS-GNB] Dummy handling for Cell Config 5G NR_SystemRequest_Type_AS_Security \n"); LOG_A(GNB_APP, "[SYS-GNB] Handling for NR_SystemRequest_Type_AS_Security\n");
if ( req->Common.ControlInfo.CnfFlag) { sys_handle_nr_as_security_req(&(req->Request.v.AS_Security));
if (req->Common.ControlInfo.CnfFlag) {
send_sys_cnf(ConfirmationResult_Type_Success, true, NR_SystemConfirm_Type_AS_Security, NULL); send_sys_cnf(ConfirmationResult_Type_Success, true, NR_SystemConfirm_Type_AS_Security, NULL);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment