// ***************************************************************************
// @copyright   Copyright Notification
//   No part may be reproduced except as authorized by written permission.
//   The copyright and the foregoing restriction extend to reproduction in all media.
//   Trademark 2010, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_10wk37
// * $Date: 2010-09-16 14:44:20 +0200 (Thu, 16 Sep 2010) $
// * $Rev: 3936 $
// ***************************************************************************

module NAS_Attach_UG {

  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_Component all;
  import from EUTRA_CellInfo all;
  import from Parameters all;
  import from CommonDefs all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_SRB_Templates all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_Paging all;
  import from NAS_CommonTypeDefs all;
  import from EPS_NAS_TypeDefs all;
  import from EPS_NAS_Constants all;
  import from EPS_NAS_Templates all;
  import from NAS_CommonTemplates all;
  import from EUTRA_NASCommonFunctions all;
  import from EUTRA_NASCommonTemplates all;
  import from EPS_NAS_MsgContainers all;
  import from EUTRA_RRCSteps all;
  import from EUTRA_NASSteps all;
  import from EUTRA_ConfigurationSteps all;
  import from UpperTesterFunctions all;
 // import from EUTRA_AuxiliaryFunctions all;
  import from NAS_AuxiliaryDefsAndFunctions all;
  import from CommonIratDefs all;
  import from EUTRA_Timing all;
  import from EUTRA_IRATFunctions all;

  group LocalTemplates {
  } // group LocalTemplates
  
  group LocalFunctions {

      function fl_TC_9_2_1_2_15_AttachRequest_AndWait(float p_Delay_sec, integer p_AttachAttempts, integer p_PassStep) runs on EUTRA_PTC
      {/* @desc  The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message
        *        and wait for p_Delay_sec to ensure that T3410 and T3411 expire
                 and therefore the UE releases locally the NAS signalling connection
        * @param p_Delay_sec
                         Time to wait to ensure the timers expire
       * @param p_AttachAttempt
                         Number of occasions where the two steps task is done,
                         it only denotes the iteration number, not the Attach Attempt Counter in the UE
       * @param p_passStep
                         Iteration within the loop where a partial pass verdict is given
       */
      var NAS_MSG_Indication_Type v_NAS_Ind;
      var integer i;
      var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();
      var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();

      for ( i := 1; i <= p_AttachAttempts; i := i + 1 ) {

        //steps 3,5,7,9,11
        // RRC Connection Establishment, with Attach Request and PDN Connectivity
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                  tsc_RRC_TI_Def,
                                                  cr_EstablishmentCause_Any,
                                                  cr_NAS_IndicationWithPiggybacking((tsc_SHT_NoSecurityProtection,
                                                                                     tsc_SHT_IntegrityProtected),
                                                                                     cr_508_ATTACH_REQUEST(v_AttachType, v_AdditionalUpdateType),
                                                                                     cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                     f_GetPdnType())));

        if (i==p_PassStep)
        {
            f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Attach Request Rx");
        }

        //steps 4,6,8,10,12
        f_Delay(p_Delay_sec);

       }//end for
    } // end fl_TC_9_2_1_2_15_AttachRequest_AndWait

      function fl_TC_9_2_1_2_15_AttachRequest_AndWait_Modified(float p_Delay_sec, integer p_AttachAttempts) runs on EUTRA_PTC
      {/* @desc  The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message
        *        and wait for p_Delay_sec to ensure that T3410 and T3411 expire
        * @param p_Delay_sec
                         Time to wait to ensure the timers expire
       * @param p_AttachAttempt
                         Number of occasions where the two steps task is done,
                         it only denotes the iteration number, not the Attach Attempt Counter in the UE
       */
      var NAS_MSG_Indication_Type v_NAS_Ind;
      var integer i;
      var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();
      var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();

      for ( i := 1; i <= p_AttachAttempts; i := i + 1 ) {

        //steps 17,19,21,23 (25)
        // RRC Connection Establishment, with Attach Request and PDN Connectivity
        v_NAS_Ind:= f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                tsc_RRC_TI_Def,
                                                cr_EstablishmentCause_Any,
                                            cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                    cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                   v_AttachType,
                                                                   v_AdditionalUpdateType,
                                                                   f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                   cr_TMSI_Status('0'B)),
                                            cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                            f_GetPdnType())));

        //steps 18,20,22,24 (26)
        f_Delay(p_Delay_sec);

       }//end for
    } // end fl_TC_9_2_1_2_15_AttachRequest_AndWait_Modified

  } // group LocalFunctions


  group TestcaseImplementations {

 /**
   *@desc: Attach / rejected / EPS services and non-EPS services not allowed (multi RAT test)
   *@note: Only cell selection to UTRAN implemented (GERAN part not yet implemented)
   */
  function f_TC_9_2_1_1_11_EUTRA() runs on EUTRA_PTC
  {
 /*
    Test Purpose (TP)
      (1)
      with { UE has sent an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message }
      ensure that {
        when { UE receives an ATTACH REJECT message with the reject cause set to "EPS services and non-EPS services not allowed" }
          then { UE considers the USIM as invalid for EPS services and non-EPS services and enters state EMM-DEREGISTERED }
                  }
      (2)
      with { UE receives an ATTACH REJECT message with the reject cause set to "EPS services and non-EPS services not allowed" }
      ensure that {
        when { the UE has been switched off, then switched on }
          then { the UE sends an ATTACH REQUEST message with IMSI, including a PDN CONNECTIVITY REQUEST message }
                  }
      (3)
      with { UE receives an ATTACH REJECT message with the reject cause set to "EPS services and non-EPS services not allowed" }
      ensure that {
        when { the UE has been switched off, then switched on and a UMTS or GSM cell is found }
          then { the UE sends an ATTACH REQUEST message with IMSI and TMSI status indicated invalid TMSI }
                  }

    */
    /*
    Pre-test conditions
      System Simulator:
          -    Cell A, Cell B (home PLMN, different TAs) and Cell G (another PLMN)
          -    If pc_UTRAN Cell 5 and if (NOT pc_UTRAN AND pc_GERAN) Cell 24 are configured according to Table 4.4.4-2 in [18].
          -    if pc_UTRAN, Cell 5 (only active when stated)
          -    if pc_GERAN and NOT pc_UTRAN, Cell 24 (only active when stated)
          -    The different cells may not be simultaneously activated.
      UE:
          -   the UE is configured to initiate EPS attach;
          -   the UE is previously registered on E-UTRAN, and when on E-UTRAN, the UE is last authenticated and registered on cell A using default message contents according to TS 36.508 [18];
          -   if pc_UTRAN (respectively if pc_GERAN and NOT pc_UTRAN), the UE is previously registered on UTRAN (respectively GERAN), and when on UTRAN (respectively GERAN), the UE is last registered on cell 5 (respectively cell 24) using default message contents according to TS 36.508 [18].
      Preamble:
          -    The UE is in state Switched OFF (state 1) according to clause [18].

    */
    var boolean v_TriggerRxd := false;

    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_UTRANCell);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_GERANcell);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell);
    }

    f_UT_ConfigureEPSAttach (UT); // R5-103810

    // create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellA);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);
    f_EUTRA_CellConfig_Def(eutra_CellG);

    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE );

    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_1_11_Body();
    // Postamble
    f_EUTRA_TestBody_Set(false);
     f_EUTRA_Postamble(eutra_CellG, E4_DEREGISTERED);

  }// function f_TC_9_2_1_1_11_EUTRA

  function fl_TC_9_2_1_1_11_Body() runs on EUTRA_PTC
  {
    var NAS_MSG_Indication_Type v_NasInd;
    var GutiParameters_Type v_GutiParams := f_EUTRA_CellInfo_GetGuti(eutra_CellA);
    var float v_NoReactionTime := f_EUTRA_SetTimerToleranceMax( eutra_CellB, 3.0 );
    var boolean v_TriggerRxd := false;
    var charstring v_OtherPTC := "";
    var template (value) CellPowerList_Type v_CellPowerList;
    var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();
    var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();

    if (pc_UTRA) {
      v_OtherPTC := "UTRAN";
    } else if (pc_GERAN) {
      v_OtherPTC := "GERAN";
    } else { // Neither UMTS, nor GSM, so just do LTE
      v_OtherPTC := "NONE";
    }

    // Step 1.
    //@siclog "Step 1" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    // Step 2
    //@siclog "Step 2" siclog@
    f_UT_SwitchOnUE (UT, false );

    // Step 3. The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message on cell A.
    //@siclog "Step 3" siclog@
    v_NasInd:= f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                              tsc_RRC_TI_Def,
                                              cr_EstablishmentCause_Any,
                                            cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                        cr_508_ATTACH_REQUEST(v_AttachType, v_AdditionalUpdateType),
                                                        cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                        f_GetPdnType())));

    // Step 4. The SS transmits an ATTACH REJECT message with EMM cause = "EPS services and non-EPS services not allowed" as specified.
    //@siclog "Step 4" siclog@
    SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellA,
                    cs_TimingInfo_Now,
                    cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                             cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_EPSandNonEPSServNotAllowed),
                                                   omit))));

    //@siclog "Step 5" siclog@
    f_EUTRA_RRC_ConnectionRelease(eutra_CellA, tsc_RRC_TI_Def, other);

   //@siclog "Step 6" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 7" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds ?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellB, 30.0, "Step 7" );

    //@siclog "Step 8" siclog@
    //+ The operator initiates an attach by MMI or by AT command.
    f_UT_TriggerAttach(UT);

    //@siclog "Step 9" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds ?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellB, 30.0, "Step 9" );

    //@siclog "Step 10 Void" siclog@

    //@siclog "Step 11" siclog@
    //+ Check: Does the test result of CALL generic procedure indicate that the UE ignores paging on cell B for PS domain with GUTI1?
    f_EUTRA_508Check_NASNoResponse( eutra_CellB,
                               cs_NasPaging_OneRecord ( cs_PagingUE_Identity_S_TMSI ( v_GutiParams.MME_Code, v_GutiParams.M_TMSI )),
                               v_NoReactionTime );

   //@siclog "Step 12" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_ServingCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 13" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds ?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellG, 30.0, "Step 13" );

    //@siclog "Step 14" siclog@
    //+ The operator initiates an attach by MMI or by AT command.
    f_UT_TriggerAttach(UT);

    //@siclog "Step 15" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds ?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellG, 30.0, "Step 15" );

    //@siclog "Step 16" siclog@
    f_UT_SwitchOffUE (UT, false);

    //@siclog "Step 17" siclog@
    f_UT_SwitchOnUE (UT, false );

    //  Check: Does the UE transmit an ATTACH REQUEST message with IMSI-1?
    //@siclog "Step 19" siclog@
    v_NasInd:= f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellG,
                                              tsc_RRC_TI_Def,
                                              cr_EstablishmentCause_Any,
                                              cr_NAS_IndicationWithPiggybacking(tsc_SHT_NoSecurityProtection,
                                                    cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                   v_AttachType,
                                                                   v_AdditionalUpdateType,
                                                                   f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                   omit),
                                                    cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                            f_GetPdnType())));

    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 19");

    //  The SS transmits an ATTACH REJECT message with EMM cause = "EPS services and non-EPS services not allowed" as specified.
    //@siclog "Step 20" siclog@
    SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellG,
                    cs_TimingInfo_Now,
                    cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                             cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_EPSandNonEPSServNotAllowed),
                                                   omit)))); // @sic R5-101012 sic@

    f_EUTRA_RRC_ConnectionRelease(eutra_CellG, tsc_RRC_TI_Def, other); // @sic R5-101012 sic@

    // Cell G as a "Non-Suitable cell" and trigger UTRAN side
    //  to set Utran-Cell5 as serving cell and continue signalling
    //@siclog "Step 21a1" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableCellRS_EPRE )
      };
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
      } case ("GERAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
      } case else { //UE doesn't support other RATs and is already Unattached and Idle, so just switch off
        f_UT_SwitchOffUE (UT, false);
      }
    }
    f_EUTRA_RRC_ConnectionRelease(eutra_CellG, tsc_RRC_TI_Def, other);

  }// function fl_tc_9_2_1_1_11_Body

// @desc Attach/ rejected/ EPS services not allowed
function f_TC_9_2_1_1_12_EUTRA () runs on EUTRA_PTC
{
/* (1) with { UE has sent an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message }
ensure that {
  when { UE receives an ATTACH REJECT message with the reject cause set to "EPS services not allowed" }
then { UE deletes the GUTI and the last visited registered TAI and KSI and considers the USIM as invalid
  for EPS services until switching off or the UICC containing the USIM is removed and deletes the list of
  equivalent PLMNS and UE enters state EMM-DEREGISTERED }
  }

    SS: Cell A, Cell B and Cell G:
        Cell A and Cell B (HPLMN, different TAs),
        Cell G (another PLMN)
        if pc_UTRA, Cell 5 (HPLMN, UTRAN NMO 2)
        if NOT pc_UTRA and pc_GERAN, Cell 24 (HPLMN, GERAN, NMO 2)
     UE: The test USIM contains IMSI-1, GUTI-1 and TAI-1 and EPS update status is "EU1: UPDATED"
         if pc_GERAN or pc_UTRA, the test USIM contains P-TMSI, P-TMSI signature1 and RAI-1 and
         GPRS update status is "GU1: UPDATED" */

    var boolean v_TriggerRxd := false;

    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_UTRANCell);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_GERANcell);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell);
    }

    f_UT_ConfigureEPSAttach (UT); // R5-103810

    // Cells B and G can be implemented as minimum uplink cells
    f_EUTRA_SetCellConfigCapability ( eutra_CellB, minimumUplinkCell );
    f_EUTRA_SetCellConfigCapability ( eutra_CellG, minimumUplinkCell );

    // create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellA);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellG);

    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
    f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_1_12_Body ();
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_Postamble(eutra_CellA, E4_DEREGISTERED);
}
  function fl_TC_9_2_1_1_12_Body() runs on EUTRA_PTC
  {
    var boolean v_TriggerRxd := false;
    //var Common_AuthenticationParams_Type v_Auth_Params;
    var template (value) CellPowerList_Type v_CellPowerList;
    var charstring v_OtherPTC := "";
 
    if (pc_UTRA) {
      v_OtherPTC := "UTRAN";
    } else if (pc_GERAN) {
      v_OtherPTC := "GERAN";
    } else { // Neither UMTS, nor GSM, so just do LTE
      v_OtherPTC := "NONE";
    }

    //@siclog "Step 1" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_SuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableOffCellRS_EPRE )
    }
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    //@siclog "Step 2 - 5" siclog@
    // UE is switched on, sends and ATTACH REQUEST and SS transmits an ATTACH REJECT with reject cause set to illegalME
    f_EUTRA_AttachReject (eutra_CellA, tsc_Cause_EPSServNotAllowed);

    //@siclog "Step 6" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_SuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableOffCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 7" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellB, 30.0 );

    //@siclog "Step 8" siclog@
    f_UT_TriggerAttach (UT);

    //@siclog "Step 9" siclog@
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellB, 30.0 );

    //@siclog "Step 10" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableOffCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_SuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_NonSuitableOffCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from UTRAN side
      } case else {} // Do nothing
    }

    //@siclog "Step 11" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellB, tsc_NonSuitableOffCellRS_EPRE ),
      cs_CellPower ( eutra_CellG, tsc_ServingCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 12" siclog@
    //+ Check: Does the UE transmit an ATTACH REQUEST message in the next 60 seconds?
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellG, 60.0 );

    //@siclog "Step 13" siclog@
    f_UT_TriggerAttach (UT);

    //@siclog "Step 14" siclog@
    f_EUTRA_CheckNoAttachOn1Cell ( eutra_CellG, 30.0 );

} // end of fl_TC_9_2_1_1_12_Body

  


    function f_TC_9_2_1_2_5_EUTRA() runs on EUTRA_PTC
    {
       // @desc Combined attach / Rejected / IMSI invalid
        /* Test Purpose (TP)
         (1)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'Illegal UE' }
            then { UE deletes GUTI, last visited registered TAI and KSI and considerse the USIM as invalid for EPS services and non-EPS services and enters state EMM-DEREGISTERED }
         }

         (2)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'Illegal UE' }
            then { UE deletes p-TMSI, p-TMSI signature, RAI, GPRS ciphering key sequence number, TMSI, LAI and ciphering key sequence number }
         }

        System Simulator:
        -   Cell A and Cell B
        -   if pc_UTRA supported by UE, Cell 5
                Cell5 belongs to LAI-1 and RAI-1 (home PLMN)
            if NOT pc_UTRA and pc_GERAN, Cell 24
                Cell24 belongs to LAI-1 and RAI-1 (home PLMN)
        UE:
        -   The UE is configured to initiate combined EPS/IMSI attach.
        -   The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
        -   The test USIM contains P-TMSI-1 (belonging RAI-1) and the GPRS update status is "GU1:UPDATED"
        -   The test USIM containts TMSI-1 (belonging to LAI-1) and the update status is "U1:UPDATED"

        Preamble:
        -   UE is in state Switched OFF (state 1) according to clause [18]
        */

        var boolean v_TriggerRxd := false;
        if (pc_UTRA) {
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_UTRANCell);
        } else if (pc_GERAN) {
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_GERANcell);
        } else { // Neither UMTS, nor GSM, so just do LTE
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
        }

        f_UT_ConfigureCombinedAttach (UT); // R5-103815

        // create cell and send out system information
        f_EUTRA_CellConfig_Def(eutra_CellA);
        f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);

        // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
        if (pc_UTRA) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
        } else if (pc_GERAN) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
        } else { // supports neither UTRAN or GERAN
            f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
        }
        f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );

        f_EUTRA_TestBody_Set(true);

        fl_TC_9_2_1_2_5and7_Body (tsc_EmmCause_IllegalUe);

        f_EUTRA_TestBody_Set(false);
        f_EUTRA_ReleaseAllCells( );

    } // end f_TC_9_2_1_2_5_EUTRA

function f_TC_9_2_1_2_7_EUTRA() runs on EUTRA_PTC
    {
       // @desc Combined attach / Rejected / IMSI invalid
        /* Test Purpose (TP)
         (1)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'EPS services and non-EPS services not allowed' }
            then { UE deletes GUTI, last visited registered TAI and KSI and considerse the USIM as invalid for EPS services and non-EPS services and enters state EMM-DEREGISTERED }
         }

         (2)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'EPS services and non-EPS services not allowed' }
            then { UE deletes p-TMSI, p-TMSI signature, RAI, GPRS ciphering key sequence number, TMSI, LAI and ciphering key sequence number }
         }

        System Simulator:
        -   Cell A and Cell B
        -   if pc_UTRA supported by UE, Cell 5
                Cell5 belongs to LAI-1 and RAI-1 (home PLMN)
            if NOT pc_UTRA and pc_GERAN, Cell 24
                Cell24 belongs to LAI-1 and RAI-1 (home PLMN)
        UE:
        -   The UE is configured to initiate combined EPS/IMSI attach.
        -   The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
        -   The test USIM contains P-TMSI-1 (belonging RAI-1) and the GPRS update status is "GU1:UPDATED"
        -   The test USIM containts TMSI-1 (belonging to LAI-1) and the update status is "U1:UPDATED"

        Preamble:
        -   UE is in state Switched OFF (state 1) according to clause [18]
        */
        var boolean v_TriggerRxd := false;

        if (pc_UTRA) {
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_UTRANCell);
        } else if (pc_GERAN) {
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_GERANcell);
        } else { // Neither UMTS, nor GSM, so just do LTE
          f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
        }

        f_UT_ConfigureCombinedAttach (UT); // R5-103815

        // create cell and send out system information
        f_EUTRA_CellConfig_Def(eutra_CellA);
        f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);

        // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
        if (pc_UTRA) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
        } else if (pc_GERAN) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
        } else { // supports neither UTRAN or GERAN
            f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
        }
        f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );

        f_EUTRA_TestBody_Set(true);

        fl_TC_9_2_1_2_5and7_Body (tsc_Cause_EPSandNonEPSServNotAllowed);

        f_EUTRA_TestBody_Set(false);

        f_EUTRA_ReleaseAllCells( );
    } // end f_TC_9_2_1_2_7_EUTRA



    function fl_TC_9_2_1_2_5and7_Body(NAS_CauseValue_Type p_RejectCause) runs on EUTRA_PTC
    {
        var boolean v_TriggerRxd := false;
        var template (value) CellPowerList_Type v_CellPowerList;
        var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
        var NAS_AttDetValue_Type v_AttachType;
        var PdnTypeValue v_PDNValue;
        var NAS_MSG_Indication_Type v_NAS_Ind;
        var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();

        var charstring v_OtherPTC := "";

        if (pc_UTRA) {
          v_OtherPTC := "UTRAN";
        } else if (pc_GERAN) {
          v_OtherPTC := "GERAN";
        } else { // Neither UMTS, nor GSM, so just do LTE
          v_OtherPTC := "NONE";
        }

        //@siclog "Step 1" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        select (v_OtherPTC) { // send trigger to other RAT to change its power level too
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
          } case else {} // Do nothing
        }

        //@siclog "Step 2 - 5" siclog@
        // UE is switched on, sends and ATTACH REQUEST and SS transmits an ATTACH REJECT with cause set to:
                    //TC92125: Illegal UE
                    //TC92127: EPS services and non-EPS services not allowed
        f_EUTRA_AttachReject (eutra_CellA, p_RejectCause);

        //@siclog "Step 6" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellB, tsc_ServingCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 7" siclog@
        // Check: Does the UE send and ATTACH REQUEST in the next 30 seconds on either Cell B or Cell A?
        f_EUTRA_CheckNoAttachOn2Cells ( eutra_CellA, eutra_CellB, 30.0 );

        //@siclog "Step 8" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
          }
        select (v_OtherPTC) { // change power level of cellB, send trigger to other RAT, then wait for trigger to be returned
          case ("UTRAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
          } case ("GERAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
          } case else {} // Do nothing
        }

        //@siclog "Step 9" siclog@
        //  The UE is powered off or switched off
        f_UT_SwitchOffUE(UT, false);

        //  Configure power levels, now CellA is the Serving Cell
        //@siclog "Step 10" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
          }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        select (v_OtherPTC) { // send trigger to other RAT to set it as Non-Suitable Cell
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
          } case else {} // Do nothing
        }

        //  UE brought back to operation
        //@siclog "Step 11" siclog@
        f_UT_SwitchOnUE (UT, false);

        v_AttachType := f_GetEAttachType();

        v_PDNValue := f_GetPdnType();

        //  UE sends and ATTACH REQUEST on CellA
        //@siclog "Step 12" siclog@
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                    v_RRC_TI,
                                                    cr_EstablishmentCause_Any,
                                                    cr_NAS_IndicationWithPiggybacking(tsc_SHT_NoSecurityProtection,
                                                                                      cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                      v_AttachType,
                                                                                      v_AdditionalUpdateType,
                                                                                      f_Imsi2MobileIdentity(px_IMSI_Def),
                                                                                      cr_TMSI_Status('0'B)),
                                                                                      cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                      v_PDNValue)));
        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 12");

        //SS transmits an ATTACH REJECT with reject cause set to:
        //@siclog "Step 13" siclog@
            //TC92125: Illegal UE
            //TC92127: EPS services and non-EPS services not allowed
        SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellA,
                                          cs_TimingInfo_Now,
                                          cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                           cs_508_AttachReject ( cs_EMM_Cause_v(p_RejectCause),
                                                                                 omit))));

        //@siclog "Step 14" siclog@
        f_EUTRA_RRC_ConnectionRelease(eutra_CellA, v_RRC_TI, other);

        //@siclog "Step 15" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
          }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        select (v_OtherPTC) { // send trigger to other RAT to change its power level too
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
          } case else { // Need to finish all RATs in same state in order to do postamble
            f_UT_SwitchOffUE (UT, false);
          }
        }
    }// end function fl_TC_9_2_1_2_5and7_Body

 
    // ===============================================================
  /**
    * @desc Combined attach / rejected / Illegal ME
    */
  function f_TC_9_2_1_2_6_EUTRA() runs on EUTRA_PTC
  {
    /*
    Test Purpose (TP)
     (1)
    with { UE has sent an ATTACH REQUEST message }
    ensure that {
      when { UE receives an ATTACH REJECT message with the EMM cause set to "Illegal ME" }
        then { UE deletes the GUTI, last visited registered TAI and KSI and considers the USIM as invalid
              for EPS services and non-EPS services and enters state EMM-DEREGISTERED }
     (2)
    with { UE has sent an ATTACH REQUEST message }
    ensure that {
      when { UE receives an ATTACH REJECT message with the EMM cause set to "Illegal ME" }
        then { UE deletes the P-TMSI, P-TMSI signature, RAI, GPRS ciphering key sequence number, TMSI, LAI and ciphering key sequence number }
    */

    /*
    Pre-test conditions

    System Simulator:
        -   Cell A and Cell B
        -   If pc_UTRAN supported by UE, Cell 5.
        -   Cell 5 belongs to LAI-1 and RAI-1(home PLMN)
        -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24.
        -   Cell 24 belongs to LAI-1 and RAI-1(home PLMN)
    UE:
        -   The UE is configured to initiate combined EPS/IMSI attach.
        -   The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
        -   The test USIM contains P-TMSI-1 (belonging to RAI-1) and the GPRS update status is "GU1: UPDATED".
        -   The test USIM contains TMSI-1 (belonging to LAI-1) and the update status is "U1: UPDATED".
    Preamble:
        -   The UE is in state Switched OFF (state 1) according to clause [18].


    */
    var boolean v_TriggerRxd := false;
    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_UTRANCell);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_GERANcell);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
    }

    f_UT_ConfigureCombinedAttach (UT); // R5-103815

    // create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellA);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);

    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_2_6_Body();
    // Postamble
    // UE either already switched off or not in this RAT
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_ReleaseAllCells( );

  }// function f_TC_9_2_1_2_6_EUTRA


  function fl_TC_9_2_1_2_6_Body() runs on EUTRA_PTC
  {
    var boolean v_TriggerRxd := false;
    var template (value) CellPowerList_Type v_CellPowerList;
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    var NAS_AttDetValue_Type v_AttachType;
    var PdnTypeValue v_PDNValue;
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();

    var charstring v_OtherPTC := "";

    if (pc_UTRA) {
      v_OtherPTC := "UTRAN";
    } else if (pc_GERAN) {
      v_OtherPTC := "GERAN";
    } else { // Neither UMTS, nor GSM, so just do LTE
      v_OtherPTC := "NONE";
    }

    //@siclog "Step 1" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
    }
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    //@siclog "Step  2 - 5" siclog@
    // UE is switched on, sends and ATTACH REQUEST and SS transmits an ATTACH REJECT with reject cause set to illegalME
    f_EUTRA_AttachReject (eutra_CellA, tsc_EmmCause_IllegalMe);

    //@siclog "Step 6" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_ServingCellRS_EPRE )
    }
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 7" siclog@
    // Check: Does the UE send and ATTACH REQUEST in the next 30 seconds on either Cell B or Cell A?  F
    f_EUTRA_CheckNoAttachOn2Cells ( eutra_CellA, eutra_CellB, 30.0 );

    //@siclog "Step 8 - 9 Void" siclog@

    //@siclog "Step 10" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
      }
    select (v_OtherPTC) { // change power level of Cell B, send trigger to other RAT, then wait for trigger to be returned
      case ("UTRAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
      } case ("GERAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
      } case else {} // Do nothing
    }

    //  Switch Off UE
    //@siclog "Step 11" siclog@
    f_UT_SwitchOffUE (UT, false);

    //@siclog "Step 12" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
      }
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    //  Switch on UE
    //@siclog "Step 13" siclog@
    f_UT_SwitchOnUE (UT, false);

    v_AttachType := f_GetEAttachType();

    v_PDNValue := f_GetPdnType();

    // UE sends and ATTACH REQUEST
    //@siclog "Step 14" siclog@
    v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                v_RRC_TI,
                                                cr_EstablishmentCause_Any,
                                                cr_NAS_IndicationWithPiggybacking(tsc_SHT_NoSecurityProtection,
                                                                                  cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                  v_AttachType,
                                                                                  v_AdditionalUpdateType,
                                                                                  f_Imsi2MobileIdentity(px_IMSI_Def),
                                                                                  cr_TMSI_Status('0'B)),
                                                                                  cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                                  v_PDNValue)));
    
    // SS transmits an ATTACH REJECT with reject cause set to illegalME
    //@siclog "Step 15" siclog@
    SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellA,
                                      cs_TimingInfo_Now,
                                      cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                       cs_508_AttachReject ( cs_EMM_Cause_v(tsc_EmmCause_IllegalMe),
                                                                             omit))));

    //@siclog "Step 16" siclog@
    f_EUTRA_RRC_ConnectionRelease(eutra_CellA, v_RRC_TI, other);

    //@siclog "Step 17" siclog@
    v_CellPowerList := {
      cs_CellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE ),
      cs_CellPower ( eutra_CellB, tsc_NonSuitableCellRS_EPRE )
      }
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else { // Need to finish all RATs in same state in order to do postamble
        f_UT_SwitchOffUE (UT, false);
      }
    }

  }// function fl_tc_9_2_1_2_6_Body

/**
  * @desc Combined attach / rejected / EPS services not allowed
*/
function f_TC_9_2_1_2_8_EUTRA() runs on EUTRA_PTC
{
   /*    (1)
    with { UE has sent an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message }
    ensure that {
      when { UE receives an ATTACH REJECT message with the reject cause set to "EPS services not allowed" }
        then { UE considers the USIM as invalid for EPS services and enters state EMM-DEREGISTERED and UE does not attempt to attach on any other cell }
     }
    System Simulator:
        -   Cell A and Cell B
        -   If pc_UTRAN supported by UE, Cell 5.
        -   Cell 5 belongs to LAI-1 and RAI-1(home PLMN)
        -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24.
        -   Cell 24 belongs to LAI-1 and RAI-1(home PLMN)
    UE:
        -   The UE is configured to initiate combined EPS/IMSI attach.
        -   The test USIM contains IMSI1, GUTI1 and TAI1, and EPS update status is "EU1: UPDATED".
        -   The test USIM contains P-TMSI-1 (belonging to RAI-1) and the GPRS update status is "GU1: UPDATED".
        -   The test USIM contains TMSI-1 (belonging to LAI-1) and the update status is "U1: UPDATED".
    Preamble:
        -   The UE is in state Switched OFF (state 1) according to clause [18].
   */

    var boolean v_TriggerRxd := false;
    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_UTRANCell);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_GERANcell);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
    }

    f_UT_ConfigureCombinedAttach (UT); // R5-103815

   // Create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellA);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellB);

    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_2_8_Body();

   // Postamble
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_Postamble(eutra_CellA, E1_IDLE);

  }// function f_TC_9_2_1_2_8_EUTRA

function fl_TC_9_2_1_2_8_Body() runs on EUTRA_PTC
{
  var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
  var ReleaseCause v_ReleaseCause := other;
  var template (value) CellPowerList_Type v_CellPowerList;
  var NAS_MSG_Indication_Type v_NasInd;
  var boolean v_TriggerRxd := false;
  var charstring v_OtherPTC := "";
  var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();
  var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();

    if (pc_UTRA) {
      v_OtherPTC := "UTRAN";
    } else if (pc_GERAN) {
      v_OtherPTC := "GERAN";
    } else { // Neither UMTS, nor GSM, so just do LTE
      v_OtherPTC := "NONE";
    }

    //@siclog "Step 1" siclog@
    //  The SS configures:
    //   - Cell A as the "Serving cell".
    //   - Cell B as a "Suitable neighbour cell".
    //   - Cell 5 or Cell 24 as a "Suitable neighbour cell".
    v_CellPowerList := {
                         cs_CellPower ( eutra_CellA, tsc_ServingCellRS_EPRE ),
                         cs_CellPower ( eutra_CellB, tsc_SuitableCellRS_EPRE )
                       };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    //@siclog "Step 2" siclog@
    //+  The UE is switched on.
    f_UT_SwitchOnUE (UT, false);

    // The following messages are sent and shall be received on Cell A.

    //@siclog "Step 3" siclog@
    //+ The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message.
     v_NasInd := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                v_RRC_TI,
                                                cr_EstablishmentCause_Any,
                                                cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                          cr_508_ATTACH_REQUEST(v_AttachType, v_AdditionalUpdateType ),
                                                          cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach, ?)));
                                                           

    //@siclog "Step 4" siclog@
    //+   The SS transmits an ATTACH REJECT message with EMM cause = "EPS services not allowed".
    SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellA,
                                    cs_TimingInfo_Now,
                                      cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                     cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_EPSServNotAllowed),
                                                                           omit))));

    //@siclog "Step 5" siclog@
    //+   The SS releases the RRC connection.
    f_EUTRA_RRC_ConnectionRelease(eutra_CellA, v_RRC_TI, v_ReleaseCause);


    //Behaviour that depends on the UE capability
    //@siclog "Step 6" siclog@
    select (v_OtherPTC) { // send trigger to other RAT, then wait for trigger to be returned
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
      } case else {} // Do nothing
    }

    //@siclog "Step 7" siclog@
    //The SS configures: Cell A as the "Suitable neighbour cell". Cell B as the "Suitable neighbour cell".
    v_CellPowerList := {
                         cs_CellPower ( eutra_CellA, tsc_SuitableCellRS_EPRE ),
                         cs_CellPower ( eutra_CellB, tsc_SuitableCellRS_EPRE )
                       };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //@siclog "Step 8" siclog@
    //+   Check: Does the UE transmit the ATTACH REQUEST message in the next 30 seconds on Cell A or Cell B? [1, F]
    f_EUTRA_CheckNoAttachOn2Cells(eutra_CellA, eutra_CellB, 30.0);
    
    // Test case finished, so just trigger other RAT to release their cell
    select (v_OtherPTC) {
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

} // function tc_9_2_1_2_8_Body

function f_TC_9_2_1_2_9_EUTRA() runs on EUTRA_PTC
{
  // @desc Combined attach / rejected / PLMN not allowed

  /*(1)
    with { UE has sent an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message }
     ensure that {
      when { UE receives an ATTACH REJECT message with the reject cause set to "PLMN not allowed" }
        then { UE deletes the GUTI, the last visited registered TAI and KSI and UE deletes the list of equivalent PLMNs and UE enters state EMM-DEREGISTERED.PLMN-SEARCH and UE stores the PLMN in the "forbidden PLMN list" }
            }

    (2)
    with { UE is switched off and a PLMN is stored in the "forbidden PLMN list" }
     ensure that {
      when { UE is powered on this PLMN }
        then { UE does not attempt to attach on the cell }
            }

    (3)
    with { UE in E-UTRA EMM-DEREGISTERED.PLMN-SEARCH state and a PLMN is stored in the "forbidden PLMN list" }
     ensure that {
       when { UE enters a PLMN which is not in the "forbidden PLMN list" }
        then { UE attempts to attach on the cell }
            }

    System Simulator:
        -   Cell I and Cell G
        -   Cell I belongs to TAI-9(visited PLMN)
        -   Cell G belongs to TAI-7(visited PLMN, another PLMN)
        -   If pc_UTRAN supported by UE, Cell 5
        -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24.
        -   Cell 5 and Cell 24 belong to RAI-1(visited PLMN, same PLMN as Cell I)
    UE:
        -   The UE is configured to initiate combined EPS/IMSI attach.
        -   The test USIM contains IMSI1, GUTI1 and TAI1, and EPS update status is "EU1: UPDATED".
        -   The "forbidden PLMN list" is empty.

    Preamble:
    -   The UE is in state Switched OFF (state 1) according to [18]
   */

    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_UTRANCell);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_GERANcell);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell);
    }

    f_UT_ConfigureCombinedAttach (UT); // R5-103815

   // Create cells and send out system information for CellI (serving) and Cell G (non-suitable)
    f_EUTRA_CellConfig_Def(eutra_CellA);//Though it not mentioned cell A, but it says USIM have GUTI1.
    f_EUTRA_CellConfig_Def(eutra_CellG);
    f_EUTRA_CellConfig_Def(eutra_CellI);
    
    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellA, RRC_IDLE, tsc_RRC_TI_Def );

    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_2_9_Body();

   // Postamble
    f_EUTRA_TestBody_Set(false);

    f_EUTRA_Postamble(eutra_CellG, E2_CONNECTED);
  }// function f_TC_9_2_1_2_9_EUTRA

function fl_TC_9_2_1_2_9_Body() runs on EUTRA_PTC
{
  var ProcedureTransactionIdentifier v_EPS_TI := '00'O;
  var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
  var ReleaseCause v_RRC_ReleaseCause := other;
  var template (value) CellPowerList_Type v_CellPowerList;
  var NAS_MSG_Indication_Type v_NasInd;
  var boolean v_TriggerRxd := false;
  var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();
  var charstring v_OtherPTC := "";
  var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();

    if (pc_UTRA) {
      v_OtherPTC := "UTRAN";
    } else if (pc_GERAN) {
      v_OtherPTC := "GERAN";
    } else { // Neither UMTS, nor GSM, so just do LTE
      v_OtherPTC := "NONE";
    }

    // The SS configures:
    //@siclog "Step 1" siclog@
    //  - Cell I as the "Serving cell".
    //  - Cell G as a "Non-Suitable cell".
    //  - Cell 5 as a "Non-Suitable cell".
    v_CellPowerList := {
                         cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
                         cs_CellPower ( eutra_CellG, tsc_NonSuitableCellRS_EPRE )
                       };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

    //@siclog "Step 2" siclog@
    //+  The UE is switched on.
    f_UT_SwitchOnUE (UT, false);

    //@siclog "Step 3" siclog@
    //The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message.
     v_NasInd := f_EUTRA_RRC_ConnEst_DefWithNas( eutra_CellI,
                                                 tsc_RRC_TI_Def,
                                                 cr_EstablishmentCause_Any,
                                                 cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                                                   cr_508_ATTACH_REQUEST(v_AttachType, v_AdditionalUpdateType),
                                                                                   cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                                   f_GetPdnType())));

    v_EPS_TI := v_NasInd.Pdu.PiggybackedPduList[0].Msg.pDN_CONNECTIVITY_REQUEST.procedureTransactionIdentifier; // Use this value in SS responses

    //@siclog "Step 4" siclog@
    //+   The SS transmits an ATTACH REJECT message with EMM cause = "PLMN not allowed".
    SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellI,
                                      cs_TimingInfo_Now,
                                      cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                       cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_PLMN_NotAllowed),
                                                                             omit))));
    //@siclog "Step 5" siclog@
    //+   The SS releases the RRC connection.
     f_EUTRA_RRC_ConnectionRelease(eutra_CellI, v_RRC_TI, v_RRC_ReleaseCause);

    //@siclog "Step 6" siclog@
    //+   Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds?[1,F]
     f_EUTRA_CheckNoAttachOn1Cell(eutra_CellI, 30.0);

    //@siclog "Step 7" siclog@
    //+   The UE is powered off or switched off.
     f_UT_SwitchOffUE (UT, false);

    //@siclog "Step 8" siclog@
    //+  The UE is powered on or switched on.
    f_UT_SwitchOnUE (UT, false);

    //@siclog "Step 9a1" siclog@
    // +   Set Cell I to "Non-Suitable Cell"
    v_CellPowerList := {
                         cs_CellPower ( eutra_CellG, tsc_NonSuitableCellRS_EPRE ),
                         cs_CellPower ( eutra_CellI, tsc_NonSuitableCellRS_EPRE )
                       };
    select (v_OtherPTC) { // change power level of Cell I, send trigger to other RAT, then wait for trigger to be returned
      case ("UTRAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
      } case ("GERAN") {
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
      } case else {} // Do nothing
    }

    //@siclog "Step 10" siclog@
    //+   The SS configures:
    //+   Cell I as a "Non-Suitable cell".
    //+   Cell G as the "Serving cell".
    //+   Note: Cell G belongs to PLMN different from PLMN belonging to Cell I.
    v_CellPowerList := {
                         cs_CellPower ( eutra_CellG, tsc_ServingCellRS_EPRE ),
                         cs_CellPower ( eutra_CellI, tsc_NonSuitableCellRS_EPRE )
                       };
    f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

    //+   The following messages are sent and shall be received on Cell G.
    //@siclog "Step 11" siclog@
    //+   Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message as specified?[1,3,P]
    v_NasInd:= f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellG,
                                              v_RRC_TI,
                                              cr_EstablishmentCause_Any,
                                              cr_NAS_IndicationWithPiggybacking(tsc_SHT_NoSecurityProtection,
                                                                                cdr_ATTACH_REQUEST_WithOldMobileIdNoTAI(v_AttachType,
                                                                                                                        v_AdditionalUpdateType,
                                                                                                                        f_Imsi2MobileIdentity(px_IMSI_Def)),
                                                                                cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                                f_GetPdnType())));
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 11");
  
    //@siclog "Step 12 - 23" siclog@
    f_EUTRA_IdleUpdated_Step5_17(eutra_CellA, STATE2_IDLEUPDATE, NORMAL, v_NasInd, false);
      
    // Test case finished, so just trigger other RAT to release their cell
    select (v_OtherPTC) { // send trigger to other RAT to change its power level too
      case ("UTRAN") {
        f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
      } case ("GERAN") {
        f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
      } case else {} // Do nothing
    }

} // function tc_9_2_1_2_9_EUTRA



    function f_TC_9_2_1_2_11_EUTRA() runs on EUTRA_PTC
    {
       // @desc Combined attach / Rejected / Roaming not allowed in this tracking area
        /* Test Purpose (TP)
 
            (1)
            with { UE has sent an ATTACH REQUEST message }
            ensure that {
              when { UE receives an ATTACH REJECT message with the EMM cause set to "Roaming not allowed in this tracking area" }
                then { UE sets the EPS update status to EU3 ROAMING NOT ALLOWED and UE deletes the GUTI, the last visited registered TAI and KSI and UE enters the state EMM-DEREGISTERED.LIMITED-SERVICE or optionally EMM-DEREGISTERED.PLMN-SEARCH and UE stores the current TAI in the list of "forbidden tracking areas for roaming" and deletes the TMSI, the LAI and the ciphering key sequence number }
                        }
            (2)
            with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE or EMM-DEREGISTERED.PLMN-SEARCH state and the current TAI is in the list of "forbidden tracking areas for roaming" }
            ensure that {
              when { UE re-selects a new cell in the same TA where it was rejected }
                then { UE does not attempt to attach }
                        }

            (3)
            with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE or EMM-DEREGISTERED.PLMN-SEARCH state and the TAI of the current cell belongs to the list of "forbidden tracking areas for roaming" }
            ensure that {
              when { UE enters a cell belonging to a tracking area not in the list of "forbidden tracking areas for roaming" }
                then { UE attempts to attach with IMSI }
                        }

            (4)
            with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE or EMM-DEREGISTERED.PLMN-SEARCH state and the list of "forbidden tracking areas for roaming" contains more than one TAI }
            ensure that {
              when { UE selects a cell belonging to one of the TAIs in the list of "forbidden tracking areas for roaming" }
                then { UE does not attempt to attach }
                        }

            (5)
            with { UE has sent an ATTACH REQUEST message }
            ensure that {
              when { UE receives an ATTACH REJECT message with the EMM cause set to "Roaming not allowed in this tracking area" }
                then { UE deletes RAI, P-TMSI, P-TMSI signature and GPRS ciphering key sequence number and sets the GPRS update status to GU3 ROAMING NOT ALLOWED }
                        }

            (6)
            with { UE is switched off or the UICC containing the USIM is removed }
            ensure that {
              when { UE is powered on in the cell belonging to the TAI which was in the list of "forbidden tracking areas for roaming" before UE was switched off or the USIM is inserted again on that cell }
                then { UE performs registration on that cell }
                        }

            (7)
            with { a cell of the HPLMN is available }
            ensure that {
              when { UE performs a PLMN selection }
                then { UE returns to a cell of the HPLMN }
                        }


            System Simulator:
            -     Cell C, Cell I, Cell K, Cell L and if pc_UTRAN Cell 5 and if (NOT pc_UTRAN AND pc_GERAN)
                  Cell 24 are configured according to Table 6.3.2.2-1 in [18],
                  but at most two cells are simultaneously activated:
            -     Cell I and Cell K (visited PLMN, same TA),
            -     Cell L (same visited PLMN, another TA),
            -     Cell C (home PLMN),
            -     if pc_UTRAN, Cell 5 (only active when stated),
            -     same PLMN like visited PLMN above
            -     RAI-1 (RAC & LAC values chosen by SS)
            -     System information indicate that NMO 1 is used
            -     if pc_GERAN and NOT pc_UTRAN, Cell 24 (only active when stated).
            -     same PLMN like visited PLMN above
            -     RAC-1 (RAC & LAC values chosen by SS)
            -     System information indicate that NMO 1 is used
            NOTE 1:   Cell K is present to confirm that UE does not attempt attach to the cell in same TAI after reject
                      from the SS.
            NOTE 2:   Cell C is present to confirm that UE does attempt attach to the cell in HPLMN after reject
                      from the SS.
            NOTE 3:   The requirement in 3GPP TS 24.301 to store at least 40 entries in the list of "forbidden tracking
                      areas for roaming" is not fully tested.
            NOTE 4:   Different types of UE may use different methods to periodically clear the list of forbidden areas
                      (e.g. every day at 12 am) for roaming. If the list is cleared while the test is being run,
                      it may be necessary to re-run the test.
            UE:
            -     The UE is configured to initiate combined EPS/IMSI attach.
            -     The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
            -     The test USIM contains P-TMSI-1 (belonging to RAI-1) and the GPRS update status is "GU1: UPDATED".
            -     The test USIM contains TMSI-1 (belonging to LAI-1) and the update status is "U1: UPDATED".

            Preamble:
            -     The UE is in state Switched OFF (state 1) according to [18]
        */
        var boolean v_TriggerRxd := false;

        if (pc_UTRA) {
          f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_UTRANCell);
        } else if (pc_GERAN) {
          f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_GERANcell);
        } else { // Neither UMTS, nor GSM, so just do LTE
          f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell);
        }

        f_UT_ConfigureCombinedAttach (UT); // R5-103815

        // create cell and send out system information
        f_EUTRA_CellConfig_Def(eutra_CellI);
        f_EUTRA_CellConfig_SRBs_Only(eutra_CellK);
        f_EUTRA_CellConfig_Def(eutra_CellL);
        f_EUTRA_CellConfig_Def(eutra_CellC);

        // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
        if (pc_UTRA) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
        } else if (pc_GERAN) {
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
            f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
        } else { // supports neither UTRAN or GERAN
            f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
        }
        f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellI, RRC_IDLE, tsc_RRC_TI_Def );

        f_EUTRA_TestBody_Set(true);

        fl_TC_9_2_1_2_11_Body ();

        f_EUTRA_TestBody_Set(false);
        f_EUTRA_Postamble(eutra_CellC, E2_CONNECTED);
    } // end f_TC_9_2_1_2_11_EUTRA

    function fl_TC_9_2_1_2_11_Body() runs on EUTRA_PTC
    {
        var boolean v_TriggerRxd := false;
        var template (value) CellPowerList_Type v_CellPowerList;
        var NAS_MSG_Indication_Type v_NAS_Ind;
        var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();
        var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();

        var charstring v_OtherPTC := "";

        if (pc_UTRA) {
          v_OtherPTC := "UTRAN";
        } else if (pc_GERAN) {
          v_OtherPTC := "GERAN";
        } else { // Neither UMTS, nor GSM, so just do LTE
          v_OtherPTC := "NONE";
        }
        //@siclog "Step 1" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
        select (v_OtherPTC) { // send trigger to other RAT to change its power level too
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
          } case else {} // Do nothing
        }

        //@siclog "Step 2 - 5" siclog@
        // UE is switched on, sends and ATTACH REQUEST and SS transmits an ATTACH REJECT with cause set to
        // Roaming not allowed in this tracking area
        f_EUTRA_AttachReject (eutra_CellI, tsc_Cause_roaming_NotAllowed);

        //@siclog "Step 6" siclog@
        // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell I?
        f_EUTRA_CheckNoAttachOn1Cell(eutra_CellI, 30.0);

        //@siclog "Step 7" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 8" siclog@
        // Check: Does the UE send and ATTACH REQUEST in the next 30 seconds on any cell?
        f_EUTRA_CheckNoAttachOn4Cells ( eutra_CellI, eutra_CellK, eutra_CellL, eutra_CellC, 30.0 );


        //@siclog "Step 9" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );


        //  Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message
        // on Cell L?
        //@siclog "Step 10" siclog@
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellL,
                                             tsc_RRC_TI_Def,
                                             cr_EstablishmentCause_Any,
                                             cr_NAS_IndicationWithPiggybacking( tsc_SHT_NoSecurityProtection,
                                                                                cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                             v_AttachType,
                                                                                             v_AdditionalUpdateType,
                                                                                             f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                                             cr_TMSI_Status('0'B)),
                                                                                cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                f_GetPdnType())));

        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 10");

        //@siclog "Step 11" siclog@
        // The SS transmits an ATTACH REJECT message, EMM cause set to "Roaming not allowed in this tracking area" on Cell L
        SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellL,
                                      cs_TimingInfo_Now,
                                      cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                       cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_roaming_NotAllowed),
                                                                             omit))));

        //@siclog "Step 12" siclog@
        // The SS releases the RRC connection
        f_EUTRA_RRC_ConnectionRelease(eutra_CellL, tsc_RRC_TI_Def, other);


        //@siclog "Step 13" siclog@
        // Check Does the UE send and ATTACH REQUEST in the next 30 seconds on either Cell L or Cell K?
        f_EUTRA_CheckNoAttachOn2Cells ( eutra_CellL, eutra_CellK, 30.0 );


        // SS Reconfigures power levels
        //@siclog "Step 14" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
        }

        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 15" siclog@
        //Check: Does the UE transmit an ATTACH REQUESTmessage in the next 30 seconds on any cell?
        f_EUTRA_CheckNoAttachOn4Cells ( eutra_CellI, eutra_CellK, eutra_CellL, eutra_CellC, 30.0 );


        //@siclog "Step 16" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE )
          }
        select (v_OtherPTC) { // change power levels, send trigger to other RAT, then wait for trigger to be returned
          case ("UTRAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
          } case ("GERAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
          } case else {} // Do nothing
        }

        //  Switch Off UE
        //@siclog "Step 17" siclog@
        f_UT_SwitchOffUE (UT, false);


        // SS Reconfigures power levels
        //@siclog "Step 18" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
        }
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );


        //  Switch on UE
        //@siclog "Step 19" siclog@
        f_UT_SwitchOnUE (UT, false);

        //@siclog "Step 20" siclog@
        // The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message on CellI
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellI,
                                             tsc_RRC_TI_Def,
                                             cr_EstablishmentCause_Any,
                                             cr_NAS_IndicationWithPiggybacking( tsc_SHT_NoSecurityProtection,
                                                                                cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                             v_AttachType,
                                                                                             v_AdditionalUpdateType,
                                                                                             f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                                             cr_TMSI_Status('0'B)),
                                                                                cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                f_GetPdnType())));
        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 20");

        //@siclog "Step 21" siclog@
        // The SS transmits an ATTACH REJECT message, EMM cause set to "Roaming not allowed in this tracking area" on CellI
        SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellI,
                                          cs_TimingInfo_Now,
                                          cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                           cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_roaming_NotAllowed),
                                                                                 omit))));

        // SS Reconfigures power levels
        //@siclog "Step 22" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_SuitableCellRS_EPRE )
        }

        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );


        //  Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message
        // on Cell C?
        //@siclog "Step 23" siclog@
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellC,
                                             tsc_RRC_TI_Def,
                                             cr_EstablishmentCause_Any,
                                             cr_NAS_IndicationWithPiggybacking( tsc_SHT_NoSecurityProtection,
                                                                                cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                             v_AttachType,
                                                                                             v_AdditionalUpdateType,
                                                                                             f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                                             cr_TMSI_Status('0'B)),
                                                                                cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                                f_GetPdnType())));
        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 23");

    //@siclog "Step 24 - 35" siclog@
    f_EUTRA_IdleUpdated_Step5_17(eutra_CellA, STATE2_IDLEUPDATE, NORMAL, v_NAS_Ind, false);

    }// end function fl_TC_9_2_1_2_11_Body


function f_TC_9_2_1_2_13_EUTRA() runs on EUTRA_PTC
{
   // @desc Combined attach / Rejected / Roaming not allowed in this tracking area
    /* Test Purpose (TP)
        (1)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'No Suitable Cells In tracking area' }
            then { UE sets the EPS update status to EU3 ROAMING NOT ALLOWED, deletes any GUTI, last visited registered TAI and KSI, resets the attach attempt counter, enters the state EMM-DEREGISTERED.LIMITED-SERVICE and stores the current TAI in the list of "forbidden tracking areas for roaming" }
                    }

        (2)
        with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE state and the current TAI is in the list of "forbidden tracking areas for roaming" }
        ensure that {
          when { UE re-selects a cell that belongs to the TAI where UE was rejected }
            then { UE does not attempt to attach }
                    }

        (3)
        with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE state and the current TAI is in the list of "forbidden tracking areas for roaming" and KSI was deleted }
        ensure that {
          when { in the same PLMN, UE enters a cell which provides normal service and belongs to the tracking area not in the list of "forbidden tracking areas for roaming" }
            then { UE attempts to attach with IMSI indicated that no key is available }
                    }

        (4)
        with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE state and the current TAI is in the list of "forbidden tracking areas for roaming" }
        ensure that {
          when { there are cells in the same PLMN and other PLMN that provide normal service and belong to the tracking area not in the list of "forbidden tracking areas for roaming" }
            then { UE attempts to attach to the cell in the same PLMN }
                    }

        (5)
        with { UE is in EMM-DEREGISTERED.LIMITED-SERVICE state and the list of "forbidden tracking areas for roaming" contains more than one TAI }
        ensure that {
          when { UE re-selects a cell that belongs to one of the TAIs in the list of "forbidden tracking areas for roaming" }
            then { UE does not attempt to attach }
                    }

        (6)
        with { UE has sent an ATTACH REQUEST message }
        ensure that {
          when { UE receives an ATTACH REJECT message with the EMM cause set to 'No Suitable Cells In tracking area' }
            then { UE deletes RAI, P-TMSI, P-TMSI signature, GPRS ciphering key sequence number, TMSI, LAI and ciphering key sequence number }
                    }

        (7)
        with { UE is swithched off }
        ensure that {
          when { UE is powered on in the cell belonging to the TAI which was in the list of "forbidden tracking areas for roaming" before UE was switched off }
            then { UE attempts to attach }
                    }


        System Simulator:
            -   Cell I, Cell J, Cell K and Cell L are configured according to Table 6.3.2.2-1 in [18] (maximum 3 cells are simultaneously active):
            -   Cell I and Cell K (visited PLMN, same TA),
            -   Cell L (same visited PLMN, another TA),
            -   Cell J (another VPLMN),
            -   if pc_UTRAN, Cell 5 (only active when stated),
            -   same PLMN like visited PLMN above
            -   RAI-1 (RAC & LAC values chosen by SS)
            -   System information indicate that NMO 1 is used
            -   if pc_GERAN and NOT pc_UTRAN, Cell 24 (only active when stated).
            -   same PLMN like visited PLMN above
            -   RAC-1 (RAC & LAC values chosen by SS)
            -   System information indicate that NMO 1 is used
            NOTE 1: Cell L is present to confirm that UE searches in the same PLMN after reject from the SS.
            NOTE 2: Cell K is present to confirm that UE shall not attempt attach to the cell in same TAI it was once rejected from.
            NOTE 3: The requirement in 3GPP TS 24.301 to store at least 40 entries in the list of "forbidden tracking areas for roaming" is not fully tested.
            NOTE 4: Different types of UE may use different methods to periodically clear the list of forbidden areas (e.g. every day at 12 am) for roaming. If the list is cleared while the test is being run, it may be necessary to re-run the test.
        UE:
            -   The UE is configured to initiate combined EPS/IMSI attach.
            -   The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
            -   The test USIM contains P-TMSI-1 (belonging to RAI-1) and the GPRS update status is "GU1: UPDATED".
            -   The test USIM contains TMSI-1 (belonging to LAI-1) and the update status is "U1: UPDATED".
            Preamble:
            -   The UE is in state Switched OFF (state 1) according to clause [18].
    */

    var boolean v_TriggerRxd := false;
    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN ,LTEmulticell_UTRANCell, LTE_NAS_Usef1_f2);
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_CellsOnDifferentPLMN, LTEmulticell_GERANcell, LTE_NAS_Usef1_f2);
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
    }

    // create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellI);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellJ);
    f_EUTRA_CellConfig_SRBs_Only(eutra_CellK);
    f_EUTRA_CellConfig_Def(eutra_CellL);

    f_UT_ConfigureCombinedAttach (UT); // R5-103815

    // Preamble: UE is in state Switched OFF (state 1)
    // ==========================================================================
    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellI, RRC_IDLE );
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_2_13_Body();

    // Postamble
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_Postamble(eutra_CellI, E2_CONNECTED);
} // end f_TC_9_2_1_2_13_EUTRA

    function fl_TC_9_2_1_2_13_Body() runs on EUTRA_PTC
    {
        var boolean v_TriggerRxd := false;
        var template (value) CellPowerList_Type v_CellPowerList;
        var NAS_MSG_Indication_Type v_NAS_Ind;
        var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();
        var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();
        var charstring v_OtherPTC := "";

        if (pc_UTRA) {
           v_OtherPTC := "UTRAN";
         } else if (pc_GERAN) {
           v_OtherPTC := "GERAN";
         } else { // Neither UMTS, nor GSM, so just do LTE
           v_OtherPTC := "NONE";
        }

        // Set Power levels
        //@siclog "Step 1" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellJ, tsc_NonSuitableCellRS_EPRE )
        };
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 2 - 5" siclog@
        // UE is switched on, sends and ATTACH REQUEST and SS transmits an ATTACH REJECT with cause set to
        // No suitable cells in this tracking area
        f_EUTRA_AttachReject (eutra_CellI, tsc_Cause_NoSuitableCells);

        //  Set Power levels
        //@siclog "Step 6" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellJ, tsc_NonSuitableCellRS_EPRE )
        };
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 7" siclog@
        //   Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on Cell K or Cell I?
        f_EUTRA_CheckNoAttachOn2Cells(eutra_CellK, eutra_CellI, 30.0, "step 7, ATTACH REQUEST message on Cell K or Cell I");

        //@siclog "Step 8" siclog@
        //  Set Power levels
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellJ, tsc_SuitableCellRS_EPRE )
        };
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 9" siclog@
        // Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message as specified on Cell L?
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellL,
                                                    tsc_RRC_TI_Def,
                                                    cr_EstablishmentCause_Any,
                                                    cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                                                  cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                       v_AttachType,
                                                                                       v_AdditionalUpdateType,
                                                                                       f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                                       cr_TMSI_Status('0'B)),
                                                                                  cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                       f_GetPdnType())));
        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 9");

        //@siclog "Step 10" siclog@
        // The SS transmits an ATTACH REJECT message with the EMM cause set to
        // No suitable cells in this tracking area on cell L
        //(The list of "forbidden tracking areas for roaming" in the UE should now contain TAI-9 and TAI-11)
        SRB.send  ( cas_SRB1_NasPdu_REQ ( eutra_CellL,
                                          cs_TimingInfo_Now,
                                          cs_NAS_Request ( tsc_SHT_NoSecurityProtection,
                                                         cs_508_AttachReject ( cs_EMM_Cause_v(tsc_Cause_NoSuitableCells),
                                                                               omit))));

        //  The SS releases the RRC connection.
        //@siclog "Step 11" siclog@
        f_EUTRA_RRC_ConnectionRelease(eutra_CellL, tsc_RRC_TI_Def, other);

        // Set Power levels
        //@siclog "Step 12" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellJ, tsc_NonSuitableCellRS_EPRE )
        };
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 13" siclog@
        // Check: Does the UE transmit the ATTACH REQUEST message in the next 30 seconds on CellI?
        f_EUTRA_CheckNoAttachOn1Cell(eutra_CellI, 30.0, "step 13");

        //  Configure Cells.
        //@siclog "Step 14" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellC, tsc_NonSuitableCellRS_EPRE )
          }
        select (v_OtherPTC) { // change power levels, send trigger to other RAT, then wait for trigger to be returned
          case ("UTRAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
          } case ("GERAN") {
            f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
          } case else {} // Do nothing
        }

        //  Set Power levels. Cell5/24 comes from Non-Suitable Cell level
        //@siclog "Step 15" siclog@
        v_CellPowerList := {
          cs_CellPower ( eutra_CellI, tsc_ServingCellRS_EPRE ),
          cs_CellPower ( eutra_CellK, tsc_NonSuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellL, tsc_SuitableCellRS_EPRE ),
          cs_CellPower ( eutra_CellJ, tsc_NonSuitableCellRS_EPRE )
        };
        f_EUTRA_SetCellPowerList ( v_CellPowerList, cs_TimingInfo_Now );

        //@siclog "Step 16" siclog@
        // If possible (see ICS) switch off is performed. Otherwise the power is removed.
        f_UT_SwitchOffUE (UT, false);

        //@siclog "Step 17" siclog@
        // The UE is brought back to operation.
        f_UT_SwitchOnUE (UT, false );

        //@siclog "Step 18" siclog@
        // Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message?
        v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellI,
                                                    tsc_RRC_TI_Def,
                                                    cr_EstablishmentCause_Any,
                                                    cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                                                  cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                                       v_AttachType,
                                                                                       v_AdditionalUpdateType,
                                                                                       f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                                       cr_TMSI_Status('0'B)),
                                                                                  cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                       f_GetPdnType())));
        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 18");

        //@siclog "Step 19 - 30" siclog@
        f_EUTRA_IdleUpdated_Step5_17 (eutra_CellI, STATE2_IDLEUPDATE, NORMAL, v_NAS_Ind, false);

    }// end function fl_TC_9_2_1_2_13_Body


function f_TC_9_2_1_2_15_EUTRA() runs on EUTRA_PTC
{
   // @desc Combined attach / Abnormal case / Handling of the EPS attach attempt counter
    /*Test Purpose (TP)
    (1)
    with { UE has detected T3410 expiry after sending an ATTACH REQUEST message and has the attach attempt counter set to the value less than four }
    ensure that {
      when { UE detects T3411 expiry }
        then { UE restarts the attach procedure }
                }

    (2)
    with { UE has sent an ATTACH REQUEST message and has the attach attempt counter set to four }
    ensure that {
      when { UE detects T3410 expiry }
        then { UE deletes GUTI, TAI list, last visited registered TAI and KSI }
                }

    (3)
    with { UE has sent an ATTACH REQUEST message and has the attach attempt counter set to four }
    ensure that {
      when { UE detects T3410 expiry }
        then { UE deletes LAI, TMSI, ciphering key sequence number, RAI, P-TMSI, P-TMSI signature, and GPRS ciphering key sequence number }
                }

    (4)
    with { UE has started T3402 }
    ensure that {
      when { UE detects T3402 expiry }
        then { UE restarts the attach procedure }
                }

    System Simulator:
    -   Cell A, if pc_UTRAN Cell 5 and if (NOT pc_UTRAN AND pc_GERAN) Cell 24 are configured.
    -   Cell A,
    -   if pc_UTRAN, Cell 5 (only active when stated),
        -   same PLMN like visited PLMN above
        -   RAI-1 (RAC & LAC values chosen by SS)
        -   System information indicate that NMO 1 is used
    -   if pc_GERAN and NOT pc_UTRAN, Cell 24 (only active when stated).
        -   same PLMN like visited PLMN above
        -   RAC-1 (RAC & LAC values chosen by SS)
        -   System information indicate that NMO 1 is used
    UE:
    -   The UE is configured to initiate combined EPS/IMSI attach.
    -   The test USIM contains IMSI-1, GUTI-1 and TAI-1, and EPS update status is "EU1: UPDATED".
    -   The test USIM contains P-TMSI-1 (belonging to RAI-1) and the GPRS update status is "GU1: UPDATED".
    -   The test USIM contains TMSI-1 (belonging to LAI-1) and the update status is "U1: UPDATED".
    Preamble:
    -   The UE is in state Switched OFF (state 1) according to [18]
    */

    var boolean v_TriggerRxd := false;
    if (pc_UTRA) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN ,LTEmulticell_UTRANCell );
    } else if (pc_GERAN) {
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell_GERANcell );
    } else { // Neither UMTS, nor GSM, so just do LTE
      f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEmulticell);
    }

    // create cell and send out system information
    f_EUTRA_CellConfig_Def(eutra_CellA);

    f_UT_ConfigureCombinedAttach (UT); // R5-103815

    // Preamble: UE is in state Switched OFF (state 1)
    // ==========================================================================
    // If pc_GERAN or pc_UTRAN supported by UE, wait for other RAT to update TMSI-1, P-TMSI-1and RAI-1, and GPRS update status is "GU1:UPDATED"
    if (pc_UTRA) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, UTRAN);
    } else if (pc_GERAN) {
        v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
        f_EUTRA_Preamble_InterRAT(eutra_CellA, STATE2_IDLEUPDATE, GERAN);
    } else { // supports neither UTRAN or GERAN
        f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    }
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_CellI, RRC_IDLE );
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_2_1_2_15_Body();

    // Postamble
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_Postamble(eutra_CellA, E2_CONNECTED);
} // end f_TC_9_2_1_2_15_EUTRA

    function fl_TC_9_2_1_2_15_Body() runs on EUTRA_PTC
    {
        var boolean v_TriggerRxd := false;
        var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
        var NAS_MSG_Indication_Type v_NasInd;
        var charstring v_OtherPTC := "";
        var float v_Wait_t3402 := f_EUTRA_SetTimerToleranceMax ( eutra_CellA, 720.0);
        var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType ();
        var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();

        if (pc_UTRA) {
          v_OtherPTC := "UTRAN";
        } else if (pc_GERAN) {
          v_OtherPTC := "GERAN";
        } else { // Neither UMTS, nor GSM, so just do LTE
          v_OtherPTC := "NONE";
        }
        //  Set Power levels
        //@siclog "Step 1" siclog@
        f_EUTRA_SetCellPower ( eutra_CellA, tsc_ServingCellRS_EPRE, cs_TimingInfo_Now );

        select (v_OtherPTC) { // Send trigger to other RAT then wait for trigger to be returned
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
          } case else {} // Do nothing
        }

        // Switch on UE
        //@siclog "Step 2" siclog@
        f_UT_SwitchOnUE (UT, false);

        //@siclog "Step 3 - 12" siclog@
        fl_TC_9_2_1_2_15_AttachRequest_AndWait(f_EUTRA_SetTimerToleranceMax ( eutra_CellA, 25.0), 5, 2);

        //  Configure Cells.
        //@siclog "Step 13" siclog@
        f_EUTRA_SetCellPower ( eutra_CellA, tsc_NonSuitableCellRS_EPRE, cs_TimingInfo_Now );
        select (v_OtherPTC) { // change power levels, send trigger to other RAT, then wait for trigger to be returned
          case ("UTRAN") {
            f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(UTRAN); // wait for trigger from UTRAN side
          } case ("GERAN") {
            f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);
            v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(GERAN); // wait for trigger from GERAN side
          } case else {} // Do nothing
        }

        //  Set Power levels. Cell5/24 comes from Non-Suitable Cell level
        //@siclog "Step 14" siclog@
        f_EUTRA_SetCellPower ( eutra_CellA, tsc_ServingCellRS_EPRE, cs_TimingInfo_Now );

        //@siclog "Step 15" siclog@
        // If possible (see ICS) switch off is performed. Otherwise the power is removed.
        f_UT_SwitchOffUE (UT, false);

        //  UE brought back to operation. Attach attempt counter is then reset
        //@siclog "Step 16" siclog@
        f_UT_SwitchOnUE (UT, false );

        //  ( four 1st iterations )
        //@siclog "Step 17 - 24" siclog@
        fl_TC_9_2_1_2_15_AttachRequest_AndWait_Modified(f_EUTRA_SetTimerToleranceMax ( eutra_CellA, 25.0), 4);

        //@siclog "Step 25 - 26" siclog@
        //The UE transmits an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message.
        //Wait for 15s to ensure that T3410 expires and the UE releases locally the NAS Signalling
        //The attach attempt counter is 5 and the UE starts T3402
        fl_TC_9_2_1_2_15_AttachRequest_AndWait_Modified(f_EUTRA_SetTimerToleranceMax ( eutra_CellA, 15.0), 1);

        //@siclog "Step 27" siclog@
        //Check: Does the UE transmit an ATTACH REQUEST message including a PDN CONNECTIVITY REQUEST message
        //after 12 minutes?
        f_Delay(v_Wait_t3402);
 
        v_NasInd:= f_EUTRA_RRC_ConnEst_DefWithNas(eutra_CellA,
                                                  v_RRC_TI,
                                                  cr_EstablishmentCause_Any,
                                                  cr_NAS_IndicationWithPiggybacking(tsc_SHT_NoSecurityProtection,
                                                    cdr_ATTACH_REQUEST_WithIMSIAndnoTAI(
                                                                   v_AttachType,
                                                                   v_AdditionalUpdateType,
                                                                   f_Imsi2MobileIdentity( px_IMSI_Def ),
                                                                   cr_TMSI_Status('0'B)),
                                                    cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach,
                                                                                    f_GetPdnType())
                                                   ));

        f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step27");

        //@siclog "Step 28 - 39" siclog@
        f_EUTRA_IdleUpdated_Step5_17(eutra_CellA, STATE2_IDLEUPDATE, NORMAL, v_NasInd, false);

    }// end function fl_TC_9_2_1_2_15_Body


  } // group TestcaseImplementations

} // module NAS_Attach_UG
