Commit f355cc61 authored by Cedric Roux's avatar Cedric Roux

- Formatted some NAS files

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4553 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 0fdd3f09
...@@ -200,6 +200,7 @@ static void* _nas_user_mngr(void* args) ...@@ -200,6 +200,7 @@ static void* _nas_user_mngr(void* args)
int exit_loop = FALSE; int exit_loop = FALSE;
int nb_command; int nb_command;
int bytes; int bytes;
int i;
int *fd = (int*) args; int *fd = (int*) args;
...@@ -227,7 +228,7 @@ static void* _nas_user_mngr(void* args) ...@@ -227,7 +228,7 @@ static void* _nas_user_mngr(void* args)
/* Decode the user data message */ /* Decode the user data message */
nb_command = user_api_decode_data (bytes); nb_command = user_api_decode_data (bytes);
for (int i = 0; i < nb_command; i++) for (i = 0; i < nb_command; i++)
{ {
/* Get the user data to be processed */ /* Get the user data to be processed */
const void* data = user_api_get_data (i); const void* data = user_api_get_data (i);
......
...@@ -61,7 +61,7 @@ Description Defines the attach related EMM procedure executed by the ...@@ -61,7 +61,7 @@ Description Defines the attach related EMM procedure executed by the
/****************************************************************************/ /****************************************************************************/
/* String representation of the EPS attach type */ /* String representation of the EPS attach type */
static const char* _emm_attach_type_str[] = { static const char *_emm_attach_type_str[] = {
"EPS", "IMSI", "EMERGENCY", "RESERVED" "EPS", "IMSI", "EMERGENCY", "RESERVED"
}; };
...@@ -74,14 +74,14 @@ static const char* _emm_attach_type_str[] = { ...@@ -74,14 +74,14 @@ static const char* _emm_attach_type_str[] = {
/* /*
* Timer handlers * Timer handlers
*/ */
void* _emm_attach_t3410_handler(void*); void *_emm_attach_t3410_handler(void *);
static void* _emm_attach_t3411_handler(void*); static void *_emm_attach_t3411_handler(void *);
static void* _emm_attach_t3402_handler(void*); static void *_emm_attach_t3402_handler(void *);
/* /*
* Abnormal case attach procedure * Abnormal case attach procedure
*/ */
static void _emm_attach_abnormal_cases_bcd(emm_sap_t*); static void _emm_attach_abnormal_cases_bcd(emm_sap_t *);
/* /*
* Internal data used for attach procedure * Internal data used for attach procedure
...@@ -102,30 +102,30 @@ static struct { ...@@ -102,30 +102,30 @@ static struct {
/* /*
* Timer handlers * Timer handlers
*/ */
static void* _emm_attach_t3450_handler(void*); static void *_emm_attach_t3450_handler(void *);
/* /*
* Functions that may initiate EMM common procedures * Functions that may initiate EMM common procedures
*/ */
static int _emm_attach_identify(void*); static int _emm_attach_identify(void *);
static int _emm_attach_security(void*); static int _emm_attach_security(void *);
static int _emm_attach(void*); static int _emm_attach(void *);
/* /*
* Abnormal case attach procedures * Abnormal case attach procedures
*/ */
static int _emm_attach_release(void*); static int _emm_attach_release(void *);
static int _emm_attach_reject(void*); static int _emm_attach_reject(void *);
static int _emm_attach_abort(void*); static int _emm_attach_abort(void *);
static int _emm_attach_have_changed(const emm_data_context_t* ctx, static int _emm_attach_have_changed(const emm_data_context_t *ctx,
emm_proc_attach_type_t type, int ksi, emm_proc_attach_type_t type, int ksi,
GUTI_t* guti, imsi_t* imsi, imei_t* imei, GUTI_t *guti, imsi_t *imsi, imei_t *imei,
int eea, int eia); int eea, int eia);
static int _emm_attach_update(emm_data_context_t* ctx, unsigned int ueid, static int _emm_attach_update(emm_data_context_t *ctx, unsigned int ueid,
emm_proc_attach_type_t type, int ksi, emm_proc_attach_type_t type, int ksi,
GUTI_t* guti, imsi_t* imsi, imei_t* imei, GUTI_t *guti, imsi_t *imsi, imei_t *imei,
int eea, int eia, const OctetString* esm_msg); int eea, int eia, const OctetString *esm_msg);
/* /*
* Internal data used for attach procedure * Internal data used for attach procedure
...@@ -138,7 +138,7 @@ typedef struct { ...@@ -138,7 +138,7 @@ typedef struct {
* the Attach Accept message */ * the Attach Accept message */
} attach_data_t; } attach_data_t;
static int _emm_attach_accept(emm_data_context_t* emm_ctx, attach_data_t* data); static int _emm_attach_accept(emm_data_context_t *emm_ctx, attach_data_t *data);
#endif // NAS_MME #endif // NAS_MME
...@@ -220,17 +220,14 @@ int emm_proc_attach(emm_proc_attach_type_t type) ...@@ -220,17 +220,14 @@ int emm_proc_attach(emm_proc_attach_type_t type)
/* Include the IMSI */ /* Include the IMSI */
emm_as->UEid.imsi = _emm_data.imsi; emm_as->UEid.imsi = _emm_data.imsi;
} }
} } else if (_emm_data.guti) {
else if (_emm_data.guti) {
/* Include a valid GUTI and the last visited registered TAI */ /* Include a valid GUTI and the last visited registered TAI */
emm_as->UEid.guti = _emm_data.guti; emm_as->UEid.guti = _emm_data.guti;
emm_as->UEid.tai = _emm_data.tai; emm_as->UEid.tai = _emm_data.tai;
} } else if (!_emm_data.is_emergency) {
else if (!_emm_data.is_emergency) {
/* Include the IMSI if no valid GUTI is available */ /* Include the IMSI if no valid GUTI is available */
emm_as->UEid.imsi = _emm_data.imsi; emm_as->UEid.imsi = _emm_data.imsi;
} } else {
else {
/* The UE is attaching for emergency bearer services and /* The UE is attaching for emergency bearer services and
* does not hold a valid GUTI */ * does not hold a valid GUTI */
if (_emm_data.imsi) { if (_emm_data.imsi) {
...@@ -315,7 +312,7 @@ int emm_proc_attach(emm_proc_attach_type_t type) ...@@ -315,7 +312,7 @@ int emm_proc_attach(emm_proc_attach_type_t type)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_request(void* args) int emm_proc_attach_request(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -363,9 +360,9 @@ int emm_proc_attach_request(void* args) ...@@ -363,9 +360,9 @@ int emm_proc_attach_request(void* args)
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_accept(long t3412, long t3402, long t3423, int emm_proc_attach_accept(long t3412, long t3402, long t3423,
int n_tais, tai_t* tai, GUTI_t* guti, int n_tais, tai_t *tai, GUTI_t *guti,
int n_eplmns, plmn_t* eplmn, int n_eplmns, plmn_t *eplmn,
const OctetString* esm_msg) const OctetString *esm_msg)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -437,8 +434,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423, ...@@ -437,8 +434,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423,
esm_sap.recv = esm_msg; esm_sap.recv = esm_msg;
rc = esm_sap_send(&esm_sap); rc = esm_sap_send(&esm_sap);
if ( (rc != RETURNerror) && (esm_sap.err == ESM_SAP_SUCCESS) ) if ( (rc != RETURNerror) && (esm_sap.err == ESM_SAP_SUCCESS) ) {
{
/* Setup EMM procedure handler to be executed upon receiving /* Setup EMM procedure handler to be executed upon receiving
* lower layer notification */ * lower layer notification */
rc = emm_proc_lowerlayer_initialize(emm_proc_attach_complete, rc = emm_proc_lowerlayer_initialize(emm_proc_attach_complete,
...@@ -466,8 +462,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423, ...@@ -466,8 +462,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423,
emm_sap.u.emm_as.u.data.NASinfo = EMM_AS_NAS_DATA_ATTACH; emm_sap.u.emm_as.u.data.NASinfo = EMM_AS_NAS_DATA_ATTACH;
emm_sap.u.emm_as.u.data.NASmsg = esm_sap.send; emm_sap.u.emm_as.u.data.NASmsg = esm_sap.send;
rc = emm_sap_send(&emm_sap); rc = emm_sap_send(&emm_sap);
} } else if (esm_sap.err != ESM_SAP_DISCARDED) {
else if (esm_sap.err != ESM_SAP_DISCARDED) {
/* 3GPP TS 24.301, section 5.5.1.2.6, case j /* 3GPP TS 24.301, section 5.5.1.2.6, case j
* If the ACTIVATE DEFAULT BEARER CONTEXT REQUEST message combined * If the ACTIVATE DEFAULT BEARER CONTEXT REQUEST message combined
* with the ATTACH ACCEPT is not accepted by the UE due to failure * with the ATTACH ACCEPT is not accepted by the UE due to failure
...@@ -476,8 +471,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423, ...@@ -476,8 +471,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423,
*/ */
emm_sap.primitive = EMMREG_DETACH_INIT; emm_sap.primitive = EMMREG_DETACH_INIT;
rc = emm_sap_send(&emm_sap); rc = emm_sap_send(&emm_sap);
} } else {
else {
/* /*
* ESM procedure failed and, received message has been discarded or * ESM procedure failed and, received message has been discarded or
* Status message has been returned; ignore ESM procedure failure * Status message has been returned; ignore ESM procedure failure
...@@ -509,7 +503,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423, ...@@ -509,7 +503,7 @@ int emm_proc_attach_accept(long t3412, long t3402, long t3423,
** Others: _emm_data, _emm_attach_data, T3410 ** ** Others: _emm_data, _emm_attach_data, T3410 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) int emm_proc_attach_reject(int emm_cause, const OctetString *esm_msg)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -525,8 +519,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) ...@@ -525,8 +519,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg)
/* Update the EPS update status, the GUTI, the visited registered TAI and /* Update the EPS update status, the GUTI, the visited registered TAI and
* the eKSI */ * the eKSI */
switch (emm_cause) switch (emm_cause) {
{
case EMM_CAUSE_ILLEGAL_UE: case EMM_CAUSE_ILLEGAL_UE:
case EMM_CAUSE_ILLEGAL_ME: case EMM_CAUSE_ILLEGAL_ME:
case EMM_CAUSE_EPS_NOT_ALLOWED: case EMM_CAUSE_EPS_NOT_ALLOWED:
...@@ -554,8 +547,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) ...@@ -554,8 +547,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg)
} }
/* Update list of equivalents PLMNs and attach attempt counter */ /* Update list of equivalents PLMNs and attach attempt counter */
switch (emm_cause) switch (emm_cause) {
{
case EMM_CAUSE_ILLEGAL_UE: case EMM_CAUSE_ILLEGAL_UE:
case EMM_CAUSE_ILLEGAL_ME: case EMM_CAUSE_ILLEGAL_ME:
case EMM_CAUSE_EPS_NOT_ALLOWED: case EMM_CAUSE_EPS_NOT_ALLOWED:
...@@ -606,8 +598,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) ...@@ -606,8 +598,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg)
} }
/* Update "forbidden lists" */ /* Update "forbidden lists" */
switch (emm_cause) switch (emm_cause) {
{
case EMM_CAUSE_PLMN_NOT_ALLOWED: case EMM_CAUSE_PLMN_NOT_ALLOWED:
case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN: case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN:
/* Store the PLMN identity in the "forbidden PLMN list" */ /* Store the PLMN identity in the "forbidden PLMN list" */
...@@ -637,8 +628,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) ...@@ -637,8 +628,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg)
} }
/* Update state of EMM sublayer */ /* Update state of EMM sublayer */
switch (emm_cause) switch (emm_cause) {
{
case EMM_CAUSE_ILLEGAL_UE: case EMM_CAUSE_ILLEGAL_UE:
case EMM_CAUSE_ILLEGAL_ME: case EMM_CAUSE_ILLEGAL_ME:
case EMM_CAUSE_EPS_NOT_ALLOWED: case EMM_CAUSE_EPS_NOT_ALLOWED:
...@@ -725,7 +715,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg) ...@@ -725,7 +715,7 @@ int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg)
** Others: _emm_data, _emm_attach_data ** ** Others: _emm_data, _emm_attach_data **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_complete(void* args) int emm_proc_attach_complete(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -791,7 +781,7 @@ int emm_proc_attach_complete(void* args) ...@@ -791,7 +781,7 @@ int emm_proc_attach_complete(void* args)
** Others: T3410, T3411 ** ** Others: T3410, T3411 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_failure(int is_initial, void* args) int emm_proc_attach_failure(int is_initial, void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -818,8 +808,7 @@ int emm_proc_attach_failure(int is_initial, void* args) ...@@ -818,8 +808,7 @@ int emm_proc_attach_failure(int is_initial, void* args)
esm_sap.primitive = ESM_PDN_CONNECTIVITY_REJ; esm_sap.primitive = ESM_PDN_CONNECTIVITY_REJ;
esm_sap.is_standalone = FALSE; esm_sap.is_standalone = FALSE;
esm_sap.recv = NULL; esm_sap.recv = NULL;
} } else {
else {
/* /*
* Notify ESM that ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message * Notify ESM that ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message
* contained in the ESM message container IE of the ATTACH COMPLETE * contained in the ESM message container IE of the ATTACH COMPLETE
...@@ -860,7 +849,7 @@ int emm_proc_attach_failure(int is_initial, void* args) ...@@ -860,7 +849,7 @@ int emm_proc_attach_failure(int is_initial, void* args)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_release(void* args) int emm_proc_attach_release(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1016,9 +1005,9 @@ int emm_proc_attach_set_detach(void) ...@@ -1016,9 +1005,9 @@ int emm_proc_attach_set_detach(void)
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
int native_ksi, int ksi, int native_guti, int native_ksi, int ksi, int native_guti,
GUTI_t* guti, imsi_t* imsi, imei_t* imei, GUTI_t *guti, imsi_t *imsi, imei_t *imei,
tai_t* tai, int eea, int eia, tai_t *tai, int eea, int eia,
const OctetString* esm_msg) const OctetString *esm_msg)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1049,8 +1038,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, ...@@ -1049,8 +1038,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
* emergency attach". * emergency attach".
*/ */
if ( !(_emm_data.conf.features & MME_API_EMERGENCY_ATTACH) && if ( !(_emm_data.conf.features & MME_API_EMERGENCY_ATTACH) &&
(type == EMM_ATTACH_TYPE_EMERGENCY) ) (type == EMM_ATTACH_TYPE_EMERGENCY) ) {
{
ue_ctx.emm_cause = EMM_CAUSE_IMEI_NOT_ACCEPTED; ue_ctx.emm_cause = EMM_CAUSE_IMEI_NOT_ACCEPTED;
/* Do not accept the UE to attach for emergency services */ /* Do not accept the UE to attach for emergency services */
rc = _emm_attach_reject(&ue_ctx); rc = _emm_attach_reject(&ue_ctx);
...@@ -1058,10 +1046,10 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, ...@@ -1058,10 +1046,10 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
} }
/* Get the UE's EMM context if it exists */ /* Get the UE's EMM context if it exists */
emm_data_context_t** emm_ctx = NULL; emm_data_context_t **emm_ctx = NULL;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
emm_data_context_t* temp = NULL; emm_data_context_t *temp = NULL;
temp = emm_data_context_get(&_emm_data, ueid); temp = emm_data_context_get(&_emm_data, ueid);
emm_ctx = &temp; emm_ctx = &temp;
...@@ -1072,8 +1060,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, ...@@ -1072,8 +1060,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
if (*emm_ctx != NULL) { if (*emm_ctx != NULL) {
/* An EMM context already exists for the UE in the network */ /* An EMM context already exists for the UE in the network */
if (_emm_attach_have_changed(*emm_ctx, type, ksi, guti, imsi, imei, if (_emm_attach_have_changed(*emm_ctx, type, ksi, guti, imsi, imei,
eea, eia)) eea, eia)) {
{
/* /*
* 3GPP TS 24.301, section 5.5.1.2.7, abnormal case e * 3GPP TS 24.301, section 5.5.1.2.7, abnormal case e
* The attach parameters have changed from the one received within * The attach parameters have changed from the one received within
...@@ -1100,16 +1087,14 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, ...@@ -1100,16 +1087,14 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
tai, eea, eia, esm_msg); tai, eea, eia, esm_msg);
} }
LOG_FUNC_RETURN(rc); LOG_FUNC_RETURN(rc);
} } else {
else {
/* Continue with the previous attach procedure */ /* Continue with the previous attach procedure */
LOG_TRACE(WARNING, "EMM-PROC - Received duplicated Attach Request"); LOG_TRACE(WARNING, "EMM-PROC - Received duplicated Attach Request");
LOG_FUNC_RETURN(RETURNok); LOG_FUNC_RETURN(RETURNok);
} }
} } else {
else {
/* Create UE's EMM context */ /* Create UE's EMM context */
*emm_ctx = (emm_data_context_t*)malloc(sizeof(emm_data_context_t)); *emm_ctx = (emm_data_context_t *)malloc(sizeof(emm_data_context_t));
if (emm_ctx == NULL) { if (emm_ctx == NULL) {
LOG_TRACE(WARNING, "EMM-PROC - Failed to create EMM context"); LOG_TRACE(WARNING, "EMM-PROC - Failed to create EMM context");
ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE; ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE;
...@@ -1143,8 +1128,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, ...@@ -1143,8 +1128,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
(*emm_ctx)->ueid = ueid; (*emm_ctx)->ueid = ueid;
(*emm_ctx)->emm_cause = EMM_CAUSE_ILLEGAL_UE; (*emm_ctx)->emm_cause = EMM_CAUSE_ILLEGAL_UE;
rc = _emm_attach_reject(*emm_ctx); rc = _emm_attach_reject(*emm_ctx);
} } else {
else {
/* /*
* Performs UE identification * Performs UE identification
*/ */
...@@ -1225,7 +1209,7 @@ int emm_proc_attach_reject(unsigned int ueid, int emm_cause) ...@@ -1225,7 +1209,7 @@ int emm_proc_attach_reject(unsigned int ueid, int emm_cause)
** Others: _emm_data, T3450 ** ** Others: _emm_data, T3450 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) int emm_proc_attach_complete(unsigned int ueid, const OctetString *esm_msg)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1240,7 +1224,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) ...@@ -1240,7 +1224,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg)
T3450.id = nas_timer_stop(T3450.id); T3450.id = nas_timer_stop(T3450.id);
/* Release retransmission timer parameters */ /* Release retransmission timer parameters */
attach_data_t* data = (attach_data_t*)(emm_proc_common_get_args(ueid)); attach_data_t *data = (attach_data_t *)(emm_proc_common_get_args(ueid));
if (data) { if (data) {
if (data->esm_msg.length > 0) { if (data->esm_msg.length > 0) {
free(data->esm_msg.value); free(data->esm_msg.value);
...@@ -1249,7 +1233,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) ...@@ -1249,7 +1233,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg)
} }
/* Get the UE context */ /* Get the UE context */
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
if (ueid > 0) { if (ueid > 0) {
...@@ -1275,8 +1259,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) ...@@ -1275,8 +1259,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg)
esm_sap.ueid = ueid; esm_sap.ueid = ueid;
esm_sap.recv = esm_msg; esm_sap.recv = esm_msg;
rc = esm_sap_send(&esm_sap); rc = esm_sap_send(&esm_sap);
} } else {
else {
LOG_TRACE(ERROR, "EMM-PROC - No EMM context exists"); LOG_TRACE(ERROR, "EMM-PROC - No EMM context exists");
} }
...@@ -1289,16 +1272,14 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) ...@@ -1289,16 +1272,14 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg)
emm_sap.primitive = EMMREG_ATTACH_CNF; emm_sap.primitive = EMMREG_ATTACH_CNF;
emm_sap.u.emm_reg.ueid = ueid; emm_sap.u.emm_reg.ueid = ueid;
rc = emm_sap_send(&emm_sap); rc = emm_sap_send(&emm_sap);
} } else if (esm_sap.err != ESM_SAP_DISCARDED) {
else if (esm_sap.err != ESM_SAP_DISCARDED) {
/* /*
* Notify EMM that attach procedure failed * Notify EMM that attach procedure failed
*/ */
emm_sap.primitive = EMMREG_ATTACH_REJ; emm_sap.primitive = EMMREG_ATTACH_REJ;
emm_sap.u.emm_reg.ueid = ueid; emm_sap.u.emm_reg.ueid = ueid;
rc = emm_sap_send(&emm_sap); rc = emm_sap_send(&emm_sap);
} } else {
else {
/* /*
* ESM procedure failed and, received message has been discarded or * ESM procedure failed and, received message has been discarded or
* Status message has been returned; ignore ESM procedure failure * Status message has been returned; ignore ESM procedure failure
...@@ -1342,7 +1323,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg) ...@@ -1342,7 +1323,7 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg)
** Others: T3410 ** ** Others: T3410 **
** ** ** **
***************************************************************************/ ***************************************************************************/
void* _emm_attach_t3410_handler(void* args) void *_emm_attach_t3410_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1383,7 +1364,7 @@ void* _emm_attach_t3410_handler(void* args) ...@@ -1383,7 +1364,7 @@ void* _emm_attach_t3410_handler(void* args)
** Others: T3411 ** ** Others: T3411 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _emm_attach_t3411_handler(void* args) static void *_emm_attach_t3411_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1427,7 +1408,7 @@ static void* _emm_attach_t3411_handler(void* args) ...@@ -1427,7 +1408,7 @@ static void* _emm_attach_t3411_handler(void* args)
** Others: _emm_attach_data, T3402 ** ** Others: _emm_attach_data, T3402 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _emm_attach_t3402_handler(void* args) static void *_emm_attach_t3402_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1478,7 +1459,7 @@ static void* _emm_attach_t3402_handler(void* args) ...@@ -1478,7 +1459,7 @@ static void* _emm_attach_t3402_handler(void* args)
** T3411 ** ** T3411 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void _emm_attach_abnormal_cases_bcd(emm_sap_t* emm_sap) static void _emm_attach_abnormal_cases_bcd(emm_sap_t *emm_sap)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1504,8 +1485,7 @@ static void _emm_attach_abnormal_cases_bcd(emm_sap_t* emm_sap) ...@@ -1504,8 +1485,7 @@ static void _emm_attach_abnormal_cases_bcd(emm_sap_t* emm_sap)
* attach procedure shall be restarted when timer T3411 expires. * attach procedure shall be restarted when timer T3411 expires.
*/ */
emm_sap->primitive = EMMREG_ATTACH_FAILED; emm_sap->primitive = EMMREG_ATTACH_FAILED;
} } else {
else {
/* Delete the GUTI */ /* Delete the GUTI */
_emm_data.guti = NULL; _emm_data.guti = NULL;
/* Delete the TAI list */ /* Delete the TAI list */
...@@ -1565,13 +1545,13 @@ static void _emm_attach_abnormal_cases_bcd(emm_sap_t* emm_sap) ...@@ -1565,13 +1545,13 @@ static void _emm_attach_abnormal_cases_bcd(emm_sap_t* emm_sap)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _emm_attach_t3450_handler(void* args) static void *_emm_attach_t3450_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
attach_data_t* data = (attach_data_t*)(args); attach_data_t *data = (attach_data_t *)(args);
/* Increment the retransmission counter */ /* Increment the retransmission counter */
data->retransmission_count += 1; data->retransmission_count += 1;
...@@ -1580,7 +1560,7 @@ static void* _emm_attach_t3450_handler(void* args) ...@@ -1580,7 +1560,7 @@ static void* _emm_attach_t3450_handler(void* args)
"counter = %d", data->retransmission_count); "counter = %d", data->retransmission_count);
/* Get the UE's EMM context */ /* Get the UE's EMM context */
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
emm_ctx = emm_data_context_get(&_emm_data, data->ueid); emm_ctx = emm_data_context_get(&_emm_data, data->ueid);
...@@ -1591,8 +1571,7 @@ static void* _emm_attach_t3450_handler(void* args) ...@@ -1591,8 +1571,7 @@ static void* _emm_attach_t3450_handler(void* args)
if (data->retransmission_count < ATTACH_COUNTER_MAX) { if (data->retransmission_count < ATTACH_COUNTER_MAX) {
/* Send attach accept message to the UE */ /* Send attach accept message to the UE */
rc = _emm_attach_accept(emm_ctx, data); rc = _emm_attach_accept(emm_ctx, data);
} } else {
else {
/* Abort the attach procedure */ /* Abort the attach procedure */
rc = _emm_attach_abort(data); rc = _emm_attach_abort(data);
} }
...@@ -1620,31 +1599,44 @@ static void* _emm_attach_t3450_handler(void* args) ...@@ -1620,31 +1599,44 @@ static void* _emm_attach_t3450_handler(void* args)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_release(void* args) static int _emm_attach_release(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
emm_data_context_t* emm_ctx = (emm_data_context_t*)(args); emm_data_context_t *emm_ctx = (emm_data_context_t *)(args);
if (emm_ctx) if (emm_ctx) {
{
LOG_TRACE(WARNING, "EMM-PROC - Release UE context data (ueid=%u)", LOG_TRACE(WARNING, "EMM-PROC - Release UE context data (ueid=%u)",
emm_ctx->ueid); emm_ctx->ueid);
unsigned int ueid = emm_ctx->ueid; unsigned int ueid = emm_ctx->ueid;
if (emm_ctx->guti) free(emm_ctx->guti); if (emm_ctx->guti) {
if (emm_ctx->imsi) free(emm_ctx->imsi); free(emm_ctx->guti);
if (emm_ctx->imei) free(emm_ctx->imei); }
if (emm_ctx->esm_msg.length > 0) free(emm_ctx->esm_msg.value); if (emm_ctx->imsi) {
free(emm_ctx->imsi);
}
if (emm_ctx->imei) {
free(emm_ctx->imei);
}
if (emm_ctx->esm_msg.length > 0) {
free(emm_ctx->esm_msg.value);
}
/* Release NAS security context */ /* Release NAS security context */
if (emm_ctx->security) { if (emm_ctx->security) {
emm_security_context_t* security = emm_ctx->security; emm_security_context_t *security = emm_ctx->security;
if (security->kasme.value) free(security->kasme.value); if (security->kasme.value) {
if (security->knas_enc.value) free(security->knas_enc.value); free(security->kasme.value);
if (security->knas_int.value) free(security->knas_int.value); }
if (security->knas_enc.value) {
free(security->knas_enc.value);
}
if (security->knas_int.value) {
free(security->knas_int.value);
}
free(emm_ctx->security); free(emm_ctx->security);
} }
/* Release the EMM context */ /* Release the EMM context */
...@@ -1685,16 +1677,15 @@ static int _emm_attach_release(void* args) ...@@ -1685,16 +1677,15 @@ static int _emm_attach_release(void* args)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_reject(void* args) static int _emm_attach_reject(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
emm_data_context_t* emm_ctx = (emm_data_context_t*)(args); emm_data_context_t *emm_ctx = (emm_data_context_t *)(args);
if (emm_ctx) if (emm_ctx) {
{
emm_sap_t emm_sap; emm_sap_t emm_sap;
LOG_TRACE(WARNING, "EMM-PROC - EMM attach procedure not accepted " LOG_TRACE(WARNING, "EMM-PROC - EMM attach procedure not accepted "
"by the network (ueid=%08x, cause=%d)", "by the network (ueid=%08x, cause=%d)",
...@@ -1749,16 +1740,15 @@ static int _emm_attach_reject(void* args) ...@@ -1749,16 +1740,15 @@ static int _emm_attach_reject(void* args)
** Others: T3450 ** ** Others: T3450 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_abort(void* args) static int _emm_attach_abort(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
attach_data_t* data = (attach_data_t*)(args); attach_data_t *data = (attach_data_t *)(args);
if (data) if (data) {
{
unsigned int ueid = data->ueid; unsigned int ueid = data->ueid;
LOG_TRACE(WARNING, "EMM-PROC - Abort the attach procedure (ueid=%u)", LOG_TRACE(WARNING, "EMM-PROC - Abort the attach procedure (ueid=%u)",
...@@ -1832,12 +1822,12 @@ static int _emm_attach_abort(void* args) ...@@ -1832,12 +1822,12 @@ static int _emm_attach_abort(void* args)
** Others: _emm_data ** ** Others: _emm_data **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_identify(void* args) static int _emm_attach_identify(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
emm_data_context_t* emm_ctx = (emm_data_context_t*)(args); emm_data_context_t *emm_ctx = (emm_data_context_t *)(args);
int guti_reallocation = FALSE; int guti_reallocation = FALSE;
LOG_TRACE(INFO, "EMM-PROC - Identify incoming UE (ueid=0x%08x) using %s", LOG_TRACE(INFO, "EMM-PROC - Identify incoming UE (ueid=0x%08x) using %s",
...@@ -1857,8 +1847,7 @@ static int _emm_attach_identify(void* args) ...@@ -1857,8 +1847,7 @@ static int _emm_attach_identify(void* args)
emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE; emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE;
} }
guti_reallocation = TRUE; guti_reallocation = TRUE;
} } else if (emm_ctx->guti) {
else if (emm_ctx->guti) {
/* The UE identifies itself using a GUTI */ /* The UE identifies itself using a GUTI */
rc = mme_api_identify_guti(emm_ctx->guti, &emm_ctx->vector); rc = mme_api_identify_guti(emm_ctx->guti, &emm_ctx->vector);
if (rc != RETURNok) { if (rc != RETURNok) {
...@@ -1887,8 +1876,7 @@ static int _emm_attach_identify(void* args) ...@@ -1887,8 +1876,7 @@ static int _emm_attach_identify(void* args)
* procedure completes */ * procedure completes */
LOG_FUNC_RETURN(rc); LOG_FUNC_RETURN(rc);
} }
} } else if ( (emm_ctx->imei) && (emm_ctx->is_emergency) ) {
else if ( (emm_ctx->imei) && (emm_ctx->is_emergency) ) {
/* The UE is attempting to attach to the network for emergency /* The UE is attempting to attach to the network for emergency
* services using an IMEI */ * services using an IMEI */
rc = mme_api_identify_imei(emm_ctx->imei, &emm_ctx->vector); rc = mme_api_identify_imei(emm_ctx->imei, &emm_ctx->vector);
...@@ -1897,8 +1885,7 @@ static int _emm_attach_identify(void* args) ...@@ -1897,8 +1885,7 @@ static int _emm_attach_identify(void* args)
"Failed to identify the UE using provided IMEI"); "Failed to identify the UE using provided IMEI");
emm_ctx->emm_cause = EMM_CAUSE_IMEI_NOT_ACCEPTED; emm_ctx->emm_cause = EMM_CAUSE_IMEI_NOT_ACCEPTED;
} }
} } else {
else {
LOG_TRACE(WARNING, "EMM-PROC - UE's identity is not available"); LOG_TRACE(WARNING, "EMM-PROC - UE's identity is not available");
emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE; emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE;
} }
...@@ -1915,15 +1902,14 @@ static int _emm_attach_identify(void* args) ...@@ -1915,15 +1902,14 @@ static int _emm_attach_identify(void* args)
/* Save the GUTI previously used by the UE to identify itself */ /* Save the GUTI previously used by the UE to identify itself */
emm_ctx->old_guti = emm_ctx->guti; emm_ctx->old_guti = emm_ctx->guti;
/* Allocate a new GUTI */ /* Allocate a new GUTI */
emm_ctx->guti = (GUTI_t*)malloc(sizeof(GUTI_t)); emm_ctx->guti = (GUTI_t *)malloc(sizeof(GUTI_t));
/* Request the MME to assign a GUTI to the UE */ /* Request the MME to assign a GUTI to the UE */
rc = mme_api_new_guti(emm_ctx->imsi, emm_ctx->guti, rc = mme_api_new_guti(emm_ctx->imsi, emm_ctx->guti,
&emm_ctx->tac, &emm_ctx->n_tacs); &emm_ctx->tac, &emm_ctx->n_tacs);
if (rc != RETURNok) { if (rc != RETURNok) {
LOG_TRACE(WARNING, "EMM-PROC - Failed to assign new GUTI"); LOG_TRACE(WARNING, "EMM-PROC - Failed to assign new GUTI");
emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE; emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE;
} } else {
else {
LOG_TRACE(WARNING, "EMM-PROC - New GUTI assigned to the UE " LOG_TRACE(WARNING, "EMM-PROC - New GUTI assigned to the UE "
"(tmsi=%u)", emm_ctx->guti->m_tmsi); "(tmsi=%u)", emm_ctx->guti->m_tmsi);
/* Update the GUTI indicator as new */ /* Update the GUTI indicator as new */
...@@ -1941,8 +1927,7 @@ static int _emm_attach_identify(void* args) ...@@ -1941,8 +1927,7 @@ static int _emm_attach_identify(void* args)
* proceed with the attach procedure. * proceed with the attach procedure.
*/ */
rc = _emm_attach(emm_ctx); rc = _emm_attach(emm_ctx);
} } else if ( (emm_ctx->is_emergency) &&
else if ( (emm_ctx->is_emergency) &&
(_emm_data.conf.features & MME_API_UNAUTHENTICATED_IMSI) ) { (_emm_data.conf.features & MME_API_UNAUTHENTICATED_IMSI) ) {
/* 3GPP TS 24.301, section 5.5.1.2.3 /* 3GPP TS 24.301, section 5.5.1.2.3
* 3GPP TS 24.401, Figure 5.3.2.1-1, point 5a * 3GPP TS 24.401, Figure 5.3.2.1-1, point 5a
...@@ -1952,16 +1937,15 @@ static int _emm_attach_identify(void* args) ...@@ -1952,16 +1937,15 @@ static int _emm_attach_identify(void* args)
* execution of the security mode control procedure. * execution of the security mode control procedure.
*/ */
rc = _emm_attach_security(emm_ctx); rc = _emm_attach_security(emm_ctx);
} } else {
else {
/* 3GPP TS 24.401, Figure 5.3.2.1-1, point 5a /* 3GPP TS 24.401, Figure 5.3.2.1-1, point 5a
* No EMM context exists for the UE in the network; authentication * No EMM context exists for the UE in the network; authentication
* and NAS security setup to activate integrity protection and NAS * and NAS security setup to activate integrity protection and NAS
* ciphering are mandatory. * ciphering are mandatory.
*/ */
auth_vector_t* auth = &emm_ctx->vector; auth_vector_t *auth = &emm_ctx->vector;
const OctetString loc_rand = {AUTH_RAND_SIZE, (uint8_t*)auth->rand}; const OctetString loc_rand = {AUTH_RAND_SIZE, (uint8_t *)auth->rand};
const OctetString autn = {AUTH_AUTN_SIZE, (uint8_t*)auth->autn}; const OctetString autn = {AUTH_AUTN_SIZE, (uint8_t *)auth->autn};
rc = emm_proc_authentication(emm_ctx->ueid, 0, // TODO: eksi != 0 rc = emm_proc_authentication(emm_ctx->ueid, 0, // TODO: eksi != 0
&loc_rand, &autn, &loc_rand, &autn,
_emm_attach_security, _emm_attach_security,
...@@ -1997,25 +1981,24 @@ static int _emm_attach_identify(void* args) ...@@ -1997,25 +1981,24 @@ static int _emm_attach_identify(void* args)
** Others: _emm_data ** ** Others: _emm_data **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_security(void* args) static int _emm_attach_security(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
emm_data_context_t* emm_ctx = (emm_data_context_t*)(args); emm_data_context_t *emm_ctx = (emm_data_context_t *)(args);
LOG_TRACE(INFO, "EMM-PROC - Setup NAS security (ueid=%u)", emm_ctx->ueid); LOG_TRACE(INFO, "EMM-PROC - Setup NAS security (ueid=%u)", emm_ctx->ueid);
/* Create new NAS security context */ /* Create new NAS security context */
if (emm_ctx->security == NULL) { if (emm_ctx->security == NULL) {
emm_ctx->security = emm_ctx->security =
(emm_security_context_t*)malloc(sizeof(emm_security_context_t)); (emm_security_context_t *)malloc(sizeof(emm_security_context_t));
} }
if (emm_ctx->security) { if (emm_ctx->security) {
memset(emm_ctx->security, 0, sizeof(emm_security_context_t)); memset(emm_ctx->security, 0, sizeof(emm_security_context_t));
emm_ctx->security->type = EMM_KSI_NOT_AVAILABLE; emm_ctx->security->type = EMM_KSI_NOT_AVAILABLE;
} } else {
else {
LOG_TRACE(WARNING, "EMM-PROC - Failed to create security context"); LOG_TRACE(WARNING, "EMM-PROC - Failed to create security context");
emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE; emm_ctx->emm_cause = EMM_CAUSE_ILLEGAL_UE;
/* Do not accept the UE to attach to the network */ /* Do not accept the UE to attach to the network */
...@@ -2066,14 +2049,14 @@ static int _emm_attach_security(void* args) ...@@ -2066,14 +2049,14 @@ static int _emm_attach_security(void* args)
** Others: _emm_data ** ** Others: _emm_data **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach(void* args) static int _emm_attach(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
esm_sap_t esm_sap; esm_sap_t esm_sap;
int rc; int rc;
emm_data_context_t* emm_ctx = (emm_data_context_t*)(args); emm_data_context_t *emm_ctx = (emm_data_context_t *)(args);
LOG_TRACE(INFO, "EMM-PROC - Attach UE (ueid=%u)", emm_ctx->ueid); LOG_TRACE(INFO, "EMM-PROC - Attach UE (ueid=%u)", emm_ctx->ueid);
...@@ -2102,7 +2085,7 @@ static int _emm_attach(void* args) ...@@ -2102,7 +2085,7 @@ static int _emm_attach(void* args)
/* Assign the TAI list the UE is registered to */ /* Assign the TAI list the UE is registered to */
/* Allocate parameters of the retransmission timer callback */ /* Allocate parameters of the retransmission timer callback */
attach_data_t* data = (attach_data_t*)malloc(sizeof(attach_data_t)); attach_data_t *data = (attach_data_t *)malloc(sizeof(attach_data_t));
if (data != NULL) { if (data != NULL) {
/* Setup ongoing EMM procedure callback functions */ /* Setup ongoing EMM procedure callback functions */
...@@ -2119,7 +2102,7 @@ static int _emm_attach(void* args) ...@@ -2119,7 +2102,7 @@ static int _emm_attach(void* args)
/* Reset the retransmission counter */ /* Reset the retransmission counter */
data->retransmission_count = 0; data->retransmission_count = 0;
/* Setup the ESM message container */ /* Setup the ESM message container */
data->esm_msg.value = (uint8_t*)malloc(esm_sap.send.length); data->esm_msg.value = (uint8_t *)malloc(esm_sap.send.length);
if (data->esm_msg.value) { if (data->esm_msg.value) {
data->esm_msg.length = esm_sap.send.length; data->esm_msg.length = esm_sap.send.length;
memcpy(data->esm_msg.value, esm_sap.send.value, memcpy(data->esm_msg.value, esm_sap.send.value,
...@@ -2141,8 +2124,7 @@ static int _emm_attach(void* args) ...@@ -2141,8 +2124,7 @@ static int _emm_attach(void* args)
} }
} }
} }
} } else if (esm_sap.err != ESM_SAP_DISCARDED) {
else if (esm_sap.err != ESM_SAP_DISCARDED) {
/* /*
* The attach procedure failed due to an ESM procedure failure * The attach procedure failed due to an ESM procedure failure
*/ */
...@@ -2152,7 +2134,7 @@ static int _emm_attach(void* args) ...@@ -2152,7 +2134,7 @@ static int _emm_attach(void* args)
if (emm_ctx->esm_msg.length > 0) { if (emm_ctx->esm_msg.length > 0) {
free(emm_ctx->esm_msg.value); free(emm_ctx->esm_msg.value);
} }
emm_ctx->esm_msg.value = (uint8_t*)malloc(esm_sap.send.length); emm_ctx->esm_msg.value = (uint8_t *)malloc(esm_sap.send.length);
if (emm_ctx->esm_msg.value) { if (emm_ctx->esm_msg.value) {
emm_ctx->esm_msg.length = esm_sap.send.length; emm_ctx->esm_msg.length = esm_sap.send.length;
memcpy(emm_ctx->esm_msg.value, esm_sap.send.value, memcpy(emm_ctx->esm_msg.value, esm_sap.send.value,
...@@ -2162,8 +2144,7 @@ static int _emm_attach(void* args) ...@@ -2162,8 +2144,7 @@ static int _emm_attach(void* args)
} else { } else {
emm_ctx->esm_msg.length = 0; emm_ctx->esm_msg.length = 0;
} }
} } else {
else {
/* /*
* ESM procedure failed and, received message has been discarded or * ESM procedure failed and, received message has been discarded or
* Status message has been returned; ignore ESM procedure failure * Status message has been returned; ignore ESM procedure failure
...@@ -2196,7 +2177,7 @@ static int _emm_attach(void* args) ...@@ -2196,7 +2177,7 @@ static int _emm_attach(void* args)
** Others: T3450 ** ** Others: T3450 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_accept(emm_data_context_t* emm_ctx, attach_data_t* data) static int _emm_attach_accept(emm_data_context_t *emm_ctx, attach_data_t *data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -2268,39 +2249,65 @@ static int _emm_attach_accept(emm_data_context_t* emm_ctx, attach_data_t* data) ...@@ -2268,39 +2249,65 @@ static int _emm_attach_accept(emm_data_context_t* emm_ctx, attach_data_t* data)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_have_changed(const emm_data_context_t* ctx, static int _emm_attach_have_changed(const emm_data_context_t *ctx,
emm_proc_attach_type_t type, int ksi, emm_proc_attach_type_t type, int ksi,
GUTI_t* guti, imsi_t* imsi, imei_t* imei, GUTI_t *guti, imsi_t *imsi, imei_t *imei,
int eea, int eia) int eea, int eia)
{ {
/* Emergency bearer services indicator */ /* Emergency bearer services indicator */
if ( (type == EMM_ATTACH_TYPE_EMERGENCY) != ctx->is_emergency) if ( (type == EMM_ATTACH_TYPE_EMERGENCY) != ctx->is_emergency) {
return (TRUE); return (TRUE);
}
/* Security key set identifier */ /* Security key set identifier */
if (ksi != ctx->ksi) return (TRUE); if (ksi != ctx->ksi) {
return (TRUE);
}
/* Supported EPS encryption algorithms */ /* Supported EPS encryption algorithms */
if (eea != ctx->eea) return (TRUE); if (eea != ctx->eea) {
return (TRUE);
}
/* Supported EPS integrity algorithms */ /* Supported EPS integrity algorithms */
if (eia != ctx->eia) return (TRUE); if (eia != ctx->eia) {
return (TRUE);
}
/* The GUTI if provided by the UE */ /* The GUTI if provided by the UE */
if ( (guti) && (ctx->guti == NULL) ) return (TRUE); if ( (guti) && (ctx->guti == NULL) ) {
if ( (guti == NULL) && (ctx->guti) ) return (TRUE); return (TRUE);
}
if ( (guti == NULL) && (ctx->guti) ) {
return (TRUE);
}
if ( (guti) && (ctx->guti) ) { if ( (guti) && (ctx->guti) ) {
if (guti->m_tmsi != ctx->guti->m_tmsi) return (TRUE); if (guti->m_tmsi != ctx->guti->m_tmsi) {
if ( memcmp(&guti->gummei, &ctx->guti->gummei, sizeof(gummei_t)) != 0 ) return (TRUE);
}
if ( memcmp(&guti->gummei, &ctx->guti->gummei, sizeof(gummei_t)) != 0 ) {
return (TRUE); return (TRUE);
} }
}
/* The IMSI if provided by the UE */ /* The IMSI if provided by the UE */
if ( (imsi) && (ctx->imsi == NULL) ) return (TRUE); if ( (imsi) && (ctx->imsi == NULL) ) {
if ( (imsi == NULL) && (ctx->imsi) ) return (TRUE); return (TRUE);
}
if ( (imsi == NULL) && (ctx->imsi) ) {
return (TRUE);
}
if ( (imsi) && (ctx->imsi) ) { if ( (imsi) && (ctx->imsi) ) {
if ( memcmp(imsi, ctx->imsi, sizeof(imsi_t)) != 0 ) return (TRUE); if ( memcmp(imsi, ctx->imsi, sizeof(imsi_t)) != 0 ) {
return (TRUE);
}
} }
/* The IMEI if provided by the UE */ /* The IMEI if provided by the UE */
if ( (imei) && (ctx->imei == NULL) ) return (TRUE); if ( (imei) && (ctx->imei == NULL) ) {
if ( (imei == NULL) && (ctx->imei) ) return (TRUE); return (TRUE);
}
if ( (imei == NULL) && (ctx->imei) ) {
return (TRUE);
}
if ( (imei) && (ctx->imei) ) { if ( (imei) && (ctx->imei) ) {
if ( memcmp(imei, ctx->imei, sizeof(imei_t)) != 0 ) return (TRUE); if ( memcmp(imei, ctx->imei, sizeof(imei_t)) != 0 ) {
return (TRUE);
}
} }
return (FALSE); return (FALSE);
} }
...@@ -2329,10 +2336,10 @@ static int _emm_attach_have_changed(const emm_data_context_t* ctx, ...@@ -2329,10 +2336,10 @@ static int _emm_attach_have_changed(const emm_data_context_t* ctx,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_attach_update(emm_data_context_t* ctx, unsigned int ueid, static int _emm_attach_update(emm_data_context_t *ctx, unsigned int ueid,
emm_proc_attach_type_t type, int ksi, emm_proc_attach_type_t type, int ksi,
GUTI_t* guti, imsi_t* imsi, imei_t* imei, GUTI_t *guti, imsi_t *imsi, imei_t *imei,
int eea, int eia, const OctetString* esm_msg) int eea, int eia, const OctetString *esm_msg)
{ {
/* UE identifier */ /* UE identifier */
ctx->ueid = ueid; ctx->ueid = ueid;
...@@ -2346,37 +2353,48 @@ static int _emm_attach_update(emm_data_context_t* ctx, unsigned int ueid, ...@@ -2346,37 +2353,48 @@ static int _emm_attach_update(emm_data_context_t* ctx, unsigned int ueid,
ctx->eia = eia; ctx->eia = eia;
/* The GUTI if provided by the UE */ /* The GUTI if provided by the UE */
if (guti) { if (guti) {
if (ctx->guti == NULL) if (ctx->guti == NULL) {
ctx->guti = (GUTI_t*)malloc(sizeof(GUTI_t)); ctx->guti = (GUTI_t *)malloc(sizeof(GUTI_t));
if (ctx->guti != NULL) }
if (ctx->guti != NULL) {
memcpy(ctx->guti, guti, sizeof(GUTI_t)); memcpy(ctx->guti, guti, sizeof(GUTI_t));
else return (RETURNerror); } else {
return (RETURNerror);
}
} }
/* The IMSI if provided by the UE */ /* The IMSI if provided by the UE */
if (imsi) { if (imsi) {
if (ctx->imsi == NULL) if (ctx->imsi == NULL) {
ctx->imsi = (imsi_t*)malloc(sizeof(imsi_t)); ctx->imsi = (imsi_t *)malloc(sizeof(imsi_t));
if (ctx->imsi != NULL) }
if (ctx->imsi != NULL) {
memcpy(ctx->imsi, imsi, sizeof(imsi_t)); memcpy(ctx->imsi, imsi, sizeof(imsi_t));
else return (RETURNerror); } else {
return (RETURNerror);
}
} }
/* The IMEI if provided by the UE */ /* The IMEI if provided by the UE */
if (imei) { if (imei) {
if (ctx->imei == NULL) if (ctx->imei == NULL) {
ctx->imei = (imei_t*)malloc(sizeof(imei_t)); ctx->imei = (imei_t *)malloc(sizeof(imei_t));
if (ctx->imei != NULL) }
if (ctx->imei != NULL) {
memcpy(ctx->imei, imei, sizeof(imei_t)); memcpy(ctx->imei, imei, sizeof(imei_t));
else return (RETURNerror); } else {
return (RETURNerror);
}
} }
/* The ESM message contained within the attach request */ /* The ESM message contained within the attach request */
if (esm_msg->length > 0) { if (esm_msg->length > 0) {
if (ctx->esm_msg.length == 0) { if (ctx->esm_msg.length == 0) {
ctx->esm_msg.value = (uint8_t*)malloc(esm_msg->length); ctx->esm_msg.value = (uint8_t *)malloc(esm_msg->length);
} }
if (ctx->esm_msg.value != NULL) { if (ctx->esm_msg.value != NULL) {
strncpy((char*)ctx->esm_msg.value, strncpy((char *)ctx->esm_msg.value,
(char*)esm_msg->value, esm_msg->length); (char *)esm_msg->value, esm_msg->length);
} else return (RETURNerror); } else {
return (RETURNerror);
}
} }
ctx->esm_msg.length = esm_msg->length; ctx->esm_msg.length = esm_msg->length;
/* Attachment indicator */ /* Attachment indicator */
......
...@@ -56,10 +56,10 @@ Description Defines the authentication EMM procedure executed by the ...@@ -56,10 +56,10 @@ Description Defines the authentication EMM procedure executed by the
/* /*
* Retransmission timer handlers * Retransmission timer handlers
*/ */
extern void* _emm_attach_t3410_handler(void*); extern void *_emm_attach_t3410_handler(void *);
extern void* _emm_service_t3417_handler(void*); extern void *_emm_service_t3417_handler(void *);
extern void* _emm_detach_t3421_handler(void*); extern void *_emm_detach_t3421_handler(void *);
extern void* _emm_tau_t3430_handler(void*); extern void *_emm_tau_t3430_handler(void *);
#endif // NAS_UE #endif // NAS_UE
/****************************************************************************/ /****************************************************************************/
...@@ -75,9 +75,9 @@ extern void* _emm_tau_t3430_handler(void*); ...@@ -75,9 +75,9 @@ extern void* _emm_tau_t3430_handler(void*);
/* /*
* Timer handlers * Timer handlers
*/ */
static void* _authentication_t3416_handler(void*); static void *_authentication_t3416_handler(void *);
static void* _authentication_t3418_handler(void*); static void *_authentication_t3418_handler(void *);
static void* _authentication_t3420_handler(void*); static void *_authentication_t3420_handler(void *);
/* /*
* Internal data used for authentication procedure * Internal data used for authentication procedure
...@@ -101,12 +101,15 @@ static struct { ...@@ -101,12 +101,15 @@ static struct {
/* /*
* Abnormal case authentication procedure * Abnormal case authentication procedure
*/ */
static int _authentication_abnormal_cases_cde(int emm_cause, const OctetString* auts); static int _authentication_abnormal_cases_cde(int emm_cause,
const OctetString *auts);
static int _authentication_abnormal_case_f(void); static int _authentication_abnormal_case_f(void);
static int _authentication_stop_timers(void); static int _authentication_stop_timers(void);
static int _authentication_start_timers(void); static int _authentication_start_timers(void);
static int _authentication_kasme(const OctetString* autn, const OctetString* ck, const OctetString* ik, const plmn_t* plmn, OctetString* kasme); static int _authentication_kasme(const OctetString *autn,
const OctetString *ck, const OctetString *ik, const plmn_t *plmn,
OctetString *kasme);
#endif // NAS_UE #endif // NAS_UE
/* /*
...@@ -118,14 +121,14 @@ static int _authentication_kasme(const OctetString* autn, const OctetString* ck, ...@@ -118,14 +121,14 @@ static int _authentication_kasme(const OctetString* autn, const OctetString* ck,
/* /*
* Timer handlers * Timer handlers
*/ */
static void* _authentication_t3460_handler(void*); static void *_authentication_t3460_handler(void *);
/* /*
* Function executed whenever the ongoing EMM procedure that initiated * Function executed whenever the ongoing EMM procedure that initiated
* the authentication procedure is aborted or the maximum value of the * the authentication procedure is aborted or the maximum value of the
* retransmission timer counter is exceed * retransmission timer counter is exceed
*/ */
static int _authentication_abort(void*); static int _authentication_abort(void *);
/* /*
* Internal data used for authentication procedure * Internal data used for authentication procedure
...@@ -142,7 +145,7 @@ typedef struct { ...@@ -142,7 +145,7 @@ typedef struct {
* to the ongoing EMM procedure */ * to the ongoing EMM procedure */
} authentication_data_t; } authentication_data_t;
static int _authentication_request(authentication_data_t* data); static int _authentication_request(authentication_data_t *data);
static int _authentication_reject(unsigned int ueid); static int _authentication_reject(unsigned int ueid);
#endif // NAS_MME #endif // NAS_MME
...@@ -184,8 +187,8 @@ static int _authentication_reject(unsigned int ueid); ...@@ -184,8 +187,8 @@ static int _authentication_reject(unsigned int ueid);
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_authentication_request(int native_ksi, int ksi, int emm_proc_authentication_request(int native_ksi, int ksi,
const OctetString* rand, const OctetString *rand,
const OctetString* autn) const OctetString *autn)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -226,7 +229,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi, ...@@ -226,7 +229,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi,
*/ */
OctetString auts; OctetString auts;
auts.length = 0; auts.length = 0;
auts.value = (uint8_t*)malloc(AUTH_AUTS_SIZE); auts.value = (uint8_t *)malloc(AUTH_AUTS_SIZE);
if (auts.value == NULL) { if (auts.value == NULL) {
LOG_TRACE(WARNING, "EMM-PROC - Failed to allocate AUTS parameter"); LOG_TRACE(WARNING, "EMM-PROC - Failed to allocate AUTS parameter");
LOG_FUNC_RETURN (RETURNerror); LOG_FUNC_RETURN (RETURNerror);
...@@ -336,7 +339,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi, ...@@ -336,7 +339,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi,
/* Create non-current EPS security context */ /* Create non-current EPS security context */
if (_emm_data.non_current == NULL) { if (_emm_data.non_current == NULL) {
_emm_data.non_current = _emm_data.non_current =
(emm_security_context_t*)malloc(sizeof(emm_security_context_t)); (emm_security_context_t *)malloc(sizeof(emm_security_context_t));
} }
if (_emm_data.non_current) { if (_emm_data.non_current) {
memset(_emm_data.non_current, 0, sizeof(emm_security_context_t)); memset(_emm_data.non_current, 0, sizeof(emm_security_context_t));
...@@ -352,7 +355,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi, ...@@ -352,7 +355,7 @@ int emm_proc_authentication_request(int native_ksi, int ksi,
* the PLMN identity of the selected PLMN */ * the PLMN identity of the selected PLMN */
_emm_data.non_current->kasme.length = AUTH_KASME_SIZE; _emm_data.non_current->kasme.length = AUTH_KASME_SIZE;
_emm_data.non_current->kasme.value = _emm_data.non_current->kasme.value =
(uint8_t*)malloc(sizeof(AUTH_KASME_SIZE)); (uint8_t *)malloc(sizeof(AUTH_KASME_SIZE));
_authentication_kasme(autn, &ck, &ik, &_emm_data.splmn, _authentication_kasme(autn, &ck, &ik, &_emm_data.splmn,
&_emm_data.non_current->kasme); &_emm_data.non_current->kasme);
/* NAS integrity and cyphering keys are not yet available */ /* NAS integrity and cyphering keys are not yet available */
...@@ -520,7 +523,7 @@ int emm_proc_authentication_delete(void) ...@@ -520,7 +523,7 @@ int emm_proc_authentication_delete(void)
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_authentication(unsigned int ueid, int ksi, int emm_proc_authentication(unsigned int ueid, int ksi,
const OctetString* _rand, const OctetString* autn, const OctetString *_rand, const OctetString *autn,
emm_common_success_callback_t success, emm_common_success_callback_t success,
emm_common_reject_callback_t reject, emm_common_reject_callback_t reject,
emm_common_failure_callback_t failure) emm_common_failure_callback_t failure)
...@@ -533,8 +536,8 @@ int emm_proc_authentication(unsigned int ueid, int ksi, ...@@ -533,8 +536,8 @@ int emm_proc_authentication(unsigned int ueid, int ksi,
LOG_TRACE(INFO, "EMM-PROC - Initiate authentication KSI = %d", ksi); LOG_TRACE(INFO, "EMM-PROC - Initiate authentication KSI = %d", ksi);
/* Allocate parameters of the retransmission timer callback */ /* Allocate parameters of the retransmission timer callback */
authentication_data_t* data = authentication_data_t *data =
(authentication_data_t*)malloc(sizeof(authentication_data_t)); (authentication_data_t *)malloc(sizeof(authentication_data_t));
if (data != NULL) { if (data != NULL) {
/* Setup ongoing EMM procedure callback functions */ /* Setup ongoing EMM procedure callback functions */
...@@ -553,7 +556,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi, ...@@ -553,7 +556,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi,
data->ksi = ksi; data->ksi = ksi;
/* Set the authentication random challenge number */ /* Set the authentication random challenge number */
if (_rand->length > 0) { if (_rand->length > 0) {
data->rand.value = (uint8_t*)malloc(_rand->length); data->rand.value = (uint8_t *)malloc(_rand->length);
data->rand.length = 0; data->rand.length = 0;
if (data->rand.value) { if (data->rand.value) {
memcpy(data->rand.value, _rand->value, _rand->length); memcpy(data->rand.value, _rand->value, _rand->length);
...@@ -562,7 +565,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi, ...@@ -562,7 +565,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi,
} }
/* Set the authentication token */ /* Set the authentication token */
if (autn->length > 0) { if (autn->length > 0) {
data->autn.value = (uint8_t*)malloc(autn->length); data->autn.value = (uint8_t *)malloc(autn->length);
data->autn.length = 0; data->autn.length = 0;
if (data->autn.value) { if (data->autn.value) {
memcpy(data->autn.value, autn->value, autn->length); memcpy(data->autn.value, autn->value, autn->length);
...@@ -610,7 +613,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi, ...@@ -610,7 +613,7 @@ int emm_proc_authentication(unsigned int ueid, int ksi,
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
const OctetString* res) const OctetString *res)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -625,8 +628,8 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, ...@@ -625,8 +628,8 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
T3460.id = nas_timer_stop(T3460.id); T3460.id = nas_timer_stop(T3460.id);
/* Release retransmission timer paramaters */ /* Release retransmission timer paramaters */
authentication_data_t* data = authentication_data_t *data =
(authentication_data_t*)(emm_proc_common_get_args(ueid)); (authentication_data_t *)(emm_proc_common_get_args(ueid));
if (data) { if (data) {
if (data->rand.length > 0) { if (data->rand.length > 0) {
free(data->rand.value); free(data->rand.value);
...@@ -638,7 +641,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, ...@@ -638,7 +641,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
} }
/* Get the UE context */ /* Get the UE context */
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
if (ueid > 0) { if (ueid > 0) {
...@@ -670,8 +673,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, ...@@ -670,8 +673,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
*/ */
emm_sap.primitive = EMMREG_COMMON_PROC_REJ; emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
emm_sap.u.emm_reg.ueid = ueid; emm_sap.u.emm_reg.ueid = ueid;
} } else {
else {
/* /*
* Notify EMM that the authentication procedure successfully completed * Notify EMM that the authentication procedure successfully completed
*/ */
...@@ -715,7 +717,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, ...@@ -715,7 +717,7 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
** Others: T3416 ** ** Others: T3416 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _authentication_t3416_handler(void* args) static void *_authentication_t3416_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -748,7 +750,7 @@ static void* _authentication_t3416_handler(void* args) ...@@ -748,7 +750,7 @@ static void* _authentication_t3416_handler(void* args)
** Others: _authentication_data, T3418 ** ** Others: _authentication_data, T3418 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _authentication_t3418_handler(void* args) static void *_authentication_t3418_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -788,7 +790,7 @@ static void* _authentication_t3418_handler(void* args) ...@@ -788,7 +790,7 @@ static void* _authentication_t3418_handler(void* args)
** Others: _authentication_data, T3420 ** ** Others: _authentication_data, T3420 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _authentication_t3420_handler(void* args) static void *_authentication_t3420_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -832,7 +834,7 @@ static void* _authentication_t3420_handler(void* args) ...@@ -832,7 +834,7 @@ static void* _authentication_t3420_handler(void* args)
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _authentication_abnormal_cases_cde(int emm_cause, static int _authentication_abnormal_cases_cde(int emm_cause,
const OctetString* auts) const OctetString *auts)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -863,8 +865,7 @@ static int _authentication_abnormal_cases_cde(int emm_cause, ...@@ -863,8 +865,7 @@ static int _authentication_abnormal_cases_cde(int emm_cause,
/* /*
* Update the authentication failure counters * Update the authentication failure counters
*/ */
switch (emm_cause) switch (emm_cause) {
{
case EMM_CAUSE_MAC_FAILURE: case EMM_CAUSE_MAC_FAILURE:
/* 3GPP TS 24.301, section 5.4.2.6, case c /* 3GPP TS 24.301, section 5.4.2.6, case c
* Update the MAC failure counter */ * Update the MAC failure counter */
...@@ -1107,9 +1108,9 @@ static int _authentication_start_timers(void) ...@@ -1107,9 +1108,9 @@ static int _authentication_start_timers(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _authentication_kasme(const OctetString* autn, static int _authentication_kasme(const OctetString *autn,
const OctetString* ck, const OctetString* ik, const OctetString *ck, const OctetString *ik,
const plmn_t* plmn, OctetString* kasme) const plmn_t *plmn, OctetString *kasme)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1125,12 +1126,16 @@ static int _authentication_kasme(const OctetString* autn, ...@@ -1125,12 +1126,16 @@ static int _authentication_kasme(const OctetString* autn,
UInt16_t length; UInt16_t length;
int offset = 0; int offset = 0;
int size_of_length = sizeof(length); int size_of_length = sizeof(length);
input[offset] = 0x10; offset += 1; input[offset] = 0x10;
offset += 1;
length = AUTH_SNID_SIZE; length = AUTH_SNID_SIZE;
memcpy(input + offset, plmn, length); offset += length; memcpy(input + offset, plmn, length);
memcpy(input + offset, &length, size_of_length); offset += size_of_length; offset += length;
memcpy(input + offset, &length, size_of_length);
offset += size_of_length;
length = AUTH_SQN_SIZE; length = AUTH_SQN_SIZE;
memcpy(input + offset, autn, length); offset += length; memcpy(input + offset, autn, length);
offset += length;
memcpy(input + offset, &length, size_of_length); memcpy(input + offset, &length, size_of_length);
/* TODO !!! Compute the Kasme key */ /* TODO !!! Compute the Kasme key */
...@@ -1168,13 +1173,13 @@ static int _authentication_kasme(const OctetString* autn, ...@@ -1168,13 +1173,13 @@ static int _authentication_kasme(const OctetString* autn,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _authentication_t3460_handler(void* args) static void *_authentication_t3460_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
authentication_data_t* data = (authentication_data_t*)(args); authentication_data_t *data = (authentication_data_t *)(args);
/* Increment the retransmission counter */ /* Increment the retransmission counter */
data->retransmission_count += 1; data->retransmission_count += 1;
...@@ -1185,8 +1190,7 @@ static void* _authentication_t3460_handler(void* args) ...@@ -1185,8 +1190,7 @@ static void* _authentication_t3460_handler(void* args)
if (data->retransmission_count < AUTHENTICATION_COUNTER_MAX) { if (data->retransmission_count < AUTHENTICATION_COUNTER_MAX) {
/* Send authentication request message to the UE */ /* Send authentication request message to the UE */
rc = _authentication_request(data); rc = _authentication_request(data);
} } else {
else {
unsigned int ueid = data->ueid; unsigned int ueid = data->ueid;
/* Set the failure notification indicator */ /* Set the failure notification indicator */
data->notify_failure = TRUE; data->notify_failure = TRUE;
...@@ -1226,7 +1230,7 @@ static void* _authentication_t3460_handler(void* args) ...@@ -1226,7 +1230,7 @@ static void* _authentication_t3460_handler(void* args)
** Others: T3460 ** ** Others: T3460 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int _authentication_request(authentication_data_t* data) int _authentication_request(authentication_data_t *data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -1332,16 +1336,15 @@ static int _authentication_reject(unsigned int ueid) ...@@ -1332,16 +1336,15 @@ static int _authentication_reject(unsigned int ueid)
** Others: T3460 ** ** Others: T3460 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _authentication_abort(void* args) static int _authentication_abort(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
authentication_data_t* data = (authentication_data_t*)(args); authentication_data_t *data = (authentication_data_t *)(args);
if (data) if (data) {
{
unsigned int ueid = data->ueid; unsigned int ueid = data->ueid;
int notify_failure = data->notify_failure; int notify_failure = data->notify_failure;
......
...@@ -46,7 +46,7 @@ Description Defines the detach related EMM procedure executed by the ...@@ -46,7 +46,7 @@ Description Defines the detach related EMM procedure executed by the
/****************************************************************************/ /****************************************************************************/
/* String representation of the detach type */ /* String representation of the detach type */
static const char* _emm_detach_type_str[] = { static const char *_emm_detach_type_str[] = {
"EPS", "IMSI", "EPS/IMSI", "EPS", "IMSI", "EPS/IMSI",
"RE-ATTACH REQUIRED", "RE-ATTACH NOT REQUIRED", "RESERVED" "RE-ATTACH REQUIRED", "RE-ATTACH NOT REQUIRED", "RESERVED"
}; };
...@@ -60,7 +60,7 @@ static const char* _emm_detach_type_str[] = { ...@@ -60,7 +60,7 @@ static const char* _emm_detach_type_str[] = {
/* /*
* Timer handlers * Timer handlers
*/ */
void* _emm_detach_t3421_handler(void*); void *_emm_detach_t3421_handler(void *);
/* /*
* Abnormal case detach procedures * Abnormal case detach procedures
...@@ -187,7 +187,7 @@ int emm_proc_detach(emm_proc_detach_type_t type, int switch_off) ...@@ -187,7 +187,7 @@ int emm_proc_detach(emm_proc_detach_type_t type, int switch_off)
** Others: T3421 ** ** Others: T3421 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_detach_request(void* args) int emm_proc_detach_request(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -281,7 +281,7 @@ int emm_proc_detach_accept(void) ...@@ -281,7 +281,7 @@ int emm_proc_detach_accept(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_detach_failure(int is_initial, void* args) int emm_proc_detach_failure(int is_initial, void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -325,7 +325,7 @@ int emm_proc_detach_failure(int is_initial, void* args) ...@@ -325,7 +325,7 @@ int emm_proc_detach_failure(int is_initial, void* args)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_detach_release(void* args) int emm_proc_detach_release(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -419,12 +419,12 @@ int emm_proc_detach(unsigned int ueid, emm_proc_detach_type_t type) ...@@ -419,12 +419,12 @@ int emm_proc_detach(unsigned int ueid, emm_proc_detach_type_t type)
***************************************************************************/ ***************************************************************************/
int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type, int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type,
int switch_off, int native_ksi, int ksi, int switch_off, int native_ksi, int ksi,
GUTI_t* guti, imsi_t* imsi, imei_t* imei) GUTI_t *guti, imsi_t *imsi, imei_t *imei)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
LOG_TRACE(INFO, "EMM-PROC - Detach type = %s (%d) requested (ueid=%u)", LOG_TRACE(INFO, "EMM-PROC - Detach type = %s (%d) requested (ueid=%u)",
_emm_detach_type_str[type], type, ueid); _emm_detach_type_str[type], type, ueid);
...@@ -445,19 +445,32 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type, ...@@ -445,19 +445,32 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type,
LOG_FUNC_RETURN(RETURNok); LOG_FUNC_RETURN(RETURNok);
} }
if (switch_off) if (switch_off) {
{
/* The UE is switched off */ /* The UE is switched off */
if (emm_ctx->guti) free(emm_ctx->guti); if (emm_ctx->guti) {
if (emm_ctx->imsi) free(emm_ctx->imsi); free(emm_ctx->guti);
if (emm_ctx->imei) free(emm_ctx->imei); }
if (emm_ctx->esm_msg.length > 0) free(emm_ctx->esm_msg.value); if (emm_ctx->imsi) {
free(emm_ctx->imsi);
}
if (emm_ctx->imei) {
free(emm_ctx->imei);
}
if (emm_ctx->esm_msg.length > 0) {
free(emm_ctx->esm_msg.value);
}
/* Release NAS security context */ /* Release NAS security context */
if (emm_ctx->security) { if (emm_ctx->security) {
emm_security_context_t* security = emm_ctx->security; emm_security_context_t *security = emm_ctx->security;
if (security->kasme.value) free(security->kasme.value); if (security->kasme.value) {
if (security->knas_enc.value) free(security->knas_enc.value); free(security->kasme.value);
if (security->knas_int.value) free(security->knas_int.value); }
if (security->knas_enc.value) {
free(security->knas_enc.value);
}
if (security->knas_int.value) {
free(security->knas_int.value);
}
free(emm_ctx->security); free(emm_ctx->security);
} }
/* Release the EMM context */ /* Release the EMM context */
...@@ -469,8 +482,7 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type, ...@@ -469,8 +482,7 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type,
_emm_data.ctx[ueid] = NULL; _emm_data.ctx[ueid] = NULL;
#endif #endif
rc = RETURNok; rc = RETURNok;
} } else {
else {
/* Normal detach without UE switch-off */ /* Normal detach without UE switch-off */
emm_sap_t emm_sap; emm_sap_t emm_sap;
emm_as_data_t *emm_as = &emm_sap.u.emm_as.u.data; emm_as_data_t *emm_as = &emm_sap.u.emm_as.u.data;
...@@ -549,7 +561,7 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type, ...@@ -549,7 +561,7 @@ int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
void* _emm_detach_t3421_handler(void* args) void *_emm_detach_t3421_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -561,8 +573,7 @@ void* _emm_detach_t3421_handler(void* args) ...@@ -561,8 +573,7 @@ void* _emm_detach_t3421_handler(void* args)
LOG_TRACE(WARNING, "EMM-PROC - T3421 timer expired, " LOG_TRACE(WARNING, "EMM-PROC - T3421 timer expired, "
"retransmission counter = %d", _emm_detach_data.count); "retransmission counter = %d", _emm_detach_data.count);
if (_emm_detach_data.count < EMM_DETACH_COUNTER_MAX) if (_emm_detach_data.count < EMM_DETACH_COUNTER_MAX) {
{
/* Retransmit the Detach Request message */ /* Retransmit the Detach Request message */
emm_sap_t emm_sap; emm_sap_t emm_sap;
emm_as_data_t *emm_as = &emm_sap.u.emm_as.u.data; emm_as_data_t *emm_as = &emm_sap.u.emm_as.u.data;
...@@ -598,8 +609,7 @@ void* _emm_detach_t3421_handler(void* args) ...@@ -598,8 +609,7 @@ void* _emm_detach_t3421_handler(void* args)
LOG_TRACE(INFO, "EMM-PROC - Timer T3421 (%d) expires in %ld " LOG_TRACE(INFO, "EMM-PROC - Timer T3421 (%d) expires in %ld "
"seconds", T3421.id, T3421.sec); "seconds", T3421.id, T3421.sec);
} }
} } else {
else {
/* Abort the detach procedure */ /* Abort the detach procedure */
rc = _emm_detach_abort(_emm_detach_data.type); rc = _emm_detach_abort(_emm_detach_data.type);
} }
......
...@@ -63,7 +63,7 @@ typedef struct emm_common_data_s { ...@@ -63,7 +63,7 @@ typedef struct emm_common_data_s {
emm_common_reject_callback_t reject; emm_common_reject_callback_t reject;
emm_common_failure_callback_t failure; emm_common_failure_callback_t failure;
emm_common_abort_callback_t abort; emm_common_abort_callback_t abort;
void* args; void *args;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
RB_ENTRY(emm_common_data_s) entries; RB_ENTRY(emm_common_data_s) entries;
...@@ -117,7 +117,7 @@ struct emm_common_data_s *emm_common_data_context_get( ...@@ -117,7 +117,7 @@ struct emm_common_data_s *emm_common_data_context_get(
return RB_FIND(emm_common_data_map, &root->emm_common_data_root, &reference); return RB_FIND(emm_common_data_map, &root->emm_common_data_root, &reference);
} }
#else #else
static emm_common_data_t* _emm_common_data[EMM_DATA_NB_UE_MAX]; static emm_common_data_t *_emm_common_data[EMM_DATA_NB_UE_MAX];
#endif #endif
/****************************************************************************/ /****************************************************************************/
...@@ -153,7 +153,7 @@ int emm_proc_common_initialize(unsigned int ueid, ...@@ -153,7 +153,7 @@ int emm_proc_common_initialize(unsigned int ueid,
emm_common_reject_callback_t _reject, emm_common_reject_callback_t _reject,
emm_common_failure_callback_t _failure, emm_common_failure_callback_t _failure,
emm_common_abort_callback_t _abort, emm_common_abort_callback_t _abort,
void* args) void *args)
{ {
struct emm_common_data_s *emm_common_data_ctx = NULL; struct emm_common_data_s *emm_common_data_ctx = NULL;
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -166,7 +166,7 @@ int emm_proc_common_initialize(unsigned int ueid, ...@@ -166,7 +166,7 @@ int emm_proc_common_initialize(unsigned int ueid,
#endif #endif
if (emm_common_data_ctx == NULL) { if (emm_common_data_ctx == NULL) {
emm_common_data_ctx = (emm_common_data_t*)malloc(sizeof(emm_common_data_t)); emm_common_data_ctx = (emm_common_data_t *)malloc(sizeof(emm_common_data_t));
emm_common_data_ctx->ueid = ueid; emm_common_data_ctx->ueid = ueid;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
RB_INSERT(emm_common_data_map, &emm_common_data_head.emm_common_data_root, RB_INSERT(emm_common_data_map, &emm_common_data_head.emm_common_data_root,
...@@ -416,7 +416,7 @@ int emm_proc_common_abort(unsigned int ueid) ...@@ -416,7 +416,7 @@ int emm_proc_common_abort(unsigned int ueid)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
void* emm_proc_common_get_args(unsigned int ueid) void *emm_proc_common_get_args(unsigned int ueid)
{ {
emm_common_data_t *emm_common_data_ctx = NULL; emm_common_data_t *emm_common_data_ctx = NULL;
LOG_FUNC_IN; LOG_FUNC_IN;
......
...@@ -47,9 +47,9 @@ Description Defines callback functions executed within EMM common procedures ...@@ -47,9 +47,9 @@ Description Defines callback functions executed within EMM common procedures
* - The EMM common procedure failed or is rejected * - The EMM common procedure failed or is rejected
* - Lower layer failure occured before the EMM common procedure completion * - Lower layer failure occured before the EMM common procedure completion
*/ */
typedef int (*emm_common_success_callback_t)(void*); typedef int (*emm_common_success_callback_t)(void *);
typedef int (*emm_common_reject_callback_t) (void*); typedef int (*emm_common_reject_callback_t) (void *);
typedef int (*emm_common_failure_callback_t)(void*); typedef int (*emm_common_failure_callback_t)(void *);
/* /*
* Type of EMM common procedure callback function * Type of EMM common procedure callback function
...@@ -57,7 +57,7 @@ typedef int (*emm_common_failure_callback_t)(void*); ...@@ -57,7 +57,7 @@ typedef int (*emm_common_failure_callback_t)(void*);
* EMM common procedure to be executed when the ongoing EMM procedure is * EMM common procedure to be executed when the ongoing EMM procedure is
* aborted. * aborted.
*/ */
typedef int (*emm_common_abort_callback_t)(void*); typedef int (*emm_common_abort_callback_t)(void *);
/****************************************************************************/ /****************************************************************************/
/******************** G L O B A L V A R I A B L E S ********************/ /******************** G L O B A L V A R I A B L E S ********************/
...@@ -72,13 +72,13 @@ int emm_proc_common_initialize(unsigned int ueid, ...@@ -72,13 +72,13 @@ int emm_proc_common_initialize(unsigned int ueid,
emm_common_reject_callback_t reject, emm_common_reject_callback_t reject,
emm_common_failure_callback_t failure, emm_common_failure_callback_t failure,
emm_common_abort_callback_t abort, emm_common_abort_callback_t abort,
void* args); void *args);
int emm_proc_common_success(unsigned int ueid); int emm_proc_common_success(unsigned int ueid);
int emm_proc_common_reject(unsigned int ueid); int emm_proc_common_reject(unsigned int ueid);
int emm_proc_common_failure(unsigned int ueid); int emm_proc_common_failure(unsigned int ueid);
int emm_proc_common_abort(unsigned int ueid); int emm_proc_common_abort(unsigned int ueid);
void* emm_proc_common_get_args(unsigned int ueid); void *emm_proc_common_get_args(unsigned int ueid);
#endif /* __EMM_COMMON_H__*/ #endif /* __EMM_COMMON_H__*/
...@@ -43,7 +43,7 @@ Description Defines the identification EMM procedure executed by the ...@@ -43,7 +43,7 @@ Description Defines the identification EMM procedure executed by the
/****************************************************************************/ /****************************************************************************/
/* String representation of the requested identity type */ /* String representation of the requested identity type */
static const char* _emm_identity_type_str[] = { static const char *_emm_identity_type_str[] = {
"NOT AVAILABLE", "IMSI", "IMEI", "IMEISV", "TMSI" "NOT AVAILABLE", "IMSI", "IMEI", "IMEISV", "TMSI"
}; };
...@@ -64,14 +64,14 @@ static const char* _emm_identity_type_str[] = { ...@@ -64,14 +64,14 @@ static const char* _emm_identity_type_str[] = {
/* /*
* Timer handlers * Timer handlers
*/ */
static void* _identification_t3470_handler(void*); static void *_identification_t3470_handler(void *);
/* /*
* Function executed whenever the ongoing EMM procedure that initiated * Function executed whenever the ongoing EMM procedure that initiated
* the identification procedure is aborted or the maximum value of the * the identification procedure is aborted or the maximum value of the
* retransmission timer counter is exceed * retransmission timer counter is exceed
*/ */
static int _identification_abort(void*); static int _identification_abort(void *);
/* /*
* Internal data used for identification procedure * Internal data used for identification procedure
...@@ -86,7 +86,7 @@ typedef struct { ...@@ -86,7 +86,7 @@ typedef struct {
* to the ongoing EMM procedure */ * to the ongoing EMM procedure */
} identification_data_t; } identification_data_t;
static int _identification_request(identification_data_t* data); static int _identification_request(identification_data_t *data);
#endif // NAS_MME #endif // NAS_MME
/****************************************************************************/ /****************************************************************************/
...@@ -140,8 +140,7 @@ int emm_proc_identification_request(emm_proc_identity_type_t type) ...@@ -140,8 +140,7 @@ int emm_proc_identification_request(emm_proc_identity_type_t type)
emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_NOT_AVAILABLE; emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_NOT_AVAILABLE;
switch (type) switch (type) {
{
case EMM_IDENT_TYPE_IMSI: case EMM_IDENT_TYPE_IMSI:
/* International Mobile Subscriber Identity is requested */ /* International Mobile Subscriber Identity is requested */
if (_emm_data.imsi) { if (_emm_data.imsi) {
...@@ -238,8 +237,8 @@ int emm_proc_identification(unsigned int ueid, ...@@ -238,8 +237,8 @@ int emm_proc_identification(unsigned int ueid,
_emm_identity_type_str[type], type); _emm_identity_type_str[type], type);
/* Allocate parameters of the retransmission timer callback */ /* Allocate parameters of the retransmission timer callback */
identification_data_t* data = identification_data_t *data =
(identification_data_t*)malloc(sizeof(identification_data_t)); (identification_data_t *)malloc(sizeof(identification_data_t));
if (data != NULL) { if (data != NULL) {
/* Setup ongoing EMM procedure callback functions */ /* Setup ongoing EMM procedure callback functions */
...@@ -297,13 +296,13 @@ int emm_proc_identification(unsigned int ueid, ...@@ -297,13 +296,13 @@ int emm_proc_identification(unsigned int ueid,
** Others: _emm_data, T3470 ** ** Others: _emm_data, T3470 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, int emm_proc_identification_complete(unsigned int ueid, const imsi_t *imsi,
const imei_t* imei, UInt32_t* tmsi) const imei_t *imei, UInt32_t *tmsi)
{ {
int rc = RETURNerror; int rc = RETURNerror;
emm_sap_t emm_sap; emm_sap_t emm_sap;
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -314,9 +313,11 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, ...@@ -314,9 +313,11 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi,
T3470.id = nas_timer_stop(T3470.id); T3470.id = nas_timer_stop(T3470.id);
/* Release retransmission timer paramaters */ /* Release retransmission timer paramaters */
identification_data_t* data = identification_data_t *data =
(identification_data_t*)(emm_proc_common_get_args(ueid)); (identification_data_t *)(emm_proc_common_get_args(ueid));
if (data) free(data); if (data) {
free(data);
}
/* Get the UE context */ /* Get the UE context */
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
...@@ -333,25 +334,23 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, ...@@ -333,25 +334,23 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi,
if (imsi) { if (imsi) {
/* Update the IMSI */ /* Update the IMSI */
if (emm_ctx->imsi == NULL) { if (emm_ctx->imsi == NULL) {
emm_ctx->imsi = (imsi_t*)malloc(sizeof(imsi_t)); emm_ctx->imsi = (imsi_t *)malloc(sizeof(imsi_t));
} }
if (emm_ctx->imsi) { if (emm_ctx->imsi) {
memcpy(emm_ctx->imsi, imsi, sizeof(imsi_t)); memcpy(emm_ctx->imsi, imsi, sizeof(imsi_t));
} }
} } else if (imei) {
else if (imei) {
/* Update the IMEI */ /* Update the IMEI */
if (emm_ctx->imei == NULL) { if (emm_ctx->imei == NULL) {
emm_ctx->imei = (imei_t*)malloc(sizeof(imei_t)); emm_ctx->imei = (imei_t *)malloc(sizeof(imei_t));
} }
if (emm_ctx->imei) { if (emm_ctx->imei) {
memcpy(emm_ctx->imei, imei, sizeof(imei_t)); memcpy(emm_ctx->imei, imei, sizeof(imei_t));
} }
} } else if (tmsi) {
else if (tmsi) {
/* Update the GUTI */ /* Update the GUTI */
if (emm_ctx->guti == NULL) { if (emm_ctx->guti == NULL) {
emm_ctx->guti = (GUTI_t*)malloc(sizeof(GUTI_t)); emm_ctx->guti = (GUTI_t *)malloc(sizeof(GUTI_t));
} }
if (emm_ctx->guti) { if (emm_ctx->guti) {
memcpy(&emm_ctx->guti->gummei, memcpy(&emm_ctx->guti->gummei,
...@@ -365,8 +364,7 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, ...@@ -365,8 +364,7 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi,
emm_sap.primitive = EMMREG_COMMON_PROC_CNF; emm_sap.primitive = EMMREG_COMMON_PROC_CNF;
emm_sap.u.emm_reg.ueid = ueid; emm_sap.u.emm_reg.ueid = ueid;
emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached; emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached;
} } else {
else {
LOG_TRACE(ERROR, "EMM-PROC - No EMM context exists"); LOG_TRACE(ERROR, "EMM-PROC - No EMM context exists");
/* /*
* Notify EMM that the identification procedure failed * Notify EMM that the identification procedure failed
...@@ -413,13 +411,13 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, ...@@ -413,13 +411,13 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _identification_t3470_handler(void* args) static void *_identification_t3470_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
identification_data_t* data = (identification_data_t*)(args); identification_data_t *data = (identification_data_t *)(args);
/* Increment the retransmission counter */ /* Increment the retransmission counter */
data->retransmission_count += 1; data->retransmission_count += 1;
...@@ -430,8 +428,7 @@ static void* _identification_t3470_handler(void* args) ...@@ -430,8 +428,7 @@ static void* _identification_t3470_handler(void* args)
if (data->retransmission_count < IDENTIFICATION_COUNTER_MAX) { if (data->retransmission_count < IDENTIFICATION_COUNTER_MAX) {
/* Send identity request message to the UE */ /* Send identity request message to the UE */
rc = _identification_request(data); rc = _identification_request(data);
} } else {
else {
/* Set the failure notification indicator */ /* Set the failure notification indicator */
data->notify_failure = TRUE; data->notify_failure = TRUE;
/* Abort the identification procedure */ /* Abort the identification procedure */
...@@ -461,7 +458,7 @@ static void* _identification_t3470_handler(void* args) ...@@ -461,7 +458,7 @@ static void* _identification_t3470_handler(void* args)
** Others: T3470 ** ** Others: T3470 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int _identification_request(identification_data_t* data) int _identification_request(identification_data_t *data)
{ {
emm_sap_t emm_sap; emm_sap_t emm_sap;
int rc; int rc;
...@@ -524,16 +521,15 @@ int _identification_request(identification_data_t* data) ...@@ -524,16 +521,15 @@ int _identification_request(identification_data_t* data)
** Others: T3470 ** ** Others: T3470 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _identification_abort(void* args) static int _identification_abort(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
identification_data_t* data = (identification_data_t*)(args); identification_data_t *data = (identification_data_t *)(args);
if (data) if (data) {
{
unsigned int ueid = data->ueid; unsigned int ueid = data->ueid;
int notify_failure = data->notify_failure; int notify_failure = data->notify_failure;
......
...@@ -60,8 +60,8 @@ Description Defines EMM procedures executed by the Non-Access Stratum ...@@ -60,8 +60,8 @@ Description Defines EMM procedures executed by the Non-Access Stratum
/******************* L O C A L D E F I N I T I O N S *******************/ /******************* L O C A L D E F I N I T I O N S *******************/
/****************************************************************************/ /****************************************************************************/
static int _IdleMode_plmn_str(char* plmn_str, const plmn_t* plmn); static int _IdleMode_plmn_str(char *plmn_str, const plmn_t *plmn);
static int _IldlMode_get_opnn_id(const plmn_t* plmn); static int _IldlMode_get_opnn_id(const plmn_t *plmn);
static int _IdleMode_get_suitable_cell(int index); static int _IdleMode_get_suitable_cell(int index);
/* /*
...@@ -94,7 +94,7 @@ static struct { ...@@ -94,7 +94,7 @@ static struct {
int n_plmns; int n_plmns;
#define EMM_PLMN_LIST_SIZE (EMM_DATA_EPLMN_MAX + EMM_DATA_PLMN_MAX + \ #define EMM_PLMN_LIST_SIZE (EMM_DATA_EPLMN_MAX + EMM_DATA_PLMN_MAX + \
EMM_DATA_OPLMN_MAX + 2) EMM_DATA_OPLMN_MAX + 2)
plmn_t* plmn[EMM_PLMN_LIST_SIZE]; plmn_t *plmn[EMM_PLMN_LIST_SIZE];
int index; /* Index of the PLMN for which selection is ongoing */ int index; /* Index of the PLMN for which selection is ongoing */
int hplmn; /* Index of the home PLMN or the highest priority int hplmn; /* Index of the home PLMN or the highest priority
* equivalent home PLMN */ * equivalent home PLMN */
...@@ -260,9 +260,8 @@ int IdleMode_update_plmn_list(int i) ...@@ -260,9 +260,8 @@ int IdleMode_update_plmn_list(int i)
int offset = 0; int offset = 0;
int n = 1; int n = 1;
while ( (i < _emm_plmn_list.n_plmns) && (offset < EMM_DATA_BUFFER_SIZE) ) while ( (i < _emm_plmn_list.n_plmns) && (offset < EMM_DATA_BUFFER_SIZE) ) {
{ struct plmn_param_t *plmn = &(_emm_plmn_list.param[i++]);
struct plmn_param_t* plmn = &(_emm_plmn_list.param[i++]);
if (n++ > 1) { if (n++ > 1) {
offset += snprintf(_emm_data.plist.buffer + offset, offset += snprintf(_emm_data.plist.buffer + offset,
EMM_DATA_BUFFER_SIZE - offset, ","); EMM_DATA_BUFFER_SIZE - offset, ",");
...@@ -300,7 +299,8 @@ int IdleMode_update_plmn_list(int i) ...@@ -300,7 +299,8 @@ int IdleMode_update_plmn_list(int i)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const char* IdleMode_get_plmn_fullname(const plmn_t* plmn, int index, size_t* len) const char *IdleMode_get_plmn_fullname(const plmn_t *plmn, int index,
size_t *len)
{ {
if (index < _emm_plmn_list.n_plmns) { if (index < _emm_plmn_list.n_plmns) {
assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) ); assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) );
...@@ -327,7 +327,8 @@ const char* IdleMode_get_plmn_fullname(const plmn_t* plmn, int index, size_t* le ...@@ -327,7 +327,8 @@ const char* IdleMode_get_plmn_fullname(const plmn_t* plmn, int index, size_t* le
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const char* IdleMode_get_plmn_shortname(const plmn_t* plmn, int index, size_t* len) const char *IdleMode_get_plmn_shortname(const plmn_t *plmn, int index,
size_t *len)
{ {
if (index < _emm_plmn_list.n_plmns) { if (index < _emm_plmn_list.n_plmns) {
assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) ); assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) );
...@@ -355,7 +356,7 @@ const char* IdleMode_get_plmn_shortname(const plmn_t* plmn, int index, size_t* l ...@@ -355,7 +356,7 @@ const char* IdleMode_get_plmn_shortname(const plmn_t* plmn, int index, size_t* l
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const char* IdleMode_get_plmn_id(const plmn_t* plmn, int index, size_t* len) const char *IdleMode_get_plmn_id(const plmn_t *plmn, int index, size_t *len)
{ {
if (index < _emm_plmn_list.n_plmns) { if (index < _emm_plmn_list.n_plmns) {
assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) ); assert( PLMNS_ARE_EQUAL(*plmn, *_emm_plmn_list.plmn[index]) );
...@@ -381,11 +382,10 @@ const char* IdleMode_get_plmn_id(const plmn_t* plmn, int index, size_t* len) ...@@ -381,11 +382,10 @@ const char* IdleMode_get_plmn_id(const plmn_t* plmn, int index, size_t* len)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int IdleMode_get_plmn_fullname_index(const char* plmn) int IdleMode_get_plmn_fullname_index(const char *plmn)
{ {
/* Get the index of the PLMN identifier with specified full name */ /* Get the index of the PLMN identifier with specified full name */
for (int index = 0; index < _emm_plmn_list.n_plmns; index++) for (int index = 0; index < _emm_plmn_list.n_plmns; index++) {
{
if ( strncmp(plmn, _emm_plmn_list.param[index].fullname, if ( strncmp(plmn, _emm_plmn_list.param[index].fullname,
NET_FORMAT_LONG_SIZE) != 0 ) { NET_FORMAT_LONG_SIZE) != 0 ) {
continue; continue;
...@@ -411,11 +411,10 @@ int IdleMode_get_plmn_fullname_index(const char* plmn) ...@@ -411,11 +411,10 @@ int IdleMode_get_plmn_fullname_index(const char* plmn)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int IdleMode_get_plmn_shortname_index(const char* plmn) int IdleMode_get_plmn_shortname_index(const char *plmn)
{ {
/* Get the index of the PLMN identifier with specified short name */ /* Get the index of the PLMN identifier with specified short name */
for (int index = 0; index < _emm_plmn_list.n_plmns; index++) for (int index = 0; index < _emm_plmn_list.n_plmns; index++) {
{
if ( !strncmp(plmn, _emm_plmn_list.param[index].shortname, if ( !strncmp(plmn, _emm_plmn_list.param[index].shortname,
NET_FORMAT_SHORT_SIZE) ) { NET_FORMAT_SHORT_SIZE) ) {
continue; continue;
...@@ -441,11 +440,10 @@ int IdleMode_get_plmn_shortname_index(const char* plmn) ...@@ -441,11 +440,10 @@ int IdleMode_get_plmn_shortname_index(const char* plmn)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int IdleMode_get_plmn_id_index(const char* plmn) int IdleMode_get_plmn_id_index(const char *plmn)
{ {
/* Get the index of the PLMN identifier with specified numeric identifier */ /* Get the index of the PLMN identifier with specified numeric identifier */
for (int index = 0; index < _emm_plmn_list.n_plmns; index++) for (int index = 0; index < _emm_plmn_list.n_plmns; index++) {
{
if ( !strncmp(plmn, _emm_plmn_list.param[index].num, if ( !strncmp(plmn, _emm_plmn_list.param[index].num,
NET_FORMAT_LONG_SIZE) ) { NET_FORMAT_LONG_SIZE) ) {
continue; continue;
...@@ -487,9 +485,7 @@ int emm_proc_initialize(void) ...@@ -487,9 +485,7 @@ int emm_proc_initialize(void)
/* The USIM application is not present or not valid */ /* The USIM application is not present or not valid */
LOG_TRACE(WARNING, "EMM-IDLE - USIM is not valid"); LOG_TRACE(WARNING, "EMM-IDLE - USIM is not valid");
emm_sap.primitive = EMMREG_NO_IMSI; emm_sap.primitive = EMMREG_NO_IMSI;
} } else {
else
{
/* The highest priority is given to either the "equivalent PLMNs" /* The highest priority is given to either the "equivalent PLMNs"
* if available, or the last registered PLMN */ * if available, or the last registered PLMN */
if (_emm_data.nvdata.eplmn.n_plmns > 0) { if (_emm_data.nvdata.eplmn.n_plmns > 0) {
...@@ -497,8 +493,7 @@ int emm_proc_initialize(void) ...@@ -497,8 +493,7 @@ int emm_proc_initialize(void)
_emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] = _emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] =
&_emm_data.nvdata.eplmn.plmn[i]; &_emm_data.nvdata.eplmn.plmn[i];
} }
} } else if ( PLMN_IS_VALID(_emm_data.nvdata.rplmn) ) {
else if ( PLMN_IS_VALID(_emm_data.nvdata.rplmn) ) {
_emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] = _emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] =
&_emm_data.nvdata.rplmn; &_emm_data.nvdata.rplmn;
} }
...@@ -514,8 +509,7 @@ int emm_proc_initialize(void) ...@@ -514,8 +509,7 @@ int emm_proc_initialize(void)
if (_emm_data.ehplmn.n_plmns > 0) { if (_emm_data.ehplmn.n_plmns > 0) {
_emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] = _emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] =
&_emm_data.ehplmn.plmn[0]; &_emm_data.ehplmn.plmn[0];
} } else {
else {
_emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] = &_emm_data.hplmn; _emm_plmn_list.plmn[_emm_plmn_list.n_plmns++] = &_emm_data.hplmn;
} }
...@@ -543,7 +537,7 @@ int emm_proc_initialize(void) ...@@ -543,7 +537,7 @@ int emm_proc_initialize(void)
/* Initialize the PLMNs' parameters */ /* Initialize the PLMNs' parameters */
for (int i=0; i < _emm_plmn_list.n_plmns; i++) { for (int i=0; i < _emm_plmn_list.n_plmns; i++) {
struct plmn_param_t* plmn = &(_emm_plmn_list.param[i]); struct plmn_param_t *plmn = &(_emm_plmn_list.param[i]);
int id = _IldlMode_get_opnn_id(_emm_plmn_list.plmn[i]); int id = _IldlMode_get_opnn_id(_emm_plmn_list.plmn[i]);
if (id < 0) { if (id < 0) {
plmn->fullname[0] = '\0'; plmn->fullname[0] = '\0';
...@@ -626,8 +620,7 @@ int emm_proc_plmn_selection(int index) ...@@ -626,8 +620,7 @@ int emm_proc_plmn_selection(int index)
LOG_TRACE(WARNING, "EMM-IDLE - Failed to notify " LOG_TRACE(WARNING, "EMM-IDLE - Failed to notify "
"network list update"); "network list update");
} }
} } else {
else {
/* /*
* Try to register to the PLMN manually selected by the user * Try to register to the PLMN manually selected by the user
*/ */
...@@ -702,8 +695,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat) ...@@ -702,8 +695,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat)
(_emm_data.plmn_mode == EMM_DATA_PLMN_MANUAL)? "Manual" : (_emm_data.plmn_mode == EMM_DATA_PLMN_MANUAL)? "Manual" :
"Automatic/manual"); "Automatic/manual");
if (found) if (found) {
{
int is_forbidden = FALSE; int is_forbidden = FALSE;
/* Select the PLMN of which a suitable cell has been found */ /* Select the PLMN of which a suitable cell has been found */
...@@ -777,8 +769,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat) ...@@ -777,8 +769,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat)
_emm_plmn_list.fplmn = index; _emm_plmn_list.fplmn = index;
} }
_emm_plmn_list.param[index].stat = NET_OPER_FORBIDDEN; _emm_plmn_list.param[index].stat = NET_OPER_FORBIDDEN;
} } else {
else {
/* A suitable cell has been found and the PLMN or tracking area /* A suitable cell has been found and the PLMN or tracking area
* is not in the forbidden list */ * is not in the forbidden list */
LOG_TRACE(INFO, "EMM-IDLE - UE may camp on this suitable cell ", LOG_TRACE(INFO, "EMM-IDLE - UE may camp on this suitable cell ",
...@@ -853,8 +844,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat) ...@@ -853,8 +844,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat)
/* Try to select the next PLMN in the list of available PLMNs */ /* Try to select the next PLMN in the list of available PLMNs */
_emm_plmn_list.index = index; _emm_plmn_list.index = index;
rc = emm_proc_plmn_selection(index); rc = emm_proc_plmn_selection(index);
} } else {
else {
/* No suitable cell of any PLMN within the ordered list /* No suitable cell of any PLMN within the ordered list
* of available PLMNs has been found */ * of available PLMNs has been found */
select_next_plmn = FALSE; select_next_plmn = FALSE;
...@@ -883,8 +873,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat) ...@@ -883,8 +873,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat)
/* Update the index of the new selected PLMN */ /* Update the index of the new selected PLMN */
if (emm_sap.primitive != EMMREG_NO_CELL) { if (emm_sap.primitive != EMMREG_NO_CELL) {
_emm_plmn_list.splmn = index; _emm_plmn_list.splmn = index;
} } else {
else {
_emm_plmn_list.splmn = -1; _emm_plmn_list.splmn = -1;
} }
/* /*
...@@ -896,8 +885,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat) ...@@ -896,8 +885,7 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat)
if (_emm_plmn_list.splmn == _emm_plmn_list.rplmn) { if (_emm_plmn_list.splmn == _emm_plmn_list.rplmn) {
/* The selected PLMN is the registered PLMN */ /* The selected PLMN is the registered PLMN */
_emm_data.is_rplmn = TRUE; _emm_data.is_rplmn = TRUE;
} } else if (_emm_plmn_list.splmn < _emm_plmn_list.hplmn) {
else if (_emm_plmn_list.splmn < _emm_plmn_list.hplmn) {
/* The selected PLMN is in the list of equivalent PLMNs */ /* The selected PLMN is in the list of equivalent PLMNs */
_emm_data.is_eplmn = TRUE; _emm_data.is_eplmn = TRUE;
} }
...@@ -978,8 +966,7 @@ int emm_proc_location_notify(tac_t tac, ci_t ci, AcT_t rat) ...@@ -978,8 +966,7 @@ int emm_proc_location_notify(tac_t tac, ci_t ci, AcT_t rat)
/* Update the location information */ /* Update the location information */
if ( (_emm_data.tac != tac) || if ( (_emm_data.tac != tac) ||
(_emm_data.ci != ci) || (_emm_data.ci != ci) ||
(_emm_data.rat != rat) ) (_emm_data.rat != rat) ) {
{
_emm_data.tac = tac; _emm_data.tac = tac;
_emm_data.ci = ci; _emm_data.ci = ci;
_emm_data.rat = rat; _emm_data.rat = rat;
...@@ -1042,19 +1029,31 @@ int emm_proc_network_notify(int index) ...@@ -1042,19 +1029,31 @@ int emm_proc_network_notify(int index)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _IdleMode_plmn_str(char* plmn_str, const plmn_t* plmn) static int _IdleMode_plmn_str(char *plmn_str, const plmn_t *plmn)
{ {
char* p = plmn_str; char *p = plmn_str;
if (plmn == NULL) { if (plmn == NULL) {
return 0; return 0;
} }
if (plmn->MCCdigit1 != 0x0F) sprintf(p++, "%u", plmn->MCCdigit1); if (plmn->MCCdigit1 != 0x0F) {
if (plmn->MCCdigit2 != 0x0F) sprintf(p++, "%u", plmn->MCCdigit2); sprintf(p++, "%u", plmn->MCCdigit1);
if (plmn->MCCdigit3 != 0x0F) sprintf(p++, "%u", plmn->MCCdigit3); }
if (plmn->MNCdigit1 != 0x0F) sprintf(p++, "%u", plmn->MNCdigit1); if (plmn->MCCdigit2 != 0x0F) {
if (plmn->MNCdigit2 != 0x0F) sprintf(p++, "%u", plmn->MNCdigit2); sprintf(p++, "%u", plmn->MCCdigit2);
if (plmn->MNCdigit3 != 0x0F) sprintf(p++, "%u", plmn->MNCdigit3); }
if (plmn->MCCdigit3 != 0x0F) {
sprintf(p++, "%u", plmn->MCCdigit3);
}
if (plmn->MNCdigit1 != 0x0F) {
sprintf(p++, "%u", plmn->MNCdigit1);
}
if (plmn->MNCdigit2 != 0x0F) {
sprintf(p++, "%u", plmn->MNCdigit2);
}
if (plmn->MNCdigit3 != 0x0F) {
sprintf(p++, "%u", plmn->MNCdigit3);
}
return (p - plmn_str); return (p - plmn_str);
} }
...@@ -1076,15 +1075,27 @@ static int _IdleMode_plmn_str(char* plmn_str, const plmn_t* plmn) ...@@ -1076,15 +1075,27 @@ static int _IdleMode_plmn_str(char* plmn_str, const plmn_t* plmn)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _IldlMode_get_opnn_id(const plmn_t* plmn) static int _IldlMode_get_opnn_id(const plmn_t *plmn)
{ {
for (int i = 0; i < _emm_data.n_opnns; i++) { for (int i = 0; i < _emm_data.n_opnns; i++) {
if (plmn->MCCdigit1 != _emm_data.opnn[i].plmn->MCCdigit1) continue; if (plmn->MCCdigit1 != _emm_data.opnn[i].plmn->MCCdigit1) {
if (plmn->MCCdigit2 != _emm_data.opnn[i].plmn->MCCdigit2) continue; continue;
if (plmn->MCCdigit3 != _emm_data.opnn[i].plmn->MCCdigit3) continue; }
if (plmn->MNCdigit1 != _emm_data.opnn[i].plmn->MNCdigit1) continue; if (plmn->MCCdigit2 != _emm_data.opnn[i].plmn->MCCdigit2) {
if (plmn->MNCdigit2 != _emm_data.opnn[i].plmn->MNCdigit2) continue; continue;
if (plmn->MNCdigit3 != _emm_data.opnn[i].plmn->MNCdigit3) continue; }
if (plmn->MCCdigit3 != _emm_data.opnn[i].plmn->MCCdigit3) {
continue;
}
if (plmn->MNCdigit1 != _emm_data.opnn[i].plmn->MNCdigit1) {
continue;
}
if (plmn->MNCdigit2 != _emm_data.opnn[i].plmn->MNCdigit2) {
continue;
}
if (plmn->MNCdigit3 != _emm_data.opnn[i].plmn->MNCdigit3) {
continue;
}
/* Found */ /* Found */
return (i); return (i);
} }
...@@ -1111,7 +1122,7 @@ static int _IldlMode_get_opnn_id(const plmn_t* plmn) ...@@ -1111,7 +1122,7 @@ static int _IldlMode_get_opnn_id(const plmn_t* plmn)
static int _IdleMode_get_suitable_cell(int index) static int _IdleMode_get_suitable_cell(int index)
{ {
emm_sap_t emm_sap; emm_sap_t emm_sap;
const plmn_t* plmn = _emm_plmn_list.plmn[index]; const plmn_t *plmn = _emm_plmn_list.plmn[index];
LOG_TRACE(INFO, "EMM-IDLE - Trying to search a suitable cell " LOG_TRACE(INFO, "EMM-IDLE - Trying to search a suitable cell "
"of PLMN %d in %s mode", index, "of PLMN %d in %s mode", index,
......
...@@ -51,12 +51,14 @@ int IdleMode_get_splmn_index(void); ...@@ -51,12 +51,14 @@ int IdleMode_get_splmn_index(void);
int IdleMode_update_plmn_list(int index); int IdleMode_update_plmn_list(int index);
const char* IdleMode_get_plmn_fullname(const plmn_t* plmn, int index, size_t* len); const char *IdleMode_get_plmn_fullname(const plmn_t *plmn, int index,
const char* IdleMode_get_plmn_shortname(const plmn_t* plmn, int index, size_t* len); size_t *len);
const char* IdleMode_get_plmn_id(const plmn_t* plmn, int index, size_t* len); const char *IdleMode_get_plmn_shortname(const plmn_t *plmn, int index,
size_t *len);
int IdleMode_get_plmn_fullname_index(const char* plmn); const char *IdleMode_get_plmn_id(const plmn_t *plmn, int index, size_t *len);
int IdleMode_get_plmn_shortname_index(const char* plmn);
int IdleMode_get_plmn_id_index(const char* plmn); int IdleMode_get_plmn_fullname_index(const char *plmn);
int IdleMode_get_plmn_shortname_index(const char *plmn);
int IdleMode_get_plmn_id_index(const char *plmn);
#endif /* __IDLEMODE_H__*/ #endif /* __IDLEMODE_H__*/
...@@ -50,7 +50,7 @@ static struct { ...@@ -50,7 +50,7 @@ static struct {
lowerlayer_success_callback_t success; /* Successful data delivery */ lowerlayer_success_callback_t success; /* Successful data delivery */
lowerlayer_failure_callback_t failure; /* Lower layer failure */ lowerlayer_failure_callback_t failure; /* Lower layer failure */
lowerlayer_release_callback_t release; /* NAS signalling release */ lowerlayer_release_callback_t release; /* NAS signalling release */
void* args; /* EMM procedure argument parameters */ void *args; /* EMM procedure argument parameters */
} _lowerlayer_data; } _lowerlayer_data;
#endif #endif
...@@ -200,7 +200,7 @@ int lowerlayer_release(int cause) ...@@ -200,7 +200,7 @@ int lowerlayer_release(int cause)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int lowerlayer_data_ind(unsigned int ueid, const OctetString* data) int lowerlayer_data_ind(unsigned int ueid, const OctetString *data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -232,7 +232,7 @@ int lowerlayer_data_ind(unsigned int ueid, const OctetString* data) ...@@ -232,7 +232,7 @@ int lowerlayer_data_ind(unsigned int ueid, const OctetString* data)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int lowerlayer_data_req(unsigned int ueid, const OctetString* data) int lowerlayer_data_req(unsigned int ueid, const OctetString *data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -303,7 +303,7 @@ int lowerlayer_data_req(unsigned int ueid, const OctetString* data) ...@@ -303,7 +303,7 @@ int lowerlayer_data_req(unsigned int ueid, const OctetString* data)
int emm_proc_lowerlayer_initialize(lowerlayer_success_callback_t success, int emm_proc_lowerlayer_initialize(lowerlayer_success_callback_t success,
lowerlayer_failure_callback_t failure, lowerlayer_failure_callback_t failure,
lowerlayer_release_callback_t release, lowerlayer_release_callback_t release,
void* args) void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -430,12 +430,12 @@ int emm_proc_lowerlayer_release(void) ...@@ -430,12 +430,12 @@ int emm_proc_lowerlayer_release(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
void emm_as_set_security_data(emm_as_security_data_t* data, const void* args, void emm_as_set_security_data(emm_as_security_data_t *data, const void *args,
int is_new, int is_ciphered) int is_new, int is_ciphered)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
const emm_security_context_t* context = (emm_security_context_t*)(args); const emm_security_context_t *context = (emm_security_context_t *)(args);
memset(data, 0, sizeof(emm_as_security_data_t)); memset(data, 0, sizeof(emm_as_security_data_t));
...@@ -448,7 +448,7 @@ void emm_as_set_security_data(emm_as_security_data_t* data, const void* args, ...@@ -448,7 +448,7 @@ void emm_as_set_security_data(emm_as_security_data_t* data, const void* args,
data->is_new = is_new; data->is_new = is_new;
data->ksi = context->eksi; data->ksi = context->eksi;
data->sqn = context->ul_count.seq_num; data->sqn = context->ul_count.seq_num;
data->count = *(UInt32_t*)(&context->ul_count); data->count = *(UInt32_t *)(&context->ul_count);
/* NAS integrity and cyphering keys may not be available if the /* NAS integrity and cyphering keys may not be available if the
* current security context is a partial EPS security context * current security context is a partial EPS security context
* and not a full native EPS security context */ * and not a full native EPS security context */
...@@ -463,8 +463,7 @@ void emm_as_set_security_data(emm_as_security_data_t* data, const void* args, ...@@ -463,8 +463,7 @@ void emm_as_set_security_data(emm_as_security_data_t* data, const void* args,
* protected and unciphered */ * protected and unciphered */
data->k_enc = &context->knas_enc; data->k_enc = &context->knas_enc;
} }
} } else {
else {
/* No valid EPS security context exists */ /* No valid EPS security context exists */
data->ksi = EMM_AS_NO_KEY_AVAILABLE; data->ksi = EMM_AS_NO_KEY_AVAILABLE;
} }
......
...@@ -35,19 +35,19 @@ Description Defines EMM procedures executed by the Non-Access Stratum ...@@ -35,19 +35,19 @@ Description Defines EMM procedures executed by the Non-Access Stratum
* Type of EMM procedure callback function executed whenever data are * Type of EMM procedure callback function executed whenever data are
* successfully delivered to the network * successfully delivered to the network
*/ */
typedef int (*lowerlayer_success_callback_t)(void*); typedef int (*lowerlayer_success_callback_t)(void *);
/* /*
* Type of EMM procedure callback function executed when data are not * Type of EMM procedure callback function executed when data are not
* delivered to the network because a lower layer failure occurred * delivered to the network because a lower layer failure occurred
*/ */
typedef int (*lowerlayer_failure_callback_t)(int, void*); typedef int (*lowerlayer_failure_callback_t)(int, void *);
/* /*
* Type of EMM procedure callback function executed when NAS signalling * Type of EMM procedure callback function executed when NAS signalling
* connection is released * connection is released
*/ */
typedef int (*lowerlayer_release_callback_t)(void*); typedef int (*lowerlayer_release_callback_t)(void *);
#endif #endif
/****************************************************************************/ /****************************************************************************/
...@@ -67,7 +67,7 @@ int lowerlayer_failure(unsigned int ueid); ...@@ -67,7 +67,7 @@ int lowerlayer_failure(unsigned int ueid);
int lowerlayer_establish(void); int lowerlayer_establish(void);
int lowerlayer_release(int cause); int lowerlayer_release(int cause);
int lowerlayer_data_ind(unsigned int ueid, const OctetString* data); int lowerlayer_data_ind(unsigned int ueid, const OctetString *data);
int lowerlayer_data_req(unsigned int ueid, const OctetString* data); int lowerlayer_data_req(unsigned int ueid, const OctetString *data);
#endif /* __LOWERLAYER_H__*/ #endif /* __LOWERLAYER_H__*/
...@@ -54,12 +54,15 @@ Description Defines the security mode control EMM procedure executed by the ...@@ -54,12 +54,15 @@ Description Defines the security mode control EMM procedure executed by the
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#ifdef NAS_UE #ifdef NAS_UE
static int _security_kdf(const OctetString* kasme, OctetString* key, static int _security_kdf(const OctetString *kasme, OctetString *key,
UInt8_t algo_dist, UInt8_t algo_id); UInt8_t algo_dist, UInt8_t algo_id);
static int _security_knas_enc(const OctetString* kasme, OctetString* knas_enc, UInt8_t eia); static int _security_knas_enc(const OctetString *kasme, OctetString *knas_enc,
static int _security_knas_int(const OctetString* kasme, OctetString* knas_int, UInt8_t eea); UInt8_t eia);
static int _security_kenb(const OctetString* kasme, OctetString* kenb, UInt32_t count); static int _security_knas_int(const OctetString *kasme, OctetString *knas_int,
UInt8_t eea);
static int _security_kenb(const OctetString *kasme, OctetString *kenb,
UInt32_t count);
/* /*
* Internal data used for security mode control procedure * Internal data used for security mode control procedure
...@@ -68,7 +71,7 @@ static struct { ...@@ -68,7 +71,7 @@ static struct {
OctetString kenb; /* eNodeB security key */ OctetString kenb; /* eNodeB security key */
} _security_data; } _security_data;
static void _security_release(emm_security_context_t* ctx); static void _security_release(emm_security_context_t *ctx);
#endif // NAS_UE #endif // NAS_UE
/* /*
...@@ -80,14 +83,14 @@ static void _security_release(emm_security_context_t* ctx); ...@@ -80,14 +83,14 @@ static void _security_release(emm_security_context_t* ctx);
/* /*
* Timer handlers * Timer handlers
*/ */
static void* _security_t3460_handler(void*); static void *_security_t3460_handler(void *);
/* /*
* Function executed whenever the ongoing EMM procedure that initiated * Function executed whenever the ongoing EMM procedure that initiated
* the security mode control procedure is aborted or the maximum value of the * the security mode control procedure is aborted or the maximum value of the
* retransmission timer counter is exceed * retransmission timer counter is exceed
*/ */
static int _security_abort(void*); static int _security_abort(void *);
/* /*
* Internal data used for security mode control procedure * Internal data used for security mode control procedure
...@@ -104,7 +107,7 @@ typedef struct { ...@@ -104,7 +107,7 @@ typedef struct {
* ongoing EMM procedure */ * ongoing EMM procedure */
} security_data_t; } security_data_t;
static int _security_request(security_data_t* data, int is_new); static int _security_request(security_data_t *data, int is_new);
#endif // NAS_MME #endif // NAS_MME
/****************************************************************************/ /****************************************************************************/
...@@ -196,7 +199,7 @@ int emm_proc_security_mode_command(int native_ksi, int ksi, ...@@ -196,7 +199,7 @@ int emm_proc_security_mode_command(int native_ksi, int ksi,
/* Derive the NAS cyphering key */ /* Derive the NAS cyphering key */
if (_emm_data.non_current->knas_enc.value == NULL) { if (_emm_data.non_current->knas_enc.value == NULL) {
_emm_data.non_current->knas_enc.value = _emm_data.non_current->knas_enc.value =
(uint8_t*)malloc(AUTH_KNAS_ENC_SIZE); (uint8_t *)malloc(AUTH_KNAS_ENC_SIZE);
_emm_data.non_current->knas_enc.length = AUTH_KNAS_ENC_SIZE; _emm_data.non_current->knas_enc.length = AUTH_KNAS_ENC_SIZE;
} }
if (_emm_data.non_current->knas_enc.value != NULL) { if (_emm_data.non_current->knas_enc.value != NULL) {
...@@ -206,7 +209,7 @@ int emm_proc_security_mode_command(int native_ksi, int ksi, ...@@ -206,7 +209,7 @@ int emm_proc_security_mode_command(int native_ksi, int ksi,
/* Derive the NAS integrity key */ /* Derive the NAS integrity key */
if (_emm_data.non_current->knas_int.value == NULL) { if (_emm_data.non_current->knas_int.value == NULL) {
_emm_data.non_current->knas_int.value = _emm_data.non_current->knas_int.value =
(uint8_t*)malloc(AUTH_KNAS_INT_SIZE); (uint8_t *)malloc(AUTH_KNAS_INT_SIZE);
_emm_data.non_current->knas_int.length = AUTH_KNAS_INT_SIZE; _emm_data.non_current->knas_int.length = AUTH_KNAS_INT_SIZE;
} }
if (_emm_data.non_current->knas_int.value != NULL) { if (_emm_data.non_current->knas_int.value != NULL) {
...@@ -217,14 +220,14 @@ int emm_proc_security_mode_command(int native_ksi, int ksi, ...@@ -217,14 +220,14 @@ int emm_proc_security_mode_command(int native_ksi, int ksi,
} }
/* Derive the eNodeB key */ /* Derive the eNodeB key */
if (_security_data.kenb.value == NULL) { if (_security_data.kenb.value == NULL) {
_security_data.kenb.value = (uint8_t*)malloc(AUTH_KENB_SIZE); _security_data.kenb.value = (uint8_t *)malloc(AUTH_KENB_SIZE);
_security_data.kenb.length = 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) { if (rc != RETURNerror) {
rc = _security_kenb(&_security_data.kenb, rc = _security_kenb(&_security_data.kenb,
&_emm_data.security->kasme, &_emm_data.security->kasme,
*(UInt32_t*)(&_emm_data.non_current->ul_count)); *(UInt32_t *)(&_emm_data.non_current->ul_count));
} }
} }
...@@ -369,7 +372,7 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia, ...@@ -369,7 +372,7 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia,
"KSI = %d", ksi); "KSI = %d", ksi);
/* Get the UE context */ /* Get the UE context */
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
if (ueid > 0) { if (ueid > 0) {
...@@ -396,15 +399,14 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia, ...@@ -396,15 +399,14 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia,
/* Set new security context indicator */ /* Set new security context indicator */
security_context_is_new = TRUE; security_context_is_new = TRUE;
} }
} } else {
else {
LOG_TRACE(WARNING, "EMM-PROC - No EPS security context exists"); LOG_TRACE(WARNING, "EMM-PROC - No EPS security context exists");
LOG_FUNC_RETURN (RETURNerror); LOG_FUNC_RETURN (RETURNerror);
} }
/* Allocate parameters of the retransmission timer callback */ /* Allocate parameters of the retransmission timer callback */
security_data_t* data = security_data_t *data =
(security_data_t*)malloc(sizeof(security_data_t)); (security_data_t *)malloc(sizeof(security_data_t));
if (data != NULL) { if (data != NULL) {
/* Setup ongoing EMM procedure callback functions */ /* Setup ongoing EMM procedure callback functions */
...@@ -467,7 +469,7 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia, ...@@ -467,7 +469,7 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia,
***************************************************************************/ ***************************************************************************/
int emm_proc_security_mode_complete(unsigned int ueid) int emm_proc_security_mode_complete(unsigned int ueid)
{ {
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
int rc = RETURNerror; int rc = RETURNerror;
emm_sap_t emm_sap; emm_sap_t emm_sap;
...@@ -481,8 +483,10 @@ int emm_proc_security_mode_complete(unsigned int ueid) ...@@ -481,8 +483,10 @@ int emm_proc_security_mode_complete(unsigned int ueid)
T3460.id = nas_timer_stop(T3460.id); T3460.id = nas_timer_stop(T3460.id);
/* Release retransmission timer paramaters */ /* Release retransmission timer paramaters */
security_data_t* data = (security_data_t*)(emm_proc_common_get_args(ueid)); security_data_t *data = (security_data_t *)(emm_proc_common_get_args(ueid));
if (data) free(data); if (data) {
free(data);
}
/* Get the UE context */ /* Get the UE context */
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
...@@ -502,8 +506,7 @@ int emm_proc_security_mode_complete(unsigned int ueid) ...@@ -502,8 +506,7 @@ int emm_proc_security_mode_complete(unsigned int ueid)
emm_sap.primitive = EMMREG_COMMON_PROC_CNF; emm_sap.primitive = EMMREG_COMMON_PROC_CNF;
emm_sap.u.emm_reg.ueid = ueid; emm_sap.u.emm_reg.ueid = ueid;
emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached; emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached;
} } else {
else {
LOG_TRACE(ERROR, "EMM-PROC - No EPS security context exists"); LOG_TRACE(ERROR, "EMM-PROC - No EPS security context exists");
/* /*
* Notify EMM that the authentication procedure failed * Notify EMM that the authentication procedure failed
...@@ -543,7 +546,7 @@ int emm_proc_security_mode_complete(unsigned int ueid) ...@@ -543,7 +546,7 @@ int emm_proc_security_mode_complete(unsigned int ueid)
***************************************************************************/ ***************************************************************************/
int emm_proc_security_mode_reject(unsigned int ueid) int emm_proc_security_mode_reject(unsigned int ueid)
{ {
emm_data_context_t* emm_ctx = NULL; emm_data_context_t *emm_ctx = NULL;
int rc = RETURNerror; int rc = RETURNerror;
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -556,8 +559,10 @@ int emm_proc_security_mode_reject(unsigned int ueid) ...@@ -556,8 +559,10 @@ int emm_proc_security_mode_reject(unsigned int ueid)
T3460.id = nas_timer_stop(T3460.id); T3460.id = nas_timer_stop(T3460.id);
/* Release retransmission timer paramaters */ /* Release retransmission timer paramaters */
security_data_t* data = (security_data_t*)(emm_proc_common_get_args(ueid)); security_data_t *data = (security_data_t *)(emm_proc_common_get_args(ueid));
if (data) free(data); if (data) {
free(data);
}
/* Get the UE context */ /* Get the UE context */
#if defined(EPC_BUILD) #if defined(EPC_BUILD)
...@@ -617,17 +622,23 @@ int emm_proc_security_mode_reject(unsigned int ueid) ...@@ -617,17 +622,23 @@ int emm_proc_security_mode_reject(unsigned int ueid)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void _security_release(emm_security_context_t* ctx) static void _security_release(emm_security_context_t *ctx)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
if (ctx) { if (ctx) {
/* Release Kasme security key */ /* Release Kasme security key */
if (ctx->kasme.value) free(ctx->kasme.value); if (ctx->kasme.value) {
free(ctx->kasme.value);
}
/* Release NAS cyphering key */ /* Release NAS cyphering key */
if (ctx->knas_enc.value) free(ctx->knas_enc.value); if (ctx->knas_enc.value) {
free(ctx->knas_enc.value);
}
/* Release NAS integrity key */ /* Release NAS integrity key */
if (ctx->knas_int.value) free(ctx->knas_int.value); if (ctx->knas_int.value) {
free(ctx->knas_int.value);
}
/* Release the NAS security context */ /* Release the NAS security context */
free(ctx); free(ctx);
} }
...@@ -653,7 +664,7 @@ static void _security_release(emm_security_context_t* ctx) ...@@ -653,7 +664,7 @@ static void _security_release(emm_security_context_t* ctx)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _security_knas_enc(const OctetString* kasme, OctetString* knas_enc, static int _security_knas_enc(const OctetString *kasme, OctetString *knas_enc,
UInt8_t eea) UInt8_t eea)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -678,7 +689,7 @@ static int _security_knas_enc(const OctetString* kasme, OctetString* knas_enc, ...@@ -678,7 +689,7 @@ static int _security_knas_enc(const OctetString* kasme, OctetString* knas_enc,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _security_knas_int(const OctetString* kasme, OctetString* knas_int, static int _security_knas_int(const OctetString *kasme, OctetString *knas_int,
UInt8_t eia) UInt8_t eia)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -703,7 +714,7 @@ static int _security_knas_int(const OctetString* kasme, OctetString* knas_int, ...@@ -703,7 +714,7 @@ static int _security_knas_int(const OctetString* kasme, OctetString* knas_int,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _security_kenb(const OctetString* kasme, OctetString* kenb, static int _security_kenb(const OctetString *kasme, OctetString *kenb,
UInt32_t count) UInt32_t count)
{ {
/* Compute the KDF input parameter /* Compute the KDF input parameter
...@@ -713,8 +724,10 @@ static int _security_kenb(const OctetString* kasme, OctetString* kenb, ...@@ -713,8 +724,10 @@ static int _security_kenb(const OctetString* kasme, OctetString* kenb,
UInt16_t length = 4; UInt16_t length = 4;
int offset = 0; int offset = 0;
input[offset] = 0x11; offset += 1; input[offset] = 0x11;
input[offset] = count; offset += length; offset += 1;
input[offset] = count;
offset += length;
input[offset] = length; input[offset] = length;
/* TODO !!! Compute the derived key */ /* TODO !!! Compute the derived key */
...@@ -742,7 +755,7 @@ static int _security_kenb(const OctetString* kasme, OctetString* kenb, ...@@ -742,7 +755,7 @@ static int _security_kenb(const OctetString* kasme, OctetString* kenb,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _security_kdf(const OctetString* kasme, OctetString* key, static int _security_kdf(const OctetString *kasme, OctetString *key,
UInt8_t algo_dist, UInt8_t algo_id) UInt8_t algo_dist, UInt8_t algo_id)
{ {
/* Compute the KDF input parameter /* Compute the KDF input parameter
...@@ -754,10 +767,14 @@ static int _security_kdf(const OctetString* kasme, OctetString* key, ...@@ -754,10 +767,14 @@ static int _security_kdf(const OctetString* kasme, OctetString* key,
int offset = 0; int offset = 0;
int size_of_length = sizeof(length); int size_of_length = sizeof(length);
input[offset] = 0x15; offset += 1; input[offset] = 0x15;
input[offset] = algo_dist; offset += length; offset += 1;
input[offset] = length; offset += size_of_length; input[offset] = algo_dist;
input[offset] = algo_id; offset += length; offset += length;
input[offset] = length;
offset += size_of_length;
input[offset] = algo_id;
offset += length;
input[offset] = length; input[offset] = length;
/* TODO !!! Compute the derived key */ /* TODO !!! Compute the derived key */
...@@ -793,13 +810,13 @@ static int _security_kdf(const OctetString* kasme, OctetString* key, ...@@ -793,13 +810,13 @@ static int _security_kdf(const OctetString* kasme, OctetString* key,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static void* _security_t3460_handler(void* args) static void *_security_t3460_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc; int rc;
security_data_t* data = (security_data_t*)(args); security_data_t *data = (security_data_t *)(args);
/* Increment the retransmission counter */ /* Increment the retransmission counter */
data->retransmission_count += 1; data->retransmission_count += 1;
...@@ -810,8 +827,7 @@ static void* _security_t3460_handler(void* args) ...@@ -810,8 +827,7 @@ static void* _security_t3460_handler(void* args)
if (data->retransmission_count < SECURITY_COUNTER_MAX) { if (data->retransmission_count < SECURITY_COUNTER_MAX) {
/* Send security mode command message to the UE */ /* Send security mode command message to the UE */
rc = _security_request(data, FALSE); rc = _security_request(data, FALSE);
} } else {
else {
/* Set the failure notification indicator */ /* Set the failure notification indicator */
data->notify_failure = TRUE; data->notify_failure = TRUE;
/* Abort the security mode control procedure */ /* Abort the security mode control procedure */
...@@ -843,7 +859,7 @@ static void* _security_t3460_handler(void* args) ...@@ -843,7 +859,7 @@ static void* _security_t3460_handler(void* args)
** Others: T3460 ** ** Others: T3460 **
** ** ** **
***************************************************************************/ ***************************************************************************/
int _security_request(security_data_t* data, int is_new) int _security_request(security_data_t *data, int is_new)
{ {
struct emm_data_context_s *emm_ctx = NULL; struct emm_data_context_s *emm_ctx = NULL;
...@@ -909,16 +925,15 @@ int _security_request(security_data_t* data, int is_new) ...@@ -909,16 +925,15 @@ int _security_request(security_data_t* data, int is_new)
** Others: T3460 ** ** Others: T3460 **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _security_abort(void* args) static int _security_abort(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int rc = RETURNerror; int rc = RETURNerror;
security_data_t* data = (security_data_t*)(args); security_data_t *data = (security_data_t *)(args);
if (data) if (data) {
{
unsigned int ueid = data->ueid; unsigned int ueid = data->ueid;
int notify_failure = data->notify_failure; int notify_failure = data->notify_failure;
......
...@@ -53,7 +53,7 @@ Description Defines the service request EMM procedure executed by the ...@@ -53,7 +53,7 @@ Description Defines the service request EMM procedure executed by the
/* /*
* Timer handlers * Timer handlers
*/ */
void* _emm_service_t3417_handler(void*); void *_emm_service_t3417_handler(void *);
#endif // NAS_UE #endif // NAS_UE
/* /*
...@@ -95,7 +95,7 @@ void* _emm_service_t3417_handler(void*); ...@@ -95,7 +95,7 @@ void* _emm_service_t3417_handler(void*);
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
void* _emm_service_t3417_handler(void* args) void *_emm_service_t3417_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
......
...@@ -50,7 +50,7 @@ Description Defines the tracking area update EMM procedure executed by the ...@@ -50,7 +50,7 @@ Description Defines the tracking area update EMM procedure executed by the
/* /*
* Timer handlers * Timer handlers
*/ */
void* _emm_tau_t3430_handler(void*); void *_emm_tau_t3430_handler(void *);
#endif // NAS_UE #endif // NAS_UE
/* /*
...@@ -92,7 +92,7 @@ void* _emm_tau_t3430_handler(void*); ...@@ -92,7 +92,7 @@ void* _emm_tau_t3430_handler(void*);
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
void* _emm_tau_t3430_handler(void* args) void *_emm_tau_t3430_handler(void *args)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
......
...@@ -302,8 +302,8 @@ typedef struct { ...@@ -302,8 +302,8 @@ typedef struct {
* EPS NAS security context * EPS NAS security context
* ------------------------ * ------------------------
*/ */
emm_security_context_t* security; /* current security context */ emm_security_context_t *security; /* current security context */
emm_security_context_t* non_current; /* non-current security context */ emm_security_context_t *non_current; /* non-current security context */
} emm_data_t; } emm_data_t;
...@@ -325,11 +325,11 @@ typedef struct emm_data_context_s { ...@@ -325,11 +325,11 @@ typedef struct emm_data_context_s {
int is_attached; /* Attachment indicator */ int is_attached; /* Attachment indicator */
int is_emergency; /* Emergency bearer services indicator */ int is_emergency; /* Emergency bearer services indicator */
imsi_t* imsi; /* The IMSI provided by the UE or the MME */ imsi_t *imsi; /* The IMSI provided by the UE or the MME */
imei_t* imei; /* The IMEI provided by the UE */ imei_t *imei; /* The IMEI provided by the UE */
int guti_is_new; /* New GUTI indicator */ int guti_is_new; /* New GUTI indicator */
GUTI_t* guti; /* The GUTI assigned to the UE */ GUTI_t *guti; /* The GUTI assigned to the UE */
GUTI_t* old_guti; /* The old GUTI */ GUTI_t *old_guti; /* The old GUTI */
int n_tacs; /* Number of concecutive tracking areas the UE is int n_tacs; /* Number of concecutive tracking areas the UE is
* registered to */ * registered to */
tac_t tac; /* Code of the first tracking area the UE is tac_t tac; /* Code of the first tracking area the UE is
...@@ -339,7 +339,7 @@ typedef struct emm_data_context_s { ...@@ -339,7 +339,7 @@ typedef struct emm_data_context_s {
int eea; /* EPS encryption algorithms supported by the UE */ int eea; /* EPS encryption algorithms supported by the UE */
int eia; /* EPS integrity algorithms supported by the UE */ int eia; /* EPS integrity algorithms supported by the UE */
auth_vector_t vector; /* EPS authentication vector */ auth_vector_t vector; /* EPS authentication vector */
emm_security_context_t* security; /* Current EPS NAS security context */ emm_security_context_t *security; /* Current EPS NAS security context */
OctetString esm_msg; /* ESM message contained within the initial request */ OctetString esm_msg; /* ESM message contained within the initial request */
int emm_cause; /* EMM failure cause code */ int emm_cause; /* EMM failure cause code */
...@@ -369,14 +369,14 @@ typedef struct { ...@@ -369,14 +369,14 @@ typedef struct {
RB_HEAD(emm_data_context_map, emm_data_context_s) ctx_map; RB_HEAD(emm_data_context_map, emm_data_context_s) ctx_map;
# else # else
# define EMM_DATA_NB_UE_MAX (MME_API_NB_UE_MAX + 1) # define EMM_DATA_NB_UE_MAX (MME_API_NB_UE_MAX + 1)
emm_data_context_t* ctx [EMM_DATA_NB_UE_MAX]; emm_data_context_t *ctx [EMM_DATA_NB_UE_MAX];
# endif # endif
} emm_data_t; } emm_data_t;
struct emm_data_context_s *emm_data_context_get( struct emm_data_context_s *emm_data_context_get(
emm_data_t *_emm_data, unsigned int _ueid); emm_data_t *_emm_data, unsigned int _ueid);
struct emm_data_context_s * emm_data_context_remove( struct emm_data_context_s *emm_data_context_remove(
emm_data_t *_emm_data, struct emm_data_context_s *elm); emm_data_t *_emm_data, struct emm_data_context_s *elm);
void emm_data_context_add(emm_data_t *emm_data, struct emm_data_context_s *elm); void emm_data_context_add(emm_data_t *emm_data, struct emm_data_context_s *elm);
......
...@@ -45,7 +45,7 @@ struct emm_data_context_s *emm_data_context_get( ...@@ -45,7 +45,7 @@ struct emm_data_context_s *emm_data_context_get(
return RB_FIND(emm_data_context_map, &emm_data->ctx_map, &reference); return RB_FIND(emm_data_context_map, &emm_data->ctx_map, &reference);
} }
struct emm_data_context_s * emm_data_context_remove( struct emm_data_context_s *emm_data_context_remove(
emm_data_t *emm_data, struct emm_data_context_s *elm) emm_data_t *emm_data, struct emm_data_context_s *elm)
{ {
return RB_REMOVE(emm_data_context_map, &emm_data->ctx_map, elm); return RB_REMOVE(emm_data_context_map, &emm_data->ctx_map, elm);
......
...@@ -42,14 +42,14 @@ Description Defines the EPS Mobility Management procedure call manager, ...@@ -42,14 +42,14 @@ Description Defines the EPS Mobility Management procedure call manager,
/****************************************************************************/ /****************************************************************************/
#ifdef NAS_UE #ifdef NAS_UE
static int _emm_main_get_imei(imei_t* imei, const char* imei_str); static int _emm_main_get_imei(imei_t *imei, const char *imei_str);
static int _emm_main_imsi_cmp(imsi_t* imsi1, imsi_t* imsi2); static int _emm_main_imsi_cmp(imsi_t *imsi1, imsi_t *imsi2);
static const char* _emm_main_get_plmn(const plmn_t* plmn, int index, static const char *_emm_main_get_plmn(const plmn_t *plmn, int index,
int format, size_t* size); int format, size_t *size);
static int _emm_main_get_plmn_index(const char* plmn, int format); static int _emm_main_get_plmn_index(const char *plmn, int format);
/* /*
* USIM application data * USIM application data
...@@ -85,14 +85,14 @@ static int _emm_main_callback(int); ...@@ -85,14 +85,14 @@ static int _emm_main_callback(int);
** Others: _emm_data ** ** Others: _emm_data **
** ** ** **
***************************************************************************/ ***************************************************************************/
void emm_main_initialize(emm_indication_callback_t cb, const char* imei) void emm_main_initialize(emm_indication_callback_t cb, const char *imei)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
/* USIM validity indicator */ /* USIM validity indicator */
_emm_data.usim_is_valid = FALSE; _emm_data.usim_is_valid = FALSE;
/* The IMEI read from the UE's non-volatile memory */ /* The IMEI read from the UE's non-volatile memory */
_emm_data.imei = (imei_t*)malloc(sizeof(imei_t)); _emm_data.imei = (imei_t *)malloc(sizeof(imei_t));
_emm_data.imei->length = _emm_main_get_imei(_emm_data.imei, imei); _emm_data.imei->length = _emm_main_get_imei(_emm_data.imei, imei);
/* The IMSI, valid only if USIM is present */ /* The IMSI, valid only if USIM is present */
_emm_data.imsi = NULL; _emm_data.imsi = NULL;
...@@ -149,9 +149,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -149,9 +149,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
if ( usim_api_read(&_usim_data) != RETURNok ) { if ( usim_api_read(&_usim_data) != RETURNok ) {
/* The USIM application may not be present or not valid */ /* The USIM application may not be present or not valid */
LOG_TRACE(WARNING, "EMM-MAIN - Failed to read USIM application data"); LOG_TRACE(WARNING, "EMM-MAIN - Failed to read USIM application data");
} } else {
else
{
int i; int i;
/* The USIM application is present and valid */ /* The USIM application is present and valid */
...@@ -205,8 +203,8 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -205,8 +203,8 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
if ( PLMN_IS_VALID(_usim_data.opl[i].plmn) ) { if ( PLMN_IS_VALID(_usim_data.opl[i].plmn) ) {
int pnn_id = _usim_data.opl[i].record_id; int pnn_id = _usim_data.opl[i].record_id;
_emm_data.opnn[i].plmn = &_usim_data.opl[i].plmn; _emm_data.opnn[i].plmn = &_usim_data.opl[i].plmn;
_emm_data.opnn[i].fullname = (char*)_usim_data.pnn[pnn_id].fullname.value; _emm_data.opnn[i].fullname = (char *)_usim_data.pnn[pnn_id].fullname.value;
_emm_data.opnn[i].shortname = (char*)_usim_data.pnn[pnn_id].shortname.value; _emm_data.opnn[i].shortname = (char *)_usim_data.pnn[pnn_id].shortname.value;
_emm_data.n_opnns += 1; _emm_data.n_opnns += 1;
} }
} }
...@@ -223,27 +221,30 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -223,27 +221,30 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
_emm_data.status = _usim_data.epsloci.status; _emm_data.status = _usim_data.epsloci.status;
/* Get NAS configuration parameters */ /* Get NAS configuration parameters */
_emm_data.NAS_SignallingPriority = _usim_data.nasconfig.NAS_SignallingPriority.value[0]; _emm_data.NAS_SignallingPriority =
_usim_data.nasconfig.NAS_SignallingPriority.value[0];
_emm_data.NMO_I_Behaviour = _usim_data.nasconfig.NMO_I_Behaviour.value[0]; _emm_data.NMO_I_Behaviour = _usim_data.nasconfig.NMO_I_Behaviour.value[0];
_emm_data.AttachWithImsi = _usim_data.nasconfig.AttachWithImsi.value[0]; _emm_data.AttachWithImsi = _usim_data.nasconfig.AttachWithImsi.value[0];
_emm_data.MinimumPeriodicSearchTimer = _usim_data.nasconfig.MinimumPeriodicSearchTimer.value[0]; _emm_data.MinimumPeriodicSearchTimer =
_emm_data.ExtendedAccessBarring = _usim_data.nasconfig.ExtendedAccessBarring.value[0]; _usim_data.nasconfig.MinimumPeriodicSearchTimer.value[0];
_emm_data.Timer_T3245_Behaviour = _usim_data.nasconfig.Timer_T3245_Behaviour.value[0]; _emm_data.ExtendedAccessBarring =
_usim_data.nasconfig.ExtendedAccessBarring.value[0];
_emm_data.Timer_T3245_Behaviour =
_usim_data.nasconfig.Timer_T3245_Behaviour.value[0];
/* /*
* Get EPS NAS security context * Get EPS NAS security context
*/ */
/* Create NAS security context */ /* Create NAS security context */
_emm_data.security = _emm_data.security =
(emm_security_context_t*)malloc(sizeof(emm_security_context_t)); (emm_security_context_t *)malloc(sizeof(emm_security_context_t));
if (_emm_data.security != NULL) { if (_emm_data.security != NULL) {
memset(_emm_data.security, 0, sizeof(emm_security_context_t)); memset(_emm_data.security, 0, sizeof(emm_security_context_t));
/* Type of security context */ /* Type of security context */
if (_usim_data.securityctx.KSIasme.value[0] != if (_usim_data.securityctx.KSIasme.value[0] !=
USIM_KSI_NOT_AVAILABLE) { USIM_KSI_NOT_AVAILABLE) {
_emm_data.security->type = EMM_KSI_NATIVE; _emm_data.security->type = EMM_KSI_NATIVE;
} } else {
else {
_emm_data.security->type = EMM_KSI_NOT_AVAILABLE; _emm_data.security->type = EMM_KSI_NOT_AVAILABLE;
} }
/* EPS key set identifier */ /* EPS key set identifier */
...@@ -252,7 +253,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -252,7 +253,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
_emm_data.security->kasme.length = _emm_data.security->kasme.length =
_usim_data.securityctx.Kasme.length; _usim_data.securityctx.Kasme.length;
_emm_data.security->kasme.value = _emm_data.security->kasme.value =
(uint8_t*)malloc(_emm_data.security->kasme.length); (uint8_t *)malloc(_emm_data.security->kasme.length);
if (_emm_data.security->kasme.value) { if (_emm_data.security->kasme.value) {
memcpy(_emm_data.security->kasme.value, memcpy(_emm_data.security->kasme.value,
_usim_data.securityctx.Kasme.value, _usim_data.securityctx.Kasme.value,
...@@ -277,8 +278,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -277,8 +278,7 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
_emm_data.security->capability.integrity = _emm_data.security->capability.integrity =
(_usim_data.securityctx.algorithmID.value[0] & 0xf); (_usim_data.securityctx.algorithmID.value[0] & 0xf);
/* NAS integrity and cyphering keys are not available */ /* NAS integrity and cyphering keys are not available */
} } else {
else {
LOG_TRACE(WARNING, LOG_TRACE(WARNING,
"EMM-PROC - Failed to create security context"); "EMM-PROC - Failed to create security context");
} }
...@@ -289,24 +289,39 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei) ...@@ -289,24 +289,39 @@ void emm_main_initialize(emm_indication_callback_t cb, const char* imei)
memset(&_emm_data.nvdata.rplmn, 0xFF, sizeof(plmn_t)); memset(&_emm_data.nvdata.rplmn, 0xFF, sizeof(plmn_t));
_emm_data.nvdata.eplmn.n_plmns = 0; _emm_data.nvdata.eplmn.n_plmns = 0;
/* Get EMM data pathname */ /* Get EMM data pathname */
char* path = memory_get_path(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME); char *path = memory_get_path(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME);
if (path == NULL) { if (path == NULL) {
LOG_TRACE(ERROR, "EMM-MAIN - Failed to get EMM data pathname"); LOG_TRACE(ERROR, "EMM-MAIN - Failed to get EMM data pathname");
} } else {
else {
/* Get EMM data stored in the non-volatile memory device */ /* Get EMM data stored in the non-volatile memory device */
int rc = memory_read(path, &_emm_data.nvdata, sizeof(emm_nvdata_t)); int rc = memory_read(path, &_emm_data.nvdata, sizeof(emm_nvdata_t));
if (rc != RETURNok) { if (rc != RETURNok) {
LOG_TRACE(ERROR, "EMM-MAIN - Failed to read %s", path); LOG_TRACE(ERROR, "EMM-MAIN - Failed to read %s", path);
} } else {
else {
/* Check the IMSI */ /* Check the IMSI */
LOG_TRACE(INFO, "EMM-MAIN - EMM data successfully read"); LOG_TRACE(INFO, "EMM-MAIN - EMM data successfully read");
_emm_data.imsi = &_usim_data.imsi; _emm_data.imsi = &_usim_data.imsi;
int imsi_ok = _emm_main_imsi_cmp(&_emm_data.nvdata.imsi, int imsi_ok = _emm_main_imsi_cmp(&_emm_data.nvdata.imsi,
&_usim_data.imsi); &_usim_data.imsi);
if (!imsi_ok) { if (!imsi_ok) {
LOG_TRACE(WARNING, "EMM-MAIN - IMSI checking failed"); LOG_TRACE(WARNING, "EMM-MAIN - IMSI checking failed nvram: "
"%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x, "
"usim: %02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
_emm_data.nvdata.imsi.u.value[0],
_emm_data.nvdata.imsi.u.value[1],
_emm_data.nvdata.imsi.u.value[2],
_emm_data.nvdata.imsi.u.value[3],
_emm_data.nvdata.imsi.u.value[4],
_emm_data.nvdata.imsi.u.value[5],
_emm_data.nvdata.imsi.u.value[6],
_emm_data.nvdata.imsi.u.value[7],
_usim_data.imsi.u.value[0],
_usim_data.imsi.u.value[1],
_usim_data.imsi.u.value[2],
_usim_data.imsi.u.value[3],
_usim_data.imsi.u.value[4],
_usim_data.imsi.u.value[5],
_usim_data.imsi.u.value[6], _usim_data.imsi.u.value[7]);
memset(&_emm_data.nvdata.rplmn, 0xFF, sizeof(plmn_t)); memset(&_emm_data.nvdata.rplmn, 0xFF, sizeof(plmn_t));
_emm_data.nvdata.eplmn.n_plmns = 0; _emm_data.nvdata.eplmn.n_plmns = 0;
} }
...@@ -421,13 +436,11 @@ void emm_main_cleanup(void) ...@@ -421,13 +436,11 @@ void emm_main_cleanup(void)
#if 0 #if 0
int i; int i;
/* Update the list of Forbidden PLMNs */ /* Update the list of Forbidden PLMNs */
for (i=0; (i < _emm_data.fplmn.n_plmns) && (i < USIM_FPLMN_MAX); i++) for (i=0; (i < _emm_data.fplmn.n_plmns) && (i < USIM_FPLMN_MAX); i++) {
{
_usim_data.fplmn[i] = _emm_data.fplmn.plmn[i]; _usim_data.fplmn[i] = _emm_data.fplmn.plmn[i];
} }
/* Update the list of Equivalent HPLMNs */ /* Update the list of Equivalent HPLMNs */
for (i=0; (i < _emm_data.ehplmn.n_plmns) && (i < USIM_EHPLMN_MAX); i++) for (i=0; (i < _emm_data.ehplmn.n_plmns) && (i < USIM_EHPLMN_MAX); i++) {
{
_usim_data.ehplmn[i] = _emm_data.ehplmn.plmn[i]; _usim_data.ehplmn[i] = _emm_data.ehplmn.plmn[i];
} }
/* Update the GUTI */ /* Update the GUTI */
...@@ -441,8 +454,7 @@ void emm_main_cleanup(void) ...@@ -441,8 +454,7 @@ void emm_main_cleanup(void)
/* Update the EPS location information */ /* Update the EPS location information */
_usim_data.epsloci.status = _emm_data.status; _usim_data.epsloci.status = _emm_data.status;
if (_emm_data.security && (_emm_data.security->type == EMM_KSI_NATIVE)) if (_emm_data.security && (_emm_data.security->type == EMM_KSI_NATIVE)) {
{
/* TODO: Update the EPS security context parameters from the full /* TODO: Update the EPS security context parameters from the full
* native EPS security context */ * native EPS security context */
} }
...@@ -464,11 +476,10 @@ void emm_main_cleanup(void) ...@@ -464,11 +476,10 @@ void emm_main_cleanup(void)
* - Registered PLMN * - Registered PLMN
* - List of equivalent PLMNs * - List of equivalent PLMNs
*/ */
char* path = memory_get_path(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME); char *path = memory_get_path(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME);
if (path == NULL) { if (path == NULL) {
LOG_TRACE(ERROR, "EMM-MAIN - Failed to get EMM data pathname"); LOG_TRACE(ERROR, "EMM-MAIN - Failed to get EMM data pathname");
} } else {
else {
int rc = memory_write(path, &_emm_data.nvdata, sizeof(emm_nvdata_t)); int rc = memory_write(path, &_emm_data.nvdata, sizeof(emm_nvdata_t));
if (rc != RETURNok) { if (rc != RETURNok) {
LOG_TRACE(ERROR, "EMM-MAIN - Failed to write %s", path); LOG_TRACE(ERROR, "EMM-MAIN - Failed to write %s", path);
...@@ -481,10 +492,16 @@ void emm_main_cleanup(void) ...@@ -481,10 +492,16 @@ void emm_main_cleanup(void)
_emm_data.imei = NULL; _emm_data.imei = NULL;
} }
if (_emm_data.security) { if (_emm_data.security) {
emm_security_context_t* security = _emm_data.security; emm_security_context_t *security = _emm_data.security;
if (security->kasme.value) free(security->kasme.value); if (security->kasme.value) {
if (security->knas_enc.value) free(security->knas_enc.value); free(security->kasme.value);
if (security->knas_int.value) free(security->knas_int.value); }
if (security->knas_enc.value) {
free(security->knas_enc.value);
}
if (security->knas_int.value) {
free(security->knas_int.value);
}
free(_emm_data.security); free(_emm_data.security);
_emm_data.security = NULL; _emm_data.security = NULL;
} }
...@@ -509,7 +526,7 @@ void emm_main_cleanup(void) ...@@ -509,7 +526,7 @@ void emm_main_cleanup(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const imsi_t* emm_main_get_imsi(void) const imsi_t *emm_main_get_imsi(void)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
LOG_FUNC_RETURN (&_emm_data.nvdata.imsi); LOG_FUNC_RETURN (&_emm_data.nvdata.imsi);
...@@ -529,7 +546,7 @@ const imsi_t* emm_main_get_imsi(void) ...@@ -529,7 +546,7 @@ const imsi_t* emm_main_get_imsi(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const msisdn_t* emm_main_get_msisdn(void) const msisdn_t *emm_main_get_msisdn(void)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
LOG_FUNC_RETURN (&_usim_data.msisdn.number); LOG_FUNC_RETURN (&_usim_data.msisdn.number);
...@@ -557,31 +574,29 @@ const msisdn_t* emm_main_get_msisdn(void) ...@@ -557,31 +574,29 @@ const msisdn_t* emm_main_get_msisdn(void)
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_main_set_plmn_selection_mode(int mode, int format, int emm_main_set_plmn_selection_mode(int mode, int format,
const network_plmn_t* plmn, int rat) const network_plmn_t *plmn, int rat)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
int index; int index;
LOG_TRACE(INFO, "EMM-MAIN - PLMN selection: mode=%d, format=%d, plmn=%s, " LOG_TRACE(INFO, "EMM-MAIN - PLMN selection: mode=%d, format=%d, plmn=%s, "
"rat=%d", mode, format, (const char*)&plmn->id, rat); "rat=%d", mode, format, (const char *)&plmn->id, rat);
_emm_data.plmn_mode = mode; _emm_data.plmn_mode = mode;
if (mode != EMM_DATA_PLMN_AUTO) { if (mode != EMM_DATA_PLMN_AUTO) {
/* Get the index of the PLMN in the list of available PLMNs */ /* Get the index of the PLMN in the list of available PLMNs */
index = _emm_main_get_plmn_index((const char*)&plmn->id, format); index = _emm_main_get_plmn_index((const char *)&plmn->id, format);
if (index < 0) { if (index < 0) {
LOG_TRACE(WARNING, "EMM-MAIN - PLMN %s not available", LOG_TRACE(WARNING, "EMM-MAIN - PLMN %s not available",
(const char*)&plmn->id); (const char *)&plmn->id);
} } else {
else {
/* Update the manually selected network selection data */ /* Update the manually selected network selection data */
_emm_data.plmn_index = index; _emm_data.plmn_index = index;
_emm_data.plmn_rat = rat; _emm_data.plmn_rat = rat;
} }
} } else {
else {
/* /*
* Get the index of the last PLMN the UE already tried to automatically * Get the index of the last PLMN the UE already tried to automatically
* register to when switched on; the equivalent PLMNs list shall not be * register to when switched on; the equivalent PLMNs list shall not be
...@@ -628,7 +643,7 @@ int emm_main_get_plmn_selection_mode(void) ...@@ -628,7 +643,7 @@ int emm_main_get_plmn_selection_mode(void)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int emm_main_get_plmn_list(const char** plist) int emm_main_get_plmn_list(const char **plist)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -655,7 +670,7 @@ int emm_main_get_plmn_list(const char** plist) ...@@ -655,7 +670,7 @@ int emm_main_get_plmn_list(const char** plist)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format) const char *emm_main_get_selected_plmn(network_plmn_t *plmn, int format)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -665,10 +680,10 @@ const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format) ...@@ -665,10 +680,10 @@ const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format)
*/ */
int index = IdleMode_get_splmn_index(); int index = IdleMode_get_splmn_index();
if ( !(index < 0) ) { if ( !(index < 0) ) {
const char* name = _emm_main_get_plmn(&_emm_data.splmn, index, const char *name = _emm_main_get_plmn(&_emm_data.splmn, index,
format, &size); format, &size);
if (size > 0) { if (size > 0) {
LOG_FUNC_RETURN ((char*) memcpy(&plmn->id, name, size)); LOG_FUNC_RETURN ((char *) memcpy(&plmn->id, name, size));
} }
} }
...@@ -692,7 +707,7 @@ const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format) ...@@ -692,7 +707,7 @@ const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
const char* emm_main_get_registered_plmn(network_plmn_t* plmn, int format) const char *emm_main_get_registered_plmn(network_plmn_t *plmn, int format)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
...@@ -703,10 +718,10 @@ const char* emm_main_get_registered_plmn(network_plmn_t* plmn, int format) ...@@ -703,10 +718,10 @@ const char* emm_main_get_registered_plmn(network_plmn_t* plmn, int format)
*/ */
int index = IdleMode_get_rplmn_index(); int index = IdleMode_get_rplmn_index();
if ( !(index < 0) ) { if ( !(index < 0) ) {
const char* name = _emm_main_get_plmn(&_emm_data.nvdata.rplmn, const char *name = _emm_main_get_plmn(&_emm_data.nvdata.rplmn,
index, format, &size); index, format, &size);
if (size > 0) { if (size > 0) {
LOG_FUNC_RETURN ((char*) memcpy(&plmn->id, name, size)); LOG_FUNC_RETURN ((char *) memcpy(&plmn->id, name, size));
} }
} }
...@@ -895,7 +910,7 @@ static int _emm_main_callback(int size) ...@@ -895,7 +910,7 @@ static int _emm_main_callback(int size)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_main_get_imei(imei_t* imei, const char* imei_str) static int _emm_main_get_imei(imei_t *imei, const char *imei_str)
{ {
int len = strlen(imei_str); int len = strlen(imei_str);
if (len % 2) { if (len % 2) {
...@@ -937,7 +952,7 @@ static int _emm_main_get_imei(imei_t* imei, const char* imei_str) ...@@ -937,7 +952,7 @@ static int _emm_main_get_imei(imei_t* imei, const char* imei_str)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_main_imsi_cmp(imsi_t* imsi1, imsi_t* imsi2) static int _emm_main_imsi_cmp(imsi_t *imsi1, imsi_t *imsi2)
{ {
if (imsi1->length != imsi2->length) { if (imsi1->length != imsi2->length) {
return FALSE; return FALSE;
...@@ -969,12 +984,11 @@ static int _emm_main_imsi_cmp(imsi_t* imsi1, imsi_t* imsi2) ...@@ -969,12 +984,11 @@ static int _emm_main_imsi_cmp(imsi_t* imsi1, imsi_t* imsi2)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static const char* _emm_main_get_plmn(const plmn_t* plmn, int index, static const char *_emm_main_get_plmn(const plmn_t *plmn, int index,
int format, size_t* size) int format, size_t *size)
{ {
if ( PLMN_IS_VALID(*plmn) ) { if ( PLMN_IS_VALID(*plmn) ) {
switch (format) switch (format) {
{
case NET_FORMAT_LONG: case NET_FORMAT_LONG:
/* Get the long alpha-numeric representation of the PLMN */ /* Get the long alpha-numeric representation of the PLMN */
return IdleMode_get_plmn_fullname(plmn, index, size); return IdleMode_get_plmn_fullname(plmn, index, size);
...@@ -1019,11 +1033,10 @@ static const char* _emm_main_get_plmn(const plmn_t* plmn, int index, ...@@ -1019,11 +1033,10 @@ static const char* _emm_main_get_plmn(const plmn_t* plmn, int index,
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
static int _emm_main_get_plmn_index(const char* plmn, int format) static int _emm_main_get_plmn_index(const char *plmn, int format)
{ {
int index = -1; int index = -1;
switch (format) switch (format) {
{
case NET_FORMAT_LONG: case NET_FORMAT_LONG:
/* Get the index of the long alpha-numeric PLMN identifier */ /* Get the index of the long alpha-numeric PLMN identifier */
index = IdleMode_get_plmn_fullname_index(plmn); index = IdleMode_get_plmn_fullname_index(plmn);
......
...@@ -41,7 +41,7 @@ Description Defines the EPS Mobility Management procedure call manager, ...@@ -41,7 +41,7 @@ Description Defines the EPS Mobility Management procedure call manager,
/****************************************************************************/ /****************************************************************************/
#ifdef NAS_UE #ifdef NAS_UE
void emm_main_initialize(emm_indication_callback_t cb, const char* imei); void emm_main_initialize(emm_indication_callback_t cb, const char *imei);
#endif #endif
#ifdef NAS_MME #ifdef NAS_MME
void emm_main_initialize(void); void emm_main_initialize(void);
...@@ -51,24 +51,24 @@ void emm_main_cleanup(void); ...@@ -51,24 +51,24 @@ void emm_main_cleanup(void);
#ifdef NAS_UE #ifdef NAS_UE
/* User's getter of UE's identity */ /* User's getter of UE's identity */
const imsi_t* emm_main_get_imsi(void); const imsi_t *emm_main_get_imsi(void);
/* User's getter of the subscriber dialing number */ /* User's getter of the subscriber dialing number */
const msisdn_t* emm_main_get_msisdn(void); const msisdn_t *emm_main_get_msisdn(void);
/* User's getter/setter for network selection */ /* User's getter/setter for network selection */
int emm_main_set_plmn_selection_mode(int mode, int format, int emm_main_set_plmn_selection_mode(int mode, int format,
const network_plmn_t* plmn, int rat); const network_plmn_t *plmn, int rat);
int emm_main_get_plmn_selection_mode(void); int emm_main_get_plmn_selection_mode(void);
int emm_main_get_plmn_list(const char** plist); int emm_main_get_plmn_list(const char **plist);
const char* emm_main_get_selected_plmn(network_plmn_t* plmn, int format); const char *emm_main_get_selected_plmn(network_plmn_t *plmn, int format);
/* User's getter for network registration */ /* User's getter for network registration */
Stat_t emm_main_get_plmn_status(void); Stat_t emm_main_get_plmn_status(void);
tac_t emm_main_get_plmn_tac(void); tac_t emm_main_get_plmn_tac(void);
ci_t emm_main_get_plmn_ci(void); ci_t emm_main_get_plmn_ci(void);
AcT_t emm_main_get_plmn_rat(void); AcT_t emm_main_get_plmn_rat(void);
const char* emm_main_get_registered_plmn(network_plmn_t* plmn, int format); const char *emm_main_get_registered_plmn(network_plmn_t *plmn, int format);
/* User's getter for network attachment */ /* User's getter for network attachment */
int emm_main_is_attached(void); int emm_main_is_attached(void);
......
...@@ -93,7 +93,7 @@ int emm_proc_status(unsigned int ueid, int emm_cause); ...@@ -93,7 +93,7 @@ int emm_proc_status(unsigned int ueid, int emm_cause);
int emm_proc_lowerlayer_initialize(lowerlayer_success_callback_t success, int emm_proc_lowerlayer_initialize(lowerlayer_success_callback_t success,
lowerlayer_failure_callback_t failure, lowerlayer_failure_callback_t failure,
lowerlayer_release_callback_t release, lowerlayer_release_callback_t release,
void* args); void *args);
int emm_proc_lowerlayer_success(void); int emm_proc_lowerlayer_success(void);
int emm_proc_lowerlayer_failure(int is_initial); int emm_proc_lowerlayer_failure(int is_initial);
int emm_proc_lowerlayer_release(void); int emm_proc_lowerlayer_release(void);
...@@ -117,12 +117,14 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat); ...@@ -117,12 +117,14 @@ int emm_proc_plmn_selection_end(int found, tac_t tac, ci_t ci, AcT_t rat);
*/ */
#ifdef NAS_UE #ifdef NAS_UE
int emm_proc_attach(emm_proc_attach_type_t type); int emm_proc_attach(emm_proc_attach_type_t type);
int emm_proc_attach_request(void* args); int emm_proc_attach_request(void *args);
int emm_proc_attach_accept(long T3412, long T3402, long T3423, int n_tais, tai_t* tai, GUTI_t* guti, int n_eplmns, plmn_t* eplmn, const OctetString* esm_msg); int emm_proc_attach_accept(long T3412, long T3402, long T3423, int n_tais,
int emm_proc_attach_reject(int emm_cause, const OctetString* esm_msg); tai_t *tai, GUTI_t *guti, int n_eplmns, plmn_t *eplmn,
int emm_proc_attach_complete(void* args); const OctetString *esm_msg);
int emm_proc_attach_failure(int is_initial, void* args); int emm_proc_attach_reject(int emm_cause, const OctetString *esm_msg);
int emm_proc_attach_release(void* args); int emm_proc_attach_complete(void *args);
int emm_proc_attach_failure(int is_initial, void *args);
int emm_proc_attach_release(void *args);
int emm_proc_attach_restart(void); int emm_proc_attach_restart(void);
int emm_proc_attach_set_emergency(void); int emm_proc_attach_set_emergency(void);
...@@ -130,9 +132,11 @@ int emm_proc_attach_set_detach(void); ...@@ -130,9 +132,11 @@ int emm_proc_attach_set_detach(void);
#endif #endif
#ifdef NAS_MME #ifdef NAS_MME
int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type, int native_ksi, int ksi, int native_guti, GUTI_t* guti, imsi_t* imsi, imei_t* imei, tai_t* tai, int eea, int eia, const OctetString* esm_msg); int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
int native_ksi, int ksi, int native_guti, GUTI_t *guti, imsi_t *imsi,
imei_t *imei, tai_t *tai, int eea, int eia, const OctetString *esm_msg);
int emm_proc_attach_reject(unsigned int ueid, int emm_cause); int emm_proc_attach_reject(unsigned int ueid, int emm_cause);
int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg); int emm_proc_attach_complete(unsigned int ueid, const OctetString *esm_msg);
#endif #endif
/* /*
...@@ -142,15 +146,17 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg); ...@@ -142,15 +146,17 @@ int emm_proc_attach_complete(unsigned int ueid, const OctetString* esm_msg);
*/ */
#ifdef NAS_UE #ifdef NAS_UE
int emm_proc_detach(emm_proc_detach_type_t type, int switch_off); int emm_proc_detach(emm_proc_detach_type_t type, int switch_off);
int emm_proc_detach_request(void* args); int emm_proc_detach_request(void *args);
int emm_proc_detach_accept(void); int emm_proc_detach_accept(void);
int emm_proc_detach_failure(int is_initial, void* args); int emm_proc_detach_failure(int is_initial, void *args);
int emm_proc_detach_release(void* args); int emm_proc_detach_release(void *args);
#endif #endif
#ifdef NAS_MME #ifdef NAS_MME
int emm_proc_detach(unsigned int ueid, emm_proc_detach_type_t type); int emm_proc_detach(unsigned int ueid, emm_proc_detach_type_t type);
int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type, int switch_off, int native_ksi, int ksi, GUTI_t* guti, imsi_t* imsi, imei_t* imei); int emm_proc_detach_request(unsigned int ueid, emm_proc_detach_type_t type,
int switch_off, int native_ksi, int ksi, GUTI_t *guti, imsi_t *imsi,
imei_t *imei);
#endif #endif
/* /*
...@@ -169,7 +175,8 @@ int emm_proc_identification(unsigned int ueid, ...@@ -169,7 +175,8 @@ int emm_proc_identification(unsigned int ueid,
emm_common_success_callback_t success, emm_common_success_callback_t success,
emm_common_reject_callback_t reject, emm_common_reject_callback_t reject,
emm_common_failure_callback_t failure); emm_common_failure_callback_t failure);
int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, const imei_t* imei, UInt32_t* tmsi); int emm_proc_identification_complete(unsigned int ueid, const imsi_t *imsi,
const imei_t *imei, UInt32_t *tmsi);
#endif #endif
/* /*
...@@ -178,18 +185,20 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, cons ...@@ -178,18 +185,20 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t* imsi, cons
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#ifdef NAS_UE #ifdef NAS_UE
int emm_proc_authentication_request(int native_ksi, int ksi, const OctetString* rand, const OctetString* autn); int emm_proc_authentication_request(int native_ksi, int ksi,
const OctetString *rand, const OctetString *autn);
int emm_proc_authentication_reject(void); int emm_proc_authentication_reject(void);
int emm_proc_authentication_delete(void); int emm_proc_authentication_delete(void);
#endif #endif
#ifdef NAS_MME #ifdef NAS_MME
int emm_proc_authentication(unsigned int ueid, int ksi, int emm_proc_authentication(unsigned int ueid, int ksi,
const OctetString* rand, const OctetString* autn, const OctetString *rand, const OctetString *autn,
emm_common_success_callback_t success, emm_common_success_callback_t success,
emm_common_reject_callback_t reject, emm_common_reject_callback_t reject,
emm_common_failure_callback_t failure); emm_common_failure_callback_t failure);
int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, const OctetString* res); int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
const OctetString *res);
#endif #endif
/* /*
...@@ -198,7 +207,8 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, const Oct ...@@ -198,7 +207,8 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause, const Oct
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
#ifdef NAS_UE #ifdef NAS_UE
int emm_proc_security_mode_command(int native_ksi, int ksi, int seea, int seia, int reea, int reia); int emm_proc_security_mode_command(int native_ksi, int ksi, int seea, int seia,
int reea, int reia);
#endif #endif
#ifdef NAS_MME #ifdef NAS_MME
......
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