diff --git a/openair3/NAS/UE/EMM/SecurityModeControl.c b/openair3/NAS/UE/EMM/SecurityModeControl.c index 684784e3dbfdf9e18f2a92bf82cc5cc48ced444d..5a90b43cdee7d64bc7f2ffa423056ab7f3e86c04 100644 --- a/openair3/NAS/UE/EMM/SecurityModeControl.c +++ b/openair3/NAS/UE/EMM/SecurityModeControl.c @@ -64,6 +64,7 @@ Description Defines the security mode control EMM procedure executed by the # include "assertions.h" #include "secu_defs.h" #include "msc.h" +#include "SecurityModeControl.h" #if defined(NAS_BUILT_IN_UE) #include "nas_itti_messaging.h" @@ -92,13 +93,6 @@ static int _security_knas_int(const OctetString *kasme, OctetString *knas_int, static int _security_kenb(const OctetString *kasme, OctetString *kenb, uint32_t count); -/* - * Internal data used for security mode control procedure - */ -static struct { - OctetString kenb; /* eNodeB security key */ -} _security_data; - static void _security_release(emm_security_context_t *ctx); /* @@ -153,6 +147,7 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi, int rc = RETURNerror; int emm_cause = EMM_CAUSE_SUCCESS; int security_context_is_new = FALSE; + security_data_t *security_data = user->security_data; LOG_TRACE(INFO, "EMM-PROC - Security mode control requested (ksi=%d)", ksi); @@ -226,17 +221,17 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi, } /* Derive the eNodeB key */ - if (_security_data.kenb.value == NULL) { - _security_data.kenb.value = (uint8_t *)calloc(1,AUTH_KENB_SIZE); - _security_data.kenb.length = AUTH_KENB_SIZE; + if (security_data->kenb.value == NULL) { + security_data->kenb.value = (uint8_t *)calloc(1,AUTH_KENB_SIZE); + security_data->kenb.length = AUTH_KENB_SIZE; } - if (_security_data.kenb.value != NULL) { + if (security_data->kenb.value != NULL) { if (rc != RETURNerror) { LOG_TRACE(INFO, "EMM-PROC - Update the non-current EPS security context kenb"); // LG COMMENT rc = _security_kenb(&user->emm_data->security->kasme, rc = _security_kenb(&user->emm_data->non_current->kasme, - &_security_data.kenb, + &security_data->kenb, *(uint32_t *)(&user->emm_data->non_current->ul_count)); } } @@ -303,10 +298,10 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi, emm_cause = EMM_CAUSE_SECURITY_MODE_REJECTED; /* Release security mode control internal data */ - if (_security_data.kenb.value) { - free(_security_data.kenb.value); - _security_data.kenb.value = NULL; - _security_data.kenb.length = 0; + if (security_data->kenb.value) { + free(security_data->kenb.value); + security_data->kenb.value = NULL; + security_data->kenb.length = 0; } } } diff --git a/openair3/NAS/UE/EMM/SecurityModeControl.h b/openair3/NAS/UE/EMM/SecurityModeControl.h new file mode 100644 index 0000000000000000000000000000000000000000..314c168544dc24564371988bf16f1065ef3f54f6 --- /dev/null +++ b/openair3/NAS/UE/EMM/SecurityModeControl.h @@ -0,0 +1,11 @@ +#ifndef _SECURITYMODECONTROL_H +#define _SECURITYMODECONTROL_H + +/* + * Internal data used for security mode control procedure + */ +typedef struct { + OctetString kenb; /* eNodeB security key */ +} security_data_t; + +#endif diff --git a/openair3/NAS/UE/nas_proc.c b/openair3/NAS/UE/nas_proc.c index 7109feea4f7f064040f3001d4f15d6955db0efa0..b77e1123705a1c9e3e0fe523059eefb012e2044b 100644 --- a/openair3/NAS/UE/nas_proc.c +++ b/openair3/NAS/UE/nas_proc.c @@ -102,6 +102,13 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, LOG_TRACE(ERROR, "NAS-PROC - Failed to alloc authentication_data"); // FIXME stop here } + + user->security_data = calloc(1, sizeof(security_data_t)); + if ( user->security_data == NULL ) { + LOG_TRACE(ERROR, "NAS-PROC - Failed to alloc security_data"); + // FIXME stop here + } + /* Initialize the EMM procedure manager */ emm_main_initialize(user, emm_cb, imei); diff --git a/openair3/NAS/UE/user_defs.h b/openair3/NAS/UE/user_defs.h index 8e299fef399b0cd6ad6ec8c47dd9ef80ba0c8bfc..068736b62293703af4eff47d05579488d7109f9b 100644 --- a/openair3/NAS/UE/user_defs.h +++ b/openair3/NAS/UE/user_defs.h @@ -53,6 +53,7 @@ Description NAS type definition to manage a user equipment #include "EMM/Authentication.h" #include "EMM/IdleMode_defs.h" #include "API/USIM/usim_api.h" +#include "SecurityModeControl.h" typedef struct { int fd; @@ -66,6 +67,7 @@ typedef struct { emm_data_t *emm_data; // EPS mobility management data emm_plmn_list_t *emm_plmn_list; // list of PLMN identities authentication_data_t *authentication_data; + security_data_t *security_data; //Internal data used for security mode control procedure // Hardware persistent storage usim_data_t usim_data; // USIM application data } nas_user_t;