Attach.c 111 KB
Newer Older
gauthier's avatar
GPLv3  
gauthier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.

 *******************************************************************************/
Cedric Roux's avatar
 
Cedric Roux committed
29 30
/*****************************************************************************

Cedric Roux's avatar
Cedric Roux committed
31
Source      Attach.c
Cedric Roux's avatar
 
Cedric Roux committed
32

Cedric Roux's avatar
Cedric Roux committed
33
Version     0.1
Cedric Roux's avatar
 
Cedric Roux committed
34

Cedric Roux's avatar
Cedric Roux committed
35
Date        2012/12/04
Cedric Roux's avatar
 
Cedric Roux committed
36

Cedric Roux's avatar
Cedric Roux committed
37
Product     NAS stack
Cedric Roux's avatar
 
Cedric Roux committed
38

Cedric Roux's avatar
Cedric Roux committed
39
Subsystem   EPS Mobility Management
Cedric Roux's avatar
 
Cedric Roux committed
40

Cedric Roux's avatar
Cedric Roux committed
41
Author      Frederic Maurel
Cedric Roux's avatar
 
Cedric Roux committed
42

Cedric Roux's avatar
Cedric Roux committed
43 44
Description Defines the attach related EMM procedure executed by the
        Non-Access Stratum.
Cedric Roux's avatar
 
Cedric Roux committed
45

Cedric Roux's avatar
Cedric Roux committed
46 47 48 49 50
        To get internet connectivity from the network, the network
        have to know about the UE. When the UE is switched on, it
        has to initiate the attach procedure to get initial access
        to the network and register its presence to the Evolved
        Packet Core (EPC) network in order to receive EPS services.
Cedric Roux's avatar
 
Cedric Roux committed
51

Cedric Roux's avatar
Cedric Roux committed
52 53 54 55 56
        As a result of a successful attach procedure, a context is
        created for the UE in the MME, and a default bearer is esta-
        blished between the UE and the PDN-GW. The UE gets the home
        agent IPv4 and IPv6 addresses and full connectivity to the
        IP network.
Cedric Roux's avatar
 
Cedric Roux committed
57

Cedric Roux's avatar
Cedric Roux committed
58 59
        The network may also initiate the activation of additional
        dedicated bearers for the support of a specific service.
Cedric Roux's avatar
 
Cedric Roux committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73

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

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

#include "emmData.h"

#include "emm_sap.h"
#include "esm_sap.h"
#include "emm_cause.h"

74 75
#include "NasSecurityAlgorithms.h"

Cedric Roux's avatar
 
Cedric Roux committed
76 77
#ifdef NAS_MME
#include "mme_api.h"
78
#include "mme_config.h"
Cedric Roux's avatar
Cedric Roux committed
79 80 81
# if defined(EPC_BUILD)
#   include "nas_itti_messaging.h"
# endif
Cedric Roux's avatar
 
Cedric Roux committed
82 83
#endif

Cedric Roux's avatar
Cedric Roux committed
84 85
#include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free
Cedric Roux's avatar
 
Cedric Roux committed
86 87 88 89 90 91 92 93 94 95

/****************************************************************************/
/****************  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 EPS attach type */
Cedric Roux's avatar
Cedric Roux committed
96
static const char *_emm_attach_type_str[] = {
Cedric Roux's avatar
 
Cedric Roux committed
97 98 99 100 101
    "EPS", "IMSI", "EMERGENCY", "RESERVED"
};

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
102
 *      Internal data handled by the attach procedure in the UE
Cedric Roux's avatar
 
Cedric Roux committed
103 104 105 106 107 108
 * --------------------------------------------------------------------------
 */
#ifdef NAS_UE
/*
 * Timer handlers
 */
Cedric Roux's avatar
Cedric Roux committed
109 110 111
void *_emm_attach_t3410_handler(void *);
static void *_emm_attach_t3411_handler(void *);
static void *_emm_attach_t3402_handler(void *);
Cedric Roux's avatar
 
Cedric Roux committed
112 113 114 115

/*
 * Abnormal case attach procedure
 */
Cedric Roux's avatar
Cedric Roux committed
116
static void _emm_attach_abnormal_cases_bcd(emm_sap_t *);
Cedric Roux's avatar
 
Cedric Roux committed
117 118 119 120 121

/*
 * Internal data used for attach procedure
 */
static struct {
Cedric Roux's avatar
Cedric Roux committed
122 123 124
#define EMM_ATTACH_COUNTER_MAX  5
    unsigned int attempt_count; /* Counter used to limit the number of
                 * subsequently rejected attach attempts */
Cedric Roux's avatar
 
Cedric Roux committed
125 126 127 128 129
} _emm_attach_data = {0};
#endif // NAS_UE

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
130
 *      Internal data handled by the attach procedure in the MME
Cedric Roux's avatar
 
Cedric Roux committed
131 132 133 134 135 136
 * --------------------------------------------------------------------------
 */
#ifdef NAS_MME
/*
 * Timer handlers
 */
Cedric Roux's avatar
Cedric Roux committed
137
static void *_emm_attach_t3450_handler(void *);
Cedric Roux's avatar
 
Cedric Roux committed
138 139 140 141

/*
 * Functions that may initiate EMM common procedures
 */
Cedric Roux's avatar
Cedric Roux committed
142 143 144
static int _emm_attach_identify(void *);
static int _emm_attach_security(void *);
static int _emm_attach(void *);
Cedric Roux's avatar
 
Cedric Roux committed
145 146 147 148

/*
 * Abnormal case attach procedures
 */
Cedric Roux's avatar
Cedric Roux committed
149 150 151 152 153 154 155
static int _emm_attach_release(void *);
static int _emm_attach_reject(void *);
static int _emm_attach_abort(void *);

static int _emm_attach_have_changed(const emm_data_context_t *ctx,
                                    emm_proc_attach_type_t type, int ksi,
                                    GUTI_t *guti, imsi_t *imsi, imei_t *imei,
gauthier's avatar
gauthier committed
156 157
                                    int eea, int eia, int ucs2, int uea, int uia, int gea,
                                    int umts_present, int gprs_present);
Cedric Roux's avatar
Cedric Roux committed
158 159 160
static int _emm_attach_update(emm_data_context_t *ctx, unsigned int ueid,
                              emm_proc_attach_type_t type, int ksi,
                              GUTI_t *guti, imsi_t *imsi, imei_t *imei,
gauthier's avatar
gauthier committed
161 162 163
                              int eea, int eia, int ucs2, int uea, int uia, int gea,
                              int umts_present, int gprs_present,
                              const OctetString *esm_msg);
Cedric Roux's avatar
 
Cedric Roux committed
164 165 166 167 168

/*
 * Internal data used for attach procedure
 */
typedef struct {
Cedric Roux's avatar
Cedric Roux committed
169 170 171 172 173
    unsigned int ueid;          /* UE identifier        */
#define ATTACH_COUNTER_MAX  5
    unsigned int retransmission_count;  /* Retransmission counter   */
    OctetString esm_msg;        /* ESM message to be sent within
                     * the Attach Accept message    */
Cedric Roux's avatar
 
Cedric Roux committed
174 175
} attach_data_t;

Cedric Roux's avatar
Cedric Roux committed
176
static int _emm_attach_accept(emm_data_context_t *emm_ctx, attach_data_t *data);
Cedric Roux's avatar
 
Cedric Roux committed
177 178 179 180 181 182 183 184 185

#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
186
 *          Attach procedure executed by the UE
Cedric Roux's avatar
 
Cedric Roux committed
187 188 189 190 191
 * --------------------------------------------------------------------------
 */
#ifdef NAS_UE
/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
192
 ** Name:    emm_proc_attach()                                         **
Cedric Roux's avatar
 
Cedric Roux committed
193 194
 **                                                                        **
 ** Description: Initiate EPS attach procedure to register a UE in PS mode **
Cedric Roux's avatar
Cedric Roux committed
195 196
 **      of operation for EPS services only, or register a UE for  **
 **      emergency bearer services.                                **
Cedric Roux's avatar
 
Cedric Roux committed
197 198
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.2                         **
Cedric Roux's avatar
Cedric Roux committed
199 200 201 202
 **      In state EMM-DEREGISTERED, the UE initiates the attach    **
 **      procedure by sending an ATTACH REQUEST message to the MME,**
 **      starting timer T3410 and entering state EMM-REGISTERED-   **
 **      INITIATED.                                                **
Cedric Roux's avatar
 
Cedric Roux committed
203
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
204 205
 ** Inputs:  type:      Type of the requested attach               **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
206
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
207 208 209
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    T3402, T3410, T3411                        **
Cedric Roux's avatar
 
Cedric Roux committed
210 211 212 213 214 215 216 217 218 219 220 221
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach(emm_proc_attach_type_t type)
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    emm_as_establish_t *emm_as = &emm_sap.u.emm_as.u.establish;
    esm_sap_t esm_sap;
    int rc;

    LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach type = %s (%d)",
Cedric Roux's avatar
Cedric Roux committed
222
              _emm_attach_type_str[type], type);
Cedric Roux's avatar
 
Cedric Roux committed
223 224 225

    /* Update the emergency bearer service indicator */
    if (type == EMM_ATTACH_TYPE_EMERGENCY) {
Cedric Roux's avatar
Cedric Roux committed
226
        _emm_data.is_emergency = TRUE;
Cedric Roux's avatar
 
Cedric Roux committed
227 228 229 230 231 232 233 234
    }

    /* Setup initial NAS information message to transfer */
    emm_as->NASinfo = EMM_AS_NAS_INFO_ATTACH;
    /* Set the attach type */
    emm_as->type = type;
    /* Set the RRC connection establishment cause */
    if (_emm_data.is_emergency) {
Cedric Roux's avatar
Cedric Roux committed
235 236
        emm_as->RRCcause = NET_ESTABLISH_CAUSE_EMERGENCY;
        emm_as->RRCtype = NET_ESTABLISH_TYPE_EMERGENCY_CALLS;
Cedric Roux's avatar
 
Cedric Roux committed
237
    } else {
Cedric Roux's avatar
Cedric Roux committed
238 239
        emm_as->RRCcause = NET_ESTABLISH_CAUSE_MO_SIGNAL;
        emm_as->RRCtype = NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL;
Cedric Roux's avatar
 
Cedric Roux committed
240 241 242 243 244 245 246 247 248 249 250 251
    }
    /* Set the PLMN identifier of the selected PLMN */
    emm_as->plmnID = &_emm_data.splmn;
    /*
     * Process the EPS mobile identity
     */
    emm_as->UEid.guti = NULL;
    emm_as->UEid.tai  = NULL;
    emm_as->UEid.imsi = NULL;
    emm_as->UEid.imei = NULL;
    /* Check whether the UE is configured for "AttachWithIMSI" */
    if (_emm_data.AttachWithImsi) {
Cedric Roux's avatar
Cedric Roux committed
252 253 254
        /* Check whether the selected PLMN is neither the registered PLMN
         * nor in the list of equivalent PLMNs */
        if ( (!_emm_data.is_rplmn) && (!_emm_data.is_eplmn) ) {
255
            LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach with IMSI");
Cedric Roux's avatar
Cedric Roux committed
256 257
            /* Include the IMSI */
            emm_as->UEid.imsi = _emm_data.imsi;
258 259 260 261 262
        } else {
            LOG_TRACE(INFO,
                    "EMM-PROC  - Initiate EPS attach with NO IMSI, is registered PLMN %d, is equivalent PLMN %d",
                    _emm_data.is_rplmn,
                    _emm_data.is_eplmn);
Cedric Roux's avatar
Cedric Roux committed
263 264
        }
    } else if (_emm_data.guti) {
265
        LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach with GUTI");
Cedric Roux's avatar
Cedric Roux committed
266 267 268 269
        /* Include a valid GUTI and the last visited registered TAI */
        emm_as->UEid.guti = _emm_data.guti;
        emm_as->UEid.tai = _emm_data.tai;
    } else if (!_emm_data.is_emergency) {
270
        LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach with IMSI cause is no emergency and no GUTI");
Cedric Roux's avatar
Cedric Roux committed
271 272 273 274 275 276 277
        /* Include the IMSI if no valid GUTI is available */
        emm_as->UEid.imsi = _emm_data.imsi;
    } else {
        /* The UE is attaching for emergency bearer services and
         * does not hold a valid GUTI */
        if (_emm_data.imsi) {
            /* Include the IMSI if valid (USIM is present) */
278
            LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach with IMSI cause is emergency and no GUTI");
Cedric Roux's avatar
Cedric Roux committed
279 280
            emm_as->UEid.imsi = _emm_data.imsi;
        } else {
281
            LOG_TRACE(INFO, "EMM-PROC  - Initiate EPS attach with IMSI cause is emergency and no GUTI and no IMSI");
Cedric Roux's avatar
Cedric Roux committed
282 283 284
            /* Include the IMEI if the IMSI is not valid */
            emm_as->UEid.imei = _emm_data.imei;
        }
Cedric Roux's avatar
 
Cedric Roux committed
285 286 287 288 289
    }
    /* Setup EPS NAS security data */
    emm_as_set_security_data(&emm_as->sctx, _emm_data.security, FALSE, FALSE);
    emm_as->ksi = EMM_AS_NO_KEY_AVAILABLE;
    if (_emm_data.security) {
Cedric Roux's avatar
Cedric Roux committed
290 291 292
        if (_emm_data.security->type != EMM_KSI_NOT_AVAILABLE) {
            emm_as->ksi = _emm_data.security->eksi;
        }
gauthier's avatar
gauthier committed
293 294 295 296
        LOG_TRACE(INFO, "EMM-PROC  - eps_encryption 0x%X", _emm_data.security->capability.eps_encryption);
        LOG_TRACE(INFO, "EMM-PROC  - eps_integrity  0x%X", _emm_data.security->capability.eps_integrity);
        emm_as->encryption = _emm_data.security->capability.eps_encryption;
        emm_as->integrity = _emm_data.security->capability.eps_integrity;
Cedric Roux's avatar
 
Cedric Roux committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    }
    /*
     * Notify ESM that initiation of a PDN connectivity procedure
     * is requested to setup a default EPS bearer
     */
    esm_sap.primitive = ESM_PDN_CONNECTIVITY_REQ;
    esm_sap.is_standalone = FALSE;
    esm_sap.data.pdn_connect.is_defined = TRUE;
    esm_sap.data.pdn_connect.cid = 1;
    /* TODO: PDN type should be set according to the IP capability of the UE */
    esm_sap.data.pdn_connect.pdn_type = NET_PDN_TYPE_IPV4V6;
    esm_sap.data.pdn_connect.apn = NULL;
    esm_sap.data.pdn_connect.is_emergency = _emm_data.is_emergency;
    rc = esm_sap_send(&esm_sap);

    if (rc != RETURNerror) {
Cedric Roux's avatar
Cedric Roux committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
        /* Setup EMM procedure handler to be executed upon receiving
         * lower layer notification */
        rc = emm_proc_lowerlayer_initialize(emm_proc_attach_request,
                                            emm_proc_attach_failure,
                                            emm_proc_attach_release, NULL);
        if (rc != RETURNok) {
            LOG_TRACE(WARNING, "Failed to initialize EMM procedure handler");
            LOG_FUNC_RETURN (RETURNerror);
        }

        /* Start T3410 timer */
        T3410.id = nas_timer_start(T3410.sec, _emm_attach_t3410_handler, NULL);
        LOG_TRACE(INFO,"EMM-PROC  - Timer T3410 (%d) expires in %ld seconds",
                  T3410.id, T3410.sec);
        /* Stop T3402 and T3411 timers if running */
        T3402.id = nas_timer_stop(T3402.id);
        T3411.id = nas_timer_stop(T3411.id);

        /*
         * Notify EMM-AS SAP that a RRC connection establishment procedure
         * is requested from the Access-Stratum to send initial NAS message
         * attach request to the network
         */
        emm_sap.primitive = EMMAS_ESTABLISH_REQ;
        /* Get the PDN connectivity request to transfer within the ESM
         * container of the initial attach request message */
        emm_sap.u.emm_as.u.establish.NASmsg = esm_sap.send;
        rc = emm_sap_send(&emm_sap);
Cedric Roux's avatar
 
Cedric Roux committed
341 342 343 344 345 346 347
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
348
 ** Name:    emm_proc_attach_request()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
349 350
 **                                                                        **
 ** Description: Performs the attach procedure upon receipt of indication  **
Cedric Roux's avatar
Cedric Roux committed
351 352
 **      from lower layers that Attach Request message has been    **
 **      successfully delivered to the network.                    **
Cedric Roux's avatar
 
Cedric Roux committed
353
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
354 355
 ** Inputs:  args:      Not used                                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
356
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
357 358 359
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
360 361
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
362
int emm_proc_attach_request(void *args)
Cedric Roux's avatar
 
Cedric Roux committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    int rc;

    /*
     * Notify EMM that Attach Request has been sent to the network
     */
    emm_sap.primitive = EMMREG_ATTACH_REQ;
    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
380
 ** Name:    emm_proc_attach_accept()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
381 382 383 384
 **                                                                        **
 ** Description: Performs the attach procedure accepted by the network.    **
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.4                         **
Cedric Roux's avatar
Cedric Roux committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
 **      Upon receiving the ATTACH ACCEPT message, the UE shall    **
 **      stop timer T3410 and send an ATTACH COMPLETE message to   **
 **      the MME.                                                  **
 **                                                                        **
 ** Inputs:  t3412:     Value of the T3412 timer in seconds        **
 **      t3402:     Value of the T3402 timer in seconds        **
 **      t3423:     Value of the T3423 timer in seconds        **
 **      n_tais:    Number of tracking area identities contai- **
 **             ned in the TAI list                        **
 **      tai:       The TAI list that identifies the tracking  **
 **             areas the UE is registered to              **
 **      guti:      New UE's temporary identity assigned by    **
 **             the MME (GUTI reallocation)                **
 **      n_eplmns:  Number of equivalent PLMNs                 **
 **      eplmns:    List of equivalent PLMNs                   **
 **      esm_msg:   Activate default EPS bearer context re-    **
 **             quest ESM message                          **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data, T3412, T3402, T3423             **
Cedric Roux's avatar
 
Cedric Roux committed
407 408 409
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_accept(long t3412, long t3402, long t3423,
Cedric Roux's avatar
Cedric Roux committed
410 411 412
                           int n_tais, tai_t *tai, GUTI_t *guti,
                           int n_eplmns, plmn_t *eplmn,
                           const OctetString *esm_msg)
Cedric Roux's avatar
 
Cedric Roux committed
413 414 415 416 417 418
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    esm_sap_t esm_sap;
    int rc;
419 420
    int i;
    int j;
Cedric Roux's avatar
 
Cedric Roux committed
421 422 423 424 425 426 427 428 429

    LOG_TRACE(INFO, "EMM-PROC  - EPS attach accepted by the network");

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

    /* Delete old TAI list and store the received TAI list */
    _emm_data.ltai.n_tais = n_tais;
430
    for (i = 0; (i < n_tais) && (i < EMM_DATA_TAI_MAX); i++) {
Cedric Roux's avatar
Cedric Roux committed
431
        _emm_data.ltai.tai[i] = tai[i];
Cedric Roux's avatar
 
Cedric Roux committed
432 433 434 435 436 437
    }

    /* Update periodic tracking area update timer value */
    T3412.sec = t3412;
    /* Update attach failure timer value */
    if ( !(t3402 < 0) ) {
Cedric Roux's avatar
Cedric Roux committed
438
        T3402.sec = t3402;
Cedric Roux's avatar
 
Cedric Roux committed
439 440 441
    }
    /* Update E-UTRAN deactivate ISR timer value */
    if ( !(t3423 < 0) ) {
Cedric Roux's avatar
Cedric Roux committed
442
        T3423.sec = t3423;
Cedric Roux's avatar
 
Cedric Roux committed
443 444 445 446
    }

    /* Delete old GUTI and store the new assigned GUTI if provided */
    if (guti) {
Cedric Roux's avatar
Cedric Roux committed
447
        *_emm_data.guti = *guti;
Cedric Roux's avatar
 
Cedric Roux committed
448 449 450 451 452
    }

    /* Update the stored list of equivalent PLMNs */
    _emm_data.nvdata.eplmn.n_plmns = 0;
    if (n_eplmns > 0) {
453
        for (i = 0; (i < n_eplmns) && (i < EMM_DATA_EPLMN_MAX); i++) {
Cedric Roux's avatar
Cedric Roux committed
454 455 456 457 458
            int is_forbidden = FALSE;
            if (!_emm_data.is_emergency) {
                /* If the attach procedure is not for emergency bearer
                 * services, the UE shall remove from the list any PLMN
                 * code that is already in the list of forbidden PLMNs */
459
                for (j = 0; j < _emm_data.fplmn.n_plmns; j++) {
Cedric Roux's avatar
Cedric Roux committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
                    if (PLMNS_ARE_EQUAL(eplmn[i], _emm_data.fplmn.plmn[j])) {
                        is_forbidden = TRUE;
                        break;
                    }
                }
            }
            if ( !is_forbidden ) {
                _emm_data.nvdata.eplmn.plmn[_emm_data.nvdata.eplmn.n_plmns++] =
                    eplmn[i];
            }
        }
        /* Add the PLMN code of the registered PLMN that sent the list */
        if (_emm_data.nvdata.eplmn.n_plmns < EMM_DATA_EPLMN_MAX) {
            _emm_data.nvdata.eplmn.plmn[_emm_data.nvdata.eplmn.n_plmns++] =
                _emm_data.splmn;
        }
Cedric Roux's avatar
 
Cedric Roux committed
476 477 478 479 480 481 482 483 484 485
    }

    /*
     * Notify ESM that a default EPS bearer has to be activated
     */
    esm_sap.primitive = ESM_DEFAULT_EPS_BEARER_CONTEXT_ACTIVATE_REQ;
    esm_sap.is_standalone = FALSE;
    esm_sap.recv = esm_msg;
    rc = esm_sap_send(&esm_sap);

Cedric Roux's avatar
Cedric Roux committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    if ( (rc != RETURNerror) && (esm_sap.err == ESM_SAP_SUCCESS) ) {
        /* Setup EMM procedure handler to be executed upon receiving
         * lower layer notification */
        rc = emm_proc_lowerlayer_initialize(emm_proc_attach_complete,
                                            emm_proc_attach_failure,
                                            NULL, NULL);
        if (rc != RETURNok) {
            LOG_TRACE(WARNING,
                      "EMM-PROC  - Failed to initialize EMM procedure handler");
            LOG_FUNC_RETURN (RETURNerror);
        }
        /*
         * Notify EMM-AS SAP that Attach Complete message together with
         * an Activate Default EPS Bearer Context Accept message has to
         * be sent to the network
         */
        emm_sap.primitive = EMMAS_DATA_REQ;
        emm_sap.u.emm_as.u.data.guti = _emm_data.guti;
        emm_sap.u.emm_as.u.data.ueid = 0;
        /* Setup EPS NAS security data */
        emm_as_set_security_data(&emm_sap.u.emm_as.u.data.sctx,
                                 _emm_data.security, FALSE, TRUE);
        /* Get the activate default EPS bearer context accept message
         * to be transfered within the ESM container of the attach
         * complete message */
        emm_sap.u.emm_as.u.data.NASinfo = EMM_AS_NAS_DATA_ATTACH;
        emm_sap.u.emm_as.u.data.NASmsg = esm_sap.send;
        rc = emm_sap_send(&emm_sap);
    } else if (esm_sap.err != ESM_SAP_DISCARDED) {
        /* 3GPP TS 24.301, section 5.5.1.2.6, case j
         * If the ACTIVATE DEFAULT BEARER CONTEXT REQUEST message combined
         * with the ATTACH ACCEPT is not accepted by the UE due to failure
         * in the UE ESM sublayer, then the UE shall initiate the detach
         * procedure by sending a DETACH REQUEST message to the network.
         */
        emm_sap.primitive = EMMREG_DETACH_INIT;
        rc = emm_sap_send(&emm_sap);
    } else {
        /*
         * ESM procedure failed and, received message has been discarded or
         * Status message has been returned; ignore ESM procedure failure
         */
        rc = RETURNok;
Cedric Roux's avatar
 
Cedric Roux committed
529 530 531 532 533 534 535
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
536
 ** Name:    emm_proc_attach_reject()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
537 538 539 540
 **                                                                        **
 ** Description: Performs the attach procedure rejected by the network.    **
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.5                         **
Cedric Roux's avatar
Cedric Roux committed
541 542 543
 **      Upon receiving the ATTACH REJECT message, the UE shall    **
 **      stop timer T3410 and take actions depending on the EMM    **
 **      cause value received.                                     **
Cedric Roux's avatar
 
Cedric Roux committed
544
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
545 546 547 548
 ** Inputs:  emm_cause: EMM cause indicating why the network re-   **
 **             jected the attach request                  **
 **      esm_msg:   PDN connectivity reject ESM message        **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
549
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
550 551 552
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data, _emm_attach_data, T3410         **
Cedric Roux's avatar
 
Cedric Roux committed
553 554
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
555
int emm_proc_attach_reject(int emm_cause, const OctetString *esm_msg)
Cedric Roux's avatar
 
Cedric Roux committed
556 557 558 559 560 561 562
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    int rc;

    LOG_TRACE(WARNING, "EMM-PROC  - EPS attach rejected by the network, "
Cedric Roux's avatar
Cedric Roux committed
563
              "EMM cause = %d", emm_cause);
Cedric Roux's avatar
 
Cedric Roux committed
564 565 566 567 568 569 570

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

    /* Update the EPS update status, the GUTI, the visited registered TAI and
     * the eKSI */
Cedric Roux's avatar
Cedric Roux committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
    switch (emm_cause) {
        case EMM_CAUSE_ILLEGAL_UE:
        case EMM_CAUSE_ILLEGAL_ME:
        case EMM_CAUSE_EPS_NOT_ALLOWED:
        case EMM_CAUSE_BOTH_NOT_ALLOWED:
        case EMM_CAUSE_PLMN_NOT_ALLOWED:
        case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN:
        case EMM_CAUSE_EPS_NOT_ALLOWED_IN_PLMN:
        case EMM_CAUSE_TA_NOT_ALLOWED:
        case EMM_CAUSE_ROAMING_NOT_ALLOWED:
        case EMM_CAUSE_NO_SUITABLE_CELLS:
            /* Set the EPS update status to EU3 ROAMING NOT ALLOWED */
            _emm_data.status = EU3_ROAMING_NOT_ALLOWED;
            /* Delete the GUTI */
            _emm_data.guti = NULL;
            /* Delete the last visited registered TAI */
            _emm_data.tai = NULL;
            /* Delete the eKSI */
            if (_emm_data.security) {
                _emm_data.security->type = EMM_KSI_NOT_AVAILABLE;
            }
            break;

        default :
            break;
Cedric Roux's avatar
 
Cedric Roux committed
596 597 598
    }

    /* Update list of equivalents PLMNs and attach attempt counter */
Cedric Roux's avatar
Cedric Roux committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    switch (emm_cause) {
        case EMM_CAUSE_ILLEGAL_UE:
        case EMM_CAUSE_ILLEGAL_ME:
        case EMM_CAUSE_EPS_NOT_ALLOWED:
        case EMM_CAUSE_BOTH_NOT_ALLOWED:
            /* Consider the USIM as invalid for EPS services */
            _emm_data.usim_is_valid = FALSE;
            /* Delete the list of equivalent PLMNs */
            _emm_data.nvdata.eplmn.n_plmns = 0;
            break;

        case EMM_CAUSE_PLMN_NOT_ALLOWED:
        case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN:
        case EMM_CAUSE_ROAMING_NOT_ALLOWED:
            /* Delete the list of equivalent PLMNs */
            _emm_data.nvdata.eplmn.n_plmns = 0;
            /* Reset the attach attempt counter */
            _emm_attach_data.attempt_count = 0;
            break;

        case EMM_CAUSE_TA_NOT_ALLOWED:
        case EMM_CAUSE_EPS_NOT_ALLOWED_IN_PLMN:
        case EMM_CAUSE_NO_SUITABLE_CELLS:
            /* Reset the attach attempt counter */
            _emm_attach_data.attempt_count = 0;
            break;

        case EMM_CAUSE_ESM_FAILURE:
            /* 3GPP TS 24.301, section 5.5.1.2.6, case d */
            if (_emm_data.NAS_SignallingPriority != 1) {
                /* The UE is not configured for NAS signalling low priority;
                 * set the attach attempt counter to 5 */
                _emm_attach_data.attempt_count = EMM_ATTACH_COUNTER_MAX;
            }
            break;

        case EMM_CAUSE_SEMANTICALLY_INCORRECT:
        case EMM_CAUSE_INVALID_MANDATORY_INFO:
        case EMM_CAUSE_MESSAGE_TYPE_NOT_IMPLEMENTED:
        case EMM_CAUSE_IE_NOT_IMPLEMENTED:
        case EMM_CAUSE_PROTOCOL_ERROR:
            /* 3GPP TS 24.301, section 5.5.1.2.6, case d
             * Set the attach attempt counter to 5 */
            _emm_attach_data.attempt_count = EMM_ATTACH_COUNTER_MAX;
            break;

        default :
            break;
Cedric Roux's avatar
 
Cedric Roux committed
647 648 649
    }

    /* Update "forbidden lists" */
Cedric Roux's avatar
Cedric Roux committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
    switch (emm_cause) {
        case EMM_CAUSE_PLMN_NOT_ALLOWED:
        case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN:
            /* Store the PLMN identity in the "forbidden PLMN list" */
            _emm_data.fplmn.plmn[_emm_data.fplmn.n_plmns++] = _emm_data.splmn;
            break;

        case EMM_CAUSE_TA_NOT_ALLOWED:
            /* Store the current TAI in the list of "forbidden tracking
             * areas for regional provision of service" */
            _emm_data.ftai.tai[_emm_data.ftai.n_tais++] = *_emm_data.tai;
            break;

        case EMM_CAUSE_ROAMING_NOT_ALLOWED:
            /* Store the current TAI in the list of "forbidden tracking
             * areas for roaming" */
            _emm_data.ftai_roaming.tai[_emm_data.ftai_roaming.n_tais++] = *_emm_data.tai;
            break;

        case EMM_CAUSE_EPS_NOT_ALLOWED_IN_PLMN:
            /* Store the PLMN identity in the "forbidden PLMNs for GPRS
             * service" list */
            _emm_data.fplmn_gprs.plmn[_emm_data.fplmn_gprs.n_plmns++] = _emm_data.splmn;
            break;

        default :
            break;
Cedric Roux's avatar
 
Cedric Roux committed
677 678 679
    }

    /* Update state of EMM sublayer */
Cedric Roux's avatar
Cedric Roux committed
680 681 682 683 684 685 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
    switch (emm_cause) {
        case EMM_CAUSE_ILLEGAL_UE:
        case EMM_CAUSE_ILLEGAL_ME:
        case EMM_CAUSE_EPS_NOT_ALLOWED:
        case EMM_CAUSE_BOTH_NOT_ALLOWED:
            /*
             * Notify EMM that EPS attach is rejected
             */
            emm_sap.primitive = EMMREG_ATTACH_REJ;
            break;

        case EMM_CAUSE_PLMN_NOT_ALLOWED:
        case EMM_CAUSE_NOT_AUTHORIZED_IN_PLMN:
        case EMM_CAUSE_EPS_NOT_ALLOWED_IN_PLMN:
            /*
             * Notify EMM that the UE has to perform a PLMN selection because
             * it is not allowed to operate in the currently selected PLMN
             */
            emm_sap.primitive = EMMREG_REGISTER_REQ;
            break;

        case EMM_CAUSE_TA_NOT_ALLOWED:
        case EMM_CAUSE_ROAMING_NOT_ALLOWED:
        case EMM_CAUSE_NO_SUITABLE_CELLS:
            /*
             * Notify EMM that the UE failed to register to the network for
             * EPS services because it is not allowed to operate in the
             * requested tracking area
             */
            emm_sap.primitive = EMMREG_REGISTER_REJ;
            break;

        case EMM_CAUSE_IMEI_NOT_ACCEPTED:
            if (_emm_data.is_emergency) {
                /*
                 * Notify EMM that the UE failed to register to the network
                 * for emergency bearer services because "IMEI not accepted"
                 */
                emm_sap.primitive = EMMREG_NO_IMSI;
                break;
            }
            /* break is volontary missing */

        default :
            /* Other values are considered as abnormal cases
             * 3GPP TS 24.301, section 5.5.1.2.6, case d */
            _emm_attach_abnormal_cases_bcd(&emm_sap);
            break;
Cedric Roux's avatar
 
Cedric Roux committed
728 729 730 731 732 733 734 735
    }

    rc = emm_sap_send(&emm_sap);

    /*
     * Notify ESM that the network rejected connectivity to the PDN
     */
    if (esm_msg != NULL) {
Cedric Roux's avatar
Cedric Roux committed
736 737 738 739 740
        esm_sap_t esm_sap;
        esm_sap.primitive = ESM_PDN_CONNECTIVITY_REJ;
        esm_sap.is_standalone = FALSE;
        esm_sap.recv = esm_msg;
        rc = esm_sap_send(&esm_sap);
Cedric Roux's avatar
 
Cedric Roux committed
741 742 743 744 745 746 747
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
748
 ** Name:    emm_proc_attach_complete()                                **
Cedric Roux's avatar
 
Cedric Roux committed
749 750
 **                                                                        **
 ** Description: Terminates the attach procedure when Attach Complete mes- **
Cedric Roux's avatar
Cedric Roux committed
751
 **      sage has been successfully delivered to the MME.          **
Cedric Roux's avatar
 
Cedric Roux committed
752 753
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.4                         **
Cedric Roux's avatar
Cedric Roux committed
754 755 756 757
 **      Upon successfully sending the ATTACH COMPLETE message,    **
 **      the UE shall reset the attach attempt counter and tra-    **
 **      cking area updating attempt counter, enter state EMM-     **
 **      REGISTERED and set the EPS update status to EU1-UPDATED.  **
Cedric Roux's avatar
 
Cedric Roux committed
758
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
759 760
 ** Inputs:  args:      Not used                                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
761
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
762 763 764
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data, _emm_attach_data                **
Cedric Roux's avatar
 
Cedric Roux committed
765 766
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
767
int emm_proc_attach_complete(void *args)
Cedric Roux's avatar
 
Cedric Roux committed
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    esm_sap_t esm_sap;
    int rc;

    LOG_TRACE(INFO, "EMM-PROC  - EPS attach complete");

    /* Reset EMM procedure handler */
    (void) emm_proc_lowerlayer_initialize(NULL, NULL, NULL, NULL);

    /* Reset the attach attempt counter */
    _emm_attach_data.attempt_count = 0;
    /* TODO: Reset the tracking area updating attempt counter */

    /* Set the EPS update status to EU1 UPDATED */
    _emm_data.status = EU1_UPDATED;
    _emm_data.is_attached = TRUE;

    /*
     * Notify EMM that network attach complete message has been delivered
     * to the network
     */
    emm_sap.primitive = EMMREG_ATTACH_CNF;
    rc = emm_sap_send(&emm_sap);

    if (rc != RETURNerror) {
Cedric Roux's avatar
Cedric Roux committed
796 797 798 799 800 801 802 803
        /*
         * Notify ESM that the Activate Default EPS Bearer Context Accept
         * message has been delivered to the network within the Attach
         * Complete message
         */
        esm_sap.primitive = ESM_DEFAULT_EPS_BEARER_CONTEXT_ACTIVATE_CNF;
        esm_sap.is_standalone = FALSE;
        rc = esm_sap_send(&esm_sap);
Cedric Roux's avatar
 
Cedric Roux committed
804 805 806 807 808 809 810
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
811
 ** Name:    emm_proc_attach_failure()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
812 813
 **                                                                        **
 ** Description: Performs the attach procedure abnormal case upon receipt  **
Cedric Roux's avatar
Cedric Roux committed
814 815
 **      of transmission failure of Attach Request message or At-  **
 **      tach Complete message.                                    **
Cedric Roux's avatar
 
Cedric Roux committed
816 817
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.6, cases h and i          **
Cedric Roux's avatar
Cedric Roux committed
818 819
 **      The  UE  shall restart the attach  procedure when timer   **
 **      T3411 expires.                                            **
Cedric Roux's avatar
 
Cedric Roux committed
820
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
821 822 823 824 825 826
 ** Inputs:  is_initial:    TRUE if the NAS message that failed to be  **
 **             transfered is an initial NAS message (ESM  **
 **             message embedded within an Attach Request  **
 **             message)                                   **
 **          args:      Not used                                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
827
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
828 829 830
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    T3410, T3411                               **
Cedric Roux's avatar
 
Cedric Roux committed
831 832
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
833
int emm_proc_attach_failure(int is_initial, void *args)
Cedric Roux's avatar
 
Cedric Roux committed
834 835 836 837 838 839 840 841 842 843 844 845 846
{
    LOG_FUNC_IN;

    int rc = RETURNok;
    esm_sap_t esm_sap;

    LOG_TRACE(WARNING, "EMM-PROC  - EPS attach failure");

    /* Reset EMM procedure handler */
    (void) emm_proc_lowerlayer_initialize(NULL, NULL, NULL, NULL);

    /* Stop timer T3410 if still running */
    if (T3410.id != NAS_TIMER_INACTIVE_ID) {
Cedric Roux's avatar
Cedric Roux committed
847 848
        LOG_TRACE(INFO, "EMM-PROC  - Stop timer T3410 (%d)", T3410.id);
        T3410.id = nas_timer_stop(T3410.id);
Cedric Roux's avatar
 
Cedric Roux committed
849 850 851
    }

    if (is_initial) {
Cedric Roux's avatar
Cedric Roux committed
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
        /*
         * Notify ESM that the PDN CONNECTIVITY REQUEST message contained
         * in the ESM message container IE of the ATTACH REQUEST has failed
         * to be transmitted
         */
        esm_sap.primitive = ESM_PDN_CONNECTIVITY_REJ;
        esm_sap.is_standalone = FALSE;
        esm_sap.recv = NULL;
    } else {
        /*
         * Notify ESM that ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message
         * contained in the ESM message container IE of the ATTACH COMPLETE
         * has failed to be transmitted
         */
        esm_sap.primitive = ESM_DEFAULT_EPS_BEARER_CONTEXT_ACTIVATE_REJ;
        esm_sap.is_standalone = FALSE;
        esm_sap.recv = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
869 870 871 872
    }
    rc = esm_sap_send(&esm_sap);

    if (rc != RETURNerror) {
Cedric Roux's avatar
Cedric Roux committed
873 874 875 876
        /* Start T3411 timer */
        T3411.id = nas_timer_start(T3411.sec, _emm_attach_t3411_handler, NULL);
        LOG_TRACE(INFO, "EMM-PROC  - Timer T3411 (%d) expires in %ld seconds",
                  T3411.id, T3411.sec);
Cedric Roux's avatar
 
Cedric Roux committed
877 878 879 880 881 882 883
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
884
 ** Name:    emm_proc_attach_release()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
885 886
 **                                                                        **
 ** Description: Performs the attach procedure abnormal case upon receipt  **
Cedric Roux's avatar
Cedric Roux committed
887
 **      of NAS signalling connection release indication.          **
Cedric Roux's avatar
 
Cedric Roux committed
888 889
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.6, case b                 **
Cedric Roux's avatar
Cedric Roux committed
890 891
 **      The attach procedure shall be aborted and the UE shall    **
 **      execute abnormal case attach procedure.                   **
Cedric Roux's avatar
 
Cedric Roux committed
892
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
893 894
 ** Inputs:  args:      Not used                                   **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
895
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
896 897 898
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
899 900
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
901
int emm_proc_attach_release(void *args)
Cedric Roux's avatar
 
Cedric Roux committed
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    int rc;

    LOG_TRACE(WARNING, "EMM-PROC  - NAS signalling connection released");

    /* Execute abnormal case attach procedure */
    _emm_attach_abnormal_cases_bcd(&emm_sap);

    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
920
 ** Name:    emm_proc_attach_restart()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
921 922 923
 **                                                                        **
 ** Description: Restarts the attach procedure                             **
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
924 925
 ** Inputs:  None                                                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
926
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
927 928 929
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_restart(void)
{
    LOG_FUNC_IN;

    emm_sap_t emm_sap;
    int rc;

    LOG_TRACE(INFO, "EMM-PROC  - Restart EPS attach procedure");

    /*
     * Notify EMM that the attach procedure has to be restarted
     */
    emm_sap.primitive = EMMREG_ATTACH_INIT;
    emm_sap.u.emm_reg.u.attach.is_emergency = _emm_data.is_emergency;
    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
953
 ** Name:    emm_proc_attach_set_emergency()                           **
Cedric Roux's avatar
 
Cedric Roux committed
954 955 956
 **                                                                        **
 ** Description: Set the emergency bearer services indicator               **
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
957 958
 ** Inputs:  None                                                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
959
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
960 961 962
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
963 964 965 966 967 968 969
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_set_emergency(void)
{
    LOG_FUNC_IN;

    LOG_TRACE(WARNING, "EMM-PROC  - UE is now attached to the network for "
Cedric Roux's avatar
Cedric Roux committed
970
              "emergency bearer services only");
Cedric Roux's avatar
 
Cedric Roux committed
971 972 973 974 975 976 977 978

    _emm_data.is_emergency = TRUE;

    LOG_FUNC_RETURN(RETURNok);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
979
 ** Name:    emm_proc_attach_set_detach()                              **
Cedric Roux's avatar
 
Cedric Roux committed
980 981
 **                                                                        **
 ** Description: Reset the network attachment indicator and enter state    **
Cedric Roux's avatar
Cedric Roux committed
982
 **      EMM-DEREGISTERED
Cedric Roux's avatar
 
Cedric Roux committed
983
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
984 985
 ** Inputs:  None                                                      **
 **      Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
986
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
987 988 989
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
990 991 992 993 994 995 996 997 998
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_set_detach(void)
{
    LOG_FUNC_IN;

    int rc;

    LOG_TRACE(WARNING,
Cedric Roux's avatar
Cedric Roux committed
999
              "EMM-PROC  - UE is now locally detached from the network");
Cedric Roux's avatar
 
Cedric Roux committed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

    /* Reset the network attachment indicator */
    _emm_data.is_attached = FALSE;
    /*
     * Notify that the UE is locally detached from the network
     */
    emm_sap_t emm_sap;
    emm_sap.primitive = EMMREG_DETACH_CNF;
    rc = emm_sap_send(&emm_sap);

    LOG_FUNC_RETURN(rc);
}

#endif

/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
1017
 *          Attach procedure executed by the MME
Cedric Roux's avatar
 
Cedric Roux committed
1018 1019 1020 1021 1022
 * --------------------------------------------------------------------------
 */
#ifdef NAS_MME
/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
1023
 ** Name:    emm_proc_attach_request()                                 **
Cedric Roux's avatar
 
Cedric Roux committed
1024 1025 1026 1027
 **                                                                        **
 ** Description: Performs the UE requested attach procedure                **
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.3                         **
Cedric Roux's avatar
Cedric Roux committed
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
 **      The network may initiate EMM common procedures, e.g. the  **
 **      identification, authentication and security mode control  **
 **      procedures during the attach procedure, depending on the  **
 **      information received in the ATTACH REQUEST message (e.g.  **
 **      IMSI, GUTI and KSI).                                      **
 **                                                                        **
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      type:      Type of the requested attach               **
 **      native_ksi:    TRUE if the security context is of type    **
 **             native (for KSIASME)                       **
 **      ksi:       The NAS ket sey identifier                 **
 **      native_guti:   TRUE if the provided GUTI is native GUTI   **
 **      guti:      The GUTI if provided by the UE             **
 **      imsi:      The IMSI if provided by the UE             **
 **      imei:      The IMEI if provided by the UE             **
 **      tai:       Identifies the last visited tracking area  **
 **             the UE is registered to                    **
 **      eea:       Supported EPS encryption algorithms        **
 **      eia:       Supported EPS integrity algorithms         **
 **      esm_msg:   PDN connectivity request ESM message       **
 **      Others:    _emm_data                                  **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
1053 1054 1055
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
Cedric Roux's avatar
Cedric Roux committed
1056 1057
                            int native_ksi, int ksi, int native_guti,
                            GUTI_t *guti, imsi_t *imsi, imei_t *imei,
gauthier's avatar
gauthier committed
1058 1059 1060
                            tai_t *tai,
                            int eea, int eia, int ucs2, int uea, int uia, int gea,
                            int umts_present, int gprs_present,
Cedric Roux's avatar
Cedric Roux committed
1061
                            const OctetString *esm_msg)
Cedric Roux's avatar
 
Cedric Roux committed
1062 1063 1064 1065 1066 1067 1068 1069
{
    LOG_FUNC_IN;

    int rc;
    emm_data_context_t ue_ctx;

    LOG_TRACE(INFO, "EMM-PROC  - EPS attach type = %s (%d) requested (ueid=0x%08x)",
              _emm_attach_type_str[type], type, ueid);
gauthier's avatar
gauthier committed
1070 1071
    LOG_TRACE(INFO, "EMM-PROC  - umts_present = %u umts_present = %u",
            umts_present, gprs_present);
Cedric Roux's avatar
 
Cedric Roux committed
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093

    /* Initialize the temporary UE context */
    memset(&ue_ctx, 0 , sizeof(emm_data_context_t));
    ue_ctx.is_dynamic = FALSE;
    ue_ctx.ueid = ueid;

#if !defined(EPC_BUILD)
    /* UE identifier sanity check */
    if (ueid >= EMM_DATA_NB_UE_MAX) {
        ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE;
        /* Do not accept UE with invalid identifier */
        rc = _emm_attach_reject(&ue_ctx);
        LOG_FUNC_RETURN(rc);
    }
#endif

    /* 3GPP TS 24.301, section 5.5.1.1
     * MME not configured to support attach for emergency bearer services
     * shall reject any request to attach with an attach type set to "EPS
     * emergency attach".
     */
    if ( !(_emm_data.conf.features & MME_API_EMERGENCY_ATTACH) &&
Cedric Roux's avatar
Cedric Roux committed
1094
            (type == EMM_ATTACH_TYPE_EMERGENCY) ) {
Cedric Roux's avatar
 
Cedric Roux committed
1095 1096 1097 1098 1099 1100 1101
        ue_ctx.emm_cause = EMM_CAUSE_IMEI_NOT_ACCEPTED;
        /* Do not accept the UE to attach for emergency services */
        rc = _emm_attach_reject(&ue_ctx);
        LOG_FUNC_RETURN(rc);
    }

    /* Get the UE's EMM context if it exists */
Cedric Roux's avatar
Cedric Roux committed
1102
    emm_data_context_t **emm_ctx = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
1103 1104

#if defined(EPC_BUILD)
Cedric Roux's avatar
Cedric Roux committed
1105
    emm_data_context_t *temp = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
1106 1107 1108 1109 1110 1111 1112 1113

    temp    = emm_data_context_get(&_emm_data, ueid);
    emm_ctx = &temp;
#else
    emm_ctx = &_emm_data.ctx[ueid];
#endif

    if (*emm_ctx != NULL) {
Cedric Roux's avatar
Cedric Roux committed
1114 1115
        /* An EMM context already exists for the UE in the network */
        if (_emm_attach_have_changed(*emm_ctx, type, ksi, guti, imsi, imei,
gauthier's avatar
gauthier committed
1116
                eea, eia, ucs2, uea, uia, gea, umts_present, gprs_present)) {
Cedric Roux's avatar
Cedric Roux committed
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
            /*
             * 3GPP TS 24.301, section 5.5.1.2.7, abnormal case e
             * The attach parameters have changed from the one received within
             * the previous Attach Request message;
             * the previously initiated attach procedure shall be aborted and
             * the new attach procedure shall be executed;
             */
            LOG_TRACE(WARNING, "EMM-PROC  - Attach parameters have changed");
            /*
             * Notify EMM that the attach procedure is aborted
             */
            emm_sap_t emm_sap;
            emm_sap.primitive = EMMREG_PROC_ABORT;
            emm_sap.u.emm_reg.ueid = ueid;
Cedric Roux's avatar
 
Cedric Roux committed
1131 1132
            emm_sap.u.emm_reg.ctx  = *emm_ctx;

Cedric Roux's avatar
Cedric Roux committed
1133 1134 1135 1136 1137 1138 1139
            rc = emm_sap_send(&emm_sap);

            if (rc != RETURNerror) {
                /* Process new attach procedure */
                LOG_TRACE(WARNING, "EMM-PROC  - Initiate new attach procedure");
                rc = emm_proc_attach_request(ueid, type, native_ksi, ksi,
                                             native_guti, guti, imsi, imei,
gauthier's avatar
gauthier committed
1140 1141
                                             tai, eea, eia, ucs2, uea, uia, gea,
                                             umts_present, gprs_present, esm_msg);
Cedric Roux's avatar
Cedric Roux committed
1142 1143 1144 1145 1146 1147 1148 1149 1150
            }
            LOG_FUNC_RETURN(rc);
        } else {
            /* Continue with the previous attach procedure */
            LOG_TRACE(WARNING, "EMM-PROC  - Received duplicated Attach Request");
            LOG_FUNC_RETURN(RETURNok);
        }
    } else {
        /* Create UE's EMM context */
1151
        *emm_ctx = (emm_data_context_t *)calloc(1, sizeof(emm_data_context_t));
Cedric Roux's avatar
Cedric Roux committed
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
        if (emm_ctx == NULL) {
            LOG_TRACE(WARNING, "EMM-PROC  - Failed to create EMM context");
            ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE;
            /* Do not accept the UE to attach to the network */
            rc = _emm_attach_reject(&ue_ctx);
            LOG_FUNC_RETURN(rc);
        }
        (*emm_ctx)->is_dynamic = TRUE;
        (*emm_ctx)->guti = NULL;
        (*emm_ctx)->old_guti = NULL;
        (*emm_ctx)->imsi = NULL;
        (*emm_ctx)->imei = NULL;
        (*emm_ctx)->security = NULL;
        (*emm_ctx)->esm_msg.length = 0;
        (*emm_ctx)->esm_msg.value = NULL;
        (*emm_ctx)->emm_cause = EMM_CAUSE_SUCCESS;
1168
        (*emm_ctx)->_emm_fsm_status = EMM_INVALID;
1169
        (*emm_ctx)->ueid = ueid;
Cedric Roux's avatar
 
Cedric Roux committed
1170

1171
        emm_fsm_set_status(ueid, *emm_ctx, EMM_DEREGISTERED);
Cedric Roux's avatar
 
Cedric Roux committed
1172 1173 1174
#if defined(EPC_BUILD)
        emm_data_context_add(&_emm_data, *(emm_ctx));
#endif
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

#warning "TRICK TO SET TAC, BUT LOOK AT SPEC"
        if (tai){
            LOG_TRACE(WARNING,
                "EMM-PROC  - Set tac %u in context %u ",
                tai->tac);
            (*emm_ctx)->tac = tai->tac;
        } else {
            LOG_TRACE(WARNING,
                "EMM-PROC  - Could not set tac in context, cause tai is NULL ");
        }
Cedric Roux's avatar
 
Cedric Roux committed
1186 1187 1188 1189
    }

    /* Update the EMM context with the current attach procedure parameters */
    rc = _emm_attach_update(*emm_ctx, ueid, type, ksi, guti, imsi, imei,
gauthier's avatar
gauthier committed
1190
            eea, eia, ucs2, uea, uia, gea, umts_present, gprs_present, esm_msg);
Cedric Roux's avatar
 
Cedric Roux committed
1191
    if (rc != RETURNok) {
Cedric Roux's avatar
Cedric Roux committed
1192 1193 1194 1195 1196 1197 1198 1199 1200
        LOG_TRACE(WARNING, "EMM-PROC  - Failed to update EMM context");
        /* Do not accept the UE to attach to the network */
        (*emm_ctx)->emm_cause = EMM_CAUSE_ILLEGAL_UE;
        rc = _emm_attach_reject(*emm_ctx);
    } else {
        /*
         * Performs UE identification
         */
        rc = _emm_attach_identify(*emm_ctx);
Cedric Roux's avatar
 
Cedric Roux committed
1201 1202 1203 1204 1205 1206 1207
    }

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
1208
 ** Name:        emm_proc_attach_reject()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
1209 1210 1211 1212
 **                                                                        **
 ** Description: Performs the protocol error abnormal case                 **
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.7, case b                 **
1213 1214
 **              If the ATTACH REQUEST message is received with a protocol **
 **              error, the network shall return an ATTACH REJECT message. **
Cedric Roux's avatar
 
Cedric Roux committed
1215
 **                                                                        **
1216 1217 1218
 ** Inputs:  ueid:              UE lower layer identifier                  **
 **                  emm_cause: EMM cause code to be reported              **
 **                  Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
1219
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
1220
 ** Outputs:     None                                                      **
1221 1222
 **                  Return:    RETURNok, RETURNerror                      **
 **                  Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
 **                                                                        **
 ***************************************************************************/
int emm_proc_attach_reject(unsigned int ueid, int emm_cause)
{
    LOG_FUNC_IN;

    int rc;

    /* Create temporary UE context */
    emm_data_context_t ue_ctx;
    memset(&ue_ctx, 0 , sizeof(emm_data_context_t));
    ue_ctx.is_dynamic = FALSE;
    ue_ctx.ueid = ueid;

    /* Update the EMM cause code */
#if defined(EPC_BUILD)
1239
    if (ueid > 0)
Cedric Roux's avatar
 
Cedric Roux committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
#else
    if (ueid < EMM_DATA_NB_UE_MAX)
#endif
    {
        ue_ctx.emm_cause = emm_cause;
    } else {
        ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE;
    }

    /* Do not accept attach request with protocol error */
    rc = _emm_attach_reject(&ue_ctx);

    LOG_FUNC_RETURN(rc);
}

/****************************************************************************
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
1257
 ** Name:    emm_proc_attach_complete()                                **
Cedric Roux's avatar
 
Cedric Roux committed
1258 1259
 **                                                                        **
 ** Description: Terminates the attach procedure upon receiving Attach     **
Cedric Roux's avatar
Cedric Roux committed
1260
 **      Complete message from the UE.                             **
Cedric Roux's avatar
 
Cedric Roux committed
1261 1262
 **                                                                        **
 **              3GPP TS 24.301, section 5.5.1.2.4                         **
Cedric Roux's avatar
Cedric Roux committed
1263 1264 1265
 **      Upon receiving an ATTACH COMPLETE message, the MME shall  **
 **      stop timer T3450, enter state EMM-REGISTERED and consider **
 **      the GUTI sent in the ATTACH ACCEPT message as valid.      **
Cedric Roux's avatar
 
Cedric Roux committed
1266
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
1267 1268 1269 1270
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **      esm_msg:   Activate default EPS bearer context accept **
 **             ESM message                                **
 **      Others:    _emm_data                                  **
Cedric Roux's avatar
 
Cedric Roux committed
1271
 **                                                                        **
Cedric Roux's avatar
Cedric Roux committed
1272 1273 1274
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    _emm_data, T3450                           **
Cedric Roux's avatar
 
Cedric Roux committed
1275 1276
 **                                                                        **
 ***************************************************************************/
Cedric Roux's avatar
Cedric Roux committed
1277
int emm_proc_attach_complete(unsigned int ueid, const OctetString *esm_msg)
Cedric Roux's avatar
 
Cedric Roux committed
1278
{
1279
    emm_data_context_t *emm_ctx = NULL;
Cedric Roux's avatar
 
Cedric Roux committed
1280 1281 1282 1283
    int rc = RETURNerror;
    emm_sap_t emm_sap;
    esm_sap_t esm_sap;

1284 1285
    LOG_FUNC_IN;

Cedric Roux's avatar
 
Cedric Roux committed
1286 1287 1288 1289 1290 1291 1292
    LOG_TRACE(INFO, "EMM-PROC  - EPS attach complete (ueid=%u)", ueid);

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

    /* Release retransmission timer parameters */
Cedric Roux's avatar
Cedric Roux committed
1293
    attach_data_t *data = (attach_data_t *)(emm_proc_common_get_args(ueid));
Cedric Roux's avatar
 
Cedric Roux committed
1294
    if (data) {
Cedric Roux's avatar
Cedric Roux committed
1295 1296 1297 1298
        if (data->esm_msg.length > 0) {
            free(data->esm_msg.value);
        }
        free(data);
Cedric Roux's avatar
 
Cedric Roux committed
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
    }

    /* 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) {
Cedric Roux's avatar
Cedric Roux committed
1309
        emm_ctx = _emm_data.ctx[ueid];
Cedric Roux's avatar
 
Cedric Roux committed
1310 1311 1312 1313
    }
#endif

    if (emm_ctx) {
Cedric Roux's avatar
Cedric Roux committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
        /* Delete the old GUTI and consider the GUTI sent in the Attach
         * Accept message as valid */
        emm_ctx->guti_is_new = FALSE;
        emm_ctx->old_guti = NULL;
        /*
         * Forward the Activate Default EPS Bearer Context Accept message
         * to the EPS session management sublayer
         */
        esm_sap.primitive = ESM_DEFAULT_EPS_BEARER_CONTEXT_ACTIVATE_CNF;
        esm_sap.is_standalone = FALSE;
        esm_sap.ueid = ueid;
        esm_sap.recv = esm_msg;
1326
        esm_sap.ctx  = emm_ctx;
Cedric Roux's avatar
Cedric Roux committed
1327 1328 1329
        rc = esm_sap_send(&esm_sap);
    } else {
        LOG_TRACE(ERROR, "EMM-PROC  - No EMM context exists");
Cedric Roux's avatar
 
Cedric Roux committed
1330 1331 1332
    }

    if ( (rc != RETURNerror) && (esm_sap.err == ESM_SAP_SUCCESS) ) {
Cedric Roux's avatar
Cedric Roux committed
1333 1334 1335 1336 1337 1338 1339
        /* Set the network attachment indicator */
        emm_ctx->is_attached = TRUE;
        /*
         * Notify EMM that attach procedure has successfully completed
         */
        emm_sap.primitive = EMMREG_ATTACH_CNF;
        emm_sap.u.emm_reg.ueid = ueid;
1340
        emm_sap.u.emm_reg.ctx  = emm_ctx;
Cedric Roux's avatar
Cedric Roux committed
1341 1342 1343 1344 1345 1346 1347
        rc = emm_sap_send(&emm_sap);
    } else if (esm_sap.err != ESM_SAP_DISCARDED) {
        /*
         * Notify EMM that attach procedure failed
         */
        emm_sap.primitive = EMMREG_ATTACH_REJ;
        emm_sap.u.emm_reg.ueid = ueid;
1348
        emm_sap.u.emm_reg.ctx  = emm_ctx;
Cedric Roux's avatar
Cedric Roux committed
1349 1350 1351 1352 1353 1354 1355
        rc = emm_sap_send(&emm_sap);
    } else {
        /*
         * ESM procedure failed and, received message has been discarded or
         * Status message has been returned; ignore ESM procedure failure
         */
        rc = RETURNok;
Cedric Roux's avatar
 
Cedric Roux committed
1356 1357 1358 1359 1360
    }

    LOG_FUNC_RETURN(rc);
}

Cedric Roux's avatar
Cedric Roux committed
1361
#endif  // NAS_MME
Cedric Roux's avatar
 
Cedric Roux committed
1362 1363 1364 1365 1366 1367 1368 1369

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

#ifdef NAS_UE
/*
 * --------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
1370