/****************************************************************************
 **                                                                        **
 ** Name:    EmmDeregisteredAttemptingToAttach()                       **
 **                                                                        **
 ** Description: Handles the behaviour of the UE while the EMM-SAP is in   **
 **      EMM-DEREGISTERED.ATTEMPTING-TO-ATTACH state.              **
 **                                                                        **
 **              3GPP TS 24.301, section 5.2.2.3.3                         **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmDeregisteredAttemptingToAttach(const emm_reg_t *evt)
{
  LOG_FUNC_IN;

  int rc = RETURNerror;

  assert(emm_fsm_get_status() == EMM_DEREGISTERED_ATTEMPTING_TO_ATTACH);

  switch (evt->primitive) {
  case _EMMREG_ATTACH_INIT:

    /*
     * Attach procedure has to be restarted (timers T3402 or T3411
     * expired)
     */

    /* Move to the corresponding initial EMM state */
    if (evt->u.attach.is_emergency) {
      rc = emm_fsm_set_status(EMM_DEREGISTERED_LIMITED_SERVICE);
    } else {
      rc = emm_fsm_set_status(EMM_DEREGISTERED_NORMAL_SERVICE);
    }

    if (rc != RETURNerror) {
      /* Restart the attach procedure */
      rc = emm_proc_attach_restart();
    }

    break;

  case _EMMREG_LOWERLAYER_SUCCESS:
    /*
     * Data successfully delivered to the network
     */
    rc = emm_proc_lowerlayer_success();
    break;

  case _EMMREG_LOWERLAYER_FAILURE:
    /*
     * Data failed to be delivered to the network
     */
    rc = emm_proc_lowerlayer_failure(FALSE);
    break;

  default:
    LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
              evt->primitive);
    break;
  }

  LOG_FUNC_RETURN (rc);
}
/****************************************************************************
 **                                                                        **
 ** Name:    EmmDeregisteredNoCellAvailable()                          **
 **                                                                        **
 ** Description: Handles the behaviour of the UE while the EMM-SAP is in   **
 **      EMM-DEREGISTERED.NO-CELL-AVAILABLE state.                 **
 **                                                                        **
 **              3GPP TS 24.301, section 5.2.2.3.7                         **
 **      The UE shall perform cell selection and choose an appro-  **
 **      priate substate when a cell is found.                     **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmDeregisteredNoCellAvailable(nas_user_t *user, const emm_reg_t *evt)
{
  LOG_FUNC_IN;

  int rc = RETURNerror;
  emm_data_t *emm_data = user->emm_data;
  user_api_id_t *user_api_id = user->user_api_id;

  assert(emm_fsm_get_status(user) == EMM_DEREGISTERED_NO_CELL_AVAILABLE);

  switch (evt->primitive) {
    /* TODO: network re-selection is not allowed when in No Cell
     * Available substate. The AS should search for a suitable cell
     * and notify the NAS when such a cell is found (TS 24.008 section
     * 4.2.4.1.2) */
  case _EMMREG_REGISTER_REQ:
    /*
     * The user manually re-selected a PLMN to register to
     */
    rc = emm_fsm_set_status(user, EMM_DEREGISTERED_PLMN_SEARCH);

    if (rc != RETURNerror) {
      /*
       * Notify EMM that the MT is currently searching an operator
       * to register to
       */
      rc = emm_proc_registration_notify(user_api_id, emm_data, NET_REG_STATE_ON);

      if (rc != RETURNok) {
        LOG_TRACE(WARNING, "EMM-FSM   - "
                  "Failed to notify registration update");
      }

      /*
       * Perform network re-selection procedure
       */
      rc = emm_proc_plmn_selection(user, evt->u.regist.index);
    }

    break;

  default:
    LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
              evt->primitive);
    break;
  }

  LOG_FUNC_RETURN (rc);
}
Example #3
0
/****************************************************************************
 **                                                                        **
 ** Name:    EmmNull()                                                 **
 **                                                                        **
 ** Description: Handles the behaviour of the UE while the EMM-SAP is in   **
 **      EMM-NULL state.                                           **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmNull(const emm_reg_t *evt)
{
    LOG_FUNC_IN;

    int rc;

    assert(emm_fsm_get_status() == EMM_NULL);

    /* Delete the authentication data RAND and RES */
    rc = emm_proc_authentication_delete();
    if (rc != RETURNok) {
        LOG_FUNC_RETURN (rc);
    }

    switch (evt->primitive) {
        case _EMMREG_S1_ENABLED:
            /*
             * The EPS capability has been enabled in the UE:
             * Move to the DEREGISTERED state;
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED);

            /*
             * And initialize the EMM procedure call manager in order to
             * establish an EMM context and make the UE reachable by an MME.
             */
            if (rc != RETURNerror) {
                rc = emm_proc_initialize();
            }
            break;

        default:
            rc = RETURNerror;
            LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
                      evt->primitive);
            LOG_TRACE(WARNING, "EMM-FSM   - Set phone functionnality to "
                      "enable EPS capability (+cfun=1)");
            break;
    }

    LOG_FUNC_RETURN (rc);
}
/****************************************************************************
 **                                                                        **
 ** Name:    EmmRegisteredInitiated()                                  **
 **                                                                        **
 ** Description: Handles the behaviour of the UE while the EMM-SAP is in   **
 **      EMM-REGISTERED-INITIATED state.                           **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmRegisteredInitiated(const emm_reg_t *evt)
{
    LOG_FUNC_IN;

    int rc = RETURNerror;

    assert(emm_fsm_get_status() == EMM_REGISTERED_INITIATED);

    switch (evt->primitive) {
        case _EMMREG_ATTACH_INIT:
            /*
             * Attach procedure has to be restarted (timers T3402 or T3411
             * expired)
             */

            /* Move to the corresponding initial EMM state */
            if (evt->u.attach.is_emergency) {
                rc = emm_fsm_set_status(EMM_DEREGISTERED_LIMITED_SERVICE);
            } else {
                rc = emm_fsm_set_status(EMM_DEREGISTERED_NORMAL_SERVICE);
            }
            if (rc != RETURNerror) {
                /* Restart the attach procedure */
                rc = emm_proc_attach_restart();
            }
            break;

        case _EMMREG_ATTACH_FAILED:
            /*
             * Attempt to attach to the network failed (abnormal case or
             * timer T3410 expired). The network attach procedure shall be
             * restarted when timer T3411 expires.
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_ATTEMPTING_TO_ATTACH);
            break;

        case _EMMREG_ATTACH_EXCEEDED:
            /*
             * Attempt to attach to the network failed (abnormal case or
             * timer T3410 expired) and the attach attempt counter reached
             * its maximum value. The state is changed to EMM-DEREGISTERED.
             * ATTEMPTING-TO-ATTACH or optionally to EMM-DEREGISTERED.PLMN-
             * SEARCH in order to perform a PLMN selection.
             */
            /* TODO: ATTEMPTING-TO-ATTACH or PLMN-SEARCH ??? */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_ATTEMPTING_TO_ATTACH);
            break;

        case _EMMREG_ATTACH_CNF:
            /*
             * EPS network attach accepted by the network;
             * enter state EMM-REGISTERED.
             */
            rc = emm_fsm_set_status(EMM_REGISTERED);

            if (rc != RETURNerror) {
                /*
                 * Notify EMM that the MT is registered
                 */
                rc = emm_proc_registration_notify(NET_REG_STATE_HN);
                if (rc != RETURNok) {
                    LOG_TRACE(WARNING, "EMM-FSM   - "
                              "Failed to notify registration update");
                }
            }
            break;

        case _EMMREG_AUTH_REJ:
            /*
             * UE authentication rejected by the network;
             * abort any EMM signalling procedure
             */
        case _EMMREG_ATTACH_REJ:
            /*
             * EPS network attach rejected by the network;
             * enter state EMM-DEREGISTERED.
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED);

            if (rc != RETURNerror) {
                /*
                 * Notify EMM that the MT's registration is denied
                 */
                rc = emm_proc_registration_notify(NET_REG_STATE_DENIED);
                if (rc != RETURNok) {
                    LOG_TRACE(WARNING, "EMM-FSM   - "
                              "Failed to notify registration update");
                }
            }
            break;

        case _EMMREG_REGISTER_REQ:
            /*
             * The UE has to select a new PLMN to register to
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_PLMN_SEARCH);
            if (rc != RETURNerror) {
                /* Process the network registration request */
                rc = emm_fsm_process(evt);
            }
            break;

        case _EMMREG_REGISTER_REJ:
            /*
             * The UE failed to register to the network for normal EPS service
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_LIMITED_SERVICE);
            break;

        case _EMMREG_NO_IMSI:
            /*
             * The UE failed to register to the network for emergency
             * bearer services
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_NO_IMSI);
            break;

        case _EMMREG_DETACH_INIT:
            /*
             * Initiate detach procedure for EPS services
             */
            rc = emm_proc_detach(EMM_DETACH_TYPE_EPS, evt->u.detach.switch_off);
            break;

        case _EMMREG_DETACH_REQ:
            /*
             * An EPS network detach has been requested (Detach Request
             * message successfully delivered to the network);
             * enter state EMM-DEREGISTERED-INITIATED
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_INITIATED);
            break;

        case _EMMREG_LOWERLAYER_SUCCESS:
            /*
             * Data transfer message has been successfully delivered;
             * The NAS message may be Attach Complete, Detach Request or
             * any message transfered by EMM common procedures requested
             * by the network.
             */
            rc = emm_proc_lowerlayer_success();
            break;

        case _EMMREG_LOWERLAYER_FAILURE:
            /*
             * Data transfer message failed to be delivered;
             * The NAS message may be Attach Complete, Detach Request or
             * any message transfered by EMM common procedures requested
             * by the network.
             */
            rc = emm_proc_lowerlayer_failure(FALSE);
            break;

        case _EMMREG_LOWERLAYER_RELEASE:
            /*
             * NAS signalling connection has been released before the Attach
             * Accept, Attach Reject, or any message transfered by EMM common
             * procedures requested by the network, is received.
             */
            rc = emm_proc_lowerlayer_release();
            break;

        default:
            LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
                      evt->primitive);
            break;
    }

    LOG_FUNC_RETURN (rc);
}
/****************************************************************************
 **                                                                        **
 ** Name:    EmmDeregisteredNormalService()                            **
 **                                                                        **
 ** Description: Handles the behaviour of the UE while the EMM-SAP is in   **
 **      EMM-DEREGISTERED.NORMAL-SERVICE state.                    **
 **                                                                        **
 **              3GPP TS 24.301, section 5.2.2.3.1                         **
 **      The UE shall initiate an attach or combined attach proce- **
 **      dure.                                                     **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmDeregisteredNormalService(const emm_reg_t *evt)
{
  LOG_FUNC_IN;

  int rc = RETURNerror;

  assert(emm_fsm_get_status() == EMM_DEREGISTERED_NORMAL_SERVICE);

  switch (evt->primitive) {
  case _EMMREG_REGISTER_REQ:
    /*
     * The user manually re-selected a PLMN to register to
     */
    rc = emm_fsm_set_status(EMM_DEREGISTERED_PLMN_SEARCH);

    if (rc != RETURNerror) {
      /* Process the network registration request */
      rc = emm_fsm_process(evt);
    }

    break;

  case _EMMREG_ATTACH_INIT:
    /*
     * Initiate the attach procedure for EPS services
     */
    rc = emm_proc_attach(EMM_ATTACH_TYPE_EPS);
    break;

  case _EMMREG_ATTACH_REQ:
    /*
     * An EPS network attach has been requested (Attach Request
     * message successfully delivered to the network);
     * enter state EMM-REGISTERED-INITIATED
     */
    rc = emm_fsm_set_status(EMM_REGISTERED_INITIATED);
    break;

  case _EMMREG_LOWERLAYER_SUCCESS:
    /*
     * Initial NAS message has been successfully delivered
     * to the network
     */
    rc = emm_proc_lowerlayer_success();
    break;

  case _EMMREG_LOWERLAYER_FAILURE:
    /*
     * Initial NAS message failed to be delivered to the network
     */
    rc = emm_proc_lowerlayer_failure(TRUE);
    break;

  case _EMMREG_LOWERLAYER_RELEASE:
    /*
     * NAS signalling connection has been released
     */
    rc = emm_proc_lowerlayer_release();
    break;

  case _EMMREG_ATTACH_CNF:
    /*
     * Attach procedure successful and default EPS bearer
     * context activated;
     * enter state EMM-REGISTERED.
     */
    rc = emm_fsm_set_status(EMM_REGISTERED);
    break;

  default:
    LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
              evt->primitive);
    break;
  }

  LOG_FUNC_RETURN (rc);
}
/****************************************************************************
 **                                                                        **
 ** Name:    EmmCommonProcedureInitiated()                             **
 **                                                                        **
 ** Description: Handles the behaviour of the MME while the EMM-SAP is in  **
 **      EMM_COMMON_PROCEDURE_INITIATED state.                     **
 **                                                                        **
 **              3GPP TS 24.301, section 5.1.3.4.2                         **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmCommonProcedureInitiated(const emm_reg_t *evt)
{
  int rc = RETURNerror;

  LOG_FUNC_IN;

  assert(emm_fsm_get_status(evt->ueid,
                            evt->ctx) == EMM_COMMON_PROCEDURE_INITIATED);

  switch (evt->primitive) {
  case _EMMREG_PROC_ABORT:
    /*
     * The EMM procedure that initiated EMM common procedure aborted
     */
    rc = emm_proc_common_abort(evt->ueid);
    break;

  case _EMMREG_COMMON_PROC_CNF:

    /*
     * An EMM common procedure successfully completed;
     */
    if (evt->u.common.is_attached) {
      rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_REGISTERED);
    } else {
      rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_DEREGISTERED);
    }

    if (rc != RETURNerror) {
      rc = emm_proc_common_success(evt->ueid);
    }

    break;

  case _EMMREG_COMMON_PROC_REJ:
    /*
     * An EMM common procedure failed;
     * enter state EMM-DEREGISTERED.
     */
    rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_DEREGISTERED);

    if (rc != RETURNerror) {
      rc = emm_proc_common_reject(evt->ueid);
    }

    break;

  case _EMMREG_ATTACH_CNF:
    /*
     * Attach procedure successful and default EPS bearer
     * context activated;
     * enter state EMM-REGISTERED.
     */
    rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_REGISTERED);
    break;

  case _EMMREG_ATTACH_REJ:
    /*
     * Attach procedure failed;
     * enter state EMM-DEREGISTERED.
     */
    rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_DEREGISTERED);
    break;

  case _EMMREG_LOWERLAYER_SUCCESS:
    /*
     * Data successfully delivered to the network
     */
    rc = RETURNok;
    break;

  case _EMMREG_LOWERLAYER_FAILURE:
    /*
     * Transmission failure occurred before the EMM common
     * procedure being completed
     */
    rc = emm_proc_common_failure(evt->ueid);

    if (rc != RETURNerror) {
      rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_DEREGISTERED);
    }

    break;

  default:
    LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
              evt->primitive);
    break;
  }

  LOG_FUNC_RETURN (rc);
}
Example #7
0
/****************************************************************************
 **                                                                        **
 ** Name:    EmmRegistered()                                           **
 **                                                                        **
 ** Description: Handles the behaviour of the UE and the MME while the     **
 **      EMM-SAP is in EMM-REGISTERED state.                       **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmRegistered(const emm_reg_t *evt)
{
    LOG_FUNC_IN;

    int rc = RETURNerror;

#ifdef NAS_UE
    assert(emm_fsm_get_status() == EMM_REGISTERED);
#endif
#ifdef NAS_MME
    assert(emm_fsm_get_status(evt->ueid, evt->ctx) == EMM_REGISTERED);
#endif

    switch (evt->primitive) {
#ifdef NAS_UE
        case _EMMREG_DETACH_INIT:
            /*
             * Initiate detach procedure for EPS services
             */
            rc = emm_proc_detach(EMM_DETACH_TYPE_EPS, evt->u.detach.switch_off);
            break;

        case _EMMREG_DETACH_REQ:
            /*
             * Network detach has been requested (Detach Request
             * message successfully delivered to the network);
             * enter state EMM-DEREGISTERED-INITIATED
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_INITIATED);
            break;

        case _EMMREG_DETACH_CNF:
            /*
             * The UE implicitly detached from the network (all EPS
             * bearer contexts may have been deactivated)
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED);
            break;

        case _EMMREG_TAU_REQ:
            /*
             * TODO: Tracking Area Update has been requested
             */
            LOG_TRACE(ERROR, "EMM-FSM   - Tracking Area Update procedure "
                      "is not implemented");
            break;

        case _EMMREG_SERVICE_REQ:
            /*
             * TODO: Service Request has been requested
             */
            LOG_TRACE(ERROR, "EMM-FSM   - Service Request procedure "
                      "is not implemented");
            break;

        case _EMMREG_LOWERLAYER_SUCCESS:
            /*
             * Data transfer message has been successfully delivered
             */
            rc = emm_proc_lowerlayer_success();
            break;

        case _EMMREG_LOWERLAYER_FAILURE:
            /*
             * Data transfer message failed to be delivered
             */
            rc = emm_proc_lowerlayer_failure(FALSE);
            break;

        case _EMMREG_LOWERLAYER_RELEASE:
            /*
             * NAS signalling connection has been released
             */
            rc = emm_proc_lowerlayer_release();
            break;
#endif

#ifdef NAS_MME
        case _EMMREG_DETACH_REQ:
            /*
             * Network detach has been requested (implicit detach);
             * enter state EMM-DEREGISTERED
             */
            rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_DEREGISTERED);
            break;

        case _EMMREG_COMMON_PROC_REQ:
            /*
             * An EMM common procedure has been initiated;
             * enter state EMM-COMMON-PROCEDURE-INITIATED.
             */
            rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_COMMON_PROCEDURE_INITIATED);
            break;

        case _EMMREG_TAU_REJ:
            /*
             * TODO: Tracking Area Update has been rejected
             */
            LOG_TRACE(ERROR, "EMM-FSM   - Tracking Area Update procedure "
                      "is not implemented");
            break;

        case _EMMREG_LOWERLAYER_SUCCESS:
            /*
             * Data successfully delivered to the network
             */
            rc = RETURNok;
            break;

        case _EMMREG_LOWERLAYER_FAILURE:
            /*
             * Data failed to be delivered to the network
             */
            rc = RETURNok;
            break;
#endif

        default:
            LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
                      evt->primitive);
            break;
    }

    LOG_FUNC_RETURN (rc);
}
Example #8
0
/****************************************************************************
 **                                                                        **
 ** Name:    EmmDeregistered()                                         **
 **                                                                        **
 ** Description: Handles the behaviour of the UE and the MME while the     **
 **      EMM-SAP is in EMM-DEREGISTERED state.                     **
 **                                                                        **
 **              3GPP TS 24.301, section 5.2.2.2                           **
 **                                                                        **
 ** Inputs:  evt:       The received EMM-SAP event                 **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ** Outputs:     None                                                      **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    emm_fsm_status                             **
 **                                                                        **
 ***************************************************************************/
int EmmDeregistered(const emm_reg_t *evt)
{
    LOG_FUNC_IN;

    int rc = RETURNerror;

#ifdef NAS_UE
    assert(emm_fsm_get_status() == EMM_DEREGISTERED);
#endif
#ifdef NAS_MME
    assert(emm_fsm_get_status(evt->ueid, evt->ctx) == EMM_DEREGISTERED);
#endif

#ifdef NAS_UE
    /* Delete the authentication data RAND and RES */
    rc = emm_proc_authentication_delete();
    if (rc != RETURNok) {
        LOG_FUNC_RETURN (rc);
    }
    /* TODO: 3GPP TS 24.301, section 4.4.2.1
     * The UE shall store the current native EPS security context as specified
     * in annex C and mark it as valid only when the UE enters state EMM-
     * DEREGISTERED from any other state except EMM-NULL or when the UE aborts
     * the attach procedure without having left EMM-DEREGISTERED.
     */
#endif

    switch (evt->primitive) {

#ifdef NAS_UE
        case _EMMREG_NO_IMSI:
            /*
             * The UE was powered on without a valid USIM application present
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_NO_IMSI);
            break;

        case _EMMREG_REGISTER_REQ:
            /*
             * The default EMM primary substate when the UE is switched on
             * with valid USIM application shall be PLMN-SEARCH
             */
            rc = emm_fsm_set_status(EMM_DEREGISTERED_PLMN_SEARCH);
            if (rc != RETURNerror) {
                /* Process the network registration request */
                rc = emm_fsm_process(evt);
            }
            break;

        case _EMMREG_ATTACH_INIT:
            /*
             * Attach procedure has to be restarted (timers T3402 or T3411
             * expired) while the UE locally detached from the network
             */

            /* Move to the corresponding initial EMM state */
            if (evt->u.attach.is_emergency) {
                rc = emm_fsm_set_status(EMM_DEREGISTERED_LIMITED_SERVICE);
            } else {
                rc = emm_fsm_set_status(EMM_DEREGISTERED_NORMAL_SERVICE);
            }
            if (rc != RETURNerror) {
                /* Restart the attach procedure */
                rc = emm_proc_attach_restart();
            }
            break;

#endif

#ifdef NAS_MME
        case _EMMREG_PROC_ABORT:
            /*
             * Ongoing EMM procedure aborted
             */
            rc = RETURNok;
            break;

        case _EMMREG_COMMON_PROC_REQ:
            /*
             * An EMM common procedure has been initiated;
             * enter state EMM-COMMON-PROCEDURE-INITIATED.
             */
            rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_COMMON_PROCEDURE_INITIATED);
            break;

        case _EMMREG_ATTACH_CNF:
            /*
             * Attach procedure successful and default EPS bearer
             * context activated;
             * enter state EMM-REGISTERED.
             */
            rc = emm_fsm_set_status(evt->ueid, evt->ctx, EMM_REGISTERED);
            break;

#endif

        case _EMMREG_LOWERLAYER_SUCCESS:
            /*
             * Data successfully delivered to the network
             */
            rc = RETURNok;
            break;

        case _EMMREG_LOWERLAYER_FAILURE:
            /*
             * Data failed to be delivered to the network
             */
            rc = RETURNok;
            break;

        default:
            LOG_TRACE(ERROR, "EMM-FSM   - Primitive is not valid (%d)",
                      evt->primitive);
            break;
    }

#ifdef NAS_UE
    /* TODO: 3GPP TS 24.301, section 4.4.2.1
     * The UE shall mark the EPS security context on the USIM or in the non-
     * volatile memory as invalid when the UE initiates an attach procedure
     * or when the UE leaves state EMM-DEREGISTERED for any other state except
     * EMM-NULL.
     */
#endif

    LOG_FUNC_RETURN (rc);
}