Identification.c 22.6 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
1
/*****************************************************************************
Cedric Roux's avatar
Cedric Roux committed
2 3
            Eurecom OpenAirInterface 3
            Copyright(c) 2012 Eurecom
Cedric Roux's avatar
 
Cedric Roux committed
4

Cedric Roux's avatar
Cedric Roux committed
5
Source      Identification.c
Cedric Roux's avatar
 
Cedric Roux committed
6

Cedric Roux's avatar
Cedric Roux committed
7
Version     0.1
Cedric Roux's avatar
 
Cedric Roux committed
8

Cedric Roux's avatar
Cedric Roux committed
9
Date        2013/04/09
Cedric Roux's avatar
 
Cedric Roux committed
10

Cedric Roux's avatar
Cedric Roux committed
11
Product     NAS stack
Cedric Roux's avatar
 
Cedric Roux committed
12

Cedric Roux's avatar
Cedric Roux committed
13
Subsystem   EPS Mobility Management
Cedric Roux's avatar
 
Cedric Roux committed
14

Cedric Roux's avatar
Cedric Roux committed
15
Author      Frederic Maurel
Cedric Roux's avatar
 
Cedric Roux committed
16

Cedric Roux's avatar
Cedric Roux committed
17 18
Description Defines the identification EMM procedure executed by the
        Non-Access Stratum.
Cedric Roux's avatar
 
Cedric Roux committed
19

Cedric Roux's avatar
Cedric Roux committed
20 21 22
        The identification procedure is used by the network to request
        a particular UE to provide specific identification parameters
        (IMSI, IMEI).
Cedric Roux's avatar
 
Cedric Roux committed
23 24 25 26 27 28 29 30 31 32 33

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

#include "emm_proc.h"
#include "nas_log.h"
#include "nas_timer.h"

#include "emmData.h"

#include "emm_sap.h"

Cedric Roux's avatar
Cedric Roux committed
34 35
#include <stdlib.h> // malloc, free
#include <string.h> // memcpy
Cedric Roux's avatar
 
Cedric Roux committed
36 37 38 39 40 41 42 43 44 45

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

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

/* String representation of the requested identity type */
Cedric Roux's avatar
Cedric Roux committed
46
static const char *_emm_identity_type_str[] = {
Cedric Roux's avatar
 
Cedric Roux committed
47 48 49 50 51
    "NOT AVAILABLE", "IMSI", "IMEI", "IMEISV", "TMSI"
};

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
52
 *  Internal data handled by the identification procedure in the UE
Cedric Roux's avatar
 
Cedric Roux committed
53 54 55
 * --------------------------------------------------------------------------
 */
#ifdef NAS_UE
Cedric Roux's avatar
Cedric Roux committed
56
#endif  // NAS_UE
Cedric Roux's avatar
 
Cedric Roux committed
57 58 59

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
60
 *  Internal data handled by the identification procedure in the MME
Cedric Roux's avatar
 
Cedric Roux committed
61 62 63 64 65 66
 * --------------------------------------------------------------------------
 */
#ifdef NAS_MME
/*
 * Timer handlers
 */
Cedric Roux's avatar
Cedric Roux committed
67
static void *_identification_t3470_handler(void *);
Cedric Roux's avatar
 
Cedric Roux committed
68 69 70 71 72 73

/*
 * 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
 */
Cedric Roux's avatar
Cedric Roux committed
74
static int _identification_abort(void *);
Cedric Roux's avatar
 
Cedric Roux committed
75 76 77 78 79

/*
 * Internal data used for identification procedure
 */
typedef struct {
Cedric Roux's avatar
Cedric Roux committed
80 81 82 83 84 85 86
    unsigned int ueid;          /* UE identifier        */
#define IDENTIFICATION_COUNTER_MAX  5
    unsigned int retransmission_count;  /* Retransmission counter   */
    emm_proc_identity_type_t type;  /* Type of UE identity      */
    int notify_failure;         /* Indicates whether the identification
                     * procedure failure shall be notified
                     * to the ongoing EMM procedure */
Cedric Roux's avatar
 
Cedric Roux committed
87 88
} identification_data_t;

Cedric Roux's avatar
Cedric Roux committed
89
static int _identification_request(identification_data_t *data);
Cedric Roux's avatar
 
Cedric Roux committed
90 91 92 93 94 95 96 97
#endif // NAS_MME

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

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
98
 *      Identification procedure executed by the UE
Cedric Roux's avatar
 
Cedric Roux committed
99 100 101 102 103
 * --------------------------------------------------------------------------
 */
#ifdef NAS_UE
/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
104
 ** Name:    emm_proc_identification_request()                         **
Cedric Roux's avatar
 
Cedric Roux committed
105 106 107 108
 **                                                                        **
 ** Description: Performs the MME requested identification procedure.      **
 **                                                                        **
 **              3GPP TS 24.301, section 5.4.4.3                           **
Cedric Roux's avatar
Cedric Roux committed
109 110 111 112
 **      Upon receiving the IDENTITY REQUEST message, the UE shall **
 **      send  an  IDENTITY  RESPONSE  message to the network. The **
 **      IDENTITY RESPONSE message shall contain the identifica-   **
 **      tion parameters as requested by the network.              **
Cedric Roux's avatar
 
Cedric Roux committed
113
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
114 115
 ** Inputs:  type:      Type of the requested identity             **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
116
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
117 118 119
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
120 121 122 123 124 125 126 127 128 129
 **                                                                        **
 ***************************************************************************/
int emm_proc_identification_request(emm_proc_identity_type_t type)
{
    LOG_FUNC_IN;

    int rc;
    emm_sap_t emm_sap;

    LOG_TRACE(INFO, "EMM-PROC  - Identification requested type = %s (%d)",
Cedric Roux's avatar
Cedric Roux committed
130
              _emm_identity_type_str[type], type);
Cedric Roux's avatar
 
Cedric Roux committed
131 132 133 134 135

    /* Setup EMM procedure handler to be executed upon receiving
     * lower layer notification */
    rc = emm_proc_lowerlayer_initialize(NULL, NULL, NULL, NULL);
    if (rc != RETURNok) {
Cedric Roux's avatar
Cedric Roux committed
136 137 138
        LOG_TRACE(WARNING,
                  "EMM-PROC  - Failed to initialize EMM procedure handler");
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
139 140 141 142
    }

    emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_NOT_AVAILABLE;

Cedric Roux's avatar
Cedric Roux committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    switch (type) {
        case EMM_IDENT_TYPE_IMSI:
            /* International Mobile Subscriber Identity is requested */
            if (_emm_data.imsi) {
                emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_IMSI;
                emm_sap.u.emm_as.u.security.imsi = _emm_data.imsi;
            }
            break;

        case EMM_IDENT_TYPE_IMEI:
            /* International Mobile Equipment Identity is requested */
            if (_emm_data.imei) {
                emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_IMEI;
                emm_sap.u.emm_as.u.security.imei = _emm_data.imei;
            }
            break;

        case EMM_IDENT_TYPE_TMSI:
            /* Temporary Mobile Subscriber Identity is requested */
            if (_emm_data.guti) {
                emm_sap.u.emm_as.u.security.identType = EMM_IDENT_TYPE_TMSI;
                emm_sap.u.emm_as.u.security.tmsi = _emm_data.guti->m_tmsi;
            }
            break;

        default:
            /* Other identities are not available */
            break;
Cedric Roux's avatar
 
Cedric Roux committed
171 172 173 174 175 176 177 178 179 180 181 182
    }

    /*
     * Notify EMM-AS SAP that Identity Response message has to be sent
     * to the MME
     */
    emm_sap.primitive = EMMAS_SECURITY_RES;
    emm_sap.u.emm_as.u.security.guti = _emm_data.guti;
    emm_sap.u.emm_as.u.security.ueid = 0;
    emm_sap.u.emm_as.u.security.msgType = EMM_AS_MSG_TYPE_IDENT;
    /* Setup EPS NAS security data */
    emm_as_set_security_data(&emm_sap.u.emm_as.u.security.sctx,
Cedric Roux's avatar
Cedric Roux committed
183
                             _emm_data.security, FALSE, TRUE);
Cedric Roux's avatar
 
Cedric Roux committed
184 185 186 187 188 189 190 191
    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN (rc);
}
#endif // NAS_UE

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
192
 *      Identification procedure executed by the MME
Cedric Roux's avatar
 
Cedric Roux committed
193 194 195 196 197
 * --------------------------------------------------------------------------
 */
#ifdef NAS_MME
/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
198
 ** Name:    emm_proc_identification()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
199 200 201 202
 **                                                                        **
 ** Description: Initiates an identification procedure.                    **
 **                                                                        **
 **              3GPP TS 24.301, section 5.4.4.2                           **
Cedric Roux's avatar
Cedric Roux committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
 **      The network initiates the identification procedure by     **
 **      sending an IDENTITY REQUEST message to the UE and star-   **
 **      ting the timer T3470. The IDENTITY REQUEST message speci- **
 **      fies the requested identification parameters in the Iden- **
 **      tity type information element.                            **
 **                                                                        **
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      type:      Type of the requested identity             **
 **      success:   Callback function executed when the identi-**
 **             fication procedure successfully completes  **
 **      reject:    Callback function executed when the identi-**
 **             fication procedure fails or is rejected    **
 **      failure:   Callback function executed whener a lower  **
 **             layer failure occured before the identifi- **
 **             cation procedure comnpletes                **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
223 224 225 226 227
 **                                                                        **
 ***************************************************************************/
int emm_proc_identification(unsigned int                   ueid,
                            emm_data_context_t            *emm_ctx,
                            emm_proc_identity_type_t       type,
Cedric Roux's avatar
Cedric Roux committed
228 229 230
                            emm_common_success_callback_t  success,
                            emm_common_reject_callback_t   reject,
                            emm_common_failure_callback_t  failure)
Cedric Roux's avatar
 
Cedric Roux committed
231 232 233 234 235
{
    LOG_FUNC_IN;

    int rc = RETURNerror;

236 237
    LOG_TRACE(INFO, "EMM-PROC  - Initiate identification type = %s (%d), ctx = %p",
              _emm_identity_type_str[type], type, emm_ctx);
Cedric Roux's avatar
 
Cedric Roux committed
238 239

    /* Allocate parameters of the retransmission timer callback */
Cedric Roux's avatar
Cedric Roux committed
240 241
    identification_data_t *data =
        (identification_data_t *)malloc(sizeof(identification_data_t));
Cedric Roux's avatar
 
Cedric Roux committed
242 243

    if (data != NULL) {
Cedric Roux's avatar
Cedric Roux committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        /* Setup ongoing EMM procedure callback functions */
        rc = emm_proc_common_initialize(ueid, success, reject, failure,
                                        _identification_abort, data);
        if (rc != RETURNok) {
            LOG_TRACE(WARNING, "Failed to initialize EMM callback functions");
            free(data);
            LOG_FUNC_RETURN (RETURNerror);
        }
        /* Set the UE identifier */
        data->ueid = ueid;
        /* Reset the retransmission counter */
        data->retransmission_count = 0;
        /* Set the type of the requested identity */
        data->type = type;
        /* Set the failure notification indicator */
        data->notify_failure = FALSE;
        /* Send identity request message to the UE */
        rc = _identification_request(data);
        if (rc != RETURNerror) {
            /*
             * Notify EMM that common procedure has been initiated
             */
            emm_sap_t emm_sap;
            emm_sap.primitive = EMMREG_COMMON_PROC_REQ;
            emm_sap.u.emm_reg.ueid = ueid;
Cedric Roux's avatar
 
Cedric Roux committed
269
            emm_sap.u.emm_reg.ctx  = emm_ctx;
Cedric Roux's avatar
Cedric Roux committed
270 271
            rc = emm_sap_send(&emm_sap);
        }
Cedric Roux's avatar
 
Cedric Roux committed
272 273 274 275 276 277 278
    }

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
279
 ** Name:    emm_proc_identification_complete()                        **
Cedric Roux's avatar
 
Cedric Roux committed
280 281
 **                                                                        **
 ** Description: Performs the identification completion procedure executed **
Cedric Roux's avatar
Cedric Roux committed
282
 **      by the network.                                           **
Cedric Roux's avatar
 
Cedric Roux committed
283 284
 **                                                                        **
 **              3GPP TS 24.301, section 5.4.4.4                           **
Cedric Roux's avatar
Cedric Roux committed
285 286
 **      Upon receiving the IDENTITY RESPONSE message, the MME     **
 **      shall stop timer T3470.                                   **
Cedric Roux's avatar
 
Cedric Roux committed
287
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
288 289 290 291 292
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      imsi:      The IMSI received from the UE              **
 **      imei:      The IMEI received from the UE              **
 **      tmsi:      The TMSI received from the UE              **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
293
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
294 295 296
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data, T3470                           **
Cedric Roux's avatar
 
Cedric Roux committed
297 298
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
299 300
int emm_proc_identification_complete(unsigned int ueid, const imsi_t *imsi,
                                     const imei_t *imei, UInt32_t *tmsi)
Cedric Roux's avatar
 
Cedric Roux committed
301 302 303 304
{
    int rc = RETURNerror;
    emm_sap_t emm_sap;

Cedric Roux's avatar
Cedric Roux committed
305
    emm_data_context_t *emm_ctx = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
306 307 308 309 310 311 312 313 314 315

    LOG_FUNC_IN;

    LOG_TRACE(INFO, "EMM-PROC  - Identification complete (ueid=%u)", ueid);

    /* Stop timer T3470 */
    LOG_TRACE(INFO, "EMM-PROC  - Stop timer T3470 (%d)", T3470.id);
    T3470.id = nas_timer_stop(T3470.id);

    /* Release retransmission timer paramaters */
Cedric Roux's avatar
Cedric Roux committed
316 317 318 319 320
    identification_data_t *data =
        (identification_data_t *)(emm_proc_common_get_args(ueid));
    if (data) {
        free(data);
    }
Cedric Roux's avatar
 
Cedric Roux committed
321 322 323 324 325 326 327 328 329 330 331 332 333

    /* Get the UE context */
#if defined(EPC_BUILD)
    if (ueid > 0) {
        emm_ctx = emm_data_context_get(&_emm_data, ueid);
    }
#else
    if (ueid < EMM_DATA_NB_UE_MAX) {
        emm_ctx = _emm_data.ctx[ueid];
    }
#endif

    if (emm_ctx) {
Cedric Roux's avatar
Cedric Roux committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
        if (imsi) {
            /* Update the IMSI */
            if (emm_ctx->imsi == NULL) {
                emm_ctx->imsi = (imsi_t *)malloc(sizeof(imsi_t));
            }
            if (emm_ctx->imsi) {
                memcpy(emm_ctx->imsi, imsi, sizeof(imsi_t));
            }
        } else if (imei) {
            /* Update the IMEI */
            if (emm_ctx->imei == NULL) {
                emm_ctx->imei = (imei_t *)malloc(sizeof(imei_t));
            }
            if (emm_ctx->imei) {
                memcpy(emm_ctx->imei, imei, sizeof(imei_t));
            }
        } else if (tmsi) {
            /* Update the GUTI */
            if (emm_ctx->guti == NULL) {
                emm_ctx->guti = (GUTI_t *)malloc(sizeof(GUTI_t));
            }
            if (emm_ctx->guti) {
                memcpy(&emm_ctx->guti->gummei,
                       &_emm_data.conf.gummei, sizeof(gummei_t));
                emm_ctx->guti->m_tmsi = *tmsi;
            }
        }
        /*
         * Notify EMM that the identification procedure successfully completed
         */
        emm_sap.primitive = EMMREG_COMMON_PROC_CNF;
        emm_sap.u.emm_reg.ueid = ueid;
366
        emm_sap.u.emm_reg.ctx  = emm_ctx;
Cedric Roux's avatar
Cedric Roux committed
367 368 369 370 371 372 373 374
        emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached;
    } else {
        LOG_TRACE(ERROR, "EMM-PROC  - No EMM context exists");
        /*
         * Notify EMM that the identification procedure failed
         */
        emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
        emm_sap.u.emm_reg.ueid = ueid;
375
        emm_sap.u.emm_reg.ctx  = emm_ctx;
Cedric Roux's avatar
 
Cedric Roux committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    }

    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN (rc);
}

#endif // NAS_MME

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

#ifdef NAS_MME
/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
392
 *              Timer handlers
Cedric Roux's avatar
 
Cedric Roux committed
393 394 395 396 397
 * --------------------------------------------------------------------------
 */

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
398
 ** Name:    _identification_t3470_handler()                           **
Cedric Roux's avatar
 
Cedric Roux committed
399 400
 **                                                                        **
 ** Description: T3470 timeout handler                                     **
Cedric Roux's avatar
Cedric Roux committed
401 402 403 404
 **      Upon T3470 timer expiration, the identification request   **
 **      message is retransmitted and the timer restarted. When    **
 **      retransmission counter is exceed, the MME shall abort the **
 **      identification procedure and any ongoing EMM procedure.   **
Cedric Roux's avatar
 
Cedric Roux committed
405 406 407
 **                                                                        **
 **              3GPP TS 24.301, section 5.4.4.6, case b                   **
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
408 409
 ** Inputs:  args:      handler parameters                         **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
410
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
411 412 413
 ** Outputs:     None                                                      **
 **      Return:    None                                       **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
414 415
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
416
static void *_identification_t3470_handler(void *args)
Cedric Roux's avatar
 
Cedric Roux committed
417 418 419 420 421
{
    LOG_FUNC_IN;

    int rc;

Cedric Roux's avatar
Cedric Roux committed
422
    identification_data_t *data = (identification_data_t *)(args);
Cedric Roux's avatar
 
Cedric Roux committed
423 424 425 426 427

    /* Increment the retransmission counter */
    data->retransmission_count += 1;

    LOG_TRACE(WARNING, "EMM-PROC  - T3470 timer expired, retransmission "
Cedric Roux's avatar
Cedric Roux committed
428
              "counter = %d", data->retransmission_count);
Cedric Roux's avatar
 
Cedric Roux committed
429 430

    if (data->retransmission_count < IDENTIFICATION_COUNTER_MAX) {
Cedric Roux's avatar
Cedric Roux committed
431 432 433 434 435 436 437
        /* Send identity request message to the UE */
        rc = _identification_request(data);
    } else {
        /* Set the failure notification indicator */
        data->notify_failure = TRUE;
        /* Abort the identification procedure */
        rc = _identification_abort(data);
Cedric Roux's avatar
 
Cedric Roux committed
438 439 440 441 442 443 444
    }

    LOG_FUNC_RETURN (NULL);
}

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
445
 *              MME specific local functions
Cedric Roux's avatar
 
Cedric Roux committed
446 447 448 449 450
 * --------------------------------------------------------------------------
 */

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
451
 ** Name:    _identification_request()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
452 453 454
 **                                                                        **
 ** Description: Sends IDENTITY REQUEST message and start timer T3470.     **
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
455 456
 ** Inputs:  args:      handler parameters                         **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
457
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
458 459 460
 ** Outputs:     None                                                      **
 **      Return:    None                                       **
 **      Others:    T3470                                      **
Cedric Roux's avatar
 
Cedric Roux committed
461 462
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
463
int _identification_request(identification_data_t *data)
Cedric Roux's avatar
 
Cedric Roux committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
{
    emm_sap_t emm_sap;
    int rc;

    struct emm_data_context_s *emm_ctx = NULL;

    LOG_FUNC_IN;

    /*
     * Notify EMM-AS SAP that Identity Request message has to be sent
     * to the UE
     */
    emm_sap.primitive = EMMAS_SECURITY_REQ;
    emm_sap.u.emm_as.u.security.guti = NULL;
    emm_sap.u.emm_as.u.security.ueid = data->ueid;
    emm_sap.u.emm_as.u.security.msgType = EMM_AS_MSG_TYPE_IDENT;
    emm_sap.u.emm_as.u.security.identType = data->type;

#if defined(EPC_BUILD)
    if (data->ueid > 0) {
        emm_ctx = emm_data_context_get(&_emm_data, data->ueid);
    }
#else
    if (data->ueid < EMM_DATA_NB_UE_MAX) {
        emm_ctx = _emm_data.ctx[data->ueid];
    }
#endif
    /* Setup EPS NAS security data */
    emm_as_set_security_data(&emm_sap.u.emm_as.u.security.sctx,
                             emm_ctx->security, FALSE, TRUE);
    rc = emm_sap_send(&emm_sap);

    if (rc != RETURNerror) {
Cedric Roux's avatar
Cedric Roux committed
497 498 499 500 501 502 503 504 505 506
        if (T3470.id != NAS_TIMER_INACTIVE_ID) {
            /* Re-start T3470 timer */
            T3470.id = nas_timer_restart(T3470.id);
        } else {
            /* Start T3470 timer */
            T3470.id = nas_timer_start(T3470.sec, _identification_t3470_handler,
                                       data);
        }
        LOG_TRACE(INFO,"EMM-PROC  - Timer T3470 (%d) expires in %ld seconds",
                  T3470.id, T3470.sec);
Cedric Roux's avatar
 
Cedric Roux committed
507 508 509 510 511 512 513
    }

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
514
 ** Name:    _identification_abort()                                   **
Cedric Roux's avatar
 
Cedric Roux committed
515 516 517
 **                                                                        **
 ** Description: Aborts the identification procedure currently in progress **
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
518 519
 ** Inputs:  args:      Identification data to be released         **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
520
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
521 522 523
 ** Outputs:     None                                                      **
 **      Return:    None                                       **
 **      Others:    T3470                                      **
Cedric Roux's avatar
 
Cedric Roux committed
524 525
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
526
static int _identification_abort(void *args)
Cedric Roux's avatar
 
Cedric Roux committed
527 528 529 530 531
{
    LOG_FUNC_IN;

    int rc = RETURNerror;

Cedric Roux's avatar
Cedric Roux committed
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
    identification_data_t *data = (identification_data_t *)(args);

    if (data) {
        unsigned int ueid = data->ueid;
        int notify_failure = data->notify_failure;

        LOG_TRACE(WARNING, "EMM-PROC  - Abort identification procedure "
                  "(ueid=%u)", ueid);

        /* Stop timer T3470 */
        if (T3470.id != NAS_TIMER_INACTIVE_ID) {
            LOG_TRACE(INFO, "EMM-PROC  - Stop timer T3470 (%d)", T3470.id);
            T3470.id = nas_timer_stop(T3470.id);
        }
        /* Release retransmission timer paramaters */
        free(data);

        /*
         * Notify EMM that the identification procedure failed
         */
        if (notify_failure) {
            emm_sap_t emm_sap;
            emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
            emm_sap.u.emm_reg.ueid = ueid;
            rc = emm_sap_send(&emm_sap);
        } else {
            rc = RETURNok;
        }
Cedric Roux's avatar
 
Cedric Roux committed
560 561 562 563 564 565 566
    }

    LOG_FUNC_RETURN(rc);
}

#endif // NAS_MME