/******************************************************************************/
// @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-17 10:35:29 +0200 (Fri, 17 Sep 2010) $
// $Rev: 3951 $
/******************************************************************************/

module MultiLayer_Procedures {

//----------------------------------------------------------------------
// Import part
//----------------------------------------------------------------------

  import from CommonDefs all;
  import from CommonIP all;
  import from CommonIratDefs all;
  import from Parameters all;
  import from UpperTesterFunctions all;
  import from EPS_NAS_Constants all;
  import from EPS_NAS_MsgContainers all;
  import from EPS_NAS_Templates all;
  import from EPS_NAS_TypeDefs all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_CellInfo all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_Component all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_LoopBack all;
  import from EUTRA_Measurement_Templates all;
  import from EUTRA_NASSteps all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_RRCSteps all;
  import from EUTRA_SRB_Templates all;
  import from EUTRA_DRB_Templates all;
  import from EUTRA_SecurityFunctions all;
  import from EUTRA_SecuritySteps all;
  import from EUTRA_SysInfo_Templates all;
  import from EUTRA_IdleMode all;
  import from EUTRA_NASCommonTemplates all;
  import from EUTRA_Paging all;
  import from EUTRA_IRATFunctions all;

  import from UTRAN_CapabilityFunctions all; //For f_U_EncodeHandoverToUtran_64kPS_FDD


//----------------------------------------------------------------------
// Templates
//----------------------------------------------------------------------

  group TC_13_2_1_Templates {

  //Step3
  template (value) DL_DCCH_Message cs_RRCConnectionReconfiguration_13_2_1_Step3(RRC_TransactionIdentifier p_RRC_TI,
                                                                                 ARFCN_ValueEUTRA p_EUTRA_DL_CarrierFreq1,
                                                                                 AllowedMeasBandwidth p_MeasurementBandwidth1) :=
    /* @status    APPROVED */
    cs_508_RRCConnectionReconfiguration_ConditionMEAS (p_RRC_TI,
                                                       cs_MeasConfig (omit,
                                                                      cs_MeasObjectToAddModList_1Entry (tsc_IdMeasObject_f1,
                                                                                                        cs_MeasObject_measObjectEUTRA_Common (p_EUTRA_DL_CarrierFreq1,
                                                                                                                                              p_MeasurementBandwidth1,
                                                                                                                                              omit,
                                                                                                                                              omit,
                                                                                                                                              omit)),
                                                                      omit,
                                                                      cs_ReportConfigToAddModList_1Entry (1, cs_508_ReportConfigEUTRA_A3),
                                                                      omit,
                                                                      cs_MeasIdToAddModList_1Entry (1, tsc_IdMeasObject_f1, 1),
                                                                      cs_QuantityConfig(cs_QuantityConfigEUTRA (omit, omit), omit, omit, omit ), //@sic R5s100288 sic@
                                                                      omit, //@sic R5s100288 sic@
                                                                      omit,
                                                                      omit,
                                                                      omit));
  
  //Step 4
  template (value) ReportConfigToAddMod.reportConfig cs_508_ReportConfigEUTRA_A3_H :=
    cs_ReportConfig_reportConfigEUTRA_eventA3( 20, false, 0, ms0, rsrp, sameAsTriggerQuantity, 1, ms1024, r1 );
  
  
  //Step6
  template UL_DCCH_Message cr_MeasurementReport_13_2_1_Step6( PhysCellId p_PhysCellId ) :=
    /* @status    APPROVED */
    cr_MeasurementReport(1,
                         ?,
                         ?,
                         cr_MeasResultNeighCells_measResultListEUTRA_1Entry( p_PhysCellId, omit,?, ? ) );

  } //group TC_13_2_1_Templates


  template (value) PagingIdentity cs_PagingIdentity ( B1_Type p_PagingId ) := {
   iei       := omit,
   spareBits := '0000000'B,
   pagingId  := p_PagingId
  };

  template (value) NAS_DL_Message_Type cs_508_Service_Notification :=  {
  
    cS_SERVICE_NOTIFICATION := {
      securityHeaderType    := tsc_SHT_NoSecurityProtection,
      protocolDiscriminator := tsc_PD_EMM,
      messageType           := tsc_MT_CSServiceNotification,
      pagingIdentity        := cs_PagingIdentity('1'B),
      cli                   := omit,
      ssCode                := omit,
      lcsIndicator          := omit,
      lcsClientIdentity     := omit
    }
  };

  template (value) DL_DCCH_Message cs_508_RRCConnectionReconfiguration_MeasConfig_UTRAN ( ARFCN_ValueUTRA           p_CarrierFreq,
                                                                                          EUTRA_RS_EPRE_Type        p_EUTRA_RS_EPRE_Type,
                                                                                          UTRA_Ec_Io_dB_Type        p_UTRA_Ec_Io_dB_Type,
                                                                                          RRC_TransactionIdentifier p_RRC_TI := tsc_RRC_TI_Def) :=
  cs_508_RRCConnectionReconfiguration_ConditionMEAS(
    p_RRC_TI,
    cs_MeasConfig(
      omit,
      cs_MeasObjectToAddModList_1Entry(
        tsc_IdMeasObject_f8,
        cs_508_MeasObjectUTRA_GENERIC( p_CarrierFreq ) ),
      omit,
      cs_ReportConfigToAddModList_1Entry(
        1,
        cs_508_ReportConfigInterRAT_B2_UTRA_ConditionFDD( p_EUTRA_RS_EPRE_Type, p_UTRA_Ec_Io_dB_Type ) ),
      omit,
      cs_MeasIdToAddModList_1Entry( 1, tsc_IdMeasObject_f8, 1 ),
      cs_QuantityConfig( omit, cs_QuantityConfigUTRA( cpich_EcN0, pccpch_RSCP, fc0 ), omit, omit ),
      cs_508_MeasGapConfig_GP1,
      omit, omit, omit ) );
      
  template UL_DCCH_Message cr_MeasurementReport_UTRAN( template MeasResults.measResultNeighCells p_MeasResultNeighCells ) :=
    cr_MeasurementReport( 1, ?, ?, p_MeasResultNeighCells );
    
  template NAS_UL_Message_Type cdr_EXT_SERVICE_REQUEST_MO(NAS_KsiValue p_KsiValue,
                                                          EPS_ServiceTypeValue p_ServiceType,
                                                          EPS_M_Tmsi p_MTmsi) modifies cr_508_EXT_SERVICE_REQUEST :=
  {
    eXT_SERVICE_REQUEST := {
      csfbResponse := omit   //The UE shall include this IE only if the Service type information element is set to "mobile terminating CS fallback or 1xCS fallback".
    }
  };

//----------------------------------------------------------------------
// Test cases
//----------------------------------------------------------------------
  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.1.1
   * @status    APPROVED
   */
  function f_TC_13_1_1_EUTRA() runs on EUTRA_PTC
  { /* Activation and deactivation of additional data radio bearer in E-UTRA */

    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    var template(value) NAS_MSG_Request_Type v_NAS_MSG_Request;
    var template (value) ESM_Cause v_EsmCause36 := cs_ESM_Cause_v ('00100100'B); // "Regular deactivation"  // @sic R5-101118: ESM_Cause sic@
    var ProcedureTransactionIdentifier v_EPS_TI := '00'O;
    var EPS_BearerIdentity v_DedicatedEpsBeareId := tsc_EpsDedicatedBearerId;
    var EPS_BearerIdentity v_LinkedEpsBearerId := tsc_EpsDefaultBearerId;
    var UInt16_Type v_Src_Port := 31160; // @sic R5s100068 sic@ // @sic R5s100135 sic@
    var UInt16_Type v_Dst_Port := 61000; // @sic R5s100068 sic@ // @sic R5s100135 sic@
    var template (value) octetstring v_AnyUdpPacket;
    
    if (pc_IPv4) {
      v_AnyUdpPacket := crs_IPv4_AnyUdpPacket ( px_IPv4_RemoteAddress, // @sic R5s100135 sic@ // @sic R5-103846, R5s100189 sic@
                                                px_IPv4_RemoteAddress,
                                                v_Src_Port,
                                                v_Dst_Port );
    } else {
      v_AnyUdpPacket := crs_IPv6_AnyUdpPacket ( px_IPv6_RemoteAddress, // @sic R5s100135 sic@ // @sic R5-103846, R5s100189 sic@
                                                px_IPv6_RemoteAddress,
                                                v_Src_Port,
                                                v_Dst_Port );
    }
    
    f_EUTRA_Init ( c1 );

    v_NAS_MSG_Request := cs_NAS_Request( tsc_SHT_IntegrityProtected_Ciphered,
                                         cs_508_DeactivateEPSBearerCxtReq( v_DedicatedEpsBeareId,
                                                                           v_EPS_TI,
                                                                           v_EsmCause36 ) ); // @sic R5-101118: ESM_Cause sic@

    //Create and configure cell
    f_EUTRA_CellConfig_DRB_Common ( eutra_Cell1, 1, 0);

    /* Preamble The UE is in state Generic RB Established, UE test mode activated (state 3A) according to [18] using the UE TEST LOOP MODE B. */
    f_EUTRA_Preamble ( eutra_Cell1, STATE2A_TESTLOOP_ModeB );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );

    f_EUTRA_TestBody_Set ( true, layer2 );  // @sic R5-101050 sic@

    //@siclog "Step 1 - 2" siclog@
    /* Step 1: SS transmits an RRCConnectionReconfiguration message to establish a data radio bearer.
     *         The SS transmits a ACTIVATE DEDICATED EPS BEARER CONTEXT REQUEST message activating a new EPS bearer context.
     *         The NAS message is included in a RRCConnectionReconfiguration message.
     * Step 2: The UE transmit a RRCConnectionReconfigurationComplete message to confirm the establishment of data radio bearer. */
    f_EUTRA_TxDedicatedEpsBearerCtxtReq ( eutra_Cell1,
                                          tsc_DRB2,
                                          v_DedicatedEpsBeareId,
                                          v_EPS_TI,
                                          cs_LinkedId(hex2bit( v_LinkedEpsBearerId)),
                                          cs_508_EPS_QoS_Dedicated_1, // According to Context#1 in TS 36.508
                                          cs_508_Tft_Dedicated_1 ); // According to Context#1 in TS 36.508

    //@siclog "Step 3" siclog@
    /* The UE transmits an ACTIVATE DEDICATE EPS BEARER CONTEXT ACCEPT message. */
    SRB.receive ( car_SRB2_NasPdu_IND( eutra_Cell1,
                                       cr_NAS_Indication( tsc_SHT_IntegrityProtected_Ciphered,
                                                          cr_508_ActDedicatedEPSBearerCxtAccept ( v_DedicatedEpsBeareId ) ) ) );

    //@siclog "Step 4" siclog@
    /* The SS closes the UE test loop mode. */
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '00'O );

    //@siclog "Step 5" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB1,
                                             cs_TimingInfo_Now,
                                             { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                             px_IPv4_Address ) } ) ); // @sic R5s100135 sic@

    //@siclog "Step 6" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell1,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) ); // @sic R5s100135 sic@
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.2.1 Step 6");

    //@siclog "Step 7" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the dedicated EPS bearer context. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB2,
                                             cs_TimingInfo_Now,
                                             {v_AnyUdpPacket} ) ); // @sic R5s100135 sic@

    //@siclog "Step 8" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the dedicated EPS bearer context? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell1,
                                                    tsc_RbId_DRB2,
                                                    ?,
                                                    { v_AnyUdpPacket } ) ); // @sic R5s100135 sic@
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.2.1 Step 8");

    //@siclog "Step 9" siclog@
    /*         SS transmits an RRCConnectionReconfiguration message to release a data radio bearer.
     *         The SS transmits a DEACTIVATE EPS BEARER CONTEXT REQUEST including the EPS bearer identity of the dedicated EPS bearer.
     *         The NAS message is included in a RRCConnectionReconfiguration message. */
    SRB.send ( cas_SRB1_RrcNasPdu_REQ ( eutra_Cell1,
                                        cs_TimingInfo_Now,
                                        cs_RRCConnectionReconfiguration_DRB_Release ( v_RRC_TI, tsc_DRB2 ),
                                        v_NAS_MSG_Request ) );

    //@siclog "Step 10" siclog@
    /* The UE transmits an RRCConnectionReconfigurationComplete message. */
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete ( v_RRC_TI ) ) );

    //@siclog "Step 11" siclog@
    /* The UE transmit a DEACTIVATE EPS BEARER CONTEXT ACCEPT. */
    SRB.receive ( car_SRB2_NasPdu_IND ( eutra_Cell1,
                                        cr_NAS_Indication ( tsc_SHT_IntegrityProtected_Ciphered,
                                                            cr_508_DeactivateEPSBearerCxtAccept ( v_DedicatedEpsBeareId ) ) ) );

    //@siclog "Step 12" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB1,
                                             cs_TimingInfo_Now,
                                             { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                             px_IPv4_Address ) } ) ); // @sic R5s100135 sic@

    //@siclog "Step 13" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell1,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) ); // @sic R5s100135 sic@
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.2.1 Step 13");

    f_EUTRA_TestBody_Set ( false );

    /* Postamble */
    f_EUTRA_Postamble ( eutra_Cell1, E3_TESTMODE ); //@sic R5-103875 sic@
  }
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.1.2
   * @status
   */
  function f_TC_13_1_2_EUTRA() runs on EUTRA_PTC {
  
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var GutiParameters_Type v_GutiParams;
    var IRAT_CoOrd_SysInfo_Type v_UTRANSysInfo;
    var template (value) RedirectedCarrierInfo v_RedirectedCarrierInfo;
    var EUTRA_SecurityParams_Type v_AuthParams;
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_Info;
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo;
    var boolean v_TriggerRxd := false;
    var ReleaseCause v_ReleaseCause := other;
    
    f_EUTRA_Init (c4);//SIB2, SIB3 & SIB6 are transmitted
    
    //Get cell information
    v_GutiParams := f_EUTRA_CellInfo_GetGuti(eutra_Cell1);
    v_EUTRA_FDD_TDD_Info := f_EUTRA_CellInfo_GetFDD_TDD_Info (eutra_Cell1);
    v_AntennaInfo :=  f_EUTRA_CellInfo_GetAntennaInfoDedicated (eutra_Cell1);
    
    //Coordinate with UTRAN component to receive UTRAN frequency of utran_Cell5
    v_UTRANSysInfo := f_WaitForIRATCoOrd_SysInfo (UTRAN);
    
    //Set the Redirect Information in the RRCConnectionRelease message according to Table 13.1.2.3.3-3
    if ( f_EUTRA_CellInfo_GetFDD_TDD (eutra_Cell1) == FDD ) {//Since we do not have mixed FDD/TDD InterRat environment.
        v_RedirectedCarrierInfo := cs_RedirectionInfo_UtraFdd ( v_UTRANSysInfo.Utran[0].FDD.Freq );
    }
    else {
        v_RedirectedCarrierInfo := cs_RedirectionInfo_UtraTdd ( v_UTRANSysInfo.Utran[0].TDD.Freq );
    }

    //Set SIB6 for Cell 1 according to Table 13.1.2.3.3-1
    if ( f_EUTRA_CellInfo_GetFDD_TDD (eutra_Cell1) == FDD ){//Since we do not have mixed FDD/TDD InterRat environment.
      f_EUTRA_CellInfo_SetSIB6 ( eutra_Cell1,
                                 cs_508_SystemInformationBlockType6_Def ( { cs_CarrierFreqUTRA_FDD_CRPrio ( v_UTRANSysInfo.Utran[0].FDD.Freq, 3)},
                                                                          omit));
    }
    else {
      f_EUTRA_CellInfo_SetSIB6 ( eutra_Cell1,
                                 cs_508_SystemInformationBlockType6_Def ( omit,
                                                                          { cs_CarrierFreqUTRA_TDD_CRPrio ( v_UTRANSysInfo.Utran[0].TDD.Freq, 3)}));
    }

    f_EUTRA_CellInfo_InitMaxReferencePower (eutra_Cell1, -75);
    
    //Create and configure cells
    f_EUTRA_CellConfig_Def (eutra_Cell1);

    //Bring UE to initial state
    f_UT_ConfigureCombinedAttach(UT);
    f_EUTRA_Preamble_InterRAT (eutra_Cell1, STATE2_IDLEUPDATE, UTRAN);
    
    //Set cell power level according to T0
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    f_EUTRA_SetCellPower ( eutra_Cell1, -75, cs_TimingInfo_Now);

    f_EUTRA_TestBody_Set (true);
    
    //@siclog "Step 1" siclog@
    //Initiate a CS call
    f_UT_RequestCSCall (UT);
    
    //@siclog "Step 2-4" siclog@
    //Receive RRCConnectionRequest, Transmit RRCConnectionSetup & Receive EXTENDED SERVICE REQUEST
    v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_Cell1,
                                                tsc_RRC_TI_Def,
                                                cr_EstablishmentCause_Any,
                                                cr_NAS_Indication(tsc_SHT_IntegrityProtected_Ciphered,
                                                                  cdr_EXT_SERVICE_REQUEST_MO(f_EUTRA_SecurityKSIasme_Get(),
                                                                                             tsc_EST_CsFallback_MO,
                                                                                             bit2oct(v_GutiParams.M_TMSI))));
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Step 4");
    
    //@siclog "Step 5-6" siclog@
    //Transmit SecurityModeCommand & Receieve SecurityModeComplete to activate RRC security
    v_AuthParams := f_EUTRA_Security_Get();
    v_AuthParams := f_EUTRA_RRC_ActivateSecurity(eutra_Cell1, v_AuthParams, v_NAS_Ind.SecurityProtection.NasCount);
    f_EUTRA_Security_Set (v_AuthParams);

    //@siclog "Step 6" siclog@
    //Transmit RRCConnectionReconfiguration message  (with condition SRB2-DRB(1,0).
    SRB.send (cas_SRB1_RrcPdu_REQ (eutra_Cell1,
                                   cs_TimingInfo_Now,
                                   cs_RRCConnectionReconfiguration_SRB2_1AM_DRB_Est (tsc_RRC_TI_Def,
                                                                                     v_EUTRA_FDD_TDD_Info.cqi_ReportConfig,
                                                                                     v_EUTRA_FDD_TDD_Info.soundingRS_UL_Config,
                                                                                     v_AntennaInfo)));
    
    //@siclog "Step 7" siclog@
    //Receive RRCConnectionReconfigurationComplete
    SRB.receive (car_SRB1_RrcPdu_IND (eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete (tsc_RRC_TI_Def)));
    
    //@siclog "Step 8" siclog@
    //Transmit RRCConnectionRelease to redirect UE to utran cell 5
    f_EUTRA_RRC_ConnectionRelease_Common (eutra_Cell1,
                                          cs_RRCConnectionRelease (tsc_RRC_TI_Def,
                                                                   v_ReleaseCause,
                                                                   v_RedirectedCarrierInfo,
                                                                   omit));
                                                                   
    //Tell the UTRAN PTC to take over the test case
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    
    f_EUTRA_TestBody_Set (false);
    
    //Wait till end of test case
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (UTRAN);
    
    //Remove E-UTRA cell
    f_EUTRA_ReleaseAllCells();
  }

  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.1.3
   * @status
   */
  function f_TC_13_1_3_EUTRA() runs on EUTRA_PTC {
  
    /* Open issues/FFSs/TBDs
     * 1. Step 6 in prose states: "message with Establishment cause 'Signaling' to initiate RA"
     *    Enumerated type EstablishmentCause does not include 'Signaling'
     * 2. Step 7
     *    Since UE has a CM Application Request pending (Paging Response), UE might set the Follow-On-Request flag in the RAU Request
     * 3. Parallel behaviour
     *    In step 6 the UE reselects Cell5 and performs Combined RAU as NMO I is default Network Operation Mode.
     *    As the UE is now updated for PS services as well, the steps 1-3 in Table 13.1.3.3.2-3 may not be required?
     *    Have been in contact with author and this is to be clarified in prose => See answer below
     *    Answer from prose writer:
          - I think I introduced a bad correction in this test case. Right now, the way the test case is written, the RAU procedure is executed twice.
            First time as part of the generic procedure in 6.4.2.8 steps 4,9 and 10, and subsequently for a second time in the parallel procedure.
            I think the parallel procedure should just have the service request instead of the RAU procedure
            (that's how it was originally - therefore the service request message contents in table 13.1.3.3.3-8).
            The SR would be triggered once the loopback timer expires after 255 seconds.
          - I agree, actually with the loopback delay at 255 seconds, unless the test box executes the sequence very slowly,
            I think it would always follow the scenario you described.
            This would be fixed if we add the above proposed change (replace RAU procedure by SR in the parallel procedure)
          As consequence of answer the test case behavior from step 14 have been modified and we expect
             - combined RAU
             - then Paging Response
             - then CS call setup
             - RRC Connection is released
             - and then Service Request procedure for PS call setup
             - and finally loop back of IP packet
     *       => No parallel behaviour
     *
     *    In case the parallel behaviour is really going to happen the PS RAB establishment procedure needs to be re-written
     *    => For steps 3-4 in Parallel behaviour: pr_GotoState6_14_PS_CS_NewSIB1_11
     * 4. Step 15-25
     *    f_UTRAN_MM_Authentication includes security initialisation. This should be aligned with security responsible.
     *    Function f_MM_AuthenticationInit is not yet complete
    */
  
    var IRAT_CoOrd_SysInfo_Type v_UTRANSysInfo;
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    var boolean v_TriggerRxd := false;
    var integer v_RSEPRE_Cell1_T0 := -75;
    var octetstring v_IP_PDU_delay := 'FF'O;// IP_PDU_delay = 255 sec
    var CellReselectionPriority v_CellReselectionPriority_Cell5 := 3;
    var GutiParameters_Type v_GutiParams;
    var ReleaseCause v_ReleaseCause := other;
    var template (value) RedirectedCarrierInfo v_RedirectedCarrierInfo;

    f_EUTRA_Init (c4);

    v_GutiParams := f_EUTRA_CellInfo_GetGuti (eutra_Cell1);

    //Coordinate with UTRAN component to receive UTRAN frequency of utran_Cell5
    v_UTRANSysInfo := f_WaitForIRATCoOrd_SysInfo (UTRAN);
    
    //Set the Redirect Information in the RRCConnectionRelease message
    if ( f_EUTRA_CellInfo_GetFDD_TDD (eutra_Cell1) == FDD ) {//Since we do not have mixed FDD/TDD InterRat environment.
        v_RedirectedCarrierInfo := cs_RedirectionInfo_UtraFdd ( v_UTRANSysInfo.Utran[0].FDD.Freq );
    }
    else {
        v_RedirectedCarrierInfo := cs_RedirectionInfo_UtraTdd ( v_UTRANSysInfo.Utran[0].TDD.Freq );
    }

    //Set SIB6 for Cell 1 according to Table 13.1.3.3.3 -2
    if ( f_EUTRA_CellInfo_GetFDD_TDD (eutra_Cell1) == FDD ){//Since we do not have mixed FDD/TDD InterRat environment.
      f_EUTRA_CellInfo_SetSIB6 ( eutra_Cell1,
                                 cs_508_SystemInformationBlockType6_Def ( { cs_CarrierFreqUTRA_FDD_CRPrio ( v_UTRANSysInfo.Utran[0].FDD.Freq,
                                                                                                            v_CellReselectionPriority_Cell5 )},
                                                                          omit));
    }
    else {
      f_EUTRA_CellInfo_SetSIB6 ( eutra_Cell1,
                                 cs_508_SystemInformationBlockType6_Def ( omit,
                                                                          { cs_CarrierFreqUTRA_TDD_CRPrio ( v_UTRANSysInfo.Utran[0].TDD.Freq,
                                                                                                            v_CellReselectionPriority_Cell5 )}));
    }

    f_EUTRA_CellInfo_InitMaxReferencePower (eutra_Cell1, -75);
    
    //Create and configure cells
    f_EUTRA_CellConfig_Def (eutra_Cell1);

    //Bring UE to initial state
    f_EUTRA_Preamble_InterRAT ( eutra_Cell1, STATE2A_TESTLOOP_ModeB, UTRAN );
    f_EUTRA_RbEst_Def (eutra_Cell1);
    f_EUTRA_CloseUE_TestLoopModeB (eutra_Cell1, v_IP_PDU_delay);
    
    //Set cell power level according to T0
    f_SendIRATCoOrd ( UTRAN, cms_IRAT_Trigger );
    f_EUTRA_SetCellPower ( eutra_Cell1, v_RSEPRE_Cell1_T0, cs_TimingInfo_Now );

    f_EUTRA_TestBody_Set ( true, layer2 );

    //@siclog "Step 1" siclog@
    //The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context on Cell 1
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU( eutra_Cell1,
                                            tsc_RbId_DRB1,
                                            cs_TimingInfo_Now,
                                            { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                            px_IPv4_Address )}));
    
    //@siclog "Step 2" siclog@
    //SS transmits a DLInformationTransfer message on Cell 1 containing a CS SERVICE NOTIFICATION message
    SRB.send ( cas_SRB1_NasPdu_REQ( eutra_Cell1,
                                    cs_TimingInfo_Now,
                                    cs_NAS_Request( tsc_SHT_IntegrityProtected_Ciphered,
                                                    cs_508_Service_Notification ) ) );

    //@siclog "Step 3a1" siclog@
    //If needed, the incomming call is accepted through user interface
    if ( not pc_ImmConnect ) {
      f_UT_AnswerCSCall (UT);
    }

    //@siclog "Step 4" siclog@
    //Verify that the UE sends Extended Service Request
    SRB.receive ( car_SRB2_NasPdu_IND ( eutra_Cell1,
                                        cr_NAS_Indication ( tsc_SHT_IntegrityProtected_Ciphered,
                                                            cr_508_EXT_SERVICE_REQUEST( f_EUTRA_SecurityKSIasme_Get(),
                                                                                        tsc_EST_CsFallback_MT,
                                                                                        bit2oct(v_GutiParams.M_TMSI)))));
    //@verdict UE sends a Extended Service Request message
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.1.3 Step 4");
    
    //@siclog "Step 5" siclog@
    //SS transmits an RRCConnectionRelease message on Cell 1 with IE redirectionInformation including UTRA-CarrierFreq of Cell 5
    f_EUTRA_RRC_ConnectionRelease_Common ( eutra_Cell1,
                                           cs_RRCConnectionRelease ( v_RRC_TI,
                                                                     v_ReleaseCause,
                                                                     v_RedirectedCarrierInfo,
                                                                     omit ) );

    //Notify UTRA after sending RRCConnectionRelease at Step 5
    f_SendIRATCoOrd ( UTRAN, cms_IRAT_Trigger );
    
    //Wait for end of test case
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( UTRAN );
    
    f_EUTRA_TestBody_Set ( false );

    //Remove E-UTRA cell
    f_EUTRA_ReleaseAllCells( );
  }
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.1.4
   * @status
   */
  function f_TC_13_1_4_EUTRA() runs on EUTRA_PTC
  {
  
    var GutiParameters_Type v_GutiParams;
    var IRAT_CoOrd_SysInfo_Type v_UTRANSysInfo;
    var integer v_UTRAN_ARFCN_Cell5, v_UTRAN_ScrCode_Cell5, v_UTRAN_Ul_ScrCode_Cell5, v_UTRAN_ParametersID_Cell5;
    var octetstring v_HandoverToUtranCommand, v_Nas_SecurityParamFromEUTRA;
    var NAS_MSG_Indication_Type v_NasInd;
    var NasCount_Type v_NasCountDL;
    var boolean v_TriggerRxd := false;
  
    f_EUTRA_Init (c4);
    
    f_EUTRA_CellInfo_InitMaxReferencePower (eutra_Cell1, -75);
    
    //Synchronise with UTRAN PTC and get Cell Parameters for UTRAN cell
    v_UTRANSysInfo := f_WaitForIRATCoOrd_SysInfo (UTRAN);
    
    //Build the HO-to-UTRAN command
    if (ischosen (v_UTRANSysInfo.Utran[0].FDD)) {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].FDD.Freq;
      v_UTRAN_ScrCode_Cell5 := v_UTRANSysInfo.Utran[0].FDD.ScramblingCode;
      v_UTRAN_Ul_ScrCode_Cell5 := 0;/* Hardcoded since CoOrd_UTRANSysInfoFDD_Type is an APPROVED object
                                       instead using the coordination message => v_UTRANSysInfo.Utran[0].FDD.Ul_ScramblingCode */
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_FDD (v_UTRAN_Ul_ScrCode_Cell5,
                                                                       v_UTRAN_ScrCode_Cell5,
                                                                       v_UTRAN_ARFCN_Cell5);
    }
    else {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].TDD.Freq;
      v_UTRAN_ParametersID_Cell5 := v_UTRANSysInfo.Utran[0].TDD.CellParametersID;
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_TDD (v_UTRAN_ParametersID_Cell5,
                                                                        v_UTRAN_ARFCN_Cell5);
    }
    
    //Set SIB6 for Cell 1 according to Table 13.1.4.3.3-2
    if ( f_EUTRA_CellInfo_GetFDD_TDD (eutra_Cell1) == FDD ){//Since we do not have mixed FDD/TDD InterRat environment.
      f_EUTRA_CellInfo_SetSIB6 (eutra_Cell1,
                                cs_508_SystemInformationBlockType6_Def ( { cs_CarrierFreqUTRA_FDD_CRPrio ( v_UTRANSysInfo.Utran[0].FDD.Freq, 3)},
                                                                         omit));
    }
    else {
      f_EUTRA_CellInfo_SetSIB6 (eutra_Cell1,
                                cs_508_SystemInformationBlockType6_Def ( omit,
                                                                         { cs_CarrierFreqUTRA_TDD_CRPrio ( v_UTRANSysInfo.Utran[0].TDD.Freq, 3)}));
    }
    
    //Bring UE to initial state
    f_EUTRA_Preamble_InterRAT (eutra_Cell1, STATE2_IDLEUPDATE, UTRAN);
    
    //Tell UTRA PTC to set appropiate cell levels
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    f_EUTRA_SetCellPower ( eutra_Cell1, -75, cs_TimingInfo_Now);
    
    f_EUTRA_TestBody_Set (true);
    
    //@siclog "Step 1" siclog@
    //Transmit a Paging message to the UE on Cell 1 using S-TMSI with CN domain indicator set to "CS"
    v_GutiParams := f_EUTRA_CellInfo_GetGuti(eutra_Cell1);
    f_EUTRA_UE_Page (eutra_Cell1,
                     cs_DomainNasPaging_OneRecord(cs_PagingUE_Identity_S_TMSI(v_GutiParams.MME_Code,
                                                                              v_GutiParams.M_TMSI),
                                                  cs));
    
    //@siclog "Step 2a1" siclog@
    //IF the UE needs to request upper layer input before accepting the CS fallback, the incoming CS call is accepted at the UE through MMI or AT command.
    if ( not pc_ImmConnect ) {
      f_UT_AnswerCSCall (UT);
    }

    //@siclog "Step 3-5" siclog@
    //Receieve RRCConnectionRequest, send RRCConnectionSetup and
    //receive RRCConnectionSetupComplete containing an EXTENDED SERVICE REQUEST with Service Type IE set to "mobile terminating CS fallback or 1xCS fallback"
    v_NasInd := f_EUTRA_RRC_ConnEst_DefWithNas(eutra_Cell1,
                                               tsc_RRC_TI_Def,
                                               cr_EstablishmentCause_Any,
                                               cr_NAS_Indication(tsc_SHT_IntegrityProtected_Ciphered,
                                                                 cr_508_EXT_SERVICE_REQUEST(f_EUTRA_SecurityKSIasme_Get(),
                                                                                            tsc_EST_CsFallback_MT,
                                                                                            bit2oct(v_GutiParams.M_TMSI))));
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.1.4 Step 5");

    //Get NAS DL Count
    v_NasCountDL := f_EUTRA_SS_NAS_CountGetDL();
    //nas-securityParamFromEUTRA is the 4 least significant bits of the NAS downlink COUNT value according to Table 13.1.4.3.3-6
    v_Nas_SecurityParamFromEUTRA := substr(v_NasCountDL, 8, 1);

    //@siclog "Step 6" siclog@
    //Send MobilityFromEUTRACommand with IE handover
    SRB.send (cas_SRB1_RrcPdu_REQ (eutra_Cell1,
                                   cs_TimingInfo_Now,
                                   cs_MobilityFromEutraCommand (tsc_RRC_TI_Def,
                                                                v_HandoverToUtranCommand,
                                                                v_Nas_SecurityParamFromEUTRA)));

    //Hand over the test case to the UTRAN PTC
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);

    f_EUTRA_TestBody_Set (false);
    
    //Wait till test case ends
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (UTRAN);

    //Release non serving cell(s)
    f_EUTRA_ReleaseAllCells ();
  }

  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.1.5
   * @status
   */
  function f_TC_13_1_5_EUTRA() runs on EUTRA_PTC
  {
  /* Open issues
   * 1. Initial conditions state that UE is registered to LAI-1, how will that happen?
  */

    var GutiParameters_Type v_GutiParams;
    var boolean v_TriggerRxd := false;
    var IRAT_CoOrd_SysInfo_Type v_UTRANSysInfo;
    var integer v_UTRAN_ARFCN_Cell5, v_UTRAN_ScrCode_Cell5, v_UTRAN_Ul_ScrCode_Cell5, v_UTRAN_ParametersID_Cell5;
    var NasCount_Type v_NasCountDL;
    var octetstring v_HandoverToUtranCommand, v_Nas_SecurityParamFromEUTRA;
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;

    f_EUTRA_Init (c4);

    v_GutiParams := f_EUTRA_CellInfo_GetGuti(eutra_Cell1);

    //Create and configure cell
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );

    //Synchronise with UTRAN PTC and get Cell Parameters for UTRAN cell
    v_UTRANSysInfo := f_WaitForIRATCoOrd_SysInfo (UTRAN);
    
    //Build the HO-to-UTRAN command
    if (ischosen (v_UTRANSysInfo.Utran[0].FDD)) {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].FDD.Freq;
      v_UTRAN_ScrCode_Cell5 := v_UTRANSysInfo.Utran[0].FDD.ScramblingCode;
      v_UTRAN_Ul_ScrCode_Cell5 := 0;/* Hardcoded since CoOrd_UTRANSysInfoFDD_Type is an APPROVED object
                                       instead using the coordination message => v_UTRANSysInfo.Utran[0].FDD.Ul_ScramblingCode */
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_FDD (v_UTRAN_Ul_ScrCode_Cell5,
                                                                       v_UTRAN_ScrCode_Cell5,
                                                                       v_UTRAN_ARFCN_Cell5 );
    }
    else {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].TDD.Freq;
      v_UTRAN_ParametersID_Cell5 := v_UTRANSysInfo.Utran[0].TDD.CellParametersID;
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_TDD (v_UTRAN_ParametersID_Cell5,
                                                                       v_UTRAN_ARFCN_Cell5);
    }
    
    //Bring UE to initial state
    f_EUTRA_Preamble_InterRAT ( eutra_Cell1, STATE2A_TESTLOOP_ModeB, UTRAN );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '00'O );

    //Tell UTRA PTC to set appropiate cell levels
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    
    f_EUTRA_TestBody_Set ( true, layer2 );
    
    //@siclog "Step 1" siclog@
    //The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context
    DRB.send (cas_DRB_COMMON_REQ_PDCP_SDU(eutra_Cell1,
                                          tsc_RbId_DRB1,
                                          cs_TimingInfo_Now,
                                          { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                          px_IPv4_Address )}));
    
    //@siclog "Step 2" siclog@
    //Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context?
    DRB.receive (car_DRB_COMMON_IND_PDCP_SDUList(eutra_Cell1,
                                                 tsc_RbId_DRB1,
                                                 ?,
                                                 { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                 px_IPv4_Address )}));

    //@siclog "Step 3" siclog@
    //Make the UE initiate an outgoing call
    f_UT_RequestCSCall(UT);

    //@siclog "Step 4" siclog@
    //The UE transmits an ULInformationTransfer message including Extanded Service Request
    SRB.receive(car_SRB2_NasPdu_IND(eutra_Cell1,
                                    cr_NAS_Indication(tsc_SHT_IntegrityProtected_Ciphered,
                                                      cdr_EXT_SERVICE_REQUEST_MO(f_EUTRA_SecurityKSIasme_Get(),
                                                                                 tsc_EST_CsFallback_MO,
                                                                                 bit2oct(v_GutiParams.M_TMSI)))));

    //Get NAS DL Count
    v_NasCountDL := f_EUTRA_SS_NAS_CountGetDL();
    //nas-securityParamFromEUTRA is the 4 least significant bits of the NAS downlink COUNT value 36.508, Table 4.6.1-6
    v_Nas_SecurityParamFromEUTRA := substr( v_NasCountDL, 8, 1);

    //@siclog "Step 5" siclog@
    //The SS transmits a MobilityFromEUTRACommand message on Cell 1
    SRB.send ( cas_SRB1_RrcPdu_REQ ( eutra_Cell1,
                                     cs_TimingInfo_Now,
                                     cs_MobilityFromEutraCommand ( v_RRC_TI,
                                                                   v_HandoverToUtranCommand,
                                                                   v_Nas_SecurityParamFromEUTRA ) ) );

    //Send trigger to UTRAN side to
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);

    //Wait till test case ends
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( UTRAN );

    f_EUTRA_TestBody_Set(false);

    //Release non serving cell(s)
    f_EUTRA_ReleaseAllCells (  );
  }

  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.2.1
   * @status    APPROVED
   */
  function f_TC_13_2_1_EUTRA() runs on EUTRA_PTC
  { /* RRC Connection Reconfiguration; E-UTRA to E-UTRA */
    var template (value) CellPowerList_Type v_CellPowerList_AtT0;
    var template (value) CellPowerList_Type v_CellPowerList_AtT1;
    var PhysCellId v_PhysCellId_Cell1;
    var PhysCellId v_PhysCellId_Cell2;
    var Frequency_IE_Type v_Frequency_IE_f1;
    var ChannelBandwidthDependency_Type v_ChBandDependency_f1;
    var default v_DefaultRef;
    
    f_EUTRA_Init ( c2 );
  
    v_PhysCellId_Cell1 := f_EUTRA_CellInfo_GetPhyCellId( eutra_Cell1 );
    v_PhysCellId_Cell2 := f_EUTRA_CellInfo_GetPhyCellId( eutra_Cell2 );

    v_Frequency_IE_f1 := f_EUTRA_CellInfo_GetFrequencyIEs( eutra_Cell1 );

    v_ChBandDependency_f1 := f_EUTRA_BandDependentParam( v_Frequency_IE_f1.DL_ChBandwidth, v_Frequency_IE_f1.UL_ChBandwidth );
 
    //Create and configure cells
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );
    f_EUTRA_CellConfig_Def ( eutra_Cell2 );

    /* Preamble The UE is in state Generic RB Established (state 4) on Cell 1 according to [18] using the UE TEST LOOP MODE B. */
    f_EUTRA_Preamble ( eutra_Cell1, STATE2A_TESTLOOP_ModeB );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '00'O );

    //Set initial cell power levels
    v_CellPowerList_AtT0 := {
      cs_CellPower ( eutra_Cell1, -85 ),
      cs_CellPower ( eutra_Cell2, -91 )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT0, cs_TimingInfo_Now );

    f_EUTRA_TestBody_Set ( true, layer2 );

    //@siclog "Step 1" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context on Cell 1. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB1,
                                             cs_TimingInfo_Now,
                                             { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                             px_IPv4_Address ) } ) );

    //@siclog "Step 2" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context on Cell 1? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell1,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) );
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.2.1 Step 2");

    //@siclog "Step 3" siclog@
    /* The SS transmits an RRCConnectionReconfiguration message on Cell 1 to setup intra frequency measurement. */
    SRB.send( cas_SRB1_RrcPdu_REQ ( eutra_Cell1,
                                    cs_TimingInfo_Now,
                                    cs_RRCConnectionReconfiguration_13_2_1_Step3 ( tsc_RRC_TI_Def,
                                                                                   v_Frequency_IE_f1.UL_DL_Earfcn.dl_CarrierFreq,
                                                                                   v_ChBandDependency_f1.AllowedMeasBandwidth ) ) );

    //@siclog "Step 4" siclog@
    /* The UE transmits an RRCConnectionReconfigurationComplete message on Cell 1. */
    SRB.receive( car_SRB1_RrcPdu_IND( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete( tsc_RRC_TI_Def ) ) );

    //@siclog "Step 5" siclog@
    /* The SS changes Cell 1 and Cell 2 parameters according to the row "T1" in table 13.2.1.3.2-1 */
    v_CellPowerList_AtT1 := {
      cs_CellPower ( eutra_Cell1, -91 ),
      cs_CellPower ( eutra_Cell2, -85 )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT1, cs_TimingInfo_Now );

    //@siclog "Step 6" siclog@
    /* The UE transmits a MeasurementReport message on Cell 1 to report event A3 with the measured RSRP and RSRQ value for Cell 2. */
    SRB.receive( car_SRB1_RrcPdu_IND( eutra_Cell1,
                                      cr_MeasurementReport_13_2_1_Step6 ( v_PhysCellId_Cell2 ) ) );

    //Activate the default to receive periodical reports for Cell2.
    v_DefaultRef := activate( a_EUTRA_AddDefault_PeriodicalMeasurmentReport( eutra_Cell1,
                                                                             cr_MeasurementReport_13_2_1_Step6 ( v_PhysCellId_Cell2 ) ) );
    
    //PDCP count shall be kept in PDCP re-establishment for AM DRB
    f_EUTRA_SS_PdcpCount_Handover ( eutra_Cell1, //@sic R5s100288 sic@
                                    eutra_Cell2,
                                    { tsc_DRB1 } );

    //@siclog "Step 7 - 8" siclog@
    /* The SS transmits an RRCConnectionReconfiguration message on Cell 1 to order the UE to perform intra frequency handover to Cell 2. */
    /* The UE transmit an RRCConnectionReconfigurationComplete message on Cell 2 to confirm the successful completion of the intra frequency handover. */
    f_EUTRA_508RRC_IntraLTE_HO_InterCell ( eutra_Cell1, eutra_Cell2 ); //@sic R5s100288 R5s100430 R5s100524 sic@

    //Deactivate the default to stop receiving periodical Measurement Report
    deactivate( v_DefaultRef );

    //@siclog "Step 9" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context on Cell 2. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU( eutra_Cell2,
                                            tsc_RbId_DRB1,
                                            cs_TimingInfo_Now,
                                            { crs_IPv4_AnyIcmpEchoReply_2 ( px_IPv4_Address,
                                                                            px_IPv4_Address )}));

    //@siclog "Step 10" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context on Cell 2? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell2,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_2 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) );
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.2.1 Step 10");

    f_EUTRA_TestBody_Set ( false );

    /* Postamble */
    f_EUTRA_Postamble ( eutra_Cell2, E3_TESTMODE );

  }


  function f_TC_13_3_1_1_EUTRA()
      runs on EUTRA_PTC {
  /* Intra System Connection Reestablishment / Radio Link Recovery while T310 is running */

    //Init cell array and security
    f_EUTRA_Init ( c1 );

    //Set Sys info for cell 1 to be used at creation
    f_EUTRA_CellInfo_SetSysInfo_T310 ( eutra_Cell1, ms2000 );

    //Create and configure cell
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );

    //The UE is in state Loopback Activated (state 4) on Cell 1 according to [18] using the UE TEST LOOP MODE B.
    f_EUTRA_Preamble ( eutra_Cell1, STATE2A_TESTLOOP_ModeB );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '05'O );

    //* @desc Set cell power levels according to T0 in Table 13.4.1.2.3.2-1
    f_EUTRA_SetCellPower ( eutra_Cell1, -97, cs_TimingInfo_Now );

    f_EUTRA_TestBody_Set ( true, layer2 );

    //@siclog "Step 1" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context on Cell 1. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB1,
                                             cs_TimingInfo_Now,
                                             { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                             px_IPv4_Address ) } ) );

    //@siclog "Step 2" siclog@
    /* The SS reduce DL RS TX power level of Cell 1 from "T0" to "T1" in table 13.3.1.1.3.2-1. */
    f_EUTRA_SetCellPower ( eutra_Cell1, tsc_NonSuitableOffCellRS_EPRE, cs_TimingInfo_Now );

    //@siclog "Step 3" siclog@
    /* The SS waits for 1.5s. T310 is 2s. */
    f_Delay(1.5); //No need to take tolerances into account, because 1.5s is reached though before T310 expires.

    //@siclog "Step 4" siclog@
    /* The SS recovers DL RS TX power level of Cell 1 from "T1" to "T2" in table 13.3.1.1.3.2-1.  */
    f_EUTRA_SetCellPower ( eutra_Cell1, tsc_ServingCellRS_EPRE, cs_TimingInfo_Now );

    //@siclog "Step 5" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context on Cell 1?( Note 1) */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell1,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) );
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.3.1.1 Step 5");

    f_EUTRA_TestBody_Set ( false );

    //Postamble
    f_EUTRA_Postamble ( eutra_Cell1, E3_TESTMODE );

  }


  function f_TC_13_3_1_2_EUTRA()
      runs on EUTRA_PTC {
  /* Intra-system connection re-establishment / Re-establishment of a new connection when further data is to be transferred */

    var template (value) CellPowerList_Type v_CellPowerList_AtT0, v_CellPowerList_AtT1;
    var ShortMAC_I v_ShortMAC_I;
    var PhysCellId v_PhysicalCellIdentity_Cell1;
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_Info;
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo;
    var EUTRA_SecurityParams_Type v_Auth_Params;
    var NextHopChainingCount v_NextHopChainingCount := 0; // Default configuration value according to TS 36.508 Table 4.6.1-10

    //Init cell array and security
    f_EUTRA_Init ( c1 );

    //Get cell specific parameters for Cell 1
    v_PhysicalCellIdentity_Cell1 := f_EUTRA_CellInfo_GetPhyCellId ( eutra_Cell1 );
    
    //Get FDD or TDD mode from Cell-configuration
    v_EUTRA_FDD_TDD_Info := f_EUTRA_CellInfo_GetFDD_TDD_Info ( eutra_Cell2 );
    v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated ( eutra_Cell2 );

    //Create and configure cell
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );
    f_EUTRA_CellConfig_Def ( eutra_Cell2 );

    //The UE is in state Loopback Activated (state 4) on Cell 1 according to [18] using the UE TEST LOOP MODE B.
    f_EUTRA_Preamble ( eutra_Cell1, STATE2A_TESTLOOP_ModeB );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '00'O );

    //Set initial cell power levels
    v_CellPowerList_AtT0 := {
      cs_CellPower ( eutra_Cell1, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_Cell2, tsc_NonSuitableCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT0, cs_TimingInfo_Now );

    v_ShortMAC_I := f_Calculate_ShortMAC ( eutra_Cell1, eutra_Cell2 );

    f_EUTRA_TestBody_Set ( true, layer2 );

    //@siclog "Step 1" siclog@
    /* The SS transmits one IP packet to the UE on the DRB associated with the default EPS bearer context on Cell 1. */
    DRB.send ( cas_DRB_COMMON_REQ_PDCP_SDU ( eutra_Cell1,
                                             tsc_RbId_DRB1,
                                             cs_TimingInfo_Now,
                                             { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                             px_IPv4_Address ) } ) );

    //@siclog "Step 2" siclog@
    /* The SS changes the power level of cell 1 to non-suitable "Off" and changes the power level of cell 2 to suitable
               according to TS 36.508 subclause 6.2.2.1 in order that the radio link quality of Cell 1 is degraded. */
    v_CellPowerList_AtT1 := {
      cs_CellPower ( eutra_Cell1, tsc_NonSuitableOffCellRS_EPRE ),
      cs_CellPower ( eutra_Cell2, tsc_SuitableCellRS_EPRE )
    };
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT1, cs_TimingInfo_Now );

    //@siclog "Step 3" siclog@
    /* Check: Does the UE initiate an RRC connection re-establisment procedure and transmit an RRCConnectionReestablishmentRequest
               message on Cell 2?  */
    SRB.receive( car_SRB0_RrcPdu_IND( eutra_Cell2,
                                      cr_508_RRCConnectionReestablishmentRequest ( tsc_C_RNTI_Def,
                                                                                   v_PhysicalCellIdentity_Cell1,
                                                                                   cr_ReestablishmentCause_OtherFailure,
                                                                                   v_ShortMAC_I ) ) );
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.3.1.2 Step 3");

    // Start UL grant transmission in Cell 2
    f_EUTRA_StartDefULGrantTransmission ( eutra_Cell2, cs_TimingInfo_Now );

    //PDCP count shall be kept in PDCP re-establishment for AM DRB
    f_EUTRA_SS_PdcpCount_Handover( eutra_Cell1,
                                   eutra_Cell2,
                                  { tsc_DRB1 } );


    //@siclog "Step 4" siclog@
    /* The SS transmits RRCConnectionReestablishment message. */
    f_EUTRA_RRC_RRCConnectionReestablishment_Def ( eutra_Cell2, tsc_RRC_TI_Def, v_NextHopChainingCount );

    // Activate RRC security at SS target cell (Cell2) for SRB 1, 2 and 1 AM DRB
    v_Auth_Params := f_EUTRA_SS_AS_ActivateSecurity_HO_Reest ( eutra_Cell2, f_EUTRA_Security_Get ( ), v_NextHopChainingCount );
    f_EUTRA_Security_Set ( v_Auth_Params );
   
    //@siclog "Step 5" siclog@
    /* UE transmits an RRCConnectionReestablishmentComplete message */
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell2,  cr_508_RRCConnectionReestablishmentComplete( tsc_RRC_TI_Def ) ) );

    //@siclog "Step 6" siclog@
    /* The SS transmits RRCConnectionReconfiguration message */
    SRB.send ( cas_SRB1_RrcPdu_REQ ( eutra_Cell2,
                                     cs_TimingInfo_Now,
                                     cs_RRCConnectionReconfiguration_SRB2_1AM_DRB_Est ( tsc_RRC_TI_Def,
                                                                                        v_EUTRA_FDD_TDD_Info.cqi_ReportConfig,
                                                                                        v_EUTRA_FDD_TDD_Info.soundingRS_UL_Config,
                                                                                        v_AntennaInfo ) ) );
    
    //@siclog "Step 7" siclog@
    /* UE transmits an RRCConnectionConfigurationComplete message */
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell2, cr_508_RRCConnectionReconfigurationComplete ( tsc_RRC_TI_Def ) ) );

    //@siclog "Step 8" siclog@
    /* Check: Does the UE loop back the IP packet on the DRB associated with the default EPS bearer context on Cell 2? */
    DRB.receive ( car_DRB_COMMON_IND_PDCP_SDUList ( eutra_Cell2,
                                                    tsc_RbId_DRB1,
                                                    ?,
                                                    { crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address,
                                                                                    px_IPv4_Address ) } ) );
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.3.1.2 Step 8");

    f_EUTRA_TestBody_Set ( false );

    //Postamble
    f_EUTRA_Postamble ( eutra_Cell1, E3_TESTMODE );

  }


  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.4.1.2
   * @status
   */
  function f_TC_13_4_1_2_EUTRA() runs on EUTRA_PTC
  {
    var Frequency_IE_Type v_Frequency_IE_Cell3;
    var ChannelBandwidthDependency_Type v_ChBandDependency_Cell3;
    var PhysCellId v_PhysicalCellIdentity_Cell3;
    var default v_DefaultRef;
    var EUTRA_SecurityParams_Type v_Auth_Params;
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;

    //Init cell array and security
    f_EUTRA_Init (c1);

    //Set cell powel level for cell 3 to be used at creation
    f_EUTRA_CellInfo_InitMaxReferencePower (eutra_Cell3, -73);

    //Get cell specific parameters for Cell 3
    v_Frequency_IE_Cell3 := f_EUTRA_CellInfo_GetFrequencyIEs (eutra_Cell3);
    v_ChBandDependency_Cell3 := f_EUTRA_BandDependentParam (v_Frequency_IE_Cell3.DL_ChBandwidth,
                                                            v_Frequency_IE_Cell3.UL_ChBandwidth);
    v_PhysicalCellIdentity_Cell3 := f_EUTRA_CellInfo_GetPhyCellId (eutra_Cell13);

    //Apply new C-RNTI on target cell to be used at creation of cell 3
    f_EUTRA_CellInfo_SetC_RNTI (eutra_Cell3, tsc_C_RNTI_Def2 );

    //* @desc Create and configure cell with SRBs and one AM DRB.
    // The AM DRB will be associated with the default EPS bearer context
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_CellConfig_Def (eutra_Cell3);

    //Bring UE to Initial state
    //UE is in state Generic RB Established, UE test mode activated (state 3A) according to [18] using the UE TEST LOOP MODE B
    f_EUTRA_Preamble (eutra_Cell1, STATE2A_TESTLOOP_ModeB);
    f_EUTRA_RbEst_Def (eutra_Cell1);
    f_EUTRA_CloseUE_TestLoopModeB (eutra_Cell1, '00'O);

    //Set cell power levels according to T0 in Table 13.4.1.2.3.2-1
    f_EUTRA_SetCellPower (eutra_Cell3, -97, cs_TimingInfo_Now);

    //Get security parameters
    v_Auth_Params := f_EUTRA_Security_Get();

    f_EUTRA_TestBody_Set (true, layer2);

    //@siclog "Step 1" siclog@
    //Transmits one IP packet to the UE on the DRB associated with the default EPS bearer context
    DRB.send (cas_DRB_COMMON_REQ_PDCP_SDU(eutra_Cell1,
                                          tsc_RbId_DRB1,
                                          cs_TimingInfo_Now,
                                          {crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address, px_IPv4_Address )}));

    //@siclog "Step 2" siclog@
    //Check if UE loops back the IP packet
    DRB.receive (car_DRB_COMMON_IND_PDCP_SDUList(eutra_Cell1,
                                                 tsc_RbId_DRB1,
                                                 ?,
                                                 {crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address, px_IPv4_Address )}));
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.4.1.2 Step 2");

    //@siclog "Step 3" siclog@
    //Transmit RRCConnectionReconfiguration message to setup inter frequency measurement and reporting for event A3
    SRB.send (cas_SRB1_RrcPdu_REQ (eutra_Cell1,
                                   cs_TimingInfo_Now,
                                   cs_508_RRCConnectionReconfiguration_ConditionMEAS (tsc_RRC_TI_Def,
                                                                                      cs_Measurement_Config_A3 (v_Frequency_IE_Cell3.UL_DL_Earfcn.dl_CarrierFreq,
                                                                                                                v_ChBandDependency_Cell3.AllowedMeasBandwidth))));

    //@siclog "Step 4" siclog@
    //Receieve RRCConnectionReconfigurationComplete message
    SRB.receive (car_SRB1_RrcPdu_IND (eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete (v_RRC_TI)));

    //@siclog "Step 5" siclog@
    //Set Cell 3 parameters according to T1 in table 13.4.1.2.3.2-1
    f_EUTRA_SetCellPower (eutra_Cell3, -73, cs_TimingInfo_Now);

    //@siclog "Step 6" siclog@
    //Receive a MeasurementReport message on Cell 1 to report event A3 with the measured RSRP and RSRQ value for Cell 3
    SRB.receive (car_SRB1_RrcPdu_IND (eutra_Cell1, cr_MeasurementReport (1,//Measurement ID
                                                                         ?,//RSRP result
                                                                         ?,//RSRQ result
                                                                         cr_MeasResultNeighCells_measResultListEUTRA_1Entry (v_PhysicalCellIdentity_Cell3,
                                                                                                                             omit,//CGI Info
                                                                                                                             ?,//RSRP result
                                                                                                                             ?))));//RSRQ result

    //Activate the default to receive further measurement reports for cell 4 on cell 1
    v_DefaultRef := activate (a_EUTRA_AddDefault_PeriodicalMeasurmentReport (eutra_Cell1,
                                                                             cr_MeasurementReport (1, ?, ?,
                                                                             cr_MeasResultNeighCells_measResultListEUTRA_1Entry (v_PhysicalCellIdentity_Cell3,
                                                                                                                                 omit, ?, ?))));

    //Transfer the PDCP count/sequence number from source to target cell
    f_EUTRA_SS_PdcpCount_Handover (eutra_Cell1, eutra_Cell3, { tsc_DRB1 });

    //@siclog "Step 7 - 8" siclog@
    //Transmit RRCConnectionReconfiguration message to order the UE to perform inter frequency handover to Cell 3
    //Receieve RRCConnectionReconfigurationComplete message to confirm the successful completion of the inter frequency HO
    f_EUTRA_508RRC_IntraLTE_HO_InterCell (eutra_Cell1, eutra_Cell3);

    //Deactivate the default to stop receiving measurement reports for cell 3 on cell 1
    deactivate (v_DefaultRef);

    //@siclog "Step 9" siclog@
    //Transmits one IP packet to the UE on the DRB associated with the default EPS bearer context
    DRB.send (cas_DRB_COMMON_REQ_PDCP_SDU (eutra_Cell3,
                                           tsc_RbId_DRB1,
                                           cs_TimingInfo_Now,
                                           {crs_IPv4_AnyIcmpEchoReply_1 (px_IPv4_Address, px_IPv4_Address)}));

    //@siclog "Step 10" siclog@
    //Check if UE loops back the IP packet
    DRB.receive (car_DRB_COMMON_IND_PDCP_SDUList (eutra_Cell3,
                                                  tsc_RbId_DRB1,
                                                  ?,
                                                  {crs_IPv4_AnyIcmpEchoReply_1 (px_IPv4_Address, px_IPv4_Address)}));
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.4.1.2 Step 10");

    f_EUTRA_TestBody_Set (false);

    //Postamble
    f_EUTRA_Postamble (eutra_Cell3, E3_TESTMODE);
  }
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 13.4.2.1
   * @status
   */
  function f_TC_13_4_2_1_EUTRA() runs on EUTRA_PTC
  {
  
  /* OPEN ISSUES
   * 1. How to set/transfer the PDCP count/sequence number?
  */

    var IRAT_CoOrd_SysInfo_Type v_UTRANSysInfo;
    var template MeasResults.measResultNeighCells v_MeasurementResult_Step6;
    var EUTRA_SecurityParams_Type v_Auth_Params;
    var integer v_UTRAN_ARFCN_Cell5, v_UTRAN_ScrCode_Cell5, v_UTRAN_Ul_ScrCode_Cell5, v_UTRAN_ParametersID_Cell5;
    var octetstring v_HandoverToUtranCommand, v_Nas_SecurityParamFromEUTRA;
    var default v_DefaultRef;
    var NasCount_Type v_NasCountDL;
    var boolean v_TriggerRxd := false;
    
    //Init cell array and security
    f_EUTRA_Init ( c1 );

    //Create and configure cell with SRBs and one AM DRB.
    //The AM DRB will be associated with the default EPS bearer context
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );

    //Bring UE to Initial state
    //UE is in state Generic RB Established, UE test mode activated (state 3A) according to [18] using the UE TEST LOOP MODE B
    f_EUTRA_Preamble_InterRAT ( eutra_Cell1, STATE2A_TESTLOOP_ModeB, UTRAN );
    f_EUTRA_RbEst_Def ( eutra_Cell1 );
    f_EUTRA_CloseUE_TestLoopModeB ( eutra_Cell1, '00'O );

    //Set cell power levels according to T0
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);

    //Get security parameters
    v_Auth_Params := f_EUTRA_Security_Get ( );
    
    //Start the test case
    f_EUTRA_TestBody_Set ( true, layer2 );
    
    //Synchronise with UTRAN PTC and get Cell Parameters for UTRAN cell
    v_UTRANSysInfo := f_WaitForIRATCoOrd_SysInfo (UTRAN);
    
    //Build the HO-to-UTRAN command and the Measurement report to be received in step 6
    if (ischosen (v_UTRANSysInfo.Utran[0].FDD)) {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].FDD.Freq;
      v_UTRAN_ScrCode_Cell5 := v_UTRANSysInfo.Utran[0].FDD.ScramblingCode;
      v_UTRAN_Ul_ScrCode_Cell5 := 0;/* Hardcoded since CoOrd_UTRANSysInfoFDD_Type is an APPROVED object
                                       instead using the coordination message => v_UTRANSysInfo.Utran[0].FDD.Ul_ScramblingCode */
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_FDD (v_UTRAN_Ul_ScrCode_Cell5,
                                                                       v_UTRAN_ScrCode_Cell5,
                                                                       v_UTRAN_ARFCN_Cell5);
      v_MeasurementResult_Step6 := cr_MeasResultNeighCells_measResultListUTRA_1Entry_FDD (v_UTRAN_ScrCode_Cell5, omit,?,?);
    }
    else {
      v_UTRAN_ARFCN_Cell5 := v_UTRANSysInfo.Utran[0].TDD.Freq;
      v_UTRAN_ParametersID_Cell5 := v_UTRANSysInfo.Utran[0].TDD.CellParametersID;
      v_HandoverToUtranCommand := f_U_EncodeHandoverToUtran_64kPS_TDD (v_UTRAN_ParametersID_Cell5,
                                                                       v_UTRAN_ARFCN_Cell5);
      v_MeasurementResult_Step6 := cr_MeasResultNeighCells_measResultListUTRA_1Entry_TDD ( v_UTRAN_ParametersID_Cell5, omit,?,? );
    }

    //@siclog "Step 1" siclog@
    //Step 1: Transmits one IP packet to the UE on the DRB associated with the default EPS bearer context
    DRB.send (cas_DRB_COMMON_REQ_PDCP_SDU(eutra_Cell1, tsc_RbId_DRB1, cs_TimingInfo_Now, {crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address, px_IPv4_Address )}));

    //@siclog "Step 2" siclog@
    //Check if UE loops back the IP packet
    DRB.receive (car_DRB_COMMON_IND_PDCP_SDUList(eutra_Cell1, tsc_RbId_DRB1, ?, {crs_IPv4_AnyIcmpEchoReply_1 ( px_IPv4_Address, px_IPv4_Address )}));
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Test Case 13.4.2.1 Step 2");

    //@siclog "Step 3" siclog@
    //Transmit RRCConnectionReconfiguration message to setup inter RAT measurement and reporting for event B2
    SRB.send( cas_SRB1_RrcPdu_REQ( eutra_Cell1,
                                   cs_TimingInfo_Now,
                                   cs_508_RRCConnectionReconfiguration_MeasConfig_UTRAN ( v_UTRAN_ARFCN_Cell5,
                                                                                          -90, -18 ) ) );

    //@siclog "Step 4" siclog@
    //Receieve RRCConnectionReconfigurationComplete message
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete ( tsc_RRC_TI_Def ) ) );

    //@siclog "Step 5" siclog@
    //Set Cell parameters according to T1
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    f_EUTRA_SetCellPower ( eutra_Cell1, -100, cs_TimingInfo_Now );

    //@siclog "Step 6" siclog@
    //Receive a MeasurementReport message on Cell 1
    SRB.receive( car_SRB1_RrcPdu_IND( eutra_Cell1,
                                      cr_MeasurementReport_UTRAN( v_MeasurementResult_Step6 )));
                                      
    //Activate the default to receive further measurement reports
    v_DefaultRef := activate( a_EUTRA_AddDefault_PeriodicalMeasurmentReport( eutra_Cell1,
                                                                             cr_MeasurementReport_UTRAN( v_MeasurementResult_Step6 )));
    
    //Get NAS DL Count
    v_NasCountDL := f_EUTRA_SS_NAS_CountGetDL();
    //nas-securityParamFromEUTRA is the 4 least significant bits of the NAS downlink COUNT value 36.508, Table 4.6.1-6
    v_Nas_SecurityParamFromEUTRA := substr( v_NasCountDL, 8, 1);

    //@siclog "Step 7" siclog@
    //Transmit RRCConnectionReconfiguration message
    SRB.send ( cas_SRB1_RrcPdu_REQ ( eutra_Cell1,
                                     cs_TimingInfo_Now,
                                     cs_MobilityFromEutraCommand ( tsc_RRC_TI_Def,
                                                                   v_HandoverToUtranCommand,
                                                                   v_Nas_SecurityParamFromEUTRA ) ) );
                                                                   
    //@siclog "Step 8 - 17" siclog@
    //Receive HANDOVER TO UTRAN COMPLETE message, do RAU and loopback IP packet on UTRAN PTC
    f_SendIRATCoOrd (UTRAN, cms_IRAT_Trigger);
    
    //Stop UL grant transmission on cell 1
    f_EUTRA_StopULGrantTransmission ( eutra_Cell1, cs_TimingInfo_Now );

    //Re-establish SRBs and DRB(s) of source cell
    f_EUTRA_SS_SRBs_DRB1_ResetNow ( eutra_Cell1 );

    //Deactivate the default to stop receiving measurement reports for cell 3 on cell 1
    deactivate ( v_DefaultRef );
    
    //Test case ends
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( UTRAN );
    f_EUTRA_TestBody_Set ( false );

    //Remove the cell(s)
    f_EUTRA_ReleaseAllCells();
  }
}
