// ***************************************************************************
// @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 09:26:47 +0200 (Fri, 17 Sep 2010) $
// * $Rev: 3949 $
// ***************************************************************************

module NAS_TrackingArea_UTRAN {

  import from CommonDefs all;
  import from UTRAN_Parameters all;
  import from UTRAN_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from UTRAN_ASP_Definitions language "ASN.1:1997" all;
  import from Parameters all;
  import from UTRAN_Component all;
  import from CommonIratDefs all;
  import from UTRAN_ConfigurationSteps all;
  import from UTRAN_CellInfo all;
  import from UTRAN_CommonFunctions all;
  import from NAS_24008TypeDefs all;
  import from NAS_CommonTypeDefs all;
  import from NAS_CommonTemplates all;
  import from NAS_24008Templates all;
  import from UTRAN_TypeDefs all;
  import from UTRAN_Templates all;
  import from UTRAN_RAB_Functions all;
  import from UpperTesterFunctions all;
  import from NAS_AuxiliaryDefsAndFunctions all;
  import from UTRANGERAN_CommonFunctions all;

// Local Templates
//---------------------------------------------------------------------

  template RRCDataIndType cr_U_RA_UpdReq_WithUtranSignatures ( template (present) UpdateType p_UpdateType,
                                                                       template (present) KeySeq          p_KeySeq,
                                                                       template (present) RoutingAreaId   p_RAI,
                                                                       template PTMSI_Signature p_PTMSISig,
                                                                       template (present) octetstring     p_Tmsi,
                                                                       template MobileIdentity  p_AddMobileId,
                                                                       template RoutingAreaId2  p_AddOldRAI ) :=
  {
    routingAreaUpdateRequest :=  {
    skipIndicator   := '0000'B,
    gMMProtocolDiscriminator := tsc_GMM_PD,
    msgType         := '00001000'B,
    gprsCiphKeySeqNo := cr_CiphKeySeqNum(p_KeySeq),
    updateType      := p_UpdateType,
    oldRAI          := p_RAI,
    msRadioAccessCap := cr_MS_RadioAccessCapLVAny,
    oldPTMSI_Signature := p_PTMSISig,
    readyTimer      := *,
    drxParameter    := *,
    tmsiStatus      := omit,
    ptmsi           := cdr_MobileIdTMSI_tlv ( p_Tmsi ),
    msNetworkCap    := *,
    pDP_ContextStatus := *,
    pS_LCS_Capability := *,
    mBMS_ContextStatus := *,
    ueNetworkCapability := ?,
    addMobileId      := p_AddMobileId,
    addOldRAI        := p_AddOldRAI,
    msClassmark2     := *,
    msClassmark3     := *,
    supportedCodecList := *
  }};

  template (value) DL_DCCH_Message cs_UE_EUTRA_CapabilityEnq ( IntegrityCheckInfo        p_IntegrityCheckInfo,
                                                               RRC_TransactionIdentifier p_RRC_TI := tsc_RRC_TI ) :=
  {
    integrityCheckInfo := p_IntegrityCheckInfo,
    message_ := {
      ueCapabilityEnquiry := {
        r3 := {
          ueCapabilityEnquiry_r3 := {
            rrc_TransactionIdentifier := p_RRC_TI,
            capabilityUpdateRequirement := {
              ue_RadioCapabilityFDDUpdateRequirement := false,
              ue_RadioCapabilityTDDUpdateRequirement := false,
              systemSpecificCapUpdateReqList := omit
            }
          },
          laterNonCriticalExtensions := {
            ueCapabilityEnquiry_r3_add_ext := omit,
            v4b0NonCriticalExtensions := {
              ueCapabilityEnquiry_v4b0ext := {
                capabilityUpdateRequirement_r4_ext := {
                  ue_RadioCapabilityUpdateRequirement_TDD128 := false
                }
              },
              v590NonCriticalExtensions := {
                ueCapabilityEnquiry_v590ext := {
                  systemSpecificCapUpdateReq := geranIu
                },
                v770NonCriticalExtensions := {
                  ueCapabilityEnquiry_v770ext := {
                    capabilityUpdateRequirement := {
                      ue_RadioCapabilityTDDUpdateRequirement_TDD768 := false
                    }
                  },
                  v860NonCriticalExtensions := {
                    ueCapabilityEnquiry_v860ext := {
                      capabilityUpdateRequirement := {
                        systemSpecificCapUpdateReqList := { eutra }
                      }
                    },
                    nonCriticalExtensions := omit
                  }
                }
              }
            }
          }
        }
      }
    }
  };

  template UL_DCCH_Message cr_UE_AnyCapabilityInfoAM ( RRC_TransactionIdentifier p_RRC_TI ) :=
  {
    integrityCheckInfo := *,
    message_ := {
      ueCapabilityInformation := {
        rrc_TransactionIdentifier := p_RRC_TI,
        ue_RadioAccessCapability := *,
        ue_RATSpecificCapability := *,
        v370NonCriticalExtensions := *
      }
    }
  };

  template (value) DL_DCCH_Message cs_UE_CapabilityInfoCnfAM ( IntegrityCheckInfo        p_IntegrityCheckInfo,
                                                               RRC_TransactionIdentifier p_RRC_TI ) :=
  {
    integrityCheckInfo := p_IntegrityCheckInfo,
    message_ := {
      ueCapabilityInformationConfirm := {
        r3 := {
          ueCapabilityInformationConfirm_r3 := {
            rrc_TransactionIdentifier := p_RRC_TI
          },
          laterNonCriticalExtensions := omit
        }
      }
    }
  };

  template (value) GMM_Cause cs_GMM_Cause (B8_Type p_RejectCause) :=
  {
   iei := '25'O,
   gmmCauseValue := p_RejectCause
  };

//---------------------------------------------------------------------

function f_TC_9_2_3_1_10_UTRAN () runs on UTRAN_PTC
  {
        fl_TC_9_2_3_1_10_11_AND_12_Body ();
  }

function f_TC_9_2_3_1_11_UTRAN () runs on UTRAN_PTC
  {
        fl_TC_9_2_3_1_10_11_AND_12_Body ();
  }

function f_TC_9_2_3_1_12_UTRAN () runs on UTRAN_PTC
  {
        fl_TC_9_2_3_1_10_11_AND_12_Body ();
  }


function fl_TC_9_2_3_1_10_11_AND_12_Body () runs on UTRAN_PTC
{

    var boolean v_TriggerRxd := false;

    if (pc_UTRA) { // UE supports UTRAN

    f_UTRAN_Init(EUTRA_UTRAN);

    f_SS_CreateCellDCH(utran_Cell5);
    f_UTRAN_SendDefSysInfo (utran_Cell5);

    f_UTRAN_Pre_Preamble (utran_Cell5);
    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);
    f_UTRAN_TestBody_Set( true );

    //@siclog "Step 13" siclog@
    // Set Cell 5 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

    //@siclog "Step 14a1" siclog@
    //+  IF pc_GERAN or pc_UTRAN THEN the user initiates an attach by MMI or by AT command.
    f_UT_TriggerAttach(UT);

    //@siclog "Step 14a2" siclog@
    // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell 5?
    f_UTRAN_CheckNoAttachOnCell (utran_Cell5, 30.0, "Step 14a2");

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

    //+ Set the cell type of cell 5 or 24 to the ''Non-Suitable cell''.
    //@siclog "Step 16" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // Test case now finished on UTRAN side, Finished here for now
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);


    // Test case now finished on UTRAN side
    f_UTRAN_TestBody_Set( false );
    f_UTRAN_ReleaseCell ( utran_Cell5 );
  }
} // fl_TC_9_2_3_1_10_AND_11_UTRAN

//---------------------------------------------------------------------

// @desc Normal tracking area update / Rejected / PLMN not allowed
function f_TC_9_2_3_1_15_UTRAN () runs on UTRAN_PTC
{
 /* Test Purpose (TP)
    (1)
    with { UE has sent a TRACKING AREA UPDATE REQUEST message }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE 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 having a PLMN stored in the "forbidden PLMN list" }
    ensure that {
      when { UE is powered up on this PLMN }
        then { UE doesn't perform an attach procedure }
    }
    (3)
    with { UE in EMM-DEREGISTERED.PLMN-SEARCH state having a PLMN stored in the "forbidden PLMN list" }
    ensure that {
      when { UE enters a cell which is not in the "forbidden PLMN list" }
        then { UE initiates an attach procedure }
    }
    (4)
    with { UE in E-UTRA EMM-DEREGISTERED.PLMN-SEARCH state having a PLMN stored in the "forbidden PLMN list" }
    ensure that {
      when { UE is in a forbidden PLMN cells and when the PLMN is selected manually }
        then { UE initiates an attach procedure }
    }
    */

    /*
    Pre-test conditions
    System Simulator:
    -   Cell G, Cell H and Cell I are configured according to Table 6.3.2.2-1 in [18].
    -   Cell G belongs to TAI-7(visited PLMN) and is set to ''Serving cell''
    -   Cell H belongs to TAI-8(visited PLMN, another TAC) and is set to ''Non- Suitable cell''
    -   Cell I belongs to TAI-9(visited PLMN, another PLMN) and is set to ''Non-Suitable cell''
    PLMN in Cell G, Cell H and Cell I are not HPLMN of the UE.
    -   Cell 5 (UTRAN) or Cell 24 (GERAN).
    - Cell 5 and Cell 24 belong to RAI-1 as specified TS34.123-1 clause 12 and are set to ''Non- Suitable cell''
    UE:
    -   The UE is configured to initiate EPS attach
    -   The UE has GUTI-7.
    -   The UE is registered on TAI-7.
    -   IF pc_GERAN or pc_UTRAN THEN the UE has P-TMSI-1 and P-TMSI signature-1.
    Preamble:
    -   UE is in state Registered, Idle Mode (state 2) on Cell G according to [18].

    */


  var boolean v_TriggerRxd := false;

  if (pc_UTRA and not pc_GERAN) { // UE supports UTRAN but not GERAN
    f_UTRAN_Init(EUTRA_UTRAN);

    f_SS_CreateCellDCH(utran_Cell5);
    f_UTRAN_SendDefSysInfo (utran_Cell5);

    // Pre-Preamble on UTRAN cell first to set PTSMI, PTSMI Sig and TMSI in USIM
    f_UTRAN_Pre_Preamble (utran_Cell5);
    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_TestBody_Set( true );

    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // First Trigger:
    //@siclog "Step 12" siclog@
    // Set Cell 5 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);
    
    //@siclog "Step 13a1" siclog@
    //+  IF pc_GERAN or pc_UTRAN THEN the user initiates an attach by MMI or by AT command.
    f_UT_TriggerAttach(UT);

    //@siclog "Step 13a2" siclog@
    // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell 5?
    f_UTRAN_CheckNoAttachOnCell (utran_Cell5, 30.0, "Step 13a2");

    //+   Set the cell type of cell 5 to the ''Non-Suitable cell''.
    //@siclog "Step 15" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // Test case now finished on UTRAN side, Finished here for now
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);
    f_UTRAN_TestBody_Set( false );

    f_UTRAN_ReleaseCell ( utran_Cell5 );

    } // UE doesn't support GERAN, or supports UTRAN too, so do nothing
} // f_TC_9_2_3_1_15_UTRAN

//---------------------------------------------------------------------

// @desc Normal tracking area update / Rejected / Roaming not allowed in this tracking area
function f_TC_9_2_3_1_17_UTRAN () runs on UTRAN_PTC
{
 /* Test Purpose (TP)
    (1)
    with { the UE has sent TRACKING AREA UPDATE REQUEST message }
    ensure that {
      when { the UE receives TRACKING AREA UPDATE REJECT message with the reject cause set to "roaming not allowed in this tracking area" }
        then { the UE sets the EPS update status to EU3 ROAMING NOT ALLOWED and the UE deletes the last visited registered TAI and the UE enters the state EMM-REGISTERED.PLMN-SEARCH and the UE stores the current TAI in the list of "forbidden tracking areas for roaming" }
                }
    (2)
    with { the UE is in EMM-REGISTERED.PLMN-SEARCH state and the current TAI in the list of "forbidden tracking areas for roaming"}
    ensure that {
      when { the serving cell belongs to TAI where UE was rejected }
        then { the UE does not attempt to send TRACKING AREA UPDATE REQUEST message }
                }
    (3)
    with { the UE is in EMM-REGISTERED.PLMN-SEARCH state and the TAI of the current cell belongs to the list of "forbidden tracking areas for roaming"}
    ensure that {
      when { the UE enters a cell belonging to same PLMN and TAI not in the list of "forbidden tracking areas for roaming"}
        then { the UE sends TRACKING AREA UPDATE REQUEST message }
                }
    (4)
    with { the UE is in EMM-REGISTERED.PLMN-SEARCH state and the TAI of the current cell belongs to the list of "forbidden tracking areas for roaming"}
    ensure that {
      when { the UE enters a cell belonging to another PLMN }
        then { the UE sends TRACKING AREA UPDATE REQUEST message }
                }

    (5)
    with { the UE, which A/Gb mode or Iu mode is supported by the UE, in EMM-DEREGISTERED.PLMN-SEARCH state and the list of "forbidden tracking areas for roaming" contains more than one TAI }
    ensure that {
      when { the UE move to UTRAN or GERAN cell }
        then { the UE sends ROUTING AREA UPDATE REQUEST message }
    }
    */

    /*
    Pre-test conditions
    System Simulator:
    -   Cell G, Cell H and Cell I are configured according to Table 6.3.2.2-1 in [18].
    -   Cell G belongs to TAI-7(visited PLMN) and is set to ''Serving cell''
    -   Cell H belongs to TAI-8(visited PLMN, another TAC) and is set to ''Non- Suitable cell''
    -   Cell I belongs to TAI-9(visited PLMN, another PLMN) and is set to ''Non-Suitable cell''
    -   PLMN in Cell G, Cell H and Cell I are not HPLMN of the UE.
    -   If pc_UTRAN, Cell 5;
    -   If NOT pc_UTRAN and pc_GERAN, Cell 24.
    - Cell 5 and Cell 24 belong to RAI-8 (visited PLMN) as specified TS34.123-1 clause 12 and is set to ''Non- Suitable cell''
    -   System information indicate that NMO 1 is used
    UE:
    -   The UE is configured to initiate EPS attach
    Preamble:
    -   UE is in state Registered, Idle Mode (state 2) on Cell G according to [18]
    
    */

  var boolean v_TriggerRxd := false;
  var RRC_DATA_IND v_RRC_DataInd;
  timer t_Wait30s := f_UG_SetTimerToleranceMax (30.0);


  if (pc_UTRA and not pc_GERAN) { // UE supports UTRAN but not GERAN
    f_UTRAN_Init(EUTRA_UTRAN);

    f_SS_CreateCellDCH(utran_Cell5);
    f_UTRAN_SendDefSysInfo (utran_Cell5);

    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_TestBody_Set( true );

    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // First Trigger
    //@siclog "Step 10" siclog@
    // Set Cell 24 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

    //@siclog "Step 11a1" siclog@
    // Check: Does the UE transmit a ROUTING AREA UPDATE REQUEST message in the next 30 seconds on cell 24?
    
    f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
    t_Wait30s.start;
    alt {
    [] t_Wait30s.timeout { // Can't arrive too late
      f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 11a1");
       }
    [] U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3,
                                                cr_U_RA_UpdReq_WithUtranSignatures ( cr_GMM_UpdateType ( ?, '000'B),
                                                                       ?,
                                                                       cr_RAI_Any (omit),
                                                                       cr_PTMSI_SignatureAny ifpresent,
                                                                       '0000'O, // Hellen TO DO PTMSI mapped from GUTI
                                                                       cr_MobileIdAny('1A'O) ifpresent,
                                                                       cr_RoutingAreaId2_Any ifpresent)))
          -> value v_RRC_DataInd {
      t_Wait30s.stop;
      f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 11a1");
      }
    }

    //@siclog "Step 11a2" siclog@
    // Send ROUTING AREA UPDATE REJECT message with cause "Roaming not allowed in this area"
    U_Dc.send(cs_PS_DataReq(utran_CellDedicated,
                            tsc_RB3,
                            cs_U_RAUpdReject(cs_GMM_Cause('00001101'B)))); // cause 'Roaming not allowed in this area'

    
    //@siclog "Step 11a3" siclog@
    // Release the RRC connection
    f_UTRAN_RRC_ConnRel ( utran_Cell5, cell_Dch );
    
    //+ Set the cell type of cell 5 to the ''Non-Suitable cell''.
    //@siclog "Step 12" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // Test case now finished on UTRAN side, Finished here for now
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);
    f_UTRAN_TestBody_Set( false );

    f_UTRA_Postamble ( utran_Cell5, U1_IDLE );

    } // UE doesn't support GERAN, or supports UTRAN too, so do nothing
} // f_TC_9_2_3_1_17_UTRAN

//---------------------------------------------------------------------

// @desc Normal tracking area update / Rejected / EPS services not allowed in this PLMN
function f_TC_9_2_3_1_18_UTRAN () runs on UTRAN_PTC
{

 /* Test Purpose (TP)
    (1)
    with { UE has sent a TRACKING AREA UPDATE REQUEST message}
    ensure that {
      when { UE receives a TRACKING AREA UPDATE REJECT message with the reject cause set to 'EPS services not allowed in this PLMN' }
        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 PLMNs for GPRS service" }
    }
    (2)
    with { UE in E-UTRA EMM-DEREGISTERED.PLMN-SEARCH state and a PLMN is stored in the "forbidden PLMNs for GPRS service" }
    ensure that {
      when { UE enters a cell which is in the "forbidden PLMNs for GPRS service" }
        then { UE doesn't perform an attach procedure }
    }
    (3)
    with { UE in EMM-DEREGISTERED.PLMN-SEARCH state and a PLMN is stored in the "forbidden PLMNs for GPRS service" }
    ensure that {
      when { UE enters a cell which is not in the "forbidden PLMNs for GPRS service" }
        then { UE initiates an attach procedure }
    }
    (4)
    with { UE is switched off and a PLMN is stored in the 'forbidden PLMNs for GPRS service' }
    ensure that {
      when { UE is power ON in a cell with forbidden PLMNs for GPRS service }
        then { UE initiates an attach procedure }
    }
    */

    /*
    Pre-test conditions
    System Simulator:
    -   Cell G, Cell H and Cell I are configured according to Table 6.3.2.2-1 in [18].
    -   Cell G belongs to TAI-7(visited PLMN) and is set to ''Serving cell''
    -   Cell H belongs to TAI-8(visited PLMN, another TAC) and is set to ''Non- Suitable cell''
    -   Cell I belongs to TAI-9(visited PLMN, another PLMN) and is set to ''Non-Suitable cell''
    -   PLMN in Cell G, Cell H and Cell I are not HPLMN of the UE.
    -   If pc_UTRAN, Cell 5;
    -   If NOT pc_UTRAN and pc_GERAN, Cell 24.
    -    Cell 5 and Cell 24 belong to RAI-8 (visited PLMN) as specified TS34.123-1 clause 12 and is set to ''Non- Suitable cell''
    -   System information indicate that NMO 1 is used
    UE:
    -   The UE is configured to initiate EPS attach
    Preamble:
    -   UE is in state Registered, Idle Mode (state 2) on Cell G according to [18]
    */


  var boolean v_TriggerRxd := false;

  if (pc_UTRA and not pc_GERAN) { // UE supports UTRAN but not GERAN
    f_UTRAN_Init(EUTRA_UTRAN);

    f_SS_CreateCellDCH(utran_Cell5);
    f_UTRAN_SendDefSysInfo (utran_Cell5);

    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_TestBody_Set( true );

    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // First Trigger
    //@siclog "Step 9" siclog@
    // Set Cell 5 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);
    
    //@siclog "Step 10a1" siclog@
    //+  IF pc_GERAN or pc_UTRAN THEN the user initiates an attach by MMI or by AT command.
    f_UT_TriggerAttach(UT);

    //@siclog "Step 10a2" siclog@
    // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell 5?
    f_UTRAN_CheckNoAttachOnCell (utran_Cell5, 30.0, "Step 10a2");

    //+ Set the cell type of cell 5 to the ''Non-Suitable cell''.
    //@siclog "Step 11" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

    // Test case now finished on UTRAN side, Finished here for now
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);
    f_UTRAN_TestBody_Set( false );

    f_UTRAN_ReleaseCell ( utran_Cell5 );

    } // UE doesn't support GERAN, or supports UTRAN too, so do nothing
} // f_TC_9_2_3_1_18_UTRAN

//---------------------------------------------------------------------

/// @desc Combined tracking area update / Successful for EPS services only / MSC temporarily not reachable
function f_TC_9_2_3_2_3_UTRAN () runs on UTRAN_PTC
{
 /*
    Test Purpose (TP)
    (1)
    with { UE having sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating' or 'Combined TA/LA updating with IMSI attach' and having the tracking area updating attempt counter set to the value less than four }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE ACCEPT message with the EPS update result set to 'TA updated' and the EMM cause set to 'MSC temporarily not reachable', 'Network failure' or 'Congestion' }
        then { UE sends TRACKING AREA UPDATE REQUEST message after T3411 expiry }
                }

    (2)
    with { UE having sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating with IMSI attach', having the tracking area updating attempt counter set to four and operating in CS/PS mode 2 of operation }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE ACCEPT message with the EPS update result set to 'TA updated' and the EMM cause set to 'MSC temporarily not reachable', 'Network failure' or 'Congestion' }
        then { UE sends TRACKING AREA UPDATE REQUEST message after T3402 expiry }
                }

    (3)
    with { UE having sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating with IMSI attach', having the tracking area updating attempt counter set to four and operating in CS/PS mode 1 of operation }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE ACCEPT message with the EPS update result set to 'TA updated' and the EMM cause set to 'MSC temporarily not reachable', 'Network failure' or 'Congestion' }
        then { UE attempts to select GERAN or UTRAN radio access technology }
                }

    */

    // 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:
    None.
    Preamble:
    -   The UE is in state Switched OFF (state 1) according to [18].

    */

  var boolean v_TriggerRxd := false;

  f_UTRAN_Init(EUTRA_UTRAN);

  f_SS_CreateCellDCH(utran_Cell5);
  f_UTRAN_SendDefSysInfo (utran_Cell5);

  f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_UTRAN_TestBody_Set( true );
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);


  //@siclog "Step 20b1" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

  //  RAU procedure
  //@siclog "Step 20b2 - 20b5" siclog@
  f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
  f_UTRAN_GMM_RAU_MappedContext( utran_Cell5 );
  f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "");
  f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side

  // Test case now finished on UTRAN side
  f_UTRAN_TestBody_Set( false );
  f_UTRA_Postamble ( utran_Cell5, U1_IDLE );
  // f_UTRAN_GMM_DetachOnSwitchOff ( utran_Cell5 );
  // f_UTRAN_ReleaseCell ( utran_Cell5 );
  
} // f_TC_9_2_3_2_3_UTRAN

//---------------------------------------------------------------------

/// @desc tracking area update / Rejected / Illegal ME
function f_TC_9_2_3_2_6_UTRAN () runs on UTRAN_PTC
{
 /*
    Test Purpose (TP)
    (1)
    with { UE having sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating' }
            ensure that {
              when { UE receives a TRACKING AREA UPDATE REJECT message with the EMM cause set to 'Illegal ME' }
                then { UE considers the USIM as invalid for EPS services and non-EPS services and enters state EMM-DEREGISTERED }
                }
        */

    // Pre-test conditions
            // -------------------
            /* System Simulator:
                -   Cell A, Cell B and Cell C.
                -   If pc_UTRAN supported by UE, Cell 5.
                -   Cell 5 belongs to RAI-1(home PLMN)
                -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24.
                -   Cell 24 belongs to RAI-1(home PLMN)
                -   Cell A is "Serving cell" and Cell B, Cell C, Cell 5 and Cell 24 are "non-Suitable cell".
            UE:
                -   The UE is configured to initiate combined EPS/IMSI attach.
            Preamble:
                -   The UE is in state Registered, Idle mode (state 2) on Cell A according to [18].
        */
  
  fl_TC_9_2_3_2_6_AND_7_Body ();
        
}// f_TC_9_2_3_2_6_UTRAN


/// @desc Combined tracking area update / Rejected / EPS services and non-EPS services not allowed
function f_TC_9_2_3_2_7_UTRAN () runs on UTRAN_PTC
{

 /*
    Test Purpose (TP)
    (1)
    with { UE having sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating' }
            ensure that {
              when { UE receives a TRACKING AREA UPDATE REJECT message with the EMM 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 }
                }
        */

    // Pre-test conditions
            // -------------------
            /* System Simulator:
                -   Cell A, Cell B and Cell C.
                -   If pc_UTRAN supported by UE, Cell 5.
                -   Cell 5 belongs to RAI-1(home PLMN)
                -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24.
                -   Cell 24 belongs to RAI-1(home PLMN)
                -   Cell A is "Serving cell" and Cell B, Cell C, Cell 5 and Cell 24 are "non-Suitable cell".
            UE:
                -   The UE is configured to initiate combined EPS/IMSI attach.
            Preamble:
                -   The UE is in state Registered, Idle mode (state 2) on Cell A according to [18].
        */
  
  fl_TC_9_2_3_2_6_AND_7_Body ();
        
}// f_TC_9_2_3_2_7_UTRAN

function fl_TC_9_2_3_2_6_AND_7_Body () runs on UTRAN_PTC
{

  var boolean v_TriggerRxd := false;

  f_UTRAN_Init(EUTRA_UTRAN);

  f_SS_CreateCellDCH(utran_Cell5);
  f_UTRAN_SendDefSysInfo (utran_Cell5);

  f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_UTRAN_TestBody_Set( true );
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

  //@siclog "Step 7a1" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

  //@siclog "Step 7a3" siclog@
  // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell 5?
  f_UTRAN_CheckNoAttachOnCell (utran_Cell5, 30.0, "Step 7a3");

  //+ Set the cell type of cell 5 to the ''Non-Suitable cell''.
  //@siclog "Step 8" siclog@
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

  f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side
  // Test case now finished on UTRAN side
  f_UTRAN_TestBody_Set( false );
  f_UTRAN_ReleaseCell ( utran_Cell5);
  
} // fl_TC_9_2_3_2_6_AND_7_Body

//---------------------------------------------------------------------

// @desc Combined tracking area update / Rejected / UE identity cannot be derived by the network
function f_TC_9_2_3_2_9_UTRAN () runs on UTRAN_PTC
{
 /*
    Test Purpose (TP)
    (1)
    with { UE has sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating' }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE REJECT message with the EMM cause set to 'UE identity cannot be derived by the network' }
        then { UE deletes GUTI, last visited registered TAI, TAI list and KSI, enters the state EMM-DEREGISTERED, subsequently, automatically initiates the attach procedure and is still IMSI attached for non-EPS services }
                }

    (2)
    with { UE has sent a TRACKING AREA UPDATE REQUEST message with EPS update type set to 'Combined TA/LA updating' }
    ensure that {
      when { UE receives a TRACKING AREA UPDATE REJECT message with the EMM cause set to 'UE identity cannot be derived by the network' }
        then { UE deletes P-TMSI, P-TMSI signature, RAI and GPRS ciphering key sequence number }
                }

    */

    // Pre-test conditions
    // -------------------
    /* System Simulator:
    -   Cell A and Cell B are configured according to Table 6.3.2.2-1 in [18].
    -   Cell A belongs to TAI-1(home PLMN) and is set to ''Serving cell''
    -   Cell B belongs to TAI-2(home PLMN, another TAC) and is set to ''Non-Suitable cell''
    -   If pc_UTRAN supported by UE, Cell 5 is configured.
    -   Cell 5 belongs to RAI-1(home PLMN) and is set to ''Non-Suitable cell''
    -   If pc_GERAN and NOT pc_UTRAN supported by UE, Cell 24 is configured.
    -   Cell 24 belongs to RAI-1(home PLMN) and is set to ''Non-Suitable cell''
    UE:
    -   The UE is configured to initiate EPS attach
    -   The UE has GUTI-1.
    -   The UE is registered on TAI-1.
    -   IF pc_GERAN or pc_UTRAN THEN the UE has TMSI-1, P-TMSI-1 and P-TMSI signature-1, and the UE is registered on LAI-1 and RAI-1.
    Preamble:
    -   The UE is in state Registered, Idle mode (state 2) on Cell A according to [18].

    */

  var boolean v_TriggerRxd := false;
  var RRC_DATA_IND v_RRC_DataInd;
  var octetstring v_PLMN := f_U_Asn2Nas_PlmnId(f_UTRAN_CellInfo_GetPLMNIdentity(utran_Cell5));
  //var O1_Type v_RAC := f_UTRAN_CellInfo_GetRAC(utran_Cell5);
  //var O2_Type v_LAC := f_UTRAN_CellInfo_GetLAC(utran_Cell5);
  var START_Value v_START_Value := '00000000000000000000'B;
  var boolean v_NewKeyFlag := true;

  f_UTRAN_Init(EUTRA_UTRAN); // This is still only a 2 PTC test

  f_SS_CreateCellDCH(utran_Cell5);
  f_UTRAN_SendDefSysInfo (utran_Cell5);

  // Pre-Preamble on UTRAN cell first to set PTSMI, PTSMI Sig and TMSI in USIM
  f_UTRAN_Pre_Preamble (utran_Cell5);
  f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);
  f_UTRAN_TestBody_Set( true );

  //@siclog "Step 5a1" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

  // The UE transmits an ATTACH REQUEST message on Cell 5
  //@siclog "Step 5a3" siclog@
  // Check: Does the UE send an ATTACH REQUEST?
  f_UTRAN_RRC_ConnEst(utran_CellDedicated, est_Reg, registration); // Establish RRC connection
  alt {
    [] U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated,
                                              tsc_RB3,
                                              cr_U_AttachReqIMSInoTMSI(cr_AttachType(?, tsc_I_AttachTypeCombined),
                                                                       f_Imsi2MobileIdentity(px_IMSI_Def),
                                                                       cr_RAI (omit, cr_LAI(omit, v_PLMN, 'FFFE'O), ?))))
      -> value v_RRC_DataInd
      {
        f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 15a5");
        v_START_Value := v_RRC_DataInd.ttcn_start;
        f_SS_SecurityDownloadStart(ps_domain, v_START_Value);
      }
  }
  
  // The SS transmits an AUTHENTICATION REQUEST and CIPHERING REQUEST message.
  //@siclog "Step 5a4 - 5a5" siclog@
  f_GMM_Authentication();
  f_RRC_Security(utran_CellDedicated,                        // SECURITY MODE COMMAND, SECURITY MODE COMPLETE
                  v_NewKeyFlag,
                  ps_domain);
 
  //The UE transmits an AUTHENTICATION AND CIPHERING RESPONSE message.
 
  // SS responds with ATTACH ACCEPT message including valid TMSI, P-TMSI (TIN set to P-TMSI) and RAI and UE transmits an ATTACH COMPLETE message.
  //  Editor's Note: the default message contents in 51.010 clause 40.2.4.3 allocate a Negotiated READY timer value of 32 seconds.
  //  Attach Accept, Attach Complete
  //@siclog "Step 5a6 - 5a7" siclog@
  f_UTRAN_AttachAccept(utran_CellDedicated);
  
  f_UTRAN_RRC_ConnRel(utran_CellDedicated, cell_Dch);

  f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "");
  f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side

  // Test case now finished on UTRAN side
  f_UTRAN_TestBody_Set( false );
  f_UTRA_Postamble ( utran_Cell5, U1_IDLE ); // to be checked

} // f_TC_9_2_3_2_9_UTRAN

//---------------------------------------------------------------------

// @desc First Iu mode to S1 mode intersystem change after attach; go to E-UTRAN RRC idle; RAU to UTRAN
function f_TC_9_2_3_3_1_UTRAN () runs on UTRAN_PTC
{
  /*
  Pre-test conditions
      System Simulator:
       -    Cell A, Cell 5 (UTRA cell in LAI-1/RAI-1)
       -    Cell 5 is configured as Serving cell, Cell A as Non-Suitable Off cell.
        Note:   For Cell 5, power levels are defined in TS 34.108 subclause 6.1.5 (FDD) or 6.1.6 (TDD).
      UE:
       -    The test USIM contains a valid GUTI-1 and TAI-2, valid EPS security parameters, and EPS update status is "EU1: UPDATED".
      Preamble:
       -    The UE is in state Switched OFF (state 1) according to TS 36.508, [18].
  */

    /*
    FFS - Open issues
     Step 9
       FFS - Attach Complete on UTRAN side does not include Activate Default EPS Bearer Context Accept
     Step 25
       No activation time is indicated in step 22 since step 22 is VOID.
    */

  var UTRAN_FDD_TDD v_FDD_TDD_Mode_Cell5;
  var U_RLC_AM_IND v_RLC_AM_DATA_IND;
  var UTRAN_SecurityInfo_Type v_UTRAN_SecurityInfo;
  var PLMN_Identity v_PLMN_Identity_Cell5;
  var octetstring v_PLMN_Cell5, v_LAC_Cell5, v_RAC_Cell5;
  var NAS_Message v_RauReq_Msg;
  var Common_AuthenticationParams_Type v_Auth_Params;
  var template RRCDataIndType v_ExpectedRauReq_Msg;
  var B32_Type v_M_TMSI_Step18;  //To hold the M-TMSI that was allocated at step 18
  var B8_Type v_MMMEC_Step18;    //To hold the MME Code that was allocated at step 18
  var B32_Type v_P_TMSI_Step23;   //Is used to match the received P-TMSI in step23
  var B24_Type v_Old_P_TMSI_Sig_Step23;//Is used to match the received Old P-TMSI signature at step 23
  var bitstring v_Ptmsi_Def := oct2bit( px_PTMSI_Def );
  var RoutingParameter v_RoutingParameter := substr ( v_Ptmsi_Def, 14, 10);//routingparameter is "bit 23 to bit 14 of P-TMSI allocated at step 8"
  var boolean v_TriggerRxd := false;
  var boolean v_Match := false;//To store the result from the matching-procedure, which matches the expected RAUReq-message with the received RAUReq-message

  //Initialise all cells
  f_UTRAN_Init(EUTRA_UTRAN);

  v_PLMN_Identity_Cell5 := f_UTRAN_CellInfo_GetPLMNIdentity ( utran_Cell5 );
  v_PLMN_Cell5 := f_U_Asn2Nas_PlmnId ( v_PLMN_Identity_Cell5 );
  v_LAC_Cell5 := f_UTRAN_CellInfo_GetLAC ( utran_Cell5 );
  v_RAC_Cell5 := f_UTRAN_CellInfo_GetRAC ( utran_Cell5 );
  v_FDD_TDD_Mode_Cell5 := f_UTRAN_CellInfo_GetFDD_TDD ( utran_Cell5 );

  //Cell started switched on with default cell power level and max attenuation
  f_SS_CreateCellDCH ( utran_Cell5 );

  //Start sending System Information
  f_UTRAN_SendDefSysInfo ( utran_Cell5 );
  f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params

  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
  f_UTRAN_TestBody_Set ( true );

  //Set cell power level according to initial conditions
  f_UTRAN_SetCellPower ( utran_Cell5, tsc_AttenuationServingCell );

  f_UT_SwitchOnUE(UT, false);

  // UTRAN Attach procedure
  //@siclog "Step 1 - 9" siclog@
  f_UTRAN_GMMOnly_Attach ( utran_Cell5 );

  //@siclog "Step 10 - 12" siclog@
  f_UTRAN_UE_64kPS_Rb_Est ( utran_Cell5 );

  // Deactivate PDP and release RRC Connection
  //@siclog "Step 13" siclog@
  f_UTRAN_RRC_ConnRel ( utran_Cell5, cell_Dch );

  // Configure cell 5 as a Suitable Neighbour Cell
  //@siclog "Step 14" siclog@
  f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);//Send trigger to EUTRA component
  f_UTRAN_SetCellPower ( utran_Cell5, tsc_AttenuationSuitableNeigbourCell);

  //Configure cell 5 as Serving Cell
  //@siclog "Step 21" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
  f_UTRAN_SetCellPower ( utran_Cell5, tsc_AttenuationServingCell );

  //Reconfigure SS for routing UL NAS message in the AM PCO and receive an Initial Direct Transfer Routing Area Update Request
  //@siclog "Step 23" siclog@
  f_UTRA_SS_SetConfigRRC_RB3 ( utran_Cell5);
  U_AM.receive ( car_RLC_Data_Ind ( utran_Cell5,
                                    tsc_RB3,
                                    cr_InitDirectTransfer ( v_RoutingParameter,
                                                            v_PLMN_Identity_Cell5 ) ) ) -> value v_RLC_AM_DATA_IND;

  //Reconfigure SS for routing UL NAS message in the Dc PCO
  f_UTRA_SS_RemoveConfigRRC_RB3 ( utran_Cell5 );

  //Decode and check the Routing Area Update Message
  /* The GUTI that was allocated in step 18 is calculated according to below:
   1. The GUTI params given to Cell A at init is
      v_NAS_Param.Guti_Parameters := cs_Guti(cs_HPLMN_Def,//PLMN_Identity
                                             32769,       //p_MmeGroupId (integer)
                                             1);          //p_MmeCode (integer)
     =>
       MME_GroupId := int2bit(32769,16)
       MME_Code := int2bit(1,8)
       M_TMSI  := tsc_M_TMSI1 := oct2bit('12345678'O)
   2. At step 18 new GUTI parameters have been generated with the help of function f_CreateGutiParamsWithUpdatedSTmsi,
      i.e. new MME Code and M-TMSI has been generated with the help of function f_CreateNewS_Tmsi
      =>
        mmec := int2bit(((bit2int(p_S_Tmsi.mmec) + 1) mod 255), 8) - where p_S_Tmsi.mmec is int2bit(1,8)
        m_TMSI := (p_S_Tmsi.m_TMSI) <@ 1
   3. M-TMSI allocated in step 18 := oct2bit('12345678'O) <@ 1
      MME_Code allocated in step 18 := int2bit(2,8)
  */
  v_M_TMSI_Step18 := oct2bit('12345678'O) <@ 1;
  v_MMMEC_Step18 := int2bit(2,8);

  /* P-TMSI received in Step 23 is specified according to
      - bit 31 and bit 30: 1
      - bit 29 to bit 24: bit 29 to bit 24 of M-TMSI allocated in step 18
      - bit 23 to bit 16: MME code allocated in step 18
      - bit 15 to bit 0: bit 15 to bit 0 of M-TMSI allocated in step 18
  */
  v_P_TMSI_Step23 := '11'B                               //bit 31 and bit 30: 1
                     & substr ( v_M_TMSI_Step18, 24, 6 ) //bit 29 to bit 24: bit 29 to bit 24 of M-TMSI allocated in step 18
                     & v_MMMEC_Step18                    //bit 23 to bit 16: MME code allocated in step 18
                     & substr ( v_M_TMSI_Step18, 0, 16 );//bit 15 to bit 0: bit 15 to bit 0 of M-TMSI allocated in step 18
  
  /* Old P-TMSI signature received in step 23 is specified according to
       - bit 23 to bit 16: bit 23 to bit 16 of M-TMSI allocated in step 18
       - bit 15 to bit 0: FFS
  */
  v_Old_P_TMSI_Sig_Step23 := substr ( v_M_TMSI_Step18, 16, 8 )//bit 23 to bit 16: bit 23 to bit 16 of M-TMSI allocated in step 18
                             & '0000000000000000'B; //bit 15 to bit 0: FFS
  v_UTRAN_SecurityInfo := f_UTRAN_Security_Get();
  v_Auth_Params := v_UTRAN_SecurityInfo.authKeys.AuthPS;
  v_RauReq_Msg := v_RLC_AM_DATA_IND.data.aM_message.uL_DCCH_Message.message_.initialDirectTransfer.nas_Message;
  v_ExpectedRauReq_Msg := cr_U_RA_UpdReq_WithUtranSignatures ( cr_GMM_UpdateType ( ?, '000'B),         //UpdateType
                                                               v_Auth_Params.KeySeq,                   //KeySeq
                                                               cr_RAI_Any (omit),                      //RoutingAreaId - shall be GUTI-1 right shifted by 32bits
                                                               cs_PTMSI_Signature ( bit2oct(v_Old_P_TMSI_Sig_Step23) ), //PTMSI_Signature/Old P-TMSI signature
                                                               bit2oct(v_P_TMSI_Step23),//P-TMSI
                                                               cs_MobileIdTMSIorPTMSI ('18'O,  px_PTMSI_Def ),//MobileIdentity/P-TMSI allocated in step 8
                                                               cr_RoutingAreaId2 (v_PLMN_Cell5 & v_LAC_Cell5 & v_RAC_Cell5));//RoutingAreaId2 - RAI-1

  //Decode and check the Rauting Area Request message
  v_Match := f_DecodeAndMatch_RauReq_Msg ( v_RauReq_Msg, v_ExpectedRauReq_Msg.routingAreaUpdateRequest );
  if ( v_Match ) {
    f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Test case 9.2.3.3.1 Step 23");
  }
  else {
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Test case 9.2.3.3.1 Step 23");
  }

  //Activate Security
  //@siclog "Step 23A" siclog@
  f_RRC_Security ( utran_Cell7, false, ps_domain);//Authentication has not been performed => no new keyes

  //Transmit a ROUTING AREA UPDATE ACCEPT message (no new P-TMSI nor RAI)
  //@siclog "Step 24" siclog@
  U_Dc.send ( cs_PS_DataReq ( utran_Cell5,
                              tsc_RB3,
                              cs_U_RA_UpdAcc3 ( cs_GMM_UpdateResult ('001'B),
                                              cs_RAI ( omit, cs_LAI( omit, v_PLMN_Cell5, v_LAC_Cell5 ), v_RAC_Cell5 ),
                                              cs_PTMSI_Signature ( px_PTMSI_SigDef ),
                                              cs_MobileIdTMSIorPTMSI ('18'O, px_PTMSI_Def )) ) );

  v_UTRAN_SecurityInfo := f_UTRAN_Security_Get();

  //Transmit a  UE CAPABILITY ENQUIRY message requesting the UE E-UTRAN capabilty.
  //@siclog "Step 25" siclog@
  U_AM.send ( cas_RLC_Data_Req_NoCnf ( utran_Cell5,
                                       tsc_RB2,
                                       cs_UE_EUTRA_CapabilityEnq ( v_UTRAN_SecurityInfo.dl_IntegrityCheckInfo ) ) );

  // Receive a UE CAPABILITY INFORMATION message
  //@siclog "Step 26" siclog@
  U_AM.receive ( car_RLC_Data_Ind ( utran_Cell5,
                                    tsc_RB2,
                                    cr_UE_AnyCapabilityInfoAM ( tsc_RRC_TI ) ) );

  f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Test case 9.2.3.3.1 Step 26");

  //Transmit a UE CAPABILITY INFORMATION CONFIRM message
  //@siclog "Step 27" siclog@
  U_AM.send ( cas_RLC_Data_Req_NoCnf ( utran_Cell5,
                                        tsc_RB2,
                                        cs_UE_CapabilityInfoCnfAM ( v_UTRAN_SecurityInfo.dl_IntegrityCheckInfo,
                                                                    tsc_RRC_TI ) ) );

  //Relsease RRC Connection
  //@siclog "Step 28" siclog@
  f_UTRAN_RRC_ConnRel ( utran_Cell5, cell_Dch );

  f_UTRAN_TestBody_Set ( false );

  //Tell EUTRA Component that test case is finished
  f_SendIRATCoOrd ( EUTRA, cms_IRAT_Trigger );

  //Switch off UE and release cell
  f_UTRA_Postamble ( utran_Cell5, U1_IDLE );

} // f_TC_9_2_3_3_1_UTRAN

//---------------------------------------------------------------------
function f_TC_9_2_3_3_4_UTRAN() runs on UTRAN_PTC
    {
     // @desc Attach in E-UTRAN / RAU to UTRAN / Go to UTRAN RRC idle / TAU in E-UTRAN
     /* Test Purpose (TP)
        (1)
        with { the UE powered on in E-UTRAN with a USIM containing valid E-UTRAN NAS and Security parameters including a valid GUTI, and has successfully performed a combined EPS/IMSI attach, established PDN connectivity, and performed TRACKING AREA UPDATE REQUEST  }
        ensure that {
          when { the UE reselects UTRAN configured in MNO=II and TIN is set to the temporary ID belonging to the currently used RAT (i.e. ISR not active) }
            then { the UE transmits a LOCATION UPDATING REQUEST to the MSC/VLR and derives the IDNNS from the MSC/VLR TMSI, and transmits a ROUTING AREA UPDATE REQUEST message including P-TMSI, P-TMSI signature including the NAS token, and RAI mapped from GUTI, the old routing area identification mapped from the RAI, the GPRS ciphering key sequence number indicating the eKSI associated with the EPS security context. Old P-TMSI signature and Old routing area identifion are mapped from the GUTI. The message is encapsulated in an INITIAL DIRECT TRANSFER message including IDNSS mapped from GUTI, Establishment cause set to inter-RAT cell-selection, START value set to 0 and PLMN identity }

        (2)
        with { the UE camped on E-UTRAN and has a valid GUTI and P-TMSI }
        ensure that {
          when { the UE reselects UTRAN and receives a new P-TMSI as part of the RAU procedure }
            then { the UE uses the new P-TMSI (and not GUTI or old P-TMSI) for subsequent IDNNS network access (e.g. via the Service Request procedure }
                   }

        (3)
        with { the UE has performed a RAU procedure in UTRAN after initial registration at power on in E-UTRAN  }
        ensure that {
          when { the UE reselects a E-UTRAN cell with the same LA as previously selected}
            then { the UE transmits a TRACKING AREA UPDATE REQUEST message including eKSI stored in the USIM,
            old GUTI mapped from RAI and P-TMSI, GPRS ciphering sequence number, nonceUE.
            The UE encodes the RRC parameters in the RRC Connection Establishment messages correctly
            (i.e. in the RRCConnectionRequest message, the InitialUE-Identity is set to "Random value"
             and the establishmentcause is set to MO-signalling; and, in the RRCConnectionSetupComplete
             message the selectedPLMN-identity, mmegi and mmec indicate the value of the registered MME
             (e.g. as retrieved from the USIM at power-on, or, as received in the last TRACKING AREA UPDATE
             ACCEPT message) }
           }

        System Simulator:
        -   Cell A, and Cell 5
        -   Cell A is configured as Serving cell, Cell 5 as Non-Suitable Off cells.
        -   Cell 5 is operating in network operation mode II (No Gs interface present).
        -   Cell A has the absolute priorities set to LTE.
        NOTE:   For Cell 5, power levels are defined in TS 34.108 subclause 6.1.5 (FDD) or 6.1.6 (TDD).
        UE:
        -   The test USIM contains a valid IMSI-1, P-TMSI-1, RAI-1, valid GUTI-1 and TAI-1, and valid EPS security parameters
        Preamble:
        -   The UE is in state Registered Idle Mode  (state 2) according to TS 36.508, [18]
       */
    var boolean v_TriggerRxd := false;
    var PLMN_Identity v_HPLMN_987_65 := { mcc := {9, 8, 7},  mnc := {6, 5} };
    var octetstring v_PLMN := f_U_Asn2Nas_PlmnId(v_HPLMN_987_65);
    var template (value) CoOrd_GUTIParam_Type v_GTUIParams;
    var U_RLC_AM_IND v_RLC_AM_DATA_IND_LocUpd;
    var U_RLC_AM_IND v_RLC_AM_DATA_IND_RAUpd;
    var ROUTINGAREAUPDATEREQUEST v_ReceivedRauReq_Msg;
    var B3_Type v_UpdateType := '000'B;
    var O1_Type v_RAC := f_UTRAN_CellInfo_GetRAC(utran_Cell5);
    var O2_Type v_LAC := f_UTRAN_CellInfo_GetLAC(utran_Cell5);
    var B32_Type v_M_TMSIOut;
    var START_Value v_START_Value := '00000000000000000000'B;
    var boolean v_NewKeyFlag := false;//No new key generation
    var RoutingParameter v_RoutingParameterTMSI := substr ( oct2bit( px_TMSI_Def ), 14, 10);//routingparameter is "bit 23 to bit 14 of P-TMSI allocated at step 8"
    var RoutingParameter v_RoutingParameterPTMSI := substr ( oct2bit( px_PTMSI_Def ), 14, 10);//routingparameter is "bit 23 to bit 14 of P-TMSI allocated at step 8"
    
    f_UTRAN_Init(EUTRA_UTRAN);

    f_UTRAN_CellInfo_SetPLMNIdentity(utran_Cell5, v_HPLMN_987_65);
    f_UTRAN_CellInfo_SetNMO (utran_Cell5, tsc_NMO_II);

    f_SS_CreateCellDCH ( utran_Cell5 );

    //Start sending System Information
    f_UTRAN_SendDefSysInfo ( utran_Cell5 );

    // Pre-Preamble on UTRAN cell first to set PTSMI, PTSMI Sig and TMSI in USIM
    f_UTRAN_Pre_Preamble (utran_Cell5);
    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_TestBody_Set( true );

//    v_CoOrd_AuthParams := f_ReceiveAuthCoOrdParameters (EUTRA);
//    v_M_TMSIIn := v_CoOrd_AuthParams.GutiParams.M_TMSI;
    // First Trigger
    //@siclog "Step 1" siclog@
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

    // Step 2. Wait for 10 seconds for UE to camp on cell 5
    // @siclog "Step 2" siclog@
    f_Delay (10.0 * 0.9);
    
    f_UTRAN_RRC_ConnEst(utran_Cell5, est_Reg, registration); // Establish RRC connection
    
    f_UTRA_SS_SetConfigRRC_RB3 ( utran_Cell5);
    interleave {
        //Check: The UE transmits a LOCATION UPDATING REQUEST on cell 5 to the MSC as specified in the specific message contents
        // included in an INITIAL DIRECT TRANSFER message with intraDomainNasNodeSelector mapped from MSC TMSI allocated in the ATTACH ACCEPT message (step 14 table 4.5.2.3-1 of TS 36.508 [18])).
        // @siclog "Step 3" siclog@
     [] U_AM.receive ( car_RLC_Data_Ind ( utran_Cell5,
                                          tsc_RB3,
                                          cr_InitDirectTransfer_TMSI ( v_RoutingParameterTMSI,
                                                                       v_HPLMN_987_65 ) ) ) -> value v_RLC_AM_DATA_IND_LocUpd
       {}
     // Check: Does the UE transmits a ROUTING AREA UPDATE REQUEST message on Cell 5 as specified in the specific message contents
     // included in an INITIAL DIRECT TRANSFER message with intraDomainNasNodeSelector mapped from GUTI-1 and
     
     // **** TO DO Establishment Cause is not included in Initial Direct Transfer definition
     // set to inter-RAT cell-selection.
     // Note: This step is run in parallel with step 3.

    // @siclog "Step 5" siclog@
     [] U_AM.receive ( car_RLC_Data_Ind ( utran_Cell5,
                                        tsc_RB3,
                                        cr_InitDirectTransfer( v_RoutingParameterPTMSI,
                                                                v_HPLMN_987_65 ) ) ) -> value v_RLC_AM_DATA_IND_RAUpd
       {}
    }
    //Reconfigure SS for routing UL NAS message in the Dc PCO
    f_UTRA_SS_RemoveConfigRRC_RB3 ( utran_Cell5 );

    if (f_DecodeAndMatch_LocUpdReq_Msg(v_RLC_AM_DATA_IND_LocUpd.data.aM_message.uL_DCCH_Message.message_.initialDirectTransfer.nas_Message, cr_LocUpdReqAny_Common(?))) {
      f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 3");
    }

    v_START_Value := v_RLC_AM_DATA_IND_LocUpd.data.aM_message.uL_DCCH_Message.message_.initialDirectTransfer.v3a0NonCriticalExtensions.initialDirectTransfer_v3a0ext.start_Value;
    f_SS_SecurityDownloadStart(cs_domain, v_START_Value);

    //Send SECURITY MODE COMMAND and receive SECURITY MODE COMPLETE
    f_RRC_Security(utran_Cell5, v_NewKeyFlag, cs_domain );
    //Send Location Updating Accept message
    // @siclog "Step 4" siclog@
    U_Dc.send (cs_DataReq(utran_CellDedicated, tsc_RB3, cs_U_LocUpdAcpIMSI (v_PLMN, v_LAC, f_Imsi2MobileIdentity(px_IMSI_Def))));

    // The SS transmits a ROUTING AREA UPDATE ACCEPT message with Update result = "RA updated" and new P-TMSI allocated
    // with a different NRI (=IDNNS) to that in the GUTI and the P-TMSI that was stored on the USIM.
    // @siclog "Step 6" siclog@
    U_Dc.send (cs_PS_DataReq(utran_CellDedicated,
                             tsc_RB3,
                             cs_U_RA_UpdAcc3 (cs_GMM_UpdateResult (v_UpdateType),
                                              cs_RAI (omit,
                                                      cs_LAI(omit, v_PLMN, v_LAC),
                                                      v_RAC ),
                                              cs_PTMSI_Signature (px_PTMSI_SigDef),
                                              cs_MobileIdTMSIorPTMSI ('18'O, px_PTMSI_Def))));
    
    v_ReceivedRauReq_Msg := f_DecodeRauReq_Msg (v_RLC_AM_DATA_IND_RAUpd.data.aM_message.uL_DCCH_Message.message_.initialDirectTransfer.nas_Message);
    if (match(v_ReceivedRauReq_Msg, cr_RA_UpdReq_Common (cr_GMM_UpdateType(?,?), cr_RAI_Any (omit), cr_PTMSI_SignatureAny ifpresent, cr_TMSI_Status, ? ))) {
      f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 5");
    }

    v_START_Value := v_RLC_AM_DATA_IND_RAUpd.data.aM_message.uL_DCCH_Message.message_.initialDirectTransfer.v3a0NonCriticalExtensions.initialDirectTransfer_v3a0ext.start_Value;
    f_SS_SecurityDownloadStart(ps_domain, v_START_Value);
    v_UpdateType := v_ReceivedRauReq_Msg.updateType.updateValue;
    if (v_UpdateType != '000'B) {
      v_UpdateType := '001'B;
    }
    
    f_RRC_Security(utran_Cell5,                        // SECURITY MODE COMMAND, SECURITY MODE COMPLETE
           v_NewKeyFlag,
           ps_domain);

    // The UE transmits a ROUTING AREA UPDATE COMPLETE message.
    // @siclog "Step 7" siclog@
    U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3, cr_U_RAUpdComplete ));

    // @siclog "Step 8" siclog@
    f_UTRAN_RRC_ConnRel(utran_CellDedicated, cell_Dch);

    //@siclog "Step 9 - 11" siclog@
    // The SS transmits Paging with new P-TMSI allocated in step 6 on cell 5
    // Check: Does the UE send a Service Request to access the PS domain using IDNNS mapped from the P-TMSI allocated in step 16
    // The SS transmits a Service Accept message to the UE
    // *** TO DO ***

    // @siclog "Step 12" siclog@
    f_UTRAN_RRC_ConnRel(utran_CellDedicated, cell_Dch);

    // Need to Set GUTI based on PTMSI (which is px_PTMSI_Def), LAC and RAC, see 23.003
    v_M_TMSIOut := '11'B & substr(oct2bit(px_PTMSI_Def), 24, 6) & oct2bit(v_RAC) & substr(oct2bit(px_PTMSI_Def), 0, 15);
    v_GTUIParams := cs_IRAT_GUTIStuff (replace(oct2bit(v_LAC), 0, 1, '1'B), substr(oct2bit(px_PTMSI_Def), 16, 8), v_M_TMSIOut);

    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationSuitableNeigbourCell);
//    f_UTRAN_SendAuthCoOrdParameters (EUTRA, v_GTUIParams);
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);

    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA);  // wait for E-UTRAN side to finish and then the whole test case is finished.
    // Test case now finished on UTRAN side
    f_UTRAN_TestBody_Set( false );

    f_UTRAN_ReleaseCell ( utran_Cell5 );

} // end of f_TC_9_2_3_3_4_UTRAN
//---------------------------------------------------------------------
/**
  * @desc Periodic Routing Area Update (multi RAT test)
*/
function f_TC_9_2_3_3_5_UTRAN () runs on UTRAN_PTC
{
 /*
    Test Purpose (TP)
  (1)
  with { UE is camped on an E-UTRAN cell or in ECM-CONNECTED state and ISR is activated }
  ensure that {
    when { UE performs E-UTRA RRC state transitions }
      then { UE keeps the periodic routing area update timer T3312 running }
              }
   (2)
  with { UE is camped on an E-UTRAN cell or ECM-CONNECTED state and ISR is activated }
  ensure that {
    when { the periodic routing area update timer T3312 expires }
      then { UE does not change RAT }
              }
  (3)
  with { UE is in state GMM-REGISTERED.NO-CELL-AVAILABLE and ISR is activated and the periodic routing area update timer T3312 expires }
  ensure that {
    when { UE enters the state GMM-REGISTERED.NORMAL-SERVICE }
      then { UE initiates the routing area updating procedure }

    */

    /*
    Pre-test conditions
    System Simulator:
    -   Cell A and if pc_UTRAN  Cell 5 or if (NOT pc_UTRAN AND pc_GERAN) Cell 24:
    -   Cell A belongs to TAI-1 (home PLMN) and is set to "Serving cell"
    -   if pc_UTRAN, Cell 5 (only active when stated)
    -   home PLMN
    -   RAI-1 (RAC & LAC values chosen by SS)
    -   System information indicate that NMO 1 is used
    -   Set to ''Non-suitable cell''
    -   if  (NOT pc_UTRAN AND pc_GERAN), Cell 24 (only active when stated)
    -   home PLMN
    -   RAC-1 (RAC & LAC values chosen by SS)
    -   System information indicate that NMO 1 is used
    -   Set to ''Non-suitable cell''
    UE:
    -   The test USIM contains IMSI-1, GUTI-1 and TAI-1 (MCC1/MNC1/TAC1), and EPS update status is "EU1: UPDATED".
    -   if pc_UTRAN or pc_GERAN, the test USIM contains P-TMSI-1 (belonging to RAI-1) and the update status is "U1: UPDATED".
    Preamble:
    -   The UE is in state Registered, Idle Mode (state 2) on Cell A according to [18].

  */

  var boolean v_TriggerRxd := false;
  var START_Value v_START_Value := '00000000000000000000'B;
  var octetstring v_PLMN := f_U_Asn2Nas_PlmnId(f_UTRAN_CellInfo_GetPLMNIdentity(utran_Cell5));
  var octetstring v_LAC := f_UTRAN_CellInfo_GetLAC(utran_Cell5);
  var octetstring v_RAC := f_UTRAN_CellInfo_GetRAC(utran_Cell5);
  var RRC_DATA_IND v_RRC_DataInd;
  var template(value) RRCDataReqType v_RRC_DataReq;
  timer t_Wait30s := f_UG_SetTimerToleranceMax (30.0);
  timer t_T3312_high := f_UG_SetTimerToleranceMax (7.0 * 60.0); // Periodic RA Update timer + 10%
  timer t_T3312_low := f_UG_SetTimerToleranceMin (7.0 * 60.0);  // Periodic RA Update timer - 10%

  if (pc_UTRA) { // UE supports UTRAN
    f_UTRAN_Init(EUTRA_UTRAN); // This is still only a 2 PTC test

    f_SS_CreateCellDCH(utran_Cell5);
    f_UTRAN_SendDefSysInfo (utran_Cell5);

    f_UTRAN_Pre_Preamble (utran_Cell5);
    f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);
    f_UTRAN_TestBody_Set( true );

    //@siclog "Step 1a1" siclog@
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA);
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

    // Routing Area Update on UTRAN side
    //@siclog "Step 1a2 - 1a4" siclog@
    f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
    alt{
    [] U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3,
                                                cr_U_RA_UpdReq_WithUtranSignatures ( cr_GMM_UpdateType ( ?, '000'B),
                                                                       ?,
                                                                       cr_RAI_Any (omit),
                                                                       cr_PTMSI_SignatureAny ifpresent,
                                                                       '0000'O, // Hellen TO DO PTMSI mapped from GUTI
                                                                       cr_MobileIdAny('1A'O) ifpresent,
                                                                       cr_RoutingAreaId2_Any ifpresent)))
          -> value v_RRC_DataInd {
      v_START_Value := v_RRC_DataInd.ttcn_start;
      f_SS_SecurityDownloadStart(ps_domain, v_START_Value);
    }}
    // Check ISR support
    if (v_RRC_DataInd.msg.routingAreaUpdateRequest.msNetworkCap.isrSupport != '1'B) {
      f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 1a2");
    }
    // FFS  f_GMM_Authentication(p_CellId);
    // FFS f_RRC_Security(p_CellId,                        // SECURITY MODE COMMAND, SECURITY MODE COMPLETE
    //                 v_NewKeyFlag,
    //                 ps_domain);
    v_RRC_DataReq := cs_U_RA_UpdAcc3 (cs_GMM_UpdateResult ('100'B), // Updated ISR activated
                    cs_RAI (omit,
                    cs_LAI(omit, v_PLMN, v_LAC),
                    v_RAC ),
                    cs_PTMSI_Signature (px_PTMSI_SigDef),
                    cs_MobileIdTMSIorPTMSI ('18'O, px_PTMSI_Def));
    // Set RAU timer to 7 minutes (see 36.523-1 9.2.3.3.5 Table 9.2.3.3.5.3.3-3)
    // (TS 24.008 clause 10.5.7.4)
    v_RRC_DataReq.routingAreaUpdateAccept.periodicRAupdateTimer:= cs_GprsTimer_v('001'B, '00111'B);
    U_Dc.send (cs_PS_DataReq(utran_CellDedicated, tsc_RB3, v_RRC_DataReq));

    U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3, cr_U_RAUpdComplete ));
    f_UTRAN_RRC_ConnRel ( utran_Cell5, cell_Fach_Dcch );

   // Start timer for T3312, which should be started after sending of RAU accept
   t_T3312_high.start;
   t_T3312_low.start;

    //@siclog "Step 1a5" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side

    // Wait for step 2 to 8 on EUTRA to complete
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait trigger from  EUTRAN side

    //@siclog "Step 9a1" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);

    t_T3312_low.timeout; // RAU can't be too early
    // Routing Area Update on UTRAN side
    //@siclog "Step 9a2 - 9a4" siclog@
    f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
    alt{
    [] t_T3312_high.timeout { // Can't arrive too late
      f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 9a2");
       }
    [] U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3,
                                                cr_U_RA_UpdReq_WithUtranSignatures ( cr_GMM_UpdateType ( ?, '011'B),
                                                                       ?,
                                                                       cr_RAI_Any (omit),
                                                                       cr_PTMSI_SignatureAny ifpresent,
                                                                       '0000'O, // Hellen TO DO PTMSI mapped from GUTI
                                                                       cr_MobileIdAny('1A'O) ifpresent,
                                                                       cr_RoutingAreaId2_Any ifpresent)))
          -> value v_RRC_DataInd {
      t_T3312_high.stop;
      f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 9a2");
      v_START_Value := v_RRC_DataInd.ttcn_start;
      f_SS_SecurityDownloadStart(ps_domain, v_START_Value);
    }}
    // Check ISR support
    if (v_RRC_DataInd.msg.routingAreaUpdateRequest.msNetworkCap.isrSupport != '1'B) {
      f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 9a2");
    }
    // FFS  f_GMM_Authentication(p_CellId);
    // FFS f_RRC_Security(p_CellId,                        // SECURITY MODE COMMAND, SECURITY MODE COMPLETE
    //                 v_NewKeyFlag,
    //                 ps_domain);
    U_Dc.send (cs_PS_DataReq(utran_CellDedicated, tsc_RB3, v_RRC_DataReq));

    U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3, cr_U_RAUpdComplete ));
    f_UTRAN_RRC_ConnRel ( utran_Cell5, cell_Fach_Dcch );

    //@siclog "Step 9a5" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side

    // Wait for steps 10 to 20 on EUTRA to complete
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait trigger from  EUTRAN side

    //@siclog "Step 21a1" siclog@
    f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);
    t_Wait30s.start;

    // Routing Area Update on UTRAN side
    //@siclog "Step 21a2 - 21a4" siclog@
    f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
    alt{
    [] t_Wait30s.timeout{
       f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 21a2");
       }
    [] U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3,
                                                cr_U_RA_UpdReq_WithUtranSignatures ( cr_GMM_UpdateType ( ?, '011'B),
                                                                       ?,
                                                                       cr_RAI_Any (omit),
                                                                       cr_PTMSI_SignatureAny ifpresent,
                                                                       '0000'O, // Hellen TO DO PTMSI mapped from GUTI
                                                                       cr_MobileIdAny('1A'O) ifpresent,
                                                                       cr_RoutingAreaId2_Any ifpresent)))
          -> value v_RRC_DataInd {
      t_Wait30s.stop;
      f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "Step 21a2");
      v_START_Value := v_RRC_DataInd.ttcn_start;
      f_SS_SecurityDownloadStart(ps_domain, v_START_Value);
    }}
    // Check ISR support
    if (v_RRC_DataInd.msg.routingAreaUpdateRequest.msNetworkCap.isrSupport == '1'B) {
      f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 21a2");
    }
    // FFS  f_GMM_Authentication(p_CellId);
    // FFS f_RRC_Security(p_CellId,                        // SECURITY MODE COMMAND, SECURITY MODE COMPLETE
    //                 v_NewKeyFlag,
    //                 ps_domain);
    U_Dc.send (cs_PS_DataReq(utran_CellDedicated, tsc_RB3, v_RRC_DataReq));

    U_Dc.receive(car_PS_InitDirectTransfer(utran_CellDedicated, tsc_RB3, cr_U_RAUpdComplete ));

    //@siclog "Step 21a5" siclog@
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side to release cell

    // Test case now finished on UTRAN side
    f_UTRAN_TestBody_Set( false );
    f_UTRA_Postamble ( utran_Cell5, U1_IDLE ); // to be checked
 } // UTRAN not supported, so do nothing
} // f_TC_9_2_3_3_5_UTRAN


//---------------------------------------------------------------------

/**
  * @desc E-UTRAN RRC connection failure / reselection of UTRAN cell / NAS signaling
  *        to release old S1 interface connection (multi RAT test)
*/
function f_TC_9_2_3_3_6_UTRAN () runs on UTRAN_PTC
{
 /*
    Test Purpose (TP)
     (1)
    with { UE is E-UTRA RRC_CONNECTED state and ISR not activated }
    ensure that {
      when { Radio link failure is detected and UE attempts to select a suitable E-UTRA cell to re-establish the RRC connection }
        then { UE can not find a suitable cell for T311 and leaves RRC_CONNECTED state with release cause 'RRC connection failure' }
     (2)
    with { UE searches for a suitable cell after an indication of E-UTRAN 'RRC connection failure'}
    ensure that {
      when { UE detects an UTRA cell and returns to coverage }
        then { UE performs a routing area update }
                }
    */

    /*
    Pre-test conditions

    System Simulator:
    -   Cell A is configured according to Table 6.3.2.2-1 in [18].
    -   Cell A belongs to TAI-1 and is set to "Serving cell"
    -   Cell 5 is configured according to Table 4.4.4-2 in [18].
    -   Cell 5 belongs to RAI-1 and is set to ''Non-suitable cell''
    -   System information indicate that NMO 1 is used
    UE:
    None.
    Preamble:
    -   UE is in state Generic RB established (state 3) on Cell A according to [18].
  */

  var boolean v_TriggerRxd := false;

  f_UTRAN_Init(EUTRA_UTRAN);

  f_SS_CreateCellDCH(utran_Cell5);
  f_UTRAN_SendDefSysInfo (utran_Cell5);

  f_UTRAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_UTRAN_TestBody_Set( true );
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationNonSuitableCell);

  //@siclog "Step 2" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_UTRAN_SetCellPower (utran_Cell5, tsc_AttenuationServingCell);
  f_Delay(10.0);

  // Table-2 Parallel behaviour
  //@siclog "Step 3" siclog@
  f_UTRAN_RRC_ConnEst ( utran_Cell5, est_Reg, registration );
  f_UTRAN_GMM_RAU( utran_Cell5 );
  f_UTRAN_PreliminaryPass (__FILE__, __LINE__, "");
  f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger); // Send trigger to EUTRA side

  // Test case now finished on UTRAN side
  f_UTRAN_TestBody_Set( false );
  f_UTRA_Postamble ( utran_Cell5, U2_CONNECTED );
//  f_UTRAN_GMM_DetachOnSwitchOff ( utran_Cell5 );
//  f_UTRAN_ReleaseCell ( utran_Cell5 );
} // f_TC_9_2_3_3_6_UTRAN

} // module NAS_TrackingArea_UTRAN
