Commit f8219745 authored by Anatolii Pankevych's avatar Anatolii Pankevych Committed by Jerome Peraldi

bugz #125253: add AS Data Plane security: TC 7.1.3.2.x and 7.1.3.3.x

parent 542bcfb4
...@@ -260,6 +260,7 @@ security = { ...@@ -260,6 +260,7 @@ security = {
# rlc_log_level ="info"; # rlc_log_level ="info";
# pdcp_log_level ="info"; # pdcp_log_level ="info";
# rrc_log_level ="info"; # rrc_log_level ="info";
# ngap_log_level ="debug"; # nr_rrc_log_level ="info";
# ngap_log_level ="debug";
}; };
...@@ -5,9 +5,7 @@ log_config = { ...@@ -5,9 +5,7 @@ log_config = {
mac_log_level ="error"; mac_log_level ="error";
nr_mac_log_level ="error"; nr_mac_log_level ="error";
rlc_log_level ="info"; rlc_log_level ="info";
nr_rlc_log_level ="info"; pdcp_log_level ="info";
pdcp_log_level ="debug";
nr_pdcp_log_level ="debug";
rrc_log_level ="info"; rrc_log_level ="info";
nr_rrc_log_level ="info"; nr_rrc_log_level ="info";
}; };
......
...@@ -39,6 +39,18 @@ ...@@ -39,6 +39,18 @@
#include "radio/SS/ss_config.h" #include "radio/SS/ss_config.h"
#include "RRC/NR/nr_rrc_defs.h" #include "RRC/NR/nr_rrc_defs.h"
// Used for loopback message routing in DRB-specific TC's
typedef enum {
DRB_MacPdu = 0,
DRB_RlcPdu,
DRB_RlcSdu,
DRB_PdcpPdu,
DRB_PdcpSdu,
DRB_SdapPdu,
DRB_SdapSdu,
DRB_data_type_qty
} nr_drb_data_t;
// forward declarations to avoid including the full typess ***eNB; // forward declarations to avoid including the full typess ***eNB;
struct PHY_VARS_gNB_s; struct PHY_VARS_gNB_s;
struct PHY_VARS_eNB_NB_IoT_s; struct PHY_VARS_eNB_NB_IoT_s;
...@@ -133,6 +145,8 @@ typedef struct { ...@@ -133,6 +145,8 @@ typedef struct {
struct ss_config_s ss; struct ss_config_s ss;
// Variable to store Transaction ID for SS in case of RRCReconfiguration // Variable to store Transaction ID for SS in case of RRCReconfiguration
long rrc_Transaction_Identifier; long rrc_Transaction_Identifier;
// Loopback mode can operate on either sdap, pdcp or rlc
nr_drb_data_t nr_drb_data_type;
RBConfig RB_Config[MAX_NUM_CCs][MAX_RBS]; RBConfig RB_Config[MAX_NUM_CCs][MAX_RBS];
NRRBConfig NR_RB_Config[MAX_NUM_CCs][MAX_NR_RBS]; NRRBConfig NR_RB_Config[MAX_NUM_CCs][MAX_NR_RBS];
} RAN_CONTEXT_t; } RAN_CONTEXT_t;
......
...@@ -153,6 +153,8 @@ typedef struct SecurityActTimeList_s { ...@@ -153,6 +153,8 @@ typedef struct SecurityActTimeList_s {
typedef struct AS_IntegrityInfo_s { typedef struct AS_IntegrityInfo_s {
e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm; e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
uint8_t *kRRCint; uint8_t *kRRCint;
bool isUPIntegrityInfoPresent;
uint8_t *kUPint;
SecurityActTimeList ActTimeList; SecurityActTimeList ActTimeList;
}AS_IntegrityInfo; }AS_IntegrityInfo;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "nr_pdcp_integrity_nia1.h" #include "nr_pdcp_integrity_nia1.h"
#include "nr_pdcp_sdu.h" #include "nr_pdcp_sdu.h"
#include "MAC/mac.h" // for DCCH
#include "LOG/log.h" #include "LOG/log.h"
// 2DO: REMOVE, FOR DEBUG PURPOSES ONLY // 2DO: REMOVE, FOR DEBUG PURPOSES ONLY
#include "nr_pdcp_security.h" #include "nr_pdcp_security.h"
...@@ -93,7 +95,6 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity, ...@@ -93,7 +95,6 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
entity->stats.rxpdu_dd_pkts++; entity->stats.rxpdu_dd_pkts++;
entity->stats.rxpdu_dd_bytes += size; entity->stats.rxpdu_dd_bytes += size;
return; return;
} }
...@@ -116,7 +117,8 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity, ...@@ -116,7 +117,8 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
if (entity->has_ciphering) if (entity->has_ciphering)
{ {
if (entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_SMC) { // 3GPP TS 33.501 6.7.4, Security Mode Command is on SRB1
if (entity->type == NR_PDCP_SRB && entity->rb_id == DCCH && entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_SMC) {
LOG_I(PDCP, "%s: Skip deciphering during Security Mode Command\n", __FUNCTION__); LOG_I(PDCP, "%s: Skip deciphering during Security Mode Command\n", __FUNCTION__);
} else { } else {
LOG_I(PDCP, "%s: Deciphering...\n", __FUNCTION__); LOG_I(PDCP, "%s: Deciphering...\n", __FUNCTION__);
...@@ -206,7 +208,7 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity, ...@@ -206,7 +208,7 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
FNOUT; FNOUT;
} }
// RRC to PDCP // RRC/SDAP to PDCP
static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity, static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity,
char *buffer, int size, int sdu_id) char *buffer, int size, int sdu_id)
{ {
...@@ -256,7 +258,8 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity, ...@@ -256,7 +258,8 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity,
LOG_I(PDCP, "Entity security status (%d): ciphering %d, integrity check %d\n", entity->has_ciphering, LOG_I(PDCP, "Entity security status (%d): ciphering %d, integrity check %d\n", entity->has_ciphering,
entity->has_ciphering?entity->ciphering_algorithm:-1, entity->has_integrity?entity->integrity_algorithm:-1); entity->has_ciphering?entity->ciphering_algorithm:-1, entity->has_integrity?entity->integrity_algorithm:-1);
if (entity->has_integrity){ if (entity->has_integrity)
{
uint8_t integrity[4] = {0}; uint8_t integrity[4] = {0};
LOG_I(PDCP, "%s: Integrity protection...\n", __FUNCTION__); LOG_I(PDCP, "%s: Integrity protection...\n", __FUNCTION__);
LOG_MSG(buf, header_size + size, "rbid=%d cnt=%d dir=%d, buffer(%d): ", entity->rb_id, count, entity->is_gnb ? 1 : 0, header_size + size); LOG_MSG(buf, header_size + size, "rbid=%d cnt=%d dir=%d, buffer(%d): ", entity->rb_id, count, entity->is_gnb ? 1 : 0, header_size + size);
...@@ -270,13 +273,14 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity, ...@@ -270,13 +273,14 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity,
memcpy((unsigned char *)buf + header_size + size, integrity, 4); memcpy((unsigned char *)buf + header_size + size, integrity, 4);
} else if (integrity_size == 4) { } else if (integrity_size == 4) {
// set MAC-I to 0 for SRBs with integrity not active // set MAC-I to 0 for SRBs with integrity not active
memset(buf + header_size + size, 0, 4); memset(buf + header_size + size, 0, 4);
} }
if (entity->has_ciphering) if (entity->has_ciphering)
{ {
if (entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_SMC) { // 3GPP TS 33.501 6.7.4, Security Mode Command is on SRB1
if (entity->type == NR_PDCP_SRB && entity->rb_id == DCCH && entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_SMC) {
/* 3GPP TS 33.501, 6.7.4: RRC DL ciphering @gNB shall start after sending the AS security mode command message */ /* 3GPP TS 33.501, 6.7.4: RRC DL ciphering @gNB shall start after sending the AS security mode command message */
LOG_I(PDCP, "%s: Skip ciphering during Security Mode Command\n", __FUNCTION__); LOG_I(PDCP, "%s: Skip ciphering during Security Mode Command\n", __FUNCTION__);
if (!entity->is_gnb && count > 0) { if (!entity->is_gnb && count > 0) {
...@@ -376,7 +380,9 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity, ...@@ -376,7 +380,9 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity,
} }
if (ciphering_algorithm != 0 && ciphering_algorithm != -1) { if (ciphering_algorithm != 0 && ciphering_algorithm != -1) {
entity->has_ciphering = entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_ON?NR_PDCP_ENTITY_CIPHERING_ON:NR_PDCP_ENTITY_CIPHERING_SMC; if (entity->type == NR_PDCP_SRB && entity->rb_id == DCCH && entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_OFF) {
entity->has_ciphering = NR_PDCP_ENTITY_CIPHERING_SMC;
}
LOG_I(PDCP, "%s: entity->has_ciphering %d\n", __FUNCTION__, entity->has_ciphering); LOG_I(PDCP, "%s: entity->has_ciphering %d\n", __FUNCTION__, entity->has_ciphering);
if (entity->free_security != NULL) { if (entity->free_security != NULL) {
entity->free_security(entity->security_context); entity->free_security(entity->security_context);
......
...@@ -36,7 +36,7 @@ typedef enum { ...@@ -36,7 +36,7 @@ typedef enum {
} nr_pdcp_entity_type_t; } nr_pdcp_entity_type_t;
/** /**
* 3GPP TS 33.501 * 3GPP TS 33.501 6.7.4
* RRC downlink ciphering (encryption) at the gNB shall start after sending the AS security mode command message. * 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 deciphering (decryption) at the gNB shall start after receiving and successful verification of the AS security mode complete message.
* *
......
This diff is collapsed.
...@@ -158,8 +158,10 @@ void mac_rlc_data_ind ( ...@@ -158,8 +158,10 @@ void mac_rlc_data_ind (
T(T_ENB_RLC_MAC_UL, T_INT(module_idP), T_INT(rntiP), T(T_ENB_RLC_MAC_UL, T_INT(module_idP), T_INT(rntiP),
T_INT(channel_idP), T_INT(tb_sizeP)); T_INT(channel_idP), T_INT(tb_sizeP));
LOG_UDUMPMSG(RLC, buffer_pP, tb_sizeP, LOG_DUMP_CHAR, "%s: ", __FUNCTION__);
if (RC.ss.mode >= SS_SOFTMODEM) { if (RC.ss.mode >= SS_SOFTMODEM) {
if ((tb_sizeP != 0) && (true == enb_flagP) && (channel_idP >= 4)) { if ((tb_sizeP != 0) && (true == enb_flagP) && (channel_idP >= 4) && (RC.nr_drb_data_type == DRB_RlcPdu)) {
int drb_id = channel_idP - 3; int drb_id = channel_idP - 3;
int result; int result;
LOG_A(RLC, "Sending packet to SS, Calling SS_DRB_PDU_IND ue %x drb id %d size %u\n", rntiP, drb_id, tb_sizeP); LOG_A(RLC, "Sending packet to SS, Calling SS_DRB_PDU_IND ue %x drb id %d size %u\n", rntiP, drb_id, tb_sizeP);
...@@ -179,11 +181,11 @@ void mac_rlc_data_ind ( ...@@ -179,11 +181,11 @@ void mac_rlc_data_ind (
} }
} }
RC.nr_drb_data_type = DRB_data_type_qty;
return; return;
} }
} }
// Trace UL RLC PDU Here
nr_rlc_pkt_info_t rlc_pkt; nr_rlc_pkt_info_t rlc_pkt;
rlc_pkt.direction = DIRECTION_UPLINK; rlc_pkt.direction = DIRECTION_UPLINK;
rlc_pkt.ueid = rntiP; rlc_pkt.ueid = rntiP;
...@@ -239,7 +241,6 @@ tbs_size_t mac_rlc_data_req( ...@@ -239,7 +241,6 @@ tbs_size_t mac_rlc_data_req(
nr_rlc_entity_t *rb; nr_rlc_entity_t *rb;
int maxsize; int maxsize;
// Trace UL RLC PDU Here
nr_rlc_pkt_info_t rlc_pkt; nr_rlc_pkt_info_t rlc_pkt;
rlc_pkt.direction = DIRECTION_DOWNLINK; rlc_pkt.direction = DIRECTION_DOWNLINK;
rlc_pkt.ueid = rntiP; rlc_pkt.ueid = rntiP;
...@@ -630,6 +631,8 @@ rb_found: ...@@ -630,6 +631,8 @@ rb_found:
is_enb = nr_rlc_manager_get_enb_flag(nr_rlc_ue_manager); is_enb = nr_rlc_manager_get_enb_flag(nr_rlc_ue_manager);
ctx.enb_flag = is_enb; ctx.enb_flag = is_enb;
LOG_UDUMPMSG(RLC, buf, size, LOG_DUMP_CHAR, "%s: ", __FUNCTION__);
if (is_enb) { if (is_enb) {
T(T_ENB_RLC_UL, T(T_ENB_RLC_UL,
T_INT(0 /*ctxt_pP->module_id*/), T_INT(0 /*ctxt_pP->module_id*/),
...@@ -681,7 +684,7 @@ rb_found: ...@@ -681,7 +684,7 @@ rb_found:
exit(1); exit(1);
} }
memcpy(memblock->data, buf, size); memcpy(memblock->data, buf, size);
LOG_D(PDCP, "Calling PDCP layer from RLC in %s\n", __FUNCTION__); LOG_I(RLC, "Calling PDCP layer from RLC in %s\n", __FUNCTION__);
if (!pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock, NULL, NULL)) { if (!pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock, NULL, NULL)) {
LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__); LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__);
/* what to do in case of failure? for the moment: nothing */ /* what to do in case of failure? for the moment: nothing */
...@@ -722,7 +725,7 @@ static void successful_delivery(void *_ue, nr_rlc_entity_t *entity, int sdu_id) ...@@ -722,7 +725,7 @@ static void successful_delivery(void *_ue, nr_rlc_entity_t *entity, int sdu_id)
exit(1); exit(1);
rb_found: rb_found:
LOG_D(RLC, "sdu %d was successfully delivered on %s %d\n", LOG_I(RLC, "sdu %d was successfully delivered on %s %d\n",
sdu_id, sdu_id,
is_srb ? "SRB" : "DRB", is_srb ? "SRB" : "DRB",
rb_id); rb_id);
...@@ -820,7 +823,7 @@ void *rlc_enb_task(void *arg) ...@@ -820,7 +823,7 @@ void *rlc_enb_task(void *arg)
if (RC.ss.mode >= SS_SOFTMODEM) { if (RC.ss.mode >= SS_SOFTMODEM) {
protocol_ctxt_t ctxt; protocol_ctxt_t ctxt;
instance_t instance = ITTI_MSG_DESTINATION_INSTANCE(received_msg); instance_t instance = ITTI_MSG_DESTINATION_INSTANCE(received_msg);
LOG_D(RLC, "RLC received SS_DRB_PDU_REQ DRB_ID:%d SDU_SIZE:%d\n", LOG_I(RLC, "RLC received SS_DRB_PDU_REQ DRB_ID:%d SDU_SIZE:%d\n",
SS_DRB_PDU_REQ(received_msg).drb_id, SS_DRB_PDU_REQ(received_msg).sdu_size); SS_DRB_PDU_REQ(received_msg).drb_id, SS_DRB_PDU_REQ(received_msg).sdu_size);
PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
instance, instance,
......
...@@ -122,11 +122,13 @@ mui_t rrc_gNB_mui = 0; ...@@ -122,11 +122,13 @@ 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 // temp static storage of AS Security settings for SRB1 and SRB2
static e_NR_IntegrityProtAlgorithm _int_algo = 0; static e_NR_IntegrityProtAlgorithm _int_algo = 0;
static NR_CipheringAlgorithm_t _cip_algo = 0; static NR_CipheringAlgorithm_t _cip_algo = 0;
static uint8_t _nr_cp_int_key[16] = {0}; static uint8_t _nr_control_plane_int_key[16] = {0};
static uint8_t _nr_cp_cip_key[16] = {0}; static uint8_t _nr_control_plane_cip_key[16] = {0};
static uint8_t _nr_data_plane_int_key[16] = {0};
static uint8_t _nr_data_plane_cip_key[16] = {0};
///---------------------------------------------------------------------------------------------------------------/// ///---------------------------------------------------------------------------------------------------------------///
///---------------------------------------------------------------------------------------------------------------/// ///---------------------------------------------------------------------------------------------------------------///
...@@ -917,10 +919,9 @@ static void rrc_gNB_generate_defaultRRCReconfiguration(const protocol_ctxt_t *co ...@@ -917,10 +919,9 @@ static void rrc_gNB_generate_defaultRRCReconfiguration(const protocol_ctxt_t *co
size, size,
buffer, buffer,
PDCP_TRANSMISSION_MODE_CONTROL); PDCP_TRANSMISSION_MODE_CONTROL);
}
// rrc_pdcp_config_asn1_req // rrc_pdcp_config_asn1_req
}
break; break;
case ngran_gNB_DU: case ngran_gNB_DU:
// nothing to do for DU // nothing to do for DU
...@@ -1646,9 +1647,13 @@ rrc_gNB_process_RRCReconfigurationComplete( ...@@ -1646,9 +1647,13 @@ rrc_gNB_process_RRCReconfigurationComplete(
kRRCenc = (uint8_t*)malloc(16); kRRCenc = (uint8_t*)malloc(16);
kRRCint = (uint8_t*)malloc(16); kRRCint = (uint8_t*)malloc(16);
AssertFatal(kRRCint && kRRCenc, "malloc failed"); kUPint = (uint8_t*)malloc(16);
memcpy(kRRCenc, _nr_cp_cip_key, 16); kUPenc = (uint8_t*)malloc(16);
memcpy(kRRCint, _nr_cp_int_key, 16); AssertFatal(kRRCint && kRRCenc && kUPint && kUPenc, "malloc failed\n");
memcpy(kRRCenc, _nr_control_plane_cip_key, 16);
memcpy(kRRCint, _nr_control_plane_int_key, 16);
memcpy(kUPint, _nr_data_plane_int_key, 16);
memcpy(kUPenc, _nr_data_plane_int_key, 16);
LOG_D(NR_RRC, "Configuring PDCP DRBs/SRBs for UE %04x\n", ue_context_pP->ue_context.rnti); LOG_D(NR_RRC, "Configuring PDCP DRBs/SRBs for UE %04x\n", ue_context_pP->ue_context.rnti);
...@@ -1674,7 +1679,7 @@ rrc_gNB_process_RRCReconfigurationComplete( ...@@ -1674,7 +1679,7 @@ rrc_gNB_process_RRCReconfigurationComplete(
ctxt_pP->rntiMaybeUEid, ctxt_pP->rntiMaybeUEid,
reestablish_ue_id, reestablish_ue_id,
DRB_configList, DRB_configList,
(ue_context_pP->ue_context.integrity_algorithm << 4) | ue_context_pP->ue_context.ciphering_algorithm, (_int_algo << 4) | _cip_algo,
kUPenc, kUPenc,
kUPint, kUPint,
get_softmodem_params()->sa ? ue_context_pP->ue_context.masterCellGroup->rlc_BearerToAddModList : NULL); get_softmodem_params()->sa ? ue_context_pP->ue_context.masterCellGroup->rlc_BearerToAddModList : NULL);
...@@ -4678,15 +4683,19 @@ void *rrc_gnb_task(void *args_p) { ...@@ -4678,15 +4683,19 @@ void *rrc_gnb_task(void *args_p) {
msg_p->ittiMsgHeader.lte_time.frame, msg_p->ittiMsgHeader.lte_time.slot); msg_p->ittiMsgHeader.lte_time.frame, msg_p->ittiMsgHeader.lte_time.slot);
if (_int_algo > 0) { if (_int_algo > 0) {
memcpy(&(_nr_cp_int_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[0]), 16); memcpy(&(_nr_control_plane_int_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[0]), 16);
memcpy(&(_nr_data_plane_int_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kUPint[0]), 16);
} else { } else {
memset(&(_nr_cp_int_key[0]), 0, 16); memset(&(_nr_control_plane_int_key[0]), 0, 16);
memset(&(_nr_data_plane_int_key[0]), 0, 16);
} }
if (_cip_algo > 0) { if (_cip_algo > 0) {
memcpy(&(_nr_cp_cip_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc[0]), 16); memcpy(&(_nr_control_plane_cip_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kRRCenc[0]), 16);
memcpy(&(_nr_data_plane_cip_key[0]), &(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Ciphering.kUPenc[0]), 16);
} else { } else {
memset(&(_nr_cp_cip_key[0]), 0, 16); memset(&(_nr_control_plane_cip_key[0]), 0, 16);
memset(&(_nr_data_plane_cip_key[0]), 0, 16);
} }
int unused = 0; int unused = 0;
......
...@@ -1784,8 +1784,8 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB ...@@ -1784,8 +1784,8 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
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);
} }
log_dump(MAC, buffer, 16, LOG_DUMP_CHAR, "securityModeComplete payload: "); log_dump(NR_RRC, buffer, (enc_rval.encoded+7)/8, LOG_DUMP_CHAR, "securityModeComplete payload: ");
LOG_D(NR_RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8); LOG_I(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_I(NR_RRC, "%02x.", buffer[i]); LOG_I(NR_RRC, "%02x.", buffer[i]);
......
...@@ -1311,11 +1311,14 @@ static void generateCloseUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNa ...@@ -1311,11 +1311,14 @@ static void generateCloseUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNa
} }
static void generateOpenUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNasMsg) { static void generateOpenUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNasMsg) {
LOG_FUNC_IN;
int size = sizeof(mm_msg_header_t); int size = sizeof(mm_msg_header_t);
fgs_nas_message_t nas_msg={0}; fgs_nas_message_t nas_msg={0};
int security_header_len = 0;
int msg_len = 0;
MM_msg *mm_msg; MM_msg *mm_msg;
nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE;
nas_msg.header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED; nas_msg.header.security_header_type = INTEGRITY_PROTECTED_AND_CIPHERED;
size += 7; size += 7;
...@@ -1335,36 +1338,33 @@ static void generateOpenUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNas ...@@ -1335,36 +1338,33 @@ static void generateOpenUeTestLoopComplete(int Mod_id, as_nas_info_t *initialNas
// encode the message // encode the message
initialNasMsg->data = (Byte_t *)malloc(size * sizeof(Byte_t)); initialNasMsg->data = (Byte_t *)malloc(size * sizeof(Byte_t));
int security_header_len = nas_protected_security_header_encode((char*)(initialNasMsg->data),&(nas_msg.header), size); security_header_len = nas_protected_security_header_encode((char*)(initialNasMsg->data),&(nas_msg.header), size);
msg_len = mm_msg_encode(mm_msg, (uint8_t*)(initialNasMsg->data+security_header_len), size-security_header_len);
initialNasMsg->length = security_header_len + mm_msg_encode(mm_msg, (uint8_t*)(initialNasMsg->data+security_header_len), size-security_header_len); initialNasMsg->length = security_header_len + msg_len;
LOG_T(NAS, "header len %d, msg len %d, todal: %d\n", security_header_len, msg_len, initialNasMsg->length);
printf("Before Security: "); for (int i = 0; i < initialNasMsg->length; ++i) printf("%02x", (initialNasMsg->data)[i]); printf("\n");
_ul_nas_count = 256; /* HACK: Only to match expected TTCN value in TC 7.1.3.x*/
// Ciphering
_encrypt_nas_msg(Mod_id, _ul_nas_count, initialNasMsg->data + security_header_len, msg_len);
/* Workaround fix of bypassing security for the TTCN */ // Integrity
#if 0 _calculate_nas_maci(Mod_id, SECU_DIRECTION_UPLINK, _ul_nas_count, initialNasMsg->data + security_header_len - 1, msg_len +1, mac);
nas_stream_cipher_t stream_cipher; printf("xmac %02x%02x%02x%02x\n", mac[0], mac[1], mac[2], mac[3]);
stream_cipher.key = ue_security_key[Mod_id]->knas_int; for(int i = 0; i < 4; i++) {
stream_cipher.key_length = 16; initialNasMsg->data[2+i] = mac[i];
stream_cipher.count = 0;
stream_cipher.bearer = 1;
stream_cipher.direction = 0;
stream_cipher.message = (unsigned char *)(initialNasMsg->data + 6);
/* length in bits */
stream_cipher.blength = (initialNasMsg->length - 6) << 3;
// only for Type of integrity protection algorithm: 128-5G-IA2 (2)
nas_stream_encrypt_eia2(
&stream_cipher,
mac);
#endif
for(int i = 0; i < 4; i++){
initialNasMsg->data[2+i] = 0;//mac[i];/* Workaround fix of bypassing security for the TTCN */
} }
printf("After Security: "); for (int i = 0; i < initialNasMsg->length; ++i) printf("%02x", (initialNasMsg->data)[i]); printf("\n");
LOG_FUNC_OUT;
} }
static void generateDeactivateTestModeComplete(int Mod_id, as_nas_info_t *initialNasMsg) { static void generateDeactivateTestModeComplete(int Mod_id, as_nas_info_t *initialNasMsg) {
LOG_FUNC_IN;
int size = sizeof(mm_msg_header_t); int size = sizeof(mm_msg_header_t);
fgs_nas_message_t nas_msg={0}; fgs_nas_message_t nas_msg={0};
int security_header_len = 0;
int msg_len = 0;
MM_msg *mm_msg; MM_msg *mm_msg;
nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE; nas_msg.header.protocol_discriminator = FGS_MOBILITY_MANAGEMENT_MESSAGE;
...@@ -1386,34 +1386,25 @@ static void generateDeactivateTestModeComplete(int Mod_id, as_nas_info_t *initia ...@@ -1386,34 +1386,25 @@ static void generateDeactivateTestModeComplete(int Mod_id, as_nas_info_t *initia
// encode the message // encode the message
initialNasMsg->data = (Byte_t *)malloc(size * sizeof(Byte_t)); initialNasMsg->data = (Byte_t *)malloc(size * sizeof(Byte_t));
int security_header_len = nas_protected_security_header_encode((char*)(initialNasMsg->data),&(nas_msg.header), size); security_header_len = nas_protected_security_header_encode((char*)(initialNasMsg->data),&(nas_msg.header), size);
msg_len = mm_msg_encode(mm_msg, (uint8_t*)(initialNasMsg->data+security_header_len), size-security_header_len);
initialNasMsg->length = security_header_len + mm_msg_encode(mm_msg, (uint8_t*)(initialNasMsg->data+security_header_len), size-security_header_len); initialNasMsg->length = security_header_len + msg_len;
#if 0 LOG_T(NAS, "header len %d, msg len %d, todal: %d\n", security_header_len, msg_len, initialNasMsg->length);
nas_stream_cipher_t stream_cipher;
stream_cipher.key = ue_security_key[Mod_id]->knas_int;
stream_cipher.key_length = 16;
stream_cipher.count = 0;
stream_cipher.bearer = 1;
stream_cipher.direction = 0;
stream_cipher.message = (unsigned char *)(initialNasMsg->data + 6);
/* length in bits */
stream_cipher.blength = (initialNasMsg->length - 6) << 3;
/* Workaround fix of bypassing security for the TTCN */ printf("Before Security: "); for (int i = 0; i < initialNasMsg->length; ++i) printf("%02x", (initialNasMsg->data)[i]); printf("\n");
_ul_nas_count = 256; /* HACK: Only to match expected TTCN value in TC 7.1.3.x*/
// Ciphering
_encrypt_nas_msg(Mod_id, _ul_nas_count, initialNasMsg->data + security_header_len, msg_len);
// only for Type of integrity protection algorithm: 128-5G-IA2 (2) // Integrity
uint8_t mac[4]; _calculate_nas_maci(Mod_id, SECU_DIRECTION_UPLINK, _ul_nas_count, initialNasMsg->data + security_header_len - 1, msg_len +1, mac);
nas_stream_encrypt_eia2(
&stream_cipher,
mac);
printf("xmac %02x%02x%02x%02x\n", mac[0], mac[1], mac[2], mac[3]);
#endif
for(int i = 0; i < 4; i++){ printf("xmac %02x%02x%02x%02x\n", mac[0], mac[1], mac[2], mac[3]);
initialNasMsg->data[2+i] = 0;//mac[i];/* Workaround fix of bypassing security for the TTCN */ for(int i = 0; i < 4; i++) {
initialNasMsg->data[2+i] = mac[i];
} }
printf("After Security: "); for (int i = 0; i < initialNasMsg->length; ++i) printf("%02x", (initialNasMsg->data)[i]); printf("\n");
LOG_FUNC_OUT;
} }
void generateServiceRequestInner(as_nas_info_t *initialNasMsg, int Mod_id) { void generateServiceRequestInner(as_nas_info_t *initialNasMsg, int Mod_id) {
...@@ -1654,9 +1645,12 @@ void *nas_nrue_task(void *args_p) ...@@ -1654,9 +1645,12 @@ void *nas_nrue_task(void *args_p)
pdu_buffer_len = NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length; pdu_buffer_len = NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length;
LOG_I(NAS, "NAS_DOWNLINK_DATA_IND msg: "); LOG_I(NAS, "NAS_DOWNLINK_DATA_IND msg: ");
// TODOAGP replace
for (int i = 0; i < pdu_buffer_len; i++) { for (int i = 0; i < pdu_buffer_len; i++) {
LOG_I(NAS, "%02x", pdu_buffer[i]); // LOG_I(NAS, "%02x", pdu_buffer[i]);
printf("%02x", pdu_buffer[i]);
} }
printf("\n");
if(_security_set) { if(_security_set) {
_dl_nas_count++; _dl_nas_count++;
......
This diff is collapsed.
...@@ -283,7 +283,7 @@ static void ss_task_handle_rrc_pdu_req(struct NR_RRC_PDU_REQ *req) ...@@ -283,7 +283,7 @@ static void ss_task_handle_rrc_pdu_req(struct NR_RRC_PDU_REQ *req)
} }
LOG_A(GNB_APP, "[SS_SRB][NR_RRC_PDU_REQ] sending to TASK_RRC_GNB: {srb: %d, ch: %s, qty: %d }", LOG_A(GNB_APP, "[SS_SRB][NR_RRC_PDU_REQ] sending to TASK_RRC_GNB: {srb: %d, ch: %s, qty: %d }\n",
SS_NRRRC_PDU_REQ(message_p).srb_id, SS_NRRRC_PDU_REQ(message_p).srb_id,
req->RrcPdu.d == NR_RRC_MSG_Request_Type_Ccch ? "CCCH" : "DCCH", SS_NRRRC_PDU_REQ(message_p).sdu_size); req->RrcPdu.d == NR_RRC_MSG_Request_Type_Ccch ? "CCCH" : "DCCH", SS_NRRRC_PDU_REQ(message_p).sdu_size);
...@@ -294,7 +294,7 @@ static void ss_task_handle_rrc_pdu_req(struct NR_RRC_PDU_REQ *req) ...@@ -294,7 +294,7 @@ static void ss_task_handle_rrc_pdu_req(struct NR_RRC_PDU_REQ *req)
LOG_A(GNB_APP, "[SS_SRB] Error in itti_send_msg_to_task"); LOG_A(GNB_APP, "[SS_SRB] Error in itti_send_msg_to_task");
} }
LOG_A(GNB_APP, "Send res: %d", send_res); LOG_A(GNB_APP, "Send res: %d\n", send_res);
} }
} }
......
...@@ -262,7 +262,7 @@ static void sys_handle_nr_as_security_req(struct NR_AS_Security_Type *ASSecurity ...@@ -262,7 +262,7 @@ 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); MessageDef *msg_p = itti_alloc_new_message(TASK_SYS_GNB, INSTANCE_DEFAULT, RRC_AS_SECURITY_CONFIG_REQ);
if(msg_p) if(msg_p)
{ {
LOG_E(GNB_APP,"[SYS-GNB] AS Security Request Received\n"); LOG_I(GNB_APP,"[SYS-GNB] AS Security Request Received\n");
RRC_AS_SECURITY_CONFIG_REQ(msg_p).rnti = SS_context.ss_rnti_g; RRC_AS_SECURITY_CONFIG_REQ(msg_p).rnti = SS_context.ss_rnti_g;
switch(ASSecurity->d) { switch(ASSecurity->d) {
...@@ -275,9 +275,21 @@ static void sys_handle_nr_as_security_req(struct NR_AS_Security_Type *ASSecurity ...@@ -275,9 +275,21 @@ static void sys_handle_nr_as_security_req(struct NR_AS_Security_Type *ASSecurity
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint = CALLOC(1,16); RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint = CALLOC(1,16);
memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint,0,16); memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint,0,16);
bits_copy_from_array((char*)RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint, 0, (const char*)ASSecurity->v.StartRestart.Integrity.v.KRRCint, 128); bits_copy_from_array((char*)RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint, 0, (const char*)ASSecurity->v.StartRestart.Integrity.v.KRRCint, 128);
LOG_E(GNB_APP, "[SYS-GNB] kRRCint:\n"); LOG_I(GNB_APP, "[SYS-GNB] kRRCint:\n");
for(int i = 0; i < 16; i++) { for(int i = 0; i < 16; i++) {
LOG_E(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[i]); LOG_I(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kRRCint[i]);
}
if (ASSecurity->v.StartRestart.Integrity.v.KUPint.d == true) {
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.isUPIntegrityInfoPresent = true;
RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kUPint = CALLOC(1, 16);
memset(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kUPint, 0, 16);
bits_copy_from_array(RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kUPint, 0, ASSecurity->v.StartRestart.Integrity.v.KUPint.v, 128);
LOG_I(GNB_APP, "[SYS-GNB] kUPint:\n");
for(int i = 0; i < 16; i++) {
LOG_I(GNB_APP, "%02x\n", RRC_AS_SECURITY_CONFIG_REQ(msg_p).Integrity.kUPint[i]);
}
} }
if(ASSecurity->v.StartRestart.Integrity.v.ActTimeList.d == true) if(ASSecurity->v.StartRestart.Integrity.v.ActTimeList.d == true)
......
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