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