diff --git a/openair3/NAS/UE/EMM/Attach.c b/openair3/NAS/UE/EMM/Attach.c index 0594306f6acc2552390c5f1552bf9ed3bf754bdb..b47b8cea8b5cfc4bc8c8c9742f8423026a36d89f 100644 --- a/openair3/NAS/UE/EMM/Attach.c +++ b/openair3/NAS/UE/EMM/Attach.c @@ -99,16 +99,6 @@ static void *_emm_attach_t3402_handler(void *); */ static void _emm_attach_abnormal_cases_bcd(nas_user_t *user, emm_sap_t *); -/* - * Internal data used for attach procedure - */ -static struct { -#define EMM_ATTACH_COUNTER_MAX 5 - unsigned int attempt_count; /* Counter used to limit the number of - * subsequently rejected attach attempts */ -} _emm_attach_data = {0}; - - /****************************************************************************/ /****************** E X P O R T E D F U N C T I O N S ******************/ /****************************************************************************/ @@ -499,7 +489,6 @@ int emm_proc_attach_accept(nas_user_t *user, long t3412, long t3402, long t3423, ** ** ** Outputs: None ** ** Return: RETURNok, RETURNerror ** - ** Others: user->emm_data-> _emm_attach_data, T3410 ** ** ** ***************************************************************************/ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *esm_msg_pP) @@ -509,6 +498,7 @@ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *e emm_sap_t emm_sap; int rc; emm_timers_t *emm_timers = user->emm_data->emm_timers; + emm_attach_data_t *emm_attach_data = user->emm_data->emm_attach_data; LOG_TRACE(WARNING, "EMM-PROC - EPS attach rejected by the network, " "EMM cause = %d", emm_cause); @@ -566,14 +556,14 @@ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *e /* Delete the list of equivalent PLMNs */ user->emm_data->nvdata.eplmn.n_plmns = 0; /* Reset the attach attempt counter */ - _emm_attach_data.attempt_count = 0; + emm_attach_data->attempt_count = 0; break; case EMM_CAUSE_TA_NOT_ALLOWED: case EMM_CAUSE_EPS_NOT_ALLOWED_IN_PLMN: case EMM_CAUSE_NO_SUITABLE_CELLS: /* Reset the attach attempt counter */ - _emm_attach_data.attempt_count = 0; + emm_attach_data->attempt_count = 0; break; case EMM_CAUSE_ESM_FAILURE: @@ -582,7 +572,7 @@ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *e if (user->emm_data->NAS_SignallingPriority != 1) { /* The UE is not configured for NAS signalling low priority; * set the attach attempt counter to 5 */ - _emm_attach_data.attempt_count = EMM_ATTACH_COUNTER_MAX; + emm_attach_data->attempt_count = EMM_ATTACH_COUNTER_MAX; } break; @@ -594,7 +584,7 @@ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *e case EMM_CAUSE_PROTOCOL_ERROR: /* 3GPP TS 24.301, section 5.5.1.2.6, case d * Set the attach attempt counter to 5 */ - _emm_attach_data.attempt_count = EMM_ATTACH_COUNTER_MAX; + emm_attach_data->attempt_count = EMM_ATTACH_COUNTER_MAX; break; default : @@ -717,14 +707,14 @@ int emm_proc_attach_reject(nas_user_t *user, int emm_cause, const OctetString *e ** ** ** Outputs: None ** ** Return: RETURNok, RETURNerror ** - ** Others: user->emm_data-> _emm_attach_data ** ** ** ***************************************************************************/ int emm_proc_attach_complete(void *args) { LOG_FUNC_IN; - nas_user_t *user=args; + nas_user_t *user = args; + emm_attach_data_t *emm_attach_data = user->emm_data->emm_attach_data; emm_sap_t emm_sap; esm_sap_t esm_sap; int rc; @@ -735,7 +725,7 @@ int emm_proc_attach_complete(void *args) (void) emm_proc_lowerlayer_initialize(NULL, NULL, NULL, NULL); /* Reset the attach attempt counter */ - _emm_attach_data.attempt_count = 0; + emm_attach_data->attempt_count = 0; /* TODO: Reset the tracking area updating attempt counter */ /* Set the EPS update status to EU1 UPDATED */ @@ -1088,15 +1078,15 @@ static void *_emm_attach_t3411_handler(void *args) ** ** ** Outputs: None ** ** Return: None ** - ** Others: _emm_attach_data, T3402 ** ** ** ***************************************************************************/ static void *_emm_attach_t3402_handler(void *args) { LOG_FUNC_IN; - nas_user_t *user=args; + nas_user_t *user = args; emm_timers_t *emm_timers = user->emm_data->emm_timers; + emm_attach_data_t *emm_attach_data = user->emm_data->emm_attach_data; emm_sap_t emm_sap; LOG_TRACE(WARNING, "EMM-PROC - T3402 timer expired"); @@ -1104,7 +1094,7 @@ static void *_emm_attach_t3402_handler(void *args) /* Stop T3402 timer */ emm_timers->T3402.id = nas_timer_stop(emm_timers->T3402.id); /* Reset the attach attempt counter */ - _emm_attach_data.attempt_count = 0; + emm_attach_data->attempt_count = 0; /* * Notify EMM that timer T3402 expired and attach procedure has to be * restarted @@ -1140,7 +1130,6 @@ static void *_emm_attach_t3402_handler(void *args) ** ** ** Outputs: emm_sap: EMM service access point ** ** Return: None ** - ** Others: user->emm_data-> _emm_attach_data, T3402, T3410, ** ** T3411 ** ** ** ***************************************************************************/ @@ -1148,8 +1137,9 @@ static void _emm_attach_abnormal_cases_bcd(nas_user_t *user, emm_sap_t *emm_sap) { LOG_FUNC_IN; emm_timers_t *emm_timers = user->emm_data->emm_timers; + emm_attach_data_t *emm_attach_data = user->emm_data->emm_attach_data; LOG_TRACE(WARNING, "EMM-PROC - Abnormal case, attach counter = %d", - _emm_attach_data.attempt_count); + emm_attach_data->attempt_count); /* Stop timer T3410 */ if (emm_timers->T3410.id != NAS_TIMER_INACTIVE_ID) { @@ -1157,9 +1147,9 @@ static void _emm_attach_abnormal_cases_bcd(nas_user_t *user, emm_sap_t *emm_sap) emm_timers->T3410.id = nas_timer_stop(emm_timers->T3410.id); } - if (_emm_attach_data.attempt_count < EMM_ATTACH_COUNTER_MAX) { + if (emm_attach_data->attempt_count < EMM_ATTACH_COUNTER_MAX) { /* Increment the attach attempt counter */ - _emm_attach_data.attempt_count += 1; + emm_attach_data->attempt_count += 1; /* Start T3411 timer */ emm_timers->T3411.id = nas_timer_start(emm_timers->T3411.sec, _emm_attach_t3411_handler, NULL); LOG_TRACE(INFO, "EMM-PROC - Timer T3411 (%d) expires in %ld seconds", diff --git a/openair3/NAS/UE/EMM/emmData.h b/openair3/NAS/UE/EMM/emmData.h index a9921c8c8b8e46e8224b048831f549902ea0a122..84e58bb963023f393b3d6333eb743d4753b04455 100644 --- a/openair3/NAS/UE/EMM/emmData.h +++ b/openair3/NAS/UE/EMM/emmData.h @@ -94,6 +94,17 @@ Description Defines internal private data handled by EPS Mobility /************************ G L O B A L T Y P E S ************************/ /****************************************************************************/ +/* + * Internal data used for attach procedure + */ + +#define EMM_ATTACH_COUNTER_MAX 5 + +typedef struct { + unsigned int attempt_count; /* Counter used to limit the number of + * subsequently rejected attach attempts */ +} emm_attach_data_t; + /* * Internal data used for detach procedure */ @@ -357,6 +368,7 @@ typedef struct emm_data_s { */ emm_timers_t *emm_timers; emm_detach_data_t *emm_detach_data; + emm_attach_data_t *emm_attach_data; } emm_data_t; diff --git a/openair3/NAS/UE/EMM/emm_main.c b/openair3/NAS/UE/EMM/emm_main.c index 95ab7872f836884e556bd6c19ef98bda1b561e33..5b6a44909ef6c796102c927f02fd298b41a3b0d1 100644 --- a/openair3/NAS/UE/EMM/emm_main.c +++ b/openair3/NAS/UE/EMM/emm_main.c @@ -106,6 +106,10 @@ void _emm_timers_initialize(emm_timers_t *emm_timers) { emm_timers->T3430.sec = T3430_DEFAULT_VALUE; } +void _emm_attach_initialize(emm_attach_data_t *emm_attach_data) { + emm_attach_data->attempt_count = 0; +} + void _emm_detach_initialize(emm_detach_data_t *emm_detach) { emm_detach->count = 0; emm_detach->switch_off = FALSE; @@ -410,6 +414,16 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c } _emm_detach_initialize(user->emm_data->emm_detach_data); + /* + * Initialize Internal data used for attach procedure + */ + user->emm_data->emm_attach_data = calloc(1, sizeof(emm_attach_data_t)); + if ( user->emm_data->emm_attach_data == NULL ) { + LOG_TRACE(ERROR, "EMM-MAIN - Failed to alloc emm_timers"); + // FIXME stop here + } + _emm_attach_initialize(user->emm_data->emm_attach_data); + /* * Initialize the user notification callback */