emm_main.c 47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
gauthier's avatar
 
gauthier committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

/*****************************************************************************
Source      emm_main.c

Version     0.1

Date        2012/10/10

Product     NAS stack

Subsystem   EPS Mobility Management

Author      Frederic Maurel

Description Defines the EPS Mobility Management procedure call manager,
        the main entry point for elementary EMM processing.

*****************************************************************************/

#include "emm_main.h"
#include "nas_log.h"
42
#include "utils.h"
gauthier's avatar
 
gauthier committed
43
#include "emmData.h"
44
#include "MobileIdentity.h"
45
#include "emm_proc_defs.h"
gauthier's avatar
 
gauthier committed
46 47 48 49 50 51 52 53 54 55 56 57

#include "memory.h"
#include "usim_api.h"
#include "IdleMode.h"

#include <string.h> // memset, memcpy, strlen
#include <stdio.h>  // sprintf
#include <stdlib.h> // malloc, free

/****************************************************************************/
/****************  E X T E R N A L    D E F I N I T I O N S  ****************/
/****************************************************************************/
58
extern uint8_t usim_test;
gauthier's avatar
 
gauthier committed
59 60 61 62 63 64 65 66 67

/****************************************************************************/
/*******************  L O C A L    D E F I N I T I O N S  *******************/
/****************************************************************************/

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);

68
static const char *_emm_main_get_plmn(emm_plmn_list_t *emm_plmn_list, const plmn_t *plmn, int index,
gauthier's avatar
 
gauthier committed
69 70
                                      int format, size_t *size);

71
static int _emm_main_get_plmn_index(emm_plmn_list_t *emm_plmn_list, const char *plmn, int format);
gauthier's avatar
 
gauthier committed
72 73 74 75 76 77

/*
 * Callback executed whenever a change in the network has to be notified
 * to the user application
 */
static emm_indication_callback_t _emm_main_user_callback;
78
static int _emm_main_callback(user_api_id_t *user_api_id, emm_data_t *emm_data, int size);
gauthier's avatar
 
gauthier committed
79 80 81 82 83

/****************************************************************************/
/******************  E X P O R T E D    F U N C T I O N S  ******************/
/****************************************************************************/

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  /*
   * Initialize EMM timers
   */
void _emm_timers_initialize(emm_timers_t *emm_timers) {
  emm_timers->T3410.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3410.sec = T3410_DEFAULT_VALUE;
  emm_timers->T3411.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3411.sec = T3411_DEFAULT_VALUE;
  emm_timers->T3402.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3402.sec = T3402_DEFAULT_VALUE;
  emm_timers->T3416.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3416.sec = T3416_DEFAULT_VALUE;
  emm_timers->T3417.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3417.sec = T3417_DEFAULT_VALUE;
  emm_timers->T3418.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3418.sec = T3418_DEFAULT_VALUE;
  emm_timers->T3420.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3420.sec = T3420_DEFAULT_VALUE;
  emm_timers->T3421.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3421.sec = T3421_DEFAULT_VALUE;
  emm_timers->T3423.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3423.sec = T3423_DEFAULT_VALUE;
  emm_timers->T3430.id = NAS_TIMER_INACTIVE_ID;
  emm_timers->T3430.sec = T3430_DEFAULT_VALUE;
}

110 111 112 113
void _emm_attach_initialize(emm_attach_data_t *emm_attach_data) {
  emm_attach_data->attempt_count = 0;
}

114 115 116 117 118 119
void _emm_detach_initialize(emm_detach_data_t *emm_detach) {
  emm_detach->count = 0;
  emm_detach->switch_off = FALSE;
  emm_detach->type = EMM_DETACH_TYPE_RESERVED;
}

gauthier's avatar
 
gauthier committed
120 121 122 123 124 125 126 127 128 129 130 131
/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_initialize()                                     **
 **                                                                        **
 ** Description: Initializes EMM internal data                             **
 **                                                                        **
 ** Inputs:  cb:        The user notification callback             **
 **      imei:      The IMEI read from the UE's non-volatile   **
 **             memory                                     **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    None                                       **
132
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
133 134
 **                                                                        **
 ***************************************************************************/
135
void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const char *imei)
gauthier's avatar
 
gauthier committed
136 137
{
  LOG_FUNC_IN;
138
  user->emm_data = calloc_or_fail(sizeof(emm_data_t));
gauthier's avatar
 
gauthier committed
139
  /* USIM validity indicator */
140
  user->emm_data->usim_is_valid = FALSE;
gauthier's avatar
 
gauthier committed
141
  /* The IMEI read from the UE's non-volatile memory  */
142 143
  user->emm_data->imei = (imei_t *)malloc(sizeof(imei_t));
  user->emm_data->imei->length = _emm_main_get_imei(user->emm_data->imei, imei);
gauthier's avatar
 
gauthier committed
144
  /* The IMSI, valid only if USIM is present */
145
  user->emm_data->imsi = NULL;
gauthier's avatar
 
gauthier committed
146
  /* EPS location information */
147 148 149
  user->emm_data->guti = NULL;
  user->emm_data->tai = NULL;
  user->emm_data->ltai.n_tais = 0;
gauthier's avatar
 
gauthier committed
150
  /* EPS Connection Management status */
151
  user->emm_data->ecm_status = ECM_IDLE;
gauthier's avatar
 
gauthier committed
152
  /* Network selection mode of operation */
153
  user->emm_data->plmn_mode = EMM_DATA_PLMN_AUTO;
gauthier's avatar
 
gauthier committed
154
  /* Index of the PLMN manually selected by the user */
155
  user->emm_data->plmn_index = -1;
gauthier's avatar
 
gauthier committed
156
  /* Selected Radio Access Technology */
157
  user->emm_data->plmn_rat = NET_ACCESS_UNAVAILABLE;
gauthier's avatar
 
gauthier committed
158
  /* Selected PLMN */
159 160 161
  memset(&user->emm_data->splmn, 0xFF, sizeof(plmn_t));
  user->emm_data->is_rplmn = FALSE;
  user->emm_data->is_eplmn = FALSE;
gauthier's avatar
 
gauthier committed
162
  /* Radio Access Technology of the serving cell */
163
  user->emm_data->rat = NET_ACCESS_UNAVAILABLE;
gauthier's avatar
 
gauthier committed
164
  /* Network registration status */
165 166 167
  user->emm_data->stat = NET_REG_STATE_OFF;
  user->emm_data->is_attached = FALSE;
  user->emm_data->is_emergency = FALSE;
gauthier's avatar
 
gauthier committed
168
  /* Location/Tracking area code */
169
  user->emm_data->tac = 0;  // two byte in hexadecimal format
gauthier's avatar
 
gauthier committed
170
  /* Identifier of the serving cell */
171
  user->emm_data->ci = 0;   // four byte in hexadecimal format
gauthier's avatar
 
gauthier committed
172
  /* List of operators present in the network */
173
  memset(user->emm_data->plist.buffer, 0, EMM_DATA_BUFFER_SIZE + 1);
gauthier's avatar
 
gauthier committed
174
  /* Home PLMN */
175
  memset(&user->emm_data->hplmn, 0xFF, sizeof(plmn_t));
gauthier's avatar
 
gauthier committed
176
  /* List of Forbidden PLMNs */
177
  user->emm_data->fplmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
178
  /* List of Forbidden PLMNs for GPRS service */
179
  user->emm_data->fplmn_gprs.n_plmns = 0;
gauthier's avatar
 
gauthier committed
180
  /* List of Equivalent HPLMNs */
181
  user->emm_data->ehplmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
182
  /* List of user controlled PLMNs */
183
  user->emm_data->plmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
184
  /* List of operator controlled PLMNs */
185
  user->emm_data->oplmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
186
  /* List of operator network name records */
187
  user->emm_data->n_opnns = 0;
gauthier's avatar
 
gauthier committed
188
  /* List of Forbidden Tracking Areas */
189
  user->emm_data->ftai.n_tais = 0;
gauthier's avatar
 
gauthier committed
190
  /* List of Forbidden Tracking Areas for roaming */
191
  user->emm_data->ftai_roaming.n_tais = 0;
gauthier's avatar
 
gauthier committed
192 193 194 195

  /*
   * Get USIM application data
   */
196
  if ( usim_api_read(user->usim_data_store, &user->usim_data) != RETURNok ) {
gauthier's avatar
 
gauthier committed
197 198 199 200 201 202 203
    /* The USIM application may not be present or not valid */
    LOG_TRACE(WARNING, "EMM-MAIN  - Failed to read USIM application data");
  } else {
    int i;

    /* The USIM application is present and valid */
    LOG_TRACE(INFO, "EMM-MAIN  - USIM application data successfully read");
204
    user->emm_data->usim_is_valid = TRUE;
gauthier's avatar
 
gauthier committed
205 206

    /* Get the Home PLMN derived from the IMSI */
207 208 209 210 211 212
    user->emm_data->hplmn.MCCdigit1 = user->usim_data.imsi.u.num.digit1;
    user->emm_data->hplmn.MCCdigit2 = user->usim_data.imsi.u.num.digit2;
    user->emm_data->hplmn.MCCdigit3 = user->usim_data.imsi.u.num.digit3;
    user->emm_data->hplmn.MNCdigit1 = user->usim_data.imsi.u.num.digit4;
    user->emm_data->hplmn.MNCdigit2 = user->usim_data.imsi.u.num.digit5;
    user->emm_data->hplmn.MNCdigit3 = user->usim_data.imsi.u.num.digit6;
gauthier's avatar
 
gauthier committed
213 214 215

    /* Get the list of forbidden PLMNs */
    for (i=0; (i < EMM_DATA_FPLMN_MAX) && (i < USIM_FPLMN_MAX); i++) {
216 217
      if ( PLMN_IS_VALID(user->usim_data.fplmn[i]) ) {
        user->emm_data->fplmn.plmn[i] = user->usim_data.fplmn[i];
218
        user->emm_data->fplmn.n_plmns += 1;
gauthier's avatar
 
gauthier committed
219 220 221 222 223
      }
    }

    /* Get the list of Equivalent HPLMNs */
    for (i=0; (i < EMM_DATA_EHPLMN_MAX) && (i < USIM_EHPLMN_MAX); i++) {
224 225
      if ( PLMN_IS_VALID(user->usim_data.ehplmn[i]) ) {
        user->emm_data->ehplmn.plmn[i] = user->usim_data.ehplmn[i];
226
        user->emm_data->ehplmn.n_plmns += 1;
gauthier's avatar
 
gauthier committed
227 228 229 230 231
      }
    }

    /* Get the list of User controlled PLMN Selector */
    for (i=0; (i < EMM_DATA_PLMN_MAX) && (i < USIM_PLMN_MAX); i++) {
232 233 234
      if ( PLMN_IS_VALID(user->usim_data.plmn[i].plmn) ) {
        user->emm_data->plmn.plmn[i] = user->usim_data.plmn[i].plmn;
        user->emm_data->userAcT[i] = user->usim_data.plmn[i].AcT;
235
        user->emm_data->plmn.n_plmns += 1;
gauthier's avatar
 
gauthier committed
236 237 238 239 240
      }
    }

    /* Get the list of Operator controlled PLMN Selector */
    for (i=0; (i < EMM_DATA_OPLMN_MAX) && (i < USIM_OPLMN_MAX); i++) {
241 242 243
      if ( PLMN_IS_VALID(user->usim_data.oplmn[i].plmn) ) {
        user->emm_data->oplmn.plmn[i] = user->usim_data.oplmn[i].plmn;
        user->emm_data->operAcT[i] = user->usim_data.oplmn[i].AcT;
244
        user->emm_data->oplmn.n_plmns += 1;
gauthier's avatar
 
gauthier committed
245 246 247 248 249
      }
    }

    /* Get the list of Operator network name records */
    for (i=0; (i < EMM_DATA_OPNN_MAX) && (i < USIM_OPL_MAX); i++) {
250 251 252 253 254
      if ( PLMN_IS_VALID(user->usim_data.opl[i].plmn) ) {
        int pnn_id = user->usim_data.opl[i].record_id;
        user->emm_data->opnn[i].plmn = &user->usim_data.opl[i].plmn;
        user->emm_data->opnn[i].fullname = (char *)user->usim_data.pnn[pnn_id].fullname.value;
        user->emm_data->opnn[i].shortname = (char *)user->usim_data.pnn[pnn_id].shortname.value;
255
        user->emm_data->n_opnns += 1;
gauthier's avatar
 
gauthier committed
256 257 258 259 260 261
      }
    }

    /* TODO: Get the Higher Priority PLMN search period parameter */

    /* Get the EPS location information */
262 263
    if (PLMN_IS_VALID(user->usim_data.epsloci.guti.gummei.plmn)) {
      user->emm_data->guti = &user->usim_data.epsloci.guti;
gauthier's avatar
 
gauthier committed
264 265
    }

266 267
    if (TAI_IS_VALID(user->usim_data.epsloci.tai)) {
      user->emm_data->tai = &user->usim_data.epsloci.tai;
gauthier's avatar
 
gauthier committed
268 269
    }

270
    user->emm_data->status = user->usim_data.epsloci.status;
gauthier's avatar
 
gauthier committed
271 272

    /* Get NAS configuration parameters */
273
    user->emm_data->NAS_SignallingPriority =
274 275 276
      user->usim_data.nasconfig.NAS_SignallingPriority.value[0];
    user->emm_data->NMO_I_Behaviour = user->usim_data.nasconfig.NMO_I_Behaviour.value[0];
    user->emm_data->AttachWithImsi = user->usim_data.nasconfig.AttachWithImsi.value[0];
277
    user->emm_data->MinimumPeriodicSearchTimer =
278
      user->usim_data.nasconfig.MinimumPeriodicSearchTimer.value[0];
279
    user->emm_data->ExtendedAccessBarring =
280
      user->usim_data.nasconfig.ExtendedAccessBarring.value[0];
281
    user->emm_data->Timer_T3245_Behaviour =
282
      user->usim_data.nasconfig.Timer_T3245_Behaviour.value[0];
gauthier's avatar
 
gauthier committed
283 284 285 286 287

    /*
     * Get EPS NAS security context
     */
    /* Create NAS security context */
288
    user->emm_data->security =
gauthier's avatar
 
gauthier committed
289 290
      (emm_security_context_t *)malloc(sizeof(emm_security_context_t));

291 292
    if (user->emm_data->security != NULL) {
      memset(user->emm_data->security, 0, sizeof(emm_security_context_t));
gauthier's avatar
 
gauthier committed
293 294

      /* Type of security context */
295
      if (user->usim_data.securityctx.KSIasme.value[0] !=
gauthier's avatar
 
gauthier committed
296
          USIM_KSI_NOT_AVAILABLE) {
297
        user->emm_data->security->type = EMM_KSI_NATIVE;
gauthier's avatar
 
gauthier committed
298
      } else {
299
        user->emm_data->security->type = EMM_KSI_NOT_AVAILABLE;
gauthier's avatar
 
gauthier committed
300 301 302
      }

      /* EPS key set identifier */
303
      user->emm_data->security->eksi = user->usim_data.securityctx.KSIasme.value[0];
gauthier's avatar
 
gauthier committed
304
      /* ASME security key */
305
      user->emm_data->security->kasme.length =
306
        user->usim_data.securityctx.Kasme.length;
307 308
      user->emm_data->security->kasme.value =
        (uint8_t *)malloc(user->emm_data->security->kasme.length);
gauthier's avatar
 
gauthier committed
309

310 311
      if (user->emm_data->security->kasme.value) {
        memcpy(user->emm_data->security->kasme.value,
312
               user->usim_data.securityctx.Kasme.value,
313
               user->emm_data->security->kasme.length);
gauthier's avatar
 
gauthier committed
314 315 316
      }

      /* Downlink count parameter */
317
      if (user->usim_data.securityctx.dlNAScount.length <= sizeof(uint32_t)) {
318
        memcpy(&user->emm_data->security->dl_count,
319 320
               user->usim_data.securityctx.dlNAScount.value,
               user->usim_data.securityctx.dlNAScount.length);
gauthier's avatar
 
gauthier committed
321 322 323
      }

      /* Uplink count parameter */
324
      if (user->usim_data.securityctx.ulNAScount.length <= sizeof(uint32_t)) {
325
        memcpy(&user->emm_data->security->ul_count,
326 327
               user->usim_data.securityctx.ulNAScount.value,
               user->usim_data.securityctx.ulNAScount.length);
gauthier's avatar
 
gauthier committed
328 329 330
      }

      /* Ciphering algorithm */
331
      user->emm_data->security->capability.eps_encryption =
332
        ((user->usim_data.securityctx.algorithmID.value[0] >> 4) & 0xf);
gauthier's avatar
 
gauthier committed
333
      /* Identity protection algorithm */
334
      user->emm_data->security->capability.eps_integrity =
335
        (user->usim_data.securityctx.algorithmID.value[0] & 0xf);
gauthier's avatar
 
gauthier committed
336 337 338 339 340 341 342 343 344
      /* NAS integrity and cyphering keys are not available */
    } else {
      LOG_TRACE(WARNING,
                "EMM-PROC  - Failed to create security context");
    }

    /*
     * Get EMM data from the UE's non-volatile memory
     */
345 346
    memset(&user->emm_data->nvdata.rplmn, 0xFF, sizeof(plmn_t));
    user->emm_data->nvdata.eplmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
347 348 349 350 351 352 353
    /* Get EMM data pathname */
    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 {
      /* Get EMM data stored in the non-volatile memory device */
354
      int rc = memory_read(path, &user->emm_data->nvdata, sizeof(emm_nvdata_t));
gauthier's avatar
 
gauthier committed
355 356 357 358 359 360

      if (rc != RETURNok) {
        LOG_TRACE(ERROR, "EMM-MAIN  - Failed to read %s", path);
      } else {
        /* Check the IMSI */
        LOG_TRACE(INFO, "EMM-MAIN  - EMM data successfully read");
361
        user->emm_data->imsi = &user->usim_data.imsi;
362
        int imsi_ok = _emm_main_imsi_cmp(&user->emm_data->nvdata.imsi,
363
                                         &user->usim_data.imsi);
gauthier's avatar
 
gauthier committed
364 365 366 367 368

        if (!imsi_ok) {
          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",
369 370 371 372 373 374 375 376
                    user->emm_data->nvdata.imsi.u.value[0],
                    user->emm_data->nvdata.imsi.u.value[1],
                    user->emm_data->nvdata.imsi.u.value[2],
                    user->emm_data->nvdata.imsi.u.value[3],
                    user->emm_data->nvdata.imsi.u.value[4],
                    user->emm_data->nvdata.imsi.u.value[5],
                    user->emm_data->nvdata.imsi.u.value[6],
                    user->emm_data->nvdata.imsi.u.value[7],
377 378 379 380 381 382 383 384
                    user->usim_data.imsi.u.value[0],
                    user->usim_data.imsi.u.value[1],
                    user->usim_data.imsi.u.value[2],
                    user->usim_data.imsi.u.value[3],
                    user->usim_data.imsi.u.value[4],
                    user->usim_data.imsi.u.value[5],
                    user->usim_data.imsi.u.value[6],
                    user->usim_data.imsi.u.value[7]);
385 386
          memset(&user->emm_data->nvdata.rplmn, 0xFF, sizeof(plmn_t));
          user->emm_data->nvdata.eplmn.n_plmns = 0;
gauthier's avatar
 
gauthier committed
387 388 389 390 391 392 393 394 395 396
        }
      }

      free(path);
    }
  }

  /*
   * Initialize EMM timers
   */
397
  user->emm_data->emm_timers = calloc_or_fail(sizeof(emm_timers_t));
398
  _emm_timers_initialize(user->emm_data->emm_timers);
gauthier's avatar
 
gauthier committed
399

400 401 402
  /*
   * Initialize Internal data used for detach procedure
   */
403
  user->emm_data->emm_detach_data = calloc_or_fail(sizeof(emm_detach_data_t));
404 405
  _emm_detach_initialize(user->emm_data->emm_detach_data);

406 407 408
  /*
   * Initialize Internal data used for attach procedure
   */
409
  user->emm_data->emm_attach_data = calloc_or_fail(sizeof(emm_attach_data_t));
410 411
  _emm_attach_initialize(user->emm_data->emm_attach_data);

gauthier's avatar
 
gauthier committed
412 413 414 415 416 417 418 419
  /*
   * Initialize the user notification callback
   */
  _emm_main_user_callback = *cb;

  /*
   * Initialize EMM internal data used for UE in idle mode
   */
420
  IdleMode_initialize(user, &_emm_main_callback);
gauthier's avatar
 
gauthier committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

  LOG_FUNC_OUT;
}


/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_cleanup()                                        **
 **                                                                        **
 ** Description: Performs the EPS Mobility Management clean up procedure   **
 **                                                                        **
 ** Inputs:  None                                                      **
 **          Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **          Return:    None                                       **
 **          Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
440
void emm_main_cleanup(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
441 442 443
{
  LOG_FUNC_IN;

444
  if (emm_data->usim_is_valid) {
gauthier's avatar
 
gauthier committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    /*
     * TODO: Update USIM application data
     */
  }

  /*
   * Store EMM data into the UE's non-volatile memory
   * - Registered PLMN
   * - List of equivalent PLMNs
   */
  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 {
460
    int rc = memory_write(path, &emm_data->nvdata, sizeof(emm_nvdata_t));
gauthier's avatar
 
gauthier committed
461 462 463 464 465 466 467

    if (rc != RETURNok) {
      LOG_TRACE(ERROR, "EMM-MAIN  - Failed to write %s", path);
    }
  }

  /* Release dynamically allocated memory */
468 469 470
  if (emm_data->imei) {
    free(emm_data->imei);
    emm_data->imei = NULL;
gauthier's avatar
 
gauthier committed
471 472
  }

473 474
  if (emm_data->security) {
    emm_security_context_t *security = emm_data->security;
gauthier's avatar
 
gauthier committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493

    if (security->kasme.value) {
      free(security->kasme.value);
      security->kasme.value  = NULL;
      security->kasme.length = 0;
    }

    if (security->knas_enc.value) {
      free(security->knas_enc.value);
      security->knas_enc.value  = NULL;
      security->knas_enc.length = 0;
    }

    if (security->knas_int.value) {
      free(security->knas_int.value);
      security->knas_int.value  = NULL;
      security->knas_int.length = 0;
    }

494 495
    free(emm_data->security);
    emm_data->security = NULL;
gauthier's avatar
 
gauthier committed
496 497 498 499 500 501 502 503 504 505 506
  }
  LOG_FUNC_OUT;
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_imsi()                                       **
 **                                                                        **
 ** Description: Get the International Mobile Subscriber Identity number   **
 **                                                                        **
 ** Inputs:  None                                                      **
507
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
508 509 510 511 512 513
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    Pointer to the IMSI                        **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
514
const imsi_t *emm_main_get_imsi(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
515 516
{
  LOG_FUNC_IN;
517
  LOG_FUNC_RETURN (&emm_data->nvdata.imsi);
gauthier's avatar
 
gauthier committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_msisdn()                                     **
 **                                                                        **
 ** Description: Get the Mobile Subscriber Dialing Number from the USIM    **
 **                                                                        **
 ** Inputs:  None                                                      **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    Pointer to the subscriber dialing number   **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
533
const msisdn_t *emm_main_get_msisdn(nas_user_t *user)
gauthier's avatar
 
gauthier committed
534 535
{
  LOG_FUNC_IN;
536
  LOG_FUNC_RETURN (&user->usim_data.msisdn.number);
gauthier's avatar
 
gauthier committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_set_plmn_selection_mode()                        **
 **                                                                        **
 ** Description: Set the network selection mode of operation to the given  **
 **      mode and update the manually selected network selection   **
 **      data                                                      **
 **                                                                        **
 ** Inputs:  mode:      The specified network selection mode of    **
 **             operation                                  **
 **      format:    The representation format of the PLMN      **
 **             identifier                                 **
 **      plmn:      Identifier of the selected PLMN            **
 **      rat:       The selected Radio Access Techonology      **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
557
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
558 559
 **                                                                        **
 ***************************************************************************/
560
int emm_main_set_plmn_selection_mode(nas_user_t *user, int mode, int format,
gauthier's avatar
 
gauthier committed
561 562 563 564 565
                                     const network_plmn_t *plmn, int rat)
{
  LOG_FUNC_IN;

  int index;
566 567
  emm_data_t *emm_data = user->emm_data;
  emm_plmn_list_t *emm_plmn_list = user->emm_plmn_list;
gauthier's avatar
 
gauthier committed
568 569 570 571

  LOG_TRACE(INFO, "EMM-MAIN  - PLMN selection: mode=%d, format=%d, plmn=%s, "
            "rat=%d", mode, format, (const char *)&plmn->id, rat);

572
  emm_data->plmn_mode = mode;
gauthier's avatar
 
gauthier committed
573 574 575

  if (mode != EMM_DATA_PLMN_AUTO) {
    /* Get the index of the PLMN in the list of available PLMNs */
576
    index = _emm_main_get_plmn_index(emm_plmn_list, (const char *)&plmn->id, format);
gauthier's avatar
 
gauthier committed
577 578 579 580 581 582

    if (index < 0) {
      LOG_TRACE(WARNING, "EMM-MAIN  - PLMN %s not available",
                (const char *)&plmn->id);
    } else {
      /* Update the manually selected network selection data */
583 584
      emm_data->plmn_index = index;
      emm_data->plmn_rat = rat;
gauthier's avatar
 
gauthier committed
585 586 587 588 589 590 591
    }
  } 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
     * applied to the user reselection in Automatic Network Selection Mode.
     */
592
    index = IdleMode_get_hplmn_index(emm_plmn_list);
gauthier's avatar
 
gauthier committed
593 594 595 596 597 598 599 600 601 602 603 604 605
  }

  LOG_FUNC_RETURN (index);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_selection_mode()                        **
 **                                                                        **
 ** Description: Get the current value of the network selection mode of    **
 **      operation                                                 **
 **                                                                        **
 ** Inputs:  None                                                      **
606
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
607 608 609 610 611 612
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The value of the network selection mode    **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
613
int emm_main_get_plmn_selection_mode(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
614 615
{
  LOG_FUNC_IN;
616
  LOG_FUNC_RETURN (emm_data->plmn_mode);
gauthier's avatar
 
gauthier committed
617 618 619 620 621 622 623 624 625
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_list()                                  **
 **                                                                        **
 ** Description: Get the list of available PLMNs                           **
 **                                                                        **
 ** Inputs:  None                                                      **
626
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
627 628 629 630 631 632
 **                                                                        **
 ** Outputs:     plist:     Pointer to the list of available PLMNs     **
 **      Return:    The size of the list in bytes              **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
633
int emm_main_get_plmn_list(emm_plmn_list_t *emm_plmn_list, emm_data_t *emm_data, const char **plist)
gauthier's avatar
 
gauthier committed
634 635 636
{
  LOG_FUNC_IN;

637
  int size = IdleMode_update_plmn_list(emm_plmn_list, emm_data, 0);
638
  *plist = emm_data->plist.buffer;
gauthier's avatar
 
gauthier committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

  LOG_FUNC_RETURN (size);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_selected_plmn()                              **
 **                                                                        **
 ** Description: Get the identifier of the currently selected PLMN         **
 **                                                                        **
 ** Inputs:  format:    The requested format of the string repre-  **
 **             sentation of the PLMN identifier           **
 **                                                                        **
 ** Outputs:     plmn:      The selected PLMN identifier coded in the  **
 **             requested format                           **
 **      Return:    A pointer to the string representation of  **
 **             the selected PLMN                          **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
659
const char *emm_main_get_selected_plmn(emm_plmn_list_t *emm_plmn_list, emm_data_t *emm_data, network_plmn_t *plmn, int format)
gauthier's avatar
 
gauthier committed
660 661 662 663 664 665 666
{
  LOG_FUNC_IN;

  size_t size = 0;
  /*
   * Get the identifier of the selected PLMN in the list of available PLMNs
   */
667
  int index = IdleMode_get_splmn_index(emm_plmn_list);
gauthier's avatar
 
gauthier committed
668 669

  if ( !(index < 0) ) {
670
    const char *name = _emm_main_get_plmn(emm_plmn_list, &emm_data->splmn, index,
gauthier's avatar
 
gauthier committed
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
                                          format, &size);

    if (size > 0) {
      LOG_FUNC_RETURN ((char *) memcpy(&plmn->id, name, size));
    }
  }

  LOG_FUNC_RETURN (NULL);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_registered_plmn()                            **
 **                                                                        **
 ** Description: Get the identifier of the currently registered PLMN       **
 **                                                                        **
 ** Inputs:  format:    The requested format of the string repre-  **
 **             sentation of the PLMN identifier           **
 **                                                                        **
 ** Outputs:     plmn:      The registered PLMN identifier coded in    **
 **             the requested format                       **
 **      Return:    A pointer to the string representation of  **
 **             the registered PLMN                        **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
697
const char *emm_main_get_registered_plmn(emm_plmn_list_t *emm_plmn_list, emm_data_t *emm_data, network_plmn_t *plmn, int format)
gauthier's avatar
 
gauthier committed
698 699 700 701 702 703 704 705
{
  LOG_FUNC_IN;

  size_t size = 0;

  /*
   * Get the identifier of the registered PLMN in the list of available PLMNs
   */
706
  int index = IdleMode_get_rplmn_index(emm_plmn_list);
gauthier's avatar
 
gauthier committed
707 708

  if ( !(index < 0) ) {
709
    const char *name = _emm_main_get_plmn(emm_plmn_list, &emm_data->nvdata.rplmn,
gauthier's avatar
 
gauthier committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
                                          index, format, &size);

    if (size > 0) {
      LOG_FUNC_RETURN ((char *) memcpy(&plmn->id, name, size));
    }
  }

  LOG_FUNC_RETURN (NULL);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_status()                                **
 **                                                                        **
 ** Description: Get the value of the network registration status which    **
 **      shows whether the network has currently indicated the     **
 **      registration of the UE                                    **
 **                                                                        **
 ** Inputs:  None                                                      **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The current network registration status    **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
735
Stat_t emm_main_get_plmn_status(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
736 737
{
  LOG_FUNC_IN;
738
  LOG_FUNC_RETURN (emm_data->stat);
gauthier's avatar
 
gauthier committed
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_tac()                                   **
 **                                                                        **
 ** Description: Get the code of the Tracking area the registered PLMN     **
 **      belongs to                                                **
 **                                                                        **
 ** Inputs:  None                                                      **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The Location/Tracking area code            **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
755
tac_t emm_main_get_plmn_tac(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
756 757
{
  LOG_FUNC_IN;
758
  LOG_FUNC_RETURN (emm_data->tac);
gauthier's avatar
 
gauthier committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_ci()                                    **
 **                                                                        **
 ** Description: Get the identifier of the serving cell                    **
 **                                                                        **
 ** Inputs:  None                                                      **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The serving cell identifier                **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
774
ci_t emm_main_get_plmn_ci(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
775 776
{
  LOG_FUNC_IN;
777
  LOG_FUNC_RETURN (emm_data->ci);
gauthier's avatar
 
gauthier committed
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_rat()                                   **
 **                                                                        **
 ** Description: Get the value of the Radio Access Technology of the ser-  **
 **      ving cell                                                 **
 **                                                                        **
 ** Inputs:  None                                                      **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The value of the Radio Access Technology   **
 **             of the serving cell                        **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
795
AcT_t emm_main_get_plmn_rat(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
796 797
{
  LOG_FUNC_IN;
798
  LOG_FUNC_RETURN (emm_data->rat);
gauthier's avatar
 
gauthier committed
799 800 801 802 803 804 805 806 807 808
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_is_attached()                                    **
 **                                                                        **
 ** Description: Indicates whether the UE is currently attached to the     **
 **      network for EPS services or emergency service only        **
 **                                                                        **
 ** Inputs:  None                                                      **
809
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
810 811 812 813 814 815 816
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    TRUE if the UE is currently attached to    **
 **             the network; FALSE otherwise.              **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
817
int emm_main_is_attached(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
818 819
{
  LOG_FUNC_IN;
820
  LOG_FUNC_RETURN (emm_data->is_attached);
gauthier's avatar
 
gauthier committed
821 822 823 824 825 826 827 828 829 830
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_main_get_plmn_rat()                                   **
 **                                                                        **
 ** Description: Indicates whether the UE is currently attached to the     **
 **      network for emergency bearer services                     **
 **                                                                        **
 ** Inputs:  None                                                      **
831
 **      Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
832 833 834 835 836 837 838 839
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    TRUE if the UE is currently attached or is **
 **             attempting to attach to the network for    **
 **             emergency bearer services; FALSE otherwise **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
840
int emm_main_is_emergency(emm_data_t *emm_data)
gauthier's avatar
 
gauthier committed
841 842
{
  LOG_FUNC_IN;
843
  LOG_FUNC_RETURN (emm_data->is_attached && emm_data->is_emergency);
gauthier's avatar
 
gauthier committed
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
}

/****************************************************************************/
/*********************  L O C A L    F U N C T I O N S  *********************/
/****************************************************************************/

/****************************************************************************
 **                                                                        **
 ** Name:    _emm_main_callback()                                      **
 **                                                                        **
 ** Description: Forwards the network indication to the upper control la-  **
 **      yer (user API) to notify that network registration and/or **
 **      location information has changed.                         **
 **                                                                        **
 ** Inputs:  size:      Size in byte of the list of operators      **
 **             present in the network. The list has to be **
 **             displayed to the user application when     **
 **             size > 0.                                  **
862
 **          Others:    user->emm_data->                                 **
gauthier's avatar
 
gauthier committed
863 864 865 866 867 868
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **          Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
869
static int _emm_main_callback(user_api_id_t *user_api_id, emm_data_t *emm_data, int size)
gauthier's avatar
 
gauthier committed
870 871 872 873
{
  LOG_FUNC_IN;

  /* Forward the notification to the user API */
874
  int rc = (*_emm_main_user_callback)(user_api_id, emm_data->stat, emm_data->tac,
875 876
                                      emm_data->ci, emm_data->rat,
                                      emm_data->plist.buffer, size);
gauthier's avatar
 
gauthier committed
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    _emm_main_get_imei()                                      **
 **                                                                        **
 ** Description: Returns the International Mobile Equipment Identity con-  **
 **      tained in the given string representation                 **
 **                                                                        **
 ** Inputs:  imei:      The string representation of the IMEI      **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     imei:      The IMEI of the UE                         **
 **      Return:    The number of digits in the IMEI           **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
static int _emm_main_get_imei(imei_t *imei, const char *imei_str)
{
  int len = strlen(imei_str);

  if (len % 2) {
901
    imei->u.num.parity = IMEI_ODD_PARITY;
gauthier's avatar
 
gauthier committed
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
  } else {
    imei->u.num.parity = EVEN_PARITY;
  }

  imei->u.num.digit1 = imei_str[0] - '0';
  imei->u.num.digit2 = imei_str[1] - '0';
  imei->u.num.digit3 = imei_str[2] - '0';
  imei->u.num.digit4 = imei_str[3] - '0';
  imei->u.num.digit5 = imei_str[4] - '0';
  imei->u.num.digit6 = imei_str[5] - '0';
  imei->u.num.digit7 = imei_str[6] - '0';
  imei->u.num.digit8 = imei_str[7] - '0';
  imei->u.num.digit9 = imei_str[8] - '0';
  imei->u.num.digit10 = imei_str[9] - '0';
  imei->u.num.digit11 = imei_str[10] - '0';
  imei->u.num.digit12 = imei_str[11] - '0';
  imei->u.num.digit13 = imei_str[12] - '0';
  imei->u.num.digit14 = imei_str[13] - '0';
  imei->u.num.digit15 = imei_str[14] - '0';
  return (len);
}

/****************************************************************************
 **                                                                        **
 ** Name:    _emm_main_imsi_cmp()                                      **
 **                                                                        **
 ** Description: Compares two International Mobile Subscriber Identifiers  **
 **                                                                        **
 ** Inputs:  imsi1:     The first IMSI                             **
 **      imsi2:     The second IMSI to compare to              **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    TRUE if the first IMSI is found to match   **
 **             the second; FALSE otherwise.               **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
static int _emm_main_imsi_cmp(imsi_t *imsi1, imsi_t *imsi2)
{
  int i;

  if (imsi1->length != imsi2->length) {
    return FALSE;
  }

  for (i = 0; i < imsi1->length; i++) {
    if (imsi1->u.value[i] != imsi2->u.value[i]) {
      return FALSE;
    }
  }

  return TRUE;
}

/****************************************************************************
 **                                                                        **
 ** Name:    _emm_main_get_plmn()                                      **
 **                                                                        **
 ** Description: Get the identifier of the PLMN at the given index in the  **
 **      list of available PLMNs.                                  **
 **                                                                        **
 ** Inputs:  plmn:      The PLMN to search for                     **
 **      index:     The index of the PLMN in the list of PLMNs **
 **      format:    The requested representation format of the **
 **             PLMN identifier                            **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     size:      The size in bytes of the PLMN identifier   **
 **             coded in the requested format              **
 **      Return:    A pointer to the identifier of the PLMN    **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
976
static const char *_emm_main_get_plmn(emm_plmn_list_t *emm_plmn_list, const plmn_t *plmn, int index,
gauthier's avatar
 
gauthier committed
977 978 979 980 981 982
                                      int format, size_t *size)
{
  if ( PLMN_IS_VALID(*plmn) ) {
    switch (format) {
    case NET_FORMAT_LONG:
      /* Get the long alpha-numeric representation of the PLMN */
983
      return IdleMode_get_plmn_fullname(emm_plmn_list, plmn, index, size);
gauthier's avatar
 
gauthier committed
984 985 986 987
      break;

    case NET_FORMAT_SHORT:
      /* Get the short alpha-numeric representation of the PLMN */
988
      return IdleMode_get_plmn_shortname(emm_plmn_list, plmn, index, size);
gauthier's avatar
 
gauthier committed
989 990 991 992
      break;

    case NET_FORMAT_NUM:
      /* Get the numeric representation of the PLMN */
993
      return IdleMode_get_plmn_id(emm_plmn_list, plmn, index, size);
gauthier's avatar
 
gauthier committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
      break;

    default:
      LOG_TRACE(WARNING, "EMM-MAIN  - Format is not valid (%d)",
                format);
      *size = 0;
      break;
    }
  }

  return (NULL);
}

/****************************************************************************
 **                                                                        **
 ** Name:    _emm_main_get_plmn_index()                                **
 **                                                                        **
 ** Description: Get the index of the given PLMN in the ordered list of    **
 **      available PLMNs                                           **
 **                                                                        **
 ** Inputs:  plmn:      Identifier of the PLMN                     **
 **      format:    The representation format of the PLMN      **
 **             identifier                                 **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    The index of the selected PLMN in the list **
 **             of available PLMNs; -1 if the PLMN is not  **
 **             found                                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
1026
static int _emm_main_get_plmn_index(emm_plmn_list_t *emm_plmn_list, const char *plmn, int format)
gauthier's avatar
 
gauthier committed
1027 1028 1029 1030 1031 1032
{
  int index = -1;

  switch (format) {
  case NET_FORMAT_LONG:
    /* Get the index of the long alpha-numeric PLMN identifier */
1033
    index = IdleMode_get_plmn_fullname_index(emm_plmn_list, plmn);
gauthier's avatar
 
gauthier committed
1034 1035 1036 1037
    break;

  case NET_FORMAT_SHORT:
    /* Get the index of the short alpha-numeric PLMN identifier */
1038
    index = IdleMode_get_plmn_shortname_index(emm_plmn_list, plmn);
gauthier's avatar
 
gauthier committed
1039 1040 1041 1042
    break;

  case NET_FORMAT_NUM:
    /* Get the index of the numeric PLMN identifier */
1043
    index = IdleMode_get_plmn_id_index(emm_plmn_list, plmn);
gauthier's avatar
 
gauthier committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
    break;

  default:
    LOG_TRACE(WARNING, "EMM-MAIN  - Format is not valid (%d)", format);
    break;
  }

  return (index);
}