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

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

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

9
Date        2013/01/30
Cedric Roux's avatar
 
Cedric Roux committed
10

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

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

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

17 18 19
Description Defines functions executed at the EMMAS Service Access
        Point upon receiving EPS Mobility Management messages
        from the Access Stratum sublayer.
Cedric Roux's avatar
 
Cedric Roux committed
20 21 22 23 24 25 26 27 28 29 30

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

#include "emm_recv.h"
#include "commonDef.h"
#include "nas_log.h"

#include "emm_msgDef.h"
#include "emm_cause.h"
#include "emm_proc.h"

31
#include <string.h> // memcpy
Cedric Roux's avatar
 
Cedric Roux committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

/****************************************************************************/
/****************  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  *******************/
/****************************************************************************/

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

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

/*
 * --------------------------------------------------------------------------
 * Functions executed by both the UE and the MME upon receiving EMM messages
 * --------------------------------------------------------------------------
 */
/****************************************************************************
 **                                                                        **
56
 ** Name:    emm_recv_status()                                         **
Cedric Roux's avatar
 
Cedric Roux committed
57 58 59
 **                                                                        **
 ** Description: Processes EMM status message                              **
 **                                                                        **
60 61 62
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **          msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
63
 **                                                                        **
64 65 66
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
67 68
 **                                                                        **
 ***************************************************************************/
69
int emm_recv_status(unsigned int ueid, emm_status_msg *msg, int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
70 71 72 73 74 75
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received EMM Status message (cause=%d)",
76
              msg->emmcause);
Cedric Roux's avatar
 
Cedric Roux committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    /*
     * Message checking
     */
    *emm_cause = EMM_CAUSE_SUCCESS;
    /*
     * Message processing
     */
    rc = emm_proc_status_ind(ueid, msg->emmcause);

    LOG_FUNC_RETURN (rc);
}

/*
 * --------------------------------------------------------------------------
 * Functions executed by the UE upon receiving EMM message from the network
 * --------------------------------------------------------------------------
 */
#ifdef NAS_UE
/****************************************************************************
 **                                                                        **
98
 ** Name:    emm_recv_attach_accept()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
99 100 101
 **                                                                        **
 ** Description: Processes Attach Accept message                           **
 **                                                                        **
102 103
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
104
 **                                                                        **
105 106 107
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
108 109
 **                                                                        **
 ***************************************************************************/
110
int emm_recv_attach_accept(attach_accept_msg *msg, int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
111 112 113 114
{
    LOG_FUNC_IN;

    int rc;
115
    int i;
Cedric Roux's avatar
 
Cedric Roux committed
116 117 118 119 120 121 122

    LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Accept message");

    /*
     * Message checking
     */
    if (msg->tailist.typeoflist !=
123 124 125 126 127 128 129 130
            TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS) {
        /* Only list of TACs belonging to one PLMN with consecutive
         * TAC values is supported */
        *emm_cause = EMM_CAUSE_IE_NOT_IMPLEMENTED;
    } else if ( (msg->presencemask & ATTACH_ACCEPT_GUTI_PRESENT) &&
                (msg->guti.guti.typeofidentity != EPS_MOBILE_IDENTITY_GUTI) ) {
        /* The only supported type of EPS mobile identity is GUTI */
        *emm_cause = EMM_CAUSE_IE_NOT_IMPLEMENTED;
Cedric Roux's avatar
 
Cedric Roux committed
131 132 133
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
134
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
135 136 137 138 139 140 141 142 143
    }

    /*
     * Message processing
     */
    /* Compute timers value */
    long T3412, T3402 = -1, T3423 = -1;
    T3412 = gprs_timer_value(&msg->t3412value);
    if (msg->presencemask & ATTACH_ACCEPT_T3402_VALUE_PRESENT) {
144
        T3402 = gprs_timer_value(&msg->t3402value);
Cedric Roux's avatar
 
Cedric Roux committed
145 146
    }
    if (msg->presencemask & ATTACH_ACCEPT_T3423_VALUE_PRESENT) {
147
        T3423 = gprs_timer_value(&msg->t3423value);
Cedric Roux's avatar
 
Cedric Roux committed
148 149
    }
    /* Get the tracking area list the UE is registered to */
150 151 152 153

    /* LW: number of elements is coded as N-1 (0 -> 1 element, 1 -> 2 elements...),
     *  see 3GPP TS 24.301, section 9.9.3.33.1 */
    int n_tais = msg->tailist.numberofelements + 1;
Cedric Roux's avatar
 
Cedric Roux committed
154
    tai_t tai[n_tais];
155
    for (i = 0; i < n_tais; i++) {
156 157 158 159 160 161 162
        tai[i].plmn.MCCdigit1 = msg->tailist.mccdigit1;
        tai[i].plmn.MCCdigit2 = msg->tailist.mccdigit2;
        tai[i].plmn.MCCdigit3 = msg->tailist.mccdigit3;
        tai[i].plmn.MNCdigit1 = msg->tailist.mncdigit1;
        tai[i].plmn.MNCdigit2 = msg->tailist.mncdigit2;
        tai[i].plmn.MNCdigit3 = msg->tailist.mncdigit3;
        tai[i].tac = msg->tailist.tac + i;
Cedric Roux's avatar
 
Cedric Roux committed
163 164
    }
    /* Get the GUTI */
165
    GUTI_t *pguti = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
166 167
    GUTI_t guti;
    if (msg->presencemask & ATTACH_ACCEPT_GUTI_PRESENT) {
168 169 170 171 172 173 174 175 176 177
        pguti = &guti;
        guti.gummei.plmn.MCCdigit1 = msg->guti.guti.mccdigit1;
        guti.gummei.plmn.MCCdigit2 = msg->guti.guti.mccdigit2;
        guti.gummei.plmn.MCCdigit3 = msg->guti.guti.mccdigit3;
        guti.gummei.plmn.MNCdigit1 = msg->guti.guti.mncdigit1;
        guti.gummei.plmn.MNCdigit2 = msg->guti.guti.mncdigit2;
        guti.gummei.plmn.MNCdigit3 = msg->guti.guti.mncdigit3;
        guti.gummei.MMEgid = msg->guti.guti.mmegroupid;
        guti.gummei.MMEcode = msg->guti.guti.mmecode;
        guti.m_tmsi = msg->guti.guti.mtmsi;
Cedric Roux's avatar
 
Cedric Roux committed
178 179 180 181 182
    }
    /* Get the list of equivalent PLMNs */
    int n_eplmns = 0;
    plmn_t eplmn;
    if (msg->presencemask & ATTACH_ACCEPT_EQUIVALENT_PLMNS_PRESENT) {
183 184 185 186 187 188 189
        n_eplmns = 1;
        eplmn.MCCdigit1 = msg->equivalentplmns.mccdigit1;
        eplmn.MCCdigit2 = msg->equivalentplmns.mccdigit2;
        eplmn.MCCdigit3 = msg->equivalentplmns.mccdigit3;
        eplmn.MNCdigit1 = msg->equivalentplmns.mncdigit1;
        eplmn.MNCdigit2 = msg->equivalentplmns.mncdigit2;
        eplmn.MNCdigit3 = msg->equivalentplmns.mncdigit3;
Cedric Roux's avatar
 
Cedric Roux committed
190 191 192 193
    }

    /* Execute attach procedure accepted by the network */
    rc = emm_proc_attach_accept(T3412, T3402, T3423, n_tais, tai, pguti,
194 195
                                n_eplmns, &eplmn,
                                &msg->esmmessagecontainer.esmmessagecontainercontents);
Cedric Roux's avatar
 
Cedric Roux committed
196 197 198 199 200 201

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
202
 ** Name:    emm_recv_attach_reject()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
203 204 205
 **                                                                        **
 ** Description: Processes Attach Reject message                           **
 **                                                                        **
206 207
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
208
 **                                                                        **
209 210 211
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
212 213
 **                                                                        **
 ***************************************************************************/
214
int emm_recv_attach_reject(attach_reject_msg *msg, int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
215 216 217 218 219 220
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Reject message (cause=%d)",
221
              msg->emmcause);
Cedric Roux's avatar
 
Cedric Roux committed
222 223 224 225 226

    /*
     * Message checking
     */
    if ( (msg->emmcause == EMM_CAUSE_ESM_FAILURE) &&
227 228 229 230 231
            !(msg->presencemask & ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) ) {
        /* The ATTACH REJECT message shall be combined with a PDN
         * CONNECTIVITY REJECT message contained in the ESM message
         * container information element */
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
232 233 234
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
235
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
236 237 238 239 240 241
    }

    /*
     * Message processing
     */
    if (msg->presencemask & ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) {
242 243 244
        /* Execute attach procedure rejected by the network */
        rc = emm_proc_attach_reject(msg->emmcause,
                                    &msg->esmmessagecontainer.esmmessagecontainercontents);
Cedric Roux's avatar
 
Cedric Roux committed
245
    } else {
246 247
        /* Execute attach procedure rejected by the network */
        rc = emm_proc_attach_reject(msg->emmcause, NULL);
Cedric Roux's avatar
 
Cedric Roux committed
248 249 250 251 252 253 254
    }

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
255
 ** Name:    emm_recv_detach_accept()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
256 257 258
 **                                                                        **
 ** Description: Processes Detach Accept message                           **
 **                                                                        **
259 260
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
261
 **                                                                        **
262 263 264
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
265 266
 **                                                                        **
 ***************************************************************************/
267
int emm_recv_detach_accept(detach_accept_msg *msg, int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Detach Accept message");

    /*
     * Message processing
     */
    /* Execute the UE initiated detach procedure completion by the UE */
    rc = emm_proc_detach_accept();

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
286
 ** Name:    emm_recv_identity_request()                               **
Cedric Roux's avatar
 
Cedric Roux committed
287 288 289
 **                                                                        **
 ** Description: Processes Identity Request message                        **
 **                                                                        **
290 291
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
292
 **                                                                        **
293 294 295
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
296 297
 **                                                                        **
 ***************************************************************************/
298
int emm_recv_identity_request(identity_request_msg *msg, int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
299 300 301 302 303 304 305 306 307 308 309 310 311
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Identity Request message");

    /*
     * Message processing
     */
    /* Get the requested identity type */
    emm_proc_identity_type_t type;
    if (msg->identitytype == IDENTITY_TYPE_2_IMSI) {
312
        type = EMM_IDENT_TYPE_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
313
    } else if (msg->identitytype == IDENTITY_TYPE_2_IMEI) {
314
        type = EMM_IDENT_TYPE_IMEI;
Cedric Roux's avatar
 
Cedric Roux committed
315
    } else if (msg->identitytype == IDENTITY_TYPE_2_IMEISV) {
316
        type = EMM_IDENT_TYPE_IMEISV;
Cedric Roux's avatar
 
Cedric Roux committed
317
    } else if (msg->identitytype == IDENTITY_TYPE_2_TMSI) {
318
        type = EMM_IDENT_TYPE_TMSI;
Cedric Roux's avatar
 
Cedric Roux committed
319
    } else {
320 321
        /* All other values are interpreted as IMSI */
        type = EMM_IDENT_TYPE_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
322 323 324 325 326 327 328 329 330 331
    }

    /* Execute the identification procedure initiated by the network */
    rc = emm_proc_identification_request(type);

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
332
 ** Name:    emm_recv_authentication_request()                         **
Cedric Roux's avatar
 
Cedric Roux committed
333 334 335
 **                                                                        **
 ** Description: Processes Authentication Request message                  **
 **                                                                        **
336 337
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
338
 **                                                                        **
339 340 341
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
342 343
 **                                                                        **
 ***************************************************************************/
344 345
int emm_recv_authentication_request(authentication_request_msg *msg,
                                    int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
346 347 348 349 350 351 352 353 354 355 356
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Request message");

    /*
     * Message checking
     */
    if ( (msg->authenticationparameterrand.rand.length == 0) ||
357 358 359
            (msg->authenticationparameterautn.autn.length == 0) ) {
        /* RAND and AUTN parameters shall not be null */
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
360 361 362
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
363
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
364 365 366 367 368 369
    }
    /*
     * Message processing
     */
    /* Execute the authentication procedure initiated by the network */
    rc = emm_proc_authentication_request(
370 371 372 373
             msg->naskeysetidentifierasme.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
             msg->naskeysetidentifierasme.naskeysetidentifier,
             &msg->authenticationparameterrand.rand,
             &msg->authenticationparameterautn.autn);
Cedric Roux's avatar
 
Cedric Roux committed
374 375 376 377 378 379

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
380
 ** Name:    emm_recv_authentication_reject()                          **
Cedric Roux's avatar
 
Cedric Roux committed
381 382 383
 **                                                                        **
 ** Description: Processes Authentication Reject message                   **
 **                                                                        **
384 385
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
386
 **                                                                        **
387 388 389
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
390 391
 **                                                                        **
 ***************************************************************************/
392 393
int emm_recv_authentication_reject(authentication_reject_msg *msg,
                                   int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Reject message");

    /*
     * Message processing
     */
    /* Execute the authentication procedure not accepted by the network */
    rc = emm_proc_authentication_reject();

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
412
 ** Name:    emm_recv_security_mode_command()                          **
Cedric Roux's avatar
 
Cedric Roux committed
413 414 415
 **                                                                        **
 ** Description: Processes Security Mode Command message                   **
 **                                                                        **
416 417
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
418
 **                                                                        **
419 420 421
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
422 423
 **                                                                        **
 ***************************************************************************/
424 425
int emm_recv_security_mode_command(security_mode_command_msg *msg,
                                   int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
426 427 428 429 430 431 432 433 434 435 436 437
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Security Mode Command message");

    /*
     * Message processing
     */
    /* Execute the security mode control procedure initiated by the network */
    rc = emm_proc_security_mode_command(
438 439 440 441 442 443
             msg->naskeysetidentifier.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
             msg->naskeysetidentifier.naskeysetidentifier,
             msg->selectednassecurityalgorithms.typeofcipheringalgorithm,
             msg->selectednassecurityalgorithms.typeofintegrityalgorithm,
             msg->replayeduesecuritycapabilities.eea,
             msg->replayeduesecuritycapabilities.eia);
Cedric Roux's avatar
 
Cedric Roux committed
444 445 446 447

    LOG_FUNC_RETURN (rc);
}

448
#endif  // NAS_UE
Cedric Roux's avatar
 
Cedric Roux committed
449 450 451 452 453 454 455 456 457

/*
 * --------------------------------------------------------------------------
 * Functions executed by the MME upon receiving EMM message from the UE
 * --------------------------------------------------------------------------
 */
#ifdef NAS_MME
/****************************************************************************
 **                                                                        **
458
 ** Name:    emm_recv_attach_request()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
459 460 461
 **                                                                        **
 ** Description: Processes Attach Request message                          **
 **                                                                        **
462 463 464
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
465
 **                                                                        **
466 467 468
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
469 470
 **                                                                        **
 ***************************************************************************/
471 472
int emm_recv_attach_request(unsigned int ueid, const attach_request_msg *msg,
                            int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486
{
    int rc;
    emm_proc_attach_type_t type;

    LOG_FUNC_IN;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Request message");

    /*
     * Message checking
     */
#if !defined(UPDATE_RELEASE_9)
    /* SR: In releases 9 and beyond the mandatory ie (old GUTI) has been removed */
    if ( (msg->oldgutiorimsi.guti.typeofidentity == EPS_MOBILE_IDENTITY_GUTI) &&
487 488 489 490
            !(msg->presencemask & ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT) ) {
        /* The Old GUTI type IE shall be included if the type of identity
         * in the EPS mobile identity IE is set to "GUTI" */
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
491 492
        LOG_TRACE(WARNING, "EMMAS-SAP - [%08x] - Received GUTI identity without "
                  "old GUTI IEI", ueid);
493
    } else
Cedric Roux's avatar
 
Cedric Roux committed
494
#endif /* !defined(UPDATE_RELEASE_9) */
495 496 497 498 499 500
        if (msg->uenetworkcapability.spare != 0b000) {
            /* Spare bits shall be coded as zero */
            *emm_cause = EMM_CAUSE_PROTOCOL_ERROR;
            LOG_TRACE(WARNING, "EMMAS-SAP - [%08x] - Non zero spare bits is suspicious",
                      ueid);
        }
Cedric Roux's avatar
 
Cedric Roux committed
501 502
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
503 504 505 506 507
        /* 3GPP TS 24.301, section 5.5.1.2.7, case b
         * Perform protocol error abnormal case on the network side */
        rc = emm_proc_attach_reject(ueid, *emm_cause);
        *emm_cause = EMM_CAUSE_SUCCESS;
        LOG_FUNC_RETURN (rc);
Cedric Roux's avatar
 
Cedric Roux committed
508 509 510 511 512 513
    }
    /*
     * Message processing
     */
    /* Get the EPS attach type */
    if (msg->epsattachtype == EPS_ATTACH_TYPE_EPS) {
514
        type = EMM_ATTACH_TYPE_EPS;
Cedric Roux's avatar
 
Cedric Roux committed
515
    } else if (msg->epsattachtype == EPS_ATTACH_TYPE_IMSI) {
516
        type = EMM_ATTACH_TYPE_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
517
    } else if (msg->epsattachtype == EPS_ATTACH_TYPE_EMERGENCY) {
518
        type = EMM_ATTACH_TYPE_EMERGENCY;
Cedric Roux's avatar
 
Cedric Roux committed
519
    } else if (msg->epsattachtype == EPS_ATTACH_TYPE_RESERVED) {
520
        type = EMM_ATTACH_TYPE_RESERVED;
Cedric Roux's avatar
 
Cedric Roux committed
521
    } else {
522 523
        /* All other values shall be interpreted as "EPS attach" */
        type = EMM_ATTACH_TYPE_EPS;
Cedric Roux's avatar
 
Cedric Roux committed
524 525 526 527 528 529
    }

    /* Get the EPS mobile identity */
    GUTI_t guti, *p_guti = NULL;
    imsi_t imsi, *p_imsi = NULL;
    imei_t imei, *p_imei = NULL;
530 531 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 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
    if (msg->oldgutiorimsi.guti.typeofidentity == EPS_MOBILE_IDENTITY_GUTI) {
        /* Get the GUTI */
        p_guti = &guti;
        guti.gummei.plmn.MCCdigit1 = msg->oldgutiorimsi.guti.mccdigit1;
        guti.gummei.plmn.MCCdigit2 = msg->oldgutiorimsi.guti.mccdigit2;
        guti.gummei.plmn.MCCdigit3 = msg->oldgutiorimsi.guti.mccdigit3;
        guti.gummei.plmn.MNCdigit1 = msg->oldgutiorimsi.guti.mncdigit1;
        guti.gummei.plmn.MNCdigit2 = msg->oldgutiorimsi.guti.mncdigit2;
        guti.gummei.plmn.MNCdigit3 = msg->oldgutiorimsi.guti.mncdigit3;
        guti.gummei.MMEgid = msg->oldgutiorimsi.guti.mmegroupid;
        guti.gummei.MMEcode = msg->oldgutiorimsi.guti.mmecode;
        guti.m_tmsi = msg->oldgutiorimsi.guti.mtmsi;
    } else if (msg->oldgutiorimsi.imsi.typeofidentity == EPS_MOBILE_IDENTITY_IMSI) {
        /* Get the IMSI */
        p_imsi = &imsi;
        imsi.u.num.digit1 = msg->oldgutiorimsi.imsi.digit1;
        imsi.u.num.digit2 = msg->oldgutiorimsi.imsi.digit2;
        imsi.u.num.digit3 = msg->oldgutiorimsi.imsi.digit3;
        imsi.u.num.digit4 = msg->oldgutiorimsi.imsi.digit4;
        imsi.u.num.digit5 = msg->oldgutiorimsi.imsi.digit5;
        imsi.u.num.digit6 = msg->oldgutiorimsi.imsi.digit6;
        imsi.u.num.digit7 = msg->oldgutiorimsi.imsi.digit7;
        imsi.u.num.digit8 = msg->oldgutiorimsi.imsi.digit8;
        imsi.u.num.digit9 = msg->oldgutiorimsi.imsi.digit9;
        imsi.u.num.digit10 = msg->oldgutiorimsi.imsi.digit10;
        imsi.u.num.digit11 = msg->oldgutiorimsi.imsi.digit11;
        imsi.u.num.digit12 = msg->oldgutiorimsi.imsi.digit12;
        imsi.u.num.digit13 = msg->oldgutiorimsi.imsi.digit13;
        imsi.u.num.digit14 = msg->oldgutiorimsi.imsi.digit14;
        imsi.u.num.digit15 = msg->oldgutiorimsi.imsi.digit15;
        imsi.u.num.parity = msg->oldgutiorimsi.imsi.oddeven;
    } else if (msg->oldgutiorimsi.imei.typeofidentity == EPS_MOBILE_IDENTITY_IMEI) {
        /* Get the IMEI */
        p_imei = &imei;
        imei.u.num.digit1 = msg->oldgutiorimsi.imei.digit1;
        imei.u.num.digit2 = msg->oldgutiorimsi.imei.digit2;
        imei.u.num.digit3 = msg->oldgutiorimsi.imei.digit3;
        imei.u.num.digit4 = msg->oldgutiorimsi.imei.digit4;
        imei.u.num.digit5 = msg->oldgutiorimsi.imei.digit5;
        imei.u.num.digit6 = msg->oldgutiorimsi.imei.digit6;
        imei.u.num.digit7 = msg->oldgutiorimsi.imei.digit7;
        imei.u.num.digit8 = msg->oldgutiorimsi.imei.digit8;
        imei.u.num.digit9 = msg->oldgutiorimsi.imei.digit9;
        imei.u.num.digit10 = msg->oldgutiorimsi.imei.digit10;
        imei.u.num.digit11 = msg->oldgutiorimsi.imei.digit11;
        imei.u.num.digit12 = msg->oldgutiorimsi.imei.digit12;
        imei.u.num.digit13 = msg->oldgutiorimsi.imei.digit13;
        imei.u.num.digit14 = msg->oldgutiorimsi.imei.digit14;
        imei.u.num.digit15 = msg->oldgutiorimsi.imei.digit15;
        imei.u.num.parity = msg->oldgutiorimsi.imei.oddeven;
Cedric Roux's avatar
 
Cedric Roux committed
580 581 582 583 584 585
    }
    /* TODO: Get the UE network capabilities */

    /* Get the Last visited registered TAI */
    tai_t tai, *p_tai  = NULL;
    if (msg->presencemask & ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT) {
586 587 588 589 590 591 592 593
        p_tai = &tai;
        tai.plmn.MCCdigit1 = msg->lastvisitedregisteredtai.mccdigit1;
        tai.plmn.MCCdigit2 = msg->lastvisitedregisteredtai.mccdigit2;
        tai.plmn.MCCdigit3 = msg->lastvisitedregisteredtai.mccdigit3;
        tai.plmn.MNCdigit1 = msg->lastvisitedregisteredtai.mncdigit1;
        tai.plmn.MNCdigit2 = msg->lastvisitedregisteredtai.mncdigit2;
        tai.plmn.MNCdigit3 = msg->lastvisitedregisteredtai.mncdigit3;
        tai.tac = msg->lastvisitedregisteredtai.tac;
Cedric Roux's avatar
 
Cedric Roux committed
594 595 596 597
    }

    /* Execute the requested UE attach procedure */
    rc = emm_proc_attach_request(ueid, type,
598 599 600 601 602
                                 msg->naskeysetidentifier.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
                                 msg->naskeysetidentifier.naskeysetidentifier,
                                 msg->oldgutitype != GUTI_MAPPED, p_guti, p_imsi, p_imei, p_tai,
                                 msg->uenetworkcapability.eea, msg->uenetworkcapability.eia,
                                 &msg->esmmessagecontainer.esmmessagecontainercontents);
Cedric Roux's avatar
 
Cedric Roux committed
603 604 605 606 607 608

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
609
 ** Name:    emm_recv_attach_complete()                                **
Cedric Roux's avatar
 
Cedric Roux committed
610 611 612
 **                                                                        **
 ** Description: Processes Attach Complete message                         **
 **                                                                        **
613 614 615
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
616
 **                                                                        **
617 618 619
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
620 621
 **                                                                        **
 ***************************************************************************/
622 623
int emm_recv_attach_complete(unsigned int ueid, const attach_complete_msg *msg,
                             int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
624 625 626 627 628 629 630 631 632
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Complete message");

    /* Execute the attach procedure completion */
    rc = emm_proc_attach_complete(ueid,
633
                                  &msg->esmmessagecontainer.esmmessagecontainercontents);
Cedric Roux's avatar
 
Cedric Roux committed
634 635 636 637 638 639

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
640
 ** Name:    emm_recv_detach_request()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
641 642 643
 **                                                                        **
 ** Description: Processes Detach Request message                          **
 **                                                                        **
644 645 646
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
647
 **                                                                        **
648 649 650
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
651 652
 **                                                                        **
 ***************************************************************************/
653 654
int emm_recv_detach_request(unsigned int ueid, const detach_request_msg *msg,
                            int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
655 656 657 658 659 660 661 662 663 664 665 666 667
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Detach Request message");

    /*
     * Message processing
     */
    /* Get the detach type */
    emm_proc_detach_type_t type;
    if (msg->detachtype.typeofdetach == DETACH_TYPE_EPS) {
668
        type = EMM_DETACH_TYPE_EPS;
Cedric Roux's avatar
 
Cedric Roux committed
669
    } else if (msg->detachtype.typeofdetach == DETACH_TYPE_IMSI) {
670
        type = EMM_DETACH_TYPE_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
671
    } else if (msg->detachtype.typeofdetach == DETACH_TYPE_EPS_IMSI) {
672
        type = EMM_DETACH_TYPE_EPS_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
673
    } else if (msg->detachtype.typeofdetach == DETACH_TYPE_RESERVED_1) {
674
        type = EMM_DETACH_TYPE_RESERVED;
Cedric Roux's avatar
 
Cedric Roux committed
675
    } else if (msg->detachtype.typeofdetach == DETACH_TYPE_RESERVED_2) {
676
        type = EMM_DETACH_TYPE_RESERVED;
Cedric Roux's avatar
 
Cedric Roux committed
677
    } else {
678 679
        /* All other values are interpreted as "combined EPS/IMSI detach" */
        type = DETACH_TYPE_EPS_IMSI;
Cedric Roux's avatar
 
Cedric Roux committed
680 681 682 683 684 685
    }

    /* Get the EPS mobile identity */
    GUTI_t guti, *p_guti = NULL;
    imsi_t imsi, *p_imsi = NULL;
    imei_t imei, *p_imei = NULL;
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 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 735
    if (msg->gutiorimsi.guti.typeofidentity == EPS_MOBILE_IDENTITY_GUTI) {
        /* Get the GUTI */
        p_guti = &guti;
        guti.gummei.plmn.MCCdigit1 = msg->gutiorimsi.guti.mccdigit1;
        guti.gummei.plmn.MCCdigit2 = msg->gutiorimsi.guti.mccdigit2;
        guti.gummei.plmn.MCCdigit3 = msg->gutiorimsi.guti.mccdigit3;
        guti.gummei.plmn.MNCdigit1 = msg->gutiorimsi.guti.mncdigit1;
        guti.gummei.plmn.MNCdigit2 = msg->gutiorimsi.guti.mncdigit2;
        guti.gummei.plmn.MNCdigit3 = msg->gutiorimsi.guti.mncdigit3;
        guti.gummei.MMEgid = msg->gutiorimsi.guti.mmegroupid;
        guti.gummei.MMEcode = msg->gutiorimsi.guti.mmecode;
        guti.m_tmsi = msg->gutiorimsi.guti.mtmsi;
    } else if (msg->gutiorimsi.imsi.typeofidentity == EPS_MOBILE_IDENTITY_IMSI) {
        /* Get the IMSI */
        p_imsi = &imsi;
        imsi.u.num.digit1 = msg->gutiorimsi.imsi.digit1;
        imsi.u.num.digit2 = msg->gutiorimsi.imsi.digit2;
        imsi.u.num.digit3 = msg->gutiorimsi.imsi.digit3;
        imsi.u.num.digit4 = msg->gutiorimsi.imsi.digit4;
        imsi.u.num.digit5 = msg->gutiorimsi.imsi.digit5;
        imsi.u.num.digit6 = msg->gutiorimsi.imsi.digit6;
        imsi.u.num.digit7 = msg->gutiorimsi.imsi.digit7;
        imsi.u.num.digit8 = msg->gutiorimsi.imsi.digit8;
        imsi.u.num.digit9 = msg->gutiorimsi.imsi.digit9;
        imsi.u.num.digit10 = msg->gutiorimsi.imsi.digit10;
        imsi.u.num.digit11 = msg->gutiorimsi.imsi.digit11;
        imsi.u.num.digit12 = msg->gutiorimsi.imsi.digit12;
        imsi.u.num.digit13 = msg->gutiorimsi.imsi.digit13;
        imsi.u.num.digit14 = msg->gutiorimsi.imsi.digit14;
        imsi.u.num.digit15 = msg->gutiorimsi.imsi.digit15;
        imsi.u.num.parity = msg->gutiorimsi.imsi.oddeven;
    } else if (msg->gutiorimsi.imei.typeofidentity == EPS_MOBILE_IDENTITY_IMEI) {
        /* Get the IMEI */
        p_imei = &imei;
        imei.u.num.digit1 = msg->gutiorimsi.imei.digit1;
        imei.u.num.digit2 = msg->gutiorimsi.imei.digit2;
        imei.u.num.digit3 = msg->gutiorimsi.imei.digit3;
        imei.u.num.digit4 = msg->gutiorimsi.imei.digit4;
        imei.u.num.digit5 = msg->gutiorimsi.imei.digit5;
        imei.u.num.digit6 = msg->gutiorimsi.imei.digit6;
        imei.u.num.digit7 = msg->gutiorimsi.imei.digit7;
        imei.u.num.digit8 = msg->gutiorimsi.imei.digit8;
        imei.u.num.digit9 = msg->gutiorimsi.imei.digit9;
        imei.u.num.digit10 = msg->gutiorimsi.imei.digit10;
        imei.u.num.digit11 = msg->gutiorimsi.imei.digit11;
        imei.u.num.digit12 = msg->gutiorimsi.imei.digit12;
        imei.u.num.digit13 = msg->gutiorimsi.imei.digit13;
        imei.u.num.digit14 = msg->gutiorimsi.imei.digit14;
        imei.u.num.digit15 = msg->gutiorimsi.imei.digit15;
        imei.u.num.parity = msg->gutiorimsi.imei.oddeven;
Cedric Roux's avatar
 
Cedric Roux committed
736 737 738 739
    }

    /* Execute the UE initiated detach procedure completion by the network */
    rc = emm_proc_detach_request(ueid, type,
740 741 742 743
                                 msg->detachtype.switchoff != DETACH_TYPE_NORMAL_DETACH,
                                 msg->naskeysetidentifier.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
                                 msg->naskeysetidentifier.naskeysetidentifier,
                                 p_guti, p_imsi, p_imei);
Cedric Roux's avatar
 
Cedric Roux committed
744 745 746 747

    LOG_FUNC_RETURN (rc);
}

748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
/****************************************************************************
 **                                                                        **
 ** Name:        emm_recv_tracking_area_update_request()                   **
 **                                                                        **
 ** Description: Processes Tracking Area Update Request message            **
 **                                                                        **
 ** Inputs:      ueid:          UE lower layer identifier                  **
 **              msg:           The received EMM message                   **
 **              Others:        None                                       **
 **                                                                        **
 ** Outputs:     emm_cause:     EMM cause code                             **
 **              Return:        RETURNok, RETURNerror                      **
 **              Others:        None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_tracking_area_update_request(unsigned int  ueid,
                                          const tracking_area_update_request_msg *msg,
                                          int *emm_cause)
{
    int rc = RETURNok;

    LOG_FUNC_IN;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Tracking Area Update Request message");

    /* LW: Not completely implemented; send a Received Tracking Area Update Reject to induce a Attach Request from UE! */
    rc = emm_proc_tracking_area_update_reject(ueid, EMM_CAUSE_IMPLICITLY_DETACHED);

    LOG_FUNC_RETURN (rc);
}

Cedric Roux's avatar
 
Cedric Roux committed
779 780
/****************************************************************************
 **                                                                        **
781
 ** Name:    emm_recv_identity_response()                              **
Cedric Roux's avatar
 
Cedric Roux committed
782 783 784
 **                                                                        **
 ** Description: Processes Identity Response message                       **
 **                                                                        **
785 786 787
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
788
 **                                                                        **
789 790 791
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
792 793
 **                                                                        **
 ***************************************************************************/
794 795
int emm_recv_identity_response(unsigned int ueid, identity_response_msg *msg,
                               int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809
{
    LOG_FUNC_IN;

    int rc = RETURNok;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Identity Response message");

    /*
     * Message processing
     */
    /* Get the mobile identity */
    imsi_t imsi, *p_imsi = NULL;
    imei_t imei, *p_imei = NULL;
    struct tmsi_struct_t {
810 811 812 813 814 815 816 817
        uint8_t  digit1:4;
        uint8_t  digit2:4;
        uint8_t  digit3:4;
        uint8_t  digit4:4;
        uint8_t  digit5:4;
        uint8_t  digit6:4;
        uint8_t  digit7:4;
        uint8_t  digit8:4;
Cedric Roux's avatar
 
Cedric Roux committed
818 819
    } tmsi, *p_tmsi = NULL;
    if (msg->mobileidentity.imsi.typeofidentity == MOBILE_IDENTITY_IMSI) {
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
        /* Get the IMSI */
        p_imsi = &imsi;
        imsi.u.num.digit1 = msg->mobileidentity.imsi.digit1;
        imsi.u.num.digit2 = msg->mobileidentity.imsi.digit2;
        imsi.u.num.digit3 = msg->mobileidentity.imsi.digit3;
        imsi.u.num.digit4 = msg->mobileidentity.imsi.digit4;
        imsi.u.num.digit5 = msg->mobileidentity.imsi.digit5;
        imsi.u.num.digit6 = msg->mobileidentity.imsi.digit6;
        imsi.u.num.digit7 = msg->mobileidentity.imsi.digit7;
        imsi.u.num.digit8 = msg->mobileidentity.imsi.digit8;
        imsi.u.num.digit9 = msg->mobileidentity.imsi.digit9;
        imsi.u.num.digit10 = msg->mobileidentity.imsi.digit10;
        imsi.u.num.digit11 = msg->mobileidentity.imsi.digit11;
        imsi.u.num.digit12 = msg->mobileidentity.imsi.digit12;
        imsi.u.num.digit13 = msg->mobileidentity.imsi.digit13;
        imsi.u.num.digit14 = msg->mobileidentity.imsi.digit14;
        imsi.u.num.digit15 = msg->mobileidentity.imsi.digit15;
        imsi.u.num.parity = msg->mobileidentity.imsi.oddeven;
    } else if ((msg->mobileidentity.imei.typeofidentity == MOBILE_IDENTITY_IMEI) ||
               (msg->mobileidentity.imeisv.typeofidentity==MOBILE_IDENTITY_IMEISV)) {
        /* Get the IMEI */
        p_imei = &imei;
        imei.u.num.digit1 = msg->mobileidentity.imei.digit1;
        imei.u.num.digit2 = msg->mobileidentity.imei.digit2;
        imei.u.num.digit3 = msg->mobileidentity.imei.digit3;
        imei.u.num.digit4 = msg->mobileidentity.imei.digit4;
        imei.u.num.digit5 = msg->mobileidentity.imei.digit5;
        imei.u.num.digit6 = msg->mobileidentity.imei.digit6;
        imei.u.num.digit7 = msg->mobileidentity.imei.digit7;
        imei.u.num.digit8 = msg->mobileidentity.imei.digit8;
        imei.u.num.digit9 = msg->mobileidentity.imei.digit9;
        imei.u.num.digit10 = msg->mobileidentity.imei.digit10;
        imei.u.num.digit11 = msg->mobileidentity.imei.digit11;
        imei.u.num.digit12 = msg->mobileidentity.imei.digit12;
        imei.u.num.digit13 = msg->mobileidentity.imei.digit13;
        imei.u.num.digit14 = msg->mobileidentity.imei.digit14;
        imei.u.num.digit15 = msg->mobileidentity.imei.digit15;
        imei.u.num.parity = msg->mobileidentity.imei.oddeven;
    } else if (msg->mobileidentity.tmsi.typeofidentity == MOBILE_IDENTITY_TMSI) {
        /* Get the TMSI */
        p_tmsi = &tmsi;
        tmsi.digit1 = msg->mobileidentity.tmsi.digit2;
        tmsi.digit2 = msg->mobileidentity.tmsi.digit3;
        tmsi.digit3 = msg->mobileidentity.tmsi.digit4;
        tmsi.digit4 = msg->mobileidentity.tmsi.digit5;
        tmsi.digit5 = msg->mobileidentity.tmsi.digit6;
        tmsi.digit6 = msg->mobileidentity.tmsi.digit7;
        tmsi.digit7 = msg->mobileidentity.tmsi.digit8;
        tmsi.digit8 = msg->mobileidentity.tmsi.digit9;
Cedric Roux's avatar
 
Cedric Roux committed
869 870 871 872
    }

    /* Execute the identification completion procedure */
    rc = emm_proc_identification_complete(ueid, p_imsi, p_imei,
873
                                          (UInt32_t *)(p_tmsi));
Cedric Roux's avatar
 
Cedric Roux committed
874 875 876 877 878
    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
879
 ** Name:    emm_recv_authentication_response()                        **
Cedric Roux's avatar
 
Cedric Roux committed
880 881 882
 **                                                                        **
 ** Description: Processes Authentication Response message                 **
 **                                                                        **
883 884 885
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
886
 **                                                                        **
887 888 889
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
890 891 892
 **                                                                        **
 ***************************************************************************/
int emm_recv_authentication_response(unsigned int ueid,
893 894
                                     authentication_response_msg *msg,
                                     int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
895 896 897 898 899 900 901 902 903 904 905
{
    LOG_FUNC_IN;

    int rc = RETURNok;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Response message");

    /*
     * Message checking
     */
    if (msg->authenticationresponseparameter.res.length == 0) {
906 907
        /* RES parameter shall not be null */
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
908 909 910
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
911
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
912 913 914 915 916 917
    }
    /*
     * Message processing
     */
    /* Execute the authentication completion procedure */
    rc = emm_proc_authentication_complete(ueid, EMM_CAUSE_SUCCESS,
918
                                          &msg->authenticationresponseparameter.res);
Cedric Roux's avatar
 
Cedric Roux committed
919 920 921 922 923
    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
924
 ** Name:    emm_recv_authentication_failure()                         **
Cedric Roux's avatar
 
Cedric Roux committed
925 926 927
 **                                                                        **
 ** Description: Processes Authentication Failure message                  **
 **                                                                        **
928 929 930
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
931
 **                                                                        **
932 933 934
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
935 936 937
 **                                                                        **
 ***************************************************************************/
int emm_recv_authentication_failure(unsigned int ueid,
938 939
                                    authentication_failure_msg *msg,
                                    int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
940 941 942 943 944 945 946 947 948 949 950
{
    LOG_FUNC_IN;

    int rc = RETURNok;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Failure message");

    /*
     * Message checking
     */
    if (msg->emmcause == EMM_CAUSE_SUCCESS) {
951 952 953 954 955 956
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
    } else if ( (msg->emmcause == EMM_CAUSE_SYNCH_FAILURE) &&
                !(msg->presencemask &
                  AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT) ) {
        /* AUTS parameter shall be present in case of "synch failure" */
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
957 958 959
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
960
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
961 962 963 964 965 966
    }
    /*
     * Message processing
     */
    /* Execute the authentication completion procedure */
    rc = emm_proc_authentication_complete(ueid, msg->emmcause,
967
                                          &msg->authenticationfailureparameter.auts);
Cedric Roux's avatar
 
Cedric Roux committed
968 969 970 971 972
    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
973
 ** Name:    emm_recv_security_mode_complete()                         **
Cedric Roux's avatar
 
Cedric Roux committed
974 975 976
 **                                                                        **
 ** Description: Processes Security Mode Complete message                  **
 **                                                                        **
977 978 979
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
980
 **                                                                        **
981 982 983
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
984 985
 **                                                                        **
 ***************************************************************************/
986 987 988 989 990
int
emm_recv_security_mode_complete(
    unsigned int                ueid,
    security_mode_complete_msg *msg,
    int                        *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
{
    LOG_FUNC_IN;

    int rc = RETURNok;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Security Mode Complete message");

    /*
     * Message processing
     */
    /* Execute the NAS security mode control completion procedure */
    rc = emm_proc_security_mode_complete(ueid);

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
1009
 ** Name:    emm_recv_security_mode_reject()                           **
Cedric Roux's avatar
 
Cedric Roux committed
1010 1011 1012
 **                                                                        **
 ** Description: Processes Security Mode Reject message                    **
 **                                                                        **
1013 1014 1015
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      msg:       The received EMM message                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
1016
 **                                                                        **
1017 1018 1019
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
1020 1021 1022
 **                                                                        **
 ***************************************************************************/
int emm_recv_security_mode_reject(unsigned int ueid,
1023 1024
                                  security_mode_reject_msg *msg,
                                  int *emm_cause)
Cedric Roux's avatar
 
Cedric Roux committed
1025 1026 1027 1028 1029 1030
{
    LOG_FUNC_IN;

    int rc = RETURNok;

    LOG_TRACE(INFO, "EMMAS-SAP - Received Security Mode Reject message "
1031
              "(cause=%d)", msg->emmcause);
Cedric Roux's avatar
 
Cedric Roux committed
1032 1033 1034 1035 1036

    /*
     * Message checking
     */
    if (msg->emmcause == EMM_CAUSE_SUCCESS) {
1037
        *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
Cedric Roux's avatar
 
Cedric Roux committed
1038 1039 1040
    }
    /* Handle message checking error */
    if (*emm_cause != EMM_CAUSE_SUCCESS) {
1041
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    }

    /*
     * Message processing
     */
    /* Execute the NAS security mode commend not accepted by the UE */
    rc = emm_proc_security_mode_reject(ueid);

    LOG_FUNC_RETURN (rc);
}
1052
#endif  // NAS_MME