Commit 5899af2e authored by Frédéric Leroy's avatar Frédéric Leroy

UE/EMM: move _authentication_data to nas_user_t

parent 576bbd25
......@@ -65,6 +65,7 @@ Description Defines the authentication EMM procedure executed by the
#include "usim_api.h"
#include "secu_defs.h"
#include "Authentication.h"
/****************************************************************************/
......@@ -97,25 +98,6 @@ static void *_authentication_t3416_handler(void *);
static void *_authentication_t3418_handler(void *);
static void *_authentication_t3420_handler(void *);
/*
* Internal data used for authentication procedure
*/
static struct {
uint8_t rand[AUTH_RAND_SIZE]; /* Random challenge number */
uint8_t res[AUTH_RES_SIZE]; /* Authentication response */
uint8_t ck[AUTH_CK_SIZE]; /* Ciphering key */
uint8_t ik[AUTH_IK_SIZE]; /* Integrity key */
#define AUTHENTICATION_T3410 0x01
#define AUTHENTICATION_T3417 0x02
#define AUTHENTICATION_T3421 0x04
#define AUTHENTICATION_T3430 0x08
unsigned char timers; /* Timer restart bitmap */
#define AUTHENTICATION_COUNTER_MAX 3
unsigned char mac_count:2; /* MAC failure counter (#20) */
unsigned char umts_count:2; /* UMTS challenge failure counter (#26) */
unsigned char sync_count:2; /* Sync failure counter (#21) */
} _authentication_data;
/*
* Abnormal case authentication procedure
*/
......@@ -123,8 +105,8 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
const OctetString *auts);
static int _authentication_abnormal_case_f(nas_user_t *user);
static int _authentication_stop_timers(void);
static int _authentication_start_timers(void);
static int _authentication_stop_timers(nas_user_t *user);
static int _authentication_start_timers(nas_user_t *user);
static int _authentication_kasme(const OctetString *autn,
const OctetString *ck, const OctetString *ik, const plmn_t *plmn,
OctetString *kasme);
......@@ -163,11 +145,9 @@ static int _authentication_kasme(const OctetString *autn,
** ksi: The NAS ket sey identifier **
** rand: Authentication parameter RAND **
** autn: Authentication parameter AUTN **
** Others: user->emm_data-> _authentication_data **
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: user->emm_data-> _authentication_data, T3416, **
** T3418, T3420 **
** **
***************************************************************************/
......@@ -178,6 +158,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
LOG_FUNC_IN;
int rc = RETURNerror;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(INFO, "EMM-PROC - Authentication requested ksi type = %s, ksi = %d", native_ksi ? "native" : "mapped", ksi);
......@@ -203,11 +184,11 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
}
/* Setup security keys */
OctetString ck = {AUTH_CK_SIZE, _authentication_data.ck};
OctetString ik = {AUTH_IK_SIZE, _authentication_data.ik};
OctetString res = {AUTH_RES_SIZE, _authentication_data.res};
OctetString ck = {AUTH_CK_SIZE, authentication_data->ck};
OctetString ik = {AUTH_IK_SIZE, authentication_data->ik};
OctetString res = {AUTH_RES_SIZE, authentication_data->res};
if (memcmp(_authentication_data.rand, rand->value, AUTH_CK_SIZE) != 0) {
if (memcmp(authentication_data->rand, rand->value, AUTH_CK_SIZE) != 0) {
/*
* There is no valid stored RAND in the ME or the stored RAND is
* different from the new received value in the AUTHENTICATION
......@@ -254,7 +235,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
(sbit == 0) ? "Non-EPS authentication unacceptable" :
"MAC code failure");
/* Delete any previously stored RAND and RES and stop timer T3416 */
(void) emm_proc_authentication_delete();
emm_proc_authentication_delete(user);
/* Proceed authentication abnormal cases procedure */
if (auts.length > 0) {
......@@ -284,7 +265,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
/* Store the new RAND in the volatile memory */
if (rand->length <= AUTH_RAND_SIZE) {
memcpy(_authentication_data.rand, rand->value, rand->length);
memcpy(authentication_data->rand, rand->value, rand->length);
}
/* Start, or reset and restart timer T3416 */
......@@ -304,7 +285,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
* the authenticity of the core network
*/
/* Start any retransmission timers */
rc = _authentication_start_timers();
rc = _authentication_start_timers(user);
if (rc != RETURNok) {
LOG_TRACE(WARNING, "EMM-PROC - Failed to start retransmission timers");
......@@ -339,9 +320,9 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
if (rc != RETURNerror) {
/* Reset the authentication failure counters */
_authentication_data.mac_count = 0;
_authentication_data.umts_count = 0;
_authentication_data.sync_count = 0;
authentication_data->mac_count = 0;
authentication_data->umts_count = 0;
authentication_data->sync_count = 0;
/* Create non-current EPS security context */
if (user->emm_data->non_current == NULL) {
......@@ -392,7 +373,6 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: user->emm_data-> _authentication_data, T3410, **
** T3417, T3430 **
** **
***************************************************************************/
......@@ -402,11 +382,12 @@ int emm_proc_authentication_reject(nas_user_t *user)
emm_sap_t emm_sap;
int rc;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(WARNING, "EMM-PROC - Authentication not accepted by the network");
/* Delete any previously stored RAND and RES and stop timer T3416 */
(void) emm_proc_authentication_delete();
(void) emm_proc_authentication_delete(user);
/* Set the EPS update status to EU3 ROAMING NOT ALLOWED */
user->emm_data->status = EU3_ROAMING_NOT_ALLOWED;
......@@ -445,7 +426,7 @@ int emm_proc_authentication_reject(nas_user_t *user)
/* Abort any EMM signalling procedure (prevent the retransmission timers to
* be restarted) */
_authentication_data.timers = 0x00;
authentication_data->timers = 0x00;
/*
* Notify EMM that authentication is not accepted by the network
......@@ -475,12 +456,12 @@ int emm_proc_authentication_reject(nas_user_t *user)
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: _authentication_data, T3416 **
** **
***************************************************************************/
int emm_proc_authentication_delete(void)
int emm_proc_authentication_delete(nas_user_t *user)
{
LOG_FUNC_IN;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(INFO, "EMM-PROC - Delete authentication data RAND and RES");
......@@ -491,8 +472,8 @@ int emm_proc_authentication_delete(void)
}
/* Delete any previously stored RAND and RES */
memset(_authentication_data.rand, 0, AUTH_RAND_SIZE);
memset(_authentication_data.res, 0, AUTH_RES_SIZE);
memset(authentication_data->rand, 0, AUTH_RAND_SIZE);
memset(authentication_data->res, 0, AUTH_RES_SIZE);
LOG_FUNC_RETURN (RETURNok);
}
......@@ -529,13 +510,14 @@ int emm_proc_authentication_delete(void)
static void *_authentication_t3416_handler(void *args)
{
LOG_FUNC_IN;
nas_user_t *user=args;
LOG_TRACE(WARNING, "EMM-PROC - T3416 timer expired");
/* Stop timer T3416 */
T3416.id = nas_timer_stop(T3416.id);
/* Delete previouly stored RAND and RES authentication data */
(void) emm_proc_authentication_delete();
(void) emm_proc_authentication_delete(user);
LOG_FUNC_RETURN (NULL);
}
......@@ -556,23 +538,23 @@ static void *_authentication_t3416_handler(void *args)
** **
** Outputs: None **
** Return: None **
** Others: _authentication_data, T3418 **
** **
***************************************************************************/
static void *_authentication_t3418_handler(void *args)
{
LOG_FUNC_IN;
nas_user_t *user=args;
int rc;
nas_user_t *user=args;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(WARNING, "EMM-PROC - T3418 timer expired");
/* Stop timer T3418 */
T3418.id = nas_timer_stop(T3418.id);
/* Reset the MAC failure and UMTS challenge failure counters */
_authentication_data.mac_count = 0;
_authentication_data.umts_count = 0;
authentication_data->mac_count = 0;
authentication_data->umts_count = 0;
/* 3GPP TS 24.301, section 5.4.2.7, case f */
rc = _authentication_abnormal_case_f(user);
......@@ -598,22 +580,22 @@ static void *_authentication_t3418_handler(void *args)
** **
** Outputs: None **
** Return: None **
** Others: _authentication_data, T3420 **
** **
***************************************************************************/
static void *_authentication_t3420_handler(void *args)
{
LOG_FUNC_IN;
nas_user_t *user=args;
int rc;
nas_user_t *user=args;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(WARNING, "EMM-PROC - T3420 timer expired");
/* Stop timer T3420 */
T3420.id = nas_timer_stop(T3420.id);
/* Reset the sync failure counter */
_authentication_data.sync_count = 0;
authentication_data->sync_count = 0;
/* 3GPP TS 24.301, section 5.4.2.7, case f */
rc = _authentication_abnormal_case_f(user);
......@@ -643,7 +625,6 @@ static void *_authentication_t3420_handler(void *args)
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: _authentication_data, T3418, T3420 **
** **
***************************************************************************/
static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
......@@ -652,11 +633,12 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
LOG_FUNC_IN;
int rc;
authentication_data_t *authentication_data = user->authentication_data;
LOG_TRACE(WARNING, "EMM-PROC - "
"Abnormal case, authentication counters c/d/e = %d/%d/%d",
_authentication_data.mac_count, _authentication_data.umts_count,
_authentication_data.sync_count);
authentication_data->mac_count, authentication_data->umts_count,
authentication_data->sync_count);
/*
* Notify EMM-AS SAP that Authentication Failure message has to be sent
......@@ -682,7 +664,7 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
case EMM_CAUSE_MAC_FAILURE:
/* 3GPP TS 24.301, section 5.4.2.6, case c
* Update the MAC failure counter */
_authentication_data.mac_count += 1;
authentication_data->mac_count += 1;
/* Start timer T3418 */
T3418.id = nas_timer_start(T3418.sec,
_authentication_t3418_handler, user);
......@@ -693,7 +675,7 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
case EMM_CAUSE_NON_EPS_AUTH_UNACCEPTABLE:
/* 3GPP TS 24.301, section 5.4.2.6, case d
* Update the UMTS challenge failure counter */
_authentication_data.umts_count += 1;
authentication_data->umts_count += 1;
/* Start timer T3418 */
T3418.id = nas_timer_start(T3418.sec,
_authentication_t3418_handler, user);
......@@ -704,7 +686,7 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
case EMM_CAUSE_SYNCH_FAILURE:
/* 3GPP TS 24.301, section 5.4.2.6, case e
* Update the synch failure counter */
_authentication_data.sync_count += 1;
authentication_data->sync_count += 1;
/* Start timer T3420 */
T3420.id = nas_timer_start(T3420.sec,
_authentication_t3420_handler, user);
......@@ -721,7 +703,7 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
/*
* Stop any retransmission timers that are running
*/
rc = _authentication_stop_timers();
rc = _authentication_stop_timers(user);
if (rc != RETURNok) {
LOG_TRACE(WARNING, "EMM-PROC - "
......@@ -735,12 +717,12 @@ static int _authentication_abnormal_cases_cde(nas_user_t *user, int emm_cause,
int failure_counter = 0;
if (emm_cause == EMM_CAUSE_MAC_FAILURE) {
failure_counter = _authentication_data.mac_count
+ _authentication_data.sync_count;
failure_counter = authentication_data->mac_count
+ authentication_data->sync_count;
} else if (emm_cause == EMM_CAUSE_SYNCH_FAILURE) {
failure_counter = _authentication_data.mac_count
+ _authentication_data.umts_count
+ _authentication_data.sync_count;
failure_counter = authentication_data->mac_count
+ authentication_data->umts_count
+ authentication_data->sync_count;
}
if (failure_counter >= AUTHENTICATION_COUNTER_MAX) {
......@@ -796,7 +778,7 @@ static int _authentication_abnormal_case_f(nas_user_t *user)
* T3430), if they were running and stopped when the UE received
* the first AUTHENTICATION REQUEST message containing an invalid
* MAC or SQN */
rc = _authentication_start_timers();
rc = _authentication_start_timers(user);
}
LOG_FUNC_RETURN (rc);
......@@ -820,40 +802,40 @@ static int _authentication_abnormal_case_f(nas_user_t *user)
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: _authentication_data, T3410, T3417, T3421, **
** T3430 **
** **
***************************************************************************/
static int _authentication_stop_timers(void)
static int _authentication_stop_timers(nas_user_t *user)
{
LOG_FUNC_IN;
authentication_data_t *authentication_data = user->authentication_data;
/* Stop attach timer */
if (T3410.id != NAS_TIMER_INACTIVE_ID) {
LOG_TRACE(INFO, "EMM-PROC - Stop timer T3410 (%d)", T3410.id);
T3410.id = nas_timer_stop(T3410.id);
_authentication_data.timers |= AUTHENTICATION_T3410;
authentication_data->timers |= AUTHENTICATION_T3410;
}
/* Stop service request timer */
if (T3417.id != NAS_TIMER_INACTIVE_ID) {
LOG_TRACE(INFO, "EMM-PROC - Stop timer T3417 (%d)", T3417.id);
T3417.id = nas_timer_stop(T3417.id);
_authentication_data.timers |= AUTHENTICATION_T3417;
authentication_data->timers |= AUTHENTICATION_T3417;
}
/* Stop detach timer */
if (T3421.id != NAS_TIMER_INACTIVE_ID) {
LOG_TRACE(INFO, "EMM-PROC - Stop timer T3421 (%d)", T3421.id);
T3421.id = nas_timer_stop(T3421.id);
_authentication_data.timers |= AUTHENTICATION_T3421;
authentication_data->timers |= AUTHENTICATION_T3421;
}
/* Stop tracking area update timer */
if (T3430.id != NAS_TIMER_INACTIVE_ID) {
LOG_TRACE(INFO, "EMM-PROC - Stop timer T3430 (%d)", T3430.id);
T3430.id = nas_timer_stop(T3430.id);
_authentication_data.timers |= AUTHENTICATION_T3430;
authentication_data->timers |= AUTHENTICATION_T3430;
}
LOG_FUNC_RETURN (RETURNok);
......@@ -871,39 +853,39 @@ static int _authentication_stop_timers(void)
** 3GPP TS 24.301, section 5.4.2.7, case f **
** **
** Inputs: None **
** Others: _authentication_data **
** **
** Outputs: None **
** Return: RETURNok, RETURNerror **
** Others: T3410, T3417, T3421, T3430 **
** **
***************************************************************************/
static int _authentication_start_timers(void)
static int _authentication_start_timers(nas_user_t *user)
{
LOG_FUNC_IN;
authentication_data_t *authentication_data = user->authentication_data;
if (_authentication_data.timers & AUTHENTICATION_T3410) {
if (authentication_data->timers & AUTHENTICATION_T3410) {
/* Start attach timer */
T3410.id = nas_timer_start(T3410.sec, _emm_attach_t3410_handler, NULL);
LOG_TRACE(INFO,"EMM-PROC - Timer T3410 (%d) expires in "
"%ld seconds", T3410.id, T3410.sec);
}
if (_authentication_data.timers & AUTHENTICATION_T3417) {
if (authentication_data->timers & AUTHENTICATION_T3417) {
/* Start service request timer */
T3417.id = nas_timer_start(T3417.sec, _emm_service_t3417_handler, NULL);
LOG_TRACE(INFO,"EMM-PROC - Timer T3417 (%d) expires in "
"%ld seconds", T3417.id, T3417.sec);
}
if (_authentication_data.timers & AUTHENTICATION_T3421) {
if (authentication_data->timers & AUTHENTICATION_T3421) {
/* Start detach timer */
T3421.id = nas_timer_start(T3421.sec, _emm_detach_t3421_handler, NULL);
LOG_TRACE(INFO,"EMM-PROC - Timer T3421 (%d) expires in "
"%ld seconds", T3421.id, T3421.sec);
}
if (_authentication_data.timers & AUTHENTICATION_T3430) {
if (authentication_data->timers & AUTHENTICATION_T3430) {
/* Start tracking area update timer */
T3430.id = nas_timer_start(T3430.sec, _emm_tau_t3430_handler, NULL);
LOG_TRACE(INFO,"EMM-PROC - Timer T3430 (%d) expires in "
......
#ifndef _AUTHENTICATION_H
#define _AUTHENTICATION_H
/*
* Internal data used for authentication procedure
*/
typedef struct {
uint8_t rand[AUTH_RAND_SIZE]; /* Random challenge number */
uint8_t res[AUTH_RES_SIZE]; /* Authentication response */
uint8_t ck[AUTH_CK_SIZE]; /* Ciphering key */
uint8_t ik[AUTH_IK_SIZE]; /* Integrity key */
#define AUTHENTICATION_T3410 0x01
#define AUTHENTICATION_T3417 0x02
#define AUTHENTICATION_T3421 0x04
#define AUTHENTICATION_T3430 0x08
unsigned char timers; /* Timer restart bitmap */
#define AUTHENTICATION_COUNTER_MAX 3
unsigned char mac_count:2; /* MAC failure counter (#20) */
unsigned char umts_count:2; /* UMTS challenge failure counter (#26) */
unsigned char sync_count:2; /* Sync failure counter (#21) */
} authentication_data_t;
#endif
......@@ -98,7 +98,7 @@ int EmmDeregistered(nas_user_t *user, const emm_reg_t *evt)
/* Delete the authentication data RAND and RES */
// FIXME REVIEW
rc = emm_proc_authentication_delete();
rc = emm_proc_authentication_delete(user);
if (rc != RETURNok) {
LOG_FUNC_RETURN (rc);
......
......@@ -86,7 +86,7 @@ int EmmNull(nas_user_t *user, const emm_reg_t *evt)
assert(emm_fsm_get_status(user) == EMM_NULL);
/* Delete the authentication data RAND and RES */
rc = emm_proc_authentication_delete();
rc = emm_proc_authentication_delete(user);
if (rc != RETURNok) {
LOG_FUNC_RETURN (rc);
......
......@@ -158,7 +158,7 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi,
ksi);
/* Delete any previously stored RAND and RES and stop timer T3416 */
(void) emm_proc_authentication_delete();
(void) emm_proc_authentication_delete(user);
/*
* Check the replayed UE security capabilities
......
......@@ -352,6 +352,7 @@ typedef struct emm_data_s {
#define T3430_DEFAULT_VALUE 15 /* 15 seconds */
#define T3440_DEFAULT_VALUE 10 /* 10 seconds */
// FIXME put in another structure
struct nas_timer_t T3402; /* attach failure timer */
struct nas_timer_t T3410; /* attach timer */
struct nas_timer_t T3411; /* attach restart timer */
......
......@@ -167,7 +167,7 @@ int emm_proc_identification_request(nas_user_t *user, emm_proc_identity_type_t t
int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
const OctetString *rand, const OctetString *autn);
int emm_proc_authentication_reject(nas_user_t *user);
int emm_proc_authentication_delete(void);
int emm_proc_authentication_delete(nas_user_t *user);
/*
......
......@@ -97,6 +97,11 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN;
user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN;
user->authentication_data = calloc(1, sizeof(authentication_data_t));
if ( user->authentication_data == NULL ) {
LOG_TRACE(ERROR, "NAS-PROC - Failed to alloc authentication_data");
// FIXME stop here
}
/* Initialize the EMM procedure manager */
emm_main_initialize(user, emm_cb, imei);
......
......@@ -50,18 +50,23 @@ Description NAS type definition to manage a user equipment
#include "esm_pt_defs.h"
#include "EMM/emm_fsm_defs.h"
#include "EMM/emmData.h"
#include "EMM/Authentication.h"
#include "EMM/IdleMode_defs.h"
#include "API/USIM/usim_api.h"
typedef struct {
int fd;
proc_data_t proc;
// Eps Session Management
esm_data_t *esm_data; // ESM internal data (used within ESM only)
esm_pt_data_t *esm_pt_data;
esm_ebr_data_t *esm_ebr_data; // EPS bearer contexts
// Eps Mobility Management
emm_fsm_state_t emm_fsm_status; // Current EPS Mobility Management status
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;
// Hardware persistent storage
usim_data_t usim_data; // USIM application data
} nas_user_t;
......
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